]> git.mxchange.org Git - friendica-addons.git/commitdiff
Handling of empty messages improved. They weren't posted.
authorMichael Vogel <icarus@dabo.de>
Sun, 1 Apr 2012 11:44:39 +0000 (13:44 +0200)
committerMichael Vogel <icarus@dabo.de>
Sun, 1 Apr 2012 11:44:39 +0000 (13:44 +0200)
facebook/facebook.php

index a3d8a5b29e7b83adc0c414ece50cd21a47f6fa36..bc492f683e9360cffaf9631e808c359a13966d2f 100755 (executable)
@@ -883,9 +883,12 @@ function facebook_post_hook(&$a,&$b) {
                                }
 
                                $link = '';
+                               $linkname = '';
                                // look for bookmark-bbcode and handle it with priority
-                               if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches))
+                               if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches)) {
                                        $link = $matches[1];
+                                       $linkname = $matches[2];
+                               }
 
                                // If there is no bookmark element then take the first link
                                if ($link == '') {
@@ -893,11 +896,12 @@ function facebook_post_hook(&$a,&$b) {
                                        if (sizeof($links) > 0) {
                                                reset($links);
                                                $link = current($links);
-                                               /*if (strlen($msg."\n".$link) <= FACEBOOK_MAXPOSTLEN)
-                                                       $msg .= "\n".$link;*/
                                        }
                                }
 
+                               // Remove trailing and leading spaces
+                               $msg = trim($msg);
+
                                // Since facebook increased the maxpostlen massively this never should happen again :)
                                if (strlen($msg) > FACEBOOK_MAXPOSTLEN) {
                                        $shortlink = "";
@@ -917,7 +921,18 @@ function facebook_post_hook(&$a,&$b) {
                                        $msg .= '... ' . $shortlink;
                                }
 
-                               if(!strlen($msg) and !strlen($link) and !strlen($image))
+                               // Fallback - if message is empty
+                               if(!strlen($msg))
+                                       $msg = $linkname;
+
+                               if(!strlen($msg))
+                                       $msg = $link;
+
+                               if(!strlen($msg))
+                                       $msg = $image;
+
+                               // If there is nothing to post then exit
+                               if(!strlen($msg))
                                        return;
 
                                logger('Facebook post: msg=' . $msg, LOGGER_DATA);