Topic: latest comment

How can I show latest comments in CN 1.5? Thanx

Re: latest comment

There was a hack for this in 1.3.6 here:
https://cutephp.com/forum/index.php?showtopic=10545

With slight modification it works in 1.5
i.e the require_once lines
change references from data folder to cdata
add correct $mPath references

Re: latest comment

There was a hack for this in 1.3.6 here:
https://cutephp.com/forum/index.php?showtopic=10545

With slight modification it works in 1.5
i.e the require_once lines
change references from data folder to cdata
add correct $mPath references

yes, it works. You can see hear http://www.pasqualemarinelli.com/indexb.php , to the right menu, running under a little bit. But look the error message: "503 Service Unavailable invalid template characters". What I can do to fix?

Re: latest comment

I have tested the script and it works, when modified, on one of my servers.
503 Service Unavailable error is usually due to something overloading the server.
Take out the latest comments script and see if the error is still there.
If it is then the problem is in the central include.

Re: latest comment

I have tested the script and it works, when modified, on one of my servers.
503 Service Unavailable error is usually due to something overloading the server.
Take out the latest comments script and see if the error is still there.
If it is then the problem is in the central include.


when I take out the latest comments script, the error 503 is not still there. Please Help me!!!! http://www.pasqualemarinelli.com/indexb.php

Re: latest comment

Did you use the version for PHP 5?
Post your modified version here.

Re: latest comment

Did you use the version for PHP 5?
Post your modified version here.

This is PHP 5 version, modified

<?php
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Configuration
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

//number of latest comments to show
if(!isset($comments_number)) $comments_number = 5;

//URL to where you include your news, example: http://site.com/news.php
$site_url = 'http://www.pasqualemarinelli.com/indexb.php';

//more help on the format: http://www.php.net/manual/en/function.date.php
$date_format = 'd M y';

//In your template you can use: {url}, {name}, {date}, {comment}, {ip}, {mail}, {newsid}, {comid}
$template = '[url={]#[/url] by {name} @ {date} : {comment}
';

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  END - END - END - END - END - END / don't edit below /
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

    $latest_comments = array_fill(1, $comments_number, array('newsid'=>'0','comid'=>'0','name'=>'','mail'=>'','ip'=>'','comment'=>''));

    function check_latest_comment($comment_line, $newsid){
        global $latest_comments;
        $tmp_latest_comments = $latest_comments;
        $comment_arr = explode("|", $comment_line);
        foreach($latest_comments as $key=>$latest_comment){

            if($latest_comment['comid'] < $comment_arr[0]){

                $previous = $latest_comments[$key];
                foreach($latest_comments as $my_key=>$latest_comment_arr){
                    if($key < $my_key){
                     $current = $latest_comments[$my_key];
                     $latest_comments[$my_key] = $previous;
                     $previous = $current;
                    }
                }

                $latest_comments[$key] = array(
                                       'newsid'    => $newsid,
                                       'comid'    => $comment_arr[0],
                                       'name'    => $comment_arr[1],
                                       'mail'    => $comment_arr[2],
                                       'ip'        => $comment_arr[3],
                                       'comment'=> $comment_arr[4],
                                               );
            }
        }
    }

    $all_comments = file("b/cdata/comments.txt");
    foreach($all_comments as $comment_line)
    {
        $comment_line_arr = explode("|>|", $comment_line);
        $newsid = $comment_line_arr[0];
        $comment_arr = explode("||", $comment_line_arr[1]);
        foreach($comment_arr as $single_comment)
        {
            check_latest_comment($single_comment, $newsid);
        }
    }


    foreach($latest_comments as $comment){
        $output = $template;
        $output = str_replace("{url}", $site_url."?subaction=showcomments&id={newsid}#{comid}", $output);
        $output = str_replace("{name}", $comment['name'], $output);
        $output = str_replace("{mail}", $comment['mail'], $output);
        $output = str_replace("{ip}", $comment['ip'], $output);
        $output = str_replace("{comment}", $comment['comment'], $output);
        $output = str_replace("{date}", date($date_format, $comment['comid']), $output);
        $output = str_replace("{newsid}", $comment['newsid'], $output);
        $output = str_replace("{comid}", $comment['comid'], $output);
        echo $output;
    }
?>

8 (edited by 2012-11-03 15:33:34)

Re: latest comment

Your code works here without giving an error, although it repeats the same comment. Try changing $template to a different name. Are you using any other variables both in your main include and in the comments hack?

Re: latest comment

Your code works here without giving an error, although it repeats the same comment. Try changing $template to a different name. Are you using any other variables both in your main include and in the comments hack?

Not bad Damoor!!! Good point! I had to add in main include this:

$template="Default";


Now it works very fine. thank you!!!

Re: latest comment

Why my latest comments script, in CN 1.5, shows 5 times the same comment, but not the last 5 comments? You con see it here, to the right side, downward http://www.pasqualemarinelli.com/indexb.php

This is my script:

<?php
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Configuration
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

//number of latest comments to show
if(!isset($comments_number)) $comments_number = 5;

//URL to where you include your news, example: http://site.com/news.php
$site_url = 'http://www.pasqualemarinelli.com/indexb.php';

//more help on the format: http://www.php.net/manual/en/function.date.php
$date_format = 'd/m/Y';

//In your template you can use: {url}, {name}, {date}, {comment}, {ip}, {mail}, {newsid}, {comid}
$template = '<font face="Arial">[b]{name} [{date}] scrive:[/b] {comment} [url={][u]Vai al post[/u][/url]

</font>';

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  END - END - END - END - END - END / don't edit below /
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

    $latest_comments = array_fill(1, $comments_number, array('newsid'=>'0','comid'=>'0','name'=>'','mail'=>'','ip'=>'','comment'=>''));

    function check_latest_comment($comment_line, $newsid){
        global $latest_comments;
        $tmp_latest_comments = $latest_comments;
        $comment_arr = explode("|", $comment_line);
        foreach($latest_comments as $key=>$latest_comment){

            if($latest_comment['comid'] < $comment_arr[0]){

                $previous = $latest_comments[$key];
                foreach($latest_comments as $my_key=>$latest_comment_arr){
                    if($key < $my_key){
                     $current = $latest_comments[$my_key];
                     $latest_comments[$my_key] = $previous;
                     $previous = $current;
                    }
                }

                $latest_comments[$key] = array(
                                       'newsid'    => $newsid,
                                       'comid'    => $comment_arr[0],
                                       'name'    => $comment_arr[1],
                                       'mail'    => $comment_arr[2],
                                       'ip'        => $comment_arr[3],
                                       'comment'=> $comment_arr[4],
                                               );
            }
        }
    }

    $all_comments = file("b/cdata/comments.txt");
    foreach($all_comments as $comment_line)
    {
        $comment_line_arr = explode("|>|", $comment_line);
        $newsid = $comment_line_arr[0];
        $comment_arr = explode("||", $comment_line_arr[1]);
        foreach($comment_arr as $single_comment)
        {
            check_latest_comment($single_comment, $newsid);
        }
    }


    foreach($latest_comments as $comment){
        $output = $template;
        $output = str_replace("{url}", $site_url."?subaction=showcomments&id={newsid}#{comid}", $output);
        $output = str_replace("{name}", $comment['name'], $output);
        $output = str_replace("{mail}", $comment['mail'], $output);
        $output = str_replace("{ip}", $comment['ip'], $output);
        $output = str_replace("{comment}", $comment['comment'], $output);
        $output = str_replace("{date}", date($date_format, $comment['comid']), $output);
        $output = str_replace("{newsid}", $comment['newsid'], $output);
        $output = str_replace("{comid}", $comment['comid'], $output);
        echo $output;
    }
?>