Esempio n. 1
0
 public function testSimplify()
 {
     $this->assertEquals('application/pdf', Mime_Type::simplify('application/x-pdf'));
     $this->assertEquals('inode/directory', Mime_Type::simplify('x-inode/x-directory'));
     $this->assertEquals('application/octet-stream', Mime_Type::simplify('application/octet-stream; encoding=compress'));
     $this->assertEquals('application/test', Mime_Type::simplify('application/x-test; encoding=compress'));
     $this->assertEquals('text/plain', Mime_Type::simplify('text/plain; charset=iso-8859-1'));
     $this->assertEquals('text/plain', Mime_Type::simplify('text/plain charset=us-ascii'));
 }
Esempio n. 2
0
 /**
  * Checks if resource has (not) one of given MIME types
  *
  * This check is less strict in that it isn't sensitive to MIME types with or
  * without properties or experimental indicators. This holds true for the type
  * which is subject of the check as well as types provided for $deny and
  * $allow. I.e. `audio/x-ogg` will be allowed if $allow contains `audio/ogg`
  * and `video/ogg` works also if $allow contains the stricter `video/x-ogg`.
  *
  * @param Model $Model
  * @param array $field
  * @param mixed $deny True or * blocks any MIME type,
  * 	an array containing MIME types selectively blocks,
  * 	false blocks no MIME type
  * @param mixed $allow True or * allows any extension,
  * 	an array containing extensions selectively allows,
  * 	false allows no MIME type
  * @return boolean
  */
 function checkMimeType(&$Model, $field, $deny = false, $allow = true)
 {
     extract($this->runtime[$Model->alias]);
     extract($this->settings[$Model->alias], EXTR_SKIP);
     foreach (array('source', 'temporary') as $type) {
         /*
          * MIME types and trustClient setting
          *
          * trust | source   | (temporary) | (destination)
          * ------|----------|----------------------------
          * true  | x/x      | x/x         | x/x,null
          * ------|----------|----------------------------
          * false | x/x,null | x/x,null    | null
          */
         /* Temporary is optional */
         if ($type === 'temporary' && empty(${$type})) {
             continue;
         }
         /* With `trustClient` set to `false` we don't necessarily have a MIME type */
         if (!isset(${$type}['mimeType']) && !$trustClient) {
             continue;
         }
         $result = MediaValidation::mimeType(${$type}['mimeType'], $deny, $allow);
         $result |= MediaValidation::mimeType(Mime_Type::simplify(${$type}['mimeType']), $deny, $allow);
         return $result;
     }
     return true;
 }
Esempio n. 3
0
 /**
  * Checks if resource has (not) one of given MIME types
  *
  * This check is less strict in that it isn't sensitive to MIME types with or
  * without properties or experimental indicators. This holds true for the type
  * which is subject of the check as well as types provided for $deny and
  * $allow. I.e. `audio/x-ogg` will be allowed if $allow contains `audio/ogg`
  * and `video/ogg` works also if $allow contains the stricter `video/x-ogg`.
  *
  * @param Model $Model
  * @param array $field
  * @param mixed $deny True or * blocks any MIME type,
  * 	an array containing MIME types selectively blocks,
  * 	false blocks no MIME type
  * @param mixed $allow True or * allows any extension,
  * 	an array containing extensions selectively allows,
  * 	false allows no MIME type
  * @return boolean
  */
 public function checkMimeType(Model $Model, $field, $deny = false, $allow = true)
 {
     extract($this->runtime[$Model->alias]);
     /* @var $source array */
     /* @var $temporary string */
     /* @var $destination string */
     /* @var $hasPerformed boolean */
     extract($this->settings[$Model->alias], EXTR_SKIP);
     /* @var $trustClient boolean */
     /* @var $transferDirectory string */
     /* @var $createDirectory boolean */
     /* @var $alternativeFile integer */
     /* @var $overwrite boolean */
     foreach (array('source', 'temporary') as $type) {
         /*
          * MIME types and trustClient setting
          *
          * trust | source   | (temporary) | (destination)
          * ------|----------|----------------------------
          * true  | x/x      | x/x         | x/x,null
          * ------|----------|----------------------------
          * false | x/x,null | x/x,null    | null
          */
         /* Temporary is optional */
         if ($type === 'temporary' && empty(${$type})) {
             continue;
         }
         /* With `trustClient` set to `false` we don't necessarily have a MIME type */
         if (!isset(${$type}['mimeType']) && !$trustClient) {
             continue;
         }
         $result = MediaValidation::mimeType(${$type}['mimeType'], $deny, $allow);
         $result |= MediaValidation::mimeType(Mime_Type::simplify(${$type}['mimeType']), $deny, $allow);
         return $result;
     }
     return true;
 }