| 1 |
1
|
kore |
<?php |
|
| 2 |
↓
|
kore |
/** |
|
| 3 |
2
|
kore |
* phpillow CouchDB backend |
|
| 4 |
1
|
kore |
* |
|
| 5 |
2
|
kore |
* This file is part of phpillow. |
|
| 6 |
1
|
kore |
* |
|
| 7 |
3
|
kore |
* phpillow is free software; you can redistribute it and/or modify it under |
|
| 8 |
↓
|
kore |
* the terms of the GNU Lesser General Public License as published by the Free |
|
| 9 |
↓
|
kore |
* Software Foundation; version 3 of the License. |
|
| 10 |
1
|
kore |
* |
|
| 11 |
3
|
kore |
* phpillow is distributed in the hope that it will be useful, but WITHOUT ANY |
|
| 12 |
↓
|
kore |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
| 13 |
↓
|
kore |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
|
| 14 |
↓
|
kore |
* more details. |
|
| 15 |
1
|
kore |
* |
|
| 16 |
3
|
kore |
* You should have received a copy of the GNU Lesser General Public License |
|
| 17 |
↓
|
kore |
* along with phpillow; if not, write to the Free Software Foundation, Inc., 51 |
|
| 18 |
↓
|
kore |
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 19 |
1
|
kore |
* |
|
| 20 |
↓
|
kore |
* @package Core |
|
| 21 |
4
|
kore |
* @version $Revision: 4 $ |
|
| 22 |
3
|
kore |
* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL |
|
| 23 |
1
|
kore |
*/ |
|
| 24 |
↓
|
kore |
|
|
| 25 |
↓
|
kore |
/** |
|
| 26 |
↓
|
kore |
* Validate given file as a valid image file |
|
| 27 |
↓
|
kore |
* |
|
| 28 |
↓
|
kore |
* @package Core |
|
| 29 |
4
|
kore |
* @version $Revision: 4 $ |
|
| 30 |
3
|
kore |
* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL |
|
| 31 |
1
|
kore |
*/ |
|
| 32 |
4
|
kore |
class phpillowImageFileLocationValidator extends phpillowValidator |
|
| 33 |
1
|
kore |
{ |
|
| 34 |
↓
|
kore |
/** |
|
| 35 |
↓
|
kore |
* Array containing a list of supported image formats. |
|
| 36 |
↓
|
kore |
* |
|
| 37 |
↓
|
kore |
* @var array |
|
| 38 |
↓
|
kore |
*/ |
|
| 39 |
↓
|
kore |
protected $supportedImageFormats = array( |
|
| 40 |
↓
|
kore |
IMAGETYPE_GIF, |
|
| 41 |
↓
|
kore |
IMAGETYPE_JPEG, |
|
| 42 |
↓
|
kore |
IMAGETYPE_PNG, |
|
| 43 |
↓
|
kore |
); |
|
| 44 |
↓
|
kore |
|
|
| 45 |
↓
|
kore |
/** |
|
| 46 |
↓
|
kore |
* Validate input as string |
|
| 47 |
↓
|
kore |
* |
|
| 48 |
↓
|
kore |
* @param mixed $input |
|
| 49 |
↓
|
kore |
* @return string |
|
| 50 |
↓
|
kore |
*/ |
|
| 51 |
↓
|
kore |
public function validate( $input ) |
|
| 52 |
↓
|
kore |
{ |
|
| 53 |
↓
|
kore |
// Check if we got readaccess to the provided file name at all. |
|
| 54 |
↓
|
kore |
if ( !is_file( $input ) || !is_readable( $input ) ) |
|
| 55 |
↓
|
kore |
{ |
|
| 56 |
2
|
kore |
throw new phpillowRuntimeException( 'Given image file not found: ' . $input ); |
|
| 57 |
1
|
kore |
} |
|
| 58 |
↓
|
kore |
|
|
| 59 |
↓
|
kore |
// Use getimagesize to determine the filetype of the image, and compare |
|
| 60 |
↓
|
kore |
// with whitelist of supported image formats. |
|
| 61 |
↓
|
kore |
$imageData = getimagesize( $input ); |
|
| 62 |
↓
|
kore |
if ( ( $imageData === false ) || |
|
| 63 |
↓
|
kore |
( !in_array( $imageData[2], $this->supportedImageFormats ) ) ) |
|
| 64 |
↓
|
kore |
{ |
|
| 65 |
3
|
kore |
throw new phpillowValidationException( 'Unsupported image format provided.', array() ); |
|
| 66 |
1
|
kore |
} |
|
| 67 |
↓
|
kore |
|
|
| 68 |
↓
|
kore |
// If all checks passed, we assume that this is a proper image file. |
|
| 69 |
↓
|
kore |
return $input; |
|
| 70 |
↓
|
kore |
} |
|
| 71 |
↓
|
kore |
} |
|
| 72 |
↓
|
kore |
|
|