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

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );    
   5      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );    
   7      lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
   8  
   9      /**
  10       * \ingroup Action
  11       * @private
  12       *
  13       * This class represents the defaut view in our application
  14       */
  15      class DefaultAction extends BlogAction 
  16      {
  17  
  18          var $_config;
  19          var $_date;
  20          var $_categoryId;
  21          var $_categoryName;
  22          var $_userId;
  23          var $_userName;
  24          var $_postAmount;
  25  
  26  		function DefaultAction( $actionInfo, $request )
  27          {
  28              $this->BlogAction( $actionInfo, $request );
  29              
  30              $this->registerFieldValidator( "postCategoryId", new IntegerValidator(), true );
  31              $this->registerFieldValidator( "postCategoryName", new StringValidator(), true );
  32              $this->registerFieldValidator( "userId", new IntegerValidator(), true );
  33              $this->registerFieldValidator( "userName", new StringValidator(), true );
  34              
  35              $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_articles" ));
  36          }
  37  
  38          function validate()
  39          {
  40              if( !parent::validate())
  41                  return false;
  42      
  43              // value of the Date parameter from the request
  44              $this->_date = $this->_request->getValue( "Date", -1 );
  45              $val = new IntegerValidator();
  46              if( !$val->validate( $this->_date ) )
  47                  $this->_date = -1;
  48              $this->_categoryName = $this->_request->getValue( 'postCategoryName' );
  49              $this->_categoryId = $this->_request->getValue( 'postCategoryId' );
  50              if( $this->_categoryId == '' )
  51                  if( $this->_date == -1 )
  52                      $this->_categoryId = 0;
  53                  else
  54                      $this->_categoryId = -1;
  55                      
  56              $this->_userId = $this->_request->getValue( 'userId', -1 );
  57              $this->_userName = $this->_request->getValue( 'userName', '' );
  58              $this->_searchTerms = $this->_request->getValue( 'searchTerms', '' );
  59  
  60              return true;
  61          }
  62  
  63          /**
  64           * Executes the action
  65           */
  66          function perform()
  67          {
  68              lt_include( PLOG_CLASS_PATH."class/view/defaultview.class.php" );
  69              
  70              // first of all, we have to determine which blog we would like to see
  71              $blogId = $this->_blogInfo->getId();
  72  
  73              // fetch the settings for that blog
  74              $blogSettings = $this->_blogInfo->getSettings();
  75  
  76              // prepare the view
  77              $this->_view = new DefaultView( $this->_blogInfo,
  78                                              Array( "categoryId" => $this->_categoryId,
  79                                                      "blogId" => $this->_blogInfo->getId(),
  80                                                      "categoryName" => $this->_categoryName,
  81                                                      "date" => $this->_date,
  82                                                      "userName" => $this->_userName,
  83                                                      "userId" => $this->_userId,
  84                                                      "searchTerms" => $this->_searchTerms,
  85                                                      "page" => $this->_page ));
  86                                                            
  87              // check if everything's cached because if it is, then we don't have to
  88              // do any work... it's already been done before and we should "safely" assume
  89              // that there hasn't been any change so far
  90              if( $this->_view->isCached()) {
  91                  $this->setCommonData();
  92                  return true;
  93              }
  94  
  95              lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
  96              lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
  97              lt_include( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
  98              lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
  99              lt_include( PLOG_CLASS_PATH."class/config/siteconfig.class.php" );            
 100  
 101              // if we got a category name instead of a category id, then we
 102              // should first look up this category in the database and see if
 103              // it exists
 104              $categories = new ArticleCategories();
 105              if( $this->_categoryName ) {
 106                  $category = $categories->getCategoryByName( $this->_categoryName, $this->_blogInfo->getId());
 107                  if( !$category ) {
 108                      $this->_view = new ErrorView( $this->_blogInfo );
 109                      $this->_view->setValue( 'message', "error_incorrect_category_id" );
 110                      $this->setCommonData();
 111                      return false;
 112                  }
 113                  
 114                  // if everything went fine...
 115                  $this->_categoryId = $category->getId();
 116              }
 117              else {
 118                  // we don't do anything if the cateogry id is '0' or '-1'
 119                  if( $this->_categoryId > 0 ) {
 120                      $category = $categories->getCategory( $this->_categoryId, $this->_blogInfo->getId());
 121                      if( !$category ) {
 122                          $this->_view = new ErrorView( $this->_blogInfo );
 123                          $this->_view->setValue( 'message', "error_incorrect_category_id" );
 124                          $this->setCommonData();
 125                          return false;
 126                      }
 127                  }
 128                  else {
 129                      // if only to avoid a warning...
 130                      $category = null;
 131                  }
 132              }
 133              
 134              // export the category object in case it is needed
 135              if( isset($category) )
 136                  $this->_view->setValue( "category", $category );            
 137              
 138              lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
 139              $users = new Users();
 140  
 141              // if we got a user user id, then we should first look up this id
 142              // user in the database and see if it exists
 143              if( $this->_userId > 0) {
 144                  $user = $users->getUserInfoFromId( $this->_userId );
 145                  if( !$user ) {
 146                      $this->_view = new ErrorView( $this->_blogInfo );
 147                      $this->_view->setValue( 'message', 'error_incorrect_user_id' );
 148                      $this->setCommonData();
 149                      return false;
 150                  }
 151              } 
 152              else if( $this->_userName ) {
 153                      // if we got a user name instead of a user id, then we
 154                      // should first look up this user in the database and see if
 155                      // it exists
 156                  $user = $users->getUserInfoFromUsername( $this->_userName );
 157                  if( !$user ) {
 158                      $this->_view = new ErrorView( $this->_blogInfo );
 159                      $this->_view->setValue( 'message', 'error_incorrect_user_username' );
 160                      $this->setCommonData();
 161                      return false;
 162                  }
 163                  
 164                  // if everything went fine...
 165                  $this->_userId = $user->getId();
 166              }
 167              else {
 168                  // if only to avoid a warning...
 169                  $user = null;
 170              }    
 171  
 172              if( ($blogSettings->getValue( 'show_future_posts_in_calendar')) && ( $this->_date > -1 )) {
 173                  // if posts in the future are to be shown, we shouldn't set a maximum date
 174                  $todayTimestamp = 0;
 175              }
 176              else {            
 177                  $t = new Timestamp();
 178                  $todayTimestamp = $t->getTimestamp();
 179                 }
 180                             
 181                 // get the articles...
 182              $hardLimit = SiteConfig::getHardShowPostsMax();
 183              $this->_postAmount = $blogSettings->getValue( "show_posts_max" );            
 184              if( $this->_postAmount > $hardLimit ) $this->_postAmount = $hardLimit;
 185  
 186              $articles = new Articles();
 187              $blogArticles = $articles->getBlogArticles( 
 188                                      $blogId, 
 189                                      $this->_date,
 190                                      $this->_postAmount, 
 191                                      $this->_categoryId,
 192                                      POST_STATUS_PUBLISHED, 
 193                                      $this->_userId, 
 194                                      $todayTimestamp,
 195                                      $this->_searchTerms,
 196                                      $this->_page );                        
 197              // and the total number based on the conditions given
 198              $numArticles = $articles->getNumBlogArticles( 
 199                                      $blogId,
 200                                      $this->_date,
 201                                      $this->_categoryId,
 202                                      POST_STATUS_PUBLISHED,
 203                                      $this->_userId,
 204                                      $todayTimestamp,
 205                                      $this->_searchTerms );
 206  
 207              // if we couldn't fetch the articles, send an error and quit
 208              if( count($blogArticles) == 0 ) {
 209                  $this->_view = new ErrorView( $this->_blogInfo );
 210                  $this->_view->setValue( 'message', 'error_fetching_articles' );
 211              }
 212              else {
 213                  // ---
 214                  // before finishing, let's see if there's any plugin that would like to do 
 215                  // anything with the post that we just loaded
 216                  // ---
 217                  $pm =& PluginManager::getPluginManager();
 218                  $pm->setBlogInfo( $this->_blogInfo );
 219                  $pm->setUserInfo( $this->_userInfo );
 220                  $result = $pm->notifyEvent( EVENT_POSTS_LOADED, Array( 'articles' => &$blogArticles ));
 221                  $articles = Array();
 222                  foreach( $blogArticles as $article ) {
 223                      $postText = $article->getIntroText();
 224                      $postExtendedText = $article->getExtendedText();
 225                      $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postText ));
 226                      $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postExtendedText ));
 227                      $article->setIntroText( $postText );
 228                      $article->setExtendedText( $postExtendedText );
 229                      array_push( $articles, $article );
 230                  }
 231                  
 232                  $this->_view->setValue( 'posts', $articles );
 233                  
 234                  // build the pager and pass it to the view
 235                  $url = $this->_blogInfo->getBlogRequestGenerator();
 236                  $basePageUrl = $url->getCurrentUrl( $category,
 237                                                      $user,
 238                                                      $this->_date );
 239                  
 240                  $pager = new Pager( $basePageUrl,            // url to the next page
 241                                      $this->_page,            // current page
 242                                      $numArticles,            // total number of articles
 243                                      $this->_postAmount );                
 244                  $this->_view->setValue( 'pager', $pager );
 245  
 246                      // pass the date onto the template, in case users would like to show it
 247                  if( $this->_date > - 1 ) {
 248                      $date = str_pad( $this->_date, 14, "0" );
 249                      $this->_view->setValue( "date", new Timestamp( $date ));
 250                  }
 251              }           
 252  
 253              $this->setCommonData();
 254              // save the information about the session for later
 255              $this->saveSession();
 256  
 257              return true;
 258          }
 259      }
 260  ?>


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