1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: 17: 18: 19: 20: 21: 22: 23:
24: class cFrontendHelper {
25:
26: 27: 28: 29: 30:
31: private static $_instance = NULL;
32:
33: 34: 35: 36: 37: 38: 39:
40: public static function getInstance() {
41: cDeprecated("The cFrontendHelper getInstance method are no longer supported.");
42:
43: if (self::$_instance === NULL) {
44: self::$_instance = new self();
45: }
46:
47: return self::$_instance;
48: }
49:
50: 51: 52: 53: 54: 55:
56: protected function __construct() {
57: cDeprecated("The cFrontendHelper classes are no longer supported.");
58: }
59:
60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75:
76: protected function _fetchCategoryTree($baseCategoryId, $depth, $currentCategoryId) {
77: cDeprecated("The cFrontendHelper _fetchCategoryTree method are no longer supported.");
78:
79: if ((int) $baseCategoryId == 0) {
80: throw new cUnexpectedValueException("Expect category ID greater than 0.");
81: }
82:
83: $categoryHelper = cCategoryHelper::getInstance();
84: $categoryHelper->setAuth(cRegistry::getAuth());
85:
86: $categoryTree = $categoryHelper->getSubCategories($baseCategoryId, $depth);
87:
88: $tree = array();
89:
90: $parentCategories = $categoryHelper->getParentCategoryIds($currentCategoryId);
91:
92: foreach ($categoryTree as $treeData) {
93: $catId = $treeData['idcat'];
94:
95: $firstChildId = $lastChildId = 0;
96: if (count($treeData['subcats']) > 0) {
97: $lastIndex = count($treeData['subcats']) - 1;
98:
99: $firstChildId = $treeData['subcats'][0]['idcat'];
100: $lastChildId = $treeData['subcats'][$lastIndex]['idcat'];
101: }
102:
103: $markActive = ($currentCategoryId == $catId);
104: if ($markActive == false && in_array($catId, $parentCategories)) {
105: $markActive = true;
106: }
107:
108: $treeItem['first_child_id'] = $firstChildId;
109: $treeItem['last_child_id'] = $lastChildId;
110: $treeItem['tree_data'] = $treeData;
111: $treeItem['active'] = $markActive;
112: $tree[] = $treeItem;
113: }
114:
115: return $tree;
116: }
117:
118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131:
132: public function renderNavigation($baseCategoryId, $depth, $currentCategoryId) {
133: cDeprecated("The cFrontendHelper renderNavigation method are no longer supported.");
134:
135: $tree = $this->_fetchCategoryTree($baseCategoryId, $depth, $currentCategoryId);
136:
137: return $tree;
138: }
139:
140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151:
152: public function renderSitemap($baseCategoryId, $depth, cTemplate &$tpl) {
153: cDeprecated("The cFrontendHelper renderSitemap method are no longer supported.");
154:
155: $tree = $this->_fetchCategoryTree($baseCategoryId, $depth, 0);
156:
157: foreach ($tree as $treeItem) {
158: $treeData = $treeItem['tree_data'];
159: $catId = $treeData['idcat'];
160:
161: $firstChildId = $treeItem['first_child_id'];
162:
163: $tpl->set('d', 'name', $treeData['item']->getField('name'));
164: $tpl->set('d', 'css_level', $treeData['level']);
165: $tpl->set('d', 'url', $treeData['item']->getLink());
166: $tpl->next();
167:
168: if ($firstChildId != 0) {
169: $this->renderSitemap($catId, $depth, $tpl);
170: }
171: }
172: }
173: }