[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 /** 4 * @package net 5 */ 6 7 8 lt_include( PLOG_CLASS_PATH."class/net/baserequestgenerator.class.php" ); 9 10 /** 11 * \ingroup Net 12 * 13 * Generates prettier but non-customizable requests. 14 * 15 * @see RequestGenerator 16 * @see BaseRequestGenerator 17 */ 18 class PrettyRequestGenerator extends BaseRequestGenerator 19 { 20 21 /** 22 * Constructor. 23 * 24 * @param blogInfo A BlogInfo object 25 */ 26 function PrettyRequestGenerator( $blogInfo ) 27 { 28 $this->BaseRequestGenerator( $blogInfo ); 29 30 } 31 32 /** 33 * Returns the permalink for a post 34 * 35 * @param post The Article object 36 * @return The link for the permalink 37 */ 38 function postPermalink( $post ) 39 { 40 $permaLink = $this->getBaseUrl()."/post/".$this->_blogInfo->getId()."/".$post->getId(); 41 42 return $permaLink; 43 } 44 45 /** 46 * generates an archive link given a date. 47 * 48 * @param date A String in the format yyyymm 49 * @return A valid archive link 50 */ 51 function getArchiveLink( $date ) 52 { 53 $archiveLink = $this->getBaseUrl()."/archives"; 54 if( $this->_blogInfo != null ) 55 $archiveLink .= "/".$this->_blogInfo->getId(); 56 $archiveLink .= "/$date"; 57 58 return $archiveLink; 59 } 60 61 /** 62 * Returns the comment link for a post 63 * 64 * @param post The Article object 65 * @return The correct string 66 */ 67 function postCommentLink( $post ) 68 { 69 $commentLink = $this->getBaseUrl()."/comment/".$this->_blogInfo->getId()."/".$post->getId(); 70 71 return $commentLink; 72 } 73 74 /** 75 * Returns the link for the post 76 * 77 * @param post The Article object 78 * @return The link for the post 79 */ 80 function postLink( $post ) 81 { 82 83 $postLink = $this->postPermalink( $post ); 84 85 return $postLink; 86 } 87 88 /** 89 * Returns the link for the post. This is kind of a dirty trick... :( This is only meant to be 90 * used in the template that generates the rss feed for a blog. 91 * 92 * @param post The Article object 93 * @return The link for the post 94 */ 95 function postRssLink( $post ) 96 { 97 $postLink = $this->postPermalink($post); 98 99 return $postLink; 100 } 101 102 /** 103 * Returns the link of a category. 104 * 105 * @param post The post from which we'll fetch the category and then generate the right link. 106 * @return The url pointing to the page with only the posts belonging to that category. 107 * @see Article 108 * @see categoryLink 109 */ 110 function postCategoryLink( $post ) 111 { 112 throw( new Exception( "DEPRECATED!")); 113 die(); 114 } 115 116 /** 117 * Returns the link but given a category. Does the same as postCategoryLink but this time we don't need 118 * a post but an ArticleCategory object. 119 * 120 * @see postCategoryLink 121 * @see ArticleCategory 122 * @param An ArticleCategory object containing the information regarding the category. 123 * @return A string with the correct url pointing to the page that will show only the posts that belong 124 * to the given category. 125 */ 126 function categoryLink( $category ) 127 { 128 $categoryLink = $this->getBaseUrl()."/category/".$this->_blogInfo->getId()."/".$category->getId(); 129 130 return $categoryLink; 131 } 132 133 /** 134 * Returns a link to only the articles of the user 135 * 136 * @param user The user whose posts we would like to see 137 * @return A string containing the right url to only the posts of the user. 138 * @see UserInfo 139 * @see ArticleCategory 140 */ 141 function postUserLink( $user ) 142 { 143 $userLink = $this->getBaseUrl()."/user/".$this->_blogInfo->getId()."/".$user->getId(); 144 145 return $userLink; 146 } 147 148 /** 149 * Returns the url of the host where the blog is running 150 * 151 * @return Returns the url where the blog is running. 152 */ 153 function blogLink( $blogInfo = null, $ignoreSubdomainSettings = false ) 154 { 155 $config =& Config::getConfig(); 156 // if subdomains are enabled, there is no need to do much more here... 157 if( $config->getValue( "subdomains_enabled" ) && !$ignoreSubdomainSettings ) { 158 $link = $this->getBaseUrl(); 159 } 160 else { 161 // if not, we need some additional logic 162 $path = "/blog/"; 163 164 if( $blogInfo == null ) { 165 if( $config->getValue( "pretty_urls_force_use_username" )) { 166 $userInfo = $this->_blogInfo->getOwnerInfo(); 167 $link = $this->getBaseUrl().$path.$userInfo->getUsername(); 168 } 169 else { 170 $link = $this->getBaseUrl().$path.$this->_blogInfo->getId(); 171 } 172 } 173 else { 174 $link = $this->getBaseUrl().$path.$blogInfo->getId(); 175 } 176 } 177 178 return $link; 179 } 180 181 /** 182 * Returns the url where the rss feed is running 183 * 184 * @param blogInfo A BlogInfo object containing information about the blog. 185 * @param profile The RSS profile we'd like to use. It defaults to none. 186 * @return The url pointing to the rss feed of the journal. 187 * @see BlogInfo 188 */ 189 function rssLink( $profile = "", $blogInfo = null ) 190 { 191 $rssBase = $this->getBaseUrl()."/rss/"; 192 if( $profile != "" ) 193 $rssBase .= $profile."/"; 194 195 if( $blogInfo == null ) 196 $rssLink = $rssBase.$this->_blogInfo->getId(); 197 else 198 $rssLink = $rssBase.$blogInfo->getId(); 199 200 return $rssLink; 201 } 202 203 /** 204 * Returns the url for the rss feed of a category 205 * 206 * @param category The ArticleCategory object with information about the category 207 * whose RSS feed we'd like to generate 208 * @þaram profile The profile we'd like to generate: RSS 0.90, RSS 1.0, RSS 2.0 209 * or XML. 210 * @param blogInfo A BlogInfo object containing information about the blog. 211 * @return The url pointing to the rss feed of the journal. 212 * @see BlogInfo 213 */ 214 function categoryRssLink( $category, $profile = "", $blogInfo = null ) 215 { 216 $rssBase = $this->getBaseUrl()."/rss/"; 217 218 if( $profile != "" ) 219 $rssBase .= $profile."/"; 220 221 if( $blogInfo == null ) 222 $rssLink = $rssBase.$this->_blogInfo->getId(); 223 else 224 $rssLink = $rssBase.$blogInfo->getId(); 225 226 $rssLink .= "/".$category->getId(); 227 228 return $rssLink; 229 } 230 231 /** 232 * Returns the url to reply to a given comment. 233 * 234 * @param post An Article object with information about the post 235 * @param commen A UserComment object containing information about the post we'd like to reply to. 236 * @return The right url to reply to this comment. 237 * @see UserComment 238 * @see Article 239 */ 240 function replyCommentLink( $post, $comment ) 241 { 242 $replyCommentLink = $this->getIndexUrl()."?op=Comment&articleId=".$post->getId()."&parentId=".$comment->getId()."&blogId=".$this->_blogInfo->getId(); 243 244 return $replyCommentLink; 245 } 246 247 /** 248 * Returns the link to the page showing the trackback statistics for a given post. 249 * 250 * @param post The post with the information. 251 * @return Returns a string with the valid link. 252 */ 253 function postTrackbackStatsLink( $post ) 254 { 255 $tbStatsLink = $this->getBaseUrl()."/trackbacks/".$this->_blogInfo->getId()."/".$post->getId(); 256 257 return $tbStatsLink; 258 } 259 260 /** 261 * Returns the link to an album 262 * 263 * @param album The GalleryAlbum object. 264 */ 265 function albumLink( $album = null ) 266 { 267 if( $album == null ) 268 $albumLink = $this->getBaseUrl()."/album/".$this->_blogInfo->getId()."/0"; 269 else 270 $albumLink = $this->getBaseUrl()."/album/".$this->_blogInfo->getId()."/".$album->getId(); 271 272 return $albumLink; 273 } 274 275 /** 276 * Given an album, generates a link to its parent. Must be implemented by child classes to generate 277 * a valid URL. 278 * 279 * @param album The album 280 */ 281 function parentAlbumLink( $album ) 282 { 283 $albumLink = $this->getBaseUrl()."/album/".$this->_blogInfo->getId()."/".$album->getParentId(); 284 285 return $albumLink; 286 } 287 288 /** 289 * Given the name of a template file, generate the right link to it. Must be implemented by child 290 * classes to generate a valid URL. 291 * 292 * @param template 293 * @return A link to the given template file/static page 294 */ 295 function templatePage( $template ) 296 { 297 $templatePage = $this->getBaseUrl()."/static/".$this->_blogInfo->getId()."/".$template; 298 299 return $templatePage; 300 } 301 302 /** 303 * Returns the link to a resource 304 * 305 * @param album Generates the correct link to fetch a resource 306 */ 307 function resourceLink( $resource ) 308 { 309 $blogId = ($resource->getOwnerId() ? $resource->getOwnerId() : $this->_blogInfo->getId()); 310 311 return $resourceLink = $this->getBaseUrl()."/resource/".$blogId."/".$resource->getId(); 312 } 313 314 /** 315 * Returns a string representing the request 316 * 317 * @return A String object representing the request 318 */ 319 function getRequest() 320 { 321 throw( new Exception( "PrettyRequestGenerator::getRequest: function not implemented" )); 322 die(); 323 } 324 325 /** 326 * given the parameters, recalculates the current URL. This method also has support 327 * for paged urls 328 * 329 * @param category 330 * @param userInfo 331 * @param date 332 * @param page 333 * @return the current url with its page 334 */ 335 function getCurrentUrl( $category = null, $userInfo = null, $date = null, $page = null ) 336 { 337 if( $category ) { 338 $url = $this->categoryLink( $category ); 339 } 340 elseif( $userInfo ) { 341 $url = $this->postUserLink( $userInfo ); 342 } 343 elseif( $date > -1 ) { 344 $url = $this->getArchiveLink( $date ); 345 } 346 else { 347 // if none of the above, we should at least get a link to the blog! 348 $url = $this->blogLink( null, true ); 349 } 350 351 return( $url.$this->getPageSuffix()); 352 } 353 354 /** 355 * Returns the page format for this URL generator 356 * 357 * @return A page suffix 358 */ 359 function getPageSuffix() 360 { 361 $pageFormat = "/page/"; 362 return( $pageFormat ); 363 } 364 } 365 ?>
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 |
![]() |