From 0748cccdad0226f1d7ae3667f4d4d6f799edf9c1 Mon Sep 17 00:00:00 2001 From: dionisrom Date: Wed, 7 Mar 2012 13:22:01 +0000 Subject: [PATCH] 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 --- common/lang/lang.xml | 3 + modules/comment/comment.admin.controller.php | 170 ++++++++---- modules/comment/comment.controller.php | 276 ++++++++++++++----- modules/comment/comment.model.php | 32 ++- modules/comment/conf/module.xml | 37 +-- modules/comment/tpl/comment_list.html | 2 +- 6 files changed, 358 insertions(+), 162 deletions(-) diff --git a/common/lang/lang.xml b/common/lang/lang.xml index bc4ff5927..544297e62 100644 --- a/common/lang/lang.xml +++ b/common/lang/lang.xml @@ -2809,6 +2809,9 @@ Xin vui lòng kiểm tra lại thông tin Database.]]> + + + diff --git a/modules/comment/comment.admin.controller.php b/modules/comment/comment.admin.controller.php index d986da04c..5c2bb5a4e 100644 --- a/modules/comment/comment.admin.controller.php +++ b/modules/comment/comment.admin.controller.php @@ -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("
%s

%s
",$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 ". strtoupper($module_info->mid)." module. +
+
Comment content: + ".$comment->content." +
+ "; + $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;$isetReceiptor($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 **/ diff --git a/modules/comment/comment.controller.php b/modules/comment/comment.controller.php index f2dbba63c..af58262d5 100644 --- a/modules/comment/comment.controller.php +++ b/modules/comment/comment.controller.php @@ -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. +
+
+ Author: ".$member_info->nick_name." +
Author e-mail: ".$member_info->email_address." +
Comment: +
\"".$obj->content."\" +
+
+ Approve it: ".$url_approve." +
Trash it: ".$url_trash." +
Currently ".$nr_comments_not_approved." comments on \"".Context::get('mid')."\" module are waiting for approval. Please visit the moderation panel: +
module_srl)."\">".getFullUrl('','module','admin','act','dispCommentAdminList','search_target','module','search_keyword',$obj->module_srl)." + "; + $oMail->setContent($mail_content); + } + else + { + $mail_content = " + Author: ".$member_info->nick_name." +
Author e-mail: ".$member_info->email_address." +
Comment: +
\"".$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;$isetReceiptor($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 : %s?document_srl=%s&comment_srl=%s#comment_%d
\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 ". strtoupper($module_info->mid)." module before to be publish. +
+
Comment content: + ".$obj->content." +
+ "; + $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); + } } ?> diff --git a/modules/comment/comment.model.php b/modules/comment/comment.model.php index fe884b166..579a7bd9d 100644 --- a/modules/comment/comment.model.php +++ b/modules/comment/comment.model.php @@ -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; diff --git a/modules/comment/conf/module.xml b/modules/comment/conf/module.xml index 99cdcb480..f681d3f47 100644 --- a/modules/comment/conf/module.xml +++ b/modules/comment/conf/module.xml @@ -1,26 +1,27 @@ - - + + - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - + + + Comment diff --git a/modules/comment/tpl/comment_list.html b/modules/comment/tpl/comment_list.html index fa4806689..48b8584f6 100644 --- a/modules/comment/tpl/comment_list.html +++ b/modules/comment/tpl/comment_list.html @@ -79,7 +79,7 @@ xe.lang.msg_empty_search_keyword = '{$lang->msg_empty_search_keyword}'; {(zdate($val->regdate,"Y-m-d\nH:i:s"))} {$val->ipaddress} {$secret_name_list['Y']}{$secret_name_list['N']} - {$lang->published_name_list['Y']}{$lang->published_name_list['N']} + {$lang->published_name_list['Y']}{$lang->published_name_list['N']}