]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/FacebookBridge/lib/facebookclient.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / FacebookBridge / lib / facebookclient.php
index 26e21cbd6e1daf8642755938e9866ede7e87e6bd..5faad5dfb767f009606311147d935408a6a57dce 100644 (file)
@@ -66,13 +66,12 @@ class Facebookclient
         $this->notice = $notice;
 
         $profile_id = $profile ? $profile->id : $notice->profile_id;
-        $this->flink = Foreign_link::getByUserID(
-            $profile_id,
-            FACEBOOK_SERVICE
-        );
-
-        if (!empty($this->flink)) {
+        try {
+            $this->flink = Foreign_link::getByUserID($profile_id, FACEBOOK_SERVICE);
             $this->user = $this->flink->getUser();
+        } catch (NoResultException $e) {
+            // at least $this->flink could've gotten set to something,
+            // but the logic that was here before didn't care, so let's not care either
         }
     }
 
@@ -628,7 +627,7 @@ class Facebookclient
 
         // Facebook has a 420-char hardcoded max.
         if (mb_strlen($statustxt) > 420) {
-            $noticeUrl = common_shorten_url($this->notice->uri);
+            $noticeUrl = common_shorten_url($this->notice->getUrl());
             $urlLen = mb_strlen($noticeUrl);
             $txt = mb_substr($statustxt, 0, 420 - ($urlLen + 3)) . ' … ' . $noticeUrl;
         }
@@ -651,9 +650,10 @@ class Facebookclient
 
         foreach($attachments as $attachment)
         {
-            if($enclosure = $attachment->getEnclosure()){
+            try {
+                $enclosure = $attachment->getEnclosure();
                 $fbmedia = $this->getFacebookMedia($enclosure);
-            }else{
+            } catch (ServerException $e) {
                 $fbmedia = $this->getFacebookMedia($attachment);
             }
             if($fbmedia){
@@ -897,7 +897,7 @@ class Facebookclient
      */
     static function facebookStatusId($notice)
     {
-        $n2i = Notice_to_item::staticGet('notice_id', $notice->id);
+        $n2i = Notice_to_item::getKV('notice_id', $notice->id);
 
         if (empty($n2i)) {
             return null;
@@ -917,12 +917,9 @@ class Facebookclient
     static function addFacebookUser($fbuser)
     {
         // remove any existing, possibly outdated, record
-        $luser = Foreign_user::getForeignUser($fbuser->id, FACEBOOK_SERVICE);
-
-        if (!empty($luser)) {
-
-            $result = $luser->delete();
-
+        try {
+            $fuser = Foreign_user::getForeignUser($fbuser->id, FACEBOOK_SERVICE);
+            $result = $fuser->delete();
             if ($result != false) {
                 common_log(
                     LOG_INFO,
@@ -934,6 +931,8 @@ class Facebookclient
                     __FILE__
                 );
             }
+        } catch (NoResultException $e) {
+            // no old foreign users exist for this id
         }
 
         $fuser = new Foreign_user();
@@ -979,7 +978,7 @@ class Facebookclient
      */
     function streamRemove()
     {
-        $n2i = Notice_to_item::staticGet('notice_id', $this->notice->id);
+        $n2i = Notice_to_item::getKV('notice_id', $this->notice->id);
 
         if (!empty($this->flink) && !empty($n2i)) {
             try {
@@ -1034,7 +1033,7 @@ class Facebookclient
      */
     function like()
     {
-        $n2i = Notice_to_item::staticGet('notice_id', $this->notice->id);
+        $n2i = Notice_to_item::getKV('notice_id', $this->notice->id);
 
         if (!empty($this->flink) && !empty($n2i)) {
             try {
@@ -1085,7 +1084,7 @@ class Facebookclient
      */
     function unLike()
     {
-        $n2i = Notice_to_item::staticGet('notice_id', $this->notice->id);
+        $n2i = Notice_to_item::getKV('notice_id', $this->notice->id);
 
         if (!empty($this->flink) && !empty($n2i)) {
             try {