]> git.mxchange.org Git - friendica-addons.git/blobdiff - buffer/buffer.php
Merge pull request #408 from tobiasd/2017ß320-pledgie
[friendica-addons.git] / buffer / buffer.php
index 595dba43d9fcce41ab84bf9d63e8e5416e98280b..89000c1ff8772b7a88cda8dccdd288bd0ea12420 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * Name: Buffer Post Connector
- * Description: Post to Buffer (Linkedin, App.net, Google+, Facebook, Twitter)
+ * Description: Post to Buffer (Facebook, Google+, LinkedIn, Twitter)
  * Version: 0.2
  * Author: Michael Vogel <http://pirati.ca/profile/heluecht>
  */
@@ -234,8 +234,6 @@ function buffer_send(&$a,&$b) {
        if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))
                return;
 
-       logger("buffer_send: parameter ".print_r($b, true), LOGGER_DATA);
-
        if(! strstr($b['postopts'],'buffer'))
                return;
 
@@ -243,8 +241,8 @@ function buffer_send(&$a,&$b) {
                return;
 
        // if post comes from buffer don't send it back
-       if($b['app'] == "Buffer")
-               return;
+       //if($b['app'] == "Buffer")
+       //      return;
 
        $client_id = get_config("buffer", "client_id");
        $client_secret = get_config("buffer", "client_secret");
@@ -258,38 +256,55 @@ function buffer_send(&$a,&$b) {
 
                $profiles = $buffer->go('/profiles');
                if (is_array($profiles)) {
+                       logger("Will send these parameter ".print_r($b, true), LOGGER_DEBUG);
+
                        foreach ($profiles as $profile) {
                                if (!$profile->default)
                                        continue;
 
+                               $send = false;
+
                                switch ($profile->service) {
                                        case 'appdotnet':
+                                               $send = ($b["extid"] != NETWORK_APPNET);
                                                $limit = 256;
                                                $markup = false;
                                                $includedlinks = true;
+                                               $htmlmode = 6;
                                                break;
                                        case 'facebook':
+                                               $send = ($b["extid"] != NETWORK_FACEBOOK);
                                                $limit = 0;
                                                $markup = false;
                                                $includedlinks = false;
+                                               $htmlmode = 9;
                                                break;
                                        case 'google':
+                                               $send = ($b["extid"] != NETWORK_GPLUS);
                                                $limit = 0;
                                                $markup = true;
                                                $includedlinks = false;
+                                               $htmlmode = 9;
                                                break;
                                        case 'twitter':
+                                               $send = ($b["extid"] != NETWORK_TWITTER);
                                                $limit = 140;
                                                $markup = false;
                                                $includedlinks = true;
+                                               $htmlmode = 8;
                                                break;
                                        case 'linkedin':
+                                               $send = ($b["extid"] != NETWORK_LINKEDIN);
                                                $limit = 700;
                                                $markup = false;
                                                $includedlinks = true;
+                                               $htmlmode = 2;
                                                break;
                                }
 
+                               if (!$send)
+                                       continue;
+
                                $item = $b;
 
                                // Markup for Google+
@@ -302,7 +317,7 @@ function buffer_send(&$a,&$b) {
                                        $item["body"] = preg_replace("(\[s\](.*?)\[\/s\])ism",'-$1-',$item["body"]);
                                }
 
-                               $post = plaintext($a, $item, $limit, $includedlinks);
+                               $post = plaintext($a, $item, $limit, $includedlinks, $htmlmode);
                                logger("buffer_send: converted message ".$b["id"]." result: ".print_r($post, true), LOGGER_DEBUG);
 
                                // The image proxy is used as a sanitizer. Buffer seems to be really picky about pictures
@@ -313,27 +328,28 @@ function buffer_send(&$a,&$b) {
                                if (isset($post["preview"]))
                                        $post["preview"] = proxy_url($post["preview"]);
 
-                               //if ($profile->service == "twitter") {
-                               if ($includedlinks) {
-                                       if (isset($post["url"]))
-                                               $post["url"] = short_link($post["url"]);
-                                       if (isset($post["image"]))
-                                               $post["image"] = short_link($post["image"]);
-                                       if (isset($post["preview"]))
-                                               $post["preview"] = short_link($post["preview"]);
-                               }
+                               //if ($includedlinks) {
+                               //      if (isset($post["url"]))
+                               //              $post["url"] = short_link($post["url"]);
+                               //      if (isset($post["image"]))
+                               //              $post["image"] = short_link($post["image"]);
+                               //      if (isset($post["preview"]))
+                               //              $post["preview"] = short_link($post["preview"]);
+                               //}
 
                                // Seems like a bug to me
                                // Buffer doesn't add links to Twitter and App.net (but pictures)
                                //if ($includedlinks AND isset($post["url"]))
-                               if (($profile->service == "twitter") AND isset($post["url"]))
+                               if (($profile->service == "twitter") AND isset($post["url"]) AND ($post["type"] != "photo"))
                                        $post["text"] .= " ".$post["url"];
-                               elseif (($profile->service == "appdotnet") AND isset($post["url"]) AND isset($post["title"])) {
+                               elseif (($profile->service == "appdotnet") AND isset($post["url"]) AND isset($post["title"]) AND ($post["type"] != "photo")) {
                                        $post["title"] = shortenmsg($post["title"], 90);
                                        $post["text"] = shortenmsg($post["text"], $limit - (24 + strlen($post["title"])));
                                        $post["text"] .= "\n[".$post["title"]."](".$post["url"].")";
-                               } elseif (($profile->service == "appdotnet") AND isset($post["url"]))
+                               } elseif (($profile->service == "appdotnet") AND isset($post["url"]) AND ($post["type"] != "photo"))
                                        $post["text"] .= " ".$post["url"];
+                               elseif ($profile->service == "google")
+                                       $post["text"] .= html_entity_decode("&#x00A0;", ENT_QUOTES, 'UTF-8'); // Send a special blank to identify the post through the "fromgplus" addon
 
                                $message = array();
                                $message["text"] = $post["text"];
@@ -360,6 +376,7 @@ function buffer_send(&$a,&$b) {
                                        $message["media[thumbnail]"] = $post["preview"];
 
                                //print_r($message);
+                               logger("buffer_send: data for message ".$b["id"].": ".print_r($message, true), LOGGER_DEBUG);
                                $ret = $buffer->go('/updates/create', $message);
                                logger("buffer_send: send message ".$b["id"]." result: ".print_r($ret, true), LOGGER_DEBUG);
                        }