@@ -10,11 +10,17 @@ |
||
10 | 10 | } |
11 | 11 | }; |
12 | 12 | <?php |
13 | - if(isset($_GET['type'])) $type = htmlspecialchars(trim($_GET['type']), ENT_QUOTES); |
|
14 | - elseif(isset($_GET['Type'])) $type = htmlspecialchars(trim($_GET['Type']), ENT_QUOTES); |
|
15 | - else $type = 'images'; |
|
13 | + if(isset($_GET['type'])) { |
|
14 | + $type = htmlspecialchars(trim($_GET['type']), ENT_QUOTES); |
|
15 | + } elseif(isset($_GET['Type'])) { |
|
16 | + $type = htmlspecialchars(trim($_GET['Type']), ENT_QUOTES); |
|
17 | + } else { |
|
18 | + $type = 'images'; |
|
19 | + } |
|
16 | 20 | |
17 | - if($type==='image') $type = 'images'; |
|
21 | + if($type==='image') { |
|
22 | + $type = 'images'; |
|
23 | + } |
|
18 | 24 | |
19 | 25 | $opener = (isset($_GET['editor'])) ? 'opener=' . htmlspecialchars(trim($_GET['editor']), ENT_QUOTES) : ''; |
20 | 26 | $request_uri = "{$opener}&type={$type}"; |
@@ -12,23 +12,27 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class dir { |
|
15 | +class dir |
|
16 | +{ |
|
16 | 17 | |
17 | 18 | /** Checks if the given directory is really writable. The standard PHP |
18 | 19 | * function is_writable() does not work properly on Windows servers |
19 | 20 | * @param string $dir |
20 | 21 | * @return bool */ |
21 | 22 | |
22 | - static function isWritable($dir) { |
|
23 | + static function isWritable($dir) |
|
24 | + { |
|
23 | 25 | $dir = path::normalize($dir); |
24 | - if (!is_dir($dir)) |
|
25 | - return false; |
|
26 | + if (!is_dir($dir)) { |
|
27 | + return false; |
|
28 | + } |
|
26 | 29 | $i = 0; |
27 | 30 | do { |
28 | 31 | $file = "$dir/is_writable_" . md5($i++); |
29 | 32 | } while (file_exists($file)); |
30 | - if (!@touch($file)) |
|
31 | - return false; |
|
33 | + if (!@touch($file)) { |
|
34 | + return false; |
|
35 | + } |
|
32 | 36 | unlink($file); |
33 | 37 | return true; |
34 | 38 | } |
@@ -44,12 +48,16 @@ discard block |
||
44 | 48 | * @param array $failed |
45 | 49 | * @return mixed */ |
46 | 50 | |
47 | - static function prune($dir, $firstFailExit=true, array $failed=null) { |
|
48 | - if ($failed === null) $failed = array(); |
|
51 | + static function prune($dir, $firstFailExit=true, array $failed=null) |
|
52 | + { |
|
53 | + if ($failed === null) { |
|
54 | + $failed = array(); |
|
55 | + } |
|
49 | 56 | $files = self::content($dir); |
50 | 57 | if ($files === false) { |
51 | - if ($firstFailExit) |
|
52 | - return $dir; |
|
58 | + if ($firstFailExit) { |
|
59 | + return $dir; |
|
60 | + } |
|
53 | 61 | $failed[] = $dir; |
54 | 62 | return $failed; |
55 | 63 | } |
@@ -58,23 +66,27 @@ discard block |
||
58 | 66 | if (is_dir($file)) { |
59 | 67 | $failed_in = self::prune($file, $firstFailExit, $failed); |
60 | 68 | if ($failed_in !== true) { |
61 | - if ($firstFailExit) |
|
62 | - return $failed_in; |
|
63 | - if (is_array($failed_in)) |
|
64 | - $failed = array_merge($failed, $failed_in); |
|
65 | - else |
|
66 | - $failed[] = $failed_in; |
|
69 | + if ($firstFailExit) { |
|
70 | + return $failed_in; |
|
71 | + } |
|
72 | + if (is_array($failed_in)) { |
|
73 | + $failed = array_merge($failed, $failed_in); |
|
74 | + } else { |
|
75 | + $failed[] = $failed_in; |
|
76 | + } |
|
67 | 77 | } |
68 | 78 | } elseif (!@unlink($file)) { |
69 | - if ($firstFailExit) |
|
70 | - return $file; |
|
79 | + if ($firstFailExit) { |
|
80 | + return $file; |
|
81 | + } |
|
71 | 82 | $failed[] = $file; |
72 | 83 | } |
73 | 84 | } |
74 | 85 | |
75 | 86 | if (!@rmdir($dir)) { |
76 | - if ($firstFailExit) |
|
77 | - return $dir; |
|
87 | + if ($firstFailExit) { |
|
88 | + return $dir; |
|
89 | + } |
|
78 | 90 | $failed[] = $dir; |
79 | 91 | } |
80 | 92 | |
@@ -87,7 +99,8 @@ discard block |
||
87 | 99 | * @param array $options |
88 | 100 | * @return mixed */ |
89 | 101 | |
90 | - static function content($dir, array $options=null) { |
|
102 | + static function content($dir, array $options=null) |
|
103 | + { |
|
91 | 104 | |
92 | 105 | $defaultOptions = array( |
93 | 106 | 'types' => "all", // Allowed: "all" or possible return values |
@@ -97,23 +110,28 @@ discard block |
||
97 | 110 | 'followLinks' => true |
98 | 111 | ); |
99 | 112 | |
100 | - if (!is_dir($dir) || !is_readable($dir)) |
|
101 | - return false; |
|
113 | + if (!is_dir($dir) || !is_readable($dir)) { |
|
114 | + return false; |
|
115 | + } |
|
102 | 116 | |
103 | - if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") |
|
104 | - $dir = str_replace("\\", "/", $dir); |
|
117 | + if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") { |
|
118 | + $dir = str_replace("\\", "/", $dir); |
|
119 | + } |
|
105 | 120 | $dir = rtrim($dir, "/"); |
106 | 121 | |
107 | 122 | $dh = @opendir($dir); |
108 | - if ($dh === false) |
|
109 | - return false; |
|
123 | + if ($dh === false) { |
|
124 | + return false; |
|
125 | + } |
|
110 | 126 | |
111 | - if ($options === null) |
|
112 | - $options = $defaultOptions; |
|
127 | + if ($options === null) { |
|
128 | + $options = $defaultOptions; |
|
129 | + } |
|
113 | 130 | |
114 | - foreach ($defaultOptions as $key => $val) |
|
115 | - if (!isset($options[$key])) |
|
131 | + foreach ($defaultOptions as $key => $val) { |
|
132 | + if (!isset($options[$key])) |
|
116 | 133 | $options[$key] = $val; |
134 | + } |
|
117 | 135 | |
118 | 136 | $files = array(); |
119 | 137 | while (($file = @readdir($dh)) !== false) { |
@@ -124,28 +142,32 @@ discard block |
||
124 | 142 | do { |
125 | 143 | $ldir = dirname($lfile); |
126 | 144 | $lfile = @readlink($lfile); |
127 | - if (substr($lfile, 0, 1) != "/") |
|
128 | - $lfile = "$ldir/$lfile"; |
|
145 | + if (substr($lfile, 0, 1) != "/") { |
|
146 | + $lfile = "$ldir/$lfile"; |
|
147 | + } |
|
129 | 148 | $type = filetype($lfile); |
130 | 149 | } while ($type == "link"); |
131 | 150 | } |
132 | 151 | |
133 | 152 | if ((($type === "dir") && (($file == ".") || ($file == ".."))) || |
134 | 153 | !preg_match($options['pattern'], $file) |
135 | - ) |
|
136 | - continue; |
|
154 | + ) { |
|
155 | + continue; |
|
156 | + } |
|
137 | 157 | |
138 | 158 | if (($options['types'] === "all") || ($type === $options['types']) || |
139 | 159 | ((is_array($options['types'])) && in_array($type, $options['types'])) |
140 | - ) |
|
141 | - $files[] = $options['addPath'] ? "$dir/$file" : $file; |
|
160 | + ) { |
|
161 | + $files[] = $options['addPath'] ? "$dir/$file" : $file; |
|
162 | + } |
|
142 | 163 | } |
143 | 164 | closedir($dh); |
144 | 165 | usort($files, array("dir", "fileSort")); |
145 | 166 | return $files; |
146 | 167 | } |
147 | 168 | |
148 | - static function fileSort($a, $b) { |
|
169 | + static function fileSort($a, $b) |
|
170 | + { |
|
149 | 171 | if (function_exists("mb_strtolower")) { |
150 | 172 | $a = mb_strtolower($a); |
151 | 173 | $b = mb_strtolower($b); |
@@ -153,7 +175,9 @@ discard block |
||
153 | 175 | $a = strtolower($a); |
154 | 176 | $b = strtolower($b); |
155 | 177 | } |
156 | - if ($a == $b) return 0; |
|
178 | + if ($a == $b) { |
|
179 | + return 0; |
|
180 | + } |
|
157 | 181 | return ($a < $b) ? -1 : 1; |
158 | 182 | } |
159 | 183 | } |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class input { |
|
15 | +class input |
|
16 | +{ |
|
16 | 17 | |
17 | 18 | /** Filtered $_GET array |
18 | 19 | * @var array */ |
@@ -26,7 +27,8 @@ discard block |
||
26 | 27 | * @var array */ |
27 | 28 | public $cookie; |
28 | 29 | |
29 | - public function __construct() { |
|
30 | + public function __construct() |
|
31 | + { |
|
30 | 32 | $this->get = &$_GET; |
31 | 33 | $this->post = &$_POST; |
32 | 34 | $this->cookie = &$_COOKIE; |
@@ -36,7 +38,8 @@ discard block |
||
36 | 38 | * @param string $property |
37 | 39 | * @return mixed */ |
38 | 40 | |
39 | - public function __get($property) { |
|
41 | + public function __get($property) |
|
42 | + { |
|
40 | 43 | return property_exists($this, $property) ? $this->$property : null; |
41 | 44 | } |
42 | 45 | } |
@@ -12,29 +12,36 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class path { |
|
15 | +class path |
|
16 | +{ |
|
16 | 17 | |
17 | 18 | /** Get the absolute URL path of the given one. Returns FALSE if the URL |
18 | 19 | * is not valid or the current directory cannot be resolved (getcwd()) |
19 | 20 | * @param string $path |
20 | 21 | * @return string */ |
21 | 22 | |
22 | - static function rel2abs_url($path) { |
|
23 | - if (substr($path, 0, 1) == "/") return $path; |
|
23 | + static function rel2abs_url($path) |
|
24 | + { |
|
25 | + if (substr($path, 0, 1) == "/") { |
|
26 | + return $path; |
|
27 | + } |
|
24 | 28 | $dir = @getcwd(); |
25 | 29 | |
26 | - if (!isset($_SERVER['DOCUMENT_ROOT']) || ($dir === false)) |
|
27 | - return false; |
|
30 | + if (!isset($_SERVER['DOCUMENT_ROOT']) || ($dir === false)) { |
|
31 | + return false; |
|
32 | + } |
|
28 | 33 | |
29 | 34 | $dir = self::normalize($dir); |
30 | 35 | $doc_root = self::normalize($_SERVER['DOCUMENT_ROOT']); |
31 | 36 | |
32 | - if (substr($dir, 0, strlen($doc_root)) != $doc_root) |
|
33 | - return false; |
|
37 | + if (substr($dir, 0, strlen($doc_root)) != $doc_root) { |
|
38 | + return false; |
|
39 | + } |
|
34 | 40 | |
35 | 41 | $return = self::normalize(substr($dir, strlen($doc_root)) . "/$path"); |
36 | - if (substr($return, 0, 1) !== "/") |
|
37 | - $return = "/$return"; |
|
42 | + if (substr($return, 0, 1) !== "/") { |
|
43 | + $return = "/$return"; |
|
44 | + } |
|
38 | 45 | |
39 | 46 | return $return; |
40 | 47 | } |
@@ -44,7 +51,8 @@ discard block |
||
44 | 51 | * @param string $url |
45 | 52 | * @return string */ |
46 | 53 | |
47 | - static function url2fullPath($url) { |
|
54 | + static function url2fullPath($url) |
|
55 | + { |
|
48 | 56 | $url = self::normalize($url); |
49 | 57 | |
50 | 58 | $uri = isset($_SERVER['SCRIPT_NAME']) |
@@ -55,7 +63,9 @@ discard block |
||
55 | 63 | $uri = self::normalize($uri); |
56 | 64 | |
57 | 65 | if (substr($url, 0, 1) !== "/") { |
58 | - if ($uri === false) return false; |
|
66 | + if ($uri === false) { |
|
67 | + return false; |
|
68 | + } |
|
59 | 69 | $url = dirname($uri) . "/$url"; |
60 | 70 | } |
61 | 71 | |
@@ -63,7 +73,9 @@ discard block |
||
63 | 73 | return self::normalize($_SERVER['DOCUMENT_ROOT'] . "/$url"); |
64 | 74 | |
65 | 75 | } else { |
66 | - if ($uri === false) return false; |
|
76 | + if ($uri === false) { |
|
77 | + return false; |
|
78 | + } |
|
67 | 79 | |
68 | 80 | if (isset($_SERVER['SCRIPT_FILENAME'])) { |
69 | 81 | $scr_filename = self::normalize($_SERVER['SCRIPT_FILENAME']); |
@@ -71,13 +83,15 @@ discard block |
||
71 | 83 | } |
72 | 84 | |
73 | 85 | $count = count(explode('/', $uri)) - 1; |
74 | - for ($i = 0, $chdir = ""; $i < $count; $i++) |
|
75 | - $chdir .= "../"; |
|
86 | + for ($i = 0, $chdir = ""; $i < $count; $i++) { |
|
87 | + $chdir .= "../"; |
|
88 | + } |
|
76 | 89 | $chdir = self::normalize($chdir); |
77 | 90 | |
78 | 91 | $dir = getcwd(); |
79 | - if (($dir === false) || !@chdir($chdir)) |
|
80 | - return false; |
|
92 | + if (($dir === false) || !@chdir($chdir)) { |
|
93 | + return false; |
|
94 | + } |
|
81 | 95 | $rdir = getcwd(); |
82 | 96 | chdir($dir); |
83 | 97 | return ($rdir !== false) ? self::normalize($rdir . "/$url") : false; |
@@ -92,22 +106,29 @@ discard block |
||
92 | 106 | * @param string $path |
93 | 107 | * @return string */ |
94 | 108 | |
95 | - static function normalize($path) { |
|
109 | + static function normalize($path) |
|
110 | + { |
|
96 | 111 | if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") { |
97 | 112 | $path = preg_replace('/([^\\\])\\\([^\\\])/', "$1/$2", $path); |
98 | - if (substr($path, -1) == "\\") $path = substr($path, 0, -1); |
|
99 | - if (substr($path, 0, 1) == "\\") $path = "/" . substr($path, 1); |
|
113 | + if (substr($path, -1) == "\\") { |
|
114 | + $path = substr($path, 0, -1); |
|
115 | + } |
|
116 | + if (substr($path, 0, 1) == "\\") { |
|
117 | + $path = "/" . substr($path, 1); |
|
118 | + } |
|
100 | 119 | } |
101 | 120 | |
102 | 121 | $path = preg_replace('/\/+/s', "/", $path); |
103 | 122 | |
104 | 123 | $path = "/$path"; |
105 | - if (substr($path, -1) != "/") |
|
106 | - $path .= "/"; |
|
124 | + if (substr($path, -1) != "/") { |
|
125 | + $path .= "/"; |
|
126 | + } |
|
107 | 127 | |
108 | 128 | $expr = '/\/([^\/]{1}|[^\.\/]{2}|[^\/]{3,})\/\.\.\//s'; |
109 | - while (preg_match($expr, $path)) |
|
110 | - $path = preg_replace($expr, "/", $path); |
|
129 | + while (preg_match($expr, $path)) { |
|
130 | + $path = preg_replace($expr, "/", $path); |
|
131 | + } |
|
111 | 132 | |
112 | 133 | $path = substr($path, 0, -1); |
113 | 134 | $path = substr($path, 1); |
@@ -118,11 +139,13 @@ discard block |
||
118 | 139 | * @param string $path |
119 | 140 | * @return string */ |
120 | 141 | |
121 | - static function urlPathEncode($path) { |
|
142 | + static function urlPathEncode($path) |
|
143 | + { |
|
122 | 144 | $path = self::normalize($path); |
123 | 145 | $encoded = ""; |
124 | - foreach (explode("/", $path) as $dir) |
|
125 | - $encoded .= rawurlencode($dir) . "/"; |
|
146 | + foreach (explode("/", $path) as $dir) { |
|
147 | + $encoded .= rawurlencode($dir) . "/"; |
|
148 | + } |
|
126 | 149 | $encoded = substr($encoded, 0, -1); |
127 | 150 | return $encoded; |
128 | 151 | } |
@@ -131,11 +154,13 @@ discard block |
||
131 | 154 | * @param string $path |
132 | 155 | * @return string */ |
133 | 156 | |
134 | - static function urlPathDecode($path) { |
|
157 | + static function urlPathDecode($path) |
|
158 | + { |
|
135 | 159 | $path = self::normalize($path); |
136 | 160 | $decoded = ""; |
137 | - foreach (explode("/", $path) as $dir) |
|
138 | - $decoded .= rawurldecode($dir) . "/"; |
|
161 | + foreach (explode("/", $path) as $dir) { |
|
162 | + $decoded .= rawurldecode($dir) . "/"; |
|
163 | + } |
|
139 | 164 | $decoded = substr($decoded, 0, -1); |
140 | 165 | return $decoded; |
141 | 166 | } |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class file { |
|
15 | +class file |
|
16 | +{ |
|
16 | 17 | |
17 | 18 | static $MIME = array( |
18 | 19 | 'ai' => 'application/postscript', |
@@ -105,10 +106,12 @@ discard block |
||
105 | 106 | * @param string $dir |
106 | 107 | * @return bool */ |
107 | 108 | |
108 | - static function isWritable($filename) { |
|
109 | + static function isWritable($filename) |
|
110 | + { |
|
109 | 111 | $filename = path::normalize($filename); |
110 | - if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) |
|
111 | - return false; |
|
112 | + if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) { |
|
113 | + return false; |
|
114 | + } |
|
112 | 115 | fclose($fp); |
113 | 116 | return true; |
114 | 117 | } |
@@ -118,7 +121,8 @@ discard block |
||
118 | 121 | * @param bool $toLower |
119 | 122 | * @return string */ |
120 | 123 | |
121 | - static function getExtension($filename, $toLower=true) { |
|
124 | + static function getExtension($filename, $toLower=true) |
|
125 | + { |
|
122 | 126 | return preg_match('/^.*\.([^\.]*)$/s', $filename, $patt) |
123 | 127 | ? ($toLower ? strtolower($patt[1]) : $patt[1]) : ""; |
124 | 128 | } |
@@ -134,7 +138,8 @@ discard block |
||
134 | 138 | * @param string $magic |
135 | 139 | * @return string */ |
136 | 140 | |
137 | - static function getMimeType($filename, $magic=null) { |
|
141 | + static function getMimeType($filename, $magic=null) |
|
142 | + { |
|
138 | 143 | if (class_exists("finfo")) { |
139 | 144 | $finfo = ($magic === null) |
140 | 145 | ? new finfo(FILEINFO_MIME) |
@@ -170,12 +175,15 @@ discard block |
||
170 | 175 | * @param string $tpl |
171 | 176 | * @return string */ |
172 | 177 | |
173 | - static function getInexistantFilename($filename, $dir=null, $tpl=null) { |
|
174 | - if ($tpl === null) $tpl = "{name}({sufix}){ext}"; |
|
178 | + static function getInexistantFilename($filename, $dir=null, $tpl=null) |
|
179 | + { |
|
180 | + if ($tpl === null) { |
|
181 | + $tpl = "{name}({sufix}){ext}"; |
|
182 | + } |
|
175 | 183 | $fullPath = ($dir === null); |
176 | - if ($fullPath) |
|
177 | - $dir = path::normalize(dirname($filename)); |
|
178 | - else { |
|
184 | + if ($fullPath) { |
|
185 | + $dir = path::normalize(dirname($filename)); |
|
186 | + } else { |
|
179 | 187 | $fdir = dirname($filename); |
180 | 188 | $dir = strlen($fdir) |
181 | 189 | ? path::normalize("$dir/$fdir") |
@@ -187,8 +195,9 @@ discard block |
||
187 | 195 | $tpl = str_replace('{name}', $name, $tpl); |
188 | 196 | $tpl = str_replace('{ext}', (strlen($ext) ? ".$ext" : ""), $tpl); |
189 | 197 | $i = 1; $file = "$dir/$filename"; |
190 | - while (file_exists($file)) |
|
191 | - $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
198 | + while (file_exists($file)) { |
|
199 | + $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
200 | + } |
|
192 | 201 | |
193 | 202 | return $fullPath |
194 | 203 | ? $file |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -abstract class image { |
|
15 | +abstract class image |
|
16 | +{ |
|
16 | 17 | const DEFAULT_JPEG_QUALITY = 75; |
17 | 18 | |
18 | 19 | /** Image resource or object |
@@ -41,7 +42,8 @@ discard block |
||
41 | 42 | * @param string $property |
42 | 43 | * @return mixed */ |
43 | 44 | |
44 | - final public function __get($property) { |
|
45 | + final public function __get($property) |
|
46 | + { |
|
45 | 47 | return property_exists($this, $property) ? $this->$property : null; |
46 | 48 | } |
47 | 49 | |
@@ -57,14 +59,16 @@ discard block |
||
57 | 59 | * @param mixed $image |
58 | 60 | * @param array $options */ |
59 | 61 | |
60 | - public function __construct($image, array $options=array()) { |
|
62 | + public function __construct($image, array $options=array()) |
|
63 | + { |
|
61 | 64 | $this->image = $this->width = $this->height = null; |
62 | 65 | $imageDetails = $this->buildImage($image); |
63 | 66 | |
64 | - if ($imageDetails !== false) |
|
65 | - list($this->image, $this->width, $this->height) = $imageDetails; |
|
66 | - else |
|
67 | - $this->initError = true; |
|
67 | + if ($imageDetails !== false) { |
|
68 | + list($this->image, $this->width, $this->height) = $imageDetails; |
|
69 | + } else { |
|
70 | + $this->initError = true; |
|
71 | + } |
|
68 | 72 | $this->options = $options; |
69 | 73 | } |
70 | 74 | |
@@ -75,7 +79,8 @@ discard block |
||
75 | 79 | * @param mixed $image |
76 | 80 | * @return object */ |
77 | 81 | |
78 | - final static function factory($driver, $image, array $options=array()) { |
|
82 | + final static function factory($driver, $image, array $options=array()) |
|
83 | + { |
|
79 | 84 | $class = "image_$driver"; |
80 | 85 | return new $class($image, $options); |
81 | 86 | } |
@@ -86,14 +91,18 @@ discard block |
||
86 | 91 | * @param array $drivers |
87 | 92 | * @return string */ |
88 | 93 | |
89 | - final static function getDriver(array $drivers=array('gd')) { |
|
94 | + final static function getDriver(array $drivers=array('gd')) |
|
95 | + { |
|
90 | 96 | foreach ($drivers as $driver) { |
91 | - if (!preg_match('/^[a-z0-9\_]+$/i', $driver)) |
|
92 | - continue; |
|
97 | + if (!preg_match('/^[a-z0-9\_]+$/i', $driver)) { |
|
98 | + continue; |
|
99 | + } |
|
93 | 100 | $class = "image_$driver"; |
94 | 101 | if (class_exists($class) && method_exists($class, "available")) { |
95 | 102 | eval("\$avail = $class::available();"); |
96 | - if ($avail) return $driver; |
|
103 | + if ($avail) { |
|
104 | + return $driver; |
|
105 | + } |
|
97 | 106 | } |
98 | 107 | } |
99 | 108 | return false; |
@@ -105,7 +114,8 @@ discard block |
||
105 | 114 | * @param mixed $image |
106 | 115 | * @return array */ |
107 | 116 | |
108 | - final protected function buildImage($image) { |
|
117 | + final protected function buildImage($image) |
|
118 | + { |
|
109 | 119 | $class = get_class($this); |
110 | 120 | |
111 | 121 | if ($image instanceof $class) { |
@@ -118,8 +128,9 @@ discard block |
||
118 | 128 | list($key, $height) = each($image); |
119 | 129 | $img = $this->getBlankImage($width, $height); |
120 | 130 | |
121 | - } else |
|
122 | - $img = $this->getImage($image, $width, $height); |
|
131 | + } else { |
|
132 | + $img = $this->getImage($image, $width, $height); |
|
133 | + } |
|
123 | 134 | |
124 | 135 | return ($img !== false) |
125 | 136 | ? array($img, $width, $height) |
@@ -131,9 +142,12 @@ discard block |
||
131 | 142 | * @param integer $resizedHeight |
132 | 143 | * @return integer */ |
133 | 144 | |
134 | - final public function getPropWidth($resizedHeight) { |
|
145 | + final public function getPropWidth($resizedHeight) |
|
146 | + { |
|
135 | 147 | $width = round(($this->width * $resizedHeight) / $this->height); |
136 | - if (!$width) $width = 1; |
|
148 | + if (!$width) { |
|
149 | + $width = 1; |
|
150 | + } |
|
137 | 151 | return $width; |
138 | 152 | } |
139 | 153 | |
@@ -142,9 +156,12 @@ discard block |
||
142 | 156 | * @param integer $resizedWidth |
143 | 157 | * @return integer */ |
144 | 158 | |
145 | - final public function getPropHeight($resizedWidth) { |
|
159 | + final public function getPropHeight($resizedWidth) |
|
160 | + { |
|
146 | 161 | $height = round(($this->height * $resizedWidth) / $this->width); |
147 | - if (!$height) $height = 1; |
|
162 | + if (!$height) { |
|
163 | + $height = 1; |
|
164 | + } |
|
148 | 165 | return $height; |
149 | 166 | } |
150 | 167 | |
@@ -153,13 +170,17 @@ discard block |
||
153 | 170 | * static method should be implemented into driver classes like abstract |
154 | 171 | * methods |
155 | 172 | * @return bool */ |
156 | - static function available() { return false; } |
|
173 | + static function available() |
|
174 | + { |
|
175 | +return false; } |
|
157 | 176 | |
158 | 177 | /** Checks if file is an image. This static method should be implemented into |
159 | 178 | * driver classes like abstract methods |
160 | 179 | * @param string $file |
161 | 180 | * @return bool */ |
162 | - static function checkImage($file) { return false; } |
|
181 | + static function checkImage($file) |
|
182 | + { |
|
183 | +return false; } |
|
163 | 184 | |
164 | 185 | /** Resize image. Should return TRUE on success or FALSE on failure |
165 | 186 | * @param integer $width |
@@ -12,7 +12,8 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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; |
@@ -12,14 +12,20 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -12,13 +12,15 @@ discard block |
||
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 |
||
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('"', """, |
32 | 35 | str_replace("'", ''', |
@@ -39,7 +42,8 @@ discard block |
||
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 |
||
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 |
||
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); |