[ 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/ -> adminchangecommentsstatusaction.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/view/admin/adminarticlecommentslistview.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );    
   6      lt_include( PLOG_CLASS_PATH."class/dao/articlecomments.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       * Action that shows a list of all the comments for a given post
  15       */
  16      class AdminChangeCommentsStatusAction extends AdminAction 
  17      {
  18  
  19          var $_articleId;
  20          var $_commentIds;
  21          var $_commentStatus;
  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 AdminChangeCommentsStatusAction( $actionInfo, $request )
  28          {
  29              $this->AdminAction( $actionInfo, $request );
  30              $this->registerFieldValidator( "articleId", new IntegerValidator());
  31              $this->registerFieldValidator( "commentIds", new ArrayValidator());
  32              $this->registerFieldValidator( "commentStatus", new IntegerValidator());
  33              $view = new AdminArticleCommentsListView( $this->_blogInfo );
  34              $view->setErrorMessage( $this->_locale->tr("error_updating_comments"));
  35              $this->setValidationErrorView( $view );
  36          }
  37          
  38          /**
  39           * sets up the parameters and calls the method below
  40           */
  41  		function perform()
  42          {
  43              $this->_articleId = $this->_request->getValue( "articleId" );
  44              $this->_commentIds = $this->_request->getValue( "commentIds" );
  45              $this->_commentStatus = $this->_request->getValue( "commentStatus" );
  46                  
  47              $this->_changeComments();
  48              
  49              return true;
  50          }
  51  
  52          /**
  53           * changes comments status
  54           * @private
  55           */
  56          function _changeComments()
  57          {
  58              $comments = new ArticleComments();
  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 AdminArticleCommentsListView( $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 comments...
  77                  $article = null;
  78              }
  79              
  80              // loop through the comments and change them
  81              foreach( $this->_commentIds as $commentId ) {
  82                  // fetch the comment
  83                  $comment = $comments->getComment( $commentId );
  84                  
  85                  if( !$comment ) {
  86                      $errorMessage .= $this->_locale->pr("error_updating_comment_no_comment", $commentId);
  87                  }
  88                  else {
  89                      // fire the pre-event
  90                      $this->notifyEvent( EVENT_PRE_COMMENT_UPDATE, Array( "comment" => &$comment ));
  91                      
  92                      // check if the comment really belongs to this blog...
  93                      $article = $comment->getArticle();
  94                      if( $article->getBlogId() != $this->_blogInfo->getId()) {
  95                          // if not, then we shouldn't be allowed to change anything!                        
  96                          $errorMessage .= $this->_locale->pr("error_updating_comment_wrong_blog", $comment->getTopic())."<br/>";
  97                      }
  98                      else
  99                      {
 100                          $preCommentStatus = $comment->getStatus();
 101                          
 102                          if ( $preCommentStatus == $this->_commentStatus )
 103                          {
 104                              $errorMessage .= $this->_locale->pr("error_updating_comment_already_updated", $comment->getTopic())."<br/>";
 105                              continue;
 106                          }
 107  
 108                          $comment->setStatus( $this->_commentStatus );
 109                          if( !$comments->updateComment( $comment ))
 110                              $errorMessage .= $this->_locale->pr("error_updating_comment", $comment->getTopic())."<br/>";
 111                          else {
 112                              if( $this->_commentStatus == COMMENT_STATUS_SPAM )
 113                              {
 114                                  $this->_markCommentAsSpam($comment);
 115                              }
 116                              elseif( $this->_commentStatus == COMMENT_STATUS_NONSPAM )
 117                              {
 118                                  $this->_markCommentAsNonSpam($comment);
 119                              }
 120  
 121                              $totalOk++;
 122                              if( $totalOk < 2 )
 123                                  $successMessage .= $this->_locale->tr("comment_updated_ok")."<br/>";
 124                              else
 125                                  $successMessage = $this->_locale->pr("comments_updated_ok", $totalOk );
 126                              
 127                              // fire the post-event
 128                              $this->notifyEvent( EVENT_POST_COMMENT_UPDATE, Array( "comment" => &$comment ));
 129                          }
 130                      }
 131                  }
 132              }
 133  
 134              // if everything fine, then display the same view again with the feedback
 135              if( $this->_articleId == 0 )
 136                  $this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => null ));
 137              else
 138                  $this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $article ));
 139                  
 140              if( $successMessage != "" ) {
 141                  $this->_view->setSuccessMessage( $successMessage );
 142                  // clear the cache
 143                  CacheControl::resetBlogCache( $this->_blogInfo->getId());
 144              }
 145              if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
 146              $this->setCommonData();
 147  
 148              // better to return true if everything fine
 149              return true;
 150          }
 151          
 152          function _markCommentAsSpam( $comment )
 153          {
 154              // throw the pre-event
 155              $this->notifyEvent( EVENT_PRE_MARK_SPAM_COMMENT, Array( "commentId" => $comment->getId() ));
 156  
 157              // We should get the comment and train the filter to recognize this as spam...
 158                 lt_include( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
 159                 $bayesian = new BayesianFilterCore();
 160      
 161              $bayesian->untrain( $this->_blogInfo->getId(),
 162                                  $comment->getTopic(),
 163                                  $comment->getText(),
 164                                  $comment->getUserName(),
 165                                  $comment->getUserEmail(),
 166                                  $comment->getUserUrl(),
 167                                  false );
 168                                        
 169              $bayesian->train( $this->_blogInfo->getId(),
 170                                $comment->getTopic(),
 171                                $comment->getText(),
 172                                $comment->getUserName(),
 173                                $comment->getUserEmail(),
 174                                $comment->getUserUrl(),
 175                                true );
 176                                        
 177              // throw the post-event if everythign went fine
 178              $this->notifyEvent( EVENT_POST_MARK_SPAM_COMMENT, Array( "commentId" => $comment->getId() ));                                  
 179          }
 180          
 181          /**
 182           * @private
 183           */
 184          function _markCommentAsNonSpam( $comment )
 185          {
 186              // throw the pre-event
 187              $this->notifyEvent( EVENT_PRE_MARK_NO_SPAM_COMMENT, Array( "commentId" => $comment->getId() ));
 188          
 189              // we should get the comment and train the filter
 190                 lt_include( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
 191                 $bayesian = new BayesianFilterCore();
 192                 
 193              $bayesian->untrain( $this->_blogInfo->getId(),
 194                                  $comment->getTopic(),
 195                                  $comment->getText(),
 196                                  $comment->getUserName(),
 197                                  $comment->getUserEmail(),
 198                                  $comment->getUserUrl(),
 199                                  true );
 200                                        
 201              $bayesian->train( $this->_blogInfo->getId(),
 202                                $comment->getTopic(),
 203                                $comment->getText(),
 204                                $comment->getUserName(),
 205                                $comment->getUserEmail(),
 206                                $comment->getUserUrl(),
 207                                false );
 208  
 209              // throw the post-event if everythign went fine
 210              $this->notifyEvent( EVENT_POST_MARK_NO_SPAM_COMMENT, Array( "commentId" => $comment->getId() ));
 211          }
 212      }
 213  ?>


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