1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: cInclude('includes', 'functions.pathresolver.php');
19:
20: 21: 22: 23: 24: 25: 26: 27:
28: class cUriBuilderCustomPath extends cUriBuilder {
29:
30: 31: 32: 33:
34: static private $_instance;
35:
36: 37: 38: 39:
40: private $aConfig;
41:
42: 43: 44:
45: private function __construct() {
46: $this->sHttpBasePath = '';
47: }
48:
49: 50: 51: 52:
53: public static function getInstance() {
54: if (self::$_instance == NULL) {
55: self::$_instance = new self();
56: }
57: return self::$_instance;
58: }
59:
60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71:
72: public function buildUrl(array $aParams, $bUseAbsolutePath = false, array $aConfig = array()) {
73: if (!isset($aParams['idcat'])) {
74: throw new cInvalidArgumentException('$aParams[idcat] must be set!');
75: }
76: if (!isset($aParams['level'])) {
77:
78: $aParams['level'] = '1';
79: }
80: if (!isset($aParams['lang'])) {
81: throw new cInvalidArgumentException('$aParams[lang] must be set!');
82: }
83: if (sizeof($aParams) <= 3) {
84: throw new cInvalidArgumentException('$aParams must have at least one custom entry!');
85: }
86:
87: if (sizeof($aConfig) == 0 || !isset($aConfig['prefix']) || !isset($aConfig['suffix']) || !isset($aConfig['separator'])) {
88: include_once('class.uribuilder.config.php');
89: $aConfig = cUriBuilderConfig::getConfig();
90: }
91: $this->aConfig = $aConfig;
92:
93: $sCategoryString = '';
94: prCreateURLNameLocationString(intval($aParams['idcat']), "/", $sCategoryString, false, "", $aParams['level'], $aParams['lang'], true, false);
95: if (strlen($sCategoryString) > 0 && substr($sCategoryString, -1) != '/') {
96: $sCategoryString .= '/';
97: }
98: $this->sUrl = $bUseAbsolutePath === true ? $this->sHttpBasePath : '';
99: $this->sUrl .= $sCategoryString;
100: $this->sUrl .= $this->aConfig['prefix'];
101: foreach ($aParams as $sKey => $mVal) {
102: if ($sKey != 'idcat' && $sKey != 'lang' && $sKey != 'level') {
103: $sVal = $mVal;
104: if (is_array($mVal)) {
105: $sVal = implode($this->aConfig['separator'], $mVal);
106: }
107: $this->sUrl .= $this->aConfig['separator'] . strval($sKey) . $this->aConfig['separator'] . strval($sVal);
108: }
109: }
110: $this->sUrl .= $this->aConfig['suffix'];
111: }
112:
113: }
114: