Advanced search  

News:

cpg1.5.46 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter recently discovered vulnerabilities. It is important that all users who run version cpg1.5.44 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Comment List  (Read 10392 times)

0 Members and 1 Guest are viewing this topic.

Gizmo

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1015
    • BullsEye Photos
Comment List
« on: August 22, 2008, 06:41:58 pm »

WordPress has a plugin that can list current comments in a sidebar. It's actually a link to the comment in a post so what's shown in the sidebar is the person who commented and the post. You can see the plugin in action here on this blog. I wrangled with this idea trying to get CPG to spit out the commentor and the actual comment of a photo but I've had zero success. This idea would make a great addition to themes and was wondering if someone with more coding experience would be willing to give this a try or maybe give me some code snippets to help me along. This would also make a great plugin but I would like to have it to make it part of the themes I'm porting. Being able to specify how may comments are displayed would be required.

Thanks for any help that can be given.  :)
Logged
Did you read the manual first???? Taking 2 minutes to backup your files can save you hours of wondering what you screwed up.
Billy Bullock - BullsEyePhotos Blog of Indecision

Gizmo

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1015
    • BullsEye Photos
Re: Comment List
« Reply #1 on: October 05, 2008, 12:58:44 am »

I thought I'd give this another try but I'm only having limited success. I can get the list to spit out but it's displayed at the top of the gallery page outside and above the <html> when you view the html source.

Here's what I've gotten so far:
Code: [Select]
function lastcomments()
{
global $CONFIG;
$query = "SELECT * from {$CONFIG['TABLE_COMMENTS']} ORDER by msg_id DESC $limit";
$result = cpg_db_query($query);
$comment_cnt = 3; //number of comments to retrieve
echo "<ul>";
    while($row = mysql_fetch_array($result) and $comment_cnt > 0) {
echo "<li>" . $row['msg_body'] . " by " . $row['msg_author'] . " on " . $row['msg_date'] . "</li>";
$comment_cnt--;

}
echo "</ul>";
mysql_free_result($result);
}

Then I put '{LASTCOM}' => lastcomments(), in the function pageheader and {LASTCOM} in a sidebar in the template.html but it displays at the top of the gallery. You can see it here on a test gallery.

Any help will be appreciated.
Logged
Did you read the manual first???? Taking 2 minutes to backup your files can save you hours of wondering what you screwed up.
Billy Bullock - BullsEyePhotos Blog of Indecision

Nibbler

  • Guest
Re: Comment List
« Reply #2 on: October 05, 2008, 01:24:05 am »

You need to return the HTML code, not echo it directly. Also, be more careful with the database. You only need the last 3 comments so don't make the database sort and retrieve all of them.

Code: [Select]
function lastcomments()
{
global $CONFIG;

$comment_cnt = 3; //number of comments to retrieve

$query = "SELECT msg_body, msg_author, msg_date FROM {$CONFIG['TABLE_COMMENTS']} ORDER BY msg_id DESC LIMIT $comment_cnt";
$result = cpg_db_query($query);

$output = '<ul>';

while ($row = mysql_fetch_assoc($result)) {
$output .= '<li>' . $row['msg_body'] . ' by ' . $row['msg_author'] . ' on ' . $row['msg_date'] . '</li>';
}

$output .= '</ul>';

mysql_free_result($result);

return $output;
}
Logged

Gizmo

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1015
    • BullsEye Photos
Re: Comment List
« Reply #3 on: October 05, 2008, 02:06:22 am »

Thanks Nibbler! This is much clearer now. I understand about hitting the database but was trying to get the code to display correctly first plus I'll also link the comment to the image. This is quite nice and will be a good addition to some new themes I want to work on. :)
Logged
Did you read the manual first???? Taking 2 minutes to backup your files can save you hours of wondering what you screwed up.
Billy Bullock - BullsEyePhotos Blog of Indecision

Gizmo

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1015
    • BullsEye Photos
Re: Comment List
« Reply #4 on: October 08, 2008, 08:28:27 pm »

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 ?>.
Code: [Select]
// 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.
Code: [Select]
// 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.
Code: [Select]
//$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. :D 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!  ;D

Enjoy!  :)

Billy
« Last Edit: October 08, 2008, 08:52:57 pm by Gizmo »
Logged
Did you read the manual first???? Taking 2 minutes to backup your files can save you hours of wondering what you screwed up.
Billy Bullock - BullsEyePhotos Blog of Indecision

atomjani

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: Comment List
« Reply #5 on: June 21, 2010, 11:12:31 am »

This is work in cpg1.5.x?
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47844
  • aka "GauGau"
    • gaugau.de
Re: Comment List
« Reply #6 on: June 21, 2010, 02:30:42 pm »

No, probably not. You're not allowed to ask such questions as per Don't ask for other versions. Failing to respect board rules doesn't supporters more inclined to look into your issues. Mods are deprecated in general; use plugins instead.
Locking
Logged
Pages: [1]   Go Up
 

Page created in 0.032 seconds with 21 queries.