本文整理汇总了PHP中common_shorten_url函数的典型用法代码示例。如果您正苦于以下问题:PHP common_shorten_url函数的具体用法?PHP common_shorten_url怎么用?PHP common_shorten_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了common_shorten_url函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
function __construct(Profile $scoped, $filename = null, $mimetype = null, $filehash = null)
{
$this->scoped = $scoped;
$this->filename = $filename;
$this->mimetype = $mimetype;
$this->filehash = $filehash;
$this->fileRecord = $this->storeFile();
$this->fileurl = common_local_url('attachment', array('attachment' => $this->fileRecord->id));
$this->maybeAddRedir($this->fileRecord->id, $this->fileurl);
$this->short_fileurl = common_shorten_url($this->fileurl);
$this->maybeAddRedir($this->fileRecord->id, $this->short_fileurl);
}
示例2: __construct
function __construct($user = null, $filename = null, $mimetype = null)
{
if ($user == null) {
$this->user = common_current_user();
}
$this->filename = $filename;
$this->mimetype = $mimetype;
$this->fileRecord = $this->storeFile();
$this->fileurl = common_local_url('attachment', array('attachment' => $this->fileRecord->id));
$this->maybeAddRedir($this->fileRecord->id, $this->fileurl);
$this->short_fileurl = common_shorten_url($this->fileurl);
$this->maybeAddRedir($this->fileRecord->id, $this->short_fileurl);
}
示例3: _userMakeShort
function _userMakeShort($long_url, User $user = null, $force = false)
{
$short_url = common_shorten_url($long_url, $user, $force);
if (!empty($short_url) && $short_url != $long_url) {
$short_url = (string) $short_url;
// store it
$file = File::staticGet('url', $long_url);
if (empty($file)) {
// Check if the target URL is itself a redirect...
$redir_data = File_redirection::where($long_url);
if (is_array($redir_data)) {
// We haven't seen the target URL before.
// Save file and embedding data about it!
$file = File::saveNew($redir_data, $long_url);
$file_id = $file->id;
if (!empty($redir_data['oembed']['json'])) {
File_oembed::saveNew($redir_data['oembed']['json'], $file_id);
}
} else {
if (is_string($redir_data)) {
// The file is a known redirect target.
$file = File::staticGet('url', $redir_data);
if (empty($file)) {
// @fixme should we save a new one?
// this case was triggering sometimes for redirects
// with unresolvable targets; found while fixing
// "can't linkify" bugs with shortened links to
// SSL sites with cert issues.
return null;
}
$file_id = $file->id;
}
}
} else {
$file_id = $file->id;
}
$file_redir = File_redirection::staticGet('url', $short_url);
if (empty($file_redir)) {
$file_redir = new File_redirection();
$file_redir->url = $short_url;
$file_redir->file_id = $file_id;
$file_redir->insert();
}
return $short_url;
}
return null;
}
示例4: processPost
/**
* Process an incoming post activity from this remote feed.
* @param Activity $activity
* @param string $method 'push' or 'salmon'
* @return mixed saved Notice or false
* @todo FIXME: Break up this function, it's getting nasty long
*/
public function processPost($activity, $method)
{
$notice = null;
$oprofile = $this->checkAuthorship($activity);
if (empty($oprofile)) {
return null;
}
// It's not always an ActivityObject::NOTE, but... let's just say it is.
$note = $activity->objects[0];
// The id URI will be used as a unique identifier for for the notice,
// protecting against duplicate saves. It isn't required to be a URL;
// tag: URIs for instance are found in Google Buzz feeds.
$sourceUri = $note->id;
$dupe = Notice::staticGet('uri', $sourceUri);
if ($dupe) {
common_log(LOG_INFO, "OStatus: ignoring duplicate post: {$sourceUri}");
return $dupe;
}
// We'll also want to save a web link to the original notice, if provided.
$sourceUrl = null;
if ($note->link) {
$sourceUrl = $note->link;
} else {
if ($activity->link) {
$sourceUrl = $activity->link;
} else {
if (preg_match('!^https?://!', $note->id)) {
$sourceUrl = $note->id;
}
}
}
// Use summary as fallback for content
if (!empty($note->content)) {
$sourceContent = $note->content;
} else {
if (!empty($note->summary)) {
$sourceContent = $note->summary;
} else {
if (!empty($note->title)) {
$sourceContent = $note->title;
} else {
// @todo FIXME: Fetch from $sourceUrl?
// TRANS: Client exception. %s is a source URI.
throw new ClientException(sprintf(_m('No content for notice %s.'), $sourceUri));
}
}
}
// Get (safe!) HTML and text versions of the content
$rendered = $this->purify($sourceContent);
$content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8');
$shortened = common_shorten_links($content);
// If it's too long, try using the summary, and make the
// HTML an attachment.
$attachment = null;
if (Notice::contentTooLong($shortened)) {
$attachment = $this->saveHTMLFile($note->title, $rendered);
$summary = html_entity_decode(strip_tags($note->summary), ENT_QUOTES, 'UTF-8');
if (empty($summary)) {
$summary = $content;
}
$shortSummary = common_shorten_links($summary);
if (Notice::contentTooLong($shortSummary)) {
$url = common_shorten_url($sourceUrl);
$shortSummary = substr($shortSummary, 0, Notice::maxContent() - (mb_strlen($url) + 2));
$content = $shortSummary . ' ' . $url;
// We mark up the attachment link specially for the HTML output
// so we can fold-out the full version inline.
// @todo FIXME i18n: This tooltip will be saved with the site's default language
// TRANS: Shown when a notice is longer than supported and/or when attachments are present. At runtime
// TRANS: this will usually be replaced with localised text from StatusNet core messages.
$showMoreText = _m('Show more');
$attachUrl = common_local_url('attachment', array('attachment' => $attachment->id));
$rendered = common_render_text($shortSummary) . '<a href="' . htmlspecialchars($attachUrl) . '"' . ' class="attachment more"' . ' title="' . htmlspecialchars($showMoreText) . '">' . '…' . '</a>';
}
}
$options = array('is_local' => Notice::REMOTE, 'url' => $sourceUrl, 'uri' => $sourceUri, 'rendered' => $rendered, 'replies' => array(), 'groups' => array(), 'peopletags' => array(), 'tags' => array(), 'urls' => array());
// Check for optional attributes...
if (!empty($activity->time)) {
$options['created'] = common_sql_date($activity->time);
}
if ($activity->context) {
// Any individual or group attn: targets?
$replies = $activity->context->attention;
$options['groups'] = $this->filterReplies($oprofile, $replies);
$options['replies'] = $replies;
// Maintain direct reply associations
// @todo FIXME: What about conversation ID?
if (!empty($activity->context->replyToID)) {
$orig = Notice::staticGet('uri', $activity->context->replyToID);
if (!empty($orig)) {
$options['reply_to'] = $orig->id;
}
}
//.........这里部分代码省略.........
示例5: format_status
function format_status($notice)
{
// XXX: Hack to get around PHP cURL's use of @ being a a meta character
$statustxt = preg_replace('/^@/', ' @', $notice->content);
// Convert !groups to #hashes
// XXX: Make this an optional setting?
$statustxt = preg_replace('/(^|\\s)!([A-Za-z0-9]{1,64})/', "\\1#\\2", $statustxt);
if (mb_strlen($statustxt) > 140) {
$noticeUrl = common_shorten_url($notice->uri);
$urlLen = mb_strlen($noticeUrl);
$statustxt = mb_substr($statustxt, 0, 140 - ($urlLen + 3)) . ' … ' . $noticeUrl;
}
return $statustxt;
}
示例6: _userMakeShort
function _userMakeShort($long_url)
{
$short_url = common_shorten_url($long_url);
if (!empty($short_url) && $short_url != $long_url) {
$short_url = (string) $short_url;
// store it
$file = File::staticGet('url', $long_url);
if (empty($file)) {
// Check if the target URL is itself a redirect...
$redir_data = File_redirection::where($long_url);
if (is_array($redir_data)) {
// We haven't seen the target URL before.
// Save file and embedding data about it!
$file = File::saveNew($redir_data, $long_url);
$file_id = $file->id;
if (!empty($redir_data['oembed']['json'])) {
File_oembed::saveNew($redir_data['oembed']['json'], $file_id);
}
} else {
if (is_string($redir_data)) {
// The file is a known redirect target.
$file = File::staticGet('url', $redir_data);
$file_id = $file->id;
}
}
} else {
$file_id = $file->id;
}
$file_redir = File_redirection::staticGet('url', $short_url);
if (empty($file_redir)) {
$file_redir = new File_redirection();
$file_redir->url = $short_url;
$file_redir->file_id = $file_id;
$file_redir->insert();
}
return $short_url;
}
return null;
}
示例7: processPost
/**
* Process an incoming post activity from this remote feed.
* @param Activity $activity
* @param string $method 'push' or 'salmon'
* @return mixed saved Notice or false
* @fixme break up this function, it's getting nasty long
*/
public function processPost($activity, $method)
{
if ($this->isGroup()) {
// A group feed will contain posts from multiple authors.
// @fixme validate these profiles in some way!
$oprofile = self::ensureActorProfile($activity);
if ($oprofile->isGroup()) {
// Groups can't post notices in StatusNet.
common_log(LOG_WARNING, "OStatus: skipping post with group listed as author: {$oprofile->uri} in feed from {$this->uri}");
return false;
}
} else {
$actor = $activity->actor;
if (empty($actor)) {
// OK here! assume the default
} else {
if ($actor->id == $this->uri || $actor->link == $this->uri) {
$this->updateFromActivityObject($actor);
} else {
throw new Exception("Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}");
}
}
$oprofile = $this;
}
// It's not always an ActivityObject::NOTE, but... let's just say it is.
$note = $activity->objects[0];
// The id URI will be used as a unique identifier for for the notice,
// protecting against duplicate saves. It isn't required to be a URL;
// tag: URIs for instance are found in Google Buzz feeds.
$sourceUri = $note->id;
$dupe = Notice::staticGet('uri', $sourceUri);
if ($dupe) {
common_log(LOG_INFO, "OStatus: ignoring duplicate post: {$sourceUri}");
return false;
}
// We'll also want to save a web link to the original notice, if provided.
$sourceUrl = null;
if ($note->link) {
$sourceUrl = $note->link;
} else {
if ($activity->link) {
$sourceUrl = $activity->link;
} else {
if (preg_match('!^https?://!', $note->id)) {
$sourceUrl = $note->id;
}
}
}
// Use summary as fallback for content
if (!empty($note->content)) {
$sourceContent = $note->content;
} else {
if (!empty($note->summary)) {
$sourceContent = $note->summary;
} else {
if (!empty($note->title)) {
$sourceContent = $note->title;
} else {
// @fixme fetch from $sourceUrl?
throw new ClientException("No content for notice {$sourceUri}");
}
}
}
// Get (safe!) HTML and text versions of the content
$rendered = $this->purify($sourceContent);
$content = html_entity_decode(strip_tags($rendered));
$shortened = common_shorten_links($content);
// If it's too long, try using the summary, and make the
// HTML an attachment.
$attachment = null;
if (Notice::contentTooLong($shortened)) {
$attachment = $this->saveHTMLFile($note->title, $rendered);
$summary = html_entity_decode(strip_tags($note->summary));
if (empty($summary)) {
$summary = $content;
}
$shortSummary = common_shorten_links($summary);
if (Notice::contentTooLong($shortSummary)) {
$url = common_shorten_url($sourceUrl);
$shortSummary = substr($shortSummary, 0, Notice::maxContent() - (mb_strlen($url) + 2));
$content = $shortSummary . ' ' . $url;
// We mark up the attachment link specially for the HTML output
// so we can fold-out the full version inline.
$attachUrl = common_local_url('attachment', array('attachment' => $attachment->id));
$rendered = common_render_text($shortSummary) . '<a href="' . htmlspecialchars($attachUrl) . '"' . ' class="attachment more"' . ' title="' . htmlspecialchars(_m('Show more')) . '">' . '…' . '</a>';
}
}
$options = array('is_local' => Notice::REMOTE_OMB, 'url' => $sourceUrl, 'uri' => $sourceUri, 'rendered' => $rendered, 'replies' => array(), 'groups' => array(), 'tags' => array(), 'urls' => array());
// Check for optional attributes...
if (!empty($activity->time)) {
$options['created'] = common_sql_date($activity->time);
}
if ($activity->context) {
//.........这里部分代码省略.........
示例8: format_status
function format_status($notice)
{
// Start with the plaintext source of this notice...
$statustxt = $notice->content;
// Convert !groups to #hashes
// XXX: Make this an optional setting?
$statustxt = preg_replace('/(^|\\s)!([A-Za-z0-9]{1,64})/', "\\1#\\2", $statustxt);
// Twitter still has a 140-char hardcoded max.
if (mb_strlen($statustxt) > 140) {
$noticeUrl = common_shorten_url($notice->uri);
$urlLen = mb_strlen($noticeUrl);
$statustxt = mb_substr($statustxt, 0, 140 - ($urlLen + 3)) . ' … ' . $noticeUrl;
}
return $statustxt;
}
示例9: formatMessage
function formatMessage()
{
// Start with the plaintext source of this notice...
$txt = $this->notice->content;
// Facebook has a 420-char hardcoded max.
if (mb_strlen($statustxt) > 420) {
$noticeUrl = common_shorten_url($this->notice->getUrl());
$urlLen = mb_strlen($noticeUrl);
$txt = mb_substr($statustxt, 0, 420 - ($urlLen + 3)) . ' … ' . $noticeUrl;
}
return $txt;
}
示例10: _userMakeShort
static function _userMakeShort($long_url, User $user = null, $force = false)
{
$short_url = common_shorten_url($long_url, $user, $force);
if (!empty($short_url) && $short_url != $long_url) {
$short_url = (string) $short_url;
// store it
try {
$file = File::getByUrl($long_url);
} catch (NoResultException $e) {
// Check if the target URL is itself a redirect...
$redir = File_redirection::where($long_url);
$file = $redir->getFile();
if (empty($file->id)) {
$file->saveFile();
}
}
// Now we definitely have a File object in $file
try {
$file_redir = File_redirection::getByUrl($short_url);
} catch (NoResultException $e) {
$file_redir = new File_redirection();
$file_redir->urlhash = File::hashurl($short_url);
$file_redir->url = $short_url;
$file_redir->file_id = $file->getID();
$file_redir->insert();
}
return $short_url;
}
return null;
}
示例11: _userMakeShort
function _userMakeShort($long_url)
{
$short_url = common_shorten_url($long_url);
if (!empty($short_url) && $short_url != $long_url) {
$short_url = (string) $short_url;
// store it
$file = File::staticGet('url', $long_url);
if (empty($file)) {
$redir_data = File_redirection::where($long_url);
$file = File::saveNew($redir_data, $long_url);
$file_id = $file->id;
if (!empty($redir_data['oembed']['json'])) {
File_oembed::saveNew($redir_data['oembed']['json'], $file_id);
}
} else {
$file_id = $file->id;
}
$file_redir = File_redirection::staticGet('url', $short_url);
if (empty($file_redir)) {
$file_redir = new File_redirection();
$file_redir->url = $short_url;
$file_redir->file_id = $file_id;
$file_redir->insert();
}
return $short_url;
}
return null;
}