]> git.mxchange.org Git - friendica-addons.git/blobdiff - buffer/buffer.php
Setting "editplain", "page" and "privacy_image_cache" as deprecated. Using new cache...
[friendica-addons.git] / buffer / buffer.php
index 76156e16f9d04bbd50df20f0004f9680e29f34e6..595dba43d9fcce41ab84bf9d63e8e5416e98280b 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 /**
  * Name: Buffer Post Connector
- * Description: Post to Buffer
- * Version: 0.1 alpha
+ * Description: Post to Buffer (Linkedin, App.net, Google+, Facebook, Twitter)
+ * Version: 0.2
  * Author: Michael Vogel <http://pirati.ca/profile/heluecht>
  */
 require('addon/buffer/bufferapp.php');
@@ -60,6 +60,13 @@ function buffer_plugin_admin(&$a, &$o){
                '$client_secret' => array('client_secret', t('Client Secret'),  get_config('buffer', 'client_secret' ), ''),
        ));
 }
+function buffer_plugin_admin_post(&$a){
+        $client_id     =       ((x($_POST,'client_id'))              ? notags(trim($_POST['client_id']))   : '');
+        $client_secret =       ((x($_POST,'client_secret'))   ? notags(trim($_POST['client_secret'])): '');
+        set_config('buffer','client_id',$client_id);
+        set_config('buffer','client_secret',$client_secret);
+        info( t('Settings updated.'). EOL );
+}
 
 function buffer_connect(&$a) {
 
@@ -195,23 +202,8 @@ function buffer_settings_post(&$a,&$b) {
                        set_pconfig(local_user(),'buffer','post',false);
                        set_pconfig(local_user(),'buffer','post_by_default',false);
                } else {
-                       // filtering the username if it is filled wrong
-                       $user = $_POST['buffer_user'];
-                       if (strstr($user, "@")) {
-                               $pos = strpos($user, "@");
-                               if ($pos > 0)
-                                       $user = substr($user, 0, $pos);
-                       }
-
-                       // Filtering the hostname if someone is entering it with "http"
-                       $host = $_POST['buffer_host'];
-                       $host = trim($host);
-                       $host = str_replace(array("https://", "http://"), array("", ""), $host);
-
                        set_pconfig(local_user(),'buffer','post',intval($_POST['buffer']));
                        set_pconfig(local_user(),'buffer','post_by_default',intval($_POST['buffer_bydefault']));
-
-                       //header("Location: ".$a->get_baseurl()."/buffer/connect");
                }
        }
 }
@@ -261,9 +253,6 @@ function buffer_send(&$a,&$b) {
        if($access_token) {
                $buffer = new BufferApp($client_id, $client_secret, $callback_url, $access_token);
 
-               $result = q("SELECT `installed` FROM `addon` WHERE `name` = 'privacy_image_cache' AND `installed`");
-               $image_cache = (count($result) > 0);
-
                require_once("include/plaintext.php");
                require_once("include/network.php");
 
@@ -316,31 +305,35 @@ function buffer_send(&$a,&$b) {
                                $post = plaintext($a, $item, $limit, $includedlinks);
                                logger("buffer_send: converted message ".$b["id"]." result: ".print_r($post, true), LOGGER_DEBUG);
 
-                               // The image cache is used as a sanitizer. Buffer seems to be really picky about pictures
-                               if ($image_cache) {
-                                       require_once("addon/privacy_image_cache/privacy_image_cache.php");
-                                       if (isset($post["image"]))
-                                               $post["image"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($post["image"]);
+                               // The image proxy is used as a sanitizer. Buffer seems to be really picky about pictures
+                               require_once("mod/proxy.php");
+                               if (isset($post["image"]))
+                                       $post["image"] = proxy_url($post["image"]);
+
+                               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"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($post["preview"]);
+                                               $post["preview"] = short_link($post["preview"]);
                                }
 
-                               //if ($includedlinks AND isset($post["url"]))
-                               //      $post["url"] = short_link($post["url"]);
-
                                // Seems like a bug to me
                                // Buffer doesn't add links to Twitter and App.net (but pictures)
-                               if ($includedlinks AND isset($post["url"]))
-                                       $post["text"] .= " ".short_link($post["url"]);
-
-                               //if ($includedlinks AND ($post["type"] == "link"))
-                               //      $post["text"] .= " ".$post["url"];
-
-                               //if ($includedlinks AND ($post["type"] == "video"))
-                               //      $post["text"] .= " ".$post["url"];
-
-                               //print_r($post);
+                               //if ($includedlinks AND isset($post["url"]))
+                               if (($profile->service == "twitter") AND isset($post["url"]))
+                                       $post["text"] .= " ".$post["url"];
+                               elseif (($profile->service == "appdotnet") AND isset($post["url"]) AND isset($post["title"])) {
+                                       $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"]))
+                                       $post["text"] .= " ".$post["url"];
 
                                $message = array();
                                $message["text"] = $post["text"];
@@ -354,7 +347,7 @@ function buffer_send(&$a,&$b) {
                                if (isset($post["description"]))
                                        $message["media[description]"] = $post["description"];
 
-                               if (isset($post["url"]))
+                               if (isset($post["url"]) AND ($post["type"] != "photo"))
                                        $message["media[link]"] = $post["url"];
 
                                if (isset($post["image"])) {