PageRenderTime 89ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/concreteOLD/libraries/3rdparty/Zend/Validate/File/IsImage.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 173 lines | 109 code | 12 blank | 52 comment | 6 complexity | 32aba30b324b9975b35454d9c3d30425 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Validate
  17. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: IsImage.php 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /**
  22. * @see Zend_Validate_File_MimeType
  23. */
  24. require_once 'Zend/Validate/File/MimeType.php';
  25. /**
  26. * Validator which checks if the file already exists in the directory
  27. *
  28. * @category Zend
  29. * @package Zend_Validate
  30. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType
  34. {
  35. /**
  36. * @const string Error constants
  37. */
  38. const FALSE_TYPE = 'fileIsImageFalseType';
  39. const NOT_DETECTED = 'fileIsImageNotDetected';
  40. const NOT_READABLE = 'fileIsImageNotReadable';
  41. /**
  42. * @var array Error message templates
  43. */
  44. protected $_messageTemplates = array(
  45. self::FALSE_TYPE => "File '%value%' is no image, '%type%' detected",
  46. self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected",
  47. self::NOT_READABLE => "File '%value%' is not readable or does not exist",
  48. );
  49. /**
  50. * Sets validator options
  51. *
  52. * @param string|array|Zend_Config $mimetype
  53. * @return void
  54. */
  55. public function __construct($mimetype = array())
  56. {
  57. if ($mimetype instanceof Zend_Config) {
  58. $mimetype = $mimetype->toArray();
  59. }
  60. $temp = array();
  61. // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
  62. // http://www.iana.org/assignments/media-types/image/
  63. $default = array(
  64. 'application/cdf',
  65. 'application/dicom',
  66. 'application/fractals',
  67. 'application/postscript',
  68. 'application/vnd.hp-hpgl',
  69. 'application/vnd.oasis.opendocument.graphics',
  70. 'application/x-cdf',
  71. 'application/x-cmu-raster',
  72. 'application/x-ima',
  73. 'application/x-inventor',
  74. 'application/x-koan',
  75. 'application/x-portable-anymap',
  76. 'application/x-world-x-3dmf',
  77. 'image/bmp',
  78. 'image/c',
  79. 'image/cgm',
  80. 'image/fif',
  81. 'image/gif',
  82. 'image/jpeg',
  83. 'image/jpm',
  84. 'image/jpx',
  85. 'image/jp2',
  86. 'image/naplps',
  87. 'image/pjpeg',
  88. 'image/png',
  89. 'image/svg',
  90. 'image/svg+xml',
  91. 'image/tiff',
  92. 'image/vnd.adobe.photoshop',
  93. 'image/vnd.djvu',
  94. 'image/vnd.fpx',
  95. 'image/vnd.net-fpx',
  96. 'image/x-cmu-raster',
  97. 'image/x-cmx',
  98. 'image/x-coreldraw',
  99. 'image/x-cpi',
  100. 'image/x-emf',
  101. 'image/x-ico',
  102. 'image/x-icon',
  103. 'image/x-jg',
  104. 'image/x-ms-bmp',
  105. 'image/x-niff',
  106. 'image/x-pict',
  107. 'image/x-pcx',
  108. 'image/x-portable-anymap',
  109. 'image/x-portable-bitmap',
  110. 'image/x-portable-greymap',
  111. 'image/x-portable-pixmap',
  112. 'image/x-quicktime',
  113. 'image/x-rgb',
  114. 'image/x-tiff',
  115. 'image/x-unknown',
  116. 'image/x-windows-bmp',
  117. 'image/x-xpmi',
  118. );
  119. if (is_array($mimetype)) {
  120. $temp = $mimetype;
  121. if (array_key_exists('magicfile', $temp)) {
  122. unset($temp['magicfile']);
  123. }
  124. if (array_key_exists('headerCheck', $temp)) {
  125. unset($temp['headerCheck']);
  126. }
  127. if (empty($temp)) {
  128. $mimetype += $default;
  129. }
  130. }
  131. if (empty($mimetype)) {
  132. $mimetype = $default;
  133. }
  134. parent::__construct($mimetype);
  135. }
  136. /**
  137. * Throws an error of the given type
  138. * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2
  139. *
  140. * @param string $file
  141. * @param string $errorType
  142. * @return false
  143. */
  144. protected function _throw($file, $errorType)
  145. {
  146. $this->_value = $file['name'];
  147. switch($errorType) {
  148. case Zend_Validate_File_MimeType::FALSE_TYPE :
  149. $errorType = self::FALSE_TYPE;
  150. break;
  151. case Zend_Validate_File_MimeType::NOT_DETECTED :
  152. $errorType = self::NOT_DETECTED;
  153. break;
  154. case Zend_Validate_File_MimeType::NOT_READABLE :
  155. $errorType = self::NOT_READABLE;
  156. break;
  157. }
  158. $this->_error($errorType);
  159. return false;
  160. }
  161. }