本文整理汇总了PHP中common_replace_urls_callback函数的典型用法代码示例。如果您正苦于以下问题:PHP common_replace_urls_callback函数的具体用法?PHP common_replace_urls_callback怎么用?PHP common_replace_urls_callback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了common_replace_urls_callback函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onStartNoticeSave
function onStartNoticeSave($notice)
{
// Only run this on local notices
if ($notice->isLocal()) {
$text = $notice->content;
// From /lib/util.php::common_render_text
// We don't want to call it directly since we don't want to
// run common_linkify() on the text
$text = common_remove_unicode_formatting($text);
$text = preg_replace('/[\\x{0}-\\x{8}\\x{b}-\\x{c}\\x{e}-\\x{19}]/', '', $text);
$text = common_replace_urls_callback($text, 'common_linkify');
// Link #hashtags
$rendered = preg_replace_callback('/(^|\\"\\;|\'|\\(|\\[|\\{|\\s+)#([\\pL\\pN_\\-\\.]{1,64})/u', function ($m) {
return "{$m[1]}#" . common_tag_link($m[2]);
}, $text);
// Link @mentions, !mentions, @#mentions
$rendered = common_linkify_mentions($rendered, $notice->getProfile(), $notice->hasParent() ? $notice->getParent() : null);
// Prevent leading #hashtags from becoming headers by adding a backslash
// before the "#", telling markdown to leave it alone
// $repl_rendered = preg_replace('/^#[\pL\pN_\-\.]{1,64}/u', 'replaced!', $rendered);
$repl_rendered = preg_replace('/^#<span class="tag">/u', '\\\\\\0', $rendered);
// Only use the replaced value from above if it returned a success
if ($rendered !== null) {
$rendered = $repl_rendered;
}
// handle Markdown link forms in order not to convert doubly.
$rendered = preg_replace('/\\[([^]]+)\\]\\((<a [^>]+>)([^<]+)<\\/a>\\)/u', '\\2\\1</a>', $rendered);
// Convert Markdown to HTML
$notice->rendered = \Michelf\Markdown::defaultTransform($rendered);
}
return true;
}
示例2: onHandleQueuedNotice
function onHandleQueuedNotice($notice)
{
if (intval($notice->is_local) === Notice::LOCAL_PUBLIC) {
// Try to avoid actually mucking with the
// notice content
$c = $notice->content;
$this->notice = $notice;
if (!$notice->getProfile()->getPref("linkbackplugin", "disable_linkbacks")) {
// Ignoring results
common_replace_urls_callback($c, array($this, 'linkbackUrl'));
}
if ($notice->isRepeat()) {
$repeat = Notice::getByID($notice->repeat_of);
$this->linkbackUrl($repeat->getUrl());
} else {
if (!empty($notice->reply_to)) {
$parent = $notice->getParent();
$this->linkbackUrl($parent->getUrl());
}
}
$replyProfiles = Profile::multiGet('id', $notice->getReplies());
foreach ($replyProfiles->fetchAll('profileurl') as $profileurl) {
$this->linkbackUrl($profileurl);
}
}
return true;
}
示例3: render_text
function render_text($text)
{
$text = common_remove_unicode_formatting($text);
$text = preg_replace('/[\\x{0}-\\x{8}\\x{b}-\\x{c}\\x{e}-\\x{19}]/', '', $text);
$text = common_replace_urls_callback($text, 'common_linkify');
// Link #hashtags
$rendered = preg_replace_callback('/(^|\\"\\;|\'|\\(|\\[|\\{|\\s+)#([\\pL\\pN_\\-\\.]{1,64})/u', function ($m) {
return "{$m[1]}#" . common_tag_link($m[2]);
}, $text);
return $rendered;
}
示例4: onEndNoticeSave
function onEndNoticeSave($notice)
{
if ($notice->is_local == 1) {
// Try to avoid actually mucking with the
// notice content
$c = $notice->content;
$this->notice = $notice;
// Ignoring results
common_replace_urls_callback($c, array($this, 'linkbackUrl'));
}
return true;
}
示例5: common_shorten_links
function common_shorten_links($text)
{
$maxLength = Notice::maxContent();
if ($maxLength == 0 || mb_strlen($text) <= $maxLength) {
return $text;
}
return common_replace_urls_callback($text, array('File_redirection', 'makeShort'));
}
示例6: common_shorten_links
/**
* Find and shorten links in a given chunk of text if it's longer than the
* configured notice content limit (or unconditionally).
*
* Side effects: may save file and file_redirection records for referenced URLs.
*
* Pass the $user option or call $user->shortenLinks($text) to ensure the proper
* user's options are used; otherwise the current web session user's setitngs
* will be used or ur1.ca if there is no active web login.
*
* @param string $text
* @param boolean $always (optional)
* @param User $user (optional)
*
* @return string
*/
function common_shorten_links($text, $always = false, User $user = null)
{
$user = common_current_user();
$maxLength = User_urlshortener_prefs::maxNoticeLength($user);
if ($always || mb_strlen($text) > $maxLength) {
return common_replace_urls_callback($text, array('File_redirection', 'forceShort'), $user);
} else {
return common_replace_urls_callback($text, array('File_redirection', 'makeShort'), $user);
}
}
示例7: common_shorten_links
/**
* Find and shorten links in a given chunk of text if it's longer than the
* configured notice content limit (or unconditionally).
*
* Side effects: may save file and file_redirection records for referenced URLs.
*
* Pass the $user option or call $user->shortenLinks($text) to ensure the proper
* user's options are used; otherwise the current web session user's setitngs
* will be used or ur1.ca if there is no active web login.
*
* @param string $text
* @param boolean $always (optional)
* @param User $user (optional)
*
* @return string
*/
function common_shorten_links($text, $always = false, User $user = null)
{
$maxLength = Notice::maxContent();
if (!$always && ($maxLength == 0 || mb_strlen($text) <= $maxLength)) {
return $text;
}
return common_replace_urls_callback($text, array('File_redirection', 'makeShort'), $user);
}
示例8: onStartNoticeSave
/**
* Hook notice save to prevent blacklisted urls
*
* Throws an exception if there's a blacklisted url in the content.
*
* @param Notice &$notice Notice being saved
*
* @return boolean hook value
*/
function onStartNoticeSave(&$notice)
{
common_replace_urls_callback($notice->content, array($this, 'checkNoticeUrl'));
return true;
}
示例9: linkify
function linkify($status)
{
$text = $status->text;
if (empty($status->entities)) {
$statusId = twitter_id($status);
common_log(LOG_WARNING, "No entities data for {$statusId}; trying to fake up links ourselves.");
$text = common_replace_urls_callback($text, 'common_linkify');
$text = preg_replace('/(^|\\"\\;|\'|\\(|\\[|\\{|\\s+)#([\\pL\\pN_\\-\\.]{1,64})/e', "'\\1#'.TwitterStatusFetcher::tagLink('\\2')", $text);
$text = preg_replace('/(^|\\s+)@([a-z0-9A-Z_]{1,64})/e', "'\\1@'.TwitterStatusFetcher::atLink('\\2')", $text);
return $text;
}
// Move all the entities into order so we can
// replace them and escape surrounding plaintext
// in order
$toReplace = array();
if (!empty($status->entities->urls)) {
foreach ($status->entities->urls as $url) {
$toReplace[$url->indices[0]] = array(self::URL, $url);
}
}
if (!empty($status->entities->hashtags)) {
foreach ($status->entities->hashtags as $hashtag) {
$toReplace[$hashtag->indices[0]] = array(self::HASHTAG, $hashtag);
}
}
if (!empty($status->entities->user_mentions)) {
foreach ($status->entities->user_mentions as $mention) {
$toReplace[$mention->indices[0]] = array(self::MENTION, $mention);
}
}
// sort in forward order by key
ksort($toReplace);
$result = '';
$cursor = 0;
foreach ($toReplace as $part) {
list($type, $object) = $part;
$start = $object->indices[0];
$end = $object->indices[1];
if ($cursor < $start) {
// Copy in the preceding plaintext
$result .= $this->twitEscape(mb_substr($text, $cursor, $start - $cursor));
$cursor = $start;
}
$orig = $this->twitEscape(mb_substr($text, $start, $end - $start));
switch ($type) {
case self::URL:
$linkText = $this->makeUrlLink($object, $orig);
break;
case self::HASHTAG:
$linkText = $this->makeHashtagLink($object, $orig);
break;
case self::MENTION:
$linkText = $this->makeMentionLink($object, $orig);
break;
default:
$linkText = $orig;
continue;
}
$result .= $linkText;
$cursor = $end;
}
$last = $this->twitEscape(mb_substr($text, $cursor));
$result .= $last;
return $result;
}
示例10: saveUrls
/** save all urls in the notice to the db
*
* follow redirects and save all available file information
* (mimetype, date, size, oembed, etc.)
*
* @return void
*/
function saveUrls()
{
if (common_config('attachments', 'process_links')) {
common_replace_urls_callback($this->content, array($this, 'saveUrl'), $this);
}
}
示例11: saveUrls
/** save all urls in the notice to the db
*
* follow redirects and save all available file information
* (mimetype, date, size, oembed, etc.)
*
* @return void
*/
function saveUrls()
{
common_replace_urls_callback($this->content, array($this, 'saveUrl'), $this->id);
}
示例12: common_shorten_links
function common_shorten_links($text)
{
if (mb_strlen($text) <= 140) {
return $text;
}
static $cache = array();
if (isset($cache[$text])) {
return $cache[$text];
}
// \s = not a horizontal whitespace character (since PHP 5.2.4)
return $cache[$text] = common_replace_urls_callback($text, 'common_shorten_link');
}
示例13: linkify
function linkify($status)
{
$text = $status->text;
if (empty($status->entities)) {
common_log(LOG_WARNING, "No entities data for {$status->id}; trying to fake up links ourselves.");
$text = common_replace_urls_callback($text, 'common_linkify');
$text = preg_replace('/(^|\\"\\;|\'|\\(|\\[|\\{|\\s+)#([\\pL\\pN_\\-\\.]{1,64})/e', "'\\1#'.TwitterStatusFetcher::tagLink('\\2')", $text);
$text = preg_replace('/(^|\\s+)@([a-z0-9A-Z_]{1,64})/e', "'\\1@'.TwitterStatusFetcher::atLink('\\2')", $text);
return $text;
}
// Move all the entities into order so we can
// replace them in reverse order and thus
// not mess up their indices
$toReplace = array();
if (!empty($status->entities->urls)) {
foreach ($status->entities->urls as $url) {
$toReplace[$url->indices[0]] = array(self::URL, $url);
}
}
if (!empty($status->entities->hashtags)) {
foreach ($status->entities->hashtags as $hashtag) {
$toReplace[$hashtag->indices[0]] = array(self::HASHTAG, $hashtag);
}
}
if (!empty($status->entities->user_mentions)) {
foreach ($status->entities->user_mentions as $mention) {
$toReplace[$mention->indices[0]] = array(self::MENTION, $mention);
}
}
// sort in reverse order by key
krsort($toReplace);
foreach ($toReplace as $part) {
list($type, $object) = $part;
switch ($type) {
case self::URL:
$linkText = $this->makeUrlLink($object);
break;
case self::HASHTAG:
$linkText = $this->makeHashtagLink($object);
break;
case self::MENTION:
$linkText = $this->makeMentionLink($object);
break;
default:
continue;
}
$text = mb_substr($text, 0, $object->indices[0]) . $linkText . mb_substr($text, $object->indices[1]);
}
return $text;
}