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

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/summary/action/summaryaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/summary/dao/summarystats.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/summary/view/summaryrssview.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/net/rawrequestgenerator.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
  10      
  11      define( "SUMMARY_RSS_TYPE_DEFAULT", "default" );
  12      define( "SUMMARY_RSS_TYPE_MOST_COMMENTED", "mostcommented" );
  13      define( "SUMMARY_RSS_TYPE_MOST_READ", "mostread" );
  14      define( "SUMMARY_RSS_TYPE_MOST_ACTIVE_BLOGS", "mostactiveblogs" );
  15      define( "SUMMARY_RSS_TYPE_NEWEST_BLOGS", "newestblogs" );
  16      define( "SUMMARY_RSS_TYPE_POSTS_LIST", "postslist" );
  17      define( "SUMMARY_RSS_TYPE_BLOGS_LIST", "blogslist" );    
  18  
  19       /**
  20        * This is the one and only default action. It simply fetches all the most recent
  21        * posts from the database and shows them. The default locale is the one specified
  22        * in the configuration file and the amount of posts shown in this page is also
  23        * configurable through the config file.
  24        */
  25       class SummaryRssAction extends SummaryAction
  26       {
  27  
  28          function SummaryRssAction( $actionInfo, $request )
  29          {
  30              $this->SummaryAction( $actionInfo, $request );
  31          }
  32          
  33  		function validate()
  34          {
  35              // make sure that the mode is set to something meaningful...
  36              $this->_mode = $this->_request->getValue( "type" );
  37              if( $this->_mode != SUMMARY_RSS_TYPE_DEFAULT &&
  38                  $this->_mode != SUMMARY_RSS_TYPE_MOST_COMMENTED &&
  39                  $this->_mode != SUMMARY_RSS_TYPE_MOST_READ &&
  40                  $this->_mode != SUMMARY_RSS_TYPE_MOST_ACTIVE_BLOGS &&
  41                  $this->_mode != SUMMARY_RSS_TYPE_NEWEST_BLOGS &&
  42                  $this->_mode != SUMMARY_RSS_TYPE_POSTS_LIST &&
  43                  $this->_mode != SUMMARY_RSS_TYPE_BLOGS_LIST ) {
  44                  
  45                  // in case the parameter looks weird, let's use a default one...
  46                  $this->_mode = SUMMARY_RSS_TYPE_DEFAULT;
  47              }
  48              
  49              $this->_profile = $this->_request->getValue( "profile" );
  50              
  51              return true;
  52          }
  53  
  54          /**
  55           * Loads the posts and shows them.
  56           */
  57          function perform()
  58          {
  59              if( $this->_mode == SUMMARY_RSS_TYPE_MOST_COMMENTED ||
  60                  $this->_mode == SUMMARY_RSS_TYPE_MOST_READ ||
  61                  $this->_mode == SUMMARY_RSS_TYPE_DEFAULT ||
  62                  $this->_mode == SUMMARY_RSS_TYPE_POSTS_LIST ) {                    
  63                      
  64                  // get the globalArticleCategoryId from request
  65                  $globalArticleCategoryId = $this->_request->getValue( "globalArticleCategoryId" );
  66                  $val = new IntegerValidator();
  67                  if( !$val->validate( $globalArticleCategoryId ))
  68                      $globalArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES;
  69                                  
  70                  // RSS feeds for posts stuff
  71                  $this->_view = new SummaryRssView( $this->_profile, Array( "summary" => "rss", 
  72                                                     "globalArticleCategoryId" => $globalArticleCategoryId,
  73                                                     "mode" => $this->_mode,
  74                                                     "profile" => $this->_profile ));
  75                  if( $this->_view->isCached()) {
  76                      $this->setCommonData();
  77                      return true;
  78                  }
  79          
  80                  $blogs       = new Blogs();
  81                  $stats       = new SummaryStats();
  82                      
  83                  if( $this->_mode == SUMMARY_RSS_TYPE_MOST_COMMENTED ) {
  84                      $postslist = $stats->getMostCommentedArticles();
  85                  }
  86                  elseif( $this->_mode == SUMMARY_RSS_TYPE_MOST_READ ) {
  87                      $postslist = $stats->getMostReadArticles();            
  88                  }
  89                  elseif( $this->_mode == SUMMARY_RSS_TYPE_POSTS_LIST ) {
  90                       lt_include( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" );
  91                      lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
  92                      
  93                      // get the summary_items_per_page from config
  94                      $config =& Config::getConfig();
  95                      $summaryItemsPerPage = $config->getValue( "summary_items_per_page", SUMMARY_DEFAULT_ITEMS_PER_PAGE );
  96                      
  97                      $categories = new GlobalArticleCategories();
  98                      $currentGlobalArticleCategory = $categories->getGlobalArticleCategory( $globalArticleCategoryId );
  99                      
 100                      if( empty($currentGlobalArticleCategory) )
 101                          $globalArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES;
 102                          
 103                      $postslist = $stats->getPostsByGlobalCategory( $globalArticleCategoryId,
 104                                                                        $page = 1, 
 105                                                                        $summaryItemsPerPage );
 106                  }                
 107                  else {
 108                      lt_include( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" );
 109                      $categories = new GlobalArticleCategories();
 110                      $currentGlobalArticleCategory = $categories->getGlobalArticleCategory( $globalArticleCategoryId );
 111                      
 112                      if( empty($currentGlobalArticleCategory) )
 113                          $globalArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES;
 114                      
 115                      $postslist = $stats->getRecentArticles( $globalArticleCategoryId );
 116                  }
 117      
 118                  if( !$postslist ) {
 119                      $postslist = Array();
 120                  }
 121      
 122                  $this->_view->setValue( "posts", $postslist );
 123              }
 124              elseif( $this->_mode == SUMMARY_RSS_TYPE_MOST_ACTIVE_BLOGS ||
 125                      $this->_mode == SUMMARY_RSS_TYPE_NEWEST_BLOGS ||
 126                      $this->_mode == SUMMARY_RSS_TYPE_BLOGS_LIST ) {
 127                  
 128                  // get the globalArticleCategoryId from request
 129                  $blogCategoryId = $this->_request->getValue( "blogCategoryId" );
 130                  $val = new IntegerValidator();
 131                  if( !$val->validate( $blogCategoryId ))
 132                      $blogCategoryId = ALL_BLOG_CATEGORIES;
 133  
 134                  // RSS feeds for blogs, need different template sets...
 135                  $this->_view = new SummaryRssView( "blogs_".$this->_profile, Array( "summary" => "rss",
 136                                                     "blogCategoryId" => $blogCategoryId, 
 137                                                     "mode" => $this->_mode,
 138                                                     "profile" => $this->_profile ));
 139                  if( $this->_view->isCached()) {
 140                      $this->setCommonData();
 141                      return true;
 142                  }
 143                  
 144                  // load the stuff
 145                  $blogs = new Blogs();
 146                  $stats = new SummaryStats();
 147                  
 148                  if( $this->_mode == SUMMARY_RSS_TYPE_MOST_ACTIVE_BLOGS ) {
 149                      $blogslist = $stats->getMostActiveBlogs();    
 150                  }
 151                  elseif( $this->_mode == SUMMARY_RSS_TYPE_BLOGS_LIST ) {
 152                       lt_include( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
 153                      lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
 154                      
 155                      // get the summary_items_per_page from config
 156                      $config =& Config::getConfig();
 157                      $summaryItemsPerPage = $config->getValue( "summary_items_per_page", SUMMARY_DEFAULT_ITEMS_PER_PAGE );
 158                      
 159                      $categories = new BlogCategories();
 160                      $currentBlogCategory = $categories->getBlogCategory( $blogCategoryId );
 161                      
 162                      if( empty($currentBlogCategory) )
 163                          $blogCategoryId = ALL_BLOG_CATEGORIES;
 164                          
 165                      $blogslist = $blogs->getAllBlogs( BLOG_STATUS_ACTIVE, 
 166                                                        $blogCategoryId, 
 167                                                        "", 
 168                                                        1, 
 169                                                        $summaryItemsPerPage );
 170                  }
 171                  else {
 172                      $blogslist = $stats->getRecentBlogs();
 173                  }
 174                  
 175                  // in case there is really no data to fetch...
 176                  if( !$blogslist )
 177                      $blogslist = Array();
 178                      
 179                  $this->_view->setValue( "blogs", $blogslist );                                
 180              }
 181              
 182              $this->_view->setValue( "type", $this->_mode );
 183              $this->_view->setValue( "summary", true );
 184  
 185              // this 'url' object is just a dummy one... But we cannot get it from the list
 186              // of blogs that we fetched because it could potentially be null! Besides, we only
 187              // need it to generate the base url to rss.css and to summary.php, so no need to
 188              // have a fully-featured object
 189              $this->_view->setValue( "url", new RawRequestGenerator( null ));
 190              
 191              $this->setCommonData();        
 192  
 193              return true;
 194          }
 195       }
 196  ?>


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