当前位置: 首页>>代码示例>>PHP>>正文


PHP common_replace_urls_callback函数代码示例

本文整理汇总了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('/(^|\\&quot\\;|\'|\\(|\\[|\\{|\\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;
 }
开发者ID:shnarazk,项目名称:gs-markdown,代码行数:32,代码来源:MarkdownPlugin.php

示例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;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:27,代码来源:LinkbackPlugin.php

示例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('/(^|\\&quot\\;|\'|\\(|\\[|\\{|\\s+)#([\\pL\\pN_\\-\\.]{1,64})/u', function ($m) {
         return "{$m[1]}#" . common_tag_link($m[2]);
     }, $text);
     return $rendered;
 }
开发者ID:bashrc,项目名称:gs-markdown,代码行数:11,代码来源:MarkdownPlugin.php

示例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;
 }
开发者ID:Br3nda,项目名称:laconica,代码行数:12,代码来源:LinkbackPlugin.php

示例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'));
}
开发者ID:himmelex,项目名称:NTW,代码行数:8,代码来源:util.php

示例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);
    }
}
开发者ID:harriewang,项目名称:InnertieWebsite,代码行数:26,代码来源:util.php

示例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);
}
开发者ID:microcosmx,项目名称:experiments,代码行数:24,代码来源:util.php

示例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;
 }
开发者ID:harriewang,项目名称:InnertieWebsite,代码行数:14,代码来源:BlacklistPlugin.php

示例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('/(^|\\&quot\\;|\'|\\(|\\[|\\{|\\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;
 }
开发者ID:harriewang,项目名称:InnertieWebsite,代码行数:65,代码来源:twitterimport.php

示例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);
     }
 }
开发者ID:a780201,项目名称:gnu-social,代码行数:13,代码来源:Notice.php

示例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);
 }
开发者ID:Br3nda,项目名称:statusnet-debian,代码行数:11,代码来源:Notice.php

示例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');
}
开发者ID:Br3nda,项目名称:laconica,代码行数:12,代码来源:util.php

示例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('/(^|\\&quot\\;|\'|\\(|\\[|\\{|\\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;
 }
开发者ID:Br3nda,项目名称:statusnet-debian,代码行数:50,代码来源:twitterstatusfetcher.php


注:本文中的common_replace_urls_callback函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。