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: public function fetchFullStructure($idclient = NULL, $idlang = NULL) {
97: global $client, $lang;
98:
99: $db = cRegistry::getDb();
100: $db2 = cRegistry::getDb();
101:
102: if (!$idclient || (int) $idclient == 0) {
103: $idclient = $client;
104: }
105: if (!$idlang || (int) $idlang == 0) {
106: $idlang = $lang;
107: }
108:
109: $aTab = $this->_aCfgTab;
110:
111: $aStruct = array();
112:
113: $sql = "SELECT
114: *
115: FROM
116: " . $aTab['cat_tree'] . " AS a,
117: " . $aTab['cat_lang'] . " AS b,
118: " . $aTab['cat'] . " AS c
119: WHERE
120: a.idcat = b.idcat AND
121: c.idcat = a.idcat AND
122: c.idclient = '" . $idclient . "' AND
123: b.idlang = '" . $idlang . "'
124: ORDER BY
125: a.idtree";
126:
127: $db->query($sql);
128:
129: $counter = 0;
130:
131: while ($db->nextRecord()) {
132:
133: if (++$counter == $this->_iMaxItems) {
134: break;
135: }
136:
137: $idcat = $db->f('idcat');
138: $aStruct[$idcat] = $db->getRecord();
139: $aStruct[$idcat]['articles'] = array();
140:
141: $sql2 = "SELECT
142: *
143: FROM
144: " . $aTab['cat_art'] . " AS a,
145: " . $aTab['art'] . " AS b,
146: " . $aTab['art_lang'] . " AS c
147: WHERE
148: a.idcat = '" . $idcat . "' AND
149: b.idart = a.idart AND
150: c.idart = a.idart AND
151: c.idlang = '" . $idlang . "' AND
152: b.idclient = '" . $idclient . "'
153: ORDER BY
154: c.title ASC";
155:
156: $db2->query($sql2);
157:
158: while ($db2->nextRecord()) {
159: $idart = $db2->f('idart');
160: $aStruct[$idcat]['articles'][$idart] = $db2->getRecord();
161: if (++$counter == $this->_iMaxItems) {
162: break 2;
163: }
164: }
165: }
166:
167: return $aStruct;
168: }
169:
170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184:
185: public function composeURL($arr, $type) {
186: $type = ($type == 'a') ? 'a' : 'c';
187:
188: $param = array();
189:
190: if ($type == 'c') {
191: $param[] = 'idcat=' . $arr['idcat'];
192: } else {
193: if (mr_getRequest('idart')) {
194: $param[] = 'idart=' . $arr['idart'];
195: }
196: if (mr_getRequest('idcat')) {
197: $param[] = 'idcat=' . $arr['idcat'];
198: }
199: if (mr_getRequest('idcatart')) {
200: $param[] = 'idcatart=' . $arr['idcatart'];
201: }
202: if (mr_getRequest('idartlang')) {
203: $param[] = 'idartlang=' . $arr['idartlang'];
204: }
205: }
206: $param[] = 'foo=bar';
207: return 'front_content.php?' . implode('&', $param);
208: }
209:
210: 211: 212: 213: 214: 215: 216:
217: public function resolveUrl($url) {
218:
219: $aGlobs = array(
220: 'mr_preprocessedPageError', 'idart', 'idcat'
221: );
222: foreach ($aGlobs as $p => $k) {
223: if (isset($GLOBALS[$k])) {
224: unset($GLOBALS[$k]);
225: }
226: }
227:
228: $aReturn = array();
229:
230:
231: $oMRController = new ModRewriteController($url);
232: $oMRController->execute();
233:
234: if ($oMRController->errorOccured()) {
235:
236:
237: $aReturn['mr_preprocessedPageError'] = 1;
238: $aReturn['error'] = $oMRController->getError();
239:
240: $this->_sResolvedUrl = '';
241: $this->_bRoutingFound = false;
242: } else {
243:
244:
245:
246: $this->_sResolvedUrl = $oMRController->getResolvedUrl();
247: $this->_bRoutingFound = $oMRController->getRoutingFoundState();
248:
249: if ($oMRController->getClient()) {
250: $aReturn['client'] = $oMRController->getClient();
251: }
252:
253: if ($oMRController->getChangeClient()) {
254: $aReturn['changeclient'] = $oMRController->getChangeClient();
255: }
256:
257: if ($oMRController->getLang()) {
258: $aReturn['lang'] = $oMRController->getLang();
259: }
260:
261: if ($oMRController->getChangeLang()) {
262: $aReturn['changelang'] = $oMRController->getChangeLang();
263: }
264:
265: if ($oMRController->getIdArt()) {
266: $aReturn['idart'] = $oMRController->getIdArt();
267: }
268:
269: if ($oMRController->getIdCat()) {
270: $aReturn['idcat'] = $oMRController->getIdCat();
271: }
272:
273: if ($oMRController->getPath()) {
274: $aReturn['path'] = $oMRController->getPath();
275: }
276: }
277:
278: return $aReturn;
279: }
280:
281: 282: 283: 284: 285: 286:
287: public function getReadableResolvedData(array $data) {
288:
289: $ret = '';
290: foreach ($data as $k => $v) {
291: $ret .= $k . '=' . $v . '; ';
292: }
293: $ret = substr($ret, 0, strlen($ret) - 2);
294: return $ret;
295: }
296:
297: }
298: