[geeklog-cvs] geeklog-1.3/public_html article.php,1.58,1.59 lib-common.php,1.410,1.411 comment.php,1.85,1.86

vinny at iowaoutdoors.org vinny at iowaoutdoors.org
Fri Jan 21 18:31:47 EST 2005


Update of /var/cvs/geeklog-1.3/public_html
In directory www:/tmp/cvs-serv921/public_html

Modified Files:
	article.php lib-common.php comment.php 
Log Message:
Moved comment functions into lib-comment.php.


Index: comment.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/public_html/comment.php,v
retrieving revision 1.85
retrieving revision 1.86
diff -C2 -d -r1.85 -r1.86
*** comment.php	16 Dec 2004 11:09:51 -0000	1.85
--- comment.php	21 Jan 2005 23:31:44 -0000	1.86
***************
*** 50,53 ****
--- 50,58 ----
  require_once('lib-common.php');
  
+ /**
+  * Geeklog comment function library
+  */
+ require_once( $_CONF['path_system'] . 'lib-comment.php' );
+ 
  // Uncomment the line below if you need to debug the HTTP variables being passed
  // to the script.  This will sometimes cause errors but it will allow you to see
***************
*** 55,699 ****
  // echo COM_debug($_POST);
  
- /**
- * Displays the comment form
- *
- * @param    int     $uid        User ID
- * @param    string  $title      Title of comment
- * @param    string  $comment    Text of comment
- * @param    string  $sid        ID of object comment belongs to
- * @param    int     $pid        ID of parent comment
- * @param    string  $type       Type of object comment is posted to
- * @param    string  $mode       Mode, e.g. 'preview'
- * @param    string  $postmode   Indicates if comment is plain text or HTML
- * @return   string  HTML for comment form
- *
- */
- function commentform($uid,$title,$comment,$sid,$pid='0',$type,$mode,$postmode) 
- {
-     global $_CONF, $_TABLES, $_USER, $LANG03, $LANG12, $LANG_LOGIN;
- 
-     $retval = '';
- 
-     // never trust $uid ...
-     if (empty ($_USER['uid'])) {
-         $uid = 1;
-     } else {
-         $uid = $_USER['uid'];
-     }
- 
-     if (empty($_USER['username']) &&
-         (($_CONF['loginrequired'] == 1) || ($_CONF['commentsloginrequired'] == 1))) {
-         $retval .= COM_startBlock ($LANG_LOGIN[1], '',
-                            COM_getBlockTemplate ('_msg_block', 'header'));
-         $loginreq = new Template($_CONF['path_layout'] . 'submit');
-         $loginreq->set_file('loginreq', 'submitloginrequired.thtml');
-         $loginreq->set_var('login_message', $LANG_LOGIN[2]);
-         $loginreq->set_var('site_url', $_CONF['site_url']);
-         $loginreq->set_var('lang_login', $LANG_LOGIN[3]);
-         $loginreq->set_var('lang_newuser', $LANG_LOGIN[4]);
-         $loginreq->parse('errormsg', 'loginreq');
-         $retval .= $loginreq->finish($loginreq->get_var('errormsg'));
-         $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
-         return $retval;
-     } else {
-         COM_clearSpeedlimit ($_CONF['commentspeedlimit'], 'comment');
- 
-         $last = COM_checkSpeedlimit ('comment');
- 
-         if ($last > 0) {
-             $retval .= COM_startBlock ($LANG12[26], '',
-                                COM_getBlockTemplate ('_msg_block', 'header'))
-                 . $LANG03[7]
-                 . $last
-                 . $LANG03[8]
-                 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
-         } else {
- 
-             if (empty ($postmode)) {
-                 $postmode = $_CONF['postmode'];
-             }
- 
-             $sig = '';
-             if ($uid > 1) {
-                 $sig = DB_getItem ($_TABLES['users'], 'sig', "uid = '$uid'");
-             }
- 
-             // Note:
-             // $comment / $newcomment is what goes into the preview / is
-             // actually stored in the database -> strip HTML
-             // $commenttext is what the user entered and goes back into the
-             // <textarea> -> don't strip HTML
- 
-             $commenttext = htmlspecialchars (COM_stripslashes ($comment));
- 
-             $fakepostmode = $postmode;
-             if ($postmode == 'html') {
-                 $comment = COM_checkWords (COM_checkHTML (addslashes (COM_stripslashes ($comment))));
-             } else {
-                 $comment = htmlspecialchars (COM_checkWords (COM_stripslashes ($comment)));
-                 $newcomment = COM_makeClickableLinks ($comment);
-                 if (strcmp ($comment, $newcomment) != 0) {
-                     $comment = nl2br ($newcomment);
-                     $fakepostmode = 'html';
-                 }
-             }
-             // Replace $, {, and } with special HTML equivalents
-             $commenttext = str_replace('$','$',$commenttext);
-             $commenttext = str_replace('{','{',$commenttext);
-             $commenttext = str_replace('}','}',$commenttext);
- 
-             $title = htmlspecialchars (COM_checkWords (strip_tags (COM_stripslashes ($title))));
-             // $title = str_replace('$','$',$title); done in COM_getComment
-             $title = str_replace('{','{',$title);
-             $title = str_replace('}','}',$title);
- 
-             $_POST['title'] = addslashes ($title);
-             $newcomment = $comment;
-             if (!empty ($sig)) {
-                 if (($postmode == 'html') || ($fakepostmode == 'html')) {
-                     $newcomment .= '<p>---<br>' . nl2br ($sig);
-                 } else {
-                     $newcomment .= LB . LB . '---' . LB . $sig;
-                 }
-             }
-             $_POST['comment'] = addslashes ($newcomment);
- 
-             if ($mode == $LANG03[14] && !empty($title) && !empty($comment) ) {
-                 $start = new Template( $_CONF['path_layout'] . 'comment' );
-                 $start->set_file( array( 'comment' => 'startcomment.thtml' ));
-                 $start->set_var( 'site_url', $_CONF['site_url'] );
-                 $start->set_var( 'layout_url', $_CONF['layout_url'] );
- 
-                 if (empty ($_POST['username'])) {
-                     $_POST['username'] = DB_getItem ($_TABLES['users'],
-                             'username', "uid = $uid");
-                 }
-                 $thecomments = COM_getComment ($_POST, 'flat', $type,
-                                                'ASC', false, true );
- 
-                 $start->set_var( 'comments', $thecomments );
-                 $retval .= COM_startBlock ($LANG03[14])
-                         . $start->finish( $start->parse( 'output', 'comment' ))
-                         . COM_endBlock ();
-             } else if ($mode == $LANG03[14]) {
-                 $retval .= COM_startBlock ($LANG03[17], '',
-                                COM_getBlockTemplate ('_msg_block', 'header'))
-                     . $LANG03[12]
-                     . COM_endBlock(COM_getBlockTemplate ('_msg_block', 'footer'));
-                 $mode = 'error';
-             }
- 
-             $comment_template = new Template($_CONF['path_layout'] . 'comment');
-             if (($_CONF['advanced_editor'] == 1) && file_exists ($_CONF['path_layout'] . 'comment/commentform_advanced.thtml')) {
-                 $comment_template->set_file('form','commentform_advanced.thtml');
-             } else {
-                 $comment_template->set_file('form','commentform.thtml');
-             }
-             $comment_template->set_var('site_url', $_CONF['site_url']);
-             $comment_template->set_var('start_block_postacomment', COM_startBlock($LANG03[1]));
-             $comment_template->set_var('lang_username', $LANG03[5]);
-             $comment_template->set_var('sid', $sid);
-             $comment_template->set_var('pid', $pid);
-             $comment_template->set_var('type', $type);
- 
-             if (!empty($_USER['username'])) {
-                 $comment_template->set_var('uid', $_USER['uid']);
-                 $comment_template->set_var('username', $_USER['username']);
-                 $comment_template->set_var('action_url', $_CONF['site_url'] . '/users.php?mode=logout');
-                 $comment_template->set_var('lang_logoutorcreateaccount', $LANG03[03]);
-             } else {
-                 $comment_template->set_var('uid', 1);
-                 $comment_template->set_var('username', $LANG03[24]);
-                 $comment_template->set_var('action_url', $_CONF['site_url'] . '/users.php?mode=new'); 
-                 $comment_template->set_var('lang_logoutorcreateaccount', $LANG03[04]);
-             }
- 
-             $comment_template->set_var('lang_title', $LANG03[16]);
-             $comment_template->set_var('title', stripslashes($title));
-             $comment_template->set_var('lang_comment', $LANG03[9]);
-             $comment_template->set_var('comment', $commenttext);
-             $comment_template->set_var('lang_postmode', $LANG03[2]);
-             $comment_template->set_var('postmode_options', COM_optionList($_TABLES['postmodes'],'code,name',$postmode));
-             $comment_template->set_var('allowed_html', COM_allowedHTML());
-             $comment_template->set_var('lang_importantstuff', $LANG03[18]);
-             $comment_template->set_var('lang_instr_line1', $LANG03[19]);        
-             $comment_template->set_var('lang_instr_line2', $LANG03[20]);        
-             $comment_template->set_var('lang_instr_line3', $LANG03[21]);        
-             $comment_template->set_var('lang_instr_line4', $LANG03[22]);        
-             $comment_template->set_var('lang_instr_line5', $LANG03[23]);        
-             $comment_template->set_var('lang_preview', $LANG03[14]);
- 
-             if (($_CONF['skip_preview'] == 1) || ($mode == $LANG03[14])) {
-                 $comment_template->set_var('save_option', '<input type="submit" name="mode" value="' . $LANG03[11] . '">');
-             }
- 
-             $comment_template->set_var('end_block', COM_endBlock());        
-             $comment_template->parse('output', 'form');
-             $retval .= $comment_template->finish($comment_template->get_var('output'));
-         }
-     }
- 
-     return $retval;
- }
- 
- /**
- * Save a comment
- *
- * @param        int         $uid        User ID of user making the comment
- * @param        string      $title      Title of comment
- * @param        string      $comment    Text of comment
- * @param        string      $sid        ID of object receiving comment
- * @param        int         $pid        ID of parent comment
- * @param        string      $type       Type of comment this is (article, poll, etc)
- * @param        string      $postmode   Indicates if text is HTML or plain text
- * @param        string        $prepocessed Indicates that preprocessing by another plugin
- *                                        i.e. Spamx has already occured
- * @return       string      either nothing or HTML formated error
- *
- */
- function savecomment ($uid, $title, $comment, $sid, $pid, $type, $postmode) 
- {
-     global $_CONF, $_TABLES, $_USER, $LANG03;
-     
-     $retval = '';
- 
-     // ignore $uid as it may be manipulated anyway
-     if (empty ($_USER['uid'])) {
-         $uid = 1;
-     } else {
-         $uid = $_USER['uid'];
-     }
- 
-     if (empty ($sid) || empty ($title) || empty ($comment) || empty ($type) ||
-             (($uid == 1) && (($_CONF['loginrequired'] == 1) ||
-                 ($_CONF['commentsloginrequired'] == 1)))) {
-         $retval .= COM_refresh ($_CONF['site_url'] . '/index.php');
-         return $retval;
-     }
- 
-     // Check for people breaking the speed limit
-     COM_clearSpeedlimit ($_CONF['commentspeedlimit'], 'comment');
-     $last = COM_checkSpeedlimit ('comment');
-     if ($last > 0) {
-         $retval .= COM_startBlock ($LANG12[26], '', COM_getBlockTemplate ('_msg_block', 'header'))
-                 . $LANG03[7]
-                 . $last
-                 . $LANG03[8]
-                 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
-         return $retval;
-     }
- 
-     // Let plugins have a chance to check for SPAM
-     $result = PLG_checkforSpam($comment, $_CONF['spamx']);
-     // Now check the result and redirect to index.php if spam action was taken
-     if ($result > 0) {
-         echo COM_refresh($_CONF['site_url'] . '/index.php?msg='.$result.'&plugin=spamx');
-         exit;
-     }
-     // Let plugins have a chance to decide what to do before saving the comment.
-     $someError = PLG_commentPreSave($uid, $title, $comment, $sid, $pid, $type, $postmode);
-     
-     // If a plugin returned an error, return it
-     if ($someError) {
-         return $someError;
-     }
-     
-     $commentcode = 0;
-     if ($type == 'article') {
-         $commentcode = DB_getItem ($_TABLES['stories'], 'commentcode',
-                                    "sid = '$sid'");
-     } else if ($type == 'poll') {
-         $commentcode = DB_getItem ($_TABLES['pollquestions'], 'commentcode',
-                                    "qid = '$sid'");
-     }
-     if ($commentcode < 0) {
-         return COM_refresh ($_CONF['site_url'] . '/index.php');
-     }
- 
-     // Clean 'em up a bit!
-     if ($postmode == 'html') {
-         $comment = COM_checkWords (COM_checkHTML (addslashes (COM_stripslashes ($comment))));
-     } else {
-         $comment = htmlspecialchars (COM_checkWords (COM_stripslashes ($comment)));
-         $newcomment = COM_makeClickableLinks ($comment);
-         if (strcmp ($comment, $newcomment) != 0) {
-             $comment = nl2br ($newcomment);
-             $postmode = 'html';
-         }
-     }
- 
-     // Get signature
-     $sig = '';
-     if ($uid > 1) {
-         $sig = DB_getItem($_TABLES['users'],'sig', "uid = '$uid'");
-     }
-     if (!empty ($sig)) {
-         if ($postmode == 'html') {
-             $comment .= '<p>---<br>' . nl2br($sig);
-         } else {
-             $comment .= LB . LB . '---' . LB . $sig;
-         }
-     }
- 
-     // check again for non-int pid's
-     // this should just create a top level comment that is a reply to the original item
-     if (!is_numeric($pid)) {
-         $pid = 0;
-     }
- 
-     $title = htmlspecialchars (COM_checkWords (strip_tags (COM_stripslashes ($title))));
- 
-     if (!empty ($title) && !empty ($comment)) {
-         COM_updateSpeedlimit ('comment');
-         $title = addslashes ($title);
-         $comment = addslashes ($comment);
- 
-         // Insert the comment into the comment table
-         DB_query("LOCK TABLES {$_TABLES['comments']} WRITE");
-         if ($pid > 0) {
-             $result = DB_query("SELECT rht, indent FROM {$_TABLES['comments']} WHERE cid = $pid");
-             list($rht, $indent) = DB_fetchArray($result);
-             DB_query("UPDATE {$_TABLES['comments']} SET lft = lft + 2 "
-                    . "WHERE sid = '$sid' AND lft >= $rht");
-             DB_query("UPDATE {$_TABLES['comments']} SET rht = rht + 2 "
-                    . "WHERE sid = '$sid' AND rht >= $rht");
-             DB_save ($_TABLES['comments'], 'sid,uid,comment,date,title,pid,lft,rht,indent,type,ipaddress',
-                     "'$sid',$uid,'$comment',now(),'$title',$pid,$rht,$rht+1,$indent+1,'$type','{$_SERVER['REMOTE_ADDR']}'");
-         } else {
-             $rht = DB_getItem($_TABLES['comments'], 'MAX(rht)');
-             DB_save ($_TABLES['comments'], 'sid,uid,comment,date,title,pid,lft,rht,indent,type,ipaddress',
-                     "'$sid',$uid,'$comment',now(),'$title',$pid,$rht+1,$rht+2,0,'$type','{$_SERVER['REMOTE_ADDR']}'");
-         }
-         $cid = DB_insertId();
-         DB_query('UNLOCK TABLES');
- 
-         if (isset ($_CONF['notification']) &&
-                 in_array ('comment', $_CONF['notification'])) {
-             sendNotification ($title, $comment, $uid, $_SERVER['REMOTE_ADDR'],
-                               $type, $cid);
-         }
- 
-         if ($type == 'poll') {
-             $retval = COM_refresh ($_CONF['site_url']
-                     . "/pollbooth.php?qid=$sid&aid=-1");
-         } elseif ($type == 'article') {
-             $comments = DB_count ($_TABLES['comments'], 'sid', $sid);
-             DB_change ($_TABLES['stories'], 'comments', $comments, 'sid', $sid);
-             COM_olderStuff (); // update comment count in Older Stories block
-             $retval = COM_refresh (COM_buildUrl ($_CONF['site_url']
-                     . "/article.php?story=$sid"));
-         } else { // assume it's a comment handled by a plugin
-             $cid = DB_getItem ($_TABLES['comments'], 'cid', "(type = '$type') AND (pid = '$pid') AND (sid = '$sid') AND (uid = '$uid')");
-             $retval = PLG_handlePluginComment ($type, $cid, 'save');
-             if (empty ($retval)) {
-                 $retval = COM_refresh ($_CONF['site_url'] . '/index.php');
-             }
-         }
-     } else {
-         $retval .= COM_siteHeader()
-             . commentform ($uid, $title, $comment, $sid, $pid, $type,
-                            $LANG03[14], $postmode)
-             . COM_siteFooter();
-     }
- 
-     return $retval;
- }
- 
- /**
- * Send an email notification for a new comment submission.
- *
- * @param    $title      string      comment title
- * @param    $comment    string      text of the comment
- * @param    $uid        integer     user id
- * @param    $ipaddress  string      poster's IP address
- * @param    $type       string      type of comment ('article', 'poll', ...)
- * @param    $cid        integer     comment id
- *
- */
- function sendNotification ($title, $comment, $uid, $ipaddress, $type, $cid)
- {
-     global $_CONF, $_TABLES, $LANG03, $LANG08, $LANG09;
- 
-     // we have to undo the addslashes() call from savecomment()
-     $title = stripslashes ($title);
-     $comment = stripslashes ($comment);
- 
-     // strip HTML if posted in HTML mode
-     if (preg_match ('/<.*>/', $comment) != 0) {
-         $comment = strip_tags ($comment);
-     }
- 
-     $author = DB_getItem ($_TABLES['users'], 'username', "uid = '$uid'");
-     if (($uid <= 1) && !empty ($ipaddress)) {
-         // add IP address for anonymous posters
-         $author .= ' (' . $ipaddress . ')';
-     }
- 
-     $mailbody = "$LANG03[16]: $title\n"
-               . "$LANG03[5]: $author\n";
- 
-     if (($type != 'article') && ($type != 'poll')) {
-         $mailbody .= "$LANG09[5]: $type\n";
-     }
- 
-     if ($_CONF['emailstorieslength'] > 0) {
-         if ($_CONF['emailstorieslength'] > 1) {
-             $comment = substr ($comment, 0, $_CONF['emailstorieslength'])
-                      . '...';
-         }
-         $mailbody .= $comment . "\n\n";
-     }
- 
-     $mailbody .= $LANG08[33] . ' <' . $_CONF['site_url']
-               . '/comment.php?mode=view&cid=' . $cid . ">\n\n";
- 
-     $mailbody .= "\n------------------------------\n";
-     $mailbody .= "\n$LANG08[34]\n";
-     $mailbody .= "\n------------------------------\n";
- 
-     $mailsubject = $_CONF['site_name'] . ' ' . $LANG03[9];
- 
-     COM_mail ($_CONF['site_mail'], $mailsubject, $mailbody);
- }
- 
- /**
- * Deletes a given comment
- *
- * @param    int         $cid    Comment ID
- * @param    string      $sid    ID of object comment belongs to
- * @param    string      $type   Comment type (e.g. article, poll, etc)
- * @return   string      Returns string needed to redirect page to right place
- *
- */
- function deletecomment ($cid, $sid, $type) 
- {
-     global $_CONF, $_TABLES, $_USER;
- 
-     $retval = '';
- 
-     if (is_numeric ($cid) && ($cid > 0) && !empty ($sid) && !empty ($type)) {
- 
-         // only comments of type 'article' and 'poll' are handled by Geeklog
-         if (($type == 'article') || ($type == 'poll')) {
- 
-             if ($type == 'article') {
-                 $table = $_TABLES['stories'];
-                 $idname = 'sid';
-                 $has_editPermissions = SEC_hasRights ('story.edit');
-             } else {
-                 $table = $_TABLES['pollquestions'];
-                 $idname = 'qid';
-                 $has_editPermissions = SEC_hasRights ('poll.edit');
-             }
-             $result = DB_query ("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$table} WHERE {$idname} = '{$sid}'");
-             $A = DB_fetchArray ($result);
- 
-             if ($has_editPermissions && SEC_hasAccess ($A['owner_id'],
-                     $A['group_id'], $A['perm_owner'], $A['perm_group'],
-                     $A['perm_members'], $A['perm_anon']) == 3) {
-                 DB_query("LOCK TABLES {$_TABLES['comments']} WRITE");
-                 $result = DB_query("SELECT pid, lft, rht FROM {$_TABLES['comments']} "
-                                  . "WHERE cid = $cid");
-                 list($pid,$lft,$rht) = DB_fetchArray($result); 
-                 DB_change ($_TABLES['comments'], 'pid', $pid, 'pid', $cid);
-                 DB_delete ($_TABLES['comments'], 'cid', $cid);
-                 DB_query("UPDATE {$_TABLES['comments']} SET indent = indent - 1 "
-                    . "WHERE sid = '$sid' AND lft BETWEEN $lft AND $rht");
-                 DB_query("UPDATE {$_TABLES['comments']} SET lft = lft - 2 "
-                    . "WHERE sid = '$sid' AND lft >= $rht");
-                 DB_query("UPDATE {$_TABLES['comments']} SET rht = rht - 2 "
-                    . "WHERE sid = '$sid' AND rht >= $rht");
-                 DB_query('UNLOCK TABLES');
- 
-                 if ($type == 'poll') {
-                     $retval .= COM_refresh ($_CONF['site_url']
-                             . '/pollbooth.php?qid=' . $sid . '&aid=-1');
-                 } else {
-                     $comments = DB_count ($_TABLES['comments'], 'sid', $sid);
-                     DB_change ($_TABLES['stories'], 'comments', $comments,
-                                'sid', $sid);
-                     $retval .= COM_refresh (COM_buildUrl ($_CONF['site_url']
-                             . '/article.php?story=' . $sid) . '#comments');
-                 }
-             } else {
-                 COM_errorLog ('User ' . $_USER['username'] . ' (IP: '
-                         . $_SERVER['REMOTE_ADDR']
-                         . ') tried to illegally delete comment '
-                         . $cid . ' from ' . $type . ' ' . $sid);
-                 $retval .= COM_refresh ($_CONF['site_url'] . '/index.php');
-             }
-         } else {
-             // See if plugin will handle this
-             $retval = PLG_handlePluginComment ($type, $cid, 'delete');
-             if (empty ($retval)) {
-                 $retval = COM_refresh ($_CONF['site_url'] . '/index.php');
-             }
-         }
-     } else {
-         $retval .= COM_refresh ($_CONF['site_url'] . '/index.php');
-     }
- 
-     return $retval;
- }
- 
- /**
- * Display form to report abusive comment.
- *
- * @param    string  $cid    comment id
- * @param    string  $type   type of comment ('article', 'poll', ...)
- * @return   string          HTML for the form (or error message)
- *
- */
- function report_abusive_comment ($cid, $type)
- {
-     global $_CONF, $_TABLES, $_USER, $LANG03, $LANG12, $LANG_LOGIN;
- 
-     $retval = '';
- 
-     if (empty ($_USER['username'])) {
-         $retval .= COM_startBlock ($LANG_LOGIN[1], '',
-                            COM_getBlockTemplate ('_msg_block', 'header'));     
-         $loginreq = new Template ($_CONF['path_layout'] . 'submit');            
-         $loginreq->set_file ('loginreq', 'submitloginrequired.thtml');          
-         $loginreq->set_var ('login_message', $LANG_LOGIN[2]);
-         $loginreq->set_var ('site_url', $_CONF['site_url']);                    
-         $loginreq->set_var ('lang_login', $LANG_LOGIN[3]);
-         $loginreq->set_var ('lang_newuser', $LANG_LOGIN[4]);
-         $loginreq->parse ('errormsg', 'loginreq');
-         $retval .= $loginreq->finish ($loginreq->get_var ('errormsg'));
-         $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
- 
-         return $retval;
-     }
- 
-     COM_clearSpeedlimit ($_CONF['speedlimit'], 'mail');
-     $last = COM_checkSpeedlimit ('mail');
-     if ($last > 0) {
-         $retval .= COM_startBlock ($LANG12[26], '',
-                             COM_getBlockTemplate ('_msg_block', 'header'))
-                 . $LANG12[30] . $last . $LANG12[31]
-                 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
- 
-         return $retval;
-     }
- 
-     $start = new Template ($_CONF['path_layout'] . 'comment');
-     $start->set_file (array ('report' => 'reportcomment.thtml'));
-     $start->set_var ('site_url', $_CONF['site_url']);
-     $start->set_var ('layout_url', $_CONF['layout_url']);
-     $start->set_var ('lang_report_this', $LANG03[25]);
-     $start->set_var ('lang_send_report', $LANG03[10]);
-     $start->set_var ('cid', $cid);
-     $start->set_var ('type', $type);
- 
-     $result = DB_query ("SELECT uid,sid,pid,title,comment,UNIX_TIMESTAMP(date) AS nice_date FROM {$_TABLES['comments']} WHERE cid = $cid AND type = '$type'");
-     $A = DB_fetchArray ($result);
- 
-     $result = DB_query ("SELECT username,fullname,photo FROM {$_TABLES['users']} WHERE uid = {$A['uid']}");
-     $B = DB_fetchArray ($result);
- 
-     // prepare data for comment preview
-     $A['cid'] = $cid;
-     $A['type'] = $type;
-     $A['username'] = $B['username'];
-     $A['fullname'] = $B['fullname'];
-     $A['photo'] = $B['photo'];
-     $A['indent'] = 0;
-     $A['pindent'] = 0;
- 
-     $thecomment = COM_getComment ($A, 'flat', $type, 'ASC', false, true);
-     $start->set_var ('comment', $thecomment);
-     $retval .= COM_startBlock ($LANG03[15])
-             . $start->finish ($start->parse ('output', 'report'))
-             . COM_endBlock ();
- 
-     return $retval;
- }
- 
- /**
- * Send report about abusive comment
- *
- * @param    string  $cid    comment id
- * @param    string  $type   type of comment ('article', 'poll', ...)
- * @return   string          Meta refresh or HTML for error message
- *
- */
- function send_report ($cid, $type)
- {
-     global $_CONF, $_TABLES, $_USER, $LANG03, $LANG08, $LANG_LOGIN;
- 
-     if (empty ($_USER['username'])) {
-         $retval = COM_siteHeader ('menu');
-         $retval .= COM_startBlock ($LANG_LOGIN[1], '',
-                            COM_getBlockTemplate ('_msg_block', 'header'));     
-         $loginreq = new Template ($_CONF['path_layout'] . 'submit');            
-         $loginreq->set_file ('loginreq', 'submitloginrequired.thtml');          
-         $loginreq->set_var ('login_message', $LANG_LOGIN[2]);
-         $loginreq->set_var ('site_url', $_CONF['site_url']);                    
-         $loginreq->set_var ('lang_login', $LANG_LOGIN[3]);
-         $loginreq->set_var ('lang_newuser', $LANG_LOGIN[4]);
-         $loginreq->parse ('errormsg', 'loginreq');
-         $retval .= $loginreq->finish ($loginreq->get_var ('errormsg'));
-         $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
-         $retval .= COM_siteFooter ();
- 
-         return $retval;
-     }
- 
-     COM_clearSpeedlimit ($_CONF['speedlimit'], 'mail');
-     if (COM_checkSpeedlimit ('mail') > 0) {
-         return COM_refresh ($_CONF['site_url'] . '/index.php');
-     }
- 
-     $username = DB_getItem ($_TABLES['users'], 'username',
-                             "uid = {$_USER['uid']}");
-     $result = DB_query ("SELECT uid,title,comment,sid,ipaddress FROM {$_TABLES['comments']} WHERE cid = $cid AND type = '$type'");
-     $A = DB_fetchArray ($result);
- 
-     $title = stripslashes ($A['title']);
-     $comment = stripslashes ($A['comment']);
- 
-     // strip HTML if posted in HTML mode
-     if (preg_match ('/<.*>/', $comment) != 0) {
-         $comment = strip_tags ($comment);
-     }
- 
-     $author = DB_getItem ($_TABLES['users'], 'username', "uid = {$A['uid']}");
-     if (($A['uid'] <= 1) && !empty ($A['ipaddress'])) {
-         // add IP address for anonymous posters
-         $author .= ' (' . $A['ipaddress'] . ')';
-     }
- 
-     $mailbody = sprintf ($LANG03[26], $username);
-     $mailbody .= "\n\n"
-               . "$LANG03[16]: $title\n"
-               . "$LANG03[5]: $author\n";
-     
-     if (($type != 'article') && ($type != 'poll')) {
-         $mailbody .= "$LANG09[5]: $type\n";
-     }
- 
-     if ($_CONF['emailstorieslength'] > 0) {
-         if ($_CONF['emailstorieslength'] > 1) {
-             $comment = substr ($comment, 0, $_CONF['emailstorieslength'])
-                      . '...';
-         }
-         $mailbody .= $comment . "\n\n";
-     }
- 
-     $mailbody .= $LANG08[33] . ' <' . $_CONF['site_url']
-               . '/comment.php?mode=view&cid=' . $cid . ">\n\n";
- 
-     $mailbody .= "\n------------------------------\n";
-     $mailbody .= "\n$LANG08[34]\n";
-     $mailbody .= "\n------------------------------\n";
- 
-     $mailsubject = $_CONF['site_name'] . ' ' . $LANG03[27];
- 
-     COM_mail ($_CONF['site_mail'], $mailsubject, $mailbody);
-     COM_updateSpeedlimit ('mail');
- 
-     return COM_refresh ($_CONF['site_url'] . '/index.php?msg=27');
- }
  
  
--- 60,63 ----
***************
*** 708,712 ****
  case $LANG03[14]: // Preview
      $display .= COM_siteHeader()
!         . commentform (COM_applyFilter ($_POST['uid'], true),
              strip_tags ($_POST['title']), $_POST['comment'],
              COM_applyFilter ($_POST['sid']),
--- 72,76 ----
  case $LANG03[14]: // Preview
      $display .= COM_siteHeader()
!         . CMT_commentForm (COM_applyFilter ($_POST['uid'], true),
              strip_tags ($_POST['title']), $_POST['comment'],
              COM_applyFilter ($_POST['sid']),
***************
*** 718,722 ****
  
  case $LANG03[11]: // Submit Comment
!     $display .= savecomment (COM_applyFilter ($_POST['uid'], true),
              strip_tags ($_POST['title']), $_POST['comment'],
              COM_applyFilter ($_POST['sid']),
--- 82,86 ----
  
  case $LANG03[11]: // Submit Comment
!     $display .= CMT_saveComment (COM_applyFilter ($_POST['uid'], true),
              strip_tags ($_POST['title']), $_POST['comment'],
              COM_applyFilter ($_POST['sid']),
***************
*** 727,733 ****
  
  case 'delete':
!     $display .= deletecomment (COM_applyFilter ($_REQUEST['cid'], true),
!                                COM_applyFilter ($_REQUEST['sid']),
!                                COM_applyFilter ($_REQUEST['type']));
      break;
  
--- 91,97 ----
  
  case 'delete':
!     $display .= CMT_deleteComment (COM_applyFilter ($_REQUEST['cid'], true),
!                                    COM_applyFilter ($_REQUEST['sid']),
!                                    COM_applyFilter ($_REQUEST['type']));
      break;
  
***************
*** 774,778 ****
                  $delete_option = false;
              }
!             $display .= COM_userComments ($sid, $title, $type, 
                              COM_applyFilter ($_REQUEST['order']), $format, $cid,
                              COM_applyFilter ($_REQUEST['page'], true), true, $delete_option);
--- 138,142 ----
                  $delete_option = false;
              }
!             $display .= CMT_userComments ($sid, $title, $type, 
                              COM_applyFilter ($_REQUEST['order']), $format, $cid,
                              COM_applyFilter ($_REQUEST['page'], true), true, $delete_option);
***************
*** 826,830 ****
                  $delete_option = false;
              }
!             $display .= COM_userComments ($sid, $title, $type,
                      COM_applyFilter ($_REQUEST['order']), $format, $pid,
                      COM_applyFilter ($_REQUEST['page'], true), false, $delete_option);
--- 190,194 ----
                  $delete_option = false;
              }
!             $display .= CMT_userComments ($sid, $title, $type,
                      COM_applyFilter ($_REQUEST['order']), $format, $pid,
                      COM_applyFilter ($_REQUEST['page'], true), false, $delete_option);
***************
*** 843,854 ****
  case 'report':
      $display = COM_siteHeader ('menu')
!              . report_abusive_comment (COM_applyFilter ($_GET['cid'], true),
!                                        COM_applyFilter ($_GET['type']))
               . COM_siteFooter ();
      break;
  
  case 'sendreport':
!     $display = send_report (COM_applyFilter ($_POST['cid'], true),
!                             COM_applyFilter ($_POST['type']));
      break;
  
--- 207,218 ----
  case 'report':
      $display = COM_siteHeader ('menu')
!              . CMT_reportAbusiveComment (COM_applyFilter ($_GET['cid'], true),
!                                          COM_applyFilter ($_GET['type']))
               . COM_siteFooter ();
      break;
  
  case 'sendreport':
!     $display = CMT_sendReport (COM_applyFilter ($_POST['cid'], true),
!                                COM_applyFilter ($_POST['type']));
      break;
  
***************
*** 874,878 ****
          if (!empty ($type)) {
              $display .= COM_siteHeader('menu', $LANG03[1])
!                 . commentform ($_USER['uid'], $title, '', $sid, $pid, $type,
                                 $mode, $postmode)
                  . COM_siteFooter();
--- 238,242 ----
          if (!empty ($type)) {
              $display .= COM_siteHeader('menu', $LANG03[1])
!                 . CMT_commentForm ($_USER['uid'], $title, '', $sid, $pid, $type,
                                 $mode, $postmode)
                  . COM_siteFooter();

Index: lib-common.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/public_html/lib-common.php,v
retrieving revision 1.410
retrieving revision 1.411
diff -C2 -d -r1.410 -r1.411
*** lib-common.php	17 Jan 2005 12:42:05 -0000	1.410
--- lib-common.php	21 Jan 2005 23:31:44 -0000	1.411
***************
*** 1916,1920 ****
                      $Q['perm_owner'], $Q['perm_group'], $Q['perm_members'],
                      $Q['perm_anon'] ) == 3 ? true : false );
!                 $retval .= COM_userComments( $qid, $Q['question'], 'poll',
                                  $order, $mode, 0, 1, false, $delete_option ); 
              }
--- 1916,1922 ----
                      $Q['perm_owner'], $Q['perm_group'], $Q['perm_members'],
                      $Q['perm_anon'] ) == 3 ? true : false );
! 
!                 require_once ( $_CONF['path_system'] . 'lib-comment.php' );
!                 $retval .= CMT_userComments( $qid, $Q['question'], 'poll',
                                  $order, $mode, 0, 1, false, $delete_option ); 
              }
***************
*** 2628,3196 ****
  
  /**
! * This function displays the comment control bar
! *
! * Prints the control that allows the user to interact with Geeklog Comments
! *
! * @param        string      $sid        ID of item in question
! * @param        string      $title      Title of item
! * @param        string      $type       Type of item (i.e. story, photo, etc)
! * @param        string      $order      Order that comments are displayed in
! * @param        string      $mode       Mode (nested, flat, etc.)
! * @see COM_userComments
! * @see COM_commentChildren
! * @return     string   HTML Formated comment bar
! *
! */
! function COM_commentBar( $sid, $title, $type, $order, $mode )
! {
!     global $_CONF, $_TABLES, $_USER, $LANG01;
! 
!     $page = array_pop( explode( '/', $_SERVER['PHP_SELF'] ));
!     $nrows = DB_count( $_TABLES['comments'], 'sid', $sid );
! 
!     $commentbar = new Template( $_CONF['path_layout'] . 'comment' );
!     $commentbar->set_file( array( 'commentbar' => 'commentbar.thtml' ));
!     $commentbar->set_var( 'site_url', $_CONF['site_url'] );
!     $commentbar->set_var( 'layout_url', $_CONF['layout_url'] );
! 
!     $commentbar->set_var( 'lang_comments', $LANG01[3] );
!     $commentbar->set_var( 'lang_refresh', $LANG01[39] );
!     $commentbar->set_var( 'lang_reply', $LANG01[25] );
!     $commentbar->set_var( 'lang_disclaimer', $LANG01[26] );
! 
!     $commentbar->set_var( 'story_title', stripslashes( $title ));
!     $commentbar->set_var( 'num_comments', $nrows );
!     $commentbar->set_var( 'comment_type', $type );
! 
!     if( $type == 'poll' )
!     {
!         $commentbar->set_var( 'story_link', $_CONF['site_url']
!                 . "/pollbooth.php?scale=400&qid=$sid&aid=-1" );
!     }
!     else if( $type == 'article' )
!     {
!         $articleUrl = COM_buildUrl( $_CONF['site_url'] . '/article.php?story='
!                                     . $sid );
!         $commentbar->set_var( 'story_link', $articleUrl );
!         $commentbar->set_var( 'article_url', $articleUrl );
!     }
!     else
!     {
!         $commentbar->set_var( 'story_link', $_CONF['site_url']
!                 . "/comment.php?type=$type&cid=$sid" );
!     }
! 
!     if( $_USER['uid'] > 1 )
!     {
!         $username = $_USER['username'];
!         $fullname = DB_getItem( $_TABLES['users'], 'fullname',
!                                 "uid = '{$_USER['uid']}'" ); 
!     }
!     else
!     {
!         $result = DB_query( "SELECT username,fullname FROM {$_TABLES['users']} WHERE uid = 1" );
!         $N = DB_fetchArray( $result );
!         $username = $N['username'];
!         $fullname = $N['fullname'];
!     }
!     if( empty( $fullname ))
!     {
!         $fullname = $username;
!     }
!     $commentbar->set_var( 'user_name', $username );   
!     $commentbar->set_var( 'user_fullname', $fullname );    
! 
!     if( !empty( $_USER['username'] ))
!     {
!         $commentbar->set_var( 'user_nullname', $username );
!         $commentbar->set_var( 'login_logout_url',
!                               $_CONF['site_url'] . '/users.php?mode=logout' );
!         $commentbar->set_var( 'lang_login_logout', $LANG01[35] );
!     }
!     else
!     {
!         $commentbar->set_var( 'user_nullname', '' );
!         $commentbar->set_var( 'login_logout_url',
!                               $_CONF['site_url'] . '/users.php?mode=new' );
!         $commentbar->set_var( 'lang_login_logout', $LANG01[61] );
!     }
! 
!     if( $page == 'comment.php' ) 
!     {
!         $commentbar->set_var( 'parent_url', 
!                               $_CONF['site_url'] . '/comment.php' );
!         $hidden = '';
!         if( $_REQUEST['mode'] == 'view' )
!         {
!             $hidden .= '<input type="hidden" name="cid" value="' . $_REQUEST['cid'] . '">';
!             $hidden .= '<input type="hidden" name="pid" value="' . $_REQUEST['cid'] . '">';
!         }
!         else if( $_REQUEST['mode'] == 'display' )
!         {
!             $hidden .= '<input type="hidden" name="pid" value="' . $_REQUEST['pid'] . '">';
!         }
!         else /* This is likely a plugin (or a mistake) */
!         {
!             $hidden .= '<input type="hidden" name="cid" value="' . $sid . '">';
!         }
!         $commentbar->set_var( 'hidden_field', $hidden . 
!                 '<input type="hidden" name="mode" value="' . $_REQUEST['mode'] . '">' );
!     }
!     else if( $type == 'poll' )
!     {
!         $commentbar->set_var( 'parent_url', 
!                               $_CONF['site_url'] . '/pollbooth.php' );
!         $commentbar->set_var( 'hidden_field',         
!                 '<input type="hidden" name="scale" value="400">' .
!                 '<input type="hidden" name="qid" value="' . $sid . '">' .
!                 '<input type="hidden" name="aid" value="-1">' );
!     }
!     else
!     {
!         $commentbar->set_var( 'parent_url',
!                               $_CONF['site_url'] . '/article.php' );
!         $commentbar->set_var( 'hidden_field',
!                 '<input type="hidden" name="story" value="' . $sid . '">' );
!     }
! 
!     // Order
!     $selector = '<select name="order">' . LB
!               . COM_optionList( $_TABLES['sortcodes'], 'code,name', $order )
!               . LB . '</select>';
!     $commentbar->set_var( 'order_selector', $selector);
! 
!     // Mode
!     if( $page == 'comment.php' ) 
!     {
!         $selector = '<select name="format">';
!     }
!     else
!     {
!         $selector = '<select name="mode">';
!     }
!     $selector .= LB
!                . COM_optionList( $_TABLES['commentmodes'], 'mode,name', $mode )
!                . LB . '</select>';
!     $commentbar->set_var( 'mode_selector', $selector);
! 
!     return $commentbar->finish( $commentbar->parse( 'output', 'commentbar' ));
! }    
! 
! 
! /**
! * This function prints &$comments (db results set of comments) in comment format
! * -For previews, &$comments is assumed to be an associative array containing
! *  data for a single comment.
! * 
! * @param     array      &$comments Database result set of comments to be printed
! * @param     string     $mode      'flat', 'threaded', etc
! * @param     string     $type      Type of item (article, poll, etc.)
! * @param     string     $order     How to order the comments 'ASC' or 'DESC'
! * @param     boolean    $delete_option   if current user can delete comments
! * @param     boolean    $preview   Preview display (for edit) or not
! * @return    string     HTML       Formated Comment 
! *
! */
! function COM_getComment( &$comments, $mode, $type, $order, $delete_option = false, $preview = false )
! {
!     global $_CONF, $_TABLES, $_USER, $LANG01, $query;
! 
!     $indent = 0;  // begin with 0 indent
!     $level = array(); // used to track depth
!     $retval = ''; // initialize return value
! 
!     $template = new Template( $_CONF['path_layout'] . 'comment' );
!     $template->set_file( array( 'comment' => 'comment.thtml',
!                                 'thread'  => 'thread.thtml'  ));
! 
!     // generic template variables
!     $template->set_var( 'site_url', $_CONF['site_url'] );
!     $template->set_var( 'layout_url', $_CONF['layout_url'] );
!     $template->set_var( 'lang_replytothis', $LANG01[43] );
!     $template->set_var( 'lang_reply', $LANG01[25] );
!     $template->set_var( 'lang_authoredby', $LANG01[42] );
!     $template->set_var( 'lang_on', $LANG01[36] );
!     $template->set_var( 'order', $order );    
! 
!     // Make sure we have a default value for comment indentation
!     if( !isset( $_CONF['comment_indent'] ))
!     {
!         $_CONF['comment_indent'] = 25;
!     }
! 
!     if( $preview )
!     {
!         $A = $comments;   
!         $mode = 'flat';
!     }
!     else
!     {
!         $A = DB_fetchArray($comments);
!     }
! 
!     if( empty( $A ) )
!     {
!         return '';
!     }
! 
!     do
!     {
!         // determines indentation for current comment
!         if( $mode == 'threaded' || $mode == 'nested' )
!         {
!             $indent = ($A['indent'] - $A['pindent']) * $_CONF['comment_indent'];
!         }
! 
!         // comment variables
!         $template->set_var( 'indent', $indent );
!         $template->set_var( 'author', $A['username'] );
!         $template->set_var( 'author_id', $A['uid'] );
! 
!         if( $A['uid'] > 1 )
!         {
!             if( empty( $A['fullname'] ))
!             {
!                 $template->set_var( 'author_fullname', $A['username'] );
!                 $alttext = $A['username'];
!             }
!             else
!             {
!                 $template->set_var( 'author_fullname', $A['fullname'] );
!                 $alttext = $A['fullname'];
!             }
! 
!             if( !empty( $A['photo'] ))
!             {
!                 $template->set_var( 'author_photo', '<img src="'
!                                     . $_CONF['site_url']
!                                     . '/images/userphotos/' . $A['photo']
!                                     . '" alt="' . $alttext . '">' );
!                 $template->set_var( 'camera_icon', '<a href="'
!                         . $_CONF['site_url']
!                         . '/users.php?mode=profile&uid=' . $A['uid']
!                         . '"><img src="' . $_CONF['layout_url']
!                         . '/images/smallcamera.gif" border="0" alt=""></a>' );
!             }
!             else
!             {
!                 $template->set_var( 'author_photo', '' );
!                 $template->set_var( 'camera_icon', '' );
!             }
! 
!             $template->set_var( 'start_author_anchortag', '<a href="'
!                     . $_CONF['site_url'] . '/users.php?mode=profile&uid='
!                     . $A['uid'] . '">' );
!             $template->set_var( 'end_author_anchortag', '</a>' );
!         }
!         else
!         {
!             $template->set_var( 'author_fullname', $A['username'] );
!             $template->set_var( 'author_photo', '' );
!             $template->set_var( 'camera_icon', '' );
!             $template->set_var( 'start_author_anchortag', '' );
!             $template->set_var( 'end_author_anchortag', '' );
!         }
! 
!         // hide reply link from anonymous users if they can't post replies
!         $hidefromanon = false;
!         if( empty( $_USER['username'] ) && (( $_CONF['loginrequired'] == 1 ) || ( $_CONF['commentsloginrequired'] == 1 )))
!         {
!             $hidefromanon = true;
!         }
! 
!         // this will hide HTML that should not be viewed in preview mode
!         if( $preview || $hidefromanon )
!         {
!             $template->set_var( 'hide_if_preview', 'style="display:none"' );
!         }
!         else
!         {
!             $template->set_var( 'hide_if_preview', '' );
!         }
! 
!         // for threaded mode, add a link to comment parent
!         if( $mode == 'threaded' && $A['pid'] != 0 && $indent == 0 )
!         {
!             $result = DB_query( "SELECT title,pid from {$_TABLES['comments']} where cid = '{$A['pid']}'" );
!             $P = DB_fetchArray( $result );
!             if ($P['pid'] != 0) {
!                 $plink = $_CONF['site_url'] . '/comment.php?mode=display&sid='
!                        . $A['sid'] . '&title=' . rawurlencode( $P['title'] )
!                        . '&type=' . $type . '&order=' . $order . '&pid='
!                        . $P['pid'];
!             } else {
!                 $plink = $_CONF['site_url'] . '/comment.php?mode=view&sid='
!                        . $A['sid'] . '&title=' . rawurlencode( $P['title'] )
!                        . '&type=' . $type . '&order=' . $order . '&cid='
!                        . $A['pid'] . '&format=threaded';
!             }
!             $template->set_var( 'parent_link', "| <a href=\"$plink\">{$LANG01[44]}</a>");
!         }
!         else
!         {
!             $template->set_var( 'parent_link', '');
!         }
! 
!         $template->set_var( 'date', strftime( $_CONF['date'], $A['nice_date'] ));
!         $template->set_var( 'sid', $A['sid'] );
!         $template->set_var( 'type', $A['type'] );
! 
!         // If deletion is allowed, displays delete link
!         if( $delete_option )
!         {
!             $deloption = '| <a href="' . $_CONF['site_url']
!                        . '/comment.php?mode=delete&cid='
!                        . $A['cid'] . '&sid=' . $A['sid'] . '&type='
!                        . $type . '">' . $LANG01[28] . '</a> ';
!             if( !empty( $A['ipaddress'] ))
!             {
!                 if( empty( $_CONF['ip_lookup'] ))
!                 {
!                     $deloption .= '| ' . $A['ipaddress'] . ' ';
!                 }
!                 else
!                 {
!                     $iplookup = str_replace( '*', $A['ipaddress'],
!                                              $_CONF['ip_lookup'] );
!                     $deloption .= '| <a href="' . $iplookup . '">'
!                                . $A['ipaddress'] . '</a> ';
!                 }
!             }
!             $template->set_var( 'delete_option', $deloption );
!         }
!         else if( !empty( $_USER['username'] ))
!         {
!             $reportthis = ' | <a href="' . $_CONF['site_url']
!                         . '/comment.php?mode=report&cid=' . $A['cid']
!                         . '&type=' . $type . '" title="' . $LANG01[110]
!                         . '">' . $LANG01[109] . '</a> ';
!             $template->set_var( 'delete_option', $reportthis );
!         }
!         else
!         {
!             $template->set_var( 'delete_option', '' );
!         }
! 
!         $A['title'] = stripslashes( $A['title'] );
!         $A['title'] = htmlspecialchars( $A['title'] );
!         $A['title'] = str_replace( '$', '$', $A['title'] );
! 
!         // and finally: format the actual text of the comment
!         $A['comment'] = stripslashes( $A['comment'] );
!         if( preg_match( '/<.*>/', $A['comment'] ) == 0 )
!         {
!             $A['comment'] = nl2br( $A['comment'] );
!         }
! 
!         // highlight search terms if specified
!         if( !empty( $query ))
!         {
!             $A['comment'] = COM_highlightQuery( $A['comment'], $query );
!         }
! 
!         $A['comment'] = str_replace( '$', '$',  $A['comment'] );
!         $A['comment'] = str_replace( '{', '{', $A['comment'] );
!         $A['comment'] = str_replace( '}', '}', $A['comment'] );
! 
!         // Replace any plugin autolink tags
!         $A['comment'] = PLG_replaceTags( $A['comment'] );
! 
!         $template->set_var( 'title', $A['title'] );
!         $template->set_var( 'comments', $A['comment'] );
! 
!         // parse the templates
!         if( $mode == 'threaded' && $indent > 0 )
!         {
!             $template->set_var( 'pid', $A['pid'] );
!             $retval .= $template->parse( 'output', 'thread' );   
!         }
!         else
!         {
!             $template->set_var( 'pid', $A['cid'] );
!             $retval .= $template->parse( 'output', 'comment' ); 
!         }
!     }
!     while( $A = DB_fetchArray( $comments ));
! 
!     return $retval;
! }
! 
! /**
! * This function displays the comments in a high level format.
! *
! * Begins displaying user comments for an item
! *
! * @param        string      $sid       ID for item to show comments for
! * @param        string      $title     Title of item
! * @param        string      $type      Type of item (article, poll, etc.)
! * @param        string      $order     How to order the comments 'ASC' or 'DESC'
! * @param        string      $mode      comment mode (nested, flat, etc.)
! * @param        int         $pid       id of parent comment
! * @param        int         $page      page number of comments to display
! * @param        boolean     $cid       true if $pid should be interpreted as a cid instead
! * @param        boolean     $delete_option   if current user can delete comments
! * @see function COM_commentBar
! * @see function COM_commentChildren
! * @return     string  HTML Formated Comments
! *
! */
! function COM_userComments( $sid, $title, $type='article', $order='', $mode='', $pid = 0, $page = 1, $cid = false, $delete_option = false )
! {
!     global $_CONF, $_TABLES, $_USER, $LANG01;
! 
!     if( !empty( $_USER['uid'] ) )
!     {
!         $result = DB_query( "SELECT commentorder,commentmode,commentlimit FROM {$_TABLES['usercomment']} WHERE uid = '{$_USER['uid']}'" );
!         $U = DB_fetchArray( $result );
!         if( empty( $order ) ) 
!         {
!             $order = $U['commentorder'];
!         }
!         if( empty( $mode ) ) 
!         {
!             $mode = $U['commentmode'];
!         }
!         $limit = $U['commentlimit'];
!     }
! 
!     if( empty( $order ))
!     {
!         $order = 'ASC';
!     }
! 
!     if( empty( $mode ))
!     {
!         $mode = $_CONF['comment_mode'];
!     }
! 
!     if( empty( $limit ))
!     {
!         $limit = $_CONF['comment_limit'];
!     }
!     
!     if( !is_numeric($page) || $page < 1 )
!     {
!         $page = 1;
!     }
! 
!     $start = $limit * ( $page - 1 );
! 
!     $template = new Template( $_CONF['path_layout'] . 'comment' );
!     $template->set_file( array( 'commentarea' => 'startcomment.thtml' ));
!     $template->set_var( 'site_url', $_CONF['site_url'] );
!     $template->set_var( 'layout_url', $_CONF['layout_url'] );
!     $template->set_var( 'commentbar',
!                         COM_commentBar( $sid, $title, $type, $order, $mode));
!     
!     if( $mode == 'nested' or $mode == 'threaded' or $mode == 'flat' )
!     {
!         // build query
!         switch( $mode )
!         {
!             case 'flat':
!                 if( $cid )
!                 {
!                     $count = 1;
! 
!                     $q = "SELECT c.*, u.username, u.fullname, u.photo, " 
!                          . "unix_timestamp(c.date) AS nice_date "
!                        . "FROM {$_TABLES['comments']} as c, {$_TABLES['users']} as u "
!                        . "WHERE c.uid = u.uid AND c.cid = $pid";
!                 }
!                 else
!                 {
!                     $count = DB_count( $_TABLES['comments'], 'sid', $sid );
!             
!                     $q = "SELECT c.*, u.username, u.fullname, u.photo, " 
!                          . "unix_timestamp(c.date) AS nice_date "
!                        . "FROM {$_TABLES['comments']} as c, {$_TABLES['users']} as u "
!                        . "WHERE c.uid = u.uid AND c.sid = '$sid' "
!                        . "ORDER BY date $order LIMIT $start, $limit";
!                 }
!                 break;
! 
!             case 'nested':
!             case 'threaded':
!             default:
!                 if( $order == 'DESC' )
!                 {
!                     $cOrder = 'c.rht DESC';
!                 }
!                 else
!                 {
!                     $cOrder = 'c.lft ASC'; 
!                 }                            
! 
!                 // We can simplify the query, and hence increase performance
!                 // when pid = 0 (when fetching all the comments for a given sid)
!                 if( $cid )
!                 {
!                     // count the total number of applicable comments
!                     $q2 = "SELECT COUNT(*) "
!                         . "FROM {$_TABLES['comments']} as c, {$_TABLES['comments']} as c2 "
!                         . "WHERE c.sid = '$sid' AND (c.lft >= c2.lft AND c.lft <= c2.rht) "
!                         . "AND c2.cid = $pid";
!                     $result = DB_query( $q2 );
!                     list( $count ) = DB_fetchArray( $result );
! 
!                     $q = "SELECT c.*, u.username, u.fullname, u.photo, c2.indent as pindent, " 
!                          . "unix_timestamp(c.date) AS nice_date "
!                        . "FROM {$_TABLES['comments']} as c, {$_TABLES['comments']} as c2, "
!                          . "{$_TABLES['users']} as u "
!                        . "WHERE c.sid = '$sid' AND (c.lft >= c2.lft AND c.lft <= c2.rht) "
!                          . "AND c2.cid = $pid AND c.uid = u.uid "
!                        . "ORDER BY $cOrder LIMIT $start, $limit";
!                 }
!                 else
!                 {
!                     if( $pid == 0 )
!                     {
!                         // count the total number of applicable comments
!                         $count = DB_count( $_TABLES['comments'], 'sid', $sid );
! 
!                         $q = "SELECT c.*, u.username, u.fullname, u.photo, 0 as pindent, " 
!                              . "unix_timestamp(c.date) AS nice_date "
!                            . "FROM {$_TABLES['comments']} as c, {$_TABLES['users']} as u "
!                            . "WHERE c.sid = '$sid' AND c.uid = u.uid "
!                            . "ORDER BY $cOrder LIMIT $start, $limit";
!                     }
!                     else
!                     {
!                         // count the total number of applicable comments
!                         $q2 = "SELECT COUNT(*) "
!                             . "FROM {$_TABLES['comments']} as c, {$_TABLES['comments']} as c2 "
!                             . "WHERE c.sid = '$sid' AND (c.lft > c2.lft AND c.lft < c2.rht) "
!                             . "AND c2.cid = $pid";
!                         $result = DB_query($q2);
!                         list($count) = DB_fetchArray($result);
! 
!                         $q = "SELECT c.*, u.username, u.fullname, u.photo, c2.indent + 1 as pindent, " 
!                              . "unix_timestamp(c.date) AS nice_date "
!                            . "FROM {$_TABLES['comments']} as c, {$_TABLES['comments']} as c2, "
!                              . "{$_TABLES['users']} as u "
!                            . "WHERE c.sid = '$sid' AND (c.lft > c2.lft AND c.lft < c2.rht) "
!                              . "AND c2.cid = $pid AND c.uid = u.uid "
!                            . "ORDER BY $cOrder LIMIT $start, $limit";
!                     }
!                 }
!                 break;
!         }
! 
!         $thecomments = '';
!         $result = DB_query( $q );
!         $thecomments .= COM_getComment( $result, $mode, $type, $order,
!                                         $delete_option );
!         
!         // Pagination
!         $tot_pages =  ceil( $count / $limit );
!         $pLink = $_CONF['site_url'] . "/article.php?story=$sid&type=$type&order=$order&mode=$mode";
!         $template->set_var( 'pagenav',
!                          COM_printPageNavigation($pLink, $page, $tot_pages));
!         
!         $template->set_var( 'comments', $thecomments );
!         $retval = $template->parse( 'output', 'commentarea' );
!     }
  
!     return $retval;
  }
  
--- 2630,2640 ----
  
  /**
!  * DEPRECIATED -- see CMT_userComments in lib-comment.php
!  */
! function COM_userComments( $sid, $title, $type='article', $order='', $mode='', $pid = 0, $page = 1, $cid = false, $delete_option = false ) {
!     global $_CONF;
  
!     require_once $_CONF['path_system'] . 'lib-comment.php';
!     return CMT_userComments( $sid, $title, $type, $order, $mode, $pid, $page, $cid, $delete_option );
  }
  

Index: article.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/public_html/article.php,v
retrieving revision 1.58
retrieving revision 1.59
diff -C2 -d -r1.58 -r1.59
*** article.php	16 Jan 2005 19:14:28 -0000	1.58
--- article.php	21 Jan 2005 23:31:44 -0000	1.59
***************
*** 243,248 ****
                  $delete_option = (SEC_hasRights('story.edit') && ($access == 3)
                                   ? true : false);
                  $story_template->set_var ('commentbar',
!                         COM_userComments ($story, $A['title'], 'article',
                                            $order, $mode, 0, $page, false, $delete_option));
              }
--- 243,249 ----
                  $delete_option = (SEC_hasRights('story.edit') && ($access == 3)
                                   ? true : false);
+                 require_once ( $_CONF['path_system'] . 'lib-comment.php' );
                  $story_template->set_var ('commentbar',
!                         CMT_userComments ($story, $A['title'], 'article',
                                            $order, $mode, 0, $page, false, $delete_option));
              }




More information about the geeklog-cvs mailing list