]> git.mxchange.org Git - friendica-addons.git/blobdiff - fbpost/fbpost.php
Added function "bb_CleanPictureLinks" ro all connectors
[friendica-addons.git] / fbpost / fbpost.php
index 092d5f70407b1ea1ddd9c58e19cc367e32682b00..3b064a56a9ab308e52aa63dda8b7ac77fdfe8b61 100644 (file)
@@ -293,8 +293,8 @@ function fbpost_content(&$a) {
 function fbpost_plugin_settings(&$a,&$b) {
 
        $b .= '<div class="settings-block">';
-       $b .= '<h3>' . t('Facebook Post Settings') . '</h3>';
-       $b .= '<a href="fbpost">' . t('Facebook Post Settings') . '</a><br />';
+       //$b .= '<h3>' . t('Facebook Post Settings') . '</h3>';
+       $b .= '<a href="fbpost"><h3>' . t('Facebook Post Settings') . '</a></h3>';
        $b .= '</div>';
 
 }
@@ -363,6 +363,8 @@ function fbpost_createmsg($b) {
        require_once("include/bbcode.php");
        require_once("include/html2plain.php");
 
+       $b['body'] = bb_CleanPictureLinks($b['body']);
+
        // Looking for the first image
        $image = '';
        if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$b['body'],$matches))
@@ -632,6 +634,7 @@ function fbpost_post_hook(&$a,&$b) {
 
                                logger('fbpost_post_hook: original msg=' . $msg, LOGGER_DATA);
 
+                               // To-Do: if it is a reply, then only do a simple bbcode2plain conversion
                                $msgarr = fbpost_createmsg($b);
                                $msg = $msgarr["msg"];
                                $link = $msgarr["link"];
@@ -762,9 +765,17 @@ function fbpost_post_hook(&$a,&$b) {
                                                        intval($b['id']),
                                                        intval($b['id'])
                                                );
-                                       }
-                                       else {
-                                               if(! $likes) {
+                                       } else {
+                                               // Sometimes posts are accepted from facebook although it telling an error
+                                               // This leads to endless comment flooding.
+
+                                               // If it is a special kind of failure the post was receiced
+                                               // Although facebook said it wasn't received ...
+                                               if (!$likes AND (($retj->error->type != "OAuthException") OR ($retj->error->code != 2)) AND ($x <> "")) {
+                                                       $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($b['uid']));
+                                                       if (count($r))
+                                                               $a->contact = $r[0]["id"];
+
                                                        $s = serialize(array('url' => $url, 'item' => $b['id'], 'post' => $postvars));
                                                        require_once('include/queue_fn.php');
                                                        add_to_queue($a->contact,NETWORK_FACEBOOK,$s);
@@ -867,14 +878,17 @@ function fbpost_queue_hook(&$a,&$b) {
                if($x['network'] !== NETWORK_FACEBOOK)
                        continue;
 
-               logger('facebook_queue: run');
+               logger('fbpost_queue_hook: run');
 
                $r = q("SELECT `user`.* FROM `user` LEFT JOIN `contact` on `contact`.`uid` = `user`.`uid` 
                        WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1",
                        intval($x['cid'])
                );
-               if(! count($r))
+               if(! count($r)) {
+                       logger('fbpost_queue_hook: no user found for entry '.print_r($x, true));
+                       update_queue_time($x['id']);
                        continue;
+               }
 
                $user = $r[0];
 
@@ -903,12 +917,24 @@ function fbpost_queue_hook(&$a,&$b) {
                                        );
                                        logger('fbpost_queue_hook: success: ' . $j);
                                        remove_queue_item($x['id']);
-                               }
-                               else {
+                               } else {
                                        logger('fbpost_queue_hook: failed: ' . $j);
-                                       update_queue_time($x['id']);
+
+                                       // If it is a special kind of failure the post was receiced
+                                       // Although facebook said it wasn't received ...
+                                       $ret = json_decode($j);
+                                       if (($ret->error->type != "OAuthException") OR ($ret->error->code != 2) AND ($j <> ""))
+                                               update_queue_time($x['id']);
+                                       else
+                                               logger('fbpost_queue_hook: Not requeued, since it seems to be received');
                                }
+                       } else {
+                               logger('fbpost_queue_hook: No fb_post or fb_token.');
+                               update_queue_time($x['id']);
                        }
+               } else {
+                       logger('fbpost_queue_hook: No appid or secret.');
+                       update_queue_time($x['id']);
                }
        }
 }
@@ -1086,7 +1112,7 @@ function fbpost_fetchwall($a, $uid) {
                        $_REQUEST["body"] .= "[class=type-".$type."]";
 
                if ($content)
-                       $_REQUEST["body"] .= $content;
+                       $_REQUEST["body"] .= trim($content);
 
                if ($quote)
                        $_REQUEST["body"] .= "\n[quote]".$quote."[/quote]";