NewsNewsFeaturesDownloadsDevelopmentSupportForumDocumentsAbout Us

defaultaction.class.php

查看本檔案說明文件.
00001 <?php
00002 
00003     include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00004     include_once( PLOG_CLASS_PATH."class/view/defaultview.class.php" );
00005     include_once( PLOG_CLASS_PATH."class/net/http/session/sessioninfo.class.php" );
00006     include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00007     include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00008     include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" ); 
00009 
00016     class DefaultAction extends BlogAction 
00017     {
00018 
00019         var $_config;
00020         var $_date;
00021         var $_categoryId;
00022         var $_categoryName;
00023         var $_userId;
00024         var $_userName;
00025         var $_postAmount;
00026 
00027         function DefaultAction( $actionInfo, $request )
00028         {
00029             $this->BlogAction( $actionInfo, $request );
00030         }
00031 
00032         function validate()
00033         {
00034             // value of the Date parameter from the request
00035             $this->_date = $this->_request->getValue( "Date", -1 );
00036 
00037         $this->_categoryName = $this->_request->getValue( 'postCategoryName' );
00038             $this->_categoryId = $this->_request->getValue( 'postCategoryId' );
00039             if( $this->_categoryId == '' )
00040                 if( $this->_date == -1 )
00041                     $this->_categoryId = 0;
00042                 else
00043                     $this->_categoryId = -1;
00044                     
00045             $this->_userId = $this->_request->getValue( 'userId', -1 );
00046             $this->_userName = $this->_request->getValue( 'userName' );
00047 
00048             return true;
00049         }
00050 
00054         function perform()
00055         {
00056             // first of all, we have to determine which blog we would like to see
00057             $blogId = $this->_blogInfo->getId();
00058 
00059             // fetch the settings for that blog
00060             $blogSettings = $this->_blogInfo->getSettings();
00061 
00062             // prepare the view
00063             $this->_view = new DefaultView( $this->_blogInfo,
00064                                             Array( "categoryId" => $this->_categoryId,
00065                                    "blogId" => $this->_blogInfo->getId(),
00066                                    "categoryName" => $this->_categoryName,
00067                                "date" => $this->_date,
00068                                "userName" => $this->_userName,
00069                                "userId" => $this->_userId ));
00070                                                           
00071             // check if everything's cached because if it is, then we don't have to
00072             // do any work... it's already been done before and we should "safely" assume
00073             // that there hasn't been any change so far
00074             if( $this->_view->isCached()) {
00075                 return true;
00076             }
00077 
00078             // if we got a category name instead of a category id, then we
00079             // should first look up this category in the database and see if
00080             // it exists
00081             $categories = new ArticleCategories();
00082             if( $this->_categoryName ) {
00083                 $category = $categories->getCategoryByName( $this->_categoryName, $this->_blogInfo->getId());
00084                 if( !$category ) {
00085                     $this->_view = new ErrorView( $this->_blogInfo );
00086                     $this->_view->setValue( 'message', "error_incorrect_category_id" );
00087                     $this->setCommonData();
00088                     return false;
00089                 }
00090                 
00091                 // if everything went fine...
00092                 $this->_categoryId = $category->getId();
00093             }
00094             else {
00095                 // we don't do anything if the cateogry id is '0' or '-1'
00096                 if( $this->_categoryId > 0 ) {
00097                     $category = $categories->getCategory( $this->_categoryId, $this->_blogInfo->getId());
00098                     if( !$category ) {
00099                         $this->_view = new ErrorView( $this->_blogInfo );
00100                         $this->_view->setValue( 'message', "error_incorrect_category_id" );
00101                         $this->setCommonData();
00102                         return false;
00103                     }
00104                 }
00105             }
00106             
00107             // export the category object in case it is needed
00108             if( isset($category) )
00109                 $this->_view->setValue( "category", $category );            
00110             
00111 
00112             $users = new Users();
00113 
00114             // if we got a user user id, then we should first look up this id
00115             // user in the database and see if it exists
00116             if( $this->_userId > 0) {
00117                 $user = $users->getUserInfoFromId( $this->_userId );
00118                 if( !$user ) {
00119                     $this->_view = new ErrorView( $this->_blogInfo );
00120                     $this->_view->setValue( 'message', 'error_incorrect_user_id' );
00121                     $this->setCommonData();
00122                     return false;
00123                 }
00124             } 
00125             else if( $this->_userName ) {
00126                     // if we got a user name instead of a user id, then we
00127                     // should first look up this user in the database and see if
00128                     // it exists
00129                 $user = $users->getUserInfoFromUsername( $this->_userName );
00130                 if( !$user ) {
00131                     $this->_view = new ErrorView( $this->_blogInfo );
00132                     $this->_view->setValue( 'message', 'error_incorrect_user_username' );
00133                     $this->setCommonData();
00134                     return false;
00135                 }
00136                 
00137                 // if everything went fine...
00138                 $this->_userId = $user->getId();
00139             }
00140 
00141             // export the owner. The owner information should get from blogInfo directly
00142             $this->_view->setValue( "owner", $this->_blogInfo->getOwnerInfo() );
00143             
00144             $t = new Timestamp();
00145             $todayTimestamp = $t->getTimestamp();
00146             
00147             // amount of posts that we have to show, but keeping in mind that when browsing a
00148             // category or specific date, we should show *all* of them
00149             if( $this->_date > 0 || $this->_categoryId > 0 ) {
00150                 $this->_postAmount = -1;
00151                 // also, inform the template that we're showing them all!
00152                 $this->_view->setValue( 'showAll', true );
00153             }
00154             else {
00155                 $this->_postAmount = $blogSettings->getValue( 'show_posts_max' );
00156                 $this->_view->setValue( 'showAll', false );
00157             }
00158             
00159             //
00160             // :KLUDGE:
00161             // the more things we add here to filter, the more complicated this function
00162             // gets... look at this call and look at how many parameters it needs!! :(
00163             //
00164             
00165             if( ($blogSettings->getValue( 'show_future_posts_in_calendar')) && ( $this->_date > -1 )) {
00166                 // if posts in the future are to be shown, we shouldn't set a maximum date
00167                 $blogArticles = $this->articles->getBlogArticles( $blogId, $this->_date,
00168                                 $this->_postAmount, $this->_categoryId,
00169                                 POST_STATUS_PUBLISHED, $this->_userId );            
00170             }
00171             else {
00172                 $blogArticles = $this->articles->getBlogArticles( $blogId, $this->_date,
00173                                 $this->_postAmount, $this->_categoryId,
00174                                 POST_STATUS_PUBLISHED, $this->_userId, $todayTimestamp );
00175             }
00176 
00177             // if we couldn't fetch the articles, send an error and quit
00178             if( count($blogArticles) == 0 ) {
00179                 $this->_view = new ErrorView( $this->_blogInfo );
00180                 $this->_view->setValue( 'message', 'error_fetching_articles' );
00181             }
00182             else {
00183                 // otherwise, continue
00184                 // the view will take care of cutting the post if we have the "show more"
00185                 // feature enabled or not... we could do it here but I think that belongs
00186                 // to the view since it is presentation stuff... It could also be handled
00187                 // by the template but then it'd make the template a little bit more
00188                 // complicated...
00189                 
00190                 // ---
00191                 // before finishing, let's see if there's any plugin that would like to do 
00192                 // anything with the post that we just loaded
00193                 // ---
00194                 $pm =& PluginManager::getPluginManager();
00195                 $pm->setBlogInfo( $this->_blogInfo );
00196                 $pm->setUserInfo( $this->_userInfo );
00197                 $result = $pm->notifyEvent( EVENT_POSTS_LOADED, Array( 'articles' => &$blogArticles ));
00198                 $articles = Array();
00199                 foreach( $blogArticles as $article ) {
00200                     $postText = $article->getIntroText();
00201                     $postExtendedText = $article->getExtendedText();
00202                     $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postText ));
00203                     $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postExtendedText ));
00204                     $article->setIntroText( $postText );
00205                     $article->setExtendedText( $postExtendedText );
00206                     array_push( $articles, $article );
00207                 }
00208                 
00209                 $this->_view->setValue( 'posts', $articles );
00210             }
00211 
00212             $this->setCommonData();
00213             // save the information about the session for later
00214             $this->saveSession();
00215 
00216             return true;
00217         }
00218     }
00219 ?>