コード例 #1
0
ファイル: Nodes.php プロジェクト: radekstepan/Fireside
 private function filterLinkify($text)
 {
     $urls = explode(' ', $text);
     $containsLink = FALSE;
     foreach ($urls as &$link) {
         if (Fari_Filter::isURL($link)) {
             $containsLink = TRUE;
             // do we have a YouTube video?
             // source: http://www.youtube.com/watch?v=nBBMnY7mANg&feature=popular
             // target: <img src="http://img.youtube.com/vi/nBBMnY7mANg/0.jpg" alt="0">
             if (stripos(strtolower($link), 'youtube') !== FALSE) {
                 $url = parse_url($link);
                 parse_str($url[query], $query);
                 // replace link with an image 'boosted' link :)
                 $link = '<a class="youtube" target="_blank" href="' . $link . '"><img src="http://img.youtube.com/vi/' . $query['v'] . '/0.jpg" alt="YouTube"></a>';
             } else {
                 // plain old link
                 $link = '<a target="_blank" href="' . $link . '">' . $link . '</a>';
             }
             // convert so we can insert into DB
             $link = Fari_Escape::html($link);
         }
     }
     if ($containsLink) {
         return implode(' ', $urls);
     } else {
         return $text;
     }
 }
コード例 #2
0
/**
 * Transforms all URLs or e-mail addresses within the string into clickable HTML links.
 * @param string $string email or url
 * @param string $ref reference to the link (optional)
 * @param string $type link/email (optional)
 */
function autoLink($string, $ref = NULL, $type = NULL)
{
    // target reference
    if (!isset($ref)) {
        $ref = $string;
    }
    // it's an email
    if ($type == 'email' || Fari_Filter::isEmail($string)) {
        echo "<a href=\"mailto:{$string}\">{$ref}</a>";
        // or a link
    } else {
        // formed URL, just echo as a link
        if (Fari_Filter::isURL($string)) {
            echo '<a href="' . $string . '">' . $ref . '</a>';
        } else {
            // prefix with BASEPATH so we can link internally
            if (substr($string, 0, 1) !== '/') {
                $string = "/{$string}";
            }
            echo '<a href="' . WWW_DIR . $string . '">' . $ref . '</a>';
        }
    }
}