[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 9 10 /** 11 * \ingroup Action 12 * @private 13 * 14 * Deletes a post from the database 15 */ 16 class AdminDeletePostAction extends AdminAction 17 { 18 19 var $_postIds; 20 21 /** 22 * Constructor. If nothing else, it also has to call the constructor of the parent 23 * class, BlogAction with the same parameters 24 */ 25 function AdminDeletePostAction( $actionInfo, $request ) 26 { 27 $this->AdminAction( $actionInfo, $request ); 28 29 // data validation stuff... 30 $this->_mode = $actionInfo->getActionParamValue(); 31 32 if( $this->_mode == "deletePost" ) 33 $this->registerFieldValidator( "postId", new IntegerValidator()); 34 else 35 $this->registerFieldValidator( "postIds", new ArrayValidator()); 36 37 $view = new AdminPostsListView( $this->_blogInfo ); 38 $view->setErrorMessage( $this->_locale->tr("error_incorrect_article_id")); 39 $this->setValidationErrorView( $view ); 40 41 $this->requirePermission( "update_post" ); 42 } 43 44 /** 45 * Carries out the specified action 46 */ 47 function _deletePosts() 48 { 49 // delete the post (it is not physically deleted but rather, we set 50 // the status field to 'DELETED' 51 $articles = new Articles(); 52 $errorMessage = ""; 53 $successMessage = ""; 54 $totalOk = 0; 55 56 foreach( $this->_postIds as $postId ) { 57 // get the post 58 $post = $articles->getBlogArticle( $postId, $this->_blogInfo->getId()); 59 60 if( $post ) { 61 // fire the event 62 $this->notifyEvent( EVENT_PRE_POST_DELETE, Array( "article" => &$post )); 63 64 $canDelete = false; 65 $userId = 0; 66 if( $this->userHasPermission( "update_all_user_articles" )) 67 $canDelete = true; 68 else { 69 if( $post->getUserId() != $this->_userInfo->getId()) 70 $canDelete = false; 71 else 72 $canDelete = true; 73 } 74 75 if( $canDelete ) 76 $result = $articles->deleteArticle( $postId, $post->getUser(), $this->_blogInfo->getId(), false ); 77 else { 78 $errorMessage .= $this->_locale->tr("error_can_only_update_own_articles")." "; 79 $result = false; 80 } 81 82 if( !$result ) { 83 $errorMessage .= $this->_locale->pr("error_deleting_article", $post->getTopic())."<br/>"; 84 } 85 else { 86 $totalOk++; 87 if( $totalOk < 2 ) 88 $successMessage .= $this->_locale->pr("article_deleted_ok", $post->getTopic())."<br/>"; 89 else 90 $successMessage = $this->_locale->pr("articles_deleted_ok", $totalOk ); 91 // fire the post event 92 $this->notifyEvent( EVENT_POST_POST_DELETE, Array( "article" => &$post )); 93 } 94 } 95 else { 96 $errorMessage .= $this->_locale->pr( "error_deleting_article2", $postId )."<br/>"; 97 } 98 } 99 100 // clean up the cache 101 CacheControl::resetBlogCache( $this->_blogInfo->getId()); 102 103 $this->_view = new AdminPostsListView( $this->_blogInfo ); 104 if( $errorMessage != "" ) 105 $this->_view->setErrorMessage( $errorMessage ); 106 if( $successMessage != "" ) 107 $this->_view->setSuccessMessage( $successMessage ); 108 109 $this->setCommonData(); 110 111 return true; 112 } 113 114 function perform() 115 { 116 // prepare the parameters.. If there's only one category id, then add it to 117 // an array. 118 if( $this->_mode == "deletePost" ) { 119 $this->_postIds = Array(); 120 $this->_postIds[] = $this->_request->getValue( "postId" ); 121 } 122 else 123 $this->_postIds = $this->_request->getValue( "postIds" ); 124 125 $this->_deletePosts(); 126 } 127 } 128 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |