00001 <?php
00002
00003 lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00004 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.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/view/errorview.class.php" );
00008 lt_include( PLOG_CLASS_PATH."class/config/siteconfig.class.php" );
00009
00016 class ViewArticleAction extends BlogAction
00017 {
00018
00019 var $_config;
00020 var $_articleId;
00021 var $_articleName;
00022 var $_date;
00023 var $_maxDate;
00024 var $_userId;
00025 var $_userName;
00026 var $_categoryId;
00027 var $_categoryName;
00028 var $_article;
00029
00030 function ViewArticleAction( $actionInfo, $request )
00031 {
00032 $this->BlogAction( $actionInfo, $request );
00033
00034 $this->registerFieldValidator( "articleId", new IntegerValidator(), true );
00035 $this->registerFieldValidator( "articleName", new StringValidator(), true );
00036 $this->registerFieldValidator( "postCategoryId", new IntegerValidator(), true );
00037 $this->registerFieldValidator( "postCategoryName", new StringValidator(), true );
00038 $this->registerFieldValidator( "userId", new IntegerValidator(), true );
00039 $this->registerFieldValidator( "userName", new UsernameValidator(), true );
00040 $this->registerFieldValidator( "Date", new IntegerValidator(), true );
00041
00042 $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_article" ));
00043 }
00044
00045
00046 function validate()
00047 {
00048 if( !parent::validate())
00049 return( false );
00050
00051 $this->_articleId = $this->_request->getValue( "articleId" );
00052 $this->_articleName = $this->_request->getValue( "articleName" );
00053
00054
00055 $this->_categoryId = $this->_request->getValue( "postCategoryId", -1 );
00056 $this->_categoryName = $this->_request->getValue( "postCategoryName" );
00057 $this->_userId = $this->_request->getValue( "userId", -1 );
00058 $this->_userName = $this->_request->getValue( "userName" );
00059 $this->_date = $this->_request->getValue( "Date", -1 );
00060 $val = new IntegerValidator();
00061 if( !$val->validate( $this->_date ) )
00062 $this->_date = -1;
00063 $this->_isCommentAdded = ($this->_request->getValue( "op" ) == "AddComment" );
00064
00065
00066 $adjustedDates = $this->_getCorrectedDatePeriod( $this->_date );
00067 $this->_date = $adjustedDates["adjustedDate"];
00068 $this->_maxDate = $adjustedDates["maxDate"];
00069
00070
00071 return true;
00072 }
00073
00074 function _setErrorView()
00075 {
00076 $this->_view = new ErrorView( $this->_blogInfo );
00077 $this->_view->setValue( "message", "error_fetching_article" );
00078 if( $this->_config->getValue( 'request_format_mode' ) != NORMAL_REQUEST_MODE )
00079 {
00080 $this->_view->_headers[0] = "HTTP/1.0 404 Not Found";
00081 }
00082 $this->setCommonData();
00083 }
00084
00089 function _updateArticleReferrers($article){
00090 $this->_updateArticleReferrersById($article->getId());
00091 }
00096 function _updateArticleReferrersById($articleId)
00097 {
00098 lt_include( PLOG_CLASS_PATH."class/dao/referers.class.php" );
00099
00100 if ( array_key_exists( 'HTTP_REFERER', $_SERVER ) )
00101 {
00102 $referrers = new Referers();
00103 $referrers->addReferer( $_SERVER['HTTP_REFERER'],
00104 $articleId, $this->_blogInfo->getId());
00105 }
00106 }
00111 function _updateArticleReferrersByTitle($slug)
00112 {
00113 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00114 $articles = new Articles();
00115 $article = $articles->getBlogArticleByTitle( $slug, $this->_blogInfo->getId());
00116 $article ? $id = $article->getId() : $id = 0;
00117
00118
00119 $this->_updateArticleReferrersById( $id );
00120 }
00121
00129 function updateNumArticleReads( $articleId )
00130 {
00131 $articles = new Articles();
00132 $articles->updateArticleNumReads( $articleId );
00133
00134 return( true );
00135 }
00136
00137 function perform()
00138 {
00139 lt_include( PLOG_CLASS_PATH."class/view/viewarticleview.class.php" );
00140 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00141
00142 $this->_view = new ViewArticleView( $this->_blogInfo,
00143 Array( "articleId" => $this->_articleId,
00144 "articleName" => $this->_articleName,
00145 "categoryId" => $this->_categoryId,
00146 "categoryName" => $this->_categoryName,
00147 "userId" => $this->_userId,
00148 "userName" => $this->_userName,
00149 "date" => $this->_date,
00150 "page" => $this->_page ));
00151
00152 if( $this->_view->isCached()) {
00153 if( $this->_config->getValue( 'update_cached_article_reads', false )) {
00154 $articles = new Articles();
00155 if( $this->_articleId ){
00156 $articles->updateArticleNumReads( $this->_articleId );
00157 if( $this->_config->getValue( "referer_tracker_enabled" )) {
00158 $this->_updateArticleReferrersById( $this->_articleId );
00159 }
00160 }
00161 else if($this->_articleName){
00162 $articles->updateArticleNumReadsByName( $this->_articleName );
00163 if( $this->_config->getValue( "referer_tracker_enabled" )) {
00164 $this->_updateArticleReferrersByTitle($this->_articleName );
00165 }
00166 }
00167 else{
00168
00169 }
00170 }
00171
00172 $this->setCommonData();
00173 return true;
00174 }
00175
00176
00177 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
00178 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
00179 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00180 lt_include( PLOG_CLASS_PATH.'class/data/pager/pager.class.php' );
00181 lt_include( PLOG_CLASS_PATH.'class/dao/articlecomments.class.php' );
00182
00183
00184
00185
00186
00187
00188
00189 if( $this->_userName ) {
00190 $users = new Users();
00191 $user = $users->getUserInfoFromUsername( $this->_userName );
00192 if( !$user ) {
00193 $this->_setErrorView();
00194 return false;
00195 }
00196
00197 $this->_userId = $user->getId();
00198 }
00199
00200
00201 if( $this->_categoryName ) {
00202 $categories = new ArticleCategories();
00203 $category = $categories->getCategoryByName( $this->_categoryName, $this->_blogInfo->getId());
00204 if( !$category ) {
00205 $this->_setErrorView();
00206 return false;
00207 }
00208
00209 $this->_categoryId = $category->getId();
00210 }
00211
00212
00213
00214 if( $this->_articleId ) {
00215 $articles = new Articles();
00216 $article = $articles->getBlogArticle( $this->_articleId,
00217 $this->_blogInfo->getId(),
00218 false,
00219 $this->_date,
00220 $this->_categoryId,
00221 $this->_userId,
00222 POST_STATUS_PUBLISHED,
00223 $this->_maxDate);
00224 } else if($this->_articleName){
00225 $articles = new Articles();
00226 $article = $articles->getBlogArticleByTitle( $this->_articleName,
00227 $this->_blogInfo->getId(),
00228 false,
00229 $this->_date,
00230 $this->_categoryId,
00231 $this->_userId,
00232 POST_STATUS_PUBLISHED,
00233 $this->_maxDate);
00234 }
00235 else{
00236
00237 $article = null;
00238 }
00239
00240
00241 if( !$article ) {
00242 $this->_setErrorView();
00243 return false;
00244 }
00245
00246 $this->_article = $article;
00247
00248
00249 if( $this->_config->getValue( "update_article_reads" )) {
00250 $this->updateNumArticleReads( $article->getId());
00251 }
00252
00253
00254 if( $this->_config->getValue( "referer_tracker_enabled" )) {
00255 $this->_updateArticleReferrers( $article );
00256 }
00257
00258
00259 $this->_view->setArticle( $article );
00260
00261 $blogSettings = $this->_blogInfo->getSettings();
00262 $hardLimit = SiteConfig::getHardShowCommentsMax();
00263 $commentsPerPage = $blogSettings->getValue( "show_comments_max", $this->_config->getValue( "show_comments_max" ));
00264 if( $commentsPerPage > $hardLimit ) $commentsPerPage = $hardLimit;
00265
00266 $comments = new ArticleComments();
00267 $order = $blogSettings->getValue( "comments_order", COMMENT_ORDER_NEWEST_FIRST );
00268 $postComments = $comments->getPostComments( $article->getId(),
00269 $order,
00270 COMMENT_STATUS_NONSPAM,
00271 $this->_page,
00272 $commentsPerPage );
00273 $this->_view->setValue( 'comments', $postComments );
00274
00275 $url = $this->_blogInfo->getBlogRequestGenerator();
00276 $pager = new Pager( $url->postPermalink( $article ).$url->getPageSuffix(),
00277 $this->_page,
00278 $article->getNumComments(),
00279 $commentsPerPage );
00280 $this->_view->setValue( 'pager', $pager );
00281
00282 $this->setCommonData();
00283
00284
00285 return true;
00286 }
00287 }
00288 ?>