@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | $tpl = $this->get('template'); |
| 191 | 191 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
| 192 | 192 | foreach ($tvTPL as $item) { |
| 193 | - if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { |
|
| 193 | + if (isset($this->tvid[$item]) && ! array_key_exists($this->tvid[$item], $out)) { |
|
| 194 | 194 | $out[$this->tvid[$item]] = $this->get($this->tvid[$item]); |
| 195 | 195 | } |
| 196 | 196 | } |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | { |
| 229 | 229 | $out = null; |
| 230 | 230 | $id = (int)$this->getID(); |
| 231 | - if (!empty($id)) { |
|
| 231 | + if ( ! empty($id)) { |
|
| 232 | 232 | $out = $this->modx->makeUrl($id); |
| 233 | 233 | } |
| 234 | 234 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | */ |
| 323 | 323 | public function set($key, $value) |
| 324 | 324 | { |
| 325 | - if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
| 325 | + if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && ! empty($key)) { |
|
| 326 | 326 | switch ($key) { |
| 327 | 327 | case 'parent': |
| 328 | 328 | $value = (int)$value; |
@@ -395,12 +395,12 @@ discard block |
||
| 395 | 395 | { |
| 396 | 396 | $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0); |
| 397 | 397 | $value = (int)$value; |
| 398 | - if (!empty($value)) { |
|
| 398 | + if ( ! empty($value)) { |
|
| 399 | 399 | $by = $this->findUserBy($value); |
| 400 | - $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) { |
|
| 400 | + $exists = $this->managerUsers->exists(function($key, Helpers\Collection $val) use ($by, $value) { |
|
| 401 | 401 | return ($val->containsKey($by) && $val->get($by) === (string)$value); |
| 402 | 402 | }); |
| 403 | - if (!$exists) { |
|
| 403 | + if ( ! $exists) { |
|
| 404 | 404 | $value = 0; |
| 405 | 405 | } |
| 406 | 406 | } |
@@ -441,11 +441,11 @@ discard block |
||
| 441 | 441 | protected function getTime($value) |
| 442 | 442 | { |
| 443 | 443 | $value = trim($value); |
| 444 | - if (!empty($value)) { |
|
| 445 | - if (!is_numeric($value)) { |
|
| 444 | + if ( ! empty($value)) { |
|
| 445 | + if ( ! is_numeric($value)) { |
|
| 446 | 446 | $value = (int)strtotime($value); |
| 447 | 447 | } |
| 448 | - if (!empty($value)) { |
|
| 448 | + if ( ! empty($value)) { |
|
| 449 | 449 | $value += $this->modxConfig('server_offset_time'); |
| 450 | 450 | } |
| 451 | 451 | } |
@@ -525,8 +525,8 @@ discard block |
||
| 525 | 525 | |
| 526 | 526 | if ( |
| 527 | 527 | $this->field['parent'] == 0 && |
| 528 | - !$this->modxConfig('udperms_allowroot') && |
|
| 529 | - !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) |
|
| 528 | + ! $this->modxConfig('udperms_allowroot') && |
|
| 529 | + ! ($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) |
|
| 530 | 530 | ) { |
| 531 | 531 | $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off'; |
| 532 | 532 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | $fld = $this->encodeFields()->toArray(null, null, null, false); |
| 546 | 546 | foreach ($this->default_field as $key => $value) { |
| 547 | 547 | $tmp = $this->get($key); |
| 548 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 548 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 549 | 549 | if ($tmp == $value) { |
| 550 | 550 | switch ($key) { |
| 551 | 551 | case 'cacheable': |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | $this->field[$key] = $parent; |
| 578 | 578 | $this->Uset($key); |
| 579 | 579 | break; |
| 580 | - case ($key == 'alias_visible' && !$this->checkVersion('1.0.10', true)): |
|
| 580 | + case ($key == 'alias_visible' && ! $this->checkVersion('1.0.10', true)): |
|
| 581 | 581 | $this->eraseField('alias_visible'); |
| 582 | 582 | break; |
| 583 | 583 | default: |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | unset($fld[$key]); |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | - if (!empty($this->set)) { |
|
| 589 | + if ( ! empty($this->set)) { |
|
| 590 | 590 | if ($this->newDoc) { |
| 591 | 591 | $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); |
| 592 | 592 | } else { |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | |
| 607 | 607 | $_deleteTVs = $_updateTVs = $_insertTVs = array(); |
| 608 | 608 | foreach ($fld as $key => $value) { |
| 609 | - if (empty($this->tv[$key]) || !$this->isChanged($key)) { |
|
| 609 | + if (empty($this->tv[$key]) || ! $this->isChanged($key)) { |
|
| 610 | 610 | continue; |
| 611 | 611 | } elseif ($value === '') { |
| 612 | 612 | $_deleteTVs[] = $this->tv[$key]; |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | } |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - if (!$this->newDoc && !empty($_insertTVs)) { |
|
| 618 | + if ( ! $this->newDoc && ! empty($_insertTVs)) { |
|
| 619 | 619 | $ids = implode(',', array_keys($_insertTVs)); |
| 620 | 620 | $result = $this->query("SELECT `tmplvarid` FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid`={$this->id} AND `tmplvarid` IN ({$ids})"); |
| 621 | 621 | $existedTVs = $this->modx->db->getColumn('tmplvarid', $result); |
@@ -625,13 +625,13 @@ discard block |
||
| 625 | 625 | } |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - if (!empty($_updateTVs)) { |
|
| 628 | + if ( ! empty($_updateTVs)) { |
|
| 629 | 629 | foreach ($_updateTVs as $id => $value) { |
| 630 | 630 | $this->query("UPDATE {$this->makeTable('site_tmplvar_contentvalues')} SET `value` = '{$value}' WHERE `contentid` = {$this->id} AND `tmplvarid` = {$id}"); |
| 631 | 631 | } |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - if (!empty($_insertTVs)) { |
|
| 634 | + if ( ! empty($_insertTVs)) { |
|
| 635 | 635 | $values = array(); |
| 636 | 636 | foreach ($_insertTVs as $id => $value) { |
| 637 | 637 | $values[] = "({$this->id}, {$id}, '{$value}')"; |
@@ -640,12 +640,12 @@ discard block |
||
| 640 | 640 | $this->query("INSERT into {$this->makeTable('site_tmplvar_contentvalues')} (`contentid`,`tmplvarid`,`value`) VALUES {$values}"); |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | - if (!empty($_deleteTVs)) { |
|
| 643 | + if ( ! empty($_deleteTVs)) { |
|
| 644 | 644 | $ids = implode(',', $_deleteTVs); |
| 645 | 645 | $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})"); |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - if (!isset($this->mode)) { |
|
| 648 | + if ( ! isset($this->mode)) { |
|
| 649 | 649 | $this->mode = $this->newDoc ? "new" : "upd"; |
| 650 | 650 | $this->newDoc = false; |
| 651 | 651 | } |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | $_ids = $this->cleanIDs($ids, ','); |
| 724 | 724 | if (is_array($_ids) && $_ids != array()) { |
| 725 | 725 | $id = $this->sanitarIn($_ids); |
| 726 | - if (!empty($id)) { |
|
| 726 | + if ( ! empty($id)) { |
|
| 727 | 727 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); |
| 728 | 728 | $id = $this->modx->db->getColumn('id', $q); |
| 729 | 729 | if ($depth > 0 || $depth === true) { |
@@ -788,12 +788,12 @@ discard block |
||
| 788 | 788 | $alias = strtolower($alias); |
| 789 | 789 | if ($this->modxConfig('friendly_urls')) { |
| 790 | 790 | $_alias = $this->escape($alias); |
| 791 | - if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
| 791 | + if (( ! $this->modxConfig('allow_duplicate_alias') && ! $this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
| 792 | 792 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1")); |
| 793 | 793 | } else { |
| 794 | 794 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1")); |
| 795 | 795 | } |
| 796 | - if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) { |
|
| 796 | + if (($flag && $this->newDoc) || ( ! $this->newDoc && $flag && $this->id != $flag)) { |
|
| 797 | 797 | $suffix = substr($alias, -2); |
| 798 | 798 | if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { |
| 799 | 799 | $suffix = (int)$tmp[1] + 1; |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | */ |
| 869 | 869 | protected function loadTVDefault(array $tvId = array()) |
| 870 | 870 | { |
| 871 | - if (is_array($tvId) && !empty($tvId)) { |
|
| 871 | + if (is_array($tvId) && ! empty($tvId)) { |
|
| 872 | 872 | $tbl_site_tmplvars = $this->makeTable('site_tmplvars'); |
| 873 | 873 | $fields = 'id,name,default_text as value,display,display_params,type'; |
| 874 | 874 | $implodeTvId = implode(',', $tvId); |
@@ -890,11 +890,11 @@ discard block |
||
| 890 | 890 | */ |
| 891 | 891 | public function setTemplate($tpl) |
| 892 | 892 | { |
| 893 | - if (!is_numeric($tpl) || $tpl != (int)$tpl) { |
|
| 893 | + if ( ! is_numeric($tpl) || $tpl != (int)$tpl) { |
|
| 894 | 894 | if (is_scalar($tpl)) { |
| 895 | 895 | $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'"; |
| 896 | 896 | $rs = $this->query($sql); |
| 897 | - if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
| 897 | + if ( ! $rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
| 898 | 898 | throw new Exception("Template {$tpl} is not exists"); |
| 899 | 899 | } |
| 900 | 900 | $tpl = $this->modx->db->getValue($rs); |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | $template = $this->modxConfig('default_template'); |
| 956 | 956 | switch ($this->modxConfig('auto_template_logic')) { |
| 957 | 957 | case 'sibling': |
| 958 | - if (!$parent) { |
|
| 958 | + if ( ! $parent) { |
|
| 959 | 959 | $site_start = $this->modxConfig('site_start'); |
| 960 | 960 | $where = "sc.isfolder=0 AND sc.id!={$site_start}"; |
| 961 | 961 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1); |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | */ |
| 1103 | 1103 | public function setDocumentGroups($docId = 0, $groupIds = array()) |
| 1104 | 1104 | { |
| 1105 | - if (!is_array($groupIds)) return $this; |
|
| 1105 | + if ( ! is_array($groupIds)) return $this; |
|
| 1106 | 1106 | if ($this->newDoc && $docId == 0) { |
| 1107 | 1107 | $this->groupIds = $groupIds; |
| 1108 | 1108 | } else { |
@@ -1111,7 +1111,7 @@ discard block |
||
| 1111 | 1111 | foreach ($groupIds as $gid) { |
| 1112 | 1112 | $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')"); |
| 1113 | 1113 | } |
| 1114 | - if (!$this->newDoc) { |
|
| 1114 | + if ( ! $this->newDoc) { |
|
| 1115 | 1115 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 1116 | 1116 | $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})"); |
| 1117 | 1117 | } |
@@ -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 | */ |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | * @param DocumentParser $modx |
| 160 | 160 | * @param bool $debug |
| 161 | 161 | */ |
| 162 | - public function __construct($modx, $debug = false) |
|
| 163 | - { |
|
| 162 | + public function __construct($modx, $debug = false) |
|
| 163 | + {
|
|
| 164 | 164 | parent::__construct($modx, $debug); |
| 165 | 165 | $this->get_TV(); |
| 166 | 166 | $uTable = $this->makeTable("manager_users"); |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | /** |
| 174 | 174 | * @return array |
| 175 | 175 | */ |
| 176 | - public function toArrayMain() |
|
| 177 | - { |
|
| 176 | + public function toArrayMain() |
|
| 177 | + {
|
|
| 178 | 178 | $out = array_intersect_key(parent::toArray(), $this->default_field); |
| 179 | 179 | |
| 180 | 180 | return $out; |
@@ -184,18 +184,18 @@ discard block |
||
| 184 | 184 | * @param bool $render |
| 185 | 185 | * @return array |
| 186 | 186 | */ |
| 187 | - public function toArrayTV($render = false) |
|
| 188 | - { |
|
| 187 | + public function toArrayTV($render = false) |
|
| 188 | + {
|
|
| 189 | 189 | $out = array_diff_key(parent::toArray(), $this->default_field); |
| 190 | 190 | $tpl = $this->get('template'); |
| 191 | 191 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
| 192 | - foreach ($tvTPL as $item) { |
|
| 193 | - if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { |
|
| 192 | + foreach ($tvTPL as $item) {
|
|
| 193 | + if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
|
|
| 194 | 194 | $out[$this->tvid[$item]] = $this->get($this->tvid[$item]); |
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | - if ($render) { |
|
| 198 | - foreach ($out as $key => $val) { |
|
| 197 | + if ($render) {
|
|
| 198 | + foreach ($out as $key => $val) {
|
|
| 199 | 199 | $out[$key] = $this->renderTV($key); |
| 200 | 200 | } |
| 201 | 201 | } |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | * @param bool $render |
| 211 | 211 | * @return array |
| 212 | 212 | */ |
| 213 | - public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) |
|
| 214 | - { |
|
| 213 | + public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) |
|
| 214 | + {
|
|
| 215 | 215 | $out = array_merge( |
| 216 | 216 | $this->toArrayMain(), |
| 217 | 217 | $this->toArrayTV($render), |
@@ -224,11 +224,11 @@ discard block |
||
| 224 | 224 | /** |
| 225 | 225 | * @return null|string |
| 226 | 226 | */ |
| 227 | - public function getUrl() |
|
| 228 | - { |
|
| 227 | + public function getUrl() |
|
| 228 | + {
|
|
| 229 | 229 | $out = null; |
| 230 | 230 | $id = (int)$this->getID(); |
| 231 | - if (!empty($id)) { |
|
| 231 | + if (!empty($id)) {
|
|
| 232 | 232 | $out = $this->modx->makeUrl($id); |
| 233 | 233 | } |
| 234 | 234 | |
@@ -240,10 +240,10 @@ discard block |
||
| 240 | 240 | * @param string $second |
| 241 | 241 | * @return mixed |
| 242 | 242 | */ |
| 243 | - public function getTitle($main = 'menutitle', $second = 'pagetitle') |
|
| 244 | - { |
|
| 243 | + public function getTitle($main = 'menutitle', $second = 'pagetitle') |
|
| 244 | + {
|
|
| 245 | 245 | $title = $this->get($main); |
| 246 | - if (empty($title) && $title !== '0') { |
|
| 246 | + if (empty($title) && $title !== '0') {
|
|
| 247 | 247 | $title = $this->get($second); |
| 248 | 248 | } |
| 249 | 249 | |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | /** |
| 254 | 254 | * @return bool |
| 255 | 255 | */ |
| 256 | - public function isWebShow() |
|
| 257 | - { |
|
| 256 | + public function isWebShow() |
|
| 257 | + {
|
|
| 258 | 258 | $pub = ($this->get('publishedon') < time() && $this->get('published')); |
| 259 | 259 | $unpub = ($this->get('unpub_date') == 0 || $this->get('unpub_date') > time()); |
| 260 | 260 | $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time())); |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | /** |
| 266 | 266 | * @return $this |
| 267 | 267 | */ |
| 268 | - public function touch() |
|
| 269 | - { |
|
| 268 | + public function touch() |
|
| 269 | + {
|
|
| 270 | 270 | $this->set('editedon', time()); |
| 271 | 271 | |
| 272 | 272 | return $this; |
@@ -276,14 +276,14 @@ discard block |
||
| 276 | 276 | * @param $tvname |
| 277 | 277 | * @return null|string |
| 278 | 278 | */ |
| 279 | - public function renderTV($tvname) |
|
| 280 | - { |
|
| 279 | + public function renderTV($tvname) |
|
| 280 | + {
|
|
| 281 | 281 | $out = null; |
| 282 | - if ($this->getID() > 0) { |
|
| 282 | + if ($this->getID() > 0) {
|
|
| 283 | 283 | include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php"; |
| 284 | 284 | include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php"; |
| 285 | 285 | $tvval = $this->get($tvname); |
| 286 | - if ($this->isTVarrayField($tvname) && is_array($tvval)) { |
|
| 286 | + if ($this->isTVarrayField($tvname) && is_array($tvval)) {
|
|
| 287 | 287 | $tvval = implode('||', $tvval); |
| 288 | 288 | } |
| 289 | 289 | $param = APIHelpers::getkey($this->tvd, $tvname, array()); |
@@ -300,14 +300,14 @@ discard block |
||
| 300 | 300 | * @param $key |
| 301 | 301 | * @return mixed |
| 302 | 302 | */ |
| 303 | - public function get($key) |
|
| 304 | - { |
|
| 303 | + public function get($key) |
|
| 304 | + {
|
|
| 305 | 305 | $out = parent::get($key); |
| 306 | - if (isset($this->tv[$key])) { |
|
| 306 | + if (isset($this->tv[$key])) {
|
|
| 307 | 307 | $tpl = $this->get('template'); |
| 308 | 308 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
| 309 | 309 | $tvID = APIHelpers::getkey($this->tv, $key, 0); |
| 310 | - if (in_array($tvID, $tvTPL) && is_null($out)) { |
|
| 310 | + if (in_array($tvID, $tvTPL) && is_null($out)) {
|
|
| 311 | 311 | $out = APIHelpers::getkey($this->tvd[$key], 'value', null); |
| 312 | 312 | } |
| 313 | 313 | } |
@@ -320,10 +320,10 @@ discard block |
||
| 320 | 320 | * @param $value |
| 321 | 321 | * @return $this |
| 322 | 322 | */ |
| 323 | - public function set($key, $value) |
|
| 324 | - { |
|
| 325 | - if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
| 326 | - switch ($key) { |
|
| 323 | + public function set($key, $value) |
|
| 324 | + {
|
|
| 325 | + if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
|
|
| 326 | + switch ($key) {
|
|
| 327 | 327 | case 'parent': |
| 328 | 328 | $value = (int)$value; |
| 329 | 329 | break; |
@@ -333,38 +333,38 @@ discard block |
||
| 333 | 333 | break; |
| 334 | 334 | case 'published': |
| 335 | 335 | $value = (int)((bool)$value); |
| 336 | - if ($value) { |
|
| 336 | + if ($value) {
|
|
| 337 | 337 | $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time'); |
| 338 | 338 | } |
| 339 | 339 | break; |
| 340 | 340 | case 'pub_date': |
| 341 | 341 | $value = $this->getTime($value); |
| 342 | - if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
| 342 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
|
|
| 343 | 343 | $this->field['published'] = 1; |
| 344 | 344 | $this->field['publishedon'] = $value; |
| 345 | 345 | } |
| 346 | 346 | break; |
| 347 | 347 | case 'unpub_date': |
| 348 | 348 | $value = $this->getTime($value); |
| 349 | - if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
| 349 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
|
|
| 350 | 350 | $this->field['published'] = 0; |
| 351 | 351 | $this->field['publishedon'] = 0; |
| 352 | 352 | } |
| 353 | 353 | break; |
| 354 | 354 | case 'deleted': |
| 355 | 355 | $value = (int)((bool)$value); |
| 356 | - if ($value) { |
|
| 356 | + if ($value) {
|
|
| 357 | 357 | $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time'); |
| 358 | - } else { |
|
| 358 | + } else {
|
|
| 359 | 359 | $this->field['deletedon'] = 0; |
| 360 | 360 | } |
| 361 | 361 | break; |
| 362 | 362 | case 'deletedon': |
| 363 | 363 | $value = $this->getTime($value); |
| 364 | - if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) { |
|
| 364 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) {
|
|
| 365 | 365 | $value = 0; |
| 366 | 366 | } |
| 367 | - if ($value) { |
|
| 367 | + if ($value) {
|
|
| 368 | 368 | $this->field['deleted'] = 1; |
| 369 | 369 | } |
| 370 | 370 | break; |
@@ -391,20 +391,20 @@ discard block |
||
| 391 | 391 | * @param int $default |
| 392 | 392 | * @return int|mixed |
| 393 | 393 | */ |
| 394 | - protected function getUser($value, $default = 0) |
|
| 395 | - { |
|
| 394 | + protected function getUser($value, $default = 0) |
|
| 395 | + {
|
|
| 396 | 396 | $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0); |
| 397 | 397 | $value = (int)$value; |
| 398 | - if (!empty($value)) { |
|
| 398 | + if (!empty($value)) {
|
|
| 399 | 399 | $by = $this->findUserBy($value); |
| 400 | - $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) { |
|
| 400 | + $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) {
|
|
| 401 | 401 | return ($val->containsKey($by) && $val->get($by) === (string)$value); |
| 402 | 402 | }); |
| 403 | - if (!$exists) { |
|
| 403 | + if (!$exists) {
|
|
| 404 | 404 | $value = 0; |
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | - if (empty($value)) { |
|
| 407 | + if (empty($value)) {
|
|
| 408 | 408 | $value = empty($currentAdmin) ? $default : $currentAdmin; |
| 409 | 409 | } |
| 410 | 410 | |
@@ -415,9 +415,9 @@ discard block |
||
| 415 | 415 | * @param $data |
| 416 | 416 | * @return bool|string |
| 417 | 417 | */ |
| 418 | - protected function findUserBy($data) |
|
| 419 | - { |
|
| 420 | - switch (true) { |
|
| 418 | + protected function findUserBy($data) |
|
| 419 | + {
|
|
| 420 | + switch (true) {
|
|
| 421 | 421 | case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): |
| 422 | 422 | $find = 'id'; |
| 423 | 423 | break; |
@@ -438,14 +438,14 @@ discard block |
||
| 438 | 438 | * @param $value |
| 439 | 439 | * @return int|mixed|string |
| 440 | 440 | */ |
| 441 | - protected function getTime($value) |
|
| 442 | - { |
|
| 441 | + protected function getTime($value) |
|
| 442 | + {
|
|
| 443 | 443 | $value = trim($value); |
| 444 | - if (!empty($value)) { |
|
| 445 | - if (!is_numeric($value)) { |
|
| 444 | + if (!empty($value)) {
|
|
| 445 | + if (!is_numeric($value)) {
|
|
| 446 | 446 | $value = (int)strtotime($value); |
| 447 | 447 | } |
| 448 | - if (!empty($value)) { |
|
| 448 | + if (!empty($value)) {
|
|
| 449 | 449 | $value += $this->modxConfig('server_offset_time'); |
| 450 | 450 | } |
| 451 | 451 | } |
@@ -457,11 +457,11 @@ discard block |
||
| 457 | 457 | * @param array $data |
| 458 | 458 | * @return $this |
| 459 | 459 | */ |
| 460 | - public function create($data = array()) |
|
| 461 | - { |
|
| 460 | + public function create($data = array()) |
|
| 461 | + {
|
|
| 462 | 462 | $this->close(); |
| 463 | 463 | $fld = array(); |
| 464 | - foreach ($this->tvd as $name => $tv) { |
|
| 464 | + foreach ($this->tvd as $name => $tv) {
|
|
| 465 | 465 | $fld[$name] = $tv['value']; |
| 466 | 466 | }; |
| 467 | 467 | $this->store($fld); |
@@ -479,10 +479,10 @@ discard block |
||
| 479 | 479 | * @param $id |
| 480 | 480 | * @return $this |
| 481 | 481 | */ |
| 482 | - public function edit($id) |
|
| 483 | - { |
|
| 482 | + public function edit($id) |
|
| 483 | + {
|
|
| 484 | 484 | $id = is_scalar($id) ? trim($id) : ''; |
| 485 | - if ($this->getID() != $id) { |
|
| 485 | + if ($this->getID() != $id) {
|
|
| 486 | 486 | $this->close(); |
| 487 | 487 | $this->markAllEncode(); |
| 488 | 488 | $this->newDoc = false; |
@@ -490,12 +490,12 @@ discard block |
||
| 490 | 490 | $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id); |
| 491 | 491 | $this->fromArray($this->modx->db->getRow($result)); |
| 492 | 492 | $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id); |
| 493 | - while ($row = $this->modx->db->getRow($result)) { |
|
| 493 | + while ($row = $this->modx->db->getRow($result)) {
|
|
| 494 | 494 | $this->field[$this->tvid[$row['tmplvarid']]] = $row['value']; |
| 495 | 495 | } |
| 496 | - if (empty($this->field['id'])) { |
|
| 496 | + if (empty($this->field['id'])) {
|
|
| 497 | 497 | $this->id = null; |
| 498 | - } else { |
|
| 498 | + } else {
|
|
| 499 | 499 | $this->id = $this->field['id']; |
| 500 | 500 | $this->set('editedby', null)->touch(); |
| 501 | 501 | $this->decodeFields(); |
@@ -512,10 +512,10 @@ discard block |
||
| 512 | 512 | * @param bool $clearCache |
| 513 | 513 | * @return bool|null |
| 514 | 514 | */ |
| 515 | - public function save($fire_events = false, $clearCache = false) |
|
| 516 | - { |
|
| 515 | + public function save($fire_events = false, $clearCache = false) |
|
| 516 | + {
|
|
| 517 | 517 | $parent = null; |
| 518 | - if ($this->field['pagetitle'] == '') { |
|
| 518 | + if ($this->field['pagetitle'] == '') {
|
|
| 519 | 519 | $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>'; |
| 520 | 520 | |
| 521 | 521 | return false; |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | $this->field['parent'] == 0 && |
| 528 | 528 | !$this->modxConfig('udperms_allowroot') && |
| 529 | 529 | !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) |
| 530 | - ) { |
|
| 530 | + ) {
|
|
| 531 | 531 | $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off'; |
| 532 | 532 | |
| 533 | 533 | return false; |
@@ -543,11 +543,11 @@ discard block |
||
| 543 | 543 | ), $fire_events); |
| 544 | 544 | |
| 545 | 545 | $fld = $this->encodeFields()->toArray(null, null, null, false); |
| 546 | - foreach ($this->default_field as $key => $value) { |
|
| 546 | + foreach ($this->default_field as $key => $value) {
|
|
| 547 | 547 | $tmp = $this->get($key); |
| 548 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 549 | - if ($tmp == $value) { |
|
| 550 | - switch ($key) { |
|
| 548 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 549 | + if ($tmp == $value) {
|
|
| 550 | + switch ($key) {
|
|
| 551 | 551 | case 'cacheable': |
| 552 | 552 | $value = $this->modxConfig('cache_default'); |
| 553 | 553 | break; |
@@ -567,11 +567,11 @@ discard block |
||
| 567 | 567 | } |
| 568 | 568 | $this->field[$key] = $value; |
| 569 | 569 | } |
| 570 | - switch (true) { |
|
| 570 | + switch (true) {
|
|
| 571 | 571 | case $key == 'parent': |
| 572 | 572 | $parent = (int)$this->get($key); |
| 573 | 573 | $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'"); |
| 574 | - if ($this->modx->db->getValue($q) != 1) { |
|
| 574 | + if ($this->modx->db->getValue($q) != 1) {
|
|
| 575 | 575 | $parent = 0; |
| 576 | 576 | } |
| 577 | 577 | $this->field[$key] = $parent; |
@@ -586,71 +586,73 @@ discard block |
||
| 586 | 586 | unset($fld[$key]); |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | - if (!empty($this->set)) { |
|
| 590 | - if ($this->newDoc) { |
|
| 589 | + if (!empty($this->set)) {
|
|
| 590 | + if ($this->newDoc) {
|
|
| 591 | 591 | $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); |
| 592 | - } else { |
|
| 592 | + } else {
|
|
| 593 | 593 | $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ', |
| 594 | 594 | $this->set) . " WHERE `id` = " . $this->id; |
| 595 | 595 | } |
| 596 | 596 | $this->query($SQL); |
| 597 | 597 | |
| 598 | - if ($this->newDoc) { |
|
| 598 | + if ($this->newDoc) {
|
|
| 599 | 599 | $this->id = $this->modx->db->getInsertId(); |
| 600 | 600 | } |
| 601 | 601 | |
| 602 | - if ($parent > 0) { |
|
| 602 | + if ($parent > 0) {
|
|
| 603 | 603 | $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'"); |
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | $_deleteTVs = $_updateTVs = $_insertTVs = array(); |
| 608 | - foreach ($fld as $key => $value) { |
|
| 609 | - if (empty($this->tv[$key]) || !$this->isChanged($key)) { |
|
| 608 | + foreach ($fld as $key => $value) {
|
|
| 609 | + if (empty($this->tv[$key]) || !$this->isChanged($key)) {
|
|
| 610 | 610 | continue; |
| 611 | - } elseif ($value === '') { |
|
| 611 | + } elseif ($value === '') {
|
|
| 612 | 612 | $_deleteTVs[] = $this->tv[$key]; |
| 613 | - } else { |
|
| 613 | + } else {
|
|
| 614 | 614 | $_insertTVs[$this->tv[$key]] = $this->escape($value); |
| 615 | 615 | } |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - if (!$this->newDoc && !empty($_insertTVs)) { |
|
| 618 | + if (!$this->newDoc && !empty($_insertTVs)) {
|
|
| 619 | 619 | $ids = implode(',', array_keys($_insertTVs)); |
| 620 | 620 | $result = $this->query("SELECT `tmplvarid` FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid`={$this->id} AND `tmplvarid` IN ({$ids})"); |
| 621 | 621 | $existedTVs = $this->modx->db->getColumn('tmplvarid', $result); |
| 622 | - foreach ($existedTVs as $id) { |
|
| 622 | + foreach ($existedTVs as $id) {
|
|
| 623 | 623 | $_updateTVs[$id] = $_insertTVs[$id]; |
| 624 | 624 | unset($_insertTVs[$id]); |
| 625 | 625 | } |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - if (!empty($_updateTVs)) { |
|
| 629 | - foreach ($_updateTVs as $id => $value) { |
|
| 628 | + if (!empty($_updateTVs)) {
|
|
| 629 | + foreach ($_updateTVs as $id => $value) {
|
|
| 630 | 630 | $this->query("UPDATE {$this->makeTable('site_tmplvar_contentvalues')} SET `value` = '{$value}' WHERE `contentid` = {$this->id} AND `tmplvarid` = {$id}"); |
| 631 | 631 | } |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - if (!empty($_insertTVs)) { |
|
| 634 | + if (!empty($_insertTVs)) {
|
|
| 635 | 635 | $values = array(); |
| 636 | - foreach ($_insertTVs as $id => $value) { |
|
| 636 | + foreach ($_insertTVs as $id => $value) {
|
|
| 637 | 637 | $values[] = "({$this->id}, {$id}, '{$value}')"; |
| 638 | 638 | } |
| 639 | 639 | $values = implode(',', $values); |
| 640 | 640 | $this->query("INSERT into {$this->makeTable('site_tmplvar_contentvalues')} (`contentid`,`tmplvarid`,`value`) VALUES {$values}"); |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | - if (!empty($_deleteTVs)) { |
|
| 643 | + if (!empty($_deleteTVs)) {
|
|
| 644 | 644 | $ids = implode(',', $_deleteTVs); |
| 645 | 645 | $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})"); |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - if (!isset($this->mode)) { |
|
| 648 | + if (!isset($this->mode)) {
|
|
| 649 | 649 | $this->mode = $this->newDoc ? "new" : "upd"; |
| 650 | 650 | $this->newDoc = false; |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | - if ($this->groupIds) $this->setDocumentGroups($this->id, $this->groupIds); |
|
| 653 | + if ($this->groupIds) {
|
|
| 654 | + $this->setDocumentGroups($this->id, $this->groupIds); |
|
| 655 | + } |
|
| 654 | 656 | $this->invokeEvent('OnDocFormSave', array( |
| 655 | 657 | 'mode' => $this->mode, |
| 656 | 658 | 'id' => $this->id, |
@@ -658,7 +660,7 @@ discard block |
||
| 658 | 660 | 'docObj' => $this |
| 659 | 661 | ), $fire_events); |
| 660 | 662 | |
| 661 | - if ($clearCache) { |
|
| 663 | + if ($clearCache) {
|
|
| 662 | 664 | $this->clearCache($fire_events); |
| 663 | 665 | } |
| 664 | 666 | $this->decodeFields(); |
@@ -671,16 +673,16 @@ discard block |
||
| 671 | 673 | * @return $this |
| 672 | 674 | * @throws Exception |
| 673 | 675 | */ |
| 674 | - public function toTrash($ids) |
|
| 675 | - { |
|
| 676 | + public function toTrash($ids) |
|
| 677 | + {
|
|
| 676 | 678 | $ignore = $this->systemID(); |
| 677 | 679 | $_ids = $this->cleanIDs($ids, ',', $ignore); |
| 678 | - if (is_array($_ids) && $_ids != array()) { |
|
| 680 | + if (is_array($_ids) && $_ids != array()) {
|
|
| 679 | 681 | $id = $this->sanitarIn($_ids); |
| 680 | 682 | $uid = (int)$this->modx->getLoginUserId(); |
| 681 | 683 | $deletedon = time() + $this->modxConfig('server_offset_time'); |
| 682 | 684 | $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})"); |
| 683 | - } else { |
|
| 685 | + } else {
|
|
| 684 | 686 | throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, |
| 685 | 687 | 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
| 686 | 688 | } |
@@ -692,11 +694,11 @@ discard block |
||
| 692 | 694 | * @param bool $fire_events |
| 693 | 695 | * @return $this |
| 694 | 696 | */ |
| 695 | - public function clearTrash($fire_events = false) |
|
| 696 | - { |
|
| 697 | + public function clearTrash($fire_events = false) |
|
| 698 | + {
|
|
| 697 | 699 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'"); |
| 698 | 700 | $_ids = $this->modx->db->getColumn('id', $q); |
| 699 | - if (is_array($_ids) && $_ids != array()) { |
|
| 701 | + if (is_array($_ids) && $_ids != array()) {
|
|
| 700 | 702 | $this->invokeEvent('OnBeforeEmptyTrash', array( |
| 701 | 703 | "ids" => $_ids |
| 702 | 704 | ), $fire_events); |
@@ -718,15 +720,15 @@ discard block |
||
| 718 | 720 | * @param int|bool $depth |
| 719 | 721 | * @return array |
| 720 | 722 | */ |
| 721 | - public function children($ids, $depth) |
|
| 722 | - { |
|
| 723 | + public function children($ids, $depth) |
|
| 724 | + {
|
|
| 723 | 725 | $_ids = $this->cleanIDs($ids, ','); |
| 724 | - if (is_array($_ids) && $_ids != array()) { |
|
| 726 | + if (is_array($_ids) && $_ids != array()) {
|
|
| 725 | 727 | $id = $this->sanitarIn($_ids); |
| 726 | - if (!empty($id)) { |
|
| 728 | + if (!empty($id)) {
|
|
| 727 | 729 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); |
| 728 | 730 | $id = $this->modx->db->getColumn('id', $q); |
| 729 | - if ($depth > 0 || $depth === true) { |
|
| 731 | + if ($depth > 0 || $depth === true) {
|
|
| 730 | 732 | $id = $this->children($id, is_bool($depth) ? $depth : ($depth - 1)); |
| 731 | 733 | } |
| 732 | 734 | $_ids = array_merge($_ids, $id); |
@@ -742,8 +744,8 @@ discard block |
||
| 742 | 744 | * @return $this |
| 743 | 745 | * @throws Exception |
| 744 | 746 | */ |
| 745 | - public function delete($ids, $fire_events = false) |
|
| 746 | - { |
|
| 747 | + public function delete($ids, $fire_events = false) |
|
| 748 | + {
|
|
| 747 | 749 | $ids = $this->children($ids, true); |
| 748 | 750 | $_ids = $this->cleanIDs($ids, ',', $this->systemID()); |
| 749 | 751 | $this->invokeEvent('OnBeforeDocFormDelete', array( |
@@ -760,8 +762,8 @@ discard block |
||
| 760 | 762 | /** |
| 761 | 763 | * @return array |
| 762 | 764 | */ |
| 763 | - private function systemID() |
|
| 764 | - { |
|
| 765 | + private function systemID() |
|
| 766 | + {
|
|
| 765 | 767 | $ignore = array( |
| 766 | 768 | 0, //empty document |
| 767 | 769 | (int)$this->modxConfig('site_start'), |
@@ -771,7 +773,7 @@ discard block |
||
| 771 | 773 | ); |
| 772 | 774 | $data = $this->query("SELECT DISTINCT setting_value FROM {$this->makeTable('web_user_settings')} WHERE `setting_name`='login_home' AND `setting_value`!=''"); |
| 773 | 775 | $data = $this->modx->db->makeArray($data); |
| 774 | - foreach ($data as $item) { |
|
| 776 | + foreach ($data as $item) {
|
|
| 775 | 777 | $ignore[] = (int)$item['setting_value']; |
| 776 | 778 | } |
| 777 | 779 | |
@@ -783,22 +785,22 @@ discard block |
||
| 783 | 785 | * @param $alias |
| 784 | 786 | * @return string |
| 785 | 787 | */ |
| 786 | - protected function checkAlias($alias) |
|
| 787 | - { |
|
| 788 | + protected function checkAlias($alias) |
|
| 789 | + {
|
|
| 788 | 790 | $alias = strtolower($alias); |
| 789 | - if ($this->modxConfig('friendly_urls')) { |
|
| 791 | + if ($this->modxConfig('friendly_urls')) {
|
|
| 790 | 792 | $_alias = $this->escape($alias); |
| 791 | - if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
| 793 | + if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
|
|
| 792 | 794 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1")); |
| 793 | - } else { |
|
| 795 | + } else {
|
|
| 794 | 796 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1")); |
| 795 | 797 | } |
| 796 | - if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) { |
|
| 798 | + if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
|
|
| 797 | 799 | $suffix = substr($alias, -2); |
| 798 | - if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { |
|
| 800 | + if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
|
|
| 799 | 801 | $suffix = (int)$tmp[1] + 1; |
| 800 | 802 | $alias = substr($alias, 0, -2) . '-' . $suffix; |
| 801 | - } else { |
|
| 803 | + } else {
|
|
| 802 | 804 | $alias .= '-2'; |
| 803 | 805 | } |
| 804 | 806 | $alias = $this->checkAlias($alias); |
@@ -812,8 +814,8 @@ discard block |
||
| 812 | 814 | * @param $key |
| 813 | 815 | * @return bool |
| 814 | 816 | */ |
| 815 | - public function issetField($key) |
|
| 816 | - { |
|
| 817 | + public function issetField($key) |
|
| 818 | + {
|
|
| 817 | 819 | return (array_key_exists($key, $this->default_field) || array_key_exists($key, $this->tv)); |
| 818 | 820 | } |
| 819 | 821 | |
@@ -821,11 +823,11 @@ discard block |
||
| 821 | 823 | * @param bool $reload |
| 822 | 824 | * @return $this |
| 823 | 825 | */ |
| 824 | - protected function get_TV($reload = false) |
|
| 825 | - { |
|
| 826 | - if (empty($this->modx->_TVnames) || $reload) { |
|
| 826 | + protected function get_TV($reload = false) |
|
| 827 | + {
|
|
| 828 | + if (empty($this->modx->_TVnames) || $reload) {
|
|
| 827 | 829 | $result = $this->query('SELECT `id`,`name`,`type` FROM ' . $this->makeTable('site_tmplvars')); |
| 828 | - while ($row = $this->modx->db->GetRow($result)) { |
|
| 830 | + while ($row = $this->modx->db->GetRow($result)) {
|
|
| 829 | 831 | $this->modx->_TVnames[$row['name']] = array( |
| 830 | 832 | "id" => $row['id'], |
| 831 | 833 | "type" => $row['type'] |
@@ -834,14 +836,16 @@ discard block |
||
| 834 | 836 | } |
| 835 | 837 | $arrayTypes = array('checkbox', 'listbox-multiple'); |
| 836 | 838 | $arrayTVs = array(); |
| 837 | - foreach ($this->modx->_TVnames as $name => $data) { |
|
| 839 | + foreach ($this->modx->_TVnames as $name => $data) {
|
|
| 838 | 840 | $this->tvid[$data['id']] = $name; |
| 839 | 841 | $this->tv[$name] = $data['id']; |
| 840 | - if (in_array($data['type'], $arrayTypes)) { |
|
| 842 | + if (in_array($data['type'], $arrayTypes)) {
|
|
| 841 | 843 | $arrayTVs[] = $name; |
| 842 | 844 | } |
| 843 | 845 | } |
| 844 | - if (empty($this->tvaFields)) $this->tvaFields = $arrayTVs; |
|
| 846 | + if (empty($this->tvaFields)) {
|
|
| 847 | + $this->tvaFields = $arrayTVs; |
|
| 848 | + } |
|
| 845 | 849 | $this->loadTVTemplate()->loadTVDefault(array_values($this->tv)); |
| 846 | 850 | |
| 847 | 851 | return $this; |
@@ -850,12 +854,12 @@ discard block |
||
| 850 | 854 | /** |
| 851 | 855 | * @return $this |
| 852 | 856 | */ |
| 853 | - protected function loadTVTemplate() |
|
| 854 | - { |
|
| 857 | + protected function loadTVTemplate() |
|
| 858 | + {
|
|
| 855 | 859 | $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates')); |
| 856 | 860 | $q = $this->modx->db->makeArray($q); |
| 857 | 861 | $this->tvTpl = array(); |
| 858 | - foreach ($q as $item) { |
|
| 862 | + foreach ($q as $item) {
|
|
| 859 | 863 | $this->tvTpl[$item['templateid']][] = $item['tmplvarid']; |
| 860 | 864 | } |
| 861 | 865 | |
@@ -866,16 +870,16 @@ discard block |
||
| 866 | 870 | * @param array $tvId |
| 867 | 871 | * @return $this |
| 868 | 872 | */ |
| 869 | - protected function loadTVDefault(array $tvId = array()) |
|
| 870 | - { |
|
| 871 | - if (is_array($tvId) && !empty($tvId)) { |
|
| 873 | + protected function loadTVDefault(array $tvId = array()) |
|
| 874 | + {
|
|
| 875 | + if (is_array($tvId) && !empty($tvId)) {
|
|
| 872 | 876 | $tbl_site_tmplvars = $this->makeTable('site_tmplvars'); |
| 873 | 877 | $fields = 'id,name,default_text as value,display,display_params,type'; |
| 874 | 878 | $implodeTvId = implode(',', $tvId); |
| 875 | 879 | $rs = $this->query("SELECT {$fields} FROM {$tbl_site_tmplvars} WHERE id IN({$implodeTvId})"); |
| 876 | 880 | $rows = $this->modx->db->makeArray($rs); |
| 877 | 881 | $this->tvd = array(); |
| 878 | - foreach ($rows as $item) { |
|
| 882 | + foreach ($rows as $item) {
|
|
| 879 | 883 | $this->tvd[$item['name']] = $item; |
| 880 | 884 | } |
| 881 | 885 | } |
@@ -888,17 +892,17 @@ discard block |
||
| 888 | 892 | * @return int |
| 889 | 893 | * @throws Exception |
| 890 | 894 | */ |
| 891 | - public function setTemplate($tpl) |
|
| 892 | - { |
|
| 893 | - if (!is_numeric($tpl) || $tpl != (int)$tpl) { |
|
| 894 | - if (is_scalar($tpl)) { |
|
| 895 | + public function setTemplate($tpl) |
|
| 896 | + {
|
|
| 897 | + if (!is_numeric($tpl) || $tpl != (int)$tpl) {
|
|
| 898 | + if (is_scalar($tpl)) {
|
|
| 895 | 899 | $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'"; |
| 896 | 900 | $rs = $this->query($sql); |
| 897 | - if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
| 901 | + if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
|
|
| 898 | 902 | throw new Exception("Template {$tpl} is not exists"); |
| 899 | 903 | } |
| 900 | 904 | $tpl = $this->modx->db->getValue($rs); |
| 901 | - } else { |
|
| 905 | + } else {
|
|
| 902 | 906 | throw new Exception("Invalid template name: " . print_r($tpl, 1)); |
| 903 | 907 | } |
| 904 | 908 | } |
@@ -909,14 +913,14 @@ discard block |
||
| 909 | 913 | /** |
| 910 | 914 | * @return string |
| 911 | 915 | */ |
| 912 | - protected function getAlias() |
|
| 913 | - { |
|
| 914 | - if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') { |
|
| 916 | + protected function getAlias() |
|
| 917 | + {
|
|
| 918 | + if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') {
|
|
| 915 | 919 | $alias = strtr($this->get('pagetitle'), $this->table); |
| 916 | - } else { |
|
| 917 | - if ($this->get('alias') != '') { |
|
| 920 | + } else {
|
|
| 921 | + if ($this->get('alias') != '') {
|
|
| 918 | 922 | $alias = $this->get('alias'); |
| 919 | - } else { |
|
| 923 | + } else {
|
|
| 920 | 924 | $alias = ''; |
| 921 | 925 | } |
| 922 | 926 | } |
@@ -933,10 +937,10 @@ discard block |
||
| 933 | 937 | * |
| 934 | 938 | * Пересчет menuindex по полю таблицы site_content |
| 935 | 939 | */ |
| 936 | - public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc') |
|
| 937 | - { |
|
| 940 | + public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc') |
|
| 941 | + {
|
|
| 938 | 942 | $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc'; |
| 939 | - if (is_integer($parent) && $criteria !== '') { |
|
| 943 | + if (is_integer($parent) && $criteria !== '') {
|
|
| 940 | 944 | $this->query("SET @index := 0"); |
| 941 | 945 | $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}"); |
| 942 | 946 | } |
@@ -949,37 +953,37 @@ discard block |
||
| 949 | 953 | * |
| 950 | 954 | * @return $this |
| 951 | 955 | */ |
| 952 | - public function setDefaultTemplate() |
|
| 953 | - { |
|
| 956 | + public function setDefaultTemplate() |
|
| 957 | + {
|
|
| 954 | 958 | $parent = $this->get('parent'); |
| 955 | 959 | $template = $this->modxConfig('default_template'); |
| 956 | - switch ($this->modxConfig('auto_template_logic')) { |
|
| 960 | + switch ($this->modxConfig('auto_template_logic')) {
|
|
| 957 | 961 | case 'sibling': |
| 958 | - if (!$parent) { |
|
| 962 | + if (!$parent) {
|
|
| 959 | 963 | $site_start = $this->modxConfig('site_start'); |
| 960 | 964 | $where = "sc.isfolder=0 AND sc.id!={$site_start}"; |
| 961 | 965 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1); |
| 962 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
| 966 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
|
|
| 963 | 967 | $template = $sibl[0]['template']; |
| 964 | 968 | } |
| 965 | - } else { |
|
| 969 | + } else {
|
|
| 966 | 970 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', 'isfolder=0', 'menuindex', |
| 967 | 971 | 'ASC', 1); |
| 968 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
| 972 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
|
|
| 969 | 973 | $template = $sibl[0]['template']; |
| 970 | - } else { |
|
| 974 | + } else {
|
|
| 971 | 975 | $sibl = $this->modx->getDocumentChildren($parent, 0, 0, 'template', 'isfolder=0', 'menuindex', |
| 972 | 976 | 'ASC', 1); |
| 973 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
| 977 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
|
|
| 974 | 978 | $template = $sibl[0]['template']; |
| 975 | 979 | } |
| 976 | 980 | } |
| 977 | 981 | } |
| 978 | 982 | break; |
| 979 | 983 | case 'parent': |
| 980 | - if ($parent) { |
|
| 984 | + if ($parent) {
|
|
| 981 | 985 | $_parent = $this->modx->getPageInfo($parent, 0, 'template'); |
| 982 | - if (isset($_parent['template'])) { |
|
| 986 | + if (isset($_parent['template'])) {
|
|
| 983 | 987 | $template = $_parent['template']; |
| 984 | 988 | } |
| 985 | 989 | } |
@@ -996,18 +1000,18 @@ discard block |
||
| 996 | 1000 | * @param bool $store обновить распакованное поле |
| 997 | 1001 | * @return array ассоциативный массив с данными из json строки |
| 998 | 1002 | */ |
| 999 | - public function decodeField($field, $store = false) |
|
| 1000 | - { |
|
| 1003 | + public function decodeField($field, $store = false) |
|
| 1004 | + {
|
|
| 1001 | 1005 | $out = array(); |
| 1002 | - if ($this->isDecodableField($field)) { |
|
| 1006 | + if ($this->isDecodableField($field)) {
|
|
| 1003 | 1007 | $data = $this->get($field); |
| 1004 | - if ($this->isTVarrayField($field)) { |
|
| 1008 | + if ($this->isTVarrayField($field)) {
|
|
| 1005 | 1009 | $out = explode('||', $data); |
| 1006 | - } else { |
|
| 1010 | + } else {
|
|
| 1007 | 1011 | $out = jsonHelper::jsonDecode($data, array('assoc' => true), true); |
| 1008 | 1012 | } |
| 1009 | 1013 | } |
| 1010 | - if ($store) { |
|
| 1014 | + if ($store) {
|
|
| 1011 | 1015 | $this->field[$field] = $out; |
| 1012 | 1016 | $this->markAsDecode($field); |
| 1013 | 1017 | } |
@@ -1021,18 +1025,18 @@ discard block |
||
| 1021 | 1025 | * @param bool $store обновить запакованное поле |
| 1022 | 1026 | * @return string|null json строка |
| 1023 | 1027 | */ |
| 1024 | - public function encodeField($field, $store = false) |
|
| 1025 | - { |
|
| 1028 | + public function encodeField($field, $store = false) |
|
| 1029 | + {
|
|
| 1026 | 1030 | $out = null; |
| 1027 | - if ($this->isEncodableField($field)) { |
|
| 1031 | + if ($this->isEncodableField($field)) {
|
|
| 1028 | 1032 | $data = $this->get($field); |
| 1029 | - if ($this->isTVarrayField($field)) { |
|
| 1033 | + if ($this->isTVarrayField($field)) {
|
|
| 1030 | 1034 | $out = is_array($data) ? implode('||', $data) : $data; |
| 1031 | - } else { |
|
| 1035 | + } else {
|
|
| 1032 | 1036 | $out = json_encode($data); |
| 1033 | 1037 | } |
| 1034 | 1038 | } |
| 1035 | - if ($store) { |
|
| 1039 | + if ($store) {
|
|
| 1036 | 1040 | $this->field[$field] = $out; |
| 1037 | 1041 | $this->markAsEncode($field); |
| 1038 | 1042 | } |
@@ -1045,8 +1049,8 @@ discard block |
||
| 1045 | 1049 | * @param string $field имя поля |
| 1046 | 1050 | * @return boolean |
| 1047 | 1051 | */ |
| 1048 | - public function isTVarrayField($field) |
|
| 1049 | - { |
|
| 1052 | + public function isTVarrayField($field) |
|
| 1053 | + {
|
|
| 1050 | 1054 | return (is_scalar($field) && in_array($field, $this->tvaFields)); |
| 1051 | 1055 | } |
| 1052 | 1056 | |
@@ -1054,10 +1058,10 @@ discard block |
||
| 1054 | 1058 | * Пометить все поля как запакованные |
| 1055 | 1059 | * @return $this |
| 1056 | 1060 | */ |
| 1057 | - public function markAllEncode() |
|
| 1058 | - { |
|
| 1061 | + public function markAllEncode() |
|
| 1062 | + {
|
|
| 1059 | 1063 | parent::markAllEncode(); |
| 1060 | - foreach ($this->tvaFields as $field) { |
|
| 1064 | + foreach ($this->tvaFields as $field) {
|
|
| 1061 | 1065 | $this->markAsEncode($field); |
| 1062 | 1066 | } |
| 1063 | 1067 | |
@@ -1068,10 +1072,10 @@ discard block |
||
| 1068 | 1072 | * Пометить все поля как распакованные |
| 1069 | 1073 | * @return $this |
| 1070 | 1074 | */ |
| 1071 | - public function markAllDecode() |
|
| 1072 | - { |
|
| 1075 | + public function markAllDecode() |
|
| 1076 | + {
|
|
| 1073 | 1077 | parent::markAllDecode(); |
| 1074 | - foreach ($this->tvaFields as $field) { |
|
| 1078 | + foreach ($this->tvaFields as $field) {
|
|
| 1075 | 1079 | $this->markAsDecode($field); |
| 1076 | 1080 | } |
| 1077 | 1081 | |
@@ -1081,10 +1085,11 @@ discard block |
||
| 1081 | 1085 | /** |
| 1082 | 1086 | * @param int $docId |
| 1083 | 1087 | */ |
| 1084 | - public function getDocumentGroups($docId = 0) { |
|
| 1088 | + public function getDocumentGroups($docId = 0) |
|
| 1089 | + {
|
|
| 1085 | 1090 | $out = array(); |
| 1086 | 1091 | $doc = $this->switchObject($docId); |
| 1087 | - if (null !== $doc->getID()) { |
|
| 1092 | + if (null !== $doc->getID()) {
|
|
| 1088 | 1093 | $doc_groups = $this->modx->getFullTableName('document_groups'); |
| 1089 | 1094 | $sql = "SELECT `document_group` FROM {$doc_groups} WHERE `document` = " . $doc->getID(); |
| 1090 | 1095 | $out = $this->modx->db->getColumn('document_group', $this->query($sql)); |
@@ -1100,18 +1105,20 @@ discard block |
||
| 1100 | 1105 | * @param array $groupIds |
| 1101 | 1106 | * @return $this |
| 1102 | 1107 | */ |
| 1103 | - public function setDocumentGroups($docId = 0, $groupIds = array()) |
|
| 1104 | - { |
|
| 1105 | - if (!is_array($groupIds)) return $this; |
|
| 1106 | - if ($this->newDoc && $docId == 0) { |
|
| 1108 | + public function setDocumentGroups($docId = 0, $groupIds = array()) |
|
| 1109 | + {
|
|
| 1110 | + if (!is_array($groupIds)) {
|
|
| 1111 | + return $this; |
|
| 1112 | + } |
|
| 1113 | + if ($this->newDoc && $docId == 0) {
|
|
| 1107 | 1114 | $this->groupIds = $groupIds; |
| 1108 | - } else { |
|
| 1115 | + } else {
|
|
| 1109 | 1116 | $doc = $this->switchObject($docId); |
| 1110 | - if ($id = $doc->getID()) { |
|
| 1111 | - foreach ($groupIds as $gid) { |
|
| 1117 | + if ($id = $doc->getID()) {
|
|
| 1118 | + foreach ($groupIds as $gid) {
|
|
| 1112 | 1119 | $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')"); |
| 1113 | 1120 | } |
| 1114 | - if (!$this->newDoc) { |
|
| 1121 | + if (!$this->newDoc) {
|
|
| 1115 | 1122 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 1116 | 1123 | $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})"); |
| 1117 | 1124 | } |