]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge remote branch 'gitorious/0.9.x' into 0.9.x
authorEvan Prodromou <evan@status.net>
Tue, 21 Sep 2010 18:07:48 +0000 (14:07 -0400)
committerEvan Prodromou <evan@status.net>
Tue, 21 Sep 2010 18:07:48 +0000 (14:07 -0400)
1  2 
plugins/TwitterBridge/daemons/twitterstatusfetcher.php

index 181be3dcf3827a7dc812db7ae0b7cdef4af5b763,31129b96d9e452ce63d9e21d7299457dd688a6dc..590fa2954d1ac467c65d2f23a97917a9b1ef59e6
@@@ -62,7 -62,6 +62,6 @@@ require_once INSTALLDIR . '/plugins/Twi
   * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
   * @link     http://status.net/
   */
  class TwitterStatusFetcher extends ParallelizingDaemon
  {
      /**
@@@ -87,7 -86,6 +86,6 @@@
       *
       * @return string Name of the daemon.
       */
      function name()
      {
          return ('twitterstatusfetcher.'.$this->_id);
@@@ -99,7 -97,6 +97,6 @@@
       *
       * @return array flinks an array of Foreign_link objects
       */
      function getObjects()
      {
          global $_DB_DATAOBJECT;
      }
  
      function childTask($flink) {
          // Each child ps needs its own DB connection
  
          // Note: DataObject::getDatabaseConnection() creates
          // a new connection if there isn't one already
          $conn = &$flink->getDatabaseConnection();
  
          $this->getTimeline($flink);
  
          // XXX: Couldn't find a less brutal way to blow
          // away a cached connection
          global $_DB_DATAOBJECT;
          unset($_DB_DATAOBJECT['CONNECTIONS']);
      }
          // Reverse to preserve order
  
          foreach (array_reverse($timeline) as $status) {
              // Hacktastic: filter out stuff coming from this StatusNet
              $source = mb_strtolower(common_config('integration', 'source'));
  
              if (preg_match("/$source/", mb_strtolower($status->source))) {
  
              // Don't save it if the user is protected
              // FIXME: save it but treat it as private
              if ($status->user->protected) {
                  continue;
              }
          }
  
          // Okay, record the time we synced with Twitter for posterity
          $flink->last_noticesync = common_sql_now();
          $flink->update();
      }
          $statusUri = $this->makeStatusURI($status->user->screen_name, $status->id);
  
          // check to see if we've already imported the status
          $n2s = Notice_to_status::staticGet('status_id', $status->id);
  
          if (!empty($n2s)) {
          }
  
          // If it's a retweet, save it as a repeat!
          if (!empty($status->retweeted_status)) {
              common_log(LOG_INFO, "Status {$status->id} is a retweet of {$status->retweeted_status->id}.");
              $original = $this->saveStatus($status->retweeted_status);
                  $author = $original->getProfile();
                  // TRANS: Message used to repeat a notice. RT is the abbreviation of 'retweet'.
                  // TRANS: %1$s is the repeated user's name, %2$s is the repeated notice.
-                 $content = sprintf(_('RT @%1$s %2$s'),
+                 $content = sprintf(_m('RT @%1$s %2$s'),
                                     $author->nickname,
                                     $original->content);
  
       *
       * @return string URI
       */
      function makeStatusURI($username, $id)
      {
          return 'http://twitter.com/'
       *
       * @return mixed value the first Profile with that url, or null
       */
      function getProfileByUrl($nickname, $profileurl)
      {
          $profile = new Profile();
       *
       * @return mixed value a matching Notice or null
       */
      function checkDupe($profile, $statusUri)
      {
          $notice = new Notice();
      function ensureProfile($user)
      {
          // check to see if there's already a profile for this user
          $profileurl = 'http://twitter.com/' . $user->screen_name;
          $profile = $this->getProfileByUrl($user->screen_name, $profileurl);
  
              return $profile;
  
          } else {
              common_debug($this->name() . ' - Adding profile and remote profile ' .
                           "for Twitter user: $profileurl.");
  
              $remote_pro = Remote_profile::staticGet('uri', $profileurl);
  
              if (empty($remote_pro)) {
                  $remote_pro = new Remote_profile();
  
                  $remote_pro->id = $id;
          $avatar = $profile->getAvatar($sizes[$size]);
  
          // Delete the avatar, if present
          if ($avatar) {
              $avatar->delete();
          }
              $avatar->height = 48;
              break;
          default:
              // Note: Twitter's big avatars are a different size than
              // StatusNet's (StatusNet's = 96)
              $avatar->width  = 73;
              $avatar->height = 73;
          }
          $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;
          }
  
  
      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)
@@@ -840,4 -801,3 +819,3 @@@ if (have_option('d') || have_option('de
  
  $fetcher = new TwitterStatusFetcher($id, 60, 2, $debug);
  $fetcher->runOnce();