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