diff --git a/comment.php b/comment.php
index 8e298d09d..0b406ece6 100644
--- a/comment.php
+++ b/comment.php
@@ -62,9 +62,9 @@ if(e_AJAX_REQUEST) // TODO improve security
}
- if(varset($_GET['mode']) == 'delete' && vartrue($_POST['itemid']) && ADMIN)
+ if(varset($_GET['mode']) == 'delete' && !empty($_POST['id']) && ADMIN)
{
- $status = e107::getComment()->deleteComment($_POST['itemid']);
+ $status = e107::getComment()->deleteComment($_POST['id'],$_POST['table'],$_POST['itemid']);
$ret['msg'] = ($status) ? 'Ok' : COMLAN_332;
$ret['error'] = ($status) ? false : true;
echo json_encode($ret);
diff --git a/e107_core/shortcodes/batch/comment_shortcodes.php b/e107_core/shortcodes/batch/comment_shortcodes.php
index be169ffcd..ee13f69c5 100644
--- a/e107_core/shortcodes/batch/comment_shortcodes.php
+++ b/e107_core/shortcodes/batch/comment_shortcodes.php
@@ -194,8 +194,11 @@ class comment_shortcodes extends e_shortcode
return;
}
- // TODO put into a
drop-down format.
- $text = " ";
+ // TODO put into a drop-down format.
+
+ e107::getDebug()->log($this->var);
+
+ $text = " ";
if($this->var['comment_blocked'] == 2) // pending approval.
{
diff --git a/e107_handlers/comment_class.php b/e107_handlers/comment_class.php
index 768a7804d..3f8fc01c8 100644
--- a/e107_handlers/comment_class.php
+++ b/e107_handlers/comment_class.php
@@ -598,8 +598,14 @@ class comment
return $text;
}
-
- function deleteComment($id) // delete a single comment by comment id.
+
+ /**
+ * @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.
{
if($this->engine != 'e107')
@@ -609,9 +615,18 @@ class comment
if(!getperms('0') && !getperms("B"))
{
- return;
+ return null;
}
- return e107::getDb()->update("comments","comment_blocked=1 WHERE comment_id = ".intval($id)."");
+
+ $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;
}
function approveComment($id) // appropve a single comment by comment id.
diff --git a/e107_plugins/news/e_event.php b/e107_plugins/news/e_event.php
index 6a440788d..d2913c778 100644
--- a/e107_plugins/news/e_event.php
+++ b/e107_plugins/news/e_event.php
@@ -30,7 +30,12 @@ class news_event // plugin-folder + '_event'
$event[] = array(
'name' => "user_comment_posted", // when this is triggered... (see http://e107.org/developer-manual/classes-and-methods#events)
- 'function' => "incrementComment", // ..run this function (see below).
+ 'function' => "commentCountUp", // ..run this function (see below).
+ );
+
+ $event[] = array(
+ 'name' => "user_comment_deleted", // when this is triggered... (see http://e107.org/developer-manual/classes-and-methods#events)
+ 'function' => "commentCountDown", // ..run this function (see below).
);
return $event;
@@ -38,7 +43,7 @@ class news_event // plugin-folder + '_event'
}
- function incrementComment($data) // the method to run.
+ function commentCountUp($data) // the method to run.
{
if($data['comment_type'] !== 'news' && !empty($data['comment_type']))
{
@@ -55,7 +60,22 @@ class news_event // plugin-folder + '_event'
}
+ function commentCountDown($data) // the method to run.
+ {
+ if($data['comment_type'] !== 'news' && !empty($data['comment_type']))
+ {
+ return false;
+ }
+
+ if(!empty($data['comment_item_id']))
+ {
+ $id = intval($data['comment_item_id']);
+ e107::getDb()->update("news", "news_comment_total=news_comment_total-1 WHERE news_id=".$id);
+ e107::getCache()->clear('news_php_extend_'.$id.'_');
+ }
+
+ }
} //end class
diff --git a/e107_web/js/core/front.jquery.js b/e107_web/js/core/front.jquery.js
index a981c46a8..bf810a416 100644
--- a/e107_web/js/core/front.jquery.js
+++ b/e107_web/js/core/front.jquery.js
@@ -271,6 +271,8 @@ $(document).ready(function()
$(document).on("click", ".e-comment-delete", function(){
var url = $(this).attr("data-target");
+ var table = $(this).attr("data-type");
+ var itemid = $(this).attr("data-itemid");
var sp = $(this).attr('id').split("-");
var id = "#comment-" + sp[3];
var total = parseInt($("#e-comment-total").text());
@@ -278,7 +280,7 @@ $(document).ready(function()
$.ajax({
type: 'POST',
url: url + '?ajax_used=1&mode=delete',
- data: { itemid: sp[3] },
+ data: { id: sp[3], itemid: itemid, table: table },
success: function(data) {
var a = $.parseJSON(data);
diff --git a/page.php b/page.php
index f34beb38b..a433e754a 100644
--- a/page.php
+++ b/page.php
@@ -594,6 +594,8 @@ class pageClass
$this->page = $sql->fetch();
+
+
// setting override to true breaks default.
$this->templateID = vartrue($this->page['page_template'], 'default');
@@ -676,9 +678,10 @@ class pageClass
$this->page['book_name'] = $this->getName($this->page['chapter_parent']);
// -----------------
+ e107::getEvent()->trigger('user_page_item_viewed',$this->page);
$this->batch->setVars($this->page);
-
+
define('e_PAGETITLE', eHelper::formatMetaTitle($this->page['page_title']));
if($this->page['page_metadscr']) define('META_DESCRIPTION', eHelper::formatMetaDescription($this->page['page_metadscr']));