@@ -212,7 +212,7 @@ |
||
212 | 212 | /** |
213 | 213 | * Reduce the collection to a single value. |
214 | 214 | * |
215 | - * @param callable $callback |
|
215 | + * @param Closure $callback |
|
216 | 216 | * @param mixed $initial |
217 | 217 | * @return mixed |
218 | 218 | */ |
@@ -9,10 +9,10 @@ discard block |
||
9 | 9 | class Collection implements \Countable, \IteratorAggregate, \ArrayAccess{ |
10 | 10 | protected $data = array(); |
11 | 11 | |
12 | - public function __construct(array $data = array()){ |
|
12 | + public function __construct(array $data = array()) { |
|
13 | 13 | $this->data = $data; |
14 | 14 | } |
15 | - public function create(array $data = array()){ |
|
15 | + public function create(array $data = array()) { |
|
16 | 16 | return new static($data); |
17 | 17 | } |
18 | 18 | public function getIterator() |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | public function forAll(Closure $p) |
39 | 39 | { |
40 | 40 | foreach ($this->data as $key => $element) { |
41 | - if ( ! $p($key, $element)) { |
|
41 | + if (!$p($key, $element)) { |
|
42 | 42 | return false; |
43 | 43 | } |
44 | 44 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | { |
65 | 65 | return empty($this->data); |
66 | 66 | } |
67 | - public function clear(){ |
|
67 | + public function clear() { |
|
68 | 68 | $this->data = array(); |
69 | 69 | return $this; |
70 | 70 | } |
@@ -72,20 +72,20 @@ discard block |
||
72 | 72 | $this->data[] = $value; |
73 | 73 | return $this; |
74 | 74 | } |
75 | - public function add($data, $id = null){ |
|
76 | - if((is_int($id) || is_string($id)) && $id !== ''){ |
|
75 | + public function add($data, $id = null) { |
|
76 | + if ((is_int($id) || is_string($id)) && $id !== '') { |
|
77 | 77 | $this->data[$id] = $data; |
78 | - }else{ |
|
78 | + } else { |
|
79 | 79 | $this->append($data); |
80 | 80 | } |
81 | 81 | return $this; |
82 | 82 | } |
83 | - public function count(){ |
|
83 | + public function count() { |
|
84 | 84 | return count($this->data); |
85 | 85 | } |
86 | - public function get($id){ |
|
86 | + public function get($id) { |
|
87 | 87 | $out = null; |
88 | - if(is_scalar($id) && $id!=='' && $this->containsKey($id)){ |
|
88 | + if (is_scalar($id) && $id !== '' && $this->containsKey($id)) { |
|
89 | 89 | $out = $this->data[$id]; |
90 | 90 | } |
91 | 91 | return $out; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | { |
109 | 109 | return key($this->data); |
110 | 110 | } |
111 | - public function prev(){ |
|
111 | + public function prev() { |
|
112 | 112 | return prev($this->data); |
113 | 113 | } |
114 | 114 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | |
125 | 125 | public function remove($key) |
126 | 126 | { |
127 | - if ( ! isset($this->data[$key]) && ! array_key_exists($key, $this->data)) { |
|
127 | + if (!isset($this->data[$key]) && !array_key_exists($key, $this->data)) { |
|
128 | 128 | return null; |
129 | 129 | } |
130 | 130 | $removed = $this->data[$key]; |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | { |
147 | 147 | return $this->containsKey($offset); |
148 | 148 | } |
149 | - public function dump(){ |
|
149 | + public function dump() { |
|
150 | 150 | return var_dump($this->data); |
151 | 151 | } |
152 | - public function show(){ |
|
152 | + public function show() { |
|
153 | 153 | print_r($this->data); |
154 | 154 | } |
155 | 155 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | |
161 | 161 | public function offsetSet($offset, $value) |
162 | 162 | { |
163 | - if ( ! isset($offset)) { |
|
163 | + if (!isset($offset)) { |
|
164 | 164 | return $this->add($value); |
165 | 165 | } |
166 | 166 | $this->set($offset, $value); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | return array_values($this->data); |
206 | 206 | } |
207 | 207 | |
208 | - public function toArray(){ |
|
208 | + public function toArray() { |
|
209 | 209 | return $this->data; |
210 | 210 | } |
211 | 211 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | return $this; |
271 | 271 | } |
272 | 272 | |
273 | - public function reindex(){ |
|
273 | + public function reindex() { |
|
274 | 274 | $this->data = array_values($this->data); |
275 | 275 | return $this; |
276 | 276 | } |
@@ -41,7 +41,7 @@ |
||
41 | 41 | $text = mb_substr($text, 0, $len+1, $encoding); |
42 | 42 | if(mb_substr($text, -1, null, $encoding) == ' '){ |
43 | 43 | $out = trim($text); |
44 | - }else{ |
|
44 | + } else{ |
|
45 | 45 | $out = mb_substr($text, 0, mb_strripos($text, ' ', null, $encoding), $encoding); |
46 | 46 | } |
47 | 47 | return preg_replace("/(([\.,\-:!?;\s])|(&\w+;))+$/ui", "", $out); |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | - * @param $data |
|
51 | - * @return bool|string |
|
50 | + * @param string $data |
|
51 | + * @return string|false |
|
52 | 52 | */ |
53 | 53 | protected function findUser($data) |
54 | 54 | { |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | - * @param $key |
|
101 | + * @param string $key |
|
102 | 102 | * @param $value |
103 | 103 | * @return $this |
104 | 104 | */ |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | /** |
303 | 303 | * @param $id |
304 | 304 | * @param $password |
305 | - * @param $blocker |
|
305 | + * @param boolean $blocker |
|
306 | 306 | * @param null $fire_events |
307 | 307 | * @return bool |
308 | 308 | */ |
@@ -384,7 +384,8 @@ discard block |
||
384 | 384 | * Starts the user session on login success. Destroys session on error or logout. |
385 | 385 | * |
386 | 386 | * @param string $directive ('start' or 'destroy') |
387 | - * @return void |
|
387 | + * @param string $cookieName |
|
388 | + * @return modUsers |
|
388 | 389 | * @author Raymond Irving |
389 | 390 | * @author Scotty Delicious |
390 | 391 | * |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | 'gender' => null, |
29 | 29 | 'country' => null, |
30 | 30 | 'state' => null, |
31 | - 'city' => null, |
|
31 | + 'city' => null, |
|
32 | 32 | 'zip' => null, |
33 | 33 | 'fax' => null, |
34 | 34 | 'photo' => null, |
@@ -211,8 +211,8 @@ discard block |
||
211 | 211 | $this->invokeEvent('OnWebChangePassword',array( |
212 | 212 | 'userObj' => $this, |
213 | 213 | 'userid' => $this->id, |
214 | - 'user' => $this->toArray(), |
|
215 | - 'userpassword' => $this->givenPassword, |
|
214 | + 'user' => $this->toArray(), |
|
215 | + 'userpassword' => $this->givenPassword, |
|
216 | 216 | 'internalKey' => $this->id, |
217 | 217 | 'username' => $this->get('username') |
218 | 218 | ),$fire_events); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | if (!$find = $this->findUser($id)) { |
83 | 83 | $this->id = null; |
84 | - }else { |
|
84 | + } else { |
|
85 | 85 | $result = $this->query(" |
86 | 86 | SELECT * from {$this->makeTable('web_user_attributes')} as attribute |
87 | 87 | LEFT JOIN {$this->makeTable('web_users')} as user ON user.id=attribute.internalKey |
@@ -133,17 +133,17 @@ discard block |
||
133 | 133 | public function save($fire_events = null, $clearCache = false) |
134 | 134 | { |
135 | 135 | if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
136 | - $this->log['EmptyPKField'] = 'Email, username or password is empty <pre>' . print_r($this->toArray(), true) . '</pre>'; |
|
136 | + $this->log['EmptyPKField'] = 'Email, username or password is empty <pre>'.print_r($this->toArray(), true).'</pre>'; |
|
137 | 137 | return false; |
138 | 138 | } |
139 | 139 | |
140 | 140 | if (!$this->checkUnique('web_users', 'username')) { |
141 | - $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), true) . '</pre>'; |
|
141 | + $this->log['UniqueUsername'] = 'username not unique <pre>'.print_r($this->get('username'), true).'</pre>'; |
|
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | |
145 | 145 | if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
146 | - $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
|
146 | + $this->log['UniqueEmail'] = 'Email not unique <pre>'.print_r($this->get('email'), true).'</pre>'; |
|
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | $fld = $this->toArray(); |
156 | 156 | foreach ($this->default_field['user'] as $key => $value) { |
157 | 157 | $tmp = $this->get($key); |
158 | - if ($this->newDoc && ( !is_int($tmp) && $tmp=='')) { |
|
159 | - if($tmp == $value){ |
|
158 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
159 | + if ($tmp == $value) { |
|
160 | 160 | //take default value from global config |
161 | 161 | } |
162 | 162 | $this->field[$key] = $value; |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | } |
167 | 167 | if (!empty($this->set['user'])) { |
168 | 168 | if ($this->newDoc) { |
169 | - $SQL = "INSERT into {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']); |
|
169 | + $SQL = "INSERT into {$this->makeTable('web_users')} SET ".implode(', ', $this->set['user']); |
|
170 | 170 | } else { |
171 | - $SQL = "UPDATE {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']) . " WHERE id = " . $this->id; |
|
171 | + $SQL = "UPDATE {$this->makeTable('web_users')} SET ".implode(', ', $this->set['user'])." WHERE id = ".$this->id; |
|
172 | 172 | } |
173 | 173 | $this->query($SQL); |
174 | 174 | } |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | |
180 | 180 | foreach ($this->default_field['attribute'] as $key => $value) { |
181 | 181 | $tmp = $this->get($key); |
182 | - if ($this->newDoc && ( !is_int($tmp) && $tmp=='')) { |
|
183 | - if($tmp == $value){ |
|
182 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
183 | + if ($tmp == $value) { |
|
184 | 184 | //take default value from global config |
185 | 185 | } |
186 | 186 | $this->field[$key] = $value; |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | if (!empty($this->set['attribute'])) { |
192 | 192 | if ($this->newDoc) { |
193 | 193 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
194 | - $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET " . implode(', ', $this->set['attribute']); |
|
194 | + $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET ".implode(', ', $this->set['attribute']); |
|
195 | 195 | } else { |
196 | - $SQL = "UPDATE {$this->makeTable('web_user_attributes')} SET " . implode(', ', $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
|
196 | + $SQL = "UPDATE {$this->makeTable('web_user_attributes')} SET ".implode(', ', $this->set['attribute'])." WHERE internalKey = ".$this->getID(); |
|
197 | 197 | } |
198 | 198 | $this->query($SQL); |
199 | 199 | } |
@@ -208,21 +208,21 @@ discard block |
||
208 | 208 | } |
209 | 209 | } |
210 | 210 | if (!$this->newDoc && $this->givenPassword) { |
211 | - $this->invokeEvent('OnWebChangePassword',array( |
|
211 | + $this->invokeEvent('OnWebChangePassword', array( |
|
212 | 212 | 'userObj' => $this, |
213 | 213 | 'userid' => $this->id, |
214 | 214 | 'user' => $this->toArray(), |
215 | 215 | 'userpassword' => $this->givenPassword, |
216 | 216 | 'internalKey' => $this->id, |
217 | 217 | 'username' => $this->get('username') |
218 | - ),$fire_events); |
|
218 | + ), $fire_events); |
|
219 | 219 | } |
220 | - $this->invokeEvent('OnWebSaveUser',array ( |
|
220 | + $this->invokeEvent('OnWebSaveUser', array( |
|
221 | 221 | 'userObj' => $this, |
222 | 222 | 'mode' => $this->newDoc ? "new" : "upd", |
223 | 223 | 'id' => $this->id, |
224 | 224 | 'user' => $this->toArray() |
225 | - ),$fire_events); |
|
225 | + ), $fire_events); |
|
226 | 226 | |
227 | 227 | if ($clearCache) { |
228 | 228 | $this->clearCache($fire_events); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | 'username' => $this->get('username'), |
275 | 275 | 'userpassword' => $this->givenPassword, |
276 | 276 | 'rememberme' => $fulltime |
277 | - ),$fire_events); |
|
277 | + ), $fire_events); |
|
278 | 278 | } |
279 | 279 | return $flag; |
280 | 280 | } |
@@ -317,13 +317,13 @@ discard block |
||
317 | 317 | if ( |
318 | 318 | ($tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
319 | 319 | ) { |
320 | - $eventResult = $this->getInvokeEventResult('OnWebAuthentication',array( |
|
320 | + $eventResult = $this->getInvokeEventResult('OnWebAuthentication', array( |
|
321 | 321 | 'userObj' => $this, |
322 | 322 | 'userid' => $tmp->getID(), |
323 | 323 | 'username' => $tmp->get('username'), |
324 | 324 | 'userpassword' => $password, |
325 | 325 | 'savedpassword' => $tmp->get('password') |
326 | - ),$fire_events); |
|
326 | + ), $fire_events); |
|
327 | 327 | if (is_array($eventResult)) { |
328 | 328 | foreach ($eventResult as $result) { |
329 | 329 | $pluginFlag = (bool)$result; |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | $cookie = explode('|', $_COOKIE[$cookieName], 2); |
352 | 352 | if (isset($cookie[0], $cookie[1]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) { |
353 | 353 | $this->close(); |
354 | - $q = $this->modx->db->query("SELECT id FROM " . $this->makeTable('web_users') . " WHERE md5(username)='{$this->escape($cookie[0])}'"); |
|
354 | + $q = $this->modx->db->query("SELECT id FROM ".$this->makeTable('web_users')." WHERE md5(username)='{$this->escape($cookie[0])}'"); |
|
355 | 355 | $id = $this->modx->db->getValue($q); |
356 | 356 | if ($this->edit($id) && $this->getID() && $this->get('password') == $cookie[1] && $this->testAuth($this->getID(), $cookie[1], true)) { |
357 | 357 | $flag = $this->authUser($this->getID(), $fulltime, $cookieName, $fire_events); |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | $_SESSION['webUserGroupNames'] = $this->getUserGroups(); |
411 | 411 | $_SESSION['webDocgroups'] = $this->getDocumentGroups(); |
412 | 412 | if ($remember) { |
413 | - $cookieValue = md5($this->get('username')) . '|' . $this->get('password'); |
|
413 | + $cookieValue = md5($this->get('username')).'|'.$this->get('password'); |
|
414 | 414 | $cookieExpires = time() + (is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember); |
415 | 415 | setcookie($cookieName, $cookieValue, $cookieExpires, '/'); |
416 | 416 | } |
@@ -452,17 +452,17 @@ discard block |
||
452 | 452 | * @param int $userID |
453 | 453 | * @return array |
454 | 454 | */ |
455 | - public function getDocumentGroups($userID = 0){ |
|
455 | + public function getDocumentGroups($userID = 0) { |
|
456 | 456 | $out = array(); |
457 | 457 | $user = $this->switchObject($userID); |
458 | - if($user->getID()){ |
|
458 | + if ($user->getID()) { |
|
459 | 459 | $web_groups = $this->modx->getFullTableName('web_groups'); |
460 | 460 | $webgroup_access = $this->modx->getFullTableName('webgroup_access'); |
461 | 461 | |
462 | 462 | $sql = "SELECT `uga`.`documentgroup` FROM {$web_groups} as `ug` |
463 | 463 | INNER JOIN {$webgroup_access} as `uga` ON `uga`.`webgroup`=`ug`.`webgroup` |
464 | 464 | WHERE `ug`.`webuser` = ".$user->getID(); |
465 | - $out = $this->modx->db->getColumn('documentgroup',$this->query($sql)); |
|
465 | + $out = $this->modx->db->getColumn('documentgroup', $this->query($sql)); |
|
466 | 466 | |
467 | 467 | } |
468 | 468 | unset($user); |
@@ -473,17 +473,17 @@ discard block |
||
473 | 473 | * @param int $userID |
474 | 474 | * @return array |
475 | 475 | */ |
476 | - public function getUserGroups($userID = 0){ |
|
476 | + public function getUserGroups($userID = 0) { |
|
477 | 477 | $out = array(); |
478 | 478 | $user = $this->switchObject($userID); |
479 | - if($user->getID()){ |
|
479 | + if ($user->getID()) { |
|
480 | 480 | $web_groups = $this->makeTable('web_groups'); |
481 | 481 | $webgroup_names = $this->makeTable('webgroup_names'); |
482 | 482 | |
483 | 483 | $sql = "SELECT `ugn`.`name` FROM {$web_groups} as `ug` |
484 | 484 | INNER JOIN {$webgroup_names} as `ugn` ON `ugn`.`id`=`ug`.`webgroup` |
485 | 485 | WHERE `ug`.`webuser` = ".$user->getID(); |
486 | - $out = $this->modx->db->getColumn('name',$this->query($sql)); |
|
486 | + $out = $this->modx->db->getColumn('name', $this->query($sql)); |
|
487 | 487 | } |
488 | 488 | unset($user); |
489 | 489 | return $out; |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | |
492 | 492 | public function setUserGroups($userID = 0, $groupIds = array()) { |
493 | 493 | $user = $this->switchObject($userID); |
494 | - if(($uid = $user->getID()) && is_array($groupIds)) { |
|
494 | + if (($uid = $user->getID()) && is_array($groupIds)) { |
|
495 | 495 | foreach ($groupIds as $gid) { |
496 | 496 | $this->query("REPLACE INTO {$this->makeTable('web_groups')} (`webgroup`, `webuser`) VALUES ('{$gid}', '{$uid}')"); |
497 | 497 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | if (!$find = $this->findUser($id)) { |
83 | 83 | $this->id = null; |
84 | - }else { |
|
84 | + } else { |
|
85 | 85 | $result = $this->query(" |
86 | 86 | SELECT * from {$this->makeTable('web_user_attributes')} as attribute |
87 | 87 | LEFT JOIN {$this->makeTable('web_users')} as user ON user.id=attribute.internalKey |
@@ -199,7 +199,9 @@ discard block |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | foreach ($fld as $key => $value) { |
202 | - if ($value == '') continue; |
|
202 | + if ($value == '') { |
|
203 | + continue; |
|
204 | + } |
|
203 | 205 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}'"); |
204 | 206 | if ($this->modx->db->getRecordCount($result) > 0) { |
205 | 207 | $this->query("UPDATE {$this->makeTable('web_user_settings')} SET `setting_value` = '{$value}' WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}';"); |
@@ -263,7 +265,9 @@ discard block |
||
263 | 265 | public function authUser($id = 0, $fulltime = true, $cookieName = 'WebLoginPE', $fire_events = null) |
264 | 266 | { |
265 | 267 | $flag = false; |
266 | - if (!$this->getID() && $id) $this->edit($id); |
|
268 | + if (!$this->getID() && $id) { |
|
269 | + $this->edit($id); |
|
270 | + } |
|
267 | 271 | if ($this->getID()) { |
268 | 272 | //$this->logOut($cookieName); |
269 | 273 | $flag = true; |
@@ -368,7 +372,9 @@ discard block |
||
368 | 372 | */ |
369 | 373 | public function logOut($cookieName = 'WebLoginPE', $fire_events = null) |
370 | 374 | { |
371 | - if (!$uid = $this->modx->getLoginUserID('web')) return; |
|
375 | + if (!$uid = $this->modx->getLoginUserID('web')) { |
|
376 | + return; |
|
377 | + } |
|
372 | 378 | $params = array( |
373 | 379 | 'username' => $_SESSION['webShortname'], |
374 | 380 | 'internalKey' => $uid, |
@@ -6,7 +6,10 @@ |
||
6 | 6 | include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLTemplate.class.php'); |
7 | 7 | include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLCollection.class.php'); |
8 | 8 | |
9 | -use APIHelpers, DocumentParser, DLCollection, DLTemplate; |
|
9 | +use APIHelpers; |
|
10 | +use DocumentParser; |
|
11 | +use DLCollection; |
|
12 | +use DLTemplate; |
|
10 | 13 | use Helpers\FS; |
11 | 14 | |
12 | 15 | class Actions{ |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | class Actions{ |
13 | 13 | protected $modx = null; |
14 | 14 | public $userObj = null; |
15 | - /** |
|
16 | - * @var DLCollection |
|
17 | - */ |
|
15 | + /** |
|
16 | + * @var DLCollection |
|
17 | + */ |
|
18 | 18 | public $url; |
19 | 19 | protected static $lang = null; |
20 | 20 | protected static $langDic = array(); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | protected static $instance; |
25 | 25 | |
26 | - protected $config = array(); |
|
26 | + protected $config = array(); |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * gets the instance via lazy initialization (created on first usage) |
@@ -50,15 +50,15 @@ discard block |
||
50 | 50 | private function __construct(DocumentParser $modx, $userClass, $debug) |
51 | 51 | { |
52 | 52 | $this->modx = $modx; |
53 | - $this->userObj = new $userClass($this->modx, $debug); |
|
54 | - $this->url = new DLCollection($this->modx); |
|
53 | + $this->userObj = new $userClass($this->modx, $debug); |
|
54 | + $this->url = new DLCollection($this->modx); |
|
55 | 55 | |
56 | - $site_url = $this->modx->getConfig('site_url'); |
|
57 | - $site_start = $this->modx->getConfig('site_start', 1); |
|
58 | - $error_page = $this->modx->getConfig('error_page', $site_start); |
|
59 | - $unauthorized_page = $this->modx->getConfig('unauthorized_page', $error_page); |
|
56 | + $site_url = $this->modx->getConfig('site_url'); |
|
57 | + $site_start = $this->modx->getConfig('site_start', 1); |
|
58 | + $error_page = $this->modx->getConfig('error_page', $site_start); |
|
59 | + $unauthorized_page = $this->modx->getConfig('unauthorized_page', $error_page); |
|
60 | 60 | |
61 | - $this->config = compact('site_url', 'site_start', 'error_page', 'unauthorized_page'); |
|
61 | + $this->config = compact('site_url', 'site_start', 'error_page', 'unauthorized_page'); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -85,47 +85,47 @@ discard block |
||
85 | 85 | * Сброс авторизации и обновление страницы |
86 | 86 | */ |
87 | 87 | public function logout($params){ |
88 | - $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
89 | - if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){ |
|
90 | - $userID = $this->UserID('web'); |
|
91 | - if($userID){ |
|
92 | - $this->userObj->edit($userID); |
|
93 | - if($this->userObj->getID()){ |
|
94 | - $this->modx->invokeEvent("OnBeforeWebLogout", array( |
|
95 | - "userid" => $this->userObj->getID(), |
|
96 | - "username" => $this->userObj->get('username') |
|
97 | - )); |
|
98 | - } |
|
99 | - $this->userObj->logOut(); |
|
100 | - if($this->userObj->getID()){ |
|
101 | - $this->modx->invokeEvent("OnWebLogout", array( |
|
102 | - "userid" => $this->userObj->getID(), |
|
103 | - "username" => $this->userObj->get('username') |
|
104 | - )); |
|
105 | - } |
|
106 | - |
|
107 | - $go = APIHelpers::getkey($params, 'url', ''); |
|
108 | - if(empty($go)){ |
|
109 | - $go = str_replace( |
|
110 | - array("?".$LogoutName, "&".$LogoutName), |
|
111 | - array("", ""), |
|
112 | - $_SERVER['REQUEST_URI'] |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - $start = $this->makeUrl($this->config['site_start']); |
|
117 | - if($start == $go){ |
|
118 | - $go = $this->config['site_url']; |
|
119 | - }else{ |
|
120 | - $go = $this->config['site_url'].ltrim($go, '/'); |
|
121 | - } |
|
122 | - $this->moveTo(array('url' => $go)); |
|
123 | - }else{ |
|
124 | - //Если юзер не авторизован, то показываем ему 404 ошибку |
|
125 | - $this->modx->sendErrorPage(); |
|
126 | - } |
|
127 | - } |
|
128 | - return true; |
|
88 | + $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
89 | + if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){ |
|
90 | + $userID = $this->UserID('web'); |
|
91 | + if($userID){ |
|
92 | + $this->userObj->edit($userID); |
|
93 | + if($this->userObj->getID()){ |
|
94 | + $this->modx->invokeEvent("OnBeforeWebLogout", array( |
|
95 | + "userid" => $this->userObj->getID(), |
|
96 | + "username" => $this->userObj->get('username') |
|
97 | + )); |
|
98 | + } |
|
99 | + $this->userObj->logOut(); |
|
100 | + if($this->userObj->getID()){ |
|
101 | + $this->modx->invokeEvent("OnWebLogout", array( |
|
102 | + "userid" => $this->userObj->getID(), |
|
103 | + "username" => $this->userObj->get('username') |
|
104 | + )); |
|
105 | + } |
|
106 | + |
|
107 | + $go = APIHelpers::getkey($params, 'url', ''); |
|
108 | + if(empty($go)){ |
|
109 | + $go = str_replace( |
|
110 | + array("?".$LogoutName, "&".$LogoutName), |
|
111 | + array("", ""), |
|
112 | + $_SERVER['REQUEST_URI'] |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + $start = $this->makeUrl($this->config['site_start']); |
|
117 | + if($start == $go){ |
|
118 | + $go = $this->config['site_url']; |
|
119 | + }else{ |
|
120 | + $go = $this->config['site_url'].ltrim($go, '/'); |
|
121 | + } |
|
122 | + $this->moveTo(array('url' => $go)); |
|
123 | + }else{ |
|
124 | + //Если юзер не авторизован, то показываем ему 404 ошибку |
|
125 | + $this->modx->sendErrorPage(); |
|
126 | + } |
|
127 | + } |
|
128 | + return true; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -133,14 +133,14 @@ discard block |
||
133 | 133 | * @return string |
134 | 134 | */ |
135 | 135 | public function logoutUrl($params){ |
136 | - $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
137 | - $request = parse_url($_SERVER['REQUEST_URI']); |
|
136 | + $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
137 | + $request = parse_url($_SERVER['REQUEST_URI']); |
|
138 | 138 | |
139 | - //Во избежании XSS мы не сохраняем весь REQUEST_URI, а берем только path |
|
140 | - /*$query = (!empty($request['query'])) ? $request['query'].'&' : '';*/ |
|
141 | - $query = '?'.$LogoutName; |
|
139 | + //Во избежании XSS мы не сохраняем весь REQUEST_URI, а берем только path |
|
140 | + /*$query = (!empty($request['query'])) ? $request['query'].'&' : '';*/ |
|
141 | + $query = '?'.$LogoutName; |
|
142 | 142 | |
143 | - return $request['path'].$query; |
|
143 | + return $request['path'].$query; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,343 +149,343 @@ discard block |
||
149 | 149 | * В противном случае вся работа происходит внутри самого блока |
150 | 150 | */ |
151 | 151 | public function AuthBlock($params){ |
152 | - $POST = array('backUrl' => $_SERVER['REQUEST_URI']); |
|
153 | - |
|
154 | - $error = $errorCode = ''; |
|
155 | - |
|
156 | - $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
157 | - $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
158 | - $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
159 | - |
|
160 | - if($this->UserID('web')){ |
|
161 | - $tpl = APIHelpers::getkey($params, 'tplProfile', ''); |
|
162 | - if(empty($tpl)){ |
|
163 | - $tpl = $this->getTemplate('tplProfile'); |
|
164 | - } |
|
165 | - $dataTPL = $this->userObj->toArray(); |
|
166 | - $dataTPL['url.logout'] = $this->logoutUrl($params); |
|
167 | - $homeID = APIHelpers::getkey($params, 'homeID'); |
|
168 | - if(!empty($homeID)){ |
|
169 | - $dataTPL['url.profile'] = $this->makeUrl($homeID); |
|
170 | - } |
|
171 | - }else{ |
|
172 | - $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
|
173 | - if(empty($tpl)){ |
|
174 | - $tpl = $this->getTemplate('authForm'); |
|
175 | - } |
|
176 | - $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
177 | - $dataTPL = array( |
|
178 | - 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
179 | - 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
180 | - 'emailField' => $emailField, |
|
181 | - 'pwdField' => $pwdField, |
|
182 | - 'method' => strtolower(__METHOD__), |
|
183 | - 'error' => $error, |
|
184 | - 'errorCode' => $errorCode |
|
185 | - ); |
|
186 | - $authId = APIHelpers::getkey($params, 'authId'); |
|
187 | - if(!empty($authId)){ |
|
188 | - $dataTPL['authPage'] = $this->makeUrl($authId); |
|
189 | - $dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage'); |
|
190 | - } |
|
191 | - } |
|
192 | - return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL); |
|
152 | + $POST = array('backUrl' => $_SERVER['REQUEST_URI']); |
|
153 | + |
|
154 | + $error = $errorCode = ''; |
|
155 | + |
|
156 | + $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
157 | + $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
158 | + $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
159 | + |
|
160 | + if($this->UserID('web')){ |
|
161 | + $tpl = APIHelpers::getkey($params, 'tplProfile', ''); |
|
162 | + if(empty($tpl)){ |
|
163 | + $tpl = $this->getTemplate('tplProfile'); |
|
164 | + } |
|
165 | + $dataTPL = $this->userObj->toArray(); |
|
166 | + $dataTPL['url.logout'] = $this->logoutUrl($params); |
|
167 | + $homeID = APIHelpers::getkey($params, 'homeID'); |
|
168 | + if(!empty($homeID)){ |
|
169 | + $dataTPL['url.profile'] = $this->makeUrl($homeID); |
|
170 | + } |
|
171 | + }else{ |
|
172 | + $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
|
173 | + if(empty($tpl)){ |
|
174 | + $tpl = $this->getTemplate('authForm'); |
|
175 | + } |
|
176 | + $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
177 | + $dataTPL = array( |
|
178 | + 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
179 | + 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
180 | + 'emailField' => $emailField, |
|
181 | + 'pwdField' => $pwdField, |
|
182 | + 'method' => strtolower(__METHOD__), |
|
183 | + 'error' => $error, |
|
184 | + 'errorCode' => $errorCode |
|
185 | + ); |
|
186 | + $authId = APIHelpers::getkey($params, 'authId'); |
|
187 | + if(!empty($authId)){ |
|
188 | + $dataTPL['authPage'] = $this->makeUrl($authId); |
|
189 | + $dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage'); |
|
190 | + } |
|
191 | + } |
|
192 | + return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL); |
|
193 | 193 | } |
194 | 194 | |
195 | - /** |
|
196 | - * Авторизация на сайте со страницы авторизации |
|
197 | - * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!] |
|
198 | - */ |
|
199 | - public function AuthPage($params){ |
|
200 | - $homeID = APIHelpers::getkey($params, 'homeID'); |
|
201 | - $this->isAuthGoHome(array('id' => $homeID)); |
|
202 | - |
|
203 | - $error = $errorCode = ''; |
|
204 | - $POST = array('backUrl' => ''); |
|
205 | - |
|
206 | - $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
207 | - $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
208 | - $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
209 | - |
|
210 | - $tpl = APIHelpers::getkey($params, 'tpl', ''); |
|
211 | - if(empty($tpl)){ |
|
212 | - $tpl = $this->getTemplate('authForm'); |
|
213 | - } |
|
214 | - |
|
215 | - $request = parse_url($_SERVER['REQUEST_URI']); |
|
216 | - if(!empty($_SERVER['HTTP_REFERER'])){ |
|
217 | - /** |
|
218 | - * Thank you for super protection against hacking in protect.inc.php:-) |
|
219 | - */ |
|
220 | - $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
|
221 | - }else{ |
|
222 | - $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
|
223 | - if(empty( $request['host']) || $request['host']==$selfHost){ |
|
224 | - $query = !empty($request['query']) ? '?'.$request['query'] : ''; |
|
225 | - $refer = !empty($request['path']) ? $request['path'].$query : ''; |
|
226 | - }else{ |
|
227 | - $refer = ''; |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
|
232 | - $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
|
233 | - if(!is_scalar($backUrl)){ |
|
234 | - $backUrl = $refer; |
|
235 | - }else{ |
|
236 | - $backUrl = urldecode($backUrl); |
|
237 | - } |
|
238 | - }else{ |
|
239 | - $backUrl = $refer; |
|
240 | - } |
|
241 | - $backUrl = parse_url($backUrl); |
|
242 | - if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){ |
|
243 | - $POST['backUrl'] = $backUrl['path']; |
|
244 | - }else{ |
|
245 | - $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
|
246 | - if(empty($backUrl['host']) || $backUrl['host']==$selfHost){ |
|
247 | - $query = !empty($backUrl['query']) ? '?'.$backUrl['query'] : ''; |
|
248 | - $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : ''; |
|
249 | - }else{ |
|
250 | - $POST['backUrl'] = ''; |
|
251 | - } |
|
252 | - } |
|
253 | - if(!empty($POST['backUrl'])){ |
|
254 | - $idURL = $this->moveTo(array( |
|
255 | - 'url' => '/'.ltrim($POST['backUrl'], '/'), |
|
256 | - 'validate' => true |
|
257 | - )); |
|
258 | - }else{ |
|
259 | - $idURL = 0; |
|
260 | - } |
|
261 | - if(empty($idURL)){ |
|
262 | - if(empty($homeID)){ |
|
263 | - $homeID = $this->config['site_start']; |
|
264 | - } |
|
265 | - $POST['backUrl'] = $this->makeUrl($homeID); |
|
266 | - } |
|
267 | - $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
268 | - return DLTemplate::getInstance($this->modx)->parseChunk($tpl, array( |
|
269 | - 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
270 | - 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
271 | - 'emailField' => $emailField, |
|
272 | - 'pwdField' => $pwdField, |
|
273 | - 'method' => strtolower(__METHOD__), |
|
274 | - 'error' => $error, |
|
275 | - 'errorCode' => $errorCode |
|
276 | - )); |
|
277 | - } |
|
278 | - protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){ |
|
279 | - $POST = array( |
|
280 | - 'backUrl' => urlencode($backUrl) |
|
281 | - ); |
|
282 | - $userObj = &$this->userObj; |
|
283 | - if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){ |
|
284 | - $POST = array_merge($POST, array( |
|
285 | - 'password' => APIHelpers::getkey($_POST, $pwdField, ''), |
|
286 | - 'email' => APIHelpers::getkey($_POST, $emailField, ''), |
|
287 | - 'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0)) |
|
288 | - )); |
|
289 | - if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){ |
|
290 | - $userObj->edit($POST['email']); |
|
291 | - |
|
292 | - $this->modx->invokeEvent("OnBeforeWebLogin", array( |
|
293 | - "username" => $POST['email'], |
|
294 | - "userpassword" => $POST['password'], |
|
295 | - "rememberme" => $POST['remember'], |
|
296 | - 'userObj' => $userObj |
|
297 | - )); |
|
298 | - if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){ |
|
299 | - $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array( |
|
300 | - "userid" => $userObj->getID(), |
|
301 | - "username" => $userObj->get('username'), |
|
302 | - "userpassword" => $POST['password'], |
|
303 | - "savedpassword" => $userObj->get('password'), |
|
304 | - "rememberme" => $POST['remember'], |
|
305 | - )); |
|
306 | - if( |
|
307 | - ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0)) |
|
308 | - && |
|
309 | - $userObj->authUser($userObj->getID(), $POST['remember']) |
|
310 | - ){ |
|
311 | - $userObj->set('logincount', (int)$userObj->get('logincount') + 1); |
|
312 | - $userObj->set('lastlogin', time()); |
|
313 | - $userObj->set('failedlogincount', 0); |
|
314 | - $userObj->save(false, false); |
|
315 | - |
|
316 | - $this->modx->invokeEvent("OnWebLogin", array( |
|
317 | - "userid" => $userObj->getID(), |
|
318 | - "username" => $userObj->get('username'), |
|
319 | - "userpassword" => $POST['password'], |
|
320 | - "rememberme" => $POST['remember'], |
|
321 | - )); |
|
322 | - $this->moveTo(array('url' => urldecode($POST['backUrl']))); |
|
323 | - }else{ |
|
324 | - $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1); |
|
325 | - $userObj->save(false, false); |
|
326 | - |
|
327 | - $error = 'error.incorrect_password'; |
|
328 | - } |
|
329 | - }else{ |
|
330 | - $error = 'error.no_user'; |
|
331 | - } |
|
332 | - }else{ |
|
333 | - $error = 'error.incorrect_mail'; |
|
334 | - $POST['email'] = ''; |
|
335 | - } |
|
336 | - } |
|
337 | - if(!empty($error)){ |
|
338 | - $errorCode = $error; |
|
339 | - $error = APIHelpers::getkey($params, $error, ''); |
|
340 | - $error = static::getLangMsg($error, $error); |
|
341 | - } |
|
342 | - return $POST; |
|
343 | - } |
|
344 | - /** |
|
345 | - * Информация о пользователе |
|
346 | - * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!] |
|
347 | - */ |
|
348 | - public function UserInfo($params){ |
|
349 | - $out = ''; |
|
350 | - $userID = APIHelpers::getkey($params, 'id', 0); |
|
351 | - if(empty($userID)){ |
|
352 | - $userID = $this->UserID('web'); |
|
353 | - } |
|
354 | - $field = APIHelpers::getkey($params, 'field', 'username'); |
|
355 | - if($userID > 0){ |
|
356 | - $this->userObj->edit($userID); |
|
357 | - switch(true){ |
|
358 | - case ($field == $this->userObj->fieldPKName()): |
|
359 | - $out = $this->userObj->getID(); |
|
360 | - break; |
|
361 | - case ($this->userObj->issetField($field)): |
|
362 | - $out = $this->userObj->get($field); |
|
363 | - break; |
|
364 | - } |
|
365 | - } |
|
366 | - return $out; |
|
367 | - } |
|
368 | - /** |
|
369 | - * ID пользователя |
|
370 | - */ |
|
371 | - public function UserID($type = 'web'){ |
|
372 | - return $this->modx->getLoginUserID($type); |
|
373 | - } |
|
374 | - /** |
|
375 | - * Если не авторизован - то отправить на страницу |
|
376 | - */ |
|
377 | - public function isGuestGoHome($params){ |
|
378 | - if(!$this->UserID('web')){ |
|
379 | - /** |
|
380 | - * @see : http://modx.im/blog/triks/105.html |
|
381 | - */ |
|
382 | - $this->modx->invokeEvent('OnPageUnauthorized'); |
|
383 | - $id = APIHelpers::getkey($params, 'id', $this->config['unauthorized_page']); |
|
384 | - $this->moveTo(compact('id')); |
|
385 | - } |
|
386 | - return; |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Если авторизован - то открыть личный кабинет |
|
391 | - */ |
|
392 | - public function isAuthGoHome($params){ |
|
393 | - $userID = $this->UserID('web'); |
|
394 | - if($userID>0){ |
|
395 | - $id = APIHelpers::getkey($params, 'homeID'); |
|
396 | - if(empty($id)){ |
|
397 | - $id = $this->modx->getConfig('login_home', $this->config['site_start']); |
|
398 | - } |
|
399 | - $this->moveTo(compact('id')); |
|
400 | - } |
|
401 | - return; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Редирект |
|
406 | - */ |
|
407 | - public function moveTo($params){ |
|
408 | - $id = (int)APIHelpers::getkey($params, 'id', 0); |
|
409 | - $uri = APIHelpers::getkey($params, 'url', ''); |
|
410 | - if((empty($uri) && !empty($id)) || !is_string($uri)){ |
|
411 | - $uri = $this->makeUrl($id); |
|
412 | - } |
|
413 | - $code = (int)APIHelpers::getkey($params, 'code', 0); |
|
414 | - $addUrl = APIHelpers::getkey($params, 'addUrl', ''); |
|
415 | - if(is_scalar($addUrl) && $addUrl!=''){ |
|
416 | - $uri .= "?".$addUrl; |
|
417 | - } |
|
418 | - if(APIHelpers::getkey($params, 'validate', false)){ |
|
419 | - if(isset($this->modx->snippetCache['getPageID'])){ |
|
420 | - $out = $this->modx->runSnippet('getPageID', compact('uri')); |
|
421 | - if(empty($out)){ |
|
422 | - $uri = ''; |
|
423 | - } |
|
424 | - }else{ |
|
425 | - $uri = APIhelpers::sanitarTag($uri); |
|
426 | - } |
|
427 | - }else{ |
|
428 | - //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
|
429 | - header("Location: ".$uri, true, ($code>0 ? $code : 307)); |
|
430 | - } |
|
431 | - return $uri; |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Создание ссылки на страницу |
|
436 | - * |
|
437 | - * @param int $id ID документа |
|
438 | - * @return string |
|
439 | - */ |
|
440 | - protected function makeUrl($id = null){ |
|
441 | - $id = (int)$id; |
|
442 | - if($id <= 0){ |
|
443 | - $id = $this->modx->documentObject['id']; |
|
444 | - } |
|
445 | - if($this->url->containsKey($id)){ |
|
446 | - $url = $this->url->get($id); |
|
447 | - }else{ |
|
448 | - $url = $this->modx->makeUrl($id); |
|
449 | - $this->url->set($id, $url); |
|
450 | - } |
|
451 | - return $url; |
|
452 | - } |
|
453 | - protected function getTemplate($name){ |
|
454 | - $out = ''; |
|
455 | - $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html'; |
|
456 | - if( FS::getInstance()->checkFile($file)){ |
|
457 | - $out = '@CODE: '.file_get_contents($file); |
|
458 | - } |
|
459 | - return $out; |
|
460 | - } |
|
461 | - protected static function loadLang($lang){ |
|
462 | - $file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php'; |
|
463 | - if( ! FS::getInstance()->checkFile($file)){ |
|
464 | - $file = false; |
|
465 | - } |
|
466 | - if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){ |
|
467 | - static::$langDic[$lang] = include_once($file); |
|
468 | - if(is_array(static::$langDic[$lang])){ |
|
469 | - static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
|
470 | - }else{ |
|
471 | - static::$langDic[$lang] = array(); |
|
472 | - } |
|
473 | - } |
|
474 | - return !(empty($lang) || empty(static::$langDic[$lang])); |
|
475 | - } |
|
476 | - protected static function getLangMsg($key, $default){ |
|
477 | - $out = $default; |
|
478 | - $lng = static::$lang; |
|
479 | - $dic = static::$langDic; |
|
480 | - if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){ |
|
481 | - $out = $dic[$lng][$lng.'.'.$key]; |
|
482 | - } |
|
483 | - if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){ |
|
484 | - $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key)); |
|
485 | - if(!empty($msg)){ |
|
486 | - $out = $msg; |
|
487 | - } |
|
488 | - } |
|
489 | - return $out; |
|
490 | - } |
|
195 | + /** |
|
196 | + * Авторизация на сайте со страницы авторизации |
|
197 | + * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!] |
|
198 | + */ |
|
199 | + public function AuthPage($params){ |
|
200 | + $homeID = APIHelpers::getkey($params, 'homeID'); |
|
201 | + $this->isAuthGoHome(array('id' => $homeID)); |
|
202 | + |
|
203 | + $error = $errorCode = ''; |
|
204 | + $POST = array('backUrl' => ''); |
|
205 | + |
|
206 | + $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
207 | + $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
208 | + $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
209 | + |
|
210 | + $tpl = APIHelpers::getkey($params, 'tpl', ''); |
|
211 | + if(empty($tpl)){ |
|
212 | + $tpl = $this->getTemplate('authForm'); |
|
213 | + } |
|
214 | + |
|
215 | + $request = parse_url($_SERVER['REQUEST_URI']); |
|
216 | + if(!empty($_SERVER['HTTP_REFERER'])){ |
|
217 | + /** |
|
218 | + * Thank you for super protection against hacking in protect.inc.php:-) |
|
219 | + */ |
|
220 | + $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
|
221 | + }else{ |
|
222 | + $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
|
223 | + if(empty( $request['host']) || $request['host']==$selfHost){ |
|
224 | + $query = !empty($request['query']) ? '?'.$request['query'] : ''; |
|
225 | + $refer = !empty($request['path']) ? $request['path'].$query : ''; |
|
226 | + }else{ |
|
227 | + $refer = ''; |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
|
232 | + $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
|
233 | + if(!is_scalar($backUrl)){ |
|
234 | + $backUrl = $refer; |
|
235 | + }else{ |
|
236 | + $backUrl = urldecode($backUrl); |
|
237 | + } |
|
238 | + }else{ |
|
239 | + $backUrl = $refer; |
|
240 | + } |
|
241 | + $backUrl = parse_url($backUrl); |
|
242 | + if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){ |
|
243 | + $POST['backUrl'] = $backUrl['path']; |
|
244 | + }else{ |
|
245 | + $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
|
246 | + if(empty($backUrl['host']) || $backUrl['host']==$selfHost){ |
|
247 | + $query = !empty($backUrl['query']) ? '?'.$backUrl['query'] : ''; |
|
248 | + $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : ''; |
|
249 | + }else{ |
|
250 | + $POST['backUrl'] = ''; |
|
251 | + } |
|
252 | + } |
|
253 | + if(!empty($POST['backUrl'])){ |
|
254 | + $idURL = $this->moveTo(array( |
|
255 | + 'url' => '/'.ltrim($POST['backUrl'], '/'), |
|
256 | + 'validate' => true |
|
257 | + )); |
|
258 | + }else{ |
|
259 | + $idURL = 0; |
|
260 | + } |
|
261 | + if(empty($idURL)){ |
|
262 | + if(empty($homeID)){ |
|
263 | + $homeID = $this->config['site_start']; |
|
264 | + } |
|
265 | + $POST['backUrl'] = $this->makeUrl($homeID); |
|
266 | + } |
|
267 | + $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
268 | + return DLTemplate::getInstance($this->modx)->parseChunk($tpl, array( |
|
269 | + 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
270 | + 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
271 | + 'emailField' => $emailField, |
|
272 | + 'pwdField' => $pwdField, |
|
273 | + 'method' => strtolower(__METHOD__), |
|
274 | + 'error' => $error, |
|
275 | + 'errorCode' => $errorCode |
|
276 | + )); |
|
277 | + } |
|
278 | + protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){ |
|
279 | + $POST = array( |
|
280 | + 'backUrl' => urlencode($backUrl) |
|
281 | + ); |
|
282 | + $userObj = &$this->userObj; |
|
283 | + if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){ |
|
284 | + $POST = array_merge($POST, array( |
|
285 | + 'password' => APIHelpers::getkey($_POST, $pwdField, ''), |
|
286 | + 'email' => APIHelpers::getkey($_POST, $emailField, ''), |
|
287 | + 'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0)) |
|
288 | + )); |
|
289 | + if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){ |
|
290 | + $userObj->edit($POST['email']); |
|
291 | + |
|
292 | + $this->modx->invokeEvent("OnBeforeWebLogin", array( |
|
293 | + "username" => $POST['email'], |
|
294 | + "userpassword" => $POST['password'], |
|
295 | + "rememberme" => $POST['remember'], |
|
296 | + 'userObj' => $userObj |
|
297 | + )); |
|
298 | + if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){ |
|
299 | + $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array( |
|
300 | + "userid" => $userObj->getID(), |
|
301 | + "username" => $userObj->get('username'), |
|
302 | + "userpassword" => $POST['password'], |
|
303 | + "savedpassword" => $userObj->get('password'), |
|
304 | + "rememberme" => $POST['remember'], |
|
305 | + )); |
|
306 | + if( |
|
307 | + ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0)) |
|
308 | + && |
|
309 | + $userObj->authUser($userObj->getID(), $POST['remember']) |
|
310 | + ){ |
|
311 | + $userObj->set('logincount', (int)$userObj->get('logincount') + 1); |
|
312 | + $userObj->set('lastlogin', time()); |
|
313 | + $userObj->set('failedlogincount', 0); |
|
314 | + $userObj->save(false, false); |
|
315 | + |
|
316 | + $this->modx->invokeEvent("OnWebLogin", array( |
|
317 | + "userid" => $userObj->getID(), |
|
318 | + "username" => $userObj->get('username'), |
|
319 | + "userpassword" => $POST['password'], |
|
320 | + "rememberme" => $POST['remember'], |
|
321 | + )); |
|
322 | + $this->moveTo(array('url' => urldecode($POST['backUrl']))); |
|
323 | + }else{ |
|
324 | + $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1); |
|
325 | + $userObj->save(false, false); |
|
326 | + |
|
327 | + $error = 'error.incorrect_password'; |
|
328 | + } |
|
329 | + }else{ |
|
330 | + $error = 'error.no_user'; |
|
331 | + } |
|
332 | + }else{ |
|
333 | + $error = 'error.incorrect_mail'; |
|
334 | + $POST['email'] = ''; |
|
335 | + } |
|
336 | + } |
|
337 | + if(!empty($error)){ |
|
338 | + $errorCode = $error; |
|
339 | + $error = APIHelpers::getkey($params, $error, ''); |
|
340 | + $error = static::getLangMsg($error, $error); |
|
341 | + } |
|
342 | + return $POST; |
|
343 | + } |
|
344 | + /** |
|
345 | + * Информация о пользователе |
|
346 | + * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!] |
|
347 | + */ |
|
348 | + public function UserInfo($params){ |
|
349 | + $out = ''; |
|
350 | + $userID = APIHelpers::getkey($params, 'id', 0); |
|
351 | + if(empty($userID)){ |
|
352 | + $userID = $this->UserID('web'); |
|
353 | + } |
|
354 | + $field = APIHelpers::getkey($params, 'field', 'username'); |
|
355 | + if($userID > 0){ |
|
356 | + $this->userObj->edit($userID); |
|
357 | + switch(true){ |
|
358 | + case ($field == $this->userObj->fieldPKName()): |
|
359 | + $out = $this->userObj->getID(); |
|
360 | + break; |
|
361 | + case ($this->userObj->issetField($field)): |
|
362 | + $out = $this->userObj->get($field); |
|
363 | + break; |
|
364 | + } |
|
365 | + } |
|
366 | + return $out; |
|
367 | + } |
|
368 | + /** |
|
369 | + * ID пользователя |
|
370 | + */ |
|
371 | + public function UserID($type = 'web'){ |
|
372 | + return $this->modx->getLoginUserID($type); |
|
373 | + } |
|
374 | + /** |
|
375 | + * Если не авторизован - то отправить на страницу |
|
376 | + */ |
|
377 | + public function isGuestGoHome($params){ |
|
378 | + if(!$this->UserID('web')){ |
|
379 | + /** |
|
380 | + * @see : http://modx.im/blog/triks/105.html |
|
381 | + */ |
|
382 | + $this->modx->invokeEvent('OnPageUnauthorized'); |
|
383 | + $id = APIHelpers::getkey($params, 'id', $this->config['unauthorized_page']); |
|
384 | + $this->moveTo(compact('id')); |
|
385 | + } |
|
386 | + return; |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Если авторизован - то открыть личный кабинет |
|
391 | + */ |
|
392 | + public function isAuthGoHome($params){ |
|
393 | + $userID = $this->UserID('web'); |
|
394 | + if($userID>0){ |
|
395 | + $id = APIHelpers::getkey($params, 'homeID'); |
|
396 | + if(empty($id)){ |
|
397 | + $id = $this->modx->getConfig('login_home', $this->config['site_start']); |
|
398 | + } |
|
399 | + $this->moveTo(compact('id')); |
|
400 | + } |
|
401 | + return; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Редирект |
|
406 | + */ |
|
407 | + public function moveTo($params){ |
|
408 | + $id = (int)APIHelpers::getkey($params, 'id', 0); |
|
409 | + $uri = APIHelpers::getkey($params, 'url', ''); |
|
410 | + if((empty($uri) && !empty($id)) || !is_string($uri)){ |
|
411 | + $uri = $this->makeUrl($id); |
|
412 | + } |
|
413 | + $code = (int)APIHelpers::getkey($params, 'code', 0); |
|
414 | + $addUrl = APIHelpers::getkey($params, 'addUrl', ''); |
|
415 | + if(is_scalar($addUrl) && $addUrl!=''){ |
|
416 | + $uri .= "?".$addUrl; |
|
417 | + } |
|
418 | + if(APIHelpers::getkey($params, 'validate', false)){ |
|
419 | + if(isset($this->modx->snippetCache['getPageID'])){ |
|
420 | + $out = $this->modx->runSnippet('getPageID', compact('uri')); |
|
421 | + if(empty($out)){ |
|
422 | + $uri = ''; |
|
423 | + } |
|
424 | + }else{ |
|
425 | + $uri = APIhelpers::sanitarTag($uri); |
|
426 | + } |
|
427 | + }else{ |
|
428 | + //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
|
429 | + header("Location: ".$uri, true, ($code>0 ? $code : 307)); |
|
430 | + } |
|
431 | + return $uri; |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Создание ссылки на страницу |
|
436 | + * |
|
437 | + * @param int $id ID документа |
|
438 | + * @return string |
|
439 | + */ |
|
440 | + protected function makeUrl($id = null){ |
|
441 | + $id = (int)$id; |
|
442 | + if($id <= 0){ |
|
443 | + $id = $this->modx->documentObject['id']; |
|
444 | + } |
|
445 | + if($this->url->containsKey($id)){ |
|
446 | + $url = $this->url->get($id); |
|
447 | + }else{ |
|
448 | + $url = $this->modx->makeUrl($id); |
|
449 | + $this->url->set($id, $url); |
|
450 | + } |
|
451 | + return $url; |
|
452 | + } |
|
453 | + protected function getTemplate($name){ |
|
454 | + $out = ''; |
|
455 | + $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html'; |
|
456 | + if( FS::getInstance()->checkFile($file)){ |
|
457 | + $out = '@CODE: '.file_get_contents($file); |
|
458 | + } |
|
459 | + return $out; |
|
460 | + } |
|
461 | + protected static function loadLang($lang){ |
|
462 | + $file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php'; |
|
463 | + if( ! FS::getInstance()->checkFile($file)){ |
|
464 | + $file = false; |
|
465 | + } |
|
466 | + if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){ |
|
467 | + static::$langDic[$lang] = include_once($file); |
|
468 | + if(is_array(static::$langDic[$lang])){ |
|
469 | + static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
|
470 | + }else{ |
|
471 | + static::$langDic[$lang] = array(); |
|
472 | + } |
|
473 | + } |
|
474 | + return !(empty($lang) || empty(static::$langDic[$lang])); |
|
475 | + } |
|
476 | + protected static function getLangMsg($key, $default){ |
|
477 | + $out = $default; |
|
478 | + $lng = static::$lang; |
|
479 | + $dic = static::$langDic; |
|
480 | + if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){ |
|
481 | + $out = $dic[$lng][$lng.'.'.$key]; |
|
482 | + } |
|
483 | + if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){ |
|
484 | + $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key)); |
|
485 | + if(!empty($msg)){ |
|
486 | + $out = $msg; |
|
487 | + } |
|
488 | + } |
|
489 | + return $out; |
|
490 | + } |
|
491 | 491 | } |
492 | 492 | \ No newline at end of file |
@@ -1,15 +1,15 @@ discard block |
||
1 | 1 | <?php namespace DLUsers; |
2 | 2 | |
3 | -include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
|
4 | -include_once(MODX_BASE_PATH . 'assets/lib/Helpers/FS.php'); |
|
5 | -include_once(MODX_BASE_PATH . 'assets/lib/MODxAPI/modUsers.php'); |
|
6 | -include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLTemplate.class.php'); |
|
7 | -include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLCollection.class.php'); |
|
3 | +include_once(MODX_BASE_PATH.'assets/lib/APIHelpers.class.php'); |
|
4 | +include_once(MODX_BASE_PATH.'assets/lib/Helpers/FS.php'); |
|
5 | +include_once(MODX_BASE_PATH.'assets/lib/MODxAPI/modUsers.php'); |
|
6 | +include_once(MODX_BASE_PATH.'assets/snippets/DocLister/lib/DLTemplate.class.php'); |
|
7 | +include_once(MODX_BASE_PATH.'assets/snippets/DocLister/lib/DLCollection.class.php'); |
|
8 | 8 | |
9 | 9 | use APIHelpers, DocumentParser, DLCollection, DLTemplate; |
10 | 10 | use Helpers\FS; |
11 | 11 | |
12 | -class Actions{ |
|
12 | +class Actions { |
|
13 | 13 | protected $modx = null; |
14 | 14 | public $userObj = null; |
15 | 15 | /** |
@@ -84,20 +84,20 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * Сброс авторизации и обновление страницы |
86 | 86 | */ |
87 | - public function logout($params){ |
|
87 | + public function logout($params) { |
|
88 | 88 | $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
89 | - if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){ |
|
89 | + if (is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])) { |
|
90 | 90 | $userID = $this->UserID('web'); |
91 | - if($userID){ |
|
91 | + if ($userID) { |
|
92 | 92 | $this->userObj->edit($userID); |
93 | - if($this->userObj->getID()){ |
|
93 | + if ($this->userObj->getID()) { |
|
94 | 94 | $this->modx->invokeEvent("OnBeforeWebLogout", array( |
95 | 95 | "userid" => $this->userObj->getID(), |
96 | 96 | "username" => $this->userObj->get('username') |
97 | 97 | )); |
98 | 98 | } |
99 | 99 | $this->userObj->logOut(); |
100 | - if($this->userObj->getID()){ |
|
100 | + if ($this->userObj->getID()) { |
|
101 | 101 | $this->modx->invokeEvent("OnWebLogout", array( |
102 | 102 | "userid" => $this->userObj->getID(), |
103 | 103 | "username" => $this->userObj->get('username') |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | $go = APIHelpers::getkey($params, 'url', ''); |
108 | - if(empty($go)){ |
|
108 | + if (empty($go)) { |
|
109 | 109 | $go = str_replace( |
110 | 110 | array("?".$LogoutName, "&".$LogoutName), |
111 | 111 | array("", ""), |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | $start = $this->makeUrl($this->config['site_start']); |
117 | - if($start == $go){ |
|
117 | + if ($start == $go) { |
|
118 | 118 | $go = $this->config['site_url']; |
119 | - }else{ |
|
119 | + } else { |
|
120 | 120 | $go = $this->config['site_url'].ltrim($go, '/'); |
121 | 121 | } |
122 | 122 | $this->moveTo(array('url' => $go)); |
123 | - }else{ |
|
123 | + } else { |
|
124 | 124 | //Если юзер не авторизован, то показываем ему 404 ошибку |
125 | 125 | $this->modx->sendErrorPage(); |
126 | 126 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * Генерация ссылки под кнопку выход |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public function logoutUrl($params){ |
|
135 | + public function logoutUrl($params) { |
|
136 | 136 | $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
137 | 137 | $request = parse_url($_SERVER['REQUEST_URI']); |
138 | 138 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * если указан параметр authId, то данные из формы перекидываются в метод AuthPage |
149 | 149 | * В противном случае вся работа происходит внутри самого блока |
150 | 150 | */ |
151 | - public function AuthBlock($params){ |
|
151 | + public function AuthBlock($params) { |
|
152 | 152 | $POST = array('backUrl' => $_SERVER['REQUEST_URI']); |
153 | 153 | |
154 | 154 | $error = $errorCode = ''; |
@@ -157,20 +157,20 @@ discard block |
||
157 | 157 | $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
158 | 158 | $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
159 | 159 | |
160 | - if($this->UserID('web')){ |
|
160 | + if ($this->UserID('web')) { |
|
161 | 161 | $tpl = APIHelpers::getkey($params, 'tplProfile', ''); |
162 | - if(empty($tpl)){ |
|
162 | + if (empty($tpl)) { |
|
163 | 163 | $tpl = $this->getTemplate('tplProfile'); |
164 | 164 | } |
165 | 165 | $dataTPL = $this->userObj->toArray(); |
166 | 166 | $dataTPL['url.logout'] = $this->logoutUrl($params); |
167 | 167 | $homeID = APIHelpers::getkey($params, 'homeID'); |
168 | - if(!empty($homeID)){ |
|
168 | + if (!empty($homeID)) { |
|
169 | 169 | $dataTPL['url.profile'] = $this->makeUrl($homeID); |
170 | 170 | } |
171 | - }else{ |
|
171 | + } else { |
|
172 | 172 | $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
173 | - if(empty($tpl)){ |
|
173 | + if (empty($tpl)) { |
|
174 | 174 | $tpl = $this->getTemplate('authForm'); |
175 | 175 | } |
176 | 176 | $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | 'errorCode' => $errorCode |
185 | 185 | ); |
186 | 186 | $authId = APIHelpers::getkey($params, 'authId'); |
187 | - if(!empty($authId)){ |
|
187 | + if (!empty($authId)) { |
|
188 | 188 | $dataTPL['authPage'] = $this->makeUrl($authId); |
189 | - $dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage'); |
|
189 | + $dataTPL['method'] = strtolower(__CLASS__.'::'.'authpage'); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL); |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * Авторизация на сайте со страницы авторизации |
197 | 197 | * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!] |
198 | 198 | */ |
199 | - public function AuthPage($params){ |
|
199 | + public function AuthPage($params) { |
|
200 | 200 | $homeID = APIHelpers::getkey($params, 'homeID'); |
201 | 201 | $this->isAuthGoHome(array('id' => $homeID)); |
202 | 202 | |
@@ -208,58 +208,58 @@ discard block |
||
208 | 208 | $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
209 | 209 | |
210 | 210 | $tpl = APIHelpers::getkey($params, 'tpl', ''); |
211 | - if(empty($tpl)){ |
|
211 | + if (empty($tpl)) { |
|
212 | 212 | $tpl = $this->getTemplate('authForm'); |
213 | 213 | } |
214 | 214 | |
215 | 215 | $request = parse_url($_SERVER['REQUEST_URI']); |
216 | - if(!empty($_SERVER['HTTP_REFERER'])){ |
|
216 | + if (!empty($_SERVER['HTTP_REFERER'])) { |
|
217 | 217 | /** |
218 | 218 | * Thank you for super protection against hacking in protect.inc.php:-) |
219 | 219 | */ |
220 | 220 | $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
221 | - }else{ |
|
221 | + } else { |
|
222 | 222 | $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
223 | - if(empty( $request['host']) || $request['host']==$selfHost){ |
|
223 | + if (empty($request['host']) || $request['host'] == $selfHost) { |
|
224 | 224 | $query = !empty($request['query']) ? '?'.$request['query'] : ''; |
225 | 225 | $refer = !empty($request['path']) ? $request['path'].$query : ''; |
226 | - }else{ |
|
226 | + } else { |
|
227 | 227 | $refer = ''; |
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | - if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
|
231 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
232 | 232 | $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
233 | - if(!is_scalar($backUrl)){ |
|
233 | + if (!is_scalar($backUrl)) { |
|
234 | 234 | $backUrl = $refer; |
235 | - }else{ |
|
235 | + } else { |
|
236 | 236 | $backUrl = urldecode($backUrl); |
237 | 237 | } |
238 | - }else{ |
|
238 | + } else { |
|
239 | 239 | $backUrl = $refer; |
240 | 240 | } |
241 | 241 | $backUrl = parse_url($backUrl); |
242 | - if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){ |
|
242 | + if (!empty($backUrl['path']) && $request['path'] != $backUrl['path']) { |
|
243 | 243 | $POST['backUrl'] = $backUrl['path']; |
244 | - }else{ |
|
244 | + } else { |
|
245 | 245 | $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
246 | - if(empty($backUrl['host']) || $backUrl['host']==$selfHost){ |
|
246 | + if (empty($backUrl['host']) || $backUrl['host'] == $selfHost) { |
|
247 | 247 | $query = !empty($backUrl['query']) ? '?'.$backUrl['query'] : ''; |
248 | 248 | $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : ''; |
249 | - }else{ |
|
249 | + } else { |
|
250 | 250 | $POST['backUrl'] = ''; |
251 | 251 | } |
252 | 252 | } |
253 | - if(!empty($POST['backUrl'])){ |
|
253 | + if (!empty($POST['backUrl'])) { |
|
254 | 254 | $idURL = $this->moveTo(array( |
255 | 255 | 'url' => '/'.ltrim($POST['backUrl'], '/'), |
256 | 256 | 'validate' => true |
257 | 257 | )); |
258 | - }else{ |
|
258 | + } else { |
|
259 | 259 | $idURL = 0; |
260 | 260 | } |
261 | - if(empty($idURL)){ |
|
262 | - if(empty($homeID)){ |
|
261 | + if (empty($idURL)) { |
|
262 | + if (empty($homeID)) { |
|
263 | 263 | $homeID = $this->config['site_start']; |
264 | 264 | } |
265 | 265 | $POST['backUrl'] = $this->makeUrl($homeID); |
@@ -275,18 +275,18 @@ discard block |
||
275 | 275 | 'errorCode' => $errorCode |
276 | 276 | )); |
277 | 277 | } |
278 | - protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){ |
|
278 | + protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()) { |
|
279 | 279 | $POST = array( |
280 | 280 | 'backUrl' => urlencode($backUrl) |
281 | 281 | ); |
282 | 282 | $userObj = &$this->userObj; |
283 | - if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){ |
|
283 | + if ($_SERVER['REQUEST_METHOD'] == 'POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)) { |
|
284 | 284 | $POST = array_merge($POST, array( |
285 | 285 | 'password' => APIHelpers::getkey($_POST, $pwdField, ''), |
286 | 286 | 'email' => APIHelpers::getkey($_POST, $emailField, ''), |
287 | 287 | 'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0)) |
288 | 288 | )); |
289 | - if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){ |
|
289 | + if (!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)) { |
|
290 | 290 | $userObj->edit($POST['email']); |
291 | 291 | |
292 | 292 | $this->modx->invokeEvent("OnBeforeWebLogin", array( |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | "rememberme" => $POST['remember'], |
296 | 296 | 'userObj' => $userObj |
297 | 297 | )); |
298 | - if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){ |
|
298 | + if ($userObj->getID() && !$userObj->checkBlock($userObj->getID())) { |
|
299 | 299 | $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array( |
300 | 300 | "userid" => $userObj->getID(), |
301 | 301 | "username" => $userObj->get('username'), |
@@ -303,11 +303,11 @@ discard block |
||
303 | 303 | "savedpassword" => $userObj->get('password'), |
304 | 304 | "rememberme" => $POST['remember'], |
305 | 305 | )); |
306 | - if( |
|
306 | + if ( |
|
307 | 307 | ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0)) |
308 | 308 | && |
309 | 309 | $userObj->authUser($userObj->getID(), $POST['remember']) |
310 | - ){ |
|
310 | + ) { |
|
311 | 311 | $userObj->set('logincount', (int)$userObj->get('logincount') + 1); |
312 | 312 | $userObj->set('lastlogin', time()); |
313 | 313 | $userObj->set('failedlogincount', 0); |
@@ -320,21 +320,21 @@ discard block |
||
320 | 320 | "rememberme" => $POST['remember'], |
321 | 321 | )); |
322 | 322 | $this->moveTo(array('url' => urldecode($POST['backUrl']))); |
323 | - }else{ |
|
323 | + } else { |
|
324 | 324 | $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1); |
325 | 325 | $userObj->save(false, false); |
326 | 326 | |
327 | 327 | $error = 'error.incorrect_password'; |
328 | 328 | } |
329 | - }else{ |
|
329 | + } else { |
|
330 | 330 | $error = 'error.no_user'; |
331 | 331 | } |
332 | - }else{ |
|
332 | + } else { |
|
333 | 333 | $error = 'error.incorrect_mail'; |
334 | 334 | $POST['email'] = ''; |
335 | 335 | } |
336 | 336 | } |
337 | - if(!empty($error)){ |
|
337 | + if (!empty($error)) { |
|
338 | 338 | $errorCode = $error; |
339 | 339 | $error = APIHelpers::getkey($params, $error, ''); |
340 | 340 | $error = static::getLangMsg($error, $error); |
@@ -345,16 +345,16 @@ discard block |
||
345 | 345 | * Информация о пользователе |
346 | 346 | * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!] |
347 | 347 | */ |
348 | - public function UserInfo($params){ |
|
348 | + public function UserInfo($params) { |
|
349 | 349 | $out = ''; |
350 | 350 | $userID = APIHelpers::getkey($params, 'id', 0); |
351 | - if(empty($userID)){ |
|
351 | + if (empty($userID)) { |
|
352 | 352 | $userID = $this->UserID('web'); |
353 | 353 | } |
354 | 354 | $field = APIHelpers::getkey($params, 'field', 'username'); |
355 | - if($userID > 0){ |
|
355 | + if ($userID > 0) { |
|
356 | 356 | $this->userObj->edit($userID); |
357 | - switch(true){ |
|
357 | + switch (true) { |
|
358 | 358 | case ($field == $this->userObj->fieldPKName()): |
359 | 359 | $out = $this->userObj->getID(); |
360 | 360 | break; |
@@ -368,14 +368,14 @@ discard block |
||
368 | 368 | /** |
369 | 369 | * ID пользователя |
370 | 370 | */ |
371 | - public function UserID($type = 'web'){ |
|
371 | + public function UserID($type = 'web') { |
|
372 | 372 | return $this->modx->getLoginUserID($type); |
373 | 373 | } |
374 | 374 | /** |
375 | 375 | * Если не авторизован - то отправить на страницу |
376 | 376 | */ |
377 | - public function isGuestGoHome($params){ |
|
378 | - if(!$this->UserID('web')){ |
|
377 | + public function isGuestGoHome($params) { |
|
378 | + if (!$this->UserID('web')) { |
|
379 | 379 | /** |
380 | 380 | * @see : http://modx.im/blog/triks/105.html |
381 | 381 | */ |
@@ -389,11 +389,11 @@ discard block |
||
389 | 389 | /** |
390 | 390 | * Если авторизован - то открыть личный кабинет |
391 | 391 | */ |
392 | - public function isAuthGoHome($params){ |
|
392 | + public function isAuthGoHome($params) { |
|
393 | 393 | $userID = $this->UserID('web'); |
394 | - if($userID>0){ |
|
394 | + if ($userID > 0) { |
|
395 | 395 | $id = APIHelpers::getkey($params, 'homeID'); |
396 | - if(empty($id)){ |
|
396 | + if (empty($id)) { |
|
397 | 397 | $id = $this->modx->getConfig('login_home', $this->config['site_start']); |
398 | 398 | } |
399 | 399 | $this->moveTo(compact('id')); |
@@ -404,29 +404,29 @@ discard block |
||
404 | 404 | /** |
405 | 405 | * Редирект |
406 | 406 | */ |
407 | - public function moveTo($params){ |
|
407 | + public function moveTo($params) { |
|
408 | 408 | $id = (int)APIHelpers::getkey($params, 'id', 0); |
409 | 409 | $uri = APIHelpers::getkey($params, 'url', ''); |
410 | - if((empty($uri) && !empty($id)) || !is_string($uri)){ |
|
410 | + if ((empty($uri) && !empty($id)) || !is_string($uri)) { |
|
411 | 411 | $uri = $this->makeUrl($id); |
412 | 412 | } |
413 | 413 | $code = (int)APIHelpers::getkey($params, 'code', 0); |
414 | 414 | $addUrl = APIHelpers::getkey($params, 'addUrl', ''); |
415 | - if(is_scalar($addUrl) && $addUrl!=''){ |
|
415 | + if (is_scalar($addUrl) && $addUrl != '') { |
|
416 | 416 | $uri .= "?".$addUrl; |
417 | 417 | } |
418 | - if(APIHelpers::getkey($params, 'validate', false)){ |
|
419 | - if(isset($this->modx->snippetCache['getPageID'])){ |
|
418 | + if (APIHelpers::getkey($params, 'validate', false)) { |
|
419 | + if (isset($this->modx->snippetCache['getPageID'])) { |
|
420 | 420 | $out = $this->modx->runSnippet('getPageID', compact('uri')); |
421 | - if(empty($out)){ |
|
421 | + if (empty($out)) { |
|
422 | 422 | $uri = ''; |
423 | 423 | } |
424 | - }else{ |
|
424 | + } else { |
|
425 | 425 | $uri = APIhelpers::sanitarTag($uri); |
426 | 426 | } |
427 | - }else{ |
|
427 | + } else { |
|
428 | 428 | //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
429 | - header("Location: ".$uri, true, ($code>0 ? $code : 307)); |
|
429 | + header("Location: ".$uri, true, ($code > 0 ? $code : 307)); |
|
430 | 430 | } |
431 | 431 | return $uri; |
432 | 432 | } |
@@ -437,52 +437,52 @@ discard block |
||
437 | 437 | * @param int $id ID документа |
438 | 438 | * @return string |
439 | 439 | */ |
440 | - protected function makeUrl($id = null){ |
|
440 | + protected function makeUrl($id = null) { |
|
441 | 441 | $id = (int)$id; |
442 | - if($id <= 0){ |
|
442 | + if ($id <= 0) { |
|
443 | 443 | $id = $this->modx->documentObject['id']; |
444 | 444 | } |
445 | - if($this->url->containsKey($id)){ |
|
445 | + if ($this->url->containsKey($id)) { |
|
446 | 446 | $url = $this->url->get($id); |
447 | - }else{ |
|
447 | + } else { |
|
448 | 448 | $url = $this->modx->makeUrl($id); |
449 | 449 | $this->url->set($id, $url); |
450 | 450 | } |
451 | 451 | return $url; |
452 | 452 | } |
453 | - protected function getTemplate($name){ |
|
453 | + protected function getTemplate($name) { |
|
454 | 454 | $out = ''; |
455 | 455 | $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html'; |
456 | - if( FS::getInstance()->checkFile($file)){ |
|
456 | + if (FS::getInstance()->checkFile($file)) { |
|
457 | 457 | $out = '@CODE: '.file_get_contents($file); |
458 | 458 | } |
459 | 459 | return $out; |
460 | 460 | } |
461 | - protected static function loadLang($lang){ |
|
461 | + protected static function loadLang($lang) { |
|
462 | 462 | $file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php'; |
463 | - if( ! FS::getInstance()->checkFile($file)){ |
|
463 | + if (!FS::getInstance()->checkFile($file)) { |
|
464 | 464 | $file = false; |
465 | 465 | } |
466 | - if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){ |
|
466 | + if (!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)) { |
|
467 | 467 | static::$langDic[$lang] = include_once($file); |
468 | - if(is_array(static::$langDic[$lang])){ |
|
468 | + if (is_array(static::$langDic[$lang])) { |
|
469 | 469 | static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
470 | - }else{ |
|
470 | + } else { |
|
471 | 471 | static::$langDic[$lang] = array(); |
472 | 472 | } |
473 | 473 | } |
474 | 474 | return !(empty($lang) || empty(static::$langDic[$lang])); |
475 | 475 | } |
476 | - protected static function getLangMsg($key, $default){ |
|
476 | + protected static function getLangMsg($key, $default) { |
|
477 | 477 | $out = $default; |
478 | 478 | $lng = static::$lang; |
479 | 479 | $dic = static::$langDic; |
480 | - if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){ |
|
480 | + if (isset($dic[$lng], $dic[$lng][$lng.'.'.$key])) { |
|
481 | 481 | $out = $dic[$lng][$lng.'.'.$key]; |
482 | 482 | } |
483 | - if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){ |
|
483 | + if (class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])) { |
|
484 | 484 | $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key)); |
485 | - if(!empty($msg)){ |
|
485 | + if (!empty($msg)) { |
|
486 | 486 | $out = $msg; |
487 | 487 | } |
488 | 488 | } |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | $start = $this->makeUrl($this->config['site_start']); |
117 | 117 | if($start == $go){ |
118 | 118 | $go = $this->config['site_url']; |
119 | - }else{ |
|
119 | + } else{ |
|
120 | 120 | $go = $this->config['site_url'].ltrim($go, '/'); |
121 | 121 | } |
122 | 122 | $this->moveTo(array('url' => $go)); |
123 | - }else{ |
|
123 | + } else{ |
|
124 | 124 | //Если юзер не авторизован, то показываем ему 404 ошибку |
125 | 125 | $this->modx->sendErrorPage(); |
126 | 126 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | if(!empty($homeID)){ |
169 | 169 | $dataTPL['url.profile'] = $this->makeUrl($homeID); |
170 | 170 | } |
171 | - }else{ |
|
171 | + } else{ |
|
172 | 172 | $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
173 | 173 | if(empty($tpl)){ |
174 | 174 | $tpl = $this->getTemplate('authForm'); |
@@ -218,12 +218,12 @@ discard block |
||
218 | 218 | * Thank you for super protection against hacking in protect.inc.php:-) |
219 | 219 | */ |
220 | 220 | $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
221 | - }else{ |
|
221 | + } else{ |
|
222 | 222 | $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
223 | 223 | if(empty( $request['host']) || $request['host']==$selfHost){ |
224 | 224 | $query = !empty($request['query']) ? '?'.$request['query'] : ''; |
225 | 225 | $refer = !empty($request['path']) ? $request['path'].$query : ''; |
226 | - }else{ |
|
226 | + } else{ |
|
227 | 227 | $refer = ''; |
228 | 228 | } |
229 | 229 | } |
@@ -232,21 +232,21 @@ discard block |
||
232 | 232 | $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
233 | 233 | if(!is_scalar($backUrl)){ |
234 | 234 | $backUrl = $refer; |
235 | - }else{ |
|
235 | + } else{ |
|
236 | 236 | $backUrl = urldecode($backUrl); |
237 | 237 | } |
238 | - }else{ |
|
238 | + } else{ |
|
239 | 239 | $backUrl = $refer; |
240 | 240 | } |
241 | 241 | $backUrl = parse_url($backUrl); |
242 | 242 | if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){ |
243 | 243 | $POST['backUrl'] = $backUrl['path']; |
244 | - }else{ |
|
244 | + } else{ |
|
245 | 245 | $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/'); |
246 | 246 | if(empty($backUrl['host']) || $backUrl['host']==$selfHost){ |
247 | 247 | $query = !empty($backUrl['query']) ? '?'.$backUrl['query'] : ''; |
248 | 248 | $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : ''; |
249 | - }else{ |
|
249 | + } else{ |
|
250 | 250 | $POST['backUrl'] = ''; |
251 | 251 | } |
252 | 252 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | 'url' => '/'.ltrim($POST['backUrl'], '/'), |
256 | 256 | 'validate' => true |
257 | 257 | )); |
258 | - }else{ |
|
258 | + } else{ |
|
259 | 259 | $idURL = 0; |
260 | 260 | } |
261 | 261 | if(empty($idURL)){ |
@@ -320,16 +320,16 @@ discard block |
||
320 | 320 | "rememberme" => $POST['remember'], |
321 | 321 | )); |
322 | 322 | $this->moveTo(array('url' => urldecode($POST['backUrl']))); |
323 | - }else{ |
|
323 | + } else{ |
|
324 | 324 | $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1); |
325 | 325 | $userObj->save(false, false); |
326 | 326 | |
327 | 327 | $error = 'error.incorrect_password'; |
328 | 328 | } |
329 | - }else{ |
|
329 | + } else{ |
|
330 | 330 | $error = 'error.no_user'; |
331 | 331 | } |
332 | - }else{ |
|
332 | + } else{ |
|
333 | 333 | $error = 'error.incorrect_mail'; |
334 | 334 | $POST['email'] = ''; |
335 | 335 | } |
@@ -421,10 +421,10 @@ discard block |
||
421 | 421 | if(empty($out)){ |
422 | 422 | $uri = ''; |
423 | 423 | } |
424 | - }else{ |
|
424 | + } else{ |
|
425 | 425 | $uri = APIhelpers::sanitarTag($uri); |
426 | 426 | } |
427 | - }else{ |
|
427 | + } else{ |
|
428 | 428 | //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
429 | 429 | header("Location: ".$uri, true, ($code>0 ? $code : 307)); |
430 | 430 | } |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | } |
445 | 445 | if($this->url->containsKey($id)){ |
446 | 446 | $url = $this->url->get($id); |
447 | - }else{ |
|
447 | + } else{ |
|
448 | 448 | $url = $this->modx->makeUrl($id); |
449 | 449 | $this->url->set($id, $url); |
450 | 450 | } |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | static::$langDic[$lang] = include_once($file); |
468 | 468 | if(is_array(static::$langDic[$lang])){ |
469 | 469 | static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
470 | - }else{ |
|
470 | + } else{ |
|
471 | 471 | static::$langDic[$lang] = array(); |
472 | 472 | } |
473 | 473 | } |
@@ -394,6 +394,12 @@ discard block |
||
394 | 394 | } |
395 | 395 | |
396 | 396 | |
397 | + /** |
|
398 | + * @param string $table |
|
399 | + * @param string $alias |
|
400 | + * |
|
401 | + * @return string |
|
402 | + */ |
|
397 | 403 | public function TableAlias($name, $table, $alias) |
398 | 404 | { |
399 | 405 | if (!$this->checkTableAlias($name, $table)) { |
@@ -451,7 +457,7 @@ discard block |
||
451 | 457 | /** |
452 | 458 | * Разбор JSON строки при помощи json_decode |
453 | 459 | * |
454 | - * @param $json string строка c JSON |
|
460 | + * @param string $json string строка c JSON |
|
455 | 461 | * @param array $config ассоциативный массив с настройками для json_decode |
456 | 462 | * @param bool $nop создавать ли пустой объект запрашиваемого типа |
457 | 463 | * @return array|mixed|xNop |
@@ -526,7 +532,7 @@ discard block |
||
526 | 532 | * Удаление определенных данных из массива |
527 | 533 | * |
528 | 534 | * @param array $data массив с данными |
529 | - * @param mixed $val значение которые необходимо удалить из массива |
|
535 | + * @param string $val значение которые необходимо удалить из массива |
|
530 | 536 | * @return array отчищеный массив с данными |
531 | 537 | */ |
532 | 538 | private function unsetArrayVal($data, $val) |
@@ -824,7 +830,7 @@ discard block |
||
824 | 830 | /** |
825 | 831 | * Получение строки из языкового пакета |
826 | 832 | * |
827 | - * @param $name имя записи в языковом пакете |
|
833 | + * @param string $name имя записи в языковом пакете |
|
828 | 834 | * @param string $def Строка по умолчанию, если запись в языковом пакете не будет обнаружена |
829 | 835 | * @return string строка в соответствии с текущими языковыми настройками |
830 | 836 | */ |
@@ -1113,6 +1119,9 @@ discard block |
||
1113 | 1119 | return $this->outData; |
1114 | 1120 | } |
1115 | 1121 | |
1122 | + /** |
|
1123 | + * @param summary_DL_Extender $extSummary |
|
1124 | + */ |
|
1116 | 1125 | protected function getSummary(array $item = array(), $extSummary = null, $introField = '', $contentField = '') |
1117 | 1126 | { |
1118 | 1127 | $out = ''; |
@@ -1159,7 +1168,7 @@ discard block |
||
1159 | 1168 | /** |
1160 | 1169 | * Вытащить экземпляр класса экстендера из общего массива экстендеров |
1161 | 1170 | * |
1162 | - * @param $name имя экстендера |
|
1171 | + * @param string $name имя экстендера |
|
1163 | 1172 | * @param bool $autoload Если экстендер не загружен, то пытаться ли его загрузить |
1164 | 1173 | * @param bool $nop если экстендер не загружен, то загружать ли xNop |
1165 | 1174 | * @return null|xNop |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | protected $idField = 'id'; |
108 | 108 | |
109 | 109 | /** |
110 | - * Parent Key основной таблицы |
|
111 | - * @var string |
|
112 | - * @access protected |
|
113 | - */ |
|
110 | + * Parent Key основной таблицы |
|
111 | + * @var string |
|
112 | + * @access protected |
|
113 | + */ |
|
114 | 114 | protected $parentField = 'parent'; |
115 | 115 | /** |
116 | 116 | * Дополнительные условия для SQL запросов |
@@ -168,18 +168,18 @@ discard block |
||
168 | 168 | |
169 | 169 | public $FS = null; |
170 | 170 | /** @var string результатирующая строка которая была последний раз сгенирирована |
171 | - * вызовами методов DocLister::render и DocLister::getJSON |
|
172 | - */ |
|
171 | + * вызовами методов DocLister::render и DocLister::getJSON |
|
172 | + */ |
|
173 | 173 | protected $outData = ''; |
174 | 174 | |
175 | - /** @var int Число документов, которые были отфильтрованы через prepare при выводе */ |
|
176 | - public $skippedDocs = 0; |
|
175 | + /** @var int Число документов, которые были отфильтрованы через prepare при выводе */ |
|
176 | + public $skippedDocs = 0; |
|
177 | 177 | |
178 | - /** @var string Имя таблицы */ |
|
179 | - protected $table = ''; |
|
178 | + /** @var string Имя таблицы */ |
|
179 | + protected $table = ''; |
|
180 | 180 | |
181 | - /** @var null|paginate_DL_Extender */ |
|
182 | - protected $extPaginate = null; |
|
181 | + /** @var null|paginate_DL_Extender */ |
|
182 | + protected $extPaginate = null; |
|
183 | 183 | /** |
184 | 184 | * Конструктор контроллеров DocLister |
185 | 185 | * |
@@ -191,30 +191,30 @@ discard block |
||
191 | 191 | { |
192 | 192 | $this->setTimeStart($startTime); |
193 | 193 | |
194 | - if (extension_loaded('mbstring')) { |
|
195 | - mb_internal_encoding("UTF-8"); |
|
196 | - } else { |
|
197 | - throw new Exception('Not found php extension mbstring'); |
|
198 | - } |
|
194 | + if (extension_loaded('mbstring')) { |
|
195 | + mb_internal_encoding("UTF-8"); |
|
196 | + } else { |
|
197 | + throw new Exception('Not found php extension mbstring'); |
|
198 | + } |
|
199 | 199 | |
200 | 200 | if ($modx instanceof DocumentParser) { |
201 | - $this->modx = $modx; |
|
201 | + $this->modx = $modx; |
|
202 | 202 | $this->setDebug(1); |
203 | 203 | $this->loadLang(array('core', 'json')); |
204 | 204 | |
205 | 205 | if (!is_array($cfg) || empty($cfg)) $cfg = $this->modx->Event->params; |
206 | - } else { |
|
207 | - throw new Exception('MODX var is not instaceof DocumentParser'); |
|
208 | - } |
|
206 | + } else { |
|
207 | + throw new Exception('MODX var is not instaceof DocumentParser'); |
|
208 | + } |
|
209 | 209 | |
210 | 210 | $this->FS = \Helpers\FS::getInstance(); |
211 | 211 | if (isset($cfg['config'])) { |
212 | - $cfg = array_merge($this->loadConfig($cfg['config']), $cfg); |
|
213 | - } |
|
212 | + $cfg = array_merge($this->loadConfig($cfg['config']), $cfg); |
|
213 | + } |
|
214 | 214 | |
215 | - if (!$this->setConfig($cfg)) { |
|
216 | - throw new Exception('no parameters to run DocLister'); |
|
217 | - } |
|
215 | + if (!$this->setConfig($cfg)) { |
|
216 | + throw new Exception('no parameters to run DocLister'); |
|
217 | + } |
|
218 | 218 | |
219 | 219 | $this->setDebug($this->getCFGDef('debug', 0)); |
220 | 220 | |
@@ -262,48 +262,48 @@ discard block |
||
262 | 262 | |
263 | 263 | /** |
264 | 264 | * Разбиение фильтра на субфильтры с учётом вложенности |
265 | - * @param string $str строка с фильтром |
|
265 | + * @param string $str строка с фильтром |
|
266 | 266 | * @return array массив субфильтров |
267 | 267 | */ |
268 | - public function smartSplit($str){ |
|
269 | - $res = array(); |
|
270 | - $cur = ''; |
|
271 | - $open = 0; |
|
272 | - $strlen = mb_strlen($str, 'UTF-8'); |
|
273 | - for($i=0;$i<=$strlen;$i++){ |
|
274 | - $e = mb_substr($str, $i, 1, 'UTF-8'); |
|
275 | - switch($e){ |
|
276 | - case ')': |
|
277 | - $open--; |
|
278 | - if($open == 0){ |
|
279 | - $res[] = $cur.')'; |
|
280 | - $cur = ''; |
|
281 | - } else { |
|
282 | - $cur .= $e; |
|
283 | - } |
|
284 | - break; |
|
285 | - case '(': |
|
286 | - $open++; |
|
287 | - $cur .= $e; |
|
288 | - break; |
|
289 | - case ';': |
|
290 | - if($open == 0){ |
|
291 | - $res[] = $cur; |
|
292 | - $cur = ''; |
|
293 | - } else { |
|
294 | - $cur .= $e; |
|
295 | - } |
|
296 | - break; |
|
297 | - default: |
|
298 | - $cur .= $e; |
|
299 | - } |
|
300 | - } |
|
301 | - $cur = preg_replace("/(\))$/u", '', $cur); |
|
302 | - if ($cur != ''){ |
|
303 | - $res[] = $cur; |
|
304 | - } |
|
305 | - return $res; |
|
306 | - } |
|
268 | + public function smartSplit($str){ |
|
269 | + $res = array(); |
|
270 | + $cur = ''; |
|
271 | + $open = 0; |
|
272 | + $strlen = mb_strlen($str, 'UTF-8'); |
|
273 | + for($i=0;$i<=$strlen;$i++){ |
|
274 | + $e = mb_substr($str, $i, 1, 'UTF-8'); |
|
275 | + switch($e){ |
|
276 | + case ')': |
|
277 | + $open--; |
|
278 | + if($open == 0){ |
|
279 | + $res[] = $cur.')'; |
|
280 | + $cur = ''; |
|
281 | + } else { |
|
282 | + $cur .= $e; |
|
283 | + } |
|
284 | + break; |
|
285 | + case '(': |
|
286 | + $open++; |
|
287 | + $cur .= $e; |
|
288 | + break; |
|
289 | + case ';': |
|
290 | + if($open == 0){ |
|
291 | + $res[] = $cur; |
|
292 | + $cur = ''; |
|
293 | + } else { |
|
294 | + $cur .= $e; |
|
295 | + } |
|
296 | + break; |
|
297 | + default: |
|
298 | + $cur .= $e; |
|
299 | + } |
|
300 | + } |
|
301 | + $cur = preg_replace("/(\))$/u", '', $cur); |
|
302 | + if ($cur != ''){ |
|
303 | + $res[] = $cur; |
|
304 | + } |
|
305 | + return $res; |
|
306 | + } |
|
307 | 307 | |
308 | 308 | /** |
309 | 309 | * Трансформация объекта в строку |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | $flag = true; |
492 | 492 | $extenders = $this->getCFGDef('extender', ''); |
493 | 493 | $extenders = explode(",", $extenders); |
494 | - if (($this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders)) && !$this->_loadExtender('request')) { //OR request in extender's parameter |
|
494 | + if (($this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders)) && !$this->_loadExtender('request')) { //OR request in extender's parameter |
|
495 | 495 | throw new Exception('Error load request extender'); |
496 | 496 | } |
497 | 497 | |
@@ -595,17 +595,17 @@ discard block |
||
595 | 595 | ****************** CORE Block ********************* |
596 | 596 | ***************************************************/ |
597 | 597 | |
598 | - /** |
|
599 | - * Определение ID страницы открытой во фронте |
|
600 | - * |
|
601 | - * @return int |
|
602 | - */ |
|
603 | - public function getCurrentMODXPageID(){ |
|
604 | - $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
|
605 | - $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array(); |
|
598 | + /** |
|
599 | + * Определение ID страницы открытой во фронте |
|
600 | + * |
|
601 | + * @return int |
|
602 | + */ |
|
603 | + public function getCurrentMODXPageID(){ |
|
604 | + $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
|
605 | + $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array(); |
|
606 | 606 | |
607 | - return empty($id) ? \APIHelpers::getkey($docData, 'id', 0) : $id; |
|
608 | - } |
|
607 | + return empty($id) ? \APIHelpers::getkey($docData, 'id', 0) : $id; |
|
608 | + } |
|
609 | 609 | |
610 | 610 | /** |
611 | 611 | * Display and save error information |
@@ -653,14 +653,14 @@ discard block |
||
653 | 653 | $ext = explode(",", $ext); |
654 | 654 | foreach ($ext as $item) { |
655 | 655 | if ($item != '' && !$this->_loadExtender($item)) { |
656 | - throw new Exception('Error load ' . APIHelpers::e($item) . ' extender'); |
|
657 | - } |
|
656 | + throw new Exception('Error load ' . APIHelpers::e($item) . ' extender'); |
|
657 | + } |
|
658 | 658 | } |
659 | 659 | } |
660 | 660 | return $out; |
661 | 661 | } |
662 | 662 | |
663 | - /** |
|
663 | + /** |
|
664 | 664 | * Получение всего списка настроек |
665 | 665 | * @return array |
666 | 666 | */ |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | */ |
677 | 677 | public function setConfig($cfg) |
678 | 678 | { |
679 | - if (is_array($cfg)) { |
|
679 | + if (is_array($cfg)) { |
|
680 | 680 | $this->_cfg = array_merge($this->_cfg, $cfg); |
681 | 681 | $ret = count($this->_cfg); |
682 | 682 | } else { |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | return $ret; |
686 | 686 | } |
687 | 687 | |
688 | - /** |
|
688 | + /** |
|
689 | 689 | * Полная перезапись настроек вызова сниппета |
690 | 690 | * @param array $cfg массив настроек |
691 | 691 | * @return int Общее число новых настроек |
@@ -693,9 +693,9 @@ discard block |
||
693 | 693 | public function replaceConfig($cfg) |
694 | 694 | { |
695 | 695 | if (!is_array($cfg)) { |
696 | - $cfg = array(); |
|
696 | + $cfg = array(); |
|
697 | 697 | } |
698 | - $this->_cfg = $cfg; |
|
698 | + $this->_cfg = $cfg; |
|
699 | 699 | return count($this->_cfg); |
700 | 700 | } |
701 | 701 | |
@@ -979,21 +979,21 @@ discard block |
||
979 | 979 | */ |
980 | 980 | public function renderWrap($data){ |
981 | 981 | $out = $data; |
982 | - $docs = count($this->_docs) - $this->skippedDocs; |
|
983 | - if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
|
982 | + $docs = count($this->_docs) - $this->skippedDocs; |
|
983 | + if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
|
984 | 984 | $this->debug->debug("","renderWrapTPL",2); |
985 | 985 | $parse = true; |
986 | 986 | $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data); |
987 | 987 | /** |
988 | - * @var $extPrepare prepare_DL_Extender |
|
989 | - */ |
|
988 | + * @var $extPrepare prepare_DL_Extender |
|
989 | + */ |
|
990 | 990 | $extPrepare = $this->getExtender('prepare'); |
991 | 991 | if ($extPrepare) { |
992 | 992 | $params = $extPrepare->init($this, array( |
993 | 993 | 'data' => array( |
994 | - 'docs' => $this->_docs, |
|
995 | - 'placeholders' => $plh |
|
996 | - ), |
|
994 | + 'docs' => $this->_docs, |
|
995 | + 'placeholders' => $plh |
|
996 | + ), |
|
997 | 997 | 'nameParam' => 'prepareWrap', |
998 | 998 | 'return' => 'placeholders' |
999 | 999 | )); |
@@ -1019,12 +1019,12 @@ discard block |
||
1019 | 1019 | return $out; |
1020 | 1020 | } |
1021 | 1021 | /** |
1022 | - * Единые обработки массива с данными о документе для всех контроллеров |
|
1023 | - * |
|
1024 | - * @param array $data массив с данными о текущем документе |
|
1025 | - * @param int $i номер итерации в цикле |
|
1026 | - * @return array массив с данными которые можно использовать в цикле render метода |
|
1027 | - */ |
|
1022 | + * Единые обработки массива с данными о документе для всех контроллеров |
|
1023 | + * |
|
1024 | + * @param array $data массив с данными о текущем документе |
|
1025 | + * @param int $i номер итерации в цикле |
|
1026 | + * @return array массив с данными которые можно использовать в цикле render метода |
|
1027 | + */ |
|
1028 | 1028 | protected function uniformPrepare(&$data, $i=0){ |
1029 | 1029 | $class = array(); |
1030 | 1030 | |
@@ -1057,8 +1057,8 @@ discard block |
||
1057 | 1057 | $data[$this->getCFGDef("sysKey", "dl") . '.class'] = $class; |
1058 | 1058 | |
1059 | 1059 | /** |
1060 | - * @var $extE e_DL_Extender |
|
1061 | - */ |
|
1060 | + * @var $extE e_DL_Extender |
|
1061 | + */ |
|
1062 | 1062 | $extE = $this->getExtender('e', true, true); |
1063 | 1063 | if($out = $extE->init($this, compact('data'))){ |
1064 | 1064 | if(is_array($out)){ |
@@ -1296,7 +1296,7 @@ discard block |
||
1296 | 1296 | return $out; |
1297 | 1297 | } |
1298 | 1298 | |
1299 | - public function docsCollection(){ |
|
1299 | + public function docsCollection(){ |
|
1300 | 1300 | return new DLCollection($this->modx, $this->_docs); |
1301 | 1301 | } |
1302 | 1302 | |
@@ -1363,10 +1363,10 @@ discard block |
||
1363 | 1363 | switch (true) { |
1364 | 1364 | case ('' != ($tmp = $this->getCFGDef('sortDir', ''))): //higher priority than order |
1365 | 1365 | $out['order'] = $tmp; |
1366 | - // no break |
|
1366 | + // no break |
|
1367 | 1367 | case ('' != ($tmp = $this->getCFGDef('order', ''))): |
1368 | 1368 | $out['order'] = $tmp; |
1369 | - // no break |
|
1369 | + // no break |
|
1370 | 1370 | } |
1371 | 1371 | if ('' == $out['order'] || !in_array(strtoupper($out['order']), array('ASC', 'DESC'))) { |
1372 | 1372 | $out['order'] = $orderDef; //Default |
@@ -1487,10 +1487,10 @@ discard block |
||
1487 | 1487 | } |
1488 | 1488 | |
1489 | 1489 | /** |
1490 | - * Получение Parent key |
|
1491 | - * По умолчанию это parent. Переопределить можно в контроллере присвоив другое значение переменной parentField |
|
1492 | - * @return string Parent Key основной таблицы |
|
1493 | - */ |
|
1490 | + * Получение Parent key |
|
1491 | + * По умолчанию это parent. Переопределить можно в контроллере присвоив другое значение переменной parentField |
|
1492 | + * @return string Parent Key основной таблицы |
|
1493 | + */ |
|
1494 | 1494 | public function getParentField(){ |
1495 | 1495 | return isset($this->parentField) ? $this->parentField : ''; |
1496 | 1496 | } |
@@ -1509,7 +1509,7 @@ discard block |
||
1509 | 1509 | if (!$filter_string) return; |
1510 | 1510 | $output = array('join' => '', 'where' => ''); |
1511 | 1511 | $logic_op_found = false; |
1512 | - $joins = $wheres = array(); |
|
1512 | + $joins = $wheres = array(); |
|
1513 | 1513 | foreach ($this->_logic_ops as $op => $sql) { |
1514 | 1514 | if (strpos($filter_string, $op) === 0) { |
1515 | 1515 | $logic_op_found = true; |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | * @TODO depending on the parameters |
18 | 18 | * @TODO prepare value before return final data (maybe callback function OR extender) |
19 | 19 | */ |
20 | -include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
|
21 | -include_once(MODX_BASE_PATH . 'assets/lib/Helpers/FS.php'); |
|
22 | -require_once(dirname(dirname(__FILE__)) . "/lib/jsonHelper.class.php"); |
|
23 | -require_once(dirname(dirname(__FILE__)) . "/lib/sqlHelper.class.php"); |
|
24 | -require_once(dirname(dirname(__FILE__)) . "/lib/DLTemplate.class.php"); |
|
25 | -require_once(dirname(dirname(__FILE__)) . "/lib/DLCollection.class.php"); |
|
26 | -require_once(dirname(dirname(__FILE__)) . "/lib/xnop.class.php"); |
|
20 | +include_once(MODX_BASE_PATH.'assets/lib/APIHelpers.class.php'); |
|
21 | +include_once(MODX_BASE_PATH.'assets/lib/Helpers/FS.php'); |
|
22 | +require_once(dirname(dirname(__FILE__))."/lib/jsonHelper.class.php"); |
|
23 | +require_once(dirname(dirname(__FILE__))."/lib/sqlHelper.class.php"); |
|
24 | +require_once(dirname(dirname(__FILE__))."/lib/DLTemplate.class.php"); |
|
25 | +require_once(dirname(dirname(__FILE__))."/lib/DLCollection.class.php"); |
|
26 | +require_once(dirname(dirname(__FILE__))."/lib/xnop.class.php"); |
|
27 | 27 | |
28 | 28 | abstract class DocLister |
29 | 29 | { |
@@ -265,17 +265,17 @@ discard block |
||
265 | 265 | * @param string $str строка с фильтром |
266 | 266 | * @return array массив субфильтров |
267 | 267 | */ |
268 | - public function smartSplit($str){ |
|
268 | + public function smartSplit($str) { |
|
269 | 269 | $res = array(); |
270 | 270 | $cur = ''; |
271 | 271 | $open = 0; |
272 | 272 | $strlen = mb_strlen($str, 'UTF-8'); |
273 | - for($i=0;$i<=$strlen;$i++){ |
|
273 | + for ($i = 0; $i <= $strlen; $i++) { |
|
274 | 274 | $e = mb_substr($str, $i, 1, 'UTF-8'); |
275 | - switch($e){ |
|
275 | + switch ($e) { |
|
276 | 276 | case ')': |
277 | 277 | $open--; |
278 | - if($open == 0){ |
|
278 | + if ($open == 0) { |
|
279 | 279 | $res[] = $cur.')'; |
280 | 280 | $cur = ''; |
281 | 281 | } else { |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | $cur .= $e; |
288 | 288 | break; |
289 | 289 | case ';': |
290 | - if($open == 0){ |
|
290 | + if ($open == 0) { |
|
291 | 291 | $res[] = $cur; |
292 | 292 | $cur = ''; |
293 | 293 | } else { |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | } |
300 | 300 | } |
301 | 301 | $cur = preg_replace("/(\))$/u", '', $cur); |
302 | - if ($cur != ''){ |
|
302 | + if ($cur != '') { |
|
303 | 303 | $res[] = $cur; |
304 | 304 | } |
305 | 305 | return $res; |
@@ -349,8 +349,8 @@ discard block |
||
349 | 349 | ini_set('display_errors', 1); |
350 | 350 | } |
351 | 351 | $dir = dirname(dirname(__FILE__)); |
352 | - if (file_exists($dir . "/lib/DLdebug.class.php")) { |
|
353 | - include_once($dir . "/lib/DLdebug.class.php"); |
|
352 | + if (file_exists($dir."/lib/DLdebug.class.php")) { |
|
353 | + include_once($dir."/lib/DLdebug.class.php"); |
|
354 | 354 | if (class_exists("DLdebug", false)) { |
355 | 355 | $this->debug = new DLdebug($this); |
356 | 356 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | } |
389 | 389 | $table = $this->_table[$name]; |
390 | 390 | if (!empty($alias) && is_scalar($alias)) { |
391 | - $table .= " as `" . $alias . "`"; |
|
391 | + $table .= " as `".$alias."`"; |
|
392 | 392 | } |
393 | 393 | return $table; |
394 | 394 | } |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | */ |
416 | 416 | public function loadConfig($name) |
417 | 417 | { |
418 | - $this->debug->debug('Load json config: ' . $this->debug->dumpData($name), 'loadconfig', 2); |
|
418 | + $this->debug->debug('Load json config: '.$this->debug->dumpData($name), 'loadconfig', 2); |
|
419 | 419 | if (!is_scalar($name)) { |
420 | 420 | $name = ''; |
421 | 421 | } |
@@ -427,13 +427,13 @@ discard block |
||
427 | 427 | $cfgName[1] = 'custom'; |
428 | 428 | } |
429 | 429 | $cfgName[1] = rtrim($cfgName[1], '/'); |
430 | - switch($cfgName[1]){ |
|
430 | + switch ($cfgName[1]) { |
|
431 | 431 | case 'custom': |
432 | 432 | case 'core': |
433 | - $configFile = dirname(dirname(__FILE__)) . "/config/{$cfgName[1]}/{$cfgName[0]}.json"; |
|
433 | + $configFile = dirname(dirname(__FILE__))."/config/{$cfgName[1]}/{$cfgName[0]}.json"; |
|
434 | 434 | break; |
435 | 435 | default: |
436 | - $configFile = $this->FS->relativePath( $cfgName[1] . '/' . $cfgName[0] . ".json"); |
|
436 | + $configFile = $this->FS->relativePath($cfgName[1].'/'.$cfgName[0].".json"); |
|
437 | 437 | break; |
438 | 438 | } |
439 | 439 | |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | */ |
459 | 459 | public function jsonDecode($json, $config = array(), $nop = false) |
460 | 460 | { |
461 | - $this->debug->debug('Decode JSON: ' . $this->debug->dumpData($json) . "\r\nwith config: " . $this->debug->dumpData($config), 'jsonDecode', 2); |
|
461 | + $this->debug->debug('Decode JSON: '.$this->debug->dumpData($json)."\r\nwith config: ".$this->debug->dumpData($config), 'jsonDecode', 2); |
|
462 | 462 | $config = jsonHelper::jsonDecode($json, $config, $nop); |
463 | 463 | $this->isErrorJSON($json); |
464 | 464 | $this->debug->debugEnd("jsonDecode"); |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | { |
476 | 476 | $error = jsonHelper::json_last_error_msg(); |
477 | 477 | if (!in_array($error, array('error_none', 'other'))) { |
478 | - $this->debug->error($this->getMsg('json.' . $error) . ": " . $this->debug->dumpData($json, 'code'), 'JSON'); |
|
478 | + $this->debug->error($this->getMsg('json.'.$error).": ".$this->debug->dumpData($json, 'code'), 'JSON'); |
|
479 | 479 | $error = true; |
480 | 480 | } |
481 | 481 | return $error; |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | * |
601 | 601 | * @return int |
602 | 602 | */ |
603 | - public function getCurrentMODXPageID(){ |
|
603 | + public function getCurrentMODXPageID() { |
|
604 | 604 | $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
605 | 605 | $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array(); |
606 | 606 | |
@@ -621,8 +621,8 @@ discard block |
||
621 | 621 | public function ErrorLogger($message, $code, $file, $line, $trace) |
622 | 622 | { |
623 | 623 | if (abs($this->getCFGDef('debug', '0')) == '1') { |
624 | - echo "CODE #" . $code . "<br />"; |
|
625 | - echo "on file: " . $file . ":" . $line . "<br />"; |
|
624 | + echo "CODE #".$code."<br />"; |
|
625 | + echo "on file: ".$file.":".$line."<br />"; |
|
626 | 626 | echo "<pre>"; |
627 | 627 | var_dump($trace); |
628 | 628 | echo "</pre>"; |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | $ext = explode(",", $ext); |
654 | 654 | foreach ($ext as $item) { |
655 | 655 | if ($item != '' && !$this->_loadExtender($item)) { |
656 | - throw new Exception('Error load ' . APIHelpers::e($item) . ' extender'); |
|
656 | + throw new Exception('Error load '.APIHelpers::e($item).' extender'); |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | } |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id); |
732 | 732 | |
733 | 733 | $this->debug->debugEnd( |
734 | - "toPlaceholders", array($key ." placeholder" => $data), array('html') |
|
734 | + "toPlaceholders", array($key." placeholder" => $data), array('html') |
|
735 | 735 | ); |
736 | 736 | return $out; |
737 | 737 | } |
@@ -753,12 +753,12 @@ discard block |
||
753 | 753 | } |
754 | 754 | $out = array(); |
755 | 755 | foreach ($data as $item) { |
756 | - if($item !== ''){ |
|
756 | + if ($item !== '') { |
|
757 | 757 | $out[] = $this->modx->db->escape($item); |
758 | 758 | } |
759 | 759 | } |
760 | 760 | $q = $quote ? "'" : ""; |
761 | - $out = $q . implode($q . "," . $q, $out) . $q; |
|
761 | + $out = $q.implode($q.",".$q, $out).$q; |
|
762 | 762 | return $out; |
763 | 763 | } |
764 | 764 | |
@@ -778,8 +778,8 @@ discard block |
||
778 | 778 | if (empty($lang)) { |
779 | 779 | $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']); |
780 | 780 | } |
781 | - if (file_exists(dirname(dirname(__FILE__)) . "/lang/" . $lang . ".php")) { |
|
782 | - $tmp = include(dirname(__FILE__) . "/lang/" . $lang . ".php"); |
|
781 | + if (file_exists(dirname(dirname(__FILE__))."/lang/".$lang.".php")) { |
|
782 | + $tmp = include(dirname(__FILE__)."/lang/".$lang.".php"); |
|
783 | 783 | $this->_customLang = is_array($tmp) ? $tmp : array(); |
784 | 784 | } |
785 | 785 | return $this->_customLang; |
@@ -799,13 +799,13 @@ discard block |
||
799 | 799 | $lang = $this->getCFGDef('lang', $this->modx->config['manager_language']); |
800 | 800 | } |
801 | 801 | |
802 | - $this->debug->debug('Load language ' . $this->debug->dumpData($name) . "." . $this->debug->dumpData($lang), 'loadlang', 2); |
|
802 | + $this->debug->debug('Load language '.$this->debug->dumpData($name).".".$this->debug->dumpData($lang), 'loadlang', 2); |
|
803 | 803 | if (is_scalar($name)) { |
804 | 804 | $name = array($name); |
805 | 805 | } |
806 | 806 | foreach ($name as $n) { |
807 | - if (file_exists(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php")) { |
|
808 | - $tmp = include(dirname(__FILE__) . "/lang/" . $lang . "/" . $n . ".inc.php"); |
|
807 | + if (file_exists(dirname(__FILE__)."/lang/".$lang."/".$n.".inc.php")) { |
|
808 | + $tmp = include(dirname(__FILE__)."/lang/".$lang."/".$n.".inc.php"); |
|
809 | 809 | if (is_array($tmp)) { |
810 | 810 | /** |
811 | 811 | * Переименовыываем элементы массива из array('test'=>'data') в array('name.test'=>'data') |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | } |
886 | 886 | } |
887 | 887 | |
888 | - $data[$this->getCFGDef("sysKey", "dl") . ".wrap"] = $this->renderWrap($out); |
|
888 | + $data[$this->getCFGDef("sysKey", "dl").".wrap"] = $this->renderWrap($out); |
|
889 | 889 | $out = $this->parseChunk($this->getCFGDef('tpl', ''), $data); |
890 | 890 | return $out; |
891 | 891 | } |
@@ -950,7 +950,7 @@ discard block |
||
950 | 950 | ); |
951 | 951 | $out = DLTemplate::getInstance($this->getMODX())->parseChunk($name, $data, $parseDocumentSource); |
952 | 952 | if (empty($out)) { |
953 | - $this->debug->debug("Empty chunk: " . $this->debug->dumpData($name), '', 2); |
|
953 | + $this->debug->debug("Empty chunk: ".$this->debug->dumpData($name), '', 2); |
|
954 | 954 | } |
955 | 955 | $this->debug->debugEnd("parseChunk"); |
956 | 956 | return $out; |
@@ -977,13 +977,13 @@ discard block |
||
977 | 977 | * @param string $data html код который нужно обернуть в ownerTPL |
978 | 978 | * @return string результатирующий html код |
979 | 979 | */ |
980 | - public function renderWrap($data){ |
|
980 | + public function renderWrap($data) { |
|
981 | 981 | $out = $data; |
982 | 982 | $docs = count($this->_docs) - $this->skippedDocs; |
983 | 983 | if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) { |
984 | - $this->debug->debug("","renderWrapTPL",2); |
|
984 | + $this->debug->debug("", "renderWrapTPL", 2); |
|
985 | 985 | $parse = true; |
986 | - $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data); |
|
986 | + $plh = array($this->getCFGDef("sysKey", "dl").".wrap" => $data); |
|
987 | 987 | /** |
988 | 988 | * @var $extPrepare prepare_DL_Extender |
989 | 989 | */ |
@@ -997,13 +997,13 @@ discard block |
||
997 | 997 | 'nameParam' => 'prepareWrap', |
998 | 998 | 'return' => 'placeholders' |
999 | 999 | )); |
1000 | - if (is_bool($params) && $params === false){ |
|
1000 | + if (is_bool($params) && $params === false) { |
|
1001 | 1001 | $out = $data; |
1002 | 1002 | $parse = false; |
1003 | 1003 | } |
1004 | 1004 | $plh = $params; |
1005 | 1005 | } |
1006 | - if($parse && !empty($this->ownerTPL)){ |
|
1006 | + if ($parse && !empty($this->ownerTPL)) { |
|
1007 | 1007 | $this->debug->updateMessage( |
1008 | 1008 | array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)), |
1009 | 1009 | "renderWrapTPL", |
@@ -1011,7 +1011,7 @@ discard block |
||
1011 | 1011 | ); |
1012 | 1012 | $out = $this->parseChunk($this->ownerTPL, $plh); |
1013 | 1013 | } |
1014 | - if(empty($this->ownerTPL)){ |
|
1014 | + if (empty($this->ownerTPL)) { |
|
1015 | 1015 | $this->debug->updateMessage("empty ownerTPL", "renderWrapTPL"); |
1016 | 1016 | } |
1017 | 1017 | $this->debug->debugEnd("renderWrapTPL"); |
@@ -1025,17 +1025,17 @@ discard block |
||
1025 | 1025 | * @param int $i номер итерации в цикле |
1026 | 1026 | * @return array массив с данными которые можно использовать в цикле render метода |
1027 | 1027 | */ |
1028 | - protected function uniformPrepare(&$data, $i=0){ |
|
1028 | + protected function uniformPrepare(&$data, $i = 0) { |
|
1029 | 1029 | $class = array(); |
1030 | 1030 | |
1031 | 1031 | $iterationName = ($i % 2 == 0) ? 'Odd' : 'Even'; |
1032 | 1032 | $tmp = strtolower($iterationName); |
1033 | 1033 | $class[] = $this->getCFGDef($tmp.'Class', $tmp); |
1034 | 1034 | |
1035 | - $this->renderTPL = $this->getCFGDef('tplId' . $i, $this->renderTPL); |
|
1036 | - $this->renderTPL = $this->getCFGDef('tpl' . $iterationName, $this->renderTPL); |
|
1035 | + $this->renderTPL = $this->getCFGDef('tplId'.$i, $this->renderTPL); |
|
1036 | + $this->renderTPL = $this->getCFGDef('tpl'.$iterationName, $this->renderTPL); |
|
1037 | 1037 | |
1038 | - $data[$this->getCFGDef("sysKey", "dl") . '.full_iteration'] = ($this->extPaginate) ? ($i + $this->getCFGDef('display', 0) * ($this->extPaginate->currentPage() - 1)) : $i; |
|
1038 | + $data[$this->getCFGDef("sysKey", "dl").'.full_iteration'] = ($this->extPaginate) ? ($i + $this->getCFGDef('display', 0) * ($this->extPaginate->currentPage() - 1)) : $i; |
|
1039 | 1039 | |
1040 | 1040 | if ($i == 1) { |
1041 | 1041 | $this->renderTPL = $this->getCFGDef('tplFirst', $this->renderTPL); |
@@ -1047,22 +1047,22 @@ discard block |
||
1047 | 1047 | } |
1048 | 1048 | if ($this->modx->documentIdentifier == $data['id']) { |
1049 | 1049 | $this->renderTPL = $this->getCFGDef('tplCurrent', $this->renderTPL); |
1050 | - $data[$this->getCFGDef("sysKey", "dl") . '.active'] = 1; //[+active+] - 1 if $modx->documentIdentifer equal ID this element |
|
1050 | + $data[$this->getCFGDef("sysKey", "dl").'.active'] = 1; //[+active+] - 1 if $modx->documentIdentifer equal ID this element |
|
1051 | 1051 | $class[] = $this->getCFGDef('currentClass', 'current'); |
1052 | 1052 | } else { |
1053 | - $data[$this->getCFGDef("sysKey", "dl") . '.active'] = 0; |
|
1053 | + $data[$this->getCFGDef("sysKey", "dl").'.active'] = 0; |
|
1054 | 1054 | } |
1055 | 1055 | |
1056 | 1056 | $class = implode(" ", $class); |
1057 | - $data[$this->getCFGDef("sysKey", "dl") . '.class'] = $class; |
|
1057 | + $data[$this->getCFGDef("sysKey", "dl").'.class'] = $class; |
|
1058 | 1058 | |
1059 | 1059 | /** |
1060 | 1060 | * @var $extE e_DL_Extender |
1061 | 1061 | */ |
1062 | 1062 | $extE = $this->getExtender('e', true, true); |
1063 | - if($out = $extE->init($this, compact('data'))){ |
|
1064 | - if(is_array($out)){ |
|
1065 | - $data = $out; |
|
1063 | + if ($out = $extE->init($this, compact('data'))) { |
|
1064 | + if (is_array($out)) { |
|
1065 | + $data = $out; |
|
1066 | 1066 | } |
1067 | 1067 | } |
1068 | 1068 | return compact('class', 'iterationName'); |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | */ |
1149 | 1149 | public function checkExtender($name) |
1150 | 1150 | { |
1151 | - return (isset($this->extender[$name]) && $this->extender[$name] instanceof $name . "_DL_Extender"); |
|
1151 | + return (isset($this->extender[$name]) && $this->extender[$name] instanceof $name."_DL_Extender"); |
|
1152 | 1152 | } |
1153 | 1153 | |
1154 | 1154 | public function setExtender($name, $obj) |
@@ -1184,17 +1184,17 @@ discard block |
||
1184 | 1184 | */ |
1185 | 1185 | protected function _loadExtender($name) |
1186 | 1186 | { |
1187 | - $this->debug->debug('Load Extender ' . $this->debug->dumpData($name), 'LoadExtender', 2); |
|
1187 | + $this->debug->debug('Load Extender '.$this->debug->dumpData($name), 'LoadExtender', 2); |
|
1188 | 1188 | $flag = false; |
1189 | 1189 | |
1190 | - $classname = ($name != '') ? $name . "_DL_Extender" : ""; |
|
1190 | + $classname = ($name != '') ? $name."_DL_Extender" : ""; |
|
1191 | 1191 | if ($classname != '' && isset($this->extender[$name]) && $this->extender[$name] instanceof $classname) { |
1192 | 1192 | $flag = true; |
1193 | 1193 | |
1194 | 1194 | } else { |
1195 | 1195 | if (!class_exists($classname, false) && $classname != '') { |
1196 | - if (file_exists(dirname(__FILE__) . "/extender/" . $name . ".extender.inc")) { |
|
1197 | - include_once(dirname(__FILE__) . "/extender/" . $name . ".extender.inc"); |
|
1196 | + if (file_exists(dirname(__FILE__)."/extender/".$name.".extender.inc")) { |
|
1197 | + include_once(dirname(__FILE__)."/extender/".$name.".extender.inc"); |
|
1198 | 1198 | } |
1199 | 1199 | } |
1200 | 1200 | if (class_exists($classname, false) && $classname != '') { |
@@ -1203,7 +1203,7 @@ discard block |
||
1203 | 1203 | } |
1204 | 1204 | } |
1205 | 1205 | if (!$flag) { |
1206 | - $this->debug->debug("Error load Extender " . $this->debug->dumpData($name)); |
|
1206 | + $this->debug->debug("Error load Extender ".$this->debug->dumpData($name)); |
|
1207 | 1207 | } |
1208 | 1208 | $this->debug->debugEnd('LoadExtender'); |
1209 | 1209 | return $flag; |
@@ -1221,7 +1221,7 @@ discard block |
||
1221 | 1221 | */ |
1222 | 1222 | public function setIDs($IDs) |
1223 | 1223 | { |
1224 | - $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2); |
|
1224 | + $this->debug->debug('set ID list '.$this->debug->dumpData($IDs), 'setIDs', 2); |
|
1225 | 1225 | $IDs = $this->cleanIDs($IDs); |
1226 | 1226 | $type = $this->getCFGDef('idType', 'parents'); |
1227 | 1227 | $depth = $this->getCFGDef('depth', ''); |
@@ -1252,7 +1252,7 @@ discard block |
||
1252 | 1252 | */ |
1253 | 1253 | public function cleanIDs($IDs, $sep = ',') |
1254 | 1254 | { |
1255 | - $this->debug->debug('clean IDs ' . $this->debug->dumpData($IDs) . ' with separator ' . $this->debug->dumpData($sep), 'cleanIDs', 2); |
|
1255 | + $this->debug->debug('clean IDs '.$this->debug->dumpData($IDs).' with separator '.$this->debug->dumpData($sep), 'cleanIDs', 2); |
|
1256 | 1256 | $out = array(); |
1257 | 1257 | if (!is_array($IDs)) { |
1258 | 1258 | $IDs = explode($sep, $IDs); |
@@ -1296,7 +1296,7 @@ discard block |
||
1296 | 1296 | return $out; |
1297 | 1297 | } |
1298 | 1298 | |
1299 | - public function docsCollection(){ |
|
1299 | + public function docsCollection() { |
|
1300 | 1300 | return new DLCollection($this->modx, $this->_docs); |
1301 | 1301 | } |
1302 | 1302 | |
@@ -1324,7 +1324,7 @@ discard block |
||
1324 | 1324 | { |
1325 | 1325 | $out = ''; |
1326 | 1326 | if ($group != '') { |
1327 | - $out = 'GROUP BY ' . $group; |
|
1327 | + $out = 'GROUP BY '.$group; |
|
1328 | 1328 | } |
1329 | 1329 | return $out; |
1330 | 1330 | } |
@@ -1353,7 +1353,7 @@ discard block |
||
1353 | 1353 | $idList = $this->sanitarIn($this->IDs, ',', false); |
1354 | 1354 | $out = array('orderBy' => "FIND_IN_SET({$this->getCFGDef('sortBy', $this->getPK())}, '{$idList}')"); |
1355 | 1355 | $this->setConfig($out); //reload config; |
1356 | - $sort = "ORDER BY " . $out['orderBy']; |
|
1356 | + $sort = "ORDER BY ".$out['orderBy']; |
|
1357 | 1357 | break; |
1358 | 1358 | default: |
1359 | 1359 | $out = array('orderBy' => '', 'order' => '', 'sortBy' => ''); |
@@ -1373,13 +1373,13 @@ discard block |
||
1373 | 1373 | } |
1374 | 1374 | |
1375 | 1375 | $out['sortBy'] = (($tmp = $this->getCFGDef('sortBy', '')) != '') ? $tmp : $sortName; |
1376 | - $out['orderBy'] = $out['sortBy'] . " " . $out['order']; |
|
1376 | + $out['orderBy'] = $out['sortBy']." ".$out['order']; |
|
1377 | 1377 | } |
1378 | 1378 | $this->setConfig($out); //reload config; |
1379 | - $sort = "ORDER BY " . $out['orderBy']; |
|
1379 | + $sort = "ORDER BY ".$out['orderBy']; |
|
1380 | 1380 | break; |
1381 | 1381 | } |
1382 | - $this->debug->debugEnd("sortORDER", 'Get sort order for SQL: ' . $this->debug->dumpData($sort)); |
|
1382 | + $this->debug->debugEnd("sortORDER", 'Get sort order for SQL: '.$this->debug->dumpData($sort)); |
|
1383 | 1383 | return $sort; |
1384 | 1384 | } |
1385 | 1385 | |
@@ -1406,17 +1406,17 @@ discard block |
||
1406 | 1406 | } |
1407 | 1407 | |
1408 | 1408 | if ($limit != 0) { |
1409 | - $ret = "LIMIT " . (int)$offset . "," . (int)$limit; |
|
1409 | + $ret = "LIMIT ".(int)$offset.",".(int)$limit; |
|
1410 | 1410 | } else { |
1411 | 1411 | if ($offset != 0) { |
1412 | 1412 | /** |
1413 | 1413 | * To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter |
1414 | 1414 | * @see http://dev.mysql.com/doc/refman/5.0/en/select.html |
1415 | 1415 | */ |
1416 | - $ret = "LIMIT " . (int)$offset . ",18446744073709551615"; |
|
1416 | + $ret = "LIMIT ".(int)$offset.",18446744073709551615"; |
|
1417 | 1417 | } |
1418 | 1418 | } |
1419 | - $this->debug->debugEnd("limitSQL", "Get limit for SQL: " . $this->debug->dumpData($ret)); |
|
1419 | + $this->debug->debugEnd("limitSQL", "Get limit for SQL: ".$this->debug->dumpData($ret)); |
|
1420 | 1420 | return $ret; |
1421 | 1421 | } |
1422 | 1422 | |
@@ -1455,18 +1455,18 @@ discard block |
||
1455 | 1455 | $children = array(); // children of each ID |
1456 | 1456 | $ids = array(); |
1457 | 1457 | foreach ($data as $i => $r) { |
1458 | - $row =& $data[$i]; |
|
1458 | + $row = & $data[$i]; |
|
1459 | 1459 | $id = $row[$idName]; |
1460 | 1460 | $pid = $row[$pidName]; |
1461 | - $children[$pid][$id] =& $row; |
|
1461 | + $children[$pid][$id] = & $row; |
|
1462 | 1462 | if (!isset($children[$id])) $children[$id] = array(); |
1463 | - $row['#childNodes'] =& $children[$id]; |
|
1463 | + $row['#childNodes'] = & $children[$id]; |
|
1464 | 1464 | $ids[$row[$idName]] = true; |
1465 | 1465 | } |
1466 | 1466 | // Root elements are elements with non-found PIDs. |
1467 | 1467 | $this->_tree = array(); |
1468 | 1468 | foreach ($data as $i => $r) { |
1469 | - $row =& $data[$i]; |
|
1469 | + $row = & $data[$i]; |
|
1470 | 1470 | if (!isset($ids[$row[$pidName]])) { |
1471 | 1471 | $this->_tree[$row[$idName]] = $row; |
1472 | 1472 | } |
@@ -1491,7 +1491,7 @@ discard block |
||
1491 | 1491 | * По умолчанию это parent. Переопределить можно в контроллере присвоив другое значение переменной parentField |
1492 | 1492 | * @return string Parent Key основной таблицы |
1493 | 1493 | */ |
1494 | - public function getParentField(){ |
|
1494 | + public function getParentField() { |
|
1495 | 1495 | return isset($this->parentField) ? $this->parentField : ''; |
1496 | 1496 | } |
1497 | 1497 | /** |
@@ -1503,7 +1503,7 @@ discard block |
||
1503 | 1503 | */ |
1504 | 1504 | protected function getFilters($filter_string) |
1505 | 1505 | { |
1506 | - $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1); |
|
1506 | + $this->debug->debug("getFilters: ".$this->debug->dumpData($filter_string), 'getFilter', 1); |
|
1507 | 1507 | // the filter parameter tells us, which filters can be used in this query |
1508 | 1508 | $filter_string = trim($filter_string, ' ;'); |
1509 | 1509 | if (!$filter_string) return; |
@@ -1522,14 +1522,14 @@ discard block |
||
1522 | 1522 | if ($subfilter['where']) $wheres[] = $subfilter['where']; |
1523 | 1523 | } |
1524 | 1524 | $output['join'] = !empty($joins) ? implode(' ', $joins) : ''; |
1525 | - $output['where'] = !empty($wheres) ? '(' . implode($sql, $wheres) . ')' : ''; |
|
1525 | + $output['where'] = !empty($wheres) ? '('.implode($sql, $wheres).')' : ''; |
|
1526 | 1526 | } |
1527 | 1527 | } |
1528 | 1528 | |
1529 | 1529 | if (!$logic_op_found) { |
1530 | 1530 | $filter = $this->loadFilter($filter_string); |
1531 | 1531 | if (!$filter) { |
1532 | - $this->debug->warning('Error while loading DocLister filter "' . $this->debug->dumpData($filter_string) . '": check syntax!'); |
|
1532 | + $this->debug->warning('Error while loading DocLister filter "'.$this->debug->dumpData($filter_string).'": check syntax!'); |
|
1533 | 1533 | $output = false; |
1534 | 1534 | } else { |
1535 | 1535 | $output['join'] = $filter->get_join(); |
@@ -1562,19 +1562,19 @@ discard block |
||
1562 | 1562 | $type = trim($type); |
1563 | 1563 | switch (strtoupper($type)) { |
1564 | 1564 | case 'DECIMAL': |
1565 | - $field = 'CAST(' . $field . ' as DECIMAL(10,2))'; |
|
1565 | + $field = 'CAST('.$field.' as DECIMAL(10,2))'; |
|
1566 | 1566 | break; |
1567 | 1567 | case 'UNSIGNED': |
1568 | - $field = 'CAST(' . $field . ' as UNSIGNED)'; |
|
1568 | + $field = 'CAST('.$field.' as UNSIGNED)'; |
|
1569 | 1569 | break; |
1570 | 1570 | case 'BINARY': |
1571 | - $field = 'CAST(' . $field . ' as BINARY)'; |
|
1571 | + $field = 'CAST('.$field.' as BINARY)'; |
|
1572 | 1572 | break; |
1573 | 1573 | case 'DATETIME': |
1574 | - $field = 'CAST(' . $field . ' as DATETIME)'; |
|
1574 | + $field = 'CAST('.$field.' as DATETIME)'; |
|
1575 | 1575 | break; |
1576 | 1576 | case 'SIGNED': |
1577 | - $field = 'CAST(' . $field . ' as SIGNED)'; |
|
1577 | + $field = 'CAST('.$field.' as SIGNED)'; |
|
1578 | 1578 | break; |
1579 | 1579 | } |
1580 | 1580 | return $field; |
@@ -1587,17 +1587,17 @@ discard block |
||
1587 | 1587 | */ |
1588 | 1588 | protected function loadFilter($filter) |
1589 | 1589 | { |
1590 | - $this->debug->debug('Load filter ' . $this->debug->dumpData($filter), 'loadFilter', 2); |
|
1590 | + $this->debug->debug('Load filter '.$this->debug->dumpData($filter), 'loadFilter', 2); |
|
1591 | 1591 | $out = false; |
1592 | 1592 | $fltr_params = explode(':', $filter, 2); |
1593 | 1593 | $fltr = APIHelpers::getkey($fltr_params, 0, null); |
1594 | 1594 | // check if the filter is implemented |
1595 | - if (!is_null($fltr) && file_exists(dirname(__FILE__) . '/filter/' . $fltr . '.filter.php')) { |
|
1596 | - require_once dirname(__FILE__) . '/filter/' . $fltr . '.filter.php'; |
|
1595 | + if (!is_null($fltr) && file_exists(dirname(__FILE__).'/filter/'.$fltr.'.filter.php')) { |
|
1596 | + require_once dirname(__FILE__).'/filter/'.$fltr.'.filter.php'; |
|
1597 | 1597 | /** |
1598 | 1598 | * @var tv_DL_filter|content_DL_filter $fltr_class |
1599 | 1599 | */ |
1600 | - $fltr_class = $fltr . '_DL_filter'; |
|
1600 | + $fltr_class = $fltr.'_DL_filter'; |
|
1601 | 1601 | $this->totalFilters++; |
1602 | 1602 | $fltr_obj = new $fltr_class(); |
1603 | 1603 | if ($fltr_obj->init($this, $filter)) { |
@@ -1655,7 +1655,7 @@ discard block |
||
1655 | 1655 | public function getRequest() |
1656 | 1656 | { |
1657 | 1657 | $URL = null; |
1658 | - parse_str(parse_url(MODX_SITE_URL . $_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL); |
|
1658 | + parse_str(parse_url(MODX_SITE_URL.$_SERVER['REQUEST_URI'], PHP_URL_QUERY), $URL); |
|
1659 | 1659 | return http_build_query(array_merge($URL, array(DocLister::AliasRequest => null))); |
1660 | 1660 | } |
1661 | 1661 | } |
1662 | 1662 | \ No newline at end of file |
@@ -202,7 +202,9 @@ discard block |
||
202 | 202 | $this->setDebug(1); |
203 | 203 | $this->loadLang(array('core', 'json')); |
204 | 204 | |
205 | - if (!is_array($cfg) || empty($cfg)) $cfg = $this->modx->Event->params; |
|
205 | + if (!is_array($cfg) || empty($cfg)) { |
|
206 | + $cfg = $this->modx->Event->params; |
|
207 | + } |
|
206 | 208 | } else { |
207 | 209 | throw new Exception('MODX var is not instaceof DocumentParser'); |
208 | 210 | } |
@@ -727,7 +729,9 @@ discard block |
||
727 | 729 | } |
728 | 730 | $this->_plh[$key] = $data; |
729 | 731 | $id = $this->getCFGDef('id', ''); |
730 | - if ($id != '') $id .= "."; |
|
732 | + if ($id != '') { |
|
733 | + $id .= "."; |
|
734 | + } |
|
731 | 735 | $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id); |
732 | 736 | |
733 | 737 | $this->debug->debugEnd( |
@@ -1459,7 +1463,9 @@ discard block |
||
1459 | 1463 | $id = $row[$idName]; |
1460 | 1464 | $pid = $row[$pidName]; |
1461 | 1465 | $children[$pid][$id] =& $row; |
1462 | - if (!isset($children[$id])) $children[$id] = array(); |
|
1466 | + if (!isset($children[$id])) { |
|
1467 | + $children[$id] = array(); |
|
1468 | + } |
|
1463 | 1469 | $row['#childNodes'] =& $children[$id]; |
1464 | 1470 | $ids[$row[$idName]] = true; |
1465 | 1471 | } |
@@ -1506,7 +1512,9 @@ discard block |
||
1506 | 1512 | $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1); |
1507 | 1513 | // the filter parameter tells us, which filters can be used in this query |
1508 | 1514 | $filter_string = trim($filter_string, ' ;'); |
1509 | - if (!$filter_string) return; |
|
1515 | + if (!$filter_string) { |
|
1516 | + return; |
|
1517 | + } |
|
1510 | 1518 | $output = array('join' => '', 'where' => ''); |
1511 | 1519 | $logic_op_found = false; |
1512 | 1520 | $joins = $wheres = array(); |
@@ -1517,9 +1525,15 @@ discard block |
||
1517 | 1525 | $subfilters = $this->smartSplit($subfilters); |
1518 | 1526 | foreach ($subfilters as $subfilter) { |
1519 | 1527 | $subfilter = $this->getFilters(trim($subfilter)); |
1520 | - if (!$subfilter) continue; |
|
1521 | - if ($subfilter['join']) $joins[] = $subfilter['join']; |
|
1522 | - if ($subfilter['where']) $wheres[] = $subfilter['where']; |
|
1528 | + if (!$subfilter) { |
|
1529 | + continue; |
|
1530 | + } |
|
1531 | + if ($subfilter['join']) { |
|
1532 | + $joins[] = $subfilter['join']; |
|
1533 | + } |
|
1534 | + if ($subfilter['where']) { |
|
1535 | + $wheres[] = $subfilter['where']; |
|
1536 | + } |
|
1523 | 1537 | } |
1524 | 1538 | $output['join'] = !empty($joins) ? implode(' ', $joins) : ''; |
1525 | 1539 | $output['where'] = !empty($wheres) ? '(' . implode($sql, $wheres) . ')' : ''; |
@@ -61,7 +61,6 @@ |
||
61 | 61 | * Вызов экстенедара с параметрами полученными в этой функции |
62 | 62 | * |
63 | 63 | * @param DocLister $DocLister объект класса DocLister |
64 | - * @param mixed $config , ... неограниченное число параметров (используются для конфигурации экстендера) |
|
65 | 64 | * @return mixed ответ от экстендера (как правило это string) |
66 | 65 | */ |
67 | 66 | public function init($DocLister) |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | if (!defined('MODX_BASE_PATH')) { |
10 | 10 | die('HACK???'); |
11 | 11 | } |
12 | -include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
|
12 | +include_once(MODX_BASE_PATH.'assets/lib/APIHelpers.class.php'); |
|
13 | 13 | abstract class extDocLister |
14 | 14 | { |
15 | 15 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function init($DocLister) |
68 | 68 | { |
69 | - $this->DocLister->debug->debug('Run extender ' . get_class($this), 'runExtender', 2); |
|
69 | + $this->DocLister->debug->debug('Run extender '.get_class($this), 'runExtender', 2); |
|
70 | 70 | $flag = false; |
71 | 71 | if ($DocLister instanceof DocLister) { |
72 | 72 | $this->DocLister = $DocLister; |
@@ -116,10 +116,10 @@ |
||
116 | 116 | /** |
117 | 117 | * Конструктор условий для WHERE секции |
118 | 118 | * |
119 | - * @param $table_alias алиас таблицы |
|
120 | - * @param $field поле для фильтрации |
|
121 | - * @param $operator оператор сопоставления |
|
122 | - * @param $value искомое значение |
|
119 | + * @param string $table_alias алиас таблицы |
|
120 | + * @param string $field поле для фильтрации |
|
121 | + * @param string $operator оператор сопоставления |
|
122 | + * @param string $value искомое значение |
|
123 | 123 | * @return string |
124 | 124 | */ |
125 | 125 | protected function build_sql_where($table_alias, $field, $operator, $value) |
@@ -124,35 +124,35 @@ discard block |
||
124 | 124 | */ |
125 | 125 | protected function build_sql_where($table_alias, $field, $operator, $value) |
126 | 126 | { |
127 | - $this->DocLister->debug->debug('Build SQL query for filters: ' . $this->DocLister->debug->dumpData(func_get_args()), 'buildQuery', 2); |
|
127 | + $this->DocLister->debug->debug('Build SQL query for filters: '.$this->DocLister->debug->dumpData(func_get_args()), 'buildQuery', 2); |
|
128 | 128 | $output = sqlHelper::tildeField($field, $table_alias); |
129 | 129 | |
130 | 130 | switch ($operator) { |
131 | 131 | case '=': |
132 | 132 | case 'eq': |
133 | 133 | case 'is': |
134 | - $output .= " = '" . $this->modx->db->escape($value) . "'"; |
|
134 | + $output .= " = '".$this->modx->db->escape($value)."'"; |
|
135 | 135 | break; |
136 | 136 | case '!=': |
137 | 137 | case 'no': |
138 | 138 | case 'isnot': |
139 | - $output .= " != '" . $this->modx->db->escape($value) . "'"; |
|
139 | + $output .= " != '".$this->modx->db->escape($value)."'"; |
|
140 | 140 | break; |
141 | 141 | case '>': |
142 | 142 | case 'gt': |
143 | - $output .= ' > ' . str_replace(',','.',floatval($value)); |
|
143 | + $output .= ' > '.str_replace(',', '.', floatval($value)); |
|
144 | 144 | break; |
145 | 145 | case '<': |
146 | 146 | case 'lt': |
147 | - $output .= ' < ' . str_replace(',','.',floatval($value)); |
|
147 | + $output .= ' < '.str_replace(',', '.', floatval($value)); |
|
148 | 148 | break; |
149 | 149 | case '<=': |
150 | 150 | case 'elt': |
151 | - $output .= ' <= ' . str_replace(',','.',floatval($value)); |
|
151 | + $output .= ' <= '.str_replace(',', '.', floatval($value)); |
|
152 | 152 | break; |
153 | 153 | case '>=': |
154 | 154 | case 'egt': |
155 | - $output .= ' >= ' . str_replace(',','.',floatval($value)); |
|
155 | + $output .= ' >= '.str_replace(',', '.', floatval($value)); |
|
156 | 156 | break; |
157 | 157 | case '%': |
158 | 158 | case 'like': |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $output = $this->DocLister->LikeEscape($output, $value, '=', '%[+value+]'); |
166 | 166 | break; |
167 | 167 | case 'regexp': |
168 | - $output .= " REGEXP '" . $this->modx->db->escape($value) . "'"; |
|
168 | + $output .= " REGEXP '".$this->modx->db->escape($value)."'"; |
|
169 | 169 | break; |
170 | 170 | case 'against': |
171 | 171 | /** content:pagetitle,description,content,introtext:against:искомая строка */ |
@@ -188,16 +188,16 @@ discard block |
||
188 | 188 | $word_arr[] = $this->DocLister->LikeEscape($output, $word); |
189 | 189 | } |
190 | 190 | if (!empty($word_arr)) { |
191 | - $output = '(' . implode(' OR ', $word_arr) . ')'; |
|
191 | + $output = '('.implode(' OR ', $word_arr).')'; |
|
192 | 192 | } else { |
193 | 193 | $output = ''; |
194 | 194 | } |
195 | 195 | break; |
196 | 196 | case 'in': |
197 | - $output .= ' IN(' . $this->DocLister->sanitarIn($value, ',', true) . ')'; |
|
197 | + $output .= ' IN('.$this->DocLister->sanitarIn($value, ',', true).')'; |
|
198 | 198 | break; |
199 | 199 | case 'notin': |
200 | - $output .= ' NOT IN(' . $this->DocLister->sanitarIn($value, ',', true) . ')'; |
|
200 | + $output .= ' NOT IN('.$this->DocLister->sanitarIn($value, ',', true).')'; |
|
201 | 201 | break; |
202 | 202 | default: |
203 | 203 | $output = ''; |
@@ -4,11 +4,11 @@ |
||
4 | 4 | } |
5 | 5 | |
6 | 6 | $_lang = array( |
7 | - 'error' => array( |
|
8 | - 'incorrect_mail' => 'Указан (если вообще указан) не корректный email', |
|
9 | - 'no_user' => 'Пользователь не обнаружен или заблокирован', |
|
10 | - 'incorrect_password' => 'Не удалось авторизоваться. Пароль указан не верно или в плагине отказали в авторизации' |
|
11 | - ) |
|
7 | + 'error' => array( |
|
8 | + 'incorrect_mail' => 'Указан (если вообще указан) не корректный email', |
|
9 | + 'no_user' => 'Пользователь не обнаружен или заблокирован', |
|
10 | + 'incorrect_password' => 'Не удалось авторизоваться. Пароль указан не верно или в плагине отказали в авторизации' |
|
11 | + ) |
|
12 | 12 | ); |
13 | 13 | |
14 | 14 | return $_lang; |
15 | 15 | \ No newline at end of file |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | if(!defined('MODX_BASE_PATH')){die('What are you doing? Get out of here!');} |
3 | 3 | if ($modx->event->name == 'OnWebPagePrerender' && $modx->getLoginUserID('web')){ |
4 | - $snippetName = (isset($snippetName) && is_string($snippetName)) ? $snippetName : 'DLUsers'; |
|
4 | + $snippetName = (isset($snippetName) && is_string($snippetName)) ? $snippetName : 'DLUsers'; |
|
5 | 5 | $modx->runSnippet($snippetName, array( |
6 | 6 | 'action' => 'logout' |
7 | 7 | )); |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | -if(!defined('MODX_BASE_PATH')){die('What are you doing? Get out of here!');} |
|
3 | -if ($modx->event->name == 'OnWebPagePrerender' && $modx->getLoginUserID('web')){ |
|
2 | +if (!defined('MODX_BASE_PATH')) {die('What are you doing? Get out of here!'); } |
|
3 | +if ($modx->event->name == 'OnWebPagePrerender' && $modx->getLoginUserID('web')) { |
|
4 | 4 | $snippetName = (isset($snippetName) && is_string($snippetName)) ? $snippetName : 'DLUsers'; |
5 | 5 | $modx->runSnippet($snippetName, array( |
6 | 6 | 'action' => 'logout' |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | -include_once(MODX_BASE_PATH . 'assets/snippets/DLUsers/src/Actions.php'); |
|
2 | +include_once(MODX_BASE_PATH.'assets/snippets/DLUsers/src/Actions.php'); |
|
3 | 3 | $params = is_array($modx->event->params) ? $modx->event->params : array(); |
4 | 4 | $action = APIHelpers::getkey($params, 'action', ''); |
5 | 5 | $lang = APIHelpers::getkey($params, 'lang', $modx->getConfig('manager_language')); |
6 | 6 | $userClass = APIHelpers::getkey($params, 'userClass', 'modUsers'); |
7 | 7 | $DLUsers = \DLUsers\Actions::getInstance($modx, $lang, $userClass); |
8 | 8 | $out = ''; |
9 | -if(!empty($action) && method_exists($DLUsers, $action)) { |
|
9 | +if (!empty($action) && method_exists($DLUsers, $action)) { |
|
10 | 10 | $out = call_user_func_array(array($DLUsers, $action), array($params)); |
11 | 11 | } |
12 | 12 | return $out; |
13 | 13 | \ No newline at end of file |