Looking for a script

Anything and Everything. Chat about stuff not related to PopTray.

Moderators: KY Dave, jojobear99, Rdsok

Post Reply
User avatar
homaquebec
PopTray Family
Posts: 913
Joined: Tue May 27, 2003 6:47 pm
Location: Québec (Canada)

Looking for a script

Post by homaquebec » Mon Mar 24, 2008 5:21 pm

I am looking for a script that will generate a form that visitors of my blog will use to send me comments without passing by their email client.

I presently have one but when a comment is sent, a window opens with a confirmation message, in english. In addition, an ad page displays.

I would like one that does not present a confirmation message or, if it does, it would be possible to customize it. In addition, I do not want an ad page being displayed.

Any suggestion?

My blog is here. You can also look at the english version generated by automatic translation.

User avatar
KY Dave
Not the Developer
Posts: 1599
Joined: Thu Mar 14, 2002 7:29 pm
Location: Burkesville, KY. U.S.A.
Contact:

Post by KY Dave » Mon Mar 24, 2008 7:49 pm

Your server will need to let php scripts run.

The code below should copied and pasted into NOTEPAD or WORDPAD. Then search for 'homaquebec' and replace those areas with the correct code, then it should be saved as "comment.php" and added to your website in the same directory as your blog.

Code: Select all

<?php
// Settings:

// File in which the entries will be saved (requires CHMOD 666):
$comment_settings['comment_file'] = "comments.dat";

// Admin E-mail for notifications (optional):
$comment_settings['admin_email'] = "homaquebec@poptray.org";

// Add new comments at the top or at the bottom?
$comment_settings['add_comments'] = "bottom";

// How many comments per page?
$comment_settings['comments_per_page'] = 10;

// Make links clickable:
$comment_settings['auto_link'] = true;

// Length limitations:
$comment_settings['text_maxlength'] = 500;
$comment_settings['word_maxlength'] = 50;

// If no name is entered:
$comment_settings['anonym'] = "Anonymous";

// Time format:
$comment_settings['time_format'] = "%m-%d-%Y, %H:%M";

// Anker, where the comments are on your pages:
$comment_settings['anker'] = "/comments";

// replace wordwrap? (if no "<br />"):
$comment_settings['wordwrap'] = " - ";

// Language settings:
$comment_lang['language'] =           "en";
$comment_lang['title'] =              "Please Leave Your Comments";
$comment_lang['email_title'] =        "E-mail to homaquebec";
$comment_lang['hp_title'] =           "Homepage: Homaquebec Blog";
$comment_lang['no_comments_yet'] =    "No comments yet.";
$comment_lang['comments_shown'] =     "[comments] of [comments_total] comments (part [part])";
$comment_lang['previous'] =           "Previous part";
$comment_lang['next'] =               "Next part";
$comment_lang['show_all'] =           "Show all comments";
$comment_lang['add_comment'] =        "Your comment:";
$comment_lang['name'] =               "Name:";
$comment_lang['email_hp'] =           "E-mail or homepage (voluntary):";
$comment_lang['ok'] =                 "OK";
$comment_lang['no_comments'] =        "Leave a comment";
$comment_lang['one_comment'] =        "1 comment";
$comment_lang['several_comments'] =   "[comments] comments";
$comment_lang['comment_link_title'] = "Read or write comments";
$comment_lang['email_subject'] =      "Comment to [comment_to]";
$comment_lang['email_text'] =         "Comment to [comment_to] by [name]:\n\n[comment]\n\n\nLink to the comment:\n[link]";
$comment_lang['error'] =              "Error:";
$comment_lang['err_text_too_long'] =  "the text is too long ([characters] characters - maximum is [characters_max] characters)";
$comment_lang['err_word_too_long'] =  "the word [word] is too long";

// End of settings

function comment_make_link($string)
 {
  $string = ' ' . $string;
  $string = preg_replace("#(^|[\n ])([\w]+?://.*?[^ \"\n\r\t<]*)#is", "\\1<a href=\"\\2\">\\2</a>", $string);
  $string = preg_replace("#(^|[\n ])((www|ftp)\.[\w\-]+\.[\w\-.\~]+(?:/[^ \"\t\n\r<]*)?)#is", "\\1<a href=\"http://\\2\">\\2</a>", $string);
  $string = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $string);
  $string = substr($string, 1);
  return $string;
 }

function count_comments($comment_id, $text=0)
 {
  global $comment_settings, $comment_lang;
  $data = file($comment_settings['comment_file']);
  $comment_total_entries = count($data);
  // count entries:
  $comment_count = 0;
  for ($i = 0; $i < $comment_total_entries; $i++)
  {
   $parts = explode("|", $data[$i]);
   if ($parts[3] == $comment_id) $comment_count++;
  }
  if ($text == 0) return $comment_count;
  else
   {
    if ($comment_count == 0) $count_text = $comment_lang['no_comments'];
    elseif ($comment_count == 1) $count_text = $comment_lang['one_comment'];
    else $count_text = str_replace("[comments]", $comment_count, $comment_lang['several_comments']);
    return $count_text;
   }
 }

if (isset($_GET['comment_id'])) $comment_id = $_GET['comment_id'];
if (isset($_POST['comment_id'])) $comment_id = $_POST['comment_id'];
if (isset($_GET['comment_popup'])) $comment_popup = $_GET['comment_popup'];
if (isset($_POST['comment_popup'])) $comment_popup = $_POST['comment_popup'];

if (empty($comment_popup) && empty($comment_id) && empty($_GET['comment_popup_link'])) $comment_id = basename($_SERVER["PHP_SELF"]);

if (isset($comment_id))
 {
  if (isset($_GET['comment_page'])) $comment_page = $_GET['comment_page']; else $comment_page = 1;

// if comment entered::
if (isset($_POST['comment_text']) && trim($_POST['comment_text']) != "")
  {
   // check posted data:
   unset($errors);
   if (strlen($_POST['comment_text']) > $comment_settings['text_maxlength']) { $err_txt_too_lng = str_replace("[characters]", strlen($_POST['comment_text']), $comment_lang['err_text_too_long']); $err_txt_too_lng = str_replace("[characters_max]", $comment_settings['text_maxlength'], $err_txt_too_lng); $errors[] = $err_txt_too_lng; }
   $text_arr = str_replace("\n", " ", $_POST['comment_text']);
   $text_arr = explode(" ",$text_arr); for ($i=0;$i<count($text_arr);$i++) { trim($text_arr[$i]); $laenge = strlen($text_arr[$i]); if ($laenge > $comment_settings['word_maxlength']) { $errors[] = str_replace("[word]", "\"".htmlentities(stripslashes(substr($text_arr[$i],0,$comment_settings['word_maxlength'])))."...\"", $comment_lang['err_word_too_long']); } }

   // look if double:
   $data = file($comment_settings['comment_file']);
   $row_count = count($data);
   for ($row = 0; $row < $row_count; $row++)
     {
      $parts = explode("|", $data[$row]);
      if ($parts[3] == $_POST['comment_id'] && urldecode($parts[4]) == trim($_POST['name']) && trim(urldecode($parts[6])) == trim($_POST['comment_text'])) { $double_entry = true; break; }
     }

   // save if no errors:
   if (empty($errors) && empty($double_entry))
    {
      $comment_text = urlencode(trim($_POST['comment_text']));
      $name = urlencode(trim($_POST['name']));
      $email_hp = trim($_POST['email_hp']);
      if (substr($email_hp,0,7) == "http://") $email_hp = substr($email_hp,7);
      $email_hp = urlencode(base64_encode($email_hp));

      $uniqid = uniqid("");
      if ($comment_settings['add_comments'] == "top")
      {
       $data = file($comment_settings['comment_file']);
       $c = count($data);
       $datei = fopen($comment_settings['comment_file'], 'w+');
       flock($datei, 2);
       fwrite($datei, $uniqid."|".time()."|".$_SERVER["REMOTE_ADDR"]."|".$_POST['comment_id']."|".$name."|".$email_hp."|".$comment_text."\n");
       for ($i = 0; $i < $c; $i++) { fwrite($datei, trim($data[$i])."\n"); }
       flock($datei, 3);
       fclose($datei);
      }
      else
      {
       $datei = fopen($comment_settings['comment_file'], "a");
       flock($datei, 2);
       fwrite($datei, $uniqid."|".time()."|".$_SERVER["REMOTE_ADDR"]."|".$_POST['comment_id']."|".$name."|".$email_hp."|".$comment_text."\n");
       flock($datei, 3);
       fclose($datei);
      }

     // E-mail notification to admin:
     if (isset($comment_settings['admin_email']) && $comment_settings['admin_email'] !="")
      {
       if (isset($comment_popup)) { $acid1="?comment_id=".$comment_id."&ampcomment_popup=true"; $acid2="&comment_id=".$comment_id."&comment_popup=true"; } else { $acid1 = ""; $acid2 = ""; }
       $sender_name = trim($_POST['name']);
       if ($sender_name=="") $sender_name = $comment_settings['anonym'];
       if (preg_match("/^[^@]+@.+\.\D{2,5}$/", base64_decode(urldecode($email_hp)))) $sender_email = base64_decode(urldecode($email_hp)); else $sender_email = "no@email.xx";
       $comment_subject = str_replace("[comment_to]", $_POST['comment_id'], $comment_lang['email_subject']);
       $comment_email_text = str_replace("[comment_to]",$_POST['comment_id'],$comment_lang['email_text']);
       $comment_email_text = str_replace("[name]",stripslashes($sender_name),$comment_email_text);
       $comment_email_text = str_replace("[comment]",stripslashes($_POST['comment_text']),$comment_email_text);
       $emailbody = str_replace("[link]","http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'].$acid1.$comment_settings['anker'],$comment_email_text);
       $header= "From: ".stripslashes($sender_name)." <".stripslashes($sender_email).">\n";
       $header .= "X-Mailer: PHP/" . phpversion(). "\n";
       $header .= "X-Sender-IP: ".$_SERVER["REMOTE_ADDR"]."\n";
       $header .= "Content-Type: text/plain";
       @mail($comment_settings['admin_email'], $comment_subject, $emailbody, $header);
      }
     }
   }

  // count:
  $data = file($comment_settings['comment_file']);
  $comment_total_entries = count($data);
  $comment_count = count_comments($comment_id);

  // Header for popup window:
  if (isset($comment_popup))
   {
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $comment_lang['language']; ?>"><head><title><?php echo $comment_lang['title']; ?></title><meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /><style type="text/css"><!-- body { color: #000000; background: #ffffff; margin: 15px; padding: 0px; font-family: verdana, arial, sans-serif; font-size: 13px; } p { font-family: verdana, arial, sans-serif; font-size: 13px; line-height: 19px; } h1 { font-family: verdana, arial, sans-serif; font-size: 18px; font-weight: bold; } --></style></head><body><h1><?php echo $comment_lang['title']; ?></h1><?php
   }

  // show comments:
  if (isset($_GET['show_comments'])) $show_comments = $_GET['show_comments'];
  if (isset($_POST['show_comments'])) $show_comments = $_POST['show_comments'];
  if (isset($show_comments) && isset($hide_comments)) unset($hide_comments);
  if (empty($hide_comments))
  {
  $comment_k = 0;
  $comment_a = 0;
  for ($i = 0; $i < $comment_total_entries; $i++)
    {
     $parts = explode("|", $data[$i]);
     if ($parts[3] == $comment_id)
      {
       $comment_k++;
       if ($parts[4] != "") $name = htmlentities(stripslashes(urldecode($parts[4]))); else $name = $comment_settings['anonym'];
       if ($parts[5] != "")
        {
         $email_hp = htmlentities(stripslashes(base64_decode(urldecode($parts[5]))));
         if (preg_match("/^[^@]+@.+\.\D{2,5}$/", $email_hp))
             {
              $email_parts = explode("@", $email_hp);
              $email_name = $email_parts[0];
              $email_domain_tld = $email_parts[1];
              $domain_parts = explode(".", $email_domain_tld);
              $email_domain = "";
              for ($x = 0; $x < count($domain_parts)-1; $x++)
               {
                $email_domain .= $domain_parts[$x].".";
               }
              $email_tld = $domain_parts[$x];
              $email_title = str_replace("[name]",$name,$comment_lang['email_title']);
              $name = "<script type=\"text/javascript\">
              <!--
              document.write('<a href=\"mailto:');
              document.write('".$email_name."');
              document.write('@');
              document.write('".$email_domain."');
              document.write('".$email_tld."');
              document.write('\" title=\"".$email_title."\">');
              //-->
              </script>".$name."<script type=\"text/javascript\">
              <!--
              document.write('</a>');
              //-->
              </script>";
             }
          else
          {
           $hp_title = str_replace("[homepage]",$email_hp,$comment_lang['hp_title']);
           if (isset($comment_popup)) $name = '<a href="http://'.$email_hp.'" title="'.$hp_title.'" target="_blank">'.$name.'</a>';
           else $name = '<a href="http://'.$email_hp.'" title="'.$hp_title.'">'.$name.'</a>';
          }
        }
       $comment = htmlentities(stripslashes(urldecode($parts[6])));
       if (isset($comment_settings['wordwrap']) && $comment_settings['wordwrap'] != "") $comment = str_replace("\n", $comment_settings['wordwrap'], trim($comment));
       if (isset($comment_settings['auto_link']) && $comment_settings['auto_link']==true) $comment = comment_make_link($comment);
       $zeit = $parts[1];

       if ($comment_settings['add_comments'] == "top")
        {
         if ($comment_page=="show_all" || ($comment_k>($comment_page-1)*$comment_settings['comments_per_page'] && $comment_k<$comment_page*$comment_settings['comments_per_page']+1)) { ?><p style="margin:0px 0px 5px 0px;"><b><?php echo $name; ?>:</b>&nbsp;<?php echo $comment; ?><br /><span style="font-size: 10px; color: #808080;">(<?php echo strftime($comment_settings['time_format'], $parts[1]); ?>)</span></p><?php $comment_a++; }
        }
       else
        {
         if ($comment_page=="show_all" || ($comment_k > ( ($comment_count-$comment_settings['comments_per_page']) - ( ($comment_page-1) * $comment_settings['comments_per_page'] ) ) && $comment_k < (($comment_count-$comment_settings['comments_per_page'])-(($comment_page-1)*$comment_settings['comments_per_page']))+($comment_settings['comments_per_page']+1))) { ?><p style="margin:0px 0px 5px 0px;"><b><?php echo $name; ?>:</b>&nbsp;<?php echo $comment; ?><br /><span style="font-size: 10px; color: #808080;">(<?php echo strftime($comment_settings['time_format'], $parts[1]); ?>)</span></p><?php $comment_a++; }
        }
      }
    }

 $comments_shown = str_replace("[comments]", $comment_a, $comment_lang['comments_shown']);
 $comments_shown = str_replace("[comments_total]", $comment_count, $comments_shown);
 $comments_shown = str_replace("[part]", $comment_page, $comments_shown);
 if ($comment_k == 0) echo "<p><i>".$comment_lang['no_comments_yet']."</i></p>";
 if ($comment_settings['comments_per_page'] < $comment_count && $comment_page != "show_all") { ?><p style="margin:10px 0px 3px 0px; font-family: verdana, arial, sans-serif; font-size: 11px;"><?php echo $comments_shown; ?>&nbsp;<?php
 if ($comment_settings['comments_per_page'] < $comment_count && $comment_page > 1) { ?>[ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?comment_id=<?php echo $comment_id; ?>&comment_page=<?php echo $comment_page-1; if (isset($comment_popup)) echo "&comment_popup=true"; if (isset($show_comments)) echo "&show_comments=true"; echo $comment_settings['anker']; ?>" title="<?php echo $comment_lang['previous']; ?>">&laquo;</a> ] <?php }
 if ($comment_settings['comments_per_page'] < $comment_count && $comment_page < (($comment_count/$comment_settings['comments_per_page']))) { ?>[ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?comment_id=<?php echo $comment_id; ?>&comment_page=<?php echo $comment_page+1; if (isset($comment_popup)) echo "&comment_popup=true"; if (isset($show_comments)) echo "&show_comments=true"; echo $comment_settings['anker']; ?>" title="<?php echo $comment_lang['next']; ?>">&raquo;</a> ] <?php }
 ?>
 [ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?comment_id=<?php echo $comment_id; ?>&comment_page=show_all<?php if (isset($comment_popup)) echo "&comment_popup=true"; if (isset($show_comments)) echo "&show_comments=true"; echo $comment_settings['anker']; ?>" title="<?php echo $comment_lang['show_all']; ?>">*</a> ]</p><?php }
 if(isset($errors))
  {
   ?><p style="color:red; font-weight:bold;"><?php echo $comment_lang['error']; ?></p><ul><?php foreach($errors as $f) { ?><li><?php echo $f; ?></li><?php } ?></ul><?php
  }
 ?>
 <form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>"><div>
 <?php if (isset($comment_popup)) { ?><input type="hidden" name="comment_popup" value="true" /><?php } ?>
 <input type="hidden" name="comment_id" value="<?php echo $comment_id; ?>" />
 <input type="hidden" name="show_comments" value="true" />
 <table style="margin-top: 10px;" border="0" cellpadding="1" cellspacing="0">
  <tr>
   <td colspan="3">
   <b><?php echo $comment_lang['add_comment']; ?></b><br />
   <textarea style="width: 400px;" name="comment_text" cols="45" rows="4"><?php if (isset($errors) && isset($_POST['comment_text'])) echo htmlentities(stripslashes($_POST['comment_text'])); ?></textarea><br />
   </td>
  </tr>
  <tr>
   <td style="font-family: verdana, arial, sans-serif; font-size: 11px; vertical-align: bottom;"><?php echo $comment_lang['name']; ?><br /><input type="text" name="name" value="<?php if (isset($errors) && isset($_POST['name'])) echo htmlentities(stripslashes($_POST['name'])); else echo ""; ?>" size="23" maxlength="25" /></td>
   <td style="font-family: verdana, arial, sans-serif; font-size: 11px; vertical-align: bottom;"><?php echo $comment_lang['email_hp']; ?><br/><input type="text" name="email_hp" value="<?php if (isset($errors) && isset($_POST['email_hp'])) echo htmlentities(stripslashes($_POST['email_hp'])); else echo ""; ?>" size="23" maxlength="60" /></td>
   <td style="font-family: verdana, arial, sans-serif; font-size: 11px; vertical-align: bottom;"><input type="submit" value="  <?php echo $comment_lang['ok']; ?>  " /></td>
  </tr>
 </table>
 </div></form>
 <?php // If you want to remove the Link please donate some Euros: http://www.mylittlehomepage.net/donation.html ?>
 <p style="font-size: 11px;">Script by <a href="http://www.mylittlehomepage.net/comment_script.html"<?php if (isset($comment_popup)) echo " target=\"_blank\""; ?>>Alex</a></p>
 <?php
 }
 else
 {

  ?><p>[ <a href="<?php echo basename($_SERVER['PHP_SELF']); ?>?show_comments=true<?php echo $comment_settings['anker']; ?>" title="<?php echo $comment_lang['comment_link_title']; ?>"><?php echo count_comments($comment_id, 1); ?></a> ]</p>
  <?php
 }
 // Footer for popup window:
 if (isset($comment_popup))
  {
   ?></body></html><?php
  }
}
// JavaScript for popup window and link:
if (isset($_GET['comment_popup_link']))
 {
 ?>function comment(id)
 {
 var page = "<?php echo $_SERVER['PHP_SELF']; ?>?comment_id=" + id + "&comment_popup=true";
 popwin = window.open(page,"","width=460,height=500,scrollbars,resizable")
 popwin.focus();
 }
 document.open();
 document.write("[ <a href=\"javascript:comment('<?php echo $_GET['comment_popup_link']; ?>')\" title=\"<?php echo $comment_lang['comment_link_title']; ?>\"><?php echo count_comments($_GET['comment_popup_link'], 1); ?></a> ]");
 document.close();
 <?php
 }
?>
The code below should copied and pasted into NOTEPAD or WORDPAD. Then search for 'homaquebec' and replace that areas with your password, then it should be saved as "comment-admin.php" and added to your website in the same directory as your blog.

Code: Select all

<?php
// Settings:

// Admin password:
$pw = "homaquebec";

// Comment file:
$comment_file = "comments.dat";

// End of settings

$comment_comments_per_page = 10;
$comment_time_format = "%d.%m.%Y, %H:%M Uhr";
$comment_anonym = "Anonym";
if (isset($_GET['comment_page'])) $comment_page = $_GET['comment_page']; else $comment_page = 1;
if (isset($_POST['category'])) $category = $_POST['category'];
if (isset($_GET['category'])) $category = $_GET['category'];

session_start();
// Login:
if (!isset($_SESSION['admin']) && isset($_POST['login']))
 {
  if ($_POST['ppw'] == $pw)
   {
    $_SESSION['admin'] = true;
    header("location: ".basename($_SERVER['PHP_SELF']));
   }
  else die("Password wrong!");
 }

 if (isset($_GET['logout']))
 {
  session_destroy();
  header("location: ".basename($_SERVER['PHP_SELF']));
 }

// Löschen:
if (isset($_POST['delete_id']) && isset($_SESSION["admin"]))
 {
  $data = file($comment_file);
  $row_count = count($data);
  $fp = fopen($comment_file, 'w+');
  flock($fp, 2);
  for ($row = 0; $row < $row_count; $row++)
   {
    $parts = explode("|", $data[$row]);
    if (!in_array($parts[0], $_POST['delete_id'])) { fwrite($fp, trim($data[$row])."\n"); }
   }
  flock($fp, 3);
  fclose($fp);
   header("location: ".basename($_SERVER["PHP_SELF"])."?category=".$_POST['category']."&comment_page=".$_POST['comment_page']);
 }

// Editieren:
if (isset($_POST['edit_id']) && isset($_SESSION["admin"]))
 {
  $data = file($comment_file);
  $row_count = count($data);
  $fp = fopen($comment_file, "w+");
  flock($fp, 2);
  for ($row = 0; $row < $row_count; $row++)
   {
    $parts = explode("|", $data[$row]);
    if ($parts[0] == $_POST['edit_id']) { fwrite($fp, $parts[0]."|".$parts[1]."|".$parts[2]."|".$parts[3]."|".urlencode($_POST['name'])."|".$email_hp = urlencode(base64_encode($_POST['email_hp']))."|".urlencode($_POST['comment_text'])."\n"); }
    else { fwrite($fp, trim($data[$row])."\n"); }
   }
  flock($fp, 3);
  fclose($fp);
  header("location: ".basename($_SERVER["PHP_SELF"])."?category=".$_POST['category']."&comment_page=".$_POST['comment_page']);
 }


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>my little commet script - admin area</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
body             { color: #000000; background: #ffffff; margin: 20px; padding: 0px; font-family: verdana, arial, sans-serif; font-size: 13px;}
p                { font-family: verdana, arial, sans-serif; font-size: 13px; }
h1               { font-family: verdana, arial, sans-serif; font-size: 18px; font-weight: bold; }
h2               { margin-top: 30px; font-family: verdana, arial, sans-serif; font-size: 18px; font-weight: bold; }
.comments-th     { padding: 5px; border: 1px solid #aaa; font-weight: bold; vertical-align: top; text-align: left; }
.comments-td     { padding: 5px; border: 1px solid #aaa; vertical-align: top; text-align: left; }
.submit-td       { padding: 5px; vertical-align: top; }
-->
</style>
<script language="javascript">
<!--
 function checkall()
 {
  if(document.commentform.check_all)
   {
    var c = document.commentform.check_all.checked;
   }
  for (var i=0;i<document.commentform.elements.length;i++)
   {
    var e = document.commentform.elements[i];
    if(e.name != 'check_all') e.checked = c;
   }
 }
//-->
</script>
</head>
<body>
<h1>my little commet script - admin area<?php if (isset($_SESSION['admin'])) { ?> <span style="font-size: 11px; font-weight: normal;">[ <a href="<?php echo basename($_SERVER['PHP_SELF']); ?>?logout">log out</a> ]</span><?php } ?>
</h1>
<?php
if (!isset($_SESSION['admin']) && empty($_POST['login']))
 {
  ?><form action="<?php echo basename($_SERVER['PHP_SELF']); ?>" method="post">
  Password:<br />
  <input type="password" name="ppw" value="" size="" maxlength="" />
  <input type="submit" name="login" value="OK">
  </form><?php
 }

elseif (isset($_SESSION['admin']) && empty($_GET['edit']))
 {
  $categories[] = "";
  $data = file($comment_file);
  $row_count = count($data);
  for ($row = 0; $row < $row_count; $row++)
   {
    $parts = explode("|", $data[$row]);
    if (!in_array($parts[3], $categories)) { $categories[] = $parts[3]; }
   }

  if ($row_count > 0)
   {
    ?><div style="height: 35px; float: left;">
    <form style="float: left;" method="post" action="<?php echo basename($_SERVER['PHP_SELF']); ?>">
    <select size="1" name="category" onchange="this.form.submit();">
    <option value="">choose:</option>
    <?php
    sort($categories);
    for ($x=1; $x<count($categories); $x++)
     {
      if (isset($category) && $categories[$x]==$category) echo ('<option value="'.$categories[$x].'" selected="selected">'.$categories[$x].'</option>');
      else echo ('<option value="'.$categories[$x].'">'. $categories[$x].'</option>');
     }
     ?></select>
     </form></div>
     <?php
     if (isset($category) && $category != "")
      {
       // Kommentar-Datei einlesen:
       $data = file($comment_file);
       $comment_total_entries = count($data);

       // zählen, wieviele Einträge es gibt:
       $comment_count = 0;
       for ($i = 0; $i < $comment_total_entries; $i++)
        {
         $parts = explode("|", $data[$i]);
         if ($parts[3] == $category) $comment_count++;
        }
       ?><div style="height: 35px;"><p style="text-align: right;">
       <?php
       if ($comment_count > 0)
        {
         if ($comment_comments_per_page < $comment_count && $comment_page != "show_all") { ?>Part <?php echo $comment_page; ?> of <?php echo $comment_count; ?> comments.&nbsp;<?php
         if ($comment_comments_per_page < $comment_count && $comment_page > 1) { ?>[ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?category=<?php echo $category; ?>&comment_page=<?php echo $comment_page-1; ?>" title="Previous part">&laquo;</a> ] <?php }
         if ($comment_comments_per_page < $comment_count && $comment_page < (($comment_count/$comment_comments_per_page))) { ?>[ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?category=<?php echo $category; ?>&comment_page=<?php echo $comment_page+1; ?>" title="next Part">&raquo;</a> ] <?php }
         ?> [ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?category=<?php echo $category; ?>&comment_page=show_all" title="show all comments">all</a> ]<?php }
         else echo "&nbsp;";
        }
       ?></p></div><?php
       if ($comment_count == 0) echo "&nbsp;";
       else
       {
        ?><form name="commentform" method="post" action="<?php echo basename($_SERVER['PHP_SELF']); ?>">
  <input type="hidden" name="category" value="<?php echo $category; ?>" />
  <input type="hidden" name="comment_page" value="<?php echo $comment_page; ?>" />
  <table style="border-collapse: collapse;" border="0" cellpadding="0" cellspacing="0">
  <tr>

  <th class="comments-th">Date</th>
  <th class="comments-th">Name</th>
  <th class="comments-th">Comment</th>
  <th class="comments-th">edit</th>
  <th class="comments-th">delete</th>
  </tr>
  <?php
  // show comments:
  $comment_k = 0;
  $comment_a = 0;
  for ($i = 0; $i < $comment_total_entries; $i++)
    {
     $parts = explode("|", $data[$i]);
     if ($parts[3] == $category)
      {
       $comment_k++;
       if ($parts[4] != "") $name = htmlentities(stripslashes(urldecode($parts[4]))); else $name = $comment_anonym;
       if ($parts[5] != "")
        {
         $email_hp = htmlentities(stripslashes(base64_decode(urldecode($parts[5]))));
         if (preg_match("/^[^@]+@.+\.\D{2,5}$/", $email_hp)) $name = '<a href="mailto:'.$email_hp.'" title="E-mail: '.$email_hp.'">'.$name.'</a>';
         else $name = '<a href="http://'.$email_hp.'" title="Homepage: '.$email_hp.'">'.$name.'</a>';
        }
       $kommentar = htmlentities(stripslashes(urldecode($parts[6])));
       #$kommentar = str_replace("\n", " - ", trim($kommentar));
       if (isset($comment_autolink) && $comment_autolink==true) $kommentar = comment_make_link($kommentar);
       $zeit = $parts[1];

       /*if ($comment_add_comments == "top")
        {
         if ($comment_page=="show_all" || ($comment_k>($comment_page-1)*$comment_comments_per_page && $comment_k<$comment_page*$comment_comments_per_page+1)) { ?><p style="margin:0px 0px 5px 0px;"><b><?php echo $name; ?>:</b>&nbsp;<?php echo $kommentar; ?><br /><span style="font-size: 10px; color: #808080;">(<?php echo strftime($comment_time_format, $parts[1]); ?>)</span><?php if (isset($_COOKIE['comment_cookie_pw']) && $_COOKIE['comment_cookie_pw'] == $comment_pw) { ?><span style="font-size: 11px;">&nbsp;&nbsp;[ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?comment_delete=<?php echo $parts[0]; if (isset($comment_popup)) echo "&comment_popup=true"; ?>">löschen</a> ]</span><?php } ?></p><?php $comment_a++; }
        }
       else
        {  */

       if ($comment_page=="show_all" || ($comment_k > ( ($comment_count-$comment_comments_per_page) - ( ($comment_page-1) * $comment_comments_per_page ) ) && $comment_k < (($comment_count-$comment_comments_per_page)-(($comment_page-1)*$comment_comments_per_page))+($comment_comments_per_page+1))) { ?><tr><td class="comments-td"><?php echo strftime($comment_time_format, $parts[1]); ?></td><td class="comments-td"><?php echo $name; ?></td><td class="comments-td"><?php echo $kommentar; ?></td><td class="comments-td"><a href="<?php echo basename($_SERVER['PHP_SELF'])."?edit=" . $parts[0] ."&category=".$category ."&comment_page=".$comment_page; ?>">edit</a></td><td class="comments-td"><input type="checkbox" name="delete_id[]" value="<?php echo $parts[0]; ?>"></td></tr><?php $comment_a++; }

      }

    }

 ?><tr><td colspan="4"></td><td class="submit-td"><input name="check_all" type="checkbox" value="check all" onclick="checkall();" /><span style="font-size: 11px;">all</span><br /><input style="font-weight: bold; color: red;" type="submit" name="delete_comments" value="delete" /></td></tr>
 </table>
 </form><?php
  }
 }
}
else echo "<i>No comments yet.</i>";
}

elseif (isset($_SESSION['admin']) && isset($_GET['edit']))
 {
  $data = file($comment_file);
  $row_count = count($data);
  for ($row = 0; $row < $row_count; $row++)
   {
    $parts = explode("|", $data[$row]);
    if ($parts[0] == $_GET['edit'])
     {
      $name = urldecode($parts[4]);
      $email_hp = base64_decode(urldecode($parts[5]));
      $comment_text = urldecode($parts[6]);
      break;
     }
   }

  ?>[ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?category=<?php echo $category; ?>&comment_page=<?php echo $comment_page; ?>">back</a> ]
  <form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>"><div>
  <input type="hidden" name="edit_id" value="<?php echo $_GET['edit']; ?>" />
  <input type="hidden" name="category" value="<?php echo $category; ?>" />
  <input type="hidden" name="comment_page" value="<?php echo $comment_page; ?>" />
  <table style="margin-top: 10px;" border="0" cellpadding="1" cellspacing="0">
  <tr>
   <td colspan="3">
   <b>Edit comment:</b><br />
   <textarea style="width: 400px;" name="comment_text" cols="45" rows="10"><?php if (isset($comment_text)) echo htmlentities(stripslashes($comment_text)); ?></textarea><br />
   </td>
  </tr>
  <tr>
   <td style="font-family: verdana, arial, sans-serif; font-size: 11px; vertical-align: bottom;">Name:<br /><input type="text" name="name" value="<?php if (isset($name)) echo htmlentities(stripslashes($name)); else echo ""; ?>" size="23" maxlength="25" /></td>
   <td style="font-family: verdana, arial, sans-serif; font-size: 11px; vertical-align: bottom;">E-mail or Homepage:<br/><input type="text" name="email_hp" value="<?php if (isset($email_hp)) echo htmlentities(stripslashes($email_hp)); else echo ""; ?>" size="23" maxlength="60" /></td>
   <td style="font-family: verdana, arial, sans-serif; font-size: 11px; vertical-align: bottom;"><input type="submit" name="edit_submitted" value="  OK  " /></td>
  </tr>
  </table>
  </div></form><?php
 }
else echo "<i>No comments.</i>";

?>
</body>
</html>
Then the code below will need a link to the script url where you have saved the "comment.php" file and it will need to be added to your blog software template so each post will contain the code...

Code: Select all

<script src="http://your url here/comment.php?comment_popup_link=686" type="text/javascript"></script>
You can see it in action on my Family Blog, which is linked in my signature.
KY Dave

Family Blog
You can STOP SPAM using PopFile and PopTray.

User avatar
homaquebec
PopTray Family
Posts: 913
Joined: Tue May 27, 2003 6:47 pm
Location: Québec (Canada)

Post by homaquebec » Mon Mar 24, 2008 8:22 pm

Thanks.

To make a test, can I copy the two php files in a directory that I will create and copy the script in a html page that I would name index.htlm and place it in the same directory?

User avatar
KY Dave
Not the Developer
Posts: 1599
Joined: Thu Mar 14, 2002 7:29 pm
Location: Burkesville, KY. U.S.A.
Contact:

Post by KY Dave » Mon Mar 24, 2008 8:51 pm

Yep, that should work for a test. Of course the two files need to be edited as mentioned in my posting.
KY Dave

Family Blog
You can STOP SPAM using PopFile and PopTray.

User avatar
homaquebec
PopTray Family
Posts: 913
Joined: Tue May 27, 2003 6:47 pm
Location: Québec (Canada)

Post by homaquebec » Mon Mar 24, 2008 9:28 pm

I does not work.

On the forum of the company that manages the server on which is my blog I asked if they allow php scripts to run.

User avatar
homaquebec
PopTray Family
Posts: 913
Joined: Tue May 27, 2003 6:47 pm
Location: Québec (Canada)

Succeeded… almost completely

Post by homaquebec » Tue Mar 25, 2008 6:59 pm

KY Dave,

I did not succeed to have your script working even if my server can run php scripts. Anyway, it was not exactly what I wanted because visitors’comments on my blog are not written immediately below the post but on a special page.

After researches I found one that is almost exactly what I want. The main script itself can be copied in a html page and modified. At the end, I just kept the script. This script works with some php files that I can also modify using wordpad. After many tests, I got the results that I wanted.

The sender can choose to receive a copy of his email.

There is only one thing that bothers me. Accents in the email are kept but if the sender uses an apostrophe, when I receive the email, there is a backslash before the apostrophe. If the sender chose to receive a copy, his text will have backlashes if there are apostrophes in the text. I know that it comes from the programming but I do not know if there is a way to solve the problem.

I will live with this script till I find a better solution.

Thanks for you help. I am a newbie in blogs and in scripts.
Last edited by homaquebec on Sat May 02, 2009 2:31 pm, edited 3 times in total.

User avatar
homaquebec
PopTray Family
Posts: 913
Joined: Tue May 27, 2003 6:47 pm
Location: Québec (Canada)

StripSlashes

Post by homaquebec » Tue Mar 25, 2008 8:33 pm

I found on the web that is possible to remove the backslashes by writing a routine in the php files.

Could somebody exactly tell be what I have to write and where I must write routine(s) in php files to remove the backslash in documents generated by using php files?

Thanks.

User avatar
Zythan
Enthusiast
Posts: 48
Joined: Mon May 09, 2005 9:02 pm
Location: France

Re: Looking for a script / StripSlashes

Post by Zythan » Sat May 02, 2009 9:59 am

Hello,

The blog would appear to be off-line at the moment.

Will it be up and running soon, so that I can look at it and suggest something.

Regards.

Zythan

User avatar
homaquebec
PopTray Family
Posts: 913
Joined: Tue May 27, 2003 6:47 pm
Location: Québec (Canada)

Re: Looking for a script / StripSlashes

Post by homaquebec » Sat May 02, 2009 2:16 pm

Zythan wrote:Hello,

The blog would appear to be off-line at the moment.

Will it be up and running soon, so that I can look at it and suggest something.

Regards.

Zythan
Hi Zythan,

If you are writing about my blog, it is online and running. And you can look at it.

Regards.

P.S. There is a welcoming page in french, you can get directly to a page of the blog, with entries, here. To make a test with a comment, you click on Envoyer un commentaire. You can make tests if you want, they will not appear on the blog.

To help you if necessary, the form to send a comment is translated in english here (automatic translation). You can use the english version to make tests.

User avatar
Zythan
Enthusiast
Posts: 48
Joined: Mon May 09, 2005 9:02 pm
Location: France

Re: Looking for a script / StripSlashes

Post by Zythan » Sat May 02, 2009 6:41 pm

Hello,

The link at the top of this post is not working for me, but the one you gave in your reply is.

I will check out a variation of the form that is used on one of the sites I manage and get back to you.

Just out of interest which version of PHP ?

Regards.

Zythan

User avatar
homaquebec
PopTray Family
Posts: 913
Joined: Tue May 27, 2003 6:47 pm
Location: Québec (Canada)

Re: Looking for a script / StripSlashes

Post by homaquebec » Sat May 02, 2009 6:55 pm

Zythan wrote: Just out of interest which version of PHP ?
Probably phpBB2 or phpBB3.

Here is the content of the config.php file. Maybe it could help you. I deleted personal information.

_______________
<?
// Script simple d'envoi de mail par Blaster
// http://www.phpbb-graph.com

// Configuration Générale

$votresite="phpBB-Graph"; // Chroniques du faubourg
$urldevotresite="http://www.x.y"; // URL de votre site
$from="contact@domaine.com"; // L'adresse courriel de l'expediteur
$votremail="x@x"; // Votre courriel où sera envoyé le courriel quand on vous contactera
$votresite="Nom de votre site"; // Nom de votre site ici (optionnel)
$urldevotresite="http://"; // L'url de votre site ici (optionnel)

// POur personnaliser les mails qui sont envoyer , $m1 est le mail envoyer a l'internaute et $m2 et le mail qui vous averti lorsqu'un mail vous a été envoyer !!!

// configuration des courriels envoyés

// Variable a passer par form /!\ ne pas toucher
$prenom = $_POST["prenom"];
$sonmail = $_POST["sonmail"];
$sujet = $_POST["sujet"];
$urlsite = $_POST["urlsite"];
$commentaire = $_POST["commentaire"];
// fin des variables

$m1="Bonjour $prenom ,
Votre commentaire nous a bien été envoyé .\n
Il sera mis en ligne le plus tôt possible .\n
Voici un rappel de votre commentaire : \n
Votre prénom : $prenom \n
Votre courriel : $sonmail \n
Sujet du commentaire : $sujet \n
URL de votre site : $urlsite \n
Votre commentaire :\n
$commentaire \n\n
A bientôt ! L'auteur du blogue $votresite \n
$urldevotresite \n\n";

$m2="Un courriel vient de vous être envoyé .\n
Son adresse courriel : $sonmail \n
Son prénom : $prenom \n
Sujet du message : $sujet \n
Url de son site : $urlsite \n
Son message : $commentaire";
?>

<p>&nbsp;</p>

______________

Thanks and regards.

User avatar
Zythan
Enthusiast
Posts: 48
Joined: Mon May 09, 2005 9:02 pm
Location: France

Re: Looking for a script / StripSlashes

Post by Zythan » Sat May 02, 2009 7:29 pm

Hello,

I was just thinking, but why do you work with a template for phpBB.

The reason why I ask is this.

Normally phpBB has the possibility for "visitors" to send comments, they can be posted directly or put on hold for validation.

Also it is much more simple to have a PHP form that allows a "visitor" just to send an email with their comments.

Best regards.

Zythan.

PS: The version of PHP is independent to the version of phpBB.

User avatar
homaquebec
PopTray Family
Posts: 913
Joined: Tue May 27, 2003 6:47 pm
Location: Québec (Canada)

Post by homaquebec » Sat May 02, 2009 7:42 pm

The reason is very simple.

I did not find any (free) software to manage a blog. So I used TOWeb (that can create web sites without any programming) and I adapted a web site a way that satisfied me and allowed me to do plenty of things on my blog. And then followed the template to send a comment.

Best regards.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests