@@ -95,20 +95,20 @@ discard block |
||
95 | 95 | $out = array_diff_key(parent::toArray(), $this->default_field); |
96 | 96 | $tpl = $this->get('template'); |
97 | 97 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
98 | - foreach($tvTPL as $item){ |
|
99 | - if(isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)){ |
|
98 | + foreach ($tvTPL as $item) { |
|
99 | + if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { |
|
100 | 100 | $out[$this->tvid[$item]] = $this->get($this->tvid[$item]); |
101 | 101 | } |
102 | 102 | } |
103 | - if($render){ |
|
104 | - foreach($out as $key => $val){ |
|
103 | + if ($render) { |
|
104 | + foreach ($out as $key => $val) { |
|
105 | 105 | $out[$key] = $this->renderTV($key); |
106 | 106 | } |
107 | 107 | } |
108 | 108 | return $out; |
109 | 109 | } |
110 | 110 | |
111 | - public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true){ |
|
111 | + public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) { |
|
112 | 112 | $out = array_merge( |
113 | 113 | $this->toArrayMain(), |
114 | 114 | $this->toArrayTV($render), |
@@ -116,17 +116,17 @@ discard block |
||
116 | 116 | ); |
117 | 117 | return \APIhelpers::renameKeyArr($out, $prefix, $suffix, $sep); |
118 | 118 | } |
119 | - public function getUrl(){ |
|
119 | + public function getUrl() { |
|
120 | 120 | $out = null; |
121 | 121 | $id = (int)$this->getID(); |
122 | - if(!empty($id)){ |
|
122 | + if (!empty($id)) { |
|
123 | 123 | $out = $this->modx->makeUrl($id); |
124 | 124 | } |
125 | 125 | return $out; |
126 | 126 | } |
127 | - public function getTitle($main = 'menutitle', $second = 'pagetitle'){ |
|
127 | + public function getTitle($main = 'menutitle', $second = 'pagetitle') { |
|
128 | 128 | $title = $this->get($main); |
129 | - if(empty($title) && $title !== '0'){ |
|
129 | + if (empty($title) && $title !== '0') { |
|
130 | 130 | $title = $this->get($second); |
131 | 131 | } |
132 | 132 | return $title; |
@@ -139,16 +139,16 @@ discard block |
||
139 | 139 | $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time())); |
140 | 140 | return ($pub && $unpub && $del); |
141 | 141 | } |
142 | - public function touch(){ |
|
142 | + public function touch() { |
|
143 | 143 | $this->set('editedon', time()); |
144 | 144 | return $this; |
145 | 145 | } |
146 | 146 | |
147 | - public function renderTV($tvname){ |
|
147 | + public function renderTV($tvname) { |
|
148 | 148 | $out = null; |
149 | - if($this->getID() > 0){ |
|
150 | - include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php"; |
|
151 | - include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php"; |
|
149 | + if ($this->getID() > 0) { |
|
150 | + include_once MODX_MANAGER_PATH."includes/tmplvars.format.inc.php"; |
|
151 | + include_once MODX_MANAGER_PATH."includes/tmplvars.commands.inc.php"; |
|
152 | 152 | $tvval = $this->get($tvname); |
153 | 153 | $param = APIHelpers::getkey($this->tvd, $tvname, array()); |
154 | 154 | $display = APIHelpers::getkey($param, 'display', ''); |
@@ -159,13 +159,13 @@ discard block |
||
159 | 159 | return $out; |
160 | 160 | } |
161 | 161 | |
162 | - public function get($key){ |
|
162 | + public function get($key) { |
|
163 | 163 | $out = parent::get($key); |
164 | - if(isset($this->tv[$key])){ |
|
164 | + if (isset($this->tv[$key])) { |
|
165 | 165 | $tpl = $this->get('template'); |
166 | 166 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
167 | 167 | $tvID = APIHelpers::getkey($this->tv, $key, 0); |
168 | - if(in_array($tvID, $tvTPL) && is_null($out)){ |
|
168 | + if (in_array($tvID, $tvTPL) && is_null($out)) { |
|
169 | 169 | $out = APIHelpers::getkey($this->tvd[$key], 'value', null); |
170 | 170 | } |
171 | 171 | } |
@@ -185,38 +185,38 @@ discard block |
||
185 | 185 | break; |
186 | 186 | case 'published': |
187 | 187 | $value = (int)((bool)$value); |
188 | - if($value){ |
|
188 | + if ($value) { |
|
189 | 189 | $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time'); |
190 | 190 | } |
191 | 191 | break; |
192 | 192 | case 'pub_date': |
193 | 193 | $value = $this->getTime($value); |
194 | - if($value > 0 && time() + $this->modxConfig('server_offset_time') > $value){ |
|
194 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
195 | 195 | $this->field['published'] = 1; |
196 | 196 | $this->field['publishedon'] = $value; |
197 | 197 | } |
198 | 198 | break; |
199 | 199 | case 'unpub_date': |
200 | 200 | $value = $this->getTime($value); |
201 | - if($value > 0 && time() + $this->modxConfig('server_offset_time') > $value){ |
|
201 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
202 | 202 | $this->field['published'] = 0; |
203 | 203 | $this->field['publishedon'] = 0; |
204 | 204 | } |
205 | 205 | break; |
206 | 206 | case 'deleted': |
207 | 207 | $value = (int)((bool)$value); |
208 | - if($value){ |
|
208 | + if ($value) { |
|
209 | 209 | $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time'); |
210 | - }else{ |
|
210 | + } else { |
|
211 | 211 | $this->field['deletedon'] = 0; |
212 | 212 | } |
213 | 213 | break; |
214 | 214 | case 'deletedon': |
215 | 215 | $value = $this->getTime($value); |
216 | - if($value > 0 && time() + $this->modxConfig('server_offset_time') < $value){ |
|
216 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) { |
|
217 | 217 | $value = 0; |
218 | 218 | } |
219 | - if($value){ |
|
219 | + if ($value) { |
|
220 | 220 | $this->field['deleted'] = 1; |
221 | 221 | } |
222 | 222 | break; |
@@ -237,19 +237,19 @@ discard block |
||
237 | 237 | return $this; |
238 | 238 | } |
239 | 239 | |
240 | - protected function getUser($value, $default = 0){ |
|
240 | + protected function getUser($value, $default = 0) { |
|
241 | 241 | $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0); |
242 | 242 | $value = (int)$value; |
243 | - if(!empty($value)){ |
|
243 | + if (!empty($value)) { |
|
244 | 244 | $by = $this->findUserBy($value); |
245 | 245 | $exists = $this->managerUsers->exists(function($key, $val) use ($by, $value){ |
246 | 246 | return ($val->containsKey($by) && $val->get($by) === (string)$value); |
247 | 247 | }); |
248 | - if(!$exists){ |
|
248 | + if (!$exists) { |
|
249 | 249 | $value = 0; |
250 | 250 | } |
251 | 251 | } |
252 | - if(empty($value)){ |
|
252 | + if (empty($value)) { |
|
253 | 253 | $value = empty($currentAdmin) ? $default : $currentAdmin; |
254 | 254 | } |
255 | 255 | return $value; |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | return $find; |
274 | 274 | } |
275 | 275 | |
276 | - protected function getTime($value){ |
|
276 | + protected function getTime($value) { |
|
277 | 277 | $value = trim($value); |
278 | - if(!empty($value)){ |
|
279 | - if(!is_numeric($value)){ |
|
278 | + if (!empty($value)) { |
|
279 | + if (!is_numeric($value)) { |
|
280 | 280 | $value = (int)strtotime($value); |
281 | 281 | } |
282 | - if(!empty($value)){ |
|
282 | + if (!empty($value)) { |
|
283 | 283 | $value += $this->modxConfig('server_offset_time'); |
284 | 284 | } |
285 | 285 | } |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | $this->close(); |
303 | 303 | $this->newDoc = false; |
304 | 304 | |
305 | - $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id); |
|
305 | + $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=".(int)$id); |
|
306 | 306 | $this->fromArray($this->modx->db->getRow($result)); |
307 | - $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id); |
|
307 | + $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=".(int)$id); |
|
308 | 308 | while ($row = $this->modx->db->getRow($result)) { |
309 | 309 | $this->field[$this->tvid[$row['tmplvarid']]] = $row['value']; |
310 | 310 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | { |
324 | 324 | $parent = null; |
325 | 325 | if ($this->field['pagetitle'] == '') { |
326 | - $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>'; |
|
326 | + $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>'.print_r($this->field, true).'</pre>'; |
|
327 | 327 | return false; |
328 | 328 | } |
329 | 329 | |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | $fld = $this->toArray(null, null, null, false); |
340 | 340 | foreach ($this->default_field as $key => $value) { |
341 | 341 | $tmp = $this->get($key); |
342 | - if ($this->newDoc && ( !is_int($tmp) && $tmp=='')) { |
|
343 | - if($tmp == $value){ |
|
342 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
343 | + if ($tmp == $value) { |
|
344 | 344 | switch ($key) { |
345 | 345 | case 'cacheable': |
346 | 346 | $value = $this->modxConfig('cache_default'); |
@@ -361,11 +361,11 @@ discard block |
||
361 | 361 | } |
362 | 362 | $this->field[$key] = $value; |
363 | 363 | } |
364 | - switch(true){ |
|
364 | + switch (true) { |
|
365 | 365 | case $key == 'parent': |
366 | 366 | $parent = (int)$this->get($key); |
367 | 367 | $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'"); |
368 | - if($this->modx->db->getValue($q)!=1){ |
|
368 | + if ($this->modx->db->getValue($q) != 1) { |
|
369 | 369 | $parent = $value; |
370 | 370 | } |
371 | 371 | $this->field[$key] = $parent; |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | |
383 | 383 | if (!empty($this->set)) { |
384 | 384 | if ($this->newDoc) { |
385 | - $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); |
|
385 | + $SQL = "INSERT into {$this->makeTable('site_content')} SET ".implode(', ', $this->set); |
|
386 | 386 | } else { |
387 | - $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ', $this->set) . " WHERE `id` = " . $this->id; |
|
387 | + $SQL = "UPDATE {$this->makeTable('site_content')} SET ".implode(', ', $this->set)." WHERE `id` = ".$this->id; |
|
388 | 388 | } |
389 | 389 | $this->query($SQL); |
390 | 390 | |
@@ -428,20 +428,20 @@ discard block |
||
428 | 428 | return $this->id; |
429 | 429 | } |
430 | 430 | |
431 | - public function toTrash($ids){ |
|
431 | + public function toTrash($ids) { |
|
432 | 432 | $ignore = $this->systemID(); |
433 | 433 | $_ids = $this->cleanIDs($ids, ',', $ignore); |
434 | 434 | if (is_array($_ids) && $_ids != array()) { |
435 | 435 | $id = $this->sanitarIn($_ids); |
436 | 436 | $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`='1' WHERE `id` IN ({$id})"); |
437 | - } else throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
437 | + } else throw new Exception('Invalid IDs list for mark trash: <pre>'.print_r($ids, 1).'</pre> please, check ignore list: <pre>'.print_r($ignore, 1).'</pre>'); |
|
438 | 438 | return $this; |
439 | 439 | } |
440 | - public function clearTrash($fire_events = null){ |
|
440 | + public function clearTrash($fire_events = null) { |
|
441 | 441 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'"); |
442 | 442 | $q = $this->modx->makeArray($q); |
443 | 443 | $_ids = array(); |
444 | - foreach($q as $item){ |
|
444 | + foreach ($q as $item) { |
|
445 | 445 | $_ids[] = $item['id']; |
446 | 446 | } |
447 | 447 | if (is_array($_ids) && $_ids != array()) { |
@@ -465,10 +465,10 @@ discard block |
||
465 | 465 | $_ids = $this->cleanIDs($ids, ','); |
466 | 466 | if (is_array($_ids) && $_ids != array()) { |
467 | 467 | $id = $this->sanitarIn($_ids); |
468 | - if(!empty($id)) { |
|
468 | + if (!empty($id)) { |
|
469 | 469 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); |
470 | 470 | $id = $this->modx->db->getColumn('id', $q); |
471 | - if($depth > 0 || (is_bool($depth) && $depth == true)){ |
|
471 | + if ($depth > 0 || (is_bool($depth) && $depth == true)) { |
|
472 | 472 | $id = $this->childrens($id, is_bool($depth) ? $depth : ($depth - 1)); |
473 | 473 | } |
474 | 474 | $_ids = array_merge($_ids, $id); |
@@ -487,14 +487,14 @@ discard block |
||
487 | 487 | ), $fire_events); |
488 | 488 | |
489 | 489 | $id = $this->sanitarIn($_ids); |
490 | - if(!empty($id)){ |
|
490 | + if (!empty($id)) { |
|
491 | 491 | $this->query("DELETE from {$this->makeTable('site_content')} where `id` IN ({$id})"); |
492 | 492 | $this->query("DELETE from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid` IN ({$id})"); |
493 | 493 | $this->invokeEvent('OnEmptyTrash', array( |
494 | 494 | "ids" => $_ids |
495 | 495 | ), $fire_events); |
496 | 496 | } |
497 | - } else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
|
497 | + } else throw new Exception('Invalid IDs list for delete: <pre>'.print_r($ids, 1).'</pre> please, check ignore list: <pre>'.print_r($ignore, 1).'</pre>'); |
|
498 | 498 | |
499 | 499 | return $this; |
500 | 500 | } |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | $suffix = substr($alias, -2); |
532 | 532 | if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { |
533 | 533 | $suffix = (int)$tmp[1] + 1; |
534 | - $alias = substr($alias, 0, -2) . '-' . $suffix; |
|
534 | + $alias = substr($alias, 0, -2).'-'.$suffix; |
|
535 | 535 | } else { |
536 | 536 | $alias .= '-2'; |
537 | 537 | } |
@@ -549,30 +549,30 @@ discard block |
||
549 | 549 | protected function get_TV($reload = false) |
550 | 550 | { |
551 | 551 | if (empty($this->modx->_TVnames) || $reload) { |
552 | - $result = $this->query('SELECT `id`,`name` FROM ' . $this->makeTable('site_tmplvars')); |
|
552 | + $result = $this->query('SELECT `id`,`name` FROM '.$this->makeTable('site_tmplvars')); |
|
553 | 553 | while ($row = $this->modx->db->GetRow($result)) { |
554 | 554 | $this->modx->_TVnames[$row['name']] = $row['id']; |
555 | 555 | } |
556 | 556 | } |
557 | - foreach($this->modx->_TVnames as $name => $id){ |
|
557 | + foreach ($this->modx->_TVnames as $name => $id) { |
|
558 | 558 | $this->tvid[$id] = $name; |
559 | 559 | $this->tv[$name] = $id; |
560 | 560 | } |
561 | 561 | $this->loadTVTemplate()->loadTVDefault(array_values($this->tv)); |
562 | 562 | return $this; |
563 | 563 | } |
564 | - protected function loadTVTemplate(){ |
|
564 | + protected function loadTVTemplate() { |
|
565 | 565 | $q = $this->query("SELECT `tmplvarid`, `templateid` FROM ".$this->makeTable('site_tmplvar_templates')); |
566 | 566 | $q = $this->modx->db->makeArray($q); |
567 | 567 | $this->tvTpl = array(); |
568 | - foreach($q as $item){ |
|
568 | + foreach ($q as $item) { |
|
569 | 569 | $this->tvTpl[$item['templateid']][] = $item['tmplvarid']; |
570 | 570 | } |
571 | 571 | return $this; |
572 | 572 | } |
573 | 573 | protected function loadTVDefault(array $tvId = array()) |
574 | 574 | { |
575 | - if(is_array($tvId) && !empty($tvId)){ |
|
575 | + if (is_array($tvId) && !empty($tvId)) { |
|
576 | 576 | $tbl_site_tmplvars = $this->makeTable('site_tmplvars'); |
577 | 577 | $fields = 'id,name,default_text as value,display,display_params,type'; |
578 | 578 | $implodeTvId = implode(',', $tvId); |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) throw new Exception("Template {$tpl} is not exists"); |
595 | 595 | $tpl = $this->modx->db->getValue($rs); |
596 | 596 | } else { |
597 | - throw new Exception("Invalid template name: " . print_r($tpl, 1)); |
|
597 | + throw new Exception("Invalid template name: ".print_r($tpl, 1)); |
|
598 | 598 | } |
599 | 599 | } |
600 | 600 | return (int)$tpl; |