X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=buffer%2Fbuffer.php;h=90a797583b65e710aa461f002f8c29819640421d;hb=be2e3e6bf7767f7fd4bee4d34dea7f284555ba45;hp=766cef4a5b079c2537eebcd7b81c1c670f4c1124;hpb=bd04842776207984b684ff0666cabc6583ade8d7;p=friendica-addons.git diff --git a/buffer/buffer.php b/buffer/buffer.php index 766cef4a..90a79758 100644 --- a/buffer/buffer.php +++ b/buffer/buffer.php @@ -1,8 +1,8 @@ */ 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"); } } } @@ -242,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; @@ -251,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"); @@ -261,46 +251,60 @@ 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"); $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+ @@ -313,18 +317,16 @@ 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 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"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($post["preview"]); - } + if (isset($post["preview"])) + $post["preview"] = proxy_url($post["preview"]); //if ($profile->service == "twitter") { if ($includedlinks) { @@ -342,16 +344,13 @@ function buffer_send(&$a,&$b) { if (($profile->service == "twitter") AND isset($post["url"])) $post["text"] .= " ".$post["url"]; elseif (($profile->service == "appdotnet") AND isset($post["url"]) AND isset($post["title"])) { - $maxdesclength = $limit - (strlen($post["text"]) + 1); - if (strlen($post["title"]) > $maxdesclength) - $posttitle = trim(substr($post["title"], 0, $maxdesclength - 3))."..."; - else - $posttitle = trim($post["title"]); - - $post["text"] .= "\n[".$posttitle."](".$post["url"].")"; + $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"]; - + elseif ($profile->service == "google") + $post["text"] .= html_entity_decode(" ", ENT_QUOTES, 'UTF-8'); // Send a special blank to identify the post through the "fromgplus" addon $message = array(); $message["text"] = $post["text"];