2014-05-03 11:56:57 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: Buffer Post Connector
|
2019-01-18 07:57:11 +01:00
|
|
|
* Description: Post to Buffer (Facebook Pages, LinkedIn, Twitter)
|
2014-05-29 12:42:25 +02:00
|
|
|
* Version: 0.2
|
2014-05-03 11:56:57 +02:00
|
|
|
* Author: Michael Vogel <http://pirati.ca/profile/heluecht>
|
2019-12-07 22:56:43 +01:00
|
|
|
* Status: Unsupported
|
2014-05-03 11:56:57 +02:00
|
|
|
*/
|
2018-01-04 18:15:53 +01:00
|
|
|
require 'addon/buffer/bufferapp.php';
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-01-04 18:15:53 +01:00
|
|
|
use Friendica\App;
|
2017-11-07 00:55:24 +01:00
|
|
|
use Friendica\Core\Config;
|
2018-12-26 08:28:16 +01:00
|
|
|
use Friendica\Core\Hook;
|
2018-01-22 20:03:11 +01:00
|
|
|
use Friendica\Core\L10n;
|
2018-10-30 00:40:18 +01:00
|
|
|
use Friendica\Core\Logger;
|
2017-11-07 00:55:24 +01:00
|
|
|
use Friendica\Core\PConfig;
|
2018-08-11 22:40:48 +02:00
|
|
|
use Friendica\Core\Protocol;
|
2018-10-31 15:55:15 +01:00
|
|
|
use Friendica\Core\Renderer;
|
2018-07-20 14:20:48 +02:00
|
|
|
use Friendica\Database\DBA;
|
2019-12-16 01:05:14 +01:00
|
|
|
use Friendica\DI;
|
2018-04-22 02:50:58 +02:00
|
|
|
use Friendica\Model\ItemContent;
|
2018-07-31 03:20:29 +02:00
|
|
|
use Friendica\Util\Proxy as ProxyUtils;
|
2018-11-08 17:45:19 +01:00
|
|
|
use Friendica\Util\Strings;
|
2017-11-07 00:55:24 +01:00
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
function buffer_install()
|
|
|
|
{
|
2018-12-26 08:28:16 +01:00
|
|
|
Hook::register('hook_fork', 'addon/buffer/buffer.php', 'buffer_hook_fork');
|
|
|
|
Hook::register('post_local', 'addon/buffer/buffer.php', 'buffer_post_local');
|
|
|
|
Hook::register('notifier_normal', 'addon/buffer/buffer.php', 'buffer_send');
|
|
|
|
Hook::register('jot_networks', 'addon/buffer/buffer.php', 'buffer_jot_nets');
|
|
|
|
Hook::register('connector_settings', 'addon/buffer/buffer.php', 'buffer_settings');
|
|
|
|
Hook::register('connector_settings_post', 'addon/buffer/buffer.php', 'buffer_settings_post');
|
2014-05-03 11:56:57 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
function buffer_uninstall()
|
|
|
|
{
|
2018-12-26 08:28:16 +01:00
|
|
|
Hook::unregister('hook_fork', 'addon/buffer/buffer.php', 'buffer_hook_fork');
|
|
|
|
Hook::unregister('post_local', 'addon/buffer/buffer.php', 'buffer_post_local');
|
|
|
|
Hook::unregister('notifier_normal', 'addon/buffer/buffer.php', 'buffer_send');
|
|
|
|
Hook::unregister('jot_networks', 'addon/buffer/buffer.php', 'buffer_jot_nets');
|
|
|
|
Hook::unregister('connector_settings', 'addon/buffer/buffer.php', 'buffer_settings');
|
|
|
|
Hook::unregister('connector_settings_post', 'addon/buffer/buffer.php', 'buffer_settings_post');
|
2014-05-03 11:56:57 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
function buffer_module()
|
|
|
|
{
|
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
function buffer_content(App $a)
|
|
|
|
{
|
|
|
|
if (! local_user()) {
|
2018-01-22 20:03:11 +01:00
|
|
|
notice(L10n::t('Permission denied.') . EOL);
|
2014-05-03 11:56:57 +02:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
require_once "mod/settings.php";
|
2014-05-03 11:56:57 +02:00
|
|
|
settings_init($a);
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
if (isset($a->argv[1])) {
|
2014-05-03 11:56:57 +02:00
|
|
|
switch ($a->argv[1]) {
|
|
|
|
case "connect":
|
|
|
|
$o = buffer_connect($a);
|
|
|
|
break;
|
2018-07-24 13:44:42 +02:00
|
|
|
|
2014-05-03 11:56:57 +02:00
|
|
|
default:
|
|
|
|
$o = print_r($a->argv, true);
|
|
|
|
break;
|
|
|
|
}
|
2018-07-24 13:44:42 +02:00
|
|
|
} else {
|
2014-05-03 11:56:57 +02:00
|
|
|
$o = buffer_connect($a);
|
2018-07-24 13:44:42 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
function buffer_addon_admin(App $a, &$o)
|
2018-01-20 14:57:41 +01:00
|
|
|
{
|
2018-10-31 15:55:15 +01:00
|
|
|
$t = Renderer::getMarkupTemplate("admin.tpl", "addon/buffer/");
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-10-31 15:55:15 +01:00
|
|
|
$o = Renderer::replaceMacros($t, [
|
2018-01-22 20:03:11 +01:00
|
|
|
'$submit' => L10n::t('Save Settings'),
|
2018-01-20 14:57:41 +01:00
|
|
|
// name, label, value, help, [extra values]
|
2018-01-22 20:03:11 +01: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 14:15:33 +01:00
|
|
|
]);
|
2014-05-03 11:56:57 +02:00
|
|
|
}
|
2018-07-24 13:44:42 +02:00
|
|
|
|
|
|
|
function buffer_addon_admin_post(App $a)
|
2018-01-20 14:57:41 +01:00
|
|
|
{
|
2018-11-30 15:11:56 +01:00
|
|
|
$client_id = (!empty($_POST['client_id']) ? Strings::escapeTags(trim($_POST['client_id'])) : '');
|
|
|
|
$client_secret = (!empty($_POST['client_secret']) ? Strings::escapeTags(trim($_POST['client_secret'])) : '');
|
2018-07-24 13:44:42 +02:00
|
|
|
|
|
|
|
Config::set('buffer', 'client_id' , $client_id);
|
2018-01-20 14:57:41 +01:00
|
|
|
Config::set('buffer', 'client_secret', $client_secret);
|
2018-07-24 13:44:42 +02:00
|
|
|
|
2018-01-22 20:03:11 +01:00
|
|
|
info(L10n::t('Settings updated.'). EOL);
|
2014-06-15 13:18:37 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
function buffer_connect(App $a)
|
|
|
|
{
|
2014-05-03 11:56:57 +02:00
|
|
|
if (isset($_REQUEST["error"])) {
|
2018-01-22 20:03:11 +01:00
|
|
|
$o = L10n::t('Error when registering buffer connection:')." ".$_REQUEST["error"];
|
2014-05-03 11:56:57 +02:00
|
|
|
return $o;
|
|
|
|
}
|
2018-07-24 13:44:42 +02:00
|
|
|
|
2014-05-03 11:56:57 +02:00
|
|
|
// 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-07 00:55:24 +01:00
|
|
|
$client_id = Config::get('buffer','client_id');
|
|
|
|
$client_secret = Config::get('buffer','client_secret');
|
2014-05-03 11:56:57 +02:00
|
|
|
|
|
|
|
// The callback URL is the script that gets called after the user authenticates with buffer
|
2019-12-16 01:05:14 +01:00
|
|
|
$callback_url = DI::baseUrl()->get()."/buffer/connect";
|
2014-05-03 11:56:57 +02:00
|
|
|
|
|
|
|
$buffer = new BufferApp($client_id, $client_secret, $callback_url);
|
|
|
|
|
|
|
|
if (!$buffer->ok) {
|
2019-03-20 07:17:04 +01:00
|
|
|
$o = '<a href="' . $buffer->get_login_url() . '">Connect to Buffer!</a>';
|
2014-05-03 11:56:57 +02:00
|
|
|
} else {
|
2018-10-30 00:40:18 +01:00
|
|
|
Logger::log("buffer_connect: authenticated");
|
2019-03-20 07:17:04 +01:00
|
|
|
$o = L10n::t("You are now authenticated to buffer. ");
|
2019-12-16 01:05:14 +01:00
|
|
|
$o .= '<br /><a href="' . DI::baseUrl()->get() . '/settings/connectors">' . L10n::t("return to the connector page") . '</a>';
|
2017-11-07 00:55:24 +01:00
|
|
|
PConfig::set(local_user(), 'buffer','access_token', $buffer->access_token);
|
2014-05-03 11:56:57 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
return $o;
|
2014-05-03 11:56:57 +02:00
|
|
|
}
|
|
|
|
|
2019-03-25 03:44:50 +01:00
|
|
|
function buffer_jot_nets(App $a, array &$jotnets_fields)
|
2018-07-24 13:44:42 +02:00
|
|
|
{
|
|
|
|
if (!local_user()) {
|
2014-05-03 11:56:57 +02:00
|
|
|
return;
|
2018-07-24 13:44:42 +02:00
|
|
|
}
|
|
|
|
|
2020-01-18 16:50:56 +01:00
|
|
|
if (DI::pConfig()->get(local_user(), 'buffer', 'post')) {
|
2019-03-25 03:44:50 +01:00
|
|
|
$jotnets_fields[] = [
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'field' => [
|
|
|
|
'buffer_enable',
|
|
|
|
L10n::t('Post to Buffer'),
|
2020-01-18 16:50:56 +01:00
|
|
|
DI::pConfig()->get(local_user(), 'buffer', 'post_by_default')
|
2019-03-25 03:44:50 +01:00
|
|
|
]
|
|
|
|
];
|
2014-05-03 11:56:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
function buffer_settings(App $a, &$s)
|
|
|
|
{
|
|
|
|
if (! local_user()) {
|
2014-05-03 11:56:57 +02:00
|
|
|
return;
|
2018-07-24 13:44:42 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
|
|
|
/* Add our stylesheet to the page so we can make our settings look nice */
|
|
|
|
|
2019-12-30 20:02:08 +01:00
|
|
|
DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/buffer/buffer.css' . '" media="all" />' . "\r\n";
|
2014-05-03 11:56:57 +02:00
|
|
|
|
|
|
|
/* Get the current state of our config variables */
|
|
|
|
|
2020-01-18 16:50:56 +01:00
|
|
|
$enabled = DI::pConfig()->get(local_user(),'buffer','post');
|
2014-05-03 11:56:57 +02:00
|
|
|
$checked = (($enabled) ? ' checked="checked" ' : '');
|
|
|
|
$css = (($enabled) ? '' : '-disabled');
|
|
|
|
|
2020-01-18 16:50:56 +01:00
|
|
|
$def_enabled = DI::pConfig()->get(local_user(),'buffer','post_by_default');
|
2014-05-03 11:56:57 +02: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 20:03:11 +01:00
|
|
|
$s .= '<img class="connector'.$css.'" src="images/buffer.png" /><h3 class="connector">'. L10n::t('Buffer Export').'</h3>';
|
2014-05-03 11:56:57 +02: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 20:03:11 +01:00
|
|
|
$s .= '<img class="connector'.$css.'" src="images/buffer.png" /><h3 class="connector">'. L10n::t('Buffer Export').'</h3>';
|
2014-05-03 11:56:57 +02:00
|
|
|
$s .= '</span>';
|
|
|
|
|
2017-11-07 00:55:24 +01:00
|
|
|
$client_id = Config::get("buffer", "client_id");
|
|
|
|
$client_secret = Config::get("buffer", "client_secret");
|
2020-01-18 16:50:56 +01:00
|
|
|
$access_token = DI::pConfig()->get(local_user(), "buffer", "access_token");
|
2014-05-03 11:56:57 +02:00
|
|
|
|
|
|
|
$s .= '<div id="buffer-password-wrapper">';
|
2018-07-24 13:44:42 +02:00
|
|
|
|
2014-05-03 11:56:57 +02:00
|
|
|
if ($access_token == "") {
|
|
|
|
$s .= '<div id="buffer-authenticate-wrapper">';
|
2019-12-16 01:05:14 +01:00
|
|
|
$s .= '<a href="'.DI::baseUrl()->get().'/buffer/connect">'.L10n::t("Authenticate your Buffer connection").'</a>';
|
2014-05-03 11:56:57 +02:00
|
|
|
$s .= '</div><div class="clear"></div>';
|
|
|
|
} else {
|
|
|
|
$s .= '<div id="buffer-enable-wrapper">';
|
2018-01-22 20:03:11 +01:00
|
|
|
$s .= '<label id="buffer-enable-label" for="buffer-checkbox">' . L10n::t('Enable Buffer Post Addon') . '</label>';
|
2014-05-03 11:56:57 +02: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 20:03:11 +01:00
|
|
|
$s .= '<label id="buffer-bydefault-label" for="buffer-bydefault">' . L10n::t('Post to Buffer by default') . '</label>';
|
2014-05-03 11:56:57 +02: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 20:03:11 +01:00
|
|
|
$s .= '<label id="buffer-delete-label" for="buffer-delete">' . L10n::t('Check to delete this preset') . '</label>';
|
2014-05-03 11:56:57 +02:00
|
|
|
$s .= '<input id="buffer-delete" type="checkbox" name="buffer_delete" value="1" />';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
|
|
|
|
2018-08-09 06:40:19 +02:00
|
|
|
// The callback URL is the script that gets called after the user authenticates with buffer
|
2019-12-16 01:05:14 +01:00
|
|
|
$callback_url = DI::baseUrl()->get() . '/buffer/connect';
|
2018-08-09 06:40:19 +02:00
|
|
|
|
2014-05-03 11:56:57 +02:00
|
|
|
$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 20:03:11 +01:00
|
|
|
$s .= L10n::t("Posts are going to all accounts that are enabled by default:");
|
2014-05-03 11:56:57 +02: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 20:03:11 +01: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 11:56:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
function buffer_settings_post(App $a, array &$b)
|
|
|
|
{
|
|
|
|
if (!empty($_POST['buffer-submit'])) {
|
|
|
|
if (!empty($_POST['buffer_delete'])) {
|
|
|
|
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 11:56:57 +02:00
|
|
|
} else {
|
2019-10-13 18:07:27 +02:00
|
|
|
PConfig::set(local_user(), 'buffer', 'post' , intval($_POST['buffer'] ?? false));
|
|
|
|
PConfig::set(local_user(), 'buffer', 'post_by_default', intval($_POST['buffer_bydefault'] ?? false));
|
2014-05-03 11:56:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
function buffer_post_local(App $a, array &$b)
|
|
|
|
{
|
2017-09-06 18:16:33 +02:00
|
|
|
if (!local_user() || (local_user() != $b['uid'])) {
|
2014-05-03 11:56:57 +02:00
|
|
|
return;
|
2017-09-06 18:16:33 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2020-01-18 16:50:56 +01:00
|
|
|
$buffer_post = intval(DI::pConfig()->get(local_user(),'buffer','post'));
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
$buffer_enable = (($buffer_post && !empty($_REQUEST['buffer_enable'])) ? intval($_REQUEST['buffer_enable']) : 0);
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2020-01-18 16:50:56 +01:00
|
|
|
if ($b['api_source'] && intval(DI::pConfig()->get(local_user(),'buffer','post_by_default'))) {
|
2014-05-03 11:56:57 +02:00
|
|
|
$buffer_enable = 1;
|
2017-09-06 18:16:33 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2017-09-06 18:16:33 +02:00
|
|
|
if (!$buffer_enable) {
|
2014-05-03 11:56:57 +02:00
|
|
|
return;
|
2017-09-06 18:16:33 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2017-09-06 18:16:33 +02:00
|
|
|
if (strlen($b['postopts'])) {
|
2014-05-03 11:56:57 +02:00
|
|
|
$b['postopts'] .= ',';
|
2017-09-06 18:16:33 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
|
|
|
$b['postopts'] .= 'buffer';
|
|
|
|
}
|
|
|
|
|
2018-11-10 17:20:19 +01:00
|
|
|
function buffer_hook_fork(&$a, &$b)
|
|
|
|
{
|
|
|
|
if ($b['name'] != 'notifier_normal') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$post = $b['data'];
|
|
|
|
|
|
|
|
if ($post['deleted'] || $post['private'] || ($post['created'] !== $post['edited']) ||
|
|
|
|
!strstr($post['postopts'], 'buffer') || ($post['parent'] != $post['id'])) {
|
|
|
|
$b['execute'] = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
function buffer_send(App $a, array &$b)
|
2018-01-04 18:15:53 +01:00
|
|
|
{
|
2018-07-24 13:44:42 +02:00
|
|
|
if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
|
2014-05-03 11:56:57 +02:00
|
|
|
return;
|
2018-01-10 04:27:40 +01:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
if (!strstr($b['postopts'],'buffer')) {
|
2014-05-03 11:56:57 +02:00
|
|
|
return;
|
2018-01-10 04:27:40 +01:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
if ($b['parent'] != $b['id']) {
|
2014-05-03 11:56:57 +02:00
|
|
|
return;
|
2018-01-10 04:27:40 +01:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2017-11-26 00:56:18 +01:00
|
|
|
// Dont't post if the post doesn't belong to us.
|
|
|
|
// This is a check for forum postings
|
2018-07-20 14:20:48 +02:00
|
|
|
$self = DBA::selectFirst('contact', ['id'], ['uid' => $b['uid'], 'self' => true]);
|
2017-11-26 00:56:18 +01:00
|
|
|
if ($b['contact-id'] != $self['id']) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-03 11:56:57 +02:00
|
|
|
// if post comes from buffer don't send it back
|
2014-12-01 22:31:29 +01:00
|
|
|
//if($b['app'] == "Buffer")
|
|
|
|
// return;
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2017-11-07 00:55:24 +01:00
|
|
|
$client_id = Config::get("buffer", "client_id");
|
|
|
|
$client_secret = Config::get("buffer", "client_secret");
|
2020-01-18 16:50:56 +01:00
|
|
|
$access_token = DI::pConfig()->get($b['uid'], "buffer","access_token");
|
2018-07-15 20:40:20 +02:00
|
|
|
$callback_url = "";
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-01-27 14:52:02 +01:00
|
|
|
if ($access_token) {
|
2014-05-03 11:56:57 +02:00
|
|
|
$buffer = new BufferApp($client_id, $client_secret, $callback_url, $access_token);
|
|
|
|
|
|
|
|
$profiles = $buffer->go('/profiles');
|
|
|
|
if (is_array($profiles)) {
|
2018-10-30 14:48:09 +01:00
|
|
|
Logger::log("Will send these parameter ".print_r($b, true), Logger::DEBUG);
|
2014-12-01 22:31:29 +01:00
|
|
|
|
2014-05-03 11:56:57 +02:00
|
|
|
foreach ($profiles as $profile) {
|
|
|
|
if (!$profile->default)
|
|
|
|
continue;
|
|
|
|
|
2014-12-01 22:31:29 +01:00
|
|
|
$send = false;
|
|
|
|
|
2014-05-03 11:56:57 +02:00
|
|
|
switch ($profile->service) {
|
|
|
|
case 'facebook':
|
2018-08-11 22:40:48 +02:00
|
|
|
$send = ($b["extid"] != Protocol::FACEBOOK);
|
2014-05-03 11:56:57 +02:00
|
|
|
$limit = 0;
|
|
|
|
$includedlinks = false;
|
2014-12-01 22:31:29 +01:00
|
|
|
$htmlmode = 9;
|
2014-05-03 11:56:57 +02:00
|
|
|
break;
|
2018-07-24 13:44:42 +02:00
|
|
|
|
2014-05-03 11:56:57 +02:00
|
|
|
case 'twitter':
|
2018-08-11 22:40:48 +02:00
|
|
|
$send = ($b["extid"] != Protocol::TWITTER);
|
2017-11-07 23:44:39 +01:00
|
|
|
$limit = 280;
|
2014-05-03 11:56:57 +02:00
|
|
|
$includedlinks = true;
|
2014-12-01 22:31:29 +01:00
|
|
|
$htmlmode = 8;
|
2014-05-03 11:56:57 +02:00
|
|
|
break;
|
2018-07-24 13:44:42 +02:00
|
|
|
|
2014-05-03 11:56:57 +02:00
|
|
|
case 'linkedin':
|
2018-08-11 22:40:48 +02:00
|
|
|
$send = ($b["extid"] != Protocol::LINKEDIN);
|
2014-05-03 11:56:57 +02:00
|
|
|
$limit = 700;
|
|
|
|
$includedlinks = true;
|
2014-12-01 22:31:29 +01:00
|
|
|
$htmlmode = 2;
|
2014-05-03 11:56:57 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-01 22:31:29 +01:00
|
|
|
if (!$send)
|
|
|
|
continue;
|
|
|
|
|
2014-05-03 11:56:57 +02:00
|
|
|
$item = $b;
|
|
|
|
|
2018-04-22 02:50:58 +02:00
|
|
|
$post = ItemContent::getPlaintextPost($item, $limit, $includedlinks, $htmlmode);
|
2018-10-30 14:48:09 +01:00
|
|
|
Logger::log("buffer_send: converted message ".$b["id"]." result: ".print_r($post, true), Logger::DEBUG);
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2014-08-16 10:25:29 +02:00
|
|
|
// The image proxy is used as a sanitizer. Buffer seems to be really picky about pictures
|
2018-07-24 13:44:42 +02:00
|
|
|
if (isset($post["image"])) {
|
2018-07-28 20:24:16 +02:00
|
|
|
$post["image"] = ProxyUtils::proxifyUrl($post["image"]);
|
2018-07-24 13:44:42 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
if (isset($post["preview"])) {
|
2018-07-28 20:24:16 +02:00
|
|
|
$post["preview"] = ProxyUtils::proxifyUrl($post["preview"]);
|
2018-07-24 13:44:42 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
|
|
|
// Seems like a bug to me
|
2018-08-09 06:40:19 +02:00
|
|
|
// Buffer doesn't add links to Twitter (but pictures)
|
2018-07-24 13:44:42 +02:00
|
|
|
if (($profile->service == "twitter") && isset($post["url"]) && ($post["type"] != "photo")) {
|
|
|
|
$post["text"] .= " " . $post["url"];
|
|
|
|
}
|
2014-05-18 19:10:48 +02:00
|
|
|
|
2018-01-15 14:15:33 +01:00
|
|
|
$message = [];
|
2014-05-03 11:56:57 +02:00
|
|
|
$message["text"] = $post["text"];
|
|
|
|
$message["profile_ids[]"] = $profile->id;
|
|
|
|
$message["shorten"] = false;
|
|
|
|
$message["now"] = true;
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
if (isset($post["title"])) {
|
2014-05-03 11:56:57 +02:00
|
|
|
$message["media[title]"] = $post["title"];
|
2018-07-24 13:44:42 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
if (isset($post["description"])) {
|
2014-05-03 11:56:57 +02:00
|
|
|
$message["media[description]"] = $post["description"];
|
2018-07-24 13:44:42 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
if (isset($post["url"]) && ($post["type"] != "photo")) {
|
2014-05-03 11:56:57 +02:00
|
|
|
$message["media[link]"] = $post["url"];
|
2018-07-24 13:44:42 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
|
|
|
if (isset($post["image"])) {
|
|
|
|
$message["media[picture]"] = $post["image"];
|
2018-07-24 13:44:42 +02:00
|
|
|
|
|
|
|
if ($post["type"] == "photo") {
|
2014-05-03 11:56:57 +02:00
|
|
|
$message["media[thumbnail]"] = $post["image"];
|
2018-07-24 13:44:42 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 13:44:42 +02:00
|
|
|
if (isset($post["preview"])) {
|
2014-05-03 11:56:57 +02:00
|
|
|
$message["media[thumbnail]"] = $post["preview"];
|
2018-07-24 13:44:42 +02:00
|
|
|
}
|
2014-05-03 11:56:57 +02:00
|
|
|
|
|
|
|
//print_r($message);
|
2018-10-30 14:48:09 +01:00
|
|
|
Logger::log("buffer_send: data for message " . $b["id"] . ": " . print_r($message, true), Logger::DEBUG);
|
2014-05-03 11:56:57 +02:00
|
|
|
$ret = $buffer->go('/updates/create', $message);
|
2018-10-30 14:48:09 +01:00
|
|
|
Logger::log("buffer_send: send message " . $b["id"] . " result: " . print_r($ret, true), Logger::DEBUG);
|
2014-05-03 11:56:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|