From deb8f2a38b08bfe410d127d4779ced5433f67876 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 10 Sep 2010 09:10:53 -0400 Subject: [PATCH] make our own twitter links if Twitter doesn't give us entities --- .../daemons/twitterstatusfetcher.php | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/plugins/TwitterBridge/daemons/twitterstatusfetcher.php b/plugins/TwitterBridge/daemons/twitterstatusfetcher.php index f1305696b3..b2bcc22bcc 100755 --- a/plugins/TwitterBridge/daemons/twitterstatusfetcher.php +++ b/plugins/TwitterBridge/daemons/twitterstatusfetcher.php @@ -713,6 +713,10 @@ class TwitterStatusFetcher extends ParallelizingDaemon $text = $status->text; if (empty($status->entities)) { + common_log(LOG_WARNING, "No entities data for {$status->id}; trying to fake up links ourselves."); + $text = common_replace_urls_callback($text, 'common_linkify'); + $text = preg_replace('/(^|\"\;|\'|\(|\[|\{|\s+)#([\pL\pN_\-\.]{1,64})/e', "'\\1#'.TwitterStatusFetcher::tagLink('\\2')", $text); + $text = preg_replace('/(?:^|\s+)@([a-z0-9A-Z_]{1,64})/e', "'\\1@'.TwitterStatusFetcher::atLink('\\2')", $text); return $text; } @@ -771,12 +775,26 @@ class TwitterStatusFetcher extends ParallelizingDaemon function makeHashtagLink($object) { - return "#{$object->text}"; + return "#" . self::tagLink($object->text); } function makeMentionLink($object) { - return "@{$object->screen_name}"; + return "@".self::atLink($object->screen_name, $object->name); + } + + static function tagLink($tag) + { + return "{$tag}"; + } + + static function atLink($screenName, $fullName=null) + { + if (!empty($fullName)) { + return "{$screenName}"; + } else { + return "{$screenName}"; + } } function saveStatusMentions($notice, $status)