Completed
Push — master ( 6b2b1e...f0d0bc )
by Agel_Nash
05:25 queued 02:08
created
assets/lib/APIHelpers.class.php 1 patch
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      * @license    GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
74 74
      * @param string $email проверяемый email
75 75
      * @param boolean $dns проверять ли DNS записи
76
-     * @return boolean Результат проверки почтового ящика
76
+     * @return false|string Результат проверки почтового ящика
77 77
      * @author Anton Shevchuk
78 78
      */
79 79
     public static function emailValidate($email, $dns = true)
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     }
147 147
 
148 148
     /**
149
-     * @param $data
149
+     * @param string $data
150 150
      * @return bool|false|string
151 151
      */
152 152
     private function _getEnv($data)
Please login to merge, or discard this patch.
assets/lib/Formatter/SqlFormatter.php 1 patch
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -330,8 +330,8 @@
 block discarded – undo
330 330
     }
331 331
 
332 332
     /**
333
-     * @param $string
334
-     * @return null
333
+     * @param string $string
334
+     * @return string|null
335 335
      */
336 336
     protected static function getQuotedString($string)
337 337
     {
Please login to merge, or discard this patch.
assets/lib/Helpers/PHPThumb.php 1 patch
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
     }
24 24
 
25 25
     /**
26
-     * @param $inputFile
27
-     * @param $outputFile
26
+     * @param string $inputFile
27
+     * @param string $outputFile
28 28
      * @param $options
29 29
      * @return bool
30 30
      */
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     }
67 67
 
68 68
     /**
69
-     * @param $options
69
+     * @param string $options
70 70
      */
71 71
     private function setOptions($options) {
72 72
         $options = strtr($options, Array("," => "&", "_" => "=", '{' => '[', '}' => ']'));
Please login to merge, or discard this patch.
assets/lib/Module/Helper.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	}
29 29
 
30 30
     /**
31
-     * @param $text
31
+     * @param string $text
32 32
      */
33 33
     public static function setMode($text)
34 34
 	{
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	}
37 37
 
38 38
     /**
39
-     * @param $from
39
+     * @param string $from
40 40
      * @param string $where
41 41
      * @return mixed
42 42
      */
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 
106 106
     /**
107 107
      * @param $path
108
-     * @param $callback
108
+     * @param \Closure $callback
109 109
      * @param array $callbackParams
110 110
      * @param int $lines
111 111
      * @param int $size
Please login to merge, or discard this patch.
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class Helper extends \APIhelpers{
10 10
     protected static $modx = null;
11
-	protected static $mode = 'list';
11
+    protected static $mode = 'list';
12 12
 
13 13
     /**
14 14
      * @param \DocumentParser $modx
@@ -16,24 +16,24 @@  discard block
 block discarded – undo
16 16
      */
17 17
     public static function init(\DocumentParser $modx, $mode = 'list'){
18 18
         self::$modx = $modx;
19
-		self::setMode($mode);
19
+        self::setMode($mode);
20 20
     }
21 21
 
22 22
     /**
23 23
      * @return string
24 24
      */
25 25
     public static function getMode()
26
-	{
27
-		return self::$mode;
28
-	}
26
+    {
27
+        return self::$mode;
28
+    }
29 29
 
30 30
     /**
31 31
      * @param $text
32 32
      */
33 33
     public static function setMode($text)
34
-	{
35
-		self::$mode = $text;
36
-	}
34
+    {
35
+        self::$mode = $text;
36
+    }
37 37
 
38 38
     /**
39 39
      * @param $from
@@ -51,16 +51,16 @@  discard block
 block discarded – undo
51 51
      * @return array
52 52
      */
53 53
     public static function jeditable($key = 'id', $post = true){
54
-       $data = array();
55
-       $request = $post ? $_POST : $_GET;
56
-       $match = (isset($request[$key]) && is_scalar($request[$key]) && preg_match("/^(.*)_(\d+)$/i", $request[$key], $match)) ? $match : array();
57
-       if(!empty($match)){
58
-           $data = array(
59
-               'key' => $match[1],
60
-               'id' => $match[2]
61
-           );
62
-       }
63
-       return $data;
54
+        $data = array();
55
+        $request = $post ? $_POST : $_GET;
56
+        $match = (isset($request[$key]) && is_scalar($request[$key]) && preg_match("/^(.*)_(\d+)$/i", $request[$key], $match)) ? $match : array();
57
+        if(!empty($match)){
58
+            $data = array(
59
+                'key' => $match[1],
60
+                'id' => $match[2]
61
+            );
62
+        }
63
+        return $data;
64 64
     }
65 65
 
66 66
     /**
@@ -71,37 +71,37 @@  discard block
 block discarded – undo
71 71
      * @return mixed
72 72
      */
73 73
     public static function curl($url, $data = '', $post = false, array $header = array())
74
-	{
75
-		$ch = curl_init();
76
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
77
-		$post = (bool)$post;
78
-		curl_setopt($ch, CURLOPT_POST, $post);
79
-		if ($post) {
80
-			curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
81
-		}
82
-		if (!empty($header)) {
83
-			curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
84
-		}
85
-		curl_setopt($ch, CURLOPT_TIMEOUT, 10);
86
-		curl_setopt($ch, CURLOPT_URL, $url);
87
-		return curl_exec($ch);
88
-	}
74
+    {
75
+        $ch = curl_init();
76
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
77
+        $post = (bool)$post;
78
+        curl_setopt($ch, CURLOPT_POST, $post);
79
+        if ($post) {
80
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
81
+        }
82
+        if (!empty($header)) {
83
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
84
+        }
85
+        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
86
+        curl_setopt($ch, CURLOPT_URL, $url);
87
+        return curl_exec($ch);
88
+    }
89 89
 
90
-	/**
91
-	 * Были ли ошибки во время работы с JSON
92
-	 *
93
-	 * @param $json string строка с JSON для записи в лог при отладке
94
-	 * @return bool|string
95
-	 */
96
-	public function isErrorJSON($json)
97
-	{
98
-		require_once(MODX_BASE_PATH . "assets/snippets/DocLister/lib/jsonHelper.class.php");
99
-		$error = \jsonHelper::json_last_error_msg();
100
-		if (!in_array($error, array('error_none', 'other'))) {
101
-			$error = true;
102
-		}
103
-		return $error;
104
-	}
90
+    /**
91
+     * Были ли ошибки во время работы с JSON
92
+     *
93
+     * @param $json string строка с JSON для записи в лог при отладке
94
+     * @return bool|string
95
+     */
96
+    public function isErrorJSON($json)
97
+    {
98
+        require_once(MODX_BASE_PATH . "assets/snippets/DocLister/lib/jsonHelper.class.php");
99
+        $error = \jsonHelper::json_last_error_msg();
100
+        if (!in_array($error, array('error_none', 'other'))) {
101
+            $error = true;
102
+        }
103
+        return $error;
104
+    }
105 105
 
106 106
     /**
107 107
      * @param $path
@@ -112,24 +112,24 @@  discard block
 block discarded – undo
112 112
      * @return array
113 113
      */
114 114
     public static function readFileLine($path, $callback, array $callbackParams = array(), $lines = 0, $size = 4096)
115
-	{
116
-		$handle = fopen($path, "r");
117
-		$i = $total = 0;
118
-		while (!feof($handle)) {
119
-			$i++;
120
-			$buffer = fgets($handle, $size);
121
-			if (is_callable($callback)) {
122
-				$callbackParams['line'] = $buffer;
123
-				$callbackParams['numLine'] = $i;
124
-				if (call_user_func($callback, $callbackParams)) {
125
-					$total++;
126
-				}
127
-			}
128
-			if ($lines > 0 && $i >= $lines) {
129
-				break;
130
-			}
131
-		}
132
-		fclose($handle);
133
-		return array('line' => $i, 'add' => $total);
134
-	}
115
+    {
116
+        $handle = fopen($path, "r");
117
+        $i = $total = 0;
118
+        while (!feof($handle)) {
119
+            $i++;
120
+            $buffer = fgets($handle, $size);
121
+            if (is_callable($callback)) {
122
+                $callbackParams['line'] = $buffer;
123
+                $callbackParams['numLine'] = $i;
124
+                if (call_user_func($callback, $callbackParams)) {
125
+                    $total++;
126
+                }
127
+            }
128
+            if ($lines > 0 && $i >= $lines) {
129
+                break;
130
+            }
131
+        }
132
+        fclose($handle);
133
+        return array('line' => $i, 'add' => $total);
134
+    }
135 135
 }
136 136
\ No newline at end of file
Please login to merge, or discard this patch.
assets/lib/Module/Template.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     }
79 79
 
80 80
     /**
81
-     * @param $name
81
+     * @param string $name
82 82
      * @return string
83 83
      */
84 84
     protected function _getMainTpl($name){
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
     }
115 115
 
116 116
     /**
117
-     * @param $TplName
117
+     * @param string $TplName
118 118
      * @param array $tplParams
119 119
      * @return string
120 120
      */
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 abstract class Template{
8 8
     protected $_modx = null;
9 9
     protected $_tplFolder = null;
10
-	protected $_publicFolder;
10
+    protected $_publicFolder;
11 11
     const TPL_EXT = 'html';
12 12
 
13 13
     public $vars = array(
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
         self::$_ajax = (boolean) $ajax;
36 36
         $this->loadVars();
37 37
         if(is_null($tplFolder)){
38
-		  $tplFolder = dirname(dirname(__FILE__));
38
+            $tplFolder = dirname(dirname(__FILE__));
39 39
         }
40 40
         $FS = \Helpers\FS::getInstance();
41 41
         $tplFolder = $FS->relativePath($tplFolder);
42 42
 
43
-		$this->_publicFolder = "/".$tplFolder."/public/";
43
+        $this->_publicFolder = "/".$tplFolder."/public/";
44 44
         $this->_tplFolder = MODX_BASE_PATH.$tplFolder."/template/";
45 45
 
46 46
         if(!defined('MODX_MAIN_URL')){
@@ -59,16 +59,16 @@  discard block
 block discarded – undo
59 59
      * @return string
60 60
      */
61 61
     public function publicFolder(){
62
-		return $this->_publicFolder;
63
-	}
62
+        return $this->_publicFolder;
63
+    }
64 64
 
65 65
     /**
66 66
      * @param $path
67 67
      * @return string
68 68
      */
69 69
     public function src($path){
70
-		return rtrim(MODX_MAIN_URL, '/').$this->publicFolder().ltrim($path, '/');
71
-	}
70
+        return rtrim(MODX_MAIN_URL, '/').$this->publicFolder().ltrim($path, '/');
71
+    }
72 72
 
73 73
     /**
74 74
      * @return string
@@ -160,10 +160,10 @@  discard block
 block discarded – undo
160 160
                 'id' => empty($module) ? self::getParam('id', $content, 0) : (int)$module
161 161
             )
162 162
         );
163
-		$out = implode("?", array($this->_modx->getManagerPath(), http_build_query($data)));
164
-		if ($full) {
165
-			$out = $this->_modx->getConfig('site_url') . ltrim($out, '/');
166
-		}
163
+        $out = implode("?", array($this->_modx->getManagerPath(), http_build_query($data)));
164
+        if ($full) {
165
+            $out = $this->_modx->getConfig('site_url') . ltrim($out, '/');
166
+        }
167 167
         return $out;
168 168
     }
169 169
 
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * Class Template
5 5
  * @package Module
6 6
  */
7
-abstract class Template{
7
+abstract class Template {
8 8
     protected $_modx = null;
9 9
     protected $_tplFolder = null;
10 10
 	protected $_publicFolder;
@@ -30,11 +30,11 @@  discard block
 block discarded – undo
30 30
      * @param bool $ajax
31 31
      * @param null $tplFolder
32 32
      */
33
-    public function __construct(\DocumentParser $modx, $ajax = false, $tplFolder = null){
33
+    public function __construct(\DocumentParser $modx, $ajax = false, $tplFolder = null) {
34 34
         $this->_modx = $modx;
35
-        self::$_ajax = (boolean) $ajax;
35
+        self::$_ajax = (boolean)$ajax;
36 36
         $this->loadVars();
37
-        if(is_null($tplFolder)){
37
+        if (is_null($tplFolder)) {
38 38
 		  $tplFolder = dirname(dirname(__FILE__));
39 39
         }
40 40
         $FS = \Helpers\FS::getInstance();
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 		$this->_publicFolder = "/".$tplFolder."/public/";
44 44
         $this->_tplFolder = MODX_BASE_PATH.$tplFolder."/template/";
45 45
 
46
-        if(!defined('MODX_MAIN_URL')){
46
+        if (!defined('MODX_MAIN_URL')) {
47 47
             define('MODX_MAIN_URL', MODX_SITE_URL);
48 48
         }
49 49
     }
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
     /**
52 52
      * @return bool
53 53
      */
54
-    public static function isAjax(){
54
+    public static function isAjax() {
55 55
         return self::$_ajax;
56 56
     }
57 57
 
58 58
     /**
59 59
      * @return string
60 60
      */
61
-    public function publicFolder(){
61
+    public function publicFolder() {
62 62
 		return $this->_publicFolder;
63 63
 	}
64 64
 
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
      * @param $path
67 67
      * @return string
68 68
      */
69
-    public function src($path){
69
+    public function src($path) {
70 70
 		return rtrim(MODX_MAIN_URL, '/').$this->publicFolder().ltrim($path, '/');
71 71
 	}
72 72
 
73 73
     /**
74 74
      * @return string
75 75
      */
76
-    public function showHeader(){
76
+    public function showHeader() {
77 77
         return $this->_getMainTpl('header.inc.php');
78 78
     }
79 79
 
@@ -81,23 +81,23 @@  discard block
 block discarded – undo
81 81
      * @param $name
82 82
      * @return string
83 83
      */
84
-    protected function _getMainTpl($name){
84
+    protected function _getMainTpl($name) {
85 85
         $content = '';
86
-        if( ! self::isAjax()){
86
+        if (!self::isAjax()) {
87 87
 
88 88
             ob_start();
89 89
             extract($this->vars);
90
-            if(file_exists($incPath . $name)){
91
-                include($incPath . $name);
90
+            if (file_exists($incPath.$name)) {
91
+                include($incPath.$name);
92 92
                 $content = ob_get_contents();
93 93
             }
94 94
             ob_end_clean();
95 95
         }
96 96
         return $content;
97 97
     }
98
-    public function loadVars(){
98
+    public function loadVars() {
99 99
         $vars = array();
100
-        foreach($this->vars as $item){
100
+        foreach ($this->vars as $item) {
101 101
             global $$item;
102 102
             $vars[$item] = $$item;
103 103
         }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     /**
110 110
      * @return string
111 111
      */
112
-    public function showFooter(){
112
+    public function showFooter() {
113 113
         return $this->_getMainTpl('footer.inc.php');
114 114
     }
115 115
 
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
      * @param array $tplParams
119 119
      * @return string
120 120
      */
121
-    public function showBody($TplName, array $tplParams = array()){
121
+    public function showBody($TplName, array $tplParams = array()) {
122 122
         ob_start();
123
-        if(file_exists($this->_tplFolder.$TplName.".".self::TPL_EXT)){
123
+        if (file_exists($this->_tplFolder.$TplName.".".self::TPL_EXT)) {
124 124
             extract($this->vars);
125 125
             include($this->_tplFolder.$TplName.".".self::TPL_EXT);
126 126
         }
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      * @param null $default
136 136
      * @return mixed|null
137 137
      */
138
-    public static function getParam($key, array $param = array(), $default = null){
138
+    public static function getParam($key, array $param = array(), $default = null) {
139 139
         return isset($param[$key]) ? $param[$key] : $default;
140 140
     }
141 141
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      * @param bool $full
147 147
      * @return string
148 148
      */
149
-    public function makeUrl($action, array $data = array(), $module = null, $full = false){
149
+    public function makeUrl($action, array $data = array(), $module = null, $full = false) {
150 150
         $action = is_scalar($action) ? $action : '';
151 151
         $content = self::getParam('content', $this->vars, array());
152 152
         $data = array_merge(
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
         );
163 163
 		$out = implode("?", array($this->_modx->getManagerPath(), http_build_query($data)));
164 164
 		if ($full) {
165
-			$out = $this->_modx->getConfig('site_url') . ltrim($out, '/');
165
+			$out = $this->_modx->getConfig('site_url').ltrim($out, '/');
166 166
 		}
167 167
         return $out;
168 168
     }
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
     /**
171 171
      * @return string
172 172
      */
173
-    public static function showLog(){
173
+    public static function showLog() {
174 174
         return self::isAjax() ? 'log' : 'main';
175 175
     }
176 176
     abstract public function Lists();
Please login to merge, or discard this patch.
assets/lib/MODxAPI/modResource.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
     }
221 221
 
222 222
     /**
223
-     * @param $key
223
+     * @param string $key
224 224
      * @param $value
225 225
      * @return $this
226 226
      */
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
     }
314 314
 
315 315
     /**
316
-     * @param $data
317
-     * @return bool|string
316
+     * @param integer $data
317
+     * @return string|false
318 318
      */
319 319
     protected function findUserBy($data)
320 320
     {
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
     }
601 601
 
602 602
     /**
603
-     * @return array
603
+     * @return integer[]
604 604
      */
605 605
     private function systemID()
606 606
     {
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
     }
712 712
 
713 713
     /**
714
-     * @param $tpl
714
+     * @param string $tpl
715 715
      * @return int
716 716
      * @throws Exception
717 717
      */
Please login to merge, or discard this patch.
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -143,13 +143,13 @@  discard block
 block discarded – undo
143 143
      * @return null
144 144
      */
145 145
     public function getUrl(){
146
-		$out = null;
147
-		$id = (int)$this->getID();
148
-		if(!empty($id)){
149
-			$out = $this->modx->makeUrl($id);
150
-		}
151
-		return $out;
152
-	}
146
+        $out = null;
147
+        $id = (int)$this->getID();
148
+        if(!empty($id)){
149
+            $out = $this->modx->makeUrl($id);
150
+        }
151
+        return $out;
152
+    }
153 153
 
154 154
     /**
155 155
      * @param string $main
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
      * @return mixed
158 158
      */
159 159
     public function getTitle($main = 'menutitle', $second = 'pagetitle'){
160
-		$title = $this->get($main);
161
-		if(empty($title) && $title !== '0'){
162
-			$title = $this->get($second);
163
-		}
164
-		return $title;
165
-	}
160
+        $title = $this->get($main);
161
+        if(empty($title) && $title !== '0'){
162
+            $title = $this->get($second);
163
+        }
164
+        return $title;
165
+    }
166 166
 
167 167
     /**
168 168
      * @return bool
@@ -516,9 +516,9 @@  discard block
 block discarded – undo
516 516
         $ignore = $this->systemID();
517 517
         $_ids = $this->cleanIDs($ids, ',', $ignore);
518 518
         if (is_array($_ids) && $_ids != array()) {
519
-        	$id = $this->sanitarIn($_ids);
519
+            $id = $this->sanitarIn($_ids);
520 520
             $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`='1' WHERE `id` IN ({$id})");
521
-		} else throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
521
+        } else throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
522 522
         return $this;
523 523
     }
524 524
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
         $q = $this->modx->makeArray($q);
532 532
         $_ids = array();
533 533
         foreach($q as $item){
534
-              $_ids[] = $item['id'];
534
+                $_ids[] = $item['id'];
535 535
         }
536 536
         if (is_array($_ids) && $_ids != array()) {
537 537
             $this->invokeEvent('OnBeforeEmptyTrash', array(
@@ -582,19 +582,19 @@  discard block
 block discarded – undo
582 582
         $ids = $this->childrens($ids, true);
583 583
         $_ids = $this->cleanIDs($ids, ',', $this->systemID());
584 584
         if (is_array($_ids) && $_ids != array()) {
585
-        	$this->invokeEvent('OnBeforeEmptyTrash', array(
586
-            	"ids" => $_ids
587
-			), $fire_events);
588
-
589
-			$id = $this->sanitarIn($_ids);
590
-			if(!empty($id)){
591
-				$this->query("DELETE from {$this->makeTable('site_content')} where `id` IN ({$id})");
592
-				$this->query("DELETE from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid` IN ({$id})");
593
-				$this->invokeEvent('OnEmptyTrash', array(
594
-					"ids" => $_ids
595
-				), $fire_events);
596
-			}
597
-		} else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
585
+            $this->invokeEvent('OnBeforeEmptyTrash', array(
586
+                "ids" => $_ids
587
+            ), $fire_events);
588
+
589
+            $id = $this->sanitarIn($_ids);
590
+            if(!empty($id)){
591
+                $this->query("DELETE from {$this->makeTable('site_content')} where `id` IN ({$id})");
592
+                $this->query("DELETE from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid` IN ({$id})");
593
+                $this->invokeEvent('OnEmptyTrash', array(
594
+                    "ids" => $_ids
595
+                ), $fire_events);
596
+            }
597
+        } else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
598 598
 
599 599
         return $this;
600 600
     }
@@ -719,13 +719,13 @@  discard block
 block discarded – undo
719 719
     {
720 720
         if (!is_numeric($tpl) || $tpl != (int)$tpl) {
721 721
             if (is_scalar($tpl)) {
722
-            	$sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '".$this->escape($tpl)."'";
723
-				$rs = $this->query($sql);
724
-				if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) throw new Exception("Template {$tpl} is not exists");
725
-				$tpl = $this->modx->db->getValue($rs);
726
-			} else {
727
-				throw new Exception("Invalid template name: " . print_r($tpl, 1));
728
-			}
722
+                $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '".$this->escape($tpl)."'";
723
+                $rs = $this->query($sql);
724
+                if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) throw new Exception("Template {$tpl} is not exists");
725
+                $tpl = $this->modx->db->getValue($rs);
726
+            } else {
727
+                throw new Exception("Invalid template name: " . print_r($tpl, 1));
728
+            }
729 729
         }
730 730
         return (int)$tpl;
731 731
     }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
         $out = array_diff_key(parent::toArray(), $this->default_field);
111 111
         $tpl = $this->get('template');
112 112
         $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array());
113
-        foreach($tvTPL as $item){
114
-            if(isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)){
113
+        foreach ($tvTPL as $item) {
114
+            if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
115 115
                 $out[$this->tvid[$item]] = $this->get($this->tvid[$item]);
116 116
             }
117 117
         }
118
-        if($render){
119
-            foreach($out as $key => $val){
118
+        if ($render) {
119
+            foreach ($out as $key => $val) {
120 120
                 $out[$key] = $this->renderTV($key);
121 121
             }
122 122
         }
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      * @param bool $render
131 131
      * @return array
132 132
      */
133
-    public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true){
133
+    public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) {
134 134
         $out = array_merge(
135 135
             $this->toArrayMain(),
136 136
             $this->toArrayTV($render),
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
     /**
143 143
      * @return null
144 144
      */
145
-    public function getUrl(){
145
+    public function getUrl() {
146 146
 		$out = null;
147 147
 		$id = (int)$this->getID();
148
-		if(!empty($id)){
148
+		if (!empty($id)) {
149 149
 			$out = $this->modx->makeUrl($id);
150 150
 		}
151 151
 		return $out;
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
      * @param string $second
157 157
      * @return mixed
158 158
      */
159
-    public function getTitle($main = 'menutitle', $second = 'pagetitle'){
159
+    public function getTitle($main = 'menutitle', $second = 'pagetitle') {
160 160
 		$title = $this->get($main);
161
-		if(empty($title) && $title !== '0'){
161
+		if (empty($title) && $title !== '0') {
162 162
 			$title = $this->get($second);
163 163
 		}
164 164
 		return $title;
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
     /**
179 179
      * @return $this
180 180
      */
181
-    public function touch(){
181
+    public function touch() {
182 182
         $this->set('editedon', time());
183 183
         return $this;
184 184
     }
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
      * @param $tvname
188 188
      * @return null
189 189
      */
190
-    public function renderTV($tvname){
190
+    public function renderTV($tvname) {
191 191
         $out = null;
192
-        if($this->getID() > 0){
193
-            include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php";
194
-            include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php";
192
+        if ($this->getID() > 0) {
193
+            include_once MODX_MANAGER_PATH."includes/tmplvars.format.inc.php";
194
+            include_once MODX_MANAGER_PATH."includes/tmplvars.commands.inc.php";
195 195
             $tvval = $this->get($tvname);
196 196
             $param = APIHelpers::getkey($this->tvd, $tvname, array());
197 197
             $display = APIHelpers::getkey($param, 'display', '');
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
      * @param $key
207 207
      * @return mixed
208 208
      */
209
-    public function get($key){
209
+    public function get($key) {
210 210
         $out = parent::get($key);
211
-        if(isset($this->tv[$key])){
211
+        if (isset($this->tv[$key])) {
212 212
             $tpl = $this->get('template');
213 213
             $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array());
214 214
             $tvID = APIHelpers::getkey($this->tv, $key, 0);
215
-            if(in_array($tvID, $tvTPL) && is_null($out)){
215
+            if (in_array($tvID, $tvTPL) && is_null($out)) {
216 216
                 $out = APIHelpers::getkey($this->tvd[$key], 'value', null);
217 217
             }
218 218
         }
@@ -237,38 +237,38 @@  discard block
 block discarded – undo
237 237
                     break;
238 238
                 case 'published':
239 239
                     $value = (int)((bool)$value);
240
-                    if($value){
240
+                    if ($value) {
241 241
                         $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time');
242 242
                     }
243 243
                     break;
244 244
                 case 'pub_date':
245 245
                     $value = $this->getTime($value);
246
-                    if($value > 0 && time() + $this->modxConfig('server_offset_time') > $value){
246
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
247 247
                         $this->field['published'] = 1;
248 248
                         $this->field['publishedon'] = $value;
249 249
                     }
250 250
                     break;
251 251
                 case 'unpub_date':
252 252
                     $value = $this->getTime($value);
253
-                    if($value > 0 && time() + $this->modxConfig('server_offset_time') > $value){
253
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
254 254
                         $this->field['published'] = 0;
255 255
                         $this->field['publishedon'] = 0;
256 256
                     }
257 257
                     break;
258 258
                 case 'deleted':
259 259
                     $value = (int)((bool)$value);
260
-                    if($value){
260
+                    if ($value) {
261 261
                         $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time');
262
-                    }else{
262
+                    } else {
263 263
                         $this->field['deletedon'] = 0;
264 264
                     }
265 265
                     break;
266 266
                 case 'deletedon':
267 267
                     $value = $this->getTime($value);
268
-                    if($value > 0 && time() + $this->modxConfig('server_offset_time') < $value){
268
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) {
269 269
                         $value = 0;
270 270
                     }
271
-                    if($value){
271
+                    if ($value) {
272 272
                         $this->field['deleted'] = 1;
273 273
                     }
274 274
                     break;
@@ -294,19 +294,19 @@  discard block
 block discarded – undo
294 294
      * @param int $default
295 295
      * @return int|mixed
296 296
      */
297
-    protected function getUser($value, $default = 0){
297
+    protected function getUser($value, $default = 0) {
298 298
         $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0);
299 299
         $value = (int)$value;
300
-        if(!empty($value)){
300
+        if (!empty($value)) {
301 301
             $by = $this->findUserBy($value);
302 302
             $exists = $this->managerUsers->exists(function($key, $val) use ($by, $value){
303 303
                 return ($val->containsKey($by) && $val->get($by) === (string)$value);
304 304
             });
305
-            if(!$exists){
305
+            if (!$exists) {
306 306
                 $value = 0;
307 307
             }
308 308
         }
309
-        if(empty($value)){
309
+        if (empty($value)) {
310 310
             $value = empty($currentAdmin) ? $default : $currentAdmin;
311 311
         }
312 312
         return $value;
@@ -338,13 +338,13 @@  discard block
 block discarded – undo
338 338
      * @param $value
339 339
      * @return int|mixed|string
340 340
      */
341
-    protected function getTime($value){
341
+    protected function getTime($value) {
342 342
         $value = trim($value);
343
-        if(!empty($value)){
344
-            if(!is_numeric($value)){
343
+        if (!empty($value)) {
344
+            if (!is_numeric($value)) {
345 345
                 $value = (int)strtotime($value);
346 346
             }
347
-            if(!empty($value)){
347
+            if (!empty($value)) {
348 348
                 $value += $this->modxConfig('server_offset_time');
349 349
             }
350 350
         }
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
             $this->close();
377 377
             $this->newDoc = false;
378 378
 
379
-            $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id);
379
+            $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=".(int)$id);
380 380
             $this->fromArray($this->modx->db->getRow($result));
381
-            $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id);
381
+            $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=".(int)$id);
382 382
             while ($row = $this->modx->db->getRow($result)) {
383 383
                 $this->field[$this->tvid[$row['tmplvarid']]] = $row['value'];
384 384
             }
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
     {
403 403
         $parent = null;
404 404
         if ($this->field['pagetitle'] == '') {
405
-            $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>';
405
+            $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>'.print_r($this->field, true).'</pre>';
406 406
             return false;
407 407
         }
408 408
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
         $fld = $this->toArray(null, null, null, false);
419 419
         foreach ($this->default_field as $key => $value) {
420 420
             $tmp = $this->get($key);
421
-            if ($this->newDoc && ( !is_int($tmp) && $tmp=='')) {
422
-                if($tmp == $value){
421
+            if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
422
+                if ($tmp == $value) {
423 423
                     switch ($key) {
424 424
                         case 'cacheable':
425 425
                             $value = $this->modxConfig('cache_default');
@@ -440,11 +440,11 @@  discard block
 block discarded – undo
440 440
                 }
441 441
                 $this->field[$key] = $value;
442 442
             }
443
-            switch(true){
443
+            switch (true) {
444 444
                 case $key == 'parent':
445 445
                     $parent = (int)$this->get($key);
446 446
                     $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'");
447
-                    if($this->modx->db->getValue($q)!=1){
447
+                    if ($this->modx->db->getValue($q) != 1) {
448 448
                         $parent = $value;
449 449
                     }
450 450
                     $this->field[$key] = $parent;
@@ -461,9 +461,9 @@  discard block
 block discarded – undo
461 461
 
462 462
         if (!empty($this->set)) {
463 463
             if ($this->newDoc) {
464
-                $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set);
464
+                $SQL = "INSERT into {$this->makeTable('site_content')} SET ".implode(', ', $this->set);
465 465
             } else {
466
-                $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ', $this->set) . " WHERE `id` = " . $this->id;
466
+                $SQL = "UPDATE {$this->makeTable('site_content')} SET ".implode(', ', $this->set)." WHERE `id` = ".$this->id;
467 467
             }
468 468
             $this->query($SQL);
469 469
 
@@ -512,13 +512,13 @@  discard block
 block discarded – undo
512 512
      * @return $this
513 513
      * @throws Exception
514 514
      */
515
-    public function toTrash($ids){
515
+    public function toTrash($ids) {
516 516
         $ignore = $this->systemID();
517 517
         $_ids = $this->cleanIDs($ids, ',', $ignore);
518 518
         if (is_array($_ids) && $_ids != array()) {
519 519
         	$id = $this->sanitarIn($_ids);
520 520
             $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`='1' WHERE `id` IN ({$id})");
521
-		} else throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
521
+		} else throw new Exception('Invalid IDs list for mark trash: <pre>'.print_r($ids, 1).'</pre> please, check ignore list: <pre>'.print_r($ignore, 1).'</pre>');
522 522
         return $this;
523 523
     }
524 524
 
@@ -526,11 +526,11 @@  discard block
 block discarded – undo
526 526
      * @param null $fire_events
527 527
      * @return $this
528 528
      */
529
-    public function clearTrash($fire_events = null){
529
+    public function clearTrash($fire_events = null) {
530 530
         $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'");
531 531
         $q = $this->modx->makeArray($q);
532 532
         $_ids = array();
533
-        foreach($q as $item){
533
+        foreach ($q as $item) {
534 534
               $_ids[] = $item['id'];
535 535
         }
536 536
         if (is_array($_ids) && $_ids != array()) {
@@ -559,10 +559,10 @@  discard block
 block discarded – undo
559 559
         $_ids = $this->cleanIDs($ids, ',');
560 560
         if (is_array($_ids) && $_ids != array()) {
561 561
             $id = $this->sanitarIn($_ids);
562
-            if(!empty($id)) {
562
+            if (!empty($id)) {
563 563
                 $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})");
564 564
                 $id = $this->modx->db->getColumn('id', $q);
565
-                if($depth > 0 || $depth === true){
565
+                if ($depth > 0 || $depth === true) {
566 566
                     $id = $this->childrens($id, is_bool($depth) ? $depth : ($depth - 1));
567 567
                 }
568 568
                 $_ids = array_merge($_ids, $id);
@@ -587,14 +587,14 @@  discard block
 block discarded – undo
587 587
 			), $fire_events);
588 588
 
589 589
 			$id = $this->sanitarIn($_ids);
590
-			if(!empty($id)){
590
+			if (!empty($id)) {
591 591
 				$this->query("DELETE from {$this->makeTable('site_content')} where `id` IN ({$id})");
592 592
 				$this->query("DELETE from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid` IN ({$id})");
593 593
 				$this->invokeEvent('OnEmptyTrash', array(
594 594
 					"ids" => $_ids
595 595
 				), $fire_events);
596 596
 			}
597
-		} else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
597
+		} else throw new Exception('Invalid IDs list for delete: <pre>'.print_r($ids, 1).'</pre> please, check ignore list: <pre>'.print_r($ignore, 1).'</pre>');
598 598
 
599 599
         return $this;
600 600
     }
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
                 $suffix = substr($alias, -2);
639 639
                 if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
640 640
                     $suffix = (int)$tmp[1] + 1;
641
-                    $alias = substr($alias, 0, -2) . '-' . $suffix;
641
+                    $alias = substr($alias, 0, -2).'-'.$suffix;
642 642
                 } else {
643 643
                     $alias .= '-2';
644 644
                 }
@@ -664,12 +664,12 @@  discard block
 block discarded – undo
664 664
     protected function get_TV($reload = false)
665 665
     {
666 666
         if (empty($this->modx->_TVnames) || $reload) {
667
-            $result = $this->query('SELECT `id`,`name` FROM ' . $this->makeTable('site_tmplvars'));
667
+            $result = $this->query('SELECT `id`,`name` FROM '.$this->makeTable('site_tmplvars'));
668 668
             while ($row = $this->modx->db->GetRow($result)) {
669 669
                 $this->modx->_TVnames[$row['name']] = $row['id'];
670 670
             }
671 671
         }
672
-        foreach($this->modx->_TVnames as $name => $id){
672
+        foreach ($this->modx->_TVnames as $name => $id) {
673 673
             $this->tvid[$id] = $name;
674 674
             $this->tv[$name] = $id;
675 675
         }
@@ -680,11 +680,11 @@  discard block
 block discarded – undo
680 680
     /**
681 681
      * @return $this
682 682
      */
683
-    protected function loadTVTemplate(){
683
+    protected function loadTVTemplate() {
684 684
         $q = $this->query("SELECT `tmplvarid`, `templateid` FROM ".$this->makeTable('site_tmplvar_templates'));
685 685
         $q = $this->modx->db->makeArray($q);
686 686
         $this->tvTpl = array();
687
-        foreach($q as $item){
687
+        foreach ($q as $item) {
688 688
             $this->tvTpl[$item['templateid']][] = $item['tmplvarid'];
689 689
         }
690 690
         return $this;
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
      */
697 697
     protected function loadTVDefault(array $tvId = array())
698 698
     {
699
-        if(is_array($tvId) && !empty($tvId)){
699
+        if (is_array($tvId) && !empty($tvId)) {
700 700
             $tbl_site_tmplvars = $this->makeTable('site_tmplvars');
701 701
             $fields = 'id,name,default_text as value,display,display_params,type';
702 702
             $implodeTvId = implode(',', $tvId);
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
 				if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) throw new Exception("Template {$tpl} is not exists");
725 725
 				$tpl = $this->modx->db->getValue($rs);
726 726
 			} else {
727
-				throw new Exception("Invalid template name: " . print_r($tpl, 1));
727
+				throw new Exception("Invalid template name: ".print_r($tpl, 1));
728 728
 			}
729 729
         }
730 730
         return (int)$tpl;
Please login to merge, or discard this patch.
assets/lib/MODxAPI/modUsers.php 1 patch
Doc Comments   +7 added lines, -6 removed lines patch added patch discarded remove patch
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
     }
55 55
 
56 56
     /**
57
-     * @param $data
58
-     * @return bool|string
57
+     * @param string $data
58
+     * @return string|false
59 59
      */
60 60
     protected function findUser($data)
61 61
     {
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
     }
106 106
 
107 107
     /**
108
-     * @param $key
108
+     * @param string $key
109 109
      * @param $value
110 110
      * @return $this
111 111
      */
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     /**
241 241
      * @param $ids
242 242
      * @param null $fire_events
243
-     * @return bool|null
243
+     * @return null|false
244 244
      */
245 245
     public function delete($ids, $fire_events = null)
246 246
     {
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
     /**
315 315
      * @param $id
316 316
      * @param $password
317
-     * @param $blocker
317
+     * @param boolean $blocker
318 318
      * @param null $fire_events
319 319
      * @return bool
320 320
      */
@@ -396,7 +396,8 @@  discard block
 block discarded – undo
396 396
      * Starts the user session on login success. Destroys session on error or logout.
397 397
      *
398 398
      * @param string $directive ('start' or 'destroy')
399
-     * @return void
399
+     * @param string $cookieName
400
+     * @return modUsers
400 401
      * @author Raymond Irving
401 402
      * @author Scotty Delicious
402 403
      *
Please login to merge, or discard this patch.
assets/lib/MODxAPI/MODx.php 3 patches
Doc Comments   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     /**
13 13
      * @param $email
14 14
      * @param bool $dns
15
-     * @return bool
15
+     * @return false|string
16 16
      */
17 17
     public function emailValidate($email, $dns = true)
18 18
     {
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     }
102 102
 
103 103
     /**
104
-     * @param $flag
104
+     * @param boolean $flag
105 105
      * @return $this
106 106
      */
107 107
     public function setDebug($flag){
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
     }
125 125
 
126 126
     /**
127
-     * @param $name
127
+     * @param string $name
128 128
      * @param null $default
129 129
      * @return mixed
130 130
      */
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
      }
178 178
 
179 179
     /**
180
-     * @param $name
180
+     * @param string $name
181 181
      * @param array $data
182 182
      * @param bool $flag
183 183
      * @return $this
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     }
193 193
 
194 194
     /**
195
-     * @param $name
195
+     * @param string $name
196 196
      * @param array $data
197 197
      * @param null $flag
198 198
      * @return mixed
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
     }
289 289
 
290 290
     /**
291
-     * @param $id
291
+     * @param integer $id
292 292
      * @return MODxAPI
293 293
      */
294 294
     public function switchObject($id){
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
     /**
400 400
      * @param $IDs
401 401
      * @param string $sep
402
-     * @param array $ignore
402
+     * @param integer[] $ignore
403 403
      * @return array
404 404
      * @throws Exception
405 405
      */
@@ -557,8 +557,8 @@  discard block
 block discarded – undo
557 557
     }
558 558
 
559 559
     /**
560
-     * @param $table
561
-     * @param $field
560
+     * @param string $table
561
+     * @param string $field
562 562
      * @param string $PK
563 563
      * @return bool
564 564
      */
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
     abstract public function save($fire_events = null, $clearCache = false);
648 648
 
649 649
     /**
650
-     * @param $ids
650
+     * @param integer $ids
651 651
      * @param null $fire_events
652 652
      * @return mixed
653 653
      */
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
     }
664 664
 
665 665
     /**
666
-     * @param $version
666
+     * @param string $version
667 667
      * @param bool $dmi3yy
668 668
      * @return bool
669 669
      */
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
     }
686 686
 
687 687
     /**
688
-     * @param $name
688
+     * @param string $name
689 689
      * @return bool|mixed
690 690
      */
691 691
     protected function eraseField($name)
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 
758 758
     /**
759 759
      * Получить список не запакованных полей
760
-     * @return array
760
+     * @return DLCollection
761 761
      */
762 762
     public function getNoEncodeFields(){
763 763
         return $this->_decodedFields->filter(function($value){
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
 
768 768
     /**
769 769
      * Получить список не распакованных полей
770
-     * @return array
770
+     * @return DLCollection
771 771
      */
772 772
     public function getNoDecodeFields(){
773 773
        return $this->_decodedFields->filter(function($value){
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
      * Запаковывает конкретное поле в JSON
835 835
      * @param  string $field Имя поля
836 836
      * @param  bool $store обновить запакованное поле
837
-     * @return array json строка
837
+     * @return string|null json строка
838 838
      */
839 839
     public function encodeField($field, $store = false){
840 840
         $out = null;
Please login to merge, or discard this patch.
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -73,15 +73,15 @@  discard block
 block discarded – undo
73 73
     protected $set = array();
74 74
     protected $newDoc = false;
75 75
     protected $pkName = 'id';
76
-	protected $ignoreError = '';
76
+    protected $ignoreError = '';
77 77
     protected $_debug = false;
78 78
     protected $_query = array();
79 79
     protected $jsonFields = array();
80
-	/**
81
-	 * @var DLCollection
82
-	 */
80
+    /**
81
+     * @var DLCollection
82
+     */
83 83
     private $_decodedFields;
84
-	private $_table = array();
84
+    private $_table = array();
85 85
 
86 86
     /**
87 87
      * MODxAPI constructor.
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function __construct(DocumentParser $modx, $debug = false)
93 93
     {	
94
-    	$this->modx = $modx;
94
+        $this->modx = $modx;
95 95
         if(function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()){
96
-        	throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.');
97
-		}
96
+            throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.');
97
+        }
98 98
 
99
-		$this->setDebug($debug);
99
+        $this->setDebug($debug);
100 100
         $this->_decodedFields = new DLCollection($this->modx);
101 101
     }
102 102
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             $value = $this->modx->db->escape($value);
175 175
         }
176 176
         return $value;
177
-     }
177
+        }
178 178
 
179 179
     /**
180 180
      * @param $name
@@ -251,39 +251,39 @@  discard block
 block discarded – undo
251 251
      */
252 252
     final public function clearCache($fire_events = null, $custom = false)
253 253
     {
254
-		$IDs = array();
255
-		if($custom === false) {
256
-			$this->modx->clearCache();
257
-			include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php');
258
-			$sync = new synccache();
259
-			$path = $this->getCachePath(true);
260
-			$sync->setCachepath($path);
261
-			$sync->setReport(false);
262
-			$sync->emptyCache();
263
-		}else {
264
-			if(is_scalar($custom)){
265
-				$custom = array($custom);
266
-			}
267
-			switch ($this->modx->config['cache_type']) {
268
-				case 2:
269
-					$cacheFile = "_*.pageCache.php";
270
-					break;
271
-				default:
272
-					$cacheFile = ".pageCache.php";
273
-			}
274
-			if(is_array($custom)) {
275
-				foreach($custom as $id) {
276
-					$tmp = glob(MODX_BASE_PATH."assets/cache/docid_" . $id . $cacheFile);
277
-					foreach($tmp as $file){
278
-						if(is_readable($file)){
279
-							unlink($file);
280
-						}
281
-						$IDs[] = $id;
282
-					}
283
-				}
284
-			}
285
-			clearstatcache();
286
-		}
254
+        $IDs = array();
255
+        if($custom === false) {
256
+            $this->modx->clearCache();
257
+            include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php');
258
+            $sync = new synccache();
259
+            $path = $this->getCachePath(true);
260
+            $sync->setCachepath($path);
261
+            $sync->setReport(false);
262
+            $sync->emptyCache();
263
+        }else {
264
+            if(is_scalar($custom)){
265
+                $custom = array($custom);
266
+            }
267
+            switch ($this->modx->config['cache_type']) {
268
+                case 2:
269
+                    $cacheFile = "_*.pageCache.php";
270
+                    break;
271
+                default:
272
+                    $cacheFile = ".pageCache.php";
273
+            }
274
+            if(is_array($custom)) {
275
+                foreach($custom as $id) {
276
+                    $tmp = glob(MODX_BASE_PATH."assets/cache/docid_" . $id . $cacheFile);
277
+                    foreach($tmp as $file){
278
+                        if(is_readable($file)){
279
+                            unlink($file);
280
+                        }
281
+                        $IDs[] = $id;
282
+                    }
283
+                }
284
+            }
285
+            clearstatcache();
286
+        }
287 287
         $this->invokeEvent('OnSiteRefresh', array('IDs' => $IDs), $fire_events);
288 288
     }
289 289
 
@@ -314,16 +314,16 @@  discard block
 block discarded – undo
314 314
      * @return $this
315 315
      */
316 316
     public function useIgnore($flag = true){
317
-		$this->ignoreError = $flag ? 'IGNORE' : '';
318
-		return $this;
319
-	}
317
+        $this->ignoreError = $flag ? 'IGNORE' : '';
318
+        return $this;
319
+    }
320 320
 
321 321
     /**
322 322
      * @return bool
323 323
      */
324 324
     public function hasIgnore(){
325
-		return (bool)$this->ignoreError;
326
-	}
325
+        return (bool)$this->ignoreError;
326
+    }
327 327
 
328 328
     /**
329 329
      * @param $key
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
             $this->log[] = "{$key} is empty";
383 383
         } else {
384 384
             if ($this->issetField($key) && is_scalar($this->field[$key])) {
385
-            	$tmp = "`{$key}`='{$this->escape($this->field[$key])}'";
386
-			} else throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>");
385
+                $tmp = "`{$key}`='{$this->escape($this->field[$key])}'";
386
+            } else throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>");
387 387
         }
388 388
         if (!empty($tmp)) {
389 389
             if ($id == '') {
@@ -408,11 +408,11 @@  discard block
 block discarded – undo
408 408
         $out = array();
409 409
         if (!is_array($IDs)) {
410 410
             if (is_scalar($IDs)) {
411
-            	$IDs = explode($sep, $IDs);
412
-			} else {
413
-            	$IDs = array();
411
+                $IDs = explode($sep, $IDs);
412
+            } else {
413
+                $IDs = array();
414 414
                 throw new Exception('Invalid IDs list <pre>' . print_r($IDs, 1) . '</pre>');
415
-			}
415
+            }
416 416
         }
417 417
         foreach ($IDs as $item) {
418 418
             $item = trim($item);
@@ -437,21 +437,21 @@  discard block
 block discarded – undo
437 437
     final public function fromJson($data, $callback = null)
438 438
     {
439 439
         if (is_scalar($data) && !empty($data)) {
440
-        	$json = json_decode($data);
441
-		} else throw new Exception("json is not string with json data");
442
-
443
-		if ($this->jsonError($json)) {
444
-        	if (isset($callback) && is_callable($callback)) {
445
-            	call_user_func_array($callback, array($json));
446
-			} else {
447
-            	if (isset($callback)) throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
440
+            $json = json_decode($data);
441
+        } else throw new Exception("json is not string with json data");
442
+
443
+        if ($this->jsonError($json)) {
444
+            if (isset($callback) && is_callable($callback)) {
445
+                call_user_func_array($callback, array($json));
446
+            } else {
447
+                if (isset($callback)) throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
448 448
                 foreach ($json as $key => $val) {
449
-                	$this->set($key, $val);
450
-				}
451
-			}
452
-		} else throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
449
+                    $this->set($key, $val);
450
+                }
451
+            }
452
+        } else throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
453 453
 
454
-		return $this;
454
+        return $this;
455 455
     }
456 456
 
457 457
     /**
@@ -463,17 +463,17 @@  discard block
 block discarded – undo
463 463
     {
464 464
         $data = $this->toArray();
465 465
         if (isset($callback) && is_callable($callback)) {
466
-        	$data = call_user_func_array($callback, array($data));
467
-		} else {
468
-        	if (isset($callback)) throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
469
-		}
466
+            $data = call_user_func_array($callback, array($data));
467
+        } else {
468
+            if (isset($callback)) throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
469
+        }
470 470
         $json = json_encode($data);
471 471
 
472
-		if ($this->jsonError($data)) {
473
-        	throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
474
-		}
472
+        if ($this->jsonError($data)) {
473
+            throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
474
+        }
475 475
 
476
-		return $json;
476
+        return $json;
477 477
     }
478 478
 
479 479
     /**
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
      * @return array
771 771
      */
772 772
     public function getNoDecodeFields(){
773
-       return $this->_decodedFields->filter(function($value){
773
+        return $this->_decodedFields->filter(function($value){
774 774
             return ($value === true);
775 775
         });
776 776
     }
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     public function __construct(DocumentParser $modx, $debug = false)
93 93
     {	
94 94
     	$this->modx = $modx;
95
-        if(function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()){
95
+        if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) {
96 96
         	throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.');
97 97
 		}
98 98
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
      * @param $flag
105 105
      * @return $this
106 106
      */
107
-    public function setDebug($flag){
107
+    public function setDebug($flag) {
108 108
         $this->_debug = (bool)$flag;
109 109
         return $this;
110 110
     }
@@ -112,14 +112,14 @@  discard block
 block discarded – undo
112 112
     /**
113 113
      * @return bool
114 114
      */
115
-    public function getDebug(){
115
+    public function getDebug() {
116 116
         return $this->_debug;
117 117
     }
118 118
 
119 119
     /**
120 120
      * @return array
121 121
      */
122
-    public function getDefaultFields(){
122
+    public function getDefaultFields() {
123 123
         return $this->default_field;
124 124
     }
125 125
 
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
      * @param $q
138 138
      * @return $this
139 139
      */
140
-    public function addQuery($q){
141
-        if(is_scalar($q) && !empty($q)){
140
+    public function addQuery($q) {
141
+        if (is_scalar($q) && !empty($q)) {
142 142
             $this->_query[] = $q;
143 143
         }
144 144
         return $this;
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     /**
148 148
      * @return array
149 149
      */
150
-    public function getQueryList(){
150
+    public function getQueryList() {
151 151
         return $this->_query;
152 152
     }
153 153
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      */
158 158
     final public function query($SQL)
159 159
     {
160
-        if($this->getDebug()){
160
+        if ($this->getDebug()) {
161 161
             $this->addQuery($SQL);
162 162
         }
163 163
         return empty($SQL) ? null : $this->modx->db->query($SQL);
@@ -167,10 +167,10 @@  discard block
 block discarded – undo
167 167
      * @param $value
168 168
      * @return string
169 169
      */
170
-    final public function escape($value){
171
-        if(!is_scalar($value)){
170
+    final public function escape($value) {
171
+        if (!is_scalar($value)) {
172 172
             $value = '';
173
-        }else{
173
+        } else {
174 174
             $value = $this->modx->db->escape($value);
175 175
         }
176 176
         return $value;
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      */
228 228
     final public function list_log($flush = false)
229 229
     {
230
-        echo '<pre>' . print_r(APIHelpers::sanitarTag($this->log), true) . '</pre>';
230
+        echo '<pre>'.print_r(APIHelpers::sanitarTag($this->log), true).'</pre>';
231 231
         if ($flush) $this->clearLog();
232 232
         return $this;
233 233
     }
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     {
241 241
         $path = $this->modx->getCachePath();
242 242
         if ($full) {
243
-            $path = MODX_BASE_PATH . substr($path, strlen(MODX_BASE_URL));
243
+            $path = MODX_BASE_PATH.substr($path, strlen(MODX_BASE_URL));
244 244
         }
245 245
         return $path;
246 246
     }
@@ -252,16 +252,16 @@  discard block
 block discarded – undo
252 252
     final public function clearCache($fire_events = null, $custom = false)
253 253
     {
254 254
 		$IDs = array();
255
-		if($custom === false) {
255
+		if ($custom === false) {
256 256
 			$this->modx->clearCache();
257
-			include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php');
257
+			include_once(MODX_MANAGER_PATH.'processors/cache_sync.class.processor.php');
258 258
 			$sync = new synccache();
259 259
 			$path = $this->getCachePath(true);
260 260
 			$sync->setCachepath($path);
261 261
 			$sync->setReport(false);
262 262
 			$sync->emptyCache();
263
-		}else {
264
-			if(is_scalar($custom)){
263
+		} else {
264
+			if (is_scalar($custom)) {
265 265
 				$custom = array($custom);
266 266
 			}
267 267
 			switch ($this->modx->config['cache_type']) {
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
 				default:
272 272
 					$cacheFile = ".pageCache.php";
273 273
 			}
274
-			if(is_array($custom)) {
275
-				foreach($custom as $id) {
276
-					$tmp = glob(MODX_BASE_PATH."assets/cache/docid_" . $id . $cacheFile);
277
-					foreach($tmp as $file){
278
-						if(is_readable($file)){
274
+			if (is_array($custom)) {
275
+				foreach ($custom as $id) {
276
+					$tmp = glob(MODX_BASE_PATH."assets/cache/docid_".$id.$cacheFile);
277
+					foreach ($tmp as $file) {
278
+						if (is_readable($file)) {
279 279
 							unlink($file);
280 280
 						}
281 281
 						$IDs[] = $id;
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
      * @param $id
292 292
      * @return MODxAPI
293 293
      */
294
-    public function switchObject($id){
295
-        switch(true){
294
+    public function switchObject($id) {
295
+        switch (true) {
296 296
             //Если загружен другой объект - не тот, с которым мы хотим временно поработать
297 297
             case ($this->getID() != $id && $id):
298 298
                 $obj = clone $this;
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
      * @param bool $flag
314 314
      * @return $this
315 315
      */
316
-    public function useIgnore($flag = true){
316
+    public function useIgnore($flag = true) {
317 317
 		$this->ignoreError = $flag ? 'IGNORE' : '';
318 318
 		return $this;
319 319
 	}
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     /**
322 322
      * @return bool
323 323
      */
324
-    public function hasIgnore(){
324
+    public function hasIgnore() {
325 325
 		return (bool)$this->ignoreError;
326 326
 	}
327 327
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
         } else {
384 384
             if ($this->issetField($key) && is_scalar($this->field[$key])) {
385 385
             	$tmp = "`{$key}`='{$this->escape($this->field[$key])}'";
386
-			} else throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>");
386
+			} else throw new Exception("{$key} is invalid <pre>".print_r($this->field[$key], true)."</pre>");
387 387
         }
388 388
         if (!empty($tmp)) {
389 389
             if ($id == '') {
@@ -411,14 +411,14 @@  discard block
 block discarded – undo
411 411
             	$IDs = explode($sep, $IDs);
412 412
 			} else {
413 413
             	$IDs = array();
414
-                throw new Exception('Invalid IDs list <pre>' . print_r($IDs, 1) . '</pre>');
414
+                throw new Exception('Invalid IDs list <pre>'.print_r($IDs, 1).'</pre>');
415 415
 			}
416 416
         }
417 417
         foreach ($IDs as $item) {
418 418
             $item = trim($item);
419 419
             if (is_scalar($item) && (int)$item >= 0) { //Fix 0xfffffffff
420 420
                 if (!empty($ignore) && in_array((int)$item, $ignore, true)) {
421
-                    $this->log[] = 'Ignore id ' . (int)$item;
421
+                    $this->log[] = 'Ignore id '.(int)$item;
422 422
                 } else {
423 423
                     $out[] = (int)$item;
424 424
                 }
@@ -444,12 +444,12 @@  discard block
 block discarded – undo
444 444
         	if (isset($callback) && is_callable($callback)) {
445 445
             	call_user_func_array($callback, array($json));
446 446
 			} else {
447
-            	if (isset($callback)) throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
447
+            	if (isset($callback)) throw new Exception("Can't call callback JSON unpack <pre>".print_r($callback, 1)."</pre>");
448 448
                 foreach ($json as $key => $val) {
449 449
                 	$this->set($key, $val);
450 450
 				}
451 451
 			}
452
-		} else throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
452
+		} else throw new Exception('Error from JSON decode: <pre>'.print_r($data, 1).'</pre>');
453 453
 
454 454
 		return $this;
455 455
     }
@@ -465,12 +465,12 @@  discard block
 block discarded – undo
465 465
         if (isset($callback) && is_callable($callback)) {
466 466
         	$data = call_user_func_array($callback, array($data));
467 467
 		} else {
468
-        	if (isset($callback)) throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
468
+        	if (isset($callback)) throw new Exception("Can't call callback JSON pre pack <pre>".print_r($callback, 1)."</pre>");
469 469
 		}
470 470
         $json = json_encode($data);
471 471
 
472 472
 		if ($this->jsonError($data)) {
473
-        	throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
473
+        	throw new Exception('Error from JSON decode: <pre>'.print_r($data, 1).'</pre>');
474 474
 		}
475 475
 
476 476
 		return $json;
@@ -500,11 +500,11 @@  discard block
 block discarded – undo
500 500
         $tpl = '';
501 501
         $plh = '[+key+]';
502 502
         if ($prefix !== '') {
503
-            $tpl = $prefix . $sep;
503
+            $tpl = $prefix.$sep;
504 504
         }
505 505
         $tpl .= $plh;
506 506
         if ($suffix !== '') {
507
-            $tpl .= $sep . $suffix;
507
+            $tpl .= $sep.$suffix;
508 508
         }
509 509
         $out = array();
510 510
         $fields = $this->field;
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
     /**
523 523
      * @return string
524 524
      */
525
-    final public function fieldPKName(){
525
+    final public function fieldPKName() {
526 526
         return $this->pkName;
527 527
     }
528 528
 
@@ -548,11 +548,11 @@  discard block
 block discarded – undo
548 548
         }
549 549
         $out = array();
550 550
         foreach ($data as $item) {
551
-            if($item !== ''){
551
+            if ($item !== '') {
552 552
                 $out[] = $this->escape($item);
553 553
             }
554 554
         }
555
-        $out = empty($out) ? '' : "'" . implode("','", $out) . "'";
555
+        $out = empty($out) ? '' : "'".implode("','", $out)."'";
556 556
         return $out;
557 557
     }
558 558
 
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
                 if ($val != '')
572 572
                     $where[] = "`".$this->escape($_field)."` = '".$this->escape($val)."'";
573 573
             }
574
-            $where = implode(' AND ',$where);
574
+            $where = implode(' AND ', $where);
575 575
         } else {
576 576
             $where = '';
577 577
             $val = $this->get($field);
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
         }
581 581
         
582 582
         if ($where != '') {
583
-            $sql = $this->query("SELECT `" . $this->escape($PK) . "` FROM " . $this->makeTable($table) . " WHERE ".$where);
583
+            $sql = $this->query("SELECT `".$this->escape($PK)."` FROM ".$this->makeTable($table)." WHERE ".$where);
584 584
             $id = $this->modx->db->getValue($sql);
585 585
             if (is_null($id) || (!$this->newDoc && $id == $this->getID())) {
586 586
                 $flag = true;
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
         if (version_compare($tmp, $version, '>=')) {
679 679
             $flag = true;
680 680
             if ($dmi3yy) {
681
-                $flag = (boolean)preg_match('/^' . $tmp . '(.*)\-d/', $currentVer);
681
+                $flag = (boolean)preg_match('/^'.$tmp.'(.*)\-d/', $currentVer);
682 682
             }
683 683
         }
684 684
         return $flag;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
      * @param  string $field имя поля
704 704
      * @return boolean
705 705
      */
706
-    public function isJsonField($field){
706
+    public function isJsonField($field) {
707 707
         return (is_scalar($field) && in_array($field, $this->jsonFields));
708 708
     }
709 709
 
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
      * @param  string $field имя поля
713 713
      * @return $this
714 714
      */
715
-    public function markAsDecode($field){
716
-        if(is_scalar($field)){
715
+    public function markAsDecode($field) {
716
+        if (is_scalar($field)) {
717 717
             $this->_decodedFields->set($field, false);
718 718
         }
719 719
         return $this;
@@ -724,8 +724,8 @@  discard block
 block discarded – undo
724 724
      * @param  string $field имя поля
725 725
      * @return $this
726 726
      */
727
-    public function markAsEncode($field){
728
-        if(is_scalar($field)){
727
+    public function markAsEncode($field) {
728
+        if (is_scalar($field)) {
729 729
             $this->_decodedFields->set($field, true);
730 730
         }
731 731
         return $this;
@@ -735,9 +735,9 @@  discard block
 block discarded – undo
735 735
      * Пометить все поля как запакованные
736 736
      * @return $this
737 737
      */
738
-    public function markAllEncode(){
738
+    public function markAllEncode() {
739 739
         $this->_decodedFields->clear();
740
-        foreach($this->jsonFields as $field){
740
+        foreach ($this->jsonFields as $field) {
741 741
             $this->markAsEncode($field);
742 742
         }
743 743
         return $this;
@@ -747,9 +747,9 @@  discard block
 block discarded – undo
747 747
      * Пометить все поля как распакованные
748 748
      * @return $this
749 749
      */
750
-    public function markAllDecode(){
750
+    public function markAllDecode() {
751 751
         $this->_decodedFields->clear();
752
-        foreach($this->jsonFields as $field){
752
+        foreach ($this->jsonFields as $field) {
753 753
             $this->markAsDecode($field);
754 754
         }
755 755
         return $this;
@@ -759,8 +759,8 @@  discard block
 block discarded – undo
759 759
      * Получить список не запакованных полей
760 760
      * @return array
761 761
      */
762
-    public function getNoEncodeFields(){
763
-        return $this->_decodedFields->filter(function($value){
762
+    public function getNoEncodeFields() {
763
+        return $this->_decodedFields->filter(function($value) {
764 764
             return ($value === false);
765 765
         });
766 766
     }
@@ -769,8 +769,8 @@  discard block
 block discarded – undo
769 769
      * Получить список не распакованных полей
770 770
      * @return array
771 771
      */
772
-    public function getNoDecodeFields(){
773
-       return $this->_decodedFields->filter(function($value){
772
+    public function getNoDecodeFields() {
773
+       return $this->_decodedFields->filter(function($value) {
774 774
             return ($value === true);
775 775
         });
776 776
     }
@@ -780,12 +780,12 @@  discard block
 block discarded – undo
780 780
      * @param  string $field имя поля
781 781
      * @return boolean
782 782
      */
783
-    public function isDecodableField($field){
783
+    public function isDecodableField($field) {
784 784
         $data = $this->get($field);
785 785
         /**
786 786
          * Если поле скалярного типа и оно не распаковывалось раньше
787 787
          */
788
-        return (is_scalar($data) && is_scalar($field) && $this->_decodedFields->get($field)===true);
788
+        return (is_scalar($data) && is_scalar($field) && $this->_decodedFields->get($field) === true);
789 789
     }
790 790
 
791 791
     /**
@@ -793,11 +793,11 @@  discard block
 block discarded – undo
793 793
      * @param  string  $field имя поля
794 794
      * @return boolean
795 795
      */
796
-    public function isEncodableField($field){
796
+    public function isEncodableField($field) {
797 797
         /**
798 798
          * Если поле было распаковано ранее и еще не упаковано
799 799
          */
800
-        return (is_scalar($field) && $this->_decodedFields->get($field)===false);
800
+        return (is_scalar($field) && $this->_decodedFields->get($field) === false);
801 801
     }
802 802
 
803 803
     /**
@@ -806,13 +806,13 @@  discard block
 block discarded – undo
806 806
      * @param  bool $store обновить распакованное поле
807 807
      * @return array ассоциативный массив с данными из json строки
808 808
      */
809
-    public function decodeField($field, $store = false){
809
+    public function decodeField($field, $store = false) {
810 810
         $out = array();
811
-        if($this->isDecodableField($field)){
811
+        if ($this->isDecodableField($field)) {
812 812
             $data = $this->get($field);
813 813
             $out = jsonHelper::jsonDecode($data, array('assoc' => true), true);
814 814
         }
815
-        if($store){
815
+        if ($store) {
816 816
             $this->field[$field] = $out;
817 817
             $this->markAsDecode($field);
818 818
         }
@@ -823,8 +823,8 @@  discard block
 block discarded – undo
823 823
      * Декодирование всех json полей
824 824
      * @return $this
825 825
      */
826
-    protected function decodeFields(){
827
-        foreach($this->getNoDecodeFields() as $field => $flag){
826
+    protected function decodeFields() {
827
+        foreach ($this->getNoDecodeFields() as $field => $flag) {
828 828
             $this->decodeField($field, true);
829 829
         }
830 830
         return $this;
@@ -836,13 +836,13 @@  discard block
 block discarded – undo
836 836
      * @param  bool $store обновить запакованное поле
837 837
      * @return array json строка
838 838
      */
839
-    public function encodeField($field, $store = false){
839
+    public function encodeField($field, $store = false) {
840 840
         $out = null;
841
-        if($this->isEncodableField($field)){
841
+        if ($this->isEncodableField($field)) {
842 842
             $data = $this->get($field);
843 843
             $out = json_encode($data);
844 844
         }
845
-        if($store){
845
+        if ($store) {
846 846
             $this->field[$field] = $out;
847 847
             $this->markAsEncode($field);
848 848
         }
@@ -853,8 +853,8 @@  discard block
 block discarded – undo
853 853
      * Запаковка всех json полей
854 854
      * @return $this
855 855
      */
856
-    protected function encodeFields(){
857
-        foreach($this->getNoEncodeFields() as $field => $flag){
856
+    protected function encodeFields() {
857
+        foreach ($this->getNoEncodeFields() as $field => $flag) {
858 858
             $this->encodeField($field, true);
859 859
         }
860 860
         return $this;
Please login to merge, or discard this patch.
assets/snippets/DLUsers/src/Actions.php 3 patches
Doc Comments   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,6 +50,8 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * is not allowed to call from outside: private!
52 52
      *
53
+     * @param string $userClass
54
+     * @param boolean $debug
53 55
      */
54 56
     private function __construct(DocumentParser $modx, $userClass, $debug)
55 57
     {
@@ -285,9 +287,9 @@  discard block
 block discarded – undo
285 287
      * @param $emailField
286 288
      * @param $rememberField
287 289
      * @param $backUrl
288
-     * @param $method
289
-     * @param $error
290
-     * @param $errorCode
290
+     * @param string $method
291
+     * @param string $error
292
+     * @param string $errorCode
291 293
      * @param array $params
292 294
      * @return array
293 295
      */
@@ -468,7 +470,7 @@  discard block
 block discarded – undo
468 470
 	}
469 471
 
470 472
     /**
471
-     * @param $name
473
+     * @param string $name
472 474
      * @return string
473 475
      */
474 476
     protected function getTemplate($name){
Please login to merge, or discard this patch.
Indentation   +391 added lines, -391 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
 class Actions{
17 17
     protected $modx = null;
18 18
     public $userObj = null;
19
-	/**
20
-	 * @var DLCollection
21
-	 */
19
+    /**
20
+     * @var DLCollection
21
+     */
22 22
     public $url;
23 23
     protected static $lang = null;
24 24
     protected static $langDic = array();
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      */
28 28
     protected static $instance;
29 29
 
30
-	protected $config = array();
30
+    protected $config = array();
31 31
 
32 32
     /**
33 33
      * gets the instance via lazy initialization (created on first usage)
@@ -54,15 +54,15 @@  discard block
 block discarded – undo
54 54
     private function __construct(DocumentParser $modx, $userClass, $debug)
55 55
     {
56 56
         $this->modx = $modx;
57
-		$this->userObj = new $userClass($this->modx, $debug);
58
-		$this->url = new DLCollection($this->modx);
57
+        $this->userObj = new $userClass($this->modx, $debug);
58
+        $this->url = new DLCollection($this->modx);
59 59
 
60
-		$site_url = $this->modx->getConfig('site_url');
61
-		$site_start = $this->modx->getConfig('site_start', 1);
62
-		$error_page = $this->modx->getConfig('error_page', $site_start);
63
-		$unauthorized_page = $this->modx->getConfig('unauthorized_page', $error_page);
60
+        $site_url = $this->modx->getConfig('site_url');
61
+        $site_start = $this->modx->getConfig('site_start', 1);
62
+        $error_page = $this->modx->getConfig('error_page', $site_start);
63
+        $unauthorized_page = $this->modx->getConfig('unauthorized_page', $error_page);
64 64
 
65
-		$this->config = compact('site_url', 'site_start', 'error_page', 'unauthorized_page');
65
+        $this->config = compact('site_url', 'site_start', 'error_page', 'unauthorized_page');
66 66
     }
67 67
 
68 68
     /**
@@ -89,47 +89,47 @@  discard block
 block discarded – undo
89 89
      * Сброс авторизации и обновление страницы
90 90
      */
91 91
     public function logout($params){
92
-    	$LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout');
93
-    	if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){
94
-    		$userID = $this->UserID('web');
95
-    		if($userID){
96
-    			$this->userObj->edit($userID);
97
-    			if($this->userObj->getID()){
98
-	    			$this->modx->invokeEvent("OnBeforeWebLogout", array(
99
-		    			"userid"   => $this->userObj->getID(),
100
-		    			"username" => $this->userObj->get('username')
101
-		    		));
102
-	    		}
103
-		    	$this->userObj->logOut();
104
-		    	if($this->userObj->getID()){
105
-		    		$this->modx->invokeEvent("OnWebLogout", array(
106
-		    			"userid"        => $this->userObj->getID(),
107
-		    			"username"      => $this->userObj->get('username')
108
-		    		));
109
-		    	}
110
-
111
-			    $go = APIHelpers::getkey($params, 'url', '');
112
-			    if(empty($go)){
113
-			    	$go = str_replace(
114
-			    		array("?".$LogoutName, "&".$LogoutName),
115
-			    		array("", ""),
116
-			    		$_SERVER['REQUEST_URI']
117
-			    	);
118
-			    }
119
-
120
-			    $start = $this->makeUrl($this->config['site_start']);
121
-			    if($start == $go){
122
-			        $go = $this->config['site_url'];
123
-			    }else{
124
-			        $go = $this->config['site_url'].ltrim($go, '/');
125
-			    }
126
-			    $this->moveTo(array('url' => $go));
127
-    		}else{
128
-    			//Если юзер не авторизован, то показываем ему 404 ошибку
129
-    			$this->modx->sendErrorPage();
130
-    		}
131
-		}
132
-	    return true;
92
+        $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout');
93
+        if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){
94
+            $userID = $this->UserID('web');
95
+            if($userID){
96
+                $this->userObj->edit($userID);
97
+                if($this->userObj->getID()){
98
+                    $this->modx->invokeEvent("OnBeforeWebLogout", array(
99
+                        "userid"   => $this->userObj->getID(),
100
+                        "username" => $this->userObj->get('username')
101
+                    ));
102
+                }
103
+                $this->userObj->logOut();
104
+                if($this->userObj->getID()){
105
+                    $this->modx->invokeEvent("OnWebLogout", array(
106
+                        "userid"        => $this->userObj->getID(),
107
+                        "username"      => $this->userObj->get('username')
108
+                    ));
109
+                }
110
+
111
+                $go = APIHelpers::getkey($params, 'url', '');
112
+                if(empty($go)){
113
+                    $go = str_replace(
114
+                        array("?".$LogoutName, "&".$LogoutName),
115
+                        array("", ""),
116
+                        $_SERVER['REQUEST_URI']
117
+                    );
118
+                }
119
+
120
+                $start = $this->makeUrl($this->config['site_start']);
121
+                if($start == $go){
122
+                    $go = $this->config['site_url'];
123
+                }else{
124
+                    $go = $this->config['site_url'].ltrim($go, '/');
125
+                }
126
+                $this->moveTo(array('url' => $go));
127
+            }else{
128
+                //Если юзер не авторизован, то показываем ему 404 ошибку
129
+                $this->modx->sendErrorPage();
130
+            }
131
+        }
132
+        return true;
133 133
     }
134 134
 
135 135
     /**
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
      * @return string
138 138
      */
139 139
     public function logoutUrl($params){
140
-    	$LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout');
141
-    	$request = parse_url($_SERVER['REQUEST_URI']);
140
+        $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout');
141
+        $request = parse_url($_SERVER['REQUEST_URI']);
142 142
 
143
-    	//Во избежании XSS мы не сохраняем весь REQUEST_URI, а берем только path
144
-    	/*$query = (!empty($request['query'])) ? $request['query'].'&' : '';*/
145
-    	$query = '?'.$LogoutName;
143
+        //Во избежании XSS мы не сохраняем весь REQUEST_URI, а берем только path
144
+        /*$query = (!empty($request['query'])) ? $request['query'].'&' : '';*/
145
+        $query = '?'.$LogoutName;
146 146
 
147
-    	return $request['path'].$query;
147
+        return $request['path'].$query;
148 148
     }
149 149
 
150 150
     /**
@@ -153,132 +153,132 @@  discard block
 block discarded – undo
153 153
      *   	В противном случае вся работа происходит внутри самого блока
154 154
      */
155 155
     public function AuthBlock($params){
156
-    	$POST = array('backUrl' => $_SERVER['REQUEST_URI']);
157
-
158
-    	$error = $errorCode = '';
159
-
160
-    	$pwdField = APIHelpers::getkey($params, 'pwdField', 'password');
161
-		$emailField = APIHelpers::getkey($params, 'emailField', 'email');
162
-		$rememberField = APIHelpers::getkey($params, 'rememberField', 'remember');
163
-
164
-    	if($this->UserID('web')){
165
-			$tpl = APIHelpers::getkey($params, 'tplProfile', '');
166
-			if(empty($tpl)){
167
-				$tpl = $this->getTemplate('tplProfile');
168
-			}
169
-			$dataTPL = $this->userObj->toArray();
170
-			$dataTPL['url.logout'] = $this->logoutUrl($params);
171
-    		$homeID = APIHelpers::getkey($params, 'homeID');
172
-			if(!empty($homeID)){
173
-				$dataTPL['url.profile'] = $this->makeUrl($homeID);
174
-			}
175
-		}else{
176
-			$tpl = APIHelpers::getkey($params, 'tplForm', '');
177
-			if(empty($tpl)){
178
-				$tpl = $this->getTemplate('authForm');
179
-			}
180
-			$POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params);
181
-	    	$dataTPL = array(
182
-				'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''),
183
-				'emailValue' => APIHelpers::getkey($POST, 'email', ''),
184
-				'emailField' => $emailField,
185
-				'pwdField' => $pwdField,
186
-		    	'method' => strtolower(__METHOD__),
187
-				'error' => $error,
188
-				'errorCode' => $errorCode
189
-			);
190
-			$authId = APIHelpers::getkey($params, 'authId');
191
-			if(!empty($authId)){
192
-				$dataTPL['authPage'] = $this->makeUrl($authId);
193
-				$dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage');
194
-			}
195
-		}
196
-		return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL);
156
+        $POST = array('backUrl' => $_SERVER['REQUEST_URI']);
157
+
158
+        $error = $errorCode = '';
159
+
160
+        $pwdField = APIHelpers::getkey($params, 'pwdField', 'password');
161
+        $emailField = APIHelpers::getkey($params, 'emailField', 'email');
162
+        $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember');
163
+
164
+        if($this->UserID('web')){
165
+            $tpl = APIHelpers::getkey($params, 'tplProfile', '');
166
+            if(empty($tpl)){
167
+                $tpl = $this->getTemplate('tplProfile');
168
+            }
169
+            $dataTPL = $this->userObj->toArray();
170
+            $dataTPL['url.logout'] = $this->logoutUrl($params);
171
+            $homeID = APIHelpers::getkey($params, 'homeID');
172
+            if(!empty($homeID)){
173
+                $dataTPL['url.profile'] = $this->makeUrl($homeID);
174
+            }
175
+        }else{
176
+            $tpl = APIHelpers::getkey($params, 'tplForm', '');
177
+            if(empty($tpl)){
178
+                $tpl = $this->getTemplate('authForm');
179
+            }
180
+            $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params);
181
+            $dataTPL = array(
182
+                'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''),
183
+                'emailValue' => APIHelpers::getkey($POST, 'email', ''),
184
+                'emailField' => $emailField,
185
+                'pwdField' => $pwdField,
186
+                'method' => strtolower(__METHOD__),
187
+                'error' => $error,
188
+                'errorCode' => $errorCode
189
+            );
190
+            $authId = APIHelpers::getkey($params, 'authId');
191
+            if(!empty($authId)){
192
+                $dataTPL['authPage'] = $this->makeUrl($authId);
193
+                $dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage');
194
+            }
195
+        }
196
+        return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL);
197 197
     }
198 198
 
199
-	/**
200
-	 * Авторизация на сайте со страницы авторизации
201
-	 * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!]
202
-	 */
203
-	public function AuthPage($params){
204
-		$homeID = APIHelpers::getkey($params, 'homeID');
205
-		$this->isAuthGoHome(array('id' => $homeID));
206
-
207
-		$error = $errorCode = '';
208
-		$POST = array('backUrl' => '');
209
-
210
-		$pwdField = APIHelpers::getkey($params, 'pwdField', 'password');
211
-		$emailField = APIHelpers::getkey($params, 'emailField', 'email');
212
-		$rememberField = APIHelpers::getkey($params, 'rememberField', 'remember');
213
-
214
-		$tpl = APIHelpers::getkey($params, 'tpl', '');
215
-		if(empty($tpl)){
216
-			$tpl = $this->getTemplate('authForm');
217
-		}
218
-
219
-		$request = parse_url($_SERVER['REQUEST_URI']);
220
-		if(!empty($_SERVER['HTTP_REFERER'])){
221
-			/**
222
-			 * Thank you for super protection against hacking in protect.inc.php:-)
223
-			 */
224
-			$refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES);
225
-		}else{
226
-			$selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
227
-			if(empty( $request['host']) ||  $request['host']==$selfHost){
228
-				$query = !empty($request['query']) ? '?'.$request['query'] : '';
229
-			    $refer = !empty($request['path']) ? $request['path'].$query : '';
230
-			}else{
231
-				$refer = '';
232
-			}
233
-		}
234
-
235
-		if($_SERVER['REQUEST_METHOD'] == 'POST'){
236
-			$backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']);
237
-			if(!is_scalar($backUrl)){
238
-				$backUrl = $refer;
239
-			}else{
240
-				$backUrl = urldecode($backUrl);
241
-			}
242
-		}else{
243
-			$backUrl = $refer;
244
-		}
245
-		$backUrl = parse_url($backUrl);
246
-		if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){
247
-		    $POST['backUrl'] = $backUrl['path'];
248
-		}else{
249
-			$selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
250
-			if(empty($backUrl['host']) || $backUrl['host']==$selfHost){
251
-				$query = !empty($backUrl['query']) ? '?'.$backUrl['query'] : '';
252
-			    $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : '';
253
-			}else{
254
-				$POST['backUrl'] = '';
255
-			}
256
-		}
257
-		if(!empty($POST['backUrl'])){
258
-			$idURL = $this->moveTo(array(
259
-				'url' => '/'.ltrim($POST['backUrl'], '/'),
260
-			    'validate' => true
261
-			));
262
-		}else{
263
-			$idURL = 0;
264
-		}
265
-		if(empty($idURL)){
266
-			if(empty($homeID)){
267
-				$homeID = $this->config['site_start'];
268
-			}
269
-			$POST['backUrl'] = $this->makeUrl($homeID);
270
-		}
271
-		$POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params);
272
-		return DLTemplate::getInstance($this->modx)->parseChunk($tpl, array(
273
-		    'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''),
274
-			'emailValue' => APIHelpers::getkey($POST, 'email', ''),
275
-			'emailField' => $emailField,
276
-		    'pwdField' => $pwdField,
277
-		    'method' => strtolower(__METHOD__),
278
-			'error' => $error,
279
-			'errorCode' => $errorCode
280
-		));
281
-	}
199
+    /**
200
+     * Авторизация на сайте со страницы авторизации
201
+     * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!]
202
+     */
203
+    public function AuthPage($params){
204
+        $homeID = APIHelpers::getkey($params, 'homeID');
205
+        $this->isAuthGoHome(array('id' => $homeID));
206
+
207
+        $error = $errorCode = '';
208
+        $POST = array('backUrl' => '');
209
+
210
+        $pwdField = APIHelpers::getkey($params, 'pwdField', 'password');
211
+        $emailField = APIHelpers::getkey($params, 'emailField', 'email');
212
+        $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember');
213
+
214
+        $tpl = APIHelpers::getkey($params, 'tpl', '');
215
+        if(empty($tpl)){
216
+            $tpl = $this->getTemplate('authForm');
217
+        }
218
+
219
+        $request = parse_url($_SERVER['REQUEST_URI']);
220
+        if(!empty($_SERVER['HTTP_REFERER'])){
221
+            /**
222
+             * Thank you for super protection against hacking in protect.inc.php:-)
223
+             */
224
+            $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES);
225
+        }else{
226
+            $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
227
+            if(empty( $request['host']) ||  $request['host']==$selfHost){
228
+                $query = !empty($request['query']) ? '?'.$request['query'] : '';
229
+                $refer = !empty($request['path']) ? $request['path'].$query : '';
230
+            }else{
231
+                $refer = '';
232
+            }
233
+        }
234
+
235
+        if($_SERVER['REQUEST_METHOD'] == 'POST'){
236
+            $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']);
237
+            if(!is_scalar($backUrl)){
238
+                $backUrl = $refer;
239
+            }else{
240
+                $backUrl = urldecode($backUrl);
241
+            }
242
+        }else{
243
+            $backUrl = $refer;
244
+        }
245
+        $backUrl = parse_url($backUrl);
246
+        if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){
247
+            $POST['backUrl'] = $backUrl['path'];
248
+        }else{
249
+            $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
250
+            if(empty($backUrl['host']) || $backUrl['host']==$selfHost){
251
+                $query = !empty($backUrl['query']) ? '?'.$backUrl['query'] : '';
252
+                $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : '';
253
+            }else{
254
+                $POST['backUrl'] = '';
255
+            }
256
+        }
257
+        if(!empty($POST['backUrl'])){
258
+            $idURL = $this->moveTo(array(
259
+                'url' => '/'.ltrim($POST['backUrl'], '/'),
260
+                'validate' => true
261
+            ));
262
+        }else{
263
+            $idURL = 0;
264
+        }
265
+        if(empty($idURL)){
266
+            if(empty($homeID)){
267
+                $homeID = $this->config['site_start'];
268
+            }
269
+            $POST['backUrl'] = $this->makeUrl($homeID);
270
+        }
271
+        $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params);
272
+        return DLTemplate::getInstance($this->modx)->parseChunk($tpl, array(
273
+            'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''),
274
+            'emailValue' => APIHelpers::getkey($POST, 'email', ''),
275
+            'emailField' => $emailField,
276
+            'pwdField' => $pwdField,
277
+            'method' => strtolower(__METHOD__),
278
+            'error' => $error,
279
+            'errorCode' => $errorCode
280
+        ));
281
+    }
282 282
 
283 283
     /**
284 284
      * @param $pwdField
@@ -292,213 +292,213 @@  discard block
 block discarded – undo
292 292
      * @return array
293 293
      */
294 294
     protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){
295
-		$POST = array(
296
-			'backUrl' => urlencode($backUrl)
297
-		);
298
-		$userObj = &$this->userObj;
299
-		if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){
300
-			$POST = array_merge($POST, array(
301
-				'password' => APIHelpers::getkey($_POST, $pwdField, ''),
302
-				'email' => APIHelpers::getkey($_POST, $emailField, ''),
303
-				'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0))
304
-			));
305
-			if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){
306
-				$userObj->edit($POST['email']);
307
-
308
-				$this->modx->invokeEvent("OnBeforeWebLogin", array(
309
-		            "username"		=> $POST['email'],
310
-		            "userpassword"	=> $POST['password'],
311
-		            "rememberme"	=> $POST['remember'],
312
-		            'userObj'		=> $userObj
313
-		        ));
314
-				if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){
315
-					$pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array(
316
-	                    "userid"        => $userObj->getID(),
317
-	                    "username"      => $userObj->get('username'),
318
-	                    "userpassword"  => $POST['password'],
319
-	                    "savedpassword" => $userObj->get('password'),
320
-	                    "rememberme"    => $POST['remember'],
321
-	                ));
322
-					if(
323
-						($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0))
324
-							&&
325
-						$userObj->authUser($userObj->getID(), $POST['remember'])
326
-					){
327
-						$userObj->set('logincount', (int)$userObj->get('logincount') + 1);
328
-						$userObj->set('lastlogin', time());
329
-						$userObj->set('failedlogincount', 0);
330
-						$userObj->save(false, false);
331
-
332
-						$this->modx->invokeEvent("OnWebLogin", array(
333
-			                "userid"		=> $userObj->getID(),
334
-			                "username"		=> $userObj->get('username'),
335
-			                "userpassword"	=> $POST['password'],
336
-			                "rememberme"	=> $POST['remember'],
337
-			            ));
338
-						$this->moveTo(array('url' => urldecode($POST['backUrl'])));
339
-					}else{
340
-						$userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1);
341
-						$userObj->save(false, false);
342
-
343
-						$error = 'error.incorrect_password';
344
-					}
345
-				}else{
346
-					$error = 'error.no_user';
347
-				}
348
-			}else{
349
-				$error = 'error.incorrect_mail';
350
-				$POST['email'] = '';
351
-			}
352
-		}
353
-		if(!empty($error)){
354
-			$errorCode = $error;
355
-			$error = APIHelpers::getkey($params, $error, '');
356
-			$error = static::getLangMsg($error, $error);
357
-		}
358
-		return $POST;
359
-	}
360
-	/**
361
-	 * Информация о пользователе
362
-	 * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!]
363
-	 */
364
-	public function UserInfo($params){
365
-		$out = '';
366
-		$userID = APIHelpers::getkey($params, 'id', 0);
367
-		if(empty($userID)){
368
-			$userID = $this->UserID('web');
369
-		}
370
-		$field = APIHelpers::getkey($params, 'field', 'username');
371
-		if($userID > 0){
372
-			$this->userObj->edit($userID);
373
-			switch(true){
374
-				case ($field == $this->userObj->fieldPKName()):
375
-					$out = $this->userObj->getID();
376
-					break;
377
-				case ($this->userObj->issetField($field)):
378
-					$out = $this->userObj->get($field);
379
-					break;
380
-			}
381
-		}
382
-		return $out;
383
-	}
384
-	/**
385
-	 * ID пользователя
386
-	 */
387
-	public function UserID($type = 'web'){
388
-		return $this->modx->getLoginUserID($type);
389
-	}
390
-	/**
391
-	 * Если не авторизован - то отправить на страницу
392
-	 */
393
-	public function isGuestGoHome($params){
394
-		if(!$this->UserID('web')){
395
-			/**
396
-			 * @see : http://modx.im/blog/triks/105.html
397
-			 */
398
-			$this->modx->invokeEvent('OnPageUnauthorized');
399
-			$id = APIHelpers::getkey($params, 'id', $this->config['unauthorized_page']);
400
-		    $this->moveTo(compact('id'));
401
-		}
402
-		return;
403
-	}
404
-
405
-	/**
406
-	 * Если авторизован - то открыть личный кабинет
407
-	 */
408
-	public function isAuthGoHome($params){
409
-		$userID = $this->UserID('web');
410
-		if($userID>0){
411
-			$id = APIHelpers::getkey($params, 'homeID');
412
-		    if(empty($id)){
413
-				$id = $this->modx->getConfig('login_home', $this->config['site_start']);
414
-		    }
415
-		    $this->moveTo(compact('id'));
416
-		}
417
-		return;
418
-	}
419
-
420
-	/**
421
-	 * Редирект
422
-	 */
423
-	public function moveTo($params){
424
-		$id = (int)APIHelpers::getkey($params, 'id', 0);
425
-		$uri = APIHelpers::getkey($params, 'url', '');
426
-		if((empty($uri) && !empty($id)) || !is_string($uri)){
427
-			$uri = $this->makeUrl($id);
428
-		}
429
-		$code = (int)APIHelpers::getkey($params, 'code', 0);
430
-		$addUrl = APIHelpers::getkey($params, 'addUrl', '');
431
-		if(is_scalar($addUrl) && $addUrl!=''){
432
-		    $uri .= "?".$addUrl;
433
-		}
434
-		if(APIHelpers::getkey($params, 'validate', false)){
435
-			if(isset($this->modx->snippetCache['getPageID'])){
436
-				$out = $this->modx->runSnippet('getPageID', compact('uri'));
437
-				if(empty($out)){
438
-					$uri = '';
439
-				}
440
-			}else{
441
-				$uri = APIhelpers::sanitarTag($uri);
442
-			}
443
-		}else{
444
-			//$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect');
445
-			header("Location: ".$uri, true, ($code>0 ? $code : 307));
446
-		}
447
-		return $uri;
448
-	}
449
-
450
-	/**
451
-	 * Создание ссылки на страницу
452
-	 *
453
-	 * @param  int $id ID документа
454
-	 * @return string
455
-	 */
456
-	protected function makeUrl($id = null){
457
-		$id = (int)$id;
458
-		if($id <= 0){
459
-			$id = $this->modx->documentObject['id'];
460
-		}
461
-		if($this->url->containsKey($id)){
462
-			$url = $this->url->get($id);
463
-		}else{
464
-			$url = $this->modx->makeUrl($id);
465
-			$this->url->set($id, $url);
466
-		}
467
-		return $url;
468
-	}
295
+        $POST = array(
296
+            'backUrl' => urlencode($backUrl)
297
+        );
298
+        $userObj = &$this->userObj;
299
+        if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){
300
+            $POST = array_merge($POST, array(
301
+                'password' => APIHelpers::getkey($_POST, $pwdField, ''),
302
+                'email' => APIHelpers::getkey($_POST, $emailField, ''),
303
+                'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0))
304
+            ));
305
+            if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){
306
+                $userObj->edit($POST['email']);
307
+
308
+                $this->modx->invokeEvent("OnBeforeWebLogin", array(
309
+                    "username"		=> $POST['email'],
310
+                    "userpassword"	=> $POST['password'],
311
+                    "rememberme"	=> $POST['remember'],
312
+                    'userObj'		=> $userObj
313
+                ));
314
+                if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){
315
+                    $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array(
316
+                        "userid"        => $userObj->getID(),
317
+                        "username"      => $userObj->get('username'),
318
+                        "userpassword"  => $POST['password'],
319
+                        "savedpassword" => $userObj->get('password'),
320
+                        "rememberme"    => $POST['remember'],
321
+                    ));
322
+                    if(
323
+                        ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0))
324
+                            &&
325
+                        $userObj->authUser($userObj->getID(), $POST['remember'])
326
+                    ){
327
+                        $userObj->set('logincount', (int)$userObj->get('logincount') + 1);
328
+                        $userObj->set('lastlogin', time());
329
+                        $userObj->set('failedlogincount', 0);
330
+                        $userObj->save(false, false);
331
+
332
+                        $this->modx->invokeEvent("OnWebLogin", array(
333
+                            "userid"		=> $userObj->getID(),
334
+                            "username"		=> $userObj->get('username'),
335
+                            "userpassword"	=> $POST['password'],
336
+                            "rememberme"	=> $POST['remember'],
337
+                        ));
338
+                        $this->moveTo(array('url' => urldecode($POST['backUrl'])));
339
+                    }else{
340
+                        $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1);
341
+                        $userObj->save(false, false);
342
+
343
+                        $error = 'error.incorrect_password';
344
+                    }
345
+                }else{
346
+                    $error = 'error.no_user';
347
+                }
348
+            }else{
349
+                $error = 'error.incorrect_mail';
350
+                $POST['email'] = '';
351
+            }
352
+        }
353
+        if(!empty($error)){
354
+            $errorCode = $error;
355
+            $error = APIHelpers::getkey($params, $error, '');
356
+            $error = static::getLangMsg($error, $error);
357
+        }
358
+        return $POST;
359
+    }
360
+    /**
361
+     * Информация о пользователе
362
+     * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!]
363
+     */
364
+    public function UserInfo($params){
365
+        $out = '';
366
+        $userID = APIHelpers::getkey($params, 'id', 0);
367
+        if(empty($userID)){
368
+            $userID = $this->UserID('web');
369
+        }
370
+        $field = APIHelpers::getkey($params, 'field', 'username');
371
+        if($userID > 0){
372
+            $this->userObj->edit($userID);
373
+            switch(true){
374
+                case ($field == $this->userObj->fieldPKName()):
375
+                    $out = $this->userObj->getID();
376
+                    break;
377
+                case ($this->userObj->issetField($field)):
378
+                    $out = $this->userObj->get($field);
379
+                    break;
380
+            }
381
+        }
382
+        return $out;
383
+    }
384
+    /**
385
+     * ID пользователя
386
+     */
387
+    public function UserID($type = 'web'){
388
+        return $this->modx->getLoginUserID($type);
389
+    }
390
+    /**
391
+     * Если не авторизован - то отправить на страницу
392
+     */
393
+    public function isGuestGoHome($params){
394
+        if(!$this->UserID('web')){
395
+            /**
396
+             * @see : http://modx.im/blog/triks/105.html
397
+             */
398
+            $this->modx->invokeEvent('OnPageUnauthorized');
399
+            $id = APIHelpers::getkey($params, 'id', $this->config['unauthorized_page']);
400
+            $this->moveTo(compact('id'));
401
+        }
402
+        return;
403
+    }
404
+
405
+    /**
406
+     * Если авторизован - то открыть личный кабинет
407
+     */
408
+    public function isAuthGoHome($params){
409
+        $userID = $this->UserID('web');
410
+        if($userID>0){
411
+            $id = APIHelpers::getkey($params, 'homeID');
412
+            if(empty($id)){
413
+                $id = $this->modx->getConfig('login_home', $this->config['site_start']);
414
+            }
415
+            $this->moveTo(compact('id'));
416
+        }
417
+        return;
418
+    }
419
+
420
+    /**
421
+     * Редирект
422
+     */
423
+    public function moveTo($params){
424
+        $id = (int)APIHelpers::getkey($params, 'id', 0);
425
+        $uri = APIHelpers::getkey($params, 'url', '');
426
+        if((empty($uri) && !empty($id)) || !is_string($uri)){
427
+            $uri = $this->makeUrl($id);
428
+        }
429
+        $code = (int)APIHelpers::getkey($params, 'code', 0);
430
+        $addUrl = APIHelpers::getkey($params, 'addUrl', '');
431
+        if(is_scalar($addUrl) && $addUrl!=''){
432
+            $uri .= "?".$addUrl;
433
+        }
434
+        if(APIHelpers::getkey($params, 'validate', false)){
435
+            if(isset($this->modx->snippetCache['getPageID'])){
436
+                $out = $this->modx->runSnippet('getPageID', compact('uri'));
437
+                if(empty($out)){
438
+                    $uri = '';
439
+                }
440
+            }else{
441
+                $uri = APIhelpers::sanitarTag($uri);
442
+            }
443
+        }else{
444
+            //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect');
445
+            header("Location: ".$uri, true, ($code>0 ? $code : 307));
446
+        }
447
+        return $uri;
448
+    }
449
+
450
+    /**
451
+     * Создание ссылки на страницу
452
+     *
453
+     * @param  int $id ID документа
454
+     * @return string
455
+     */
456
+    protected function makeUrl($id = null){
457
+        $id = (int)$id;
458
+        if($id <= 0){
459
+            $id = $this->modx->documentObject['id'];
460
+        }
461
+        if($this->url->containsKey($id)){
462
+            $url = $this->url->get($id);
463
+        }else{
464
+            $url = $this->modx->makeUrl($id);
465
+            $this->url->set($id, $url);
466
+        }
467
+        return $url;
468
+    }
469 469
 
470 470
     /**
471 471
      * @param $name
472 472
      * @return string
473 473
      */
474 474
     protected function getTemplate($name){
475
-		$out = '';
476
-		$file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html';
477
-		if( FS::getInstance()->checkFile($file)){
478
-			$out = '@CODE: '.file_get_contents($file);
479
-		}
480
-		return $out;
481
-	}
475
+        $out = '';
476
+        $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html';
477
+        if( FS::getInstance()->checkFile($file)){
478
+            $out = '@CODE: '.file_get_contents($file);
479
+        }
480
+        return $out;
481
+    }
482 482
 
483 483
     /**
484 484
      * @param $lang
485 485
      * @return bool
486 486
      */
487 487
     protected static function loadLang($lang){
488
-		$file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php';
489
-		if( ! FS::getInstance()->checkFile($file)){
490
-			$file = false;
491
-		}
492
-		if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){
493
-			static::$langDic[$lang] = include_once($file);
494
-			if(is_array(static::$langDic[$lang])){
495
-				static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang);
496
-			}else{
497
-				static::$langDic[$lang] = array();
498
-			}
499
-		}
500
-		return !(empty($lang) || empty(static::$langDic[$lang]));
501
-	}
488
+        $file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php';
489
+        if( ! FS::getInstance()->checkFile($file)){
490
+            $file = false;
491
+        }
492
+        if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){
493
+            static::$langDic[$lang] = include_once($file);
494
+            if(is_array(static::$langDic[$lang])){
495
+                static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang);
496
+            }else{
497
+                static::$langDic[$lang] = array();
498
+            }
499
+        }
500
+        return !(empty($lang) || empty(static::$langDic[$lang]));
501
+    }
502 502
 
503 503
     /**
504 504
      * @param $key
@@ -506,18 +506,18 @@  discard block
 block discarded – undo
506 506
      * @return mixed
507 507
      */
508 508
     protected static function getLangMsg($key, $default){
509
-		$out = $default;
510
-		$lng = static::$lang;
511
-		$dic = static::$langDic;
512
-		if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){
513
-			$out = $dic[$lng][$lng.'.'.$key];
514
-		}
515
-		if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){
516
-			$msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key));
517
-			if(!empty($msg)){
518
-				$out = $msg;
519
-			}
520
-		}
521
-		return $out;
522
-	}
509
+        $out = $default;
510
+        $lng = static::$lang;
511
+        $dic = static::$langDic;
512
+        if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){
513
+            $out = $dic[$lng][$lng.'.'.$key];
514
+        }
515
+        if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){
516
+            $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key));
517
+            if(!empty($msg)){
518
+                $out = $msg;
519
+            }
520
+        }
521
+        return $out;
522
+    }
523 523
 }
524 524
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
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;
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Class Actions
14 14
  * @package DLUsers
15 15
  */
16
-class Actions{
16
+class Actions {
17 17
     protected $modx = null;
18 18
     public $userObj = null;
19 19
 	/**
@@ -88,20 +88,20 @@  discard block
 block discarded – undo
88 88
     /**
89 89
      * Сброс авторизации и обновление страницы
90 90
      */
91
-    public function logout($params){
91
+    public function logout($params) {
92 92
     	$LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout');
93
-    	if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){
93
+    	if (is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])) {
94 94
     		$userID = $this->UserID('web');
95
-    		if($userID){
95
+    		if ($userID) {
96 96
     			$this->userObj->edit($userID);
97
-    			if($this->userObj->getID()){
97
+    			if ($this->userObj->getID()) {
98 98
 	    			$this->modx->invokeEvent("OnBeforeWebLogout", array(
99 99
 		    			"userid"   => $this->userObj->getID(),
100 100
 		    			"username" => $this->userObj->get('username')
101 101
 		    		));
102 102
 	    		}
103 103
 		    	$this->userObj->logOut();
104
-		    	if($this->userObj->getID()){
104
+		    	if ($this->userObj->getID()) {
105 105
 		    		$this->modx->invokeEvent("OnWebLogout", array(
106 106
 		    			"userid"        => $this->userObj->getID(),
107 107
 		    			"username"      => $this->userObj->get('username')
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		    	}
110 110
 
111 111
 			    $go = APIHelpers::getkey($params, 'url', '');
112
-			    if(empty($go)){
112
+			    if (empty($go)) {
113 113
 			    	$go = str_replace(
114 114
 			    		array("?".$LogoutName, "&".$LogoutName),
115 115
 			    		array("", ""),
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
 			    }
119 119
 
120 120
 			    $start = $this->makeUrl($this->config['site_start']);
121
-			    if($start == $go){
121
+			    if ($start == $go) {
122 122
 			        $go = $this->config['site_url'];
123
-			    }else{
123
+			    } else {
124 124
 			        $go = $this->config['site_url'].ltrim($go, '/');
125 125
 			    }
126 126
 			    $this->moveTo(array('url' => $go));
127
-    		}else{
127
+    		} else {
128 128
     			//Если юзер не авторизован, то показываем ему 404 ошибку
129 129
     			$this->modx->sendErrorPage();
130 130
     		}
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      * Генерация ссылки под кнопку выход
137 137
      * @return string
138 138
      */
139
-    public function logoutUrl($params){
139
+    public function logoutUrl($params) {
140 140
     	$LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout');
141 141
     	$request = parse_url($_SERVER['REQUEST_URI']);
142 142
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      * 		если указан параметр authId, то данные из формы перекидываются в метод AuthPage
153 153
      *   	В противном случае вся работа происходит внутри самого блока
154 154
      */
155
-    public function AuthBlock($params){
155
+    public function AuthBlock($params) {
156 156
     	$POST = array('backUrl' => $_SERVER['REQUEST_URI']);
157 157
 
158 158
     	$error = $errorCode = '';
@@ -161,20 +161,20 @@  discard block
 block discarded – undo
161 161
 		$emailField = APIHelpers::getkey($params, 'emailField', 'email');
162 162
 		$rememberField = APIHelpers::getkey($params, 'rememberField', 'remember');
163 163
 
164
-    	if($this->UserID('web')){
164
+    	if ($this->UserID('web')) {
165 165
 			$tpl = APIHelpers::getkey($params, 'tplProfile', '');
166
-			if(empty($tpl)){
166
+			if (empty($tpl)) {
167 167
 				$tpl = $this->getTemplate('tplProfile');
168 168
 			}
169 169
 			$dataTPL = $this->userObj->toArray();
170 170
 			$dataTPL['url.logout'] = $this->logoutUrl($params);
171 171
     		$homeID = APIHelpers::getkey($params, 'homeID');
172
-			if(!empty($homeID)){
172
+			if (!empty($homeID)) {
173 173
 				$dataTPL['url.profile'] = $this->makeUrl($homeID);
174 174
 			}
175
-		}else{
175
+		} else {
176 176
 			$tpl = APIHelpers::getkey($params, 'tplForm', '');
177
-			if(empty($tpl)){
177
+			if (empty($tpl)) {
178 178
 				$tpl = $this->getTemplate('authForm');
179 179
 			}
180 180
 			$POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params);
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
 				'errorCode' => $errorCode
189 189
 			);
190 190
 			$authId = APIHelpers::getkey($params, 'authId');
191
-			if(!empty($authId)){
191
+			if (!empty($authId)) {
192 192
 				$dataTPL['authPage'] = $this->makeUrl($authId);
193
-				$dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage');
193
+				$dataTPL['method'] = strtolower(__CLASS__.'::'.'authpage');
194 194
 			}
195 195
 		}
196 196
 		return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL);
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * Авторизация на сайте со страницы авторизации
201 201
 	 * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!]
202 202
 	 */
203
-	public function AuthPage($params){
203
+	public function AuthPage($params) {
204 204
 		$homeID = APIHelpers::getkey($params, 'homeID');
205 205
 		$this->isAuthGoHome(array('id' => $homeID));
206 206
 
@@ -212,58 +212,58 @@  discard block
 block discarded – undo
212 212
 		$rememberField = APIHelpers::getkey($params, 'rememberField', 'remember');
213 213
 
214 214
 		$tpl = APIHelpers::getkey($params, 'tpl', '');
215
-		if(empty($tpl)){
215
+		if (empty($tpl)) {
216 216
 			$tpl = $this->getTemplate('authForm');
217 217
 		}
218 218
 
219 219
 		$request = parse_url($_SERVER['REQUEST_URI']);
220
-		if(!empty($_SERVER['HTTP_REFERER'])){
220
+		if (!empty($_SERVER['HTTP_REFERER'])) {
221 221
 			/**
222 222
 			 * Thank you for super protection against hacking in protect.inc.php:-)
223 223
 			 */
224 224
 			$refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES);
225
-		}else{
225
+		} else {
226 226
 			$selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
227
-			if(empty( $request['host']) ||  $request['host']==$selfHost){
227
+			if (empty($request['host']) || $request['host'] == $selfHost) {
228 228
 				$query = !empty($request['query']) ? '?'.$request['query'] : '';
229 229
 			    $refer = !empty($request['path']) ? $request['path'].$query : '';
230
-			}else{
230
+			} else {
231 231
 				$refer = '';
232 232
 			}
233 233
 		}
234 234
 
235
-		if($_SERVER['REQUEST_METHOD'] == 'POST'){
235
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
236 236
 			$backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']);
237
-			if(!is_scalar($backUrl)){
237
+			if (!is_scalar($backUrl)) {
238 238
 				$backUrl = $refer;
239
-			}else{
239
+			} else {
240 240
 				$backUrl = urldecode($backUrl);
241 241
 			}
242
-		}else{
242
+		} else {
243 243
 			$backUrl = $refer;
244 244
 		}
245 245
 		$backUrl = parse_url($backUrl);
246
-		if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){
246
+		if (!empty($backUrl['path']) && $request['path'] != $backUrl['path']) {
247 247
 		    $POST['backUrl'] = $backUrl['path'];
248
-		}else{
248
+		} else {
249 249
 			$selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
250
-			if(empty($backUrl['host']) || $backUrl['host']==$selfHost){
250
+			if (empty($backUrl['host']) || $backUrl['host'] == $selfHost) {
251 251
 				$query = !empty($backUrl['query']) ? '?'.$backUrl['query'] : '';
252 252
 			    $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : '';
253
-			}else{
253
+			} else {
254 254
 				$POST['backUrl'] = '';
255 255
 			}
256 256
 		}
257
-		if(!empty($POST['backUrl'])){
257
+		if (!empty($POST['backUrl'])) {
258 258
 			$idURL = $this->moveTo(array(
259 259
 				'url' => '/'.ltrim($POST['backUrl'], '/'),
260 260
 			    'validate' => true
261 261
 			));
262
-		}else{
262
+		} else {
263 263
 			$idURL = 0;
264 264
 		}
265
-		if(empty($idURL)){
266
-			if(empty($homeID)){
265
+		if (empty($idURL)) {
266
+			if (empty($homeID)) {
267 267
 				$homeID = $this->config['site_start'];
268 268
 			}
269 269
 			$POST['backUrl'] = $this->makeUrl($homeID);
@@ -291,18 +291,18 @@  discard block
 block discarded – undo
291 291
      * @param array $params
292 292
      * @return array
293 293
      */
294
-    protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){
294
+    protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()) {
295 295
 		$POST = array(
296 296
 			'backUrl' => urlencode($backUrl)
297 297
 		);
298 298
 		$userObj = &$this->userObj;
299
-		if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){
299
+		if ($_SERVER['REQUEST_METHOD'] == 'POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)) {
300 300
 			$POST = array_merge($POST, array(
301 301
 				'password' => APIHelpers::getkey($_POST, $pwdField, ''),
302 302
 				'email' => APIHelpers::getkey($_POST, $emailField, ''),
303 303
 				'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0))
304 304
 			));
305
-			if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){
305
+			if (!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)) {
306 306
 				$userObj->edit($POST['email']);
307 307
 
308 308
 				$this->modx->invokeEvent("OnBeforeWebLogin", array(
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 		            "rememberme"	=> $POST['remember'],
312 312
 		            'userObj'		=> $userObj
313 313
 		        ));
314
-				if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){
314
+				if ($userObj->getID() && !$userObj->checkBlock($userObj->getID())) {
315 315
 					$pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array(
316 316
 	                    "userid"        => $userObj->getID(),
317 317
 	                    "username"      => $userObj->get('username'),
@@ -319,11 +319,11 @@  discard block
 block discarded – undo
319 319
 	                    "savedpassword" => $userObj->get('password'),
320 320
 	                    "rememberme"    => $POST['remember'],
321 321
 	                ));
322
-					if(
322
+					if (
323 323
 						($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0))
324 324
 							&&
325 325
 						$userObj->authUser($userObj->getID(), $POST['remember'])
326
-					){
326
+					) {
327 327
 						$userObj->set('logincount', (int)$userObj->get('logincount') + 1);
328 328
 						$userObj->set('lastlogin', time());
329 329
 						$userObj->set('failedlogincount', 0);
@@ -336,21 +336,21 @@  discard block
 block discarded – undo
336 336
 			                "rememberme"	=> $POST['remember'],
337 337
 			            ));
338 338
 						$this->moveTo(array('url' => urldecode($POST['backUrl'])));
339
-					}else{
339
+					} else {
340 340
 						$userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1);
341 341
 						$userObj->save(false, false);
342 342
 
343 343
 						$error = 'error.incorrect_password';
344 344
 					}
345
-				}else{
345
+				} else {
346 346
 					$error = 'error.no_user';
347 347
 				}
348
-			}else{
348
+			} else {
349 349
 				$error = 'error.incorrect_mail';
350 350
 				$POST['email'] = '';
351 351
 			}
352 352
 		}
353
-		if(!empty($error)){
353
+		if (!empty($error)) {
354 354
 			$errorCode = $error;
355 355
 			$error = APIHelpers::getkey($params, $error, '');
356 356
 			$error = static::getLangMsg($error, $error);
@@ -361,16 +361,16 @@  discard block
 block discarded – undo
361 361
 	 * Информация о пользователе
362 362
 	 * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!]
363 363
 	 */
364
-	public function UserInfo($params){
364
+	public function UserInfo($params) {
365 365
 		$out = '';
366 366
 		$userID = APIHelpers::getkey($params, 'id', 0);
367
-		if(empty($userID)){
367
+		if (empty($userID)) {
368 368
 			$userID = $this->UserID('web');
369 369
 		}
370 370
 		$field = APIHelpers::getkey($params, 'field', 'username');
371
-		if($userID > 0){
371
+		if ($userID > 0) {
372 372
 			$this->userObj->edit($userID);
373
-			switch(true){
373
+			switch (true) {
374 374
 				case ($field == $this->userObj->fieldPKName()):
375 375
 					$out = $this->userObj->getID();
376 376
 					break;
@@ -384,14 +384,14 @@  discard block
 block discarded – undo
384 384
 	/**
385 385
 	 * ID пользователя
386 386
 	 */
387
-	public function UserID($type = 'web'){
387
+	public function UserID($type = 'web') {
388 388
 		return $this->modx->getLoginUserID($type);
389 389
 	}
390 390
 	/**
391 391
 	 * Если не авторизован - то отправить на страницу
392 392
 	 */
393
-	public function isGuestGoHome($params){
394
-		if(!$this->UserID('web')){
393
+	public function isGuestGoHome($params) {
394
+		if (!$this->UserID('web')) {
395 395
 			/**
396 396
 			 * @see : http://modx.im/blog/triks/105.html
397 397
 			 */
@@ -405,11 +405,11 @@  discard block
 block discarded – undo
405 405
 	/**
406 406
 	 * Если авторизован - то открыть личный кабинет
407 407
 	 */
408
-	public function isAuthGoHome($params){
408
+	public function isAuthGoHome($params) {
409 409
 		$userID = $this->UserID('web');
410
-		if($userID>0){
410
+		if ($userID > 0) {
411 411
 			$id = APIHelpers::getkey($params, 'homeID');
412
-		    if(empty($id)){
412
+		    if (empty($id)) {
413 413
 				$id = $this->modx->getConfig('login_home', $this->config['site_start']);
414 414
 		    }
415 415
 		    $this->moveTo(compact('id'));
@@ -420,29 +420,29 @@  discard block
 block discarded – undo
420 420
 	/**
421 421
 	 * Редирект
422 422
 	 */
423
-	public function moveTo($params){
423
+	public function moveTo($params) {
424 424
 		$id = (int)APIHelpers::getkey($params, 'id', 0);
425 425
 		$uri = APIHelpers::getkey($params, 'url', '');
426
-		if((empty($uri) && !empty($id)) || !is_string($uri)){
426
+		if ((empty($uri) && !empty($id)) || !is_string($uri)) {
427 427
 			$uri = $this->makeUrl($id);
428 428
 		}
429 429
 		$code = (int)APIHelpers::getkey($params, 'code', 0);
430 430
 		$addUrl = APIHelpers::getkey($params, 'addUrl', '');
431
-		if(is_scalar($addUrl) && $addUrl!=''){
431
+		if (is_scalar($addUrl) && $addUrl != '') {
432 432
 		    $uri .= "?".$addUrl;
433 433
 		}
434
-		if(APIHelpers::getkey($params, 'validate', false)){
435
-			if(isset($this->modx->snippetCache['getPageID'])){
434
+		if (APIHelpers::getkey($params, 'validate', false)) {
435
+			if (isset($this->modx->snippetCache['getPageID'])) {
436 436
 				$out = $this->modx->runSnippet('getPageID', compact('uri'));
437
-				if(empty($out)){
437
+				if (empty($out)) {
438 438
 					$uri = '';
439 439
 				}
440
-			}else{
440
+			} else {
441 441
 				$uri = APIhelpers::sanitarTag($uri);
442 442
 			}
443
-		}else{
443
+		} else {
444 444
 			//$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect');
445
-			header("Location: ".$uri, true, ($code>0 ? $code : 307));
445
+			header("Location: ".$uri, true, ($code > 0 ? $code : 307));
446 446
 		}
447 447
 		return $uri;
448 448
 	}
@@ -453,14 +453,14 @@  discard block
 block discarded – undo
453 453
 	 * @param  int $id ID документа
454 454
 	 * @return string
455 455
 	 */
456
-	protected function makeUrl($id = null){
456
+	protected function makeUrl($id = null) {
457 457
 		$id = (int)$id;
458
-		if($id <= 0){
458
+		if ($id <= 0) {
459 459
 			$id = $this->modx->documentObject['id'];
460 460
 		}
461
-		if($this->url->containsKey($id)){
461
+		if ($this->url->containsKey($id)) {
462 462
 			$url = $this->url->get($id);
463
-		}else{
463
+		} else {
464 464
 			$url = $this->modx->makeUrl($id);
465 465
 			$this->url->set($id, $url);
466 466
 		}
@@ -471,10 +471,10 @@  discard block
 block discarded – undo
471 471
      * @param $name
472 472
      * @return string
473 473
      */
474
-    protected function getTemplate($name){
474
+    protected function getTemplate($name) {
475 475
 		$out = '';
476 476
 		$file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html';
477
-		if( FS::getInstance()->checkFile($file)){
477
+		if (FS::getInstance()->checkFile($file)) {
478 478
 			$out = '@CODE: '.file_get_contents($file);
479 479
 		}
480 480
 		return $out;
@@ -484,16 +484,16 @@  discard block
 block discarded – undo
484 484
      * @param $lang
485 485
      * @return bool
486 486
      */
487
-    protected static function loadLang($lang){
487
+    protected static function loadLang($lang) {
488 488
 		$file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php';
489
-		if( ! FS::getInstance()->checkFile($file)){
489
+		if (!FS::getInstance()->checkFile($file)) {
490 490
 			$file = false;
491 491
 		}
492
-		if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){
492
+		if (!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)) {
493 493
 			static::$langDic[$lang] = include_once($file);
494
-			if(is_array(static::$langDic[$lang])){
494
+			if (is_array(static::$langDic[$lang])) {
495 495
 				static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang);
496
-			}else{
496
+			} else {
497 497
 				static::$langDic[$lang] = array();
498 498
 			}
499 499
 		}
@@ -505,16 +505,16 @@  discard block
 block discarded – undo
505 505
      * @param $default
506 506
      * @return mixed
507 507
      */
508
-    protected static function getLangMsg($key, $default){
508
+    protected static function getLangMsg($key, $default) {
509 509
 		$out = $default;
510 510
 		$lng = static::$lang;
511 511
 		$dic = static::$langDic;
512
-		if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){
512
+		if (isset($dic[$lng], $dic[$lng][$lng.'.'.$key])) {
513 513
 			$out = $dic[$lng][$lng.'.'.$key];
514 514
 		}
515
-		if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){
515
+		if (class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])) {
516 516
 			$msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key));
517
-			if(!empty($msg)){
517
+			if (!empty($msg)) {
518 518
 				$out = $msg;
519 519
 			}
520 520
 		}
Please login to merge, or discard this patch.