[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/net/baserequestgenerator.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/data/stringutils.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/database/db.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" ); 7 8 /** 9 * \ingroup Net 10 * 11 * Generates search-engine friendly URLs and uses Apache mod_rewrite to parse them 12 * 13 * @see RequestGenerator 14 * @see BaseRequestGenerator 15 */ 16 class ModRewriteRequestGenerator extends BaseRequestGenerator 17 { 18 19 /** 20 * Constructor. 21 * 22 * @param blogInfo A BlogInfo object 23 */ 24 function ModRewriteRequestGenerator( $blogInfo ) 25 { 26 $this->BaseRequestGenerator( $blogInfo ); 27 28 } 29 30 /** 31 * Adds a parameter to the request 32 * 33 * @param paramName Name of the parameter 34 * @param paramValue Value given to the parameter 35 */ 36 function addParameter( $paramName, $paramValue ) 37 { 38 $this->_params[$paramName] = $paramValue; 39 } 40 41 /** 42 * Returns the permalink for a post 43 * 44 * @param post The Article object 45 * @return The link for the permalink 46 */ 47 function postPermalink( $post ) 48 { 49 $permaLink = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/archive/'.$post->getId().'_'.StringUtils::text2url( $post->getTopic() ).'.html'; 50 51 return $permaLink; 52 } 53 54 /** 55 * Returns the comment link for a post 56 * 57 * @param post The Article object 58 * @return The correct string 59 */ 60 function postCommentLink( $post ) 61 { 62 $commentLink = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/comment/'.$post->getId().'_'.StringUtils::text2url( $post->getTopic() ).'.html'; 63 64 return $commentLink; 65 } 66 67 /** 68 * Returns the link for the post 69 * 70 * @param post The Article object 71 * @return The link for the post 72 */ 73 function postLink( $post ) 74 { 75 $postLink = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/archive/'.$post->getId().'_'.StringUtils::text2url( $post->getTopic() ).'.html'; 76 77 return $postLink; 78 } 79 80 /** 81 * Returns the link for the post. This is kind of a dirty trick... :( This is only meant to be 82 * used in the template that generates the rss feed for a blog. 83 * 84 * @param post The Article object 85 * @return The link for the post 86 */ 87 function postRssLink( $post ) 88 { 89 $postLink = $this->postPermalink($post); 90 91 return $postLink; 92 } 93 94 /** 95 * Returns the link of a category. 96 * 97 * @param post The post from which we'll fetch the category and then generate the right link. 98 * @return The url pointing to the page with only the posts belonging to that category. 99 * @see Article 100 * @see categoryLink 101 */ 102 function postCategoryLink( $post ) 103 { 104 //throw( new Exception( "DEPRECATED" )); 105 //die(); 106 } 107 108 /** 109 * Returns the link but given a category. Does the same as postCategoryLink but this time we don't need 110 * a post but an ArticleCategory object. 111 * 112 * @see postCategoryLink 113 * @see ArticleCategory 114 * @param An ArticleCategory object containing the information regarding the category. 115 * @return A string with the correct url pointing to the page that will show only the posts that belong 116 * to the given category. 117 */ 118 function categoryLink( $category ) 119 { 120 121 $categoryLink = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/categories/'.$category->getId().'_'.StringUtils::text2url( $category->getName() ).'.html'; 122 123 return $categoryLink; 124 } 125 126 /** 127 * Returns a link to only the articles of the user 128 * 129 * @param user The user whose posts we would like to see 130 * @param category Optionally, we can specify an ArticleCategory object 131 * @return A string containing the right url to only the posts of the user. 132 * @see UserInfo 133 * @see ArticleCategory 134 */ 135 function postUserLink( $user, $category = null ) 136 { 137 $this->addParameter( "op", "Default" ); 138 $this->addParameter( "userId", $user->getId()); 139 if( $category != null ) 140 $this->addParameter( "postCategoryId", $category->getId()); 141 if( $this->_blogInfo != null ) 142 $this->addParameter( "blogId", $this->_blogInfo->getId()); 143 144 145 $userLink = $this->getIndexUrl().$this->getRequest(); 146 147 return $userLink; 148 } 149 150 /** 151 * Returns the url of the host where the blog is running 152 * 153 * @return Returns the url where the blog is running. 154 */ 155 function blogLink( $blogInfo = null ) 156 { 157 if( $blogInfo == null ) { 158 $link = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ); 159 } 160 else { 161 $link = $this->getBaseUrl().'/'.$blogInfo->getId().'_'.StringUtils::text2url( $blogInfo->getBlog() ); 162 } 163 164 return $link; 165 } 166 167 /** 168 * Returns the url where the rss feed is running 169 * 170 * @param blogInfo A BlogInfo object containing information about the blog. 171 * @param profile The RSS profile we'd like to use. It defaults to none. 172 * @return The url pointing to the rss feed of the journal. 173 * @see BlogInfo 174 */ 175 function rssLink( $profile = "", $blogInfo = null ) 176 { 177 if( $blogInfo == null ) 178 $link = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/feeds/'; 179 180 else 181 $link = $this->getBaseUrl().'/'.$blogInfo->getId().'_'.StringUtils::text2url( $bloginfo->getBlog() ).'/feeds/'; 182 183 if( $profile != "" ) 184 $link .= $profile; 185 186 187 return $link; 188 } 189 190 /** 191 * Returns the url for the rss feed of a category 192 * 193 * @param category The ArticleCategory object with information about the category 194 * whose RSS feed we'd like to generate 195 * @þaram profile The profile we'd like to generate: RSS 0.90, RSS 1.0, RSS 2.0 196 * or XML. 197 * @param blogInfo A BlogInfo object containing information about the blog. 198 * @return The url pointing to the rss feed of the journal. 199 * @see BlogInfo 200 */ 201 function categoryRssLink( $category, $profile = "", $blogInfo = null ) 202 { 203 204 if( $blogInfo == null ) 205 $link = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/feeds/categories/'.$category->getId().'_'.StringUtils::text2url( $category->getName() ).'/'; 206 else 207 $link = $this->getBaseUrl().'/'.$blogInfo->getId().'_'.StringUtils::text2url( $blogInfo->getBlog() ).'/feeds/categories/'.$category->getId().'_'.StringUtils::text2url( $category->getName() ).'/'; 208 209 if( $profile != "" ) 210 $link .= $profile; 211 212 return $link; 213 } 214 215 /** 216 * Returns the url to reply to a given comment. 217 * 218 * @param post An Article object with information about the post 219 * @param commen A UserComment object containing information about the post we'd like to reply to. 220 * @return The right url to reply to this comment. 221 * @see UserComment 222 * @see Article 223 */ 224 function replyCommentLink( $post, $comment ) 225 { 226 $this->addParameter( "op", "Comment" ); 227 $this->addParameter( "articleId", $post->getId()); 228 $this->addParameter( "parentId", $comment->getId()); 229 if( $this->_blogInfo != null ) 230 $this->addParameter( "blogId", $this->_blogInfo->getId()); 231 232 //$replyCommentLink = $_SERVER["PHP_SELF"].$rg->getRequest(); 233 $replyCommentLink = $this->getIndexUrl().$this->getRequest(); 234 235 return $replyCommentLink; 236 } 237 238 /** 239 * generates an archive link given a date. 240 * 241 * @param date A String in the format yyyymm 242 * @return A valid archive link 243 */ 244 function getArchiveLink( $date ) 245 { 246 247 if( $this->_blogInfo == null ) 248 $blogID = 1; 249 else 250 $blogID = $this->_blogInfo->getId(); 251 252 // well, does this function actually ever get called without a blogInfo Object? if so this won't work! 253 $link = $this->getBaseUrl().'/'.$blogID.'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/archive/'.$date.'.html'; 254 255 return $link; 256 } 257 258 /** 259 * Returns the link to the page showing the trackback statistics for a given post. 260 * 261 * @param post The post with the information. 262 * @return Returns a string with the valid link. 263 */ 264 function postTrackbackStatsLink( $post ) 265 { 266 $tbStatsLink = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/trackbacks/'.$post->getId().'_'.StringUtils::text2url( $post->getTopic() ).'.html'; 267 268 return $tbStatsLink; 269 } 270 271 /** 272 * Returns the link to an album 273 * 274 * @param album The GalleryAlbum object. 275 */ 276 function albumLink( $album = null ) 277 { 278 279 if( $album == null ) 280 $link = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/albums/'; 281 282 else 283 $link = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/albums/'.$album->getId().'_'.StringUtils::text2url( $album->getName() ).'.html'; 284 285 return $link; 286 } 287 288 /** 289 * Returns the link to a resource 290 * 291 * @param album Generates the correct link to fetch a resource 292 */ 293 function resourceLink( $resource ) 294 { 295 $blogId = $this->_blogInfo->getId(); 296 $ownerId = $resource->getOwnerId(); 297 298 if ( $blogId != $ownerId ) { 299 $blogId = $ownerId; 300 $blogs =& new Blogs(); 301 $blogInfo = $blogs->getBlogInfo($blogId); 302 $blogShortName = $blogInfo->getBlog(); 303 } else { 304 $blogShortName = $this->_blogInfo->getBlog(); 305 } 306 307 $resourceLink = $this->getBaseUrl().'/'.$blogId.'_'.StringUtils::text2url( $blogShortName ).'/resources/'.rawurlencode($resource->getFileName()).'.html'; 308 309 return $resourceLink; 310 } 311 312 /** 313 * Given an album, generates a link to its parent. Must be implemented by child classes to generate 314 * a valid URL. 315 * 316 * @param album The album 317 */ 318 function parentAlbumLink( $album ) 319 { 320 if( $album->getParentId() > 0 ) 321 { 322 $galleryAlbums = new GalleryAlbums(); 323 $parentAlbum = $galleryAlbums->getAlbum( $album->getParentId() ); 324 325 $albumLink = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/albums/'.$album->getParentId().'_'.StringUtils::text2url( $parentAlbum->getName() ).'.html'; 326 327 } else { 328 // this will return the default link to the albums 329 $albumLink = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/albums/'; 330 } 331 332 return $albumLink; 333 } 334 335 /** 336 * Given the name of a template file, generate the right link to it. 337 * 338 * @param template 339 * @return A link to the given template file/static page 340 */ 341 function templatePage( $template ) 342 { 343 $templatePage = $this->getBaseUrl().'/'.$this->_blogInfo->getId().'_'.StringUtils::text2url( $this->_blogInfo->getBlog() ).'/'.$template; 344 345 return $templatePage; 346 } 347 348 /** 349 * Returns a string representing the request 350 * 351 * @return A String object representing the request 352 */ 353 function getRequest() 354 { 355 $request = ""; 356 357 $amp = "&"; 358 359 foreach( $this->_params as $name => $value ) 360 { 361 if( $request == "" ) 362 $request .= "?"; 363 else 364 $request .= $amp; 365 366 $request .= urlencode($name) ."=".urlencode($value); 367 } 368 369 $this->reset(); 370 371 return $request; 372 } 373 374 /** 375 * given the parameters, recalculates the current URL. This method also has support 376 * for paged urls 377 * 378 * @param category 379 * @param userInfo 380 * @param date 381 * @param page 382 * @return the current url with its page 383 */ 384 function getCurrentUrl( $category = null, $userInfo = null, $date = null, $page = null ) 385 { 386 if( $category ) { 387 $url = $this->categoryLink( $category ); 388 } 389 elseif( $userInfo ) { 390 $url = $this->postUserLink( $userInfo ); 391 } 392 elseif( $date > -1 ) { 393 $url = $this->getArchiveLink( $date ); 394 } 395 else { 396 // if none of the above, we should at least get a link to the blog! 397 $url = $this->blogLink(); 398 } 399 400 return( $url.$this->getPageSuffix()); 401 } 402 403 /** 404 * Returns the page format for this URL generator 405 * 406 * @return A page suffix 407 */ 408 function getPageSuffix() 409 { 410 $pageFormat = ".page."; 411 return( $pageFormat ); 412 } 413 } 414 ?>
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 |
![]() |