Location: PHPKode > projects > WSN Guest > wsn-guest/comments.php
<?php
require 'start.php';

// reconstruct the current url and put it in a cookie, so we can know where to come back to if we go off somewhere soon... but only save it for 15 minutes

if ($settings->dirurl != '') $currenturl = $settings->dirurl .'/index.php';
else $currenturl =  'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
$currenturl .= '?'. $_SERVER['QUERY_STRING'];
if ($action != 'post')
{
if (($currenturl != '')&&($_SERVER['PHP_SELF'] != '')&&($currenturl != '/?')&&($currenturl != 'http://?')&&($currenturl != 'http:///?'))
setcookie("returnto", "$currenturl",  900);
}

$area = $language->title_divider . $language->title_comments;

if (($action=='post') && ($thismember->groupcansubmitcomments))
{
 if ($thismember->canpost())
 {
  if ($thismember->usergroup == 1 && extension_loaded('gd'))
  {
   $correct = securityimagevalue();
   $actual = $_POST['securityimage'];
   if ($actual != $correct) { $incomplete = true; $incompletemessage = $language->secimage_wrong; }
  }  
   
  $requiredcomments = explode(',', $settings->requiredcomments);
  $y = sizeof($requiredcomments);
  for ($x=0; $x<$y; $x++)
  {
   if ($$requiredcomments[$x] == '') { $incomplete = true; $missing .= $requiredcomments[$x]; }
  }
  if ((($settings->minlength > 1) && (strlen($message) < $settings->minlength)) || (($settings->maxlength > 1) && (strlen($message) > $settings->maxlength))) $incomplete = true;
  if ($incomplete)
  {
   $id = $entryid;
   if (!$template) $template = new template('viewcomments.tpl');
   $template->replace('{ENTRYID}', $id);
   $thislink = new onelink('dummy', $id);
   $language->viewcomments_nav = linkreplacements($language->viewcomments_nav, $thislink);  
   $language->viewcomments_commentsabout = linkreplacements($language->viewcomments_commentsabout, $thislink);  
   $template->text = linkreplacements($template->text, $thislink);
   if ($page == '') $page = 1;
   if ($perpage == '') $perpage = $settings->perpage;
   $start = ($page * $perpage) - $perpage;
   if ($orderby == '') $orderby = $settings->ordercomments;
   $totalquery = $db->select($settings->commentfields, 'commentstable', "entryid=$id AND validated=1", $orderby, ''); 
   $total = $db->numrows($totalquery);
   $query = $db->select($settings->commentfields, 'commentstable', "entryid=$id AND validated=1", $orderby, "LIMIT $start,$perpage");
   $posttemplate = templateextract($template->text, '<!-- BEGIN POST -->', '<!-- END POST -->');
   $template->replace($posttemplate, '{POSTAREA}');
   $num = $db->numrows($query);
   for ($count=0; $count<$num; $count++)
   {
    $row = $db->row($query);
    $thispost = new comment('row', $row);
    $onepost = commentreplacements($posttemplate, $thispost);
    if (strstr($posttemplate, '{MEMBER'))
    {
     if ($thispost->ownerid == '') $postingmember = new member('id', 0);
     else $postingmember = new member('id', $thispost->ownerid);
     $onepost = memberreplacements($onepost, $postingmember); 
    }
    $posts .= $onepost;
   }
   $template->replace('{POSTAREA}', $posts); 
   $numpages = ceil($total / $perpage);
   $search = urlencode($search);
   for ($count=1; $count < $page; $count++)
     $previouspages .= $language->pageselection_left. "<a href=\"comments.php?id=$id&amp;page=$count&amp;perpage=$perpage\">$count</a>". $language->pageselection_right;
   for ($count=$page; $count<$numpages; $count++)
   {
    $next = $count+1;
    $nextpages .= $language->pageselection_left ."<a href=\"comments.php?id=$id&amp;page=$next&amp;perpage=$perpage\">$next</a>". $language->pageselection_right;
   }
   $template->replace('{PREVIOUS}', $previouspages);
   $template->replace('{NEXT}', $nextpages);
   $template->replace('{CURRENTPAGE}', $page);
   $template->replace('{PAGE}', $page);
   $template->replace('{PERPAGE}', $perpage);
   $template->showsmilies();
   $ent = new comment('new', ' ');
   $ent->id = 1;
   $template->text = commentreplacements($template->text, $ent);
   if ($incompletemessage) $template->replace('{INCOMPLETE}', $incompletemessage);
   if (($settings->minlength > 1) && (strlen($message) < $settings->minlength))
   {
    $template->replace('{INCOMPLETE}', str_replace('{MIN}', $settings->minlength, $language->sign_tooshort));
   }
   else if (($settings->maxlength > 1) && (strlen($message) > $settings->maxlength))
   {
    $template->replace('{INCOMPLETE}', str_replace('{MAX}', $settings->maxlength, $language->sign_toolong));
   }
   else
   {
    $template->replace('{INCOMPLETE}', str_replace('{MISSING}', $missing, $language->comments_incomplete));
   }
  }  
  else
  {
   if (autovalidate('comments', $thismember->usergroup)) $validated = 1; else $validated = 0;
   if ($postername == '') $postername = $thismember->name;
   $posterid = $thismember->id;
   $ownerid = $thismember->id;
   $thiscomment = new comment('new', 'blank');
   $thiscomment->ip = $_SERVER['REMOTE_ADDR'];
   $thiscomment->add();
   if (!$template) $template = new template('redirect.tpl');
   $template->replace('{MESSAGE}', $language->comments_thanks);
   $template->replace('{DESTINATION}', "comments.php?id=$entryid");
   if ($validated == 1) $thismember->addcomment();
  }
 }
 else
 {
  if (!$template) $template = new template('redirect.tpl');
  $template->replace('{MESSAGE}', str_replace('{DELAYTIME}', $settings->floodcheck, $language->comments_floodcheck));
  $template->replace('{DESTINATION}', "comments.php?id=$entryid");
 }
}
else if (($action == 'post') && !($thismember->groupcansubmitcomments))
{
 // not allowed to submit
 if (!$template) $template = new template('redirect.tpl');
 $template->replace('{MESSAGE}', $language->comments_cannotpost);
 $template->replace('{DESTINATION}', "comments.php?id=$entryid");
}
else
{
 // access with comments.php?id=entryid&page=x
 if (!$template) $template = new template('viewcomments.tpl');
 $template->replace('{ENTRYID}', $id);
 
 $thislink = new onelink('dummy', $id);
 $template->text = linkreplacements($template->text, $thislink);
 $language->viewcomments_nav = linkreplacements($language->viewcomments_nav, $thislink);  
 $language->viewcomments_commentsabout = linkreplacements($language->viewcomments_commentsabout, $thislink);  

 if ($page == '') $page = 1;
 if ($perpage == '') $perpage = $settings->perpage;
 $start = ($page * $perpage) - $perpage;
 if ($orderby == '') $orderby = $settings->ordercomments;
 $totalquery = $db->select($settings->commentfields, 'commentstable', "entryid=$id AND validated=1", $orderby, ''); 
 $total = $db->numrows($totalquery);
 $query = $db->select($settings->commentfields, 'commentstable', "entryid=$id AND validated=1", $orderby, "LIMIT $start,$perpage");

 $posttemplate = templateextract($template->text, '<!-- BEGIN POST -->', '<!-- END POST -->');
 $template->replace($posttemplate, '{POSTAREA}');
 $num = $db->numrows($query);
 for ($count=0; $count<$num; $count++)
 {
  $row = $db->row($query);
  $thispost = new comment('row', $row);
  $onepost = commentreplacements($posttemplate, $thispost);
  if (strstr($posttemplate, '{MEMBER'))
  {
   if ($thispost->ownerid == '') $postingmember = new member('id', 0);
   else $postingmember = new member('id', $thispost->ownerid);
    $onepost = memberreplacements($onepost, $postingmember); 
  }
  $posts .= $onepost;
 }
 $template->replace('{POSTAREA}', $posts);
 $numpages = ceil($total / $perpage);
 $search = urlencode($search);
 for ($count=1; $count < $page; $count++)
   $previouspages .= $language->pageselection_left. "<a href=\"comments.php?id=$id&amp;page=$count&amp;perpage=$perpage\">$count</a>". $language->pageselection_right;
 for ($count=$page; $count<$numpages; $count++)
 {
    $next = $count+1;
    $nextpages .= $language->pageselection_left ."<a href=\"comments.php?id=$id&amp;page=$next&amp;perpage=$perpage\">$next</a>". $language->pageselection_right;
 }
 $template->replace('{PREVIOUS}', $previouspages);
 $template->replace('{NEXT}', $nextpages);
 $template->replace('{CURRENTPAGE}', $page);
 $template->replace('{PAGE}', $page);
 $template->replace('{PERPAGE}', $perpage);
 $template->showsmilies();
 $template->replace('{INCOMPLETE}', '');
 $ent = new comment('blank', ' ');
 $template->text = commentreplacements($template->text, $ent);
}

require 'end.php';
?>
Return current item: WSN Guest