Beispiel #1
0
function common_linkify_mentions($text, $notice)
{
    $mentions = common_find_mentions($text, $notice);
    // We need to go through in reverse order by position,
    // so our positions stay valid despite our fudging with the
    // string!
    $points = array();
    foreach ($mentions as $mention) {
        $points[$mention['position']] = $mention;
    }
    krsort($points);
    foreach ($points as $position => $mention) {
        $linkText = common_linkify_mention($mention);
        $text = substr_replace($text, $linkText, $position, mb_strlen($mention['text']));
    }
    return $text;
}
Beispiel #2
0
/**
 * Finds @-mentions within the partially-rendered text section and
 * turns them into live links.
 *
 * Should generally not be called except from common_render_content().
 *
 * @param string    $text   partially-rendered HTML
 * @param Profile   $author the Profile that is composing the current notice
 * @param Notice    $parent the Notice this is sent in reply to, if any
 * @return string partially-rendered HTML
 */
function common_linkify_mentions($text, Profile $author, Notice $parent = null)
{
    $mentions = common_find_mentions($text, $author, $parent);
    // We need to go through in reverse order by position,
    // so our positions stay valid despite our fudging with the
    // string!
    $points = array();
    foreach ($mentions as $mention) {
        $points[$mention['position']] = $mention;
    }
    krsort($points);
    foreach ($points as $position => $mention) {
        $linkText = common_linkify_mention($mention);
        $text = substr_replace($text, $linkText, $position, $mention['length']);
    }
    return $text;
}