Пример #1
0
 /**
  * Checks if resource is located within given locations
  *
  * @param Model $Model
  * @param array $field
  * @param mixed $allow True or * allows any location, an array containing absolute paths to locations
  * @return boolean
  */
 function checkLocation(&$Model, $field, $allow = true)
 {
     extract($this->runtime[$Model->alias]);
     foreach ((array) $allow as $allowed) {
         if (strpos(':', $allowed) !== false) {
             $message = "TransferBehavior::checkLocation - ";
             $message .= "Makers cannot be used in parameters for this method anymore. ";
             $message .= "Please use predefined constants instead.";
             trigger_error($message, E_USER_NOTICE);
         }
     }
     foreach (array('source', 'temporary', 'destination') as $type) {
         if ($type == 'temporary' && empty(${$type})) {
             continue;
         }
         if ($type == 'source' && ${$type}['type'] == 'file-upload-remote') {
             continue;
         }
         if (!MediaValidation::location(${$type}['file'], $allow)) {
             return false;
         }
     }
     return true;
 }
 function testLocation()
 {
     $result = MediaValidation::location(TMP);
     $this->assertFalse($result);
     $result = MediaValidation::location(TMP, true);
     $this->assertTrue($result);
     $result = MediaValidation::location(TMP, array(DS));
     $this->assertTrue($result);
     $result = MediaValidation::location(TMP . DS . DS . DS, array(DS));
     $this->assertTrue($result);
     $result = MediaValidation::location(TMP . DS . 'file.png', array(DS));
     $this->assertTrue($result);
     $result = MediaValidation::location(TMP, array(TMP . 'subdir'));
     $this->assertFalse($result);
     $result = MediaValidation::location('http://cakeforge.org', true);
     $this->assertTrue($result);
     $result = MediaValidation::location('http://cakeforge.org');
     $this->assertFalse($result);
     $result = MediaValidation::location('http://cakeforge.org', array(TMP));
     $this->assertFalse($result);
     $result = MediaValidation::location('http://cakeforge.org', array(TMP, 'http://'));
     $this->assertTrue($result);
     $result = MediaValidation::location('http://cakeforge.org', 'http://rosa');
     $this->assertFalse($result);
     $result = MediaValidation::location('http://cakeforge.org', 'http://cakeforge.org');
     $this->assertTrue($result);
     $result = MediaValidation::location('http://cakeforge.org/bla/?x=?$§c $%.org', 'http://cakeforge.org');
     $this->assertFalse($result);
     $result = MediaValidation::location('http://cakeforge.org/bla', 'http://cakeforge.org');
     $this->assertTrue($result);
     $result = MediaValidation::location('http://cakeforge.org/bla?x=do', 'http://cakeforge.org');
     $this->assertTrue($result);
 }
Пример #3
0
 /**
  * Checks if resource is located within given locations
  *
  * @param Model $Model
  * @param array $field
  * @param mixed $allow True or * allows any location, an array containing absolute paths to locations
  * @return boolean
  */
 public function checkLocation(Model $Model, $field, $allow = true)
 {
     extract($this->runtime[$Model->alias]);
     foreach (array('source', 'temporary', 'destination') as $type) {
         if ($type == 'temporary' && empty(${$type})) {
             continue;
         }
         if ($type == 'source' && ${$type}['type'] == 'file-upload-remote') {
             continue;
         }
         if (!MediaValidation::location(${$type}['file'], $allow)) {
             return false;
         }
     }
     return true;
 }
Пример #4
0
 public function testLocation()
 {
     $result = MediaValidation::location(TMP);
     $this->assertFalse($result);
     $result = MediaValidation::location(TMP, true);
     $this->assertTrue($result);
     $topMostDir = current(explode(DS, TMP)) . DS;
     $result = MediaValidation::location(TMP, array($topMostDir));
     $this->assertTrue($result);
     $result = MediaValidation::location(TMP . DS . DS . DS, array($topMostDir));
     $this->assertTrue($result);
     $result = MediaValidation::location(TMP . DS . 'file.png', array($topMostDir));
     $this->assertTrue($result);
     $result = MediaValidation::location(TMP, array(TMP . 'subdir'));
     $this->assertFalse($result);
     $result = MediaValidation::location('http://cakeforge.org', true);
     $this->assertTrue($result);
     $result = MediaValidation::location('http://cakeforge.org');
     $this->assertFalse($result);
     $result = MediaValidation::location('http://cakeforge.org', array(TMP));
     $this->assertFalse($result);
     $result = MediaValidation::location('http://cakeforge.org', array(TMP, 'http://'));
     $this->assertTrue($result);
     $result = MediaValidation::location('http://cakeforge.org', 'http://rosa');
     $this->assertFalse($result);
     $result = MediaValidation::location('http://cakeforge.org', 'http://cakeforge.org');
     $this->assertTrue($result);
     $result = MediaValidation::location('http://cakeforge.org/bla/?x=?$§c $%.org', 'http://cakeforge.org');
     $this->assertFalse($result);
     $result = MediaValidation::location('http://cakeforge.org/bla', 'http://cakeforge.org');
     $this->assertTrue($result);
     $result = MediaValidation::location('http://cakeforge.org/bla?x=do', 'http://cakeforge.org');
     $this->assertTrue($result);
 }