1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22: 23:
24: class ModRewriteTest {
25:
26: 27: 28: 29:
30: protected $_aCfg;
31:
32: 33: 34: 35:
36: protected $_aCfgTab;
37:
38: 39: 40: 41:
42: protected $_iMaxItems;
43:
44: 45: 46: 47:
48: protected $_sResolvedUrl;
49:
50: 51: 52: 53:
54: protected $_bRoutingFound = false;
55:
56: 57: 58: 59:
60: public function __construct($maxItems) {
61: global $cfg;
62: $this->_aCfg = & $cfg;
63: $this->_aCfgTab = & $cfg['tab'];
64: $this->_iMaxItems = $maxItems;
65: }
66:
67: 68: 69: 70: 71:
72: public function getResolvedUrl() {
73: return $this->_sResolvedUrl;
74: }
75:
76: 77: 78: 79: 80:
81: public function getRoutingFoundState() {
82: return $this->_bRoutingFound;
83: }
84:
85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97:
98: public function fetchFullStructure($idclient = NULL, $idlang = NULL) {
99: global $client, $lang;
100:
101: $db = cRegistry::getDb();
102: $db2 = cRegistry::getDb();
103:
104: if (!$idclient || (int) $idclient == 0) {
105: $idclient = $client;
106: }
107: if (!$idlang || (int) $idlang == 0) {
108: $idlang = $lang;
109: }
110:
111: $aTab = $this->_aCfgTab;
112:
113: $aStruct = array();
114:
115: $sql = "SELECT
116: *
117: FROM
118: " . $aTab['cat_tree'] . " AS a,
119: " . $aTab['cat_lang'] . " AS b,
120: " . $aTab['cat'] . " AS c
121: WHERE
122: a.idcat = b.idcat AND
123: c.idcat = a.idcat AND
124: c.idclient = '" . $idclient . "' AND
125: b.idlang = '" . $idlang . "'
126: ORDER BY
127: a.idtree";
128:
129: $db->query($sql);
130:
131: $counter = 0;
132:
133: while ($db->nextRecord()) {
134:
135: if (++$counter == $this->_iMaxItems) {
136: break;
137: }
138:
139: $idcat = $db->f('idcat');
140: $aStruct[$idcat] = $db->getRecord();
141: $aStruct[$idcat]['articles'] = array();
142:
143: $sql2 = "SELECT
144: *
145: FROM
146: " . $aTab['cat_art'] . " AS a,
147: " . $aTab['art'] . " AS b,
148: " . $aTab['art_lang'] . " AS c
149: WHERE
150: a.idcat = '" . $idcat . "' AND
151: b.idart = a.idart AND
152: c.idart = a.idart AND
153: c.idlang = '" . $idlang . "' AND
154: b.idclient = '" . $idclient . "'
155: ORDER BY
156: c.title ASC";
157:
158: $db2->query($sql2);
159:
160: while ($db2->nextRecord()) {
161: $idart = $db2->f('idart');
162: $aStruct[$idcat]['articles'][$idart] = $db2->getRecord();
163: if (++$counter == $this->_iMaxItems) {
164: break 2;
165: }
166: }
167: }
168:
169: return $aStruct;
170: }
171:
172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188:
189: public function composeURL($arr, $type) {
190: $type = ($type == 'a') ? 'a' : 'c';
191:
192: $param = array();
193:
194: if ($type == 'c') {
195: $param[] = 'idcat=' . $arr['idcat'];
196: } else {
197: if (mr_getRequest('idart')) {
198: $param[] = 'idart=' . $arr['idart'];
199: }
200: if (mr_getRequest('idcat')) {
201: $param[] = 'idcat=' . $arr['idcat'];
202: }
203: if (mr_getRequest('idcatart')) {
204: $param[] = 'idcatart=' . $arr['idcatart'];
205: }
206: if (mr_getRequest('idartlang')) {
207: $param[] = 'idartlang=' . $arr['idartlang'];
208: }
209: }
210: $param[] = 'foo=bar';
211: return 'front_content.php?' . implode('&', $param);
212: }
213:
214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224:
225: public function resolveUrl($url) {
226:
227: $aGlobs = array(
228: 'mr_preprocessedPageError', 'idart', 'idcat'
229: );
230: foreach ($aGlobs as $p => $k) {
231: if (isset($GLOBALS[$k])) {
232: unset($GLOBALS[$k]);
233: }
234: }
235:
236: $aReturn = array();
237:
238:
239: $oMRController = new ModRewriteController($url);
240: $oMRController->execute();
241:
242: if ($oMRController->errorOccured()) {
243:
244:
245: $aReturn['mr_preprocessedPageError'] = 1;
246: $aReturn['error'] = $oMRController->getError();
247:
248: $this->_sResolvedUrl = '';
249: $this->_bRoutingFound = false;
250: } else {
251:
252:
253:
254: $this->_sResolvedUrl = $oMRController->getResolvedUrl();
255: $this->_bRoutingFound = $oMRController->getRoutingFoundState();
256:
257: if ($oMRController->getClient()) {
258: $aReturn['client'] = $oMRController->getClient();
259: }
260:
261: if ($oMRController->getChangeClient()) {
262: $aReturn['changeclient'] = $oMRController->getChangeClient();
263: }
264:
265: if ($oMRController->getLang()) {
266: $aReturn['lang'] = $oMRController->getLang();
267: }
268:
269: if ($oMRController->getChangeLang()) {
270: $aReturn['changelang'] = $oMRController->getChangeLang();
271: }
272:
273: if ($oMRController->getIdArt()) {
274: $aReturn['idart'] = $oMRController->getIdArt();
275: }
276:
277: if ($oMRController->getIdCat()) {
278: $aReturn['idcat'] = $oMRController->getIdCat();
279: }
280:
281: if ($oMRController->getPath()) {
282: $aReturn['path'] = $oMRController->getPath();
283: }
284: }
285:
286: return $aReturn;
287: }
288:
289: 290: 291: 292: 293: 294:
295: public function getReadableResolvedData(array $data) {
296:
297: $ret = '';
298: foreach ($data as $k => $v) {
299: $ret .= $k . '=' . $v . '; ';
300: }
301: $ret = cString::getPartOfString($ret, 0, cString::getStringLength($ret) - 2);
302: return $ret;
303: }
304:
305: }
306: