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