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 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00011
00018 class DefaultAction extends BlogAction
00019 {
00020
00021 var $_config;
00022 var $_date;
00023 var $_categoryId;
00024 var $_categoryName;
00025 var $_userId;
00026 var $_userName;
00027 var $_postAmount;
00028
00029 function DefaultAction( $actionInfo, $request )
00030 {
00031 $this->BlogAction( $actionInfo, $request );
00032
00033 $this->registerFieldValidator( "postCategoryId", new IntegerValidator(), true );
00034 $this->registerFieldValidator( "postCategoryName", new StringValidator(), true );
00035 $this->registerFieldValidator( "userId", new IntegerValidator(), true );
00036 $this->registerFieldValidator( "userName", new StringValidator(), true );
00037
00038 $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_articles" ));
00039 }
00040
00041 function validate()
00042 {
00043 if( !parent::validate())
00044 return false;
00045
00046
00047 $this->_date = $this->_request->getValue( "Date", -1 );
00048 $val = new IntegerValidator();
00049 if( !$val->validate( $this->_date ) ) {
00050 $this->_date = -1;
00051 }
00052
00053 $this->_categoryName = $this->_request->getValue( 'postCategoryName' );
00054 $this->_categoryId = $this->_request->getValue( 'postCategoryId' );
00055 if( $this->_categoryId == '' )
00056 if( $this->_date == -1 )
00057 $this->_categoryId = 0;
00058 else
00059 $this->_categoryId = -1;
00060
00061 $this->_userId = $this->_request->getValue( 'userId', -1 );
00062 $this->_userName = $this->_request->getValue( 'userName' );
00063
00064 return true;
00065 }
00066
00070 function perform()
00071 {
00072
00073 $blogId = $this->_blogInfo->getId();
00074
00075
00076 $blogSettings = $this->_blogInfo->getSettings();
00077
00078
00079 $this->_view = new DefaultView( $this->_blogInfo,
00080 Array( "categoryId" => $this->_categoryId,
00081 "blogId" => $this->_blogInfo->getId(),
00082 "categoryName" => $this->_categoryName,
00083 "date" => $this->_date,
00084 "userName" => $this->_userName,
00085 "userId" => $this->_userId ));
00086
00087
00088
00089
00090 if( $this->_view->isCached()) {
00091 return true;
00092 }
00093
00094
00095
00096
00097 $categories = new ArticleCategories();
00098 if( $this->_categoryName ) {
00099 $category = $categories->getCategoryByName( $this->_categoryName, $this->_blogInfo->getId());
00100 if( !$category ) {
00101 $this->_view = new ErrorView( $this->_blogInfo );
00102 $this->_view->setValue( 'message', "error_incorrect_category_id" );
00103 $this->setCommonData();
00104 return false;
00105 }
00106
00107
00108 $this->_categoryId = $category->getId();
00109 }
00110 else {
00111
00112 if( $this->_categoryId > 0 ) {
00113 $category = $categories->getCategory( $this->_categoryId, $this->_blogInfo->getId());
00114 if( !$category ) {
00115 $this->_view = new ErrorView( $this->_blogInfo );
00116 $this->_view->setValue( 'message', "error_incorrect_category_id" );
00117 $this->setCommonData();
00118 return false;
00119 }
00120 }
00121 }
00122
00123
00124 if( isset($category) )
00125 $this->_view->setValue( "category", $category );
00126
00127
00128 $users = new Users();
00129
00130
00131
00132 if( $this->_userId > 0) {
00133 $user = $users->getUserInfoFromId( $this->_userId );
00134 if( !$user ) {
00135 $this->_view = new ErrorView( $this->_blogInfo );
00136 $this->_view->setValue( 'message', 'error_incorrect_user_id' );
00137 $this->setCommonData();
00138 return false;
00139 }
00140 }
00141 else if( $this->_userName ) {
00142
00143
00144
00145 $user = $users->getUserInfoFromUsername( $this->_userName );
00146 if( !$user ) {
00147 $this->_view = new ErrorView( $this->_blogInfo );
00148 $this->_view->setValue( 'message', 'error_incorrect_user_username' );
00149 $this->setCommonData();
00150 return false;
00151 }
00152
00153
00154 $this->_userId = $user->getId();
00155 }
00156
00157
00158 $this->_view->setValue( "owner", $this->_blogInfo->getOwnerInfo() );
00159
00160 $t = new Timestamp();
00161 $todayTimestamp = $t->getTimestamp();
00162
00163
00164
00165 if( $this->_date > 0 || $this->_categoryId > 0 ) {
00166 $this->_postAmount = -1;
00167
00168 $this->_view->setValue( 'showAll', true );
00169 }
00170 else {
00171 $this->_postAmount = $blogSettings->getValue( 'show_posts_max' );
00172 $this->_view->setValue( 'showAll', false );
00173 }
00174
00175
00176
00177
00178
00179
00180
00181 if( ($blogSettings->getValue( 'show_future_posts_in_calendar')) && ( $this->_date > -1 )) {
00182
00183 $blogArticles = $this->articles->getBlogArticles( $blogId, $this->_date,
00184 $this->_postAmount, $this->_categoryId,
00185 POST_STATUS_PUBLISHED, $this->_userId );
00186 }
00187 else {
00188 $blogArticles = $this->articles->getBlogArticles( $blogId, $this->_date,
00189 $this->_postAmount, $this->_categoryId,
00190 POST_STATUS_PUBLISHED, $this->_userId, $todayTimestamp );
00191 }
00192
00193
00194 if( count($blogArticles) == 0 ) {
00195 $this->_view = new ErrorView( $this->_blogInfo );
00196 $this->_view->setValue( 'message', 'error_fetching_articles' );
00197 }
00198 else {
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 $pm =& PluginManager::getPluginManager();
00211 $pm->setBlogInfo( $this->_blogInfo );
00212 $pm->setUserInfo( $this->_userInfo );
00213 $result = $pm->notifyEvent( EVENT_POSTS_LOADED, Array( 'articles' => &$blogArticles ));
00214 $articles = Array();
00215 foreach( $blogArticles as $article ) {
00216 $postText = $article->getIntroText();
00217 $postExtendedText = $article->getExtendedText();
00218 $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postText ));
00219 $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postExtendedText ));
00220 $article->setIntroText( $postText );
00221 $article->setExtendedText( $postExtendedText );
00222 array_push( $articles, $article );
00223 }
00224
00225 $this->_view->setValue( 'posts', $articles );
00226 }
00227
00228 $this->setCommonData();
00229
00230 $this->saveSession();
00231
00232 return true;
00233 }
00234 }
00235 ?>