]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
make our own twitter links if Twitter doesn't give us entities
authorEvan Prodromou <evan@status.net>
Fri, 10 Sep 2010 13:10:53 +0000 (09:10 -0400)
committerEvan Prodromou <evan@status.net>
Fri, 10 Sep 2010 13:10:53 +0000 (09:10 -0400)
plugins/TwitterBridge/daemons/twitterstatusfetcher.php

index f1305696b3f59bf83a88cdce5d14c6722f53d9b3..b2bcc22bccf2918a41a0507c8bfbfafd990898fb 100755 (executable)
@@ -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('/(^|\&quot\;|\'|\(|\[|\{|\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 "#<a href='https://twitter.com/search?q=%23{$object->text}' class='hashtag'>{$object->text}</a>";
+        return "#" . self::tagLink($object->text);
     }
 
     function makeMentionLink($object)
     {
-        return "@<a href='http://twitter.com/{$object->screen_name}' title='{$object->name}'>{$object->screen_name}</a>";
+        return "@".self::atLink($object->screen_name, $object->name);
+    }
+
+    static function tagLink($tag)
+    {
+        return "<a href='https://twitter.com/search?q=%23{$tag}' class='hashtag'>{$tag}</a>";
+    }
+
+    static function atLink($screenName, $fullName=null)
+    {
+        if (!empty($fullName)) {
+            return "<a href='http://twitter.com/{$screenName}' title='{$fullName}'>{$screenName}</a>";
+        } else {
+            return "<a href='http://twitter.com/{$screenName}'>{$screenName}</a>";
+        }
     }
 
     function saveStatusMentions($notice, $status)