X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=buffer%2Fbuffer.php;h=c9bb93e23eadd78aa84e62639d2bbd85e67d29ab;hb=c3e93f1ed9a487f823bcc75ddd43024334c25bfc;hp=4b81fb31a82c94369d264bab9f3a705467a97728;hpb=021d6265cd544bfa25f78a3ce895d65e0e470bb4;p=friendica-addons.git
diff --git a/buffer/buffer.php b/buffer/buffer.php
index 4b81fb31..c9bb93e2 100644
--- a/buffer/buffer.php
+++ b/buffer/buffer.php
@@ -1,12 +1,15 @@
*/
require('addon/buffer/bufferapp.php');
+use Friendica\Core\Config;
+use Friendica\Core\PConfig;
+
function buffer_install() {
register_hook('post_local', 'addon/buffer/buffer.php', 'buffer_post_local');
register_hook('notifier_normal', 'addon/buffer/buffer.php', 'buffer_send');
@@ -56,10 +59,17 @@ function buffer_plugin_admin(&$a, &$o){
$o = replace_macros($t, array(
'$submit' => t('Save Settings'),
// name, label, value, help, [extra values]
- '$client_id' => array('client_id', t('Client ID'), get_config('buffer', 'client_id' ), ''),
- '$client_secret' => array('client_secret', t('Client Secret'), get_config('buffer', 'client_secret' ), ''),
+ '$client_id' => array('client_id', t('Client ID'), Config::get('buffer', 'client_id' ), ''),
+ '$client_secret' => array('client_secret', t('Client Secret'), Config::get('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'])): '');
+ Config::set('buffer','client_id',$client_id);
+ Config::set('buffer','client_secret',$client_secret);
+ info( t('Settings updated.'). EOL );
+}
function buffer_connect(&$a) {
@@ -71,8 +81,8 @@ function buffer_connect(&$a) {
session_start();
// Define the needed keys
- $client_id = get_config('buffer','client_id');
- $client_secret = get_config('buffer','client_secret');
+ $client_id = Config::get('buffer','client_id');
+ $client_secret = Config::get('buffer','client_secret');
// The callback URL is the script that gets called after the user authenticates with buffer
$callback_url = $a->get_baseurl()."/buffer/connect";
@@ -85,7 +95,7 @@ function buffer_connect(&$a) {
logger("buffer_connect: authenticated");
$o .= t("You are now authenticated to buffer. ");
$o .= '
'.t("return to the connector page").'';
- set_pconfig(local_user(), 'buffer','access_token', $buffer->access_token);
+ PConfig::set(local_user(), 'buffer','access_token', $buffer->access_token);
}
return($o);
@@ -95,9 +105,9 @@ function buffer_jot_nets(&$a,&$b) {
if(! local_user())
return;
- $buffer_post = get_pconfig(local_user(),'buffer','post');
+ $buffer_post = PConfig::get(local_user(),'buffer','post');
if(intval($buffer_post) == 1) {
- $buffer_defpost = get_pconfig(local_user(),'buffer','post_by_default');
+ $buffer_defpost = PConfig::get(local_user(),'buffer','post_by_default');
$selected = ((intval($buffer_defpost) == 1) ? ' checked="checked" ' : '');
$b .= '
'
. t('Post to Buffer') . '
';
@@ -115,11 +125,11 @@ function buffer_settings(&$a,&$s) {
/* Get the current state of our config variables */
- $enabled = get_pconfig(local_user(),'buffer','post');
+ $enabled = PConfig::get(local_user(),'buffer','post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$css = (($enabled) ? '' : '-disabled');
- $def_enabled = get_pconfig(local_user(),'buffer','post_by_default');
+ $def_enabled = PConfig::get(local_user(),'buffer','post_by_default');
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
/* Add some HTML to the existing form */
@@ -132,9 +142,9 @@ function buffer_settings(&$a,&$s) {
$s .= ''. t('Buffer Export').'
';
$s .= '';
- $client_id = get_config("buffer", "client_id");
- $client_secret = get_config("buffer", "client_secret");
- $access_token = get_pconfig(local_user(), "buffer", "access_token");
+ $client_id = Config::get("buffer", "client_id");
+ $client_secret = Config::get("buffer", "client_secret");
+ $access_token = PConfig::get(local_user(), "buffer", "access_token");
$s .= '';
if ($access_token == "") {
@@ -191,33 +201,37 @@ function buffer_settings_post(&$a,&$b) {
if(x($_POST,'buffer-submit')) {
if(x($_POST,'buffer_delete')) {
- set_pconfig(local_user(),'buffer','access_token','');
- set_pconfig(local_user(),'buffer','post',false);
- set_pconfig(local_user(),'buffer','post_by_default',false);
+ PConfig::set(local_user(),'buffer','access_token','');
+ PConfig::set(local_user(),'buffer','post',false);
+ PConfig::set(local_user(),'buffer','post_by_default',false);
} else {
- set_pconfig(local_user(),'buffer','post',intval($_POST['buffer']));
- set_pconfig(local_user(),'buffer','post_by_default',intval($_POST['buffer_bydefault']));
+ PConfig::set(local_user(),'buffer','post',intval($_POST['buffer']));
+ PConfig::set(local_user(),'buffer','post_by_default',intval($_POST['buffer_bydefault']));
}
}
}
function buffer_post_local(&$a,&$b) {
- if((! local_user()) || (local_user() != $b['uid']))
+ if (!local_user() || (local_user() != $b['uid'])) {
return;
+ }
- $buffer_post = intval(get_pconfig(local_user(),'buffer','post'));
+ $buffer_post = intval(PConfig::get(local_user(),'buffer','post'));
$buffer_enable = (($buffer_post && x($_REQUEST,'buffer_enable')) ? intval($_REQUEST['buffer_enable']) : 0);
- if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'buffer','post_by_default')))
+ if ($b['api_source'] && intval(PConfig::get(local_user(),'buffer','post_by_default'))) {
$buffer_enable = 1;
+ }
- if(! $buffer_enable)
+ if (!$buffer_enable) {
return;
+ }
- if(strlen($b['postopts']))
+ if (strlen($b['postopts'])) {
$b['postopts'] .= ',';
+ }
$b['postopts'] .= 'buffer';
}
@@ -227,8 +241,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;
@@ -236,56 +248,70 @@ 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");
- $access_token = get_pconfig($b['uid'], "buffer","access_token");
+ $client_id = Config::get("buffer", "client_id");
+ $client_secret = Config::get("buffer", "client_secret");
+ $access_token = PConfig::get($b['uid'], "buffer","access_token");
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+
@@ -298,40 +324,39 @@ 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) {
- 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 ($includedlinks && isset($post["url"]))
+ if (($profile->service == "twitter") && isset($post["url"]) && ($post["type"] != "photo"))
$post["text"] .= " ".$post["url"];
- elseif (($profile->service == "appdotnet") AND isset($post["url"]) AND isset($post["title"])) {
+ elseif (($profile->service == "appdotnet") && isset($post["url"]) && isset($post["title"]) && ($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") && isset($post["url"]) && ($post["type"] != "photo"))
$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"];
@@ -345,7 +370,7 @@ function buffer_send(&$a,&$b) {
if (isset($post["description"]))
$message["media[description]"] = $post["description"];
- if (isset($post["url"]) AND ($post["type"] != "photo"))
+ if (isset($post["url"]) && ($post["type"] != "photo"))
$message["media[link]"] = $post["url"];
if (isset($post["image"])) {
@@ -358,6 +383,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);
}