⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admindeletecommentaction.class.php

📁 一个用PHP编写的
💻 PHP
字号:
<?php	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );	lt_include( PLOG_CLASS_PATH."class/view/admin/adminarticlecommentslistview.class.php" );    lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );	    lt_include( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );    lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );	lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );    /**     * \ingroup Action     * @private     *     * Action that shows a list of all the comments for a given post     */    class AdminDeleteCommentAction extends AdminAction 	{    	var $_articleId;        var $_commentIds;		var $_mode;            	/**         * Constructor. If nothing else, it also has to call the constructor of the parent         * class, BlogAction with the same parameters         */        function AdminDeleteCommentAction( $actionInfo, $request )        {        	$this->AdminAction( $actionInfo, $request );						$this->_mode = $actionInfo->getActionParamValue();			$this->registerFieldValidator( "articleId", new IntegerValidator());			if( $this->_mode == "deleteComment" )				$this->registerFieldValidator( "commentId", new IntegerValidator());			else				$this->registerFieldValidator( "commentIds", new ArrayValidator());							$view = new AdminArticleCommentsListView( $this->_blogInfo );			$view->setErrorMessage( $this->_locale->tr("error_deleting_comments"));			$this->setValidationErrorView( $view );			$this->requirePermission( "update_comment" );			        }				/**		 * sets up the parameters and calls the method below		 */		function perform()		{			$this->_articleId = $this->_request->getValue( "articleId" );			if( $this->_mode == "deleteComment" ) {				$commentId = $this->_request->getValue( "commentId" );				$this->_commentIds = Array();				$this->_commentIds[] = $commentId;			}			else				$this->_commentIds = $this->_request->getValue( "commentIds" );							$this->_deleteComments();						return true;		}        /**         * deletes comments		 * @private         */        function _deleteComments()        {            $comments = new ArticleComments();            $errorMessage = "";			$successMessage = "";			$totalOk = 0;						if( $this->_articleId > 0 ) {				// if we can't even load the article, then forget it...				$articles = new Articles();				$article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());				if( !$article ) {					$this->_view = new AdminArticleCommentsListView( $this->_blogInfo );					$this->_view->setErrorMessage( $this->_locale->tr("error_fetching_post" ));					$this->setCommonData();										return false;				}			}			else {				// there was no article, so this probably was the view that shows all comments...				$article = null;			}						// loop through the comments and remove them            foreach( $this->_commentIds as $commentId ) {            	// fetch the comment				$comment = $comments->getComment( $commentId );								if( !$comment ) {					$errorMessage .= $this->_locale->pr("error_deleting_comment2", $commentId);				}				else {					// fire the pre-event					$this->notifyEvent( EVENT_PRE_COMMENT_DELETE, Array( "comment" => &$comment ));										// check if the comment really belongs to this blog...					$article = $comment->getArticle();                    if(!($topic = $comment->getTopic()))                        $topic = $this->_locale->tr("comment_no_topic");					if( $article->getBlogId() != $this->_blogInfo->getId()) {						// if not, then we shouldn't be allowed to remove anything!												$errorMessage .= $this->_locale->pr("error_deleting_comment", $topic)."<br/>";					}					else {						if( !$comments->deleteComment( $commentId ))							$errorMessage .= $this->_locale->pr("error_deleting_comment", $topic)."<br/>";						else {							$totalOk++;							if( $totalOk < 2 )								$successMessage .= $this->_locale->pr("comment_deleted_ok", $topic)."<br/>";							else								$successMessage = $this->_locale->pr("comments_deleted_ok", $totalOk );														// fire the post-event							$this->notifyEvent( EVENT_POST_COMMENT_DELETE, Array( "comment" => &$comment ));						}					}				}            }			// if everything fine, then display the same view again with the feedback			if( $this->_articleId == 0 )				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => null ));			else				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $article ));							if( $successMessage != "" ) {				$this->_view->setSuccessMessage( $successMessage );				// clear the cache				CacheControl::resetBlogCache( $this->_blogInfo->getId());			}			if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );            $this->setCommonData();            // better to return true if everything fine            return true;        }    }?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -