2006-12-02 04:36:16 +00:00
< ? php
/*
2010-08-23 07:28:46 +00:00
* e107 website system
*
* Copyright ( C ) 2002 - 2010 e107 Inc ( e107 . org )
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
2019-10-11 17:19:48 +02:00
* Comment handler class - This class handles all comment - related functions .
2010-08-23 07:28:46 +00:00
*
2009-08-24 18:36:07 +00:00
*/
2010-08-23 07:28:46 +00:00
2009-08-24 18:36:07 +00:00
if ( ! defined ( 'e107_INIT' ))
{
exit ;
}
2019-10-11 17:19:48 +02:00
2017-01-23 09:41:23 -08:00
e107 :: includeLan ( e_LANGUAGEDIR . e_LANGUAGE . " /lan_comment.php " );
2007-06-05 18:54:56 +00:00
global $comment_shortcodes ;
2010-02-10 21:53:56 +00:00
require_once ( e_CORE . " shortcodes/batch/comment_shortcodes.php " );
2009-08-24 18:36:07 +00:00
class comment
{
2009-11-04 03:07:44 +00:00
public $known_types = array (
0 => " news " ,
1 => 'content' ,
2 => 'download' ,
3 => 'faq' ,
4 => 'poll' ,
5 => 'docs' ,
6 => 'bugtrack'
);
2010-02-10 21:53:56 +00:00
2012-06-15 04:15:46 +00:00
private $template ;
2012-06-16 12:41:30 +00:00
private $totalComments = 0 ;
2012-06-18 13:00:47 +00:00
private $moderator = false ;
2012-08-04 21:50:47 +00:00
private $commentsPerPage = 5 ;
private $table = null ;
2012-06-15 04:15:46 +00:00
2015-04-08 14:51:06 -07:00
private $engine = 'e107' ;
2012-06-15 04:15:46 +00:00
function __construct ()
{
2012-06-18 13:00:47 +00:00
2012-08-04 21:50:47 +00:00
if ( getperms ( 'B' )) // moderator perms.
2012-06-18 13:00:47 +00:00
{
$this -> moderator = true ;
}
2015-04-08 14:51:06 -07:00
$this -> engine = e107 :: pref ( 'core' , 'comments_engine' , 'e107' );
2012-08-04 21:50:47 +00:00
//TODO - add a pref for comments per page.
// $this->commentsPerPage = pref;
2012-06-15 04:15:46 +00:00
global $COMMENTSTYLE ;
if ( ! $COMMENTSTYLE )
2013-04-30 17:02:09 -07:00
{
require ( e107 :: coreTemplatePath ( 'comment' )); // using require_once() could cause an empty template if the template is already loaded, for example, by the comment-menu al
2012-06-15 04:15:46 +00:00
}
2012-12-08 15:52:40 +01:00
elseif ( ! vartrue ( $COMMENT_TEMPLATE )) // BC template.
2012-06-15 04:15:46 +00:00
{
2012-06-15 12:50:18 +00:00
global $sc_style ;
/*
$COMMENTSTYLE = "
< table class = 'fborder' style = '".USER_WIDTH."' >
< tr >
< td colspan = '2' class = 'forumheader' >
{ SUBJECT } { USERNAME } { TIMEDATE } { REPLY } { COMMENTEDIT }
</ td >
</ tr >
< tr >
< td style = 'width:30%; vertical-align:top;' >
{ AVATAR } < span class = 'smalltext' > { COMMENTS }{ JOINED } </ span >
</ td >
< td style = 'width:70%; vertical-align:top;' >
{ COMMENT }
{ RATING }
{ IPADDRESS }
{ LEVEL }
{ LOCATION }
{ SIGNATURE }
</ td >
</ tr >
</ table >
< br /> " ;
*/
2013-02-24 01:08:40 -08:00
2012-06-15 04:15:46 +00:00
$COMMENT_TEMPLATE [ 'ITEM' ] = $COMMENTSTYLE ;
2013-02-24 01:08:40 -08:00
2012-08-04 21:50:47 +00:00
$COMMENT_TEMPLATE [ 'LAYOUT' ] = " { COMMENTS} { COMMENTFORM} { MODERATE} { COMMENTNAV} " ;
2012-06-15 12:50:18 +00:00
$COMMENT_TEMPLATE [ 'FORM' ] = " <table style='width:100%'>
{ SUBJECT_INPUT }
{ AUTHOR_INPUT }
{ RATE_INPUT }
{ COMMENT_INPUT }
{ COMMENT_BUTTON }
</ table > " ;
$sc_style [ 'SUBJECT_INPUT' ][ 'pre' ] = " <tr><td style='width:20%'> " . COMLAN_324 . " </td><td style='width:80%'> " ;
$sc_style [ 'SUBJECT_INPUT' ][ 'post' ] = " </td></tr> " ;
$sc_style [ 'AUTHOR_INPUT' ][ 'pre' ] = " <tr><td style='width:20%; vertical-align:top;'> " . COMLAN_16 . " </td><td style='width:80%'> " ;
$sc_style [ 'AUTHOR_INPUT' ][ 'post' ] = " </td></tr> " ;
2015-07-02 14:33:04 +01:00
$sc_style [ 'RATE_INPUT' ][ 'pre' ] = " <tr><td style='width:20%; vertical-align:top;'> " . LAN_RATING . " :</td><td style='width:80%;'> " ;
2012-06-15 12:50:18 +00:00
$sc_style [ 'RATE_INPUT' ][ 'post' ] = " </td></tr> " ;
$sc_style [ 'COMMENT_INPUT' ][ 'pre' ] = " <tr><td style='width:20%; vertical-align:top;'> " . COMLAN_8 . " :</td><td id='commentform' style='width:80%;'> " ;
$sc_style [ 'COMMENT_INPUT' ][ 'post' ] = " </td></tr> " ;
2016-02-13 10:48:36 -08:00
$sc_style [ 'COMMENT_BUTTON' ][ 'pre' ] = " <tr style='vertical-align:top'><td style='width:20%; vertical-align:top;'> </td><td id='commentformbutton' style='width:80%;'> " ;
2012-06-15 12:50:18 +00:00
$sc_style [ 'COMMENT_BUTTON' ][ 'post' ] = " </td></tr> " ;
2012-06-15 04:15:46 +00:00
}
2014-01-01 05:20:46 -08:00
$this -> template = array_change_key_case ( $COMMENT_TEMPLATE );
2012-06-15 04:15:46 +00:00
}
2012-06-17 08:08:01 +00:00
function replyComment ( $id ) // Ajax Reply.
{
2015-04-08 14:51:06 -07:00
if ( $this -> engine != 'e107' )
{
return null ;
}
2012-06-17 08:08:01 +00:00
$sql = e107 :: getDb ();
2019-10-11 17:19:48 +02:00
if ( $sql -> select ( " comments " , " * " , " comment_id= " . intval ( $id ) . " LIMIT 1 " ))
2012-06-17 08:08:01 +00:00
{
2019-10-11 17:19:48 +02:00
$row = $sql -> fetch ();
2012-06-17 08:08:01 +00:00
// [comment_id] => 65
return $this -> form_comment ( 'reply' , $row [ 'comment_type' ], $row [ 'comment_item_id' ], $row [ 'comment_subject' ], false , true , false , false , $id );
}
}
2006-12-02 04:36:16 +00:00
/**
2008-05-25 08:26:11 +00:00
* Display the comment editing form
2006-12-02 04:36:16 +00:00
*
* @ param unknown_type $action
* @ param unknown_type $table
* @ param unknown_type $id
* @ param unknown_type $subject
* @ param unknown_type $content_type
* @ param unknown_type $return
* @ param unknown_type $rating
* @ return unknown
*/
2012-06-17 08:08:01 +00:00
function form_comment ( $action , $table , $id , $subject , $content_type , $return = FALSE , $rating = FALSE , $tablerender = TRUE , $pid = false )
2006-12-02 04:36:16 +00:00
{
//rating : boolean, to show rating system in comment
2015-03-28 14:12:42 -07:00
2012-06-15 12:50:18 +00:00
$pref = e107 :: getPref ();
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2015-04-08 14:51:06 -07:00
if ( vartrue ( $pref [ 'comments_disabled' ]) || $this -> engine != 'e107' )
2008-05-25 08:26:11 +00:00
{
2015-04-08 14:51:06 -07:00
return null ;
2006-12-02 04:36:16 +00:00
}
2011-10-20 22:11:58 +00:00
2015-03-28 14:12:42 -07:00
if ( $user_func = e107 :: getOverride () -> check ( $this , 'form_comment' ))
{
2015-04-08 14:51:06 -07:00
return call_user_func ( $user_func , array ( 'action' => $action , 'table' => $table , 'id' => $id , 'subject' => $subject , 'content_type' => $content_type , 'return' => $return , 'rating' => $rating , 'tablerender' => $tablerender , 'pid' => $pid ));
2015-03-28 14:12:42 -07:00
}
2012-06-15 04:15:46 +00:00
// require_once(e_HANDLER."ren_help.php");
2011-10-20 22:11:58 +00:00
if ( $this -> getCommentPermissions () == 'rw' )
2006-12-02 04:36:16 +00:00
{
2009-08-24 18:36:07 +00:00
$itemid = $id ;
$ns = new e107table ;
if ( $action == " reply " && substr ( $subject , 0 , 4 ) != " Re: " )
2006-12-02 04:36:16 +00:00
{
2009-08-24 18:36:07 +00:00
$subject = COMLAN_325 . ' ' . $subject ;
2008-05-25 08:26:11 +00:00
}
2009-09-14 18:18:36 +00:00
//FIXME - e_REQUEST_URI?
//e_SELF."?".e_QUERY
2012-06-02 08:12:16 +00:00
2012-06-15 12:50:18 +00:00
if ( vartrue ( $_GET [ 'comment' ]) == 'edit' )
2009-08-24 18:36:07 +00:00
{
$eaction = 'edit' ;
$id = $_GET [ 'comment_id' ];
2006-12-02 04:36:16 +00:00
}
2009-08-24 18:36:07 +00:00
elseif ( strpos ( e_QUERY , 'edit.' ) !== FALSE )
{
$eaction = 'edit' ;
$tmp = explode ( " . " , e_QUERY );
$count = 0 ;
2011-10-20 22:11:58 +00:00
2009-08-24 18:36:07 +00:00
foreach ( $tmp as $t )
{
if ( $t == " edit " )
{
$id = $tmp [( $count + 1 )];
break ;
}
$count ++ ;
}
}
if ( isset ( $eaction ) && $eaction == " edit " )
{ // Get existing comment
$id = intval ( $id );
2019-10-11 17:19:48 +02:00
$sql -> select ( " comments " , " * " , " comment_id=' { $id } ' " );
$ecom = $sql -> fetch ();
2009-08-24 18:36:07 +00:00
if ( isset ( $ecom [ 'comment_author' ]))
{ // Old comment DB format
list ( $prid , $pname ) = explode ( " . " , $ecom [ 'comment_author' ], 2 );
}
else
{
$prid = $ecom [ 'comment_author_id' ];
$pname = $ecom [ 'comment_author_name' ];
}
if ( $prid != USERID || ! USER )
{ // Editing not allowed
echo " <div style='text-align: center;'> " . COMLAN_329 . " </div> " ;
2011-10-20 22:11:58 +00:00
require_once ( FOOTERF );
2009-08-24 18:36:07 +00:00
exit ;
}
$caption = COMLAN_318 ;
$comval = $tp -> toForm ( $ecom [ 'comment_comment' ]);
$comval = preg_replace ( " # \ [ " . COMLAN_319 . " .* \ ]#si " , " " , $comval );
}
else
{ // New comment - blank form
$caption = COMLAN_9 ;
$comval = " " ;
}
2011-10-20 22:11:58 +00:00
2009-08-24 18:36:07 +00:00
//add the rating select box/result ?
2012-06-16 05:04:22 +00:00
/*
2009-08-24 18:36:07 +00:00
$rate = " " ;
if ( $rating == TRUE && ! ( ANON == TRUE && USER == FALSE ))
{
global $rater ;
2011-10-20 22:11:58 +00:00
require_once ( e_HANDLER . " rate_class.php " );
2009-08-24 18:36:07 +00:00
if ( ! is_object ( $rater ))
{
$rater = new rater ;
}
$rate = $rater -> composerating ( $table , $itemid , $enter = TRUE , USERID , TRUE );
2012-06-15 12:50:18 +00:00
2012-06-02 08:12:16 +00:00
2009-08-24 18:36:07 +00:00
} //end rating area
2012-06-16 05:04:22 +00:00
*/
2012-06-02 08:12:16 +00:00
2012-06-15 12:50:18 +00:00
// -------------------------------------------------------------
2012-06-02 08:12:16 +00:00
2015-02-04 12:43:52 -08:00
$indent = ( $action == 'reply' ) ? " class='media col-md-offset-1 offset1' " : " class='media' " ;
2012-06-17 08:08:01 +00:00
$formid = ( $action == 'reply' ) ? " e-comment-form-reply " : " e-comment-form " ;
2013-09-26 16:11:41 +02:00
$text = " \n <div { $indent } > \n " . e107 :: getMessage () -> render ( 'postcomment' , true , false , false ); //temporary here
2013-03-29 15:31:03 -07:00
// $text .= "Indent = ".$indent;
2012-06-17 08:08:01 +00:00
$text .= " <form id=' { $formid } ' method='post' action=' " . str_replace ( 'http:' , '' , $_SERVER [ 'REQUEST_URI' ]) . " ' > " ;
2012-06-15 12:50:18 +00:00
$data = array (
'action' => $action ,
'subject' => $subject ,
'table' => $table ,
'comval' => strip_tags ( trim ( $comval )),
'itemid' => $itemid ,
2012-06-17 08:08:01 +00:00
'pid' => $pid ,
2012-08-04 21:50:47 +00:00
'eaction' => varset ( $eaction ),
'rate' => $rating
2012-06-15 12:50:18 +00:00
);
2012-06-02 08:12:16 +00:00
2012-11-02 00:23:59 +00:00
e107 :: getScBatch ( 'comment' ) -> setVars ( $data );
2012-06-02 08:12:16 +00:00
2012-06-15 12:50:18 +00:00
e107 :: getScBatch ( 'comment' ) -> setMode ( 'edit' );
2014-01-01 05:20:46 -08:00
$text .= $tp -> parseTemplate ( $this -> template [ 'form' ], TRUE , e107 :: getScBatch ( 'comment' ));
2012-06-02 08:12:16 +00:00
2012-06-17 08:08:01 +00:00
$text .= " \n <div> \n " ; // All Hidden Elements.
2012-06-02 08:12:16 +00:00
2012-06-17 08:08:01 +00:00
$text .= ( varset ( $action ) == " reply " && $pid ? " <input type='hidden' name='pid' value=' { $pid } ' /> " : '' );
2012-06-15 12:50:18 +00:00
$text .= ( isset ( $eaction ) && $eaction == " edit " ? " <input type='hidden' name='editpid' value=' { $id } ' /> " : " " );
$text .= ( isset ( $content_type ) && $content_type ? " <input type='hidden' name='content_type' value=' { $content_type } ' /> " : '' );
2012-06-17 03:56:42 +00:00
// $text .= (!$pref['nested_comments']) ? "<input type='hidden' name='subject' value='".$tp->toForm($subject)."' />\n" : "";
2012-06-16 12:41:30 +00:00
2012-06-15 12:50:18 +00:00
$text .= "
2012-06-17 03:56:42 +00:00
< input type = 'hidden' name = 'subject' value = '".$tp->toForm($subject)."' />
2013-06-19 23:52:14 -07:00
< input type = 'hidden' name = 'e-token' value = '".e_TOKEN."' />
< input type = 'hidden' name = 'table' value = '".$table."' />
< input type = 'hidden' name = 'itemid' value = '".$itemid."' />
2012-06-02 08:12:16 +00:00
</ div >
2012-06-17 08:08:01 +00:00
</ form > \n " ;
$text .= " </div> " ;
2012-06-02 08:12:16 +00:00
2009-08-24 18:36:07 +00:00
if ( $tablerender )
{
$text = $ns -> tablerender ( $caption , $text , '' , TRUE );
}
2010-02-14 11:25:50 +00:00
}
else
{ // Comment entry not allowed - point to signup link
2016-03-13 17:57:51 -07:00
$userReg = intval ( e107 :: pref ( 'core' , 'user_reg' ));
$socialLogin = e107 :: pref ( 'core' , 'social_login_active' );
$text = " <div class='comments-form-login'> " ;
$srch = array ( " [ " , " ] " );
if ( ! empty ( $userReg ) || ! empty ( $socialLogin ))
{
$COMLAN_500 = COMLAN_500 ; // Please [sign in] to leave a comment.
$repl = array ( " <a href=' " . e_LOGIN . " '> " , " </a> " );
$text .= " <div> " . str_replace ( $srch , $repl , $COMLAN_500 ) . " </div> " ;
if ( ! empty ( $socialLogin ))
{
$text .= $tp -> parseTemplate ( " { SOCIAL_LOGIN} " , true );
// $text .= "<br />";
}
}
if ( $userReg === 1 )
{
$COMLAN_501 = COMLAN_501 ; // If you are not yet registered, you may [click here to register].
$repl = array ( " <a href=' " . e_SIGNUP . " '> " , " </a> " );
$text .= " <div> " . str_replace ( $srch , $repl , $COMLAN_501 ) . " </div> " ;
}
$text .= " </div> " ;
// $text = "<br /><div style='text-align:center'><b>".COMLAN_6." <a href='".e_SIGNUP."'>".COMLAN_321."</a> ".COMLAN_322."</b></div>";
2010-02-14 11:25:50 +00:00
}
2016-03-13 17:57:51 -07:00
2011-10-20 22:11:58 +00:00
if ( $return )
{
return $text ;
}
else
{
echo $text ;
}
2006-12-02 04:36:16 +00:00
}
2011-10-20 22:11:58 +00:00
2012-08-04 21:50:47 +00:00
/**
* Check if comment is pending approval .
* @ param array - a row from the comments table .
* @ return boolean True / False
*/
private function isPending ( $row )
2012-06-18 13:00:47 +00:00
{
if ( $row [ 'comment_blocked' ] > 0 && ( $row [ 'comment_author_id' ] != USERID || ( $row [ 'comment_author_id' ] == 0 && $row [ 'comment_author_name' ] != $_SESSION [ 'comment_author_name' ])) && $this -> moderator == false )
{
$this -> totalComments = $this -> totalComments - 1 ;
return true ;
}
return false ;
}
2006-12-02 04:36:16 +00:00
/**
2012-08-04 21:50:47 +00:00
* Render a single comment and any nested comments it may have .
2006-12-02 04:36:16 +00:00
*
2012-08-04 21:50:47 +00:00
* @ param array $row
* @ param string $table
* @ param string $action
* @ param integer $id
* @ param interger $width
* @ param string $subject
* @ param integer $addrating
* @ return html
2006-12-02 04:36:16 +00:00
*/
2009-08-24 18:36:07 +00:00
function render_comment ( $row , $table , $action , $id , $width , $subject , $addrating = FALSE )
2008-05-24 12:45:34 +00:00
{
2015-03-28 14:12:42 -07:00
2015-04-08 14:51:06 -07:00
if ( $this -> engine != 'e107' )
{
return null ;
}
2015-03-28 14:12:42 -07:00
if ( $user_func = e107 :: getOverride () -> check ( $this , 'render_comment' ))
{
2015-04-08 14:51:06 -07:00
return call_user_func ( $user_func , array ( 'row' => $row , 'table' => $table , 'action' => $action , 'id' => $id , 'width' => $width , 'subject' => $subject , 'addrating' => $addrating ));
2015-03-28 14:12:42 -07:00
}
2006-12-02 04:36:16 +00:00
//addrating : boolean, to show rating system in rendered comment
2012-06-16 05:04:22 +00:00
global $sc_style , $gen ;
2012-06-15 04:15:46 +00:00
2012-06-16 05:04:22 +00:00
$tp = e107 :: getParser ();
$sql = e107 :: getDb ();
$pref = e107 :: getPref ();
2012-06-15 04:15:46 +00:00
2012-06-15 12:50:18 +00:00
if ( vartrue ( $pref [ 'comments_disabled' ]))
2008-05-24 12:45:34 +00:00
{
2009-08-24 18:36:07 +00:00
return ;
2006-12-02 04:36:16 +00:00
}
2012-06-16 05:04:22 +00:00
global $NEWIMAGE , $USERNAME , $RATING , $datestamp ;
global $thisaction , $thistable , $thisid , $e107 ;
$comrow = $row ;
$thistable = $table ;
$thisid = $id ;
$thisaction = $action ;
2010-04-24 11:48:19 +00:00
//FIXME - new level handler, currently commented to avoid parse errors
//require_once (e_HANDLER."level_handler.php");
2012-06-16 05:04:22 +00:00
2009-08-24 18:36:07 +00:00
if ( ! $width )
{
2006-12-02 04:36:16 +00:00
$width = 0 ;
}
2009-08-24 18:36:07 +00:00
if ( ! defined ( " IMAGE_nonew_comments " ))
{
2009-07-07 06:50:56 +00:00
define ( " IMAGE_nonew_comments " , ( file_exists ( THEME . " images/nonew_comments.png " ) ? " <img src=' " . THEME_ABS . " images/nonew_comments.png' alt='' /> " : " <img src=' " . e_IMAGE_ABS . " generic/nonew_comments.png' alt='' /> " ));
2006-12-02 04:36:16 +00:00
}
2009-08-24 18:36:07 +00:00
if ( ! defined ( " IMAGE_new_comments " ))
{
2009-07-07 06:50:56 +00:00
define ( " IMAGE_new_comments " , ( file_exists ( THEME . " images/new_comments.png " ) ? " <img src=' " . THEME_ABS . " images/new_comments.png' alt='' /> " : " <img src=' " . e_IMAGE_ABS . " generic/new_comments.png' alt='' /> " ));
2006-12-02 04:36:16 +00:00
}
2012-06-15 04:15:46 +00:00
2012-06-15 12:50:18 +00:00
// $ns = new e107table;
2012-06-15 04:15:46 +00:00
2009-08-24 18:36:07 +00:00
if ( ! $gen || ! is_object ( $gen ))
{
$gen = new convert ;
2012-06-15 12:50:18 +00:00
}
2012-06-15 04:15:46 +00:00
2012-06-16 05:04:22 +00:00
$row [ 'rating_enabled' ] = true ; // Toggles rating shortcode. //TODO add pref
2012-11-02 00:23:59 +00:00
e107 :: getScBatch ( 'comment' ) -> setVars ( $row );
2012-08-04 21:50:47 +00:00
2015-02-04 19:04:28 -08:00
2012-08-04 21:50:47 +00:00
$COMMENT_TEMPLATE = $this -> template ;
2012-06-18 09:06:20 +00:00
2013-02-24 01:08:40 -08:00
// $COMMENT_TEMPLATE['ITEM_START'] = "\n\n<div id='{COMMENT_ITEMID}' class='comment-box clearfix'>\n";
// $COMMENT_TEMPLATE['ITEM_END'] = "\n</div><div class='clear_b'><!-- --></div>\n";
//XXX Do NOT add to template - too important to allow for modification.
2014-01-01 05:20:46 -08:00
$COMMENT_TEMPLATE [ 'item_start' ] = " \n \n <li id=' { COMMENT_ITEMID}' class='media comment-box clearfix'> \n " ;
$COMMENT_TEMPLATE [ 'item_end' ] = " \n </li> \n " ;
if ( defset ( 'BOOTSTRAP' ) === 2 || defset ( 'BOOTSTRAP' ) === true ) // Convert Bootstrap3 to Bootstrap 2 when detected.
{
$COMMENT_TEMPLATE [ 'item' ] = str_replace ( " row " , " row-fluid " , $COMMENT_TEMPLATE [ 'item' ]);
}
2016-03-16 09:21:12 -07:00
e107 :: getParser () -> setThumbSize ( 100 , 100 ); // BC FIx. Set a default image size, in case the template doesn't have one.
2012-06-16 05:04:22 +00:00
if ( vartrue ( $pref [ 'nested_comments' ]))
2008-05-24 12:45:34 +00:00
{
2013-03-29 15:31:03 -07:00
// $width2 = 100 - $width;
// $total_width = "95%";
2009-08-24 18:36:07 +00:00
if ( $width )
2012-06-15 12:50:18 +00:00
{
2014-01-01 05:20:46 -08:00
$renderstyle = $COMMENT_TEMPLATE [ 'item_start' ];
$renderstyle .= " <div class='media offset " . $width . " col-md-offset- " . $width . " ' > " . $COMMENT_TEMPLATE [ 'item' ] . " </div> " ;
$renderstyle .= $COMMENT_TEMPLATE [ 'item_end' ];
2009-08-24 18:36:07 +00:00
}
else
{
2012-06-15 04:15:46 +00:00
2014-01-01 05:20:46 -08:00
$renderstyle = $COMMENT_TEMPLATE [ 'item_start' ] . $COMMENT_TEMPLATE [ 'item' ] . $COMMENT_TEMPLATE [ 'item_end' ];
2012-06-15 04:15:46 +00:00
2006-12-02 04:36:16 +00:00
}
2009-08-24 18:36:07 +00:00
if ( $pref [ 'comments_icon' ])
{
if ( $comrow [ 'comment_datestamp' ] > USERLV )
{
2006-12-02 04:36:16 +00:00
$NEWIMAGE = IMAGE_new_comments ;
2009-08-24 18:36:07 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
$NEWIMAGE = IMAGE_nonew_comments ;
}
2009-08-24 18:36:07 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
$NEWIMAGE = " " ;
}
2009-08-24 18:36:07 +00:00
}
else
{
2014-01-01 05:20:46 -08:00
$renderstyle = $COMMENT_TEMPLATE [ 'item' ];
2006-12-02 04:36:16 +00:00
}
$highlight_search = FALSE ;
2012-06-15 04:15:46 +00:00
2009-08-24 18:36:07 +00:00
if ( isset ( $_POST [ 'highlight_search' ]))
{
2006-12-02 04:36:16 +00:00
$highlight_search = TRUE ;
}
2012-06-15 04:15:46 +00:00
2009-08-24 18:36:07 +00:00
if ( ! defined ( " IMAGE_rank_main_admin_image " ))
{
2009-10-09 15:05:12 +00:00
define ( " IMAGE_rank_main_admin_image " , ( isset ( $pref [ 'rank_main_admin_image' ]) && $pref [ 'rank_main_admin_image' ] && file_exists ( THEME . " forum/ " . $pref [ 'rank_main_admin_image' ]) ? " <img src=' " . THEME_ABS . " forum/ " . $pref [ 'rank_main_admin_image' ] . " ' alt='' /> " : " <img src=' " . e_PLUGIN_ABS . " forum/images/lite/main_admin.png' alt='' /> " ));
2006-12-02 04:36:16 +00:00
}
2009-08-24 18:36:07 +00:00
if ( ! defined ( " IMAGE_rank_moderator_image " ))
{
2009-10-09 15:05:12 +00:00
define ( " IMAGE_rank_moderator_image " , ( isset ( $pref [ 'rank_moderator_image' ]) && $pref [ 'rank_moderator_image' ] && file_exists ( THEME . " forum/ " . $pref [ 'rank_moderator_image' ]) ? " <img src=' " . THEME_ABS . " forum/ " . $pref [ 'rank_moderator_image' ] . " ' alt='' /> " : " <img src=' " . e_PLUGIN_ABS . " forum/images/lite/admin.png' alt='' /> " ));
2006-12-02 04:36:16 +00:00
}
2009-08-24 18:36:07 +00:00
if ( ! defined ( " IMAGE_rank_admin_image " ))
{
2009-10-09 15:05:12 +00:00
define ( " IMAGE_rank_admin_image " , ( isset ( $pref [ 'rank_admin_image' ]) && $pref [ 'rank_admin_image' ] && file_exists ( THEME . " forum/ " . $pref [ 'rank_admin_image' ]) ? " <img src=' " . THEME_ABS . " forum/ " . $pref [ 'rank_admin_image' ] . " ' alt='' /> " : " <img src=' " . e_PLUGIN_ABS . " forum/images/lite/admin.png' alt='' /> " ));
2006-12-02 04:36:16 +00:00
}
2012-06-15 04:15:46 +00:00
2012-06-16 05:04:22 +00:00
// $RATING = ($addrating == TRUE && $comrow['user_id'] ? $rater->composerating($thistable, $thisid, FALSE, $comrow['user_id']) : "");
2012-06-15 04:15:46 +00:00
$comment_shortcodes = e107 :: getScBatch ( 'comment' );
2009-08-24 18:36:07 +00:00
$text = $tp -> parseTemplate ( $renderstyle , TRUE , $comment_shortcodes );
2012-06-16 05:04:22 +00:00
//FIXME - dramatically increases the number of queries performed.
2012-06-15 04:15:46 +00:00
2012-06-16 05:04:22 +00:00
if ( $action == " comment " && vartrue ( $pref [ 'nested_comments' ]))
2007-08-08 19:28:10 +00:00
{
2009-08-24 18:36:07 +00:00
$type = $this -> getCommentType ( $thistable );
2006-12-02 04:36:16 +00:00
$sub_query = "
2012-06-16 05:04:22 +00:00
SELECT c .* , u .* , ue .* , r .*
2006-12-02 04:36:16 +00:00
FROM #comments AS c
2008-05-24 12:45:34 +00:00
LEFT JOIN #user AS u ON c.comment_author_id = u.user_id
LEFT JOIN #user_extended AS ue ON c.comment_author_id = ue.user_extended_id
2012-06-16 05:04:22 +00:00
LEFT JOIN #rate AS r ON c.comment_id = r.rate_itemid AND r.rate_table = 'comments'
2009-08-24 18:36:07 +00:00
WHERE comment_item_id = '".intval($thisid)."' AND comment_type = '".$tp->toDB($type, true)."' AND comment_pid = '".intval($comrow[' comment_id '])."'
2012-06-18 13:00:47 +00:00
2012-06-15 12:50:18 +00:00
2006-12-02 04:36:16 +00:00
ORDER BY comment_datestamp
" ;
2009-08-24 18:36:07 +00:00
$sql_nc = new db ; /* a new db must be created here, for nested comment */
2013-03-29 15:31:03 -07:00
if ( $sub_total = $sql_nc -> gen ( $sub_query ))
2007-08-08 19:28:10 +00:00
{
2013-03-29 15:31:03 -07:00
while ( $row1 = $sql_nc -> fetch ())
2007-08-08 19:28:10 +00:00
{
2012-06-18 13:00:47 +00:00
if ( $this -> isPending ( $row1 ))
{
$sub_total = $sub_total - 1 ;
continue ;
}
2009-08-24 18:36:07 +00:00
if ( $pref [ 'nested_comments' ])
{
2013-03-29 15:31:03 -07:00
// $width = min($width + 1, 80);
$width = $width + 1 ;
// $width = $width=+1;
// $text .= "WIDTH=".$width;
2009-08-24 18:36:07 +00:00
}
$text .= $this -> render_comment ( $row1 , $table , $action , $id , $width , $subject , $addrating );
unset ( $width );
2006-12-02 04:36:16 +00:00
}
}
2012-06-16 12:41:30 +00:00
$this -> totalComments = $this -> totalComments + $sub_total ;
2009-08-24 18:36:07 +00:00
} // End (nested comment handling)
2012-06-15 04:15:46 +00:00
2009-01-05 22:01:43 +00:00
return $text ;
2006-12-02 04:36:16 +00:00
}
2011-10-20 22:11:58 +00:00
2016-12-22 10:00:37 -08:00
/**
* @ param $id - comment_id to delete
* @ param string $table - comment belongs to this table eg . 'news'
* @ param string $itemid - corresponding item from the table . eg . news_id
* @ return int | null | void
*/
function deleteComment ( $id , $table = '' , $itemid = '' ) // delete a single comment by comment id.
2012-06-17 03:56:42 +00:00
{
2015-04-08 14:51:06 -07:00
if ( $this -> engine != 'e107' )
{
return null ;
}
2012-06-17 03:56:42 +00:00
if ( ! getperms ( '0' ) && ! getperms ( " B " ))
{
2016-12-22 10:00:37 -08:00
return null ;
2012-06-17 03:56:42 +00:00
}
2016-12-22 10:00:37 -08:00
$table = e107 :: getParser () -> filter ( $table , 'w' );
$status = e107 :: getDb () -> update ( " comments " , " comment_blocked=1 WHERE comment_id = " . intval ( $id ) . " " );
$data = array ( 'comment_id' => intval ( $id ), 'comment_type' => $table , 'comment_item_id' => intval ( $itemid ));
e107 :: getEvent () -> trigger ( 'user_comment_deleted' , $data );
return $status ;
2012-06-17 03:56:42 +00:00
}
function approveComment ( $id ) // appropve a single comment by comment id.
{
if ( ! getperms ( '0' ) && ! getperms ( " B " ))
{
return ;
}
2013-05-24 22:40:10 +03:00
return e107 :: getDb () -> update ( " comments " , " comment_blocked=0 WHERE comment_id = " . intval ( $id ) . " " );
2012-06-17 03:56:42 +00:00
}
function updateComment ( $id , $comment )
{
2015-04-08 14:51:06 -07:00
if ( $this -> engine != 'e107' )
{
return null ;
}
2012-06-17 03:56:42 +00:00
$tp = e107 :: getParser ();
2017-09-19 16:19:39 -07:00
// if(THEME_LEGACY !== true) // old themes might still use bbcodes.
{
$comment = $tp -> toText ( $comment );
}
2012-06-17 03:56:42 +00:00
2014-01-01 05:20:46 -08:00
$comment = trim ( $comment );
2013-05-24 22:40:10 +03:00
if ( ! e107 :: getDb () -> update ( " comments " , " comment_comment= \" " . $tp -> toDB ( $comment ) . " \" WHERE comment_id = " . intval ( $id ) . " " ))
2012-06-17 03:56:42 +00:00
{
return " Update Failed " ; // trigger ajax error message.
}
}
2012-07-21 03:55:04 +00:00
function moderateComment ( $var )
{
if ( $var == e_UC_MEMBER ) // different behavior to check_class();
{
return ( USER == TRUE && ADMIN == FALSE ) ? TRUE : FALSE ;
}
return check_class ( $var );
}
2012-06-17 03:56:42 +00:00
2006-12-02 04:36:16 +00:00
/**
2011-10-20 22:11:58 +00:00
* Add a comment to an item
2011-10-24 06:30:31 +00:00
* e - token POST value should be always valid when using this method .
2006-12-02 04:36:16 +00:00
*
2015-03-09 18:45:04 -07:00
* @ param string | array $data - $author_name or array of all values .
2006-12-02 04:36:16 +00:00
* @ param unknown_type $comment
* @ param unknown_type $table
2011-10-20 22:11:58 +00:00
* @ param integer $id - reference of item in source table to which comment is linked
2012-06-15 04:15:46 +00:00
* @ param unknown_type $pid - parent comment id when it ' s a reply to a specific comment . t
2006-12-02 04:36:16 +00:00
* @ param unknown_type $subject
* @ param unknown_type $rateindex
*/
2009-08-24 18:36:07 +00:00
2012-08-17 08:51:27 +00:00
function enter_comment ( $data , $comment = '' , $table = '' , $id = '' , $pid = '' , $subject = '' , $rateindex = FALSE )
2008-05-24 12:45:34 +00:00
{
2006-12-02 04:36:16 +00:00
//rateindex : the posted value from the rateselect box (without the urljump) (see function rateselect())
2015-04-08 14:51:06 -07:00
if ( $this -> engine != 'e107' )
{
return ;
}
2015-03-28 14:12:42 -07:00
2012-08-17 08:51:27 +00:00
if ( is_array ( $data ))
{
$table = $data [ 'comment_type' ];
$id = intval ( $data [ 'comment_item_id' ]);
$pid = intval ( $data [ 'comment_pid' ]);
$subject = $data [ 'comment_subject' ];
$comment = $data [ 'comment_comment' ];
$author_name = $data [ 'comment_author_name' ];
$comment_share = intval ( $data [ 'comment_share' ]);
$comment_datestamp = $data [ 'comment_datestamp' ];
}
else
{
$author_name = $data ; //BC Fix.
}
2017-09-19 16:19:39 -07:00
2012-08-17 08:51:27 +00:00
2015-03-09 18:45:04 -07:00
global $e107 , $rater ;
2010-02-10 21:53:56 +00:00
2009-10-22 04:14:45 +00:00
$sql = e107 :: getDb ();
$sql2 = e107 :: getDb ( 'sql2' );
$tp = e107 :: getParser ();
2012-06-15 12:50:18 +00:00
$pref = e107 :: getPref ();
2010-02-10 21:53:56 +00:00
2017-09-19 16:19:39 -07:00
// if(THEME_LEGACY !== true) // old themes might still use bbcodes.
{
$comment = $tp -> toText ( $comment );
}
2011-10-20 22:11:58 +00:00
if ( $this -> getCommentPermissions () != 'rw' ) return ;
2010-02-10 21:53:56 +00:00
2015-03-28 14:12:42 -07:00
if ( $user_func = e107 :: getOverride () -> check ( $this , 'enter_comment' ))
{
2015-04-08 14:51:06 -07:00
return call_user_func ( $user_func , array ( 'data' => $data , 'comment' => $comment , 'table' => $table , 'id' => $id , 'pid' => $pid , 'subject' => $subject , 'rateindex' => $rateindex ));
2015-03-28 14:12:42 -07:00
}
2011-10-24 06:30:31 +00:00
if ( ! isset ( $_POST [ 'e-token' ])) $_POST [ 'e-token' ] = '' ; // check posted token
if ( ! e107 :: getSession () -> check ( false )) return false ; // This will return false on error
2011-10-21 21:32:32 +00:00
2006-12-02 04:36:16 +00:00
if ( isset ( $_GET [ 'comment' ]) && $_GET [ 'comment' ] == 'edit' )
{
2009-08-24 18:36:07 +00:00
$eaction = 'edit' ;
$editpid = $_GET [ 'comment_id' ];
2006-12-02 04:36:16 +00:00
}
2008-05-24 12:45:34 +00:00
elseif ( strstr ( e_QUERY , " edit " ))
2006-12-02 04:36:16 +00:00
{
2009-08-24 18:36:07 +00:00
$eaction = " edit " ;
$tmp = explode ( " . " , e_QUERY );
$count = 0 ;
foreach ( $tmp as $t )
2006-12-02 04:36:16 +00:00
{
2009-08-24 18:36:07 +00:00
if ( $t == " edit " )
{
$editpid = $tmp [( $count + 1 )];
break ;
}
$count ++ ;
2006-12-02 04:36:16 +00:00
}
}
2009-08-24 18:36:07 +00:00
$type = $this -> getCommentType ( $table );
2006-12-02 04:36:16 +00:00
$comment = $tp -> toDB ( $comment );
$subject = $tp -> toDB ( $subject );
2008-05-24 12:45:34 +00:00
$cuser_id = 0 ;
2009-08-24 18:36:07 +00:00
$cuser_name = 'Anonymous' ; // Preset as an anonymous comment
2012-06-17 03:56:42 +00:00
2015-03-09 18:45:04 -07:00
if ( ! $sql -> select ( " comments " , " * " , " comment_comment=' " . $comment . " ' AND comment_item_id=' " . intval ( $id ) . " ' AND comment_type=' " . $tp -> toDB ( $type , true ) . " ' " ))
2008-05-24 12:45:34 +00:00
{
2009-08-24 18:36:07 +00:00
if ( $_POST [ 'comment' ])
2008-05-24 12:45:34 +00:00
{
2009-08-24 18:36:07 +00:00
if ( USER == TRUE )
2008-05-24 12:45:34 +00:00
{
2009-08-24 18:36:07 +00:00
$cuser_id = USERID ;
$cuser_name = USERNAME ;
2009-09-19 15:30:47 +00:00
$cuser_mail = USEREMAIL ;
2006-12-02 04:36:16 +00:00
}
2012-06-17 03:56:42 +00:00
elseif ( $_POST [ 'author_name' ] != '' ) // See if author name is registered user
{
2015-03-09 18:45:04 -07:00
if ( $sql2 -> select ( " user " , " * " , " user_name=' " . $tp -> toDB ( $_POST [ 'author_name' ]) . " ' " ))
2009-08-24 18:36:07 +00:00
{
2016-03-13 22:24:28 -07:00
if ( $sql2 -> select ( " user " , " * " , " user_name=' " . $tp -> toDB ( $_POST [ 'author_name' ]) . " ' AND user_ip=' " . USERIP . " ' " ))
2009-08-24 18:36:07 +00:00
{
2019-10-11 17:19:48 +02:00
//list($cuser_id, $cuser_name) = $sql2->fetch();
2015-03-09 18:45:04 -07:00
$tmp = $sql2 -> fetch ();
2009-09-19 15:30:47 +00:00
$cuser_id = $tmp [ 'user_id' ];
$cuser_name = $tmp [ 'user_name' ];
$cuser_mail = $tmp [ 'user_email' ];
2009-08-24 18:36:07 +00:00
}
else
{
define ( " emessage " , COMLAN_310 );
}
}
2012-06-17 03:56:42 +00:00
else // User not on-line, so can't be entering comments
{
2009-08-24 18:36:07 +00:00
$cuser_name = $tp -> toDB ( $author_name );
}
2008-05-24 12:45:34 +00:00
}
2009-08-24 18:36:07 +00:00
if ( ! defined ( " emessage " ))
2008-05-24 12:45:34 +00:00
{
2009-08-24 18:36:07 +00:00
$ip = $e107 -> getip (); // Store IP 'in the raw' - could be IPv4 or IPv6. Its always returned in a normalised form
$_t = time ();
2015-03-09 18:45:04 -07:00
2009-08-24 18:36:07 +00:00
if ( $editpid )
{
$comment .= " \n [ " . COMLAN_319 . " [time=short] " . time () . " [/time] ] " ;
2015-03-09 18:45:04 -07:00
$sql -> update ( " comments " , " comment_comment=' { $comment } ' WHERE comment_id=' " . intval ( $editpid ) . " ' " );
e107 :: getCache () -> clear ( " comment " );
2009-08-24 18:36:07 +00:00
return ;
}
2010-02-10 21:53:56 +00:00
2009-09-19 15:30:47 +00:00
//FIXME - don't sanitize, pass raw data to e_event, use DB array (inner db sanitize)
2009-08-24 18:36:07 +00:00
$edata_li = array (
// comment_id - auto-assigned
2010-02-10 21:53:56 +00:00
'comment_pid' => intval ( $pid ),
'comment_item_id' => $id ,
'comment_subject' => $subject ,
'comment_author_id' => $cuser_id ,
2009-09-19 15:30:47 +00:00
'comment_author_name' => $cuser_name ,
'comment_author_email' => $tp -> toDB ( $cuser_mail ),
2010-02-10 21:53:56 +00:00
'comment_datestamp' => $_t ,
'comment_comment' => $comment ,
2012-07-21 03:55:04 +00:00
'comment_blocked' => ( $this -> moderateComment ( $pref [ 'comments_moderate' ]) ? 2 : 0 ),
2010-02-10 21:53:56 +00:00
'comment_ip' => $ip ,
2009-09-19 15:30:47 +00:00
'comment_type' => $tp -> toDB ( $type , true ),
2012-08-17 08:51:27 +00:00
'comment_lock' => 0 , //Not locked by default
'comment_share' => $comment_share
2009-09-19 15:30:47 +00:00
);
2010-02-10 21:53:56 +00:00
2009-09-19 15:30:47 +00:00
//SecretR: new event 'prepostcomment' - allow plugin hooks - e.g. Spam Check
$edata_li_hook = array_merge ( $edata_li , array ( 'comment_nick' => $cuser_id . '.' . $cuser_name , 'comment_time' => $_t ));
2015-03-09 18:45:04 -07:00
if ( e107 :: getEvent () -> trigger ( " prepostcomment " , $edata_li_hook ))
2009-08-24 18:36:07 +00:00
{
2009-09-19 15:30:47 +00:00
return false ; //3rd party code interception
}
2010-02-10 21:53:56 +00:00
2009-09-19 15:30:47 +00:00
//allow 3rd party code to modify insert data
if ( is_array ( $edata_li_hook ))
{
foreach ( array_keys ( $edata_li ) as $k )
{
2010-02-10 21:53:56 +00:00
if ( isset ( $edata_li_hook [ $k ]))
2009-09-19 15:30:47 +00:00
{
$edata_li [ $k ] = $edata_li_hook [ $k ]; //sanitize?
continue ;
}
2010-02-10 21:53:56 +00:00
if ( $k === 'break' )
2009-09-19 15:30:47 +00:00
{
$break = $edata_li_hook [ $k ];
}
}
}
unset ( $edata_li_hook );
2010-02-10 21:53:56 +00:00
2015-03-09 18:45:04 -07:00
if ( ! ( $inserted_id = $sql -> insert ( " comments " , $edata_li )))
2009-09-19 15:30:47 +00:00
{
//echo "<b>".COMLAN_323."</b> ".COMLAN_11;
2012-06-17 03:56:42 +00:00
if ( e_AJAX_REQUEST )
{
return " Error " ;
}
2015-03-09 18:45:04 -07:00
2009-09-29 17:43:13 +00:00
e107 :: getMessage () -> addStack ( COMLAN_11 , 'postcomment' , E_MESSAGE_ERROR );
2010-02-10 21:53:56 +00:00
2009-08-24 18:36:07 +00:00
}
else
{
2015-03-09 18:45:04 -07:00
if ( USER == true )
2009-08-24 18:36:07 +00:00
{
2015-03-09 18:45:04 -07:00
$sql -> update ( " user " , " user_comments=user_comments+1, user_lastpost=' " . time () . " ' WHERE user_id=' " . USERID . " ' " );
2009-08-24 18:36:07 +00:00
}
// Next item for backward compatibility
$edata_li [ " comment_nick " ] = $cuser_id . '.' . $cuser_name ;
$edata_li [ " comment_time " ] = $_t ;
2009-09-19 15:30:47 +00:00
$edata_li [ " comment_id " ] = $inserted_id ;
2010-02-10 21:53:56 +00:00
2009-09-19 15:30:47 +00:00
//Why?
/* unset ( $edata_li [ 'comment_pid' ]);
2009-08-24 18:36:07 +00:00
unset ( $edata_li [ 'comment_author_email' ]);
2009-09-19 15:30:47 +00:00
unset ( $edata_li [ 'comment_ip' ]); */
2010-02-10 21:53:56 +00:00
2015-03-09 18:45:04 -07:00
e107 :: getEvent () -> trigger ( " postcomment " , $edata_li );
2016-12-18 12:01:48 -08:00
e107 :: getEvent () -> trigger ( 'user_comment_posted' , $edata_li );
2015-03-09 18:45:04 -07:00
e107 :: getCache () -> clear ( " comment " );
2016-12-18 12:01:48 -08:00
// Moved to e107_plugins/news/e_event.php
/*
2010-02-10 21:53:56 +00:00
2016-03-13 22:24:28 -07:00
if (( empty ( $table ) || $table == " news " ) && ! $this -> moderateComment ( $pref [ 'comments_moderate' ]))
2009-08-24 18:36:07 +00:00
{
2015-03-09 18:45:04 -07:00
$sql -> update ( " news " , " news_comment_total=news_comment_total+1 WHERE news_id= " . intval ( $id ));
2016-12-18 12:01:48 -08:00
} */
2010-02-10 21:53:56 +00:00
2009-09-19 15:30:47 +00:00
//if rateindex is posted, enter the rating from this user
2012-06-16 12:41:30 +00:00
// if ($rateindex)
// {
// $rater->enterrating($rateindex);
// }
return $inserted_id ; // return the ID number so it can be used. true;
2009-08-24 18:36:07 +00:00
}
2006-12-02 04:36:16 +00:00
}
}
}
else
{
define ( " emessage " , COMLAN_312 );
}
2009-09-19 15:30:47 +00:00
2009-08-24 18:36:07 +00:00
if ( defined ( " emessage " ))
2006-12-02 04:36:16 +00:00
{
2012-06-17 03:56:42 +00:00
if ( e_AJAX_REQUEST )
{
return emessage ;
}
2006-12-02 04:36:16 +00:00
message_handler ( " ALERT " , emessage );
}
2009-09-19 15:30:47 +00:00
return false ;
2006-12-02 04:36:16 +00:00
}
2011-10-20 22:11:58 +00:00
2006-12-02 04:36:16 +00:00
/**
* Enter description here ...
*
2019-01-17 13:20:56 -08:00
* @ param string $table
* @ return string | int
2006-12-02 04:36:16 +00:00
*/
function getCommentType ( $table )
{
2009-08-24 18:36:07 +00:00
if ( is_numeric ( $table ))
{
return $table ;
}
2010-02-10 21:53:56 +00:00
2009-08-24 18:36:07 +00:00
switch ( $table )
{
case " news " :
$type = 0 ;
break ;
case " content " :
$type = 1 ;
break ;
case " download " :
$type = 2 ;
break ;
case " faq " :
$type = 3 ;
break ;
case " poll " :
$type = 4 ;
break ;
case " docs " :
$type = 5 ;
break ;
case " bugtrack " :
$type = 6 ;
break ;
2011-10-20 22:11:58 +00:00
default :
2009-08-24 18:36:07 +00:00
$type = $table ;
break ;
2006-12-02 04:36:16 +00:00
/****************************************
2011-10-20 22:11:58 +00:00
Add your comment type here in same format as above , ie ...
case " your_comment_type " ; $type = your_type_id ; break ;
****************************************/
2009-09-19 15:30:47 +00:00
}
return $type ;
}
2010-02-10 21:53:56 +00:00
2009-09-19 15:30:47 +00:00
/**
* Convert type number to ( core ) table string
* @ param integer | string $type
* @ return string
*/
public function getTable ( $type )
{
if ( ! is_numeric ( $type ))
{
2006-12-02 04:36:16 +00:00
return $type ;
2009-08-24 18:36:07 +00:00
}
2009-11-04 03:07:44 +00:00
else
2009-09-19 15:30:47 +00:00
{
2009-11-04 03:07:44 +00:00
if ( varset ( $this -> known_types [ $type ]))
{
return $this -> known_types [ $type ];
}
2009-09-19 15:30:47 +00:00
}
}
2010-02-10 21:53:56 +00:00
2011-10-20 22:11:58 +00:00
/**
* Enter description here ...
*
* @ param unknown_type $table
* @ param unknown_type $id
* @ return unknown
*/
function count_comments ( $table , $id )
{
2019-10-11 17:19:48 +02:00
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2011-10-20 22:11:58 +00:00
$type = $this -> getCommentType ( $table );
2019-10-11 17:19:48 +02:00
$count_comments = $sql -> count ( " comments " , " (*) " , " WHERE comment_item_id=' " . intval ( $id ) . " ' AND comment_type=' " . $tp -> toDB ( $type , true ) . " ' " );
2011-10-20 22:11:58 +00:00
return $count_comments ;
}
2006-12-02 04:36:16 +00:00
2011-10-20 22:11:58 +00:00
/**
* Get comment permissions ; may be :
* - FALSE - no permission
* - 'ro' - read - only ( Can ' t create )
* - 'rw' - can create and see
*
* This is an embryonic routine which is expected to evolve
*/
function getCommentPermissions ()
{
2015-04-08 14:51:06 -07:00
$pref = e107 :: pref ( 'core' );
2006-12-02 04:36:16 +00:00
2011-10-20 22:11:58 +00:00
if ( isset ( $pref [ 'comments_disabled' ]) && $pref [ 'comments_disabled' ] == TRUE )
2008-05-25 08:26:11 +00:00
{
2012-06-18 09:06:20 +00:00
2011-10-20 22:11:58 +00:00
return FALSE ;
2006-12-02 04:36:16 +00:00
}
2011-10-20 22:11:58 +00:00
if ( isset ( $pref [ 'comments_class' ]))
2009-08-24 18:36:07 +00:00
{
2011-10-20 22:11:58 +00:00
if ( ! check_class ( $pref [ 'comments_class' ]))
2009-08-24 18:36:07 +00:00
{
2011-10-20 22:11:58 +00:00
return FALSE ;
2009-08-24 18:36:07 +00:00
}
2011-10-20 22:11:58 +00:00
return 'rw' ;
}
else
{
if ( USER ) return 'rw' ; // Only allow anonymous comments if specifically enabled.
if ( ANON ) return 'rw' ;
}
return 'ro' ;
}
2010-02-10 21:53:56 +00:00
2011-10-20 22:11:58 +00:00
2016-04-04 12:18:12 -07:00
/**
* Returns a rendered commenting area . ( html ) v2 . x
* This is the only method a plugin developer should require in order to include user comments .
* @ param string $plugin - directory of the plugin that will own these comments .
* @ param int $id - unique id for this page / item . Usually the primary ID of your plugin ' s database table .
* @ param string $subject
* @ param bool | false $rate true = will rendered rating buttons , false will not .
* @ return null | string
*/
public function render ( $plugin , $id , $subject , $rate = false )
{
return $this -> compose_comment ( $plugin , 'comment' , $id , 0 , $subject , $rate , 'html' );
}
2011-10-20 22:11:58 +00:00
/**
* Displays existing comments , and a comment entry form
*
2018-12-19 11:21:38 -08:00
* @ param string $table - the source table for the associated item
* @ param string $action - usually 'comment' or 'reply'
2014-10-14 14:56:12 -07:00
* @ param integer $id - ID of item associated with comments ( e . g . news ID )
2018-12-19 11:21:38 -08:00
* @ param int $width - appears to not be used
* @ param string $subject
2014-10-14 14:56:12 -07:00
* @ param boolean $rate
2018-12-19 11:21:38 -08:00
* @ param boolean | string $return true , false or 'html'
* @ param boolean $tablerender
* @ return array | null | string | void
2011-10-20 22:11:58 +00:00
*/
function compose_comment ( $table , $action , $id , $width , $subject , $rate = FALSE , $return = FALSE , $tablerender = TRUE )
{
//compose comment : single call function will render the existing comments and show the form_comment
//rate : boolean, to show/hide rating system in comment, default FALSE
2015-03-28 14:12:42 -07:00
global $totcc ;
2015-04-08 14:51:06 -07:00
2012-08-04 21:50:47 +00:00
2012-06-15 04:15:46 +00:00
$tp = e107 :: getParser ();
$ns = e107 :: getRender ();
$pref = e107 :: getPref ();
2019-04-11 15:52:41 -07:00
$frm = e107 :: getForm ();
2015-03-28 14:12:42 -07:00
2011-10-20 22:11:58 +00:00
if ( $this -> getCommentPermissions () === FALSE ) return ;
2015-04-08 14:51:06 -07:00
$params = array ( 'method' => 'compose_comment' , 'table' => $table , 'action' => $action , 'id' => $id , 'width' => $width , 'subject' => $subject , 'rate' => $rate , 'return' => $return , 'tablerender' => $tablerender );
if ( $this -> engine != 'e107' )
{
list ( $plugin , $method ) = explode ( " :: " , $this -> engine );
$obj = e107 :: getAddon ( $plugin , 'e_comment' );
$text = e107 :: callMethod ( $obj , $method , $params );
if ( ! $return )
{
if ( $tablerender )
{
echo $ns -> tablerender ( null , $text , 'comment' , true );
}
else
{
echo $text ;
}
}
2017-01-11 18:57:54 -08:00
elseif ( $return === 'html' )
{
return $ns -> tablerender ( null , $text , 'comment' , true );
}
2015-04-08 14:51:06 -07:00
else
{
$ret [ 'comment' ] = $text ;
$ret [ 'comment_form' ] = '' ;
$ret [ 'caption' ] = '' ;
return ( ! $return ) ? " " : $ret ;
}
return '' ;
}
2015-03-28 14:12:42 -07:00
if ( $user_func = e107 :: getOverride () -> check ( $this , 'compose_comment' ))
{
2015-04-08 14:51:06 -07:00
return call_user_func ( $user_func , $params );
2015-03-28 14:12:42 -07:00
}
2012-06-18 09:06:20 +00:00
2012-08-04 19:06:06 +00:00
// ------------- TODO move the 'listing' into separate function so that ajax can access it easily.
2012-08-04 21:50:47 +00:00
$options = array (
'action' => $action ,
'subject' => $subject ,
'rate' => $rate
);
2012-08-23 14:28:04 +00:00
$text = $lock = $modcomment = '' ;
2012-08-04 19:06:06 +00:00
2012-08-23 14:28:04 +00:00
if ( $action != 'reply' )
2012-08-04 19:06:06 +00:00
{
2012-08-23 14:28:04 +00:00
$tmp = $this -> getComments ( $table , $id , 0 , $options ); // render all comments;
$text = $tmp [ 'comments' ];
$lock = $tmp [ 'lock' ];
unset ( $tmp );
2006-12-02 04:36:16 +00:00
}
2012-08-23 14:28:04 +00:00
// -------------------------------------------------------
2012-08-04 19:06:06 +00:00
2012-08-23 14:28:04 +00:00
if ( $text )
{
2013-02-24 01:08:40 -08:00
$modcomment = " <div class='comment-options'> " ;
2012-08-23 14:28:04 +00:00
if ( $this -> totalComments && getperms ( " B " ))
{
2013-02-24 01:08:40 -08:00
2012-08-23 14:28:04 +00:00
// $modcomment .= "<a href='".e_ADMIN_ABS."modcomment.php?$table.$id'>".COMLAN_314."</a>";
2018-01-10 15:06:40 -08:00
$modcomment .= " <a class='btn btn-default btn-secondary btn-mini btn-sm' href=' " . e_ADMIN_ABS . " comment.php?searchquery= { $id } &filter_options=comment_type__ " . $this -> getCommentType ( $table ) . " '> " . COMLAN_314 . " </a> " ;
2013-02-24 01:08:40 -08:00
2012-08-23 14:28:04 +00:00
}
2017-09-23 12:52:23 -07:00
$from = 0 ;
2012-08-23 14:28:04 +00:00
$modcomment .= $this -> nextprev ( $table , $id , $from );
2013-02-24 01:08:40 -08:00
$modcomment .= " </div> " ;
2012-08-23 14:28:04 +00:00
}
2012-08-04 19:06:06 +00:00
// ---------------------------
2011-10-24 19:43:47 +00:00
if ( $lock != '1' )
2011-10-20 22:11:58 +00:00
{
2012-06-15 04:15:46 +00:00
$comment = $this -> form_comment ( $action , $table , $id , $subject , " " , TRUE , $rate , false ); // tablerender turned off.
2011-10-20 22:11:58 +00:00
}
else
{
2019-10-02 14:57:25 +02:00
if ( BOOTSTRAP )
{
$comment = e107 :: getMessage () -> addInfo ( COMLAN_328 ) -> render ();
}
else
{
$comment = " <br /><div style='text-align:center'><b> " . COMLAN_328 . " </b></div> " ;
}
2011-10-20 22:11:58 +00:00
}
2019-04-11 15:52:41 -07:00
$containerTarget = " comments-container- " . $frm -> name2id ( $table );
2012-08-23 14:28:04 +00:00
if ( $text )
{
2013-02-24 01:08:40 -08:00
//XXX Do NOT add to template - too important to allow for modification.
2019-04-30 12:01:09 -07:00
$text = " <ul class='comments-container media-list' id=' " . $containerTarget . " '> \n " . $text . " \n </ul> " ;
2012-08-23 14:28:04 +00:00
}
2013-03-29 15:31:03 -07:00
else
{
2019-04-30 12:01:09 -07:00
$text = " <ul class='comments-container media-list' id=' " . $containerTarget . " '><li><!-- --></li></ul> " ;
2013-03-29 15:31:03 -07:00
}
2018-07-28 16:10:23 -07:00
$TEMPL = $this -> parseLayout ( $text , $comment , $modcomment );
2016-02-13 10:48:36 -08:00
// $return = null;
// $tablerender = true;
2012-06-19 09:08:41 +00:00
if ( ! $return )
{
2012-06-15 04:15:46 +00:00
if ( $tablerender )
{
2012-06-19 09:08:41 +00:00
2015-07-07 18:02:16 -07:00
echo $ns -> tablerender ( " <span id='e-comment-total'> " . $this -> totalComments . " </span> " . LAN_COMMENTS , $TEMPL , 'comment' , TRUE );
2012-06-15 04:15:46 +00:00
}
else
{
echo $TEMPL ;
}
2016-04-04 12:18:12 -07:00
}
elseif ( $return === 'html' )
{
return $ns -> tablerender ( " <span id='e-comment-total'> " . $this -> totalComments . " </span> " . LAN_COMMENTS , $TEMPL , 'comment' , true );
}
2012-06-15 04:15:46 +00:00
//echo $modcomment.$comment;
//echo $text;
2016-02-13 10:48:36 -08:00
if ( ! deftrue ( 'BOOTSTRAP' )) //v1.x
{
$comment = $ns -> tablerender ( COMLAN_9 , $comment , 'comment' , true );
}
2016-03-16 09:21:12 -07:00
2012-06-15 04:15:46 +00:00
2018-07-28 16:10:23 -07:00
$ret = array ();
2012-08-23 14:28:04 +00:00
$ret [ 'comment' ] = $text ;
2016-12-13 11:22:07 -08:00
$ret [ 'moderate' ] = $modcomment ;
2011-10-20 22:11:58 +00:00
$ret [ 'comment_form' ] = $comment ;
2015-07-07 18:02:16 -07:00
$ret [ 'caption' ] = " <span id='e-comment-total'> " . $this -> totalComments . " </span> " . LAN_COMMENTS ;
2011-10-20 22:11:58 +00:00
return ( ! $return ) ? " " : $ret ;
}
2018-07-28 16:10:23 -07:00
/**
* Parse the Comment Layout template
* @ param $comment
* @ param $form
* @ param $modcomment
* @ return mixed
*/
public function parseLayout ( $comment , $form , $modcomment )
{
$search = array ( " { MODERATE} " , " { COMMENTS} " , " { COMMENTFORM} " , " { COMMENTNAV} " );
$pagination = '' ;
$replace = array ( $modcomment , $comment , $form , $pagination );
return str_replace ( $search , $replace , $this -> template [ 'layout' ]);
2011-10-20 22:11:58 +00:00
2018-07-28 16:10:23 -07:00
}
2012-08-04 19:06:06 +00:00
2012-08-04 21:50:47 +00:00
function getComments ( $table , $id , $from = 0 , $att = null )
2012-08-04 19:06:06 +00:00
{
2012-08-04 21:50:47 +00:00
// global $e107cache, $totcc;
2012-08-04 19:06:06 +00:00
2012-08-04 21:50:47 +00:00
//TODO Cache
2012-08-04 19:06:06 +00:00
2012-08-04 21:50:47 +00:00
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
$pref = e107 :: getPref ();
2012-08-04 19:06:06 +00:00
2012-08-04 21:50:47 +00:00
$action = varset ( $att [ 'action' ]);
$subject = varset ( $att [ 'subject' ]);
$rate = varset ( $att [ 'rate' ]);
$type = $this -> getCommentType ( $table );
$sort = vartrue ( $pref [ 'comments_sort' ], 'desc' );
2012-08-04 19:06:06 +00:00
2012-08-04 21:50:47 +00:00
if ( vartrue ( $pref [ 'nested_comments' ]))
{
$query = " SELECT c.*, u.*, ue.*, r.* FROM #comments AS c
LEFT JOIN #user AS u ON c.comment_author_id = u.user_id
LEFT JOIN #user_extended AS ue ON c.comment_author_id = ue.user_extended_id
LEFT JOIN #rate AS r ON c.comment_id = r.rate_itemid AND r.rate_table = 'comments'
WHERE c . comment_item_id = '".intval($id)."' AND c . comment_type = '".$tp->toDB($type, true)."' AND c . comment_pid = '0'
ORDER BY c . comment_datestamp " . $sort ;
}
else
{
$query = " SELECT c.*, u.*, ue.*, r.* FROM #comments AS c
LEFT JOIN #user AS u ON c.comment_author_id = u.user_id
LEFT JOIN #user_extended AS ue ON c.comment_author_id = ue.user_extended_id
LEFT JOIN #rate AS r ON c.comment_id = r.rate_itemid AND r.rate_table = 'comments' ";
$query .= " WHERE c.comment_item_id=' " . intval ( $id ) . " ' AND c.comment_type=' " . $tp -> toDB ( $type , true ) . " '
ORDER BY c . comment_datestamp " . $sort ;
}
2016-02-15 00:14:45 -08:00
$this -> totalComments = $sql -> gen ( $query );
2012-08-04 21:50:47 +00:00
$query .= " LIMIT " . $from . " , " . $this -> commentsPerPage ;
$text = " " ;
$lock = '' ;
2012-08-04 19:06:06 +00:00
2015-02-04 19:04:28 -08:00
if ( $rows = $sql -> retrieve ( $query , true ))
2013-02-24 01:08:40 -08:00
{
// $text .= "<ul class='comments'>";
2015-02-04 19:04:28 -08:00
$width = 0 ;
2012-08-04 21:50:47 +00:00
foreach ( $rows as $row )
{
if ( $this -> isPending ( $row ))
{
continue ;
}
$lock = $row [ 'comment_lock' ];
if ( $pref [ 'nested_comments' ])
{
$text .= $this -> render_comment ( $row , $table , $action , $id , $width , $tp -> toHTML ( $subject ), $rate );
}
else
{
$text .= $this -> render_comment ( $row , $table , $action , $id , $width , $tp -> toHTML ( $subject ), $rate );
}
} // end loop
2013-02-24 01:08:40 -08:00
// $text .= "</ul>";
2012-08-04 21:50:47 +00:00
} // end if
return array ( 'comments' => $text , 'lock' => $lock );
}
2012-08-04 19:06:06 +00:00
2012-08-04 21:50:47 +00:00
function nextprev ( $table , $id , $from = 0 )
{
//return "table=".$table." id=".$id." from=".$from;
//$from = $from + $this->commentsPerPage;
2016-02-11 13:14:41 +01:00
2019-04-11 15:52:41 -07:00
$target = " comments-container- " . e107 :: getForm () -> name2id ( $table );
$navid = 'comments-nav-' . e107 :: getForm () -> name2id ( $table );
2016-02-11 13:14:41 +01:00
2016-01-01 14:25:03 +01:00
// from calculations are done by eNav() js.
if ( $this -> totalComments > $this -> commentsPerPage )
{
2016-02-11 13:14:41 +01:00
$prev = e_HTTP . 'comment.php?mode=list&type=' . $table . '&id=' . $id . '&from=0' ;
$next = e_HTTP . 'comment.php?mode=list&type=' . $table . '&id=' . $id . '&from=0' ;
2019-04-11 15:52:41 -07:00
return " <a class='e-ajax btn btn-default btn-secondary btn-mini btn-sm { $navid } ' href='#' data-nav-id=' { $navid } ' data-nav-total=' { $this -> totalComments } ' data-nav-dir='down' data-nav-inc=' { $this -> commentsPerPage } ' data-target=' { $target } ' data-src=' { $prev } '> " . LAN_PREVIOUS . " </a>
< a class = 'e-ajax btn btn-default btn-secondary btn-mini btn-sm {$navid}' href = '#' data - nav - id = '{$navid}' data - nav - total = '{$this->totalComments}' data - nav - dir = 'up' data - nav - inc = '{$this->commentsPerPage}' data - target = '{$target}' data - src = '{$next}' > " . LAN_NEXT . " </ a > " ;
2016-01-01 14:25:03 +01:00
}
2012-08-04 21:50:47 +00:00
}
2012-08-04 19:06:06 +00:00
2011-10-20 22:11:58 +00:00
function recalc_user_comments ( $id )
{
2019-10-11 17:19:48 +02:00
$sql = e107 :: getDb ();
2009-08-24 18:36:07 +00:00
if ( is_array ( $id ))
{
foreach ( $id as $_id )
{
$this -> recalc_user_comments ( $_id );
}
return ;
}
$qry = "
2006-12-02 04:36:16 +00:00
SELECT COUNT ( * ) AS count
FROM #comments
2008-05-24 12:45:34 +00:00
WHERE comment_author_id = '{$id}'
2006-12-02 04:36:16 +00:00
" ;
2016-02-15 00:14:45 -08:00
if ( $sql -> gen ( $qry ))
2009-08-24 18:36:07 +00:00
{
2019-10-11 17:19:48 +02:00
$row = $sql -> fetch ();
$sql -> update ( " user " , " user_comments = ' { $row [ 'count' ] } ' WHERE user_id = ' { $id } ' " );
2009-08-24 18:36:07 +00:00
}
}
2008-05-24 12:45:34 +00:00
2009-08-24 18:36:07 +00:00
function get_author_list ( $id , $comment_type )
{
2019-10-11 17:19:48 +02:00
$sql = e107 :: getDb ();
2009-08-24 18:36:07 +00:00
$authors = array ();
$qry = "
2010-02-10 21:53:56 +00:00
SELECT DISTINCT ( comment_author_id ) AS author
2006-12-02 04:36:16 +00:00
FROM #comments
2010-02-10 21:53:56 +00:00
WHERE comment_item_id = '{$id}' AND comment_type = '{$comment_type}'
2006-12-02 04:36:16 +00:00
GROUP BY author
" ;
2016-02-15 00:14:45 -08:00
if ( $sql -> gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2019-10-11 17:19:48 +02:00
while ( $row = $sql -> fetch ())
2009-08-24 18:36:07 +00:00
{
$authors [] = $row [ 'author' ];
}
2006-12-02 04:36:16 +00:00
}
2009-08-24 18:36:07 +00:00
return $authors ;
2006-12-02 04:36:16 +00:00
}
2008-05-24 12:45:34 +00:00
2009-08-24 18:36:07 +00:00
function delete_comments ( $table , $id )
{
2019-10-11 17:19:48 +02:00
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
$type = $this -> getCommentType ( $table );
$type = $tp -> toDB ( $type , true );
$id = intval ( $id );
2009-08-24 18:36:07 +00:00
$author_list = $this -> get_author_list ( $id , $type );
2019-10-11 17:19:48 +02:00
$num_deleted = $sql -> delete ( " comments " , " comment_item_id=' { $id } ' AND comment_type=' { $type } ' " );
2009-08-24 18:36:07 +00:00
$this -> recalc_user_comments ( $author_list );
2019-10-11 17:19:48 +02:00
2009-08-24 18:36:07 +00:00
return $num_deleted ;
}
2019-10-11 17:19:48 +02:00
2009-08-24 18:36:07 +00:00
//1) call function getCommentData(); from file
//2) function-> get number of records from comments db
//3) get all e_comment.php files and collect the variables
//4) interchange the db rows and the e_ vars
//5) return the interchanged data in array
//6) from file: render the returned data
//get all e_comment.php files and collect the variables
2008-05-24 12:45:34 +00:00
2006-12-02 04:36:16 +00:00
2009-08-24 18:36:07 +00:00
function get_e_comment ()
{
2015-04-08 14:51:06 -07:00
if ( $this -> engine != 'e107' )
{
return null ;
}
2009-08-24 18:36:07 +00:00
$data = getcachedvars ( 'e_comment' );
if ( $data !== FALSE )
{
return $data ;
}
2010-02-10 21:53:56 +00:00
2013-04-29 15:58:33 -07:00
if ( $files = e107 :: getPref ( 'e_comment_list' ))
2009-08-24 18:36:07 +00:00
{
2013-04-29 15:58:33 -07:00
foreach ( $files as $file => $perms )
2009-08-24 18:36:07 +00:00
{
2013-04-29 15:58:33 -07:00
unset ( $e_comment , $key );
2015-12-31 14:03:03 +01:00
include_once ( e_PLUGIN . $file . " /e_comment.php " );
2017-09-23 12:52:23 -07:00
if ( ! empty ( $e_comment ) && is_array ( $e_comment ))
2009-08-24 18:36:07 +00:00
{
2013-04-29 15:58:33 -07:00
$key = $e_comment [ 'eplug_comment_ids' ];
if ( isset ( $key ) && $key != '' )
{
$data [ $key ] = $e_comment ;
}
2009-08-24 18:36:07 +00:00
}
2013-04-29 15:58:33 -07:00
else
2009-08-24 18:36:07 +00:00
{
2013-04-29 15:58:33 -07:00
//convert old method variables into the same array method
2017-09-23 12:52:23 -07:00
if ( isset ( $e_plug_table ) && $e_plug_table != '' )
2013-04-29 15:58:33 -07:00
{
2017-09-23 12:52:23 -07:00
$key = $e_plug_table ;
2013-04-29 15:58:33 -07:00
$e_comment [ 'eplug_comment_ids' ] = $e_plug_table ;
$e_comment [ 'plugin_name' ] = $plugin_name ;
$e_comment [ 'plugin_path' ] = $plugin_path ;
$e_comment [ 'reply_location' ] = $reply_location ;
$e_comment [ 'db_title' ] = $link_name ;
$e_comment [ 'db_id' ] = $db_id ;
$e_comment [ 'db_table' ] = $db_table ;
$e_comment [ 'qry' ] = '' ;
$data [ $key ] = $e_comment ;
}
2009-08-24 18:36:07 +00:00
}
2006-12-02 04:36:16 +00:00
}
2013-04-29 15:58:33 -07:00
cachevars ( 'e_comment' , $data );
return $data ;
2006-12-02 04:36:16 +00:00
}
}
/*
2009-08-24 18:36:07 +00:00
* get number of records from comments db
* interchange the db rows and the e_comment vars
* return the interchanged data in array
*
* @ param int $amount : holds numeric value for number of comments to ge
* @ param int $from : holds numeric value from where to start retrieving
* @ param string $qry : holds custom query to add in the comment retrieval
* next two parms are only used in iterating loop if less valid records are found
* @ param int $cdvalid : number of valid records found
* @ param array $cdreta : current data set
*/
2016-12-16 12:57:19 -08:00
function getCommentData ( $amount = '' , $from = 0 , $qry = '' , $cdvalid = FALSE , $cdreta = FALSE )
2009-08-24 18:36:07 +00:00
{
2015-04-08 14:51:06 -07:00
if ( $this -> engine != 'e107' )
{
return null ;
}
2009-12-28 21:36:13 +00:00
global $pref , $sql , $sql2 , $tp ;
2009-08-24 18:36:07 +00:00
$from1 = ( $from ? $from : '0' );
$amount1 = ( $amount ? $amount : '10' );
$valid = ( $cdvalid ? $cdvalid : '0' );
$reta = ( $cdreta ? $cdreta : array ());
//get all e_comment data
$e_comment = $this -> get_e_comment ();
$qry1 = ( $qry ? " AND " . $qry : " " );
//get 'amount' of records from comment db
/*
$query = $pref [ 'nested_comments' ] ?
" SELECT c.*, u.*, ue.* FROM #comments AS c
LEFT JOIN #user AS u ON c.comment_author = u.user_id
LEFT JOIN #user_extended AS ue ON c.comment_author = ue.user_extended_id
WHERE c . comment_pid = '0' " . $qry1 . " ORDER BY c . comment_datestamp DESC LIMIT " .intval( $from1 ). " , " .intval( $amount1 ). " "
:
" SELECT c.*, u.*, ue.* FROM #comments AS c
LEFT JOIN #user AS u ON c.comment_author = u.user_id
LEFT JOIN #user_extended AS ue ON c.comment_author = ue.user_extended_id
WHERE c . comment_id != '' " . $qry1 . " ORDER BY c . comment_datestamp DESC LIMIT " .intval( $from1 ). " , " .intval( $amount1 ). " " ;
*/
$query = "
2006-12-02 04:36:16 +00:00
SELECT c .* , u .* , ue .* FROM #comments AS c
2008-05-24 12:45:34 +00:00
LEFT JOIN #user AS u ON c.comment_author_id = u.user_id
LEFT JOIN #user_extended AS ue ON c.comment_author_id = ue.user_extended_id
2008-05-25 08:26:11 +00:00
WHERE c . comment_id != '' AND c . comment_blocked = 0 " . $qry1 . " ORDER BY c . comment_datestamp DESC LIMIT " .intval( $from1 ). " , " .intval( $amount1 ). " " ;
2016-02-15 00:14:45 -08:00
if ( $comment_total = $sql -> gen ( $query ))
2008-05-24 12:45:34 +00:00
{
2009-08-24 18:36:07 +00:00
$width = 0 ;
2019-10-11 17:19:48 +02:00
while ( $row = $sql -> fetch ())
2009-08-24 18:36:07 +00:00
{
$ret = array ();
//date
$ret [ 'comment_datestamp' ] = $row [ 'comment_datestamp' ];
//author - no ned to split now
$comment_author_id = $row [ 'comment_author_id' ];
2009-11-03 20:57:10 +00:00
$ret [ 'comment_author_id' ] = $comment_author_id ;
2017-03-05 08:07:09 -08:00
$ret [ 'comment_author_image' ] = $row [ 'user_image' ];
2009-08-24 18:36:07 +00:00
$comment_author_name = $row [ 'comment_author_name' ];
2011-11-26 18:17:42 +00:00
$ret [ 'comment_author' ] = ( USERID ? " <a href=' " . e107 :: getUrl () -> create ( 'user/profile/view' , array ( 'id' => $comment_author_id , 'name' => $comment_author_name )) . " '> " . $comment_author_name . " </a> " : $comment_author_name );
2009-08-24 18:36:07 +00:00
//comment text
2009-11-01 20:21:22 +00:00
$comment = strip_tags ( preg_replace ( " / \ [.*? \ ]/ " , " " , $row [ 'comment_comment' ])); // remove bbcode - but leave text in between
2009-08-24 18:36:07 +00:00
$ret [ 'comment_comment' ] = $tp -> toHTML ( $comment , FALSE , " " , " " , $pref [ 'main_wordwrap' ]);
//subject
$ret [ 'comment_subject' ] = $tp -> toHTML ( $row [ 'comment_subject' ], TRUE );
switch ( $row [ 'comment_type' ])
2007-08-08 19:28:10 +00:00
{
2009-08-24 18:36:07 +00:00
case '0' : // news
2019-10-11 17:19:48 +02:00
if ( $sql2 -> select ( " news " , " * " , " news_id=' " . $row [ 'comment_item_id' ] . " ' AND news_class REGEXP ' " . e_CLASS_REGEXP . " ' " ))
2009-08-24 18:36:07 +00:00
{
2019-10-11 17:19:48 +02:00
$row2 = $sql2 -> fetch ();
2009-09-14 18:18:36 +00:00
require_once ( e_HANDLER . 'news_class.php' );
2009-08-24 18:36:07 +00:00
$ret [ 'comment_type' ] = COMLAN_TYPE_1 ;
$ret [ 'comment_title' ] = $tp -> toHTML ( $row2 [ 'news_title' ], TRUE , 'emotes_off, no_make_clickable' );
2011-11-26 18:17:42 +00:00
$ret [ 'comment_url' ] = e107 :: getUrl () -> create ( 'news/view/item' , $row2 ); //e_HTTP."comment.php?comment.news.".$row['comment_item_id'];
2009-08-24 18:36:07 +00:00
$ret [ 'comment_category_heading' ] = COMLAN_TYPE_1 ;
2011-11-26 18:17:42 +00:00
$ret [ 'comment_category_url' ] = e107 :: getUrl () -> create ( 'news' ); //e_HTTP."news.php";
2009-08-24 18:36:07 +00:00
}
break ;
case '1' : // article, review or content page - defunct category, but filter them out
break ;
case '2' : // downloads
$qryd = " SELECT d.download_name, dc.download_category_class, dc.download_category_id, dc.download_category_name FROM #download AS d LEFT JOIN #download_category AS dc ON d.download_category=dc.download_category_id WHERE d.download_id= { $row [ 'comment_item_id' ] } AND dc.download_category_class REGEXP ' " . e_CLASS_REGEXP . " ' " ;
2016-02-15 00:14:45 -08:00
if ( $sql2 -> gen ( $qryd ))
2009-08-24 18:36:07 +00:00
{
2019-10-11 17:19:48 +02:00
$row2 = $sql2 -> fetch ();
2009-08-24 18:36:07 +00:00
$ret [ 'comment_type' ] = COMLAN_TYPE_2 ;
$ret [ 'comment_title' ] = $tp -> toHTML ( $row2 [ 'download_name' ], TRUE , 'emotes_off, no_make_clickable' );
$ret [ 'comment_url' ] = e_HTTP . " download.php?view. " . $row [ 'comment_item_id' ];
$ret [ 'comment_category_heading' ] = $row2 [ 'download_category_name' ];
$ret [ 'comment_category_url' ] = e_HTTP . " download.php?list. " . $row2 [ 'download_category_id' ];
}
break ;
2007-08-08 19:28:10 +00:00
// '3' was FAQ
2009-08-24 18:36:07 +00:00
case '4' : // poll
2019-10-11 17:19:48 +02:00
if ( $sql2 -> select ( " polls " , " * " , " poll_id=' " . $row [ 'comment_item_id' ] . " ' " ))
2007-08-08 19:28:10 +00:00
{
2019-10-11 17:19:48 +02:00
$row2 = $sql2 -> fetch ();
2009-08-24 18:36:07 +00:00
$ret [ 'comment_type' ] = COMLAN_TYPE_4 ;
$ret [ 'comment_title' ] = $tp -> toHTML ( $row2 [ 'poll_title' ], TRUE , 'emotes_off, no_make_clickable' );
$ret [ 'comment_url' ] = e_HTTP . " comment.php?comment.poll. " . $row [ 'comment_item_id' ];
$ret [ 'comment_category_url' ] = e_PLUGIN_ABS . 'poll/poll.php' ;
2006-12-02 04:36:16 +00:00
}
2009-08-24 18:36:07 +00:00
break ;
// '5' was docs
// '6' was bugtracker
// 'ideas' was implemented
case 'profile' : // userprofile
if ( USER )
{
$ret [ 'comment_type' ] = COMLAN_TYPE_8 ;
$ret [ 'comment_title' ] = $comment_author_name ;
2016-12-18 12:01:48 -08:00
$ret [ 'comment_url' ] = e107 :: getUrl () -> create ( 'user/profile/view' , array ( 'id' => $row [ 'user_id' ], 'name' => $row [ 'user_name' ])); //e_HTTP."user.php?id.".$row['comment_item_id'];
2009-08-24 18:36:07 +00:00
}
break ;
case 'page' : // Custom Page
$ret [ 'comment_type' ] = COMLAN_TYPE_PAGE ;
$ret [ 'comment_title' ] = $ret [ 'comment_subject' ] ? $ret [ 'comment_subject' ] :
2019-10-11 17:19:48 +02:00
$ret [ 'comment_comment' ];
$ret [ 'comment_url' ] = e_HTTP . " page.php? " . $row [ 'comment_item_id' ];
break ;
default :
if ( isset ( $e_comment [ $row [ 'comment_type' ]]) && is_array ( $e_comment [ $row [ 'comment_type' ]]))
{
$var = $e_comment [ $row [ 'comment_type' ]];
$qryp = '' ;
//new method must use the 'qry' variable
if ( isset ( $var ) && $var [ 'qry' ] != '' )
2009-08-24 18:36:07 +00:00
{
2019-10-11 17:19:48 +02:00
if ( $installed = isset ( $pref [ 'plug_installed' ][ $var [ 'plugin_path' ]]))
2009-08-24 18:36:07 +00:00
{
2019-10-11 17:19:48 +02:00
$qryp = str_replace ( " { NID} " , $row [ 'comment_item_id' ], $var [ 'qry' ]);
if ( $sql2 -> gen ( $qryp ))
2009-08-24 18:36:07 +00:00
{
2019-10-11 17:19:48 +02:00
$row2 = $sql2 -> fetch ();
2009-08-24 18:36:07 +00:00
$ret [ 'comment_type' ] = $var [ 'plugin_name' ];
$ret [ 'comment_title' ] = $tp -> toHTML ( $row2 [ $var [ 'db_title' ]], TRUE , 'emotes_off, no_make_clickable' );
$ret [ 'comment_url' ] = str_replace ( " { NID} " , $row [ 'comment_item_id' ], $var [ 'reply_location' ]);
$ret [ 'comment_category_heading' ] = $var [ 'plugin_name' ];
$ret [ 'comment_category_url' ] = e_PLUGIN_ABS . $var [ 'plugin_name' ] . '/' . $var [ 'plugin_name' ] . '.php' ;
}
}
2019-10-11 17:19:48 +02:00
//old method
2009-08-24 18:36:07 +00:00
}
2019-10-11 17:19:48 +02:00
else
{
if ( $sql2 -> select ( $var [ 'db_table' ], $var [ 'db_title' ], $var [ 'db_id' ] . " = ' " . $row [ 'comment_item_id' ] . " ' " ))
{
$row2 = $sql2 -> fetch ();
$ret [ 'comment_type' ] = $var [ 'plugin_name' ];
$ret [ 'comment_title' ] = $tp -> toHTML ( $row2 [ $var [ 'db_title' ]], TRUE , 'emotes_off, no_make_clickable' );
$ret [ 'comment_url' ] = str_replace ( " { NID} " , $row [ 'comment_item_id' ], $var [ 'reply_location' ]);
$ret [ 'comment_category_heading' ] = $var [ 'plugin_name' ];
$ret [ 'comment_category_url' ] = e_PLUGIN_ABS . $var [ 'plugin_name' ] . '/' . $var [ 'plugin_name' ] . '.php' ;
}
}
}
} // End Switch
2011-10-20 22:11:58 +00:00
if ( varset ( $ret [ 'comment_title' ]))
{
$reta [] = $ret ;
$valid ++ ;
}
if ( $amount && $valid >= $amount )
{
return $reta ;
2009-08-24 18:36:07 +00:00
}
2008-05-24 12:45:34 +00:00
}
2011-10-20 22:11:58 +00:00
//loop if less records found than given $amount - probably because we discarded some
if ( $amount && ( $valid < $amount ))
{
$reta = $this -> getCommentData ( $amount , $from + $amount , $qry , $valid , $reta );
}
}
return $reta ;
}
} //end class