[ 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/dao/trackbacks.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" ); 9 lt_include( PLOG_CLASS_PATH."class/view/admin/adminarticletrackbackslistview.class.php" ); 10 11 /** 12 * \ingroup Action 13 * @private 14 * 15 * sets the spam status for a post 16 */ 17 class AdminMarkTrackbackAction extends AdminAction 18 { 19 20 var $_trackbackId; 21 var $_articleId; 22 var $_mode; 23 var $_article; 24 var $_comment; 25 26 /** 27 * Constructor. If nothing else, it also has to call the constructor of the parent 28 * class, BlogAction with the same parameters 29 */ 30 function AdminMarkTrackbackAction( $actionInfo, $request ) 31 { 32 $this->AdminAction( $actionInfo, $request ); 33 34 // data validation 35 $this->registerFieldValidator( "trackbackId", new IntegerValidator()); 36 $this->registerFieldValidator( "articleId", new IntegerValidator()); 37 $this->registerFieldValidator( "mode", new IntegerValidator()); 38 $view = new AdminPostsListView( $this->_blogInfo ); 39 $view->setErrorMessage( $this->_locale->tr("error_incorrect_trackback_id")); 40 $this->setValidationErrorView( $view ); 41 42 $this->requirePermission( "view_trackbacks" ); 43 } 44 45 /** 46 * @private 47 * Returns true wether the comment whose status we're trying to change 48 * really belongs to this blog, just in case somebody's trying to mess 49 * around with that... 50 */ 51 function _checkTrackback( $trackbackId, $articleId, $blogId ) 52 { 53 $trackbacks = new Trackbacks(); 54 $articles = new Articles(); 55 56 // fetch the comment 57 $this->_trackback = $trackbacks->getTrackBack( $trackbackId ); 58 if( !$this->_trackback ) 59 return false; 60 61 // fetch the article 62 $this->_article = $articles->getBlogArticle( $this->_trackback->getArticleId(), $blogId ); 63 if( !$this->_article ) 64 return false; 65 66 return true; 67 } 68 69 /** 70 * @private 71 */ 72 function _markTrackbackAsSpam() 73 { 74 // throw the pre-event 75 $this->notifyEvent( EVENT_PRE_MARK_SPAM_TRACKBACK, Array( "trackbackId" => $this->_trackbackId )); 76 77 $this->_view = new AdminArticleTrackbacksListview( $this->_blogInfo, Array( "article" => $this->_article )); 78 79 $trackbacks = new Trackbacks(); 80 $this->_trackback->setStatus( COMMENT_STATUS_SPAM ); 81 if( !$trackbacks->updateComment( $this->_trackback )) { 82 $this->_view->setErrorMessage( $this->_locale->tr("error_marking_trackback_as_spam" )); 83 $this->setCommonData(); 84 85 $res = false; 86 } 87 else { 88 $this->_view->setSuccessMessage( $this->_locale->tr("trackback_marked_as_spam_ok" )); 89 $this->setCommonData(); 90 91 $res = true; 92 93 // before exiting, we should get the comment and train the filter 94 // to recognize this as spam... 95 $trackback = $trackbacks->getTrackBack( $this->_trackbackId ); 96 $bayesian = new BayesianFilterCore(); 97 98 $bayesian->untrain( $this->_blogInfo->getId(), 99 $trackback->getTopic(), 100 $trackback->getText(), 101 $trackback->getUserName(), 102 $trackback->getUserEmail(), 103 $trackback->getUserUrl(), 104 false ); 105 106 $bayesian->train( $this->_blogInfo->getId(), 107 $trackback->getTopic(), 108 $trackback->getText(), 109 $trackback->getUserName(), 110 $trackback->getUserEmail(), 111 $trackback->getUserUrl(), 112 true ); 113 114 // throw the post-event if everythign went fine 115 $this->notifyEvent( EVENT_POST_MARK_SPAM_TRACKBACK, Array( "trackbackId" => $this->_trackbackId )); 116 } 117 118 return $res; 119 } 120 121 /** 122 * @private 123 */ 124 function _markTrackbackAsNonSpam() 125 { 126 // throw the pre-event 127 $this->notifyEvent( EVENT_PRE_MARK_NO_SPAM_TRACKBACK, Array( "trackbackId" => $this->_trackbackId )); 128 129 $this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo, Array( "article" => $this->_article )); 130 131 $trackbacks = new Trackbacks(); 132 $this->_trackback->setStatus( COMMENT_STATUS_NONSPAM ); 133 if( !$trackbacks->updateComment( $this->_trackback )) { 134 $this->_view->setErrorMessage( $this->_locale->tr("error_marking_trackback_as_nonspam" )); 135 $this->setCommonData(); 136 137 $res = false; 138 } 139 else { 140 $this->_view->setSuccessMessage( $this->_locale->tr("trackback_marked_as_nonspam_ok" )); 141 $this->setCommonData(); 142 143 $res = true; 144 145 // before exiting, we should get the comment and train the filter 146 // to recognize this as spam... 147 $trackback = $trackbacks->getTrackBack( $this->_trackbackId, $this->_articleId ); 148 $bayesian = new BayesianFilterCore(); 149 150 $bayesian->untrain( $this->_blogInfo->getId(), 151 $trackback->getTopic(), 152 $trackback->getText(), 153 $trackback->getUserName(), 154 $trackback->getUserEmail(), 155 $trackback->getUserUrl(), 156 true ); 157 158 $bayesian->train( $this->_blogInfo->getId(), 159 $trackback->getTopic(), 160 $trackback->getText(), 161 $trackback->getUserName(), 162 $trackback->getUserEmail(), 163 $trackback->getUserUrl(), 164 false ); 165 166 // throw the post-event if everythign went fine 167 $this->notifyEvent( EVENT_POST_MARK_NO_SPAM_TRACKBACK, Array( "trackbackId" => $this->_trackbackId )); 168 } 169 170 return $res; 171 } 172 173 /** 174 * Carries out the specified action 175 */ 176 function perform() 177 { 178 // fetch the data 179 180 $this->_trackbackId = $this->_request->getValue( "trackbackId" ); 181 $this->_articleId = $this->_request->getValue( "articleId" ); 182 $this->_mode = $this->_request->getValue( "mode" ); 183 184 // first, let's make sure that the user is trying to edit the right 185 // comment... 186 if( !$this->_checkTrackback( $this->_trackbackId, $this->_articleId, $this->_blogInfo->getId())) { 187 // if things don't match... (like trying to set the status of an article 188 // from another blog, then quit...) 189 $this->_view = new AdminPostsListView( $this->_blogInfo ); 190 $this->_view->setErrorMessage( $this->_locale->tr("error_incorrect_trackback_id")); 191 $this->setCommonData(); 192 return false; 193 } 194 195 // depending on the mode, we have to do one thing or another 196 if( $this->_mode == 0 ) 197 $result = $this->_markTrackbackAsNonSpam(); 198 else 199 $result = $this->_markTrackbackAsSpam(); 200 201 // clear the cache 202 CacheControl::resetBlogCache( $this->_blogInfo->getId()); 203 204 // better to return true if everything fine 205 return $result; 206 } 207 } 208 ?>
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 |
![]() |