Index: trunk/phase3/includes/filerepo/file/FSFile.php |
— | — | @@ -69,6 +69,15 @@ |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
| 73 | + * Guess the MIME type from the file contents alone |
| 74 | + * |
| 75 | + * @return string |
| 76 | + */ |
| 77 | + public function getMimeType() { |
| 78 | + return MimeMagic::singleton()->guessMimeType( $this->path, false ); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
73 | 82 | * Get an associative array containing information about |
74 | 83 | * a file with the given storage path. |
75 | 84 | * |
— | — | @@ -89,12 +98,11 @@ |
90 | 99 | |
91 | 100 | # get the file extension |
92 | 101 | if ( $ext === true ) { |
93 | | - $i = strrpos( $this->path, '.' ); |
94 | | - $ext = strtolower( $i ? substr( $this->path, $i + 1 ) : '' ); |
| 102 | + $ext = self::extensionFromPath( $this->path ); |
95 | 103 | } |
96 | 104 | |
97 | 105 | # mime type according to file contents |
98 | | - $info['file-mime'] = $magic->guessMimeType( $this->path, false ); |
| 106 | + $info['file-mime'] = $this->getMimeType(); |
99 | 107 | # logical mime type |
100 | 108 | $info['mime'] = $magic->improveTypeFromExtension( $info['file-mime'], $ext ); |
101 | 109 | |
— | — | @@ -143,6 +151,11 @@ |
144 | 152 | return $info; |
145 | 153 | } |
146 | 154 | |
| 155 | + /** |
| 156 | + * Exract image size information |
| 157 | + * |
| 158 | + * @return Array |
| 159 | + */ |
147 | 160 | protected function extractImageSizeInfo( array $gis ) { |
148 | 161 | $info = array(); |
149 | 162 | # NOTE: $gis[2] contains a code for the image type. This is no longer used. |
— | — | @@ -180,6 +193,17 @@ |
181 | 194 | } |
182 | 195 | |
183 | 196 | /** |
| 197 | + * Get the final file extension from a file system path |
| 198 | + * |
| 199 | + * @param $path string |
| 200 | + * @returns string |
| 201 | + */ |
| 202 | + public static function extensionFromPath( $path ) { |
| 203 | + $i = strrpos( $path, '.' ); |
| 204 | + return strtolower( $i ? substr( $path, $i + 1 ) : '' ); |
| 205 | + } |
| 206 | + |
| 207 | + /** |
184 | 208 | * Get an associative array containing information about a file in the local filesystem. |
185 | 209 | * |
186 | 210 | * @param $path String: absolute local filesystem path |
— | — | @@ -188,7 +212,7 @@ |
189 | 213 | * |
190 | 214 | * @return array |
191 | 215 | */ |
192 | | - static function getPropsFromPath( $path, $ext = true ) { |
| 216 | + public static function getPropsFromPath( $path, $ext = true ) { |
193 | 217 | $fsFile = new self( $path ); |
194 | 218 | return $fsFile->getProps( $ext ); |
195 | 219 | } |
— | — | @@ -204,7 +228,7 @@ |
205 | 229 | * |
206 | 230 | * @return false|string False on failure |
207 | 231 | */ |
208 | | - static function getSha1Base36FromPath( $path ) { |
| 232 | + public static function getSha1Base36FromPath( $path ) { |
209 | 233 | $fsFile = new self( $path ); |
210 | 234 | return $fsFile->getSha1Base36(); |
211 | 235 | } |