1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

Fixes #416 Total comment count on news items now synchronizes after comments are moderated. Pending or blocked comments are no longer counted towards the total.

This commit is contained in:
Cameron
2015-03-09 18:45:04 -07:00
parent fe263741aa
commit 7dbd07d5fe
3 changed files with 40 additions and 23 deletions

View File

@@ -63,12 +63,12 @@ class comments_admin_ui extends e_admin_ui
//TODO - finish 'user' type, set 'data' to all editable fields, set 'noedit' for all non-editable fields //TODO - finish 'user' type, set 'data' to all editable fields, set 'noedit' for all non-editable fields
protected $fields = array( protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'), 'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'comment_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE), 'comment_id' => array('title'=> LAN_ID, 'type' => null, 'width' =>'5%', 'forced'=> TRUE),
'comment_blocked' => array('title'=> LAN_STATUS, 'type' => 'method', 'inline'=>true, /*'writeParms' => array("approved","blocked","pending"), */'data'=> 'int', 'thclass' => 'center', 'class'=>'center', 'filter' => true, 'batch' => true, 'width' => 'auto'), // Photo 'comment_blocked' => array('title'=> LAN_STATUS, 'type' => 'method', 'inline'=>false, /*'writeParms' => array("approved","blocked","pending"), */'data'=> 'int', 'thclass' => 'center', 'class'=>'center', 'filter' => true, 'batch' => true, 'width' => 'auto'), // Photo
'comment_type' => array('title'=> LAN_TYPE, 'type' => 'method', 'width' => '10%', 'filter'=>TRUE), 'comment_type' => array('title'=> LAN_TYPE, 'type' => 'method', 'width' => '10%', 'filter'=>TRUE),
'comment_item_id' => array('title'=> "item id", 'type' => 'number', 'width' => '5%'), 'comment_item_id' => array('title'=> "item id", 'type' => 'text', 'data'=>'int', 'width' => '5%'),
'comment_subject' => array('title'=> "subject", 'type' => 'text', 'width' => 'auto', 'thclass' => 'left first'), // Display name 'comment_subject' => array('title'=> "subject", 'type' => 'text', 'width' => 'auto', 'thclass' => 'left first'), // Display name
'comment_comment' => array('title'=> "comment", 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name 'comment_comment' => array('title'=> "comment", 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name
'comment_author_id' => array('title'=> LAN_AUTHOR, 'type' => 'user', 'data' => 'int', 'width' => 'auto', 'writeParms' => 'nameField=comment_author_name'), // User id 'comment_author_id' => array('title'=> LAN_AUTHOR, 'type' => 'user', 'data' => 'int', 'width' => 'auto', 'writeParms' => 'nameField=comment_author_name'), // User id
@@ -93,6 +93,19 @@ class comments_admin_ui extends e_admin_ui
'allowCommentEdit' => array('title'=>PRFLAN_90, 'type'=>'boolean'), 'allowCommentEdit' => array('title'=>PRFLAN_90, 'type'=>'boolean'),
'comments_emoticons' => array('title'=>PRFLAN_166, 'type'=>'boolean') 'comments_emoticons' => array('title'=>PRFLAN_166, 'type'=>'boolean')
); );
public function afterUpdate($new_data, $old_data, $id)
{
if(($new_data['comment_type'] == 0 || $new_data['comment_type'] == 'news' ))
{
$total = e107::getDb()->select('comments', 'comment_id', "(comment_type = 0 OR comment_type = 'news') AND comment_item_id = ".$new_data['comment_item_id']." AND comment_blocked = 0");
e107::getDb()->update("news", "news_comment_total= ".intval($total)." WHERE news_id=".intval($new_data['comment_item_id']));
// e107::getMessage()->addInfo("Total Comments for this item: ".$total);
}
}
public function beforeDelete($data, $id) public function beforeDelete($data, $id)
{ {

View File

@@ -3701,7 +3701,7 @@ class e_admin_controller_ui extends e_admin_controller
} }
// filter for WHERE and FROM clauses // filter for WHERE and FROM clauses
$searchable_types = array('text', 'textarea', 'bbarea', 'email', 'int', 'integer', 'str', 'string'); //method? 'user', $searchable_types = array('text', 'textarea', 'bbarea', 'url', 'ip', 'tags', 'email', 'int', 'integer', 'str', 'string', 'number'); //method? 'user',
if($var['type'] == 'method' && ($var['data'] == 'string' || $var['data'] == 'str')) if($var['type'] == 'method' && ($var['data'] == 'string' || $var['data'] == 'str'))
{ {
@@ -3710,11 +3710,11 @@ class e_admin_controller_ui extends e_admin_controller
if(trim($searchQuery) !== '' && in_array($var['type'], $searchable_types) && $var['__tableField']) if(trim($searchQuery) !== '' && in_array($var['type'], $searchable_types) && $var['__tableField'])
{ {
if($var['type'] == 'int' || $var['type'] == 'integer') if($var['data'] == 'int' || $var['data'] == 'integer' || $var['type'] == 'int' || $var['type'] == 'integer')
{ {
if(is_numeric($searchQuery)) if(is_numeric($searchQuery))
{ {
$filter[] = $var['__tableField']."=".$searchQuery; $filter[] = $var['__tableField']." = ".$searchQuery;
} }
continue; continue;
} }
@@ -3728,6 +3728,8 @@ class e_admin_controller_ui extends e_admin_controller
} }
} }
// e107::getMessage()->addInfo(print_a($filter,true));
if($isfilter) if($isfilter)
{ {
if(!$filterFrom) return false; if(!$filterFrom) return false;

View File

@@ -583,7 +583,7 @@ class comment
* Add a comment to an item * Add a comment to an item
* e-token POST value should be always valid when using this method. * e-token POST value should be always valid when using this method.
* *
* @param string or array $data - $author_name or array of all values. * @param string|array $data - $author_name or array of all values.
* @param unknown_type $comment * @param unknown_type $comment
* @param unknown_type $table * @param unknown_type $table
* @param integer $id - reference of item in source table to which comment is linked * @param integer $id - reference of item in source table to which comment is linked
@@ -614,7 +614,7 @@ class comment
} }
global $e_event,$e107,$rater; global $e107,$rater;
$sql = e107::getDb(); $sql = e107::getDb();
$sql2 = e107::getDb('sql2'); $sql2 = e107::getDb('sql2');
@@ -653,7 +653,7 @@ class comment
$cuser_id = 0; $cuser_id = 0;
$cuser_name = 'Anonymous'; // Preset as an anonymous comment $cuser_name = 'Anonymous'; // Preset as an anonymous comment
if (!$sql->db_Select("comments", "*", "comment_comment='".$comment."' AND comment_item_id='".intval($id)."' AND comment_type='".$tp->toDB($type, true)."' ")) if (!$sql->select("comments", "*", "comment_comment='".$comment."' AND comment_item_id='".intval($id)."' AND comment_type='".$tp->toDB($type, true)."' "))
{ {
if ($_POST['comment']) if ($_POST['comment'])
{ {
@@ -665,12 +665,12 @@ class comment
} }
elseif ($_POST['author_name'] != '') // See if author name is registered user elseif ($_POST['author_name'] != '') // See if author name is registered user
{ {
if ($sql2->db_Select("user", "*", "user_name='".$tp->toDB($_POST['author_name'])."' ")) if ($sql2->select("user", "*", "user_name='".$tp->toDB($_POST['author_name'])."' "))
{ {
if ($sql2->db_Select("user", "*", "user_name='".$tp->toDB($_POST['author_name'])."' AND user_ip='".$tp->toDB($ip, true)."' ")) if ($sql2->select("user", "*", "user_name='".$tp->toDB($_POST['author_name'])."' AND user_ip='".$tp->toDB($ip, true)."' "))
{ {
//list($cuser_id, $cuser_name) = $sql2->db_Fetch(); //list($cuser_id, $cuser_name) = $sql2->db_Fetch();
$tmp = $sql2->db_Fetch(); $tmp = $sql2->fetch();
$cuser_id = $tmp['user_id']; $cuser_id = $tmp['user_id'];
$cuser_name = $tmp['user_name']; $cuser_name = $tmp['user_name'];
$cuser_mail = $tmp['user_email']; $cuser_mail = $tmp['user_email'];
@@ -689,11 +689,12 @@ class comment
{ {
$ip = $e107->getip(); // Store IP 'in the raw' - could be IPv4 or IPv6. Its always returned in a normalised form $ip = $e107->getip(); // Store IP 'in the raw' - could be IPv4 or IPv6. Its always returned in a normalised form
$_t = time(); $_t = time();
if ($editpid) if ($editpid)
{ {
$comment .= "\n[ ".COMLAN_319." [time=short]".time()."[/time] ]"; $comment .= "\n[ ".COMLAN_319." [time=short]".time()."[/time] ]";
$sql->db_Update("comments", "comment_comment='{$comment}' WHERE comment_id='".intval($editpid)."' "); $sql->update("comments", "comment_comment='{$comment}' WHERE comment_id='".intval($editpid)."' ");
$e107cache->clear("comment"); e107::getCache()->clear("comment");
return; return;
} }
@@ -717,7 +718,7 @@ class comment
//SecretR: new event 'prepostcomment' - allow plugin hooks - e.g. Spam Check //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)); $edata_li_hook = array_merge($edata_li, array('comment_nick' => $cuser_id.'.'.$cuser_name, 'comment_time' => $_t));
if($e_event->trigger("prepostcomment", $edata_li_hook)) if(e107::getEvent()->trigger("prepostcomment", $edata_li_hook))
{ {
return false; //3rd party code interception return false; //3rd party code interception
} }
@@ -740,21 +741,22 @@ class comment
} }
unset($edata_li_hook); unset($edata_li_hook);
if (!($inserted_id = $sql->db_Insert("comments", $edata_li))) if (!($inserted_id = $sql->insert("comments", $edata_li)))
{ {
//echo "<b>".COMLAN_323."</b> ".COMLAN_11; //echo "<b>".COMLAN_323."</b> ".COMLAN_11;
if(e_AJAX_REQUEST) if(e_AJAX_REQUEST)
{ {
return "Error"; return "Error";
} }
e107::getMessage()->addStack(COMLAN_11, 'postcomment', E_MESSAGE_ERROR); e107::getMessage()->addStack(COMLAN_11, 'postcomment', E_MESSAGE_ERROR);
} }
else else
{ {
if (USER == TRUE) if (USER == true)
{ {
$sql->db_Update("user", "user_comments=user_comments+1, user_lastpost='".time()."' WHERE user_id='".USERID."' "); $sql->update("user", "user_comments=user_comments+1, user_lastpost='".time()."' WHERE user_id='".USERID."' ");
} }
// Next item for backward compatibility // Next item for backward compatibility
$edata_li["comment_nick"] = $cuser_id.'.'.$cuser_name; $edata_li["comment_nick"] = $cuser_id.'.'.$cuser_name;
@@ -766,13 +768,13 @@ class comment
unset($edata_li['comment_author_email']); unset($edata_li['comment_author_email']);
unset($edata_li['comment_ip']);*/ unset($edata_li['comment_ip']);*/
$e_event->trigger("postcomment", $edata_li); e107::getEvent()->trigger("postcomment", $edata_li);
$e107cache->clear("comment"); e107::getCache()->clear("comment");
//TODO - should be handled by news
if (!$type || $type == "news") if ((empty($type) || $type == "news") && !$this->moderateComment($pref['comments_moderate']))
{ {
$sql->db_Update("news", "news_comment_total=news_comment_total+1 WHERE news_id=".intval($id)); $sql->update("news", "news_comment_total=news_comment_total+1 WHERE news_id=".intval($id));
} }
//if rateindex is posted, enter the rating from this user //if rateindex is posted, enter the rating from this user