本文整理汇总了PHP中Validate::uri方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::uri方法的具体用法?PHP Validate::uri怎么用?PHP Validate::uri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validate
的用法示例。
在下文中一共展示了Validate::uri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare
/**
* For initializing members of the class.
*
* @param array $args misc. arguments
*
* @return boolean true
*/
function prepare($args)
{
parent::prepare($args);
if (!$this->isPost()) {
throw new ClientException(_('POST only'), 405);
}
$this->checkSessionToken();
$this->url = $this->trimmed('url');
if (empty($this->url)) {
throw new ClientException(_('URL is required.'), 400);
}
if (!Validate::uri($this->url, array('allowed_schemes' => array('http', 'https')))) {
throw new ClientException(_('Invalid URL.'), 400);
}
$f = File::staticGet('url', $this->url);
if (empty($url)) {
$f = File::processNew($this->url);
}
// How about now?
if (!empty($f)) {
$this->oembed = File_oembed::staticGet('file_id', $f->id);
if (!empty($this->oembed)) {
$this->title = $this->oembed->title;
}
$this->thumbnail = File_thumbnail::staticGet('file_id', $f->id);
}
return true;
}
示例2: getNotice
/**
* Look up a notice from an argument, by poster's name to get last post
* or notice_id prefixed with #.
*
* @return Notice
* @throws CommandException
*/
function getNotice($arg)
{
$notice = null;
if (Event::handle('StartCommandGetNotice', array($this, $arg, &$notice))) {
if (substr($this->other, 0, 1) == '#') {
// A specific notice_id #123
$notice = Notice::staticGet(substr($arg, 1));
if (!$notice) {
throw new CommandException(_('Notice with that id does not exist'));
}
}
if (Validate::uri($this->other)) {
// A specific notice by URI lookup
$notice = Notice::staticGet('uri', $arg);
}
if (!$notice) {
// Local or remote profile name to get their last notice.
// May throw an exception and report 'no such user'
$recipient = $this->getProfile($arg);
$notice = $recipient->getCurrentNotice();
if (!$notice) {
throw new CommandException(_('User has no last notice'));
}
}
}
Event::handle('EndCommandGetNotice', array($this, $arg, &$notice));
if (!$notice) {
throw new CommandException(_('Notice with that id does not exist'));
}
return $notice;
}
示例3: authenticate
/**
* Eventually we should use OAuth here, since this is mainly
* for API authentication.
*
* For now let's just verify that they passed in a valid
* OpenID. The API layer verifies a valid API key later anyway,
* so we don't duplicate that effort here.
*
* @param string $name the user name
* @param string $password the password for the above user name
*
* @return mixed false if no auth
* array( contactID, ufID, unique string ) if success
* @access public
* @static
*/
static function authenticate($name, $password)
{
// check that we got a valid URL
$options = array('domain_check' => false, 'allowed_schemes' => array('http', 'https'));
require_once 'Validate.php';
$validUrl = Validate::uri($name, $options);
if (!$validUrl) {
return false;
}
// we got a valid URL, see if it's allowed to login
require_once 'CRM/Core/BAO/OpenID.php';
$allowLogin = CRM_Core_BAO_OpenID::isAllowedToLogin($name);
if (!$allowLogin) {
return false;
}
// see if the password matches the API key
require_once 'CRM/Contact/BAO/Contact.php';
$dao = CRM_Contact_BAO_Contact::matchContactOnOpenId($name);
require_once 'CRM/Core/DAO.php';
$api_key = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $dao->contact_id, 'api_key');
if ($api_key != $password) {
return false;
}
// everything looks good, setup the session and return
require_once 'CRM/Standalone/User.php';
$user = new CRM_Standalone_User($name);
require_once 'CRM/Core/BAO/UFMatch.php';
CRM_Core_BAO_UFMatch::synchronize($user, false, 'Standalone', 'Individual');
require_once 'CRM/Core/Session.php';
$session = CRM_Core_Session::singleton();
$returnArray = array($session->get('userID'), $session->get('ufID'), mt_rand());
return $returnArray;
}
示例4: __construct
/**
* Constructor for OMB_Profile
*
* Initializes the OMB_Profile object with an identifier uri.
*
* @param string $identifier_uri The profile URI as defined by the OMB. A unique
* and unchanging identifier for a profile.
*
* @access public
*/
public function __construct($identifier_uri)
{
if (!Validate::uri($identifier_uri)) {
throw new OMB_InvalidParameterException($identifier_uri, 'profile', 'omb_listenee or omb_listener');
}
$this->identifier_uri = $identifier_uri;
$this->param_array = false;
}
示例5: testCreateThenExpand
/**
* Test creating and then expanding a URL
*
* @param string $service The service to test
*
* @dataProvider allServices
* @return void
*/
public function testCreateThenExpand($service)
{
$api = Services_ShortURL::factory($service);
// Create a short URL and do some sanity checking
$small = $api->shorten($this->testURL);
$this->assertType('string', $small);
$this->assertTrue(Validate::uri($small), 'Invalid URL: ' . $small);
// Expand the short URL and do some sanity checking
$big = $api->expand($small);
$this->assertEquals($this->testURL, $big);
}
示例6: __construct
/**
* Constructor for OMB_Notice
*
* Initializes the OMB_Notice object with author, uri and content.
* These parameters are mandatory for postNotice.
*
* @param object $author An OMB_Profile object representing the author of the
* notice.
* @param string $uri The notice URI as defined by the OMB. A unique and
* unchanging identifier for a notice.
* @param string $content The content of the notice. 140 chars recommended,
* but there is no limit.
*
* @access public
*/
public function __construct($author, $uri, $content)
{
$this->content = $content;
if (is_null($author)) {
throw new OMB_InvalidParameterException('', 'notice', 'omb_listenee');
}
$this->author = $author;
if (!Validate::uri($uri)) {
throw new OMB_InvalidParameterException($uri, 'notice', 'omb_notice');
}
$this->uri = $uri;
$this->param_array = false;
}
示例7: save_notice
function save_notice(&$req, &$consumer, &$token)
{
$version = $req->get_parameter('omb_version');
if ($version != OMB_VERSION_01) {
$this->clientError(_('Unsupported OMB version'), 400);
return false;
}
# First, check to see
$listenee = $req->get_parameter('omb_listenee');
$remote_profile = Remote_profile::staticGet('uri', $listenee);
if (!$remote_profile) {
$this->clientError(_('Profile unknown'), 403);
return false;
}
$sub = Subscription::staticGet('token', $token->key);
if (!$sub) {
$this->clientError(_('No such subscription'), 403);
return false;
}
$content = $req->get_parameter('omb_notice_content');
$content_shortened = common_shorten_links($content);
if (mb_strlen($content_shortened) > 140) {
$this->clientError(_('Invalid notice content'), 400);
return false;
}
$notice_uri = $req->get_parameter('omb_notice');
if (!Validate::uri($notice_uri) && !common_valid_tag($notice_uri)) {
$this->clientError(_('Invalid notice uri'), 400);
return false;
}
$notice_url = $req->get_parameter('omb_notice_url');
if ($notice_url && !common_valid_http_url($notice_url)) {
$this->clientError(_('Invalid notice url'), 400);
return false;
}
$notice = Notice::staticGet('uri', $notice_uri);
if (!$notice) {
$notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, null, $notice_uri);
if (is_string($notice)) {
common_server_serror($notice, 500);
return false;
}
common_broadcast_notice($notice, true);
}
return true;
}
示例8: checkInput
protected function checkInput()
{
if (!$this->request->getParam('URL') && (!isset($_FILES['File']) || $_FILES['File']['tmp_name'] == '')) {
throw new binarypool_exception(109, 400, "No file uploaded.");
}
$type = $this->request->getParam('Type');
if (!$type) {
throw new binarypool_exception(110, 400, "Type param not given.");
}
if (!in_array($type, self::$UPLOAD_TYPES)) {
throw new binarypool_exception(111, 400, "Invalid upload type: " . $this->request->getParam('Type'));
}
$url = $this->request->getParam('URL');
if ($url) {
if (!Validate::uri($url, array('allowed_schemes' => array('http', 'https')))) {
throw new binarypool_exception(120, 400, "Invalid URL for download: " . $url);
}
}
}
示例9: trySave
function trySave()
{
$cur = common_current_user();
if (!$cur->isAdmin($this->group)) {
// TRANS: Client error displayed trying to edit a group while not being a group admin.
$this->clientError(_('You must be an admin to edit the group.'), 403);
return;
}
if (Event::handle('StartGroupSaveForm', array($this))) {
$nickname = Nickname::normalize($this->trimmed('newnickname'));
$fullname = $this->trimmed('fullname');
$homepage = $this->trimmed('homepage');
$description = $this->trimmed('description');
$location = $this->trimmed('location');
$aliasstring = $this->trimmed('aliases');
$private = $this->boolean('private');
if ($private) {
$force_scope = 1;
$join_policy = User_group::JOIN_POLICY_MODERATE;
} else {
$force_scope = 0;
$join_policy = User_group::JOIN_POLICY_OPEN;
}
if ($this->nicknameExists($nickname)) {
// TRANS: Group edit form validation error.
$this->showForm(_('Nickname already in use. Try another one.'));
return;
} else {
if (!User_group::allowedNickname($nickname)) {
// TRANS: Group edit form validation error.
$this->showForm(_('Not a valid nickname.'));
return;
} else {
if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
// TRANS: Group edit form validation error.
$this->showForm(_('Homepage is not a valid URL.'));
return;
} else {
if (!is_null($fullname) && mb_strlen($fullname) > 255) {
// TRANS: Group edit form validation error.
$this->showForm(_('Full name is too long (maximum 255 characters).'));
return;
} else {
if (User_group::descriptionTooLong($description)) {
$this->showForm(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', User_group::maxDescription()), User_group::maxDescription()));
return;
} else {
if (!is_null($location) && mb_strlen($location) > 255) {
// TRANS: Group edit form validation error.
$this->showForm(_('Location is too long (maximum 255 characters).'));
return;
}
}
}
}
}
}
if (!empty($aliasstring)) {
$aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $aliasstring)));
} else {
$aliases = array();
}
if (count($aliases) > common_config('group', 'maxaliases')) {
// TRANS: Group edit form validation error.
// TRANS: %d is the maximum number of allowed aliases.
$this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases')));
return;
}
foreach ($aliases as $alias) {
if (!Nickname::isValid($alias)) {
// TRANS: Group edit form validation error.
$this->showForm(sprintf(_('Invalid alias: "%s"'), $alias));
return;
}
if ($this->nicknameExists($alias)) {
// TRANS: Group edit form validation error.
$this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), $alias));
return;
}
// XXX assumes alphanum nicknames
if (strcmp($alias, $nickname) == 0) {
// TRANS: Group edit form validation error.
$this->showForm(_('Alias can\'t be the same as nickname.'));
return;
}
}
// Comprobamos si hay algo que actualizar, o si no ha cambiado nada el usuario.
$part1 = false;
if ($this->group->nickname == $nickname && $this->group->fullname == $fullname && $this->group->homepage == $homepage && $this->group->description == $description && $this->group->location == $location && $this->group->mainpage == common_local_url('showgroup', array('nickname' => $nickname)) && $this->group->join_policy == $join_policy && $this->group->force_scope == $force_scope) {
$part1 = true;
} else {
$this->group->query('BEGIN');
$orig = clone $this->group;
$this->group->nickname = $nickname;
$this->group->fullname = $fullname;
$this->group->homepage = $homepage;
$this->group->description = $description;
$this->group->location = $location;
$this->group->mainpage = common_local_url('showgroup', array('nickname' => $nickname));
$this->group->join_policy = $join_policy;
//.........这里部分代码省略.........
示例10: realpath
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
$longoptions = array('skip=', 'count=');
$helptext = <<<END_OF_HELP
testfeed.php [options] http://example.com/atom-feed-url
Pull an Atom feed and run items in it as though they were live PuSH updates.
Mainly intended for testing funky feed formats.
--skip=N Ignore the first N items in the feed.
--count=N Only process up to N items from the feed, after skipping.
END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
$validate = new Validate();
if (empty($args[0]) || !$validate->uri($args[0])) {
print "{$helptext}";
exit(1);
}
$feedurl = $args[0];
$skip = have_option('skip') ? intval(get_option_value('skip')) : 0;
$count = have_option('count') ? intval(get_option_value('count')) : 0;
$sub = FeedSub::getKV('uri', $feedurl);
if (!$sub) {
print "Feed {$feedurl} is not subscribed.\n";
exit(1);
}
// Fetch the URL
try {
$xml = HTTPClient::quickGet($feedurl, 'text/html,application/xhtml+xml');
} catch (Exception $e) {
示例11: url
static function url($url, $checkDomain = false)
{
$options = array('domain_check' => $checkDomain, 'allowed_schemes' => array('http', 'https', 'mailto', 'ftp'));
require_once 'Validate.php';
return Validate::uri($url, $options);
}
示例12: setAPI
/**
* Set API
*
* @param mixed $api Api url to set
*
* @return void
*/
public function setAPI($api)
{
if (!Validate::uri($api)) {
throw new Services_Facebook('Invalid API: ' . $api);
}
$this->api = $api;
}
示例13: handlePost
/**
* Handle a post
*
* Validate input and save changes. Reload the form with a success
* or error message.
*
* @return void
*/
function handlePost()
{
// CSRF protection
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
// TRANS: Form validation error.
$this->showForm(_('There was a problem with your session token. ' . 'Try again, please.'));
return;
}
if (Event::handle('StartProfileSaveForm', array($this))) {
try {
$nickname = Nickname::normalize($this->trimmed('nickname'));
} catch (NicknameException $e) {
$this->showForm($e->getMessage());
return;
}
$fullname = $this->trimmed('fullname');
$homepage = $this->trimmed('homepage');
$bio = $this->trimmed('bio');
$location = $this->trimmed('location');
$autosubscribe = $this->boolean('autosubscribe');
$subscribe_policy = $this->trimmed('subscribe_policy');
$private_stream = $this->boolean('private_stream');
$language = $this->trimmed('language');
$timezone = $this->trimmed('timezone');
$tagstring = $this->trimmed('tags');
// Some validation
if (!User::allowed_nickname($nickname)) {
// TRANS: Validation error in form for profile settings.
$this->showForm(_('Not a valid nickname.'));
return;
} else {
if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
// TRANS: Validation error in form for profile settings.
$this->showForm(_('Homepage is not a valid URL.'));
return;
} else {
if (!is_null($fullname) && mb_strlen($fullname) > 255) {
// TRANS: Validation error in form for profile settings.
$this->showForm(_('Full name is too long (maximum 255 characters).'));
return;
} else {
if (Profile::bioTooLong($bio)) {
// TRANS: Validation error in form for profile settings.
// TRANS: Plural form is used based on the maximum number of allowed
// TRANS: characters for the biography (%d).
$this->showForm(sprintf(_m('Bio is too long (maximum %d character).', 'Bio is too long (maximum %d characters).', Profile::maxBio()), Profile::maxBio()));
return;
} else {
if (!is_null($location) && mb_strlen($location) > 255) {
// TRANS: Validation error in form for profile settings.
$this->showForm(_('Location is too long (maximum 255 characters).'));
return;
} else {
if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
// TRANS: Validation error in form for profile settings.
$this->showForm(_('Timezone not selected.'));
return;
} else {
if ($this->nicknameExists($nickname)) {
// TRANS: Validation error in form for profile settings.
$this->showForm(_('Nickname already in use. Try another one.'));
return;
} else {
if (!is_null($language) && strlen($language) > 50) {
// TRANS: Validation error in form for profile settings.
$this->showForm(_('Language is too long (maximum 50 characters).'));
return;
}
}
}
}
}
}
}
}
$tags = array();
$tag_priv = array();
if (is_string($tagstring) && strlen($tagstring) > 0) {
$tags = preg_split('/[\\s,]+/', $tagstring);
foreach ($tags as &$tag) {
$private = @$tag[0] === '.';
$tag = common_canonical_tag($tag);
if (!common_valid_profile_tag($tag)) {
// TRANS: Validation error in form for profile settings.
// TRANS: %s is an invalid tag.
$this->showForm(sprintf(_('Invalid tag: "%s".'), $tag));
return;
}
$tag_priv[$tag] = $private;
}
}
//.........这里部分代码省略.........
示例14: define
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
$longoptions = array('skip=', 'count=');
$helptext = <<<END_OF_HELP
testfeed.php [options] http://example.com/atom-feed-url
Pull an Atom feed and run items in it as though they were live PuSH updates.
Mainly intended for testing funky feed formats.
--skip=N Ignore the first N items in the feed.
--count=N Only process up to N items from the feed, after skipping.
END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
if (empty($args[0]) || !Validate::uri($args[0])) {
print "{$helptext}";
exit(1);
}
$feedurl = $args[0];
$skip = have_option('skip') ? intval(get_option_value('skip')) : 0;
$count = have_option('count') ? intval(get_option_value('count')) : 0;
$sub = FeedSub::staticGet('topic', $feedurl);
if (!$sub) {
print "Feed {$feedurl} is not subscribed.\n";
exit(1);
}
$xml = file_get_contents($feedurl);
if ($xml === false) {
print "Bad fetch.\n";
exit(1);
示例15: pullOstatusProfile
function pullOstatusProfile($uri)
{
$oprofile = null;
if (Validate::email($uri)) {
$oprofile = LooseOstatusProfile::updateWebfinger($uri);
} else {
if (Validate::uri($uri)) {
$oprofile = LooseOstatusProfile::updateProfileURL($uri);
} else {
print "Sorry, we could not reach the address: {$uri}\n";
return false;
}
}
return $oprofile;
}