[TwitterBridge] Convert plain text URLs into HTML hyperlinks (#1627)
This commit is contained in:
parent
07c71b3b36
commit
25cff9c07b
1 changed files with 30 additions and 2 deletions
|
@ -235,9 +235,37 @@ EOD
|
||||||
// extract tweet timestamp
|
// extract tweet timestamp
|
||||||
$item['timestamp'] = $tweet->created_at;
|
$item['timestamp'] = $tweet->created_at;
|
||||||
|
|
||||||
|
// Convert plain text URLs into HTML hyperlinks
|
||||||
|
$cleanedTweet = $tweet->full_text;
|
||||||
|
$foundUrls = false;
|
||||||
|
|
||||||
|
if (isset($tweet->entities->media)) {
|
||||||
|
foreach($tweet->entities->media as $media) {
|
||||||
|
$cleanedTweet = str_replace($media->url,
|
||||||
|
'<a href="' . $media->expanded_url . '">' . $media->display_url . '</a>',
|
||||||
|
$cleanedTweet);
|
||||||
|
$foundUrls = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($tweet->entities->urls)) {
|
||||||
|
foreach($tweet->entities->urls as $url) {
|
||||||
|
$cleanedTweet = str_replace($url->url,
|
||||||
|
'<a href="' . $url->expanded_url . '">' . $url->display_url . '</a>',
|
||||||
|
$cleanedTweet);
|
||||||
|
$foundUrls = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($foundUrls === false) {
|
||||||
|
// fallback to regex'es
|
||||||
|
$reg_ex = '/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/';
|
||||||
|
if(preg_match($reg_ex, $tweet->full_text, $url)) {
|
||||||
|
$cleanedTweet = preg_replace($reg_ex,
|
||||||
|
"<a href='{$url[0]}' target='_blank'>{$url[0]}</a> ",
|
||||||
|
$cleanedTweet);
|
||||||
|
}
|
||||||
|
}
|
||||||
// generate the title
|
// generate the title
|
||||||
$item['title'] = $tweet->full_text;
|
$item['title'] = strip_tags($cleanedTweet);
|
||||||
$cleanedTweet = $tweet->full_text;
|
|
||||||
|
|
||||||
// Add avatar
|
// Add avatar
|
||||||
$picture_html = '';
|
$picture_html = '';
|
||||||
|
|
Loading…
Reference in a new issue