| [ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 /** 4 * \defgroup Net 5 * 6 * The Net package includes all the classes that are related to network functionality in one way 7 * or another. 8 * 9 * @see Net_HTTP 10 */ 11 12 define( "DEFAULT_SCRIPT_NAME", "index.php" ); 13 14 /** 15 * Default folder where resources are installed 16 */ 17 define( "DEFAULT_GALLERY_RESOURCES_FOLDER", "./gallery/" ); 18 19 20 /** 21 * \ingroup Net 22 * 23 * The BaseRequestGenerator class is some sort of proxy class that defines an interface that should be implemented 24 * by classes wishing to provide a new request generator (plus some code that can be reused by all request 25 * generators) 26 * 27 * Each request generator defines its own format for its URLs, and by using request generators we can easily 28 * change the format of our URLs without the need to alter our templates (and therefore, without the need to hardcode 29 * URLs in our templates) 30 * 31 * You should never create instances of BaseRequestGenerator as it defines no code for most of its methods and 32 * will instead throw exceptions. The correct way of getting a request generator is by using the 33 * RequestGenerator factory or whenever we have a BlogInfo object available, by using the 34 * BlogInfo::getBlogRequestGenerator() method. 35 * 36 * @see RequestGenerator 37 */ 38 class BaseRequestGenerator 39 { 40 41 var $_params; 42 var $_blogInfo; 43 var $_baseUrl; 44 var $_xhtmlEnabled; 45 var $_subdomainsEnabled; 46 var $_includeBlogId; 47 var $_subdomainsBaseUrl; 48 var $_scriptName; 49 50 /** 51 * Constructor. It initializes certain things such as the base url, checks whether subdomains are 52 * enabled, etc. This method will fetch the values of the following configuration settings: 53 * 54 * - base_url: this is the base URL that will be used to generate all other URLs in the system 55 * - subdomains_base_url: if subdomains are enabled, we should also set this URL to something valid. We can 56 * either use {blogname} or {username} to specify whether the URLs should be generated including the 57 * name of the user who owns the blog or the name of the blog. 58 * - include_blog_id_in_url 59 * - script_name: use this setting to rename index.php to something else and still have pLog generate 60 * URLs pointing to the right script. 61 * 62 * @param blogInfo A valid BlogInfo object 63 */ 64 function BaseRequestGenerator( $blogInfo = null ) 65 { 66 67 68 $this->_params = Array(); 69 70 $this->_blogInfo = $blogInfo; 71 $config =& Config::getConfig(); 72 $this->_baseUrl = $config->getValue( "base_url" ); 73 $this->_subdomainsBaseUrl = $config->getValue( "subdomains_base_url" ); 74 75 // get some information about the configuration of subdomains 76 $this->_subdomainsEnabled = $config->getValue( "subdomains_enabled" ); 77 if( $this->_subdomainsEnabled ) 78 $this->_includeBlogId = $config->getValue( "include_blog_id_in_url" ); 79 else 80 $this->_includeBlogId = true; 81 82 // prepare the correct url if subdomains are enabled... 83 if( $this->_subdomainsEnabled && $blogInfo != null ) { 84 $this->_subdomainsBaseUrl = str_replace("{blogname}", 85 $blogInfo->getMangledBlog(), 86 $this->_subdomainsBaseUrl); 87 $ownerInfo = $blogInfo->getOwnerInfo(); 88 $this->_subdomainsBaseUrl = str_replace("{username}", 89 $ownerInfo->getUsername(), 90 $this->_subdomainsBaseUrl); 91 $this->_subdomainsBaseUrl = str_replace("{blogdomain}", 92 $blogInfo->getCustomDomain(), 93 $this->_subdomainsBaseUrl); 94 } 95 $this->_scriptName = $config->getValue( "script_name", DEFAULT_SCRIPT_NAME ); 96 97 // enable the xhtml mode by default, but it can be turned off 98 // via the setXHTML() method 99 $this->_xhtmlEnabled = true; 100 } 101 102 /** 103 * @return Returns true if subdomains are enabled 104 */ 105 function getSubdomainsEnabled() 106 { 107 return $this->_subdomainsEnabled; 108 } 109 110 /** 111 * @returns true if the blog identifier should be included in the URL. This setting is only meaningful 112 * when subdomains are enabled and is only used by "raw" URLs 113 */ 114 function getIncludeBlogId() 115 { 116 return $this->_includeBlogId; 117 } 118 119 /** 120 * Returns the base URL that has been configured 121 * 122 * @param useSubdomains If set to true and subdomains are enabled, it will return the base URL as specified 123 * in the subdomains_base_url setting instead of base_url. It defaults to 'true' 124 */ 125 function getBaseUrl( $useSubdomains = true ) 126 { 127 if( $useSubdomains && $this->_subdomainsEnabled ) 128 return $this->_subdomainsBaseUrl; 129 else 130 return $this->_baseUrl; 131 } 132 133 /** 134 * @return Returns the name of the script to which for example forms will be submitted. Defaults to 135 * index.php but it can be changed via the script_name configuration parameter. 136 */ 137 function getScriptName() 138 { 139 return $this->_scriptName; 140 } 141 142 /** 143 * @return Returns the URL pointing to the main index file. This URL is built by querying the current 144 * base URL and then appending the value of the script_name configuration setting. 145 * 146 * @param useSubdomains If set to true and subdomains are enabled, it will use the base URL as specified 147 * in the subdomains_base_url setting instead of base_url. It defaults to 'true'. 148 */ 149 function getIndexUrl( $useSubdomains = true ) 150 { 151 152 $url = $this->getBaseUrl( $useSubdomains )."/".$this->getScriptName(); 153 154 return $url; 155 } 156 157 /** 158 * @return Returns the URL pointing to the admin.php file. This URL is built by querying the current 159 * base URL and then appending the value of the script_name configuration setting. 160 * 161 * @param useSubdomains If set to true and subdomains are enabled, it will use the base URL as specified 162 * in the subdomains_base_url setting instead of base_url. It defaults to 'true'. 163 */ 164 function getAdminUrl( $useSubdomains = true ) 165 { 166 $url = $this->getBaseUrl( $useSubdomains )."/admin.php"; 167 168 return $url; 169 } 170 171 /** 172 * @return Returns the URL pointing to the rss.php file. This URL is built by querying the current 173 * base URL and then appending the value of the script_name configuration setting. 174 * 175 * @param useSubdomains If set to true and subdomains are enabled, it will use the base URL as specified 176 * in the subdomains_base_url setting instead of base_url. It defaults to 'true'. 177 */ 178 function getRssUrl( $useSubdomains = false ) 179 { 180 $url = $this->getBaseUrl( $useSubdomains )."/rss.php"; 181 182 return $url; 183 } 184 185 /** 186 * @return Returns the URL pointing to the trackback.php file. This URL is built by querying the current 187 * base URL and then appending the value of the script_name configuration setting. 188 * 189 * @param useSubdomains If set to true and subdomains are enabled, it will use the base URL as specified 190 * in the subdomains_base_url setting instead of base_url. It defaults to 'true'. 191 */ 192 function getTrackbackUrl( $useSubdomains = false ) 193 { 194 $url = $this->getBaseUrl( $useSubdomains )."/trackback.php"; 195 196 return $url; 197 } 198 199 /** 200 * @return Returns the URL pointing to the resserver.php file. This URL is built by querying the current 201 * base URL and then appending the value of the script_name configuration setting. 202 * 203 * @param useSubdomains If set to true and subdomains are enabled, it will use the base URL as specified 204 * in the subdomains_base_url setting instead of base_url. It defaults to 'true'. 205 */ 206 function getResourceServerUrl( $useSubdomains = false ) 207 { 208 $url = $this->getBaseUrl( $useSubdomains )."/resserver.php"; 209 210 return $url; 211 } 212 213 /** 214 * Returns the base URL to resources 215 */ 216 function getResourcesBaseUrl() 217 { 218 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); 219 $config =& Config::getConfig(); 220 // the default value for this setting is to use a relative path that starts with './' so we have to make sure that 221 // that bit is not included in the URL (it wouldn't have any harmful effect, but it'd look ugly) 222 $galleryFolder = str_replace( "./", "/", $config->getValue( "resources_folder", DEFAULT_GALLERY_RESOURCES_FOLDER )); 223 // make sure that the base URL ends with a forward slash 224 if( $galleryFolder[strlen($galleryFolder)-1] != "/" ) 225 $galleryFolder .= "/"; 226 227 $url = $this->getBaseUrl().$galleryFolder; 228 229 return( $url ); 230 } 231 232 /** 233 * @return Returns the URL pointing to the given parameter. This URL is built by querying the current 234 * base URL and then appending the value of the $res parameter 235 * 236 * @param res A valid URL path 237 * @param useSubdomains If set to true and subdomains are enabled, it will use the base URL as specified 238 * in the subdomains_base_url setting instead of base_url. It defaults to 'true'. 239 */ 240 function getUrl( $res, $useSubdomains = false ) 241 { 242 $baseUrl = $this->getBaseUrl( $useSubdomains ); 243 $url = $baseUrl.$res; 244 245 return $url; 246 } 247 /** 248 * Adds a parameter to the request 249 * 250 * @param paramName Name of the parameter 251 * @param paramValue Value given to the parameter 252 */ 253 function addParameter( $paramName, $paramValue ) 254 { 255 $this->_params[$paramName] = $paramValue; 256 } 257 258 /** 259 * @private 260 */ 261 function reset() 262 { 263 $this->_params = Array(); 264 } 265 266 /** 267 * Returns a string representing the request. Child classes should implement this method in order 268 * to return a meaningful URL. 269 * 270 * @return A String object representing the request 271 */ 272 function getRequest() 273 { 274 throw( new Exception( "This function must be implemented by child classes." )); 275 } 276 277 /** 278 * Returns the permalink for a post. Must be implemented by child classes to generate a valid URL. 279 * 280 * @param post The Article object 281 * @return The link for the permalink 282 */ 283 function postPermalink( $post ) 284 { 285 throw( new Exception( "This function must be implemented by child classes." )); 286 } 287 288 /** 289 * Returns the comment link for a post. Must be implemented by child classes to generate a valid URL. 290 * 291 * @param post The Article object 292 * @return The correct string 293 */ 294 function postCommentLink( $post ) 295 { 296 throw( new Exception( "This function must be implemented by child classes." )); 297 } 298 299 /** 300 * Returns the link for the post. Must be implemented by child classes to generate a valid URL. 301 * 302 * @param post The Article object 303 * @return The link for the post 304 */ 305 function postLink( $post ) 306 { 307 throw( new Exception( "This function must be implemented by child classes." )); 308 } 309 310 /** 311 * Returns the link for the post. Must be implemented by child classes to generate a valid URL. 312 * 313 * @param post The Article object 314 * @return The link for the post 315 */ 316 function postRssLink( $post ) 317 { 318 throw( new Exception( "This function must be implemented by child classes." )); 319 } 320 321 /** 322 * Returns the url for the rss feed of a category 323 * 324 * @param category The ArticleCategory object with information about the category 325 * whose RSS feed we'd like to generate 326 * @þaram profile The profile we'd like to generate: RSS 0.90, RSS 1.0, RSS 2.0 327 * or XML. 328 * @param blogInfo A BlogInfo object containing information about the blog. 329 * @return The url pointing to the rss feed of the journal. 330 * @see BlogInfo 331 */ 332 function categoryRssLink( $category, $profile = "", $blogInfo = null ) 333 { 334 throw( new Exception( "This function must be implemented by child classes." )); 335 } 336 337 /** 338 * Returns the url for the rss feed of user posts. All URL generators use the same 339 * format for this for the time being, so we'll keep the method in this base class. 340 * 341 * @param category The UserInfo object with information about the category 342 * whose RSS feed we'd like to generate 343 * @þaram profile The profile we'd like to generate: RSS 0.90, RSS 1.0, RSS 2.0 344 * or XML. 345 * @return The url pointing to the rss feed of user 346 * @see BlogInfo 347 */ 348 function userRssLink( $userInfo, $profile = "" ) 349 { 350 $rssLink = $this->getRssUrl(); 351 $rssLink .= "?blogId=".$this->_blogInfo->getId(); 352 353 if( $profile != "" ) 354 $rssLink .= "&profile=$profile"; 355 356 $rssLink .= "&userId=".$userInfo->getId(); 357 return $rssLink; 358 } 359 360 /** 361 * Returns the link of a category. Must be implemented by child classes to generate a valid URL. 362 * This method has been deprecated as of pLog 1.0 so please use the method BaseRequestGenerator::categoryLink() 363 * which takes an ArticleCategory object instead of an Article object since this method does not support 364 * posts that have multiple categories. 365 * 366 * @param post The post from which we'll fetch the category and then generate the right link. 367 * @return The url pointing to the page with only the posts belonging to that category. 368 * @see Article 369 * @see categoryLink 370 * @deprecated 371 */ 372 function postCategoryLink( $post ) 373 { 374 throw( new Exception( "This function must be implemented by child classes." )); 375 } 376 377 /** 378 * Returns the link but given a category. Must be implemented by child classes to generate a valid URL. 379 * 380 * @see postCategoryLink 381 * @see ArticleCategory 382 * @param An ArticleCategory object containing the information regarding the category. 383 * @return A string with the correct url pointing to the page that will show only the posts that belong 384 * to the given category. 385 */ 386 function categoryLink( $category ) 387 { 388 throw( new Exception( "This function must be implemented by child classes." )); 389 } 390 391 /** 392 * Returns a link to only the articles of the user. Must be implemented by child classes to generate a valid URL. 393 * 394 * @param user The user whose posts we would like to see 395 * @param category Optionally, we can specify an ArticleCategory object 396 * @return A string containing the right url to only the posts of the user. 397 * @see UserInfo 398 * @see ArticleCategory 399 */ 400 function postUserLink( $user, $category = null ) 401 { 402 throw( new Exception( "This function must be implemented by child classes." )); 403 } 404 405 /** 406 * Returns the url of the host where the blog is running. Must be implemented by child classes to generate a valid URL. 407 * 408 * @return Returns the url where the blog is running. 409 */ 410 function blogLink( $blogInfo = null ) 411 { 412 throw( new Exception( "This function must be implemented by child classes." )); 413 } 414 415 /** 416 * Returns the url where the rss feed is running. Must be implemented by child classes to generate a valid URL. 417 * 418 * @param profile The profile whose link we'd like to return (rss090, rss10, rss20 or atom) 419 * @param blogInfo A BlogInfo object containing information about the blog. 420 * @return The url pointing to the rss feed of the journal. 421 * @see BlogInfo 422 */ 423 function rssLink( $profile = "", $blogInfo = null ) 424 { 425 throw( new Exception( "This function must be implemented by child classes." )); 426 } 427 428 /** 429 * Returns the url to reply to a given comment. Must be implemented by child classes to generate a valid URL. 430 * 431 * @param post An Article object with information about the post 432 * @param commen A UserComment object containing information about the post we'd like to reply to. 433 * @return The right url to reply to this comment. 434 * @see UserComment 435 * @see Article 436 */ 437 function replyCommentLink( $post, $comment ) 438 { 439 throw( new Exception( "This function must be implemented by child classes." )); 440 } 441 442 /** 443 * Manually adds the "show more" link in a post. Must be implemented by child classes to generate a valid URL. 444 * 445 * @param post The post we are going to cut. 446 * @param maxWords Amount of words we'd like to allow. 447 * @param linkText Text we are going to show. 448 * @return The modified link. 449 */ 450 function addShowMoreLink( $post, $maxWords, $linkText ) 451 { 452 throw( new Exception( "This function must be implemented by child classes." )); 453 } 454 455 /** 456 * Returns the trackback link for a given post. Must be implemented by child classes to generate a valid URL. 457 * 458 * @param post The post with the necessary information. 459 * @return A string representing the rdf trackback link. 460 */ 461 function postTrackbackLink( $post ) 462 { 463 $rdfHeader = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 464 xmlns:dc="http://purl.org/dc/elements/1.1/" 465 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'; 466 467 $trackbackLink = $this->getTrackbackUrl()."?id=".$post->getId(); 468 $postLink = $this->postLink($post); 469 $topic = str_replace('-', '\-', $post->getTopic()); 470 $rdfBody = "<rdf:Description 471 rdf:about=\"".$postLink."\" 472 dc:identifier=\"".$postLink."\" 473 dc:title=\"".$topic."\" 474 trackback:ping=\"".$trackbackLink."\"/>"; 475 $rdfFooter = "</rdf:RDF>"; 476 477 return $rdfHeader.$rdfBody.$rdfFooter; 478 } 479 480 /** 481 * generates an archive link given a date. Must be implemented by child classes to generate a valid URL. 482 * 483 * @param date A String in the format yyyymm 484 * @return A valid archive link 485 */ 486 function getArchiveLink( $date ) 487 { 488 throw( new Exception( "This function must be implemented by child classes." )); 489 } 490 491 492 /** 493 * Returns the link to the page showing the trackback statistics for a given post. Must be implemented by child classes to generate a valid URL. 494 * 495 * @param post The post with the information. 496 * @return Returns a string with the valid link. 497 */ 498 function postTrackbackStatsLink( $post ) 499 { 500 throw( new Exception( "This function must be implemented by child classes." )); 501 } 502 503 /** 504 * Returns the link to an album. If the parameter is null or zero, then a link to the top level 505 * album will be returned. Must be implemented by child classes to generate a valid URL. 506 * 507 * @param album The GalleryAlbum object. 508 */ 509 function albumLink( $album = null ) 510 { 511 throw( new Exception( "This function must be implemented by child classes." )); 512 } 513 514 /** 515 * Given an album, generates a link to its parent. Must be implemented by child classes to generate 516 * a valid URL. 517 * 518 * @param album The album 519 */ 520 function parentAlbumLink( $album ) 521 { 522 throw( new Exception( "This function must be implemented by child classes." )); 523 } 524 525 /** 526 * Given the name of a template file, generate the right link to it. Must be implemented by child 527 * classes to generate a valid URL. 528 * 529 * @param template 530 * @return A link to the given template file/static page 531 */ 532 function templatePage( $template ) 533 { 534 throw( new Exception( "This function must be implemented by child classes." )); 535 } 536 537 /** 538 * Returns the link to a resource. Must be implemented by child classes to generate a valid URL. 539 * 540 * @param album Generates the correct link to fetch a resource 541 */ 542 function resourceLink( $resource ) 543 { 544 throw( new Exception( "This function must be implemented by child classes." )); 545 } 546 547 /** 548 * Returns the link to a resource preview 549 * 550 * @param album Generates the correct link to fetch a resource preview 551 */ 552 function resourcePreviewLink( $resource ) 553 { 554 $blogId = ($resource->getOwnerId() ? $resource->getOwnerId() : $this->_blogInfo->getId()); 555 $resourceLink = $this->getResourcesBaseUrl().$blogId."/previews/".rawurlencode($resource->getPreviewFileName()); 556 return $resourceLink; 557 } 558 559 /** 560 * Returns the link to a resource preview 561 * 562 * @param album Generates the correct link to fetch a resource preview 563 */ 564 function resourceMediumSizePreviewLink( $resource ) 565 { 566 $blogId = ($resource->getOwnerId() ? $resource->getOwnerId() : $this->_blogInfo->getId()); 567 $resourceLink = $this->getResourcesBaseUrl().$blogId."/previews-med/".rawurlencode($resource->getMediumSizePreviewFileName()); 568 return $resourceLink; 569 } 570 571 /** 572 * Returns the link to a resource 573 * 574 * @param resource Generates the correct link to fetch a resource 575 */ 576 function resourceDownloadLink( $resource ) 577 { 578 $blogId = ($resource->getOwnerId() ? $resource->getOwnerId() : $this->_blogInfo->getId()); 579 $resourceLink = $this->getResourcesBaseUrl().$blogId."/".rawurlencode($resource->getOriginalSizeFileName()); 580 return $resourceLink; 581 } 582 583 /** 584 * Returns the link to a resource preview with raw file name, for TinyMCE use only 585 * 586 * @param album Generates the correct link to fetch a resource preview 587 */ 588 function rawResourcePreviewLink( $resource ) 589 { 590 $blogId = ($resource->getOwnerId() ? $resource->getOwnerId() : $this->_blogInfo->getId()); 591 $resourceLink = $this->getResourcesBaseUrl().$blogId."/previews/".$resource->getPreviewFileName(); 592 return $resourceLink; 593 } 594 595 /** 596 * Returns the link to a resource preview with raw file name, for TinyMCE use only 597 * 598 * @param album Generates the correct link to fetch a resource preview 599 */ 600 function rawResourceMediumSizePreviewLink( $resource ) 601 { 602 $blogId = ($resource->getOwnerId() ? $resource->getOwnerId() : $this->_blogInfo->getId()); 603 $resourceLink = $this->getResourcesBaseUrl().$blogId."/previews-med/".$resource->getMediumSizePreviewFileName(); 604 return $resourceLink; 605 } 606 607 /** 608 * Returns the link to a resource with raw file name, for TinyMCE use only 609 * 610 * @param resource Generates the correct link to fetch a resource 611 */ 612 function rawResourceDownloadLink( $resource ) 613 { 614 $blogId = ($resource->getOwnerId() ? $resource->getOwnerId() : $this->_blogInfo->getId()); 615 $resourceLink = $this->getResourcesBaseUrl().$blogId."/".$resource->getOriginalSizeFileName(); 616 return $resourceLink; 617 } 618 619 /** 620 * whether we should generate valid xhtml requests or not 621 * (used for example when sending out messages, as some email clients will 622 * go to the wrong url when using xhtml message 623 * 624 * @param enable Whether to enable xhtml or not (enabled by default) 625 * @return Always true 626 */ 627 function setXHTML( $enabled = true ) 628 { 629 $this->_xhtmlEnabled = $enabled; 630 } 631 632 /** 633 * whether xhtml mode is enabled or not 634 * 635 * @return True if enabled or false otherwise 636 */ 637 function isXHTML() 638 { 639 return $this->_xhtmlEnabled; 640 } 641 642 /** 643 * generates a unique atom id for the entry. This is not as easy 644 * as it sounds, take a look http://diveintomark.org/archives/2004/05/28/howto-atom-id 645 * 646 * @param article An Article object 647 * @return A unique atom article id 648 */ 649 function getAtomUniqueId( $article ) 650 { 651 lt_include( PLOG_CLASS_PATH."class/net/url.class.php" ); 652 $config =& Config::getConfig(); 653 $url = new Url($config->getValue( "base_url" )); 654 $articleDate = $article->getDateObject(); 655 656 // Timestamp::getDay() doesn't do two digits, so we'll do it here 657 $day = $articleDate->getDay(); 658 if( $day < 10 ) $day = "0".$day; 659 660 $date = $articleDate->getYear()."-".$articleDate->getMonth()."-".$day; 661 $tag = "tag:".$url->getHost().",".$date.":".$article->getId(); 662 663 return $tag; 664 } 665 666 /** 667 * get user profile picture link. It is not necessary for child classes to implement this method. 668 * 669 * @param blogInfo 670 */ 671 function profileLink($blogInfo = null) 672 { 673 if( $blogInfo == null ) { 674 $blogInfo = $this->_blogInfo; 675 } 676 677 $ownerInfo = $blogInfo->getOwnerInfo(); 678 $pic = $ownerInfo->getPicture(); 679 if(!$pic){ 680 // show a default user picture 681 return "imgs/no-user-picture.jpg"; 682 } else { 683 return $this->resourceLink($pic); 684 } 685 } 686 687 688 /** 689 * generates the correct path to a file in the template folder, without having to worry 690 * whether the template was installed in /templates/ or in /templates/blog_X/. It is not necessary 691 * for child classes to implement this method. 692 * 693 * @param file 694 * @return A string 695 */ 696 function getTemplateFile( $file ) 697 { 698 // get the current template set 699 $blogSettings = $this->_blogInfo->getSettings(); 700 $template = $blogSettings->getValue( "template" ); 701 702 // define this couple of things 703 $baseUrl = $this->getBaseUrl(); 704 $url = "$baseUrl/templates/"; 705 706 // is it a blog template? 707 $blogTemplates = $blogSettings->getValue( "blog_templates" ); 708 709 if( !is_array($blogTemplates )) 710 $url .= "$template/$file"; 711 else { 712 if( in_array( $template, $blogTemplates )) 713 $url .= "blog_".$this->_blogInfo->getId()."/$template/$file"; 714 else 715 $url .= "$template/$file"; 716 } 717 718 return $url; 719 } 720 721 /** 722 * generates the correct path to a file in the template folder, without having to worry 723 * whether the template was installed in /templates/ or in /templates/blog_X/ 724 * This is locale-aware version. 725 * 726 * @param file 727 * @return A string 728 */ 729 function getTemplateLocaledFile( $file ) 730 { 731 // get the current template set 732 $blogSettings = $this->_blogInfo->getSettings(); 733 $template = $blogSettings->getValue( "template" ); 734 $localeCode = $blogSettings->getValue( "locale" ); 735 736 // if this file has extension 737 $parts = explode( ".", $file ); 738 if( count($parts) > 1 && !strstr($parts[count($parts) - 1], "/")) { 739 $ext = array_pop( $parts ); 740 array_push ( $parts, $localeCode, $ext); 741 $localedFile = implode( ".", $parts); 742 } else { 743 $localedFile = $file; 744 } 745 unset($parts); 746 747 $baseUrl = $this->getBaseUrl(); 748 $url = "$baseUrl/templates/"; 749 750 $blogTemplates = $blogSettings->getValue( "blog_templates" ); 751 752 if( !is_array($blogTemplates) ) { 753 $filePath = "$template"; 754 } else { 755 if( in_array( $template, $blogTemplates )) 756 $filePath = "blog_".$this->_blogInfo->getId()."/$template"; 757 else 758 $filePath = "$template"; 759 } 760 761 if( File::exists("$filePath/$localedFile")) 762 $url .= "$filePath/$localedFile"; 763 else 764 $url .= "$filePath/$file"; 765 766 return $url; 767 } 768 769 /** 770 * given the parameters, recalculates the current URL. This method also has support 771 * for paged urls 772 * 773 * @param category 774 * @param userInfo 775 * @param date 776 * @param page 777 * @return the current url with its page 778 */ 779 function getCurrentUrl( $category = null, $userInfo = null, $date = null, $page = null ) 780 { 781 throw( new Exception( "This function must be implemented by child classes." )); 782 } 783 784 /** 785 * Returns the page format for this URL generator 786 * 787 * @return A page suffix 788 */ 789 function getPageSuffix( $page = "" ) 790 { 791 throw( new Exception( "This function must be implemented by child classes." )); 792 } 793 } 794 ?>
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 |
|