[ 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 AdminChangeTrackbacksStatusAction extends AdminAction 17 { 18 19 var $_articleId; 20 var $_trackbackIds; 21 var $_trackbackStatus; 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 AdminChangeTrackbacksStatusAction( $actionInfo, $request ) 28 { 29 $this->AdminAction( $actionInfo, $request ); 30 $this->registerFieldValidator( "articleId", new IntegerValidator()); 31 $this->registerFieldValidator( "trackbackIds", new ArrayValidator()); 32 $this->registerFieldValidator( "trackbackStatus", new IntegerValidator()); 33 $view = new AdminArticleTrackbacksListView( $this->_blogInfo ); 34 $view->setErrorMessage( $this->_locale->tr("error_updating_trackbacks")); 35 $this->setValidationErrorView( $view ); 36 } 37 38 /** 39 * Carries out the specified action 40 */ 41 function perform() 42 { 43 $this->_articleId = $this->_request->getValue( "articleId" ); 44 $this->_trackbackIds = $this->_request->getValue( "trackbackIds" ); 45 $this->_trackbackStatus = $this->_request->getValue( "trackbackStatus" ); 46 47 $this->_changeTrackbacks(); 48 49 return true; 50 } 51 52 /** 53 * change trackbacks status 54 * @private 55 */ 56 function _changeTrackbacks() 57 { 58 $trackbacks = new Trackbacks(); 59 $errorMessage = ""; 60 $successMessage = ""; 61 $totalOk = 0; 62 63 if( $this->_articleId > 0 ) { 64 // if we can't even load the article, then forget it... 65 $articles = new Articles(); 66 $article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId()); 67 if( !$article ) { 68 $this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo ); 69 $this->_view->setErrorMessage( $this->_locale->tr("error_fetching_article" )); 70 $this->setCommonData(); 71 72 return false; 73 } 74 } 75 else { 76 // there was no article, so this probably was the view that shows all trackbacks... 77 $article = null; 78 } 79 80 // loop through the trackbacks and remove them 81 foreach( $this->_trackbackIds as $trackbackId ) { 82 // fetch the trackback 83 $trackback = $trackbacks->getTrackBack( $trackbackId ); 84 85 if( !$trackback ) { 86 $errorMessage .= $this->_locale->pr("error_updating_trackback2", $trackbackId)."<br/>"; 87 } 88 else { 89 // fire the pre-event 90 $this->notifyEvent( EVENT_PRE_TRACKBACK_UPDATE, Array( "trackback" => &$trackback )); 91 92 // check if the trackback really belongs to this blog... 93 $article = $trackback->getArticle(); 94 if( $article->getBlogId() != $this->_blogInfo->getId()) { 95 // if not, then we shouldn't be allowed to remove anything! 96 $errorMessage .= $this->_locale->pr("error_updating_trackback", $trackback->getExcerpt())."<br/>"; 97 } 98 else 99 { 100 $preTrackbackStatus = $trackback->getStatus(); 101 102 if ( $preTrackbackStatus == $this->_trackbackStatus ) 103 { 104 $errorMessage .= $this->_locale->pr("error_updating_trackback", $trackback->getExcerpt())."<br/>"; 105 continue; 106 107 } 108 109 $trackback->setStatus( $this->_trackbackStatus ); 110 if( !$trackbacks->updateComment( $trackback )) 111 $errorMessage .= $this->_locale->pr("error_updating_trackback", $trackback->getExcerpt())."<br/>"; 112 else { 113 if( $this->_trackbackStatus == COMMENT_STATUS_SPAM ) 114 { 115 $this->_markTrackbackAsSpam($trackback); 116 } 117 elseif( $this->_trackbackStatus == COMMENT_STATUS_NONSPAM ) 118 { 119 $this->_markTrackbackAsNonSpam($trackback); 120 } 121 122 $totalOk++; 123 if( $totalOk < 2 ) 124 $successMessage .= $this->_locale->pr("trackback_updated_ok", $trackback->getExcerpt()); 125 else 126 $successMessage = $this->_locale->pr("trackbacks_updated_ok", $totalOk ); 127 128 // fire the post-event 129 $this->notifyEvent( EVENT_POST_TRACKBACK_UPDATE, Array( "trackback" => &$trackback )); 130 } 131 } 132 } 133 } 134 135 // if everything fine, then display the same view again with the feedback 136 if( $this->_articleId == 0 ) 137 $this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo, Array( "article" => null )); 138 else 139 $this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo, Array( "article" => $article )); 140 141 if( $successMessage != "" ) { 142 $this->_view->setSuccessMessage( $successMessage ); 143 // clear the cache 144 CacheControl::resetBlogCache( $this->_blogInfo->getId()); 145 } 146 if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage ); 147 $this->setCommonData(); 148 149 // better to return true if everything fine 150 return true; 151 } 152 153 function _markTrackbackAsSpam( $trackback ) 154 { 155 // throw the pre-event 156 $this->notifyEvent( EVENT_PRE_MARK_SPAM_TRACKBACK, Array( "trackbackId" => $trackback->getId() )); 157 158 // We should get the trackback and train the filter to recognize this as spam... 159 lt_include( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" ); 160 $bayesian = new BayesianFilterCore(); 161 162 $bayesian->untrain( $this->_blogInfo->getId(), 163 $trackback->getTopic(), 164 $trackback->getText(), 165 $trackback->getUserName(), 166 $trackback->getUserEmail(), 167 $trackback->getUserUrl(), 168 false ); 169 170 $bayesian->train( $this->_blogInfo->getId(), 171 $trackback->getTopic(), 172 $trackback->getText(), 173 $trackback->getUserName(), 174 $trackback->getUserEmail(), 175 $trackback->getUserUrl(), 176 true ); 177 178 // throw the post-event if everythign went fine 179 $this->notifyEvent( EVENT_POST_MARK_SPAM_TRACKBACK, Array( "trackbackId" => $trackback->getId() )); 180 } 181 182 /** 183 * @private 184 */ 185 function _markTrackbackAsNonSpam( $trackback ) 186 { 187 // throw the pre-event 188 $this->notifyEvent( EVENT_PRE_MARK_NO_SPAM_TRACKBACK, Array( "trackbackId" => $trackback->getId() )); 189 190 // we should get the trackback and train the filter 191 lt_include( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" ); 192 $bayesian = new BayesianFilterCore(); 193 194 $bayesian->untrain( $this->_blogInfo->getId(), 195 $trackback->getTopic(), 196 $trackback->getText(), 197 $trackback->getUserName(), 198 $trackback->getUserEmail(), 199 $trackback->getUserUrl(), 200 true ); 201 202 $bayesian->train( $this->_blogInfo->getId(), 203 $trackback->getTopic(), 204 $trackback->getText(), 205 $trackback->getUserName(), 206 $trackback->getUserEmail(), 207 $trackback->getUserUrl(), 208 false ); 209 210 // throw the post-event if everythign went fine 211 $this->notifyEvent( EVENT_POST_MARK_NO_SPAM_TRACKBACK, Array( "trackbackId" => $trackback->getId() )); 212 } 213 } 214 ?>
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 |
![]() |