本文整理汇总了PHP中URLify类的典型用法代码示例。如果您正苦于以下问题:PHP URLify类的具体用法?PHP URLify怎么用?PHP URLify使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了URLify类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: publishToPage
public function publishToPage(Page $c, $data, $controls)
{
$slug = array_filter($controls, function ($item) {
if ($item instanceof UrlSlugCorePageProperty) {
return true;
}
return false;
});
$this->addPageTypeComposerControlRequestValue('cName', $data['name']);
if (!count($slug) && $c->isPageDraft()) {
$txt = new \URLify();
$this->addPageTypeComposerControlRequestValue('cHandle', $txt->filter($data['name']));
}
parent::publishToPage($c, $data, $controls);
}
开发者ID:ceko,项目名称:concrete5-1,代码行数:15,代码来源:NameCorePageProperty.php
示例2: filter
public function filter($value)
{
URLify::$remove_list = array();
$value = URLify::filter($value, 60, 'de');
$value = str_replace('-', '_', $value);
return $value;
}
开发者ID:xiaoguizhidao,项目名称:koala-framework,代码行数:7,代码来源:Ascii.php
示例3: upload
/**
* {@inheritdoc}
*/
public function upload($fp, $dst, $name, $tmpname)
{
$this->setConnectorFromPlugin();
// upload file by elfinder.
$result = parent::upload($fp, $dst, $name, $tmpname);
$name = $result['name'];
$filtered = \URLify::filter($result['name'], 80);
if (strcmp($name, $filtered) != 0) {
/*$arg = array('target' => $file['hash'], 'name' => $filtered);
$elFinder->exec('rename', $arg);*/
$this->rename($result['hash'], $filtered);
}
$realPath = $this->realpath($result['hash']);
if (!empty($realPath)) {
// Getting file info
//$info = $elFinder->exec('file', array('target' => $file['hash']));
/** @var elFinderVolumeLocalFileSystem $volume */
//$volume = $info['volume'];
//$root = $volume->root();
//var/www/chamilogits/data/courses/NEWONE/document
$realPathRoot = $this->getCourseDocumentSysPath();
// Removing course path
$realPath = str_replace($realPathRoot, '/', $realPath);
\FileManager::add_document($this->connector->course, $realPath, 'file', intval($result['size']), $result['name']);
}
return $result;
}
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:30,代码来源:CourseDriver.php
示例4: execute
public function execute(Stdio $stdio, array $params = [])
{
if (strpos($params['source'], 'data/') !== 0) {
throw new \DomainException('The source must be in the data directory.');
}
if (strpos($params['target'], 'data/') !== 0) {
throw new \DomainException('The target must be in the data directory.');
}
$params['source'] = substr($params['source'], strlen('data/'));
$params['target'] = substr($params['target'], strlen('data/'));
$match = preg_match('/^(?:.*?\\/)?([0-9]{4}-[0-9]{2}-[0-9]{2}\\.|[0-9]+\\.|)([^\\/]*)$/', $params['source'], $matches);
$matches[1] = trim($matches[1], '.');
if ($params['--date']) {
$matches[1] = (new \DateTime())->format('Y-m-d');
}
if ($params['--title']) {
$matches[2] = \URLify::filter($params['--title']);
}
$file = trim($params['target'], '/') . '/';
$file .= $params['--date'] ? $matches[1] . '.' : '';
$file .= $matches[2];
$this->hooks->call('before.move');
$this->data->move($params['source'], $file);
if ($params['--title']) {
$data = $this->data->read($file);
$data['title'] = $params['--title'];
$this->data->write($file, $data);
}
$stdio->outln('<<magenta>>' . $params['source'] . ' moved to ' . $file . '<<reset>>');
$this->hooks->call('after.move');
return Status::SUCCESS;
}
开发者ID:erickmerchant,项目名称:wright,代码行数:32,代码来源:MoveCommand.php
示例5: setFile
public function setFile($title, $fieldName)
{
$storage = new \Upload\Storage\FileSystem(self::PATH_ORIGINALS);
$this->file = new \Upload\File($fieldName, $storage);
$filename = \URLify::filter($title);
$this->file->setName($filename . '-' . uniqid());
$this->file->addValidations([new \Upload\Validation\Mimetype(['image/png', 'image/jpg', 'image/jpeg', 'image/gif']), new \Upload\Validation\Size('5M')]);
}
开发者ID:supercluster,项目名称:catalog,代码行数:8,代码来源:UploaderService.php
示例6: __construct
/**
* LogFile constructor.
*
* @param string $name
* @param string $clientSlug
* @param array $args
*/
public function __construct($name, $clientSlug, $args)
{
setlocale(LC_ALL, 'en_US.UTF8');
$this->name = $name;
$this->slug = \URLify::filter($name);
$this->collectionSlug = \URLify::filter($clientSlug);
$this->args = $args;
$this->lines = new ArrayCollection();
$this->loggers = new ArrayCollection();
}
开发者ID:syonix,项目名称:log-viewer-lib,代码行数:17,代码来源:LogFile.php
示例7: run
/**
* @inheritdoc
*/
public function run()
{
if (Yii::$app->request->isPost) {
if (isset($_POST['filename'])) {
$this->fileName = \URLify::filter(pathinfo($_POST['filename'], PATHINFO_FILENAME), 255, "", true) . '_' . uniqid() . '.' . pathinfo($_POST['filename'], PATHINFO_EXTENSION);
$upload_dir = $this->uploadDir;
$upload_file = $this->fileName;
$uploader = new FileUpload('uploadfile');
$uploader->newFileName = $this->fileName;
$uploader->sizeLimit = $this->fileSizeLimit;
// Handle the upload
$result = $uploader->handleUpload($upload_dir);
unset($_POST['filename']);
if (!$result) {
$upload_result = json_encode(array('success' => false, 'msg' => $uploader->getErrorMsg()));
} else {
if ($this->isImage($upload_dir . $upload_file)) {
//
$image_name = $upload_dir . $upload_file;
// resize with calculate aspect ratio
list($image_width, $image_height, $type, $attr) = getimagesize($image_name);
$ratio = $image_width / $image_height;
if ($ratio > 1) {
$target_width = $this->resize_max_width;
$target_height = $this->resize_max_width / $ratio;
} else {
$target_width = $this->resize_max_height * $ratio;
$target_height = $this->resize_max_height;
}
// resize image if original dimension is bigger from max size
if ($target_width < $this->resize_max_width || $target_height < $this->resize_max_height) {
Image::thumbnail($image_name, $target_width, $target_height, ManipulatorInterface::THUMBNAIL_INSET)->save($image_name);
}
// apply watermark
if ($this->watermark) {
Image::watermark($image_name, $this->watermark)->save($image_name);
}
}
// thumbnails create
if ($this->thumbnail && $this->isImage($image_name) && ($this->thumbnail_width > 0 && $this->thumbnail_height > 0)) {
Image::thumbnail($image_name, $this->thumbnail_width, $this->thumbnail_height)->save($upload_dir . 'thumbs/' . $upload_file);
}
$upload_result = ['success' => true, 'filelink' => $upload_file];
}
Yii::$app->response->format = Response::FORMAT_JSON;
return $upload_result;
}
} else {
throw new BadRequestHttpException(Yii::t('upload', 'ONLY_POST_REQUEST'));
}
}
开发者ID:plathir,项目名称:yii2-smart-upload,代码行数:54,代码来源:FileUploadAction.php
示例8: filter
/**
* @param string $value
* @return string
*/
public function filter($value)
{
$transliterated = \URLify::transliterate($value);
if ($this->replaceSpacesWithDashes) {
$filter = new SeparatorToSeparator(' ', '_');
$transliterated = $filter->filter($transliterated);
} else {
if ($this->replaceSpacesWithSeparator) {
$filter = new SeparatorToSeparator(' ', $this->separator);
$transliterated = $filter->filter($transliterated);
}
}
return $transliterated;
}
开发者ID:spalax,项目名称:zf2-libs,代码行数:18,代码来源:Transliterate.php
示例9: actionNovo
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionNovo()
{
$model = new Depoimento();
$professor = Professor::model()->findByPk($_POST['Depoimento']['id_professor']);
if (!empty($_POST['Depoimento'])) {
if (empty($_POST['Depoimento']['nome'])) {
unset($_POST['Depoimento']['nome']);
}
$model->attributes = $_POST['Depoimento'];
$model->id_disciplina = empty($_POST['Depoimento']['id_disciplina']) ? null : $_POST['Depoimento']['id_disciplina'];
if ($model->save()) {
Yii::app()->user->setFlash('success', "Seu depoimento foi enviado com sucesso e está aguardando aprovação.");
$this->redirect(Yii::app()->baseUrl . '/professor/' . $model->id_professor . '/' . URLify::filter($professor->nome));
}
}
}
开发者ID:andrewinston,项目名称:professoresdaect,代码行数:20,代码来源:DepoimentoController.php
示例10: asciify
/** Takes text and converts it to an ASCII-only string (characters with code between 32 and 127, plus \t, \n and \r).
* @param string $text The text to be converted.
* @param string $locale='' The locale for the string. If not specified we consider the current locale.
* @return string
*/
public function asciify($text, $locale = '')
{
if (!strlen($locale)) {
$locale = \Localization::activeLocale();
}
$language = substr($locale, 0, strcspn($locale, '_'));
$text = \URLify::downcode($text, $language);
if (preg_match('/[^\\t\\r\\n\\x20-\\x7e]/', $text)) {
if (function_exists('iconv')) {
$t = @iconv(APP_CHARSET, 'US-ASCII//IGNORE//TRANSLIT', $text);
if (is_string($t)) {
$text = $t;
}
}
$text = preg_replace('/[^\\t\\r\\n\\x20-\\x7e]/', '', $text);
}
return $text;
}
开发者ID:meixelsberger,项目名称:concrete5-5.7.0,代码行数:23,代码来源:Text.php
示例11: new_channel_init
function new_channel_init(&$a)
{
$cmd = argc() > 1 ? argv(1) : '';
if ($cmd === 'autofill.json') {
require_once 'library/urlify/URLify.php';
$result = array('error' => false, 'message' => '');
$n = trim($_REQUEST['name']);
$x = strtolower(URLify::transliterate($n));
$test = array();
// first name
if (strpos($x, ' ')) {
$test[] = legal_webbie(substr($x, 0, strpos($x, ' ')));
}
if ($test[0]) {
// first name plus first initial of last
$test[] = strpos($x, ' ') ? $test[0] . legal_webbie(trim(substr($x, strpos($x, ' '), 2))) : '';
// first name plus random number
$test[] = $test[0] . mt_rand(1000, 9999);
}
// fullname
$test[] = legal_webbie($x);
// fullname plus random number
$test[] = legal_webbie($x) . mt_rand(1000, 9999);
json_return_and_die(check_webbie($test));
}
if ($cmd === 'checkaddr.json') {
require_once 'library/urlify/URLify.php';
$result = array('error' => false, 'message' => '');
$n = trim($_REQUEST['nick']);
$x = strtolower(URLify::transliterate($n));
$test = array();
$n = legal_webbie($x);
if (strlen($n)) {
$test[] = $n;
$test[] = $n . mt_rand(1000, 9999);
}
for ($y = 0; $y < 100; $y++) {
$test[] = 'id' . mt_rand(1000, 9999);
}
json_return_and_die(check_webbie($test));
}
}
开发者ID:Gillesq,项目名称:hubzilla,代码行数:42,代码来源:new_channel.php
示例12: execute
public function execute(Stdio $stdio, array $params = [])
{
if (strpos($params['target'], 'data/') !== 0) {
throw new \DomainException('The target must be in the data directory.');
}
$params['target'] = substr($params['target'], strlen('data/'));
if (!empty($params['--related'])) {
foreach ($params['--related'] as $key => $related) {
if (strpos($related, 'data/') !== 0) {
throw new \DomainException('Each --related must be in the data directory.');
}
$params['--related'][$key] = substr(dirname($related), strlen('data/')) . '/' . pathinfo($related, PATHINFO_FILENAME);
}
}
$data = [];
foreach (['title', 'summary', '--related'] as $param_key) {
if (!empty($params[$param_key])) {
$data[trim($param_key, '-')] = $params[$param_key];
}
}
$file = '';
if ($params['target']) {
$file = trim($params['target'], '/') . '/';
}
if ($params['--date']) {
$file .= (new \DateTime())->format('Y-m-d') . '.';
}
$file .= \URLify::filter($data['title']);
$file .= $params['--ext'] ? $params['--ext'] : '.md';
$file = trim($file, '/');
$this->hooks->call('before.make');
$this->data->write($file, $data);
$stdio->outln('<<magenta>>' . $file . ' published on ' . (new \DateTime())->format('Y-m-d') . '<<reset>>');
$this->hooks->call('after.make');
return Status::SUCCESS;
}
开发者ID:erickmerchant,项目名称:wright,代码行数:36,代码来源:MakeCommand.php
示例13: item_post
function item_post(&$a)
{
// This will change. Figure out who the observer is and whether or not
// they have permission to post here. Else ignore the post.
if (!local_channel() && !remote_channel() && !x($_REQUEST, 'commenter')) {
return;
}
require_once 'include/security.php';
$uid = local_channel();
$channel = null;
$observer = null;
/**
* Is this a reply to something?
*/
$parent = x($_REQUEST, 'parent') ? intval($_REQUEST['parent']) : 0;
$parent_mid = x($_REQUEST, 'parent_mid') ? trim($_REQUEST['parent_mid']) : '';
$remote_xchan = x($_REQUEST, 'remote_xchan') ? trim($_REQUEST['remote_xchan']) : false;
$r = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($remote_xchan));
if ($r) {
$remote_observer = $r[0];
} else {
$remote_xchan = $remote_observer = false;
}
$profile_uid = x($_REQUEST, 'profile_uid') ? intval($_REQUEST['profile_uid']) : 0;
require_once 'include/identity.php';
$sys = get_sys_channel();
if ($sys && $profile_uid && $sys['channel_id'] == $profile_uid && is_site_admin()) {
$uid = intval($sys['channel_id']);
$channel = $sys;
$observer = $sys;
}
if (x($_REQUEST, 'dropitems')) {
require_once 'include/items.php';
$arr_drop = explode(',', $_REQUEST['dropitems']);
drop_items($arr_drop);
$json = array('success' => 1);
echo json_encode($json);
killme();
}
call_hooks('post_local_start', $_REQUEST);
// logger('postvars ' . print_r($_REQUEST,true), LOGGER_DATA);
$api_source = x($_REQUEST, 'api_source') && $_REQUEST['api_source'] ? true : false;
$consensus = intval($_REQUEST['consensus']);
// 'origin' (if non-zero) indicates that this network is where the message originated,
// for the purpose of relaying comments to other conversation members.
// If using the API from a device (leaf node) you must set origin to 1 (default) or leave unset.
// If the API is used from another network with its own distribution
// and deliveries, you may wish to set origin to 0 or false and allow the other
// network to relay comments.
// If you are unsure, it is prudent (and important) to leave it unset.
$origin = $api_source && array_key_exists('origin', $_REQUEST) ? intval($_REQUEST['origin']) : 1;
// To represent message-ids on other networks - this will create an item_id record
$namespace = $api_source && array_key_exists('namespace', $_REQUEST) ? strip_tags($_REQUEST['namespace']) : '';
$remote_id = $api_source && array_key_exists('remote_id', $_REQUEST) ? strip_tags($_REQUEST['remote_id']) : '';
$owner_hash = null;
$message_id = x($_REQUEST, 'message_id') && $api_source ? strip_tags($_REQUEST['message_id']) : '';
$created = x($_REQUEST, 'created') ? datetime_convert('UTC', 'UTC', $_REQUEST['created']) : datetime_convert();
$post_id = x($_REQUEST, 'post_id') ? intval($_REQUEST['post_id']) : 0;
$app = x($_REQUEST, 'source') ? strip_tags($_REQUEST['source']) : '';
$return_path = x($_REQUEST, 'return') ? $_REQUEST['return'] : '';
$preview = x($_REQUEST, 'preview') ? intval($_REQUEST['preview']) : 0;
$categories = x($_REQUEST, 'category') ? escape_tags($_REQUEST['category']) : '';
$webpage = x($_REQUEST, 'webpage') ? intval($_REQUEST['webpage']) : 0;
$pagetitle = x($_REQUEST, 'pagetitle') ? escape_tags(urlencode($_REQUEST['pagetitle'])) : '';
$layout_mid = x($_REQUEST, 'layout_mid') ? escape_tags($_REQUEST['layout_mid']) : '';
$plink = x($_REQUEST, 'permalink') ? escape_tags($_REQUEST['permalink']) : '';
$obj_type = x($_REQUEST, 'obj_type') ? escape_tags($_REQUEST['obj_type']) : ACTIVITY_OBJ_NOTE;
// allow API to bulk load a bunch of imported items with sending out a bunch of posts.
$nopush = x($_REQUEST, 'nopush') ? intval($_REQUEST['nopush']) : 0;
/*
* Check service class limits
*/
if ($uid && !x($_REQUEST, 'parent') && !x($_REQUEST, 'post_id')) {
$ret = item_check_service_class($uid, $_REQUEST['webpage'] == ITEM_WEBPAGE ? true : false);
if (!$ret['success']) {
notice(t($ret['message']) . EOL);
if (x($_REQUEST, 'return')) {
goaway($a->get_baseurl() . "/" . $return_path);
}
killme();
}
}
if ($pagetitle) {
require_once 'library/urlify/URLify.php';
$pagetitle = strtolower(URLify::transliterate($pagetitle));
}
$item_flags = $item_restrict = 0;
$route = '';
$parent_item = null;
$parent_contact = null;
$thr_parent = '';
$parid = 0;
$r = false;
if ($parent || $parent_mid) {
if (!x($_REQUEST, 'type')) {
$_REQUEST['type'] = 'net-comment';
}
if ($obj_type == ACTIVITY_OBJ_POST) {
$obj_type = ACTIVITY_OBJ_COMMENT;
}
//.........这里部分代码省略.........
开发者ID:einervonvielen,项目名称:redmatrix,代码行数:101,代码来源:item.php
示例14: purify_username
/**
* Modifies a given username accordingly to the specification for valid characters and length.
* @param $username string The input username.
* @param bool $strict (optional) When this flag is TRUE, the result is guaranteed for full compliance, otherwise compliance may be partial. The default value is FALSE.
* @param string $encoding (optional) The character encoding for the input names. If it is omitted, the platform character set will be used by default.
* @return string The resulting purified username.
*/
public static function purify_username($username, $strict = false, $encoding = null)
{
if ($strict) {
// 1. Conversion of unacceptable letters (latinian letters with accents for example) into ASCII letters in order they not to be totally removed.
// 2. Applying the strict purifier.
// 3. Length limitation.
$return = api_get_setting('login_is_email') == 'true' ? substr(preg_replace(USERNAME_PURIFIER_MAIL, '', $username), 0, USERNAME_MAX_LENGTH) : substr(preg_replace(USERNAME_PURIFIER, '', $username), 0, USERNAME_MAX_LENGTH);
$return = URLify::transliterate($return);
return $return;
}
// 1. Applying the shallow purifier.
// 2. Length limitation.
return substr(preg_replace(USERNAME_PURIFIER_SHALLOW, '', $username), 0, USERNAME_MAX_LENGTH);
}
开发者ID:secuencia24,项目名称:chamilo-lms,代码行数:21,代码来源:usermanager.lib.php
示例15: transliterate
/**
* Converts UTF8 into Latin
*
* @param $value
*
* @return mixed
*/
public static function transliterate($value)
{
return \URLify::transliterate($value);
}
开发者ID:Jandersolutions,项目名称:mautic,代码行数:11,代码来源:InputHelper.php
示例16: makeSlug
/**
* Modify a string, so that we can use it for slugs. Like
* safeString, but using hyphens instead of underscores.
*
* @param string $str
* @param string $type
* @return string
*/
function makeSlug($str)
{
return \URLify::filter(strip_tags($str));
}
开发者ID:slick0,项目名称:docs,代码行数:12,代码来源:index.php
示例17: count
$page->num = count($this->params) > 1 && is_numeric($this->params[1]) ? $this->params[1] - 1 : 0;
$page->offset = $page->num * $page->limit;
$p = new blog\Post();
$posts = $p->by($page->author, $page->limit, $page->offset);
$page->count = $p->query()->where('published', 'yes')->where('author', $page->author)->count();
$page->last = $page->offset + count($posts);
$page->more = $page->count > $page->last ? true : false;
$page->next = $page->num + 2;
$footer = Appconf::blog('Blog', 'post_footer');
$footer_stripped = strip_tags($footer);
$footer = $footer && !empty($footer_stripped) ? $tpl->run_includes($footer) : false;
if (Appconf::blog('Blog', 'post_format') === 'markdown') {
require_once 'apps/blog/lib/markdown.php';
}
foreach ($posts as $post) {
$post->url = '/blog/post/' . $post->id . '/' . URLify::filter($post->title);
$post->tag_list = strlen($post->tags) > 0 ? explode(',', $post->tags) : array();
$post->social_buttons = $appconf['Social Buttons'];
if (Appconf::blog('Blog', 'post_format') === 'html') {
$post->body = $tpl->run_includes($post->body);
} else {
$post->body = $tpl->run_includes(Markdown($post->body));
}
if ($preview_chars) {
$post->body = blog_filter_truncate($post->body, $preview_chars) . ' <a href="' . $post->url . '">' . __('Read more') . '</a>';
} else {
$post->footer = $footer;
}
echo $tpl->render('blog/post', $post);
}
$page->title = __('Posts by %s', $tpl->sanitize($page->author));
开发者ID:Selwyn-b,项目名称:elefant,代码行数:31,代码来源:by.php
示例18: rescanPagePaths
public function rescanPagePaths($newPaths)
{
$db = Loader::db();
$txt = Loader::helper('text');
// First, get the list of page paths from the DB.
$ppaths = $this->getPagePaths();
// Second, reset all of their cPath values to null.
$paths = array();
foreach ($ppaths as $ppath) {
if (!$ppath['ppIsCanonical']) {
$paths[$ppath['ppID']] = null;
}
}
// Third, fill in the cPath values from the user updated data.
Loader::library('3rdparty/urlify');
foreach ($newPaths as $key => $val) {
if (!empty($val)) {
// Auto-prepend a slash if one is missing.
$val = trim($val, '/');
$pathSegments = explode('/', $val);
$newVal = '/';
foreach ($pathSegments as $pathSegment) {
$newVal .= URLify::filter($pathSegment) . '/';
}
$newVal = substr($newVal, 0, strlen($newVal) - 1);
$newVal = str_replace('-', PAGE_PATH_SEPARATOR, $newVal);
$paths[$key] = $newVal;
}
}
// Fourth, delete, update, or insert page paths as necessary.
foreach ($paths as $key => $val) {
if (empty($val)) {
$v = array($this->cID, $key);
$q = "delete from PagePaths where cID = ? and ppID = ?";
} else {
if (is_numeric($key)) {
$val = $this->uniquifyPagePath($val);
$v = array($val, $this->cID, $key);
$q = "update PagePaths set cPath = ?, ppIsCanonical = 0 where cID = ? and ppID = ?";
} else {
$val = $this->uniquifyPagePath($val);
$v = array($this->cID, $val);
$q = "insert into PagePaths (cID, cPath, ppIsCanonical) values (?, ?, 0)";
}
}
$r = $db->query($q, $v);
}
}
开发者ID:ronlobo,项目名称:concrete5-de,代码行数:48,代码来源:page.php
示例19: gmdate
<?php
/**
* Renders the RSS feed for the blog.
*/
$res = $memcache->get('_blog_rss');
if (!$res) {
require_once 'apps/blog/lib/Filters.php';
$p = new blog\Post();
$page->posts = $p->latest(10, 0);
$page->title = $appconf['Blog']['title'];
$page->date = gmdate('Y-m-d\\TH:i:s');
foreach ($page->posts as $k => $post) {
$page->posts[$k]->url = '/blog/post/' . $post->id . '/' . URLify::filter($post->title);
}
$res = $tpl->render('blog/rss', $page);
$memcache->set('_blog_rss', $res, 1800);
// half an hour
}
$page->layout = false;
header('Content-Type: text/xml');
echo $res;
开发者ID:nathanieltite,项目名称:elefant,代码行数:22,代码来源:rss.php
示例20: get
function get()
{
$noid = get_config('system', 'disable_openid');
if ($noid) {
goaway(z_root());
}
logger('mod_openid ' . print_r($_REQUEST, true), LOGGER_DATA);
if (x($_REQUEST, 'openid_mode')) {
$openid = new LightOpenID(z_root());
if ($openid->validate()) {
logger('openid: validate');
$authid = normalise_openid($_REQUEST['openid_identity']);
if (!strlen($authid)) {
logger(t('OpenID protocol error. No ID returned.') . EOL);
goaway(z_root());
}
$x = match_openid($authid);
if ($x) {
$r = q("select * from channel where channel_id = %d limit 1", intval($x));
if ($r) {
$y = q("select * from account where account_id = %d limit 1", intval($r[0]['channel_account_id']));
if ($y) {
foreach ($y as $record) {
if ($record['account_flags'] == ACCOUNT_OK || $record['account_flags'] == ACCOUNT_UNVERIFIED) {
logger('mod_openid: openid success for ' . $x[0]['channel_name']);
$_SESSION['uid'] = $r[0]['channel_id'];
$_SESSION['account_id'] = $r[0]['channel_account_id'];
$_SESSION['authenticated'] = true;
authenticate_success($record, $r[0], true, true, true, true);
goaway(z_root());
}
}
}
}
}
// Successful OpenID login - but we can't match it to an existing account.
// See if they've got an xchan
$r = q("select * from xconfig left join xchan on xchan_hash = xconfig.xchan where cat = 'system' and k = 'openid' and v = '%s' limit 1", dbesc($authid));
if ($r) {
$_SESSION['authenticated'] = 1;
$_SESSION['visitor_id'] = $r[0]['xchan_hash'];
$_SESSION['my_url'] = $r[0]['xchan_url'];
$_SESSION['my_address'] = $r[0]['xchan_addr'];
$arr = array('xchan' => $r[0], 'session' => $_SESSION);
call_hooks('magic_auth_openid_success', $arr);
\App::set_observer($r[0]);
require_once 'include/security.php';
\App::set_groups(init_groups_visitor($_SESSION['visitor_id']));
info(sprintf(t('Welcome %s. Remote authentication successful.'), $r[0]['xchan_name']));
logger('mod_openid: remote auth success from ' . $r[0]['xchan_addr']);
if ($_SESSION['return_url']) {
goaway($_SESSION['return_url']);
}
goaway(z_root());
}
// no xchan...
// create one.
// We should probably probe the openid url and figure out if they have any kind of
// social presence we might be able to scrape some identifying info from.
$name = $authid;
$url = trim($_REQUEST['openid_identity'], '/');
if (strpos($url, 'http') === false) {
$url = 'https://' . $url;
}
$pphoto = z_root() . '/' . get_default_profile_photo();
$parsed = @parse_url($url);
if ($parsed) {
$host = $parsed['host'];
}
$attr = $openid->getAttributes();
if (is_array($attr) && count($attr)) {
foreach ($attr as $k => $v) {
if ($k === 'namePerson/friendly') {
$nick = notags(trim($v));
}
if ($k === 'namePerson/first') {
$first = notags(trim($v));
}
if ($k === 'namePerson') {
$name = notags(trim($v));
}
if ($k === 'contact/email') {
$addr = notags(trim($v));
}
if ($k === 'media/image/aspect11') {
$photosq = trim($v);
}
if ($k === 'media/image/default') {
$photo_other = trim($v);
}
}
}
if (!$nick) {
if ($first) {
$nick = $first;
} else {
$nick = $name;
}
}
require_once 'library/urlify/URLify.php';
//.........这里部分代码省略.........
开发者ID:phellmes,项目名称:hubzilla-addons,代码行数:101,代码来源:Mod_Openid.php
注:本文中的URLify类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论