OK, here's my finished project for displaying just the text of the latest comments in a sidebar of your theme. These are the latest comments that viewers have posted on pictures from your site. It's got a couple of cool features:
- displays the smilies
- date reads "Today", "Yesterday" or month-day-year
- comment linked to the picture
- easy to change number of comments to display
- repects non-public albums
Displaying the smilies wasn't as straightforward as I hoped so you have to add 2 additional functions to your theme.php tp display them. These are
function process_smilies_custom and
function get_smilies_table_custom(). The reason is that for certain pages, the
smilies.inc.php is not included and you'll get an error if smilies are enabled in the configuration so I've added them to the theme.php. If you use custom smilies you will need to add them to this list as well as to the
smilies.inc.php.
To use this cool new feature you need to copy the below 3 functions to your theme.php before the ending
?>.
// This function is for displaying latest comments in list form in a sidebar.
// Change the number of comments to display by editing "$comment_cnt".
// Please acknowledge use of this code by including this header.
// Develeoped for Coppermine Photo Gallery by Billy Bullock - www.billygbullock.com
function lastcomments()
{
global $CONFIG;
$comment_cnt = 4; //change this number for comments to display
$select_columns = 'p.aid, p.*, msg_body, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date';
if (USER_ID) {
$query = "SELECT $select_columns FROM {$CONFIG['TABLE_COMMENTS']} as c, {$CONFIG['TABLE_PICTURES']} as p WHERE approved = 'YES' AND c.pid = p.pid ORDER by msg_id DESC LIMIT $comment_cnt";
$result = cpg_db_query($query);
}else{
$query = "SELECT $select_columns FROM {$CONFIG['TABLE_COMMENTS']} AS c, {$CONFIG['TABLE_PICTURES']} AS p, {$CONFIG['TABLE_ALBUMS']} AS a WHERE c.pid = p.pid AND p.aid = a.aid AND approved = 'YES' AND visibility = 0 ORDER by msg_id DESC LIMIT $comment_cnt";
$result = cpg_db_query($query);
}
while ($row = mysql_fetch_assoc($result)) {
if ($CONFIG['enable_smilies']) { //displays smilies if enabled in configuration. Also need "function process_smilies_custom" & "function get_smilies_table_custom()".
$comment_body = process_smilies_custom($row['msg_body']);
} else {
$comment_body = $row['msg_body'];
}
if(localised_date($row['msg_date'], '%B %d, %Y') == date("M d, Y")) { //displays date as "Today", "Yesterday" or "month, day, year" format
$comment_date = " - Today";
}elseif(localised_date($row['msg_date'], '%B %d, %Y') == date("M d, Y", strtotime("-1 days"))) {
$comment_date = " - Yesterday";
} else {
$comment_date = ' on ' . localised_date($row['msg_date'], '%B %d, %Y');
}
//$output prints out the list of comments. You may have to edit the html code to suit your theme needs.
$output .= '<li><a href="displayimage.php?pos=-' . $row['pid'] . '">' . $comment_body . '</a> by ' . $row['msg_author'] . $comment_date . '</li>';
}
mysql_free_result($result);
return $output;
}
// if you do not have smilies enable in the configuration, you can leave this function out.
// this function is for displayng smilies in comments in "function lastcomments()".
function process_smilies_custom($message, $url_prefix = '')
{
static $orig, $repl;
if (!isset($orig)) {
global $db, $board_config,$THEME_DIR;
$orig = $repl = array();
$smilies = get_smilies_table_custom();
$paths = array($THEME_DIR.'/smiles/','images/smiles/');
for($i = 0; $i < count($smilies); $i++) {
$orig[] = "/(?<=.\W|\W.|^\W)" . preg_quote($smilies[$i][0], "/") . "(?=.\W|\W.|\W$)/";
$smile_path = (file_exists($paths[0].$smilies[$i][1]))?($paths[0]):($paths[1]);
$repl[] = '<img src="' . $url_prefix . $smile_path . ($smilies[$i][1]) . '" alt="' . ($smilies[$i][2]) . '" />';
}
}
if (count($orig)) {
$message = preg_replace($orig, $repl, ' ' . $message . ' ');
$message = substr($message, 1, -1);
}
return $message;
}
// if you do not have smilies enable in the configuration, you can leave this function out.
// this function is for displayng smilies in comments in "function lastcomments()".
// if you have additional smilies you will need to list them here as well as in "smilies.inc.php".
function get_smilies_table_custom()
{
global $lang_smilies_inc_php;
return array(
array(':!:', 'icon_exclaim.gif', $lang_smilies_inc_php['Exclamation']),
array(':?:', 'icon_question.gif', $lang_smilies_inc_php['Question']),
array(':D', 'icon_biggrin.gif', $lang_smilies_inc_php['Very Happy']),
array(':-D', 'icon_biggrin.gif', $lang_smilies_inc_php['Very Happy']),
array(':grin:', 'icon_biggrin.gif', $lang_smilies_inc_php['Very Happy']),
array(':)', 'icon_smile.gif', $lang_smilies_inc_php['Smile']),
array(':-)', 'icon_smile.gif', $lang_smilies_inc_php['Smile']),
array(':smile:', 'icon_smile.gif', $lang_smilies_inc_php['Smile']),
array(':(', 'icon_sad.gif', $lang_smilies_inc_php['Sad']),
array(':-(', 'icon_sad.gif', $lang_smilies_inc_php['Sad']),
array(':sad:', 'icon_sad.gif', $lang_smilies_inc_php['Sad']),
array(':o', 'icon_surprised.gif', $lang_smilies_inc_php['Surprised']),
array(':-o', 'icon_surprised.gif', $lang_smilies_inc_php['Surprised']),
array(':eek:', 'icon_surprised.gif', $lang_smilies_inc_php['Surprised']),
array(':shock:', 'icon_eek.gif', $lang_smilies_inc_php['Shocked']),
array(':?', 'icon_confused.gif', $lang_smilies_inc_php['Confused']),
array(':-?', 'icon_confused.gif', $lang_smilies_inc_php['Confused']),
array(':???:', 'icon_confused.gif', $lang_smilies_inc_php['Confused']),
array('8)', 'icon_cool.gif', $lang_smilies_inc_php['Cool']),
array('8-)', 'icon_cool.gif', $lang_smilies_inc_php['Cool']),
array(':cool:', 'icon_cool.gif', $lang_smilies_inc_php['Cool']),
array(':lol:', 'icon_lol.gif', $lang_smilies_inc_php['Laughing']),
array(':x', 'icon_mad.gif', $lang_smilies_inc_php['Mad']),
array(':-x', 'icon_mad.gif', $lang_smilies_inc_php['Mad']),
array(':mad:', 'icon_mad.gif', $lang_smilies_inc_php['Mad']),
array(':P', 'icon_razz.gif', $lang_smilies_inc_php['Razz']),
array(':-P', 'icon_razz.gif', $lang_smilies_inc_php['Razz']),
array(':razz:', 'icon_razz.gif', $lang_smilies_inc_php['Razz']),
array(':oops:', 'icon_redface.gif', $lang_smilies_inc_php['Embarassed']),
array(':cry:', 'icon_cry.gif', $lang_smilies_inc_php['Crying or Very sad']),
array(':evil:', 'icon_evil.gif', $lang_smilies_inc_php['Evil or Very Mad']),
array(':twisted:', 'icon_twisted.gif', $lang_smilies_inc_php['Twisted Evil']),
array(':roll:', 'icon_rolleyes.gif', $lang_smilies_inc_php['Rolling Eyes']),
array(':wink:', 'icon_wink.gif', $lang_smilies_inc_php['Wink']),
array(';)', 'icon_wink.gif', $lang_smilies_inc_php['Wink']),
array(';-)', 'icon_wink.gif', $lang_smilies_inc_php['Wink']),
array(':idea:', 'icon_idea.gif', $lang_smilies_inc_php['Idea']),
array(':arrow:', 'icon_arrow.gif', $lang_smilies_inc_php['Arrow']),
array(':|', 'icon_neutral.gif', $lang_smilies_inc_php['Neutral']),
array(':-|', 'icon_neutral.gif', $lang_smilies_inc_php['Neutral']),
array(':neutral:', 'icon_neutral.gif', $lang_smilies_inc_php['Neutral']),
array(':mrgreen:', 'icon_mrgreen.gif', $lang_smilies_inc_php['Mr. Green'])
);
}
If
function pageheader is not already in your theme.php file, copy the below function and paste it into your theme.php.
// Function for writing a pageheader
function pageheader($section, $meta = '')
{
global $CONFIG, $THEME_DIR;
global $template_header, $lang_charset, $lang_text_dir;
$custom_header = cpg_get_custom_include($CONFIG['custom_header_path']);
$charset = ($CONFIG['charset'] == 'language file') ? $lang_charset : $CONFIG['charset'];
header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
header("Content-Type: text/html; charset=$charset");
user_save_profile();
$template_vars = array('{LANG_DIR}' => $lang_text_dir,
'{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
'{CHARSET}' => $charset,
'{META}' => $meta,
'{GAL_NAME}' => $CONFIG['gallery_name'],
'{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
'{SYS_MENU}' => theme_main_menu('sys_menu'),
'{SUB_MENU}' => theme_main_menu('sub_menu'),
'{ADMIN_MENU}' => theme_admin_mode_menu(),
'{CUSTOM_HEADER}' => $custom_header,
'{LASTCOM}' => lastcomments(),
);
echo template_eval($template_header, $template_vars);
}
If this function already exists then add
'{LASTCOM}' => lastcomments(), to the $template_vars list.
Now you will need to add {LASTCOM} somewhere in your template.html to display the last comment list. The above
function lastcomments() is set up to display the list in a
i3Theme such as the ones I've posted eariler so to use it with your theme you'll need to edit the html display code in this line to suit your needs. This example uses a <ul><li> lists.
//$output prints out the list of comments. You may have to edit the html code to suit your theme needs.
$output .= '<li><a href="displayimage.php?pos=-' . $row['pid'] . '">' . $comment_body . '</a> by ' . $row['msg_author'] . $comment_date . '</li>';
I want to thank Nibbler for his guidance in helping me get the output working.

I've uploaded a new theme called
i3Theme 1.7 MellowYellow so you can download a complete theme to try out on your gallery and we'll get to see it in action on the CPG theme demo site!

Enjoy!

Billy