]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/twitter.php
Merge branch 'master' of gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / plugins / TwitterBridge / twitter.php
index bd7f19e71cb9d7198135aaf204df154a6036b235..ceb83b037f23dc714b02fe6cda5b2b6bd3d0c616 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,29 +28,22 @@ require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php';
 
 function add_twitter_user($twitter_id, $screen_name)
 {
-    common_debug("Add Twitter user");
-
-    $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 ($result != false) {
-        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;
@@ -65,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;