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