Completed
Push — master ( 9db278...c5f771 )
by
unknown
02:28
created
assets/snippets/DocLister/core/controller/site_content_menu.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
             }
70 70
             if ($ids) {
71 71
                 $tv = $this->extTV->getTVList($ids, $tvlist);
72
-                if (!is_array($tv)) {
72
+                if ( ! is_array($tv)) {
73 73
                     $tv = array();
74 74
                 }
75 75
                 $this->docTvs = $tv;
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
         if ($this->getCFGDef('showParent', 0) && in_array(0, $this->IDs)) {
111 111
             $this->config->setConfig(array('showParent' => 0));
112 112
         }
113
-        $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0);
113
+        $joinMenus = $this->getCFGDef('joinMenus', 0) && ! $this->getCFGDef('showParent', 0);
114 114
         while ($currentLevel <= $maxDepth) {
115 115
             $orderBy = $this->getCFGDef('orderBy');
116 116
             if ($this->getCFGDef('showParent', 0) && $currentLevel == 1) {
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
             } else {
138 138
                 foreach ($docs as $id => &$item) {
139 139
                     $parent = $item['parent'];
140
-                    if (!isset($this->display[$parent])) {
140
+                    if ( ! isset($this->display[$parent])) {
141 141
                         $this->display[$parent] = 1;
142 142
                     }
143 143
                     $item['iteration'] = $this->display[$parent]++;
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
         $at = array_flip($a);
213 213
         $d = array();
214 214
         foreach ($b as $i) {
215
-            if (!isset($at[$i])) {
215
+            if ( ! isset($at[$i])) {
216 216
                 $d[] = $i;
217 217
             }
218 218
         }
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
                         $data = $out;
264 264
                     }
265 265
                 };
266
-                if (!isset($data['maxLevel'])) {
266
+                if ( ! isset($data['maxLevel'])) {
267 267
                     $data['maxLevel'] = 1;
268 268
                     $docs[$currentLevel - 1][$data['parent']]['maxLevel'] = 0;
269 269
                 }
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                     $data['wrap'] = $this->parseOuter($data);
284 284
                 }
285 285
                 $hideSubMenus = $this->getCFGDef('hideSubMenus', 0);
286
-                $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'],
286
+                $hideSubMenus = ! $hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'],
287 287
                             $this->activeBranch));
288 288
                 if ($hideSubMenus) {
289 289
                     $docs[$currentLevel - 1][$data['parent']]['wrap'][] = $data;
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
         }
295 295
         unset($data);
296 296
         $out = '';
297
-        $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0);
297
+        $joinMenus = $this->getCFGDef('joinMenus', 0) && ! $this->getCFGDef('showParent', 0);
298 298
         foreach ($docs[0] as $id => $data) {
299 299
             if (isset($data['wrap'])) {
300 300
                 if ($joinMenus) {
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
         if ($id == $this->getHereId()) {
331 331
             $data['here'] = 1;
332 332
         }
333
-        if (!isset($data['here']) && in_array($id, $this->activeBranch)) {
333
+        if ( ! isset($data['here']) && in_array($id, $this->activeBranch)) {
334 334
             $data['active'] = 1;
335 335
         }
336 336
         if ($this->getCFGDef('hideSubMenus') && isset($data['isfolder']) && $data['isfolder']) {
337 337
             $data['state'] = in_array($data['id'], $this->activeBranch) ? 'open' : 'closed';
338 338
         }
339 339
 
340
-        if (!isset($data['_display'])) {
340
+        if ( ! isset($data['_display'])) {
341 341
             $data['_display'] = $this->display[$data['parent']] - 1;
342 342
         }
343 343
         if ($data['iteration'] == 1) {
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
         }
349 349
 
350 350
         $titleField = $this->getCFGDef('titleField', 'title');
351
-        $data[$titleField] = isset($data['menutitle']) && !empty($data['menutitle']) ? $data['menutitle'] : $data['pagetitle'];
351
+        $data[$titleField] = isset($data['menutitle']) && ! empty($data['menutitle']) ? $data['menutitle'] : $data['pagetitle'];
352 352
         $data['level'] = $this->currentLevel;
353 353
         $data['url'] = $this->makeUrl($data);
354 354
         if ($this->getCFGDef('countChildren', 0)) {
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
      */
434 434
     public function getHereId()
435 435
     {
436
-        if (!$hereId = (int)$this->getCFGDef('hereId')) {
436
+        if ( ! $hereId = (int)$this->getCFGDef('hereId')) {
437 437
             $hereId = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0;
438 438
         }
439 439
 
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
         if (isset($data['type']) && $data['type'] == 'reference') {
487 487
             $classes['webLinkClass'] = $this->getCFGDef('webLinkClass');
488 488
         }
489
-        if (!empty($data['wrap'])) {
489
+        if ( ! empty($data['wrap'])) {
490 490
             $classes['parentClass'] = $this->getCFGDef('parentClass');
491 491
         }
492 492
         $classNames = implode(' ', array_filter(array_values($classes)));
@@ -504,10 +504,10 @@  discard block
 block discarded – undo
504 504
     protected function getRowTemplate($data = array())
505 505
     {
506 506
         $tpl = $this->getCFGDef('rowTpl', '@CODE:<li[+classes+]><a href="[+url+]">[+title+]</a></li>');
507
-        if (!empty($data['wrap'])) {
507
+        if ( ! empty($data['wrap'])) {
508 508
             $tpl = $this->getCFGDef('parentRowTpl',
509 509
                 '@CODE:<li[+classes+]><a href="[+url+]">[+title+]</a>[+wrap+]</li>');
510
-            if ((isset($data['template']) && !$data['template']) || (isset($data['link_attributes']) && strpos($data['link_attributes'],
510
+            if ((isset($data['template']) && ! $data['template']) || (isset($data['link_attributes']) && strpos($data['link_attributes'],
511 511
                         'category') !== false)
512 512
             ) {
513 513
                 $tpl = $this->getCFGDef('categoryFolderTpl', $tpl);
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
                 }
571 571
 
572 572
                 $hideSubMenus = $this->getCFGDef('hideSubMenus', 0);
573
-                $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'],
573
+                $hideSubMenus = ! $hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'],
574 574
                             $this->activeBranch));
575 575
                 if ($hideSubMenus) {
576 576
                     $docs[$currentLevel - 1][$data['parent']]['children'][] = $data;
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
         }
582 582
         unset($data);
583 583
         $out = array();
584
-        $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0);
584
+        $joinMenus = $this->getCFGDef('joinMenus', 0) && ! $this->getCFGDef('showParent', 0);
585 585
         foreach ($docs[0] as $id => $data) {
586 586
             if (isset($data['children'])) {
587 587
                 if ($joinMenus) {
Please login to merge, or discard this patch.
Braces   +138 added lines, -135 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
  * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
10 10
  * @author Agel_Nash <[email protected]>, kabachello <[email protected]>
11 11
  */
12
-class site_content_menuDocLister extends site_contentDocLister
13
-{
12
+class site_content_menuDocLister extends site_contentDocLister
13
+{
14 14
     public $levels = array();
15 15
     protected $currentLevel = 1;
16 16
     protected $docTvs = array();
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
      * @param mixed $IDs список id документов по которым необходима выборка
26 26
      * @return array очищенный массив
27 27
      */
28
-    public function setIDs($IDs)
29
-    {
28
+    public function setIDs($IDs)
29
+    {
30 30
         $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2);
31 31
         $IDs = $this->cleanIDs($IDs);
32 32
         $this->debug->debugEnd("setIDs");
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
      * @param string $tvlist
39 39
      * @return array
40 40
      */
41
-    public function getDocs($tvlist = '')
42
-    {
41
+    public function getDocs($tvlist = '')
42
+    {
43 43
         $this->extTV->getAllTV_Name();
44
-        if ($ids = $this->getCFGDef('documents')) {
44
+        if ($ids = $this->getCFGDef('documents')) {
45 45
             $this->setIDs($ids);
46 46
             $docs = $this->getDocList();
47 47
             $dispay = count($docs);
48 48
             $iteration = 1;
49
-            foreach ($docs as $id => &$item) {
49
+            foreach ($docs as $id => &$item) {
50 50
                 $item['iteration'] = $iteration++;
51 51
                 $item['_display'] = $display;
52 52
                 $item['_parent'] = $item['parent'];
@@ -54,52 +54,53 @@  discard block
 block discarded – undo
54 54
             }
55 55
             $this->levels[1] = $docs;
56 56
             $this->setActiveBranch($this->getHereId(), 1);
57
-        } else {
57
+        } else {
58 58
             $this->_getChildren();
59 59
         }
60 60
 
61
-        if ($tvlist == '') {
61
+        if ($tvlist == '') {
62 62
             $tvlist = $this->getCFGDef('tvList', '');
63 63
         }
64 64
 
65
-        if ($tvlist != '') {
65
+        if ($tvlist != '') {
66 66
             $ids = array();
67
-            foreach ($this->levels as $level => $docs) {
67
+            foreach ($this->levels as $level => $docs) {
68 68
                 $ids = array_merge($ids, array_keys($docs));
69 69
             }
70
-            if ($ids) {
70
+            if ($ids) {
71 71
                 $tv = $this->extTV->getTVList($ids, $tvlist);
72
-                if (!is_array($tv)) {
72
+                if (!is_array($tv)) {
73 73
                     $tv = array();
74 74
                 }
75 75
                 $this->docTvs = $tv;
76 76
             }
77 77
 
78 78
         }
79
-        if ($this->getCFGDef('countChildren', 0)) {
79
+        if ($this->getCFGDef('countChildren', 0)) {
80 80
             $this->countChildren();
81 81
         }
82 82
         //TODO кэширование
83 83
         return $this->levels;
84 84
     }
85 85
 
86
-    public function _getChildren() {
86
+    public function _getChildren()
87
+    {
87 88
         $maxDepth = $this->getCFGDef('maxDepth', 10);
88
-        if ($this->getCFGDef('hideSubMenus', 0) && empty($this->getCFGDef('openIds'))) {
89
+        if ($this->getCFGDef('hideSubMenus', 0) && empty($this->getCFGDef('openIds'))) {
89 90
             $maxDepth = min($maxDepth, $this->setActiveBranch($this->getHereId()));
90
-            if (empty(array_intersect($this->IDs, $this->activeBranch))) {
91
+            if (empty(array_intersect($this->IDs, $this->activeBranch))) {
91 92
                 $maxDepth = 1;
92 93
                 $this->config->setConfig(array('hideSubMenus' => 0));
93 94
             };
94
-        } else {
95
+        } else {
95 96
             $this->setActiveBranch($this->getHereId());
96 97
         }
97
-        if ($oIds = $this->getCFGDef('openIds')) {
98
+        if ($oIds = $this->getCFGDef('openIds')) {
98 99
             $maxDepth = 1;
99 100
             $oIds = $this->cleanIDs($oIds);
100 101
             $oIds[] = $this->getHereId();
101
-            foreach ($oIds as $id) {
102
-                if (($c = $this->setActiveBranch($id)) > $maxDepth) {
102
+            foreach ($oIds as $id) {
103
+                if (($c = $this->setActiveBranch($id)) > $maxDepth) {
103 104
                     $maxDepth = $c;
104 105
                 }
105 106
             }
@@ -107,44 +108,44 @@  discard block
 block discarded – undo
107 108
         }
108 109
         $currentLevel = &$this->currentLevel;
109 110
         $currentLevel = 1;
110
-        if ($this->getCFGDef('showParent', 0) && in_array(0, $this->IDs)) {
111
+        if ($this->getCFGDef('showParent', 0) && in_array(0, $this->IDs)) {
111 112
             $this->config->setConfig(array('showParent' => 0));
112 113
         }
113 114
         $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0);
114
-        while ($currentLevel <= $maxDepth) {
115
+        while ($currentLevel <= $maxDepth) {
115 116
             $orderBy = $this->getCFGDef('orderBy');
116
-            if ($this->getCFGDef('showParent', 0) && $currentLevel == 1) {
117
+            if ($this->getCFGDef('showParent', 0) && $currentLevel == 1) {
117 118
                 $docs = $this->getDocList();
118 119
                 $this->config->setConfig(array('showParent' => 0));
119
-            } else {
120
+            } else {
120 121
                 $docs = $this->getChildrenList();
121 122
             }
122
-            if ($currentLevel == 1 && $joinMenus) {
123
+            if ($currentLevel == 1 && $joinMenus) {
123 124
                 $tmp = array();
124 125
                 $display = 0;
125 126
                 $iteration = 1;
126
-                foreach ($docs as $id => $item) {
127
+                foreach ($docs as $id => $item) {
127 128
                     $tmp[$item['parent']][] = $item['id'];
128 129
                     $display++;
129 130
                 }
130
-                foreach ($tmp as $id => $item) {
131
-                    foreach ($item as $_id) {
131
+                foreach ($tmp as $id => $item) {
132
+                    foreach ($item as $_id) {
132 133
                         $docs[$_id]['_display'] = $display;
133 134
                         $docs[$_id]['iteration'] = $iteration++;
134 135
                     }
135 136
                 }
136 137
                 unset($tmp);
137
-            } else {
138
-                foreach ($docs as $id => &$item) {
138
+            } else {
139
+                foreach ($docs as $id => &$item) {
139 140
                     $parent = $item['parent'];
140
-                    if (!isset($this->display[$parent])) {
141
+                    if (!isset($this->display[$parent])) {
141 142
                         $this->display[$parent] = 1;
142 143
                     }
143 144
                     $item['iteration'] = $this->display[$parent]++;
144 145
                 }
145 146
             }
146 147
             $this->config->setConfig(array('orderBy' => $orderBy));
147
-            if (empty($docs)) {
148
+            if (empty($docs)) {
148 149
                 break;
149 150
             }
150 151
             $this->levels[$currentLevel++] = $docs;
@@ -158,8 +159,8 @@  discard block
 block discarded – undo
158 159
      * @param $id
159 160
      * @param int $maxDepth
160 161
      */
161
-    public function setActiveBranch($id, $maxDepth = 10)
162
-    {
162
+    public function setActiveBranch($id, $maxDepth = 10)
163
+    {
163 164
         $ids = array_values($this->modx->getParentIds($id, $maxDepth));
164 165
         $ids[] = $id;
165 166
         $ids[] = 0;
@@ -172,29 +173,29 @@  discard block
 block discarded – undo
172 173
     /**
173 174
      * Подсчет количества непосредственных дочерних документов
174 175
      */
175
-    public function countChildren()
176
-    {
176
+    public function countChildren()
177
+    {
177 178
         $ids = array();
178 179
         $out = &$this->countChildren;
179
-        foreach ($this->levels as $level => $docs) {
180
+        foreach ($this->levels as $level => $docs) {
180 181
             $ids = array_merge($ids, array_keys($docs));
181 182
         }
182 183
         $maxDepth = count($this->levels);
183 184
         $currentDepth = 1;
184
-        while ($currentDepth <= $maxDepth) {
185
+        while ($currentDepth <= $maxDepth) {
185 186
             $_ids = implode(',', $ids);
186
-            if (empty($_ids)) {
187
+            if (empty($_ids)) {
187 188
                 break;
188 189
             }
189 190
             $q = $this->dbQuery("SELECT `parent`,COUNT(*) as `count` FROM {$this->getTable('site_content')} WHERE `parent` IN ({$_ids}) AND `published`=1 AND `deleted`=0 GROUP BY `parent`");
190 191
             $_ids = array();
191
-            while ($row = $this->modx->db->getRow($q)) {
192
+            while ($row = $this->modx->db->getRow($q)) {
192 193
                 $_ids[] = $row['parent'];
193 194
                 $out[$row['parent']] = $row['count'];
194 195
             }
195
-            if ($_ids) {
196
+            if ($_ids) {
196 197
                 $ids = $this->diff($ids, $_ids);
197
-            } else {
198
+            } else {
198 199
                 break;
199 200
             }
200 201
             $currentDepth++;
@@ -207,12 +208,12 @@  discard block
 block discarded – undo
207 208
      * @param $a
208 209
      * @return array
209 210
      */
210
-    private function diff($b, $a)
211
-    {
211
+    private function diff($b, $a)
212
+    {
212 213
         $at = array_flip($a);
213 214
         $d = array();
214
-        foreach ($b as $i) {
215
-            if (!isset($at[$i])) {
215
+        foreach ($b as $i) {
216
+            if (!isset($at[$i])) {
216 217
                 $d[] = $i;
217 218
             }
218 219
         }
@@ -227,17 +228,17 @@  discard block
 block discarded – undo
227 228
      * @param string $tpl шаблон
228 229
      * @return string
229 230
      */
230
-    public function render($tpl = '')
231
-    {
231
+    public function render($tpl = '')
232
+    {
232 233
         $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html'));
233
-        if (empty($this->levels)) {
234
+        if (empty($this->levels)) {
234 235
             $noneTpl = $this->getCFGDef('noneTpl');
235 236
             $out = $noneTpl ? $this->parseChunk($noneTpl) : '';
236
-        } else {
237
+        } else {
237 238
             $out = $this->_render($tpl);
238 239
         }
239 240
 
240
-        if ($out) {
241
+        if ($out) {
241 242
             $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out);
242 243
         }
243 244
         $this->debug->debugEnd('render');
@@ -249,43 +250,43 @@  discard block
 block discarded – undo
249 250
      * @param string $tpl
250 251
      * @return string
251 252
      */
252
-    public function _render($tpl = '')
253
-    {
253
+    public function _render($tpl = '')
254
+    {
254 255
         $currentLevel = &$this->currentLevel;
255 256
         $currentLevel = count($this->levels);
256 257
         $docs = $this->levels;
257 258
         /** @var prepare_DL_Extender_ $extPrepare */
258 259
         $extPrepare = $this->getExtender('prepare');
259
-        while ($currentLevel > 0) {
260
-            foreach ($docs[$currentLevel] as $id => &$data) {
261
-                if ($out = $this->prepareData($data)) {
262
-                    if (is_array($out)) {
260
+        while ($currentLevel > 0) {
261
+            foreach ($docs[$currentLevel] as $id => &$data) {
262
+                if ($out = $this->prepareData($data)) {
263
+                    if (is_array($out)) {
263 264
                         $data = $out;
264 265
                     }
265 266
                 };
266
-                if (!isset($data['maxLevel'])) {
267
+                if (!isset($data['maxLevel'])) {
267 268
                     $data['maxLevel'] = 1;
268 269
                     $docs[$currentLevel - 1][$data['parent']]['maxLevel'] = 0;
269 270
                 }
270 271
 
271
-                if ($extPrepare) {
272
+                if ($extPrepare) {
272 273
                     $data = $extPrepare->init($this, array(
273 274
                         'data'      => $data,
274 275
                         'nameParam' => 'prepare'
275 276
                     ));
276
-                    if (is_bool($data) && $data === false) {
277
+                    if (is_bool($data) && $data === false) {
277 278
                         continue;
278 279
                     }
279 280
                 }
280 281
 
281
-                if (isset($data['wrap'])) {
282
+                if (isset($data['wrap'])) {
282 283
                     $data['wrap'] = is_array($data['wrap']) ? $this->parseRow($data['wrap']) : $data['wrap'];
283 284
                     $data['wrap'] = $this->parseOuter($data);
284 285
                 }
285 286
                 $hideSubMenus = $this->getCFGDef('hideSubMenus', 0);
286 287
                 $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'],
287 288
                             $this->activeBranch));
288
-                if ($hideSubMenus) {
289
+                if ($hideSubMenus) {
289 290
                     $docs[$currentLevel - 1][$data['parent']]['wrap'][] = $data;
290 291
                 }
291 292
             }
@@ -295,17 +296,17 @@  discard block
 block discarded – undo
295 296
         unset($data);
296 297
         $out = '';
297 298
         $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0);
298
-        foreach ($docs[0] as $id => $data) {
299
-            if (isset($data['wrap'])) {
300
-                if ($joinMenus) {
299
+        foreach ($docs[0] as $id => $data) {
300
+            if (isset($data['wrap'])) {
301
+                if ($joinMenus) {
301 302
                     $out .= $this->parseRow($data['wrap']);
302
-                } else {
303
+                } else {
303 304
                     $data['wrap'] = $this->parseRow($data['wrap']);
304 305
                     $out .= $this->parseOuter($data);
305 306
                 }
306 307
             }
307 308
         }
308
-        if ($joinMenus) {
309
+        if ($joinMenus) {
309 310
             $out = $this->parseOuter(array('wrap' => $out));
310 311
         }
311 312
 
@@ -317,33 +318,33 @@  discard block
 block discarded – undo
317 318
      * @param $data
318 319
      * @return array
319 320
      */
320
-    public function prepareData($data)
321
-    {
321
+    public function prepareData($data)
322
+    {
322 323
         /**
323 324
          * @var e_DL_Extender $extE
324 325
          */
325 326
         $extE = $this->getExtender('e', true, true);
326 327
         $id = $data['id'];
327
-        if (isset($this->docTvs[$id])) {
328
+        if (isset($this->docTvs[$id])) {
328 329
             $data = array_merge($data, $this->docTvs[$id]);
329 330
         }
330
-        if ($id == $this->getHereId()) {
331
+        if ($id == $this->getHereId()) {
331 332
             $data['here'] = 1;
332 333
         }
333
-        if (!isset($data['here']) && in_array($id, $this->activeBranch)) {
334
+        if (!isset($data['here']) && in_array($id, $this->activeBranch)) {
334 335
             $data['active'] = 1;
335 336
         }
336
-        if ($this->getCFGDef('hideSubMenus') && isset($data['isfolder']) && $data['isfolder']) {
337
+        if ($this->getCFGDef('hideSubMenus') && isset($data['isfolder']) && $data['isfolder']) {
337 338
             $data['state'] = in_array($data['id'], $this->activeBranch) ? 'open' : 'closed';
338 339
         }
339 340
 
340
-        if (!isset($data['_display'])) {
341
+        if (!isset($data['_display'])) {
341 342
             $data['_display'] = $this->display[$data['parent']] - 1;
342 343
         }
343
-        if ($data['iteration'] == 1) {
344
+        if ($data['iteration'] == 1) {
344 345
             $data['first'] = 1;
345 346
         }
346
-        if ($data['iteration'] == $data['_display']) {
347
+        if ($data['iteration'] == $data['_display']) {
347 348
             $data['last'] = 1;
348 349
         }
349 350
 
@@ -351,12 +352,12 @@  discard block
 block discarded – undo
351 352
         $data[$titleField] = isset($data['menutitle']) && !empty($data['menutitle']) ? $data['menutitle'] : $data['pagetitle'];
352 353
         $data['level'] = $this->currentLevel;
353 354
         $data['url'] = $this->makeUrl($data);
354
-        if ($this->getCFGDef('countChildren', 0)) {
355
+        if ($this->getCFGDef('countChildren', 0)) {
355 356
             $data['count'] = isset($this->countChildren[$data['id']]) ? $this->countChildren[$data['id']] : 0;
356 357
         }
357 358
 
358
-        if ($out = $extE->init($this, compact('data'))) {
359
-            if (is_array($out)) {
359
+        if ($out = $extE->init($this, compact('data'))) {
360
+            if (is_array($out)) {
360 361
                 $data = $out;
361 362
             }
362 363
         }
@@ -369,16 +370,16 @@  discard block
 block discarded – undo
369 370
      * @param array $data
370 371
      * @return string
371 372
      */
372
-    public function parseOuter($data = array())
373
-    {
373
+    public function parseOuter($data = array())
374
+    {
374 375
         $tpl = $this->getCFGDef('outerTpl', '@CODE:<ul[+classes+]>[+wrap+]</ul>');
375 376
         $classes = '';
376 377
         $classNames = $this->getCFGDef('outerClass');
377
-        if ($this->currentLevel >= 1) {
378
+        if ($this->currentLevel >= 1) {
378 379
             $tpl = $this->getCFGDef('innerTpl', $tpl);
379 380
             $classNames = $this->getCFGDef('innerClass');
380 381
         }
381
-        if ($classNames) {
382
+        if ($classNames) {
382 383
             $classes = " class=\"{$classNames}\"";
383 384
         }
384 385
         $tpl = isset($data['_renderOuterTpl']) ? $data['_renderOuterTpl'] : $tpl;
@@ -394,10 +395,10 @@  discard block
 block discarded – undo
394 395
      * @param array $data
395 396
      * @return string
396 397
      */
397
-    public function parseRow($data = array())
398
-    {
398
+    public function parseRow($data = array())
399
+    {
399 400
         $out = '';
400
-        foreach ($data as $iteration => $item) {
401
+        foreach ($data as $iteration => $item) {
401 402
             $tpl = isset($item['_renderRowTpl']) ? $item['_renderRowTpl'] : $this->getRowTemplate($item);
402 403
             $item = array_merge($item, $this->getClasses($item));
403 404
             $out .= $this->parseChunk($tpl, $item);
@@ -411,14 +412,14 @@  discard block
 block discarded – undo
411 412
      * @param array $data
412 413
      * @return string
413 414
      */
414
-    protected function makeUrl($data = array())
415
-    {
415
+    protected function makeUrl($data = array())
416
+    {
416 417
         $out = '';
417
-        if ($this->getCFGDef('makeUrl', 1)) {
418
-            if (isset($data['type']) && $data['type'] == 'reference' && isset($data['content'])) {
418
+        if ($this->getCFGDef('makeUrl', 1)) {
419
+            if (isset($data['type']) && $data['type'] == 'reference' && isset($data['content'])) {
419 420
                 $out = is_numeric($data['content']) ? $this->modx->makeUrl($data['content'], '', '',
420 421
                     $this->getCFGDef('urlScheme', '')) : $data['content'];
421
-            } else {
422
+            } else {
422 423
                 $out = isset($data['id']) && is_numeric($data['id']) ? $this->modx->makeUrl($data['id'], '', '',
423 424
                     $this->getCFGDef('urlScheme', '')) : '';
424 425
             }
@@ -431,9 +432,9 @@  discard block
 block discarded – undo
431 432
      * Вовзращает id текущего документа
432 433
      * @return int
433 434
      */
434
-    public function getHereId()
435
-    {
436
-        if (!$hereId = (int)$this->getCFGDef('hereId')) {
435
+    public function getHereId()
436
+    {
437
+        if (!$hereId = (int)$this->getCFGDef('hereId')) {
437 438
             $hereId = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0;
438 439
         }
439 440
 
@@ -445,8 +446,8 @@  discard block
 block discarded – undo
445 446
      * @param array $data
446 447
      * @return array
447 448
      */
448
-    protected function getClasses($data = array())
449
-    {
449
+    protected function getClasses($data = array())
450
+    {
450 451
         $classes = isset($data['classes']) ? $data['classes'] : array(
451 452
             'rowClass'     => '',
452 453
             'firstClass'   => '',
@@ -459,34 +460,34 @@  discard block
 block discarded – undo
459 460
             'oddClass'     => '',
460 461
             'evenClass'    => ''
461 462
         );
462
-        if (isset($data['state'])) {
463
+        if (isset($data['state'])) {
463 464
             $classes['stateClass'] = $this->getCFGDef($data['state'] . 'Class', $data['state']);
464 465
         }
465
-        if (isset($data['here'])) {
466
+        if (isset($data['here'])) {
466 467
             $classes['hereClass'] = $this->getCFGDef('hereClass', 'current');
467 468
         }
468
-        if (isset($data['active'])) {
469
+        if (isset($data['active'])) {
469 470
             $classes['activeClass'] = $this->getCFGDef('activeClass', 'active');
470 471
         }
471 472
         $classes['rowClass'] = $this->getCFGDef('rowClass');
472
-        if ($data['iteration'] % 2 == 1) {
473
+        if ($data['iteration'] % 2 == 1) {
473 474
             $classes['oddClass'] = $this->getCFGDef('oddClass', 'odd');
474
-        } else {
475
+        } else {
475 476
             $classes['evenClass'] = $this->getCFGDef('evenClass', 'even');
476 477
         }
477
-        if (isset($data['first'])) {
478
+        if (isset($data['first'])) {
478 479
             $classes['firstClass'] = $this->getCFGDef('firstClass', 'first');
479 480
         }
480
-        if (isset($data['last'])) {
481
+        if (isset($data['last'])) {
481 482
             $classes['lastClass'] = $this->getCFGDef('lastClass', 'last');
482 483
         }
483
-        if ($levelClass = $this->getCFGDef('levelClass', 'level')) {
484
+        if ($levelClass = $this->getCFGDef('levelClass', 'level')) {
484 485
             $classes['levelClass'] = $levelClass . $data['level'];
485 486
         }
486
-        if (isset($data['type']) && $data['type'] == 'reference') {
487
+        if (isset($data['type']) && $data['type'] == 'reference') {
487 488
             $classes['webLinkClass'] = $this->getCFGDef('webLinkClass');
488 489
         }
489
-        if (!empty($data['wrap'])) {
490
+        if (!empty($data['wrap'])) {
490 491
             $classes['parentClass'] = $this->getCFGDef('parentClass');
491 492
         }
492 493
         $classNames = implode(' ', array_filter(array_values($classes)));
@@ -501,28 +502,28 @@  discard block
 block discarded – undo
501 502
      * @param array $data
502 503
      * @return string
503 504
      */
504
-    protected function getRowTemplate($data = array())
505
-    {
505
+    protected function getRowTemplate($data = array())
506
+    {
506 507
         $tpl = $this->getCFGDef('rowTpl', '@CODE:<li[+classes+]><a href="[+url+]">[+title+]</a></li>');
507
-        if (!empty($data['wrap'])) {
508
+        if (!empty($data['wrap'])) {
508 509
             $tpl = $this->getCFGDef('parentRowTpl',
509 510
                 '@CODE:<li[+classes+]><a href="[+url+]">[+title+]</a>[+wrap+]</li>');
510 511
             if ((isset($data['template']) && !$data['template']) || (isset($data['link_attributes']) && strpos($data['link_attributes'],
511 512
                         'category') !== false)
512
-            ) {
513
+            ) {
513 514
                 $tpl = $this->getCFGDef('categoryFolderTpl', $tpl);
514
-            } elseif (isset($data['here'])) {
515
+            } elseif (isset($data['here'])) {
515 516
                 $tpl = $this->getCFGDef('parentRowHereTpl', $tpl);
516
-            } elseif (isset($data['active'])) {
517
+            } elseif (isset($data['active'])) {
517 518
                 $tpl = $this->getCFGDef('parentRowActiveTpl', $tpl);
518 519
             }
519
-        } elseif ($data['level'] > 1) {
520
+        } elseif ($data['level'] > 1) {
520 521
             $tpl = $this->getCFGDef('innerRowTpl', $tpl);
521
-            if (isset($data['here'])) {
522
+            if (isset($data['here'])) {
522 523
                 $tpl = $this->getCFGDef('innerRowHereTpl', $tpl);
523 524
             }
524
-        } else {
525
-            if (isset($data['here'])) {
525
+        } else {
526
+            if (isset($data['here'])) {
526 527
                 $tpl = $this->getCFGDef('rowHereTpl', $tpl);
527 528
             }
528 529
         }
@@ -536,35 +537,37 @@  discard block
 block discarded – undo
536 537
      * @param array $array
537 538
      * @return string
538 539
      */
539
-    public function getJSON($data, $fields, $array = array())
540
-    {
540
+    public function getJSON($data, $fields, $array = array())
541
+    {
541 542
         $currentLevel = &$this->currentLevel;
542 543
         $currentLevel = count($this->levels);
543 544
         $docs = $this->levels;
544 545
 
545
-        if (empty($docs)) return '[]';
546
+        if (empty($docs)) {
547
+            return '[]';
548
+        }
546 549
 
547 550
         /** @var prepare_DL_Extender_ $extPrepare */
548 551
         $extPrepare = $this->getExtender('prepare');
549 552
 
550
-        while ($currentLevel > 0) {
551
-            foreach ($docs[$currentLevel] as $id => &$data) {
552
-                if ($out = $this->prepareData($data)) {
553
-                    if (is_array($out)) {
553
+        while ($currentLevel > 0) {
554
+            foreach ($docs[$currentLevel] as $id => &$data) {
555
+                if ($out = $this->prepareData($data)) {
556
+                    if (is_array($out)) {
554 557
                         $data = $out;
555 558
                     }
556 559
                 };
557 560
 
558
-                if (isset($data['here']) || isset($data['active'])) {
561
+                if (isset($data['here']) || isset($data['active'])) {
559 562
                     $docs[$currentLevel - 1][$data['parent']]['active'] = 1;
560 563
                 }
561 564
 
562
-                if ($extPrepare) {
565
+                if ($extPrepare) {
563 566
                     $data = $extPrepare->init($this, array(
564 567
                         'data'      => $data,
565 568
                         'nameParam' => 'prepare'
566 569
                     ));
567
-                    if (is_bool($data) && $data === false) {
570
+                    if (is_bool($data) && $data === false) {
568 571
                         continue;
569 572
                     }
570 573
                 }
@@ -572,7 +575,7 @@  discard block
 block discarded – undo
572 575
                 $hideSubMenus = $this->getCFGDef('hideSubMenus', 0);
573 576
                 $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'],
574 577
                             $this->activeBranch));
575
-                if ($hideSubMenus) {
578
+                if ($hideSubMenus) {
576 579
                     $docs[$currentLevel - 1][$data['parent']]['children'][] = $data;
577 580
                 }
578 581
             }
@@ -582,11 +585,11 @@  discard block
 block discarded – undo
582 585
         unset($data);
583 586
         $out = array();
584 587
         $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0);
585
-        foreach ($docs[0] as $id => $data) {
586
-            if (isset($data['children'])) {
587
-                if ($joinMenus) {
588
+        foreach ($docs[0] as $id => $data) {
589
+            if (isset($data['children'])) {
590
+                if ($joinMenus) {
588 591
                     $out = array_merge($out, $data['children']);
589
-                } else {
592
+                } else {
590 593
                     $out[] = $data['children'];
591 594
                 }
592 595
             }
@@ -603,8 +606,8 @@  discard block
 block discarded – undo
603 606
      * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра
604 607
      * @return mixed значение из конфига
605 608
      */
606
-    public function getCFGDef($name, $def = null)
607
-    {
609
+    public function getCFGDef($name, $def = null)
610
+    {
608 611
         return parent::getCFGDef($name . $this->currentLevel, parent::getCFGDef($name, $def));
609 612
     }
610 613
 }
Please login to merge, or discard this patch.