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