Here is a mod for creating a shortened or truncated album description on the main page and then displaying the full description on the album thumbnail pages. All code additions or changes are done in the theme.php and I'll have a plugin for this soon. However, I think it's good to give this a try as it demonstrates how to create functions, variables and {TAGS} for your gallery. It's simple so give it a try.
Add this variable at the top of your theme.php file, preferably right after any
define statements:
$album_desc = get_album_desc($_GET[album]);
Add these two functions at the end of your theme.php file before the
?>. The first function is to retrieve the album description and the second is to truncate the description for the main page (album listing).
// Get the name of an album
function get_album_desc($aid)
{
global $CONFIG;
global $lang_errors;
$result = cpg_db_query("SELECT description from {$CONFIG['TABLE_ALBUMS']} WHERE aid='$aid'");
$count = mysql_num_rows($result);
if ($count > 0) {
$row = mysql_fetch_array($result);
return bb_decode($row['description']);
} else {
return "Album not found";
}
}
// Function for truncating long text strings.
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
// Adapted for Coppermine Photo Gallery use by Billy Bullock - www.billygbullock.com
function myTruncate($string, $limit, $break=".", $pad="...")
{
// return with no change if string is shorter than $limit
if(strlen($string) <= $limit) return $string;
// is $break present between $limit and the end of the string?
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad;
}
}
return $string;
}
Add these two functions before the previous ones you just added. These are for displaying the truncated descriptions on the album listings. There are two, one for albums displayed under categories and one for uncategorized albums.
function theme_display_album_list(&$alb_list, $nbAlb, $cat, $page, $total_pages)
{
global $CONFIG, $STATS_IN_ALB_LIST, $statistics, $template_tab_display, $template_album_list, $lang_album_list;
$theme_alb_list_tab_tmpl = $template_tab_display;
$theme_alb_list_tab_tmpl['left_text'] = strtr($theme_alb_list_tab_tmpl['left_text'], array('{LEFT_TEXT}' => $lang_album_list['album_on_page']));
$theme_alb_list_tab_tmpl['inactive_tab'] = strtr($theme_alb_list_tab_tmpl['inactive_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&page=%d'));
$theme_alb_list_tab_tmpl['inactive_next_tab'] = strtr($theme_alb_list_tab_tmpl['inactive_next_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&page=%d'));
$theme_alb_list_tab_tmpl['inactive_prev_tab'] = strtr($theme_alb_list_tab_tmpl['inactive_prev_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&page=%d'));
$tabs = create_tabs($nbAlb, $page, $total_pages, $theme_alb_list_tab_tmpl);
$album_cell = template_extract_block($template_album_list, 'album_cell');
$empty_cell = template_extract_block($template_album_list, 'empty_cell');
$tabs_row = template_extract_block($template_album_list, 'tabs');
$stat_row = template_extract_block($template_album_list, 'stat_row');
$spacer = template_extract_block($template_album_list, 'spacer');
$header = template_extract_block($template_album_list, 'header');
$footer = template_extract_block($template_album_list, 'footer');
$rows_separator = template_extract_block($template_album_list, 'row_separator');
$count = 0;
$columns = $CONFIG['album_list_cols'];
$column_width = ceil(100 / $columns);
$thumb_cell_width = $CONFIG['alb_list_thumb_size'] + 2;
starttable('100%');
if ($STATS_IN_ALB_LIST) {
$params = array('{STATISTICS}' => $statistics,
'{COLUMNS}' => $columns,
);
echo template_eval($stat_row, $params);
}
echo $header;
if (is_array($alb_list)) {
foreach($alb_list as $album) {
$count ++;
$params = array('{COL_WIDTH}' => $column_width,
'{ALBUM_TITLE}' => $album['album_title'],
'{THUMB_CELL_WIDTH}' => $thumb_cell_width,
'{ALB_LINK_TGT}' => "thumbnails.php?album={$album['aid']}",
'{ALB_LINK_PIC}' => $album['thumb_pic'],
'{ADMIN_MENU}' => $album['album_adm_menu'],
'{ALB_DESC}' => myTruncate($album['album_desc'], 30, " "), // the number changes the # of characters printed for the album description.
'{ALB_INFOS}' => $album['album_info'],
);
echo template_eval($album_cell, $params);
if ($count % $columns == 0 && $count < count($alb_list)) {
echo $rows_separator;
}
}
}
$params = array('{COL_WIDTH}' => $column_width,
'{SPACER}' => $thumb_cell_width
);
$empty_cell = template_eval($empty_cell, $params);
while ($count++ % $columns != 0) {
echo $empty_cell;
}
echo $footer;
// Tab display
$params = array('{COLUMNS}' => $columns,
'{TABS}' => $tabs,
);
echo template_eval($tabs_row, $params);
endtable();
echo $spacer;
}
// Function to display first level Albums of a category
function theme_display_album_list_cat(&$alb_list, $nbAlb, $cat, $page, $total_pages)
{
global $CONFIG, $STATS_IN_ALB_LIST, $statistics, $template_tab_display, $template_album_list_cat, $lang_album_list;
if (!$CONFIG['first_level']) {
return;
}
$theme_alb_list_tab_tmpl = $template_tab_display;
$theme_alb_list_tab_tmpl['left_text'] = strtr($theme_alb_list_tab_tmpl['left_text'], array('{LEFT_TEXT}' => $lang_album_list['album_on_page']));
$theme_alb_list_tab_tmpl['inactive_tab'] = strtr($theme_alb_list_tab_tmpl['inactive_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&page=%d'));
$tabs = create_tabs($nbAlb, $page, $total_pages, $theme_alb_list_tab_tmpl);
// echo $template_album_list_cat;
$template_album_list_cat1 = $template_album_list_cat;
$album_cell = template_extract_block($template_album_list_cat1, 'c_album_cell');
$empty_cell = template_extract_block($template_album_list_cat1, 'c_empty_cell');
$tabs_row = template_extract_block($template_album_list_cat1, 'c_tabs');
$stat_row = template_extract_block($template_album_list_cat1, 'c_stat_row');
$spacer = template_extract_block($template_album_list_cat1, 'c_spacer');
$header = template_extract_block($template_album_list_cat1, 'c_header');
$footer = template_extract_block($template_album_list_cat1, 'c_footer');
$rows_separator = template_extract_block($template_album_list_cat1, 'c_row_separator');
$count = 0;
$columns = $CONFIG['album_list_cols'];
$column_width = ceil(100 / $columns);
$thumb_cell_width = $CONFIG['alb_list_thumb_size'] + 2;
starttable('100%');
if ($STATS_IN_ALB_LIST) {
$params = array('{STATISTICS}' => $statistics,
'{COLUMNS}' => $columns,
);
echo template_eval($stat_row, $params);
}
echo $header;
if (is_array($alb_list)) {
foreach($alb_list as $album) {
$count ++;
$params = array('{COL_WIDTH}' => $column_width,
'{ALBUM_TITLE}' => $album['album_title'],
'{THUMB_CELL_WIDTH}' => $thumb_cell_width,
'{ALB_LINK_TGT}' => "thumbnails.php?album={$album['aid']}",
'{ALB_LINK_PIC}' => $album['thumb_pic'],
'{ADMIN_MENU}' => $album['album_adm_menu'],
'{ALB_DESC}' => myTruncate($album['album_desc'], 30, " "), // the number changes the # of characters printed for the album description.
'{ALB_INFOS}' => $album['album_info'],
);
echo template_eval($album_cell, $params);
if ($count % $columns == 0 && $count < count($alb_list)) {
echo $rows_separator;
}
}
}
$params = array('{COL_WIDTH}' => $column_width,
'{SPACER}' => $thumb_cell_width
);
$empty_cell = template_eval($empty_cell, $params);
while ($count++ % $columns != 0) {
echo $empty_cell;
}
echo $footer;
// Tab display
$params = array('{COLUMNS}' => $columns,
'{TABS}' => $tabs,
);
echo template_eval($tabs_row, $params);
endtable();
echo $spacer;
}
If you already have these functions in your theme.php, you'll have to edit yours to include the changes. Basically replace the lines for the parameter
'{ALB_DESC}' that appears in these new functions. To change the length of the truncated text, edit
'{ALB_DESC}' => myTruncate($album['album_desc'], 30, " "), and change
30 to a length to suit your needs.
To add the album description to the album thumbnail page, add this variable somewhere in your theme.php.
// HTML template for title row of the thumbnail view (album title + sort options)
$template_thumb_view_title_row = <<<EOT
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" class="statlink"><h2>{ALBUM_NAME}</h2></td>
<td><img src="images/spacer.gif" width="1" alt="" /></td>
<td class="sortorder_cell">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="sortorder_options">{TITLE}</td>
<td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&page={PAGE}&sort=ta" title="{SORT_TA}"> + </a></span></td>
<td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&page={PAGE}&sort=td" title="{SORT_TD}"> - </a></span></td>
</tr>
<tr>
<td class="sortorder_options">{NAME}</td>
<td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&page={PAGE}&sort=na" title="{SORT_NA}"> + </a></span></td>
<td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&page={PAGE}&sort=nd" title="{SORT_ND}"> - </a></span></td>
</tr>
<tr>
<td class="sortorder_options">{DATE}</td>
<td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&page={PAGE}&sort=da" title="{SORT_DA}"> + </a></span></td>
<td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&page={PAGE}&sort=dd" title="{SORT_DD}"> - </a></span></td>
</tr>
<tr>
<td class="sortorder_options">{POSITION}</td>
<td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&page={PAGE}&sort=pa" title="{SORT_PA}"> + </a></span></td>
<td class="sortorder_options"><span class="statlink"><a href="thumbnails.php?album={AID}&page={PAGE}&sort=pd" title="{SORT_PD}"> - </a></span></td>
</tr>
</table>
</td>
</tr>
<tr><td>
<p>{$album_desc}</p>
</td></tr>
</table>
EOT;
Again, if this variable is already in your theme.php file, you can just add
{$album_desc} and using standard HTML and css, you can move and style the text to suit your needs.
I have incorporated this mod into two of my latest themes and you can check them out in the demo gallery for
ChaoticSoul and
DFire. Check them out and let me know what you think.
Cheers,
Gizmo
ATTENTION: Code modified on Oct. 4, 2008 to fix bbcode issue when using bbcode or html code in the album description.