Adding Comments Approval System - issue 1625

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10368 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
dionisrom 2012-03-07 13:22:01 +00:00
parent 23957de302
commit 0748cccdad
6 changed files with 358 additions and 162 deletions

View file

@ -2809,6 +2809,9 @@ Xin vui lòng kiểm tra lại thông tin Database.]]></value>
<value xml:lang="en"><![CDATA[Cannot find the Keyword.]]></value>
<value xml:lang="en"><![CDATA[搜尋不到關鍵字]]></value>
</item>
<item name="comment_to_be_approved">
<value xml:lang="en"><![CDATA[Your comment must be approved by admin before being published.]]></value>
</item>
<item name="success_registed">
<value xml:lang="ko"><![CDATA[등록했습니다.]]></value>
<value xml:lang="en"><![CDATA[Registered successfully.]]></value>

View file

@ -12,68 +12,75 @@
**/
function init() {
}
function procCommentAdminChangePublishedStatusChecked()
/**
* @brief Modify comment(s) status to piublish/unpublish if calling module is using Comment Approval System
* @return Object
*/
function procCommentAdminChangePublishedStatusChecked()
{ // Error display if none is selected
$cart = Context::get('cart');
if(!is_array($cart))
{
$will_publish = Context::get('will_publish');
// Error display if none is selected
$cart = Context::get('cart');
if(!$cart)
{
return $this->stop('msg_cart_is_null');
}
if(!is_array($cart))
{
$comment_srl_list= explode('|@|', $cart);
}
else
{
$comment_srl_list = $cart;
}
$comment_count = count($comment_srl_list);
// begin transaction
// for message send - start
$message_content = Context::get('message_content');
if($message_content) $message_content = nl2br($message_content);
$comment_srl_list= explode('|@|', $cart);
}
else
{
$comment_srl_list = $cart;
}
$this->procCommentAdminChangeStatus();
if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON'))) {
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispCommentAdminList', 'search_keyword', '');
header('location:'.$returnUrl);
return;
}
}
function procCommentAdminChangeStatus()
{
$will_publish = Context::get('will_publish');
if($message_content) {
$oCommunicationController = &getController('communication');
$oCommentModel = &getModel('comment');
// Error display if none is selected
$cart = Context::get('cart');
if(!$cart)
{
return $this->stop('msg_cart_is_null');
}
if(!is_array($cart))
{
$comment_srl_list= explode('|@|', $cart);
}
else
{
$comment_srl_list = $cart;
}
$logged_info = Context::get('logged_info');
$title = cut_str($message_content,10,'...');
$sender_member_srl = $logged_info->member_srl;
for($i=0;$i<$comment_count;$i++) {
$comment_srl = $comment_srl_list[$i];
$oComment = $oCommentModel->getComment($comment_srl, true);
if(!$oComment->get('member_srl') || $oComment->get('member_srl')==$sender_member_srl) continue;
$content = sprintf("<div>%s</div><hr /><div style=\"font-weight:bold\">%s</div>",$message_content, $oComment->getContentText(20));
$oCommunicationController->sendMessage($sender_member_srl, $oComment->get('member_srl'), $title, $content, false);
}
}
// for message send - end
$args->status = $will_publish;
$args->comment_srls_list = $comment_srl_list;
$output = executeQuery('comment.updatePublishedStatus', $args);
if(!$output->toBool()) return $output;
$args->status = $will_publish;
$args->comment_srls_list = $comment_srl_list;
$output = executeQuery('comment.updatePublishedStatus', $args);
if(!$output->toBool())
{
return $output;
}
else
{
//update comment count for document
$updated_documents_arr = array();
// create the controller object of the document
$oDocumentController = &getController('document');
// create the model object of the document
$oDocumentModel = &getModel('document');
// create the comment model object
$oCommentModel = &getModel('comment');
for($i=0;$i<$comment_count;$i++)
//get admin info
$logged_info = Context::get('logged_info');
//$oMemberModule = &getModel("member");
//$logged_info = $oMemberModule->getMemberInfoByMemberSrl($logged_member_srl);
$new_status = ($will_publish) ? "published" : "unpublished";
foreach($comment_srl_list as $comment_srl)
{
$comment_srl = $comment_srl_list[$i];
// check if comment already exists
$comment = $oCommentModel->getComment($comment_srl);
if($comment->comment_srl != $comment_srl) return new Object(-1, 'msg_invalid_request');
@ -85,16 +92,63 @@
$comment_count = $oCommentModel->getCommentCount($document_srl);
// update comment count of the article posting
$output = $oDocumentController->updateCommentCount($document_srl, $comment_count, null, false);
$oDocument = $oDocumentModel->getDocument($document_srl);
$author_email=$oDocument->variables['email_address'];
$oModuleModel = &getModel("module");
$module_info = $oModuleModel->getModuleInfoByModuleSrl($comment->module_srl);
$already_sent = array();
// send email to comment's author, all admins and thread(document) subscribers - START
// -------------------------------------------------------
$oMail = new Mail();
$mail_title = "[XE - ".$module_info->mid."] comment(s) status changed to ".$new_status." on document: \"".$oDocument->getTitleText()."\"";
$oMail->setTitle($mail_title);
$mail_content = "
The comment #".$comment_srl." on document \"".$oDocument->getTitleText()."\" has been ".$new_status." by admin of <strong><i>". strtoupper($module_info->mid)."</i></strong> module.
<br />
<br />Comment content:
".$comment->content."
<br />
";
$oMail->setContent($mail_content);
$oMail->setSender($logged_info->user_name, $logged_info->email_address);
$document_author_email = $oDocument->variables['email_address'];
//mail to author of thread - START
if($document_author_email != $comment->email_address && $logged_info->email_address != $document_author_email) {
$oMail->setReceiptor($document_author_email, $document_author_email);
$oMail->send();
$already_sent[] = $document_author_email;
}
//mail to author of thread - STOP
//mail to all emails set for administrators - START
if($module_info->admin_mail)
{
$target_mail = explode(',',$module_info->admin_mail);
for($i=0;$i<count($target_mail);$i++) {
$email_address = trim($target_mail[$i]);
if(!$email_address) continue;
if($author_email != $email_address) {
$oMail->setReceiptor($email_address, $email_address);
$oMail->send();
}
}
}
//mail to all emails set for administrators - STOP
}
}
if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON'))) {
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispCommentAdminList', 'search_keyword', '');
header('location:'.$returnUrl);
return;
// ----------------------------------------------------------
// send email to comment's author, all admins and thread(document) subscribers - STOP
}
// call a trigger for calling "send mail to subscribers" (for moment just for forum)
ModuleHandler::triggerCall("comment.procCommentAdminChangeStatus","after",$comment_srl_list);
}
}
/**
* @brief Delete the selected comment from the administrator page
**/

View file

@ -98,53 +98,52 @@
$_SESSION['own_comment'][$comment_srl] = true;
}
/**
*@brief Check if module is using comment validation system
* @param number $document_srl
* @return boolean
*/
function isModuleUsingPublishValidation($document_srl=null, $module_srl=null)
/**
*@brief Check if module is using comment validation system
* @param number $document_srl
* @return boolean
*/
function isModuleUsingPublishValidation($document_srl=null, $module_srl=null)
{
$oModuleModel = &getModel('module');
$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
$module_part_config = $oModuleModel->getModulePartConfig('comment',$module_info->module_srl);
$use_validation = false;
if (isset($module_part_config->use_comment_validation) && $module_part_config->use_comment_validation == "Y")
{
$oModuleModel = &getModel('module');
if(!is_null($document_srl))
{
$module_info = $oModuleModel->getModuleInfoByDocumentSrl($document_srl);
}
if(!is_null($module_srl))
{
$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
}
$module_part_config = $oModuleModel->getModulePartConfig('comment',$module_info->module_srl);
$use_validation = false;
if (isset($module_part_config->use_comment_validation) && $module_part_config->use_comment_validation == "Y")
{
$use_validation = true;
}
return $use_validation;
$use_validation = true;
}
return $use_validation;
}
/**
* @brief Enter comments
**/
function insertComment($obj, $manual_inserted = false) {
// check if comment's module is using comment validation and set the publish status to 0 (false)
// for inserting query, otherwhise default is 1 (true - means comment is published)
$using_validation = $this->isModuleUsingPublishValidation($obj->document_srl);
if(Context::get('is_logged'))
// check if comment's module is using comment validation and set the publish status to 0 (false)
// for inserting query, otherwhise default is 1 (true - means comment is published)
$using_validation = $this->isModuleUsingPublishValidation($obj->module_srl);
if(Context::get('is_logged'))
{
$logged_info = Context::get('logged_info');
if ($logged_info->is_admin == 'Y')
{
$logged_info = Context::get('logged_info');
if ($logged_info->is_admin == 'Y')
{
$is_admin = true;
}
else
{
$is_admin = false;
}
$is_admin = true;
}
if (!$using_validation || $is_admin)
else
{
$is_admin = false;
}
}
if (!$using_validation)
{
$obj->status = 1;
}
else
{
if ($is_admin)
{
$obj->status = 1;
}
@ -152,8 +151,9 @@
{
$obj->status = 0;
}
$obj->__isupdate = false;
}
$obj->__isupdate = false;
// call a trigger (before)
$output = ModuleHandler::triggerCall('comment.insertComment', 'before', $obj);
if(!$output->toBool()) return $output;
@ -262,10 +262,17 @@
// create the controller object of the document
$oDocumentController = &getController('document');
// Update the number of comments in the post
if (!$using_validation || $is_admin)
if (!$using_validation)
{
$output = $oDocumentController->updateCommentCount($document_srl, $comment_count, $obj->nick_name, true);
}
else
{
if ($is_admin)
{
$output = $oDocumentController->updateCommentCount($document_srl, $comment_count, $obj->nick_name, true);
}
}
// grant autority of the comment
$this->addGrant($obj->comment_srl);
// call a trigger(after)
@ -292,6 +299,8 @@
}
}
$this->sendEmailToAdminAfterInsertComment($obj);
$output->add('comment_srl', $obj->comment_srl);
//remove from cache
@ -303,7 +312,128 @@
}
return $output;
}
/**
* @brief Send email to module's admins after a new comment was interted successfully
* if Comments Approval System is used
* @param type $obj
*/
function sendEmailToAdminAfterInsertComment($obj)
{
$using_validation = $this->isModuleUsingPublishValidation($obj->module_srl);
$oDocumentModel = &getModel('document');
$oDocument = $oDocumentModel->getDocument($obj->document_srl);
$oMemberModel = &getModel("member");
if (isset($obj->member_srl) && !is_null($obj->member_srl))
{
$member_info = $oMemberModel->getMemberInfoByMemberSrl($obj->member_srl);
}
else
{
$member_info->is_admin = "N";
$member_info->nick_name = $obj->nick_name;
$member_info->user_name = $obj->user_name;
$member_info->email_address = $obj->email_address;
}
$oCommentModel = &getModel("comment");
$nr_comments_not_approved = $oCommentModel->getCommentAllCount(null,false);
$oModuleModel = &getModel("module");
$module_info = $oModuleModel->getModuleInfoByDocumentSrl($obj->document_srl);
// If there is no problem to register comment then send an email to all admin were set in module admin panel
if($module_info->admin_mail && $member_info->is_admin != 'Y')
{
$oMail = new Mail();
$oMail->setSender($obj->email_address, $obj->email_address);
$mail_title = "[XE - ".Context::get('mid')."] A new comment was posted on document: \"".$oDocument->getTitleText()."\"";
$oMail->setTitle($mail_title);
if ($using_validation)
{
$url_approve = getFullUrl('','module','comment','act','procCommentAdminChangePublishedStatusChecked','cart[]',$obj->comment_srl,'will_publish','1','search_target','is_published','search_keyword','N');
$url_trash = getFullUrl('','module','comment','act','procCommentAdminDeleteChecked','cart[]',$obj->comment_srl,'search_target','is_trash','search_keyword','true');
$mail_content = "
A new comment on the document \"".$oDocument->getTitleText()."\" is waiting for your approval.
<br />
<br />
Author: ".$member_info->nick_name."
<br />Author e-mail: ".$member_info->email_address."
<br />Comment:
<br />\"".$obj->content."\"
<br />
<br />
Approve it: <a href=\"".$url_approve."\">".$url_approve."</a>
<br />Trash it: <a href=\"".$url_trash."\">".$url_trash."</a>
<br />Currently ".$nr_comments_not_approved." comments on \"".Context::get('mid')."\" module are waiting for approval. Please visit the moderation panel:
<br /><a href=\"".getFullUrl('','module','admin','act','dispCommentAdminList','search_target','module','search_keyword',$obj->module_srl)."\">".getFullUrl('','module','admin','act','dispCommentAdminList','search_target','module','search_keyword',$obj->module_srl)."</a>
";
$oMail->setContent($mail_content);
}
else
{
$mail_content = "
Author: ".$member_info->nick_name."
<br />Author e-mail: ".$member_info->email_address."
<br />Comment:
<br />\"".$obj->content."\"
";
$oMail->setContent($mail_content);
// get email of thread's author
$document_author_email = $oDocument->variables['email_address'];
//get admin info
$logged_info = Context::get('logged_info');
//mail to author of thread - START
if($document_author_email != $obj->email_address && $logged_info->email_address != $document_author_email) {
$oMail->setReceiptor($document_author_email, $document_author_email);
$oMail->send();
}
// mail to author of thread - STOP
}
// get all admins emails
$admins_emails = $module_info->admin_mail;
$target_mail = explode(',',$admins_emails);
// send email to all admins - START
for($i=0;$i<count($target_mail);$i++)
{
$email_address = trim($target_mail[$i]);
if(!$email_address) continue;
$oMail->setReceiptor($email_address, $email_address);
$oMail->send();
}
// send email to all admins - STOP
}
$comment_srl_list = array(0 => $obj->comment_srl);
// call a trigger for calling "send mail to subscribers" (for moment just for forum)
ModuleHandler::triggerCall("comment.sendEmailToAdminAfterInsertComment","after",$comment_srl_list);
/*
// send email to author - START
$oMail = new Mail();
$mail_title = "[XE - ".Context::get('mid')."] your comment on document: \"".$oDocument->getTitleText()."\" have to be approved";
$oMail->setTitle($mail_title);
//$mail_content = sprintf("From : <a href=\"%s?document_srl=%s&comment_srl=%s#comment_%d\">%s?document_srl=%s&comment_srl=%s#comment_%d</a><br/>\r\n%s ", getFullUrl(''),$comment->document_srl,$comment->comment_srl,$comment->comment_srl, getFullUrl(''),$comment->document_srl,$comment->comment_srl,$comment->comment_srl,$comment>content);
$mail_content = "
Your comment #".$obj->comment_srl." on document \"".$oDocument->getTitleText()."\" have to be approved by admin of <strong><i>". strtoupper($module_info->mid)."</i></strong> module before to be publish.
<br />
<br />Comment content:
".$obj->content."
<br />
";
$oMail->setContent($mail_content);
$oMail->setSender($obj->email_address, $obj->email_address);
$oMail->setReceiptor($obj->email_address, $obj->email_address);
$oMail->send();
// send email to author - START
*/
return;
}
/**
* @brief fix the comment
**/
@ -457,15 +587,15 @@
return $output;
}
/**
* @brief remove all comment relation log
**/
function deleteCommentLog()
{
$this->_deleteDeclaredComments($args);
$this->_deleteVotedComments($args);
return new Object(0, 'success');
}
/**
* @brief remove all comment relation log
**/
function deleteCommentLog()
{
$this->_deleteDeclaredComments($args);
$this->_deleteVotedComments($args);
return new Object(0, 'success');
}
/**
* @brief remove all comments of the article
@ -715,35 +845,35 @@
return new Object();
}
/**
* @brief get comment all list
**/
function procCommentGetList()
{
if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted');
$commentSrls = Context::get('comment_srls');
if($commentSrls) $commentSrlList = explode(',', $commentSrls);
/**
* @brief get comment all list
**/
function procCommentGetList()
{
if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted');
$commentSrls = Context::get('comment_srls');
if($commentSrls) $commentSrlList = explode(',', $commentSrls);
if(count($commentSrlList) > 0) {
$oCommentModel = &getModel('comment');
$commentList = $oCommentModel->getComments($commentSrlList);
if(count($commentSrlList) > 0) {
$oCommentModel = &getModel('comment');
$commentList = $oCommentModel->getComments($commentSrlList);
if(is_array($commentList))
if(is_array($commentList))
{
foreach($commentList AS $key=>$value)
{
foreach($commentList AS $key=>$value)
{
$value->content = strip_tags($value->content);
}
$value->content = strip_tags($value->content);
}
}
else
{
global $lang;
$commentList = array();
$this->setMessage($lang->no_documents);
}
$this->add('comment_list', $commentList);
}
else
{
global $lang;
$commentList = array();
$this->setMessage($lang->no_documents);
}
$this->add('comment_list', $commentList);
}
}
?>

View file

@ -143,14 +143,22 @@
**/
function getCommentCount($document_srl) {
$args->document_srl = $document_srl;
//check if module is using validation system
$oCommentController = &getController('comment');
$using_validation = $oCommentController->isModuleUsingPublishValidation($document_srl);
if($using_validation)
{
$args->status = 1;
}
// get the number of comments on the document module
$oDocumentModel = &getModel('document');
$columnList = array('document_srl', 'module_srl');
$oDocument = $oDocumentModel->getDocument($document_srl, false, true, $columnList);
// return if no doc exists.
if(!$oDocument->isExists()) return;
// get a list of comments
$module_srl = $oDocument->get('module_srl');
//check if module is using validation system
$oCommentController = &getController('comment');
$using_validation = $oCommentController->isModuleUsingPublishValidation($module_srl);
if($using_validation)
{
$args->status = 1;
}
$output = executeQuery('comment.getCommentCount', $args);
$total_count = $output->data->count;
@ -180,7 +188,7 @@
{
// check if module is using comment validation system
$oCommentController = &getController("comment");
$is_using_validation = $oCommentController->isModuleUsingPublishValidation(null,$module_srl);
$is_using_validation = $oCommentController->isModuleUsingPublishValidation($module_srl);
if($is_using_validation)
{
$args->status = 1;
@ -247,7 +255,7 @@
{
// check if module is using comment validation system
$oCommentController = &getController("comment");
$is_using_validation = $oCommentController->isModuleUsingPublishValidation(null,$obj->module_srl);
$is_using_validation = $oCommentController->isModuleUsingPublishValidation($obj->module_srl);
if($is_using_validation)
{
$args->status = 1;
@ -316,7 +324,7 @@
//check if module is using validation system
$oCommentController = &getController('comment');
$using_validation = $oCommentController->isModuleUsingPublishValidation($document_srl);
$using_validation = $oCommentController->isModuleUsingPublishValidation($module_srl);
if($using_validation)
{
$args->status = 1;
@ -437,7 +445,7 @@
// check if module is using comment validation system
$oCommentController = &getController("comment");
$is_using_validation = $oCommentController->isModuleUsingPublishValidation(null,$obj->module_srl);
$is_using_validation = $oCommentController->isModuleUsingPublishValidation($obj->module_srl);
if ($is_using_validation)
{
$args->s_is_published = 1;

View file

@ -1,26 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<module>
<grants />
<permissions>
<grants />
<permissions>
<permission action="procCommentAdminAddCart" target="manager" />
<permission action="procCommentGetList" target="manager" />
</permissions>
<actions>
<action name="getCommentMenu" type="model" standalone="true" />
<action name="dispCommentAdminList" type="view" admin_index="true" standalone="true" menu_name="comment" menu_index="true" />
<action name="dispCommentAdminDeclared" type="view" standalone="true" menu_name="comment" />
<action name="procCommentVoteUp" type="controller" standalone="true" />
<action name="procCommentVoteDown" type="controller" standalone="true" />
<action name="procCommentDeclare" type="controller" standalone="true" />
<action name="getCommentVotedMemberList" type="model" standalone="true" />
<action name="procCommentInsertModuleConfig" type="controller" standalone="true" ruleset="insertCommentModuleConfig" />
<action name="procCommentAdminDeleteChecked" type="controller" standalone="true" ruleset="deleteChecked" />
<action name="procCommentAdminChangePublishedStatusChecked" type="controller" standalone="true" />
<action name="isModuleUsingPublishValidation" type="controller" standalone="true" />
</permissions>
<actions>
<action name="getCommentMenu" type="model" standalone="true" />
<action name="dispCommentAdminList" type="view" admin_index="true" standalone="true" menu_name="comment" menu_index="true" />
<action name="dispCommentAdminDeclared" type="view" standalone="true" menu_name="comment" />
<action name="procCommentVoteUp" type="controller" standalone="true" />
<action name="procCommentVoteDown" type="controller" standalone="true" />
<action name="procCommentDeclare" type="controller" standalone="true" />
<action name="getCommentVotedMemberList" type="model" standalone="true" />
<action name="procCommentInsertModuleConfig" type="controller" standalone="true" ruleset="insertCommentModuleConfig" />
<action name="procCommentAdminDeleteChecked" type="controller" standalone="true" ruleset="deleteChecked" />
<action name="procCommentAdminChangeStatus" type="controller" standalone="true"/>
<action name="procCommentAdminChangePublishedStatusChecked" type="controller" standalone="true" />
<action name="isModuleUsingPublishValidation" type="controller" standalone="true" />
<action name="procCommentAdminCancelDeclare" type="controller" standalone="true" />
<action name="procCommentAdminAddCart" type="controller" standalone="true" />
<action name="procCommentGetList" type="controller" standalone="true" />
</actions>
<action name="procCommentAdminAddCart" type="controller" standalone="true" />
<action name="procCommentGetList" type="controller" standalone="true" />
</actions>
<menus>
<menu name="comment">
<title xml:lang="en">Comment</title>

View file

@ -79,7 +79,7 @@ xe.lang.msg_empty_search_keyword = '{$lang->msg_empty_search_keyword}';
<td class="nowr">{(zdate($val->regdate,"Y-m-d\nH:i:s"))}</td>
<td class="nowr"><a href="{getUrl('search_target','ipaddress','search_keyword',$val->ipaddress)}">{$val->ipaddress}</a></td>
<td class="nowr"><!--@if($val->isSecret())-->{$secret_name_list['Y']}<!--@else-->{$secret_name_list['N']}<!--@end--></td>
<td><!--@if($val->status)-->{$lang->published_name_list['Y']}<!--@else-->{$lang->published_name_list['N']}<!--@end--></td>
<td class="nowr"><!--@if($val->status)-->{$lang->published_name_list['Y']}<!--@else-->{$lang->published_name_list['N']}<!--@end--></td>
<td><input type="checkbox" name="cart" value="{$val->comment_srl}" /></td>
</tr>
<!--@end-->