Topic: [HACK] Comments Manager Module
$matches[1] Comments Manager Module
$matches[1] superhero
$matches[1] 1.3.6 - * (no incompatibility reported yet)
$matches[1] Adds a module that lists all comments by last added.
Features:
* it shows latest comments in admin panel (default 30)
* delete comment (for editor and Admin only)
* edit comment (for editor and Admin only)
* Add reply (for all users)
* Block ip (for editor and Admin only)
* check ip (all users)
* ban user (Admin only) //reported not working
* send e-mail (all user if commenter put his e-mail)
$matches[1] PHP4.
$matches[1]
find this in index.php
'editusers' => 'admin',
and add below
'moderator' => 'user',
in inc/option.mdu find this
array(
'name' => "Block IP's from posting comments",
'url' => "$PHP_SELF?mod=ipban",
'access' => "2",
),
and below add this
array(
'name' => "Moderator",
'url' => "$PHP_SELF?mod=moderator&action=moderator",
'access' => "3",
),
make a file called moderator.mdu and uplaod it to your $matches[1] folder
<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'><?PHP
////////////////////////////////////////////////////////////////////
// Moderator hack created by superhero
// I used for it latest_comments.php v 1.6 by BadDog
//
// http://www.aborowski.prv.pl
//
//can use in line 66-97:
//{url}, {name} - author, {date}, {comment}, {ip}, {mail}, {newsid}, {comid}, {title},
//{ipurl} - check ip link, {editurl} - edit comment link, {ipbanurl} - block ip link, {delete} = delete link {addurl} - add replay link
//
//you can change date format in line 25
////////////////////////////////////////////////////////////////////
if($member_db[1] > 3){ msg("error", "Access Denied", "You don't have permission for this section"); }
//////////////////////////////////////////
//////////// MODERATOR ///////////////
if($action == "moderator"){
echoheader("options", "Moderator");
//change date formt
$date_format = 'd-M-y H:m:i';
$flag = 1;
///////////////////// option bar
// Count Comments
$count_comments = 0;
$all_comments = file("./data/comments.txt");
foreach($all_comments as $news_comments){
$single_news_comments = explode("|>|", $news_comments);
$individual_comments = explode("||", $single_news_comments[1]);
$count_comments += count($individual_comments) - 1;
}
// How Many Comments to show on one page
if($comments_number == ""){ $comments_number = 30; }
// How many Comments are on page
$entries_showed = $count_comments - $comments_number;
if ( $entries_showed < 0) { $entries_showed = $count_comments;}
else { $entries_showed = $comments_number;}
echo "<table class=panel border=0 cellpading=0 cellspacing=0 width=99% >
<tr>
<td >Showing $matches[1] comments from total $matches[1]
<div>
<form action=\"?mod=moderator\" method=POST name=options_bar style=\"display:inline;\">
Comments per page
<input style=\"text-align: Center\" name=\"comments_number\" value=\"$comments_number\" type=text size=3>
<input type=submit value=\"Show\">
<input type=hidden name=action value=moderator>
</form>
<form action=\"?mod=moderator\" method=POST name=options_bar style=\"display:inline;\">
<input style=\"text-align: Center\" name=\"comments_number\" value=\"$count_comments\" type=hidden size=3>
<input type=submit value=\"Show All\">
<input type=hidden name=action value=moderator>
</form>
</div>
</td></tr></table>
";
/////////////////////////// edit list section
echo '<table width="99%" border="0" cellspacing="0" cellpadding="0">';
echo '<tr><td width="100">Author/IP/Date</td><td >(News):Comment</td></tr>';
echo '</tabel><table width="99%" border="0" cellspacing="0" cellpadding="0">';
//can use: {url}, {name} - author, {date}, {comment}, {ip}, {mail}, {newsid}, {comid}, {title}, {ipurl} - check ip link, {editurl} - edit comment link, {ipbanurl} - block ip link, {delete} = delete link {addurl} - add replay link
if($member_db[1] == 1)
{
$ctemplate = '<tr valign="top">
<td width="100" bgcolor={bg}><div style="padding:5px; margin:5px;">$matches[1]
{ipurl}<br/>{date}</div></td>
<td ><div style="padding:5px; margin:5px;" class=panel>$matches[1] {comment}<hr>{editurl} + {ipbanurl} + {delete} + {addurl} + {banuser} {mailurl}</div></td>
</tr>';
}
elseif($member_db[1] == 2)
{
$ctemplate = '<tr valign="top" >
<td width="100" bgcolor={bg}><br/>$matches[1]
{ipurl}<br/>{date}</td>
<td width="505"><br/><div style="padding:5px; margin:5px;" class=panel>$matches[1] {comment}<hr>{editurl} + {ipbanurl} + {delete} + {addurl} {mailurl}</div></td>
</tr>';
}
else{
$ctemplate = '<tr valign="top" >
<td width="100" bgcolor={bg}><br/>$matches[1]
{ipurl}<br/>{date}</td>
<td width="505"><br/><div style="padding:5px; margin:5px;" class=panel>$matches[1] {comment}<hr>{addurl} {mailurl}</div></td>
</tr>';
}
// end editing
require_once("$cutepath/data/config.php");
require_once("$cutepath/inc/functions.inc.php");
$comm_num = $config_comments_per_page;
if($archive == "" or !$archive){
$news_file = "$cutepath/data/news.txt";
$comm_file = "$cutepath/data/comments.txt";
}elseif(is_numeric($archive)){
$news_file = "$cutepath/data/archives/$archive.news.arch";
$comm_file = "$cutepath/data/archives/$archive.comments.arch";
}else{
die("Archive varialbe is invalid");
}
$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("$comm_file");
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 = $ctemplate;
if ($comment['name']){
$i++;
$title = get_title($comment['newsid'], $news_file); //make sure path is passed to prevent open errors
$output = str_replace("{editurl}", "Edit", $output);
$output = str_replace("{addurl}", "Add reply", $output);
$output = str_replace("{ipurl}", "[url=]{ip}[/url]", $output);
$output = str_replace("{ipbanurl}", "[url=]Block ip[/url]", $output);
$output = str_replace("{delete}", "$matches[1]", $output);
$output = str_replace("{banuser}", "[url=]Ban user[/url]", $output);
if( $comment['mail'] != "none"){$output = str_replace("{mailurl}", "+ [url=]send e-mail[/url]", $output);}
else {$output = str_replace("{mailurl}", "", $output);}
$tnum = countComments($comment['newsid'], $archive);
if($comm_num == 0){
$tnum = 0;
}
else{
$tnum = ($tnum / $comm_num);
}
$tnum = ereg_replace("\.(.*)","",$tnum);
$tnum = ($tnum * $comm_num);
$output = str_replace("{start}", $tnum, $output);
$output = str_replace("{name}", $comment['name'], $output);
$output = str_replace("{title}", $title, $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);
if($flag == 1){ $output = str_replace("{bg}", "#F7F6F4", $output); $flag = 0; }
else { $output = str_replace("{bg}", "#ffffff", $output); $flag = 1; }
echo $output . "\n";
}
}
echo '</table>';
/////////////////// cutenews copyrigths
echofooter();
}
/////////////////////////////////////////////////////
// Delete Comment
////////////////////////////////////////////////////
elseif($action == "doeditcomment")
{
if($member_db[1] > 2 ){ msg("error", "Access Denied", "You don't have permission for this section"); }
$news_file = "./data/news.txt";
$com_file = "./data/comments.txt";
$old_com = file("$com_file");
$new_com = fopen("$com_file","w");
foreach($old_com as $line)
{
$line_arr = explode("|>|",$line);
if($line_arr[0] == $newsid)
{
fwrite($new_com,"$line_arr[0]|>|");
$comments = explode("||", $line_arr[1]);
foreach($comments as $single_comment)
{
$single_comment = trim($single_comment);
$comment_arr = explode("|", $single_comment);
if($comment_arr[0] == $comid and $comment_arr[0] != "" and $delcomid != "all")
{
fwrite($new_com,"$comment_arr[0]|$poster|$mail|$comment_arr[3]|$comment||");
}
elseif($delcomid[$comment_arr[0]] != 1 and $comment_arr[0] != "" and $delcomid[all] != 1){
fwrite($new_com,"$single_comment||");
}
}
fwrite($new_com,"\n");
}
else{ fwrite($new_com, "$line"); }
}
if(isset($deletecomment) and $delcomid[all] == 1){ msg("info", "Comments Deleted", "All comments were deleted.", "$PHP_SELF?mod=moderator&action=moderator"); }
elseif(isset($deletecomment) and isset($delcomid)){ msg("info", "Comment Deleted", "The selected comment(s) has been deleted.", "$PHP_SELF?mod=moderator&action=moderator"); }
else{ echo"
<center>$matches[1]<br/><input type=button value=Close onClick=\"window.close();\" accesskey=\"c\">";
}else
{
fwrite($new_com, $old_comments_line);
}
}
if(!$found){/* // do not add comment if News ID is not found \\ fwrite($new_comments, "$id|>|$time|$name|$mail|$ip|$comments||\n");*/ }
@flock ($new_com,3);
fclose($new_com);
}
/////////////////////////////////////////////////
//////// functions /////////////////////////
function get_title($id, $mPath){
$all_news = file("$mPath");
foreach ($all_news as $news) {
$news_arr = explode("|", $news);
if ($news_arr[0] == "$id") {
$title = $news_arr[2];
break;
}
}
$title = ereg_replace("<[^>]*>","",$title); // incase there is html tags
$title = str_stop($title, 40); // keep the title length under 40 chars, edit to taste
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;
}
}
?></div>
