1 (edited by 2011-01-01 17:35:06)

Topic: [HACK] Comments Manager Module

Name: Comments Manager Module
Author: superhero
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: 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)


Requirements: PHP4.
Instructions:
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 inc 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 $entries_showed comments from total $count_comments


<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;">{name}
{ipurl}<br/>{date}</div></td>
        <td ><div style="padding:5px; margin:5px;" class=panel>({title}): {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/>{name}
{ipurl}<br/>{date}</td>
        <td width="505"><br/><div style="padding:5px; margin:5px;" class=panel>({title}): {comment}<hr>{editurl} + {ipbanurl} + {delete} + {addurl} {mailurl}</div></td>
        </tr>';
    }

else{
        $ctemplate = '<tr valign="top" >
        <td width="100" bgcolor={bg}><br/>{name}
{ipurl}<br/>{date}</td>
        <td width="505"><br/><div style="padding:5px; margin:5px;" class=panel>({title}): {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}", "[url=]Delete[/url]", $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>Comment is saved."; }
}

//////////////////////////////////////////
// Add Replay form
//////////////////////////////////////////

if($action == "editcomment")
{
    echo"<html>
    <head>
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\">
    <title>Add comment</title>
    <style type=\"text/css\">
    <!--
       SELECT, option, textarea, input {
       BORDER-RIGHT: #808080 1px dotted;
       BORDER-TOP: #808080 1px dotted;
       BORDER-BOTTOM: #808080 1px dotted;
       BORDER-LEFT: #808080 1px dotted;
       COLOR: #000000;
       FONT-SIZE: 11px;
       FONT-FAMILY: Verdana; BACKGROUND-COLOR: #ffffff }
       TD {text-decoration: none; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;}
       BODY {text-decoration: none; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 3pt;}
       .header { font-size : 16px; font-weight: bold; color: #808080; font-family: verdana; text-decoration: none; }
    -->
    </style>
    </head>
    <body bgcolor=\"#FFFFFF\">
    <form method=post action=\"$PHP_SELF\">
    <table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">
    <td width=\"1108\" height=\"8%\" colspan=\"2\">
    <div class=header>ADD Comment</div>
    <tr>
    <td height=20 valign=middle width=\"102\" bgcolor=\"#F9F8F7\">
    Poster
    <td height=20 valign=middle width=\"1002\" bgcolor=\"#F9F8F7\">
    <input type=hidden name=\"poster\" value=\"$member_db[2]\">$member_db[2]
    </tr>
    <tr>
    <td height=20 valign=middle  width=\"102\" bgcolor=\"#F9F8F7\">
    Comment 
    <td  height=20 valign=middle width=\"1002\" bgcolor=\"#F9F8F7\">
    <textarea rows=\"8\" name=\"comment\" cols=\"45\"></textarea>
    </tr>
    <tr>
    <td  valign=\"top\" width=\"1104\" colspan=\"2\">
    <p align=\"left\">

    <input type=submit value=\"Add Comment\" accesskey=\"s\"> 
    <input type=button value=Cencel onClick=\"window.close();\" accesskey=\"c\">
    <input type=hidden name=mod value=moderator>
    <input type=hidden name=newsid value=$newsid>
    <input type=hidden name=action value=addcomment>
    </tr>
    </table>
    </form>
    </body>
    </html>";
   
}

/////////////////////////////////////////////////       
///////////////////////////////// Save Reply
/////////////////////////////////////////////////

   elseif($action == "addcomment")
   {
   
       $com_file = "./data/comments.txt";
       $comment = str_replace("\r\n","
",$comment);
    $comment = str_replace("|","I",$comment);
   
    $time = time()+($config_date_adjust*60);
   
    if($comment == "" ){ die("comment can not be blank [url=]+ Back[/url]</div>"); }
   
    ////////////////////////// Get IP
        if (getenv("HTTP_CLIENT_IP")) {$ip = getenv("HTTP_CLIENT_IP");}
        elseif(getenv("HTTP_X_FORWARDED_FOR")) {$ip = getenv("HTTP_X_FORWARDED_FOR");}
        elseif(getenv("REMOTE_ADDR")){ $ip = getenv("REMOTE_ADDR");}
        else {$ip = "not detected";}
    ////////////////////////////////
   
    $old_com = file("$com_file");
    $new_com = fopen("$com_file","w");
    @flock ($new_com,2);
    $found = FALSE;
    foreach($old_com as $old_comments_line)
    {
                $old_comments_arr = explode("|>|", $old_comments_line);
                if($old_comments_arr[0] == $newsid)
                {
                        $old_comments_arr[1] = trim($old_comments_arr[1]);
                        fwrite($new_com, "$old_comments_arr[0]|>|$old_comments_arr[1]$time;|$poster|none|$ip|$comment||\n");
                        $found = TRUE;
                        echo"



<center><b>Comment is saved.<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>

2 (edited by 2011-02-06 11:41:12)

Re: [HACK] Comments Manager Module

Name: Comments Manager Module
Author: superhero
Updated by: Dook
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: Add's 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)


Requirements: PHP5
Instructions:
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 upload it to your inc 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
// Updated By Dook
// 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 $entries_showed comments from total $count_comments


<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;">{name}
{ipurl}<br/>{date}</div></td>
<td ><div style="padding:5px; margin:5px;" class=panel>({title}): {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/>{name}
{ipurl}<br/>{date}</td>
<td width="505"><br/><div style="padding:5px; margin:5px;" class=panel>({title}): {comment}<hr>{editurl} + {ipbanurl} + {delete} + {addurl} {mailurl}</div></td>
</tr>';
}

else{
$ctemplate = '<tr valign="top" >
<td width="100" bgcolor={bg}><br/>{name}
{ipurl}<br/>{date}</td>
<td width="505"><br/><div style="padding:5px; margin:5px;" class=panel>({title}): {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;

$insertpoint = 0;
$comment_arr = explode("|", $comment_line);

foreach($latest_comments as $key=>$latest_comment)
{
if($comment_arr[0] > $latest_comment['comid'] )
{
$insertpoint = $key;
break;
}
}

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

$latest_comments[$insertpoint] = 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}", "[url=]Edit[/url]", $output);
$output = str_replace("{addurl}", "[url=]Add reply[/url]", $output);
$output = str_replace("{ipurl}", "[url=]{ip}[/url]", $output);
$output = str_replace("{ipbanurl}", "[url=]Block ip[/url]", $output);
$output = str_replace("{delete}", "[url=]Delete[/url]", $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 = preg_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>Comment is saved."; }
}

//////////////////////////////////////////
// Add Replay form
//////////////////////////////////////////

if($action == "editcomment")
{
echo"<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\">
<title>Add comment</title>
<style type=\"text/css\">
<!--
SELECT, option, textarea, input {
BORDER-RIGHT: #808080 1px dotted;
BORDER-TOP: #808080 1px dotted;
BORDER-BOTTOM: #808080 1px dotted;
BORDER-LEFT: #808080 1px dotted;
COLOR: #000000;
FONT-SIZE: 11px;
FONT-FAMILY: Verdana; BACKGROUND-COLOR: #ffffff }
TD {text-decoration: none; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;}
BODY {text-decoration: none; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 3pt;}
.header { font-size : 16px; font-weight: bold; color: #808080; font-family: verdana; text-decoration: none; }
-->
</style>
</head>
<body bgcolor=\"#FFFFFF\">
<form method=post action=\"$PHP_SELF\">
<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">
<td width=\"1108\" height=\"8%\" colspan=\"2\">
<div class=header>ADD Comment</div>
<tr>
<td height=20 valign=middle width=\"102\" bgcolor=\"#F9F8F7\">
Poster
<td height=20 valign=middle width=\"1002\" bgcolor=\"#F9F8F7\">
<input type=hidden name=\"poster\" value=\"$member_db[2]\">$member_db[2]
</tr>
<tr>
<td height=20 valign=middle width=\"102\" bgcolor=\"#F9F8F7\">
Comment 
<td height=20 valign=middle width=\"1002\" bgcolor=\"#F9F8F7\">
<textarea rows=\"8\" name=\"comment\" cols=\"45\"></textarea>
</tr>
<tr>
<td valign=\"top\" width=\"1104\" colspan=\"2\">
<p align=\"left\">

<input type=submit value=\"Add Comment\" accesskey=\"s\"> 
<input type=button value=Cencel onClick=\"window.close();\" accesskey=\"c\">
<input type=hidden name=mod value=moderator>
<input type=hidden name=newsid value=$newsid>
<input type=hidden name=action value=addcomment>
</tr>
</table>
</form>
</body>
</html>";

}

/////////////////////////////////////////////////
///////////////////////////////// Save Reply
/////////////////////////////////////////////////

elseif($action == "addcomment")
{

$com_file = "./data/comments.txt";
$comment = str_replace("\r\n","
",$comment);
$comment = str_replace("|","I",$comment);

$time = time()+($config_date_adjust*60);

if($comment == "" ){ die("comment can not be blank [url=]+ Back[/url]</div>"); }

////////////////////////// Get IP
if (getenv("HTTP_CLIENT_IP")) {$ip = getenv("HTTP_CLIENT_IP");}
elseif(getenv("HTTP_X_FORWARDED_FOR")) {$ip = getenv("HTTP_X_FORWARDED_FOR");}
elseif(getenv("REMOTE_ADDR")){ $ip = getenv("REMOTE_ADDR");}
else {$ip = "not detected";}
////////////////////////////////

$old_com = file("$com_file");
$new_com = fopen("$com_file","w");
@flock ($new_com,2);
$found = FALSE;
foreach($old_com as $old_comments_line)
{
$old_comments_arr = explode("|>|", $old_comments_line);
if($old_comments_arr[0] == $newsid)
{
$old_comments_arr[1] = trim($old_comments_arr[1]);
fwrite($new_com, "$old_comments_arr[0]|>|$old_comments_arr[1]$time;|$poster|none|$ip|$comment||\n");
$found = TRUE;
echo"



<center><b>Comment is saved.<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 = preg_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>