[ 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/ -> adminupdatepostaction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/admin/adminpostmanagementcommonaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/view/admin/admineditpostview.class.php" );    
   6      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );    
   7      lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );        
   8      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
  10      lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfieldsvalues.class.php" );
  11      lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfields.class.php" ); 
  12      lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
  13      lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
  14      lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
  15      lt_include( PLOG_CLASS_PATH."class/data/stringutils.class.php" );
  16  
  17      /**
  18       * \ingroup Action
  19       * @private
  20       *
  21       * Updates the values of the post in the database
  22       *
  23       * Btw, this class could very well need some refactoring... :)
  24       */
  25      class AdminUpdatePostAction extends AdminPostManagementCommonAction
  26      {
  27  
  28          /**
  29           * Constructor. If nothing else, it also has to call the constructor of the parent
  30           * class, BlogAction with the same parameters
  31           */
  32          function AdminUpdatePostAction( $actionInfo, $request )
  33          {
  34              $this->AdminPostManagementCommonAction( $actionInfo, $request );
  35              
  36              // for data validation purposes, posts must have at least a topic, an intro text, and a category
  37              $this->registerFieldValidator( "postText", new StringValidator());
  38              $this->registerFieldValidator( "postTopic", new StringValidator());
  39              $this->registerFieldValidator( "postCategories", new ArrayValidator());
  40              $this->registerFieldValidator( "postId", new IntegerValidator());
  41              $this->registerFieldValidator( "globalArticleCategoryId", new IntegerValidator(), true );
  42  
  43              $view = new AdminEditPostView( $this->_blogInfo );
  44  
  45              $dateTimeParts = explode(" ", $this->_request->getValue("postDateTime"));
  46              $dateParts = explode("/", $dateTimeParts[0] );
  47              $timeParts = explode(":",$dateTimeParts[1] );
  48              $view->setValue( "postDay", $dateParts[0]);
  49              $view->setValue( "postMonth", $dateParts[1]);
  50              $view->setValue( "postYear", $dateParts[2]);
  51              $view->setValue( "postHour", $timeParts[0]);
  52              $view->setValue( "postMinutes", $timeParts[1]);
  53  
  54              $view->setErrorMessage( $this->_locale->tr("error_updating_post"));
  55              $this->setValidationErrorView( $view );
  56              
  57              // these fields do not need to be validated but should be there when we show the view once again
  58              $this->registerField( "postExtendedText" );
  59              $this->registerField( "postSlug" );
  60              $this->registerField( "postStatus" );
  61              $this->registerField( "sendNotification" );
  62              $this->registerField( "sendTrackbacks" );
  63              $this->registerField( "sendPings" );
  64              $this->registerField( "postId" );
  65              $this->registerField( "commentsEnabled" );
  66              $this->registerField( "customField" );
  67              $this->registerField( "postDateTime" );   
  68              $this->registerField( "trackbackUrls" );
  69              $this->registerField( "postUser" );       
  70  
  71              $this->requirePermission( "update_post" );
  72          }
  73          
  74          /**
  75           * Carries out the specified action
  76           */
  77          function perform()
  78          {    
  79              // fetch the data
  80              $this->_fetchCommonData();            
  81              $this->_postId = $this->_request->getValue( "postId" );
  82                  
  83              // fetch the old post
  84              $articles =  new Articles();
  85              $post     = $articles->getBlogArticle( $this->_postId, $this->_blogInfo->getId());
  86              // there must be something wrong if we can't fetch the post that we are trying to update...
  87              if( !$post ) {
  88                  $this->_view = new AdminPostsListView( $this->_blogInfo );
  89                  $this->_view->setErrorMessage( $this->_locale->tr("error_fetching_article"));
  90                  $this->setCommonData();
  91  
  92                  return false;
  93              }
  94  
  95              // if the user does not have the 'update_all_user_articles' permission, then
  96              // we have to check whether the original poster of the article and the current
  97              // user match
  98              if( !$this->userHasPermission( "update_all_user_articles" )) {
  99                  if( $post->getUserId() != $this->_userInfo->getId()) {
 100                      $this->_view = new AdminPostsListView( $this->_blogInfo );
 101                      $this->_view->setErrorMessage( $this->_locale->tr("error_can_only_update_own_articles" ));
 102                      $this->setCommonData();
 103  
 104                      return false;                    
 105                  }
 106              }
 107  
 108               // if we got it, update some fields
 109              $post->setTopic( stripslashes($this->_postTopic));
 110              $postText = $this->_postText;
 111              $post->setText( stripslashes($postText));
 112              $post->setTopic( $this->_postTopic );
 113              $post->setText( $postText );
 114              $post->setCategoryIds( $this->_postCategories );
 115              $post->setStatus( $this->_postStatus );
 116              $post->setDateObject( $this->_postTimestamp );
 117              $post->setCommentsEnabled( $this->_commentsEnabled );
 118              $post->setPostSlug( $this->_postSlug );
 119              $post->setGlobalCategoryId( $this->_globalArticleCategoryId );        
 120              $post->setUser( $this->_posterId );
 121              
 122              // set the modification date
 123              $blogSettings = $this->_blogInfo->getSettings();
 124              $modifDate = Timestamp::getDateWithOffset( new Timestamp(), $blogSettings->getValue( "time_offset", 0 ));
 125              $post->setModificationDate( $modifDate );            
 126  
 127              // prepare the custom fields
 128              $fields = Array();
 129              if( is_array($this->_customFields)) {
 130                  foreach( $this->_customFields as $fieldId => $fieldValue ) {
 131                      // 3 of those parameters are not really need when creating a new object... it's enough that
 132                      // we know the field definition id.
 133                      $customField = new CustomFieldValue( $fieldId, $fieldValue, "", -1, "", $post->getId(), $this->_blogInfo->getId(), -1);
 134                      array_push( $fields, $customField );
 135                  }
 136                  $post->setFields( $fields );
 137              }
 138              
 139              // fire the pre event
 140              $this->notifyEvent( EVENT_PRE_POST_UPDATE, Array( "article" => &$post ));
 141          
 142              // and finally save the post to the database
 143              if( !$articles->updateArticle( $post )) {
 144                  $this->_view = new AdminPostsListView( $this->_blogInfo );
 145                  $this->_view->setErrorMessage( $this->_locale->tr("error_updating_post"));
 146                  $this->setCommonData();
 147  
 148                  return false;
 149  
 150              }
 151              
 152              // clean up the cache
 153              CacheControl::resetBlogCache( $this->_blogInfo->getId());    
 154  
 155              // create the definitive view
 156              $this->_view = new AdminPostsListView( $this->_blogInfo );
 157              // show a message saying that the post was updated
 158              $message = $this->_locale->pr("post_updated_ok", $post->getTopic());
 159  
 160              // check if there was a previous notification
 161              $notifications = new ArticleNotifications();
 162              $artNotification = $notifications->getUserArticleNotification( $this->_postId, $this->_blogInfo->getId(), $this->_userInfo->getId());
 163              // check if we have to add or remove a notification
 164              if( $this->_sendNotification ) {
 165                  if( !$artNotification ) {
 166                      // if there wasn't one and now we want it, we have to add it
 167                      $notifications->addNotification( $this->_postId, $this->_blogInfo->getId(), $this->_userInfo->getId());
 168                      $message .= " ".$this->_locale->tr("notification_added");
 169                  }
 170              }
 171              else {
 172                  // if we don't want notifications, then we have to check if there is one since we
 173                  // should remove it
 174                  if( $artNotification ) {
 175                      $notifications->deleteNotification( $this->_postId, $this->_blogInfo->getId(), $this->_userInfo->getId());
 176                      $message .= " ".$this->_locale->tr("notification_removed");
 177                  }
 178              }
 179              
 180                  // only send trackbacks and xmlrpc pings
 181                  // when a post is "published"
 182              if( $post->getStatus() == POST_STATUS_PUBLISHED ) {
 183                  // get the links from the text of the post
 184                  $postLinks = StringUtils::getLinks(
 185                      stripslashes($post->getText()));
 186  
 187                  // get the real trackback links from trackbackUrls
 188                  $trackbackLinks = Array();
 189                  foreach(explode( "\r\n", $this->_trackbackUrls ) as $host ) {
 190                      trim($host);
 191                      if( $host != "" && $host != "\r\n" &&
 192                          $host != "\r" && $host != "\n" )
 193                      {
 194                          array_push( $trackbackLinks, $host );
 195                      }
 196                  }
 197                  
 198                      // if the "send xmlrpc pings" checkbox was enabled,
 199                      // do something about it...
 200                  if( $this->_sendPings ) {
 201                      $t = new Timestamp();
 202                      $today = $t->getTimestamp();
 203                      if($today > $post->getDate()){
 204                          $message .= "<br/><br/>".$this->sendXmlRpcPings();
 205                      }
 206                  }                
 207                      // and now check what to do with the trackbacks
 208                  if( $this->_sendTrackbacks ) {
 209                          // if no links, there is nothing to do
 210                      if( count($postLinks) == 0 &&
 211                          count($trackbackLinks) == 0 )
 212                      {
 213                          $this->_view = new AdminPostsListView(
 214                              $this->_blogInfo );
 215                          $this->_view->setErrorMessage(
 216                              $this->_locale->tr(
 217                                  "error_no_trackback_links_sent"));
 218                      }
 219                      else {
 220                          $this->_view = new AdminTemplatedView(
 221                              $this->_blogInfo, "sendtrackbacks" );
 222                              // get the links from the text of the post
 223                          $this->_view->setValue( "post", $post );
 224                          $this->_view->setValue( "postLinks", $postLinks );
 225                          $this->_view->setValue( "trackbackLinks",
 226                                                  $trackbackLinks );
 227                      }
 228                  }
 229              }
 230  
 231              // show the message
 232              $this->_view->setSuccessMessage( $message );
 233              
 234              // and fire the post event
 235              $this->notifyEvent( EVENT_POST_POST_UPDATE, Array( "article" => &$post ));
 236  
 237              $this->setCommonData();
 238  
 239              return true;
 240          }
 241      }
 242  ?>


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