Get rid of t.co links for notice's text version. Usefull for client using API. Complements merge-request #205 by @mmn

This commit is contained in:
Jean Baptiste Favre 2013-06-14 23:27:24 +02:00
parent 108aa5c467
commit 80da81ba14

View File

@ -172,8 +172,8 @@ class TwitterImport
$notice->is_local = Notice::GATEWAY; $notice->is_local = Notice::GATEWAY;
$notice->content = html_entity_decode($status->text, ENT_QUOTES, 'UTF-8'); $notice->content = html_entity_decode($this->linkify($status, FALSE), ENT_QUOTES, 'UTF-8');
$notice->rendered = $this->linkify($status); $notice->rendered = $this->linkify($status, TRUE);
if (Event::handle('StartNoticeSave', array(&$notice))) { if (Event::handle('StartNoticeSave', array(&$notice))) {
@ -540,7 +540,7 @@ class TwitterImport
const HASHTAG = 2; const HASHTAG = 2;
const MENTION = 3; const MENTION = 3;
function linkify($status) function linkify($status, $html = FALSE)
{ {
$text = $status->text; $text = $status->text;
@ -596,13 +596,21 @@ class TwitterImport
$orig = $this->twitEscape(mb_substr($text, $start, $end - $start)); $orig = $this->twitEscape(mb_substr($text, $start, $end - $start));
switch($type) { switch($type) {
case self::URL: case self::URL:
$linkText = $this->makeUrlLink($object, $orig); $linkText = $this->makeUrlLink($object, $orig, $html);
break; break;
case self::HASHTAG: case self::HASHTAG:
if ($html) {
$linkText = $this->makeHashtagLink($object, $orig); $linkText = $this->makeHashtagLink($object, $orig);
}else{
$linkText = $orig;
}
break; break;
case self::MENTION: case self::MENTION:
if ($html) {
$linkText = $this->makeMentionLink($object, $orig); $linkText = $this->makeMentionLink($object, $orig);
}else{
$linkText = $orig;
}
break; break;
default: default:
$linkText = $orig; $linkText = $orig;
@ -630,9 +638,13 @@ class TwitterImport
return htmlspecialchars(html_entity_decode($str, ENT_COMPAT, 'UTF-8')); return htmlspecialchars(html_entity_decode($str, ENT_COMPAT, 'UTF-8'));
} }
function makeUrlLink($object, $orig) function makeUrlLink($object, $orig, $html)
{ {
if ($html) {
return '<a href="'.htmlspecialchars($object->expanded_url).'" class="extlink">'.htmlspecialchars($object->display_url).'</a>'; return '<a href="'.htmlspecialchars($object->expanded_url).'" class="extlink">'.htmlspecialchars($object->display_url).'</a>';
}else{
return htmlspecialchars($object->expanded_url);
}
} }
function makeHashtagLink($object, $orig) function makeHashtagLink($object, $orig)