Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cUri
  • cUriBuilder
  • cUriBuilderConfig
  • cUriBuilderCustom
  • cUriBuilderCustomPath
  • cUriBuilderFactory
  • cUriBuilderFrontcontent

Exceptions

  • NotInitializedException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the uri builder custom path class.
  5:  *
  6:  * @package    Core
  7:  * @subpackage Frontend_URI
  8:  * @author     Rudi Bieller
  9:  * @copyright  four for business AG <www.4fb.de>
 10:  * @license    http://www.contenido.org/license/LIZENZ.txt
 11:  * @link       http://www.4fb.de
 12:  * @link       http://www.contenido.org
 13:  */
 14: 
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: cInclude('includes', 'functions.pathresolver.php');
 18: 
 19: /**
 20:  * Custom path uri builder class.
 21:  *
 22:  * Implementation to build URL in style index-a-1.html
 23:  * with category path (/category/subcategory/index-a-1.html).
 24:  *
 25:  * @package    Core
 26:  * @subpackage Frontend_URI
 27:  */
 28: class cUriBuilderCustomPath extends cUriBuilder {
 29: 
 30:     /**
 31:      * Self instance
 32:      *
 33:      * @var  cUriBuilderCustomPath
 34:      */
 35:     static private $_instance;
 36: 
 37:     /**
 38:      * Configuration
 39:      *
 40:      * @var array
 41:      */
 42:     private $aConfig;
 43: 
 44:     /**
 45:      * Constructor to create an instance of this class.
 46:      */
 47:     private function __construct() {
 48:         $this->sHttpBasePath = '';
 49:     }
 50: 
 51:     /**
 52:      * Get instance of self.
 53:      *
 54:      * @return cUriBuilderCustomPath
 55:      */
 56:     public static function getInstance() {
 57:         if (self::$_instance == NULL) {
 58:             self::$_instance = new self();
 59:         }
 60:         return self::$_instance;
 61:     }
 62: 
 63:     /**
 64:      * Builds a URL in index-a-1.html style.
 65:      *
 66:      * Index keys of $aParams will be used as "a", corresponding values
 67:      * as "1" in this sample.
 68:      *
 69:      * For creating the location string $aParams needs to have keys
 70:      * idcat, level, lang and at least one custom key.
 71:      *
 72:      * If level is not set, level 0 will be used as default.
 73:      *
 74:      * @todo Somehow get around using prCreateURLNameLocationString()
 75:      *
 76:      * @param array $aParams
 77:      *                                Required keys are: idcat, level, lang and at least one
 78:      *                                custom key.
 79:      * @param bool  $bUseAbsolutePath [optional]
 80:      * @param array $aConfig          [optional]
 81:      *                                If not set, will use UriBuilderConfig::getConfig()
 82:      *
 83:      * @throws cException
 84:      * @throws cInvalidArgumentException
 85:      */
 86:     public function buildUrl(array $aParams, $bUseAbsolutePath = false, array $aConfig = array()) {
 87:         if (!isset($aParams['idcat'])) {
 88:             throw new cInvalidArgumentException('$aParams[idcat] must be set!');
 89:         }
 90:         if (!isset($aParams['level'])) {
 91:             //throw new cInvalidArgumentException('$aParams[level] must be set! Setting it to 0 will create complete path.');
 92:             $aParams['level'] = '1';
 93:         }
 94:         if (!isset($aParams['lang'])) {
 95:             throw new cInvalidArgumentException('$aParams[lang] must be set!');
 96:         }
 97:         if (sizeof($aParams) <= 3) {
 98:             throw new cInvalidArgumentException('$aParams must have at least one custom entry!');
 99:         }
100:         // if no config passed or not all parameters available, use default config
101:         if (sizeof($aConfig) == 0 || !isset($aConfig['prefix']) || !isset($aConfig['suffix']) || !isset($aConfig['separator'])) {
102:             include_once('class.uribuilder.config.php');
103:             $aConfig = cUriBuilderConfig::getConfig();
104:         }
105:         $this->aConfig = $aConfig;
106: 
107:         $sCategoryString = '';
108:         prCreateURLNameLocationString(intval($aParams['idcat']), "/", $sCategoryString, false, "", $aParams['level'], $aParams['lang'], true, false);
109:         if (cString::getStringLength($sCategoryString) > 0 && cString::getPartOfString($sCategoryString, -1) != '/') {
110:             $sCategoryString .= '/';
111:         }
112:         $this->sUrl = $bUseAbsolutePath === true ? $this->sHttpBasePath : '';
113:         $this->sUrl .= $sCategoryString;
114:         $this->sUrl .= $this->aConfig['prefix'];
115:         foreach ($aParams as $sKey => $mVal) {
116:             if ($sKey != 'idcat' && $sKey != 'lang' && $sKey != 'level') {
117:                 $sVal = $mVal; // assuming mVal is a string and thus a single value
118:                 if (is_array($mVal)) { // mVal has more than one value, e.g. index-b-1-2.html
119:                     $sVal = implode($this->aConfig['separator'], $mVal);
120:                 }
121:                 $this->sUrl .= $this->aConfig['separator'] . strval($sKey) . $this->aConfig['separator'] . strval($sVal);
122:             }
123:         }
124:         $this->sUrl .= $this->aConfig['suffix'];
125:     }
126: 
127: }
128: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0