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