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
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
00057 $blogId = $this->_blogInfo->getId();
00058
00059
00060 $blogSettings = $this->_blogInfo->getSettings();
00061
00062
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
00072
00073
00074 if( $this->_view->isCached()) {
00075 return true;
00076 }
00077
00078
00079
00080
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
00092 $this->_categoryId = $category->getId();
00093 }
00094 else {
00095
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
00108 if( isset($category) )
00109 $this->_view->setValue( "category", $category );
00110
00111
00112 $users = new Users();
00113
00114
00115
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
00127
00128
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
00138 $this->_userId = $user->getId();
00139 }
00140
00141
00142 $this->_view->setValue( "owner", $this->_blogInfo->getOwnerInfo() );
00143
00144 $t = new Timestamp();
00145 $todayTimestamp = $t->getTimestamp();
00146
00147
00148
00149 if( $this->_date > 0 || $this->_categoryId > 0 ) {
00150 $this->_postAmount = -1;
00151
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
00161
00162
00163
00164
00165 if( ($blogSettings->getValue( 'show_future_posts_in_calendar')) && ( $this->_date > -1 )) {
00166
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
00178 if( count($blogArticles) == 0 ) {
00179 $this->_view = new ErrorView( $this->_blogInfo );
00180 $this->_view->setValue( 'message', 'error_fetching_articles' );
00181 }
00182 else {
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
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
00214 $this->saveSession();
00215
00216 return true;
00217 }
00218 }
00219 ?>