00001 <?php
00002
00003 include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00004 include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00005 include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00006 include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
00007 include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
00008 include_once( PLOG_CLASS_PATH."class/dao/referers.class.php" );
00009 include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00011 include_once( PLOG_CLASS_PATH."class/view/viewarticleview.class.php" );
00012 include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
00013 include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00014 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00015
00022 class ViewArticleAction extends BlogAction
00023 {
00024
00025 var $_config;
00026 var $_articleId;
00027 var $_articleName;
00028 var $_date;
00029 var $_maxDate;
00030 var $_userId;
00031 var $_userName;
00032 var $_categoryId;
00033 var $_categoryName;
00034
00035 function ViewArticleAction( $actionInfo, $request )
00036 {
00037 $this->BlogAction( $actionInfo, $request );
00038
00039 $this->registerFieldValidator( "articleId", new IntegerValidator(), true );
00040 $this->registerFieldValidator( "articleName", new StringValidator(), true );
00041 $this->registerFieldValidator( "postCategoryId", new IntegerValidator(), true );
00042 $this->registerFieldValidator( "postCategoryName", new StringValidator(), true );
00043 $this->registerFieldValidator( "userId", new IntegerValidator(), true );
00044 $this->registerFieldValidator( "userName", new StringValidator(), true );
00045
00046 $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_article" ));
00047 }
00048
00049
00050 function validate()
00051 {
00052 if( !parent::validate())
00053 return( false );
00054
00055 $this->_articleId = $this->_request->getValue( "articleId" );
00056 $this->_articleName = $this->_request->getValue( "articleName" );
00057
00058
00059 $this->_categoryId = $this->_request->getValue( "postCategoryId", -1 );
00060 $this->_categoryName = $this->_request->getValue( "postCategoryName" );
00061 $this->_userId = $this->_request->getValue( "userId", -1 );
00062 $this->_userName = $this->_request->getValue( "userName" );
00063 $this->_date = $this->_request->getValue( "Date", -1 );
00064 $val = new IntegerValidator();
00065 if( !$val->validate( $this->_date ) ) {
00066 $this->_date = -1;
00067 }
00068 $this->_isCommentAdded = ($this->_request->getValue( "op" ) == "AddComment" );
00069
00070
00071 $adjustedDates = $this->_getCorrectedDatePeriod( $this->_date );
00072 $this->_date = $adjustedDates["adjustedDate"];
00073 $this->_maxDate = $adjustedDates["maxDate"];
00074
00075 return true;
00076 }
00077
00078 function _setErrorView()
00079 {
00080 $this->_view = new ErrorView( $this->_blogInfo );
00081 $this->_view->setValue( "message", "error_fetching_article" );
00082 $this->setCommonData();
00083 }
00084
00089 function _updateArticleReferrers($article){
00090 $this->_updateArticleReferrersById($article->getId());
00091 }
00096 function _updateArticleReferrersById($articleId){
00097 if ( array_key_exists( 'HTTP_REFERER', $_SERVER ) )
00098 {
00099 $referrers = new Referers();
00100 $referrers->addReferer( $_SERVER['HTTP_REFERER'],
00101 $articleId, $this->_blogInfo->getId());
00102 }
00103 }
00108 function _updateArticleReferrersByTitle($slug){
00109 $id = $this->articles->getArticleIdFromName($slug);
00110
00111
00112 $this->_updateArticleReferrersById($id);
00113 }
00114
00122 function updateNumArticleReads( $articleId )
00123 {
00124 $this->articles->updateArticleNumReads( $articleId );
00125
00126 return( true );
00127 }
00128
00129 function perform()
00130 {
00131 $this->_view = new ViewArticleView( $this->_blogInfo,
00132 Array( "articleId" => $this->_articleId,
00133 "articleName" => $this->_articleName,
00134 "categoryId" => $this->_categoryId,
00135 "categoryName" => $this->_categoryName,
00136 "userId" => $this->_userId,
00137 "userName" => $this->_userName,
00138 "date" => $this->_date ));
00139
00140 if( $this->_view->isCached()) {
00141 if( $this->_config->getValue( 'update_cached_article_reads', false )) {
00142 if( $this->_articleId ){
00143 $this->articles->updateArticleNumReads( $this->_articleId );
00144 $this->_updateArticleReferrersById( $this->_articleId );
00145 }
00146 else{
00147 $this->articles->updateArticleNumReadsByName( $this->_articleName );
00148 $this->_updateArticleReferrersByTitle($this->_articleName );
00149 }
00150 }
00151
00152 return true;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161 if( $this->_userName ) {
00162 $users = new Users();
00163 $user = $users->getUserInfoFromUsername( $this->_userName );
00164 if( !$user ) {
00165 $this->_setErrorView();
00166 return false;
00167 }
00168
00169 $this->_userId = $user->getId();
00170 }
00171
00172 if( $this->_categoryName ) {
00173 $categories = new ArticleCategories();
00174 $category = $categories->getCategoryByName( $this->_categoryName, $this->_blogInfo->getId());
00175 if( !$category ) {
00176 $this->_setErrorView();
00177 return false;
00178 }
00179
00180 $this->_categoryId = $category->getId();
00181 }
00182
00183
00184
00185 if( $this->_articleId ) {
00186 $article = $this->articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId(), false,
00187 $this->_date, $this->_categoryId, $this->_userId,
00188 POST_STATUS_PUBLISHED, $this->_maxDate );
00189 }
00190 else {
00191 $article = $this->articles->getBlogArticleByTitle( $this->_articleName, $this->_blogInfo->getId(), false,
00192 $this->_date, $this->_categoryId, $this->_userId,
00193 POST_STATUS_PUBLISHED, $this->_maxDate );
00194 }
00195
00196
00197 if( !$article ) {
00198 $this->_setErrorView();
00199 return false;
00200 }
00201
00202
00203 $this->notifyEvent( EVENT_POST_LOADED, Array( "article" => &$article ));
00204
00205
00206 if( $this->_config->getValue( "update_article_reads" )) {
00207 $this->updateNumArticleReads( $article->getId());
00208 }
00209
00210
00211 $this->_updateArticleReferrers( $article );
00212
00213
00214 $this->_view->setArticle( $article );
00215 $this->setCommonData();
00216
00217
00218 return true;
00219 }
00220 }
00221 ?>