@@ -12,17 +12,20 @@ |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class type_img { |
|
15 | +class type_img |
|
16 | +{ |
|
16 | 17 | |
17 | - public function checkFile($file, array $config) { |
|
18 | + public function checkFile($file, array $config) |
|
19 | + { |
|
18 | 20 | |
19 | 21 | $driver = isset($config['imageDriversPriority']) |
20 | 22 | ? image::getDriver(explode(" ", $config['imageDriversPriority'])) : "gd"; |
21 | 23 | |
22 | 24 | $img = image::factory($driver, $file); |
23 | 25 | |
24 | - if ($img->initError) |
|
25 | - return "Unknown image format/encoding."; |
|
26 | + if ($img->initError) { |
|
27 | + return "Unknown image format/encoding."; |
|
28 | + } |
|
26 | 29 | |
27 | 30 | return true; |
28 | 31 | } |
@@ -12,20 +12,25 @@ |
||
12 | 12 | * @link http://kcfinder.sunhater.com |
13 | 13 | */ |
14 | 14 | |
15 | -class type_mime { |
|
15 | +class type_mime |
|
16 | +{ |
|
16 | 17 | |
17 | - public function checkFile($file, array $config) { |
|
18 | - if (!class_exists("finfo")) |
|
19 | - return "Fileinfo PECL extension is missing."; |
|
18 | + public function checkFile($file, array $config) |
|
19 | + { |
|
20 | + if (!class_exists("finfo")) { |
|
21 | + return "Fileinfo PECL extension is missing."; |
|
22 | + } |
|
20 | 23 | |
21 | - if (!isset($config['params'])) |
|
22 | - return "Undefined MIME types."; |
|
24 | + if (!isset($config['params'])) { |
|
25 | + return "Undefined MIME types."; |
|
26 | + } |
|
23 | 27 | |
24 | 28 | $finfo = strlen($config['mime_magic']) |
25 | 29 | ? new finfo(FILEINFO_MIME, $config['mime_magic']) |
26 | 30 | : new finfo(FILEINFO_MIME); |
27 | - if (!$finfo) |
|
28 | - return "Opening fileinfo database failed."; |
|
31 | + if (!$finfo) { |
|
32 | + return "Opening fileinfo database failed."; |
|
33 | + } |
|
29 | 34 | |
30 | 35 | $type = $finfo->file($file); |
31 | 36 | $type = substr($type, 0, strrpos($type, ";")); |
@@ -14,7 +14,9 @@ |
||
14 | 14 | |
15 | 15 | require "core/autoload.php"; |
16 | 16 | $mtime = @filemtime(__FILE__); |
17 | -if ($mtime) httpCache::checkMTime($mtime); |
|
17 | +if ($mtime) { |
|
18 | + httpCache::checkMTime($mtime); |
|
19 | +} |
|
18 | 20 | $browser = new browser($modx); |
19 | 21 | $config = $browser->config; |
20 | 22 | ob_start(); |
@@ -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 | -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; |