[ 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/config/config.class.php" ); 5 6 /** 7 * \ingroup Net 8 * 9 * Generates requests using a custom format. 10 * 11 * @see RequestGenerator 12 * @see BaseRequestGenerator 13 */ 14 class CustomRequestGenerator extends BaseRequestGenerator 15 { 16 17 var $_config; 18 19 /** 20 * Constructor. 21 * 22 * @param blogInfo A BlogInfo object 23 */ 24 function CustomRequestGenerator( $blogInfo = null ) 25 { 26 $this->BaseRequestGenerator( $blogInfo ); 27 $this->_config =& Config::getConfig(); 28 } 29 30 /** 31 * Returns the permalink for a post 32 * 33 * @param post The Article object 34 * @return The link for the permalink 35 */ 36 function postPermalink( $post ) 37 { 38 $postPermalinkFormat = $this->_config->getValue( "permalink_format"); 39 40 $params = $this->_fillPostParameters( $post ); 41 42 $permaLink = $this->getBaseUrl().$this->_replaceTags( $postPermalinkFormat, $params ); 43 44 return $permaLink; 45 } 46 47 /** 48 * @private 49 */ 50 function _fillPostParameters( $post ) 51 { 52 $t = $post->getDateObject(); 53 $categories = $post->getCategories(); 54 $category = array_pop( $categories ); 55 $user = $post->getUserInfo(); 56 $ownerInfo = $this->_blogInfo->getOwnerInfo(); 57 58 //print_r($post); 59 60 $day = $t->getDay(); 61 if( $day < 10 ) $day = "0".$day; 62 63 $params = Array( '{blogname}' => $this->_blogInfo->getMangledBlog(), 64 '{blogid}' => $this->_blogInfo->getId(), 65 '{blogowner}' => $ownerInfo->getUsername(), 66 '{year}' => $t->getYear(), 67 '{month}' => $t->getMonth(), 68 '{day}' => $day, 69 '{hour}' => $t->getHour(), 70 '{minute}' => $t->getMinutes(), 71 '{postid}' => $post->getId(), 72 '{postname}' => $post->getPostSlug(), 73 '{catname}' => $category->getMangledName(), 74 '{catid}' => $category->getId(), 75 '{userid}' => $user->getId(), 76 '{username}' => $user->getUsername() 77 ); 78 79 return $params; 80 } 81 82 /** 83 * generates an archive link given a date. 84 * 85 * @param date A String in the format yyyymm 86 * @return A valid archive link 87 */ 88 function getArchiveLink( $date ) 89 { 90 $archiveLinkFormat = $this->_config->getValue( 'archive_link_format' ); 91 $ownerInfo = $this->_blogInfo->getOwnerInfo(); 92 93 // this is quite a dirty one but it works... 94 $newDate = $date; 95 if( strlen($date) == 6 ) $newDate = $date."00000000"; 96 if( strlen($date) == 8 ) $newDate = $date."000000"; 97 $t = new Timestamp( $newDate ); 98 99 $params = Array( "{year}" => $t->getYear(), 100 "{month}" => $t->getMonth(), 101 "{blogname}" => $this->_blogInfo->getMangledBlog(), 102 "{blogowner}" => $ownerInfo->getUsername(), 103 "{blogid}" => $this->_blogInfo->getId()); 104 if( strlen($date) == 6 ) $params["{day}"] = ""; 105 else { 106 $day = $t->getDay(); 107 if( $day < 10 ) 108 $day = "0".$day; 109 $params["{day}"] = $day; 110 } 111 112 $archiveLink = $this->getBaseUrl().$this->_replaceTags( $archiveLinkFormat, $params ); 113 114 return $archiveLink; 115 } 116 117 /** 118 * Returns the comment link for a post 119 * 120 * @param post The Article object 121 * @return The correct string 122 */ 123 function postCommentLink( $post ) 124 { 125 $commentLink = $this->getIndexUrl()."?op=Comment&blogId=".$this->_blogInfo->getId()."&articleId=".$post->getId(); 126 127 return $commentLink; 128 } 129 130 /** 131 * Returns the link for the post 132 * 133 * @param post The Article object 134 * @return The link for the post 135 */ 136 function postLink( $post ) 137 { 138 return $this->postPermalink( $post ); 139 } 140 141 /** 142 * Returns the link for the post. This is kind of a dirty trick... :( This is only meant to be 143 * used in the template that generates the rss feed for a blog. 144 * 145 * @param post The Article object 146 * @return The link for the post 147 */ 148 function postRssLink( $post ) 149 { 150 $postLink = $this->postPermalink($post); 151 152 return $postLink; 153 } 154 155 /** 156 * Returns the link but given a category. Does the same as postCategoryLink but this time we don't need 157 * a post but an ArticleCategory object. 158 * 159 * @see postCategoryLink 160 * @see ArticleCategory 161 * @param An ArticleCategory object containing the information regarding the category. 162 * @return A string with the correct url pointing to the page that will show only the posts that belong 163 * to the given category. 164 */ 165 function categoryLink( $category ) 166 { 167 $categoryFormat = $this->_config->getValue( "category_link_format" ); 168 $ownerInfo = $this->_blogInfo->getOwnerInfo(); 169 $params = Array( "{catid}" => $category->getId(), 170 "{catname}" => $category->getMangledName(), 171 "{blogid}" => $this->_blogInfo->getId(), 172 "{blogowner}" => $ownerInfo->getUsername(), 173 "{blogname}" => $this->_blogInfo->getMangledBlog()); 174 $result = $this->_replaceTags( $categoryFormat, $params ); 175 176 $categoryLink = $this->getBaseUrl().$result; 177 178 return $categoryLink; 179 } 180 181 /** 182 * Returns a link to only the articles of the user 183 * 184 * @param user The user whose posts we would like to see 185 * @param category Optionally, we can specify an ArticleCategory object 186 * @return A string containing the right url to only the posts of the user. 187 * @see UserInfo 188 * @see ArticleCategory 189 */ 190 function postUserLink( $user, $category = null ) 191 { 192 $userPostsLink = $this->_config->getValue( "user_posts_link_format" ); 193 $ownerInfo = $this->_blogInfo->getOwnerInfo(); 194 195 $params = Array( "{blogid}" => $this->_blogInfo->getId(), 196 "{blogname}" => $this->_blogInfo->getMangledBlog(), 197 "{blogowner}" => $ownerInfo->getUsername(), 198 "{username}" => $user->getUsername(), 199 "{userid}" => $user->getId(), 200 "{year}" => "", 201 "{month}" => "", 202 "{day}" => "" ); 203 204 $userLink = $this->getBaseUrl().$this->_replaceTags( $userPostsLink, $params ); 205 206 return $userLink; 207 } 208 209 /** 210 * Returns the url of the host where the blog is running 211 * 212 * @return Returns the url where the blog is running. 213 */ 214 function blogLink( $blogInfo = null ) 215 { 216 if( $blogInfo == null ) 217 $blogInfo = $this->_blogInfo; 218 219 // get information about the owner 220 $ownerInfo = $blogInfo->getOwnerInfo(); 221 222 $blogLinkFormat = $this->_config->getValue( "blog_link_format" ); 223 $params = Array( "{blogid}" => $blogInfo->getId(), 224 "{blogname}" => $blogInfo->getMangledBlog(), 225 "{blogowner}" => $ownerInfo->getUsername()); 226 $result = $this->getBaseUrl().$this->_replaceTags( $blogLinkFormat, $params ); 227 228 return $result; 229 } 230 231 /** 232 * Returns the url where the rss feed is running 233 * 234 * @param blogInfo A BlogInfo object containing information about the blog. 235 * @param profile The RSS profile we'd like to use. It defaults to none. 236 * @return The url pointing to the rss feed of the journal. 237 * @see BlogInfo 238 */ 239 function rssLink( $profile = "", $blogInfo = null ) 240 { 241 $rssLink = $this->getRssUrl(); 242 if( $blogInfo == null ) 243 $rssLink .= "?blogId=".$this->_blogInfo->getId(); 244 else 245 $rssLink .= "?blogId=".$blogInfo->getId(); 246 247 if( $profile != "" ) 248 $rssLink .= "&profile=$profile"; 249 250 return $rssLink; 251 } 252 253 /** 254 * Returns the url for the rss feed of a category 255 * 256 * @param category The ArticleCategory object with information about the category 257 * whose RSS feed we'd like to generate 258 * @þaram profile The profile we'd like to generate: RSS 0.90, RSS 1.0, RSS 2.0 259 * or XML. 260 * @param blogInfo A BlogInfo object containing information about the blog. 261 * @return The url pointing to the rss feed of the journal. 262 * @see BlogInfo 263 */ 264 function categoryRssLink( $category, $profile = "", $blogInfo = null ) 265 { 266 $rssLink = $this->rssLink( $profile, $blogInfo ); 267 $rssLink .= "&categoryId=".$category->getId(); 268 return $rssLink; 269 } 270 271 /** 272 * Returns the url to reply to a given comment. 273 * 274 * @param post An Article object with information about the post 275 * @param commen A UserComment object containing information about the post we'd like to reply to. 276 * @return The right url to reply to this comment. 277 * @see UserComment 278 * @see Article 279 */ 280 function replyCommentLink( $post, $comment ) 281 { 282 $replyCommentLink = $this->getIndexUrl()."?op=Comment&articleId=".$post->getId()."&parentId=".$comment->getId()."&blogId=".$this->_blogInfo->getId(); 283 284 return $replyCommentLink; 285 } 286 287 /** 288 * Returns the link to the page showing the trackback statistics for a given post. 289 * 290 * @param post The post with the information. 291 * @return Returns a string with the valid link. 292 */ 293 function postTrackbackStatsLink( $post ) 294 { 295 $postTrackbacksFormat = $this->_config->getValue( "post_trackbacks_link_format"); 296 297 $params = $this->_fillPostParameters( $post ); 298 299 $permaLink = $this->getBaseUrl().$this->_replaceTags( $postTrackbacksFormat, $params ); 300 301 return $permaLink; 302 } 303 304 /** 305 * Returns the link to an album 306 * 307 * @param album The GalleryAlbum object. 308 * @param page current page 309 */ 310 function albumLink( $album = null ) 311 { 312 $albumLinkFormat = $this->_config->getValue( "album_link_format" ); 313 $ownerInfo = $this->_blogInfo->getOwnerInfo(); 314 315 $params = Array( "{blogid}" => $this->_blogInfo->getId(), 316 "{blogname}" => $this->_blogInfo->getMangledBlog(), 317 "{blogowner}" => $ownerInfo->getUsername(), 318 "{albumid}" => "", 319 "{albumname}" => "" ); 320 321 if( $album != null ) { 322 $params["{albumid}"] = $album->getId(); 323 $params["{albumname}"] = $album->getMangledName(); 324 } 325 326 $albumLink = $this->getBaseUrl().$this->_replaceTags( $albumLinkFormat, $params ); 327 328 return $albumLink; 329 } 330 331 /** 332 * Given an album, generates a link to its parent. Must be implemented by child classes to generate 333 * a valid URL. 334 * 335 * @param album The album 336 */ 337 function parentAlbumLink( $album ) 338 { 339 if( $album->getParentId() == 0 ) { 340 // if the parent album is the root album, let's make it easy... 341 $albumLink = $this->albumLink( null ); 342 } 343 else { 344 // i don't really like this bit because suddenly, a request generator class 345 // starts loading objects from the db... 346 $albums = new GalleryAlbums(); 347 $parentAlbum = $albums->getAlbum( $album->getParentId()); 348 $albumLink = $this->albumLink( $parentAlbum ); 349 } 350 351 return $albumLink; 352 } 353 354 /** 355 * Given the name of a template file, generate the right link to it. 356 * 357 * @param template 358 * @return A link to the given template file/static page 359 */ 360 function templatePage( $template ) 361 { 362 $templateLinkFormat = $this->_config->getValue( "template_link_format" ); 363 $ownerInfo = $this->_blogInfo->getOwnerInfo(); 364 365 $params = Array( "{blogid}" => $this->_blogInfo->getId(), 366 "{blogname}" => $this->_blogInfo->getMangledBlog(), 367 "{blogowner}" => $ownerInfo->getUsername(), 368 "{templatename}" => $template ); 369 370 $templatePage = $this->getBaseUrl().$this->_replaceTags( $templateLinkFormat, $params ); 371 372 return $templatePage; 373 } 374 375 /** 376 * Returns the link to a resource 377 * 378 * @param album Generates the correct link to fetch a resource 379 */ 380 function resourceLink( $resource ) 381 { 382 $resourceLinkFormat = $this->_config->getValue( "resource_link_format" ); 383 $params = $this->_fillResourceParameters( $resource ); 384 $resourceLink = $this->getBaseUrl().$this->_replaceTags( $resourceLinkFormat, $params ); 385 386 return $resourceLink; 387 } 388 389 /** 390 * @private 391 */ 392 function _fillResourceParameters( $resource ) 393 { 394 $album = $resource->getAlbum(); 395 $blogId = $this->_blogInfo->getId(); 396 $ownerId = $resource->getOwnerId(); 397 398 if ( $blogId != $ownerId ) { 399 $blogId = $ownerId; 400 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" ); 401 $blogs =& new Blogs(); 402 $blogInfo = $blogs->getBlogInfo($blogId); 403 $blogShortName = $blogInfo->getMangledBlog(); 404 $ownerInfo = $blogInfo->getOwnerInfo(); 405 } else { 406 $blogShortName = $this->_blogInfo->getMangledBlog(); 407 $ownerInfo = $this->_blogInfo->getOwnerInfo(); 408 } 409 410 $params = Array( "{blogid}" => $blogId, 411 "{blogname}" => $blogShortName, 412 "{blogowner}" => $ownerInfo->getUsername(), 413 "{resourceid}" => $resource->getId(), 414 "{resourcename}" => rawurlencode($resource->getFileName()), 415 "{albumid}" => $album->getId(), 416 "{albumname}" => $album->getMangledName()); 417 418 return $params; 419 } 420 421 422 /** 423 * Returns a string representing the request 424 * 425 * @return A String object representing the request 426 */ 427 function getRequest() 428 { 429 throw( new Exception( "PrettyRequestGenerator::getRequest: function not implemented" )); 430 die(); 431 } 432 433 /** 434 * @private 435 * @params format 436 * @params tags 437 * @return string 438 */ 439 function _replaceTags( $format, $tags ) 440 { 441 $result = $format; 442 $result = str_replace( "$", "", $format ); 443 $result = str_replace( "(", "", $result ); 444 $result = str_replace( ")", "", $result ); 445 $result = str_replace( "?", "", $result ); 446 $result = str_replace( "\\", "", $result ); 447 foreach( $tags as $key => $value ) { 448 $result = str_replace( $key, $value, $result ); 449 } 450 451 return $result; 452 } 453 454 /** 455 * given the parameters, recalculates the current URL. This method also has support 456 * for paged urls 457 * 458 * @param category 459 * @param userInfo 460 * @param date 461 * @param page 462 * @return the current url with its page 463 */ 464 function getCurrentUrl( $category = null, $userInfo = null, $date = -1 ) 465 { 466 if( $category ) { 467 $url = $this->categoryLink( $category ); 468 } 469 elseif( $userInfo ) { 470 $url = $this->postUserLink( $userInfo ); 471 } 472 elseif( $date > -1 ) { 473 $url = $this->getArchiveLink( $date ); 474 if( $url[strlen($url)-1] == "/" ) 475 $url = substr( $url, 0, -1); 476 } 477 else { 478 // if none of the above, we should at least get a link to the blog! 479 $url = $this->blogLink(); 480 } 481 482 $pageFormat = $this->getPageSuffix(); 483 484 return( $url.$pageFormat ); 485 } 486 487 /** 488 * Returns the page format for this URL generator 489 * 490 * @return A page suffix 491 */ 492 function getPageSuffix() 493 { 494 $pageFormat = $this->_config->getValue( "page_suffix_format" ); 495 496 return( $pageFormat ); 497 } 498 } 499 ?>
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 |
![]() |