@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | $this->close(); |
| 110 | 110 | $this->newDoc = false; |
| 111 | 111 | |
| 112 | - if (!$find = $this->findUser($id)) { |
|
| 112 | + if ( ! $find = $this->findUser($id)) { |
|
| 113 | 113 | $this->id = null; |
| 114 | 114 | } else { |
| 115 | 115 | $this->set('editedon', time()); |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public function set($key, $value) |
| 139 | 139 | { |
| 140 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
| 140 | + if (is_scalar($value) && is_scalar($key) && ! empty($key)) { |
|
| 141 | 141 | switch ($key) { |
| 142 | 142 | case 'password': |
| 143 | 143 | $this->givenPassword = $value; |
@@ -181,14 +181,14 @@ discard block |
||
| 181 | 181 | return false; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if (!$this->checkUnique('web_users', 'username')) { |
|
| 184 | + if ( ! $this->checkUnique('web_users', 'username')) { |
|
| 185 | 185 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
| 186 | 186 | true) . '</pre>'; |
| 187 | 187 | |
| 188 | 188 | return false; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
| 191 | + if ( ! $this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
| 192 | 192 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
| 193 | 193 | |
| 194 | 194 | return false; |
@@ -198,13 +198,13 @@ discard block |
||
| 198 | 198 | $fld = $this->toArray(); |
| 199 | 199 | foreach ($this->default_field['user'] as $key => $value) { |
| 200 | 200 | $tmp = $this->get($key); |
| 201 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 201 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 202 | 202 | $this->field[$key] = $value; |
| 203 | 203 | } |
| 204 | 204 | $this->Uset($key, 'user'); |
| 205 | 205 | unset($fld[$key]); |
| 206 | 206 | } |
| 207 | - if (!empty($this->set['user'])) { |
|
| 207 | + if ( ! empty($this->set['user'])) { |
|
| 208 | 208 | if ($this->newDoc) { |
| 209 | 209 | $SQL = "INSERT into {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']); |
| 210 | 210 | } else { |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | |
| 221 | 221 | foreach ($this->default_field['attribute'] as $key => $value) { |
| 222 | 222 | $tmp = $this->get($key); |
| 223 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 223 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 224 | 224 | $this->field[$key] = $value; |
| 225 | 225 | } |
| 226 | 226 | $this->Uset($key, 'attribute'); |
| 227 | 227 | unset($fld[$key]); |
| 228 | 228 | } |
| 229 | - if (!empty($this->set['attribute'])) { |
|
| 229 | + if ( ! empty($this->set['attribute'])) { |
|
| 230 | 230 | if ($this->newDoc) { |
| 231 | 231 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
| 232 | 232 | $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | } |
| 240 | 240 | unset($fld['id']); |
| 241 | 241 | foreach ($fld as $key => $value) { |
| 242 | - if ($value == '' || !$this->isChanged($key)) { |
|
| 242 | + if ($value == '' || ! $this->isChanged($key)) { |
|
| 243 | 243 | continue; |
| 244 | 244 | } |
| 245 | 245 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}'"); |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $this->query("INSERT into {$this->makeTable('web_user_settings')} SET `webuser` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | - if (!$this->newDoc && $this->givenPassword) { |
|
| 252 | + if ( ! $this->newDoc && $this->givenPassword) { |
|
| 253 | 253 | $this->invokeEvent('OnWebChangePassword', array( |
| 254 | 254 | 'userObj' => $this, |
| 255 | 255 | 'userid' => $this->id, |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | $b = $tmp->get('blocked'); |
| 350 | 350 | $bu = $tmp->get('blockeduntil'); |
| 351 | 351 | $ba = $tmp->get('blockedafter'); |
| 352 | - $flag = (($b && !$bu && !$ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
| 352 | + $flag = (($b && ! $bu && ! $ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
| 353 | 353 | unset($tmp); |
| 354 | 354 | |
| 355 | 355 | return $flag; |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | |
| 372 | 372 | $flag = $pluginFlag = false; |
| 373 | 373 | if ( |
| 374 | - (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
|
| 374 | + (null !== $tmp->getID()) && ( ! $blocker || ($blocker && ! $tmp->checkBlock($id))) |
|
| 375 | 375 | ) { |
| 376 | 376 | $eventResult = $this->getInvokeEventResult('OnWebAuthentication', array( |
| 377 | 377 | 'userObj' => $this, |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | } else { |
| 388 | 388 | $pluginFlag = (bool)$eventResult; |
| 389 | 389 | } |
| 390 | - if (!$pluginFlag) { |
|
| 390 | + if ( ! $pluginFlag) { |
|
| 391 | 391 | $flag = ($tmp->get('password') == $tmp->getPassword($password)); |
| 392 | 392 | } |
| 393 | 393 | } |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | && null !== $this->getID() |
| 416 | 416 | && $this->get('password') == $cookie[1] |
| 417 | 417 | && $this->get('sessionid') == $cookie[2] |
| 418 | - && !$this->checkBlock($this->getID()) |
|
| 418 | + && ! $this->checkBlock($this->getID()) |
|
| 419 | 419 | ) { |
| 420 | 420 | $flag = $this->authUser($this->getID(), $fulltime, $cookieName, $fire_events); |
| 421 | 421 | |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | */ |
| 433 | 433 | public function logOut($cookieName = 'WebLoginPE', $fire_events = null) |
| 434 | 434 | { |
| 435 | - if (!$uid = $this->modx->getLoginUserID('web')) { |
|
| 435 | + if ( ! $uid = $this->modx->getLoginUserID('web')) { |
|
| 436 | 436 | return; |
| 437 | 437 | } |
| 438 | 438 | $params = array( |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | */ |
| 528 | 528 | public function setAutoLoginCookie($cookieName, $remember = true) |
| 529 | 529 | { |
| 530 | - if (!empty($cookieName) && $this->getID()) { |
|
| 530 | + if ( ! empty($cookieName) && $this->getID()) { |
|
| 531 | 531 | $secure = $this->isSecure(); |
| 532 | 532 | $remember = is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember; |
| 533 | 533 | $cookieValue = array(md5($this->get('username')), $this->get('password'), $this->get('sessionid'), $remember); |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | */ |
| 594 | 594 | public function setUserGroups($userID = 0, $groupIds = array()) |
| 595 | 595 | { |
| 596 | - if (!is_array($groupIds)) return $this; |
|
| 596 | + if ( ! is_array($groupIds)) return $this; |
|
| 597 | 597 | if ($this->newDoc && $userID == 0) { |
| 598 | 598 | $this->groupIds = $groupIds; |
| 599 | 599 | } else { |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | foreach ($groupIds as $gid) { |
| 603 | 603 | $this->query("REPLACE INTO {$this->makeTable('web_groups')} (`webgroup`, `webuser`) VALUES ('{$gid}', '{$uid}')"); |
| 604 | 604 | } |
| 605 | - if (!$this->newDoc) { |
|
| 605 | + if ( ! $this->newDoc) { |
|
| 606 | 606 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 607 | 607 | $this->query("DELETE FROM {$this->makeTable('web_groups')} WHERE `webuser`={$uid} AND `webgroup` NOT IN ({$groupIds})"); |
| 608 | 608 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | /** |
| 5 | 5 | * Class modUsers |
| 6 | 6 | */ |
| 7 | -class modUsers extends MODxAPI |
|
| 8 | -{ |
|
| 7 | +class modUsers extends MODxAPI |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var array |
| 11 | 11 | */ |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | * @param $key |
| 58 | 58 | * @return bool |
| 59 | 59 | */ |
| 60 | - public function issetField($key) |
|
| 61 | - { |
|
| 60 | + public function issetField($key) |
|
| 61 | + {
|
|
| 62 | 62 | return (array_key_exists($key, $this->default_field['user']) || array_key_exists($key, |
| 63 | 63 | $this->default_field['attribute']) || in_array($key, $this->default_field['hidden'])); |
| 64 | 64 | } |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * @param string $data |
| 68 | 68 | * @return string|false |
| 69 | 69 | */ |
| 70 | - protected function findUser($data) |
|
| 71 | - { |
|
| 72 | - switch (true) { |
|
| 70 | + protected function findUser($data) |
|
| 71 | + {
|
|
| 72 | + switch (true) {
|
|
| 73 | 73 | case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): |
| 74 | 74 | $find = 'attribute.internalKey'; |
| 75 | 75 | break; |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | * @param array $data |
| 91 | 91 | * @return $this |
| 92 | 92 | */ |
| 93 | - public function create($data = array()) |
|
| 94 | - { |
|
| 93 | + public function create($data = array()) |
|
| 94 | + {
|
|
| 95 | 95 | parent::create($data); |
| 96 | 96 | $this->set('createdon', time()); |
| 97 | 97 | |
@@ -102,16 +102,16 @@ discard block |
||
| 102 | 102 | * @param $id |
| 103 | 103 | * @return $this |
| 104 | 104 | */ |
| 105 | - public function edit($id) |
|
| 106 | - { |
|
| 105 | + public function edit($id) |
|
| 106 | + {
|
|
| 107 | 107 | $id = is_scalar($id) ? trim($id) : ''; |
| 108 | - if ($this->getID() != $id) { |
|
| 108 | + if ($this->getID() != $id) {
|
|
| 109 | 109 | $this->close(); |
| 110 | 110 | $this->newDoc = false; |
| 111 | 111 | |
| 112 | - if (!$find = $this->findUser($id)) { |
|
| 112 | + if (!$find = $this->findUser($id)) {
|
|
| 113 | 113 | $this->id = null; |
| 114 | - } else { |
|
| 114 | + } else {
|
|
| 115 | 115 | $this->set('editedon', time()); |
| 116 | 116 | $result = $this->query(" |
| 117 | 117 | SELECT * from {$this->makeTable('web_user_attributes')} as attribute |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | * @param $value |
| 136 | 136 | * @return $this |
| 137 | 137 | */ |
| 138 | - public function set($key, $value) |
|
| 139 | - { |
|
| 140 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
| 141 | - switch ($key) { |
|
| 138 | + public function set($key, $value) |
|
| 139 | + {
|
|
| 140 | + if (is_scalar($value) && is_scalar($key) && !empty($key)) {
|
|
| 141 | + switch ($key) {
|
|
| 142 | 142 | case 'password': |
| 143 | 143 | $this->givenPassword = $value; |
| 144 | 144 | $value = $this->getPassword($value); |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | * @param $pass |
| 163 | 163 | * @return string |
| 164 | 164 | */ |
| 165 | - public function getPassword($pass) |
|
| 166 | - { |
|
| 165 | + public function getPassword($pass) |
|
| 166 | + {
|
|
| 167 | 167 | return md5($pass); |
| 168 | 168 | } |
| 169 | 169 | |
@@ -172,23 +172,23 @@ discard block |
||
| 172 | 172 | * @param bool $clearCache |
| 173 | 173 | * @return bool|int|null|void |
| 174 | 174 | */ |
| 175 | - public function save($fire_events = false, $clearCache = false) |
|
| 176 | - { |
|
| 177 | - if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
| 175 | + public function save($fire_events = false, $clearCache = false) |
|
| 176 | + {
|
|
| 177 | + if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') {
|
|
| 178 | 178 | $this->log['EmptyPKField'] = 'Email, username or password is empty <pre>' . print_r($this->toArray(), |
| 179 | 179 | true) . '</pre>'; |
| 180 | 180 | |
| 181 | 181 | return false; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if (!$this->checkUnique('web_users', 'username')) { |
|
| 184 | + if (!$this->checkUnique('web_users', 'username')) {
|
|
| 185 | 185 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
| 186 | 186 | true) . '</pre>'; |
| 187 | 187 | |
| 188 | 188 | return false; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
| 191 | + if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) {
|
|
| 192 | 192 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
| 193 | 193 | |
| 194 | 194 | return false; |
@@ -196,60 +196,60 @@ discard block |
||
| 196 | 196 | $time = |
| 197 | 197 | $this->set('sessionid', ''); |
| 198 | 198 | $fld = $this->toArray(); |
| 199 | - foreach ($this->default_field['user'] as $key => $value) { |
|
| 199 | + foreach ($this->default_field['user'] as $key => $value) {
|
|
| 200 | 200 | $tmp = $this->get($key); |
| 201 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 201 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 202 | 202 | $this->field[$key] = $value; |
| 203 | 203 | } |
| 204 | 204 | $this->Uset($key, 'user'); |
| 205 | 205 | unset($fld[$key]); |
| 206 | 206 | } |
| 207 | - if (!empty($this->set['user'])) { |
|
| 208 | - if ($this->newDoc) { |
|
| 207 | + if (!empty($this->set['user'])) {
|
|
| 208 | + if ($this->newDoc) {
|
|
| 209 | 209 | $SQL = "INSERT into {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']); |
| 210 | - } else { |
|
| 210 | + } else {
|
|
| 211 | 211 | $SQL = "UPDATE {$this->makeTable('web_users')} SET " . implode(', ', |
| 212 | 212 | $this->set['user']) . " WHERE id = " . $this->id; |
| 213 | 213 | } |
| 214 | 214 | $this->query($SQL); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ($this->newDoc) { |
|
| 217 | + if ($this->newDoc) {
|
|
| 218 | 218 | $this->id = $this->modx->db->getInsertId(); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - foreach ($this->default_field['attribute'] as $key => $value) { |
|
| 221 | + foreach ($this->default_field['attribute'] as $key => $value) {
|
|
| 222 | 222 | $tmp = $this->get($key); |
| 223 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 223 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 224 | 224 | $this->field[$key] = $value; |
| 225 | 225 | } |
| 226 | 226 | $this->Uset($key, 'attribute'); |
| 227 | 227 | unset($fld[$key]); |
| 228 | 228 | } |
| 229 | - if (!empty($this->set['attribute'])) { |
|
| 230 | - if ($this->newDoc) { |
|
| 229 | + if (!empty($this->set['attribute'])) {
|
|
| 230 | + if ($this->newDoc) {
|
|
| 231 | 231 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
| 232 | 232 | $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
| 233 | 233 | $this->set['attribute']); |
| 234 | - } else { |
|
| 234 | + } else {
|
|
| 235 | 235 | $SQL = "UPDATE {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
| 236 | 236 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
| 237 | 237 | } |
| 238 | 238 | $this->query($SQL); |
| 239 | 239 | } |
| 240 | 240 | unset($fld['id']); |
| 241 | - foreach ($fld as $key => $value) { |
|
| 242 | - if ($value == '' || !$this->isChanged($key)) { |
|
| 241 | + foreach ($fld as $key => $value) {
|
|
| 242 | + if ($value == '' || !$this->isChanged($key)) {
|
|
| 243 | 243 | continue; |
| 244 | 244 | } |
| 245 | 245 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}'"); |
| 246 | - if ($this->modx->db->getRecordCount($result) > 0) { |
|
| 246 | + if ($this->modx->db->getRecordCount($result) > 0) {
|
|
| 247 | 247 | $this->query("UPDATE {$this->makeTable('web_user_settings')} SET `setting_value` = '{$value}' WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}';"); |
| 248 | - } else { |
|
| 248 | + } else {
|
|
| 249 | 249 | $this->query("INSERT into {$this->makeTable('web_user_settings')} SET `webuser` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | - if (!$this->newDoc && $this->givenPassword) { |
|
| 252 | + if (!$this->newDoc && $this->givenPassword) {
|
|
| 253 | 253 | $this->invokeEvent('OnWebChangePassword', array( |
| 254 | 254 | 'userObj' => $this, |
| 255 | 255 | 'userid' => $this->id, |
@@ -260,7 +260,9 @@ discard block |
||
| 260 | 260 | ), $fire_events); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if ($this->groupIds) $this->setUserGroups($this->id, $this->groupIds); |
|
| 263 | + if ($this->groupIds) {
|
|
| 264 | + $this->setUserGroups($this->id, $this->groupIds); |
|
| 265 | + } |
|
| 264 | 266 | |
| 265 | 267 | $this->invokeEvent('OnWebSaveUser', array( |
| 266 | 268 | 'userObj' => $this, |
@@ -269,7 +271,7 @@ discard block |
||
| 269 | 271 | 'user' => $this->toArray() |
| 270 | 272 | ), $fire_events); |
| 271 | 273 | |
| 272 | - if ($clearCache) { |
|
| 274 | + if ($clearCache) {
|
|
| 273 | 275 | $this->clearCache($fire_events); |
| 274 | 276 | } |
| 275 | 277 | |
@@ -281,9 +283,9 @@ discard block |
||
| 281 | 283 | * @param bool $fire_events |
| 282 | 284 | * @return bool|null|void |
| 283 | 285 | */ |
| 284 | - public function delete($ids, $fire_events = false) |
|
| 285 | - { |
|
| 286 | - if ($this->edit($ids)) { |
|
| 286 | + public function delete($ids, $fire_events = false) |
|
| 287 | + {
|
|
| 288 | + if ($this->edit($ids)) {
|
|
| 287 | 289 | $flag = $this->query(" |
| 288 | 290 | DELETE user,attribute FROM {$this->makeTable('web_user_attributes')} as attribute |
| 289 | 291 | LEFT JOIN {$this->makeTable('web_users')} as user ON user.id=attribute.internalKey |
@@ -297,7 +299,7 @@ discard block |
||
| 297 | 299 | 'username' => $this->get('username'), |
| 298 | 300 | 'timestamp' => time() |
| 299 | 301 | ), $fire_events); |
| 300 | - } else { |
|
| 302 | + } else {
|
|
| 301 | 303 | $flag = false; |
| 302 | 304 | } |
| 303 | 305 | $this->close(); |
@@ -312,13 +314,13 @@ discard block |
||
| 312 | 314 | * @param bool $fire_events |
| 313 | 315 | * @return bool |
| 314 | 316 | */ |
| 315 | - public function authUser($id = 0, $fulltime = true, $cookieName = 'WebLoginPE', $fire_events = false) |
|
| 316 | - { |
|
| 317 | + public function authUser($id = 0, $fulltime = true, $cookieName = 'WebLoginPE', $fire_events = false) |
|
| 318 | + {
|
|
| 317 | 319 | $flag = false; |
| 318 | - if (null === $this->getID() && $id) { |
|
| 320 | + if (null === $this->getID() && $id) {
|
|
| 319 | 321 | $this->edit($id); |
| 320 | 322 | } |
| 321 | - if (null !== $this->getID()) { |
|
| 323 | + if (null !== $this->getID()) {
|
|
| 322 | 324 | $flag = true; |
| 323 | 325 | $this->save(false); |
| 324 | 326 | $this->SessionHandler('start', $cookieName, $fulltime); |
@@ -338,10 +340,10 @@ discard block |
||
| 338 | 340 | * @param int $id |
| 339 | 341 | * @return bool |
| 340 | 342 | */ |
| 341 | - public function checkBlock($id = 0) |
|
| 342 | - { |
|
| 343 | + public function checkBlock($id = 0) |
|
| 344 | + {
|
|
| 343 | 345 | $tmp = clone $this; |
| 344 | - if ($id && $tmp->getID() != $id) { |
|
| 346 | + if ($id && $tmp->getID() != $id) {
|
|
| 345 | 347 | $tmp->edit($id); |
| 346 | 348 | } |
| 347 | 349 | $now = time(); |
@@ -362,17 +364,17 @@ discard block |
||
| 362 | 364 | * @param bool $fire_events |
| 363 | 365 | * @return bool |
| 364 | 366 | */ |
| 365 | - public function testAuth($id, $password, $blocker, $fire_events = false) |
|
| 366 | - { |
|
| 367 | + public function testAuth($id, $password, $blocker, $fire_events = false) |
|
| 368 | + {
|
|
| 367 | 369 | $tmp = clone $this; |
| 368 | - if ($id && $tmp->getID() != $id) { |
|
| 370 | + if ($id && $tmp->getID() != $id) {
|
|
| 369 | 371 | $tmp->edit($id); |
| 370 | 372 | } |
| 371 | 373 | |
| 372 | 374 | $flag = $pluginFlag = false; |
| 373 | 375 | if ( |
| 374 | 376 | (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
| 375 | - ) { |
|
| 377 | + ) {
|
|
| 376 | 378 | $eventResult = $this->getInvokeEventResult('OnWebAuthentication', array( |
| 377 | 379 | 'userObj' => $this, |
| 378 | 380 | 'userid' => $tmp->getID(), |
@@ -380,14 +382,14 @@ discard block |
||
| 380 | 382 | 'userpassword' => $password, |
| 381 | 383 | 'savedpassword' => $tmp->get('password') |
| 382 | 384 | ), $fire_events); |
| 383 | - if (is_array($eventResult)) { |
|
| 384 | - foreach ($eventResult as $result) { |
|
| 385 | + if (is_array($eventResult)) {
|
|
| 386 | + foreach ($eventResult as $result) {
|
|
| 385 | 387 | $pluginFlag = (bool)$result; |
| 386 | 388 | } |
| 387 | - } else { |
|
| 389 | + } else {
|
|
| 388 | 390 | $pluginFlag = (bool)$eventResult; |
| 389 | 391 | } |
| 390 | - if (!$pluginFlag) { |
|
| 392 | + if (!$pluginFlag) {
|
|
| 391 | 393 | $flag = ($tmp->get('password') == $tmp->getPassword($password)); |
| 392 | 394 | } |
| 393 | 395 | } |
@@ -401,12 +403,12 @@ discard block |
||
| 401 | 403 | * @param string $cookieName |
| 402 | 404 | * @return bool |
| 403 | 405 | */ |
| 404 | - public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_events = null) |
|
| 405 | - { |
|
| 406 | + public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_events = null) |
|
| 407 | + {
|
|
| 406 | 408 | $flag = false; |
| 407 | - if (isset($_COOKIE[$cookieName])) { |
|
| 409 | + if (isset($_COOKIE[$cookieName])) {
|
|
| 408 | 410 | $cookie = explode('|', $_COOKIE[$cookieName], 3); |
| 409 | - if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) { |
|
| 411 | + if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) {
|
|
| 410 | 412 | $this->close(); |
| 411 | 413 | $q = $this->modx->db->query("SELECT id FROM " . $this->makeTable('web_users') . " WHERE md5(username)='{$this->escape($cookie[0])}'"); |
| 412 | 414 | $id = $this->modx->db->getValue($q); |
@@ -416,7 +418,7 @@ discard block |
||
| 416 | 418 | && $this->get('password') == $cookie[1] |
| 417 | 419 | && $this->get('sessionid') == $cookie[2] |
| 418 | 420 | && !$this->checkBlock($this->getID()) |
| 419 | - ) { |
|
| 421 | + ) {
|
|
| 420 | 422 | $flag = $this->authUser($this->getID(), $fulltime, $cookieName, $fire_events); |
| 421 | 423 | |
| 422 | 424 | } |
@@ -430,9 +432,9 @@ discard block |
||
| 430 | 432 | * @param string $cookieName |
| 431 | 433 | * @param null $fire_events |
| 432 | 434 | */ |
| 433 | - public function logOut($cookieName = 'WebLoginPE', $fire_events = null) |
|
| 434 | - { |
|
| 435 | - if (!$uid = $this->modx->getLoginUserID('web')) { |
|
| 435 | + public function logOut($cookieName = 'WebLoginPE', $fire_events = null) |
|
| 436 | + {
|
|
| 437 | + if (!$uid = $this->modx->getLoginUserID('web')) {
|
|
| 436 | 438 | return; |
| 437 | 439 | } |
| 438 | 440 | $params = array( |
@@ -457,11 +459,11 @@ discard block |
||
| 457 | 459 | * |
| 458 | 460 | * remeber может быть числом в секундах |
| 459 | 461 | */ |
| 460 | - protected function SessionHandler($directive, $cookieName, $remember = true) |
|
| 461 | - { |
|
| 462 | - switch ($directive) { |
|
| 462 | + protected function SessionHandler($directive, $cookieName, $remember = true) |
|
| 463 | + {
|
|
| 464 | + switch ($directive) {
|
|
| 463 | 465 | case 'start': |
| 464 | - if ($this->getID()) { |
|
| 466 | + if ($this->getID()) {
|
|
| 465 | 467 | $_SESSION['webShortname'] = $this->get('username'); |
| 466 | 468 | $_SESSION['webFullname'] = $this->get('fullname'); |
| 467 | 469 | $_SESSION['webEmail'] = $this->get('email'); |
@@ -475,13 +477,13 @@ discard block |
||
| 475 | 477 | $_SESSION['webUsrConfigSet'] = array(); |
| 476 | 478 | $_SESSION['webUserGroupNames'] = $this->getUserGroups(); |
| 477 | 479 | $_SESSION['webDocgroups'] = $this->getDocumentGroups(); |
| 478 | - if ($remember) { |
|
| 480 | + if ($remember) {
|
|
| 479 | 481 | $this->setAutoLoginCookie($cookieName, $remember); |
| 480 | 482 | } |
| 481 | 483 | } |
| 482 | 484 | break; |
| 483 | 485 | case 'destroy': |
| 484 | - if (isset($_SESSION['mgrValidated'])) { |
|
| 486 | + if (isset($_SESSION['mgrValidated'])) {
|
|
| 485 | 487 | unset($_SESSION['webShortname']); |
| 486 | 488 | unset($_SESSION['webFullname']); |
| 487 | 489 | unset($_SESSION['webEmail']); |
@@ -497,8 +499,8 @@ discard block |
||
| 497 | 499 | unset($_SESSION['webDocgroups']); |
| 498 | 500 | |
| 499 | 501 | setcookie($cookieName, '', time() - 60, '/'); |
| 500 | - } else { |
|
| 501 | - if (isset($_COOKIE[session_name()])) { |
|
| 502 | + } else {
|
|
| 503 | + if (isset($_COOKIE[session_name()])) {
|
|
| 502 | 504 | setcookie(session_name(), '', time() - 60, '/'); |
| 503 | 505 | } |
| 504 | 506 | setcookie($cookieName, '', time() - 60, '/'); |
@@ -513,8 +515,8 @@ discard block |
||
| 513 | 515 | /** |
| 514 | 516 | * @return bool |
| 515 | 517 | */ |
| 516 | - public function isSecure() |
|
| 517 | - { |
|
| 518 | + public function isSecure() |
|
| 519 | + {
|
|
| 518 | 520 | $out = $this->modxConfig('server_protocol') == 'http' ? false : true; |
| 519 | 521 | |
| 520 | 522 | return $out; |
@@ -525,9 +527,9 @@ discard block |
||
| 525 | 527 | * @param bool $remember |
| 526 | 528 | * @return $this |
| 527 | 529 | */ |
| 528 | - public function setAutoLoginCookie($cookieName, $remember = true) |
|
| 529 | - { |
|
| 530 | - if (!empty($cookieName) && $this->getID()) { |
|
| 530 | + public function setAutoLoginCookie($cookieName, $remember = true) |
|
| 531 | + {
|
|
| 532 | + if (!empty($cookieName) && $this->getID()) {
|
|
| 531 | 533 | $secure = $this->isSecure(); |
| 532 | 534 | $remember = is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember; |
| 533 | 535 | $cookieValue = array(md5($this->get('username')), $this->get('password'), $this->get('sessionid'), $remember); |
@@ -543,11 +545,11 @@ discard block |
||
| 543 | 545 | * @param int $userID |
| 544 | 546 | * @return array |
| 545 | 547 | */ |
| 546 | - public function getDocumentGroups($userID = 0) |
|
| 547 | - { |
|
| 548 | + public function getDocumentGroups($userID = 0) |
|
| 549 | + {
|
|
| 548 | 550 | $out = array(); |
| 549 | 551 | $user = $this->switchObject($userID); |
| 550 | - if (null !== $user->getID()) { |
|
| 552 | + if (null !== $user->getID()) {
|
|
| 551 | 553 | $web_groups = $this->modx->getFullTableName('web_groups'); |
| 552 | 554 | $webgroup_access = $this->modx->getFullTableName('webgroup_access'); |
| 553 | 555 | |
@@ -566,18 +568,18 @@ discard block |
||
| 566 | 568 | * @param int $userID |
| 567 | 569 | * @return array |
| 568 | 570 | */ |
| 569 | - public function getUserGroups($userID = 0) |
|
| 570 | - { |
|
| 571 | + public function getUserGroups($userID = 0) |
|
| 572 | + {
|
|
| 571 | 573 | $out = array(); |
| 572 | 574 | $user = $this->switchObject($userID); |
| 573 | - if (null !== $user->getID()) { |
|
| 575 | + if (null !== $user->getID()) {
|
|
| 574 | 576 | $web_groups = $this->makeTable('web_groups'); |
| 575 | 577 | $webgroup_names = $this->makeTable('webgroup_names'); |
| 576 | 578 | |
| 577 | 579 | $rs = $this->query("SELECT `ug`.`webgroup`, `ugn`.`name` FROM {$web_groups} as `ug` |
| 578 | 580 | INNER JOIN {$webgroup_names} as `ugn` ON `ugn`.`id`=`ug`.`webgroup` |
| 579 | 581 | WHERE `ug`.`webuser` = " . $user->getID()); |
| 580 | - while ($row = $this->modx->db->getRow($rs)) { |
|
| 582 | + while ($row = $this->modx->db->getRow($rs)) {
|
|
| 581 | 583 | $out[$row['webgroup']] = $row['name']; |
| 582 | 584 | } |
| 583 | 585 | } |
@@ -591,18 +593,20 @@ discard block |
||
| 591 | 593 | * @param array $groupIds |
| 592 | 594 | * @return $this |
| 593 | 595 | */ |
| 594 | - public function setUserGroups($userID = 0, $groupIds = array()) |
|
| 595 | - { |
|
| 596 | - if (!is_array($groupIds)) return $this; |
|
| 597 | - if ($this->newDoc && $userID == 0) { |
|
| 596 | + public function setUserGroups($userID = 0, $groupIds = array()) |
|
| 597 | + {
|
|
| 598 | + if (!is_array($groupIds)) {
|
|
| 599 | + return $this; |
|
| 600 | + } |
|
| 601 | + if ($this->newDoc && $userID == 0) {
|
|
| 598 | 602 | $this->groupIds = $groupIds; |
| 599 | - } else { |
|
| 603 | + } else {
|
|
| 600 | 604 | $user = $this->switchObject($userID); |
| 601 | - if ($uid = $user->getID()) { |
|
| 602 | - foreach ($groupIds as $gid) { |
|
| 605 | + if ($uid = $user->getID()) {
|
|
| 606 | + foreach ($groupIds as $gid) {
|
|
| 603 | 607 | $this->query("REPLACE INTO {$this->makeTable('web_groups')} (`webgroup`, `webuser`) VALUES ('{$gid}', '{$uid}')"); |
| 604 | 608 | } |
| 605 | - if (!$this->newDoc) { |
|
| 609 | + if (!$this->newDoc) {
|
|
| 606 | 610 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 607 | 611 | $this->query("DELETE FROM {$this->makeTable('web_groups')} WHERE `webuser`={$uid} AND `webgroup` NOT IN ({$groupIds})"); |
| 608 | 612 | } |
@@ -193,11 +193,11 @@ discard block |
||
| 193 | 193 | protected function getTime($value) |
| 194 | 194 | { |
| 195 | 195 | $value = trim($value); |
| 196 | - if (!empty($value)) { |
|
| 197 | - if (!is_numeric($value)) { |
|
| 196 | + if ( ! empty($value)) { |
|
| 197 | + if ( ! is_numeric($value)) { |
|
| 198 | 198 | $value = (int)strtotime($value); |
| 199 | 199 | } |
| 200 | - if (!empty($value)) { |
|
| 200 | + if ( ! empty($value)) { |
|
| 201 | 201 | $value += $this->modxConfig('server_offset_time'); |
| 202 | 202 | } |
| 203 | 203 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | public function addQuery($q) |
| 223 | 223 | { |
| 224 | - if (is_scalar($q) && !empty($q)) { |
|
| 224 | + if (is_scalar($q) && ! empty($q)) { |
|
| 225 | 225 | $this->_query[] = $q; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | final public function escape($value) |
| 257 | 257 | { |
| 258 | - if (!is_scalar($value)) { |
|
| 258 | + if ( ! is_scalar($value)) { |
|
| 259 | 259 | $value = ''; |
| 260 | 260 | } else { |
| 261 | 261 | $value = $this->modx->db->escape($value); |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | //Если уже загружен объект, с которым мы хотим временно поработать |
| 397 | 397 | case ($this->getID() == $id && $id): |
| 398 | 398 | //Если $id не указан, но уже загружен какой-то объект |
| 399 | - case (!$id && null !== $this->getID()): |
|
| 399 | + case ( ! $id && null !== $this->getID()): |
|
| 400 | 400 | default: |
| 401 | 401 | $obj = $this; |
| 402 | 402 | break; |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | public function set($key, $value) |
| 433 | 433 | { |
| 434 | - if ((is_scalar($value) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
| 434 | + if ((is_scalar($value) || $this->isJsonField($key)) && is_scalar($key) && ! empty($key)) { |
|
| 435 | 435 | $this->field[$key] = $value; |
| 436 | 436 | } |
| 437 | 437 | |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | */ |
| 481 | 481 | final protected function Uset($key, $id = '') |
| 482 | 482 | { |
| 483 | - if (!isset($this->field[$key])) { |
|
| 483 | + if ( ! isset($this->field[$key])) { |
|
| 484 | 484 | $tmp = "`{$key}`=''"; |
| 485 | 485 | $this->log[] = "{$key} is empty"; |
| 486 | 486 | } else { |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>"); |
| 491 | 491 | } |
| 492 | 492 | } |
| 493 | - if (!empty($tmp) && $this->isChanged($key)) { |
|
| 493 | + if ( ! empty($tmp) && $this->isChanged($key)) { |
|
| 494 | 494 | if ($id == '') { |
| 495 | 495 | $this->set[] = $tmp; |
| 496 | 496 | } else { |
@@ -520,8 +520,8 @@ discard block |
||
| 520 | 520 | * @return MODxAPI |
| 521 | 521 | */ |
| 522 | 522 | public function rollback($key = '') { |
| 523 | - if (!empty($key) && isset($this->store[$key])) { |
|
| 524 | - $this->set($key,$this->store[$key]); |
|
| 523 | + if ( ! empty($key) && isset($this->store[$key])) { |
|
| 524 | + $this->set($key, $this->store[$key]); |
|
| 525 | 525 | } else { |
| 526 | 526 | $this->fromArray($this->store); |
| 527 | 527 | } |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | * @return bool |
| 537 | 537 | */ |
| 538 | 538 | public function isChanged($key) { |
| 539 | - $flag = !isset($this->store[$key]) || (isset($this->store[$key]) && $this->store[$key] != $this->field[$key]); |
|
| 539 | + $flag = ! isset($this->store[$key]) || (isset($this->store[$key]) && $this->store[$key] != $this->field[$key]); |
|
| 540 | 540 | |
| 541 | 541 | return $flag; |
| 542 | 542 | } |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | final public function cleanIDs($IDs, $sep = ',', $ignore = array()) |
| 552 | 552 | { |
| 553 | 553 | $out = array(); |
| 554 | - if (!is_array($IDs)) { |
|
| 554 | + if ( ! is_array($IDs)) { |
|
| 555 | 555 | if (is_scalar($IDs)) { |
| 556 | 556 | $IDs = explode($sep, $IDs); |
| 557 | 557 | } else { |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | foreach ($IDs as $item) { |
| 563 | 563 | $item = trim($item); |
| 564 | 564 | if (is_scalar($item) && (int)$item >= 0) { //Fix 0xfffffffff |
| 565 | - if (!empty($ignore) && in_array((int)$item, $ignore, true)) { |
|
| 565 | + if ( ! empty($ignore) && in_array((int)$item, $ignore, true)) { |
|
| 566 | 566 | $this->log[] = 'Ignore id ' . (int)$item; |
| 567 | 567 | } else { |
| 568 | 568 | $out[] = (int)$item; |
@@ -582,7 +582,7 @@ discard block |
||
| 582 | 582 | */ |
| 583 | 583 | final public function fromJson($data, $callback = null) |
| 584 | 584 | { |
| 585 | - if (is_scalar($data) && !empty($data)) { |
|
| 585 | + if (is_scalar($data) && ! empty($data)) { |
|
| 586 | 586 | $json = json_decode($data); |
| 587 | 587 | } else { |
| 588 | 588 | throw new Exception("json is not string with json data"); |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | */ |
| 701 | 701 | final public function sanitarIn($data, $sep = ',') |
| 702 | 702 | { |
| 703 | - if (!is_array($data)) { |
|
| 703 | + if ( ! is_array($data)) { |
|
| 704 | 704 | $data = explode($sep, $data); |
| 705 | 705 | } |
| 706 | 706 | $out = array(); |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | if ($where != '') { |
| 743 | 743 | $sql = $this->query("SELECT `" . $this->escape($PK) . "` FROM " . $this->makeTable($table) . " WHERE " . $where); |
| 744 | 744 | $id = $this->modx->db->getValue($sql); |
| 745 | - if (is_null($id) || (!$this->newDoc && $id == $this->getID())) { |
|
| 745 | + if (is_null($id) || ( ! $this->newDoc && $id == $this->getID())) { |
|
| 746 | 746 | $flag = true; |
| 747 | 747 | } else { |
| 748 | 748 | $flag = false; |
@@ -940,7 +940,7 @@ discard block |
||
| 940 | 940 | */ |
| 941 | 941 | public function getNoEncodeFields() |
| 942 | 942 | { |
| 943 | - return $this->_decodedFields->filter(function ($value) { |
|
| 943 | + return $this->_decodedFields->filter(function($value) { |
|
| 944 | 944 | return ($value === false); |
| 945 | 945 | }); |
| 946 | 946 | } |
@@ -951,7 +951,7 @@ discard block |
||
| 951 | 951 | */ |
| 952 | 952 | public function getNoDecodeFields() |
| 953 | 953 | { |
| 954 | - return $this->_decodedFields->filter(function ($value) { |
|
| 954 | + return $this->_decodedFields->filter(function($value) { |
|
| 955 | 955 | return ($value === true); |
| 956 | 956 | }); |
| 957 | 957 | } |
@@ -7,15 +7,15 @@ discard block |
||
| 7 | 7 | /** |
| 8 | 8 | * Class MODxAPIhelpers |
| 9 | 9 | */ |
| 10 | -class MODxAPIhelpers |
|
| 11 | -{ |
|
| 10 | +class MODxAPIhelpers |
|
| 11 | +{
|
|
| 12 | 12 | /** |
| 13 | 13 | * @param $email |
| 14 | 14 | * @param bool $dns |
| 15 | 15 | * @return false|string |
| 16 | 16 | */ |
| 17 | - public function emailValidate($email, $dns = true) |
|
| 18 | - { |
|
| 17 | + public function emailValidate($email, $dns = true) |
|
| 18 | + {
|
|
| 19 | 19 | return \APIhelpers::emailValidate($email, $dns); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | * @param string $data |
| 25 | 25 | * @return string |
| 26 | 26 | */ |
| 27 | - public function genPass($len, $data = '') |
|
| 28 | - { |
|
| 27 | + public function genPass($len, $data = '') |
|
| 28 | + {
|
|
| 29 | 29 | return \APIhelpers::genPass($len, $data); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | * @param string $out |
| 34 | 34 | * @return string |
| 35 | 35 | */ |
| 36 | - public function getUserIP($out = '127.0.0.1') |
|
| 37 | - { |
|
| 36 | + public function getUserIP($out = '127.0.0.1') |
|
| 37 | + {
|
|
| 38 | 38 | return \APIhelpers::getUserIP($out); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @param $data |
| 43 | 43 | * @return array|mixed|string |
| 44 | 44 | */ |
| 45 | - public function sanitarTag($data) |
|
| 46 | - { |
|
| 45 | + public function sanitarTag($data) |
|
| 46 | + {
|
|
| 47 | 47 | return \APIhelpers::sanitarTag($data); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | * @param array $mixArray |
| 55 | 55 | * @return bool |
| 56 | 56 | */ |
| 57 | - public function checkString($value, $minLen = 1, $alph = array(), $mixArray = array()) |
|
| 58 | - { |
|
| 57 | + public function checkString($value, $minLen = 1, $alph = array(), $mixArray = array()) |
|
| 58 | + {
|
|
| 59 | 59 | return \APIhelpers::checkString($value, $minLen, $alph, $mixArray); |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * Class MODxAPI |
| 65 | 65 | */ |
| 66 | -abstract class MODxAPI extends MODxAPIhelpers |
|
| 67 | -{ |
|
| 66 | +abstract class MODxAPI extends MODxAPIhelpers |
|
| 67 | +{
|
|
| 68 | 68 | /** |
| 69 | 69 | * Объект DocumentParser - основной класс MODX |
| 70 | 70 | * @var \DocumentParser |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | * @param bool $debug |
| 149 | 149 | * @throws Exception |
| 150 | 150 | */ |
| 151 | - public function __construct(DocumentParser $modx, $debug = false) |
|
| 152 | - { |
|
| 151 | + public function __construct(DocumentParser $modx, $debug = false) |
|
| 152 | + {
|
|
| 153 | 153 | $this->modx = $modx; |
| 154 | - if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) { |
|
| 154 | + if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) {
|
|
| 155 | 155 | throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.'); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | * @param boolean $flag |
| 164 | 164 | * @return $this |
| 165 | 165 | */ |
| 166 | - public function setDebug($flag) |
|
| 167 | - { |
|
| 166 | + public function setDebug($flag) |
|
| 167 | + {
|
|
| 168 | 168 | $this->_debug = (bool)$flag; |
| 169 | 169 | |
| 170 | 170 | return $this; |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | /** |
| 174 | 174 | * @return bool |
| 175 | 175 | */ |
| 176 | - public function getDebug() |
|
| 177 | - { |
|
| 176 | + public function getDebug() |
|
| 177 | + {
|
|
| 178 | 178 | return $this->_debug; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | 182 | * @return array |
| 183 | 183 | */ |
| 184 | - public function getDefaultFields() |
|
| 185 | - { |
|
| 184 | + public function getDefaultFields() |
|
| 185 | + {
|
|
| 186 | 186 | return $this->default_field; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | * @param $value |
| 191 | 191 | * @return int|mixed|string |
| 192 | 192 | */ |
| 193 | - protected function getTime($value) |
|
| 194 | - { |
|
| 193 | + protected function getTime($value) |
|
| 194 | + {
|
|
| 195 | 195 | $value = trim($value); |
| 196 | - if (!empty($value)) { |
|
| 197 | - if (!is_numeric($value)) { |
|
| 196 | + if (!empty($value)) {
|
|
| 197 | + if (!is_numeric($value)) {
|
|
| 198 | 198 | $value = (int)strtotime($value); |
| 199 | 199 | } |
| 200 | - if (!empty($value)) { |
|
| 200 | + if (!empty($value)) {
|
|
| 201 | 201 | $value += $this->modxConfig('server_offset_time'); |
| 202 | 202 | } |
| 203 | 203 | } |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | * @param null $default |
| 211 | 211 | * @return mixed |
| 212 | 212 | */ |
| 213 | - final public function modxConfig($name, $default = null) |
|
| 214 | - { |
|
| 213 | + final public function modxConfig($name, $default = null) |
|
| 214 | + {
|
|
| 215 | 215 | return APIHelpers::getkey($this->modx->config, $name, $default); |
| 216 | 216 | } |
| 217 | 217 | |
@@ -219,9 +219,9 @@ discard block |
||
| 219 | 219 | * @param $q |
| 220 | 220 | * @return $this |
| 221 | 221 | */ |
| 222 | - public function addQuery($q) |
|
| 223 | - { |
|
| 224 | - if (is_scalar($q) && !empty($q)) { |
|
| 222 | + public function addQuery($q) |
|
| 223 | + {
|
|
| 224 | + if (is_scalar($q) && !empty($q)) {
|
|
| 225 | 225 | $this->_query[] = $q; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | /** |
| 232 | 232 | * @return array |
| 233 | 233 | */ |
| 234 | - public function getQueryList() |
|
| 235 | - { |
|
| 234 | + public function getQueryList() |
|
| 235 | + {
|
|
| 236 | 236 | return $this->_query; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | * @param $SQL |
| 241 | 241 | * @return mixed |
| 242 | 242 | */ |
| 243 | - final public function query($SQL) |
|
| 244 | - { |
|
| 245 | - if ($this->getDebug()) { |
|
| 243 | + final public function query($SQL) |
|
| 244 | + {
|
|
| 245 | + if ($this->getDebug()) {
|
|
| 246 | 246 | $this->addQuery($SQL); |
| 247 | 247 | } |
| 248 | 248 | |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | * @param $value |
| 254 | 254 | * @return string|void |
| 255 | 255 | */ |
| 256 | - final public function escape($value) |
|
| 257 | - { |
|
| 258 | - if (!is_scalar($value)) { |
|
| 256 | + final public function escape($value) |
|
| 257 | + {
|
|
| 258 | + if (!is_scalar($value)) {
|
|
| 259 | 259 | $value = ''; |
| 260 | - } else { |
|
| 260 | + } else {
|
|
| 261 | 261 | $value = $this->modx->db->escape($value); |
| 262 | 262 | } |
| 263 | 263 | |
@@ -270,10 +270,10 @@ discard block |
||
| 270 | 270 | * @param bool $flag |
| 271 | 271 | * @return $this |
| 272 | 272 | */ |
| 273 | - final public function invokeEvent($name, $data = array(), $flag = false) |
|
| 274 | - { |
|
| 273 | + final public function invokeEvent($name, $data = array(), $flag = false) |
|
| 274 | + {
|
|
| 275 | 275 | $flag = (isset($flag) && $flag != '') ? (bool)$flag : false; |
| 276 | - if ($flag) { |
|
| 276 | + if ($flag) {
|
|
| 277 | 277 | $this->modx->invokeEvent($name, $data); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | * @param boolean $flag |
| 287 | 287 | * @return array|bool |
| 288 | 288 | */ |
| 289 | - final public function getInvokeEventResult($name, $data = array(), $flag = null) |
|
| 290 | - { |
|
| 289 | + final public function getInvokeEventResult($name, $data = array(), $flag = null) |
|
| 290 | + {
|
|
| 291 | 291 | $flag = (isset($flag) && $flag != '') ? (bool)$flag : false; |
| 292 | 292 | |
| 293 | 293 | return $flag ? $this->modx->invokeEvent($name, $data) : false; |
@@ -296,8 +296,8 @@ discard block |
||
| 296 | 296 | /** |
| 297 | 297 | * @return $this |
| 298 | 298 | */ |
| 299 | - final public function clearLog() |
|
| 300 | - { |
|
| 299 | + final public function clearLog() |
|
| 300 | + {
|
|
| 301 | 301 | $this->log = array(); |
| 302 | 302 | |
| 303 | 303 | return $this; |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | /** |
| 307 | 307 | * @return array |
| 308 | 308 | */ |
| 309 | - final public function getLog() |
|
| 310 | - { |
|
| 309 | + final public function getLog() |
|
| 310 | + {
|
|
| 311 | 311 | return $this->log; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -315,10 +315,10 @@ discard block |
||
| 315 | 315 | * @param bool $flush |
| 316 | 316 | * @return $this |
| 317 | 317 | */ |
| 318 | - final public function list_log($flush = false) |
|
| 319 | - { |
|
| 318 | + final public function list_log($flush = false) |
|
| 319 | + {
|
|
| 320 | 320 | echo '<pre>' . print_r(APIHelpers::sanitarTag($this->log), true) . '</pre>'; |
| 321 | - if ($flush) { |
|
| 321 | + if ($flush) {
|
|
| 322 | 322 | $this->clearLog(); |
| 323 | 323 | } |
| 324 | 324 | |
@@ -329,10 +329,10 @@ discard block |
||
| 329 | 329 | * @param bool $full |
| 330 | 330 | * @return string |
| 331 | 331 | */ |
| 332 | - final public function getCachePath($full = true) |
|
| 333 | - { |
|
| 332 | + final public function getCachePath($full = true) |
|
| 333 | + {
|
|
| 334 | 334 | $path = $this->modx->getCachePath(); |
| 335 | - if ($full) { |
|
| 335 | + if ($full) {
|
|
| 336 | 336 | $path = MODX_BASE_PATH . substr($path, strlen(MODX_BASE_URL)); |
| 337 | 337 | } |
| 338 | 338 | |
@@ -343,10 +343,10 @@ discard block |
||
| 343 | 343 | * @param boolean $fire_events |
| 344 | 344 | * @param bool $custom |
| 345 | 345 | */ |
| 346 | - final public function clearCache($fire_events = false, $custom = false) |
|
| 347 | - { |
|
| 346 | + final public function clearCache($fire_events = false, $custom = false) |
|
| 347 | + {
|
|
| 348 | 348 | $IDs = array(); |
| 349 | - if ($custom === false) { |
|
| 349 | + if ($custom === false) {
|
|
| 350 | 350 | $this->modx->clearCache(); |
| 351 | 351 | include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php'); |
| 352 | 352 | $sync = new synccache(); |
@@ -354,22 +354,22 @@ discard block |
||
| 354 | 354 | $sync->setCachepath($path); |
| 355 | 355 | $sync->setReport(false); |
| 356 | 356 | $sync->emptyCache(); |
| 357 | - } else { |
|
| 358 | - if (is_scalar($custom)) { |
|
| 357 | + } else {
|
|
| 358 | + if (is_scalar($custom)) {
|
|
| 359 | 359 | $custom = array($custom); |
| 360 | 360 | } |
| 361 | - switch ($this->modx->config['cache_type']) { |
|
| 361 | + switch ($this->modx->config['cache_type']) {
|
|
| 362 | 362 | case 2: |
| 363 | 363 | $cacheFile = "_*.pageCache.php"; |
| 364 | 364 | break; |
| 365 | 365 | default: |
| 366 | 366 | $cacheFile = ".pageCache.php"; |
| 367 | 367 | } |
| 368 | - if (is_array($custom)) { |
|
| 369 | - foreach ($custom as $id) { |
|
| 368 | + if (is_array($custom)) {
|
|
| 369 | + foreach ($custom as $id) {
|
|
| 370 | 370 | $tmp = glob(MODX_BASE_PATH . "assets/cache/docid_" . $id . $cacheFile); |
| 371 | - foreach ($tmp as $file) { |
|
| 372 | - if (is_readable($file)) { |
|
| 371 | + foreach ($tmp as $file) {
|
|
| 372 | + if (is_readable($file)) {
|
|
| 373 | 373 | unlink($file); |
| 374 | 374 | } |
| 375 | 375 | $IDs[] = $id; |
@@ -385,9 +385,9 @@ discard block |
||
| 385 | 385 | * @param integer $id |
| 386 | 386 | * @return MODxAPI |
| 387 | 387 | */ |
| 388 | - public function switchObject($id) |
|
| 389 | - { |
|
| 390 | - switch (true) { |
|
| 388 | + public function switchObject($id) |
|
| 389 | + {
|
|
| 390 | + switch (true) {
|
|
| 391 | 391 | //Если загружен другой объект - не тот, с которым мы хотим временно поработать |
| 392 | 392 | case ($this->getID() != $id && $id): |
| 393 | 393 | $obj = clone $this; |
@@ -409,8 +409,8 @@ discard block |
||
| 409 | 409 | * @param bool $flag |
| 410 | 410 | * @return $this |
| 411 | 411 | */ |
| 412 | - public function useIgnore($flag = true) |
|
| 413 | - { |
|
| 412 | + public function useIgnore($flag = true) |
|
| 413 | + {
|
|
| 414 | 414 | $this->ignoreError = $flag ? 'IGNORE' : ''; |
| 415 | 415 | |
| 416 | 416 | return $this; |
@@ -419,8 +419,8 @@ discard block |
||
| 419 | 419 | /** |
| 420 | 420 | * @return bool |
| 421 | 421 | */ |
| 422 | - public function hasIgnore() |
|
| 423 | - { |
|
| 422 | + public function hasIgnore() |
|
| 423 | + {
|
|
| 424 | 424 | return (bool)$this->ignoreError; |
| 425 | 425 | } |
| 426 | 426 | |
@@ -429,9 +429,9 @@ discard block |
||
| 429 | 429 | * @param $value |
| 430 | 430 | * @return $this |
| 431 | 431 | */ |
| 432 | - public function set($key, $value) |
|
| 433 | - { |
|
| 434 | - if ((is_scalar($value) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
| 432 | + public function set($key, $value) |
|
| 433 | + {
|
|
| 434 | + if ((is_scalar($value) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
|
|
| 435 | 435 | $this->field[$key] = $value; |
| 436 | 436 | } |
| 437 | 437 | |
@@ -441,8 +441,8 @@ discard block |
||
| 441 | 441 | /** |
| 442 | 442 | * @return null|int |
| 443 | 443 | */ |
| 444 | - final public function getID() |
|
| 445 | - { |
|
| 444 | + final public function getID() |
|
| 445 | + {
|
|
| 446 | 446 | return $this->id; |
| 447 | 447 | } |
| 448 | 448 | |
@@ -450,8 +450,8 @@ discard block |
||
| 450 | 450 | * @param $key |
| 451 | 451 | * @return mixed |
| 452 | 452 | */ |
| 453 | - public function get($key) |
|
| 454 | - { |
|
| 453 | + public function get($key) |
|
| 454 | + {
|
|
| 455 | 455 | return APIHelpers::getkey($this->field, $key, null); |
| 456 | 456 | } |
| 457 | 457 | |
@@ -459,10 +459,10 @@ discard block |
||
| 459 | 459 | * @param $data |
| 460 | 460 | * @return $this |
| 461 | 461 | */ |
| 462 | - public function fromArray($data) |
|
| 463 | - { |
|
| 464 | - if (is_array($data)) { |
|
| 465 | - foreach ($data as $key => $value) { |
|
| 462 | + public function fromArray($data) |
|
| 463 | + {
|
|
| 464 | + if (is_array($data)) {
|
|
| 465 | + foreach ($data as $key => $value) {
|
|
| 466 | 466 | $this->set($key, $value); |
| 467 | 467 | } |
| 468 | 468 | } |
@@ -478,22 +478,22 @@ discard block |
||
| 478 | 478 | * @return $this |
| 479 | 479 | * @throws Exception |
| 480 | 480 | */ |
| 481 | - final protected function Uset($key, $id = '') |
|
| 482 | - { |
|
| 483 | - if (!isset($this->field[$key])) { |
|
| 481 | + final protected function Uset($key, $id = '') |
|
| 482 | + {
|
|
| 483 | + if (!isset($this->field[$key])) {
|
|
| 484 | 484 | $tmp = "`{$key}`=''"; |
| 485 | 485 | $this->log[] = "{$key} is empty"; |
| 486 | - } else { |
|
| 487 | - if ($this->issetField($key) && is_scalar($this->field[$key])) { |
|
| 486 | + } else {
|
|
| 487 | + if ($this->issetField($key) && is_scalar($this->field[$key])) {
|
|
| 488 | 488 | $tmp = "`{$key}`='{$this->escape($this->field[$key])}'"; |
| 489 | - } else { |
|
| 489 | + } else {
|
|
| 490 | 490 | throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>"); |
| 491 | 491 | } |
| 492 | 492 | } |
| 493 | - if (!empty($tmp) && $this->isChanged($key)) { |
|
| 494 | - if ($id == '') { |
|
| 493 | + if (!empty($tmp) && $this->isChanged($key)) {
|
|
| 494 | + if ($id == '') {
|
|
| 495 | 495 | $this->set[] = $tmp; |
| 496 | - } else { |
|
| 496 | + } else {
|
|
| 497 | 497 | $this->set[$id][] = $tmp; |
| 498 | 498 | } |
| 499 | 499 | } |
@@ -507,8 +507,11 @@ discard block |
||
| 507 | 507 | * @param array $data |
| 508 | 508 | * @return $this |
| 509 | 509 | */ |
| 510 | - public function store($data = array()) { |
|
| 511 | - if (is_array($data)) $this->store = $data; |
|
| 510 | + public function store($data = array()) |
|
| 511 | + {
|
|
| 512 | + if (is_array($data)) {
|
|
| 513 | + $this->store = $data; |
|
| 514 | + } |
|
| 512 | 515 | |
| 513 | 516 | return $this; |
| 514 | 517 | } |
@@ -519,10 +522,11 @@ discard block |
||
| 519 | 522 | * @param string $key |
| 520 | 523 | * @return MODxAPI |
| 521 | 524 | */ |
| 522 | - public function rollback($key = '') { |
|
| 523 | - if (!empty($key) && isset($this->store[$key])) { |
|
| 525 | + public function rollback($key = '') |
|
| 526 | + {
|
|
| 527 | + if (!empty($key) && isset($this->store[$key])) {
|
|
| 524 | 528 | $this->set($key,$this->store[$key]); |
| 525 | - } else { |
|
| 529 | + } else {
|
|
| 526 | 530 | $this->fromArray($this->store); |
| 527 | 531 | } |
| 528 | 532 | |
@@ -535,7 +539,8 @@ discard block |
||
| 535 | 539 | * @param $key |
| 536 | 540 | * @return bool |
| 537 | 541 | */ |
| 538 | - public function isChanged($key) { |
|
| 542 | + public function isChanged($key) |
|
| 543 | + {
|
|
| 539 | 544 | $flag = !isset($this->store[$key]) || (isset($this->store[$key]) && $this->store[$key] != $this->field[$key]); |
| 540 | 545 | |
| 541 | 546 | return $flag; |
@@ -548,23 +553,24 @@ discard block |
||
| 548 | 553 | * @return array |
| 549 | 554 | * @throws Exception |
| 550 | 555 | */ |
| 551 | - final public function cleanIDs($IDs, $sep = ',', $ignore = array()) |
|
| 552 | - { |
|
| 556 | + final public function cleanIDs($IDs, $sep = ',', $ignore = array()) |
|
| 557 | + {
|
|
| 553 | 558 | $out = array(); |
| 554 | - if (!is_array($IDs)) { |
|
| 555 | - if (is_scalar($IDs)) { |
|
| 559 | + if (!is_array($IDs)) {
|
|
| 560 | + if (is_scalar($IDs)) {
|
|
| 556 | 561 | $IDs = explode($sep, $IDs); |
| 557 | - } else { |
|
| 562 | + } else {
|
|
| 558 | 563 | $IDs = array(); |
| 559 | 564 | throw new Exception('Invalid IDs list <pre>' . print_r($IDs, 1) . '</pre>'); |
| 560 | 565 | } |
| 561 | 566 | } |
| 562 | - foreach ($IDs as $item) { |
|
| 567 | + foreach ($IDs as $item) {
|
|
| 563 | 568 | $item = trim($item); |
| 564 | - if (is_scalar($item) && (int)$item >= 0) { //Fix 0xfffffffff |
|
| 565 | - if (!empty($ignore) && in_array((int)$item, $ignore, true)) { |
|
| 569 | + if (is_scalar($item) && (int)$item >= 0) {
|
|
| 570 | +//Fix 0xfffffffff |
|
| 571 | + if (!empty($ignore) && in_array((int)$item, $ignore, true)) {
|
|
| 566 | 572 | $this->log[] = 'Ignore id ' . (int)$item; |
| 567 | - } else { |
|
| 573 | + } else {
|
|
| 568 | 574 | $out[] = (int)$item; |
| 569 | 575 | } |
| 570 | 576 | } |
@@ -580,26 +586,26 @@ discard block |
||
| 580 | 586 | * @return $this |
| 581 | 587 | * @throws Exception |
| 582 | 588 | */ |
| 583 | - final public function fromJson($data, $callback = null) |
|
| 584 | - { |
|
| 585 | - if (is_scalar($data) && !empty($data)) { |
|
| 589 | + final public function fromJson($data, $callback = null) |
|
| 590 | + {
|
|
| 591 | + if (is_scalar($data) && !empty($data)) {
|
|
| 586 | 592 | $json = json_decode($data); |
| 587 | - } else { |
|
| 593 | + } else {
|
|
| 588 | 594 | throw new Exception("json is not string with json data"); |
| 589 | 595 | } |
| 590 | 596 | |
| 591 | - if ($this->jsonError($json)) { |
|
| 592 | - if (isset($callback) && is_callable($callback)) { |
|
| 597 | + if ($this->jsonError($json)) {
|
|
| 598 | + if (isset($callback) && is_callable($callback)) {
|
|
| 593 | 599 | call_user_func_array($callback, array($json)); |
| 594 | - } else { |
|
| 595 | - if (isset($callback)) { |
|
| 600 | + } else {
|
|
| 601 | + if (isset($callback)) {
|
|
| 596 | 602 | throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>"); |
| 597 | 603 | } |
| 598 | - foreach ($json as $key => $val) { |
|
| 604 | + foreach ($json as $key => $val) {
|
|
| 599 | 605 | $this->set($key, $val); |
| 600 | 606 | } |
| 601 | 607 | } |
| 602 | - } else { |
|
| 608 | + } else {
|
|
| 603 | 609 | throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>'); |
| 604 | 610 | } |
| 605 | 611 | |
@@ -611,19 +617,19 @@ discard block |
||
| 611 | 617 | * @return string |
| 612 | 618 | * @throws Exception |
| 613 | 619 | */ |
| 614 | - final public function toJson($callback = null) |
|
| 615 | - { |
|
| 620 | + final public function toJson($callback = null) |
|
| 621 | + {
|
|
| 616 | 622 | $data = $this->toArray(); |
| 617 | - if (isset($callback) && is_callable($callback)) { |
|
| 623 | + if (isset($callback) && is_callable($callback)) {
|
|
| 618 | 624 | $data = call_user_func_array($callback, array($data)); |
| 619 | - } else { |
|
| 620 | - if (isset($callback)) { |
|
| 625 | + } else {
|
|
| 626 | + if (isset($callback)) {
|
|
| 621 | 627 | throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>"); |
| 622 | 628 | } |
| 623 | 629 | } |
| 624 | 630 | $json = json_encode($data); |
| 625 | 631 | |
| 626 | - if ($this->jsonError($data)) { |
|
| 632 | + if ($this->jsonError($data)) {
|
|
| 627 | 633 | throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>'); |
| 628 | 634 | } |
| 629 | 635 | |
@@ -634,10 +640,10 @@ discard block |
||
| 634 | 640 | * @param $data |
| 635 | 641 | * @return bool |
| 636 | 642 | */ |
| 637 | - final protected function jsonError($data) |
|
| 638 | - { |
|
| 643 | + final protected function jsonError($data) |
|
| 644 | + {
|
|
| 639 | 645 | $flag = false; |
| 640 | - if (json_last_error() === JSON_ERROR_NONE && is_object($data) && $data instanceof stdClass) { |
|
| 646 | + if (json_last_error() === JSON_ERROR_NONE && is_object($data) && $data instanceof stdClass) {
|
|
| 641 | 647 | $flag = true; |
| 642 | 648 | } |
| 643 | 649 | |
@@ -650,25 +656,25 @@ discard block |
||
| 650 | 656 | * @param string $sep |
| 651 | 657 | * @return array |
| 652 | 658 | */ |
| 653 | - public function toArray($prefix = '', $suffix = '', $sep = '_') |
|
| 654 | - { |
|
| 659 | + public function toArray($prefix = '', $suffix = '', $sep = '_') |
|
| 660 | + {
|
|
| 655 | 661 | $tpl = ''; |
| 656 | 662 | $plh = '[+key+]'; |
| 657 | - if ($prefix !== '') { |
|
| 663 | + if ($prefix !== '') {
|
|
| 658 | 664 | $tpl = $prefix . $sep; |
| 659 | 665 | } |
| 660 | 666 | $tpl .= $plh; |
| 661 | - if ($suffix !== '') { |
|
| 667 | + if ($suffix !== '') {
|
|
| 662 | 668 | $tpl .= $sep . $suffix; |
| 663 | 669 | } |
| 664 | 670 | $out = array(); |
| 665 | 671 | $fields = $this->field; |
| 666 | 672 | $fields[$this->fieldPKName()] = $this->getID(); |
| 667 | - if ($tpl != $plh) { |
|
| 668 | - foreach ($fields as $key => $value) { |
|
| 673 | + if ($tpl != $plh) {
|
|
| 674 | + foreach ($fields as $key => $value) {
|
|
| 669 | 675 | $out[str_replace($plh, $key, $tpl)] = $value; |
| 670 | 676 | } |
| 671 | - } else { |
|
| 677 | + } else {
|
|
| 672 | 678 | $out = $fields; |
| 673 | 679 | } |
| 674 | 680 | |
@@ -678,8 +684,8 @@ discard block |
||
| 678 | 684 | /** |
| 679 | 685 | * @return string |
| 680 | 686 | */ |
| 681 | - final public function fieldPKName() |
|
| 682 | - { |
|
| 687 | + final public function fieldPKName() |
|
| 688 | + {
|
|
| 683 | 689 | return $this->pkName; |
| 684 | 690 | } |
| 685 | 691 | |
@@ -687,8 +693,8 @@ discard block |
||
| 687 | 693 | * @param $table |
| 688 | 694 | * @return mixed|string |
| 689 | 695 | */ |
| 690 | - final public function makeTable($table) |
|
| 691 | - { |
|
| 696 | + final public function makeTable($table) |
|
| 697 | + {
|
|
| 692 | 698 | //Без использования APIHelpers::getkey(). Иначе getFullTableName будет всегда выполняться |
| 693 | 699 | return (isset($this->_table[$table])) ? $this->_table[$table] : $this->modx->getFullTableName($table); |
| 694 | 700 | } |
@@ -698,14 +704,14 @@ discard block |
||
| 698 | 704 | * @param string $sep |
| 699 | 705 | * @return array|string |
| 700 | 706 | */ |
| 701 | - final public function sanitarIn($data, $sep = ',') |
|
| 702 | - { |
|
| 703 | - if (!is_array($data)) { |
|
| 707 | + final public function sanitarIn($data, $sep = ',') |
|
| 708 | + {
|
|
| 709 | + if (!is_array($data)) {
|
|
| 704 | 710 | $data = explode($sep, $data); |
| 705 | 711 | } |
| 706 | 712 | $out = array(); |
| 707 | - foreach ($data as $item) { |
|
| 708 | - if ($item !== '') { |
|
| 713 | + foreach ($data as $item) {
|
|
| 714 | + if ($item !== '') {
|
|
| 709 | 715 | $out[] = $this->escape($item); |
| 710 | 716 | } |
| 711 | 717 | } |
@@ -720,34 +726,34 @@ discard block |
||
| 720 | 726 | * @param string $PK |
| 721 | 727 | * @return bool |
| 722 | 728 | */ |
| 723 | - public function checkUnique($table, $field, $PK = 'id') |
|
| 724 | - { |
|
| 725 | - if (is_array($field)) { |
|
| 729 | + public function checkUnique($table, $field, $PK = 'id') |
|
| 730 | + {
|
|
| 731 | + if (is_array($field)) {
|
|
| 726 | 732 | $where = array(); |
| 727 | - foreach ($field as $_field) { |
|
| 733 | + foreach ($field as $_field) {
|
|
| 728 | 734 | $val = $this->get($_field); |
| 729 | - if ($val != '') { |
|
| 735 | + if ($val != '') {
|
|
| 730 | 736 | $where[] = "`" . $this->escape($_field) . "` = '" . $this->escape($val) . "'"; |
| 731 | 737 | } |
| 732 | 738 | } |
| 733 | 739 | $where = implode(' AND ', $where); |
| 734 | - } else { |
|
| 740 | + } else {
|
|
| 735 | 741 | $where = ''; |
| 736 | 742 | $val = $this->get($field); |
| 737 | - if ($val != '') { |
|
| 743 | + if ($val != '') {
|
|
| 738 | 744 | $where = "`" . $this->escape($field) . "` = '" . $this->escape($val) . "'"; |
| 739 | 745 | } |
| 740 | 746 | } |
| 741 | 747 | |
| 742 | - if ($where != '') { |
|
| 748 | + if ($where != '') {
|
|
| 743 | 749 | $sql = $this->query("SELECT `" . $this->escape($PK) . "` FROM " . $this->makeTable($table) . " WHERE " . $where); |
| 744 | 750 | $id = $this->modx->db->getValue($sql); |
| 745 | - if (is_null($id) || (!$this->newDoc && $id == $this->getID())) { |
|
| 751 | + if (is_null($id) || (!$this->newDoc && $id == $this->getID())) {
|
|
| 746 | 752 | $flag = true; |
| 747 | - } else { |
|
| 753 | + } else {
|
|
| 748 | 754 | $flag = false; |
| 749 | 755 | } |
| 750 | - } else { |
|
| 756 | + } else {
|
|
| 751 | 757 | $flag = false; |
| 752 | 758 | } |
| 753 | 759 | |
@@ -758,8 +764,8 @@ discard block |
||
| 758 | 764 | * @param array $data |
| 759 | 765 | * @return $this |
| 760 | 766 | */ |
| 761 | - public function create($data = array()) |
|
| 762 | - { |
|
| 767 | + public function create($data = array()) |
|
| 768 | + {
|
|
| 763 | 769 | $this->close(); |
| 764 | 770 | $this->fromArray($data); |
| 765 | 771 | |
@@ -770,8 +776,8 @@ discard block |
||
| 770 | 776 | * @param $id |
| 771 | 777 | * @return $this |
| 772 | 778 | */ |
| 773 | - public function copy($id) |
|
| 774 | - { |
|
| 779 | + public function copy($id) |
|
| 780 | + {
|
|
| 775 | 781 | $this->edit($id)->id = 0; |
| 776 | 782 | $this->newDoc = true; |
| 777 | 783 | $this->store = array(); |
@@ -782,8 +788,8 @@ discard block |
||
| 782 | 788 | /** |
| 783 | 789 | * |
| 784 | 790 | */ |
| 785 | - public function close() |
|
| 786 | - { |
|
| 791 | + public function close() |
|
| 792 | + {
|
|
| 787 | 793 | $this->newDoc = true; |
| 788 | 794 | $this->id = null; |
| 789 | 795 | $this->field = array(); |
@@ -796,8 +802,8 @@ discard block |
||
| 796 | 802 | * @param $key |
| 797 | 803 | * @return bool |
| 798 | 804 | */ |
| 799 | - public function issetField($key) |
|
| 800 | - { |
|
| 805 | + public function issetField($key) |
|
| 806 | + {
|
|
| 801 | 807 | return (is_scalar($key) && array_key_exists($key, $this->default_field)); |
| 802 | 808 | } |
| 803 | 809 | |
@@ -825,8 +831,8 @@ discard block |
||
| 825 | 831 | * @param $data |
| 826 | 832 | * @return array|mixed|string |
| 827 | 833 | */ |
| 828 | - final public function sanitarTag($data) |
|
| 829 | - { |
|
| 834 | + final public function sanitarTag($data) |
|
| 835 | + {
|
|
| 830 | 836 | return parent::sanitarTag($this->modx->stripTags($data)); |
| 831 | 837 | } |
| 832 | 838 | |
@@ -835,17 +841,17 @@ discard block |
||
| 835 | 841 | * @param bool $dmi3yy |
| 836 | 842 | * @return bool |
| 837 | 843 | */ |
| 838 | - final protected function checkVersion($version, $dmi3yy = true) |
|
| 839 | - { |
|
| 844 | + final protected function checkVersion($version, $dmi3yy = true) |
|
| 845 | + {
|
|
| 840 | 846 | $flag = false; |
| 841 | 847 | $currentVer = $this->modx->getVersionData('version'); |
| 842 | - if (is_array($currentVer)) { |
|
| 848 | + if (is_array($currentVer)) {
|
|
| 843 | 849 | $currentVer = APIHelpers::getkey($currentVer, 'version', ''); |
| 844 | 850 | } |
| 845 | 851 | $tmp = substr($currentVer, 0, strlen($version)); |
| 846 | - if (version_compare($tmp, $version, '>=')) { |
|
| 852 | + if (version_compare($tmp, $version, '>=')) {
|
|
| 847 | 853 | $flag = true; |
| 848 | - if ($dmi3yy) { |
|
| 854 | + if ($dmi3yy) {
|
|
| 849 | 855 | $flag = (boolean)preg_match('/^' . $tmp . '(.*)\-d/', $currentVer); |
| 850 | 856 | } |
| 851 | 857 | } |
@@ -857,10 +863,10 @@ discard block |
||
| 857 | 863 | * @param string $name |
| 858 | 864 | * @return bool|mixed |
| 859 | 865 | */ |
| 860 | - protected function eraseField($name) |
|
| 861 | - { |
|
| 866 | + protected function eraseField($name) |
|
| 867 | + {
|
|
| 862 | 868 | $flag = false; |
| 863 | - if (array_key_exists($name, $this->field)) { |
|
| 869 | + if (array_key_exists($name, $this->field)) {
|
|
| 864 | 870 | $flag = $this->field[$name]; |
| 865 | 871 | unset($this->field[$name]); |
| 866 | 872 | } |
@@ -873,8 +879,8 @@ discard block |
||
| 873 | 879 | * @param string $field имя поля |
| 874 | 880 | * @return boolean |
| 875 | 881 | */ |
| 876 | - public function isJsonField($field) |
|
| 877 | - { |
|
| 882 | + public function isJsonField($field) |
|
| 883 | + {
|
|
| 878 | 884 | return (is_scalar($field) && in_array($field, $this->jsonFields)); |
| 879 | 885 | } |
| 880 | 886 | |
@@ -883,9 +889,9 @@ discard block |
||
| 883 | 889 | * @param string $field имя поля |
| 884 | 890 | * @return $this |
| 885 | 891 | */ |
| 886 | - public function markAsDecode($field) |
|
| 887 | - { |
|
| 888 | - if (is_scalar($field)) { |
|
| 892 | + public function markAsDecode($field) |
|
| 893 | + {
|
|
| 894 | + if (is_scalar($field)) {
|
|
| 889 | 895 | $this->_decodedFields->set($field, false); |
| 890 | 896 | } |
| 891 | 897 | |
@@ -897,9 +903,9 @@ discard block |
||
| 897 | 903 | * @param string $field имя поля |
| 898 | 904 | * @return $this |
| 899 | 905 | */ |
| 900 | - public function markAsEncode($field) |
|
| 901 | - { |
|
| 902 | - if (is_scalar($field)) { |
|
| 906 | + public function markAsEncode($field) |
|
| 907 | + {
|
|
| 908 | + if (is_scalar($field)) {
|
|
| 903 | 909 | $this->_decodedFields->set($field, true); |
| 904 | 910 | } |
| 905 | 911 | |
@@ -910,10 +916,10 @@ discard block |
||
| 910 | 916 | * Пометить все поля как запакованные |
| 911 | 917 | * @return $this |
| 912 | 918 | */ |
| 913 | - public function markAllEncode() |
|
| 914 | - { |
|
| 919 | + public function markAllEncode() |
|
| 920 | + {
|
|
| 915 | 921 | $this->_decodedFields->clear(); |
| 916 | - foreach ($this->jsonFields as $field) { |
|
| 922 | + foreach ($this->jsonFields as $field) {
|
|
| 917 | 923 | $this->markAsEncode($field); |
| 918 | 924 | } |
| 919 | 925 | |
@@ -924,10 +930,10 @@ discard block |
||
| 924 | 930 | * Пометить все поля как распакованные |
| 925 | 931 | * @return $this |
| 926 | 932 | */ |
| 927 | - public function markAllDecode() |
|
| 928 | - { |
|
| 933 | + public function markAllDecode() |
|
| 934 | + {
|
|
| 929 | 935 | $this->_decodedFields->clear(); |
| 930 | - foreach ($this->jsonFields as $field) { |
|
| 936 | + foreach ($this->jsonFields as $field) {
|
|
| 931 | 937 | $this->markAsDecode($field); |
| 932 | 938 | } |
| 933 | 939 | |
@@ -938,9 +944,9 @@ discard block |
||
| 938 | 944 | * Получить список не запакованных полей |
| 939 | 945 | * @return DLCollection |
| 940 | 946 | */ |
| 941 | - public function getNoEncodeFields() |
|
| 942 | - { |
|
| 943 | - return $this->_decodedFields->filter(function ($value) { |
|
| 947 | + public function getNoEncodeFields() |
|
| 948 | + {
|
|
| 949 | + return $this->_decodedFields->filter(function ($value) {
|
|
| 944 | 950 | return ($value === false); |
| 945 | 951 | }); |
| 946 | 952 | } |
@@ -949,9 +955,9 @@ discard block |
||
| 949 | 955 | * Получить список не распакованных полей |
| 950 | 956 | * @return DLCollection |
| 951 | 957 | */ |
| 952 | - public function getNoDecodeFields() |
|
| 953 | - { |
|
| 954 | - return $this->_decodedFields->filter(function ($value) { |
|
| 958 | + public function getNoDecodeFields() |
|
| 959 | + {
|
|
| 960 | + return $this->_decodedFields->filter(function ($value) {
|
|
| 955 | 961 | return ($value === true); |
| 956 | 962 | }); |
| 957 | 963 | } |
@@ -961,8 +967,8 @@ discard block |
||
| 961 | 967 | * @param string $field имя поля |
| 962 | 968 | * @return boolean |
| 963 | 969 | */ |
| 964 | - public function isDecodableField($field) |
|
| 965 | - { |
|
| 970 | + public function isDecodableField($field) |
|
| 971 | + {
|
|
| 966 | 972 | $data = $this->get($field); |
| 967 | 973 | |
| 968 | 974 | /** |
@@ -977,8 +983,8 @@ discard block |
||
| 977 | 983 | * @param string $field имя поля |
| 978 | 984 | * @return boolean |
| 979 | 985 | */ |
| 980 | - public function isEncodableField($field) |
|
| 981 | - { |
|
| 986 | + public function isEncodableField($field) |
|
| 987 | + {
|
|
| 982 | 988 | /** |
| 983 | 989 | * Если поле было распаковано ранее и еще не упаковано |
| 984 | 990 | */ |
@@ -991,14 +997,14 @@ discard block |
||
| 991 | 997 | * @param bool $store обновить распакованное поле |
| 992 | 998 | * @return array ассоциативный массив с данными из json строки |
| 993 | 999 | */ |
| 994 | - public function decodeField($field, $store = false) |
|
| 995 | - { |
|
| 1000 | + public function decodeField($field, $store = false) |
|
| 1001 | + {
|
|
| 996 | 1002 | $out = array(); |
| 997 | - if ($this->isDecodableField($field)) { |
|
| 1003 | + if ($this->isDecodableField($field)) {
|
|
| 998 | 1004 | $data = $this->get($field); |
| 999 | 1005 | $out = jsonHelper::jsonDecode($data, array('assoc' => true), true); |
| 1000 | 1006 | } |
| 1001 | - if ($store) { |
|
| 1007 | + if ($store) {
|
|
| 1002 | 1008 | $this->field[$field] = $out; |
| 1003 | 1009 | $this->markAsDecode($field); |
| 1004 | 1010 | } |
@@ -1010,9 +1016,9 @@ discard block |
||
| 1010 | 1016 | * Декодирование всех json полей |
| 1011 | 1017 | * @return $this |
| 1012 | 1018 | */ |
| 1013 | - protected function decodeFields() |
|
| 1014 | - { |
|
| 1015 | - foreach ($this->getNoDecodeFields() as $field => $flag) { |
|
| 1019 | + protected function decodeFields() |
|
| 1020 | + {
|
|
| 1021 | + foreach ($this->getNoDecodeFields() as $field => $flag) {
|
|
| 1016 | 1022 | $this->decodeField($field, true); |
| 1017 | 1023 | } |
| 1018 | 1024 | |
@@ -1025,14 +1031,14 @@ discard block |
||
| 1025 | 1031 | * @param bool $store обновить запакованное поле |
| 1026 | 1032 | * @return string|null json строка |
| 1027 | 1033 | */ |
| 1028 | - public function encodeField($field, $store = false) |
|
| 1029 | - { |
|
| 1034 | + public function encodeField($field, $store = false) |
|
| 1035 | + {
|
|
| 1030 | 1036 | $out = null; |
| 1031 | - if ($this->isEncodableField($field)) { |
|
| 1037 | + if ($this->isEncodableField($field)) {
|
|
| 1032 | 1038 | $data = $this->get($field); |
| 1033 | 1039 | $out = json_encode($data); |
| 1034 | 1040 | } |
| 1035 | - if ($store) { |
|
| 1041 | + if ($store) {
|
|
| 1036 | 1042 | $this->field[$field] = $out; |
| 1037 | 1043 | $this->markAsEncode($field); |
| 1038 | 1044 | } |
@@ -1044,9 +1050,9 @@ discard block |
||
| 1044 | 1050 | * Запаковка всех json полей |
| 1045 | 1051 | * @return $this |
| 1046 | 1052 | */ |
| 1047 | - protected function encodeFields() |
|
| 1048 | - { |
|
| 1049 | - foreach ($this->getNoEncodeFields() as $field => $flag) { |
|
| 1053 | + protected function encodeFields() |
|
| 1054 | + {
|
|
| 1055 | + foreach ($this->getNoEncodeFields() as $field => $flag) {
|
|
| 1050 | 1056 | $this->encodeField($field, true); |
| 1051 | 1057 | } |
| 1052 | 1058 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $this->close(); |
| 123 | 123 | $this->newDoc = false; |
| 124 | 124 | |
| 125 | - if (!$find = $this->findUser($id)) { |
|
| 125 | + if ( ! $find = $this->findUser($id)) { |
|
| 126 | 126 | $this->id = null; |
| 127 | 127 | } else { |
| 128 | 128 | $this->set('editedon', time()); |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public function set($key, $value) |
| 156 | 156 | { |
| 157 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
| 157 | + if (is_scalar($value) && is_scalar($key) && ! empty($key)) { |
|
| 158 | 158 | switch ($key) { |
| 159 | 159 | case 'password': |
| 160 | 160 | $this->givenPassword = $value; |
@@ -207,20 +207,20 @@ discard block |
||
| 207 | 207 | return false; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if (!$this->checkUnique('manager_users', 'username')) { |
|
| 210 | + if ( ! $this->checkUnique('manager_users', 'username')) { |
|
| 211 | 211 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
| 212 | 212 | true) . '</pre>'; |
| 213 | 213 | |
| 214 | 214 | return false; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
| 217 | + if ( ! $this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
| 218 | 218 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
| 219 | 219 | |
| 220 | 220 | return false; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if(!$this->get('role')) { |
|
| 223 | + if ( ! $this->get('role')) { |
|
| 224 | 224 | $this->log['UniqueEmail'] = 'Wrong manager role <pre>' . print_r($this->get('role'), true) . '</pre>'; |
| 225 | 225 | } |
| 226 | 226 | |
@@ -228,13 +228,13 @@ discard block |
||
| 228 | 228 | $fld = $this->toArray(); |
| 229 | 229 | foreach ($this->default_field['user'] as $key => $value) { |
| 230 | 230 | $tmp = $this->get($key); |
| 231 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 231 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 232 | 232 | $this->field[$key] = $value; |
| 233 | 233 | } |
| 234 | 234 | $this->Uset($key, 'user'); |
| 235 | 235 | unset($fld[$key]); |
| 236 | 236 | } |
| 237 | - if (!empty($this->set['user'])) { |
|
| 237 | + if ( ! empty($this->set['user'])) { |
|
| 238 | 238 | if ($this->newDoc) { |
| 239 | 239 | $SQL = "INSERT into {$this->makeTable('manager_users')} SET " . implode(', ', $this->set['user']); |
| 240 | 240 | } else { |
@@ -250,13 +250,13 @@ discard block |
||
| 250 | 250 | |
| 251 | 251 | foreach ($this->default_field['attribute'] as $key => $value) { |
| 252 | 252 | $tmp = $this->get($key); |
| 253 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 253 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 254 | 254 | $this->field[$key] = $value; |
| 255 | 255 | } |
| 256 | 256 | $this->Uset($key, 'attribute'); |
| 257 | 257 | unset($fld[$key]); |
| 258 | 258 | } |
| 259 | - if (!empty($this->set['attribute'])) { |
|
| 259 | + if ( ! empty($this->set['attribute'])) { |
|
| 260 | 260 | if ($this->newDoc) { |
| 261 | 261 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
| 262 | 262 | $SQL = "INSERT into {$this->makeTable('user_attributes')} SET " . implode(', ', |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | } |
| 270 | 270 | unset($fld['id']); |
| 271 | 271 | foreach ($fld as $key => $value) { |
| 272 | - if ($value == '' || !$this->isChanged($key)) { |
|
| 272 | + if ($value == '' || ! $this->isChanged($key)) { |
|
| 273 | 273 | continue; |
| 274 | 274 | } |
| 275 | 275 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}'"); |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | // TODO |
| 283 | - if (!$this->newDoc && $this->givenPassword) { |
|
| 283 | + if ( ! $this->newDoc && $this->givenPassword) { |
|
| 284 | 284 | $this->invokeEvent('OnManagerChangePassword', array( |
| 285 | 285 | 'userObj' => $this, |
| 286 | 286 | 'userid' => $this->id, |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | $b = $tmp->get('blocked'); |
| 387 | 387 | $bu = $tmp->get('blockeduntil'); |
| 388 | 388 | $ba = $tmp->get('blockedafter'); |
| 389 | - $flag = (($b && !$bu && !$ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
| 389 | + $flag = (($b && ! $bu && ! $ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
| 390 | 390 | unset($tmp); |
| 391 | 391 | |
| 392 | 392 | return $flag; |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | |
| 409 | 409 | $flag = $pluginFlag = false; |
| 410 | 410 | if ( |
| 411 | - (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
|
| 411 | + (null !== $tmp->getID()) && ( ! $blocker || ($blocker && ! $tmp->checkBlock($id))) |
|
| 412 | 412 | ) { |
| 413 | 413 | $_password = $tmp->get('password'); |
| 414 | 414 | $eventResult = $this->getInvokeEventResult('OnManagerAuthentication', array( |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | } else { |
| 426 | 426 | $pluginFlag = (bool)$eventResult; |
| 427 | 427 | } |
| 428 | - if (!$pluginFlag) { |
|
| 428 | + if ( ! $pluginFlag) { |
|
| 429 | 429 | $hashType = $this->getPasswordHashType($_password); |
| 430 | 430 | switch ($hashType) { |
| 431 | 431 | case 'phpass': |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | public function logOut($cookieName = 'modx_remember_manager', $fire_events = null) |
| 464 | 464 | { |
| 465 | - if (!$uid = $this->modx->getLoginUserID('mgr')) { |
|
| 465 | + if ( ! $uid = $this->modx->getLoginUserID('mgr')) { |
|
| 466 | 466 | return; |
| 467 | 467 | } |
| 468 | 468 | $params = array( |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | */ |
| 557 | 557 | public function setAutoLoginCookie($cookieName, $remember = true) |
| 558 | 558 | { |
| 559 | - if (!empty($cookieName) && $this->getID()) { |
|
| 559 | + if ( ! empty($cookieName) && $this->getID()) { |
|
| 560 | 560 | $secure = $this->isSecure(); |
| 561 | 561 | $remember = is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember; |
| 562 | 562 | $cookieValue = $this->get('username'); |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | */ |
| 621 | 621 | public function setUserGroups($userID = 0, $groupIds = array()) |
| 622 | 622 | { |
| 623 | - if (!is_array($groupIds)) { |
|
| 623 | + if ( ! is_array($groupIds)) { |
|
| 624 | 624 | return $this; |
| 625 | 625 | } |
| 626 | 626 | if ($this->newDoc && $userID == 0) { |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | foreach ($groupIds as $gid) { |
| 632 | 632 | $this->query("REPLACE INTO {$this->makeTable('member_groups')} (`user_group`, `member`) VALUES ('{$gid}', '{$uid}')"); |
| 633 | 633 | } |
| 634 | - if (!$this->newDoc) { |
|
| 634 | + if ( ! $this->newDoc) { |
|
| 635 | 635 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 636 | 636 | $this->query("DELETE FROM {$this->makeTable('member_groups')} WHERE `member`={$uid} AND `user_group` NOT IN ({$groupIds})"); |
| 637 | 637 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | /** |
| 5 | 5 | * Class modUsers |
| 6 | 6 | */ |
| 7 | -class modManagers extends MODxAPI |
|
| 8 | -{ |
|
| 7 | +class modManagers extends MODxAPI |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var array |
| 11 | 11 | */ |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | * @param bool $debug |
| 60 | 60 | * @throws Exception |
| 61 | 61 | */ |
| 62 | - public function __construct(DocumentParser $modx, $debug = false) |
|
| 63 | - { |
|
| 62 | + public function __construct(DocumentParser $modx, $debug = false) |
|
| 63 | + {
|
|
| 64 | 64 | parent::__construct($modx, $debug); |
| 65 | 65 | $this->modx->loadExtension('phpass'); |
| 66 | 66 | } |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | * @param $key |
| 71 | 71 | * @return bool |
| 72 | 72 | */ |
| 73 | - public function issetField($key) |
|
| 74 | - { |
|
| 73 | + public function issetField($key) |
|
| 74 | + {
|
|
| 75 | 75 | return (array_key_exists($key, $this->default_field['user']) || array_key_exists($key, |
| 76 | 76 | $this->default_field['attribute']) || in_array($key, $this->default_field['hidden'])); |
| 77 | 77 | } |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | * @param string $data |
| 81 | 81 | * @return string|false |
| 82 | 82 | */ |
| 83 | - protected function findUser($data) |
|
| 84 | - { |
|
| 85 | - switch (true) { |
|
| 83 | + protected function findUser($data) |
|
| 84 | + {
|
|
| 85 | + switch (true) {
|
|
| 86 | 86 | case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): |
| 87 | 87 | $find = 'attribute.internalKey'; |
| 88 | 88 | break; |
@@ -103,8 +103,8 @@ discard block |
||
| 103 | 103 | * @param array $data |
| 104 | 104 | * @return $this |
| 105 | 105 | */ |
| 106 | - public function create($data = array()) |
|
| 107 | - { |
|
| 106 | + public function create($data = array()) |
|
| 107 | + {
|
|
| 108 | 108 | parent::create($data); |
| 109 | 109 | $this->set('createdon', time()); |
| 110 | 110 | |
@@ -115,16 +115,16 @@ discard block |
||
| 115 | 115 | * @param $id |
| 116 | 116 | * @return $this |
| 117 | 117 | */ |
| 118 | - public function edit($id) |
|
| 119 | - { |
|
| 118 | + public function edit($id) |
|
| 119 | + {
|
|
| 120 | 120 | $id = is_scalar($id) ? trim($id) : ''; |
| 121 | - if ($this->getID() != $id) { |
|
| 121 | + if ($this->getID() != $id) {
|
|
| 122 | 122 | $this->close(); |
| 123 | 123 | $this->newDoc = false; |
| 124 | 124 | |
| 125 | - if (!$find = $this->findUser($id)) { |
|
| 125 | + if (!$find = $this->findUser($id)) {
|
|
| 126 | 126 | $this->id = null; |
| 127 | - } else { |
|
| 127 | + } else {
|
|
| 128 | 128 | $this->set('editedon', time()); |
| 129 | 129 | $result = $this->query(" |
| 130 | 130 | SELECT * from {$this->makeTable('user_attributes')} as attribute |
@@ -152,10 +152,10 @@ discard block |
||
| 152 | 152 | * @param $value |
| 153 | 153 | * @return $this |
| 154 | 154 | */ |
| 155 | - public function set($key, $value) |
|
| 156 | - { |
|
| 157 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
| 158 | - switch ($key) { |
|
| 155 | + public function set($key, $value) |
|
| 156 | + {
|
|
| 157 | + if (is_scalar($value) && is_scalar($key) && !empty($key)) {
|
|
| 158 | + switch ($key) {
|
|
| 159 | 159 | case 'password': |
| 160 | 160 | $this->givenPassword = $value; |
| 161 | 161 | $value = $this->getPassword($value); |
@@ -179,8 +179,8 @@ discard block |
||
| 179 | 179 | * @param $pass |
| 180 | 180 | * @return string |
| 181 | 181 | */ |
| 182 | - public function getPassword($pass) |
|
| 183 | - { |
|
| 182 | + public function getPassword($pass) |
|
| 183 | + {
|
|
| 184 | 184 | return $this->modx->phpass->HashPassword($pass); |
| 185 | 185 | } |
| 186 | 186 | |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | * @param string $name |
| 189 | 189 | * @return bool |
| 190 | 190 | */ |
| 191 | - public function hasPermission($name) |
|
| 192 | - { |
|
| 191 | + public function hasPermission($name) |
|
| 192 | + {
|
|
| 193 | 193 | return (is_string($name) && $name && isset($this->mgrPermissions[$name])); |
| 194 | 194 | } |
| 195 | 195 | |
@@ -198,89 +198,89 @@ discard block |
||
| 198 | 198 | * @param bool $clearCache |
| 199 | 199 | * @return bool|int|null|void |
| 200 | 200 | */ |
| 201 | - public function save($fire_events = false, $clearCache = false) |
|
| 202 | - { |
|
| 203 | - if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
| 201 | + public function save($fire_events = false, $clearCache = false) |
|
| 202 | + {
|
|
| 203 | + if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') {
|
|
| 204 | 204 | $this->log['EmptyPKField'] = 'Email, username or password is empty <pre>' . print_r($this->toArray(), |
| 205 | 205 | true) . '</pre>'; |
| 206 | 206 | |
| 207 | 207 | return false; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if (!$this->checkUnique('manager_users', 'username')) { |
|
| 210 | + if (!$this->checkUnique('manager_users', 'username')) {
|
|
| 211 | 211 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
| 212 | 212 | true) . '</pre>'; |
| 213 | 213 | |
| 214 | 214 | return false; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
| 217 | + if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) {
|
|
| 218 | 218 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
| 219 | 219 | |
| 220 | 220 | return false; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if(!$this->get('role')) { |
|
| 223 | + if(!$this->get('role')) {
|
|
| 224 | 224 | $this->log['UniqueEmail'] = 'Wrong manager role <pre>' . print_r($this->get('role'), true) . '</pre>'; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | $this->set('sessionid', ''); |
| 228 | 228 | $fld = $this->toArray(); |
| 229 | - foreach ($this->default_field['user'] as $key => $value) { |
|
| 229 | + foreach ($this->default_field['user'] as $key => $value) {
|
|
| 230 | 230 | $tmp = $this->get($key); |
| 231 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 231 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 232 | 232 | $this->field[$key] = $value; |
| 233 | 233 | } |
| 234 | 234 | $this->Uset($key, 'user'); |
| 235 | 235 | unset($fld[$key]); |
| 236 | 236 | } |
| 237 | - if (!empty($this->set['user'])) { |
|
| 238 | - if ($this->newDoc) { |
|
| 237 | + if (!empty($this->set['user'])) {
|
|
| 238 | + if ($this->newDoc) {
|
|
| 239 | 239 | $SQL = "INSERT into {$this->makeTable('manager_users')} SET " . implode(', ', $this->set['user']); |
| 240 | - } else { |
|
| 240 | + } else {
|
|
| 241 | 241 | $SQL = "UPDATE {$this->makeTable('manager_users')} SET " . implode(', ', |
| 242 | 242 | $this->set['user']) . " WHERE id = " . $this->id; |
| 243 | 243 | } |
| 244 | 244 | $this->query($SQL); |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - if ($this->newDoc) { |
|
| 247 | + if ($this->newDoc) {
|
|
| 248 | 248 | $this->id = $this->modx->db->getInsertId(); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - foreach ($this->default_field['attribute'] as $key => $value) { |
|
| 251 | + foreach ($this->default_field['attribute'] as $key => $value) {
|
|
| 252 | 252 | $tmp = $this->get($key); |
| 253 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 253 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 254 | 254 | $this->field[$key] = $value; |
| 255 | 255 | } |
| 256 | 256 | $this->Uset($key, 'attribute'); |
| 257 | 257 | unset($fld[$key]); |
| 258 | 258 | } |
| 259 | - if (!empty($this->set['attribute'])) { |
|
| 260 | - if ($this->newDoc) { |
|
| 259 | + if (!empty($this->set['attribute'])) {
|
|
| 260 | + if ($this->newDoc) {
|
|
| 261 | 261 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
| 262 | 262 | $SQL = "INSERT into {$this->makeTable('user_attributes')} SET " . implode(', ', |
| 263 | 263 | $this->set['attribute']); |
| 264 | - } else { |
|
| 264 | + } else {
|
|
| 265 | 265 | $SQL = "UPDATE {$this->makeTable('user_attributes')} SET " . implode(', ', |
| 266 | 266 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
| 267 | 267 | } |
| 268 | 268 | $this->query($SQL); |
| 269 | 269 | } |
| 270 | 270 | unset($fld['id']); |
| 271 | - foreach ($fld as $key => $value) { |
|
| 272 | - if ($value == '' || !$this->isChanged($key)) { |
|
| 271 | + foreach ($fld as $key => $value) {
|
|
| 272 | + if ($value == '' || !$this->isChanged($key)) {
|
|
| 273 | 273 | continue; |
| 274 | 274 | } |
| 275 | 275 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}'"); |
| 276 | - if ($this->modx->db->getRecordCount($result) > 0) { |
|
| 276 | + if ($this->modx->db->getRecordCount($result) > 0) {
|
|
| 277 | 277 | $this->query("UPDATE {$this->makeTable('user_settings')} SET `setting_value` = '{$value}' WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}';"); |
| 278 | - } else { |
|
| 278 | + } else {
|
|
| 279 | 279 | $this->query("INSERT into {$this->makeTable('user_settings')} SET `user` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | // TODO |
| 283 | - if (!$this->newDoc && $this->givenPassword) { |
|
| 283 | + if (!$this->newDoc && $this->givenPassword) {
|
|
| 284 | 284 | $this->invokeEvent('OnManagerChangePassword', array( |
| 285 | 285 | 'userObj' => $this, |
| 286 | 286 | 'userid' => $this->id, |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | ), $fire_events); |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - if ($this->groupIds) { |
|
| 293 | + if ($this->groupIds) {
|
|
| 294 | 294 | $this->setUserGroups($this->id, $this->groupIds); |
| 295 | 295 | } |
| 296 | 296 | // TODO |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | "userroleid" => $this->get('role') |
| 307 | 307 | ), $fire_events); |
| 308 | 308 | |
| 309 | - if ($clearCache) { |
|
| 309 | + if ($clearCache) {
|
|
| 310 | 310 | $this->clearCache($fire_events); |
| 311 | 311 | } |
| 312 | 312 | |
@@ -318,9 +318,9 @@ discard block |
||
| 318 | 318 | * @param bool $fire_events |
| 319 | 319 | * @return bool|null|void |
| 320 | 320 | */ |
| 321 | - public function delete($ids, $fire_events = false) |
|
| 322 | - { |
|
| 323 | - if ($this->edit($ids)) { |
|
| 321 | + public function delete($ids, $fire_events = false) |
|
| 322 | + {
|
|
| 323 | + if ($this->edit($ids)) {
|
|
| 324 | 324 | $flag = $this->query(" |
| 325 | 325 | DELETE user,attribute FROM {$this->makeTable('user_attributes')} as attribute |
| 326 | 326 | LEFT JOIN {$this->makeTable('manager_users')} as user ON user.id=attribute.internalKey |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | 'username' => $this->get('username'), |
| 335 | 335 | 'timestamp' => time() |
| 336 | 336 | ), $fire_events); |
| 337 | - } else { |
|
| 337 | + } else {
|
|
| 338 | 338 | $flag = false; |
| 339 | 339 | } |
| 340 | 340 | $this->close(); |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | * @param bool $fire_events |
| 350 | 350 | * @return bool |
| 351 | 351 | */ |
| 352 | - public function authUser($id = 0, $fulltime = true, $cookieName = 'modx_remember_manager', $fire_events = false) |
|
| 353 | - { |
|
| 352 | + public function authUser($id = 0, $fulltime = true, $cookieName = 'modx_remember_manager', $fire_events = false) |
|
| 353 | + {
|
|
| 354 | 354 | $flag = false; |
| 355 | - if (null === $this->getID() && $id) { |
|
| 355 | + if (null === $this->getID() && $id) {
|
|
| 356 | 356 | $this->edit($id); |
| 357 | 357 | } |
| 358 | - if (null !== $this->getID()) { |
|
| 358 | + if (null !== $this->getID()) {
|
|
| 359 | 359 | $flag = true; |
| 360 | 360 | $this->save(false); |
| 361 | 361 | $this->SessionHandler('start', $cookieName, $fulltime); |
@@ -375,10 +375,10 @@ discard block |
||
| 375 | 375 | * @param int $id |
| 376 | 376 | * @return bool |
| 377 | 377 | */ |
| 378 | - public function checkBlock($id = 0) |
|
| 379 | - { |
|
| 378 | + public function checkBlock($id = 0) |
|
| 379 | + {
|
|
| 380 | 380 | $tmp = clone $this; |
| 381 | - if ($id && $tmp->getID() != $id) { |
|
| 381 | + if ($id && $tmp->getID() != $id) {
|
|
| 382 | 382 | $tmp->edit($id); |
| 383 | 383 | } |
| 384 | 384 | $now = time(); |
@@ -399,17 +399,17 @@ discard block |
||
| 399 | 399 | * @param bool $fire_events |
| 400 | 400 | * @return bool |
| 401 | 401 | */ |
| 402 | - public function testAuth($id, $password, $blocker, $fire_events = false) |
|
| 403 | - { |
|
| 402 | + public function testAuth($id, $password, $blocker, $fire_events = false) |
|
| 403 | + {
|
|
| 404 | 404 | $tmp = clone $this; |
| 405 | - if ($id && $tmp->getID() != $id) { |
|
| 405 | + if ($id && $tmp->getID() != $id) {
|
|
| 406 | 406 | $tmp->edit($id); |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | $flag = $pluginFlag = false; |
| 410 | 410 | if ( |
| 411 | 411 | (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
| 412 | - ) { |
|
| 412 | + ) {
|
|
| 413 | 413 | $_password = $tmp->get('password'); |
| 414 | 414 | $eventResult = $this->getInvokeEventResult('OnManagerAuthentication', array( |
| 415 | 415 | 'userObj' => $this, |
@@ -418,16 +418,16 @@ discard block |
||
| 418 | 418 | 'userpassword' => $password, |
| 419 | 419 | 'savedpassword' => $_password |
| 420 | 420 | ), $fire_events); |
| 421 | - if (is_array($eventResult)) { |
|
| 422 | - foreach ($eventResult as $result) { |
|
| 421 | + if (is_array($eventResult)) {
|
|
| 422 | + foreach ($eventResult as $result) {
|
|
| 423 | 423 | $pluginFlag = (bool)$result; |
| 424 | 424 | } |
| 425 | - } else { |
|
| 425 | + } else {
|
|
| 426 | 426 | $pluginFlag = (bool)$eventResult; |
| 427 | 427 | } |
| 428 | - if (!$pluginFlag) { |
|
| 428 | + if (!$pluginFlag) {
|
|
| 429 | 429 | $hashType = $this->getPasswordHashType($_password); |
| 430 | - switch ($hashType) { |
|
| 430 | + switch ($hashType) {
|
|
| 431 | 431 | case 'phpass': |
| 432 | 432 | $flag = $this->modx->phpass->CheckPassword($password, $_password); |
| 433 | 433 | break; |
@@ -437,15 +437,15 @@ discard block |
||
| 437 | 437 | case 'v1': |
| 438 | 438 | $algorithm = \APIhelpers::getkey($this->modx->config, 'pwd_hash_algo', 'UNCRYPT'); |
| 439 | 439 | $userAlgorithm = $this->getPasswordHashAlgorithm($_password); |
| 440 | - if ($algorithm !== $userAlgorithm) { |
|
| 440 | + if ($algorithm !== $userAlgorithm) {
|
|
| 441 | 441 | $algorithm = $userAlgorithm; |
| 442 | 442 | } |
| 443 | 443 | $flag = $_password == $this->makeHash($password, $tmp->getID(), $algorithm); |
| 444 | 444 | break; |
| 445 | 445 | } |
| 446 | - if ($flag && $hashType == 'md5' || $hashType == 'v1') { |
|
| 446 | + if ($flag && $hashType == 'md5' || $hashType == 'v1') {
|
|
| 447 | 447 | $tmp->set('password', $password)->save(); |
| 448 | - if ($id == $this->getID()) { |
|
| 448 | + if ($id == $this->getID()) {
|
|
| 449 | 449 | $this->field['password'] = $tmp->get('password'); |
| 450 | 450 | } |
| 451 | 451 | } |
@@ -460,9 +460,9 @@ discard block |
||
| 460 | 460 | * @param string $cookieName |
| 461 | 461 | * @param null $fire_events |
| 462 | 462 | */ |
| 463 | - public function logOut($cookieName = 'modx_remember_manager', $fire_events = null) |
|
| 464 | - { |
|
| 465 | - if (!$uid = $this->modx->getLoginUserID('mgr')) { |
|
| 463 | + public function logOut($cookieName = 'modx_remember_manager', $fire_events = null) |
|
| 464 | + {
|
|
| 465 | + if (!$uid = $this->modx->getLoginUserID('mgr')) {
|
|
| 466 | 466 | return; |
| 467 | 467 | } |
| 468 | 468 | $params = array( |
@@ -489,11 +489,11 @@ discard block |
||
| 489 | 489 | * |
| 490 | 490 | * remeber может быть числом в секундах |
| 491 | 491 | */ |
| 492 | - protected function SessionHandler($directive, $cookieName, $remember = true) |
|
| 493 | - { |
|
| 494 | - switch ($directive) { |
|
| 492 | + protected function SessionHandler($directive, $cookieName, $remember = true) |
|
| 493 | + {
|
|
| 494 | + switch ($directive) {
|
|
| 495 | 495 | case 'start': |
| 496 | - if ($this->getID()) { |
|
| 496 | + if ($this->getID()) {
|
|
| 497 | 497 | $_SESSION['usertype'] = 'manager'; |
| 498 | 498 | $_SESSION['mgrShortname'] = $this->get('username'); |
| 499 | 499 | $_SESSION['mgrFullname'] = $this->get('fullname'); |
@@ -506,13 +506,13 @@ discard block |
||
| 506 | 506 | $_SESSION['mgrRole'] = $this->get('role'); |
| 507 | 507 | $_SESSION['mgrPermissions'] = $this->mgrPermissions; |
| 508 | 508 | $_SESSION['mgrDocgroups'] = $this->getDocumentGroups(); |
| 509 | - if ($remember) { |
|
| 509 | + if ($remember) {
|
|
| 510 | 510 | $this->setAutoLoginCookie($cookieName, $remember); |
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | break; |
| 514 | 514 | case 'destroy': |
| 515 | - if (isset($_SESSION['webValidated'])) { |
|
| 515 | + if (isset($_SESSION['webValidated'])) {
|
|
| 516 | 516 | unset($_SESSION['usertype']); |
| 517 | 517 | unset($_SESSION['webShortname']); |
| 518 | 518 | unset($_SESSION['mgrFullname']); |
@@ -526,8 +526,8 @@ discard block |
||
| 526 | 526 | unset($_SESSION['mgrPermissions']); |
| 527 | 527 | |
| 528 | 528 | setcookie($cookieName, '', time() - 60, '/'); |
| 529 | - } else { |
|
| 530 | - if (isset($_COOKIE[session_name()])) { |
|
| 529 | + } else {
|
|
| 530 | + if (isset($_COOKIE[session_name()])) {
|
|
| 531 | 531 | setcookie(session_name(), '', time() - 60, '/'); |
| 532 | 532 | } |
| 533 | 533 | setcookie($cookieName, '', time() - 60, '/'); |
@@ -542,8 +542,8 @@ discard block |
||
| 542 | 542 | /** |
| 543 | 543 | * @return bool |
| 544 | 544 | */ |
| 545 | - public function isSecure() |
|
| 546 | - { |
|
| 545 | + public function isSecure() |
|
| 546 | + {
|
|
| 547 | 547 | $out = $this->modxConfig('server_protocol') == 'http' ? false : true; |
| 548 | 548 | |
| 549 | 549 | return $out; |
@@ -554,9 +554,9 @@ discard block |
||
| 554 | 554 | * @param bool $remember |
| 555 | 555 | * @return $this |
| 556 | 556 | */ |
| 557 | - public function setAutoLoginCookie($cookieName, $remember = true) |
|
| 558 | - { |
|
| 559 | - if (!empty($cookieName) && $this->getID()) { |
|
| 557 | + public function setAutoLoginCookie($cookieName, $remember = true) |
|
| 558 | + {
|
|
| 559 | + if (!empty($cookieName) && $this->getID()) {
|
|
| 560 | 560 | $secure = $this->isSecure(); |
| 561 | 561 | $remember = is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember; |
| 562 | 562 | $cookieValue = $this->get('username'); |
@@ -571,11 +571,11 @@ discard block |
||
| 571 | 571 | * @param int $userID |
| 572 | 572 | * @return array |
| 573 | 573 | */ |
| 574 | - public function getDocumentGroups($userID = 0) |
|
| 575 | - { |
|
| 574 | + public function getDocumentGroups($userID = 0) |
|
| 575 | + {
|
|
| 576 | 576 | $out = array(); |
| 577 | 577 | $user = $this->switchObject($userID); |
| 578 | - if (null !== $user->getID()) { |
|
| 578 | + if (null !== $user->getID()) {
|
|
| 579 | 579 | $member_groups = $this->modx->getFullTableName('member_groups'); |
| 580 | 580 | $membergroup_access = $this->modx->getFullTableName('membergroup_access'); |
| 581 | 581 | |
@@ -593,18 +593,18 @@ discard block |
||
| 593 | 593 | * @param int $userID |
| 594 | 594 | * @return array |
| 595 | 595 | */ |
| 596 | - public function getUserGroups($userID = 0) |
|
| 597 | - { |
|
| 596 | + public function getUserGroups($userID = 0) |
|
| 597 | + {
|
|
| 598 | 598 | $out = array(); |
| 599 | 599 | $user = $this->switchObject($userID); |
| 600 | - if (null !== $user->getID()) { |
|
| 600 | + if (null !== $user->getID()) {
|
|
| 601 | 601 | $member_groups = $this->makeTable('member_groups'); |
| 602 | 602 | $membergroup_names = $this->makeTable('membergroup_names'); |
| 603 | 603 | |
| 604 | 604 | $rs = $this->query("SELECT `ug`.`user_group`, `ugn`.`name` FROM {$member_groups} as `ug` |
| 605 | 605 | INNER JOIN {$membergroup_names} as `ugn` ON `ugn`.`id`=`ug`.`user_group` |
| 606 | 606 | WHERE `ug`.`member` = " . $user->getID()); |
| 607 | - while ($row = $this->modx->db->getRow($rs)) { |
|
| 607 | + while ($row = $this->modx->db->getRow($rs)) {
|
|
| 608 | 608 | $out[$row['user_group']] = $row['name']; |
| 609 | 609 | } |
| 610 | 610 | } |
@@ -618,20 +618,20 @@ discard block |
||
| 618 | 618 | * @param array $groupIds |
| 619 | 619 | * @return $this |
| 620 | 620 | */ |
| 621 | - public function setUserGroups($userID = 0, $groupIds = array()) |
|
| 622 | - { |
|
| 623 | - if (!is_array($groupIds)) { |
|
| 621 | + public function setUserGroups($userID = 0, $groupIds = array()) |
|
| 622 | + {
|
|
| 623 | + if (!is_array($groupIds)) {
|
|
| 624 | 624 | return $this; |
| 625 | 625 | } |
| 626 | - if ($this->newDoc && $userID == 0) { |
|
| 626 | + if ($this->newDoc && $userID == 0) {
|
|
| 627 | 627 | $this->groupIds = $groupIds; |
| 628 | - } else { |
|
| 628 | + } else {
|
|
| 629 | 629 | $user = $this->switchObject($userID); |
| 630 | - if ($uid = $user->getID()) { |
|
| 631 | - foreach ($groupIds as $gid) { |
|
| 630 | + if ($uid = $user->getID()) {
|
|
| 631 | + foreach ($groupIds as $gid) {
|
|
| 632 | 632 | $this->query("REPLACE INTO {$this->makeTable('member_groups')} (`user_group`, `member`) VALUES ('{$gid}', '{$uid}')"); |
| 633 | 633 | } |
| 634 | - if (!$this->newDoc) { |
|
| 634 | + if (!$this->newDoc) {
|
|
| 635 | 635 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 636 | 636 | $this->query("DELETE FROM {$this->makeTable('member_groups')} WHERE `member`={$uid} AND `user_group` NOT IN ({$groupIds})"); |
| 637 | 637 | } |
@@ -647,14 +647,14 @@ discard block |
||
| 647 | 647 | * @param string $pass |
| 648 | 648 | * @return string |
| 649 | 649 | */ |
| 650 | - public function getPasswordHashType($pass) |
|
| 651 | - { |
|
| 650 | + public function getPasswordHashType($pass) |
|
| 651 | + {
|
|
| 652 | 652 | $out = 'unknown'; |
| 653 | - if (substr($pass, 0, 1) === '$') { |
|
| 653 | + if (substr($pass, 0, 1) === '$') {
|
|
| 654 | 654 | $out = 'phpass'; |
| 655 | - } elseif (strpos($pass, '>') !== false) { |
|
| 655 | + } elseif (strpos($pass, '>') !== false) {
|
|
| 656 | 656 | $out = 'v1'; |
| 657 | - } elseif (strlen($pass) === 32) { |
|
| 657 | + } elseif (strlen($pass) === 32) {
|
|
| 658 | 658 | $out = 'md5'; |
| 659 | 659 | } |
| 660 | 660 | |
@@ -665,8 +665,8 @@ discard block |
||
| 665 | 665 | * @param string $pass |
| 666 | 666 | * @return string |
| 667 | 667 | */ |
| 668 | - public function getPasswordHashAlgorithm($pass) |
|
| 669 | - { |
|
| 668 | + public function getPasswordHashAlgorithm($pass) |
|
| 669 | + {
|
|
| 670 | 670 | $pointer = strpos($pass, '>'); |
| 671 | 671 | $out = $pointer === false ? 'NOSALT' : substr($pass, 0, $pointer); |
| 672 | 672 | |
@@ -679,11 +679,11 @@ discard block |
||
| 679 | 679 | * @param string $algorithm |
| 680 | 680 | * @return string |
| 681 | 681 | */ |
| 682 | - public function makeHash($pass, $seed, $algorithm) |
|
| 683 | - { |
|
| 682 | + public function makeHash($pass, $seed, $algorithm) |
|
| 683 | + {
|
|
| 684 | 684 | $salt = md5($pass . $seed); |
| 685 | 685 | |
| 686 | - switch ($algorithm) { |
|
| 686 | + switch ($algorithm) {
|
|
| 687 | 687 | case 'BLOWFISH_Y': |
| 688 | 688 | $salt = '$2y$07$' . substr($salt, 0, 22); |
| 689 | 689 | break; |
@@ -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 | } |
@@ -506,8 +506,8 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | if ( |
| 508 | 508 | $this->field['parent'] == 0 && |
| 509 | - !$this->modxConfig('udperms_allowroot') && |
|
| 510 | - !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) |
|
| 509 | + ! $this->modxConfig('udperms_allowroot') && |
|
| 510 | + ! ($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) |
|
| 511 | 511 | ) { |
| 512 | 512 | $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off'; |
| 513 | 513 | |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | $fld = $this->encodeFields()->toArray(null, null, null, false); |
| 527 | 527 | foreach ($this->default_field as $key => $value) { |
| 528 | 528 | $tmp = $this->get($key); |
| 529 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 529 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 530 | 530 | if ($tmp == $value) { |
| 531 | 531 | switch ($key) { |
| 532 | 532 | case 'cacheable': |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | $this->field[$key] = $parent; |
| 559 | 559 | $this->Uset($key); |
| 560 | 560 | break; |
| 561 | - case ($key == 'alias_visible' && !$this->checkVersion('1.0.10', true)): |
|
| 561 | + case ($key == 'alias_visible' && ! $this->checkVersion('1.0.10', true)): |
|
| 562 | 562 | $this->eraseField('alias_visible'); |
| 563 | 563 | break; |
| 564 | 564 | default: |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | unset($fld[$key]); |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - if (!empty($this->set)) { |
|
| 570 | + if ( ! empty($this->set)) { |
|
| 571 | 571 | if ($this->newDoc) { |
| 572 | 572 | $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); |
| 573 | 573 | } else { |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | |
| 588 | 588 | $_deleteTVs = $_insertTVs = array(); |
| 589 | 589 | foreach ($fld as $key => $value) { |
| 590 | - if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) { |
|
| 590 | + if (empty($this->tv[$key]) || ! $this->isChanged($key) || ! $this->belongsToTemplate($this->tv[$key])) { |
|
| 591 | 591 | continue; |
| 592 | 592 | } elseif ($value === '') { |
| 593 | 593 | $_deleteTVs[] = $this->tv[$key]; |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | - if (!empty($_insertTVs)) { |
|
| 599 | + if ( ! empty($_insertTVs)) { |
|
| 600 | 600 | $values = array(); |
| 601 | 601 | foreach ($_insertTVs as $id => $value) { |
| 602 | 602 | $values[] = "({$this->id}, {$id}, '{$value}')"; |
@@ -606,12 +606,12 @@ discard block |
||
| 606 | 606 | `value` = VALUES(`value`)"); |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - if (!empty($_deleteTVs)) { |
|
| 609 | + if ( ! empty($_deleteTVs)) { |
|
| 610 | 610 | $ids = implode(',', $_deleteTVs); |
| 611 | 611 | $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})"); |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - if (!isset($this->mode)) { |
|
| 614 | + if ( ! isset($this->mode)) { |
|
| 615 | 615 | $this->mode = $this->newDoc ? "new" : "upd"; |
| 616 | 616 | $this->newDoc = false; |
| 617 | 617 | } |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | $_ids = $this->cleanIDs($ids, ','); |
| 700 | 700 | if (is_array($_ids) && $_ids != array()) { |
| 701 | 701 | $id = $this->sanitarIn($_ids); |
| 702 | - if (!empty($id)) { |
|
| 702 | + if ( ! empty($id)) { |
|
| 703 | 703 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); |
| 704 | 704 | $id = $this->modx->db->getColumn('id', $q); |
| 705 | 705 | if ($depth > 0 || $depth === true) { |
@@ -764,12 +764,12 @@ discard block |
||
| 764 | 764 | $alias = strtolower($alias); |
| 765 | 765 | if ($this->modxConfig('friendly_urls')) { |
| 766 | 766 | $_alias = $this->escape($alias); |
| 767 | - if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
| 767 | + if (( ! $this->modxConfig('allow_duplicate_alias') && ! $this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
| 768 | 768 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1")); |
| 769 | 769 | } else { |
| 770 | 770 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1")); |
| 771 | 771 | } |
| 772 | - if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) { |
|
| 772 | + if (($flag && $this->newDoc) || ( ! $this->newDoc && $flag && $this->id != $flag)) { |
|
| 773 | 773 | $suffix = substr($alias, -2); |
| 774 | 774 | if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { |
| 775 | 775 | $suffix = (int)$tmp[1] + 1; |
@@ -844,7 +844,7 @@ discard block |
||
| 844 | 844 | */ |
| 845 | 845 | protected function loadTVDefault(array $tvId = array()) |
| 846 | 846 | { |
| 847 | - if (is_array($tvId) && !empty($tvId)) { |
|
| 847 | + if (is_array($tvId) && ! empty($tvId)) { |
|
| 848 | 848 | $tbl_site_tmplvars = $this->makeTable('site_tmplvars'); |
| 849 | 849 | $fields = 'id,name,default_text as value,display,display_params,type'; |
| 850 | 850 | $implodeTvId = implode(',', $tvId); |
@@ -866,11 +866,11 @@ discard block |
||
| 866 | 866 | */ |
| 867 | 867 | public function setTemplate($tpl) |
| 868 | 868 | { |
| 869 | - if (!is_numeric($tpl) || $tpl != (int)$tpl) { |
|
| 869 | + if ( ! is_numeric($tpl) || $tpl != (int)$tpl) { |
|
| 870 | 870 | if (is_scalar($tpl)) { |
| 871 | 871 | $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'"; |
| 872 | 872 | $rs = $this->query($sql); |
| 873 | - if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
| 873 | + if ( ! $rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
| 874 | 874 | throw new Exception("Template {$tpl} is not exists"); |
| 875 | 875 | } |
| 876 | 876 | $tpl = $this->modx->db->getValue($rs); |
@@ -931,7 +931,7 @@ discard block |
||
| 931 | 931 | $template = $this->modxConfig('default_template'); |
| 932 | 932 | switch ($this->modxConfig('auto_template_logic')) { |
| 933 | 933 | case 'sibling': |
| 934 | - if (!$parent) { |
|
| 934 | + if ( ! $parent) { |
|
| 935 | 935 | $site_start = $this->modxConfig('site_start'); |
| 936 | 936 | $where = "sc.isfolder=0 AND sc.id!={$site_start}"; |
| 937 | 937 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1); |
@@ -1083,7 +1083,7 @@ discard block |
||
| 1083 | 1083 | */ |
| 1084 | 1084 | public function setDocumentGroups($docId = 0, $groupIds = array()) |
| 1085 | 1085 | { |
| 1086 | - if (!is_array($groupIds)) return $this; |
|
| 1086 | + if ( ! is_array($groupIds)) return $this; |
|
| 1087 | 1087 | if ($this->newDoc && $docId == 0) { |
| 1088 | 1088 | $this->groupIds = $groupIds; |
| 1089 | 1089 | } else { |
@@ -1092,7 +1092,7 @@ discard block |
||
| 1092 | 1092 | foreach ($groupIds as $gid) { |
| 1093 | 1093 | $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')"); |
| 1094 | 1094 | } |
| 1095 | - if (!$this->newDoc) { |
|
| 1095 | + if ( ! $this->newDoc) { |
|
| 1096 | 1096 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 1097 | 1097 | $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})"); |
| 1098 | 1098 | } |
@@ -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,11 +438,11 @@ discard block |
||
| 438 | 438 | * @param array $data |
| 439 | 439 | * @return $this |
| 440 | 440 | */ |
| 441 | - public function create($data = array()) |
|
| 442 | - { |
|
| 441 | + public function create($data = array()) |
|
| 442 | + {
|
|
| 443 | 443 | $this->close(); |
| 444 | 444 | $fld = array(); |
| 445 | - foreach ($this->tvd as $name => $tv) { |
|
| 445 | + foreach ($this->tvd as $name => $tv) {
|
|
| 446 | 446 | $fld[$name] = $tv['value']; |
| 447 | 447 | }; |
| 448 | 448 | $this->store($fld); |
@@ -460,10 +460,10 @@ discard block |
||
| 460 | 460 | * @param $id |
| 461 | 461 | * @return $this |
| 462 | 462 | */ |
| 463 | - public function edit($id) |
|
| 464 | - { |
|
| 463 | + public function edit($id) |
|
| 464 | + {
|
|
| 465 | 465 | $id = is_scalar($id) ? trim($id) : ''; |
| 466 | - if ($this->getID() != $id) { |
|
| 466 | + if ($this->getID() != $id) {
|
|
| 467 | 467 | $this->close(); |
| 468 | 468 | $this->markAllEncode(); |
| 469 | 469 | $this->newDoc = false; |
@@ -471,12 +471,12 @@ discard block |
||
| 471 | 471 | $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id); |
| 472 | 472 | $this->fromArray($this->modx->db->getRow($result)); |
| 473 | 473 | $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id); |
| 474 | - while ($row = $this->modx->db->getRow($result)) { |
|
| 474 | + while ($row = $this->modx->db->getRow($result)) {
|
|
| 475 | 475 | $this->field[$this->tvid[$row['tmplvarid']]] = $row['value']; |
| 476 | 476 | } |
| 477 | - if (empty($this->field['id'])) { |
|
| 477 | + if (empty($this->field['id'])) {
|
|
| 478 | 478 | $this->id = null; |
| 479 | - } else { |
|
| 479 | + } else {
|
|
| 480 | 480 | $this->id = $this->field['id']; |
| 481 | 481 | $this->set('editedby', null)->touch(); |
| 482 | 482 | $this->decodeFields(); |
@@ -493,10 +493,10 @@ discard block |
||
| 493 | 493 | * @param bool $clearCache |
| 494 | 494 | * @return bool|null |
| 495 | 495 | */ |
| 496 | - public function save($fire_events = false, $clearCache = false) |
|
| 497 | - { |
|
| 496 | + public function save($fire_events = false, $clearCache = false) |
|
| 497 | + {
|
|
| 498 | 498 | $parent = null; |
| 499 | - if ($this->field['pagetitle'] == '') { |
|
| 499 | + if ($this->field['pagetitle'] == '') {
|
|
| 500 | 500 | $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>'; |
| 501 | 501 | |
| 502 | 502 | return false; |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | $this->field['parent'] == 0 && |
| 509 | 509 | !$this->modxConfig('udperms_allowroot') && |
| 510 | 510 | !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) |
| 511 | - ) { |
|
| 511 | + ) {
|
|
| 512 | 512 | $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off'; |
| 513 | 513 | |
| 514 | 514 | return false; |
@@ -524,11 +524,11 @@ discard block |
||
| 524 | 524 | ), $fire_events); |
| 525 | 525 | |
| 526 | 526 | $fld = $this->encodeFields()->toArray(null, null, null, false); |
| 527 | - foreach ($this->default_field as $key => $value) { |
|
| 527 | + foreach ($this->default_field as $key => $value) {
|
|
| 528 | 528 | $tmp = $this->get($key); |
| 529 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 530 | - if ($tmp == $value) { |
|
| 531 | - switch ($key) { |
|
| 529 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 530 | + if ($tmp == $value) {
|
|
| 531 | + switch ($key) {
|
|
| 532 | 532 | case 'cacheable': |
| 533 | 533 | $value = $this->modxConfig('cache_default'); |
| 534 | 534 | break; |
@@ -548,11 +548,11 @@ discard block |
||
| 548 | 548 | } |
| 549 | 549 | $this->field[$key] = $value; |
| 550 | 550 | } |
| 551 | - switch (true) { |
|
| 551 | + switch (true) {
|
|
| 552 | 552 | case $key == 'parent': |
| 553 | 553 | $parent = (int)$this->get($key); |
| 554 | 554 | $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'"); |
| 555 | - if ($this->modx->db->getValue($q) != 1) { |
|
| 555 | + if ($this->modx->db->getValue($q) != 1) {
|
|
| 556 | 556 | $parent = 0; |
| 557 | 557 | } |
| 558 | 558 | $this->field[$key] = $parent; |
@@ -567,38 +567,38 @@ discard block |
||
| 567 | 567 | unset($fld[$key]); |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - if (!empty($this->set)) { |
|
| 571 | - if ($this->newDoc) { |
|
| 570 | + if (!empty($this->set)) {
|
|
| 571 | + if ($this->newDoc) {
|
|
| 572 | 572 | $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); |
| 573 | - } else { |
|
| 573 | + } else {
|
|
| 574 | 574 | $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ', |
| 575 | 575 | $this->set) . " WHERE `id` = " . $this->id; |
| 576 | 576 | } |
| 577 | 577 | $this->query($SQL); |
| 578 | 578 | |
| 579 | - if ($this->newDoc) { |
|
| 579 | + if ($this->newDoc) {
|
|
| 580 | 580 | $this->id = $this->modx->db->getInsertId(); |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - if ($parent > 0) { |
|
| 583 | + if ($parent > 0) {
|
|
| 584 | 584 | $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'"); |
| 585 | 585 | } |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | $_deleteTVs = $_insertTVs = array(); |
| 589 | - foreach ($fld as $key => $value) { |
|
| 590 | - if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) { |
|
| 589 | + foreach ($fld as $key => $value) {
|
|
| 590 | + if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) {
|
|
| 591 | 591 | continue; |
| 592 | - } elseif ($value === '') { |
|
| 592 | + } elseif ($value === '') {
|
|
| 593 | 593 | $_deleteTVs[] = $this->tv[$key]; |
| 594 | - } else { |
|
| 594 | + } else {
|
|
| 595 | 595 | $_insertTVs[$this->tv[$key]] = $this->escape($value); |
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | - if (!empty($_insertTVs)) { |
|
| 599 | + if (!empty($_insertTVs)) {
|
|
| 600 | 600 | $values = array(); |
| 601 | - foreach ($_insertTVs as $id => $value) { |
|
| 601 | + foreach ($_insertTVs as $id => $value) {
|
|
| 602 | 602 | $values[] = "({$this->id}, {$id}, '{$value}')"; |
| 603 | 603 | } |
| 604 | 604 | $values = implode(',', $values); |
@@ -606,17 +606,19 @@ discard block |
||
| 606 | 606 | `value` = VALUES(`value`)"); |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - if (!empty($_deleteTVs)) { |
|
| 609 | + if (!empty($_deleteTVs)) {
|
|
| 610 | 610 | $ids = implode(',', $_deleteTVs); |
| 611 | 611 | $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})"); |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - if (!isset($this->mode)) { |
|
| 614 | + if (!isset($this->mode)) {
|
|
| 615 | 615 | $this->mode = $this->newDoc ? "new" : "upd"; |
| 616 | 616 | $this->newDoc = false; |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | - if ($this->groupIds) $this->setDocumentGroups($this->id, $this->groupIds); |
|
| 619 | + if ($this->groupIds) {
|
|
| 620 | + $this->setDocumentGroups($this->id, $this->groupIds); |
|
| 621 | + } |
|
| 620 | 622 | $this->invokeEvent('OnDocFormSave', array( |
| 621 | 623 | 'mode' => $this->mode, |
| 622 | 624 | 'id' => $this->id, |
@@ -624,7 +626,7 @@ discard block |
||
| 624 | 626 | 'docObj' => $this |
| 625 | 627 | ), $fire_events); |
| 626 | 628 | |
| 627 | - if ($clearCache) { |
|
| 629 | + if ($clearCache) {
|
|
| 628 | 630 | $this->clearCache($fire_events); |
| 629 | 631 | } |
| 630 | 632 | $this->decodeFields(); |
@@ -636,7 +638,8 @@ discard block |
||
| 636 | 638 | * @param $tvId |
| 637 | 639 | * @return bool |
| 638 | 640 | */ |
| 639 | - protected function belongsToTemplate($tvId) { |
|
| 641 | + protected function belongsToTemplate($tvId) |
|
| 642 | + {
|
|
| 640 | 643 | $template = $this->get('template'); |
| 641 | 644 | |
| 642 | 645 | return isset($this->tvTpl[$template]) && in_array($tvId, $this->tvTpl[$template]); |
@@ -647,16 +650,16 @@ discard block |
||
| 647 | 650 | * @return $this |
| 648 | 651 | * @throws Exception |
| 649 | 652 | */ |
| 650 | - public function toTrash($ids) |
|
| 651 | - { |
|
| 653 | + public function toTrash($ids) |
|
| 654 | + {
|
|
| 652 | 655 | $ignore = $this->systemID(); |
| 653 | 656 | $_ids = $this->cleanIDs($ids, ',', $ignore); |
| 654 | - if (is_array($_ids) && $_ids != array()) { |
|
| 657 | + if (is_array($_ids) && $_ids != array()) {
|
|
| 655 | 658 | $id = $this->sanitarIn($_ids); |
| 656 | 659 | $uid = (int)$this->modx->getLoginUserId(); |
| 657 | 660 | $deletedon = time() + $this->modxConfig('server_offset_time'); |
| 658 | 661 | $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})"); |
| 659 | - } else { |
|
| 662 | + } else {
|
|
| 660 | 663 | throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, |
| 661 | 664 | 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
| 662 | 665 | } |
@@ -668,11 +671,11 @@ discard block |
||
| 668 | 671 | * @param bool $fire_events |
| 669 | 672 | * @return $this |
| 670 | 673 | */ |
| 671 | - public function clearTrash($fire_events = false) |
|
| 672 | - { |
|
| 674 | + public function clearTrash($fire_events = false) |
|
| 675 | + {
|
|
| 673 | 676 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'"); |
| 674 | 677 | $_ids = $this->modx->db->getColumn('id', $q); |
| 675 | - if (is_array($_ids) && $_ids != array()) { |
|
| 678 | + if (is_array($_ids) && $_ids != array()) {
|
|
| 676 | 679 | $this->invokeEvent('OnBeforeEmptyTrash', array( |
| 677 | 680 | "ids" => $_ids |
| 678 | 681 | ), $fire_events); |
@@ -694,15 +697,15 @@ discard block |
||
| 694 | 697 | * @param int|bool $depth |
| 695 | 698 | * @return array |
| 696 | 699 | */ |
| 697 | - public function children($ids, $depth) |
|
| 698 | - { |
|
| 700 | + public function children($ids, $depth) |
|
| 701 | + {
|
|
| 699 | 702 | $_ids = $this->cleanIDs($ids, ','); |
| 700 | - if (is_array($_ids) && $_ids != array()) { |
|
| 703 | + if (is_array($_ids) && $_ids != array()) {
|
|
| 701 | 704 | $id = $this->sanitarIn($_ids); |
| 702 | - if (!empty($id)) { |
|
| 705 | + if (!empty($id)) {
|
|
| 703 | 706 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); |
| 704 | 707 | $id = $this->modx->db->getColumn('id', $q); |
| 705 | - if ($depth > 0 || $depth === true) { |
|
| 708 | + if ($depth > 0 || $depth === true) {
|
|
| 706 | 709 | $id = $this->children($id, is_bool($depth) ? $depth : ($depth - 1)); |
| 707 | 710 | } |
| 708 | 711 | $_ids = array_merge($_ids, $id); |
@@ -718,8 +721,8 @@ discard block |
||
| 718 | 721 | * @return $this |
| 719 | 722 | * @throws Exception |
| 720 | 723 | */ |
| 721 | - public function delete($ids, $fire_events = false) |
|
| 722 | - { |
|
| 724 | + public function delete($ids, $fire_events = false) |
|
| 725 | + {
|
|
| 723 | 726 | $ids = $this->children($ids, true); |
| 724 | 727 | $_ids = $this->cleanIDs($ids, ',', $this->systemID()); |
| 725 | 728 | $this->invokeEvent('OnBeforeDocFormDelete', array( |
@@ -736,8 +739,8 @@ discard block |
||
| 736 | 739 | /** |
| 737 | 740 | * @return array |
| 738 | 741 | */ |
| 739 | - private function systemID() |
|
| 740 | - { |
|
| 742 | + private function systemID() |
|
| 743 | + {
|
|
| 741 | 744 | $ignore = array( |
| 742 | 745 | 0, //empty document |
| 743 | 746 | (int)$this->modxConfig('site_start'), |
@@ -747,7 +750,7 @@ discard block |
||
| 747 | 750 | ); |
| 748 | 751 | $data = $this->query("SELECT DISTINCT setting_value FROM {$this->makeTable('web_user_settings')} WHERE `setting_name`='login_home' AND `setting_value`!=''"); |
| 749 | 752 | $data = $this->modx->db->makeArray($data); |
| 750 | - foreach ($data as $item) { |
|
| 753 | + foreach ($data as $item) {
|
|
| 751 | 754 | $ignore[] = (int)$item['setting_value']; |
| 752 | 755 | } |
| 753 | 756 | |
@@ -759,22 +762,22 @@ discard block |
||
| 759 | 762 | * @param $alias |
| 760 | 763 | * @return string |
| 761 | 764 | */ |
| 762 | - protected function checkAlias($alias) |
|
| 763 | - { |
|
| 765 | + protected function checkAlias($alias) |
|
| 766 | + {
|
|
| 764 | 767 | $alias = strtolower($alias); |
| 765 | - if ($this->modxConfig('friendly_urls')) { |
|
| 768 | + if ($this->modxConfig('friendly_urls')) {
|
|
| 766 | 769 | $_alias = $this->escape($alias); |
| 767 | - if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
| 770 | + if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
|
|
| 768 | 771 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1")); |
| 769 | - } else { |
|
| 772 | + } else {
|
|
| 770 | 773 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1")); |
| 771 | 774 | } |
| 772 | - if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) { |
|
| 775 | + if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
|
|
| 773 | 776 | $suffix = substr($alias, -2); |
| 774 | - if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { |
|
| 777 | + if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
|
|
| 775 | 778 | $suffix = (int)$tmp[1] + 1; |
| 776 | 779 | $alias = substr($alias, 0, -2) . '-' . $suffix; |
| 777 | - } else { |
|
| 780 | + } else {
|
|
| 778 | 781 | $alias .= '-2'; |
| 779 | 782 | } |
| 780 | 783 | $alias = $this->checkAlias($alias); |
@@ -788,8 +791,8 @@ discard block |
||
| 788 | 791 | * @param $key |
| 789 | 792 | * @return bool |
| 790 | 793 | */ |
| 791 | - public function issetField($key) |
|
| 792 | - { |
|
| 794 | + public function issetField($key) |
|
| 795 | + {
|
|
| 793 | 796 | return (array_key_exists($key, $this->default_field) || array_key_exists($key, $this->tv)); |
| 794 | 797 | } |
| 795 | 798 | |
@@ -797,11 +800,11 @@ discard block |
||
| 797 | 800 | * @param bool $reload |
| 798 | 801 | * @return $this |
| 799 | 802 | */ |
| 800 | - protected function get_TV($reload = false) |
|
| 801 | - { |
|
| 802 | - if (empty($this->modx->_TVnames) || $reload) { |
|
| 803 | + protected function get_TV($reload = false) |
|
| 804 | + {
|
|
| 805 | + if (empty($this->modx->_TVnames) || $reload) {
|
|
| 803 | 806 | $result = $this->query('SELECT `id`,`name`,`type` FROM ' . $this->makeTable('site_tmplvars')); |
| 804 | - while ($row = $this->modx->db->GetRow($result)) { |
|
| 807 | + while ($row = $this->modx->db->GetRow($result)) {
|
|
| 805 | 808 | $this->modx->_TVnames[$row['name']] = array( |
| 806 | 809 | "id" => $row['id'], |
| 807 | 810 | "type" => $row['type'] |
@@ -810,14 +813,16 @@ discard block |
||
| 810 | 813 | } |
| 811 | 814 | $arrayTypes = array('checkbox', 'listbox-multiple'); |
| 812 | 815 | $arrayTVs = array(); |
| 813 | - foreach ($this->modx->_TVnames as $name => $data) { |
|
| 816 | + foreach ($this->modx->_TVnames as $name => $data) {
|
|
| 814 | 817 | $this->tvid[$data['id']] = $name; |
| 815 | 818 | $this->tv[$name] = $data['id']; |
| 816 | - if (in_array($data['type'], $arrayTypes)) { |
|
| 819 | + if (in_array($data['type'], $arrayTypes)) {
|
|
| 817 | 820 | $arrayTVs[] = $name; |
| 818 | 821 | } |
| 819 | 822 | } |
| 820 | - if (empty($this->tvaFields)) $this->tvaFields = $arrayTVs; |
|
| 823 | + if (empty($this->tvaFields)) {
|
|
| 824 | + $this->tvaFields = $arrayTVs; |
|
| 825 | + } |
|
| 821 | 826 | $this->loadTVTemplate()->loadTVDefault(array_values($this->tv)); |
| 822 | 827 | |
| 823 | 828 | return $this; |
@@ -826,12 +831,12 @@ discard block |
||
| 826 | 831 | /** |
| 827 | 832 | * @return $this |
| 828 | 833 | */ |
| 829 | - protected function loadTVTemplate() |
|
| 830 | - { |
|
| 834 | + protected function loadTVTemplate() |
|
| 835 | + {
|
|
| 831 | 836 | $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates')); |
| 832 | 837 | $q = $this->modx->db->makeArray($q); |
| 833 | 838 | $this->tvTpl = array(); |
| 834 | - foreach ($q as $item) { |
|
| 839 | + foreach ($q as $item) {
|
|
| 835 | 840 | $this->tvTpl[$item['templateid']][] = $item['tmplvarid']; |
| 836 | 841 | } |
| 837 | 842 | |
@@ -842,16 +847,16 @@ discard block |
||
| 842 | 847 | * @param array $tvId |
| 843 | 848 | * @return $this |
| 844 | 849 | */ |
| 845 | - protected function loadTVDefault(array $tvId = array()) |
|
| 846 | - { |
|
| 847 | - if (is_array($tvId) && !empty($tvId)) { |
|
| 850 | + protected function loadTVDefault(array $tvId = array()) |
|
| 851 | + {
|
|
| 852 | + if (is_array($tvId) && !empty($tvId)) {
|
|
| 848 | 853 | $tbl_site_tmplvars = $this->makeTable('site_tmplvars'); |
| 849 | 854 | $fields = 'id,name,default_text as value,display,display_params,type'; |
| 850 | 855 | $implodeTvId = implode(',', $tvId); |
| 851 | 856 | $rs = $this->query("SELECT {$fields} FROM {$tbl_site_tmplvars} WHERE id IN({$implodeTvId})"); |
| 852 | 857 | $rows = $this->modx->db->makeArray($rs); |
| 853 | 858 | $this->tvd = array(); |
| 854 | - foreach ($rows as $item) { |
|
| 859 | + foreach ($rows as $item) {
|
|
| 855 | 860 | $this->tvd[$item['name']] = $item; |
| 856 | 861 | } |
| 857 | 862 | } |
@@ -864,17 +869,17 @@ discard block |
||
| 864 | 869 | * @return int |
| 865 | 870 | * @throws Exception |
| 866 | 871 | */ |
| 867 | - public function setTemplate($tpl) |
|
| 868 | - { |
|
| 869 | - if (!is_numeric($tpl) || $tpl != (int)$tpl) { |
|
| 870 | - if (is_scalar($tpl)) { |
|
| 872 | + public function setTemplate($tpl) |
|
| 873 | + {
|
|
| 874 | + if (!is_numeric($tpl) || $tpl != (int)$tpl) {
|
|
| 875 | + if (is_scalar($tpl)) {
|
|
| 871 | 876 | $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'"; |
| 872 | 877 | $rs = $this->query($sql); |
| 873 | - if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
| 878 | + if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
|
|
| 874 | 879 | throw new Exception("Template {$tpl} is not exists"); |
| 875 | 880 | } |
| 876 | 881 | $tpl = $this->modx->db->getValue($rs); |
| 877 | - } else { |
|
| 882 | + } else {
|
|
| 878 | 883 | throw new Exception("Invalid template name: " . print_r($tpl, 1)); |
| 879 | 884 | } |
| 880 | 885 | } |
@@ -885,14 +890,14 @@ discard block |
||
| 885 | 890 | /** |
| 886 | 891 | * @return string |
| 887 | 892 | */ |
| 888 | - protected function getAlias() |
|
| 889 | - { |
|
| 890 | - if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') { |
|
| 893 | + protected function getAlias() |
|
| 894 | + {
|
|
| 895 | + if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') {
|
|
| 891 | 896 | $alias = strtr($this->get('pagetitle'), $this->table); |
| 892 | - } else { |
|
| 893 | - if ($this->get('alias') != '') { |
|
| 897 | + } else {
|
|
| 898 | + if ($this->get('alias') != '') {
|
|
| 894 | 899 | $alias = $this->get('alias'); |
| 895 | - } else { |
|
| 900 | + } else {
|
|
| 896 | 901 | $alias = ''; |
| 897 | 902 | } |
| 898 | 903 | } |
@@ -909,10 +914,10 @@ discard block |
||
| 909 | 914 | * |
| 910 | 915 | * Пересчет menuindex по полю таблицы site_content |
| 911 | 916 | */ |
| 912 | - public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc') |
|
| 913 | - { |
|
| 917 | + public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc') |
|
| 918 | + {
|
|
| 914 | 919 | $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc'; |
| 915 | - if (is_integer($parent) && $criteria !== '') { |
|
| 920 | + if (is_integer($parent) && $criteria !== '') {
|
|
| 916 | 921 | $this->query("SET @index := 0"); |
| 917 | 922 | $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}"); |
| 918 | 923 | } |
@@ -925,37 +930,37 @@ discard block |
||
| 925 | 930 | * |
| 926 | 931 | * @return $this |
| 927 | 932 | */ |
| 928 | - public function setDefaultTemplate() |
|
| 929 | - { |
|
| 933 | + public function setDefaultTemplate() |
|
| 934 | + {
|
|
| 930 | 935 | $parent = $this->get('parent'); |
| 931 | 936 | $template = $this->modxConfig('default_template'); |
| 932 | - switch ($this->modxConfig('auto_template_logic')) { |
|
| 937 | + switch ($this->modxConfig('auto_template_logic')) {
|
|
| 933 | 938 | case 'sibling': |
| 934 | - if (!$parent) { |
|
| 939 | + if (!$parent) {
|
|
| 935 | 940 | $site_start = $this->modxConfig('site_start'); |
| 936 | 941 | $where = "sc.isfolder=0 AND sc.id!={$site_start}"; |
| 937 | 942 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1); |
| 938 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
| 943 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
|
|
| 939 | 944 | $template = $sibl[0]['template']; |
| 940 | 945 | } |
| 941 | - } else { |
|
| 946 | + } else {
|
|
| 942 | 947 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', 'isfolder=0', 'menuindex', |
| 943 | 948 | 'ASC', 1); |
| 944 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
| 949 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
|
|
| 945 | 950 | $template = $sibl[0]['template']; |
| 946 | - } else { |
|
| 951 | + } else {
|
|
| 947 | 952 | $sibl = $this->modx->getDocumentChildren($parent, 0, 0, 'template', 'isfolder=0', 'menuindex', |
| 948 | 953 | 'ASC', 1); |
| 949 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
| 954 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
|
|
| 950 | 955 | $template = $sibl[0]['template']; |
| 951 | 956 | } |
| 952 | 957 | } |
| 953 | 958 | } |
| 954 | 959 | break; |
| 955 | 960 | case 'parent': |
| 956 | - if ($parent) { |
|
| 961 | + if ($parent) {
|
|
| 957 | 962 | $_parent = $this->modx->getPageInfo($parent, 0, 'template'); |
| 958 | - if (isset($_parent['template'])) { |
|
| 963 | + if (isset($_parent['template'])) {
|
|
| 959 | 964 | $template = $_parent['template']; |
| 960 | 965 | } |
| 961 | 966 | } |
@@ -972,18 +977,18 @@ discard block |
||
| 972 | 977 | * @param bool $store обновить распакованное поле |
| 973 | 978 | * @return array ассоциативный массив с данными из json строки |
| 974 | 979 | */ |
| 975 | - public function decodeField($field, $store = false) |
|
| 976 | - { |
|
| 980 | + public function decodeField($field, $store = false) |
|
| 981 | + {
|
|
| 977 | 982 | $out = array(); |
| 978 | - if ($this->isDecodableField($field)) { |
|
| 983 | + if ($this->isDecodableField($field)) {
|
|
| 979 | 984 | $data = $this->get($field); |
| 980 | - if ($this->isTVarrayField($field)) { |
|
| 985 | + if ($this->isTVarrayField($field)) {
|
|
| 981 | 986 | $out = explode('||', $data); |
| 982 | - } else { |
|
| 987 | + } else {
|
|
| 983 | 988 | $out = jsonHelper::jsonDecode($data, array('assoc' => true), true); |
| 984 | 989 | } |
| 985 | 990 | } |
| 986 | - if ($store) { |
|
| 991 | + if ($store) {
|
|
| 987 | 992 | $this->field[$field] = $out; |
| 988 | 993 | $this->markAsDecode($field); |
| 989 | 994 | } |
@@ -997,18 +1002,18 @@ discard block |
||
| 997 | 1002 | * @param bool $store обновить запакованное поле |
| 998 | 1003 | * @return string|null json строка |
| 999 | 1004 | */ |
| 1000 | - public function encodeField($field, $store = false) |
|
| 1001 | - { |
|
| 1005 | + public function encodeField($field, $store = false) |
|
| 1006 | + {
|
|
| 1002 | 1007 | $out = null; |
| 1003 | - if ($this->isEncodableField($field)) { |
|
| 1008 | + if ($this->isEncodableField($field)) {
|
|
| 1004 | 1009 | $data = $this->get($field); |
| 1005 | - if ($this->isTVarrayField($field)) { |
|
| 1010 | + if ($this->isTVarrayField($field)) {
|
|
| 1006 | 1011 | $out = is_array($data) ? implode('||', $data) : $data; |
| 1007 | - } else { |
|
| 1012 | + } else {
|
|
| 1008 | 1013 | $out = json_encode($data); |
| 1009 | 1014 | } |
| 1010 | 1015 | } |
| 1011 | - if ($store) { |
|
| 1016 | + if ($store) {
|
|
| 1012 | 1017 | $this->field[$field] = $out; |
| 1013 | 1018 | $this->markAsEncode($field); |
| 1014 | 1019 | } |
@@ -1021,8 +1026,8 @@ discard block |
||
| 1021 | 1026 | * @param string $field имя поля |
| 1022 | 1027 | * @return boolean |
| 1023 | 1028 | */ |
| 1024 | - public function isTVarrayField($field) |
|
| 1025 | - { |
|
| 1029 | + public function isTVarrayField($field) |
|
| 1030 | + {
|
|
| 1026 | 1031 | return (is_scalar($field) && in_array($field, $this->tvaFields)); |
| 1027 | 1032 | } |
| 1028 | 1033 | |
@@ -1030,10 +1035,10 @@ discard block |
||
| 1030 | 1035 | * Пометить все поля как запакованные |
| 1031 | 1036 | * @return $this |
| 1032 | 1037 | */ |
| 1033 | - public function markAllEncode() |
|
| 1034 | - { |
|
| 1038 | + public function markAllEncode() |
|
| 1039 | + {
|
|
| 1035 | 1040 | parent::markAllEncode(); |
| 1036 | - foreach ($this->tvaFields as $field) { |
|
| 1041 | + foreach ($this->tvaFields as $field) {
|
|
| 1037 | 1042 | $this->markAsEncode($field); |
| 1038 | 1043 | } |
| 1039 | 1044 | |
@@ -1044,10 +1049,10 @@ discard block |
||
| 1044 | 1049 | * Пометить все поля как распакованные |
| 1045 | 1050 | * @return $this |
| 1046 | 1051 | */ |
| 1047 | - public function markAllDecode() |
|
| 1048 | - { |
|
| 1052 | + public function markAllDecode() |
|
| 1053 | + {
|
|
| 1049 | 1054 | parent::markAllDecode(); |
| 1050 | - foreach ($this->tvaFields as $field) { |
|
| 1055 | + foreach ($this->tvaFields as $field) {
|
|
| 1051 | 1056 | $this->markAsDecode($field); |
| 1052 | 1057 | } |
| 1053 | 1058 | |
@@ -1057,16 +1062,17 @@ discard block |
||
| 1057 | 1062 | /** |
| 1058 | 1063 | * @param int $docId |
| 1059 | 1064 | */ |
| 1060 | - public function getDocumentGroups($docId = 0) { |
|
| 1065 | + public function getDocumentGroups($docId = 0) |
|
| 1066 | + {
|
|
| 1061 | 1067 | $out = array(); |
| 1062 | 1068 | $doc = $this->switchObject($docId); |
| 1063 | - if (null !== $doc->getID()) { |
|
| 1069 | + if (null !== $doc->getID()) {
|
|
| 1064 | 1070 | $doc_groups = $this->makeTable('document_groups'); |
| 1065 | 1071 | $docgroup_names = $this->makeTable('documentgroup_names'); |
| 1066 | 1072 | |
| 1067 | 1073 | $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` |
| 1068 | 1074 | WHERE `dg`.`document` = " . $doc->getID()); |
| 1069 | - while ($row = $this->modx->db->getRow($rs)) { |
|
| 1075 | + while ($row = $this->modx->db->getRow($rs)) {
|
|
| 1070 | 1076 | $out[$row['document_group']] = $row['name']; |
| 1071 | 1077 | } |
| 1072 | 1078 | |
@@ -1081,18 +1087,20 @@ discard block |
||
| 1081 | 1087 | * @param array $groupIds |
| 1082 | 1088 | * @return $this |
| 1083 | 1089 | */ |
| 1084 | - public function setDocumentGroups($docId = 0, $groupIds = array()) |
|
| 1085 | - { |
|
| 1086 | - if (!is_array($groupIds)) return $this; |
|
| 1087 | - if ($this->newDoc && $docId == 0) { |
|
| 1090 | + public function setDocumentGroups($docId = 0, $groupIds = array()) |
|
| 1091 | + {
|
|
| 1092 | + if (!is_array($groupIds)) {
|
|
| 1093 | + return $this; |
|
| 1094 | + } |
|
| 1095 | + if ($this->newDoc && $docId == 0) {
|
|
| 1088 | 1096 | $this->groupIds = $groupIds; |
| 1089 | - } else { |
|
| 1097 | + } else {
|
|
| 1090 | 1098 | $doc = $this->switchObject($docId); |
| 1091 | - if ($id = $doc->getID()) { |
|
| 1092 | - foreach ($groupIds as $gid) { |
|
| 1099 | + if ($id = $doc->getID()) {
|
|
| 1100 | + foreach ($groupIds as $gid) {
|
|
| 1093 | 1101 | $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')"); |
| 1094 | 1102 | } |
| 1095 | - if (!$this->newDoc) { |
|
| 1103 | + if (!$this->newDoc) {
|
|
| 1096 | 1104 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 1097 | 1105 | $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})"); |
| 1098 | 1106 | } |