url() public static method

public static url ( $value )
コード例 #1
0
 public function beforeSave($options = array())
 {
     // add http:// if not present in webpage
     $webpage = $this->data['Registrant']['webpage'];
     $V = new Validation();
     if (!empty($webpage) && $V->url($webpage) && !$V->url($webpage, true)) {
         $this->data['Registrant']['webpage'] = 'http://' . $webpage;
     }
     // generate edit key
     if (empty($this->data['Registrant']['edit_key'])) {
         $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
         $this->data['Registrant']['edit_key'] = substr(str_shuffle($chars), 0, 8);
     }
     return true;
 }
コード例 #2
0
ファイル: gravatar.php プロジェクト: kouak/ircube
 function __cleanOptions($options)
 {
     if (!$options['size']) {
         unset($options['size']);
     } else {
         if ($options['size'] < 1) {
             $options['size'] = 1;
         } elseif ($options['size'] > 512) {
             $options['size'] = 512;
         }
     }
     if (!$options['rating'] || !in_array($options['rating'], $this->__allowedRatings)) {
         unset($options['rating']);
     }
     if (!$options['default']) {
         unset($options['default']);
     } else {
         if (!in_array($options['default'], $this->__defaultIcons)) {
             if (!Validation::url($options['default'])) {
                 unset($options['default']);
             }
         }
     }
     return $options;
 }
コード例 #3
0
 function register()
 {
     global $timezones;
     $this->pageTitle = __('register', true);
     $this->set('tzs', $timezones);
     $this->set('utz', $this->data['User']['tz']);
     if (!empty($this->data)) {
         $this->Security->requirePost('register');
         $v = new Validation();
         if ($this->data['User']['email'] !== $this->data['User']['confemail']) {
             $this->User->invalidate('confemail');
         }
         if ($this->User->findByEmail($this->data['User']['email']) || !$v->email($this->data['User']['email'])) {
             $this->User->invalidate('email');
         }
         if ($this->data['User']['password'] !== $this->data['User']['confpass']) {
             $this->User->invalidate('confpass');
         }
         if (!$v->url($this->data['User']['website']) && !empty($this->data['User']['website'])) {
             $this->User->invalidate('website');
         }
         if ($this->User->validates()) {
             $clean = new Sanitize();
             // Generate and set the password, salt and activation key
             $pass = $this->Hash->password($this->data['User']['password'], $this->data['User']['email']);
             $this->data['User']['active'] = $this->Hash->keygen(10, true);
             $this->data['User']['password'] = $pass['pass'];
             $this->data['User']['salt'] = $pass['salt'];
             // Save a few fields from the wrath of cleanArray()
             $temp = array('lat' => $this->data['User']['lat'], 'lng' => $this->data['User']['lng'], 'tz' => $this->data['User']['tz'], 'email' => $this->data['User']['email']);
             // Scrub 'a dub
             $clean->clean($this->data);
             $this->data['User']['email'] = $clean->escape($temp['email']);
             $this->data['User']['lng'] = floatval($temp['lng']);
             $this->data['User']['lat'] = floatval($temp['lat']);
             $this->data['User']['tz'] = intval($temp['tz']);
             $this->data['User']['role'] = 0;
             $this->User->begin();
             if ($this->User->save($this->data)) {
                 $this->Email->to = $this->data['User']['email'];
                 $this->Email->replyTo = $this->data['User']['email'];
                 $this->Email->from = APP_NAME . ' <' . APP_EMAIL . '>';
                 $this->Email->subject = sprintf(__('email_subject_welcome', true), APP_NAME);
                 $this->Email->template = 'register';
                 $this->Email->sendAs = 'both';
                 $this->set('actcode', $this->data['User']['active']);
                 if ($this->Email->send()) {
                     $this->User->commit();
                     $this->Session->setFlash('Account created!');
                 } else {
                     $this->User->rollback();
                     $this->Session->setFlash('Error!');
                 }
             } else {
                 $this->User->rollback();
                 $this->Session->setFlash('Error\'d');
             }
         }
     }
 }
コード例 #4
0
 /**
  * Set URL
  *
  * Validates and sets the URL.
  *
  * @param string $url
  * @return true
  * @throws Exception
  */
 public function setURL($url)
 {
     if (!Validation::url($url) || !is_string($url)) {
         throw new Exception("URL is not valid to curl.");
     }
     curl_setopt($this->curl, CURLOPT_URL, $url);
     $this->set[] = 'url';
     return true;
 }
コード例 #5
0
 public function view()
 {
     if (empty($this->request->query['link'])) {
         throw new NotFoundException('Missing link parameter');
     }
     $link = rawurldecode($this->request->query['link']);
     if (!Validation::url($link)) {
         throw new NotFoundException('Invalid link');
     }
     $request = new Nodes\Curl($link);
     $request->exec();
     $responseCode = $request->getResponseCode();
     if ($responseCode != 200) {
         throw new NotFoundException('Response code was not 200 OK');
     }
     $this->response->disableCache();
     $this->response->type($request->getResponseHeader('content-type'));
     $this->response->body($request->getResponseBody());
     $this->response->send();
     $this->_stop();
 }
コード例 #6
0
ファイル: ValidationTest.php プロジェクト: alvaroziqar/galei
 /**
  * testUrl method
  *
  * @return void
  */
 public function testUrl()
 {
     $this->assertTrue(Validation::url('http://www.cakephp.org'));
     $this->assertTrue(Validation::url('http://cakephp.org'));
     $this->assertTrue(Validation::url('http://www.cakephp.org/somewhere#anchor'));
     $this->assertTrue(Validation::url('http://192.168.0.1'));
     $this->assertTrue(Validation::url('https://www.cakephp.org'));
     $this->assertTrue(Validation::url('https://cakephp.org'));
     $this->assertTrue(Validation::url('https://www.cakephp.org/somewhere#anchor'));
     $this->assertTrue(Validation::url('https://192.168.0.1'));
     $this->assertTrue(Validation::url('ftps://www.cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftps://cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftps://192.168.0.1/pub/cake'));
     $this->assertTrue(Validation::url('ftp://www.cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake'));
     $this->assertTrue(Validation::url('sftp://192.168.0.1/pub/cake'));
     $this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start'));
     $this->assertTrue(Validation::url('www.domain.tld'));
     $this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com'));
     $this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
     $this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php'));
     $this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&amp;get2=params'));
     $this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&amp;get2=params#anchor'));
     $this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing'));
     $this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)'));
     $this->assertTrue(Validation::url('http://www.cakephp.org', true));
     $this->assertTrue(Validation::url('http://example.com/~userdir/'));
     $this->assertTrue(Validation::url('http://underscore_subdomain.example.org'));
     $this->assertTrue(Validation::url('http://_jabber._tcp.gmail.com'));
     $this->assertTrue(Validation::url('http://www.domain.longttldnotallowed'));
     $this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake'));
     $this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake'));
     $this->assertFalse(Validation::url('http://w_w.domain.co_m'));
     $this->assertFalse(Validation::url('http://www.domain.12com'));
     $this->assertFalse(Validation::url('http://www.-invaliddomain.tld'));
     $this->assertFalse(Validation::url('http://www.domain.-invalidtld'));
     $this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com'));
     $this->assertFalse(Validation::url('http://www.underscore_domain.org'));
     $this->assertFalse(Validation::url('http://_jabber._tcp.g_mail.com'));
     $this->assertFalse(Validation::url('http://en.(wikipedia).org/'));
     $this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode'));
     $this->assertFalse(Validation::url('--.example.com'));
     $this->assertFalse(Validation::url('www.cakephp.org', true));
     $this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html'));
     $this->assertTrue(Validation::url('http://www.zwischenraume.de'));
     $this->assertTrue(Validation::url('http://www.zwischenraume.cz'));
     $this->assertTrue(Validation::url('http://www.last.fm/music/浜崎あゆみ'), 'utf8 path failed');
     $this->assertTrue(Validation::url('http://www.electrohome.ro/images/239537750-284232-215_300[1].jpg'));
     $this->assertTrue(Validation::url('http://www.eräume.foo'));
     $this->assertTrue(Validation::url('http://äüö.eräume.foo'));
     $this->assertTrue(Validation::url('http://cakephp.org:80'));
     $this->assertTrue(Validation::url('http://cakephp.org:443'));
     $this->assertTrue(Validation::url('http://cakephp.org:2000'));
     $this->assertTrue(Validation::url('http://cakephp.org:27000'));
     $this->assertTrue(Validation::url('http://cakephp.org:65000'));
     $this->assertTrue(Validation::url('[2001:0db8::1428:57ab]'));
     $this->assertTrue(Validation::url('[::1]'));
     $this->assertTrue(Validation::url('[2001:0db8::1428:57ab]:80'));
     $this->assertTrue(Validation::url('[::1]:80'));
     $this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]'));
     $this->assertTrue(Validation::url('http://[::1]'));
     $this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]:80'));
     $this->assertTrue(Validation::url('http://[::1]:80'));
     $this->assertFalse(Validation::url('[1::2::3]'));
 }
コード例 #7
0
 /**
  * Sanitize the options array
  *
  * @param array $options Array of options, keyed from default settings
  * @return array Clean options array
  */
 protected function _cleanOptions($options)
 {
     if (!isset($options['size']) || empty($options['size']) || !is_numeric($options['size'])) {
         unset($options['size']);
     } else {
         $options['size'] = min(max($options['size'], 1), 512);
     }
     if (!$options['rating'] || !in_array(mb_strtolower($options['rating']), $this->_allowedRatings)) {
         unset($options['rating']);
     }
     if (!$options['default']) {
         unset($options['default']);
     } else {
         App::uses('Validation', 'Utility');
         if (!in_array($options['default'], $this->_defaultIcons) && !Validation::url($options['default'])) {
             unset($options['default']);
         }
     }
     return $options;
 }
コード例 #8
0
ファイル: validation.test.php プロジェクト: evrard/cakephp2x
 /**
  * testUrl method
  *
  * @access public
  * @return void
  */
 function testUrl()
 {
     $this->assertTrue(Validation::url('http://www.cakephp.org'));
     $this->assertTrue(Validation::url('http://cakephp.org'));
     $this->assertTrue(Validation::url('http://www.cakephp.org/somewhere#anchor'));
     $this->assertTrue(Validation::url('http://192.168.0.1'));
     $this->assertTrue(Validation::url('https://www.cakephp.org'));
     $this->assertTrue(Validation::url('https://cakephp.org'));
     $this->assertTrue(Validation::url('https://www.cakephp.org/somewhere#anchor'));
     $this->assertTrue(Validation::url('https://192.168.0.1'));
     $this->assertTrue(Validation::url('ftps://www.cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftps://cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftps://192.168.0.1/pub/cake'));
     $this->assertTrue(Validation::url('ftp://www.cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake'));
     $this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake'));
     $this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake'));
     $this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start'));
     $this->assertTrue(Validation::url('www.domain.tld'));
     $this->assertFalse(Validation::url('http://w_w.domain.co_m'));
     $this->assertFalse(Validation::url('http://www.domain.12com'));
     $this->assertFalse(Validation::url('http://www.domain.longttldnotallowed'));
     $this->assertFalse(Validation::url('http://www.-invaliddomain.tld'));
     $this->assertFalse(Validation::url('http://www.domain.-invalidtld'));
     $this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com'));
     $this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com'));
     $this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
     $this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php'));
     $this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&amp;get2=params'));
     $this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&amp;get2=params#anchor'));
     $this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode'));
     $this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing'));
     $this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)'));
     $this->assertFalse(Validation::url('http://en.(wikipedia).org/'));
     $this->assertFalse(Validation::url('www.cakephp.org', true));
     $this->assertTrue(Validation::url('http://www.cakephp.org', true));
     $this->assertTrue(Validation::url('http://example.com/~userdir/'));
 }
コード例 #9
0
 /**
  * Checks if path is within given locations
  *
  * @param string $check Absolute path
  * @param mixed $allow True or * allows any location,
  * 	an array containing absolute paths to locations
  * @return boolean
  */
 function location($check, $allow = false)
 {
     $allow = self::_normalize($allow);
     if ($allow === true) {
         return true;
     } elseif ($allow === false) {
         return false;
     }
     if (!is_array($allow)) {
         $allow = array($allow);
     } else {
         $allow = array_unique($allow);
     }
     if (Validation::url($check)) {
         foreach ($allow as $path) {
             if (preg_match('/^' . preg_quote($path, '/') . '/', $check)) {
                 return true;
             }
         }
     } elseif (MediaValidation::file($check, false)) {
         $check = dirname($check);
         if (!Folder::isAbsolute($check)) {
             return false;
         }
         $Check = new Folder($check);
         foreach ($allow as $path) {
             if (!Folder::isAbsolute($path) || Validation::url($path)) {
                 continue;
             }
             if ($Check->inPath($path)) {
                 return true;
             }
         }
     }
     return false;
 }
コード例 #10
0
 /**
  * @testdox url should return false to URLs without protocol
  */
 public function testInvalidUrlWithoutPrefix()
 {
     $value = 'spaghettiphp.org/download#download';
     $this->assertFalse(Validation::url($value));
 }
コード例 #11
0
ファイル: gravatar.php プロジェクト: Galvanio/Kinspir
 /**
  * Sanitize the options array
  *
  * @param array $options Array of options, keyed from default settings
  * @return array Clean options array
  * @access public
  */
 public function __cleanOptions($options)
 {
     if (!isset($options['size']) || empty($options['size']) || !is_numeric($options['size'])) {
         unset($options['size']);
     } else {
         $options['size'] = min(max($options['size'], 1), 512);
     }
     if (!$options['rating'] || !in_array(mb_strtolower($options['rating']), $this->__allowedRatings)) {
         unset($options['rating']);
     }
     if (!$options['default']) {
         unset($options['default']);
     } else {
         if (!in_array($options['default'], $this->__defaultIcons) && !Validation::url($options['default'])) {
             unset($options['default']);
         }
     }
     return $options;
 }
コード例 #12
0
ファイル: TransferValidation.php プロジェクト: razzman/media
 /**
  * Validates url
  *
  * @param string string to check
  * @param array options for allowing different url parts currently only scheme is supported
  */
 static function url($check, $options = array())
 {
     if (!is_string($check)) {
         return false;
     }
     if (isset($options['scheme'])) {
         if (!preg_match('/^(' . implode('|', (array) $options['scheme']) . ':)+/', $check)) {
             return false;
         }
     }
     return Validation::url($check);
 }
コード例 #13
0
ファイル: MyModel.php プロジェクト: ByMyHandsOnly/BMHO_Web
 /**
  * Checks if a url is valid AND accessable (returns false otherwise)
  *
  * @param array/string $data: full url(!) starting with http://...
  * @options array
  * - allowEmpty TRUE/FALSE (TRUE: if empty => return TRUE)
  * - required TRUE/FALSE (TRUE: overrides allowEmpty)
  * - autoComplete (default: TRUE)
  * - deep (default: TRUE)
  * @return bool Success
  */
 public function validateUrl($data, $options = [])
 {
     if (is_array($data)) {
         foreach ($data as $key => $url) {
             break;
         }
     } else {
         $url = $data;
     }
     if (empty($url)) {
         if (!empty($options['allowEmpty']) && empty($options['required'])) {
             return true;
         }
         return false;
     }
     if (!isset($options['autoComplete']) || $options['autoComplete'] !== false) {
         $url = $this->_autoCompleteUrl($url);
         if (isset($key)) {
             $this->data[$this->alias][$key] = $url;
         }
     }
     if (!isset($options['strict']) || $options['strict'] !== false) {
         $options['strict'] = true;
     }
     // validation
     if (!Validation::url($url, $options['strict']) && env('REMOTE_ADDR') && env('REMOTE_ADDR') !== '127.0.0.1') {
         return false;
     }
     // same domain?
     if (!empty($options['sameDomain']) && env('HTTP_HOST')) {
         $is = parse_url($url, PHP_URL_HOST);
         $expected = env('HTTP_HOST');
         if (mb_strtolower($is) !== mb_strtolower($expected)) {
             return false;
         }
     }
     if (isset($options['deep']) && $options['deep'] === false) {
         return true;
     }
     return $this->_validUrl($url);
 }
コード例 #14
0
 /**
  * testUrl method
  *
  * @access public
  * @return void
  */
 function testUrl()
 {
     $this->assertTrue(Validation::url('http://www.cakephp.org'));
     $this->assertTrue(Validation::url('http://cakephp.org'));
     $this->assertTrue(Validation::url('http://www.cakephp.org/somewhere#anchor'));
     $this->assertTrue(Validation::url('http://192.168.0.1'));
     $this->assertTrue(Validation::url('https://www.cakephp.org'));
     $this->assertTrue(Validation::url('https://cakephp.org'));
     $this->assertTrue(Validation::url('https://www.cakephp.org/somewhere#anchor'));
     $this->assertTrue(Validation::url('https://192.168.0.1'));
     $this->assertTrue(Validation::url('ftps://www.cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftps://cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftps://192.168.0.1/pub/cake'));
     $this->assertTrue(Validation::url('ftp://www.cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake'));
     $this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake'));
     $this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake'));
     $this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start'));
     $this->assertTrue(Validation::url('www.domain.tld'));
     $this->assertFalse(Validation::url('http://w_w.domain.co_m'));
     $this->assertFalse(Validation::url('http://www.domain.12com'));
     $this->assertFalse(Validation::url('http://www.domain.longttldnotallowed'));
     $this->assertFalse(Validation::url('http://www.-invaliddomain.tld'));
     $this->assertFalse(Validation::url('http://www.domain.-invalidtld'));
     $this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com'));
     $this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com'));
     $this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
 }
コード例 #15
0
 /**
  * @brief check for urls either /something/here or full
  *
  * this can be a url relative to the site /my/page or full like
  * http://site.com/my/page it can also be empty for times when the selects
  * are used to build the url
  *
  * @todo remove current($field) == '' || as 'notEmpty' works fine
  *
  * @param array $field the field being validated
  * @access public
  *
  * @return bool is it valid
  */
 public function validateUrlOrAbsolute($Model, $field)
 {
     return current($field) == '' || substr(current($field), 0, 1) == '/' || Validation::url(current($field), true);
 }
コード例 #16
0
ファイル: Upload.php プロジェクト: nicoeche/Finalus
 private function _import()
 {
     if (!Validation::url($this->targetUrl)) {
         $this->out(__('Target URL Invalid', true));
         $this->_stop();
     }
     if (isset($this->dirName)) {
         $dirName = realPath($this->dirName);
         if (is_file($dirName)) {
             if ($this->useDataPath) {
                 $this->out(__('Second argument is a file.', true));
                 $this->out(__('DataPath mode requires that to be a directory.', true));
                 $this->_stop();
             }
             if ($this->verbose) {
                 $this->out(__('Target file found.', true));
             }
             $this->currentFileName = $dirName;
             $output = $this->_makeContent($dirName);
             if ($output != null) {
                 if (!$this->_sendContent($output, $this->_createConnection($this->targetUrl))) {
                     $this->errors++;
                     $this->failedFiles .= basename($dirName) . "\n";
                 }
             } else {
                 $this->errors++;
             }
         } elseif (is_dir($dirName)) {
             if ($this->verbose) {
                 $this->out(sprintf(__('Found Target Directory: %s', true), $dirName));
             }
             $fileList = $this->_fileOrPathFilter($dirName);
             if (empty($fileList)) {
                 if ($this->useDataPath) {
                     $this->out('No .xml files found in directory.', true);
                 } else {
                     $this->out('No .pdf or .epub files found in directory.', true);
                 }
                 $this->_stop();
             } else {
                 if (substr($dirName, -1) != '/') {
                     $dirName = $dirName . '/';
                 }
                 for ($i = 0; $i < count($fileList); $i++) {
                     $this->currentFileName = $dirName . $fileList[$i];
                     $output = $this->_makeContent($dirName . $fileList[$i]);
                     if ($output != null) {
                         if (!$this->_sendContent($output, $this->_createConnection($this->targetUrl))) {
                             continue;
                         }
                     } else {
                         $this->errors++;
                     }
                 }
             }
         } else {
             $this->out(__('Second arg must be a file or directory to package', true));
             $this->_stop();
         }
     } else {
         $this->out(__('Please supply a valid Directory', true));
         $this->_stop();
     }
     $this->out(__('Finished!'), true);
     $this->out(sprintf(__('Successful packages created: %d', true), $this->success));
     $this->out(sprintf(__('Unsuccessful packages attempts: %d', true), $this->errors));
     if (count($this->errors) > 0) {
         $this->out(sprintf(__("Here are the files that failed to package: \n %s", true), $this->failedFiles));
     }
 }
コード例 #17
0
ファイル: MyModel.php プロジェクト: robksawyer/grabitdown
 /**
  * checks if a url is valid AND accessable (returns false otherwise)
  * @param array/string $data: full url(!) starting with http://...
  * @options
  * - allowEmpty TRUE/FALSE (TRUE: if empty => return TRUE)
  * - required TRUE/FALSE (TRUE: overrides allowEmpty)
  * - autoComplete (default: TRUE)
  * - deep (default: TRUE)
  * 2010-10-18 ms
  */
 public function validateUrl($data, $options = array())
 {
     //$arguments = func_get_args();
     if (is_array($data)) {
         $url = array_shift($data);
     } else {
         $url = $data;
     }
     if (empty($url)) {
         if (!empty($options['allowEmpty']) && empty($options['required'])) {
             return true;
         }
         return false;
     }
     if (!isset($options['autoComplete']) || $options['autoComplete'] !== false) {
         $url = $this->_autoCompleteUrl($url);
     }
     if (!isset($options['strict']) || $options['strict'] !== false) {
         $options['strict'] = true;
     }
     # validation
     if (!Validation::url($url, $options['strict']) && env('REMOTE_ADDR') != '127.0.0.1') {
         return false;
     }
     # same domain?
     if (!empty($options['sameDomain']) && !empty($_SERVER['HTTP_HOST'])) {
         $is = parse_url($url, PHP_URL_HOST);
         $expected = $_SERVER['HTTP_HOST'];
         if (mb_strtolower($is) !== mb_strtolower($expected)) {
             return false;
         }
     }
     if (isset($options['deep']) && $options['deep'] === false) {
         return true;
     }
     return $this->_validUrl($url);
 }
コード例 #18
0
ファイル: validation.test.php プロジェクト: kaz0636/openflp
 function testUrl()
 {
     $this->assertTrue(Validation::url('http://www.cakephp.org'));
     $this->assertTrue(Validation::url('http://cakephp.org'));
     $this->assertTrue(Validation::url('http://www.cakephp.org/somewhere#anchor'));
     $this->assertTrue(Validation::url('http://192.168.0.1'));
     $this->assertTrue(Validation::url('https://www.cakephp.org'));
     $this->assertTrue(Validation::url('https://cakephp.org'));
     $this->assertTrue(Validation::url('https://www.cakephp.org/somewhere#anchor'));
     $this->assertTrue(Validation::url('https://192.168.0.1'));
     $this->assertTrue(Validation::url('ftps://www.cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftps://cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftps://192.168.0.1/pub/cake'));
     $this->assertTrue(Validation::url('ftp://www.cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake'));
     $this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake'));
     $this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake'));
     $this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake'));
     $this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start'));
     $this->assertTrue(Validation::url('www.domain.tld'));
     $this->assertFalse(Validation::url('http://w_w.domain.co_m'));
     $this->assertFalse(Validation::url('http://www.domain.12com'));
     $this->assertFalse(Validation::url('http://www.domain.longttldnotallowed'));
     $this->assertFalse(Validation::url('http://www.-invaliddomain.tld'));
     $this->assertFalse(Validation::url('http://www.domain.-invalidtld'));
     $this->assertFalse(Validation::url('http://www.this-domain-is-just-too-long-and-inacceptable-by-icann-rules-the-maximum-limit-of-characters-is-57.com'));
     $this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
 }
コード例 #19
0
 public function testValidUrlWithoutPrefix()
 {
     $value = "spaghettiphp.org/download#download";
     $this->assertTrue(Validation::url($value));
 }