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