本文整理汇总了PHP中Validate::url方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::url方法的具体用法?PHP Validate::url怎么用?PHP Validate::url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validate
的用法示例。
在下文中一共展示了Validate::url方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Parses a remote feed into an array.
*
* @param string remote feed URL
* @param integer item limit to fetch
* @return array
*/
public static function parse($feed, $limit = 0)
{
// Check if SimpleXML is installed
if (!function_exists('simplexml_load_file')) {
throw new Exception('SimpleXML must be installed!');
}
// Make limit an integer
$limit = (int) $limit;
// Disable error reporting while opening the feed
$ER = error_reporting(0);
// Allow loading by filename or raw XML string
$load = (is_file($feed) or Validate::url($feed)) ? 'simplexml_load_file' : 'simplexml_load_string';
// Load the feed
$feed = $load($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
// Restore error reporting
error_reporting($ER);
// Feed could not be loaded
if ($feed === FALSE) {
return array();
}
// Detect the feed type. RSS 1.0/2.0 and Atom 1.0 are supported.
$feed = isset($feed->channel) ? $feed->xpath('//item') : $feed->entry;
$i = 0;
$items = array();
foreach ($feed as $item) {
if ($limit > 0 and $i++ === $limit) {
break;
}
$items[] = (array) $item;
}
return $items;
}
示例2: set_loc
/**
* URL of the page. This URL must begin with the protocol (such as http) and end
* with a trailing slash, if your web server requires it. This value must be
* less than 2,048 characters.
* @see http://www.sitemaps.org/protocol.php
* @param string $location
*/
public function set_loc($location)
{
if (!Validate::max_length($location, 2048)) {
throw new LengthException('The location was too long, maximum length of 2,048 characters.');
}
$location = Sitemap::encode($location);
if (!Validate::url($location)) {
throw new InvalidArgumentException('The location was not a valid URL');
}
$this->attributes['loc'] = $location;
return $this;
}
示例3: __construct
/**
* Constructor is private, this is a helper "factory" class
* You can pass a URL to parse or HTML string, e.g.
*
* $html = HTML_Parser::factory($html_document);
*
* @param mixed html
*/
protected function __construct($html = NULL)
{
require_once Kohana::find_file('vendor', 'simple_html_dom');
$this->_dom = new simple_html_dom();
if ($html !== NULL) {
if (Validate::url($html)) {
$this->_dom->load_file($html);
} else {
$this->_dom->load($html);
}
}
}
示例4: test_url
/**
* Tests Validate::url()
*
* @test
* @group kohana.validation.helpers
* @dataProvider provider_url
* @param string $url The url to test
* @param boolean $expected Is it valid?
*/
public function test_url($url, $expected)
{
$this->assertSame(
$expected,
Validate::url($url)
);
}
示例5: async
/**
* 异步(非阻塞)运行一个路由
* $curl 强制使用curl方式,但此方式至少阻塞1秒
* $lose 如果可以,断开客户端连接,脚本后台运行,以后输出不能发送到浏览器
*/
public static function async($router, $curl = false, $lose = false)
{
if (is_array($router)) {
isset($GLOBALS['APP']['CLI']) && die('Async In CLI Mode Need Whole Url ');
$url = 'http://' . Request::server('HTTP_HOST') . '/' . implode('/', $router);
} else {
$url = Validate::url($router) ? $router : Error(500, 'Async needs a url or an array ');
}
if ($curl) {
if (function_exists('fastcgi_finish_request') && $lose) {
fastcgi_finish_request();
return file_get_contents($url);
}
$ch = curl_init();
$curl_opt = array(CURLOPT_URL => $url, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_TIMEOUT_MS => 1, CURLOPT_NOSIGNAL => 1, CURLOPT_HEADER => 0, CURLOPT_NOBODY => 1, CURLOPT_RETURNTRANSFER => 1);
curl_setopt_array($ch, $curl_opt);
curl_exec($ch);
curl_close($ch);
return true;
} else {
if (function_exists('fastcgi_finish_request') && $lose) {
fastcgi_finish_request();
return file_get_contents($url);
} else {
if (function_exists('fsockopen') || function_exists('stream_socket_client')) {
$parts = parse_url($url);
$parts['port'] = isset($parts['port']) ? $parts['port'] : 80;
$parts['query'] = isset($parts['query']) ? $parts['path'] . '?' . $parts['query'] : $parts['path'];
if (function_exists('stream_socket_client')) {
$fp = stream_socket_client($parts['host'] . ':' . $parts['port'], $errno, $errstr, 3);
} else {
$fp = fsockopen($parts['host'], $parts['port'], $errno, $errstr, 3);
}
$fp || Error($errno, $errstr);
stream_set_blocking($fp, 0);
$out = 'GET ' . $parts['query'] . " HTTP/1.1\r\nHost: " . $parts['host'] . "\r\nConnection: Close\r\n\r\n";
fwrite($fp, $out);
ob_flush();
flush();
fclose($fp);
return true;
}
}
return false;
}
}
示例6: save_url
/**
* Save a image URL to the registered account.
*
* @param string $url
* @param int $rating [Optional]
* @return string|boolean
* @throws Kohana_Gravatar_Xmlrpc_Exception
*/
public function save_url($url, $rating = NULL)
{
// If the URL supplied is not valid
if (!Validate::url($url)) {
// Throw an exception
throw new Kohana_Gravatar_Xmlrpc_Exception(__METHOD__ . ' invalid URL supplied : :url', array(':url' => $url));
}
// If no rating has been applied, use general
if ($rating === NULL) {
$rating = Gravatar_Xmlrpc::G;
}
// Save the image to Gravatar
return $this->_xmlrpc_request('grav.saveData', array('url' => $url, 'rating' => $rating));
}
示例7: elseif
*
* @package Anqh
* @author Antti Qvickström
* @copyright (c) 2010 Antti Qvickström
* @license http://www.opensource.org/licenses/mit-license.php MIT license
*/
?>
<?php
if ($user->title) {
echo HTML::chars(trim($user->title)) . '<br />';
}
?>
<?php
if ($user->default_image->id) {
?>
<?php
echo HTML::image($user->default_image->get_url('thumbnail')) . '<br />';
} elseif (Validate::url($user->picture)) {
?>
<?php
echo HTML::image($user->picture, array('width' => 160)) . '<br />';
}
?>
<?php
echo __('Last login: :login', array(':login' => HTML::time(Date::fuzzy_span($user->last_login), $user->last_login)));
?>
<br />
示例8: _get_mod_image
/**
* Get image mod
*
* @param Model_User $user
* @return View_Module
*/
protected function _get_mod_image(Model_User $user)
{
if ($user->default_image->id) {
$image = $user->default_image;
} else {
if (Validate::url($user->picture)) {
$image = $user->picture;
} else {
$image = null;
}
}
return View_Module::factory('generic/side_image', array('mod_actions2' => Permission::has($user, Model_User::PERMISSION_UPDATE, self::$user) ? array(array('link' => URL::user($user, 'image') . '?token=' . Security::csrf() . '&delete', 'text' => __('Delete'), 'class' => 'image-delete disabled'), array('link' => URL::user($user, 'image') . '?token=' . Security::csrf() . '&default', 'text' => __('Set as default'), 'class' => 'image-default disabled'), array('link' => URL::user($user, 'image'), 'text' => __('Add image'), 'class' => 'image-add ajaxify')) : null, 'image' => $image));
}
示例9: str_replace
$randSalt = Security_Hash::random(82, 80);
$randSalt = str_replace('"', '', $randSalt);
$randSalt = str_replace('$', '', $randSalt);
// Prepare POST Values: make sure that every $_POST value has a default value provided.
$_POST['site-salt'] = isset($_POST['site-salt']) ? Sanitize::text($_POST['site-salt']) : $randSalt;
$_POST['site-handle'] = isset($_POST['site-handle']) ? Sanitize::variable($_POST['site-handle']) : "";
$_POST['site-url'] = isset($_POST['site-url']) ? Sanitize::variable($_POST['site-url'], ":/.") : $_SERVER['SERVER_NAME'];
$_POST['site-name'] = isset($_POST['site-name']) ? Sanitize::text($_POST['site-name']) : "";
$_POST['site-domain'] = isset($_POST['site-domain']) ? Sanitize::variable($_POST['site-domain'], ":/.") : "";
$_POST['site-database-name'] = isset($_POST['site-database-name']) ? Sanitize::variable($_POST['site-database-name']) : "";
// Run the Form
if (Form::submitted("install-app-config")) {
// Check if all of the input you sent is valid:
Validate::variable("Site Handle", $_POST['site-handle'], 3, 22);
Validate::safeword("Site Name", $_POST['site-name'], 3, 42);
Validate::url("URL", $_POST['site-url'], 3, 64);
// Parse the URL input
$siteURL = URL::parse($_POST['site-url']);
if (Validate::pass()) {
// Make sure the site handle isn't taken
$packet = array("site-handle" => $_POST['site-handle'], "uni-handle" => $ownerHandle, "site-name" => $_POST['site-name'], "site-url" => $siteURL['full']);
// Call UniFaction's API to register a site with the system
// If the site fails to register, it will provide an alert explaining why
$response = API_Connect::call(URL::unifaction_com() . "/api/RegisterSiteHandle", $packet);
if ($response) {
// If the database users are provided and there is a database name that we can create, build config settings
$siteTheme = "default";
$siteThemeStyle = "default";
$buildApp = '<?php
// Site-Wide Salt