2014-05-03 09:56:57 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: Buffer Post Connector
|
2017-03-09 06:58:36 +00:00
|
|
|
* Description: Post to Buffer (Facebook, Google+, LinkedIn, Twitter)
|
2014-05-29 10:42:25 +00:00
|
|
|
* Version: 0.2
|
2014-05-03 09:56:57 +00:00
|
|
|
* Author: Michael Vogel <http://pirati.ca/profile/heluecht>
|
|
|
|
*/
|
2018-01-04 17:15:53 +00:00
|
|
|
require 'addon/buffer/bufferapp.php';
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2018-01-04 17:15:53 +00:00
|
|
|
use Friendica\App;
|
2018-01-17 00:51:12 +00:00
|
|
|
use Friendica\Core\Addon;
|
2017-11-06 23:55:24 +00:00
|
|
|
use Friendica\Core\Config;
|
2018-01-22 19:03:11 +00:00
|
|
|
use Friendica\Core\L10n;
|
2017-11-06 23:55:24 +00:00
|
|
|
use Friendica\Core\PConfig;
|
|
|
|
|
2014-05-03 09:56:57 +00:00
|
|
|
function buffer_install() {
|
2018-01-17 00:51:12 +00:00
|
|
|
Addon::registerHook('post_local', 'addon/buffer/buffer.php', 'buffer_post_local');
|
|
|
|
Addon::registerHook('notifier_normal', 'addon/buffer/buffer.php', 'buffer_send');
|
|
|
|
Addon::registerHook('jot_networks', 'addon/buffer/buffer.php', 'buffer_jot_nets');
|
|
|
|
Addon::registerHook('connector_settings', 'addon/buffer/buffer.php', 'buffer_settings');
|
|
|
|
Addon::registerHook('connector_settings_post', 'addon/buffer/buffer.php', 'buffer_settings_post');
|
2014-05-03 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function buffer_uninstall() {
|
2018-01-17 00:51:12 +00:00
|
|
|
Addon::unregisterHook('post_local', 'addon/buffer/buffer.php', 'buffer_post_local');
|
|
|
|
Addon::unregisterHook('notifier_normal', 'addon/buffer/buffer.php', 'buffer_send');
|
|
|
|
Addon::unregisterHook('jot_networks', 'addon/buffer/buffer.php', 'buffer_jot_nets');
|
|
|
|
Addon::unregisterHook('connector_settings', 'addon/buffer/buffer.php', 'buffer_settings');
|
|
|
|
Addon::unregisterHook('connector_settings_post', 'addon/buffer/buffer.php', 'buffer_settings_post');
|
2014-05-03 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function buffer_module() {}
|
|
|
|
|
|
|
|
function buffer_content(&$a) {
|
|
|
|
|
|
|
|
if(! local_user()) {
|
2018-01-22 19:03:11 +00:00
|
|
|
notice(L10n::t('Permission denied.') . EOL);
|
2014-05-03 09:56:57 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once("mod/settings.php");
|
|
|
|
settings_init($a);
|
|
|
|
|
|
|
|
if (isset($a->argv[1]))
|
|
|
|
switch ($a->argv[1]) {
|
|
|
|
case "connect":
|
|
|
|
$o = buffer_connect($a);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$o = print_r($a->argv, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$o = buffer_connect($a);
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
2018-01-20 13:57:41 +00:00
|
|
|
function buffer_addon_admin(&$a, &$o)
|
|
|
|
{
|
|
|
|
$t = get_markup_template("admin.tpl", "addon/buffer/");
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2018-01-15 13:15:33 +00:00
|
|
|
$o = replace_macros($t, [
|
2018-01-22 19:03:11 +00:00
|
|
|
'$submit' => L10n::t('Save Settings'),
|
2018-01-20 13:57:41 +00:00
|
|
|
// name, label, value, help, [extra values]
|
2018-01-22 19:03:11 +00:00
|
|
|
'$client_id' => ['client_id', L10n::t('Client ID'), Config::get('buffer', 'client_id'), ''],
|
|
|
|
'$client_secret' => ['client_secret', L10n::t('Client Secret'), Config::get('buffer', 'client_secret'), ''],
|
2018-01-15 13:15:33 +00:00
|
|
|
]);
|
2014-05-03 09:56:57 +00:00
|
|
|
}
|
2018-01-20 13:57:41 +00:00
|
|
|
function buffer_addon_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);
|
2018-01-22 19:03:11 +00:00
|
|
|
info(L10n::t('Settings updated.'). EOL);
|
2014-06-15 11:18:37 +00:00
|
|
|
}
|
2014-05-03 09:56:57 +00:00
|
|
|
|
|
|
|
function buffer_connect(&$a) {
|
|
|
|
|
|
|
|
if (isset($_REQUEST["error"])) {
|
2018-01-22 19:03:11 +00:00
|
|
|
$o = L10n::t('Error when registering buffer connection:')." ".$_REQUEST["error"];
|
2014-05-03 09:56:57 +00:00
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
// Start a session. This is necessary to hold on to a few keys the callback script will also need
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
// Define the needed keys
|
2017-11-06 23:55:24 +00:00
|
|
|
$client_id = Config::get('buffer','client_id');
|
|
|
|
$client_secret = Config::get('buffer','client_secret');
|
2014-05-03 09:56:57 +00:00
|
|
|
|
|
|
|
// The callback URL is the script that gets called after the user authenticates with buffer
|
|
|
|
$callback_url = $a->get_baseurl()."/buffer/connect";
|
|
|
|
|
|
|
|
$buffer = new BufferApp($client_id, $client_secret, $callback_url);
|
|
|
|
|
|
|
|
if (!$buffer->ok) {
|
|
|
|
$o .= '<a href="' . $buffer->get_login_url() . '">Connect to Buffer!</a>';
|
|
|
|
} else {
|
|
|
|
logger("buffer_connect: authenticated");
|
2018-01-22 19:03:11 +00:00
|
|
|
$o .= L10n::t("You are now authenticated to buffer. ");
|
|
|
|
$o .= '<br /><a href="'.$a->get_baseurl().'/settings/connectors">'.L10n::t("return to the connector page").'</a>';
|
2017-11-06 23:55:24 +00:00
|
|
|
PConfig::set(local_user(), 'buffer','access_token', $buffer->access_token);
|
2014-05-03 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return($o);
|
|
|
|
}
|
|
|
|
|
|
|
|
function buffer_jot_nets(&$a,&$b) {
|
|
|
|
if(! local_user())
|
|
|
|
return;
|
|
|
|
|
2017-11-06 23:55:24 +00:00
|
|
|
$buffer_post = PConfig::get(local_user(),'buffer','post');
|
2014-05-03 09:56:57 +00:00
|
|
|
if(intval($buffer_post) == 1) {
|
2017-11-06 23:55:24 +00:00
|
|
|
$buffer_defpost = PConfig::get(local_user(),'buffer','post_by_default');
|
2014-05-03 09:56:57 +00:00
|
|
|
$selected = ((intval($buffer_defpost) == 1) ? ' checked="checked" ' : '');
|
|
|
|
$b .= '<div class="profile-jot-net"><input type="checkbox" name="buffer_enable"' . $selected . ' value="1" /> '
|
2018-01-22 19:03:11 +00:00
|
|
|
. L10n::t('Post to Buffer') . '</div>';
|
2014-05-03 09:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buffer_settings(&$a,&$s) {
|
|
|
|
|
|
|
|
if(! local_user())
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Add our stylesheet to the page so we can make our settings look nice */
|
|
|
|
|
|
|
|
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/buffer/buffer.css' . '" media="all" />' . "\r\n";
|
|
|
|
|
|
|
|
/* Get the current state of our config variables */
|
|
|
|
|
2017-11-06 23:55:24 +00:00
|
|
|
$enabled = PConfig::get(local_user(),'buffer','post');
|
2014-05-03 09:56:57 +00:00
|
|
|
$checked = (($enabled) ? ' checked="checked" ' : '');
|
|
|
|
$css = (($enabled) ? '' : '-disabled');
|
|
|
|
|
2017-11-06 23:55:24 +00:00
|
|
|
$def_enabled = PConfig::get(local_user(),'buffer','post_by_default');
|
2014-05-03 09:56:57 +00:00
|
|
|
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
|
|
|
|
|
|
|
|
/* Add some HTML to the existing form */
|
|
|
|
|
|
|
|
$s .= '<span id="settings_buffer_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_buffer_expanded\'); openClose(\'settings_buffer_inflated\');">';
|
2018-01-22 19:03:11 +00:00
|
|
|
$s .= '<img class="connector'.$css.'" src="images/buffer.png" /><h3 class="connector">'. L10n::t('Buffer Export').'</h3>';
|
2014-05-03 09:56:57 +00:00
|
|
|
$s .= '</span>';
|
|
|
|
$s .= '<div id="settings_buffer_expanded" class="settings-block" style="display: none;">';
|
|
|
|
$s .= '<span class="fakelink" onclick="openClose(\'settings_buffer_expanded\'); openClose(\'settings_buffer_inflated\');">';
|
2018-01-22 19:03:11 +00:00
|
|
|
$s .= '<img class="connector'.$css.'" src="images/buffer.png" /><h3 class="connector">'. L10n::t('Buffer Export').'</h3>';
|
2014-05-03 09:56:57 +00:00
|
|
|
$s .= '</span>';
|
|
|
|
|
2017-11-06 23:55:24 +00:00
|
|
|
$client_id = Config::get("buffer", "client_id");
|
|
|
|
$client_secret = Config::get("buffer", "client_secret");
|
|
|
|
$access_token = PConfig::get(local_user(), "buffer", "access_token");
|
2014-05-03 09:56:57 +00:00
|
|
|
|
|
|
|
$s .= '<div id="buffer-password-wrapper">';
|
|
|
|
if ($access_token == "") {
|
|
|
|
$s .= '<div id="buffer-authenticate-wrapper">';
|
2018-01-22 19:03:11 +00:00
|
|
|
$s .= '<a href="'.$a->get_baseurl().'/buffer/connect">'.L10n::t("Authenticate your Buffer connection").'</a>';
|
2014-05-03 09:56:57 +00:00
|
|
|
$s .= '</div><div class="clear"></div>';
|
|
|
|
} else {
|
|
|
|
$s .= '<div id="buffer-enable-wrapper">';
|
2018-01-22 19:03:11 +00:00
|
|
|
$s .= '<label id="buffer-enable-label" for="buffer-checkbox">' . L10n::t('Enable Buffer Post Addon') . '</label>';
|
2014-05-03 09:56:57 +00:00
|
|
|
$s .= '<input id="buffer-checkbox" type="checkbox" name="buffer" value="1" ' . $checked . '/>';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
|
|
|
|
|
|
|
$s .= '<div id="buffer-bydefault-wrapper">';
|
2018-01-22 19:03:11 +00:00
|
|
|
$s .= '<label id="buffer-bydefault-label" for="buffer-bydefault">' . L10n::t('Post to Buffer by default') . '</label>';
|
2014-05-03 09:56:57 +00:00
|
|
|
$s .= '<input id="buffer-bydefault" type="checkbox" name="buffer_bydefault" value="1" ' . $def_checked . '/>';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
|
|
|
|
|
|
|
$s .= '<div id="buffer-delete-wrapper">';
|
2018-01-22 19:03:11 +00:00
|
|
|
$s .= '<label id="buffer-delete-label" for="buffer-delete">' . L10n::t('Check to delete this preset') . '</label>';
|
2014-05-03 09:56:57 +00:00
|
|
|
$s .= '<input id="buffer-delete" type="checkbox" name="buffer_delete" value="1" />';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
|
|
|
|
|
|
|
$buffer = new BufferApp($client_id, $client_secret, $callback_url, $access_token);
|
|
|
|
|
|
|
|
$profiles = $buffer->go('/profiles');
|
|
|
|
if (is_array($profiles)) {
|
|
|
|
$s .= '<div id="buffer-accounts-wrapper">';
|
2018-01-22 19:03:11 +00:00
|
|
|
$s .= L10n::t("Posts are going to all accounts that are enabled by default:");
|
2014-05-03 09:56:57 +00:00
|
|
|
$s .= "<ul>";
|
|
|
|
foreach ($profiles as $profile) {
|
|
|
|
if (!$profile->default)
|
|
|
|
continue;
|
|
|
|
$s .= "<li>";
|
|
|
|
//$s .= "<img src='".$profile->avatar_https."' width='16' />";
|
|
|
|
$s .= " ".$profile->formatted_username." (".$profile->formatted_service.")";
|
|
|
|
$s .= "</li>";
|
|
|
|
}
|
|
|
|
$s .= "</ul>";
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
|
|
|
|
|
|
|
/* provide a submit button */
|
|
|
|
|
2018-01-22 19:03:11 +00:00
|
|
|
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="buffer-submit" name="buffer-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
|
2014-05-03 09:56:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function buffer_settings_post(&$a,&$b) {
|
|
|
|
|
|
|
|
if(x($_POST,'buffer-submit')) {
|
|
|
|
if(x($_POST,'buffer_delete')) {
|
2017-11-06 23:55:24 +00:00
|
|
|
PConfig::set(local_user(),'buffer','access_token','');
|
|
|
|
PConfig::set(local_user(),'buffer','post',false);
|
|
|
|
PConfig::set(local_user(),'buffer','post_by_default',false);
|
2014-05-03 09:56:57 +00:00
|
|
|
} else {
|
2017-11-06 23:55:24 +00:00
|
|
|
PConfig::set(local_user(),'buffer','post',intval($_POST['buffer']));
|
|
|
|
PConfig::set(local_user(),'buffer','post_by_default',intval($_POST['buffer_bydefault']));
|
2014-05-03 09:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buffer_post_local(&$a,&$b) {
|
|
|
|
|
2017-09-06 16:16:33 +00:00
|
|
|
if (!local_user() || (local_user() != $b['uid'])) {
|
2014-05-03 09:56:57 +00:00
|
|
|
return;
|
2017-09-06 16:16:33 +00:00
|
|
|
}
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2017-11-06 23:55:24 +00:00
|
|
|
$buffer_post = intval(PConfig::get(local_user(),'buffer','post'));
|
2014-05-03 09:56:57 +00:00
|
|
|
|
|
|
|
$buffer_enable = (($buffer_post && x($_REQUEST,'buffer_enable')) ? intval($_REQUEST['buffer_enable']) : 0);
|
|
|
|
|
2017-11-06 23:55:24 +00:00
|
|
|
if ($b['api_source'] && intval(PConfig::get(local_user(),'buffer','post_by_default'))) {
|
2014-05-03 09:56:57 +00:00
|
|
|
$buffer_enable = 1;
|
2017-09-06 16:16:33 +00:00
|
|
|
}
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2017-09-06 16:16:33 +00:00
|
|
|
if (!$buffer_enable) {
|
2014-05-03 09:56:57 +00:00
|
|
|
return;
|
2017-09-06 16:16:33 +00:00
|
|
|
}
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2017-09-06 16:16:33 +00:00
|
|
|
if (strlen($b['postopts'])) {
|
2014-05-03 09:56:57 +00:00
|
|
|
$b['postopts'] .= ',';
|
2017-09-06 16:16:33 +00:00
|
|
|
}
|
2014-05-03 09:56:57 +00:00
|
|
|
|
|
|
|
$b['postopts'] .= 'buffer';
|
|
|
|
}
|
|
|
|
|
2018-01-04 17:15:53 +00:00
|
|
|
function buffer_send(App $a, &$b)
|
|
|
|
{
|
2018-01-10 03:27:40 +00:00
|
|
|
if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
|
2014-05-03 09:56:57 +00:00
|
|
|
return;
|
2018-01-10 03:27:40 +00:00
|
|
|
}
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2018-01-10 03:27:40 +00:00
|
|
|
if(! strstr($b['postopts'],'buffer')) {
|
2014-05-03 09:56:57 +00:00
|
|
|
return;
|
2018-01-10 03:27:40 +00:00
|
|
|
}
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2018-01-10 03:27:40 +00:00
|
|
|
if($b['parent'] != $b['id']) {
|
2014-05-03 09:56:57 +00:00
|
|
|
return;
|
2018-01-10 03:27:40 +00:00
|
|
|
}
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2017-11-25 23:56:18 +00:00
|
|
|
// Dont't post if the post doesn't belong to us.
|
|
|
|
// This is a check for forum postings
|
2018-01-10 13:37:11 +00:00
|
|
|
$self = dba::selectFirst('contact', ['id'], ['uid' => $b['uid'], 'self' => true]);
|
2017-11-25 23:56:18 +00:00
|
|
|
if ($b['contact-id'] != $self['id']) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-03 09:56:57 +00:00
|
|
|
// if post comes from buffer don't send it back
|
2014-12-01 21:31:29 +00:00
|
|
|
//if($b['app'] == "Buffer")
|
|
|
|
// return;
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2017-11-06 23:55:24 +00:00
|
|
|
$client_id = Config::get("buffer", "client_id");
|
|
|
|
$client_secret = Config::get("buffer", "client_secret");
|
|
|
|
$access_token = PConfig::get($b['uid'], "buffer","access_token");
|
2014-05-03 09:56:57 +00:00
|
|
|
|
|
|
|
if($access_token) {
|
|
|
|
$buffer = new BufferApp($client_id, $client_secret, $callback_url, $access_token);
|
|
|
|
|
|
|
|
require_once("include/plaintext.php");
|
|
|
|
require_once("include/network.php");
|
|
|
|
|
|
|
|
$profiles = $buffer->go('/profiles');
|
|
|
|
if (is_array($profiles)) {
|
2014-12-01 21:31:29 +00:00
|
|
|
logger("Will send these parameter ".print_r($b, true), LOGGER_DEBUG);
|
|
|
|
|
2014-05-03 09:56:57 +00:00
|
|
|
foreach ($profiles as $profile) {
|
|
|
|
if (!$profile->default)
|
|
|
|
continue;
|
|
|
|
|
2014-12-01 21:31:29 +00:00
|
|
|
$send = false;
|
|
|
|
|
2014-05-03 09:56:57 +00:00
|
|
|
switch ($profile->service) {
|
|
|
|
case 'appdotnet':
|
2014-12-01 21:31:29 +00:00
|
|
|
$send = ($b["extid"] != NETWORK_APPNET);
|
2014-05-03 09:56:57 +00:00
|
|
|
$limit = 256;
|
|
|
|
$markup = false;
|
|
|
|
$includedlinks = true;
|
2014-12-01 21:31:29 +00:00
|
|
|
$htmlmode = 6;
|
2014-05-03 09:56:57 +00:00
|
|
|
break;
|
|
|
|
case 'facebook':
|
2014-12-01 21:31:29 +00:00
|
|
|
$send = ($b["extid"] != NETWORK_FACEBOOK);
|
2014-05-03 09:56:57 +00:00
|
|
|
$limit = 0;
|
|
|
|
$markup = false;
|
|
|
|
$includedlinks = false;
|
2014-12-01 21:31:29 +00:00
|
|
|
$htmlmode = 9;
|
2014-05-03 09:56:57 +00:00
|
|
|
break;
|
|
|
|
case 'google':
|
2014-12-01 21:31:29 +00:00
|
|
|
$send = ($b["extid"] != NETWORK_GPLUS);
|
2014-05-03 09:56:57 +00:00
|
|
|
$limit = 0;
|
|
|
|
$markup = true;
|
|
|
|
$includedlinks = false;
|
2014-12-01 21:31:29 +00:00
|
|
|
$htmlmode = 9;
|
2014-05-03 09:56:57 +00:00
|
|
|
break;
|
|
|
|
case 'twitter':
|
2014-12-01 21:31:29 +00:00
|
|
|
$send = ($b["extid"] != NETWORK_TWITTER);
|
2017-11-07 22:44:39 +00:00
|
|
|
$limit = 280;
|
2014-05-03 09:56:57 +00:00
|
|
|
$markup = false;
|
|
|
|
$includedlinks = true;
|
2014-12-01 21:31:29 +00:00
|
|
|
$htmlmode = 8;
|
2014-05-03 09:56:57 +00:00
|
|
|
break;
|
|
|
|
case 'linkedin':
|
2014-12-01 21:31:29 +00:00
|
|
|
$send = ($b["extid"] != NETWORK_LINKEDIN);
|
2014-05-03 09:56:57 +00:00
|
|
|
$limit = 700;
|
|
|
|
$markup = false;
|
|
|
|
$includedlinks = true;
|
2014-12-01 21:31:29 +00:00
|
|
|
$htmlmode = 2;
|
2014-05-03 09:56:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-01 21:31:29 +00:00
|
|
|
if (!$send)
|
|
|
|
continue;
|
|
|
|
|
2014-05-03 09:56:57 +00:00
|
|
|
$item = $b;
|
|
|
|
|
|
|
|
// Markup for Google+
|
|
|
|
if ($markup) {
|
|
|
|
if ($item["title"] != "")
|
|
|
|
$item["title"] = "*".$item["title"]."*";
|
|
|
|
|
|
|
|
$item["body"] = preg_replace("(\[b\](.*?)\[\/b\])ism",'*$1*',$item["body"]);
|
|
|
|
$item["body"] = preg_replace("(\[i\](.*?)\[\/i\])ism",'_$1_',$item["body"]);
|
|
|
|
$item["body"] = preg_replace("(\[s\](.*?)\[\/s\])ism",'-$1-',$item["body"]);
|
|
|
|
}
|
|
|
|
|
2018-01-04 17:15:53 +00:00
|
|
|
$post = plaintext($item, $limit, $includedlinks, $htmlmode);
|
2014-05-03 09:56:57 +00:00
|
|
|
logger("buffer_send: converted message ".$b["id"]." result: ".print_r($post, true), LOGGER_DEBUG);
|
|
|
|
|
2014-08-16 08:25:29 +00:00
|
|
|
// 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"]);
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2014-08-16 08:25:29 +00:00
|
|
|
if (isset($post["preview"]))
|
|
|
|
$post["preview"] = proxy_url($post["preview"]);
|
2014-05-03 09:56:57 +00:00
|
|
|
|
2017-03-09 06:58:36 +00:00
|
|
|
//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"]);
|
|
|
|
//}
|
2014-05-03 09:56:57 +00:00
|
|
|
|
|
|
|
// Seems like a bug to me
|
|
|
|
// Buffer doesn't add links to Twitter and App.net (but pictures)
|
2017-06-09 01:20:27 +00:00
|
|
|
//if ($includedlinks && isset($post["url"]))
|
|
|
|
if (($profile->service == "twitter") && isset($post["url"]) && ($post["type"] != "photo"))
|
2014-05-04 20:17:41 +00:00
|
|
|
$post["text"] .= " ".$post["url"];
|
2017-06-09 01:20:27 +00:00
|
|
|
elseif (($profile->service == "appdotnet") && isset($post["url"]) && isset($post["title"]) && ($post["type"] != "photo")) {
|
2014-05-18 21:41:42 +00:00
|
|
|
$post["title"] = shortenmsg($post["title"], 90);
|
|
|
|
$post["text"] = shortenmsg($post["text"], $limit - (24 + strlen($post["title"])));
|
|
|
|
$post["text"] .= "\n[".$post["title"]."](".$post["url"].")";
|
2017-06-09 01:20:27 +00:00
|
|
|
} elseif (($profile->service == "appdotnet") && isset($post["url"]) && ($post["type"] != "photo"))
|
2014-05-18 17:10:48 +00:00
|
|
|
$post["text"] .= " ".$post["url"];
|
2014-12-01 21:31:29 +00:00
|
|
|
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
|
2014-05-18 17:10:48 +00:00
|
|
|
|
2018-01-15 13:15:33 +00:00
|
|
|
$message = [];
|
2014-05-03 09:56:57 +00:00
|
|
|
$message["text"] = $post["text"];
|
|
|
|
$message["profile_ids[]"] = $profile->id;
|
|
|
|
$message["shorten"] = false;
|
|
|
|
$message["now"] = true;
|
|
|
|
|
|
|
|
if (isset($post["title"]))
|
|
|
|
$message["media[title]"] = $post["title"];
|
|
|
|
|
|
|
|
if (isset($post["description"]))
|
|
|
|
$message["media[description]"] = $post["description"];
|
|
|
|
|
2017-06-09 01:20:27 +00:00
|
|
|
if (isset($post["url"]) && ($post["type"] != "photo"))
|
2014-05-03 09:56:57 +00:00
|
|
|
$message["media[link]"] = $post["url"];
|
|
|
|
|
|
|
|
if (isset($post["image"])) {
|
|
|
|
$message["media[picture]"] = $post["image"];
|
|
|
|
if ($post["type"] == "photo")
|
|
|
|
$message["media[thumbnail]"] = $post["image"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($post["preview"]))
|
|
|
|
$message["media[thumbnail]"] = $post["preview"];
|
|
|
|
|
|
|
|
//print_r($message);
|
2016-01-05 14:35:49 +00:00
|
|
|
logger("buffer_send: data for message ".$b["id"].": ".print_r($message, true), LOGGER_DEBUG);
|
2014-05-03 09:56:57 +00:00
|
|
|
$ret = $buffer->go('/updates/create', $message);
|
|
|
|
logger("buffer_send: send message ".$b["id"]." result: ".print_r($ret, true), LOGGER_DEBUG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|