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: 20: 21: 22: 23: 24: 25: 26:
27: class ModRewrite extends ModRewriteBase {
28:
29: 30: 31: 32: 33:
34: private static $_db;
35:
36: 37: 38: 39: 40:
41: protected static $_lookupTable;
42:
43: 44: 45: 46: 47: 48: 49: 50:
51: public static function initialize($clientId) {
52: mr_loadConfiguration($clientId, true);
53: self::$_db = cRegistry::getDb();
54: self::$_lookupTable = array();
55: }
56:
57: 58: 59: 60: 61: 62: 63: 64: 65: 66:
67: public static function isInCategories($sName = '', $iCatId = 0, $iLangId = 0) {
68: global $cfg;
69:
70: $sName = self::$_db->escape($sName);
71: $iCatId = (int) $iCatId;
72: $iLangId = (int) $iLangId;
73:
74:
75: $iParentId = 0;
76: $sql = "SELECT parentid FROM " . $cfg['tab']['cat'] . " WHERE idcat = " . $iCatId;
77: if ($aData = mr_queryAndNextRecord($sql)) {
78: $iParentId = ($aData['parentid'] > 0) ? (int) $aData['parentid'] : 0;
79: }
80:
81:
82: $sql = "SELECT count(cl.idcat) as numcats FROM " . $cfg['tab']['cat_lang'] . " cl "
83: . "LEFT JOIN " . $cfg['tab']['cat'] . " c ON cl.idcat = c.idcat WHERE "
84: . "c.parentid = '$iParentId' AND cl.idlang = " . $iLangId . " AND "
85: . "LOWER(cl.urlname) = LOWER('" . $sName . "') AND cl.idcat <> " . $iCatId;
86: ModRewriteDebugger::log($sql, 'ModRewrite::isInCategories $sql');
87:
88: if ($aData = mr_queryAndNextRecord($sql)) {
89: return ($aData['numcats'] > 0) ? true : false;
90: }
91:
92: return false;
93: }
94:
95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105:
106: public static function isInCatArticles($sName = '', $iArtId = 0, $iLangId = 0, $iCatId = 0) {
107: global $cfg;
108:
109: $sName = self::$_db->escape($sName);
110: $iArtId = (int) $iArtId;
111: $iLangId = (int) $iLangId;
112: $iCatId = (int) $iCatId;
113:
114:
115: if ($iCatId == 0) {
116:
117: $sql = "SELECT idcat FROM " . $cfg['tab']['cat_art'] . " WHERE idart = " . $iArtId;
118: if ($aData = mr_queryAndNextRecord($sql)) {
119: $iCatId = ($aData['idcat'] > 0) ? (int) $aData['idcat'] : 0;
120: }
121: }
122:
123:
124: $sql = "SELECT count(al.idart) as numcats FROM " . $cfg['tab']['art_lang'] . " al "
125: . "LEFT JOIN " . $cfg['tab']['cat_art'] . " ca ON al.idart = ca.idart WHERE "
126: . " ca.idcat='$iCatId' AND al.idlang=" . $iLangId . " AND "
127: . "LOWER(al.urlname) = LOWER('" . $sName . "') AND al.idart <> " . $iArtId;
128: if ($aData = mr_queryAndNextRecord($sql)) {
129: return ($aData['numcats'] > 0) ? true : false;
130: }
131:
132: return false;
133: }
134:
135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145:
146: public static function setArtWebsafeName($sName = '', $iArtId = 0, $iLangId = 0, $iCatId = 0) {
147: global $cfg;
148:
149: $iArtId = (int) $iArtId;
150: $iLangId = (int) $iLangId;
151: $iCatId = (int) $iCatId;
152:
153:
154: $sNewName = cString::cleanURLCharacters(conHtmlEntityDecode($sName));
155:
156:
157: $sNewName = mr_removeMultipleChars('-', $sNewName);
158:
159: $sNewName = self::$_db->escape($sNewName);
160:
161:
162: if (self::isInCatArticles($sNewName, $iArtId, $iLangId, $iCatId)) {
163:
164: $sNewName = $sNewName . $iArtId;
165: }
166:
167:
168: if (!self::isInCatArticles($sNewName, $iArtId, $iLangId, $iCatId)) {
169:
170: $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET urlname = '$sNewName' "
171: . "WHERE idart = " . $iArtId . " AND idlang = " . $iLangId;
172: return self::$_db->query($sql);
173: } else {
174: return false;
175: }
176: }
177:
178: 179: 180: 181: 182: 183: 184: 185: 186: 187:
188: public static function setCatWebsafeName($sName = '', $iCatId = 0, $iLangId = 0) {
189: global $cfg;
190:
191: $iCatId = (int) $iCatId;
192: $iLangId = (int) $iLangId;
193:
194:
195: $sNewName = cString::cleanURLCharacters(conHtmlEntityDecode($sName));
196:
197:
198: $sNewName = mr_removeMultipleChars('-', $sNewName);
199:
200: $sNewName = self::$_db->escape($sNewName);
201:
202:
203: if (self::isInCategories($sNewName, $iCatId, $iLangId)) {
204:
205: $sNewName = $sNewName . $iCatId;
206: }
207:
208:
209: if (!self::isInCategories($sNewName, $iCatId, $iLangId)) {
210:
211: $sql = "UPDATE " . $cfg['tab']['cat_lang'] . " SET urlname = '$sNewName' "
212: . "WHERE idcat = " . $iCatId . " AND idlang = " . $iLangId;
213:
214: ModRewriteDebugger::log(array(
215: 'sName' => $sName,
216: 'iCatId' => $iCatId,
217: 'iLangId' => $iLangId,
218: 'sNewName' => $sNewName
219: ), 'ModRewrite::setCatWebsafeName $data');
220:
221: return self::$_db->query($sql);
222: } else {
223: return false;
224: }
225: }
226:
227: 228: 229: 230: 231: 232: 233:
234: public static function setCatUrlPath($iCatId = 0, $iLangId = 0) {
235: global $cfg;
236:
237: $sPath = self::buildRecursivPath($iCatId, $iLangId);
238:
239: $iCatId = (int) $iCatId;
240: $iLangId = (int) $iLangId;
241:
242:
243: $sql = "UPDATE " . $cfg['tab']['cat_lang'] . " SET urlpath = '$sPath' "
244: . "WHERE idcat = " . $iCatId . " AND idlang = " . $iLangId;
245:
246: ModRewriteDebugger::log(array(
247: 'iCatId' => $iCatId,
248: 'iLangId' => $iLangId,
249: 'sPath' => $sPath
250: ), 'ModRewrite::setCatUrlPath $data');
251:
252: return self::$_db->query($sql);
253: }
254:
255: 256: 257: 258: 259: 260:
261: public static function getArtIdByArtlangId($iArtlangId = 0) {
262: global $cfg;
263:
264: $iArtlangId = (int) $iArtlangId;
265: $sql = "SELECT idart, idlang FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang = " . $iArtlangId;
266: if ($aData = mr_queryAndNextRecord($sql)) {
267: return $aData;
268: }
269: return array();
270: }
271:
272: 273: 274: 275: 276: 277: 278: 279:
280: public static function getArtIdByWebsafeName($sArtName = '', $iCatId = 0, $iLangId = 0) {
281: global $cfg, $lang;
282:
283: $sArtName = self::$_db->escape($sArtName);
284: $iCatId = (int) $iCatId;
285: $iLangId = (int) $iLangId;
286: if (0 === $iLangId && is_int($lang)) {
287: $iLangId = $lang;
288: }
289:
290: $sWhere = '';
291: if ($iLangId !== 0) {
292: $sWhere = ' AND al.idlang = ' . $iLangId;
293: }
294:
295: if ($iCatId == 0) {
296:
297: $aCatIds = array();
298: $sql = "SELECT idcat FROM " . $cfg['tab']['cat'] . " WHERE parentid = 0";
299: self::$_db->query($sql);
300: while (self::$_db->nextRecord()) {
301: $aCatIds[] = "idcat = " . (int) self::$_db->f('idcat');
302: }
303: $sWhere .= " AND (" . join(" OR ", $aCatIds) . ")";
304: } else {
305: $sWhere .= " AND ca.idcat = " . $iCatId;
306: }
307:
308: $sql = "SELECT al.idart FROM " . $cfg['tab']['art_lang'] . " al "
309: . "LEFT JOIN " . $cfg['tab']['cat_art'] . " ca ON al.idart = ca.idart "
310: . "WHERE LOWER(al.urlname) = LOWER('$sArtName')" . $sWhere;
311:
312: if ($aData = mr_queryAndNextRecord($sql)) {
313: return $aData['idart'];
314: } else {
315: return NULL;
316: }
317: }
318:
319: 320: 321: 322: 323: 324: 325:
326: public static function getCatName($iCatId = 0, $iLangId = 0) {
327: global $cfg;
328:
329: $iCatId = (int) $iCatId;
330: $iLangId = (int) $iLangId;
331: $key = 'catname_by_catid_idlang_' . $iCatId . '_' . $iLangId;
332:
333: if (isset(self::$_lookupTable[$key])) {
334: return self::$_lookupTable[$key];
335: }
336:
337: $sql = "SELECT name FROM " . $cfg['tab']['cat_lang'] . " WHERE idcat = " . $iCatId . " AND idlang = " . $iLangId;
338: if ($aData = mr_queryAndNextRecord($sql)) {
339: $catName = $aData['name'];
340: } else {
341: $catName = '';
342: }
343:
344: self::$_lookupTable[$key] = $catName;
345: return $catName;
346: }
347:
348: 349: 350: 351: 352: 353: 354: 355:
356: public static function getCatIdByUrlPath($path) {
357: global $cfg, $client, $lang;
358:
359: if (strpos($path, '/') === 0) {
360: $path = substr($path, 1);
361: }
362: if (strrpos($path, '/') === strlen($path) - 1) {
363: $path = substr($path, 0, -1);
364: }
365:
366: $catSeperator = '/';
367: $startFromRoot = parent::getConfig('startfromroot');
368: $urls2lowercase = parent::getConfig('use_lowercase_uri');
369:
370: $path = str_replace('/', parent::getConfig('category_seperator'), $path);
371:
372: $key = 'cat_ids_and_urlpath_' . $client . '_' . $lang;
373:
374: if (isset(self::$_lookupTable[$key])) {
375: $aPathsCache = self::$_lookupTable[$key];
376: } else {
377: $aPathsCache = array();
378: }
379:
380: if (count($aPathsCache) == 0) {
381: $sql = "SELECT cl.idcat, cl.urlpath FROM " . $cfg['tab']['cat_lang']
382: . " AS cl, " . $cfg['tab']['cat'] . " AS c WHERE c.idclient = " . $client
383: . " AND c.idcat = cl.idcat AND cl.idlang = " . $lang;
384:
385: self::$_db->query($sql);
386: while (self::$_db->nextRecord()) {
387: $urlPath = self::$_db->f('urlpath');
388: if ($startFromRoot == 0 && strpos($urlPath, $catSeperator) > 0) {
389:
390:
391: $urlPath = substr($urlPath, strpos($urlPath, $catSeperator) + 1);
392: }
393: if ($urls2lowercase) {
394: $urlPath = strtolower($urlPath);
395: }
396:
397:
398: $aPathsCache[self::$_db->f('idcat')] = $urlPath;
399: }
400: }
401: self::$_lookupTable[$key] = $aPathsCache;
402:
403:
404: $fPercent = 0;
405: $aResults = array();
406: foreach ($aPathsCache as $id => $pathItem) {
407: similar_text($path, $pathItem, $fPercent);
408: $aResults[$id] = $fPercent;
409: }
410:
411: arsort($aResults, SORT_NUMERIC);
412: reset($aResults);
413:
414: ModRewriteDebugger::add($path, 'ModRewrite::getCatIdByUrlPath() $path');
415: ModRewriteDebugger::add($aPathsCache, 'ModRewrite::getCatIdByUrlPath() $aPathsCache');
416: ModRewriteDebugger::add($aResults, 'ModRewrite::getCatIdByUrlPath() $aResults');
417:
418: $iMinPercentage = (int) parent::getConfig('category_resolve_min_percentage', 0);
419: $catId = key($aResults);
420: if ($iMinPercentage > 0 && $aResults[$catId] < $iMinPercentage) {
421: return 0;
422: } else {
423: return $catId;
424: }
425: }
426:
427: 428: 429: 430: 431: 432: 433: 434: 435:
436: public static function getArtTitle($iArtId = 0, $iLangId = 0) {
437: global $cfg;
438:
439: $iArtId = (int) $iArtId;
440: $iLangId = (int) $iLangId;
441:
442: $sql = "SELECT title FROM " . $cfg['tab']['art_lang'] . " WHERE "
443: . "idart = " . $iArtId . " AND idlang = " . $iLangId;
444: if ($aData = mr_queryAndNextRecord($sql)) {
445: return $aData['title'];
446: }
447: return '';
448: }
449:
450: 451: 452: 453: 454: 455:
456: public static function getCatLanguages($iCatId = 0) {
457: global $cfg;
458:
459: $iCatId = (int) $iCatId;
460: $key = 'cat_idlang_by_catid_' . $iCatId;
461:
462: if (isset(self::$_lookupTable[$key])) {
463: return self::$_lookupTable[$key];
464: }
465:
466: $aLanguages = array();
467:
468: $sql = "SELECT idlang FROM " . $cfg['tab']['cat_lang'] . " WHERE idcat = " . $iCatId;
469: self::$_db->query($sql);
470: while (self::$_db->nextRecord()) {
471: $aLanguages[] = self::$_db->f('idlang');
472: }
473:
474: self::$_lookupTable[$key] = $aLanguages;
475: return $aLanguages;
476: }
477:
478: 479: 480: 481: 482: 483:
484: public static function getArtIds($iArtlangId = 0) {
485: global $cfg;
486:
487: $iArtlangId = (int) $iArtlangId;
488: $sql = "SELECT urlname, idlang FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang = " . $iArtlangId;
489: if ($aData = mr_queryAndNextRecord($sql)) {
490: return $aData;
491: }
492: return array();
493: }
494:
495: 496: 497: 498: 499: 500: 501: 502: 503:
504: public static function buildRecursivPath($iCatId = 0, $iLangId = 0, $iLastId = 0) {
505: global $cfg;
506:
507: $aDirectories = array();
508: $bFinish = false;
509: $iTmpCatId = (int) $iCatId;
510: $iLangId = (int) $iLangId;
511: $iLastId = (int) $iLastId;
512:
513: while ($bFinish == false) {
514: $sql = "SELECT cl.urlname, c.parentid FROM " . $cfg['tab']['cat_lang'] . " cl "
515: . "LEFT JOIN " . $cfg['tab']['cat'] . " c ON cl.idcat = c.idcat "
516: . "WHERE cl.idcat = " . $iTmpCatId . " AND cl.idlang = " . $iLangId;
517: if ($aData = mr_queryAndNextRecord($sql)) {
518: $aDirectories[] = $aData['urlname'];
519: $iTmpCatId = (int) $aData['parentid'];
520:
521: if ($aData['parentid'] == 0 || $aData['parentid'] == $iLastId) {
522: $bFinish = true;
523: }
524: } else {
525: $bFinish = true;
526: }
527: }
528:
529:
530: $sPath = join('/', array_reverse($aDirectories));
531:
532: return $sPath;
533: }
534:
535: 536: 537: 538: 539: 540:
541: public static function rewriteHtmlAnchor(array $aMatches = array()) {
542: global $artname, $sess, $idart, $idcat, $client, $lang;
543:
544:
545: $sArtParam = '';
546: if (isset($artname) && strlen($artname) > 0) {
547: $sArtParam = '&idart=' . (int) $idart;
548: }
549:
550:
551: $aParamsToIgnore = array('idcat', 'idart', 'lang', 'client', 'idcatart', 'changelang', 'changeclient', 'idartlang', 'parts', 'artname');
552: $sOtherParams = '';
553:
554: if (isset($_GET) && count($_GET) > 0) {
555: foreach ($_GET as $key => $value) {
556: if (!in_array($key, $aParamsToIgnore) && strlen(trim($value)) > 0) {
557: $aNoAnchor = explode('#', $value);
558: $sOtherParams .= '&' . urlencode(urldecode($key)) . '=' . urlencode(urldecode($value));
559: }
560: }
561: }
562:
563: $url = $sess->url(
564: 'front_content.php?' . 'idcat=' . (int) $idcat . '&client=' . (int) $client .
565: '&changelang=' . (int) $lang . $sArtParam . $sOtherParams . '#' . $aMatches[2]
566: );
567:
568: $sNewUrl = '<a' . $aMatches[1] . 'href="' . $url . '"' . $aMatches[3] . '>';
569:
570: return $sNewUrl;
571: }
572:
573: 574: 575: 576: 577: 578: 579:
580: public static function contenidoHtmlAnchor(array $aMatches = array(), $bXHTML = true) {
581: global $sess;
582:
583: $aParams = array();
584: $sAmpersand = $bXHTML ? '&' : '&';
585:
586: foreach ($_GET as $key => $value) {
587: $aNoAnchor = explode('#', $value);
588: $aParams[] = urlencode(urldecode($key)) . '=' . urlencode(urldecode($aNoAnchor[0]));
589: }
590:
591: $url = $sess->url('front_content.php?' . implode($sAmpersand, $aParams) . '#' . $aMatches[2]);
592: $sNewUrl = '<a' . $aMatches[1] . 'href="' . $url . '"' . $aMatches[3] . '>';
593:
594: return $sNewUrl;
595: }
596:
597: 598: 599: 600: 601: 602: 603:
604: public static function getArtWebsafeName($iArtId = 0, $iLangId = 0) {
605: global $cfg;
606:
607: $iArtId = (int) $iArtId;
608: $iLangId = (int) $iLangId;
609: $sql = "SELECT urlname FROM " . $cfg['tab']['art_lang'] . " WHERE "
610: . "idart = " . $iArtId . " AND idlang = " . $iLangId;
611: if ($aData = mr_queryAndNextRecord($sql)) {
612: return $aData['urlname'];
613: }
614: return NULL;
615: }
616:
617: 618: 619: 620: 621: 622:
623: public static function getArtLangWebsafeName($iArtLangId = 0) {
624: global $cfg;
625:
626: $iArtLangId = (int) $iArtLangId;
627: $sql = "SELECT urlname FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang = " . $iArtLangId;
628: if ($aData = mr_queryAndNextRecord($sql)) {
629: return $aData['urlname'];
630: }
631: return NULL;
632: }
633:
634: 635: 636: 637: 638: 639:
640: public static function getClientName($clientId = 0) {
641: global $cfg;
642:
643: $clientId = (int) $clientId;
644: $key = 'clientname_by_clientid_' . $clientId;
645:
646: if (isset(self::$_lookupTable[$key])) {
647: return self::$_lookupTable[$key];
648: }
649:
650: $sql = "SELECT name FROM " . $cfg['tab']['clients'] . " WHERE idclient = " . $clientId;
651: if ($aData = mr_queryAndNextRecord($sql)) {
652: $clientName = $aData['name'];
653: } else {
654: $clientName = '';
655: }
656:
657: self::$_lookupTable[$key] = $clientName;
658: return $clientName;
659: }
660:
661: 662: 663: 664: 665: 666:
667: public static function getClientId($sClientName = '') {
668: global $cfg;
669:
670: $sClientName = strtolower(self::$_db->escape($sClientName));
671: $key = 'clientid_by_name_' . $sClientName;
672:
673: if (isset(self::$_lookupTable[$key])) {
674: return self::$_lookupTable[$key];
675: }
676:
677: $sql = "SELECT idclient FROM " . $cfg['tab']['clients'] . " WHERE LOWER(name) = '" . $sClientName . "' OR LOWER(name) = '" . urldecode($sClientName) . "'";
678:
679: if ($aData = mr_queryAndNextRecord($sql)) {
680: $clientId = $aData['idclient'];
681: } else {
682: $clientId = false;
683: }
684:
685: self::$_lookupTable[$key] = $clientId;
686: return $clientId;
687: }
688:
689: 690: 691: 692: 693: 694:
695: public static function clientIdExists($clientId) {
696: global $cfg;
697:
698: $clientId = (int) $clientId;
699: $key = 'clientid_exists_' . $clientId;
700:
701: if (isset(self::$_lookupTable[$key])) {
702: return self::$_lookupTable[$key];
703: }
704:
705: $sql = "SELECT idclient FROM " . $cfg['tab']['clients'] . " WHERE idclient = " . $clientId;
706: if ($aData = mr_queryAndNextRecord($sql)) {
707: $exists = true;
708: } else {
709: $exists = false;
710: }
711:
712: self::$_lookupTable[$key] = $exists;
713: return $exists;
714: }
715:
716: 717: 718: 719: 720: 721:
722: public static function getLanguageName($languageId = 0) {
723: global $cfg;
724:
725: $languageId = (int) $languageId;
726: $key = 'languagename_by_id_' . $languageId;
727:
728: if (isset(self::$_lookupTable[$key])) {
729: return self::$_lookupTable[$key];
730: }
731:
732: $sql = "SELECT name FROM " . $cfg['tab']['lang'] . " WHERE idlang = " . $languageId;
733: if ($aData = mr_queryAndNextRecord($sql)) {
734: $languageName = $aData['name'];
735: } else {
736: $languageName = '';
737: }
738:
739: self::$_lookupTable[$key] = $languageName;
740: return $languageName;
741: }
742:
743: 744: 745: 746: 747: 748:
749: public static function languageIdExists($languageId) {
750: global $cfg;
751:
752: $languageId = (int) $languageId;
753: $key = 'languageid_exists_' . $languageId;
754:
755: if (isset(self::$_lookupTable[$key])) {
756: return self::$_lookupTable[$key];
757: }
758:
759: $sql = "SELECT idlang FROM " . $cfg['tab']['lang'] . " WHERE idlang = " . $languageId;
760: if ($aData = mr_queryAndNextRecord($sql)) {
761: $exists = true;
762: } else {
763: $exists = false;
764: }
765:
766: self::$_lookupTable[$key] = $exists;
767: return $exists;
768: }
769:
770: 771: 772: 773: 774: 775: 776: 777:
778: public static function getLanguageId($sLanguageName = '', $iClientId = 1) {
779: global $cfg;
780:
781: $sLanguageName = strtolower(self::$_db->escape($sLanguageName));
782: $iClientId = (int) $iClientId;
783: $key = 'langid_by_langname_clientid_' . $sLanguageName . '_' . $iClientId;
784:
785: if (isset(self::$_lookupTable[$key])) {
786: return self::$_lookupTable[$key];
787: }
788:
789: $sql = "SELECT l.idlang FROM " . $cfg['tab']['lang'] . " as l "
790: . "LEFT JOIN " . $cfg['tab']['clients_lang'] . " AS cl ON l.idlang = cl.idlang "
791: . "WHERE cl.idclient = " . $iClientId . " AND (LOWER(l.name) = '" . $sLanguageName . "' "
792: . "OR LOWER(l.name) = '" . urldecode($sLanguageName) . "')";
793: if ($aData = mr_queryAndNextRecord($sql)) {
794: $languageId = $aData['idlang'];
795: } else {
796: $languageId = 0;
797: }
798:
799: self::$_lookupTable[$key] = $languageId;
800: return $languageId;
801: }
802:
803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813:
814: public static function getClientFullUrlParts($url) {
815: $clientPath = cRegistry::getFrontendUrl();
816:
817: if (stristr($url, $clientPath) !== false) {
818:
819: $url = str_replace($clientPath, '', $url);
820: $htmlPath = $clientPath;
821: $aComp = parse_url($htmlPath);
822:
823:
824: if (isset($aComp['path']) && $aComp['path'] !== parent::getConfig('rootdir')) {
825:
826:
827: $htmlPath = str_replace($aComp['path'], parent::getConfig('rootdir'), $htmlPath);
828: if (substr($htmlPath, strlen($htmlPath) - 1) == '/') {
829:
830: $htmlPath = substr($htmlPath, 0, strlen($htmlPath) - 1);
831: }
832: }
833: } else {
834: $htmlPath = '';
835: }
836: return array('htmlpath' => $htmlPath, 'url' => $url);
837: }
838:
839: 840: 841: 842: 843: 844: 845: 846: 847: 848:
849: public static function urlPreClean($url) {
850:
851: if (strpos($url, './front_content.php') === 0) {
852: $url = str_replace('./front_content.php', 'front_content.php', $url);
853: } elseif (strpos($url, '/front_content.php') === 0) {
854: $url = str_replace('/front_content.php', 'front_content.php', $url);
855: }
856: $url = str_replace('&', '&', $url);
857: return $url;
858: }
859:
860: 861: 862: 863: 864:
865: public static function recreateCategoriesAliases($bOnlyEmpty = false) {
866: global $cfg;
867:
868: $db = cRegistry::getDb();
869:
870: $aCats = array();
871:
872:
873: $sql = "SELECT name, idcat, idlang FROM " . $cfg['tab']['cat_lang'];
874: if ($bOnlyEmpty === true) {
875: $sql .= " WHERE urlname IS NULL OR urlname = '' OR urlpath IS NULL OR urlpath = ''";
876: }
877:
878: $db->query($sql);
879: while ($db->nextRecord()) {
880:
881: self::setCatWebsafeName($db->f('name'), $db->f('idcat'), $db->f('idlang'));
882: $aCats[] = array('idcat' => $db->f('idcat'), 'idlang' => $db->f('idlang'));
883: }
884:
885: foreach ($aCats as $p => $item) {
886: self::setCatUrlPath($item['idcat'], $item['idlang']);
887: }
888:
889: unset($db, $aCats);
890: }
891:
892: 893: 894: 895: 896: 897:
898: public static function getEmptyCategoriesAliases($bOnlyNumber = true) {
899: global $cfg;
900:
901: $db = cRegistry::getDb();
902: $return = ($bOnlyNumber) ? 0 : array();
903:
904:
905: $sql = "SELECT name, idcat, idlang FROM " . $cfg['tab']['cat_lang'];
906: $sql .= " WHERE urlname IS NULL OR urlname = '' OR urlpath IS NULL OR urlpath = ''";
907:
908: $db->query($sql);
909:
910: if ($bOnlyNumber) {
911: $return = (int) $db->numRows();
912: } else {
913: while ($db->nextRecord()) {
914: $return[] = array($db->f('name'), $db->f('idcat'), $db->f('idlang'));
915: }
916: }
917:
918: unset($db);
919: return $return;
920: }
921:
922: 923: 924: 925: 926:
927: public static function recreateArticlesAliases($bOnlyEmpty = false) {
928: global $cfg;
929:
930: $db = cRegistry::getDb();
931:
932:
933: $sql = "SELECT title, idart, idlang FROM " . $cfg['tab']['art_lang'];
934: if ($bOnlyEmpty === true) {
935: $sql .= " WHERE urlname IS NULL OR urlname = ''";
936: }
937: $db->query($sql);
938:
939: while ($db->nextRecord()) {
940:
941: self::setArtWebsafeName($db->f('title'), $db->f('idart'), $db->f('idlang'));
942: }
943:
944: unset($db);
945: }
946:
947: 948: 949: 950: 951: 952:
953: public static function getEmptyArticlesAliases($bOnlyNumber = true) {
954: global $cfg;
955:
956: $db = cRegistry::getDb();
957: $return = ($bOnlyNumber) ? 0 : array();
958:
959:
960: $sql = "SELECT title, idart, idlang FROM " . $cfg['tab']['art_lang'];
961: $sql .= " WHERE urlname IS NULL OR urlname = ''";
962:
963: $db->query($sql);
964: if ($bOnlyNumber) {
965: $return = (int) $db->numRows();
966: } else {
967: while ($db->nextRecord()) {
968: $return[] = array($db->f('title'), $db->f('idart'), $db->f('idlang'));
969: }
970: }
971:
972: unset($db);
973: return $return;
974: }
975:
976: 977: 978: 979: 980:
981: public static function resetAliases() {
982: self::recreateCategoriesAliases();
983: self::recreateArticlesAliases();
984: }
985:
986: 987: 988: 989: 990: 991: 992:
993: public static function recreateAliases($bOnlyEmpty = false) {
994: self::recreateCategoriesAliases($bOnlyEmpty);
995: self::recreateArticlesAliases($bOnlyEmpty);
996: }
997:
998: 999: 1000: 1001: 1002:
1003: public static function getHtaccessInfo() {
1004:
1005: $arr = array(
1006: 'contenido_full_path' => str_replace('\\', '/', realpath(cRegistry::getBackendPath() . '../') . '/'),
1007: 'client_full_path' => cRegistry::getFrontendPath(),
1008: );
1009: $arr['in_contenido_path'] = is_file($arr['contenido_full_path'] . '.htaccess');
1010: $arr['in_client_path'] = is_file($arr['client_full_path'] . '.htaccess');
1011: $arr['has_htaccess'] = ($arr['in_contenido_path'] || $arr['in_client_path']);
1012:
1013: return $arr;
1014: }
1015:
1016: }
1017: