Completed
Pull Request — develop (#518)
by Agel_Nash
05:24
created
manager/media/browser/mcpuk/lib/class_fastImage.php 1 patch
Braces   +26 added lines, -36 removed lines patch added patch discarded remove patch
@@ -21,13 +21,17 @@  discard block
 block discarded – undo
21 21
 
22 22
 	public function __construct($uri = null)
23 23
 	{
24
-		if ($uri) $this->load($uri);
24
+		if ($uri) {
25
+		    $this->load($uri);
26
+		}
25 27
 	}
26 28
 
27 29
 
28 30
 	public function load($uri)
29 31
 	{
30
-		if ($this->handle) $this->close();
32
+		if ($this->handle) {
33
+		    $this->close();
34
+		}
31 35
 
32 36
 		$this->uri = $uri;
33 37
 		$this->handle = fopen($uri, 'r');
@@ -36,15 +40,16 @@  discard block
 block discarded – undo
36 40
 
37 41
 	public function close()
38 42
 	{
39
-		if (is_resource($this->handle)) fclose($this->handle);
43
+		if (is_resource($this->handle)) {
44
+		    fclose($this->handle);
45
+		}
40 46
 	}
41 47
 
42 48
 
43 49
 	public function getSize()
44 50
 	{
45 51
 		$this->strpos = 0;
46
-		if ($this->getType())
47
-		{
52
+		if ($this->getType()) {
48 53
 			return array_values($this->parseSize());
49 54
 		}
50 55
 
@@ -56,10 +61,8 @@  discard block
 block discarded – undo
56 61
 	{
57 62
 		$this->strpos = 0;
58 63
 
59
-		if (!$this->type)
60
-		{
61
-			switch ($this->getChars(2))
62
-			{
64
+		if (!$this->type) {
65
+			switch ($this->getChars(2)) {
63 66
 				case "BM":
64 67
 					return $this->type = 'bmp';
65 68
 				case "GI":
@@ -81,8 +84,7 @@  discard block
 block discarded – undo
81 84
 	{
82 85
 		$this->strpos = 0;
83 86
 
84
-		switch ($this->type)
85
-		{
87
+		switch ($this->type) {
86 88
 			case 'png':
87 89
 				return $this->parseSizeForPNG();
88 90
 			case 'gif':
@@ -128,10 +130,8 @@  discard block
 block discarded – undo
128 130
 		$state = null;
129 131
 		$i = 0;
130 132
 
131
-		while (true)
132
-		{
133
-			switch ($state)
134
-			{
133
+		while (true) {
134
+			switch ($state) {
135 135
 				default:
136 136
 					$this->getChars(2);
137 137
 					$state = 'started';
@@ -139,27 +139,22 @@  discard block
 block discarded – undo
139 139
 
140 140
 				case 'started':
141 141
 					$b = $this->getByte();
142
-					if ($b === false) return false;
142
+					if ($b === false) {
143
+					    return false;
144
+					}
143 145
 
144 146
 					$state = $b == 0xFF ? 'sof' : 'started';
145 147
 					break;
146 148
 
147 149
 				case 'sof':
148 150
 					$b = $this->getByte();
149
-					if (in_array($b, range(0xe0, 0xef)))
150
-					{
151
+					if (in_array($b, range(0xe0, 0xef))) {
151 152
 						$state = 'skipframe';
152
-					}
153
-					elseif (in_array($b, array_merge(range(0xC0,0xC3), range(0xC5,0xC7), range(0xC9,0xCB), range(0xCD,0xCF))))
154
-					{
153
+					} elseif (in_array($b, array_merge(range(0xC0,0xC3), range(0xC5,0xC7), range(0xC9,0xCB), range(0xCD,0xCF)))) {
155 154
 						$state = 'readsize';
156
-					}
157
-					elseif ($b == 0xFF)
158
-					{
155
+					} elseif ($b == 0xFF) {
159 156
 						$state = 'sof';
160
-					}
161
-					else
162
-					{
157
+					} else {
163 158
 						$state = 'skipframe';
164 159
 					}
165 160
 					break;
@@ -188,21 +183,16 @@  discard block
 block discarded – undo
188 183
 		$response = null;
189 184
 
190 185
 		// do we need more data?
191
-		if ($this->strpos + $n -1 >= strlen($this->str))
192
-		{
186
+		if ($this->strpos + $n -1 >= strlen($this->str)) {
193 187
 			$end = ($this->strpos + $n);
194 188
 
195
-			while (strlen($this->str) < $end && $response !== false)
196
-			{
189
+			while (strlen($this->str) < $end && $response !== false) {
197 190
 				// read more from the file handle
198 191
 				$need = $end - ftell($this->handle);
199 192
 
200
-				if ($response = fread($this->handle, $need))
201
-				{
193
+				if ($response = fread($this->handle, $need)) {
202 194
 					$this->str .= $response;
203
-				}
204
-				else
205
-				{
195
+				} else {
206 196
 					return false;
207 197
 				}
208 198
 			}
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/lib/helper_httpCache.php 1 patch
Braces   +31 added lines, -14 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@  discard block
 block discarded – undo
12 12
   *      @link http://kcfinder.sunhater.com
13 13
   */
14 14
 
15
-class httpCache {
15
+class httpCache
16
+{
16 17
     const DEFAULT_TYPE = "text/html";
17 18
     const DEFAULT_EXPIRE = 604800; // in seconds
18 19
 
@@ -25,15 +26,20 @@  discard block
 block discarded – undo
25 26
     * @param integer $expire
26 27
     * @param array $headers */
27 28
 
28
-    static function file($file, $type=null, $expire=null, array $headers=null) {
29
+    static function file($file, $type=null, $expire=null, array $headers=null)
30
+    {
29 31
         $mtime = @filemtime($file);
30
-        if ($mtime !== false) self::checkMTime($mtime);
32
+        if ($mtime !== false) {
33
+            self::checkMTime($mtime);
34
+        }
31 35
 
32 36
         if ($type === null) {
33 37
             $magic = ((substr($type, 0, 1) == "/") || preg_match('/^[a-z]\:/i', $type))
34 38
                 ? $type : null;
35 39
             $type = file::getMimeType($file, $magic);
36
-            if (!$type) $type = null;
40
+            if (!$type) {
41
+                $type = null;
42
+            }
37 43
         }
38 44
 
39 45
         self::content(@file_get_contents($file), $mtime, $type, $expire, $headers, false);
@@ -47,10 +53,17 @@  discard block
 block discarded – undo
47 53
     * @param array $headers
48 54
     * @param bool $checkMTime */
49 55
 
50
-    static function content($content, $mtime, $type=null, $expire=null, array $headers=null, $checkMTime=true) {
51
-        if ($checkMTime) self::checkMTime($mtime);
52
-        if ($type === null) $type = self::DEFAULT_TYPE;
53
-        if ($expire === null) $expire = self::DEFAULT_EXPIRE;
56
+    static function content($content, $mtime, $type=null, $expire=null, array $headers=null, $checkMTime=true)
57
+    {
58
+        if ($checkMTime) {
59
+            self::checkMTime($mtime);
60
+        }
61
+        if ($type === null) {
62
+            $type = self::DEFAULT_TYPE;
63
+        }
64
+        if ($expire === null) {
65
+            $expire = self::DEFAULT_EXPIRE;
66
+        }
54 67
         $size = strlen($content);
55 68
         $expires = gmdate("D, d M Y H:i:s", time() + $expire) . " GMT";
56 69
         header("Content-Type: $type");
@@ -58,7 +71,9 @@  discard block
 block discarded – undo
58 71
         header("Cache-Control: max-age=$expire");
59 72
         header("Pragma: !invalid");
60 73
         header("Content-Length: $size");
61
-        if ($headers !== null) foreach ($headers as $header) header($header);
74
+        if ($headers !== null) {
75
+            foreach ($headers as $header) header($header);
76
+        }
62 77
         echo $content;
63 78
     }
64 79
 
@@ -68,7 +83,8 @@  discard block
 block discarded – undo
68 83
     * the PHP to be configured as Apache module.
69 84
     * @param integer $mtime */
70 85
 
71
-    static function checkMTime($mtime, $sendHeaders=null) {
86
+    static function checkMTime($mtime, $sendHeaders=null)
87
+    {
72 88
         header("Last-Modified: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT");
73 89
 
74 90
         $headers = function_exists("getallheaders")
@@ -82,11 +98,12 @@  discard block
 block discarded – undo
82 98
             $client_mtime = @strtotime($client_mtime[0]);
83 99
             if ($client_mtime >= $mtime) {
84 100
                 header('HTTP/1.1 304 Not Modified');
85
-                if (is_array($sendHeaders) && count($sendHeaders))
86
-                    foreach ($sendHeaders as $header)
101
+                if (is_array($sendHeaders) && count($sendHeaders)) {
102
+                                    foreach ($sendHeaders as $header)
87 103
                         header($header);
88
-                elseif ($sendHeaders !== null)
89
-                    header($sendHeaders);
104
+                } elseif ($sendHeaders !== null) {
105
+                                    header($sendHeaders);
106
+                }
90 107
 
91 108
 
92 109
                 die;
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/lib/class_image_gd.php 1 patch
Braces   +148 added lines, -85 removed lines patch added patch discarded remove patch
@@ -12,14 +12,20 @@  discard block
 block discarded – undo
12 12
   *      @link http://kcfinder.sunhater.com
13 13
   */
14 14
 
15
-class image_gd extends image {
15
+class image_gd extends image
16
+{
16 17
 
17 18
 
18 19
     // ABSTRACT PUBLIC METHODS
19 20
 
20
-    public function resize($width, $height) {
21
-        if (!$width) $width = 1;
22
-        if (!$height) $height = 1;
21
+    public function resize($width, $height)
22
+    {
23
+        if (!$width) {
24
+            $width = 1;
25
+        }
26
+        if (!$height) {
27
+            $height = 1;
28
+        }
23 29
         return (
24 30
             (false !== ($img = new image_gd(array($width, $height)))) &&
25 31
             $img->imageCopyResampled($this) &&
@@ -29,9 +35,11 @@  discard block
 block discarded – undo
29 35
         );
30 36
     }
31 37
 
32
-    public function resizeFit($width, $height, $background=false) {
33
-        if ((!$width && !$height) || (($width == $this->width) && ($height == $this->height)))
34
-            return true;
38
+    public function resizeFit($width, $height, $background=false)
39
+    {
40
+        if ((!$width && !$height) || (($width == $this->width) && ($height == $this->height))) {
41
+                    return true;
42
+        }
35 43
         if (!$width || (($height / $width) < ($this->height / $this->width))) {
36 44
             $h = $height;
37 45
             $w = round(($this->width * $h) / $this->height);
@@ -42,13 +50,16 @@  discard block
 block discarded – undo
42 50
             $w = $width;
43 51
             $h = $height;
44 52
         }
45
-        if (!$w) $w = 1;
46
-        if (!$h) $h = 1;
47
-
48
-        if ($background === false)
49
-            return $this->resize($w, $h);
53
+        if (!$w) {
54
+            $w = 1;
55
+        }
56
+        if (!$h) {
57
+            $h = 1;
58
+        }
50 59
 
51
-        else {
60
+        if ($background === false) {
61
+                    return $this->resize($w, $h);
62
+        } else {
52 63
             $img = new image_gd(array($width, $height));
53 64
             $x = round(($width - $w) / 2);
54 65
             $y = round(($height - $h) / 2);
@@ -56,8 +67,9 @@  discard block
 block discarded – undo
56 67
             if ((false === $this->resize($w, $h)) ||
57 68
                 (false === $img->imageFilledRectangle(0, 0, $width, $height, $background)) ||
58 69
                 (false === $img->imageCopyResampled($this->image, $x, $y, 0, 0, $w, $h))
59
-            )
60
-                return false;
70
+            ) {
71
+                            return false;
72
+            }
61 73
 
62 74
             $this->image = $img->image;
63 75
             $this->width = $width;
@@ -67,41 +79,52 @@  discard block
 block discarded – undo
67 79
         }
68 80
     }
69 81
 
70
-    public function resizeCrop($width, $height, $offset=false) {
82
+    public function resizeCrop($width, $height, $offset=false)
83
+    {
71 84
 
72 85
         if (($this->width / $this->height) > ($width / $height)) {
73 86
             $h = $height;
74 87
             $w = ($this->width * $h) / $this->height;
75 88
             $y = 0;
76 89
             if ($offset !== false) {
77
-                if ($offset > 0)
78
-                    $offset = -$offset;
79
-                if (($w + $offset) <= $width)
80
-                    $offset = $width - $w;
90
+                if ($offset > 0) {
91
+                                    $offset = -$offset;
92
+                }
93
+                if (($w + $offset) <= $width) {
94
+                                    $offset = $width - $w;
95
+                }
81 96
                 $x = $offset;
82
-            } else
83
-                $x = ($width - $w) / 2;
97
+            } else {
98
+                            $x = ($width - $w) / 2;
99
+            }
84 100
 
85 101
         } else {
86 102
             $w = $width;
87 103
             $h = ($this->height * $w) / $this->width;
88 104
             $x = 0;
89 105
             if ($offset !== false) {
90
-                if ($offset > 0)
91
-                    $offset = -$offset;
92
-                if (($h + $offset) <= $height)
93
-                    $offset = $height - $h;
106
+                if ($offset > 0) {
107
+                                    $offset = -$offset;
108
+                }
109
+                if (($h + $offset) <= $height) {
110
+                                    $offset = $height - $h;
111
+                }
94 112
                 $y = $offset;
95
-            } else
96
-                $y = ($height - $h) / 2;
113
+            } else {
114
+                            $y = ($height - $h) / 2;
115
+            }
97 116
         }
98 117
 
99 118
         $x = round($x);
100 119
         $y = round($y);
101 120
         $w = round($w);
102 121
         $h = round($h);
103
-        if (!$w) $w = 1;
104
-        if (!$h) $h = 1;
122
+        if (!$w) {
123
+            $w = 1;
124
+        }
125
+        if (!$h) {
126
+            $h = 1;
127
+        }
105 128
 
106 129
         $return = (
107 130
             (false !== ($img = new image_gd(array($width, $height))))) &&
@@ -117,50 +140,59 @@  discard block
 block discarded – undo
117 140
         return $return;
118 141
     }
119 142
 
120
-    public function rotate($angle, $background="#000000") {
143
+    public function rotate($angle, $background="#000000")
144
+    {
121 145
         $angle = -$angle;
122 146
         $img = @imagerotate($this->image, $angle, $this->gdColor($background));
123
-        if ($img === false)
124
-            return false;
147
+        if ($img === false) {
148
+                    return false;
149
+        }
125 150
         $this->width = imagesx($img);
126 151
         $this->height = imagesy($img);
127 152
         $this->image = $img;
128 153
         return true;
129 154
     }
130 155
 
131
-    public function flipHorizontal() {
156
+    public function flipHorizontal()
157
+    {
132 158
         $img = imagecreatetruecolor($this->width, $this->height);
133 159
             imagealphablending($img, false);
134 160
             imagesavealpha($img, true);
135
-        if (imagecopyresampled($img, $this->image, 0, 0, ($this->width - 1), 0, $this->width, $this->height, -$this->width, $this->height))
136
-            $this->image = $img;
137
-        else
138
-            return false;
161
+        if (imagecopyresampled($img, $this->image, 0, 0, ($this->width - 1), 0, $this->width, $this->height, -$this->width, $this->height)) {
162
+                    $this->image = $img;
163
+        } else {
164
+                    return false;
165
+        }
139 166
         return true;
140 167
     }
141 168
 
142
-    public function flipVertical() {
169
+    public function flipVertical()
170
+    {
143 171
         $img = imagecreatetruecolor($this->width, $this->height);
144 172
             imagealphablending($img, false);
145 173
             imagesavealpha($img, true);
146
-        if (imagecopyresampled($img, $this->image, 0, 0, 0, ($this->height - 1), $this->width, $this->height, $this->width, -$this->height))
147
-            $this->image = $img;
148
-        else
149
-            return false;
174
+        if (imagecopyresampled($img, $this->image, 0, 0, 0, ($this->height - 1), $this->width, $this->height, $this->width, -$this->height)) {
175
+                    $this->image = $img;
176
+        } else {
177
+                    return false;
178
+        }
150 179
         return true;
151 180
     }
152 181
 
153
-    public function watermark($file, $left=false, $top=false) {
182
+    public function watermark($file, $left=false, $top=false)
183
+    {
154 184
         $info = getimagesize($file);
155 185
         list($w, $h, $t) = $info;
156
-        if (!in_array($t, array(IMAGETYPE_PNG, IMAGETYPE_GIF)))
157
-            return false;
186
+        if (!in_array($t, array(IMAGETYPE_PNG, IMAGETYPE_GIF))) {
187
+                    return false;
188
+        }
158 189
         $imagecreate = ($t == IMAGETYPE_PNG) ? "imagecreatefrompng" : "imagecreatefromgif";
159 190
 
160 191
         if (!@imagealphablending($this->image, true) ||
161 192
             (false === ($wm = @$imagecreate($file)))
162
-        )
163
-            return false;
193
+        ) {
194
+                    return false;
195
+        }
164 196
 
165 197
         $w = imagesx($wm);
166 198
         $h = imagesy($wm);
@@ -176,28 +208,33 @@  discard block
 block discarded – undo
176 208
         if ((($x + $w) > $this->width) ||
177 209
             (($y + $h) > $this->height) ||
178 210
             ($x < 0) || ($y < 0)
179
-        )
180
-            return false;
211
+        ) {
212
+                    return false;
213
+        }
181 214
 
182
-        if (($wm === false) || !@imagecopy($this->image, $wm, $x, $y, 0, 0, $w, $h))
183
-            return false;
215
+        if (($wm === false) || !@imagecopy($this->image, $wm, $x, $y, 0, 0, $w, $h)) {
216
+                    return false;
217
+        }
184 218
 
185 219
         @imagealphablending($this->image, false);
186 220
         @imagesavealpha($this->image, true);
187 221
         return true;
188 222
     }
189 223
 
190
-    public function output($type='jpeg', array $options=array()) {
224
+    public function output($type='jpeg', array $options=array())
225
+    {
191 226
         $method = "output_$type";
192
-        if (!method_exists($this, $method))
193
-            return false;
227
+        if (!method_exists($this, $method)) {
228
+                    return false;
229
+        }
194 230
         return $this->$method($options);
195 231
     }
196 232
 
197 233
 
198 234
     // ABSTRACT PROTECTED METHODS
199 235
 
200
-    protected function getBlankImage($width, $height) {
236
+    protected function getBlankImage($width, $height)
237
+    {
201 238
         $img = @imagecreatetruecolor($width, $height);
202 239
 //        imagealphablending($img, false);
203 240
 //        imagesavealpha($img, true);
@@ -207,7 +244,8 @@  discard block
 block discarded – undo
207 244
         return $img;
208 245
     }
209 246
 
210
-    protected function getImage($image, &$width, &$height) {
247
+    protected function getImage($image, &$width, &$height)
248
+    {
211 249
 
212 250
         if (is_resource($image) && (get_resource_type($image) == "gd")) {
213 251
             $width = @imagesx($image);
@@ -227,22 +265,26 @@  discard block
 block discarded – undo
227 265
 
228 266
             return $image;
229 267
 
230
-        } else
231
-            return false;
268
+        } else {
269
+                    return false;
270
+        }
232 271
     }
233 272
 
234 273
 
235 274
     // PSEUDO-ABSTRACT STATIC METHODS
236 275
 
237
-    static function available() {
276
+    static function available()
277
+    {
238 278
         return function_exists("imagecreatefromjpeg");
239 279
     }
240 280
 
241
-    static function checkImage($file) {
281
+    static function checkImage($file)
282
+    {
242 283
         if (!is_string($file) ||
243 284
             ((false === (list($width, $height, $t) = @getimagesize($file))))
244
-        )
245
-            return false;
285
+        ) {
286
+                    return false;
287
+        }
246 288
 
247 289
         $img =
248 290
             ($t == IMAGETYPE_GIF)  ? @imagecreatefromgif($file)  : (
@@ -258,34 +300,41 @@  discard block
 block discarded – undo
258 300
 
259 301
     // OWN METHODS
260 302
 
261
-    protected function output_png(array $options=array()) {
303
+    protected function output_png(array $options=array())
304
+    {
262 305
         $file = isset($options['file']) ? $options['file'] : null;
263 306
         $quality = isset($options['quality']) ? $options['quality'] : null;
264 307
         $filters = isset($options['filters']) ? $options['filters'] : null;
265
-        if (($file === null) && !headers_sent())
266
-            header("Content-Type: image/png");
308
+        if (($file === null) && !headers_sent()) {
309
+                    header("Content-Type: image/png");
310
+        }
267 311
         @imagesavealpha($this->image, true);
268 312
         return imagepng($this->image, $file, $quality, $filters);
269 313
     }
270 314
 
271
-    protected function output_jpeg(array $options=array()) {
315
+    protected function output_jpeg(array $options=array())
316
+    {
272 317
         $file = isset($options['file']) ? $options['file'] : null;
273 318
         $quality = isset($options['quality'])
274 319
             ? $options['quality']
275 320
             : self::DEFAULT_JPEG_QUALITY;
276
-        if (($file === null) && !headers_sent())
277
-            header("Content-Type: image/jpeg");
321
+        if (($file === null) && !headers_sent()) {
322
+                    header("Content-Type: image/jpeg");
323
+        }
278 324
         return imagejpeg($this->image, $file, $quality);
279 325
     }
280 326
 
281
-    protected function output_gif(array $options=array()) {
327
+    protected function output_gif(array $options=array())
328
+    {
282 329
         $file = isset($options['file']) ? $options['file'] : null;
283
-        if (isset($options['file']) && !headers_sent())
284
-            header("Content-Type: image/gif");
330
+        if (isset($options['file']) && !headers_sent()) {
331
+                    header("Content-Type: image/gif");
332
+        }
285 333
         return imagegif($this->image, $file);
286 334
     }
287 335
 
288
-    protected function gdColor() {
336
+    protected function gdColor()
337
+    {
289 338
         $args = func_get_args();
290 339
 
291 340
         $exprRGB = '/^rgb\(\s*(\d{1,3})\s*\,\s*(\d{1,3})\s*\,\s*(\d{1,3})\s*\)$/i';
@@ -293,8 +342,9 @@  discard block
 block discarded – undo
293 342
         $exprHex2 = '/^\#?([0-9a-f])([0-9a-f])([0-9a-f])$/i';
294 343
         $exprByte = '/^([01]?\d?\d|2[0-4]\d|25[0-5])$/';
295 344
 
296
-        if (!isset($args[0]))
297
-            return false;
345
+        if (!isset($args[0])) {
346
+                    return false;
347
+        }
298 348
 
299 349
         if (count($args[0]) == 3) {
300 350
             list($r, $g, $b) = $args[0];
@@ -321,15 +371,19 @@  discard block
 block discarded – undo
321 371
         ) {
322 372
             list($r, $g, $b) = $args;
323 373
 
324
-        } else
325
-            return false;
374
+        } else {
375
+                    return false;
376
+        }
326 377
 
327 378
         return imagecolorallocate($this->image, $r, $g, $b);
328 379
     }
329 380
 
330
-    protected function imageFilledRectangle($x1, $y1, $x2, $y2, $color) {
381
+    protected function imageFilledRectangle($x1, $y1, $x2, $y2, $color)
382
+    {
331 383
         $color = $this->gdColor($color);
332
-        if ($color === false) return false;
384
+        if ($color === false) {
385
+            return false;
386
+        }
333 387
         return imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color);
334 388
     }
335 389
 
@@ -338,15 +392,24 @@  discard block
 block discarded – undo
338 392
     ) {
339 393
         $imageDetails = $this->buildImage($src);
340 394
 
341
-        if ($imageDetails === false)
342
-            return false;
395
+        if ($imageDetails === false) {
396
+                    return false;
397
+        }
343 398
 
344 399
         list($src, $srcWidth, $srcHeight) = $imageDetails;
345 400
 
346
-        if (is_null($dstW)) $dstW = $this->width - $dstW;
347
-        if (is_null($dstH)) $dstH = $this->height - $dstY;
348
-        if (is_null($srcW)) $srcW = $srcWidth - $srcX;
349
-        if (is_null($srcH)) $srcH = $srcHeight - $srcY;
401
+        if (is_null($dstW)) {
402
+            $dstW = $this->width - $dstW;
403
+        }
404
+        if (is_null($dstH)) {
405
+            $dstH = $this->height - $dstY;
406
+        }
407
+        if (is_null($srcW)) {
408
+            $srcW = $srcWidth - $srcX;
409
+        }
410
+        if (is_null($srcH)) {
411
+            $srcH = $srcHeight - $srcY;
412
+        }
350 413
         return imageCopyResampled($this->image, $src, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
351 414
     }
352 415
 }
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/lib/helper_text.php 1 patch
Braces   +15 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,13 +12,15 @@  discard block
 block discarded – undo
12 12
   *      @link http://kcfinder.sunhater.com
13 13
   */
14 14
 
15
-class text {
15
+class text
16
+{
16 17
 
17 18
   /** Replace repeated white spaces to single space
18 19
     * @param string $string
19 20
     * @return string */
20 21
 
21
-    static function clearWhitespaces($string) {
22
+    static function clearWhitespaces($string)
23
+    {
22 24
         return trim(preg_replace('/\s+/s', " ", $string));
23 25
     }
24 26
 
@@ -26,7 +28,8 @@  discard block
 block discarded – undo
26 28
     * @param string $string
27 29
     * @return string */
28 30
 
29
-    static function htmlValue($string) {
31
+    static function htmlValue($string)
32
+    {
30 33
         return
31 34
             str_replace('"', "&quot;",
32 35
             str_replace("'", '&#39;',
@@ -39,7 +42,8 @@  discard block
 block discarded – undo
39 42
     * @param string $string
40 43
     * @return string */
41 44
 
42
-    static function jsValue($string) {
45
+    static function jsValue($string)
46
+    {
43 47
         return
44 48
             preg_replace('/\r?\n/', "\\n",
45 49
             str_replace('"', "\\\"",
@@ -52,10 +56,12 @@  discard block
 block discarded – undo
52 56
     * @param string $string
53 57
     * @param bool $cdata */
54 58
 
55
-    static function xmlData($string, $cdata=false) {
59
+    static function xmlData($string, $cdata=false)
60
+    {
56 61
         $string = str_replace("]]>", "]]]]><![CDATA[>", $string);
57
-        if (!$cdata)
58
-            $string = "<![CDATA[$string]]>";
62
+        if (!$cdata) {
63
+                    $string = "<![CDATA[$string]]>";
64
+        }
59 65
         return $string;
60 66
     }
61 67
 
@@ -63,7 +69,8 @@  discard block
 block discarded – undo
63 69
     * @param string $code
64 70
     * @return string */
65 71
 
66
-    static function compressCSS($code) {
72
+    static function compressCSS($code)
73
+    {
67 74
         $code = self::clearWhitespaces($code);
68 75
         $code = preg_replace('/ ?\{ ?/', "{", $code);
69 76
         $code = preg_replace('/ ?\} ?/', "}", $code);
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/lib/class_image_gmagick.php 1 patch
Braces   +81 added lines, -40 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@  discard block
 block discarded – undo
12 12
   *      @link http://kcfinder.sunhater.com
13 13
   */
14 14
 
15
-class image_gmagick extends image {
15
+class image_gmagick extends image
16
+{
16 17
 
17 18
     static $MIMES = array(
18 19
         //'tif' => "image/tiff"
@@ -21,9 +22,15 @@  discard block
 block discarded – undo
21 22
 
22 23
     // ABSTRACT PUBLIC METHODS
23 24
 
24
-    public function resize($width, $height) {//
25
-        if (!$width) $width = 1;
26
-        if (!$height) $height = 1;
25
+    public function resize($width, $height)
26
+    {
27
+//
28
+        if (!$width) {
29
+            $width = 1;
30
+        }
31
+        if (!$height) {
32
+            $height = 1;
33
+        }
27 34
         try {
28 35
             $this->image->scaleImage($width, $height);
29 36
         } catch (Exception $e) {
@@ -34,9 +41,15 @@  discard block
 block discarded – undo
34 41
         return true;
35 42
     }
36 43
 
37
-    public function resizeFit($width, $height, $background=false) {//
38
-        if (!$width) $width = 1;
39
-        if (!$height) $height = 1;
44
+    public function resizeFit($width, $height, $background=false)
45
+    {
46
+//
47
+        if (!$width) {
48
+            $width = 1;
49
+        }
50
+        if (!$height) {
51
+            $height = 1;
52
+        }
40 53
 
41 54
         try {
42 55
             $this->image->scaleImage($width, $height, true);
@@ -69,43 +82,58 @@  discard block
 block discarded – undo
69 82
         }
70 83
     }
71 84
 
72
-    public function resizeCrop($width, $height, $offset=false) {
73
-        if (!$width) $width = 1;
74
-        if (!$height) $height = 1;
85
+    public function resizeCrop($width, $height, $offset=false)
86
+    {
87
+        if (!$width) {
88
+            $width = 1;
89
+        }
90
+        if (!$height) {
91
+            $height = 1;
92
+        }
75 93
 
76 94
         if (($this->width / $this->height) > ($width / $height)) {
77 95
             $h = $height;
78 96
             $w = ($this->width * $h) / $this->height;
79 97
             $y = 0;
80 98
             if ($offset !== false) {
81
-                if ($offset > 0)
82
-                    $offset = -$offset;
83
-                if (($w + $offset) <= $width)
84
-                    $offset = $width - $w;
99
+                if ($offset > 0) {
100
+                                    $offset = -$offset;
101
+                }
102
+                if (($w + $offset) <= $width) {
103
+                                    $offset = $width - $w;
104
+                }
85 105
                 $x = $offset;
86
-            } else
87
-                $x = ($width - $w) / 2;
106
+            } else {
107
+                            $x = ($width - $w) / 2;
108
+            }
88 109
 
89 110
         } else {
90 111
             $w = $width;
91 112
             $h = ($this->height * $w) / $this->width;
92 113
             $x = 0;
93 114
             if ($offset !== false) {
94
-                if ($offset > 0)
95
-                    $offset = -$offset;
96
-                if (($h + $offset) <= $height)
97
-                    $offset = $height - $h;
115
+                if ($offset > 0) {
116
+                                    $offset = -$offset;
117
+                }
118
+                if (($h + $offset) <= $height) {
119
+                                    $offset = $height - $h;
120
+                }
98 121
                 $y = $offset;
99
-            } else
100
-                $y = ($height - $h) / 2;
122
+            } else {
123
+                            $y = ($height - $h) / 2;
124
+            }
101 125
         }
102 126
 
103 127
         $x = round($x);
104 128
         $y = round($y);
105 129
         $w = round($w);
106 130
         $h = round($h);
107
-        if (!$w) $w = 1;
108
-        if (!$h) $h = 1;
131
+        if (!$w) {
132
+            $w = 1;
133
+        }
134
+        if (!$h) {
135
+            $h = 1;
136
+        }
109 137
 
110 138
         try {
111 139
             $this->image->scaleImage($w, $h);
@@ -119,7 +147,8 @@  discard block
 block discarded – undo
119 147
         return true;
120 148
     }
121 149
 
122
-    public function rotate($angle, $background="#000000") {
150
+    public function rotate($angle, $background="#000000")
151
+    {
123 152
         try {
124 153
             $this->image->rotateImage($background, $angle);
125 154
             $w = $this->image->getImageWidth();
@@ -132,7 +161,8 @@  discard block
 block discarded – undo
132 161
         return true;
133 162
     }
134 163
 
135
-    public function flipHorizontal() {
164
+    public function flipHorizontal()
165
+    {
136 166
         try {
137 167
             $this->image->flopImage();
138 168
         } catch (Exception $e) {
@@ -141,7 +171,8 @@  discard block
 block discarded – undo
141 171
         return true;
142 172
     }
143 173
 
144
-    public function flipVertical() {
174
+    public function flipVertical()
175
+    {
145 176
         try {
146 177
             $this->image->flipImage();
147 178
         } catch (Exception $e) {
@@ -150,7 +181,8 @@  discard block
 block discarded – undo
150 181
         return true;
151 182
     }
152 183
 
153
-    public function watermark($file, $left=false, $top=false) {
184
+    public function watermark($file, $left=false, $top=false)
185
+    {
154 186
         try {
155 187
             $wm = new Gmagick($file);
156 188
             $w = $wm->getImageWidth();
@@ -171,8 +203,9 @@  discard block
 block discarded – undo
171 203
         if ((($x + $w) > $this->width) ||
172 204
             (($y + $h) > $this->height) ||
173 205
             ($x < 0) || ($y < 0)
174
-        )
175
-            return false;
206
+        ) {
207
+                    return false;
208
+        }
176 209
 
177 210
         try {
178 211
             $this->image->compositeImage($wm, 1, $x, $y);
@@ -185,7 +218,8 @@  discard block
 block discarded – undo
185 218
 
186 219
     // ABSTRACT PROTECTED METHODS
187 220
 
188
-    protected function getBlankImage($width, $height) {
221
+    protected function getBlankImage($width, $height)
222
+    {
189 223
         try {
190 224
             $img = new Gmagick();
191 225
             $img->newImage($width, $height, "none");
@@ -195,7 +229,8 @@  discard block
 block discarded – undo
195 229
         return $img;
196 230
     }
197 231
 
198
-    protected function getImage($image, &$width, &$height) {
232
+    protected function getImage($image, &$width, &$height)
233
+    {
199 234
 
200 235
         if (is_object($image) && ($image instanceof image_gmagick)) {
201 236
             $width = $image->width;
@@ -225,18 +260,21 @@  discard block
 block discarded – undo
225 260
             $height = $h;
226 261
             return $image;
227 262
 
228
-        } else
229
-            return false;
263
+        } else {
264
+                    return false;
265
+        }
230 266
     }
231 267
 
232 268
 
233 269
     // PSEUDO-ABSTRACT STATIC METHODS
234 270
 
235
-    static function available() {
271
+    static function available()
272
+    {
236 273
         return class_exists("Gmagick");
237 274
     }
238 275
 
239
-    static function checkImage($file) {
276
+    static function checkImage($file)
277
+    {
240 278
         try {
241 279
             $img = new Gmagic($file);
242 280
         } catch (Exception $e) {
@@ -248,7 +286,8 @@  discard block
 block discarded – undo
248 286
 
249 287
     // INHERIT METHODS
250 288
 
251
-    public function output($type="jpeg", array $options=array()) {
289
+    public function output($type="jpeg", array $options=array())
290
+    {
252 291
         $type = strtolower($type);
253 292
         try {
254 293
             $this->image->setImageFormat($type);
@@ -256,8 +295,9 @@  discard block
 block discarded – undo
256 295
             return false;
257 296
         }
258 297
         $method = "optimize_$type";
259
-        if (method_exists($this, $method) && !$this->$method($options))
260
-            return false;
298
+        if (method_exists($this, $method) && !$this->$method($options)) {
299
+                    return false;
300
+        }
261 301
 
262 302
         if (!isset($options['file'])) {
263 303
             if (!headers_sent()) {
@@ -287,7 +327,8 @@  discard block
 block discarded – undo
287 327
 
288 328
     // OWN METHODS
289 329
 
290
-    protected function optimize_jpeg(array $options=array()) {
330
+    protected function optimize_jpeg(array $options=array())
331
+    {
291 332
         $quality = isset($options['quality']) ? $options['quality'] : self::DEFAULT_JPEG_QUALITY;
292 333
         try {
293 334
             $this->image->setCompressionQuality($quality);
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/lib/class_zipFolder.php 1 patch
Braces   +17 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,20 +13,23 @@  discard block
 block discarded – undo
13 13
   *      @link http://kcfinder.sunhater.com
14 14
   */
15 15
 
16
-class zipFolder {
16
+class zipFolder
17
+{
17 18
     protected $zip;
18 19
     protected $root;
19 20
     protected $ignored;
20 21
 
21
-    function __construct($file, $folder, $ignored=null) {
22
+    function __construct($file, $folder, $ignored=null)
23
+    {
22 24
         $this->zip = new ZipArchive();
23 25
 
24 26
         $this->ignored = is_array($ignored)
25 27
             ? $ignored
26 28
             : ($ignored ? array($ignored) : array());
27 29
 
28
-        if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE)
29
-            throw new Exception("cannot open <$file>\n");
30
+        if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE) {
31
+                    throw new Exception("cannot open <$file>\n");
32
+        }
30 33
 
31 34
         $folder = rtrim($folder, '/');
32 35
 
@@ -39,19 +42,22 @@  discard block
 block discarded – undo
39 42
         $this->zip->close();
40 43
     }
41 44
 
42
-    function zip($folder, $parent=null) {
45
+    function zip($folder, $parent=null)
46
+    {
43 47
         $full_path = "{$this->root}$parent$folder";
44 48
         $zip_path = "$parent$folder";
45 49
         $this->zip->addEmptyDir($zip_path);
46 50
         $dir = new DirectoryIterator($full_path);
47
-        foreach ($dir as $file)
48
-            if (!$file->isDot()) {
51
+        foreach ($dir as $file) {
52
+                    if (!$file->isDot()) {
49 53
                 $filename = $file->getFilename();
54
+        }
50 55
                 if (!in_array($filename, $this->ignored)) {
51
-                    if ($file->isDir())
52
-                        $this->zip($filename, "$zip_path/");
53
-                    else
54
-                        $this->zip->addFile("$full_path/$filename", "$zip_path/$filename");
56
+                    if ($file->isDir()) {
57
+                                            $this->zip($filename, "$zip_path/");
58
+                    } else {
59
+                                            $this->zip->addFile("$full_path/$filename", "$zip_path/$filename");
60
+                    }
55 61
                 }
56 62
             }
57 63
     }
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/browse.php 1 patch
Braces   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,14 +14,19 @@
 block discarded – undo
14 14
 
15 15
 require "core/autoload.php"; // Init MODX
16 16
 
17
-function returnNoPermissionsMessage($role) {
17
+function returnNoPermissionsMessage($role)
18
+{
18 19
 	global $_lang;
19 20
 	echo sprintf($_lang['files_management_no_permission'], $role);
20 21
 	exit;
21 22
 }
22 23
 
23
-if( $_GET['type'] == 'images' && !$modx->hasPermission('file_manager') && !$modx->hasPermission('assets_images')) returnNoPermissionsMessage('assets_images');
24
-if( $_GET['type'] == 'files'  && !$modx->hasPermission('file_manager') && !$modx->hasPermission('assets_files'))  returnNoPermissionsMessage('assets_files');
24
+if( $_GET['type'] == 'images' && !$modx->hasPermission('file_manager') && !$modx->hasPermission('assets_images')) {
25
+    returnNoPermissionsMessage('assets_images');
26
+}
27
+if( $_GET['type'] == 'files'  && !$modx->hasPermission('file_manager') && !$modx->hasPermission('assets_files')) {
28
+    returnNoPermissionsMessage('assets_files');
29
+}
25 30
 
26 31
 $browser = new browser($modx);
27 32
 $browser->action();
Please login to merge, or discard this patch.
manager/media/script/air-datepicker/datepicker.inc.php 1 patch
Braces   +22 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,24 +1,37 @@
 block discarded – undo
1 1
 <?php
2
-class DATEPICKER {
3
-    function __construct() {
2
+class DATEPICKER
3
+{
4
+    function __construct()
5
+    {
4 6
     }
5
-    function getDP() {
7
+    function getDP()
8
+    {
6 9
         global $modx;
7 10
         
8 11
         $load_script = file_get_contents(dirname(__FILE__).'/datepicker.tpl');
9
-        if(!isset($modx->config['lang_code'])) $modx->config['lang_code'] = $this->getLangCode();
12
+        if(!isset($modx->config['lang_code'])) {
13
+            $modx->config['lang_code'] = $this->getLangCode();
14
+        }
10 15
 		$modx->config['datetime_format_lc'] = isset($modx->config['datetime_format']) ? strtolower($modx->config['datetime_format']) : 'dd-mm-yyyy';
11 16
         return $modx->mergeSettingsContent($load_script);
12 17
     }
13
-    function getLangCode() {
18
+    function getLangCode()
19
+    {
14 20
         global $modx, $modx_lang_attribute;
15 21
         
16
-        if(!$modx_lang_attribute) return 'en';
22
+        if(!$modx_lang_attribute) {
23
+            return 'en';
24
+        }
17 25
         
18 26
         $lc = $modx_lang_attribute;
19
-        if($lc=='uk') return 'ru';
27
+        if($lc=='uk') {
28
+            return 'ru';
29
+        }
20 30
         $dp_path = str_replace('\\','/',dirname(__FILE__));
21
-        if(is_file("{$dp_path}/i18n/datepicker.{$lc}.js")) return $modx_lang_attribute;
22
-        else                                               return 'en';
31
+        if(is_file("{$dp_path}/i18n/datepicker.{$lc}.js")) {
32
+            return $modx_lang_attribute;
33
+        } else {
34
+            return 'en';
35
+        }
23 36
     }
24 37
 }
Please login to merge, or discard this patch.
manager/media/style/default/welcome.php 1 patch
Braces   +5 added lines, -3 removed lines patch added patch discarded remove patch
@@ -3,9 +3,11 @@
 block discarded – undo
3 3
 
4 4
 $modx->addSnippet('hasPermission','return $modx->hasPermission($key);');
5 5
 
6
-if($modx->hasPermission('new_template') || $modx->hasPermission('edit_template') || $modx->hasPermission('new_snippet') || $modx->hasPermission('edit_snippet') || $modx->hasPermission('new_plugin') || $modx->hasPermission('edit_plugin') || $modx->hasPermission('manage_metatags'))
7
-    $hasAnyPermission = 1;
8
-else $hasAnyPermission = 0;
6
+if($modx->hasPermission('new_template') || $modx->hasPermission('edit_template') || $modx->hasPermission('new_snippet') || $modx->hasPermission('edit_snippet') || $modx->hasPermission('new_plugin') || $modx->hasPermission('edit_plugin') || $modx->hasPermission('manage_metatags')) {
7
+    $hasAnyPermission = 1;
8
+} else {
9
+    $hasAnyPermission = 0;
10
+}
9 11
 $modx->addSnippet('hasAnyPermission','global $hasAnyPermission; return $hasAnyPermission;');
10 12
 $modx->addSnippet('getLoginUserName','return $modx->getLoginUserName();');
11 13
 $code = 'global $_lang;return $_SESSION["nrtotalmessages"] ? sprintf($_lang["welcome_messages"], $_SESSION["nrtotalmessages"], \'<span style="color:red;">\' . $_SESSION["nrnewmessages"] . "</span>") : $_lang["messages_no_messages"];';
Please login to merge, or discard this patch.