Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Validate/File/IsImage.php
Go to the documentation of this file.
00001 <?php
00025 require_once 'Zend/Validate/File/MimeType.php';
00026 
00035 class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType
00036 {
00040     const FALSE_TYPE   = 'fileIsImageFalseType';
00041     const NOT_DETECTED = 'fileIsImageNotDetected';
00042     const NOT_READABLE = 'fileIsImageNotReadable';
00043 
00047     protected $_messageTemplates = array(
00048         self::FALSE_TYPE   => "File '%value%' is no image, '%type%' detected",
00049         self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected",
00050         self::NOT_READABLE => "File '%value%' can not be read",
00051     );
00052 
00059     public function __construct($mimetype = array())
00060     {
00061         if ($mimetype instanceof Zend_Config) {
00062             $mimetype = $mimetype->toArray();
00063         }
00064 
00065         $temp    = array();
00066         // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
00067         // http://www.iana.org/assignments/media-types/image/
00068         $default = array(
00069             'application/cdf',
00070             'application/dicom',
00071             'application/fractals',
00072             'application/postscript',
00073             'application/vnd.hp-hpgl',
00074             'application/vnd.oasis.opendocument.graphics',
00075             'application/x-cdf',
00076             'application/x-cmu-raster',
00077             'application/x-ima',
00078             'application/x-inventor',
00079             'application/x-koan',
00080             'application/x-portable-anymap',
00081             'application/x-world-x-3dmf',
00082             'image/bmp',
00083             'image/c',
00084             'image/cgm',
00085             'image/fif',
00086             'image/gif',
00087             'image/jpeg',
00088             'image/jpm',
00089             'image/jpx',
00090             'image/jp2',
00091             'image/naplps',
00092             'image/pjpeg',
00093             'image/png',
00094             'image/svg',
00095             'image/svg+xml',
00096             'image/tiff',
00097             'image/vnd.adobe.photoshop',
00098             'image/vnd.djvu',
00099             'image/vnd.fpx',
00100             'image/vnd.net-fpx',
00101             'image/x-cmu-raster',
00102             'image/x-cmx',
00103             'image/x-coreldraw',
00104             'image/x-cpi',
00105             'image/x-emf',
00106             'image/x-ico',
00107             'image/x-icon',
00108             'image/x-jg',
00109             'image/x-ms-bmp',
00110             'image/x-niff',
00111             'image/x-pict',
00112             'image/x-pcx',
00113             'image/x-portable-anymap',
00114             'image/x-portable-bitmap',
00115             'image/x-portable-greymap',
00116             'image/x-portable-pixmap',
00117             'image/x-quicktime',
00118             'image/x-rgb',
00119             'image/x-tiff',
00120             'image/x-unknown',
00121             'image/x-windows-bmp',
00122             'image/x-xpmi',
00123         );
00124 
00125         if (is_array($mimetype)) {
00126             $temp = $mimetype;
00127             if (array_key_exists('magicfile', $temp)) {
00128                 unset($temp['magicfile']);
00129             }
00130 
00131             if (array_key_exists('headerCheck', $temp)) {
00132                 unset($temp['headerCheck']);
00133             }
00134 
00135             if (empty($temp)) {
00136                 $mimetype += $default;
00137             }
00138         }
00139 
00140         if (empty($mimetype)) {
00141             $mimetype = $default;
00142         }
00143 
00144         parent::__construct($mimetype);
00145     }
00146 
00155     protected function _throw($file, $errorType)
00156     {
00157         $this->_value = $file['name'];
00158         switch($errorType) {
00159             case Zend_Validate_File_MimeType::FALSE_TYPE :
00160                 $errorType = self::FALSE_TYPE;
00161                 break;
00162             case Zend_Validate_File_MimeType::NOT_DETECTED :
00163                 $errorType = self::NOT_DETECTED;
00164                 break;
00165             case Zend_Validate_File_MimeType::NOT_READABLE :
00166                 $errorType = self::NOT_READABLE;
00167                 break;
00168         }
00169 
00170         $this->_error($errorType);
00171         return false;
00172     }
00173 }
 All Data Structures Namespaces Files Functions Variables Enumerations