Topic: [HACK] List all commenters
Name: List all commenters
Author: FI-DD
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: on the active news page you can add a list of all people that have commented on that article.
Demo: [url="http://democute.de.funpic.de/cute/example2.php"]here[/url
Instructions:
///////////////////////////////////
Installation:
1. Open functions.inc.php and add this at the end of the file before the last ?>
//////////////////////////////////////////////////////////////////
// Function: Lists all commenters with mail or url when available
function list_commenters($news, $linebreak, $separator) {
global $cutepath;
$alle_comments = file($cutepath."/data/comments.txt");
$i=0;
foreach($alle_comments as $comments_line)
{
$comments_line = trim($comments_line);
$comments_line_arr = explode("|>|", $comments_line);
if($news == $comments_line_arr[0])
{
$individual_comment = explode("||", $comments_line_arr[1]);
foreach ($individual_comment as $single_comment)
{
$single_comment_arr = explode("|", $single_comment);
if (($single_comment_arr[0] != "") && (!stristr($output, $single_comment_arr[1])))
{
$i++;
if($single_comment_arr[2] != "none")
{
if( preg_match("/^[\.A-z0-9_\-]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $single_comment_arr[2])){ $url_target = "";$mail_or_url = "mailto:"; }
else
{
$url_target = "target=\"_blank\"";
$mail_or_url = "";
if(substr($single_comment_arr[2],0,3) == "www") $mail_or_url = "http://";
}
$output .= "[url="]".stripslashes($single_comment_arr[1])."[/url]".$separator;
}
else $output .= $single_comment_arr[1].$separator;
if (fmod($i, $linebreak)==0) $output .= "
";
}
}
}
}
if (fmod($i, $linebreak)=="0") $output = substr($output, 0, -(strlen($separator)+6));
else $output = substr($output, 0, -strlen($separator));
return $output;
}
2. Open shows.inc.php
a. Find:
$output = str_replace("{title}", $news_arr[2], $template_full);
add below:
if(CountComments($news_arr[0], $archive) > 0){
$output = str_replace('[commenters-header]', '', $output);
$output = str_replace('[/commenters-header]', '', $output);
$output = preg_replace("#\{commenters:(.*):(.*)\}#ie", "list_commenters('".$news_arr[0]."', '\\1', '\\2')", $output);
}
else $output = preg_replace("#\[commenters-header\](.*?)\[/commenters-header\]#i", "", $output);
b. Find:
$output = $template_active;
add below:
if(CountComments($news_arr[0], $archive) > 0){
$output = str_replace('[commenters-header]', '', $output);
$output = str_replace('[/commenters-header]', '', $output);
$output = preg_replace("#\{commenters:(.*):(.*)\}#ie", "list_commenters('".$news_arr[0]."', '\\1', '\\2')", $output);
}
else $output = preg_replace("#\[commenters-header\](.*?)\[/commenters-header\]#i", "", $output);
Now you can use [commenters-header]{commenters:N:S}[/commenters-header] in your template (Active News/Full Story) to list the commenters for each article.
N is the number of commenters per line (0 = all in one line) and S is the separator between each commenter.
Everything between [commenters-header] and [/commenters-header] shows only if there is a comment.
For example:
[commenters-header]{commenters:2: - }[/commenters-header]
would show this:
commenter1 - commenter2 -
commenter3 - commenter4
////////////////////////////////////////