]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/twitter.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / plugins / TwitterBridge / twitter.php
index de30d9ebf1d8999fcc7a23967e3e091ca3aaded6..2805b3ab565d99e2c68caf9f49310119e9b3f054 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
+ * Copyright (C) 2008-2010 StatusNet, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -28,28 +28,22 @@ require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php';
 
 function add_twitter_user($twitter_id, $screen_name)
 {
-
-    $new_uri = 'http://twitter.com/' . $screen_name;
-
     // Clear out any bad old foreign_users with the new user's legit URL
     // This can happen when users move around or fakester accounts get
     // repoed, and things like that.
 
-    $luser = new Foreign_user();
-    $luser->uri = $new_uri;
-    $luser->service = TWITTER_SERVICE;
-    $result = $luser->delete();
+    $luser = Foreign_user::getForeignUser($twitter_id, TWITTER_SERVICE);
 
-    if (empty($result)) {
-        common_log(LOG_WARNING,
-            "Twitter bridge - removed invalid Twitter user squatting on uri: $new_uri");
+    if (!empty($luser)) {
+        $result = $luser->delete();
+        if ($result != false) {
+            common_log(
+                LOG_INFO,
+                "Twitter bridge - removed old Twitter user: $screen_name ($twitter_id)."
+            );
+        }
     }
 
-    $luser->free();
-    unset($luser);
-
-    // Otherwise, create a new Twitter user
-
     $fuser = new Foreign_user();
 
     $fuser->nickname = $screen_name;
@@ -64,7 +58,8 @@ function add_twitter_user($twitter_id, $screen_name)
             "Twitter bridge - failed to add new Twitter user: $twitter_id - $screen_name.");
         common_log_db_error($fuser, 'INSERT', __FILE__);
     } else {
-        common_debug("Twitter bridge - Added new Twitter user: $screen_name ($twitter_id).");
+        common_log(LOG_INFO,
+                   "Twitter bridge - Added new Twitter user: $screen_name ($twitter_id).");
     }
 
     return $result;
@@ -93,9 +88,9 @@ function save_twitter_user($twitter_id, $screen_name)
                                          $screen_name,
                                          $oldname));
         }
-
-        return add_twitter_user($twitter_id, $screen_name);
     }
+
+    return add_twitter_user($twitter_id, $screen_name);
 }
 
 function is_twitter_bound($notice, $flink) {
@@ -257,8 +252,17 @@ function format_status($notice)
     $statustxt = preg_replace('/^@/', ' @', $notice->content);
 
     // Convert !groups to #hashes
+
+    // XXX: Make this an optional setting?
+
     $statustxt = preg_replace('/(^|\s)!([A-Za-z0-9]{1,64})/', "\\1#\\2", $statustxt);
 
+    if (mb_strlen($statustxt) > 140) {
+        $noticeUrl = common_shorten_url($notice->uri);
+        $urlLen = mb_strlen($noticeUrl);
+        $statustxt = mb_substr($statustxt, 0, 140 - ($urlLen + 3)) . ' … ' . $noticeUrl;
+    }
+
     return $statustxt;
 }
 
@@ -269,7 +273,7 @@ function remove_twitter_link($flink)
     common_log(LOG_INFO, 'Removing Twitter bridge Foreign link for ' .
                "user $user->nickname (user id: $user->id).");
 
-    $result = $flink->delete();
+    $result = $flink->safeDelete();
 
     if (empty($result)) {
         common_log(LOG_ERR, 'Could not remove Twitter bridge ' .