mirror of
https://github.com/e107inc/e107.git
synced 2025-07-24 16:31:48 +02:00
New Events: user_page_item_viewed, user_comment_deleted
News Comment Count now moving up/down accordingly.
This commit is contained in:
@@ -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);
|
||||
|
@@ -194,8 +194,11 @@ class comment_shortcodes extends e_shortcode
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO put into a <ul> drop-down format.
|
||||
$text = "<a href='#' data-target='".e_HTTP."comment.php' id='e-comment-delete-".$this->var['comment_id']."' class='e-comment-delete btn btn-default btn-mini btn-xs'>".LAN_DELETE."</a> ";
|
||||
// TODO put into a <ul> drop-down format.
|
||||
|
||||
e107::getDebug()->log($this->var);
|
||||
|
||||
$text = "<a href='#' data-target='".e_HTTP."comment.php' id='e-comment-delete-".$this->var['comment_id']."' data-type='".$this->var['comment_type']."' data-itemid='".$this->var['comment_item_id']."' class='e-comment-delete btn btn-default btn-mini btn-xs'>".LAN_DELETE."</a> ";
|
||||
|
||||
if($this->var['comment_blocked'] == 2) // pending approval.
|
||||
{
|
||||
|
@@ -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.
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
||||
|
5
page.php
5
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']));
|
||||
|
Reference in New Issue
Block a user