本文整理汇总了PHP中valid::url方法的典型用法代码示例。如果您正苦于以下问题:PHP valid::url方法的具体用法?PHP valid::url怎么用?PHP valid::url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类valid
的用法示例。
在下文中一共展示了valid::url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 Kohana_User_Exception('Feed Error', '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 valid::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: url_test
public function url_test()
{
$this->assert_true(valid::url("http://foo.bar.com"));
$this->assert_true(valid::url("https://foo.bar.com"));
$this->assert_false(valid::url("mailto://bar"));
$this->assert_false(valid::url("ftp://bar"));
}
示例3: convert_uploaded_to_abs
/**
* Converts a file location to an absolute URL or returns the absolute URL if absolute URL
* is passed. This function is for uploaded files since it uses the configured upload dir
*
* @param string file location or full URL
* @return string
*/
public static function convert_uploaded_to_abs($file)
{
if (valid::url($file) == true) {
return $file;
}
return url::base() . Kohana::config('upload.relative_directory') . '/' . $file;
}
示例4: request
/**
* Method that allows sending any kind of HTTP request to remote url
*
* @param string $method
* @param string $url
* @param array $headers
* @param array $data
* @return HTTP_Response
*/
public static function request($method, $url, $headers = array(), $data = array())
{
$valid_methods = array('POST', 'GET', 'PUT', 'DELETE');
$method = utf8::strtoupper($method);
if (!valid::url($url, 'http')) {
return FALSE;
}
if (!in_array($method, $valid_methods)) {
return FALSE;
}
// Get the hostname and path
$url = parse_url($url);
if (empty($url['path'])) {
// Request the root document
$url['path'] = '/';
}
// Open a remote connection
$remote = fsockopen($url['host'], 80, $errno, $errstr, 5);
if (!is_resource($remote)) {
return FALSE;
}
// Set CRLF
$CRLF = "\r\n";
$path = $url['path'];
if ($method == 'GET' and !empty($url['query'])) {
$path .= '?' . $url['query'];
}
$headers_default = array('Host' => $url['host'], 'Connection' => 'close', 'User-Agent' => 'Ushahidi Scheduler (+http://ushahidi.com/)');
$body_content = '';
if ($method != 'GET') {
$headers_default['Content-Type'] = 'application/x-www-form-urlencoded';
if (count($data) > 0) {
$body_content = http_build_query($data);
}
$headers_default['Content-Length'] = strlen($body_content);
}
$headers = array_merge($headers_default, $headers);
// Send request
$request = $method . ' ' . $path . ' HTTP/1.0' . $CRLF;
foreach ($headers as $key => $value) {
$request .= $key . ': ' . $value . $CRLF;
}
// Send one more CRLF to terminate the headers
$request .= $CRLF;
if ($body_content) {
$request .= $body_content . $CRLF;
}
fwrite($remote, $request);
$response = '';
while (!feof($remote)) {
// Get 1K from buffer
$response .= fread($remote, 1024);
}
// Close the connection
fclose($remote);
return new HTTP_Response($response, $method);
}
示例5: pull
/**
* Quickly pulls data from a URI. This only works with GET requests but
* can handle HTTP Basic Auth
*
* @param string uri the url to pull from
* @param string username the username for the service [Optional]
* @param string password the password for the user [Optional]
* @return string
* @throws Kohana_User_Exception
* @author Sam Clark
* @access public
* @static
**/
public static function pull($uri, $username = FALSE, $password = FALSE)
{
if (!valid::url($uri)) {
throw new Kohana_User_Exception('Curl::pull()', 'The URL : ' . $uri . ' is not a valid resource');
}
// Initiate a curl session based on the URL supplied
$curl = Curl::factory(array(CURLOPT_POST => FALSE), $uri);
// If a username/password is supplied
if ($username and $password) {
// Add the HTTP Basic Auth headers
$curl->setopt_array(array(CURLOPT_USERPWD => $username . ':' . $password));
}
// Launch the request and return the result
return $curl->exec()->result();
}
示例6: layer_url_file_check
/**
* Performs validation checks on the layer url and layer file - Checks that at least
* one of them has been specified using the applicable validation rules
*
* @param Validation $array Validation object containing the field names to be checked
*/
public function layer_url_file_check(Validation $array)
{
// Ensure at least a layer URL or layer file has been specified
if (empty($array->layer_url) and empty($array->layer_file) and empty($array->layer_file_old)) {
$array->add_error('layer_url', 'atleast');
}
// Add validation rule for the layer URL if specified
if (!empty($array->layer_url) and (empty($array->layer_file) or empty($array->layer_file_old))) {
if (!valid::url($array->layer_url)) {
$array->add_error('layer_url', 'url');
}
}
// Check if both the layer URL and the layer file have been specified
if (!empty($array->layer_url) and (!empty($array->layer_file_old) or !empty($array->layer_file))) {
$array->add_error('layer_url', 'both');
}
}
示例7: status
public static function status($url)
{
if (!valid::url($url, 'http')) {
return FALSE;
}
// Get the hostname and path
$url = parse_url($url);
if (empty($url['path'])) {
// Request the root document
$url['path'] = '/';
}
// Open a remote connection
if (isset($_SERVER["SERVER_PORT"])) {
$server_port = $_SERVER["SERVER_PORT"];
} else {
$server_port = '80';
}
$remote = fsockopen($url['host'], $server_port, $errno, $errstr, 5);
if (!is_resource($remote)) {
return FALSE;
}
// Set CRLF
$CRLF = "\r\n";
// Send request
fwrite($remote, 'HEAD ' . $url['path'] . ' HTTP/1.0' . $CRLF);
fwrite($remote, 'Host: ' . $url['host'] . $CRLF);
fwrite($remote, 'Connection: close' . $CRLF);
fwrite($remote, 'User-Agent: Kohana Framework (+http://kohanaphp.com/)' . $CRLF);
// Send one more CRLF to terminate the headers
fwrite($remote, $CRLF);
while (!feof($remote)) {
// Get the line
$line = trim(fgets($remote, 512));
if ($line !== '' and preg_match('#^HTTP/1\\.[01] (\\d{3})#', $line, $matches)) {
// Response code found
$response = (int) $matches[1];
break;
}
}
// Close the connection
fclose($remote);
return isset($response) ? $response : FALSE;
}
示例8: action_pay
/**
* generates the request to pay at nitpay
*/
public function action_pay()
{
$this->auto_render = FALSE;
$id_order = $this->request->param('id');
//retrieve info for the item in DB
$order = new Model_Order();
$order = $order->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
if ($order->loaded()) {
//options send to create the invoice
$options = array('buyerName' => $order->user->name, 'buyerEmail' => $order->user->email, 'currency' => $order->currency, 'redirectURL' => Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
$invoice = Bitpay::bpCreateInvoice($order->id_order, $order->amount, '', $options);
if (!isset($invoice['error']) and valid::url($invoice['url'])) {
$this->redirect($invoice['url']);
} else {
Alert::set(Alert::INFO, __('Could not create bitpay invoice'));
$this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
}
} else {
Alert::set(Alert::INFO, __('Product could not be loaded'));
$this->redirect(Route::url('default'));
}
}
示例9: 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)
{
// Make limit an integer
$limit = (int) $limit;
// Disable error reporting while opening the feed
$ER = error_reporting(0);
// Allow loading by filename/url or raw XML string
if (valid::url($feed)) {
$feed = remote::get($feed, 45);
$feed = $feed['content'];
} elseif (is_file($feed)) {
$feed = file_get_contents($feed);
}
// Double check we have something to work with
if (empty($feed)) {
return FALSE;
}
// Load the feed
$feed = simplexml_load_string($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
// Restore error reporting
error_reporting($ER);
// Feed could not be loaded
if ($feed === NO) {
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;
}
示例10: delete_photo
/**
* Delete Photo
* @param int $id The unique id of the photo to be deleted
*/
public static function delete_photo($id)
{
$photo = ORM::factory('media', $id);
$photo_large = $photo->media_link;
$photo_medium = $photo->media_medium;
$photo_thumb = $photo->media_thumb;
if (file_exists(Kohana::config('upload.directory', TRUE) . $photo_large)) {
unlink(Kohana::config('upload.directory', TRUE) . $photo_large);
} elseif (Kohana::config("cdn.cdn_store_dynamic_content") and valid::url($photo_large)) {
cdn::delete($photo_large);
}
if (file_exists(Kohana::config('upload.directory', TRUE) . $photo_medium)) {
unlink(Kohana::config('upload.directory', TRUE) . $photo_medium);
} elseif (Kohana::config("cdn.cdn_store_dynamic_content") and valid::url($photo_medium)) {
cdn::delete($photo_medium);
}
if (file_exists(Kohana::config('upload.directory', TRUE) . $photo_thumb)) {
unlink(Kohana::config('upload.directory', TRUE) . $photo_thumb);
} elseif (Kohana::config("cdn.cdn_store_dynamic_content") and valid::url($photo_thumb)) {
cdn::delete($photo_thumb);
}
// Finally Remove from DB
$photo->delete();
}
示例11: set_default
/**
* Set default avatar type or url
*
* @param string $default
* @return Gravatar
*/
public function set_default($default)
{
$default = (string) $default;
if (in_array($default, array(self::DEFAULT_IDENTICON, self::DEFAULT_MONSTERID, self::DEFAULT_WAVATAR))) {
$this->default = $default;
} else {
if (valid::url($default)) {
$this->default = urlencode($default);
}
}
return $this;
}
示例12: contact_is_valid
/**
* Check if a given string is a valid url or email.
*
* @param String $str
* @return Boolean
*/
public function contact_is_valid($str)
{
if (valid::email($str) || valid::url($str)) {
return true;
}
return false;
}
示例13: _get_incidents
//.........这里部分代码省略.........
$comment_items[$incident_comment->incident_id][$i]['comment_date'] = $incident_comment->comment_date;
$i++;
}
// Free temporary variables from memory
unset($incident_comments);
}
//
// STEP 5.
// Return XML
//
foreach ($items as $item) {
// Build xml file
$xml->startElement('incident');
$xml->writeElement('id', $item->incident_id);
$xml->writeElement('title', $item->incident_title);
$xml->writeElement('description', $item->incident_description);
$xml->writeElement('date', $item->incident_date);
$xml->writeElement('mode', $item->incident_mode);
$xml->writeElement('active', $item->incident_active);
$xml->writeElement('verified', $item->incident_verified);
$xml->startElement('location');
$xml->writeElement('id', $item->location_id);
$xml->writeElement('name', $item->location_name);
$xml->writeElement('latitude', $item->latitude);
$xml->writeElement('longitude', $item->longitude);
$xml->endElement();
$xml->startElement('categories');
$json_report_categories[$item->incident_id] = array();
// Check if the incident id exists
if (isset($category_items[$item->incident_id])) {
foreach ($category_items[$item->incident_id] as $category_item) {
if ($this->response_type == 'json') {
$category = array("id" => $category_item['cid'], "title" => $category_item['categorytitle']);
$category["icon"] = url::base() . Kohana::config('upload.relative_directory') . '/' . $category_item['categorythumb'];
if ($category_item['decayimagethumb']) {
if ($category_item['decayimagethumb'] == $this->default_decayimage_thumb) {
$category['decayimage'] = url::site() . '/plugins/decayimage/images/' . $category_item['decayimagethumb'];
} else {
$category['decayimage'] = url::base() . Kohana::config('upload.relative_directory') . '/' . $category_item['decayimagethumb'];
}
}
$json_report_categories[$item->incident_id][] = array("category" => $category);
} else {
$xml->startElement('category');
$xml->writeElement('id', $category_item['cid']);
$xml->writeElement('title', $category_item['categorytitle']);
$xml->endElement();
}
}
}
// End categories
$xml->endElement();
$xml->startElement('comments');
$json_report_comments[$item->incident_id] = array();
// Check if the incident id exists
if (isset($comment_items[$item->incident_id])) {
foreach ($comment_items[$item->incident_id] as $comment_item) {
if ($this->response_type == 'json') {
$json_report_comments[$item->incident_id][] = array("comment" => $comment_item);
} else {
$xml->startElement('comment');
$xml->writeElement('id', $comment_item['id']);
$xml->writeElement('comment_author', $comment_item['comment_author']);
$xml->writeElement('comment_email', $comment_item['comment_email']);
$xml->writeElement('comment_description', $comment_item['comment_description']);
$xml->writeElement('comment_rating', $comment_item['comment_rating']);
示例14: add_data_to_incident
private function add_data_to_incident($incident_array, $incident)
{
/*static $incident_type;
if (!$incident_type)
{
$incident_type = ORM::factory('service')->select_list('id','service_name');
}
if ($incident_array['incident_id'])
{
$incident_array['incident_id'] = array($incident_array['incident_id'] => array(
'api_url' => url::site(rest_controller::$api_base_url.'/incidents/'.$incident_array['incident_id']),
'url' => url::site('/reports/view/'.$incident_array['incident_id'])
));
}*/
// Add categories
$incident_array['category'] = array();
foreach ($incident->category as $category) {
// Only include visible categories unless we're an admin
if ($this->admin or $category->category_visible) {
$category_data = $category->as_array();
$category_data['category_image'] = $category_data['category_image'] ? url::convert_uploaded_to_abs($category_data['category_image']) : $category_data['category_image'];
$category_data['category_image_thumb'] = $category_data['category_image_thumb'] ? url::convert_uploaded_to_abs($category_data['category_image_thumb']) : $category_data['category_image_thumb'];
$category_data['api_url'] = url::site(rest_controller::$api_base_url . '/categories/' . $category_data['id']);
$incident_array['category'][] = $category_data;
}
}
// Add location
// @todo filter on location_visible
$incident_array['location'] = $incident->location->as_array();
// format date in ISO standard
$incident_array['location']['location_date'] = $incident_array['location']['location_date'] != null ? date('c', strtotime($incident_array['location']['location_date'])) : null;
// Add incident_person
if ($this->admin) {
$incident_array['incident_person'] = $incident->incident_person->as_array();
//@todo sanitize
// format date in ISO standard
$incident_array['incident_person']['person_date'] = $incident_array['incident_person']['person_date'] != null ? date('c', strtotime($incident_array['incident_person']['person_date'])) : null;
} else {
// @todo check what should be public
$incident_array['incident_person'] = array('id' => $incident->incident_person->id, 'person_first' => $incident->incident_person->person_first, 'person_last' => $incident->incident_person->person_last);
}
// Add user?
if ($this->admin) {
$incident_array['user'] = $incident->user->as_array();
//@todo sanitize
unset($incident_array['user']['password']);
unset($incident_array['user']['code']);
// format date in ISO standard
$incident_array['user']['updated'] = $incident_array['user']['updated'] != null ? date('c', strtotime($incident_array['user']['updated'])) : null;
} else {
// @todo check what should be public
$incident_array['user'] = array('id' => $incident->user->id, 'name' => $incident->user->name, 'username' => $incident->user->username);
}
// Add media?
$incident_array['media'] = array();
foreach ($incident->media as $media) {
// Only include visible categories unless we're an admin
if ($this->admin or $media->media_active) {
$media_data = $media->as_array();
if ($media->media_link and !valid::url($media->media_link)) {
$media_data['media_link'] = url::convert_uploaded_to_abs($media_data['media_link']);
$media_data['media_medium'] = url::convert_uploaded_to_abs($media_data['media_medium']);
$media_data['media_thumb'] = url::convert_uploaded_to_abs($media_data['media_thumb']);
}
// format date in ISO standard
$media_data['media_date'] = $media_data['media_date'] != null ? date('c', strtotime($media_data['media_date'])) : null;
$incident_array['media'][] = $media_data;
}
}
// Initialize custom field array - only supporting default form
$incident_array['custom_field'] = customforms::get_custom_form_fields($incident_array['id'], 1, true);
$incident_array['api_url'] = url::site(rest_controller::$api_base_url . '/incidents/' . $incident_array['id']);
$incident_array['updated_at'] = $incident->incident_datemodify == null ? $incident->incident_dateadd : $incident->incident_datemodify;
$incident_array['updated_at'] = date_create($incident_array['updated_at'])->format(DateTime::W3C);
// format all dates in ISO standard
$incident_array['incident_datemodify'] = $incident->incident_datemodify != null ? date_create($incident_array['incident_datemodify'])->format(DateTime::W3C) : null;
$incident_array['incident_dateadd'] = $incident->incident_dateadd != null ? date_create($incident_array['incident_dateadd'])->format(DateTime::W3C) : null;
$incident_array['incident_date'] = $incident->incident_date != null ? date_create($incident_array['incident_date'])->format(DateTime::W3C) : null;
return $incident_array;
}
示例15: validate
/**
* Validation of form fields
*
* @param array $post Values to be validated
*/
public static function validate(array &$post)
{
// Exception handling
if (!isset($post) or !is_array($post)) {
return FALSE;
}
// Create validation object
$post = Validation::factory($post)->pre_filter('trim', TRUE)->add_rules('incident_title', 'required', 'length[3,200]')->add_rules('incident_description', 'required')->add_rules('incident_date', 'required', 'date_mmddyyyy')->add_rules('incident_hour', 'required', 'between[1,12]')->add_rules('incident_minute', 'required', 'between[0,59]')->add_rules('incident_ampm', 'required');
if (isset($post->incident_ampm) and $post->incident_ampm != "am" and $post->incident_ampm != "pm") {
$post->add_error('incident_ampm', 'values');
}
// Validate for maximum and minimum latitude values
//$post->add_rules('latitude','required','between[-90,90]');
// Validate for maximum and minimum longitude values
//$post->add_rules('longitude','required','between[-180,180]');
$post->add_rules('location_name', 'required', 'length[3,200]');
//XXX: Hack to validate for no checkboxes checked
if (!isset($post->incident_category)) {
$post->incident_category = "";
$post->add_error('incident_category', 'required');
} else {
$post->add_rules('incident_category.*', 'required', 'numeric');
}
// Validate only the fields that are filled in
if (!empty($post->incident_news)) {
foreach ($post->incident_news as $key => $url) {
if (!empty($url) and !valid::url($url)) {
$post->add_error('incident_news', 'url');
}
}
}
// Validate only the fields that are filled in
if (!empty($post->incident_video)) {
foreach ($post->incident_video as $key => $url) {
if (!empty($url) and !valid::url($url)) {
$post->add_error('incident_video', 'url');
}
}
}
// If deployment is a single country deployment, check that the location mapped is in the default country
if (!Kohana::config('settings.multi_country') and isset($post->country_name)) {
$country = Country_Model::get_country_by_name($post->country_name);
if ($country and $country->id != Kohana::config('settings.default_country')) {
$post->add_error('country_name', 'single_country', array(ORM::factory('country', Kohana::config('settings.default_country'))->country));
}
}
// Validate photo uploads
$max_upload_size = Kohana::config('settings.max_upload_size');
$post->add_rules('incident_photo', 'upload::valid', 'upload::type[gif,jpg,png,jpeg]', "upload::size[" . $max_upload_size . "M]");
// Validate Personal Information
if (!empty($post->person_first)) {
$post->add_rules('person_first', 'length[2,100]');
} else {
$post->person_first = '';
}
if (!empty($post->person_last)) {
$post->add_rules('person_last', 'length[2,100]');
} else {
$post->person_last = '';
}
if (!empty($post->person_email)) {
$post->add_rules('person_email', 'email', 'length[3,100]');
} else {
$post->person_email = '';
}
$post->add_rules('location_id', 'numeric');
$post->add_rules('incident_active', 'between[0,1]');
$post->add_rules('incident_verified', 'between[0,1]');
$post->add_rules('incident_zoom', 'numeric');
// Custom form fields validation
customforms::validate_custom_form_fields($post);
//> END custom form fields validation
// Return
return $post->validate();
}