function twitter_parse_tags($input, $entities = false, $id = false, $source = NULL) { // Filter. if ($id && substr($_GET["q"], 0, 6) !== "status" && setting_fetch('filtero', 'no') == 'yes' && twitter_timeline_filter($input . ' ' . $source)) { return "<a href='" . BASE_URL . "status/{$id}' style='text-decoration:none;'><small>[" . __("Tweet Filtered") . "]</small></a>"; } // Linebreaks. Some clients insert \n for formatting. $out = nl2br($input); // Use the Entities to replace hyperlink URLs if ($entities && $entities->urls) { foreach ($entities->urls as $urls) { if ($urls->expanded_url != "") { $display_url = $urls->expanded_url; } else { $display_url = $urls->url; } $url_detect = parse_url($display_url); if (isset($url_detect["scheme"])) { $link_html = theme('external_link', $display_url); $url = $urls->url; // Replace all URLs *UNLESS* they have already been linked (for example to an image) $pattern = '#((?<!href\\=(\'|\\"))' . preg_quote($url, '#') . ')#i'; $out = preg_replace($pattern, $link_html, $out); } } } else { // If Entities haven't been returned, use Autolink // Create an array containing all URLs $urls = Twitter_Extractor::create($input)->extractURLs(); // Hyperlink the URLs $out = Twitter_Autolink::create($out)->addLinksToURLs(); // Hyperlink the # $out = Twitter_Autolink::create($out)->setTarget('')->addLinksToHashtags(); } // Hyperlink the @ and lists $out = Twitter_Autolink::create($out)->setTarget('')->addLinksToUsernamesAndLists(); // Hyperlink the # $out = Twitter_Autolink::create($out)->setTarget('')->addLinksToHashtags(); //Return the completed string return $out; }
function twitter_parse_tags($input, $entities = false, $id = false) { // Filter if ($id && substr($_GET["q"], 0, 6) !== "status" && setting_fetch('filtero', 'no') == 'yes' && twitter_timeline_filter($input)) { return "<a href='status/{$id}' class='filter'><span class='texts'>[Tweet Filtered]</span></a>"; } $out = $input; //Linebreaks. Some clients insert \n for formatting. $out = nl2br($out); // Use the Entities to replace hyperlink URLs // http://dev.twitter.com/pages/tweet_entities if ($entities) { if ($entities->urls) { foreach ($entities->urls as $urls) { if ($urls->display_url != "") { $display_url = $urls->display_url; } else { $display_url = $urls->url; } $expanded_url = $urls->expanded_url ? $urls->expanded_url : $urls->url; $expanded_url = add_http($expanded_url); $lurl = setting_fetch('longurl') == 'yes' && LONG_URL == 'ON' ? long_url($expanded_url) : $expanded_url; if (setting_fetch('gwt') == 'on') { $encoded = urlencode($lurl); $link = "http://google.com/gwt/n?u={$encoded}"; } else { $link = $lurl; } $atext = link_trans($display_url); $link_html = '<a href="' . $link . '" rel="external nofollow noreferrer">' . $atext . '</a>'; $url = $urls->url; // Replace all URLs *UNLESS* they have already been linked (for example to an image) $pattern = '#((?<!href\\=(\'|\\"))' . preg_quote($url, '#') . ')#i'; $out = preg_replace($pattern, $link_html, $out); } } if ($entities->hashtags) { foreach ($entities->hashtags as $hashtag) { $text = $hashtag->text; $pattern = '/(^|\\s)([##]+)(' . $text . ')/iu'; $link_html = ' <a href="hash/' . $text . '" rel="external nofollow tag noreferrer" class="hashtag">#' . $text . '</a> '; $out = preg_replace($pattern, $link_html, $out, 1); } } } else { // If Entities haven't been returned (usually because of search or a bio) use Autolink // Create an array containing all URLs $urls = Twitter_Extractor::create($input)->extractURLs(); // Hyperlink the URLs if (setting_fetch('gwt') == 'on') { foreach ($urls as $url) { if (setting_fetch('longurl') == 'yes' && LONG_URL == 'ON') { $lurl = long_url($url); } else { $lurl = $url; } $encoded = urlencode($lurl); $atext = link_trans($lurl); $out = str_replace($url, "<a href='http://google.com/gwt/n?u={$encoded}' rel='external nofollow noreferrer'>{$atext}</a>", $out); } } else { $out = Twitter_Autolink::create($out)->setTarget('')->setTag('')->addLinksToURLs(); foreach ($urls as $url) { if (setting_fetch('longurl') == 'yes' && LONG_URL == 'ON') { $lurl = long_url($url); $out = str_replace('href="' . $url . '"', 'href="' . $lurl . '"', $out); } else { $lurl = $url; } $atext = link_trans($lurl); $out = str_replace(">{$url}</a>", ">{$atext}</a>", $out); } } // Hyperlink the # $out = Twitter_Autolink::create($out)->setTarget('')->addLinksToHashtags(); } // Hyperlink the @ and lists $out = Twitter_Autolink::create($out)->setTarget('')->setTag('')->addLinksToUsernamesAndLists(); // Emails $tok = strtok($out, " \n\t\n\r"); // Tokenise the string by whitespace while ($tok !== false) { // Go through all the tokens $at = stripos($tok, "@"); // Does the string contain an "@"? if ($at && $at > 0) { // @ is in the string & isn't the first character $tok = trim($tok, "?.,!\"\\'"); // Remove any trailing punctuation if (filter_var($tok, FILTER_VALIDATE_EMAIL)) { // Use the internal PHP email validator $email = $tok; $out = str_replace($email, "<a href=\"mailto:{$email}\">{$email}</a>", $out); // Create the mailto: link } } $tok = strtok(" \n\t\n\r"); // Move to the next token } //Return the completed string return $out; }