NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype/branches/lifetype-1.0.6/class/action/rssaction.class.php

Go to the documentation of this file.
00001 <?php
00002 
00003         include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00004     include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00005     include_once( PLOG_CLASS_PATH."class/view/rssview.class.php" );
00006     include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00007     include_once( PLOG_CLASS_PATH."class/locale/locale.class.php" );
00008     include_once( PLOG_CLASS_PATH."class/locale/locales.class.php" );
00009     include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00010     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00011 
00019         class RssAction extends BlogAction 
00020         {
00021 
00025         function RssAction( $blogInfo, $request )
00026         {
00027                 $this->BlogAction( $blogInfo, $request );
00028 
00029                         $this->registerFieldValidator( "categoryId", new IntegerValidator(), true );
00030                         $this->registerFieldValidator( "profile", new StringValidator(), true );
00031 
00032                         // generate a dummy view with nothing in it to signal an error
00033                         $view = new RssView( $this->_blogInfo, DEFAULT_PROFILE );
00034                         $view->setValue( "articles", Array());
00035                         $this->setValidationErrorView( $view );                 
00036         }
00037 
00041         function perform()
00042         {
00043                 //Check the rdf syndication is allowed or not
00044                 $rdfEnabled = $this->_config->getValue( "rdf_enabled" );
00045                 if ( !$rdfEnabled ) {
00046                                 $message = $this->_locale->tr('error_rdf_syndication_not_allowed').'<br/><br/>';
00047                 $this->_view = new ErrorView( $this->_blogInfo, $message );
00048                 $this->setCommonData();
00049                 $this->_view->render();
00050 
00051                 die();
00052             }                   
00053                 
00054                 // fetch the articles for the given blog
00055                 $articles = new Articles();
00056             $blogSettings = $this->_blogInfo->getSettings();
00057             $localeCode = $blogSettings->getValue( "locale" );
00058 
00059             // fetch the default profile as chosen by the administrator
00060             $defaultProfile = $this->_config->getValue( "default_rss_profile" );
00061             if( $defaultProfile == "" || $defaultProfile == null )
00062                 $defaultProfile = DEFAULT_PROFILE;
00063 
00064             // fetch the profile
00065             // if the profile specified by the user is not valid, then we will
00066             // use the default profile as configured
00067             $profile = $this->_request->getValue( "profile" );
00068                         if( $profile == "" ) $profile = $defaultProfile;
00069 
00070             // fetch the category, or set it to '0' otherwise, which will mean
00071             // fetch all the most recent posts from any category
00072             $categoryId = $this->_request->getValue( "categoryId" );
00073             if( !is_numeric($categoryId))
00074                 $categoryId = 0;
00075                                 
00076             // check if the template is available
00077             $this->_view = new RssView( $this->_blogInfo, $profile, 
00078                                                     Array( "profile" => $profile,
00079                                                                                        "categoryId" => $categoryId ));
00080                         
00081                         // do nothing if the view was already cached
00082                         if( $this->_view->isCached()) {
00083                                 return true;
00084                         }
00085 
00086             // create an instance of a locale object
00087             $locale = Locales::getLocale( $localeCode );
00088 
00089             // fetch the posts, though we are going to fetch the same amount in both branches
00090                         $amount = $blogSettings->getValue( "recent_posts_max", 15 );            
00091                         $t = new Timestamp();
00092                         if( $blogSettings->getValue( 'show_future_posts_in_calendar' )) {
00093                                 $blogArticles = $articles->getBlogArticles( $this->_blogInfo->getId(), -1, $amount, 
00094                                                                                                                         $categoryId, POST_STATUS_PUBLISHED, 0 );
00095                         }
00096                         else {
00097                                 $today = $t->getTimestamp();
00098                                 $blogArticles = $articles->getBlogArticles( $this->_blogInfo->getId(), -1, $amount, 
00099                                                                                                                         $categoryId, POST_STATUS_PUBLISHED, 0, $today );                        
00100                         }
00101                         
00102                         // load the category
00103                         if( $categoryId > 0 ) {
00104                              include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
00105                              $articleCategories = new ArticleCategories();
00106                              $category = $articleCategories->getCategory( $categoryId );
00107                              $this->_view->setValue( "rsscategory", $category );
00108                         }   
00109                                                                                                                 
00110                         $pm =& PluginManager::getPluginManager();
00111                         $pm->setBlogInfo( $this->_blogInfo );
00112                         $pm->setUserInfo( $this->_userInfo );
00113                         $result = $pm->notifyEvent( EVENT_POSTS_LOADED, Array( 'articles' => &$blogArticles ));
00114                         $articles = Array();
00115                         foreach( $blogArticles as $article ) {
00116                                 $postText = $article->getIntroText();
00117                                 $postExtendedText = $article->getExtendedText();
00118                                 $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postText ));
00119                                 $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postExtendedText ));
00120                                 $article->setIntroText( $postText );
00121                                 $article->setExtendedText( $postExtendedText );
00122                                 array_push( $articles, $article );
00123                         }                                                                                                               
00124             
00125             $this->_view->setValue( "locale", $locale );
00126             $this->_view->setValue( "posts", $articles );
00127             $this->setCommonData();
00128 
00129             return true;
00130         }
00131     }
00132 ?>