<?php
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Update of Georgi Avramov's latest_comments.php by BadDog
Made more campatiable for CN 1.4 and also to include
title of the news for which the comment belongs to make it
usable in a sidebar.
UPDATE AGAIN BY FUNimations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
//absolute path to cutenews
$mPath = "
http://kimbert.dk/blog";$reverse = false; //false = newest comments first.
require_once( "blog/data/config.php" );
require_once( "blog/inc/functions.inc.php" );
//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://kimbert.dk/inde.php';//more help on the format:
http://www.php.net/manual/en/function.date.php$date_format = 'd M y';
//can use: {url}, {name}, {date}, {comment}, {ip}, {mail}, {newsid}, {comid}, {title}
$ctemplate = '<a href="{url}">{name}; <font size="1" color="#999999">{comment}</font></a><br><br>';
$latest_comments = array();
$all_comments = file("blog/data/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)
{
$single_comment_arr = explode("|",$single_comment);
$latest_comments[$single_comment_arr[0]] = array_merge( array( $newsid ), $single_comment_arr );
}
}
if($reverse)
ksort($latest_comments);
else
krsort($latest_comments);
$t=0;
foreach($latest_comments as $comment){
$output = $ctemplate;
if ($comment[2]){
$title = get_title($comment[0], $mPath); //make sure path is passed to prevent open errors
$category = get_cat($comment[0], $mPath); //make sure path is passed to prevent open errors
$output = str_replace("{url}", $site_url."?subaction=showcomments&id={newsid}&ucat={category}#{comid}", $output);
$output = str_replace("{name}", $comment[2], $output);
$output = str_replace("{title}", $title, $output);
$output = str_replace("{mail}", $comment[3], $output);
$output = str_replace("{ip}", $comment[4], $output);
$output = str_replace("{comment}", $comment[5],$output);
$output = str_replace("{date}", date($date_format, $comment[1]), $output);
$output = str_replace("{newsid}", $comment[0], $output);
$output = str_replace("{comid}", $comment[1], $output);
$output = str_replace("{category}", $category, $output);
$output = replace_comment("show", $output);
echo $output . "\n";
$t++;
}
if($t == $comments_number) break;
}
function get_title($id, $mPath){
$all_news = file("blog/data/news.txt");
foreach ($all_news as $news) {
$news_arr = explode("|", $news);
if ($news_arr[0] == "$id") {
$title = $news_arr[2];
}
}
$title = ereg_replace("<[^>]*>","",$title); // incase there is html tags
$title = str_stop($title, 1); // keep the title length under 40 chars, edit to taste
return $title;
}
function get_cat($id, $mPath){
$all_news = file("blog/data/news.txt");
foreach ($all_news as $news) {
$news_arr = explode("|", $news);
if ($news_arr[0] == "$id") {
return $news_arr[6];
}
}
return $title;
}
function str_stop($string, $max_length){
if (strlen($string) > $max_length){
$string = substr($string, 0, $max_length);
$pos = strrpos($string, " ");
if ($pos === false) {
return substr($string, 0, $max_length)."...";
}
return substr($string, 0, $pos)."...";
}else{
return $string;
}
}
unset($reverse);
?>