[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/action/admin/ -> adminmarkcommentaction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/dao/articlecomments.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/adminarticlecommentslistview.class.php" );
  10      
  11      /**

  12       * \ingroup Action

  13       * @private

  14       *     * sets the spam status for a post

  15       */
  16      class AdminMarkCommentAction extends AdminAction
  17      {
  18  
  19          var $_commentId;
  20          var $_articleId;
  21          var $_mode;
  22          var $_article;
  23          var $_comment;
  24  
  25          /**

  26           * Constructor. If nothing else, it also has to call the constructor of the parent

  27           * class, BlogAction with the same parameters

  28           */
  29          function AdminMarkCommentAction( $actionInfo, $request )
  30          {
  31              $this->AdminAction( $actionInfo, $request );
  32              
  33              // data validation

  34              $this->registerFieldValidator( "commentId", new IntegerValidator());
  35              $this->registerFieldValidator( "articleId", new IntegerValidator());
  36              $this->registerFieldValidator( "mode", new IntegerValidator());
  37              $view = new AdminPostsListView( $this->_blogInfo );
  38              $view->setErrorMessage( $this->_locale->tr("error_incorrect_comment_id"));
  39              $this->setValidationErrorView( $view );
  40              
  41              $this->requirePermission( "update_comment" );            
  42          }
  43  
  44          /**

  45           * @private

  46           * Returns true wether the comment whose status we're trying to change

  47           * really belongs to this blog, just in case somebody's trying to mess

  48           * around with that...

  49           */
  50          function _checkComment( $commentId, $articleId, $blogId )
  51          {
  52              $articleComments = new ArticleComments();
  53              $articles = new Articles();
  54  
  55              // fetch the comment

  56              $this->_comment = $articleComments->getComment( $commentId );
  57              if( !$this->_comment )
  58                  return false;
  59  
  60              $this->_article = $this->_comment->getArticle();
  61              
  62              // check that the comment really belongs to this blog

  63              if( $this->_blogInfo->getId() != $this->_article->getBlog())
  64                  return false;
  65  
  66              return true;
  67          }
  68  
  69          /**

  70           * @private

  71           */
  72          function _markCommentAsSpam()
  73          {
  74              // throw the pre-event

  75              $this->notifyEvent( EVENT_PRE_MARK_SPAM_COMMENT, Array( "commentId" => $this->_commentId ));
  76              
  77              if( $this->_articleId == 0 )
  78                  $this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => null ));
  79              else
  80                  $this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $this->_article ));            
  81              
  82              $comments = new ArticleComments();
  83              $comment = $comments->getComment( $this->_commentId );
  84              if( $comment ) {
  85                  $comment->setStatus( COMMENT_STATUS_SPAM );
  86                  if(($comment->getBlogId() != $this->_blogInfo->getId()) || 
  87                      (!$comments->updateComment( $comment ))) {
  88                      $this->_view->setErrorMessage( $this->_locale->tr("error_marking_comment_as_spam" ));
  89                      $this->setCommonData();
  90                      
  91                      $res = false;
  92                  }
  93                  else {
  94                      $this->_view->setSuccessMessage( $this->_locale->tr("comment_marked_as_spam_ok" ));                
  95                      $this->setCommonData();
  96                      
  97                      $res = true;
  98      
  99                      // before exiting, we should get the comment and train the filter

 100                      // to recognize this as spam...

 101                      $comment = $comments->getComment( $this->_commentId );
 102                      $bayesian = new BayesianFilterCore();
 103      
 104                      $bayesian->untrain( $this->_blogInfo->getId(),
 105                                          $comment->getTopic(),
 106                                          $comment->getText(),
 107                                          $comment->getUserName(),
 108                                          $comment->getUserEmail(),
 109                                          $comment->getUserUrl(),
 110                                          false );
 111                                        
 112                      $bayesian->train( $this->_blogInfo->getId(),
 113                                        $comment->getTopic(),
 114                                        $comment->getText(),
 115                                        $comment->getUserName(),
 116                                        $comment->getUserEmail(),
 117                                        $comment->getUserUrl(),
 118                                        true );
 119                                        
 120                      // throw the post-event if everythign went fine

 121                      $this->notifyEvent( EVENT_POST_MARK_SPAM_COMMENT, Array( "commentId" => $this->_commentId ));                                  
 122                  }                
 123              }            
 124  
 125              return $res;
 126          }
 127  
 128          /**

 129           * @private

 130           */
 131          function _markCommentAsNonSpam()
 132          {
 133              // throw the pre-event

 134              $this->notifyEvent( EVENT_PRE_MARK_NO_SPAM_COMMENT, Array( "commentId" => $this->_commentId ));
 135          
 136              if( $this->_articleId == 0 )
 137                  $this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => null ));
 138              else
 139                  $this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $this->_article ));            
 140          
 141              $comments = new ArticleComments();
 142              $comment = $comments->getComment( $this->_commentId );
 143              if( $comment ) {
 144                  $comment->setStatus( COMMENT_STATUS_NONSPAM );
 145                  if(( $comment->getBlogId() != $this->_blogInfo->getId()) ||
 146                      (!$comments->updateComment( $comment ))) {    
 147  
 148                      $this->_view->setErrorMessage( $this->_locale->tr("error_marking_comment_as_nonspam" ));
 149                      $this->setCommonData();
 150                  
 151                  $res = false;
 152                  }
 153                  else {
 154                      $this->_view->setSuccessMessage( $this->_locale->tr("comment_marked_as_nonspam_ok" ));                
 155                      $this->setCommonData();
 156                  
 157                      $res = true;
 158  
 159                      // before exiting, we should get the comment and train the filter

 160                      // to recognize this as spam...

 161                      $comment = $comments->getComment( $this->_commentId );
 162                      $bayesian = new BayesianFilterCore();
 163                  
 164                      $bayesian->untrain( $this->_blogInfo->getId(),
 165                                          $comment->getTopic(),
 166                                          $comment->getText(),
 167                                          $comment->getUserName(),
 168                                          $comment->getUserEmail(),
 169                                          $comment->getUserUrl(),
 170                                          true );
 171                                        
 172                      $bayesian->train( $this->_blogInfo->getId(),
 173                                        $comment->getTopic(),
 174                                        $comment->getText(),
 175                                        $comment->getUserName(),
 176                                        $comment->getUserEmail(),
 177                                        $comment->getUserUrl(),
 178                                        false );
 179                                        
 180                      // throw the post-event if everythign went fine

 181                      $this->notifyEvent( EVENT_POST_MARK_NO_SPAM_COMMENT, Array( "commentId" => $this->_commentId ));
 182                  }
 183             }
 184  
 185              return $res;
 186          }
 187  
 188          /**

 189           * Carries out the specified action

 190           */
 191          function perform()
 192          {
 193              // fetch the data

 194              $this->_commentId = $this->_request->getValue( "commentId" );
 195              $this->_articleId = $this->_request->getValue( "articleId" );
 196              $this->_mode = $this->_request->getValue( "mode" );        
 197          
 198              // first, let's make sure that the user is trying to edit the right

 199              // comment...

 200              if( !$this->_checkComment( $this->_commentId, $this->_articleId, $this->_blogInfo->getId())) {
 201                  // if things don't match... (like trying to set the status of an article

 202                  // from another blog, then quit...)

 203                  $this->_view = new AdminPostsListView( $this->_blogInfo );
 204                  $this->_view->setErrorMessage( $this->_locale->tr("error_incorrect_comment_id"));
 205                  $this->setCommonData();
 206                  return false;
 207              }
 208  
 209              // depending on the mode, we have to do one thing or another

 210              if( $this->_mode == 0 )
 211                  $result = $this->_markCommentAsNonSpam();
 212              else
 213                  $result = $this->_markCommentAsSpam();
 214                  
 215              // clear the cache

 216              CacheControl::resetBlogCache( $this->_blogInfo->getId());
 217  
 218              // better to return true if everything fine

 219              return $result;
 220          }
 221      }
 222  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics