00001 <?php
00002
00003 lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00004 lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00006 lt_include( PLOG_CLASS_PATH."class/data/validator/usernamevalidator.class.php" );
00007 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00008 lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00009 lt_include( PLOG_CLASS_PATH."class/data/filter/htmlfilter.class.php" );
00010
00017 class DefaultAction extends BlogAction
00018 {
00019
00020 var $_config;
00021 var $_date;
00022 var $_categoryId;
00023 var $_categoryName;
00024 var $_userId;
00025 var $_userName;
00026 var $_postAmount;
00027 var $_searchTerms;
00028
00029 function DefaultAction( $actionInfo, $request )
00030 {
00031 $this->BlogAction( $actionInfo, $request );
00032
00033 $this->registerFieldValidator( "searchTerms", new StringValidator( true ), true );
00034 $this->registerFieldValidator( "postCategoryId", new IntegerValidator(), true );
00035 $this->registerFieldValidator( "postCategoryName", new StringValidator( ), true );
00036 $this->registerFieldValidator( "userId", new IntegerValidator(), true );
00037 $this->registerFieldValidator( "userName", new UsernameValidator(), true );
00038
00039 $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_articles" ));
00040 }
00041
00042 function validate()
00043 {
00044 if( !parent::validate())
00045 return false;
00046
00047
00048 $this->_date = $this->_request->getValue( "Date", -1 );
00049 $val = new IntegerValidator();
00050 if( !$val->validate( $this->_date ) )
00051 $this->_date = -1;
00052 $this->_categoryName = $this->_request->getValue( 'postCategoryName' );
00053 $this->_categoryId = $this->_request->getValue( 'postCategoryId' );
00054 if( $this->_categoryId == '' )
00055 if( $this->_date == -1 )
00056 $this->_categoryId = 0;
00057 else
00058 $this->_categoryId = -1;
00059
00060 $this->_userId = $this->_request->getValue( 'userId', -1 );
00061 $this->_userName = $this->_request->getValue( 'userName', '' );
00062 $this->_searchTerms = $this->_request->getFilteredValue( "searchTerms", new HtmlFilter());
00063
00064 return true;
00065 }
00066
00070 function perform()
00071 {
00072 lt_include( PLOG_CLASS_PATH."class/view/defaultview.class.php" );
00073
00074
00075 $blogId = $this->_blogInfo->getId();
00076
00077
00078 $blogSettings = $this->_blogInfo->getSettings();
00079
00080
00081 $this->_view = new DefaultView( $this->_blogInfo,
00082 Array( "categoryId" => $this->_categoryId,
00083 "blogId" => $this->_blogInfo->getId(),
00084 "categoryName" => $this->_categoryName,
00085 "date" => $this->_date,
00086 "userName" => $this->_userName,
00087 "userId" => $this->_userId,
00088 "searchTerms" => $this->_searchTerms,
00089 "page" => $this->_page ));
00090
00091
00092
00093
00094 if( $this->_view->isCached()) {
00095 $this->setCommonData();
00096 return true;
00097 }
00098
00099 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
00100 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
00101 lt_include( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
00102 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00103 lt_include( PLOG_CLASS_PATH."class/config/siteconfig.class.php" );
00104
00105
00106
00107
00108 $categories = new ArticleCategories();
00109 if( $this->_categoryName ) {
00110 $category = $categories->getCategoryByName( $this->_categoryName, $this->_blogInfo->getId());
00111 if( !$category ) {
00112 $this->_view = new ErrorView( $this->_blogInfo );
00113 $this->_view->setValue( 'message', "error_incorrect_category_id" );
00114 $this->setCommonData();
00115 return false;
00116 }
00117
00118
00119 $this->_categoryId = $category->getId();
00120 }
00121 else {
00122
00123 if( $this->_categoryId > 0 ) {
00124 $category = $categories->getCategory( $this->_categoryId, $this->_blogInfo->getId());
00125 if( !$category ) {
00126 $this->_view = new ErrorView( $this->_blogInfo );
00127 $this->_view->setValue( 'message', "error_incorrect_category_id" );
00128 $this->setCommonData();
00129 return false;
00130 }
00131 }
00132 else {
00133
00134 $category = null;
00135 }
00136 }
00137
00138
00139 if( isset($category) )
00140 $this->_view->setValue( "category", $category );
00141
00142 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
00143 $users = new Users();
00144
00145
00146
00147 if( $this->_userId > 0) {
00148 $user = $users->getUserInfoFromId( $this->_userId );
00149 if( !$user ) {
00150 $this->_view = new ErrorView( $this->_blogInfo );
00151 $this->_view->setValue( 'message', 'error_incorrect_user_id' );
00152 $this->setCommonData();
00153 return false;
00154 }
00155 }
00156 else if( $this->_userName ) {
00157
00158
00159
00160 $user = $users->getUserInfoFromUsername( $this->_userName );
00161 if( !$user ) {
00162 $this->_view = new ErrorView( $this->_blogInfo );
00163 $this->_view->setValue( 'message', 'error_incorrect_user_username' );
00164 $this->setCommonData();
00165 return false;
00166 }
00167
00168
00169 $this->_userId = $user->getId();
00170 }
00171 else {
00172
00173 $user = null;
00174 }
00175
00176 if($blogSettings->getValue( 'show_future_posts_in_calendar')){
00177
00178 $todayTimestamp = 0;
00179 }
00180 else {
00181 $t = new Timestamp();
00182 $todayTimestamp = $t->getTimestamp();
00183 }
00184
00185
00186 $hardLimit = SiteConfig::getHardShowPostsMax();
00187 $this->_postAmount = $blogSettings->getValue( "show_posts_max" );
00188 if( $this->_postAmount > $hardLimit ) $this->_postAmount = $hardLimit;
00189
00190 $articles = new Articles();
00191 $blogArticles = $articles->getBlogArticles(
00192 $blogId,
00193 $this->_date,
00194 $this->_postAmount,
00195 $this->_categoryId,
00196 POST_STATUS_PUBLISHED,
00197 $this->_userId,
00198 $todayTimestamp,
00199 $this->_searchTerms,
00200 $this->_page );
00201
00202 $numArticles = $articles->getNumBlogArticles(
00203 $blogId,
00204 $this->_date,
00205 $this->_categoryId,
00206 POST_STATUS_PUBLISHED,
00207 $this->_userId,
00208 $todayTimestamp,
00209 $this->_searchTerms );
00210
00211
00212 if( count($blogArticles) == 0 ) {
00213 $this->_view = new ErrorView( $this->_blogInfo );
00214 $this->_view->setValue( 'message', 'error_fetching_articles' );
00215 }
00216 else {
00217
00218
00219
00220
00221 $pm =& PluginManager::getPluginManager();
00222 $pm->setBlogInfo( $this->_blogInfo );
00223 $pm->setUserInfo( $this->_userInfo );
00224 $result = $pm->notifyEvent( EVENT_POSTS_LOADED, Array( 'articles' => &$blogArticles ));
00225 $articles = Array();
00226 foreach( $blogArticles as $article ) {
00227 $postText = $article->getIntroText();
00228 $postExtendedText = $article->getExtendedText();
00229 $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postText ));
00230 $pm->notifyEvent( EVENT_TEXT_FILTER, Array( "text" => &$postExtendedText ));
00231 $article->setIntroText( $postText );
00232 $article->setExtendedText( $postExtendedText );
00233 array_push( $articles, $article );
00234 }
00235
00236 $this->_view->setValue( 'posts', $articles );
00237
00238
00239 $url = $this->_blogInfo->getBlogRequestGenerator();
00240 $basePageUrl = $url->getCurrentUrl( $category,
00241 $user,
00242 $this->_date );
00243
00244 $pager = new Pager( $basePageUrl,
00245 $this->_page,
00246 $numArticles,
00247 $this->_postAmount );
00248 $this->_view->setValue( 'pager', $pager );
00249
00250
00251 if( $this->_date > - 1 ) {
00252 $date = str_pad( $this->_date, 14, "0" );
00253 $this->_view->setValue( "date", new Timestamp( $date ));
00254 }
00255 }
00256
00257 $this->setCommonData();
00258
00259 $this->saveSession();
00260
00261 return true;
00262 }
00263 }
00264 ?>