[ 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/ -> adminsendtrackbacksaction.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/adminpostslistview.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/view/admin/adminnewpostview.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/dao/trackbackclient.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
  10  
  11      /**
  12       * \ingroup Action
  13       * @private
  14       *
  15       * Action that shows a form to change the settings of the current blog.
  16       */
  17      class AdminSendTrackbacksAction extends AdminAction 
  18      {
  19  
  20          var $_postLinks;
  21          var $_trackbackLinks;
  22          var $_postId;
  23          var $_locale;
  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 AdminSendTrackbacksAction( $actionInfo, $request )
  30          {
  31              $this->AdminAction( $actionInfo, $request );
  32  
  33              $this->requirePermission( "add_post" );
  34          }
  35  
  36  		function validate()
  37          {
  38              // fetch the validated data
  39              $this->_postLinks = $this->_request->getValue( "postLink" );
  40              $this->_trackbackLinks = $this->_request->getValue( "trackbackLink" );
  41              $this->_postId = $this->_request->getValue( "postId" );
  42              
  43              $intval = new IntegerValidator();
  44              if( !$intval->validate( $this->_postId ) ) {
  45                  $this->_view = new AdminPostsListView( $this->_blogInfo );
  46                  $this->_view->setErrorMessage( $this->_locale->tr("error_incorrect_article_id"));
  47                  $this->setCommonData();
  48  
  49                  return false;                
  50              }
  51              
  52              $arrryval = new ArrayValidator();
  53              if( !$arrryval->validate( $this->_postLinks ) && !$arrryval->validate( $this->_trackbackLinks ) ) {
  54                  $this->_view = new AdminPostsListView( $this->_blogInfo );
  55                  $this->_view->setErrorMessage( $this->_locale->tr("error_no_trackback_links_sent"));
  56                  $this->setCommonData();
  57  
  58                  return false;
  59              }   
  60              
  61              return true;
  62          }        
  63  
  64          /*
  65           * Carries out the specified action
  66           */
  67          function perform()
  68          {
  69              // we need to have the post
  70              $articles = new Articles();
  71              $post     = $articles->getBlogArticle( $this->_postId, $this->_blogInfo->getId());
  72              
  73              // now check the results and give the user the possiblity to retry again with the
  74              // ones that had some problem.
  75              $errors = false;
  76  
  77              // and now start sending the trackback pings
  78              $tbClient = new TrackbackClient();
  79              $postLinks = Array();
  80              $trackbackLinks = Array();
  81              $message = "";          
  82              
  83              if ( $this->_postLinks && count($this->_postLinks) != 0 ) {
  84                  $autoDiscoverResults = $tbClient->sendTrackbacks( $this->_postLinks, $post, $this->_blogInfo);
  85  
  86                  foreach( $autoDiscoverResults as $result ) {
  87                      if( $result["status"] == TRACKBACK_FAILED) {
  88                          // add them again to the list of hosts
  89                          $errors = true;
  90                          array_push( $postLinks, $result["url"] );
  91                      }
  92                      else if( $result["status"] == TRACKBACK_SUCCESS ) {
  93                          if( $message == "" ) $message = $this->_locale->tr("trackbacks_sent_ok")."<br/><br/>";
  94                          $message .= "<a href=\"".$result["url"]."\">".$result["url"]."</a><br/>";
  95                      }
  96                      else if( $result["status"] == TRACKBACK_UNAVAILABLE ) {
  97                          $message .= $this->_locale->tr("trackbacks_no_trackback")."<a href=\"".$result["url"]."\">".$result["url"]."</a><br/>";
  98                      }
  99                  }
 100              }
 101  
 102              if ( $this->_trackbackLinks && count($this->_trackbackLinks) != 0 ) {
 103                  $directPingResults = $tbClient->sendDirectTrackbacks( $this->_trackbackLinks, $post, $this->_blogInfo);
 104      
 105                  foreach( $directPingResults as $result ) {
 106                      if( $result["status"] == TRACKBACK_FAILED) {
 107                          // add them again to the list of hosts
 108                          $errors = true;
 109                          array_push( $trackbackLinks, $result["url"] );
 110                      }
 111                      else if( $result["status"] == TRACKBACK_SUCCESS ) {
 112                          if( $message == "" ) $message = $this->_locale->tr("trackbacks_sent_ok")."<br/><br/>";
 113                          $message .= "<a href=\"".$result["url"]."\">".$result["url"]."</a><br/>";
 114                      }
 115                  }
 116              }
 117  
 118              // if there were errors, we let the user try again
 119              if( $errors ) {
 120                  if( $message != "" )
 121                      $message .= "<br/>";
 122                  $message .= $this->_locale->tr("error_sending_trackbacks");
 123                   $this->_view = new AdminTemplatedView( $this->_blogInfo, "sendtrackbacks" );
 124                  $this->_view->setErrorMessage( $message );
 125                  $this->_view->setValue( "post", $post);
 126                  $this->_view->setValue( "postLinks", $postLinks );
 127                  $this->_view->setValue( "trackbackLinks", $trackbackLinks );
 128                  $this->setCommonData();
 129              }
 130              else {
 131                  if( $this->userHasPermission( "view_posts" )) 
 132                      $this->_view = new AdminPostsListView( $this->_blogInfo );
 133                  else
 134                      $this->_view = new AdminNewPostView( $this->_blogInfo );
 135                      
 136                  $this->_view->setSuccessMessage( $message );
 137                  $this->setCommonData();
 138              }
 139          }
 140      }
 141  ?>


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