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

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/view/rssview.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  
   8  
   9      /**
  10       * \ingroup Action
  11       * @private
  12       *
  13       * This class is used by the controller that takes care of handling the requests for the
  14       * RSS feed.
  15       */
  16      class RssAction extends BlogAction 
  17      {
  18  
  19          /**
  20           * Constructor.
  21           */
  22      	function RssAction( $blogInfo, $request )
  23          {
  24              $this->BlogAction( $blogInfo, $request );
  25              
  26              $this->registerFieldValidator( "categoryId", new IntegerValidator(), true );
  27              $this->registerFieldValidator( "userId", new IntegerValidator(), true );            
  28              
  29              // create a StringValidator and add an extra rule to make sure that the input string contains only
  30              // alphanumeric characters
  31              $profileValidator = new StringValidator();
  32              $profileValidator->addRule( new RegexpRule( "^([a-zA-Z0-9]*)$" ));
  33              $this->registerFieldValidator( "profile", $profileValidator, true );
  34  
  35              // generate a dummy view with nothing in it to signal an error
  36              $view = new RssView( $this->_blogInfo, RSS_VIEW_DEFAULT_PROFILE );
  37              $view->setValue( "articles", Array());
  38              $this->setValidationErrorView( $view );            
  39          }
  40  
  41          /**
  42           * Performs the action.
  43           */
  44          function perform()
  45          {
  46              //Check the rdf syndication is allowed or not
  47              $rdfEnabled = $this->_config->getValue( "rdf_enabled" );
  48              if ( !$rdfEnabled ) {
  49                  lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
  50                  $message = $this->_locale->tr('error_rdf_syndication_not_allowed').'<br/><br/>';
  51                  $this->_view = new ErrorView( $this->_blogInfo, $message );
  52                  $this->setCommonData();
  53                  $this->_view->render();
  54  
  55                  die();
  56              }                
  57              
  58              // fetch the articles for the given blog
  59              $blogSettings = $this->_blogInfo->getSettings();
  60  
  61  
  62              // fetch the default profile as chosen by the administrator
  63              $defaultProfile = $this->_config->getValue( "default_rss_profile" );
  64              if( $defaultProfile == "" || $defaultProfile == null )
  65                  $defaultProfile = RSS_VIEW_DEFAULT_PROFILE;
  66  
  67              // fetch the profile
  68              // if the profile specified by the user is not valid, then we will
  69              // use the default profile as configured
  70              $profile = $this->_request->getValue( "profile" );
  71              if( $profile == "" ) $profile = $defaultProfile;
  72              
  73              // sanitize the profile variable
  74              $profile = str_replace( ".", "", $profile );
  75              $profile = str_replace( "/", "", $profile );
  76              $profile = str_replace( "%", "", $profile );            
  77  
  78              // fetch the category, or set it to '0' otherwise, which will mean
  79              // fetch all the most recent posts from any category
  80              $categoryId = $this->_request->getValue( "categoryId" );
  81              if( !is_numeric($categoryId))
  82                  $categoryId = 0;
  83  
  84              // fetch the user id, if any
  85              $userId = $this->_request->getValue( "userId", -1 );
  86                  
  87              // check if the template is available
  88              $this->_view = new RssView( $this->_blogInfo, $profile, 
  89                                          Array( "profile" => $profile,
  90                                                 "categoryId" => $categoryId,
  91                                                  "userId" => $userId ));
  92              
  93              // do nothing if the view was already cached
  94              if( $this->_view->isCached()) {
  95                  $this->setCommonData();
  96                  return true;
  97              }
  98              
  99              lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 100              lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" );            
 101              lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 102              lt_include( PLOG_CLASS_PATH."class/config/siteconfig.class.php" );
 103              
 104              $articles = new Articles();            
 105  
 106              // fetch the posts, though we are going to fetch the same amount in both branches
 107              $hardLimit = SiteConfig::getHardRecentPostsMax();
 108              $amount = $blogSettings->getValue( "recent_posts_max", 15 );            
 109              if( $amount > $hardLimit ) $amount = $hardLimit;
 110  
 111              $t = new Timestamp();
 112              if( $blogSettings->getValue( 'show_future_posts_in_calendar' )) {
 113                  $blogArticles = $articles->getBlogArticles( $this->_blogInfo->getId(), 
 114                                                              -1, 
 115                                                              $amount, 
 116                                                              $categoryId, 
 117                                                              POST_STATUS_PUBLISHED, 
 118                                                              $userId );
 119              }
 120              else {
 121                  $today = $t->getTimestamp();
 122                  $blogArticles = $articles->getBlogArticles( $this->_blogInfo->getId(), 
 123                                                              -1, 
 124                                                              $amount, 
 125                                                              $categoryId, 
 126                                                              POST_STATUS_PUBLISHED, 
 127                                                              $userId, 
 128                                                              $today );            
 129              }
 130              
 131              // load the category
 132              if( $categoryId > 0 ) {
 133                   lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
 134                   $articleCategories = new ArticleCategories();
 135                   $category = $articleCategories->getCategory( $categoryId );
 136                   $this->_view->setValue( "rsscategory", $category );
 137              }   
 138                                                          
 139              $pm =& PluginManager::getPluginManager();
 140              $pm->setBlogInfo( $this->_blogInfo );
 141              $pm->setUserInfo( $this->_userInfo );
 142              $result = $pm->notifyEvent( EVENT_POSTS_LOADED, Array( 'articles' => &$blogArticles ));
 143              $articles = Array();
 144              
 145              foreach( $blogArticles as $article ) {
 146                  $postText = $article->getIntroText();
 147                  $postExtendedText = $article->getExtendedText();
 148                  $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postText ));
 149                  $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postExtendedText ));
 150                  $article->setIntroText( $postText );
 151                  $article->setExtendedText( $postExtendedText );
 152                  array_push( $articles, $article );
 153              }                                                        
 154              
 155              $this->_view->setValue( "locale", $this->_locale );
 156              $this->_view->setValue( "posts", $articles );
 157              $this->setCommonData();
 158  
 159              return true;
 160          }
 161      }
 162  ?>


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