1 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
12 | class Kohana_Upload_Util { |
||
13 | |||
14 | 4 | public static function download($url, $directory, $filename = NULL) |
|
61 | |||
62 | /** |
||
63 | * Move the contents of the stream to a specified directory with a given name |
||
64 | * |
||
65 | * @param string $stream |
||
66 | * @param string $directory |
||
|
|||
67 | * @param string $filename |
||
68 | */ |
||
69 | 1 | public static function stream_copy_to_file($stream, $file) |
|
82 | |||
83 | /** |
||
84 | * recursively delete directory |
||
85 | * |
||
86 | * @param string $directory |
||
87 | * @return boolean |
||
88 | */ |
||
89 | 17 | public static function rmdir($directory) |
|
111 | |||
112 | /** |
||
113 | * Method to make a filename safe for writing on the filesystem, removing all strange characters |
||
114 | * @param string $filename |
||
115 | * @return string |
||
116 | */ |
||
117 | 13 | static public function sanitize($filename, $separator = '-') |
|
118 | { |
||
119 | // Transliterate strange chars |
||
120 | 13 | $filename = UTF8::transliterate_to_ascii($filename); |
|
121 | |||
122 | // Sanitize the filename |
||
123 | 13 | $filename = preg_replace('/[^a-z0-9-\.]/', $separator, strtolower($filename)); |
|
124 | |||
125 | // Remove spaces |
||
126 | 13 | $filename = preg_replace('/\s+/u', $separator, $filename); |
|
127 | |||
128 | // Strip multiple dashes |
||
129 | 13 | $filename = preg_replace('/-{2,}/', $separator, $filename); |
|
130 | |||
131 | 13 | return $filename; |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Check if a file looks like a filename ("file.ext") |
||
136 | * @param string $filename |
||
137 | * @return boolean |
||
138 | */ |
||
139 | 16 | public static function is_filename($filename) |
|
140 | { |
||
141 | 16 | return (bool) pathinfo($filename, PATHINFO_EXTENSION); |
|
142 | } |
||
143 | |||
144 | /** |
||
145 | * Return possible filenames from a given url. |
||
146 | * Filenames can be in the query or the url of the file itself |
||
147 | * |
||
148 | * @param string $url |
||
149 | * @return array |
||
150 | */ |
||
151 | 14 | public static function filenames_candidates_from_url($url) |
|
152 | { |
||
153 | 14 | $query = parse_url($url, PHP_URL_QUERY); |
|
154 | 14 | parse_str($query, $query); |
|
155 | |||
156 | 14 | $filename_candidates = array_values( (array) $query); |
|
157 | |||
158 | 14 | $url_filename = basename(parse_url($url, PHP_URL_PATH)); |
|
159 | |||
160 | 14 | $filename_candidates[] = $url_filename; |
|
161 | |||
162 | 14 | return $filename_candidates; |
|
163 | } |
||
164 | |||
165 | /** |
||
166 | * Create a filename path from function arguments with / based on the operating system |
||
167 | * @code |
||
168 | * $filename = file::combine('usr','local','bin'); // will be "user/local/bin" |
||
169 | * @endcode |
||
170 | * @return string |
||
171 | * @author Ivan Kerin |
||
172 | */ |
||
173 | 31 | public static function combine() |
|
174 | { |
||
175 | 31 | $args = func_get_args(); |
|
176 | |||
177 | 31 | foreach ($args as $i => & $arg) |
|
178 | { |
||
179 | 31 | $arg = $i == 0 ? rtrim($arg, DIRECTORY_SEPARATOR) : trim($arg, DIRECTORY_SEPARATOR); |
|
180 | 31 | } |
|
181 | |||
182 | 31 | return join(DIRECTORY_SEPARATOR, array_filter($args)); |
|
183 | } |
||
184 | |||
185 | /** |
||
186 | * Detirmine the filename from the url |
||
187 | * @param string $url |
||
188 | * @param string $mime_type |
||
189 | * @return string |
||
190 | */ |
||
191 | 9 | public static function filename_from_url($url, $mime_type = NULL) |
|
192 | { |
||
193 | 9 | $filename_candidates = Upload_Util::filenames_candidates_from_url($url); |
|
194 | 9 | $filename_candidates = array_filter($filename_candidates, 'Upload_Util::is_filename'); |
|
195 | 9 | $file = count($filename_candidates) ? reset($filename_candidates) : uniqid(); |
|
196 | 9 | $extensions = File::exts_by_mime($mime_type); |
|
197 | |||
198 | $extension_candiates = array( |
||
199 | 9 | (is_array($extensions) ? end($extensions) : $extensions), |
|
200 | 9 | pathinfo($file, PATHINFO_EXTENSION), |
|
201 | 9 | 'jpg', |
|
202 | 9 | ); |
|
203 | 9 | $extension_candiates = array_filter($extension_candiates); |
|
204 | 9 | $extension = reset($extension_candiates); |
|
205 | |||
206 | 9 | return Upload_Util::sanitize(pathinfo($file, PATHINFO_FILENAME)).'.'.$extension; |
|
207 | } |
||
208 | |||
209 | 9 | public static function filename_from_content_disposition($content_disposition) |
|
216 | |||
217 | /** |
||
218 | * Perform transformations on an image and store it at a different location (or overwrite existing) |
||
219 | * |
||
220 | * @param string $from |
||
221 | * @param string $to |
||
222 | * @param array $transformations |
||
223 | */ |
||
224 | 3 | public static function transform_image($from, $to, array $transformations = array()) |
|
245 | } |
||
246 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.