[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/config/siteconfig.class.php" ); 8 9 /** 10 * \ingroup Action 11 * @private 12 * 13 * This class represents the defaut view in our application 14 */ 15 class ViewArticleAction extends BlogAction 16 { 17 18 var $_config; 19 var $_articleId; 20 var $_articleName; 21 var $_date; 22 var $_maxDate; 23 var $_userId; 24 var $_userName; 25 var $_categoryId; 26 var $_categoryName; 27 var $_article; 28 29 function ViewArticleAction( $actionInfo, $request ) 30 { 31 $this->BlogAction( $actionInfo, $request ); 32 33 $this->registerFieldValidator( "articleId", new IntegerValidator(), true ); 34 $this->registerFieldValidator( "articleName", new StringValidator(), true ); 35 $this->registerFieldValidator( "postCategoryId", new IntegerValidator(), true ); 36 $this->registerFieldValidator( "postCategoryName", new StringValidator(), true ); 37 $this->registerFieldValidator( "userId", new IntegerValidator(), true ); 38 $this->registerFieldValidator( "userName", new StringValidator(), true ); 39 40 $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_article" )); 41 } 42 43 // checks that the articleId is valid 44 function validate() 45 { 46 if( !parent::validate()) 47 return( false ); 48 49 $this->_articleId = $this->_request->getValue( "articleId" ); 50 $this->_articleName = $this->_request->getValue( "articleName" ); 51 // find some other additional parameters and use some 'null' values 52 // in casuse they're empty 53 $this->_categoryId = $this->_request->getValue( "postCategoryId", -1 ); 54 $this->_categoryName = $this->_request->getValue( "postCategoryName" ); 55 $this->_userId = $this->_request->getValue( "userId", -1 ); 56 $this->_userName = $this->_request->getValue( "userName" ); 57 $this->_date = $this->_request->getValue( "Date", -1 ); 58 $val = new IntegerValidator(); 59 if( !$val->validate( $this->_date ) ) 60 $this->_date = -1; 61 $this->_isCommentAdded = ($this->_request->getValue( "op" ) == "AddComment" ); 62 63 // Calculate the correct article date period 64 $adjustedDates = $this->_getCorrectedDatePeriod( $this->_date ); 65 $this->_date = $adjustedDates["adjustedDate"]; 66 $this->_maxDate = $adjustedDates["maxDate"]; 67 // if( $this->_maxDate == -1 ) $this->_maxDate = 0; 68 69 return true; 70 } 71 72 function _setErrorView() 73 { 74 $this->_view = new ErrorView( $this->_blogInfo ); 75 $this->_view->setValue( "message", "error_fetching_article" ); 76 $this->setCommonData(); 77 } 78 79 /** 80 * @private 81 * updates the article referrers given an article 82 */ 83 function _updateArticleReferrers($article){ 84 $this->_updateArticleReferrersById($article->getId()); 85 } 86 /** 87 * @private 88 * updates the article referrers given an id 89 */ 90 function _updateArticleReferrersById($articleId) 91 { 92 lt_include( PLOG_CLASS_PATH."class/dao/referers.class.php" ); 93 94 if ( array_key_exists( 'HTTP_REFERER', $_SERVER ) ) 95 { 96 $referrers = new Referers(); 97 $referrers->addReferer( $_SERVER['HTTP_REFERER'], 98 $articleId, $this->_blogInfo->getId()); 99 } 100 } 101 /** 102 * @private 103 * updates the article referrers, given a slug 104 */ 105 function _updateArticleReferrersByTitle($slug) 106 { 107 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 108 $articles = new Articles(); 109 $article = $articles->getBlogArticleByTitle( $slug, $this->_blogInfo->getId()); 110 $article ? $id = $article->getId() : $id = 0; 111 // if the article isn't found, we will save a referrer to 112 // the main page, since $id will be 0. 113 $this->_updateArticleReferrersById( $id ); 114 } 115 116 /** 117 * @private 118 * updates the number of times that an article has been read in the db 119 * 120 * @param articleId 121 * @return always true 122 */ 123 function updateNumArticleReads( $articleId ) 124 { 125 $articles = new Articles(); 126 $articles->updateArticleNumReads( $articleId ); 127 128 return( true ); 129 } 130 131 function perform() 132 { 133 lt_include( PLOG_CLASS_PATH."class/view/viewarticleview.class.php" ); 134 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 135 136 $this->_view = new ViewArticleView( $this->_blogInfo, 137 Array( "articleId" => $this->_articleId, 138 "articleName" => $this->_articleName, 139 "categoryId" => $this->_categoryId, 140 "categoryName" => $this->_categoryName, 141 "userId" => $this->_userId, 142 "userName" => $this->_userName, 143 "date" => $this->_date, 144 "page" => $this->_page )); 145 146 if( $this->_view->isCached()) { 147 if( $this->_config->getValue( 'update_cached_article_reads', false )) { 148 $articles = new Articles(); 149 if( $this->_articleId ){ 150 $articles->updateArticleNumReads( $this->_articleId ); 151 $this->_updateArticleReferrersById( $this->_articleId ); 152 } 153 else{ 154 $articles->updateArticleNumReadsByName( $this->_articleName ); 155 $this->_updateArticleReferrersByTitle($this->_articleName ); 156 } 157 } 158 159 $this->setCommonData(); 160 return true; 161 } 162 163 164 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" ); 165 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); 166 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 167 lt_include( PLOG_CLASS_PATH.'class/data/pager/pager.class.php' ); 168 lt_include( PLOG_CLASS_PATH.'class/dao/articlecomments.class.php' ); 169 170 // --- 171 // if we got a category name or a user name instead of a category 172 // id and a user id, then we have to look up first those 173 // and then proceed 174 // --- 175 // users... 176 if( $this->_userName ) { 177 $users = new Users(); 178 $user = $users->getUserInfoFromUsername( $this->_userName ); 179 if( !$user ) { 180 $this->_setErrorView(); 181 return false; 182 } 183 // if there was a user, use his/her id 184 $this->_userId = $user->getId(); 185 } 186 187 // ...and categories... 188 if( $this->_categoryName ) { 189 $categories = new ArticleCategories(); 190 $category = $categories->getCategoryByName( $this->_categoryName, $this->_blogInfo->getId()); 191 if( !$category ) { 192 $this->_setErrorView(); 193 return false; 194 } 195 // if there was a user, use his/her id 196 $this->_categoryId = $category->getId(); 197 } 198 199 // fetch the article 200 // the article identifier can be either its internal id number or its mangled topic 201 $articles = new Articles(); 202 if( $this->_articleId ) { 203 $article = $articles->getBlogArticle( $this->_articleId, 204 $this->_blogInfo->getId(), 205 false, 206 $this->_date, 207 $this->_categoryId, 208 $this->_userId, 209 POST_STATUS_PUBLISHED, 210 $this->_maxDate); 211 } else { 212 $article = $articles->getBlogArticleByTitle( $this->_articleName, 213 $this->_blogInfo->getId(), 214 false, 215 $this->_date, 216 $this->_categoryId, 217 $this->_userId, 218 POST_STATUS_PUBLISHED, 219 $this->_maxDate); 220 } 221 222 // if the article id doesn't exist, cancel the whole thing... 223 if( !$article ) { 224 $this->_setErrorView(); 225 return false; 226 } 227 228 $this->_article = $article; 229 230 // check if we have to update how many times an article has been read 231 if( $this->_config->getValue( "update_article_reads" )) { 232 $this->updateNumArticleReads( $article->getId()); 233 } 234 235 // update the referrers, if needed 236 $this->_updateArticleReferrers( $article ); 237 238 // if everything's fine, we set up the article object for the view 239 $this->_view->setArticle( $article ); 240 // and the comments 241 $blogSettings = $this->_blogInfo->getSettings(); 242 $hardLimit = SiteConfig::getHardShowCommentsMax(); 243 $commentsPerPage = $blogSettings->getValue( "show_comments_max", $this->_config->getValue( "show_comments_max" )); 244 if( $commentsPerPage > $hardLimit ) $commentsPerPage = $hardLimit; 245 246 $comments = new ArticleComments(); 247 $order = $blogSettings->getValue( "comments_order", COMMENT_ORDER_NEWEST_FIRST ); 248 $postComments = $comments->getPostComments( $article->getId(), 249 $order, 250 COMMENT_STATUS_NONSPAM, 251 $this->_page, 252 $commentsPerPage ); 253 $this->_view->setValue( 'comments', $postComments ); 254 // build the pager and pass it to the view 255 $url = $this->_blogInfo->getBlogRequestGenerator(); 256 $pager = new Pager( $url->postPermalink( $article ).$url->getPageSuffix(), 257 $this->_page, // current page 258 $article->getNumComments(), // total number of articles 259 $commentsPerPage ); // number of comments per page 260 $this->_view->setValue( 'pager', $pager ); 261 262 $this->setCommonData(); 263 264 // and return everything normal 265 return true; 266 } 267 } 268 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |