@@ -107,7 +107,7 @@ |
||
107 | 107 | |
108 | 108 | /** |
109 | 109 | * Список активных документов |
110 | - * @param $id |
|
110 | + * @param integer $id |
|
111 | 111 | * @param int $maxDepth |
112 | 112 | */ |
113 | 113 | public function setActiveBranch($id, $maxDepth = 10) |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | foreach ($this->levels as $level => $docs) { |
68 | 68 | $ids = array_merge($ids, array_keys($docs)); |
69 | 69 | } |
70 | - if (!empty($ids)) { |
|
70 | + if ( ! empty($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; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | if ($this->getCFGDef('showParent', 0) && in_array(0, $this->IDs)) { |
112 | 112 | $this->config->setConfig(array('showParent' => 0)); |
113 | 113 | } |
114 | - $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0); |
|
114 | + $joinMenus = $this->getCFGDef('joinMenus', 0) && ! $this->getCFGDef('showParent', 0); |
|
115 | 115 | while ($currentLevel <= $maxDepth) { |
116 | 116 | $orderBy = $this->getCFGDef('orderBy'); |
117 | 117 | if ($this->getCFGDef('showParent', 0) && $currentLevel == 1) { |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | } else { |
139 | 139 | foreach ($docs as $id => &$item) { |
140 | 140 | $parent = $item['parent']; |
141 | - if (!isset($this->display[$parent])) { |
|
141 | + if ( ! isset($this->display[$parent])) { |
|
142 | 142 | $this->display[$parent] = 1; |
143 | 143 | } |
144 | 144 | $item['iteration'] = $this->display[$parent]++; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $_ids[] = $row['parent']; |
194 | 194 | $out[$row['parent']] = $row['count']; |
195 | 195 | } |
196 | - if (!empty($_ids)) { |
|
196 | + if ( ! empty($_ids)) { |
|
197 | 197 | $ids = $this->diff($ids, $_ids); |
198 | 198 | } else { |
199 | 199 | break; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | $at = array_flip($a); |
214 | 214 | $d = array(); |
215 | 215 | foreach ($b as $i) { |
216 | - if (!isset($at[$i])) { |
|
216 | + if ( ! isset($at[$i])) { |
|
217 | 217 | $d[] = $i; |
218 | 218 | } |
219 | 219 | } |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | $data = $out; |
265 | 265 | } |
266 | 266 | }; |
267 | - if (!isset($data['maxLevel'])) { |
|
267 | + if ( ! isset($data['maxLevel'])) { |
|
268 | 268 | $data['maxLevel'] = 1; |
269 | 269 | $docs[$currentLevel - 1][$data['parent']]['maxLevel'] = 0; |
270 | 270 | } |
@@ -280,11 +280,11 @@ discard block |
||
280 | 280 | } |
281 | 281 | |
282 | 282 | if (isset($data['wrap'])) { |
283 | - if(is_array($data['wrap'])) $data['wrap'] = $this->parseRow($data['wrap']); |
|
283 | + if (is_array($data['wrap'])) $data['wrap'] = $this->parseRow($data['wrap']); |
|
284 | 284 | $data['wrap'] = $this->parseOuter($data); |
285 | 285 | } |
286 | 286 | $hideSubMenus = $this->getCFGDef('hideSubMenus', 0); |
287 | - $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'], |
|
287 | + $hideSubMenus = ! $hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'], |
|
288 | 288 | $this->activeBranch)); |
289 | 289 | if ($hideSubMenus) { |
290 | 290 | $docs[$currentLevel - 1][$data['parent']]['wrap'][] = $data; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | } |
296 | 296 | unset($data); |
297 | 297 | $out = ''; |
298 | - $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0); |
|
298 | + $joinMenus = $this->getCFGDef('joinMenus', 0) && ! $this->getCFGDef('showParent', 0); |
|
299 | 299 | foreach ($docs[0] as $id => $data) { |
300 | 300 | if (isset($data['wrap'])) { |
301 | 301 | if ($joinMenus) { |
@@ -329,14 +329,14 @@ discard block |
||
329 | 329 | if ($id == $this->getHereId()) { |
330 | 330 | $data['here'] = 1; |
331 | 331 | } |
332 | - if (!isset($data['here']) && in_array($id, $this->activeBranch)) { |
|
332 | + if ( ! isset($data['here']) && in_array($id, $this->activeBranch)) { |
|
333 | 333 | $data['active'] = 1; |
334 | 334 | } |
335 | 335 | if ($this->getCFGDef('hideSubMenus') && isset($data['isfolder']) && $data['isfolder']) { |
336 | 336 | $data['state'] = in_array($data['id'], $this->activeBranch) ? 'open' : 'closed'; |
337 | 337 | } |
338 | 338 | |
339 | - if (!isset($data['_display'])) { |
|
339 | + if ( ! isset($data['_display'])) { |
|
340 | 340 | $data['_display'] = $this->display[$data['parent']] - 1; |
341 | 341 | } |
342 | 342 | if ($data['iteration'] == 1) { |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | } |
348 | 348 | |
349 | 349 | $titleField = $this->getCFGDef('titleField', 'title'); |
350 | - $data[$titleField] = isset($data['menutitle']) && !empty($data['menutitle']) ? $data['menutitle'] : $data['pagetitle']; |
|
350 | + $data[$titleField] = isset($data['menutitle']) && ! empty($data['menutitle']) ? $data['menutitle'] : $data['pagetitle']; |
|
351 | 351 | $data['level'] = $this->currentLevel; |
352 | 352 | $data['url'] = $this->makeUrl($data); |
353 | 353 | if ($this->getCFGDef('countChildren', 0)) { |
@@ -433,7 +433,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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) { |
@@ -9,8 +9,8 @@ discard block |
||
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 |
||
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 |
||
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 | $display = 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,53 +54,53 @@ discard block |
||
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 (!empty($ids)) { |
|
70 | + if (!empty($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() |
|
87 | - { |
|
86 | + public function _getChildren() |
|
87 | + { |
|
88 | 88 | $maxDepth = $this->getCFGDef('maxDepth', 10); |
89 | - if ($this->getCFGDef('hideSubMenus', 0) && empty($this->getCFGDef('openIds'))) { |
|
89 | + if ($this->getCFGDef('hideSubMenus', 0) && empty($this->getCFGDef('openIds'))) { |
|
90 | 90 | $maxDepth = min($maxDepth, $this->setActiveBranch($this->getHereId())); |
91 | - if (empty(array_intersect($this->IDs, $this->activeBranch))) { |
|
91 | + if (empty(array_intersect($this->IDs, $this->activeBranch))) { |
|
92 | 92 | $maxDepth = 1; |
93 | 93 | $this->config->setConfig(array('hideSubMenus' => 0)); |
94 | 94 | }; |
95 | - } else { |
|
95 | + } else { |
|
96 | 96 | $this->setActiveBranch($this->getHereId()); |
97 | 97 | } |
98 | - if ($oIds = $this->getCFGDef('openIds')) { |
|
98 | + if ($oIds = $this->getCFGDef('openIds')) { |
|
99 | 99 | $maxDepth = 1; |
100 | 100 | $oIds = $this->cleanIDs($oIds); |
101 | 101 | $oIds[] = $this->getHereId(); |
102 | - foreach ($oIds as $id) { |
|
103 | - if (($c = $this->setActiveBranch($id)) > $maxDepth) { |
|
102 | + foreach ($oIds as $id) { |
|
103 | + if (($c = $this->setActiveBranch($id)) > $maxDepth) { |
|
104 | 104 | $maxDepth = $c; |
105 | 105 | } |
106 | 106 | } |
@@ -108,44 +108,44 @@ discard block |
||
108 | 108 | } |
109 | 109 | $currentLevel = &$this->currentLevel; |
110 | 110 | $currentLevel = 1; |
111 | - if ($this->getCFGDef('showParent', 0) && in_array(0, $this->IDs)) { |
|
111 | + if ($this->getCFGDef('showParent', 0) && in_array(0, $this->IDs)) { |
|
112 | 112 | $this->config->setConfig(array('showParent' => 0)); |
113 | 113 | } |
114 | 114 | $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0); |
115 | - while ($currentLevel <= $maxDepth) { |
|
115 | + while ($currentLevel <= $maxDepth) { |
|
116 | 116 | $orderBy = $this->getCFGDef('orderBy'); |
117 | - if ($this->getCFGDef('showParent', 0) && $currentLevel == 1) { |
|
117 | + if ($this->getCFGDef('showParent', 0) && $currentLevel == 1) { |
|
118 | 118 | $docs = $this->getDocList(); |
119 | 119 | $this->config->setConfig(array('showParent' => 0)); |
120 | - } else { |
|
120 | + } else { |
|
121 | 121 | $docs = $this->getChildrenList(); |
122 | 122 | } |
123 | - if ($currentLevel == 1 && $joinMenus) { |
|
123 | + if ($currentLevel == 1 && $joinMenus) { |
|
124 | 124 | $tmp = array(); |
125 | 125 | $display = 0; |
126 | 126 | $iteration = 1; |
127 | - foreach ($docs as $id => $item) { |
|
127 | + foreach ($docs as $id => $item) { |
|
128 | 128 | $tmp[$item['parent']][] = $item['id']; |
129 | 129 | $display++; |
130 | 130 | } |
131 | - foreach ($tmp as $id => $item) { |
|
132 | - foreach ($item as $_id) { |
|
131 | + foreach ($tmp as $id => $item) { |
|
132 | + foreach ($item as $_id) { |
|
133 | 133 | $docs[$_id]['_display'] = $display; |
134 | 134 | $docs[$_id]['iteration'] = $iteration++; |
135 | 135 | } |
136 | 136 | } |
137 | 137 | unset($tmp); |
138 | - } else { |
|
139 | - foreach ($docs as $id => &$item) { |
|
138 | + } else { |
|
139 | + foreach ($docs as $id => &$item) { |
|
140 | 140 | $parent = $item['parent']; |
141 | - if (!isset($this->display[$parent])) { |
|
141 | + if (!isset($this->display[$parent])) { |
|
142 | 142 | $this->display[$parent] = 1; |
143 | 143 | } |
144 | 144 | $item['iteration'] = $this->display[$parent]++; |
145 | 145 | } |
146 | 146 | } |
147 | 147 | $this->config->setConfig(array('orderBy' => $orderBy)); |
148 | - if (empty($docs)) { |
|
148 | + if (empty($docs)) { |
|
149 | 149 | break; |
150 | 150 | } |
151 | 151 | $this->levels[$currentLevel++] = $docs; |
@@ -159,8 +159,8 @@ discard block |
||
159 | 159 | * @param $id |
160 | 160 | * @param int $maxDepth |
161 | 161 | */ |
162 | - public function setActiveBranch($id, $maxDepth = 10) |
|
163 | - { |
|
162 | + public function setActiveBranch($id, $maxDepth = 10) |
|
163 | + { |
|
164 | 164 | $ids = array_values($this->modx->getParentIds($id, $maxDepth)); |
165 | 165 | $ids[] = $id; |
166 | 166 | $ids[] = 0; |
@@ -173,29 +173,29 @@ discard block |
||
173 | 173 | /** |
174 | 174 | * Подсчет количества непосредственных дочерних документов |
175 | 175 | */ |
176 | - public function countChildren() |
|
177 | - { |
|
176 | + public function countChildren() |
|
177 | + { |
|
178 | 178 | $ids = array(); |
179 | 179 | $out = &$this->countChildren; |
180 | - foreach ($this->levels as $level => $docs) { |
|
180 | + foreach ($this->levels as $level => $docs) { |
|
181 | 181 | $ids = array_merge($ids, array_keys($docs)); |
182 | 182 | } |
183 | 183 | $maxDepth = count($this->levels); |
184 | 184 | $currentDepth = 1; |
185 | - while ($currentDepth <= $maxDepth) { |
|
185 | + while ($currentDepth <= $maxDepth) { |
|
186 | 186 | $_ids = implode(',', $ids); |
187 | - if (empty($_ids)) { |
|
187 | + if (empty($_ids)) { |
|
188 | 188 | break; |
189 | 189 | } |
190 | 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`"); |
191 | 191 | $_ids = array(); |
192 | - while ($row = $this->modx->db->getRow($q)) { |
|
192 | + while ($row = $this->modx->db->getRow($q)) { |
|
193 | 193 | $_ids[] = $row['parent']; |
194 | 194 | $out[$row['parent']] = $row['count']; |
195 | 195 | } |
196 | - if (!empty($_ids)) { |
|
196 | + if (!empty($_ids)) { |
|
197 | 197 | $ids = $this->diff($ids, $_ids); |
198 | - } else { |
|
198 | + } else { |
|
199 | 199 | break; |
200 | 200 | } |
201 | 201 | $currentDepth++; |
@@ -208,12 +208,12 @@ discard block |
||
208 | 208 | * @param $a |
209 | 209 | * @return array |
210 | 210 | */ |
211 | - private function diff($b, $a) |
|
212 | - { |
|
211 | + private function diff($b, $a) |
|
212 | + { |
|
213 | 213 | $at = array_flip($a); |
214 | 214 | $d = array(); |
215 | - foreach ($b as $i) { |
|
216 | - if (!isset($at[$i])) { |
|
215 | + foreach ($b as $i) { |
|
216 | + if (!isset($at[$i])) { |
|
217 | 217 | $d[] = $i; |
218 | 218 | } |
219 | 219 | } |
@@ -228,17 +228,17 @@ discard block |
||
228 | 228 | * @param string $tpl шаблон |
229 | 229 | * @return string |
230 | 230 | */ |
231 | - public function render($tpl = '') |
|
232 | - { |
|
231 | + public function render($tpl = '') |
|
232 | + { |
|
233 | 233 | $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html')); |
234 | - if (empty($this->levels)) { |
|
234 | + if (empty($this->levels)) { |
|
235 | 235 | $noneTpl = $this->getCFGDef('noneTpl'); |
236 | 236 | $out = $noneTpl ? $this->parseChunk($noneTpl, array()) : ''; |
237 | - } else { |
|
237 | + } else { |
|
238 | 238 | $out = $this->_render($tpl); |
239 | 239 | } |
240 | 240 | |
241 | - if ($out) { |
|
241 | + if ($out) { |
|
242 | 242 | $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out); |
243 | 243 | } |
244 | 244 | $this->debug->debugEnd('render'); |
@@ -250,43 +250,45 @@ discard block |
||
250 | 250 | * @param string $tpl |
251 | 251 | * @return string |
252 | 252 | */ |
253 | - public function _render($tpl = '') |
|
254 | - { |
|
253 | + public function _render($tpl = '') |
|
254 | + { |
|
255 | 255 | $currentLevel = &$this->currentLevel; |
256 | 256 | $currentLevel = count($this->levels); |
257 | 257 | $docs = $this->levels; |
258 | 258 | /** @var prepare_DL_Extender_ $extPrepare */ |
259 | 259 | $extPrepare = $this->getExtender('prepare'); |
260 | - while ($currentLevel > 0) { |
|
261 | - foreach ($docs[$currentLevel] as $id => &$data) { |
|
262 | - if ($out = $this->prepareData($data)) { |
|
263 | - 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)) { |
|
264 | 264 | $data = $out; |
265 | 265 | } |
266 | 266 | }; |
267 | - if (!isset($data['maxLevel'])) { |
|
267 | + if (!isset($data['maxLevel'])) { |
|
268 | 268 | $data['maxLevel'] = 1; |
269 | 269 | $docs[$currentLevel - 1][$data['parent']]['maxLevel'] = 0; |
270 | 270 | } |
271 | 271 | |
272 | - if ($extPrepare) { |
|
272 | + if ($extPrepare) { |
|
273 | 273 | $data = $extPrepare->init($this, array( |
274 | 274 | 'data' => $data, |
275 | 275 | 'nameParam' => 'prepare' |
276 | 276 | )); |
277 | - if (is_bool($data) && $data === false) { |
|
277 | + if (is_bool($data) && $data === false) { |
|
278 | 278 | continue; |
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | - if (isset($data['wrap'])) { |
|
283 | - if(is_array($data['wrap'])) $data['wrap'] = $this->parseRow($data['wrap']); |
|
282 | + if (isset($data['wrap'])) { |
|
283 | + if(is_array($data['wrap'])) { |
|
284 | + $data['wrap'] = $this->parseRow($data['wrap']); |
|
285 | + } |
|
284 | 286 | $data['wrap'] = $this->parseOuter($data); |
285 | 287 | } |
286 | 288 | $hideSubMenus = $this->getCFGDef('hideSubMenus', 0); |
287 | 289 | $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'], |
288 | 290 | $this->activeBranch)); |
289 | - if ($hideSubMenus) { |
|
291 | + if ($hideSubMenus) { |
|
290 | 292 | $docs[$currentLevel - 1][$data['parent']]['wrap'][] = $data; |
291 | 293 | } |
292 | 294 | } |
@@ -296,17 +298,19 @@ discard block |
||
296 | 298 | unset($data); |
297 | 299 | $out = ''; |
298 | 300 | $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0); |
299 | - foreach ($docs[0] as $id => $data) { |
|
300 | - if (isset($data['wrap'])) { |
|
301 | - if ($joinMenus) { |
|
301 | + foreach ($docs[0] as $id => $data) { |
|
302 | + if (isset($data['wrap'])) { |
|
303 | + if ($joinMenus) { |
|
302 | 304 | $out .= $this->parseRow($data['wrap']); |
303 | - } else { |
|
305 | + } else { |
|
304 | 306 | $data['wrap'] = $this->parseRow($data['wrap']); |
305 | 307 | $out .= $this->parseOuter($data); |
306 | 308 | } |
307 | 309 | } |
308 | 310 | } |
309 | - if ($joinMenus) $out = $this->parseOuter(array('wrap' => $out)); |
|
311 | + if ($joinMenus) { |
|
312 | + $out = $this->parseOuter(array('wrap' => $out)); |
|
313 | + } |
|
310 | 314 | |
311 | 315 | return $out; |
312 | 316 | } |
@@ -316,33 +320,33 @@ discard block |
||
316 | 320 | * @param $data |
317 | 321 | * @return array |
318 | 322 | */ |
319 | - public function prepareData($data) |
|
320 | - { |
|
323 | + public function prepareData($data) |
|
324 | + { |
|
321 | 325 | /** |
322 | 326 | * @var e_DL_Extender $extE |
323 | 327 | */ |
324 | 328 | $extE = $this->getExtender('e', true, true); |
325 | 329 | $id = $data['id']; |
326 | - if (isset($this->docTvs[$id])) { |
|
330 | + if (isset($this->docTvs[$id])) { |
|
327 | 331 | $data = array_merge($data, $this->docTvs[$id]); |
328 | 332 | } |
329 | - if ($id == $this->getHereId()) { |
|
333 | + if ($id == $this->getHereId()) { |
|
330 | 334 | $data['here'] = 1; |
331 | 335 | } |
332 | - if (!isset($data['here']) && in_array($id, $this->activeBranch)) { |
|
336 | + if (!isset($data['here']) && in_array($id, $this->activeBranch)) { |
|
333 | 337 | $data['active'] = 1; |
334 | 338 | } |
335 | - if ($this->getCFGDef('hideSubMenus') && isset($data['isfolder']) && $data['isfolder']) { |
|
339 | + if ($this->getCFGDef('hideSubMenus') && isset($data['isfolder']) && $data['isfolder']) { |
|
336 | 340 | $data['state'] = in_array($data['id'], $this->activeBranch) ? 'open' : 'closed'; |
337 | 341 | } |
338 | 342 | |
339 | - if (!isset($data['_display'])) { |
|
343 | + if (!isset($data['_display'])) { |
|
340 | 344 | $data['_display'] = $this->display[$data['parent']] - 1; |
341 | 345 | } |
342 | - if ($data['iteration'] == 1) { |
|
346 | + if ($data['iteration'] == 1) { |
|
343 | 347 | $data['first'] = 1; |
344 | 348 | } |
345 | - if ($data['iteration'] == $data['_display']) { |
|
349 | + if ($data['iteration'] == $data['_display']) { |
|
346 | 350 | $data['last'] = 1; |
347 | 351 | } |
348 | 352 | |
@@ -350,12 +354,12 @@ discard block |
||
350 | 354 | $data[$titleField] = isset($data['menutitle']) && !empty($data['menutitle']) ? $data['menutitle'] : $data['pagetitle']; |
351 | 355 | $data['level'] = $this->currentLevel; |
352 | 356 | $data['url'] = $this->makeUrl($data); |
353 | - if ($this->getCFGDef('countChildren', 0)) { |
|
357 | + if ($this->getCFGDef('countChildren', 0)) { |
|
354 | 358 | $data['count'] = isset($this->countChildren[$data['id']]) ? $this->countChildren[$data['id']] : 0; |
355 | 359 | } |
356 | 360 | |
357 | - if ($out = $extE->init($this, compact('data'))) { |
|
358 | - if (is_array($out)) { |
|
361 | + if ($out = $extE->init($this, compact('data'))) { |
|
362 | + if (is_array($out)) { |
|
359 | 363 | $data = $out; |
360 | 364 | } |
361 | 365 | } |
@@ -368,16 +372,16 @@ discard block |
||
368 | 372 | * @param array $data |
369 | 373 | * @return string |
370 | 374 | */ |
371 | - public function parseOuter($data = array()) |
|
372 | - { |
|
375 | + public function parseOuter($data = array()) |
|
376 | + { |
|
373 | 377 | $tpl = $this->getCFGDef('outerTpl', '@CODE:<ul[+classes+]>[+wrap+]</ul>'); |
374 | 378 | $classes = ''; |
375 | 379 | $classNames = $this->getCFGDef('outerClass'); |
376 | - if ($this->currentLevel >= 1) { |
|
380 | + if ($this->currentLevel >= 1) { |
|
377 | 381 | $tpl = $this->getCFGDef('innerTpl', $tpl); |
378 | 382 | $classNames = $this->getCFGDef('innerClass'); |
379 | 383 | } |
380 | - if ($classNames) { |
|
384 | + if ($classNames) { |
|
381 | 385 | $classes = " class=\"{$classNames}\""; |
382 | 386 | } |
383 | 387 | $tpl = isset($data['_renderOuterTpl']) ? $data['_renderOuterTpl'] : $tpl; |
@@ -394,10 +398,10 @@ discard block |
||
394 | 398 | * @param array $data |
395 | 399 | * @return string |
396 | 400 | */ |
397 | - public function parseRow($data = array()) |
|
398 | - { |
|
401 | + public function parseRow($data = array()) |
|
402 | + { |
|
399 | 403 | $out = ''; |
400 | - foreach ($data as $iteration => $item) { |
|
404 | + foreach ($data as $iteration => $item) { |
|
401 | 405 | $tpl = isset($item['_renderRowTpl']) ? $item['_renderRowTpl'] : $this->getRowTemplate($item); |
402 | 406 | $item = array_merge($item, $this->getClasses($item)); |
403 | 407 | $out .= $this->parseChunk($tpl, $item); |
@@ -411,14 +415,14 @@ discard block |
||
411 | 415 | * @param array $data |
412 | 416 | * @return string |
413 | 417 | */ |
414 | - protected function makeUrl($data = array()) |
|
415 | - { |
|
418 | + protected function makeUrl($data = array()) |
|
419 | + { |
|
416 | 420 | $out = ''; |
417 | - if ($this->getCFGDef('makeUrl', 1)) { |
|
418 | - if (isset($data['type']) && $data['type'] == 'reference' && isset($data['content'])) { |
|
421 | + if ($this->getCFGDef('makeUrl', 1)) { |
|
422 | + if (isset($data['type']) && $data['type'] == 'reference' && isset($data['content'])) { |
|
419 | 423 | $out = is_numeric($data['content']) ? $this->modx->makeUrl($data['content'], '', '', |
420 | 424 | $this->getCFGDef('urlScheme', '')) : $data['content']; |
421 | - } else { |
|
425 | + } else { |
|
422 | 426 | $out = isset($data['id']) && is_numeric($data['id']) ? $this->modx->makeUrl($data['id'], '', '', |
423 | 427 | $this->getCFGDef('urlScheme', '')) : ''; |
424 | 428 | } |
@@ -431,9 +435,9 @@ discard block |
||
431 | 435 | * Вовзращает id текущего документа |
432 | 436 | * @return int |
433 | 437 | */ |
434 | - public function getHereId() |
|
435 | - { |
|
436 | - if (!$hereId = (int)$this->getCFGDef('hereId')) { |
|
438 | + public function getHereId() |
|
439 | + { |
|
440 | + if (!$hereId = (int)$this->getCFGDef('hereId')) { |
|
437 | 441 | $hereId = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
438 | 442 | } |
439 | 443 | |
@@ -445,8 +449,8 @@ discard block |
||
445 | 449 | * @param array $data |
446 | 450 | * @return array |
447 | 451 | */ |
448 | - protected function getClasses($data = array()) |
|
449 | - { |
|
452 | + protected function getClasses($data = array()) |
|
453 | + { |
|
450 | 454 | $classes = isset($data['classes']) ? $data['classes'] : array( |
451 | 455 | 'rowClass' => '', |
452 | 456 | 'firstClass' => '', |
@@ -459,34 +463,34 @@ discard block |
||
459 | 463 | 'oddClass' => '', |
460 | 464 | 'evenClass' => '' |
461 | 465 | ); |
462 | - if (isset($data['state'])) { |
|
466 | + if (isset($data['state'])) { |
|
463 | 467 | $classes['stateClass'] = $this->getCFGDef($data['state'] . 'Class', $data['state']); |
464 | 468 | } |
465 | - if (isset($data['here'])) { |
|
469 | + if (isset($data['here'])) { |
|
466 | 470 | $classes['hereClass'] = $this->getCFGDef('hereClass', 'current'); |
467 | 471 | } |
468 | - if (isset($data['active'])) { |
|
472 | + if (isset($data['active'])) { |
|
469 | 473 | $classes['activeClass'] = $this->getCFGDef('activeClass', 'active'); |
470 | 474 | } |
471 | 475 | $classes['rowClass'] = $this->getCFGDef('rowClass'); |
472 | - if ($data['iteration'] % 2 == 1) { |
|
476 | + if ($data['iteration'] % 2 == 1) { |
|
473 | 477 | $classes['oddClass'] = $this->getCFGDef('oddClass', 'odd'); |
474 | - } else { |
|
478 | + } else { |
|
475 | 479 | $classes['evenClass'] = $this->getCFGDef('evenClass', 'even'); |
476 | 480 | } |
477 | - if (isset($data['first'])) { |
|
481 | + if (isset($data['first'])) { |
|
478 | 482 | $classes['firstClass'] = $this->getCFGDef('firstClass', 'first'); |
479 | 483 | } |
480 | - if (isset($data['last'])) { |
|
484 | + if (isset($data['last'])) { |
|
481 | 485 | $classes['lastClass'] = $this->getCFGDef('lastClass', 'last'); |
482 | 486 | } |
483 | - if ($levelClass = $this->getCFGDef('levelClass', 'level')) { |
|
487 | + if ($levelClass = $this->getCFGDef('levelClass', 'level')) { |
|
484 | 488 | $classes['levelClass'] = $levelClass . $data['level']; |
485 | 489 | } |
486 | - if (isset($data['type']) && $data['type'] == 'reference') { |
|
490 | + if (isset($data['type']) && $data['type'] == 'reference') { |
|
487 | 491 | $classes['webLinkClass'] = $this->getCFGDef('webLinkClass'); |
488 | 492 | } |
489 | - if (!empty($data['wrap'])) { |
|
493 | + if (!empty($data['wrap'])) { |
|
490 | 494 | $classes['parentClass'] = $this->getCFGDef('parentClass'); |
491 | 495 | } |
492 | 496 | $classNames = implode(' ', array_filter(array_values($classes))); |
@@ -501,28 +505,28 @@ discard block |
||
501 | 505 | * @param array $data |
502 | 506 | * @return string |
503 | 507 | */ |
504 | - protected function getRowTemplate($data = array()) |
|
505 | - { |
|
508 | + protected function getRowTemplate($data = array()) |
|
509 | + { |
|
506 | 510 | $tpl = $this->getCFGDef('rowTpl', '@CODE:<li[+classes+]><a href="[+url+]">[+title+]</a></li>'); |
507 | - if (!empty($data['wrap'])) { |
|
511 | + if (!empty($data['wrap'])) { |
|
508 | 512 | $tpl = $this->getCFGDef('parentRowTpl', |
509 | 513 | '@CODE:<li[+classes+]><a href="[+url+]">[+title+]</a>[+wrap+]</li>'); |
510 | 514 | if ((isset($data['template']) && !$data['template']) || (isset($data['link_attributes']) && strpos($data['link_attributes'], |
511 | 515 | 'category') !== false) |
512 | - ) { |
|
516 | + ) { |
|
513 | 517 | $tpl = $this->getCFGDef('categoryFolderTpl', $tpl); |
514 | - } elseif (isset($data['here'])) { |
|
518 | + } elseif (isset($data['here'])) { |
|
515 | 519 | $tpl = $this->getCFGDef('parentRowHereTpl', $tpl); |
516 | - } elseif (isset($data['active'])) { |
|
520 | + } elseif (isset($data['active'])) { |
|
517 | 521 | $tpl = $this->getCFGDef('parentRowActiveTpl', $tpl); |
518 | 522 | } |
519 | - } elseif ($data['level'] > 1) { |
|
523 | + } elseif ($data['level'] > 1) { |
|
520 | 524 | $tpl = $this->getCFGDef('innerRowTpl', $tpl); |
521 | - if (isset($data['here'])) { |
|
525 | + if (isset($data['here'])) { |
|
522 | 526 | $tpl = $this->getCFGDef('innerRowHereTpl', $tpl); |
523 | 527 | } |
524 | - } else { |
|
525 | - if (isset($data['here'])) { |
|
528 | + } else { |
|
529 | + if (isset($data['here'])) { |
|
526 | 530 | $tpl = $this->getCFGDef('rowHereTpl', $tpl); |
527 | 531 | } |
528 | 532 | } |
@@ -536,35 +540,37 @@ discard block |
||
536 | 540 | * @param array $array |
537 | 541 | * @return string |
538 | 542 | */ |
539 | - public function getJSON($data, $fields, $array = array()) |
|
540 | - { |
|
543 | + public function getJSON($data, $fields, $array = array()) |
|
544 | + { |
|
541 | 545 | $currentLevel = &$this->currentLevel; |
542 | 546 | $currentLevel = count($this->levels); |
543 | 547 | $docs = $this->levels; |
544 | 548 | |
545 | - if (empty($docs)) return '[]'; |
|
549 | + if (empty($docs)) { |
|
550 | + return '[]'; |
|
551 | + } |
|
546 | 552 | |
547 | 553 | /** @var prepare_DL_Extender_ $extPrepare */ |
548 | 554 | $extPrepare = $this->getExtender('prepare'); |
549 | 555 | |
550 | - while ($currentLevel > 0) { |
|
551 | - foreach ($docs[$currentLevel] as $id => &$data) { |
|
552 | - if ($out = $this->prepareData($data)) { |
|
553 | - if (is_array($out)) { |
|
556 | + while ($currentLevel > 0) { |
|
557 | + foreach ($docs[$currentLevel] as $id => &$data) { |
|
558 | + if ($out = $this->prepareData($data)) { |
|
559 | + if (is_array($out)) { |
|
554 | 560 | $data = $out; |
555 | 561 | } |
556 | 562 | }; |
557 | 563 | |
558 | - if (isset($data['here']) || isset($data['active'])) { |
|
564 | + if (isset($data['here']) || isset($data['active'])) { |
|
559 | 565 | $docs[$currentLevel - 1][$data['parent']]['active'] = 1; |
560 | 566 | } |
561 | 567 | |
562 | - if ($extPrepare) { |
|
568 | + if ($extPrepare) { |
|
563 | 569 | $data = $extPrepare->init($this, array( |
564 | 570 | 'data' => $data, |
565 | 571 | 'nameParam' => 'prepare' |
566 | 572 | )); |
567 | - if (is_bool($data) && $data === false) { |
|
573 | + if (is_bool($data) && $data === false) { |
|
568 | 574 | continue; |
569 | 575 | } |
570 | 576 | } |
@@ -572,7 +578,7 @@ discard block |
||
572 | 578 | $hideSubMenus = $this->getCFGDef('hideSubMenus', 0); |
573 | 579 | $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'], |
574 | 580 | $this->activeBranch)); |
575 | - if ($hideSubMenus) { |
|
581 | + if ($hideSubMenus) { |
|
576 | 582 | $docs[$currentLevel - 1][$data['parent']]['children'][] = $data; |
577 | 583 | } |
578 | 584 | } |
@@ -582,11 +588,11 @@ discard block |
||
582 | 588 | unset($data); |
583 | 589 | $out = array(); |
584 | 590 | $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0); |
585 | - foreach ($docs[0] as $id => $data) { |
|
586 | - if (isset($data['children'])) { |
|
587 | - if ($joinMenus) { |
|
591 | + foreach ($docs[0] as $id => $data) { |
|
592 | + if (isset($data['children'])) { |
|
593 | + if ($joinMenus) { |
|
588 | 594 | $out = array_merge($out, $data['children']); |
589 | - } else { |
|
595 | + } else { |
|
590 | 596 | $out[] = $data['children']; |
591 | 597 | } |
592 | 598 | } |
@@ -603,8 +609,8 @@ discard block |
||
603 | 609 | * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра |
604 | 610 | * @return mixed значение из конфига |
605 | 611 | */ |
606 | - public function getCFGDef($name, $def = null) |
|
607 | - { |
|
612 | + public function getCFGDef($name, $def = null) |
|
613 | + { |
|
608 | 614 | return parent::getCFGDef($name . $this->currentLevel, parent::getCFGDef($name, $def)); |
609 | 615 | } |
610 | 616 | } |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | /** |
5 | 5 | * Class modResource |
6 | 6 | */ |
7 | -class modResource extends MODxAPI |
|
8 | -{ |
|
7 | +class modResource extends MODxAPI |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * @var string |
11 | 11 | */ |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * @param DocumentParser $modx |
158 | 158 | * @param bool $debug |
159 | 159 | */ |
160 | - public function __construct($modx, $debug = false) |
|
161 | - { |
|
160 | + public function __construct($modx, $debug = false) |
|
161 | + { |
|
162 | 162 | parent::__construct($modx, $debug); |
163 | 163 | $this->get_TV(); |
164 | 164 | $uTable = $this->makeTable("manager_users"); |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | /** |
172 | 172 | * @return array |
173 | 173 | */ |
174 | - public function toArrayMain() |
|
175 | - { |
|
174 | + public function toArrayMain() |
|
175 | + { |
|
176 | 176 | $out = array_intersect_key(parent::toArray(), $this->default_field); |
177 | 177 | |
178 | 178 | return $out; |
@@ -182,18 +182,18 @@ discard block |
||
182 | 182 | * @param bool $render |
183 | 183 | * @return array |
184 | 184 | */ |
185 | - public function toArrayTV($render = false) |
|
186 | - { |
|
185 | + public function toArrayTV($render = false) |
|
186 | + { |
|
187 | 187 | $out = array_diff_key(parent::toArray(), $this->default_field); |
188 | 188 | $tpl = $this->get('template'); |
189 | 189 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
190 | - foreach ($tvTPL as $item) { |
|
191 | - if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { |
|
190 | + foreach ($tvTPL as $item) { |
|
191 | + if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { |
|
192 | 192 | $out[$this->tvid[$item]] = $this->get($this->tvid[$item]); |
193 | 193 | } |
194 | 194 | } |
195 | - if ($render) { |
|
196 | - foreach ($out as $key => $val) { |
|
195 | + if ($render) { |
|
196 | + foreach ($out as $key => $val) { |
|
197 | 197 | $out[$key] = $this->renderTV($key); |
198 | 198 | } |
199 | 199 | } |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | * @param bool $render |
209 | 209 | * @return array |
210 | 210 | */ |
211 | - public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) |
|
212 | - { |
|
211 | + public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) |
|
212 | + { |
|
213 | 213 | $out = array_merge( |
214 | 214 | $this->toArrayMain(), |
215 | 215 | $this->toArrayTV($render), |
@@ -222,11 +222,11 @@ discard block |
||
222 | 222 | /** |
223 | 223 | * @return null|string |
224 | 224 | */ |
225 | - public function getUrl() |
|
226 | - { |
|
225 | + public function getUrl() |
|
226 | + { |
|
227 | 227 | $out = null; |
228 | 228 | $id = (int)$this->getID(); |
229 | - if (!empty($id)) { |
|
229 | + if (!empty($id)) { |
|
230 | 230 | $out = $this->modx->makeUrl($id); |
231 | 231 | } |
232 | 232 | |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | * @param string $second |
239 | 239 | * @return mixed |
240 | 240 | */ |
241 | - public function getTitle($main = 'menutitle', $second = 'pagetitle') |
|
242 | - { |
|
241 | + public function getTitle($main = 'menutitle', $second = 'pagetitle') |
|
242 | + { |
|
243 | 243 | $title = $this->get($main); |
244 | - if (empty($title) && $title !== '0') { |
|
244 | + if (empty($title) && $title !== '0') { |
|
245 | 245 | $title = $this->get($second); |
246 | 246 | } |
247 | 247 | |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | /** |
252 | 252 | * @return bool |
253 | 253 | */ |
254 | - public function isWebShow() |
|
255 | - { |
|
254 | + public function isWebShow() |
|
255 | + { |
|
256 | 256 | $pub = ($this->get('publishedon') < time() && $this->get('published')); |
257 | 257 | $unpub = ($this->get('unpub_date') == 0 || $this->get('unpub_date') > time()); |
258 | 258 | $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time())); |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | /** |
264 | 264 | * @return $this |
265 | 265 | */ |
266 | - public function touch() |
|
267 | - { |
|
266 | + public function touch() |
|
267 | + { |
|
268 | 268 | $this->set('editedon', time()); |
269 | 269 | |
270 | 270 | return $this; |
@@ -274,14 +274,14 @@ discard block |
||
274 | 274 | * @param $tvname |
275 | 275 | * @return null|string |
276 | 276 | */ |
277 | - public function renderTV($tvname) |
|
278 | - { |
|
277 | + public function renderTV($tvname) |
|
278 | + { |
|
279 | 279 | $out = null; |
280 | - if ($this->getID() > 0) { |
|
280 | + if ($this->getID() > 0) { |
|
281 | 281 | include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php"; |
282 | 282 | include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php"; |
283 | 283 | $tvval = $this->get($tvname); |
284 | - if ($this->isTVarrayField($tvname) && is_array($tvval)) { |
|
284 | + if ($this->isTVarrayField($tvname) && is_array($tvval)) { |
|
285 | 285 | $tvval = implode('||', $tvval); |
286 | 286 | } |
287 | 287 | $param = APIHelpers::getkey($this->tvd, $tvname, array()); |
@@ -298,14 +298,14 @@ discard block |
||
298 | 298 | * @param $key |
299 | 299 | * @return mixed |
300 | 300 | */ |
301 | - public function get($key) |
|
302 | - { |
|
301 | + public function get($key) |
|
302 | + { |
|
303 | 303 | $out = parent::get($key); |
304 | - if (isset($this->tv[$key])) { |
|
304 | + if (isset($this->tv[$key])) { |
|
305 | 305 | $tpl = $this->get('template'); |
306 | 306 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
307 | 307 | $tvID = APIHelpers::getkey($this->tv, $key, 0); |
308 | - if (in_array($tvID, $tvTPL) && is_null($out)) { |
|
308 | + if (in_array($tvID, $tvTPL) && is_null($out)) { |
|
309 | 309 | $out = APIHelpers::getkey($this->tvd[$key], 'value', null); |
310 | 310 | } |
311 | 311 | } |
@@ -318,10 +318,10 @@ discard block |
||
318 | 318 | * @param $value |
319 | 319 | * @return $this |
320 | 320 | */ |
321 | - public function set($key, $value) |
|
322 | - { |
|
323 | - if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
324 | - switch ($key) { |
|
321 | + public function set($key, $value) |
|
322 | + { |
|
323 | + if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
324 | + switch ($key) { |
|
325 | 325 | case 'parent': |
326 | 326 | $value = (int)$value; |
327 | 327 | break; |
@@ -331,38 +331,38 @@ discard block |
||
331 | 331 | break; |
332 | 332 | case 'published': |
333 | 333 | $value = (int)((bool)$value); |
334 | - if ($value) { |
|
334 | + if ($value) { |
|
335 | 335 | $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time'); |
336 | 336 | } |
337 | 337 | break; |
338 | 338 | case 'pub_date': |
339 | 339 | $value = $this->getTime($value); |
340 | - if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
340 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
341 | 341 | $this->field['published'] = 1; |
342 | 342 | $this->field['publishedon'] = $value; |
343 | 343 | } |
344 | 344 | break; |
345 | 345 | case 'unpub_date': |
346 | 346 | $value = $this->getTime($value); |
347 | - if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
347 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
348 | 348 | $this->field['published'] = 0; |
349 | 349 | $this->field['publishedon'] = 0; |
350 | 350 | } |
351 | 351 | break; |
352 | 352 | case 'deleted': |
353 | 353 | $value = (int)((bool)$value); |
354 | - if ($value) { |
|
354 | + if ($value) { |
|
355 | 355 | $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time'); |
356 | - } else { |
|
356 | + } else { |
|
357 | 357 | $this->field['deletedon'] = 0; |
358 | 358 | } |
359 | 359 | break; |
360 | 360 | case 'deletedon': |
361 | 361 | $value = $this->getTime($value); |
362 | - if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) { |
|
362 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) { |
|
363 | 363 | $value = 0; |
364 | 364 | } |
365 | - if ($value) { |
|
365 | + if ($value) { |
|
366 | 366 | $this->field['deleted'] = 1; |
367 | 367 | } |
368 | 368 | break; |
@@ -389,20 +389,20 @@ discard block |
||
389 | 389 | * @param int $default |
390 | 390 | * @return int|mixed |
391 | 391 | */ |
392 | - protected function getUser($value, $default = 0) |
|
393 | - { |
|
392 | + protected function getUser($value, $default = 0) |
|
393 | + { |
|
394 | 394 | $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0); |
395 | 395 | $value = (int)$value; |
396 | - if (!empty($value)) { |
|
396 | + if (!empty($value)) { |
|
397 | 397 | $by = $this->findUserBy($value); |
398 | - $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) { |
|
398 | + $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) { |
|
399 | 399 | return ($val->containsKey($by) && $val->get($by) === (string)$value); |
400 | 400 | }); |
401 | - if (!$exists) { |
|
401 | + if (!$exists) { |
|
402 | 402 | $value = 0; |
403 | 403 | } |
404 | 404 | } |
405 | - if (empty($value)) { |
|
405 | + if (empty($value)) { |
|
406 | 406 | $value = empty($currentAdmin) ? $default : $currentAdmin; |
407 | 407 | } |
408 | 408 | |
@@ -413,9 +413,9 @@ discard block |
||
413 | 413 | * @param $data |
414 | 414 | * @return bool|string |
415 | 415 | */ |
416 | - protected function findUserBy($data) |
|
417 | - { |
|
418 | - switch (true) { |
|
416 | + protected function findUserBy($data) |
|
417 | + { |
|
418 | + switch (true) { |
|
419 | 419 | case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): |
420 | 420 | $find = 'id'; |
421 | 421 | break; |
@@ -436,11 +436,11 @@ discard block |
||
436 | 436 | * @param array $data |
437 | 437 | * @return $this |
438 | 438 | */ |
439 | - public function create($data = array()) |
|
440 | - { |
|
439 | + public function create($data = array()) |
|
440 | + { |
|
441 | 441 | $this->close(); |
442 | 442 | $fld = array(); |
443 | - foreach ($this->tvd as $name => $tv) { |
|
443 | + foreach ($this->tvd as $name => $tv) { |
|
444 | 444 | $fld[$name] = $tv['value']; |
445 | 445 | }; |
446 | 446 | $this->store($fld); |
@@ -458,10 +458,10 @@ discard block |
||
458 | 458 | * @param $id |
459 | 459 | * @return $this |
460 | 460 | */ |
461 | - public function edit($id) |
|
462 | - { |
|
461 | + public function edit($id) |
|
462 | + { |
|
463 | 463 | $id = is_scalar($id) ? trim($id) : ''; |
464 | - if ($this->getID() != $id) { |
|
464 | + if ($this->getID() != $id) { |
|
465 | 465 | $this->close(); |
466 | 466 | $this->markAllEncode(); |
467 | 467 | $this->newDoc = false; |
@@ -469,12 +469,12 @@ discard block |
||
469 | 469 | $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id); |
470 | 470 | $this->fromArray($this->modx->db->getRow($result)); |
471 | 471 | $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id); |
472 | - while ($row = $this->modx->db->getRow($result)) { |
|
472 | + while ($row = $this->modx->db->getRow($result)) { |
|
473 | 473 | $this->field[$this->tvid[$row['tmplvarid']]] = $row['value']; |
474 | 474 | } |
475 | - if (empty($this->field['id'])) { |
|
475 | + if (empty($this->field['id'])) { |
|
476 | 476 | $this->id = null; |
477 | - } else { |
|
477 | + } else { |
|
478 | 478 | $this->id = $this->field['id']; |
479 | 479 | $this->set('editedby', null)->touch(); |
480 | 480 | $this->decodeFields(); |
@@ -491,10 +491,10 @@ discard block |
||
491 | 491 | * @param bool $clearCache |
492 | 492 | * @return bool|null |
493 | 493 | */ |
494 | - public function save($fire_events = false, $clearCache = false) |
|
495 | - { |
|
494 | + public function save($fire_events = false, $clearCache = false) |
|
495 | + { |
|
496 | 496 | $parent = null; |
497 | - if ($this->field['pagetitle'] == '') { |
|
497 | + if ($this->field['pagetitle'] == '') { |
|
498 | 498 | $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>'; |
499 | 499 | |
500 | 500 | return false; |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | $this->field['parent'] == 0 && |
507 | 507 | !$this->modxConfig('udperms_allowroot') && |
508 | 508 | !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) |
509 | - ) { |
|
509 | + ) { |
|
510 | 510 | $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off'; |
511 | 511 | |
512 | 512 | return false; |
@@ -522,11 +522,11 @@ discard block |
||
522 | 522 | ), $fire_events); |
523 | 523 | |
524 | 524 | $fld = $this->encodeFields()->toArray(null, null, null, false); |
525 | - foreach ($this->default_field as $key => $value) { |
|
525 | + foreach ($this->default_field as $key => $value) { |
|
526 | 526 | $tmp = $this->get($key); |
527 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
528 | - if ($tmp == $value) { |
|
529 | - switch ($key) { |
|
527 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
528 | + if ($tmp == $value) { |
|
529 | + switch ($key) { |
|
530 | 530 | case 'cacheable': |
531 | 531 | $value = $this->modxConfig('cache_default'); |
532 | 532 | break; |
@@ -546,11 +546,11 @@ discard block |
||
546 | 546 | } |
547 | 547 | $this->field[$key] = $value; |
548 | 548 | } |
549 | - switch (true) { |
|
549 | + switch (true) { |
|
550 | 550 | case $key == 'parent': |
551 | 551 | $parent = (int)$this->get($key); |
552 | 552 | $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'"); |
553 | - if ($this->modx->db->getValue($q) != 1) { |
|
553 | + if ($this->modx->db->getValue($q) != 1) { |
|
554 | 554 | $parent = 0; |
555 | 555 | } |
556 | 556 | $this->field[$key] = $parent; |
@@ -565,38 +565,38 @@ discard block |
||
565 | 565 | unset($fld[$key]); |
566 | 566 | } |
567 | 567 | |
568 | - if (!empty($this->set)) { |
|
569 | - if ($this->newDoc) { |
|
568 | + if (!empty($this->set)) { |
|
569 | + if ($this->newDoc) { |
|
570 | 570 | $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); |
571 | - } else { |
|
571 | + } else { |
|
572 | 572 | $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ', |
573 | 573 | $this->set) . " WHERE `id` = " . $this->id; |
574 | 574 | } |
575 | 575 | $this->query($SQL); |
576 | 576 | |
577 | - if ($this->newDoc) { |
|
577 | + if ($this->newDoc) { |
|
578 | 578 | $this->id = $this->modx->db->getInsertId(); |
579 | 579 | } |
580 | 580 | |
581 | - if ($parent > 0) { |
|
581 | + if ($parent > 0) { |
|
582 | 582 | $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'"); |
583 | 583 | } |
584 | 584 | } |
585 | 585 | |
586 | 586 | $_deleteTVs = $_insertTVs = array(); |
587 | - foreach ($fld as $key => $value) { |
|
588 | - if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) { |
|
587 | + foreach ($fld as $key => $value) { |
|
588 | + if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) { |
|
589 | 589 | continue; |
590 | - } elseif ($value === '') { |
|
590 | + } elseif ($value === '') { |
|
591 | 591 | $_deleteTVs[] = $this->tv[$key]; |
592 | - } else { |
|
592 | + } else { |
|
593 | 593 | $_insertTVs[$this->tv[$key]] = $this->escape($value); |
594 | 594 | } |
595 | 595 | } |
596 | 596 | |
597 | - if (!empty($_insertTVs)) { |
|
597 | + if (!empty($_insertTVs)) { |
|
598 | 598 | $values = array(); |
599 | - foreach ($_insertTVs as $id => $value) { |
|
599 | + foreach ($_insertTVs as $id => $value) { |
|
600 | 600 | $values[] = "({$this->id}, {$id}, '{$value}')"; |
601 | 601 | } |
602 | 602 | $values = implode(',', $values); |
@@ -604,17 +604,19 @@ discard block |
||
604 | 604 | `value` = VALUES(`value`)"); |
605 | 605 | } |
606 | 606 | |
607 | - if (!empty($_deleteTVs)) { |
|
607 | + if (!empty($_deleteTVs)) { |
|
608 | 608 | $ids = implode(',', $_deleteTVs); |
609 | 609 | $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})"); |
610 | 610 | } |
611 | 611 | |
612 | - if (!isset($this->mode)) { |
|
612 | + if (!isset($this->mode)) { |
|
613 | 613 | $this->mode = $this->newDoc ? "new" : "upd"; |
614 | 614 | $this->newDoc = false; |
615 | 615 | } |
616 | 616 | |
617 | - if (!empty($this->groupIds)) $this->setDocumentGroups($this->id, $this->groupIds); |
|
617 | + if (!empty($this->groupIds)) { |
|
618 | + $this->setDocumentGroups($this->id, $this->groupIds); |
|
619 | + } |
|
618 | 620 | $this->invokeEvent('OnDocFormSave', array( |
619 | 621 | 'mode' => $this->mode, |
620 | 622 | 'id' => isset($this->id) ? $this->id : '', |
@@ -622,7 +624,7 @@ discard block |
||
622 | 624 | 'docObj' => $this |
623 | 625 | ), $fire_events); |
624 | 626 | |
625 | - if ($clearCache) { |
|
627 | + if ($clearCache) { |
|
626 | 628 | $this->clearCache($fire_events); |
627 | 629 | } |
628 | 630 | $this->decodeFields(); |
@@ -634,7 +636,8 @@ discard block |
||
634 | 636 | * @param $tvId |
635 | 637 | * @return bool |
636 | 638 | */ |
637 | - protected function belongsToTemplate($tvId) { |
|
639 | + protected function belongsToTemplate($tvId) |
|
640 | + { |
|
638 | 641 | $template = $this->get('template'); |
639 | 642 | |
640 | 643 | return isset($this->tvTpl[$template]) && in_array($tvId, $this->tvTpl[$template]); |
@@ -645,16 +648,16 @@ discard block |
||
645 | 648 | * @return $this |
646 | 649 | * @throws Exception |
647 | 650 | */ |
648 | - public function toTrash($ids) |
|
649 | - { |
|
651 | + public function toTrash($ids) |
|
652 | + { |
|
650 | 653 | $ignore = $this->systemID(); |
651 | 654 | $_ids = $this->cleanIDs($ids, ',', $ignore); |
652 | - if (is_array($_ids) && $_ids != array()) { |
|
655 | + if (is_array($_ids) && $_ids != array()) { |
|
653 | 656 | $id = $this->sanitarIn($_ids); |
654 | 657 | $uid = (int)$this->modx->getLoginUserId(); |
655 | 658 | $deletedon = time() + $this->modxConfig('server_offset_time'); |
656 | 659 | $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})"); |
657 | - } else { |
|
660 | + } else { |
|
658 | 661 | throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, |
659 | 662 | 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
660 | 663 | } |
@@ -666,11 +669,11 @@ discard block |
||
666 | 669 | * @param bool $fire_events |
667 | 670 | * @return $this |
668 | 671 | */ |
669 | - public function clearTrash($fire_events = false) |
|
670 | - { |
|
672 | + public function clearTrash($fire_events = false) |
|
673 | + { |
|
671 | 674 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'"); |
672 | 675 | $_ids = $this->modx->db->getColumn('id', $q); |
673 | - if (is_array($_ids) && $_ids != array()) { |
|
676 | + if (is_array($_ids) && $_ids != array()) { |
|
674 | 677 | $this->invokeEvent('OnBeforeEmptyTrash', array( |
675 | 678 | "ids" => $_ids |
676 | 679 | ), $fire_events); |
@@ -692,15 +695,15 @@ discard block |
||
692 | 695 | * @param int|bool $depth |
693 | 696 | * @return array |
694 | 697 | */ |
695 | - public function children($ids, $depth) |
|
696 | - { |
|
698 | + public function children($ids, $depth) |
|
699 | + { |
|
697 | 700 | $_ids = $this->cleanIDs($ids, ','); |
698 | - if (is_array($_ids) && $_ids != array()) { |
|
701 | + if (is_array($_ids) && $_ids != array()) { |
|
699 | 702 | $id = $this->sanitarIn($_ids); |
700 | - if (!empty($id)) { |
|
703 | + if (!empty($id)) { |
|
701 | 704 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); |
702 | 705 | $id = $this->modx->db->getColumn('id', $q); |
703 | - if ($depth > 0 || $depth === true) { |
|
706 | + if ($depth > 0 || $depth === true) { |
|
704 | 707 | $id = $this->children($id, is_bool($depth) ? $depth : ($depth - 1)); |
705 | 708 | } |
706 | 709 | $_ids = array_merge($_ids, $id); |
@@ -716,8 +719,8 @@ discard block |
||
716 | 719 | * @return $this |
717 | 720 | * @throws Exception |
718 | 721 | */ |
719 | - public function delete($ids, $fire_events = false) |
|
720 | - { |
|
722 | + public function delete($ids, $fire_events = false) |
|
723 | + { |
|
721 | 724 | $ids = $this->children($ids, true); |
722 | 725 | $_ids = $this->cleanIDs($ids, ',', $this->systemID()); |
723 | 726 | $this->invokeEvent('OnBeforeDocFormDelete', array( |
@@ -734,8 +737,8 @@ discard block |
||
734 | 737 | /** |
735 | 738 | * @return array |
736 | 739 | */ |
737 | - private function systemID() |
|
738 | - { |
|
740 | + private function systemID() |
|
741 | + { |
|
739 | 742 | $ignore = array( |
740 | 743 | 0, //empty document |
741 | 744 | (int)$this->modxConfig('site_start'), |
@@ -745,7 +748,7 @@ discard block |
||
745 | 748 | ); |
746 | 749 | $data = $this->query("SELECT DISTINCT setting_value FROM {$this->makeTable('web_user_settings')} WHERE `setting_name`='login_home' AND `setting_value`!=''"); |
747 | 750 | $data = $this->modx->db->makeArray($data); |
748 | - foreach ($data as $item) { |
|
751 | + foreach ($data as $item) { |
|
749 | 752 | $ignore[] = (int)$item['setting_value']; |
750 | 753 | } |
751 | 754 | |
@@ -757,22 +760,22 @@ discard block |
||
757 | 760 | * @param $alias |
758 | 761 | * @return string |
759 | 762 | */ |
760 | - protected function checkAlias($alias) |
|
761 | - { |
|
763 | + protected function checkAlias($alias) |
|
764 | + { |
|
762 | 765 | $alias = strtolower($alias); |
763 | - if ($this->modxConfig('friendly_urls')) { |
|
766 | + if ($this->modxConfig('friendly_urls')) { |
|
764 | 767 | $_alias = $this->escape($alias); |
765 | - if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
768 | + if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
766 | 769 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1")); |
767 | - } else { |
|
770 | + } else { |
|
768 | 771 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1")); |
769 | 772 | } |
770 | - if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) { |
|
773 | + if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) { |
|
771 | 774 | $suffix = substr($alias, -2); |
772 | - if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { |
|
775 | + if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { |
|
773 | 776 | $suffix = (int)$tmp[1] + 1; |
774 | 777 | $alias = substr($alias, 0, -2) . '-' . $suffix; |
775 | - } else { |
|
778 | + } else { |
|
776 | 779 | $alias .= '-2'; |
777 | 780 | } |
778 | 781 | $alias = $this->checkAlias($alias); |
@@ -786,8 +789,8 @@ discard block |
||
786 | 789 | * @param $key |
787 | 790 | * @return bool |
788 | 791 | */ |
789 | - public function issetField($key) |
|
790 | - { |
|
792 | + public function issetField($key) |
|
793 | + { |
|
791 | 794 | return (array_key_exists($key, $this->default_field) || array_key_exists($key, $this->tv)); |
792 | 795 | } |
793 | 796 | |
@@ -795,12 +798,12 @@ discard block |
||
795 | 798 | * @param bool $reload |
796 | 799 | * @return $this |
797 | 800 | */ |
798 | - protected function get_TV($reload = false) |
|
799 | - { |
|
801 | + protected function get_TV($reload = false) |
|
802 | + { |
|
800 | 803 | $this->modx->_TVnames = array(); |
801 | - if (empty($this->modx->_TVnames) || $reload) { |
|
804 | + if (empty($this->modx->_TVnames) || $reload) { |
|
802 | 805 | $result = $this->query('SELECT `id`,`name`,`type` FROM ' . $this->makeTable('site_tmplvars')); |
803 | - while ($row = $this->modx->db->GetRow($result)) { |
|
806 | + while ($row = $this->modx->db->GetRow($result)) { |
|
804 | 807 | $this->modx->_TVnames[$row['name']] = array( |
805 | 808 | "id" => $row['id'], |
806 | 809 | "type" => $row['type'] |
@@ -809,14 +812,16 @@ discard block |
||
809 | 812 | } |
810 | 813 | $arrayTypes = array('checkbox', 'listbox-multiple'); |
811 | 814 | $arrayTVs = array(); |
812 | - foreach ($this->modx->_TVnames as $name => $data) { |
|
815 | + foreach ($this->modx->_TVnames as $name => $data) { |
|
813 | 816 | $this->tvid[$data['id']] = $name; |
814 | 817 | $this->tv[$name] = $data['id']; |
815 | - if (in_array($data['type'], $arrayTypes)) { |
|
818 | + if (in_array($data['type'], $arrayTypes)) { |
|
816 | 819 | $arrayTVs[] = $name; |
817 | 820 | } |
818 | 821 | } |
819 | - if (empty($this->tvaFields)) $this->tvaFields = $arrayTVs; |
|
822 | + if (empty($this->tvaFields)) { |
|
823 | + $this->tvaFields = $arrayTVs; |
|
824 | + } |
|
820 | 825 | $this->loadTVTemplate()->loadTVDefault(array_values($this->tv)); |
821 | 826 | |
822 | 827 | return $this; |
@@ -825,12 +830,12 @@ discard block |
||
825 | 830 | /** |
826 | 831 | * @return $this |
827 | 832 | */ |
828 | - protected function loadTVTemplate() |
|
829 | - { |
|
833 | + protected function loadTVTemplate() |
|
834 | + { |
|
830 | 835 | $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates')); |
831 | 836 | $q = $this->modx->db->makeArray($q); |
832 | 837 | $this->tvTpl = array(); |
833 | - foreach ($q as $item) { |
|
838 | + foreach ($q as $item) { |
|
834 | 839 | $this->tvTpl[$item['templateid']][] = $item['tmplvarid']; |
835 | 840 | } |
836 | 841 | |
@@ -841,16 +846,16 @@ discard block |
||
841 | 846 | * @param array $tvId |
842 | 847 | * @return $this |
843 | 848 | */ |
844 | - protected function loadTVDefault(array $tvId = array()) |
|
845 | - { |
|
846 | - if (is_array($tvId) && !empty($tvId)) { |
|
849 | + protected function loadTVDefault(array $tvId = array()) |
|
850 | + { |
|
851 | + if (is_array($tvId) && !empty($tvId)) { |
|
847 | 852 | $tbl_site_tmplvars = $this->makeTable('site_tmplvars'); |
848 | 853 | $fields = 'id,name,default_text as value,display,display_params,type'; |
849 | 854 | $implodeTvId = implode(',', $tvId); |
850 | 855 | $rs = $this->query("SELECT {$fields} FROM {$tbl_site_tmplvars} WHERE id IN({$implodeTvId})"); |
851 | 856 | $rows = $this->modx->db->makeArray($rs); |
852 | 857 | $this->tvd = array(); |
853 | - foreach ($rows as $item) { |
|
858 | + foreach ($rows as $item) { |
|
854 | 859 | $this->tvd[$item['name']] = $item; |
855 | 860 | } |
856 | 861 | } |
@@ -863,17 +868,17 @@ discard block |
||
863 | 868 | * @return int |
864 | 869 | * @throws Exception |
865 | 870 | */ |
866 | - public function setTemplate($tpl) |
|
867 | - { |
|
868 | - if (!is_numeric($tpl) || $tpl != (int)$tpl) { |
|
869 | - if (is_scalar($tpl)) { |
|
871 | + public function setTemplate($tpl) |
|
872 | + { |
|
873 | + if (!is_numeric($tpl) || $tpl != (int)$tpl) { |
|
874 | + if (is_scalar($tpl)) { |
|
870 | 875 | $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'"; |
871 | 876 | $rs = $this->query($sql); |
872 | - if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
877 | + if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
873 | 878 | throw new Exception("Template {$tpl} is not exists"); |
874 | 879 | } |
875 | 880 | $tpl = $this->modx->db->getValue($rs); |
876 | - } else { |
|
881 | + } else { |
|
877 | 882 | throw new Exception("Invalid template name: " . print_r($tpl, 1)); |
878 | 883 | } |
879 | 884 | } |
@@ -884,14 +889,14 @@ discard block |
||
884 | 889 | /** |
885 | 890 | * @return string |
886 | 891 | */ |
887 | - protected function getAlias() |
|
888 | - { |
|
889 | - if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') { |
|
892 | + protected function getAlias() |
|
893 | + { |
|
894 | + if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') { |
|
890 | 895 | $alias = strtr($this->get('pagetitle'), $this->table); |
891 | - } else { |
|
892 | - if ($this->get('alias') != '') { |
|
896 | + } else { |
|
897 | + if ($this->get('alias') != '') { |
|
893 | 898 | $alias = $this->get('alias'); |
894 | - } else { |
|
899 | + } else { |
|
895 | 900 | $alias = ''; |
896 | 901 | } |
897 | 902 | } |
@@ -908,10 +913,10 @@ discard block |
||
908 | 913 | * |
909 | 914 | * Пересчет menuindex по полю таблицы site_content |
910 | 915 | */ |
911 | - public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc') |
|
912 | - { |
|
916 | + public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc') |
|
917 | + { |
|
913 | 918 | $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc'; |
914 | - if (is_integer($parent) && $criteria !== '') { |
|
919 | + if (is_integer($parent) && $criteria !== '') { |
|
915 | 920 | $this->query("SET @index := 0"); |
916 | 921 | $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}"); |
917 | 922 | } |
@@ -924,37 +929,37 @@ discard block |
||
924 | 929 | * |
925 | 930 | * @return $this |
926 | 931 | */ |
927 | - public function setDefaultTemplate() |
|
928 | - { |
|
932 | + public function setDefaultTemplate() |
|
933 | + { |
|
929 | 934 | $parent = $this->get('parent'); |
930 | 935 | $template = $this->modxConfig('default_template'); |
931 | - switch ($this->modxConfig('auto_template_logic')) { |
|
936 | + switch ($this->modxConfig('auto_template_logic')) { |
|
932 | 937 | case 'sibling': |
933 | - if (!$parent) { |
|
938 | + if (!$parent) { |
|
934 | 939 | $site_start = $this->modxConfig('site_start'); |
935 | 940 | $where = "sc.isfolder=0 AND sc.id!={$site_start}"; |
936 | 941 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1); |
937 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
942 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
938 | 943 | $template = $sibl[0]['template']; |
939 | 944 | } |
940 | - } else { |
|
945 | + } else { |
|
941 | 946 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', 'isfolder=0', 'menuindex', |
942 | 947 | 'ASC', 1); |
943 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
948 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
944 | 949 | $template = $sibl[0]['template']; |
945 | - } else { |
|
950 | + } else { |
|
946 | 951 | $sibl = $this->modx->getDocumentChildren($parent, 0, 0, 'template', 'isfolder=0', 'menuindex', |
947 | 952 | 'ASC', 1); |
948 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
953 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
949 | 954 | $template = $sibl[0]['template']; |
950 | 955 | } |
951 | 956 | } |
952 | 957 | } |
953 | 958 | break; |
954 | 959 | case 'parent': |
955 | - if ($parent) { |
|
960 | + if ($parent) { |
|
956 | 961 | $_parent = $this->modx->getPageInfo($parent, 0, 'template'); |
957 | - if (isset($_parent['template'])) { |
|
962 | + if (isset($_parent['template'])) { |
|
958 | 963 | $template = $_parent['template']; |
959 | 964 | } |
960 | 965 | } |
@@ -971,18 +976,18 @@ discard block |
||
971 | 976 | * @param bool $store обновить распакованное поле |
972 | 977 | * @return array ассоциативный массив с данными из json строки |
973 | 978 | */ |
974 | - public function decodeField($field, $store = false) |
|
975 | - { |
|
979 | + public function decodeField($field, $store = false) |
|
980 | + { |
|
976 | 981 | $out = array(); |
977 | - if ($this->isDecodableField($field)) { |
|
982 | + if ($this->isDecodableField($field)) { |
|
978 | 983 | $data = $this->get($field); |
979 | - if ($this->isTVarrayField($field)) { |
|
984 | + if ($this->isTVarrayField($field)) { |
|
980 | 985 | $out = explode('||', $data); |
981 | - } else { |
|
986 | + } else { |
|
982 | 987 | $out = jsonHelper::jsonDecode($data, array('assoc' => true), true); |
983 | 988 | } |
984 | 989 | } |
985 | - if ($store) { |
|
990 | + if ($store) { |
|
986 | 991 | $this->field[$field] = $out; |
987 | 992 | $this->markAsDecode($field); |
988 | 993 | } |
@@ -996,18 +1001,18 @@ discard block |
||
996 | 1001 | * @param bool $store обновить запакованное поле |
997 | 1002 | * @return string|null json строка |
998 | 1003 | */ |
999 | - public function encodeField($field, $store = false) |
|
1000 | - { |
|
1004 | + public function encodeField($field, $store = false) |
|
1005 | + { |
|
1001 | 1006 | $out = null; |
1002 | - if ($this->isEncodableField($field)) { |
|
1007 | + if ($this->isEncodableField($field)) { |
|
1003 | 1008 | $data = $this->get($field); |
1004 | - if ($this->isTVarrayField($field)) { |
|
1009 | + if ($this->isTVarrayField($field)) { |
|
1005 | 1010 | $out = is_array($data) ? implode('||', $data) : (string)$data; |
1006 | - } else { |
|
1011 | + } else { |
|
1007 | 1012 | $out = json_encode($data); |
1008 | 1013 | } |
1009 | 1014 | } |
1010 | - if ($store) { |
|
1015 | + if ($store) { |
|
1011 | 1016 | $this->field[$field] = $out; |
1012 | 1017 | $this->markAsEncode($field); |
1013 | 1018 | } |
@@ -1020,8 +1025,8 @@ discard block |
||
1020 | 1025 | * @param string $field имя поля |
1021 | 1026 | * @return boolean |
1022 | 1027 | */ |
1023 | - public function isTVarrayField($field) |
|
1024 | - { |
|
1028 | + public function isTVarrayField($field) |
|
1029 | + { |
|
1025 | 1030 | return (is_scalar($field) && in_array($field, $this->tvaFields)); |
1026 | 1031 | } |
1027 | 1032 | |
@@ -1029,10 +1034,10 @@ discard block |
||
1029 | 1034 | * Пометить все поля как запакованные |
1030 | 1035 | * @return $this |
1031 | 1036 | */ |
1032 | - public function markAllEncode() |
|
1033 | - { |
|
1037 | + public function markAllEncode() |
|
1038 | + { |
|
1034 | 1039 | parent::markAllEncode(); |
1035 | - foreach ($this->tvaFields as $field) { |
|
1040 | + foreach ($this->tvaFields as $field) { |
|
1036 | 1041 | $this->markAsEncode($field); |
1037 | 1042 | } |
1038 | 1043 | |
@@ -1043,10 +1048,10 @@ discard block |
||
1043 | 1048 | * Пометить все поля как распакованные |
1044 | 1049 | * @return $this |
1045 | 1050 | */ |
1046 | - public function markAllDecode() |
|
1047 | - { |
|
1051 | + public function markAllDecode() |
|
1052 | + { |
|
1048 | 1053 | parent::markAllDecode(); |
1049 | - foreach ($this->tvaFields as $field) { |
|
1054 | + foreach ($this->tvaFields as $field) { |
|
1050 | 1055 | $this->markAsDecode($field); |
1051 | 1056 | } |
1052 | 1057 | |
@@ -1056,16 +1061,17 @@ discard block |
||
1056 | 1061 | /** |
1057 | 1062 | * @param int $docId |
1058 | 1063 | */ |
1059 | - public function getDocumentGroups($docId = 0) { |
|
1064 | + public function getDocumentGroups($docId = 0) |
|
1065 | + { |
|
1060 | 1066 | $out = array(); |
1061 | 1067 | $doc = $this->switchObject($docId); |
1062 | - if (null !== $doc->getID()) { |
|
1068 | + if (null !== $doc->getID()) { |
|
1063 | 1069 | $doc_groups = $this->makeTable('document_groups'); |
1064 | 1070 | $docgroup_names = $this->makeTable('documentgroup_names'); |
1065 | 1071 | |
1066 | 1072 | $rs = $this->query("SELECT `dg`.`document_group`, `dgn`.`name` FROM {$doc_groups} as `dg` INNER JOIN {$docgroup_names} as `dgn` ON `dgn`.`id`=`dg`.`document_group` |
1067 | 1073 | WHERE `dg`.`document` = " . $doc->getID()); |
1068 | - while ($row = $this->modx->db->getRow($rs)) { |
|
1074 | + while ($row = $this->modx->db->getRow($rs)) { |
|
1069 | 1075 | $out[$row['document_group']] = $row['name']; |
1070 | 1076 | } |
1071 | 1077 | |
@@ -1080,18 +1086,20 @@ discard block |
||
1080 | 1086 | * @param array $groupIds |
1081 | 1087 | * @return $this |
1082 | 1088 | */ |
1083 | - public function setDocumentGroups($docId = 0, $groupIds = array()) |
|
1084 | - { |
|
1085 | - if (!is_array($groupIds)) return $this; |
|
1086 | - if ($this->newDoc && $docId == 0) { |
|
1089 | + public function setDocumentGroups($docId = 0, $groupIds = array()) |
|
1090 | + { |
|
1091 | + if (!is_array($groupIds)) { |
|
1092 | + return $this; |
|
1093 | + } |
|
1094 | + if ($this->newDoc && $docId == 0) { |
|
1087 | 1095 | $this->groupIds = $groupIds; |
1088 | - } else { |
|
1096 | + } else { |
|
1089 | 1097 | $doc = $this->switchObject($docId); |
1090 | - if ($id = $doc->getID()) { |
|
1091 | - foreach ($groupIds as $gid) { |
|
1098 | + if ($id = $doc->getID()) { |
|
1099 | + foreach ($groupIds as $gid) { |
|
1092 | 1100 | $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')"); |
1093 | 1101 | } |
1094 | - if (!$this->newDoc) { |
|
1102 | + if (!$this->newDoc) { |
|
1095 | 1103 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
1096 | 1104 | $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})"); |
1097 | 1105 | } |
@@ -8,8 +8,8 @@ discard block |
||
8 | 8 | * Class dataTable |
9 | 9 | * @package SimpleTab |
10 | 10 | */ |
11 | -class dataTable extends \autoTable |
|
12 | -{ |
|
11 | +class dataTable extends \autoTable |
|
12 | +{ |
|
13 | 13 | /** |
14 | 14 | * @var array |
15 | 15 | */ |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | * @param \DocumentParser $modx |
41 | 41 | * @param bool $debug |
42 | 42 | */ |
43 | - public function __construct($modx, $debug = false) |
|
44 | - { |
|
43 | + public function __construct($modx, $debug = false) |
|
44 | + { |
|
45 | 45 | parent::__construct($modx, $debug); |
46 | 46 | $this->modx = $modx; |
47 | 47 | $this->fs = \Helpers\FS::getInstance(); |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @param $ids |
52 | 52 | * @param $rid |
53 | 53 | */ |
54 | - protected function clearIndexes($ids, $rid) |
|
55 | - { |
|
54 | + protected function clearIndexes($ids, $rid) |
|
55 | + { |
|
56 | 56 | $ids = $this->cleanIDs($ids, ',', array(0)); |
57 | 57 | $ids = $this->sanitarIn($ids); |
58 | 58 | $table = $this->makeTable($this->table); |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | * @param $field |
71 | 71 | * @return $this |
72 | 72 | */ |
73 | - public function touch($field) |
|
74 | - { |
|
73 | + public function touch($field) |
|
74 | + { |
|
75 | 75 | $this->set($field, date('Y-m-d H:i:s', time() + $this->modx->config['server_offset_time'])); |
76 | 76 | |
77 | 77 | return $this; |
@@ -82,22 +82,22 @@ discard block |
||
82 | 82 | * @param $dir |
83 | 83 | * @param $rid |
84 | 84 | */ |
85 | - public function place($ids, $dir, $rid) |
|
86 | - { |
|
85 | + public function place($ids, $dir, $rid) |
|
86 | + { |
|
87 | 87 | $table = $this->makeTable($this->table); |
88 | 88 | $ids = $this->cleanIDs($ids, ',', array(0)); |
89 | - if (empty($ids) || is_scalar($ids)) { |
|
89 | + if (empty($ids) || is_scalar($ids)) { |
|
90 | 90 | return false; |
91 | 91 | } |
92 | 92 | $rows = $this->query("SELECT count(`{$this->pkName}`) FROM {$table} WHERE `{$this->rfName}`={$rid}"); |
93 | 93 | $index = $this->modx->db->getValue($rows); |
94 | 94 | $cnt = count($ids); |
95 | 95 | $ids = implode(',', $ids); |
96 | - if ($dir == 'top') { |
|
96 | + if ($dir == 'top') { |
|
97 | 97 | $this->query("SET @index := " . ($index - $cnt - 1)); |
98 | 98 | $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC"); |
99 | 99 | $this->query("SET @index := -1"); |
100 | - } else { |
|
100 | + } else { |
|
101 | 101 | $this->query("SET @index := -1"); |
102 | 102 | $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC"); |
103 | 103 | $this->query("SET @index := " . ($cnt - 1)); |
@@ -112,26 +112,26 @@ discard block |
||
112 | 112 | * @param $url |
113 | 113 | * @param bool $cache |
114 | 114 | */ |
115 | - public function deleteThumb($url, $cache = false) |
|
116 | - { |
|
115 | + public function deleteThumb($url, $cache = false) |
|
116 | + { |
|
117 | 117 | $url = $this->fs->relativePath($url); |
118 | - if (empty($url)) { |
|
118 | + if (empty($url)) { |
|
119 | 119 | return; |
120 | 120 | } |
121 | - if ($this->fs->checkFile($url)) { |
|
121 | + if ($this->fs->checkFile($url)) { |
|
122 | 122 | unlink(MODX_BASE_PATH . $url); |
123 | 123 | } |
124 | 124 | $dir = $this->fs->takeFileDir($url); |
125 | 125 | $iterator = new \FilesystemIterator($dir); |
126 | - if (!$iterator->valid()) { |
|
126 | + if (!$iterator->valid()) { |
|
127 | 127 | rmdir($dir); |
128 | 128 | } |
129 | - if ($cache) { |
|
129 | + if ($cache) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | $thumbsCache = \APIhelpers::getkey($this->params,'thumbsCache',$this->thumbsCache); |
133 | 133 | $thumb = $thumbsCache . $url; |
134 | - if ($this->fs->checkFile($thumb)) { |
|
134 | + if ($this->fs->checkFile($thumb)) { |
|
135 | 135 | $this->deleteThumb($thumb, true); |
136 | 136 | } |
137 | 137 | } |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | * @param bool $fire_events |
142 | 142 | * @return $this |
143 | 143 | */ |
144 | - public function delete($ids, $fire_events = false) |
|
145 | - { |
|
144 | + public function delete($ids, $fire_events = false) |
|
145 | + { |
|
146 | 146 | $out = parent::delete($ids, $fire_events); |
147 | 147 | $this->query("ALTER TABLE {$this->makeTable($this->table)} AUTO_INCREMENT = 1"); |
148 | 148 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * @param bool $fire_events |
156 | 156 | * @return $this |
157 | 157 | */ |
158 | - public function deleteAll($ids, $rid, $fire_events = false) |
|
159 | - { |
|
158 | + public function deleteAll($ids, $rid, $fire_events = false) |
|
159 | + { |
|
160 | 160 | $this->clearIndexes($ids, $rid); |
161 | 161 | |
162 | 162 | return $this->delete($ids, $fire_events); |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | /** |
166 | 166 | * @return array |
167 | 167 | */ |
168 | - public function fieldNames() |
|
169 | - { |
|
168 | + public function fieldNames() |
|
169 | + { |
|
170 | 170 | $fields = array_keys($this->getDefaultFields()); |
171 | 171 | $fields[] = $this->fieldPKName(); |
172 | 172 | |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | * @param string $name |
178 | 178 | * @return string |
179 | 179 | */ |
180 | - public function stripName($name) |
|
181 | - { |
|
180 | + public function stripName($name) |
|
181 | + { |
|
182 | 182 | |
183 | 183 | $filename = $this->fs->takeFileName($name); |
184 | 184 | $ext = $this->fs->takeFileExt($name); |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | * @param $orderDir |
195 | 195 | * @return int|void |
196 | 196 | */ |
197 | - public function reorder($source, $target, $point, $rid, $orderDir) |
|
198 | - { |
|
197 | + public function reorder($source, $target, $point, $rid, $orderDir) |
|
198 | + { |
|
199 | 199 | $rid = (int)$rid; |
200 | 200 | $point = strtolower($point); |
201 | 201 | $orderDir = strtolower($orderDir); |
@@ -205,25 +205,25 @@ discard block |
||
205 | 205 | $table = $this->makeTable($this->table); |
206 | 206 | $rows = 0; |
207 | 207 | /* more refactoring needed */ |
208 | - if ($targetIndex < $sourceIndex) { |
|
209 | - if (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) { |
|
208 | + if ($targetIndex < $sourceIndex) { |
|
209 | + if (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) { |
|
210 | 210 | $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`+1", $table, |
211 | 211 | "`{$this->indexName}`>={$targetIndex} AND `{$this->indexName}`<{$sourceIndex} AND `{$this->rfName}`={$rid}"); |
212 | 212 | $rows = $this->modx->db->update("`{$this->indexName}`={$targetIndex}", $table, |
213 | 213 | "`{$this->pkName}`={$sourceId}"); |
214 | - } elseif (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) { |
|
214 | + } elseif (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) { |
|
215 | 215 | $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`+1", $table, |
216 | 216 | "`{$this->indexName}`>{$targetIndex} AND `{$this->indexName}`<{$sourceIndex} AND `{$this->rfName}`={$rid}"); |
217 | 217 | $rows = $this->modx->db->update("`{$this->indexName}`=1+{$targetIndex}", $table, |
218 | 218 | "`{$this->pkName}`={$sourceId}"); |
219 | 219 | } |
220 | - } else { |
|
221 | - if (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) { |
|
220 | + } else { |
|
221 | + if (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) { |
|
222 | 222 | $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`-1", $table, |
223 | 223 | "`{$this->indexName}`<={$targetIndex} AND `{$this->indexName}`>={$sourceIndex} AND `{$this->rfName}`={$rid}"); |
224 | 224 | $rows = $this->modx->db->update("`{$this->indexName}`={$targetIndex}", $table, |
225 | 225 | "`{$this->pkName}`={$sourceId}"); |
226 | - } elseif (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) { |
|
226 | + } elseif (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) { |
|
227 | 227 | $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`-1", $table, |
228 | 228 | "`{$this->indexName}`<{$targetIndex} AND `{$this->indexName}`>={$sourceIndex} AND `{$this->rfName}`={$rid}"); |
229 | 229 | $rows = $this->modx->db->update("`{$this->indexName}`=-1+{$targetIndex}", $table, |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | * @param $options |
241 | 241 | * @return bool |
242 | 242 | */ |
243 | - public function makeThumb($folder, $url, $options) |
|
244 | - { |
|
245 | - if (empty($url)) { |
|
243 | + public function makeThumb($folder, $url, $options) |
|
244 | + { |
|
245 | + if (empty($url)) { |
|
246 | 246 | return false; |
247 | 247 | } |
248 | 248 | $thumb = new \Helpers\PHPThumb(); |
@@ -250,9 +250,9 @@ discard block |
||
250 | 250 | $outputFile = MODX_BASE_PATH . $this->fs->relativePath($folder) . '/' . $this->fs->relativePath($url); |
251 | 251 | $dir = $this->fs->takeFileDir($outputFile); |
252 | 252 | $this->fs->makeDir($dir, $this->modx->config['new_folder_permissions']); |
253 | - if ($thumb->create($inputFile, $outputFile, $options)) { |
|
253 | + if ($thumb->create($inputFile, $outputFile, $options)) { |
|
254 | 254 | return true; |
255 | - } else { |
|
255 | + } else { |
|
256 | 256 | $this->modx->logEvent(0, 3, $thumb->debugMessages, __NAMESPACE__); |
257 | 257 | |
258 | 258 | return false; |
@@ -262,16 +262,18 @@ discard block |
||
262 | 262 | /** |
263 | 263 | * @return array |
264 | 264 | */ |
265 | - public function getParams() |
|
266 | - { |
|
265 | + public function getParams() |
|
266 | + { |
|
267 | 267 | return $this->params; |
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
271 | 271 | * @param array $params |
272 | 272 | */ |
273 | - public function setParams($params = array()) |
|
274 | - { |
|
275 | - if (is_array($params)) $this->params = $params; |
|
273 | + public function setParams($params = array()) |
|
274 | + { |
|
275 | + if (is_array($params)) { |
|
276 | + $this->params = $params; |
|
277 | + } |
|
276 | 278 | } |
277 | 279 | } |
@@ -76,7 +76,7 @@ |
||
76 | 76 | { |
77 | 77 | $options = strtr($options, Array("," => "&", "_" => "=", '{' => '[', '}' => ']')); |
78 | 78 | parse_str($options, $params); |
79 | - if(!is_array($params)) $params = array(); |
|
79 | + if ( ! is_array($params)) $params = array(); |
|
80 | 80 | |
81 | 81 | foreach ($params as $key => $value) { |
82 | 82 | $this->thumb->setParameter($key, $value); |
@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | * Class PHPThumb |
8 | 8 | * @package Helpers |
9 | 9 | */ |
10 | -class PHPThumb |
|
11 | -{ |
|
10 | +class PHPThumb |
|
11 | +{ |
|
12 | 12 | |
13 | 13 | private $thumb = null; |
14 | 14 | protected $fs = null; |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * PHPThumb constructor. |
19 | 19 | */ |
20 | - public function __construct() |
|
21 | - { |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | 22 | $this->thumb = new \phpthumb(); |
23 | 23 | $this->fs = FS::getInstance(); |
24 | 24 | } |
@@ -29,16 +29,16 @@ discard block |
||
29 | 29 | * @param $options |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - public function create($inputFile, $outputFile, $options) |
|
33 | - { |
|
32 | + public function create($inputFile, $outputFile, $options) |
|
33 | + { |
|
34 | 34 | $this->thumb->sourceFilename = $inputFile; |
35 | 35 | $ext = explode('.', $inputFile); |
36 | 36 | $ext = str_replace('jpeg', 'jpg', strtolower(array_pop($ext))); |
37 | 37 | $options = 'f=' . $ext . '&' . $options; |
38 | 38 | $this->setOptions($options); |
39 | - if ($this->thumb->GenerateThumbnail() && $this->thumb->RenderToFile($outputFile)) { |
|
39 | + if ($this->thumb->GenerateThumbnail() && $this->thumb->RenderToFile($outputFile)) { |
|
40 | 40 | return true; |
41 | - } else { |
|
41 | + } else { |
|
42 | 42 | $this->debugMessages = implode('<br/>', $this->thumb->debugmessages); |
43 | 43 | |
44 | 44 | return false; |
@@ -49,17 +49,17 @@ discard block |
||
49 | 49 | * @param $file |
50 | 50 | * @param string $type |
51 | 51 | */ |
52 | - public function optimize($file, $type = 'jpg') |
|
53 | - { |
|
54 | - switch ($type) { |
|
52 | + public function optimize($file, $type = 'jpg') |
|
53 | + { |
|
54 | + switch ($type) { |
|
55 | 55 | case 'jpg': |
56 | 56 | $ext = $this->fs->takeFileExt($file); |
57 | - if ($ext == 'jpeg' || $ext == 'jpg') { |
|
57 | + if ($ext == 'jpeg' || $ext == 'jpg') { |
|
58 | 58 | $cmd = '/usr/bin/jpegtran -optimize -progressive -copy none -outfile ' . escapeshellarg($file . '_') . ' ' . escapeshellarg($file); |
59 | 59 | exec($cmd, $result, $return_var); |
60 | - if ($this->fs->fileSize($file) > $this->fs->fileSize($file . '_')) { |
|
60 | + if ($this->fs->fileSize($file) > $this->fs->fileSize($file . '_')) { |
|
61 | 61 | $this->fs->moveFile($file . '_', $file); |
62 | - } else { |
|
62 | + } else { |
|
63 | 63 | $this->fs->unlink($file . '_'); |
64 | 64 | } |
65 | 65 | } |
@@ -72,13 +72,15 @@ discard block |
||
72 | 72 | /** |
73 | 73 | * @param $options |
74 | 74 | */ |
75 | - private function setOptions($options) |
|
76 | - { |
|
75 | + private function setOptions($options) |
|
76 | + { |
|
77 | 77 | $options = strtr($options, Array("," => "&", "_" => "=", '{' => '[', '}' => ']')); |
78 | 78 | parse_str($options, $params); |
79 | - if(!is_array($params)) $params = array(); |
|
79 | + if(!is_array($params)) { |
|
80 | + $params = array(); |
|
81 | + } |
|
80 | 82 | |
81 | - foreach ($params as $key => $value) { |
|
83 | + foreach ($params as $key => $value) { |
|
82 | 84 | $this->thumb->setParameter($key, $value); |
83 | 85 | } |
84 | 86 | } |
@@ -74,7 +74,7 @@ |
||
74 | 74 | */ |
75 | 75 | private function setOptions($options) |
76 | 76 | { |
77 | - $options = strtr($options, Array("," => "&", "_" => "=", '{' => '[', '}' => ']')); |
|
77 | + $options = strtr($options, array("," => "&", "_" => "=", '{' => '[', '}' => ']')); |
|
78 | 78 | parse_str($options, $params); |
79 | 79 | if(!is_array($params)) $params = array(); |
80 | 80 |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | } // Non-quoted variable name |
834 | 834 | else { |
835 | 835 | preg_match('/^(' . $string[0] . '[a-zA-Z0-9\._\$]+)/', $string, $matches); |
836 | - if (!empty($matches)) { |
|
836 | + if ( ! empty($matches)) { |
|
837 | 837 | $ret[self::TOKEN_VALUE] = $matches[1]; |
838 | 838 | } |
839 | 839 | } |
@@ -862,7 +862,7 @@ discard block |
||
862 | 862 | |
863 | 863 | // A reserved word cannot be preceded by a '.' |
864 | 864 | // this makes it so in "mytable.from", "from" is not considered a reserved word |
865 | - if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') { |
|
865 | + if ( ! $previous || ! isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') { |
|
866 | 866 | $upper = strtoupper($string); |
867 | 867 | // Top Level Reserved Word |
868 | 868 | if (preg_match('/^(' . self::$regex_reserved_toplevel . ')($|\s|' . self::$regex_boundaries . ')/', $upper, |
@@ -1118,7 +1118,7 @@ discard block |
||
1118 | 1118 | $length = 0; |
1119 | 1119 | for ($j = 1; $j <= 250; $j++) { |
1120 | 1120 | // Reached end of string |
1121 | - if (!isset($tokens[$i + $j])) { |
|
1121 | + if ( ! isset($tokens[$i + $j])) { |
|
1122 | 1122 | break; |
1123 | 1123 | } |
1124 | 1124 | |
@@ -1156,7 +1156,7 @@ discard block |
||
1156 | 1156 | $return = rtrim($return, ' '); |
1157 | 1157 | } |
1158 | 1158 | |
1159 | - if (!$inline_parentheses) { |
|
1159 | + if ( ! $inline_parentheses) { |
|
1160 | 1160 | $increase_block_indent = true; |
1161 | 1161 | // Add a newline after the parentheses |
1162 | 1162 | $newline = true; |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | // Add a newline before the closing parentheses (if not already added) |
1192 | - if (!$added_newline) { |
|
1192 | + if ( ! $added_newline) { |
|
1193 | 1193 | $return .= "\n" . str_repeat($tab, $indent_level); |
1194 | 1194 | } |
1195 | 1195 | } // Top level reserved words start a new line and increase the special indent level |
@@ -1206,7 +1206,7 @@ discard block |
||
1206 | 1206 | // Add a newline after the top level reserved word |
1207 | 1207 | $newline = true; |
1208 | 1208 | // Add a newline before the top level reserved word (if not already added) |
1209 | - if (!$added_newline) { |
|
1209 | + if ( ! $added_newline) { |
|
1210 | 1210 | $return .= "\n" . str_repeat($tab, $indent_level); |
1211 | 1211 | } // If we already added a newline, redo the indentation since it may be different now |
1212 | 1212 | else { |
@@ -1220,14 +1220,14 @@ discard block |
||
1220 | 1220 | $highlighted = preg_replace('/\s+/', ' ', $highlighted); |
1221 | 1221 | } |
1222 | 1222 | //if SQL 'LIMIT' clause, start variable to reset newline |
1223 | - if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) { |
|
1223 | + if ($token[self::TOKEN_VALUE] === 'LIMIT' && ! $inline_parentheses) { |
|
1224 | 1224 | $clause_limit = true; |
1225 | 1225 | } |
1226 | 1226 | } // Checks if we are out of the limit clause |
1227 | 1227 | elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
1228 | 1228 | $clause_limit = false; |
1229 | 1229 | } // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause) |
1230 | - elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) { |
|
1230 | + elseif ($token[self::TOKEN_VALUE] === ',' && ! $inline_parentheses) { |
|
1231 | 1231 | //If the previous TOKEN_VALUE is 'LIMIT', resets new line |
1232 | 1232 | if ($clause_limit === true) { |
1233 | 1233 | $newline = false; |
@@ -1239,7 +1239,7 @@ discard block |
||
1239 | 1239 | } // Newline reserved words start a new line |
1240 | 1240 | elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) { |
1241 | 1241 | // Add a newline before the reserved word (if not already added) |
1242 | - if (!$added_newline) { |
|
1242 | + if ( ! $added_newline) { |
|
1243 | 1243 | $return .= "\n" . str_repeat($tab, $indent_level); |
1244 | 1244 | } |
1245 | 1245 | |
@@ -1333,7 +1333,7 @@ discard block |
||
1333 | 1333 | foreach ($tokens as $token) { |
1334 | 1334 | // If this is a query separator |
1335 | 1335 | if ($token[self::TOKEN_VALUE] === ';') { |
1336 | - if (!$empty) { |
|
1336 | + if ( ! $empty) { |
|
1337 | 1337 | $queries[] = $current_query . ';'; |
1338 | 1338 | } |
1339 | 1339 | $current_query = ''; |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | $current_query .= $token[self::TOKEN_VALUE]; |
1350 | 1350 | } |
1351 | 1351 | |
1352 | - if (!$empty) { |
|
1352 | + if ( ! $empty) { |
|
1353 | 1353 | $queries[] = trim($current_query); |
1354 | 1354 | } |
1355 | 1355 | |
@@ -1643,7 +1643,7 @@ discard block |
||
1643 | 1643 | return $string . "\n"; |
1644 | 1644 | } else { |
1645 | 1645 | $string = trim($string); |
1646 | - if (!self::$use_pre) { |
|
1646 | + if ( ! self::$use_pre) { |
|
1647 | 1647 | return $string; |
1648 | 1648 | } |
1649 | 1649 |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | * @link http://github.com/jdorn/sql-formatter |
13 | 13 | * @version 1.2.18 |
14 | 14 | */ |
15 | -class SqlFormatter |
|
16 | -{ |
|
15 | +class SqlFormatter |
|
16 | +{ |
|
17 | 17 | // Constants for token types |
18 | 18 | const TOKEN_TYPE_WHITESPACE = 0; |
19 | 19 | const TOKEN_TYPE_WORD = 1; |
@@ -732,8 +732,8 @@ discard block |
||
732 | 732 | * Get stats about the token cache |
733 | 733 | * @return Array An array containing the keys 'hits', 'misses', 'entries', and 'size' in bytes |
734 | 734 | */ |
735 | - public static function getCacheStats() |
|
736 | - { |
|
735 | + public static function getCacheStats() |
|
736 | + { |
|
737 | 737 | return array( |
738 | 738 | 'hits' => self::$cache_hits, |
739 | 739 | 'misses' => self::$cache_misses, |
@@ -745,9 +745,9 @@ discard block |
||
745 | 745 | /** |
746 | 746 | * Stuff that only needs to be done once. Builds regular expressions and sorts the reserved words. |
747 | 747 | */ |
748 | - protected static function init() |
|
749 | - { |
|
750 | - if (self::$init) { |
|
748 | + protected static function init() |
|
749 | + { |
|
750 | + if (self::$init) { |
|
751 | 751 | return; |
752 | 752 | } |
753 | 753 | |
@@ -779,10 +779,10 @@ discard block |
||
779 | 779 | * |
780 | 780 | * @return Array An associative array containing the type and value of the token. |
781 | 781 | */ |
782 | - protected static function getNextToken($string, $previous = null) |
|
783 | - { |
|
782 | + protected static function getNextToken($string, $previous = null) |
|
783 | + { |
|
784 | 784 | // Whitespace |
785 | - if (preg_match('/^\s+/', $string, $matches)) { |
|
785 | + if (preg_match('/^\s+/', $string, $matches)) { |
|
786 | 786 | return array( |
787 | 787 | self::TOKEN_VALUE => $matches[0], |
788 | 788 | self::TOKEN_TYPE => self::TOKEN_TYPE_WHITESPACE |
@@ -790,17 +790,18 @@ discard block |
||
790 | 790 | } |
791 | 791 | |
792 | 792 | // Comment |
793 | - if ($string[0] === '#' || (isset($string[1]) && ($string[0] === '-' && $string[1] === '-') || ($string[0] === '/' && $string[1] === '*'))) { |
|
793 | + if ($string[0] === '#' || (isset($string[1]) && ($string[0] === '-' && $string[1] === '-') || ($string[0] === '/' && $string[1] === '*'))) { |
|
794 | 794 | // Comment until end of line |
795 | - if ($string[0] === '-' || $string[0] === '#') { |
|
795 | + if ($string[0] === '-' || $string[0] === '#') { |
|
796 | 796 | $last = strpos($string, "\n"); |
797 | 797 | $type = self::TOKEN_TYPE_COMMENT; |
798 | - } else { // Comment until closing comment tag |
|
798 | + } else { |
|
799 | +// Comment until closing comment tag |
|
799 | 800 | $last = strpos($string, "*/", 2) + 2; |
800 | 801 | $type = self::TOKEN_TYPE_BLOCK_COMMENT; |
801 | 802 | } |
802 | 803 | |
803 | - if ($last === false) { |
|
804 | + if ($last === false) { |
|
804 | 805 | $last = strlen($string); |
805 | 806 | } |
806 | 807 | |
@@ -811,7 +812,7 @@ discard block |
||
811 | 812 | } |
812 | 813 | |
813 | 814 | // Quoted String |
814 | - if ($string[0] === '"' || $string[0] === '\'' || $string[0] === '`' || $string[0] === '[') { |
|
815 | + if ($string[0] === '"' || $string[0] === '\'' || $string[0] === '`' || $string[0] === '[') { |
|
815 | 816 | $return = array( |
816 | 817 | self::TOKEN_TYPE => (($string[0] === '`' || $string[0] === '[') ? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE), |
817 | 818 | self::TOKEN_VALUE => self::getQuotedString($string) |
@@ -821,31 +822,31 @@ discard block |
||
821 | 822 | } |
822 | 823 | |
823 | 824 | // User-defined Variable |
824 | - if (($string[0] === '@' || $string[0] === ':') && isset($string[1])) { |
|
825 | + if (($string[0] === '@' || $string[0] === ':') && isset($string[1])) { |
|
825 | 826 | $ret = array( |
826 | 827 | self::TOKEN_VALUE => null, |
827 | 828 | self::TOKEN_TYPE => self::TOKEN_TYPE_VARIABLE |
828 | 829 | ); |
829 | 830 | |
830 | 831 | // If the variable name is quoted |
831 | - if ($string[1] === '"' || $string[1] === '\'' || $string[1] === '`') { |
|
832 | + if ($string[1] === '"' || $string[1] === '\'' || $string[1] === '`') { |
|
832 | 833 | $ret[self::TOKEN_VALUE] = $string[0] . self::getQuotedString(substr($string, 1)); |
833 | 834 | } // Non-quoted variable name |
834 | - else { |
|
835 | + else { |
|
835 | 836 | preg_match('/^(' . $string[0] . '[a-zA-Z0-9\._\$]+)/', $string, $matches); |
836 | - if (!empty($matches)) { |
|
837 | + if (!empty($matches)) { |
|
837 | 838 | $ret[self::TOKEN_VALUE] = $matches[1]; |
838 | 839 | } |
839 | 840 | } |
840 | 841 | |
841 | - if ($ret[self::TOKEN_VALUE] !== null) { |
|
842 | + if ($ret[self::TOKEN_VALUE] !== null) { |
|
842 | 843 | return $ret; |
843 | 844 | } |
844 | 845 | } |
845 | 846 | |
846 | 847 | // Number (decimal, binary, or hex) |
847 | 848 | if (preg_match('/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|' . self::$regex_boundaries . ')/', |
848 | - $string, $matches)) { |
|
849 | + $string, $matches)) { |
|
849 | 850 | return array( |
850 | 851 | self::TOKEN_VALUE => $matches[1], |
851 | 852 | self::TOKEN_TYPE => self::TOKEN_TYPE_NUMBER |
@@ -853,7 +854,7 @@ discard block |
||
853 | 854 | } |
854 | 855 | |
855 | 856 | // Boundary Character (punctuation and symbols) |
856 | - if (preg_match('/^(' . self::$regex_boundaries . ')/', $string, $matches)) { |
|
857 | + if (preg_match('/^(' . self::$regex_boundaries . ')/', $string, $matches)) { |
|
857 | 858 | return array( |
858 | 859 | self::TOKEN_VALUE => $matches[1], |
859 | 860 | self::TOKEN_TYPE => self::TOKEN_TYPE_BOUNDARY |
@@ -862,11 +863,11 @@ discard block |
||
862 | 863 | |
863 | 864 | // A reserved word cannot be preceded by a '.' |
864 | 865 | // this makes it so in "mytable.from", "from" is not considered a reserved word |
865 | - if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') { |
|
866 | + if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') { |
|
866 | 867 | $upper = strtoupper($string); |
867 | 868 | // Top Level Reserved Word |
868 | 869 | if (preg_match('/^(' . self::$regex_reserved_toplevel . ')($|\s|' . self::$regex_boundaries . ')/', $upper, |
869 | - $matches)) { |
|
870 | + $matches)) { |
|
870 | 871 | return array( |
871 | 872 | self::TOKEN_TYPE => self::TOKEN_TYPE_RESERVED_TOPLEVEL, |
872 | 873 | self::TOKEN_VALUE => substr($string, 0, strlen($matches[1])) |
@@ -874,7 +875,7 @@ discard block |
||
874 | 875 | } |
875 | 876 | // Newline Reserved Word |
876 | 877 | if (preg_match('/^(' . self::$regex_reserved_newline . ')($|\s|' . self::$regex_boundaries . ')/', $upper, |
877 | - $matches)) { |
|
878 | + $matches)) { |
|
878 | 879 | return array( |
879 | 880 | self::TOKEN_TYPE => self::TOKEN_TYPE_RESERVED_NEWLINE, |
880 | 881 | self::TOKEN_VALUE => substr($string, 0, strlen($matches[1])) |
@@ -882,7 +883,7 @@ discard block |
||
882 | 883 | } |
883 | 884 | // Other Reserved Word |
884 | 885 | if (preg_match('/^(' . self::$regex_reserved . ')($|\s|' . self::$regex_boundaries . ')/', $upper, |
885 | - $matches)) { |
|
886 | + $matches)) { |
|
886 | 887 | return array( |
887 | 888 | self::TOKEN_TYPE => self::TOKEN_TYPE_RESERVED, |
888 | 889 | self::TOKEN_VALUE => substr($string, 0, strlen($matches[1])) |
@@ -894,7 +895,7 @@ discard block |
||
894 | 895 | // this makes it so "count(" is considered a function, but "count" alone is not |
895 | 896 | $upper = strtoupper($string); |
896 | 897 | // function |
897 | - if (preg_match('/^(' . self::$regex_function . '[(]|\s|[)])/', $upper, $matches)) { |
|
898 | + if (preg_match('/^(' . self::$regex_function . '[(]|\s|[)])/', $upper, $matches)) { |
|
898 | 899 | return array( |
899 | 900 | self::TOKEN_TYPE => self::TOKEN_TYPE_RESERVED, |
900 | 901 | self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]) - 1) |
@@ -914,8 +915,8 @@ discard block |
||
914 | 915 | * @param $string |
915 | 916 | * @return null |
916 | 917 | */ |
917 | - protected static function getQuotedString($string) |
|
918 | - { |
|
918 | + protected static function getQuotedString($string) |
|
919 | + { |
|
919 | 920 | $ret = null; |
920 | 921 | |
921 | 922 | // This checks for the following patterns: |
@@ -924,7 +925,7 @@ discard block |
||
924 | 925 | // 3. double quoted string using "" or \" to escape |
925 | 926 | // 4. single quoted string using '' or \' to escape |
926 | 927 | if (preg_match('/^(((`[^`]*($|`))+)|((\[[^\]]*($|\]))(\][^\]]*($|\]))*)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', |
927 | - $string, $matches)) { |
|
928 | + $string, $matches)) { |
|
928 | 929 | $ret = $matches[1]; |
929 | 930 | } |
930 | 931 | |
@@ -939,8 +940,8 @@ discard block |
||
939 | 940 | * |
940 | 941 | * @return Array An array of tokens. |
941 | 942 | */ |
942 | - protected static function tokenize($string) |
|
943 | - { |
|
943 | + protected static function tokenize($string) |
|
944 | + { |
|
944 | 945 | self::init(); |
945 | 946 | |
946 | 947 | $tokens = array(); |
@@ -953,9 +954,9 @@ discard block |
||
953 | 954 | $current_length = strlen($string); |
954 | 955 | |
955 | 956 | // Keep processing the string until it is empty |
956 | - while ($current_length) { |
|
957 | + while ($current_length) { |
|
957 | 958 | // If the string stopped shrinking, there was a problem |
958 | - if ($old_string_len <= $current_length) { |
|
959 | + if ($old_string_len <= $current_length) { |
|
959 | 960 | $tokens[] = array( |
960 | 961 | self::TOKEN_VALUE => $string, |
961 | 962 | self::TOKEN_TYPE => self::TOKEN_TYPE_ERROR |
@@ -966,26 +967,26 @@ discard block |
||
966 | 967 | $old_string_len = $current_length; |
967 | 968 | |
968 | 969 | // Determine if we can use caching |
969 | - if ($current_length >= self::$max_cachekey_size) { |
|
970 | + if ($current_length >= self::$max_cachekey_size) { |
|
970 | 971 | $cacheKey = substr($string, 0, self::$max_cachekey_size); |
971 | - } else { |
|
972 | + } else { |
|
972 | 973 | $cacheKey = false; |
973 | 974 | } |
974 | 975 | |
975 | 976 | // See if the token is already cached |
976 | - if ($cacheKey !== false && isset(self::$token_cache[$cacheKey])) { |
|
977 | + if ($cacheKey !== false && isset(self::$token_cache[$cacheKey])) { |
|
977 | 978 | // Retrieve from cache |
978 | 979 | $token = self::$token_cache[$cacheKey]; |
979 | 980 | $token_length = strlen($token[self::TOKEN_VALUE]); |
980 | 981 | self::$cache_hits++; |
981 | - } else { |
|
982 | + } else { |
|
982 | 983 | // Get the next token and the token type |
983 | 984 | $token = self::getNextToken($string, $token); |
984 | 985 | $token_length = strlen($token[self::TOKEN_VALUE]); |
985 | 986 | self::$cache_misses++; |
986 | 987 | |
987 | 988 | // If the token is shorter than the max length, store it in cache |
988 | - if ($cacheKey !== false && $token_length < self::$max_cachekey_size) { |
|
989 | + if ($cacheKey !== false && $token_length < self::$max_cachekey_size) { |
|
989 | 990 | self::$token_cache[$cacheKey] = $token; |
990 | 991 | } |
991 | 992 | } |
@@ -1009,8 +1010,8 @@ discard block |
||
1009 | 1010 | * |
1010 | 1011 | * @return String The SQL string with HTML styles and formatting wrapped in a <pre> tag |
1011 | 1012 | */ |
1012 | - public static function format($string, $highlight = true) |
|
1013 | - { |
|
1013 | + public static function format($string, $highlight = true) |
|
1014 | + { |
|
1014 | 1015 | // This variable will be populated with formatted html |
1015 | 1016 | $return = ''; |
1016 | 1017 | |
@@ -1032,47 +1033,48 @@ discard block |
||
1032 | 1033 | |
1033 | 1034 | // Remove existing whitespace |
1034 | 1035 | $tokens = array(); |
1035 | - foreach ($original_tokens as $i => $token) { |
|
1036 | - if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
1036 | + foreach ($original_tokens as $i => $token) { |
|
1037 | + if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
1037 | 1038 | $token['i'] = $i; |
1038 | 1039 | $tokens[] = $token; |
1039 | 1040 | } |
1040 | 1041 | } |
1041 | 1042 | |
1042 | 1043 | // Format token by token |
1043 | - foreach ($tokens as $i => $token) { |
|
1044 | + foreach ($tokens as $i => $token) { |
|
1044 | 1045 | // Get highlighted token if doing syntax highlighting |
1045 | - if ($highlight) { |
|
1046 | + if ($highlight) { |
|
1046 | 1047 | $highlighted = self::highlightToken($token); |
1047 | - } else { // If returning raw text |
|
1048 | + } else { |
|
1049 | +// If returning raw text |
|
1048 | 1050 | $highlighted = $token[self::TOKEN_VALUE]; |
1049 | 1051 | } |
1050 | 1052 | |
1051 | 1053 | // If we are increasing the special indent level now |
1052 | - if ($increase_special_indent) { |
|
1054 | + if ($increase_special_indent) { |
|
1053 | 1055 | $indent_level++; |
1054 | 1056 | $increase_special_indent = false; |
1055 | 1057 | array_unshift($indent_types, 'special'); |
1056 | 1058 | } |
1057 | 1059 | // If we are increasing the block indent level now |
1058 | - if ($increase_block_indent) { |
|
1060 | + if ($increase_block_indent) { |
|
1059 | 1061 | $indent_level++; |
1060 | 1062 | $increase_block_indent = false; |
1061 | 1063 | array_unshift($indent_types, 'block'); |
1062 | 1064 | } |
1063 | 1065 | |
1064 | 1066 | // If we need a new line before the token |
1065 | - if ($newline) { |
|
1067 | + if ($newline) { |
|
1066 | 1068 | $return .= "\n" . str_repeat($tab, $indent_level); |
1067 | 1069 | $newline = false; |
1068 | 1070 | $added_newline = true; |
1069 | - } else { |
|
1071 | + } else { |
|
1070 | 1072 | $added_newline = false; |
1071 | 1073 | } |
1072 | 1074 | |
1073 | 1075 | // Display comments directly where they appear in the source |
1074 | - if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1075 | - if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1076 | + if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1077 | + if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1076 | 1078 | $indent = str_repeat($tab, $indent_level); |
1077 | 1079 | $return .= "\n" . $indent; |
1078 | 1080 | $highlighted = str_replace("\n", "\n" . $indent, $highlighted); |
@@ -1083,12 +1085,12 @@ discard block |
||
1083 | 1085 | continue; |
1084 | 1086 | } |
1085 | 1087 | |
1086 | - if ($inline_parentheses) { |
|
1088 | + if ($inline_parentheses) { |
|
1087 | 1089 | // End of inline parentheses |
1088 | - if ($token[self::TOKEN_VALUE] === ')') { |
|
1090 | + if ($token[self::TOKEN_VALUE] === ')') { |
|
1089 | 1091 | $return = rtrim($return, ' '); |
1090 | 1092 | |
1091 | - if ($inline_indented) { |
|
1093 | + if ($inline_indented) { |
|
1092 | 1094 | array_shift($indent_types); |
1093 | 1095 | $indent_level--; |
1094 | 1096 | $return .= "\n" . str_repeat($tab, $indent_level); |
@@ -1100,8 +1102,8 @@ discard block |
||
1100 | 1102 | continue; |
1101 | 1103 | } |
1102 | 1104 | |
1103 | - if ($token[self::TOKEN_VALUE] === ',') { |
|
1104 | - if ($inline_count >= 30) { |
|
1105 | + if ($token[self::TOKEN_VALUE] === ',') { |
|
1106 | + if ($inline_count >= 30) { |
|
1105 | 1107 | $inline_count = 0; |
1106 | 1108 | $newline = true; |
1107 | 1109 | } |
@@ -1111,21 +1113,21 @@ discard block |
||
1111 | 1113 | } |
1112 | 1114 | |
1113 | 1115 | // Opening parentheses increase the block indent level and start a new line |
1114 | - if ($token[self::TOKEN_VALUE] === '(') { |
|
1116 | + if ($token[self::TOKEN_VALUE] === '(') { |
|
1115 | 1117 | // First check if this should be an inline parentheses block |
1116 | 1118 | // Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2) |
1117 | 1119 | // Allow up to 3 non-whitespace tokens inside inline parentheses |
1118 | 1120 | $length = 0; |
1119 | - for ($j = 1; $j <= 250; $j++) { |
|
1121 | + for ($j = 1; $j <= 250; $j++) { |
|
1120 | 1122 | // Reached end of string |
1121 | - if (!isset($tokens[$i + $j])) { |
|
1123 | + if (!isset($tokens[$i + $j])) { |
|
1122 | 1124 | break; |
1123 | 1125 | } |
1124 | 1126 | |
1125 | 1127 | $next = $tokens[$i + $j]; |
1126 | 1128 | |
1127 | 1129 | // Reached closing parentheses, able to inline it |
1128 | - if ($next[self::TOKEN_VALUE] === ')') { |
|
1130 | + if ($next[self::TOKEN_VALUE] === ')') { |
|
1129 | 1131 | $inline_parentheses = true; |
1130 | 1132 | $inline_count = 0; |
1131 | 1133 | $inline_indented = false; |
@@ -1133,72 +1135,72 @@ discard block |
||
1133 | 1135 | } |
1134 | 1136 | |
1135 | 1137 | // Reached an invalid token for inline parentheses |
1136 | - if ($next[self::TOKEN_VALUE] === ';' || $next[self::TOKEN_VALUE] === '(') { |
|
1138 | + if ($next[self::TOKEN_VALUE] === ';' || $next[self::TOKEN_VALUE] === '(') { |
|
1137 | 1139 | break; |
1138 | 1140 | } |
1139 | 1141 | |
1140 | 1142 | // Reached an invalid token type for inline parentheses |
1141 | - if ($next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1143 | + if ($next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1142 | 1144 | break; |
1143 | 1145 | } |
1144 | 1146 | |
1145 | 1147 | $length += strlen($next[self::TOKEN_VALUE]); |
1146 | 1148 | } |
1147 | 1149 | |
1148 | - if ($inline_parentheses && $length > 30) { |
|
1150 | + if ($inline_parentheses && $length > 30) { |
|
1149 | 1151 | $increase_block_indent = true; |
1150 | 1152 | $inline_indented = true; |
1151 | 1153 | $newline = true; |
1152 | 1154 | } |
1153 | 1155 | |
1154 | 1156 | // Take out the preceding space unless there was whitespace there in the original query |
1155 | - if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
1157 | + if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
1156 | 1158 | $return = rtrim($return, ' '); |
1157 | 1159 | } |
1158 | 1160 | |
1159 | - if (!$inline_parentheses) { |
|
1161 | + if (!$inline_parentheses) { |
|
1160 | 1162 | $increase_block_indent = true; |
1161 | 1163 | // Add a newline after the parentheses |
1162 | 1164 | $newline = true; |
1163 | 1165 | } |
1164 | 1166 | |
1165 | 1167 | } // Closing parentheses decrease the block indent level |
1166 | - elseif ($token[self::TOKEN_VALUE] === ')') { |
|
1168 | + elseif ($token[self::TOKEN_VALUE] === ')') { |
|
1167 | 1169 | // Remove whitespace before the closing parentheses |
1168 | 1170 | $return = rtrim($return, ' '); |
1169 | 1171 | |
1170 | 1172 | $indent_level--; |
1171 | 1173 | |
1172 | 1174 | // Reset indent level |
1173 | - while ($j = array_shift($indent_types)) { |
|
1174 | - if ($j === 'special') { |
|
1175 | + while ($j = array_shift($indent_types)) { |
|
1176 | + if ($j === 'special') { |
|
1175 | 1177 | $indent_level--; |
1176 | - } else { |
|
1178 | + } else { |
|
1177 | 1179 | break; |
1178 | 1180 | } |
1179 | 1181 | } |
1180 | 1182 | |
1181 | - if ($indent_level < 0) { |
|
1183 | + if ($indent_level < 0) { |
|
1182 | 1184 | // This is an error |
1183 | 1185 | $indent_level = 0; |
1184 | 1186 | |
1185 | - if ($highlight) { |
|
1187 | + if ($highlight) { |
|
1186 | 1188 | $return .= "\n" . self::highlightError($token[self::TOKEN_VALUE]); |
1187 | 1189 | continue; |
1188 | 1190 | } |
1189 | 1191 | } |
1190 | 1192 | |
1191 | 1193 | // Add a newline before the closing parentheses (if not already added) |
1192 | - if (!$added_newline) { |
|
1194 | + if (!$added_newline) { |
|
1193 | 1195 | $return .= "\n" . str_repeat($tab, $indent_level); |
1194 | 1196 | } |
1195 | 1197 | } // Top level reserved words start a new line and increase the special indent level |
1196 | - elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
1198 | + elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
1197 | 1199 | $increase_special_indent = true; |
1198 | 1200 | |
1199 | 1201 | // If the last indent type was 'special', decrease the special indent for this round |
1200 | 1202 | reset($indent_types); |
1201 | - if (current($indent_types) === 'special') { |
|
1203 | + if (current($indent_types) === 'special') { |
|
1202 | 1204 | $indent_level--; |
1203 | 1205 | array_shift($indent_types); |
1204 | 1206 | } |
@@ -1206,88 +1208,88 @@ discard block |
||
1206 | 1208 | // Add a newline after the top level reserved word |
1207 | 1209 | $newline = true; |
1208 | 1210 | // Add a newline before the top level reserved word (if not already added) |
1209 | - if (!$added_newline) { |
|
1211 | + if (!$added_newline) { |
|
1210 | 1212 | $return .= "\n" . str_repeat($tab, $indent_level); |
1211 | 1213 | } // If we already added a newline, redo the indentation since it may be different now |
1212 | - else { |
|
1214 | + else { |
|
1213 | 1215 | $return = rtrim($return, $tab) . str_repeat($tab, $indent_level); |
1214 | 1216 | } |
1215 | 1217 | |
1216 | 1218 | // If the token may have extra whitespace |
1217 | 1219 | if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE], |
1218 | 1220 | "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false |
1219 | - ) { |
|
1221 | + ) { |
|
1220 | 1222 | $highlighted = preg_replace('/\s+/', ' ', $highlighted); |
1221 | 1223 | } |
1222 | 1224 | //if SQL 'LIMIT' clause, start variable to reset newline |
1223 | - if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) { |
|
1225 | + if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) { |
|
1224 | 1226 | $clause_limit = true; |
1225 | 1227 | } |
1226 | 1228 | } // Checks if we are out of the limit clause |
1227 | - elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
1229 | + elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
1228 | 1230 | $clause_limit = false; |
1229 | 1231 | } // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause) |
1230 | - elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) { |
|
1232 | + elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) { |
|
1231 | 1233 | //If the previous TOKEN_VALUE is 'LIMIT', resets new line |
1232 | - if ($clause_limit === true) { |
|
1234 | + if ($clause_limit === true) { |
|
1233 | 1235 | $newline = false; |
1234 | 1236 | $clause_limit = false; |
1235 | 1237 | } // All other cases of commas |
1236 | - else { |
|
1238 | + else { |
|
1237 | 1239 | $newline = true; |
1238 | 1240 | } |
1239 | 1241 | } // Newline reserved words start a new line |
1240 | - elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) { |
|
1242 | + elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) { |
|
1241 | 1243 | // Add a newline before the reserved word (if not already added) |
1242 | - if (!$added_newline) { |
|
1244 | + if (!$added_newline) { |
|
1243 | 1245 | $return .= "\n" . str_repeat($tab, $indent_level); |
1244 | 1246 | } |
1245 | 1247 | |
1246 | 1248 | // If the token may have extra whitespace |
1247 | 1249 | if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE], |
1248 | 1250 | "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false |
1249 | - ) { |
|
1251 | + ) { |
|
1250 | 1252 | $highlighted = preg_replace('/\s+/', ' ', $highlighted); |
1251 | 1253 | } |
1252 | 1254 | } // Multiple boundary characters in a row should not have spaces between them (not including parentheses) |
1253 | - elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) { |
|
1254 | - if (isset($tokens[$i - 1]) && $tokens[$i - 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) { |
|
1255 | - if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
1255 | + elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) { |
|
1256 | + if (isset($tokens[$i - 1]) && $tokens[$i - 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) { |
|
1257 | + if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { |
|
1256 | 1258 | $return = rtrim($return, ' '); |
1257 | 1259 | } |
1258 | 1260 | } |
1259 | 1261 | } |
1260 | 1262 | |
1261 | 1263 | // If the token shouldn't have a space before it |
1262 | - if ($token[self::TOKEN_VALUE] === '.' || $token[self::TOKEN_VALUE] === ',' || $token[self::TOKEN_VALUE] === ';') { |
|
1264 | + if ($token[self::TOKEN_VALUE] === '.' || $token[self::TOKEN_VALUE] === ',' || $token[self::TOKEN_VALUE] === ';') { |
|
1263 | 1265 | $return = rtrim($return, ' '); |
1264 | 1266 | } |
1265 | 1267 | |
1266 | 1268 | $return .= $highlighted . ' '; |
1267 | 1269 | |
1268 | 1270 | // If the token shouldn't have a space after it |
1269 | - if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') { |
|
1271 | + if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') { |
|
1270 | 1272 | $return = rtrim($return, ' '); |
1271 | 1273 | } |
1272 | 1274 | |
1273 | 1275 | // If this is the "-" of a negative number, it shouldn't have a space after it |
1274 | - if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i + 1]) && $tokens[$i + 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i - 1])) { |
|
1276 | + if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i + 1]) && $tokens[$i + 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i - 1])) { |
|
1275 | 1277 | $prev = $tokens[$i - 1][self::TOKEN_TYPE]; |
1276 | - if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) { |
|
1278 | + if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) { |
|
1277 | 1279 | $return = rtrim($return, ' '); |
1278 | 1280 | } |
1279 | 1281 | } |
1280 | 1282 | } |
1281 | 1283 | |
1282 | 1284 | // If there are unmatched parentheses |
1283 | - if ($highlight && array_search('block', $indent_types) !== false) { |
|
1285 | + if ($highlight && array_search('block', $indent_types) !== false) { |
|
1284 | 1286 | $return .= "\n" . self::highlightError("WARNING: unclosed parentheses or section"); |
1285 | 1287 | } |
1286 | 1288 | |
1287 | 1289 | // Replace tab characters with the configuration tab character |
1288 | 1290 | $return = trim(str_replace("\t", self::$tab, $return)); |
1289 | 1291 | |
1290 | - if ($highlight) { |
|
1292 | + if ($highlight) { |
|
1291 | 1293 | $return = self::output($return); |
1292 | 1294 | } |
1293 | 1295 | |
@@ -1301,13 +1303,13 @@ discard block |
||
1301 | 1303 | * |
1302 | 1304 | * @return String The SQL string with HTML styles applied |
1303 | 1305 | */ |
1304 | - public static function highlight($string) |
|
1305 | - { |
|
1306 | + public static function highlight($string) |
|
1307 | + { |
|
1306 | 1308 | $tokens = self::tokenize($string); |
1307 | 1309 | |
1308 | 1310 | $return = ''; |
1309 | 1311 | |
1310 | - foreach ($tokens as $token) { |
|
1312 | + foreach ($tokens as $token) { |
|
1311 | 1313 | $return .= self::highlightToken($token); |
1312 | 1314 | } |
1313 | 1315 | |
@@ -1322,18 +1324,18 @@ discard block |
||
1322 | 1324 | * |
1323 | 1325 | * @return Array An array of individual query strings without trailing semicolons |
1324 | 1326 | */ |
1325 | - public static function splitQuery($string) |
|
1326 | - { |
|
1327 | + public static function splitQuery($string) |
|
1328 | + { |
|
1327 | 1329 | $queries = array(); |
1328 | 1330 | $current_query = ''; |
1329 | 1331 | $empty = true; |
1330 | 1332 | |
1331 | 1333 | $tokens = self::tokenize($string); |
1332 | 1334 | |
1333 | - foreach ($tokens as $token) { |
|
1335 | + foreach ($tokens as $token) { |
|
1334 | 1336 | // If this is a query separator |
1335 | - if ($token[self::TOKEN_VALUE] === ';') { |
|
1336 | - if (!$empty) { |
|
1337 | + if ($token[self::TOKEN_VALUE] === ';') { |
|
1338 | + if (!$empty) { |
|
1337 | 1339 | $queries[] = $current_query . ';'; |
1338 | 1340 | } |
1339 | 1341 | $current_query = ''; |
@@ -1342,14 +1344,14 @@ discard block |
||
1342 | 1344 | } |
1343 | 1345 | |
1344 | 1346 | // If this is a non-empty character |
1345 | - if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1347 | + if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1346 | 1348 | $empty = false; |
1347 | 1349 | } |
1348 | 1350 | |
1349 | 1351 | $current_query .= $token[self::TOKEN_VALUE]; |
1350 | 1352 | } |
1351 | 1353 | |
1352 | - if (!$empty) { |
|
1354 | + if (!$empty) { |
|
1353 | 1355 | $queries[] = trim($current_query); |
1354 | 1356 | } |
1355 | 1357 | |
@@ -1363,15 +1365,15 @@ discard block |
||
1363 | 1365 | * |
1364 | 1366 | * @return String The SQL string without comments |
1365 | 1367 | */ |
1366 | - public static function removeComments($string) |
|
1367 | - { |
|
1368 | + public static function removeComments($string) |
|
1369 | + { |
|
1368 | 1370 | $result = ''; |
1369 | 1371 | |
1370 | 1372 | $tokens = self::tokenize($string); |
1371 | 1373 | |
1372 | - foreach ($tokens as $token) { |
|
1374 | + foreach ($tokens as $token) { |
|
1373 | 1375 | // Skip comment tokens |
1374 | - if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1376 | + if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1375 | 1377 | continue; |
1376 | 1378 | } |
1377 | 1379 | |
@@ -1389,32 +1391,32 @@ discard block |
||
1389 | 1391 | * |
1390 | 1392 | * @return String The SQL string without comments |
1391 | 1393 | */ |
1392 | - public static function compress($string) |
|
1393 | - { |
|
1394 | + public static function compress($string) |
|
1395 | + { |
|
1394 | 1396 | $result = ''; |
1395 | 1397 | |
1396 | 1398 | $tokens = self::tokenize($string); |
1397 | 1399 | |
1398 | 1400 | $whitespace = true; |
1399 | - foreach ($tokens as $token) { |
|
1401 | + foreach ($tokens as $token) { |
|
1400 | 1402 | // Skip comment tokens |
1401 | - if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1403 | + if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1402 | 1404 | continue; |
1403 | 1405 | } // Remove extra whitespace in reserved words (e.g "OUTER JOIN" becomes "OUTER JOIN") |
1404 | - elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
1406 | + elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
1405 | 1407 | $token[self::TOKEN_VALUE] = preg_replace('/\s+/', ' ', $token[self::TOKEN_VALUE]); |
1406 | 1408 | } |
1407 | 1409 | |
1408 | - if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) { |
|
1410 | + if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) { |
|
1409 | 1411 | // If the last token was whitespace, don't add another one |
1410 | - if ($whitespace) { |
|
1412 | + if ($whitespace) { |
|
1411 | 1413 | continue; |
1412 | - } else { |
|
1414 | + } else { |
|
1413 | 1415 | $whitespace = true; |
1414 | 1416 | // Convert all whitespace to a single space |
1415 | 1417 | $token[self::TOKEN_VALUE] = ' '; |
1416 | 1418 | } |
1417 | - } else { |
|
1419 | + } else { |
|
1418 | 1420 | $whitespace = false; |
1419 | 1421 | } |
1420 | 1422 | |
@@ -1431,39 +1433,39 @@ discard block |
||
1431 | 1433 | * |
1432 | 1434 | * @return String HTML code of the highlighted token. |
1433 | 1435 | */ |
1434 | - protected static function highlightToken($token) |
|
1435 | - { |
|
1436 | + protected static function highlightToken($token) |
|
1437 | + { |
|
1436 | 1438 | $type = $token[self::TOKEN_TYPE]; |
1437 | 1439 | |
1438 | - if (self::is_cli()) { |
|
1440 | + if (self::is_cli()) { |
|
1439 | 1441 | $token = $token[self::TOKEN_VALUE]; |
1440 | - } else { |
|
1441 | - if (defined('ENT_IGNORE')) { |
|
1442 | + } else { |
|
1443 | + if (defined('ENT_IGNORE')) { |
|
1442 | 1444 | $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT | ENT_IGNORE, 'UTF-8'); |
1443 | - } else { |
|
1445 | + } else { |
|
1444 | 1446 | $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT, 'UTF-8'); |
1445 | 1447 | } |
1446 | 1448 | } |
1447 | 1449 | |
1448 | - if ($type === self::TOKEN_TYPE_BOUNDARY) { |
|
1450 | + if ($type === self::TOKEN_TYPE_BOUNDARY) { |
|
1449 | 1451 | return self::highlightBoundary($token); |
1450 | - } elseif ($type === self::TOKEN_TYPE_WORD) { |
|
1452 | + } elseif ($type === self::TOKEN_TYPE_WORD) { |
|
1451 | 1453 | return self::highlightWord($token); |
1452 | - } elseif ($type === self::TOKEN_TYPE_BACKTICK_QUOTE) { |
|
1454 | + } elseif ($type === self::TOKEN_TYPE_BACKTICK_QUOTE) { |
|
1453 | 1455 | return self::highlightBacktickQuote($token); |
1454 | - } elseif ($type === self::TOKEN_TYPE_QUOTE) { |
|
1456 | + } elseif ($type === self::TOKEN_TYPE_QUOTE) { |
|
1455 | 1457 | return self::highlightQuote($token); |
1456 | - } elseif ($type === self::TOKEN_TYPE_RESERVED) { |
|
1458 | + } elseif ($type === self::TOKEN_TYPE_RESERVED) { |
|
1457 | 1459 | return self::highlightReservedWord($token); |
1458 | - } elseif ($type === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
1460 | + } elseif ($type === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { |
|
1459 | 1461 | return self::highlightReservedWord($token); |
1460 | - } elseif ($type === self::TOKEN_TYPE_RESERVED_NEWLINE) { |
|
1462 | + } elseif ($type === self::TOKEN_TYPE_RESERVED_NEWLINE) { |
|
1461 | 1463 | return self::highlightReservedWord($token); |
1462 | - } elseif ($type === self::TOKEN_TYPE_NUMBER) { |
|
1464 | + } elseif ($type === self::TOKEN_TYPE_NUMBER) { |
|
1463 | 1465 | return self::highlightNumber($token); |
1464 | - } elseif ($type === self::TOKEN_TYPE_VARIABLE) { |
|
1466 | + } elseif ($type === self::TOKEN_TYPE_VARIABLE) { |
|
1465 | 1467 | return self::highlightVariable($token); |
1466 | - } elseif ($type === self::TOKEN_TYPE_COMMENT || $type === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1468 | + } elseif ($type === self::TOKEN_TYPE_COMMENT || $type === self::TOKEN_TYPE_BLOCK_COMMENT) { |
|
1467 | 1469 | return self::highlightComment($token); |
1468 | 1470 | } |
1469 | 1471 | |
@@ -1477,11 +1479,11 @@ discard block |
||
1477 | 1479 | * |
1478 | 1480 | * @return String HTML code of the highlighted token. |
1479 | 1481 | */ |
1480 | - protected static function highlightQuote($value) |
|
1481 | - { |
|
1482 | - if (self::is_cli()) { |
|
1482 | + protected static function highlightQuote($value) |
|
1483 | + { |
|
1484 | + if (self::is_cli()) { |
|
1483 | 1485 | return self::$cli_quote . $value . "\x1b[0m"; |
1484 | - } else { |
|
1486 | + } else { |
|
1485 | 1487 | return '<span ' . self::$quote_attributes . '>' . $value . '</span>'; |
1486 | 1488 | } |
1487 | 1489 | } |
@@ -1493,11 +1495,11 @@ discard block |
||
1493 | 1495 | * |
1494 | 1496 | * @return String HTML code of the highlighted token. |
1495 | 1497 | */ |
1496 | - protected static function highlightBacktickQuote($value) |
|
1497 | - { |
|
1498 | - if (self::is_cli()) { |
|
1498 | + protected static function highlightBacktickQuote($value) |
|
1499 | + { |
|
1500 | + if (self::is_cli()) { |
|
1499 | 1501 | return self::$cli_backtick_quote . $value . "\x1b[0m"; |
1500 | - } else { |
|
1502 | + } else { |
|
1501 | 1503 | return '<span ' . self::$backtick_quote_attributes . '>' . $value . '</span>'; |
1502 | 1504 | } |
1503 | 1505 | } |
@@ -1509,11 +1511,11 @@ discard block |
||
1509 | 1511 | * |
1510 | 1512 | * @return String HTML code of the highlighted token. |
1511 | 1513 | */ |
1512 | - protected static function highlightReservedWord($value) |
|
1513 | - { |
|
1514 | - if (self::is_cli()) { |
|
1514 | + protected static function highlightReservedWord($value) |
|
1515 | + { |
|
1516 | + if (self::is_cli()) { |
|
1515 | 1517 | return self::$cli_reserved . $value . "\x1b[0m"; |
1516 | - } else { |
|
1518 | + } else { |
|
1517 | 1519 | return '<span ' . self::$reserved_attributes . '>' . $value . '</span>'; |
1518 | 1520 | } |
1519 | 1521 | } |
@@ -1525,15 +1527,15 @@ discard block |
||
1525 | 1527 | * |
1526 | 1528 | * @return String HTML code of the highlighted token. |
1527 | 1529 | */ |
1528 | - protected static function highlightBoundary($value) |
|
1529 | - { |
|
1530 | - if ($value === '(' || $value === ')') { |
|
1530 | + protected static function highlightBoundary($value) |
|
1531 | + { |
|
1532 | + if ($value === '(' || $value === ')') { |
|
1531 | 1533 | return $value; |
1532 | 1534 | } |
1533 | 1535 | |
1534 | - if (self::is_cli()) { |
|
1536 | + if (self::is_cli()) { |
|
1535 | 1537 | return self::$cli_boundary . $value . "\x1b[0m"; |
1536 | - } else { |
|
1538 | + } else { |
|
1537 | 1539 | return '<span ' . self::$boundary_attributes . '>' . $value . '</span>'; |
1538 | 1540 | } |
1539 | 1541 | } |
@@ -1545,11 +1547,11 @@ discard block |
||
1545 | 1547 | * |
1546 | 1548 | * @return String HTML code of the highlighted token. |
1547 | 1549 | */ |
1548 | - protected static function highlightNumber($value) |
|
1549 | - { |
|
1550 | - if (self::is_cli()) { |
|
1550 | + protected static function highlightNumber($value) |
|
1551 | + { |
|
1552 | + if (self::is_cli()) { |
|
1551 | 1553 | return self::$cli_number . $value . "\x1b[0m"; |
1552 | - } else { |
|
1554 | + } else { |
|
1553 | 1555 | return '<span ' . self::$number_attributes . '>' . $value . '</span>'; |
1554 | 1556 | } |
1555 | 1557 | } |
@@ -1561,11 +1563,11 @@ discard block |
||
1561 | 1563 | * |
1562 | 1564 | * @return String HTML code of the highlighted token. |
1563 | 1565 | */ |
1564 | - protected static function highlightError($value) |
|
1565 | - { |
|
1566 | - if (self::is_cli()) { |
|
1566 | + protected static function highlightError($value) |
|
1567 | + { |
|
1568 | + if (self::is_cli()) { |
|
1567 | 1569 | return self::$cli_error . $value . "\x1b[0m"; |
1568 | - } else { |
|
1570 | + } else { |
|
1569 | 1571 | return '<span ' . self::$error_attributes . '>' . $value . '</span>'; |
1570 | 1572 | } |
1571 | 1573 | } |
@@ -1577,11 +1579,11 @@ discard block |
||
1577 | 1579 | * |
1578 | 1580 | * @return String HTML code of the highlighted token. |
1579 | 1581 | */ |
1580 | - protected static function highlightComment($value) |
|
1581 | - { |
|
1582 | - if (self::is_cli()) { |
|
1582 | + protected static function highlightComment($value) |
|
1583 | + { |
|
1584 | + if (self::is_cli()) { |
|
1583 | 1585 | return self::$cli_comment . $value . "\x1b[0m"; |
1584 | - } else { |
|
1586 | + } else { |
|
1585 | 1587 | return '<span ' . self::$comment_attributes . '>' . $value . '</span>'; |
1586 | 1588 | } |
1587 | 1589 | } |
@@ -1593,11 +1595,11 @@ discard block |
||
1593 | 1595 | * |
1594 | 1596 | * @return String HTML code of the highlighted token. |
1595 | 1597 | */ |
1596 | - protected static function highlightWord($value) |
|
1597 | - { |
|
1598 | - if (self::is_cli()) { |
|
1598 | + protected static function highlightWord($value) |
|
1599 | + { |
|
1600 | + if (self::is_cli()) { |
|
1599 | 1601 | return self::$cli_word . $value . "\x1b[0m"; |
1600 | - } else { |
|
1602 | + } else { |
|
1601 | 1603 | return '<span ' . self::$word_attributes . '>' . $value . '</span>'; |
1602 | 1604 | } |
1603 | 1605 | } |
@@ -1609,11 +1611,11 @@ discard block |
||
1609 | 1611 | * |
1610 | 1612 | * @return String HTML code of the highlighted token. |
1611 | 1613 | */ |
1612 | - protected static function highlightVariable($value) |
|
1613 | - { |
|
1614 | - if (self::is_cli()) { |
|
1614 | + protected static function highlightVariable($value) |
|
1615 | + { |
|
1616 | + if (self::is_cli()) { |
|
1615 | 1617 | return self::$cli_variable . $value . "\x1b[0m"; |
1616 | - } else { |
|
1618 | + } else { |
|
1617 | 1619 | return '<span ' . self::$variable_attributes . '>' . $value . '</span>'; |
1618 | 1620 | } |
1619 | 1621 | } |
@@ -1625,8 +1627,8 @@ discard block |
||
1625 | 1627 | * |
1626 | 1628 | * @return String The quoted string |
1627 | 1629 | */ |
1628 | - private static function quote_regex($a) |
|
1629 | - { |
|
1630 | + private static function quote_regex($a) |
|
1631 | + { |
|
1630 | 1632 | return preg_quote($a, '/'); |
1631 | 1633 | } |
1632 | 1634 | |
@@ -1637,13 +1639,13 @@ discard block |
||
1637 | 1639 | * |
1638 | 1640 | * @return String The quoted string |
1639 | 1641 | */ |
1640 | - private static function output($string) |
|
1641 | - { |
|
1642 | - if (self::is_cli()) { |
|
1642 | + private static function output($string) |
|
1643 | + { |
|
1644 | + if (self::is_cli()) { |
|
1643 | 1645 | return $string . "\n"; |
1644 | - } else { |
|
1646 | + } else { |
|
1645 | 1647 | $string = trim($string); |
1646 | - if (!self::$use_pre) { |
|
1648 | + if (!self::$use_pre) { |
|
1647 | 1649 | return $string; |
1648 | 1650 | } |
1649 | 1651 | |
@@ -1654,11 +1656,11 @@ discard block |
||
1654 | 1656 | /** |
1655 | 1657 | * @return bool |
1656 | 1658 | */ |
1657 | - private static function is_cli() |
|
1658 | - { |
|
1659 | - if (isset(self::$cli)) { |
|
1659 | + private static function is_cli() |
|
1660 | + { |
|
1661 | + if (isset(self::$cli)) { |
|
1660 | 1662 | return self::$cli; |
1661 | - } else { |
|
1663 | + } else { |
|
1662 | 1664 | return php_sapi_name() === 'cli'; |
1663 | 1665 | } |
1664 | 1666 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | default: |
202 | 202 | $this->Log("MODx / PHx placeholder variable: " . $input); |
203 | 203 | // Check if placeholder is set |
204 | - if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input, |
|
204 | + if ( ! array_key_exists($input, $this->placeholders) && ! array_key_exists($input, |
|
205 | 205 | $modx->placeholders) |
206 | 206 | ) { |
207 | 207 | // not set so try again later. |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | case "show": |
311 | 311 | $conditional = implode(' ', $condition); |
312 | 312 | $isvalid = intval($this->runCode($conditional)); |
313 | - if (!$isvalid) { |
|
313 | + if ( ! $isvalid) { |
|
314 | 314 | $output = null; |
315 | 315 | } |
316 | 316 | break; |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | case "else": |
327 | 327 | $conditional = implode(' ', $condition); |
328 | 328 | $isvalid = intval($this->runCode($condition)); |
329 | - if (!$isvalid) { |
|
329 | + if ( ! $isvalid) { |
|
330 | 330 | $output = $modifier_value[$i]; |
331 | 331 | } |
332 | 332 | break; |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | break; |
393 | 393 | case "wordwrap": // default: 70 |
394 | 394 | $wrapat = intval($modifier_value[$i]) ? intval($modifier_value[$i]) : 70; |
395 | - $output = preg_replace_callback("@(\b\w+\b)@",function($m) use($wrapat) {return wordwrap($m[1],$wrapat,' ',1);},$output); |
|
395 | + $output = preg_replace_callback("@(\b\w+\b)@", function($m) use($wrapat) {return wordwrap($m[1], $wrapat, ' ', 1); },$output); |
|
396 | 396 | break; |
397 | 397 | case "limit": // default: 100 |
398 | 398 | $limit = intval($modifier_value[$i]) ? intval($modifier_value[$i]) : 100; |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | $output = eval("return " . $filter . ";"); |
416 | 416 | break; |
417 | 417 | case "isnotempty": |
418 | - if (!empty($output)) { |
|
418 | + if ( ! empty($output)) { |
|
419 | 419 | $output = $modifier_value[$i]; |
420 | 420 | } |
421 | 421 | break; |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | $cm = $snippet; |
495 | 495 | // end // |
496 | 496 | |
497 | - if (!empty($cm)) { |
|
497 | + if ( ! empty($cm)) { |
|
498 | 498 | ob_start(); |
499 | 499 | $options = $modifier_value[$i]; |
500 | 500 | $custom = eval($cm); |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | return $output; |
517 | 517 | } |
518 | 518 | |
519 | - private function runCode($code){ |
|
519 | + private function runCode($code) { |
|
520 | 520 | return eval("return (" . $code . ");"); |
521 | 521 | } |
522 | 522 | // Event logging (debug) |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | */ |
526 | 526 | public function createEventLog() |
527 | 527 | { |
528 | - if (!empty($this->console)) { |
|
528 | + if ( ! empty($this->console)) { |
|
529 | 529 | $console = implode("\n", $this->console); |
530 | 530 | $this->console = array(); |
531 | 531 | |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | public function ModUser($userid, $field) |
599 | 599 | { |
600 | 600 | global $modx; |
601 | - if (!array_key_exists($userid, $this->cache["ui"])) { |
|
601 | + if ( ! array_key_exists($userid, $this->cache["ui"])) { |
|
602 | 602 | if (intval($userid) < 0) { |
603 | 603 | $user = $modx->getWebUserInfo(-($userid)); |
604 | 604 | } else { |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | global $modx; |
624 | 624 | |
625 | 625 | // if $groupNames is not an array return false |
626 | - if (!is_array($groupNames)) { |
|
626 | + if ( ! is_array($groupNames)) { |
|
627 | 627 | return false; |
628 | 628 | } |
629 | 629 | |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | } |
634 | 634 | |
635 | 635 | // Creates an array with all webgroups the user id is in |
636 | - if (!array_key_exists($userid, $this->cache["mo"])) { |
|
636 | + if ( ! array_key_exists($userid, $this->cache["mo"])) { |
|
637 | 637 | $tbl = $modx->getFullTableName("webgroup_names"); |
638 | 638 | $tbl2 = $modx->getFullTableName("web_groups"); |
639 | 639 | $sql = "SELECT wgn.name FROM $tbl wgn INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wg.webuser='" . $userid . "'"; |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class DLphx |
17 | 17 | */ |
18 | -class DLphx |
|
19 | -{ |
|
18 | +class DLphx |
|
19 | +{ |
|
20 | 20 | public $placeholders = array(); |
21 | 21 | public $name = 'PHx'; |
22 | 22 | public $version = '2.2.0'; |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @param int|bool|string $debug |
44 | 44 | * @param int $maxpass |
45 | 45 | */ |
46 | - public function __construct($debug = false, $maxpass = 50) |
|
47 | - { |
|
46 | + public function __construct($debug = false, $maxpass = 50) |
|
47 | + { |
|
48 | 48 | global $modx; |
49 | 49 | |
50 | 50 | $this->user["mgrid"] = isset($_SESSION['mgrInternalKey']) ? intval($_SESSION['mgrInternalKey']) : 0; |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | $this->maxPasses = ($maxpass != '') ? $maxpass : 50; |
57 | 57 | |
58 | 58 | $modx->setPlaceholder("phx", "&_PHX_INTERNAL_&"); |
59 | - if (function_exists('mb_internal_encoding')) { |
|
59 | + if (function_exists('mb_internal_encoding')) { |
|
60 | 60 | mb_internal_encoding($modx->config['modx_charset']); |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | 64 | // Plugin event hook for MODx |
65 | - public function OnParseDocument() |
|
66 | - { |
|
65 | + public function OnParseDocument() |
|
66 | + { |
|
67 | 67 | global $modx; |
68 | 68 | // Get document output from MODx |
69 | 69 | $template = $modx->documentOutput; |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | * @param string $template |
79 | 79 | * @return mixed|string |
80 | 80 | */ |
81 | - public function Parse($template = '') |
|
82 | - { |
|
81 | + public function Parse($template = '') |
|
82 | + { |
|
83 | 83 | global $modx; |
84 | 84 | // If we already reached max passes don't get at it again. |
85 | - if ($this->curPass == $this->maxPasses) { |
|
85 | + if ($this->curPass == $this->maxPasses) { |
|
86 | 86 | return $template; |
87 | 87 | } |
88 | 88 | // Set template pre-process hash |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $template = $this->ParseValues($template); |
94 | 94 | // clean up unused placeholders that have modifiers attached (MODx can't clean them) |
95 | 95 | preg_match_all('~(?:=`[^`@]*?)(\[\+([^:\+\[\]]+)([^\[\]]*?)\+\])~s', $template, $matches); |
96 | - if ($matches[0]) { |
|
96 | + if ($matches[0]) { |
|
97 | 97 | $template = str_replace($matches[1], '', $template); |
98 | 98 | $this->Log("Cleaning unsolved tags: \n" . implode("\n", $matches[2])); |
99 | 99 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | // Set template post-process hash |
103 | 103 | $et = md5($template); |
104 | 104 | // If template has changed, parse it once more... |
105 | - if ($st != $et) { |
|
105 | + if ($st != $et) { |
|
106 | 106 | $template = $this->Parse($template); |
107 | 107 | } |
108 | 108 | // Write an event log if debugging is enabled and there is something to log |
109 | - if ($this->debug && $this->debugLog) { |
|
109 | + if ($this->debug && $this->debugLog) { |
|
110 | 110 | $modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name . ' ' . $this->version); |
111 | 111 | $this->debugLog = false; |
112 | 112 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $template |
121 | 121 | * @return mixed|string |
122 | 122 | */ |
123 | - public function ParseValues($template = '') |
|
124 | - { |
|
123 | + public function ParseValues($template = '') |
|
124 | + { |
|
125 | 125 | global $modx; |
126 | 126 | |
127 | 127 | $this->curPass = $this->curPass + 1; |
@@ -130,12 +130,12 @@ discard block |
||
130 | 130 | $this->LogPass(); |
131 | 131 | |
132 | 132 | // MODX Chunks |
133 | - if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) { |
|
133 | + if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) { |
|
134 | 134 | $this->Log('MODX Chunks -> Merging all chunk tags'); |
135 | 135 | $count = count($matches[0]); |
136 | 136 | $var_search = array(); |
137 | 137 | $var_replace = array(); |
138 | - for ($i = 0; $i < $count; $i++) { |
|
138 | + for ($i = 0; $i < $count; $i++) { |
|
139 | 139 | $var_search[] = $matches[0][$i]; |
140 | 140 | $input = $matches[1][$i]; |
141 | 141 | $this->Log('MODX Chunk: ' . $input); |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | |
148 | 148 | // MODx Snippets |
149 | 149 | //if ( preg_match_all('~\[(\[|!)([^\[]*?)(!|\])\]~s',$template, $matches)) { |
150 | - if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) { |
|
150 | + if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) { |
|
151 | 151 | $count = count($matches[0]); |
152 | 152 | $var_search = array(); |
153 | 153 | $var_replace = array(); |
154 | 154 | |
155 | 155 | // for each detected snippet |
156 | - for ($i = 0; $i < $count; $i++) { |
|
156 | + for ($i = 0; $i < $count; $i++) { |
|
157 | 157 | $snippet = $matches[2][$i]; // snippet call |
158 | 158 | $this->Log("MODx Snippet -> " . $snippet); |
159 | 159 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | } |
170 | 170 | |
171 | 171 | // PHx / MODx Tags |
172 | - if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) { |
|
172 | + if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) { |
|
173 | 173 | |
174 | 174 | //$matches[0] // Complete string that's need to be replaced |
175 | 175 | //$matches[1] // Type |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | $count = count($matches[0]); |
181 | 181 | $var_search = array(); |
182 | 182 | $var_replace = array(); |
183 | - for ($i = 0; $i < $count; $i++) { |
|
183 | + for ($i = 0; $i < $count; $i++) { |
|
184 | 184 | $input = $matches[2][$i]; |
185 | 185 | $modifiers = $matches[3][$i]; |
186 | 186 | $var_search[] = $matches[0][$i]; |
187 | - switch ($matches[1][$i]) { |
|
187 | + switch ($matches[1][$i]) { |
|
188 | 188 | // Document / Template Variable eXtended |
189 | 189 | case "*": |
190 | 190 | $this->Log("MODx TV/DV: " . $input); |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | // Check if placeholder is set |
204 | 204 | if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input, |
205 | 205 | $modx->placeholders) |
206 | - ) { |
|
206 | + ) { |
|
207 | 207 | // not set so try again later. |
208 | 208 | $input = ''; |
209 | - } else { |
|
209 | + } else { |
|
210 | 210 | // is set, get value and run filter |
211 | 211 | $input = $this->getPHxVariable($input); |
212 | 212 | } |
@@ -220,11 +220,11 @@ discard block |
||
220 | 220 | $et = md5($template); // Post-process template hash |
221 | 221 | |
222 | 222 | // Log an event if this was the maximum pass |
223 | - if ($this->curPass == $this->maxPasses) { |
|
223 | + if ($this->curPass == $this->maxPasses) { |
|
224 | 224 | $this->Log("Max passes reached. infinite loop protection so exiting.\n If you need the extra passes set the max passes to the highest count of nested tags in your template."); |
225 | 225 | } |
226 | 226 | // If this pass is not at maximum passes and the template hash is not the same, get at it again. |
227 | - if (($this->curPass < $this->maxPasses) && ($st != $et)) { |
|
227 | + if (($this->curPass < $this->maxPasses) && ($st != $et)) { |
|
228 | 228 | $template = $this->ParseValues($template); |
229 | 229 | } |
230 | 230 | |
@@ -237,23 +237,23 @@ discard block |
||
237 | 237 | * @param $modifiers |
238 | 238 | * @return mixed|null|string |
239 | 239 | */ |
240 | - public function Filter($input, $modifiers) |
|
241 | - { |
|
240 | + public function Filter($input, $modifiers) |
|
241 | + { |
|
242 | 242 | global $modx; |
243 | 243 | $output = $input; |
244 | 244 | $this->Log(" |--- Input = '" . $output . "'"); |
245 | - if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) { |
|
245 | + if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) { |
|
246 | 246 | $modifier_cmd = $matches[1]; // modifier command |
247 | 247 | $modifier_value = $matches[2]; // modifier value |
248 | 248 | $count = count($modifier_cmd); |
249 | 249 | $condition = array(); |
250 | - for ($i = 0; $i < $count; $i++) { |
|
250 | + for ($i = 0; $i < $count; $i++) { |
|
251 | 251 | $output = trim($output); |
252 | 252 | $this->Log(" |--- Modifier = '" . $modifier_cmd[$i] . "'"); |
253 | - if ($modifier_value[$i] != '') { |
|
253 | + if ($modifier_value[$i] != '') { |
|
254 | 254 | $this->Log(" |--- Options = '" . $modifier_value[$i] . "'"); |
255 | 255 | } |
256 | - switch ($modifier_cmd[$i]) { |
|
256 | + switch ($modifier_cmd[$i]) { |
|
257 | 257 | ##### Conditional Modifiers |
258 | 258 | case "input": |
259 | 259 | case "if": |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | case "ir": |
296 | 296 | case "memberof": |
297 | 297 | case "mo": // Is Member Of (same as inrole but this one can be stringed as a conditional) |
298 | - if ($output == "&_PHX_INTERNAL_&") { |
|
298 | + if ($output == "&_PHX_INTERNAL_&") { |
|
299 | 299 | $output = $this->user["id"]; |
300 | 300 | } |
301 | 301 | $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array(); |
@@ -310,23 +310,23 @@ discard block |
||
310 | 310 | case "show": |
311 | 311 | $conditional = implode(' ', $condition); |
312 | 312 | $isvalid = intval($this->runCode($conditional)); |
313 | - if (!$isvalid) { |
|
313 | + if (!$isvalid) { |
|
314 | 314 | $output = null; |
315 | 315 | } |
316 | 316 | break; |
317 | 317 | case "then": |
318 | 318 | $conditional = implode(' ', $condition); |
319 | 319 | $isvalid = intval($this->runCode($conditional)); |
320 | - if ($isvalid) { |
|
320 | + if ($isvalid) { |
|
321 | 321 | $output = $modifier_value[$i]; |
322 | - } else { |
|
322 | + } else { |
|
323 | 323 | $output = null; |
324 | 324 | } |
325 | 325 | break; |
326 | 326 | case "else": |
327 | 327 | $conditional = implode(' ', $condition); |
328 | 328 | $isvalid = intval($this->runCode($condition)); |
329 | - if (!$isvalid) { |
|
329 | + if (!$isvalid) { |
|
330 | 330 | $output = $modifier_value[$i]; |
331 | 331 | } |
332 | 332 | break; |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | $raw = explode("&", $modifier_value[$i]); |
335 | 335 | $map = array(); |
336 | 336 | $count = count($raw); |
337 | - for ($m = 0; $m < $count; $m++) { |
|
337 | + for ($m = 0; $m < $count; $m++) { |
|
338 | 338 | $mi = explode("=", $raw[$m]); |
339 | 339 | $map[$mi[0]] = $mi[1]; |
340 | 340 | } |
@@ -415,13 +415,13 @@ discard block |
||
415 | 415 | $output = eval("return " . $filter . ";"); |
416 | 416 | break; |
417 | 417 | case "isnotempty": |
418 | - if (!empty($output)) { |
|
418 | + if (!empty($output)) { |
|
419 | 419 | $output = $modifier_value[$i]; |
420 | 420 | } |
421 | 421 | break; |
422 | 422 | case "isempty": |
423 | 423 | case "ifempty": |
424 | - if (empty($output)) { |
|
424 | + if (empty($output)) { |
|
425 | 425 | $output = $modifier_value[$i]; |
426 | 426 | } |
427 | 427 | break; |
@@ -433,12 +433,12 @@ discard block |
||
433 | 433 | break; |
434 | 434 | case "set": |
435 | 435 | $c = $i + 1; |
436 | - if ($count > $c && $modifier_cmd[$c] == "value") { |
|
436 | + if ($count > $c && $modifier_cmd[$c] == "value") { |
|
437 | 437 | $output = preg_replace("~([^a-zA-Z0-9])~", "", $modifier_value[$i]); |
438 | 438 | } |
439 | 439 | break; |
440 | 440 | case "value": |
441 | - if ($i > 0 && $modifier_cmd[$i - 1] == "set") { |
|
441 | + if ($i > 0 && $modifier_cmd[$i - 1] == "set") { |
|
442 | 442 | $modx->SetPlaceholder("phx." . $output, $modifier_value[$i]); |
443 | 443 | } |
444 | 444 | $output = null; |
@@ -447,13 +447,13 @@ discard block |
||
447 | 447 | $output = md5($output); |
448 | 448 | break; |
449 | 449 | case "userinfo": |
450 | - if ($output == "&_PHX_INTERNAL_&") { |
|
450 | + if ($output == "&_PHX_INTERNAL_&") { |
|
451 | 451 | $output = $this->user["id"]; |
452 | 452 | } |
453 | 453 | $output = $this->ModUser($output, $modifier_value[$i]); |
454 | 454 | break; |
455 | 455 | case "inrole": // deprecated |
456 | - if ($output == "&_PHX_INTERNAL_&") { |
|
456 | + if ($output == "&_PHX_INTERNAL_&") { |
|
457 | 457 | $output = $this->user["id"]; |
458 | 458 | } |
459 | 459 | $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array(); |
@@ -465,19 +465,21 @@ discard block |
||
465 | 465 | $snippet = ''; |
466 | 466 | // modified by Anton Kuzmin (23.06.2010) // |
467 | 467 | $snippetName = 'phx:' . $modifier_cmd[$i]; |
468 | - if (isset($modx->snippetCache[$snippetName])) { |
|
468 | + if (isset($modx->snippetCache[$snippetName])) { |
|
469 | 469 | $snippet = $modx->snippetCache[$snippetName]; |
470 | - } else { // not in cache so let's check the db |
|
470 | + } else { |
|
471 | +// not in cache so let's check the db |
|
471 | 472 | $sql = "SELECT snippet FROM " . $modx->getFullTableName("site_snippets") . " WHERE " . $modx->getFullTableName("site_snippets") . ".name='" . $modx->db->escape($snippetName) . "';"; |
472 | 473 | $result = $modx->dbQuery($sql); |
473 | - if ($modx->recordCount($result) == 1) { |
|
474 | + if ($modx->recordCount($result) == 1) { |
|
474 | 475 | $row = $modx->fetchRow($result); |
475 | 476 | $snippet = $modx->snippetCache[$row['name']] = $row['snippet']; |
476 | 477 | $this->Log(" |--- DB -> Custom Modifier"); |
477 | - } else { |
|
478 | - if ($modx->recordCount($result) == 0) { // If snippet not found, look in the modifiers folder |
|
478 | + } else { |
|
479 | + if ($modx->recordCount($result) == 0) { |
|
480 | +// If snippet not found, look in the modifiers folder |
|
479 | 481 | $filename = $modx->config['rb_base_dir'] . 'plugins/phx/modifiers/' . $modifier_cmd[$i] . '.phx.php'; |
480 | - if (@file_exists($filename)) { |
|
482 | + if (@file_exists($filename)) { |
|
481 | 483 | $file_contents = @file_get_contents($filename); |
482 | 484 | $file_contents = str_replace('<' . '?php', '', $file_contents); |
483 | 485 | $file_contents = str_replace('?' . '>', '', $file_contents); |
@@ -485,7 +487,7 @@ discard block |
||
485 | 487 | $snippet = $modx->snippetCache[$snippetName] = $file_contents; |
486 | 488 | $modx->snippetCache[$snippetName . 'Props'] = ''; |
487 | 489 | $this->Log(" |--- File ($filename) -> Custom Modifier"); |
488 | - } else { |
|
490 | + } else { |
|
489 | 491 | $this->Log(" |--- PHX Error: {$modifier_cmd[$i]} could not be found"); |
490 | 492 | } |
491 | 493 | } |
@@ -494,19 +496,19 @@ discard block |
||
494 | 496 | $cm = $snippet; |
495 | 497 | // end // |
496 | 498 | |
497 | - if (!empty($cm)) { |
|
499 | + if (!empty($cm)) { |
|
498 | 500 | ob_start(); |
499 | 501 | $options = $modifier_value[$i]; |
500 | 502 | $custom = eval($cm); |
501 | 503 | $msg = ob_get_contents(); |
502 | 504 | $output = $msg . $custom; |
503 | 505 | ob_end_clean(); |
504 | - } else { |
|
506 | + } else { |
|
505 | 507 | $output = ''; |
506 | 508 | } |
507 | 509 | break; |
508 | 510 | } |
509 | - if (count($condition)) { |
|
511 | + if (count($condition)) { |
|
510 | 512 | $this->Log(" |--- Condition = '" . $condition[count($condition) - 1] . "'"); |
511 | 513 | } |
512 | 514 | $this->Log(" |--- Output = '" . $output . "'"); |
@@ -516,16 +518,17 @@ discard block |
||
516 | 518 | return $output; |
517 | 519 | } |
518 | 520 | |
519 | - private function runCode($code){ |
|
521 | + private function runCode($code) |
|
522 | + { |
|
520 | 523 | return eval("return (" . $code . ");"); |
521 | 524 | } |
522 | 525 | // Event logging (debug) |
523 | 526 | /** |
524 | 527 | * @return string |
525 | 528 | */ |
526 | - public function createEventLog() |
|
527 | - { |
|
528 | - if (!empty($this->console)) { |
|
529 | + public function createEventLog() |
|
530 | + { |
|
531 | + if (!empty($this->console)) { |
|
529 | 532 | $console = implode("\n", $this->console); |
530 | 533 | $this->console = array(); |
531 | 534 | |
@@ -538,8 +541,8 @@ discard block |
||
538 | 541 | * @param $string |
539 | 542 | * @return array|mixed|string |
540 | 543 | */ |
541 | - public function LogClean($string) |
|
542 | - { |
|
544 | + public function LogClean($string) |
|
545 | + { |
|
543 | 546 | $string = preg_replace("/&(#[0-9]+|[a-z]+);/i", "&$1;", $string); |
544 | 547 | $string = APIHelpers::sanitarTag($string); |
545 | 548 | |
@@ -550,9 +553,9 @@ discard block |
||
550 | 553 | /** |
551 | 554 | * @param $string |
552 | 555 | */ |
553 | - public function Log($string) |
|
554 | - { |
|
555 | - if ($this->debug) { |
|
556 | + public function Log($string) |
|
557 | + { |
|
558 | + if ($this->debug) { |
|
556 | 559 | $this->debugLog = true; |
557 | 560 | $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S", |
558 | 561 | time()) . "] " . $this->LogClean($string); |
@@ -563,9 +566,9 @@ discard block |
||
563 | 566 | /** |
564 | 567 | * @param $string |
565 | 568 | */ |
566 | - public function LogSnippet($string) |
|
567 | - { |
|
568 | - if ($this->debug) { |
|
569 | + public function LogSnippet($string) |
|
570 | + { |
|
571 | + if ($this->debug) { |
|
569 | 572 | $this->debugLog = true; |
570 | 573 | $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S", |
571 | 574 | time()) . "] " . " |--- Returns: <div style='margin: 10px;'>" . $this->LogClean($string) . "</div>"; |
@@ -573,8 +576,8 @@ discard block |
||
573 | 576 | } |
574 | 577 | |
575 | 578 | // Log pass |
576 | - public function LogPass() |
|
577 | - { |
|
579 | + public function LogPass() |
|
580 | + { |
|
578 | 581 | $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>"; |
579 | 582 | } |
580 | 583 | |
@@ -582,8 +585,8 @@ discard block |
||
582 | 585 | /** |
583 | 586 | * @param $string |
584 | 587 | */ |
585 | - public function LogSource($string) |
|
586 | - { |
|
588 | + public function LogSource($string) |
|
589 | + { |
|
587 | 590 | $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string); |
588 | 591 | } |
589 | 592 | |
@@ -595,17 +598,17 @@ discard block |
||
595 | 598 | * @param $field |
596 | 599 | * @return mixed |
597 | 600 | */ |
598 | - public function ModUser($userid, $field) |
|
599 | - { |
|
601 | + public function ModUser($userid, $field) |
|
602 | + { |
|
600 | 603 | global $modx; |
601 | - if (!array_key_exists($userid, $this->cache["ui"])) { |
|
602 | - if (intval($userid) < 0) { |
|
604 | + if (!array_key_exists($userid, $this->cache["ui"])) { |
|
605 | + if (intval($userid) < 0) { |
|
603 | 606 | $user = $modx->getWebUserInfo(-($userid)); |
604 | - } else { |
|
607 | + } else { |
|
605 | 608 | $user = $modx->getUserInfo($userid); |
606 | 609 | } |
607 | 610 | $this->cache["ui"][$userid] = $user; |
608 | - } else { |
|
611 | + } else { |
|
609 | 612 | $user = $this->cache["ui"][$userid]; |
610 | 613 | } |
611 | 614 | |
@@ -618,32 +621,32 @@ discard block |
||
618 | 621 | * @param array $groupNames |
619 | 622 | * @return bool |
620 | 623 | */ |
621 | - public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
|
622 | - { |
|
624 | + public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
|
625 | + { |
|
623 | 626 | global $modx; |
624 | 627 | |
625 | 628 | // if $groupNames is not an array return false |
626 | - if (!is_array($groupNames)) { |
|
629 | + if (!is_array($groupNames)) { |
|
627 | 630 | return false; |
628 | 631 | } |
629 | 632 | |
630 | 633 | // if the user id is a negative number make it positive |
631 | - if (intval($userid) < 0) { |
|
634 | + if (intval($userid) < 0) { |
|
632 | 635 | $userid = -($userid); |
633 | 636 | } |
634 | 637 | |
635 | 638 | // Creates an array with all webgroups the user id is in |
636 | - if (!array_key_exists($userid, $this->cache["mo"])) { |
|
639 | + if (!array_key_exists($userid, $this->cache["mo"])) { |
|
637 | 640 | $tbl = $modx->getFullTableName("webgroup_names"); |
638 | 641 | $tbl2 = $modx->getFullTableName("web_groups"); |
639 | 642 | $sql = "SELECT wgn.name FROM $tbl wgn INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wg.webuser='" . $userid . "'"; |
640 | 643 | $this->cache["mo"][$userid] = $grpNames = $modx->db->getColumn("name", $sql); |
641 | - } else { |
|
644 | + } else { |
|
642 | 645 | $grpNames = $this->cache["mo"][$userid]; |
643 | 646 | } |
644 | 647 | // Check if a supplied group matches a webgroup from the array we just created |
645 | - foreach ($groupNames as $k => $v) { |
|
646 | - if (in_array(trim($v), $grpNames)) { |
|
648 | + foreach ($groupNames as $k => $v) { |
|
649 | + if (in_array(trim($v), $grpNames)) { |
|
647 | 650 | return true; |
648 | 651 | } |
649 | 652 | } |
@@ -657,14 +660,14 @@ discard block |
||
657 | 660 | * @param $name |
658 | 661 | * @return mixed|string |
659 | 662 | */ |
660 | - public function getPHxVariable($name) |
|
661 | - { |
|
663 | + public function getPHxVariable($name) |
|
664 | + { |
|
662 | 665 | global $modx; |
663 | 666 | // Check if this variable is created by PHx |
664 | - if (array_key_exists($name, $this->placeholders)) { |
|
667 | + if (array_key_exists($name, $this->placeholders)) { |
|
665 | 668 | // Return the value from PHx |
666 | 669 | return $this->placeholders[$name]; |
667 | - } else { |
|
670 | + } else { |
|
668 | 671 | // Return the value from MODx |
669 | 672 | return $modx->getPlaceholder($name); |
670 | 673 | } |
@@ -675,9 +678,9 @@ discard block |
||
675 | 678 | * @param $name |
676 | 679 | * @param $value |
677 | 680 | */ |
678 | - public function setPHxVariable($name, $value) |
|
679 | - { |
|
680 | - if ($name != "phx") { |
|
681 | + public function setPHxVariable($name, $value) |
|
682 | + { |
|
683 | + if ($name != "phx") { |
|
681 | 684 | $this->placeholders[$name] = $value; |
682 | 685 | } |
683 | 686 | } |
@@ -689,9 +692,9 @@ discard block |
||
689 | 692 | * @param null $l |
690 | 693 | * @return string |
691 | 694 | */ |
692 | - public function substr($str, $s, $l = null) |
|
693 | - { |
|
694 | - if (function_exists('mb_substr')) { |
|
695 | + public function substr($str, $s, $l = null) |
|
696 | + { |
|
697 | + if (function_exists('mb_substr')) { |
|
695 | 698 | return mb_substr($str, $s, $l); |
696 | 699 | } |
697 | 700 | |
@@ -702,9 +705,9 @@ discard block |
||
702 | 705 | * @param $str |
703 | 706 | * @return int |
704 | 707 | */ |
705 | - public function strlen($str) |
|
706 | - { |
|
707 | - if (function_exists('mb_strlen')) { |
|
708 | + public function strlen($str) |
|
709 | + { |
|
710 | + if (function_exists('mb_strlen')) { |
|
708 | 711 | return mb_strlen($str); |
709 | 712 | } |
710 | 713 | |
@@ -715,9 +718,9 @@ discard block |
||
715 | 718 | * @param $str |
716 | 719 | * @return string |
717 | 720 | */ |
718 | - public function strtolower($str) |
|
719 | - { |
|
720 | - if (function_exists('mb_strtolower')) { |
|
721 | + public function strtolower($str) |
|
722 | + { |
|
723 | + if (function_exists('mb_strtolower')) { |
|
721 | 724 | return mb_strtolower($str); |
722 | 725 | } |
723 | 726 | |
@@ -728,9 +731,9 @@ discard block |
||
728 | 731 | * @param $str |
729 | 732 | * @return string |
730 | 733 | */ |
731 | - public function strtoupper($str) |
|
732 | - { |
|
733 | - if (function_exists('mb_strtoupper')) { |
|
734 | + public function strtoupper($str) |
|
735 | + { |
|
736 | + if (function_exists('mb_strtoupper')) { |
|
734 | 737 | return mb_strtoupper($str); |
735 | 738 | } |
736 | 739 | |
@@ -741,9 +744,9 @@ discard block |
||
741 | 744 | * @param $str |
742 | 745 | * @return string |
743 | 746 | */ |
744 | - public function ucfirst($str) |
|
745 | - { |
|
746 | - if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
747 | + public function ucfirst($str) |
|
748 | + { |
|
749 | + if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
747 | 750 | return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
748 | 751 | } |
749 | 752 | |
@@ -754,9 +757,9 @@ discard block |
||
754 | 757 | * @param $str |
755 | 758 | * @return string |
756 | 759 | */ |
757 | - public function lcfirst($str) |
|
758 | - { |
|
759 | - if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
760 | + public function lcfirst($str) |
|
761 | + { |
|
762 | + if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
760 | 763 | return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
761 | 764 | } |
762 | 765 | |
@@ -767,9 +770,9 @@ discard block |
||
767 | 770 | * @param $str |
768 | 771 | * @return string |
769 | 772 | */ |
770 | - public function ucwords($str) |
|
771 | - { |
|
772 | - if (function_exists('mb_convert_case')) { |
|
773 | + public function ucwords($str) |
|
774 | + { |
|
775 | + if (function_exists('mb_convert_case')) { |
|
773 | 776 | return mb_convert_case($str, MB_CASE_TITLE); |
774 | 777 | } |
775 | 778 | |
@@ -780,8 +783,8 @@ discard block |
||
780 | 783 | * @param $str |
781 | 784 | * @return string |
782 | 785 | */ |
783 | - public function strrev($str) |
|
784 | - { |
|
786 | + public function strrev($str) |
|
787 | + { |
|
785 | 788 | preg_match_all('/./us', $str, $ar); |
786 | 789 | |
787 | 790 | return implode(array_reverse($ar[0])); |
@@ -791,8 +794,8 @@ discard block |
||
791 | 794 | * @param $str |
792 | 795 | * @return string |
793 | 796 | */ |
794 | - public function str_shuffle($str) |
|
795 | - { |
|
797 | + public function str_shuffle($str) |
|
798 | + { |
|
796 | 799 | preg_match_all('/./us', $str, $ar); |
797 | 800 | shuffle($ar[0]); |
798 | 801 | |
@@ -803,8 +806,8 @@ discard block |
||
803 | 806 | * @param $str |
804 | 807 | * @return int |
805 | 808 | */ |
806 | - public function str_word_count($str) |
|
807 | - { |
|
809 | + public function str_word_count($str) |
|
810 | + { |
|
808 | 811 | return count(preg_split('~[^\p{L}\p{N}\']+~u', $str)); |
809 | 812 | } |
810 | 813 | } |