| [ 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/adminarticletrackbackslistview.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" ); 9 10 /** 11 * \ingroup Action 12 * @private 13 * 14 * Allows to remove trackbacks from a certain article 15 */ 16 class AdminDeleteTrackbackAction extends AdminAction 17 { 18 19 var $_articleId; 20 var $_trackbackIds; 21 var $_mode; 22 23 /** 24 * Constructor. If nothing else, it also has to call the constructor of the parent 25 * class, BlogAction with the same parameters 26 */ 27 function AdminDeleteTrackbackAction( $actionInfo, $request ) 28 { 29 $this->AdminAction( $actionInfo, $request ); 30 31 $this->_mode = $actionInfo->getActionParamValue(); 32 $this->registerFieldValidator( "articleId", new IntegerValidator()); 33 if( $this->_mode == "deleteTrackback" ) 34 $this->registerFieldValidator( "trackbackId", new IntegerValidator()); 35 else 36 $this->registerFieldValidator( "trackbackIds", new ArrayValidator()); 37 38 $view = new AdminArticleTrackbacksListView( $this->_blogInfo ); 39 $view->setErrorMessage( $this->_locale->tr("error_deleting_trackbacks")); 40 $this->setValidationErrorView( $view ); 41 42 $this->requirePermission( "update_trackback" ); 43 } 44 45 /** 46 * Carries out the specified action 47 */ 48 function perform() 49 { 50 $this->_articleId = $this->_request->getValue( "articleId" ); 51 if( $this->_mode == "deleteTrackback" ) { 52 $trackbackId = $this->_request->getValue( "trackbackId" ); 53 $this->_trackbackIds = Array(); 54 $this->_trackbackIds[] = $trackbackId; 55 } 56 else 57 $this->_trackbackIds = $this->_request->getValue( "trackbackIds" ); 58 59 $this->_deleteTrackbacks(); 60 61 return true; 62 } 63 64 /** 65 * deletes trackbacks 66 * @private 67 */ 68 function _deleteTrackbacks() 69 { 70 $trackbacks = new Trackbacks(); 71 $errorMessage = ""; 72 $successMessage = ""; 73 $totalOk = 0; 74 75 if( $this->_articleId > 0 ) { 76 // if we can't even load the article, then forget it... 77 $articles = new Articles(); 78 $article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId()); 79 if( !$article ) { 80 $this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo ); 81 $this->_view->setErrorMessage( $this->_locale->tr("error_fetching_article" )); 82 $this->setCommonData(); 83 84 return false; 85 } 86 } 87 else { 88 // there was no article, so this probably was the view that shows all trackbacks... 89 $article = null; 90 } 91 92 // loop through the trackbacks and remove them 93 foreach( $this->_trackbackIds as $trackbackId ) { 94 // fetch the trackback 95 $trackback = $trackbacks->getTrackBack( $trackbackId ); 96 97 if( !$trackback ) { 98 $errorMessage .= $this->_locale->pr("error_deleting_trackback2", $trackbackId)."<br/>"; 99 } 100 else { 101 // fire the pre-event 102 $this->notifyEvent( EVENT_PRE_TRACKBACK_DELETE, Array( "trackback" => &$trackback )); 103 104 // check if the trackback really belongs to this blog... 105 $article = $trackback->getArticle(); 106 if( $article && ($article->getBlogId() != $this->_blogInfo->getId())) { 107 // if not, then we shouldn't be allowed to remove anything! 108 $errorMessage .= $this->_locale->pr("error_deleting_trackback", $trackback->getExcerpt())."<br/>"; 109 } 110 else { 111 if( !$trackbacks->deleteTrackBack( $trackbackId )) 112 $errorMessage .= $this->_locale->pr("error_deleting_trackback", $trackback->getExcerpt())."<br/>"; 113 else { 114 $totalOk++; 115 if( $totalOk < 2 ) 116 $successMessage .= $this->_locale->pr("trackback_deleted_ok", $trackback->getExcerpt()); 117 else 118 $successMessage = $this->_locale->pr("trackbacks_deleted_ok", $totalOk ); 119 120 // fire the post-event 121 $this->notifyEvent( EVENT_POST_TRACKBACK_DELETE, Array( "trackback" => &$trackback )); 122 } 123 } 124 } 125 } 126 127 // if everything fine, then display the same view again with the feedback 128 if( $this->_articleId == 0 ) 129 $this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo, Array( "article" => null )); 130 else 131 $this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo, Array( "article" => $article )); 132 133 if( $successMessage != "" ) { 134 $this->_view->setSuccessMessage( $successMessage ); 135 // clear the cache 136 CacheControl::resetBlogCache( $this->_blogInfo->getId()); 137 } 138 if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage ); 139 $this->setCommonData(); 140 141 // better to return true if everything fine 142 return true; 143 } 144 } 145 ?>
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 |
|