Mark facebook and facebook_restrict as unsupported, change version number of fbsync. #189
11 changed files with 652 additions and 20 deletions
5
buffer/README.md
Normal file
5
buffer/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
The addon uses the library from [https://github.com/thewebguy/bufferapp-php](https://github.com/thewebguy/bufferapp-php)
|
||||
|
||||
Please register an app at [http://bufferapp.com/developers/api](http://bufferapp.com/developers/api)
|
||||
|
||||
Please use (your server address)/buffer/connect as Callback URL.
|
15
buffer/buffer.css
Executable file
15
buffer/buffer.css
Executable file
|
@ -0,0 +1,15 @@
|
|||
#buffer-enable-label, #buffer-bydefault-label, #buffer-delete-label {
|
||||
float: left;
|
||||
width: 200px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
#buffer-checkbox, #buffer-bydefault, #buffer-delete {
|
||||
float: left;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
#buffer-submit {
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
373
buffer/buffer.php
Normal file
373
buffer/buffer.php
Normal file
|
@ -0,0 +1,373 @@
|
|||
<?php
|
||||
/**
|
||||
* Name: Buffer Post Connector
|
||||
* Description: Post to Buffer
|
||||
* Version: 0.1 alpha
|
||||
* Author: Michael Vogel <http://pirati.ca/profile/heluecht>
|
||||
*/
|
||||
require('addon/buffer/bufferapp.php');
|
||||
|
||||
function buffer_install() {
|
||||
register_hook('post_local', 'addon/buffer/buffer.php', 'buffer_post_local');
|
||||
register_hook('notifier_normal', 'addon/buffer/buffer.php', 'buffer_send');
|
||||
register_hook('jot_networks', 'addon/buffer/buffer.php', 'buffer_jot_nets');
|
||||
register_hook('connector_settings', 'addon/buffer/buffer.php', 'buffer_settings');
|
||||
register_hook('connector_settings_post', 'addon/buffer/buffer.php', 'buffer_settings_post');
|
||||
}
|
||||
|
||||
function buffer_uninstall() {
|
||||
unregister_hook('post_local', 'addon/buffer/buffer.php', 'buffer_post_local');
|
||||
unregister_hook('notifier_normal', 'addon/buffer/buffer.php', 'buffer_send');
|
||||
unregister_hook('jot_networks', 'addon/buffer/buffer.php', 'buffer_jot_nets');
|
||||
unregister_hook('connector_settings', 'addon/buffer/buffer.php', 'buffer_settings');
|
||||
unregister_hook('connector_settings_post', 'addon/buffer/buffer.php', 'buffer_settings_post');
|
||||
}
|
||||
|
||||
function buffer_module() {}
|
||||
|
||||
function buffer_content(&$a) {
|
||||
|
||||
if(! local_user()) {
|
||||
notice( t('Permission denied.') . EOL);
|
||||
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;
|
||||
}
|
||||
|
||||
function buffer_plugin_admin(&$a, &$o){
|
||||
$t = get_markup_template( "admin.tpl", "addon/buffer/" );
|
||||
|
||||
$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' ), ''),
|
||||
));
|
||||
}
|
||||
|
||||
function buffer_connect(&$a) {
|
||||
|
||||
if (isset($_REQUEST["error"])) {
|
||||
$o = t('Error when registering buffer connection:')." ".$_REQUEST["error"];
|
||||
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
|
||||
$client_id = get_config('buffer','client_id');
|
||||
$client_secret = get_config('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";
|
||||
|
||||
$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");
|
||||
$o .= t("You are now authenticated to buffer. ");
|
||||
$o .= '<br /><a href="'.$a->get_baseurl().'/settings/connectors">'.t("return to the connector page").'</a>';
|
||||
set_pconfig(local_user(), 'buffer','access_token', $buffer->access_token);
|
||||
}
|
||||
|
||||
return($o);
|
||||
}
|
||||
|
||||
function buffer_jot_nets(&$a,&$b) {
|
||||
if(! local_user())
|
||||
return;
|
||||
|
||||
$buffer_post = get_pconfig(local_user(),'buffer','post');
|
||||
if(intval($buffer_post) == 1) {
|
||||
$buffer_defpost = get_pconfig(local_user(),'buffer','post_by_default');
|
||||
$selected = ((intval($buffer_defpost) == 1) ? ' checked="checked" ' : '');
|
||||
$b .= '<div class="profile-jot-net"><input type="checkbox" name="buffer_enable"' . $selected . ' value="1" /> '
|
||||
. t('Post to Buffer') . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
$enabled = get_pconfig(local_user(),'buffer','post');
|
||||
$checked = (($enabled) ? ' checked="checked" ' : '');
|
||||
$css = (($enabled) ? '' : '-disabled');
|
||||
|
||||
$def_enabled = get_pconfig(local_user(),'buffer','post_by_default');
|
||||
$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\');">';
|
||||
$s .= '<img class="connector'.$css.'" src="images/buffer.png" /><h3 class="connector">'. t('Buffer Export').'</h3>';
|
||||
$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\');">';
|
||||
$s .= '<img class="connector'.$css.'" src="images/buffer.png" /><h3 class="connector">'. t('Buffer Export').'</h3>';
|
||||
$s .= '</span>';
|
||||
|
||||
$client_id = get_config("buffer", "client_id");
|
||||
$client_secret = get_config("buffer", "client_secret");
|
||||
$access_token = get_pconfig(local_user(), "buffer", "access_token");
|
||||
|
||||
$s .= '<div id="buffer-password-wrapper">';
|
||||
if ($access_token == "") {
|
||||
$s .= '<div id="buffer-authenticate-wrapper">';
|
||||
$s .= '<a href="'.$a->get_baseurl().'/buffer/connect">'.t("Authenticate your Buffer connection").'</a>';
|
||||
$s .= '</div><div class="clear"></div>';
|
||||
} else {
|
||||
$s .= '<div id="buffer-enable-wrapper">';
|
||||
$s .= '<label id="buffer-enable-label" for="buffer-checkbox">' . t('Enable Buffer Post Plugin') . '</label>';
|
||||
$s .= '<input id="buffer-checkbox" type="checkbox" name="buffer" value="1" ' . $checked . '/>';
|
||||
$s .= '</div><div class="clear"></div>';
|
||||
|
||||
$s .= '<div id="buffer-bydefault-wrapper">';
|
||||
$s .= '<label id="buffer-bydefault-label" for="buffer-bydefault">' . t('Post to Buffer by default') . '</label>';
|
||||
$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">';
|
||||
$s .= '<label id="buffer-delete-label" for="buffer-delete">' . t('Check to delete this preset') . '</label>';
|
||||
$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">';
|
||||
$s .= t("Posts are going to all accounts that are enabled by default:");
|
||||
$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 */
|
||||
|
||||
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="buffer-submit" name="buffer-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
} 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function buffer_post_local(&$a,&$b) {
|
||||
|
||||
if((! local_user()) || (local_user() != $b['uid']))
|
||||
return;
|
||||
|
||||
$buffer_post = intval(get_pconfig(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')))
|
||||
$buffer_enable = 1;
|
||||
|
||||
if(! $buffer_enable)
|
||||
return;
|
||||
|
||||
if(strlen($b['postopts']))
|
||||
$b['postopts'] .= ',';
|
||||
|
||||
$b['postopts'] .= 'buffer';
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if($b['parent'] != $b['id'])
|
||||
return;
|
||||
|
||||
// if post comes from buffer don't send it back
|
||||
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");
|
||||
|
||||
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)) {
|
||||
foreach ($profiles as $profile) {
|
||||
if (!$profile->default)
|
||||
continue;
|
||||
|
||||
switch ($profile->service) {
|
||||
case 'appdotnet':
|
||||
$limit = 256;
|
||||
$markup = false;
|
||||
$includedlinks = true;
|
||||
break;
|
||||
case 'facebook':
|
||||
$limit = 0;
|
||||
$markup = false;
|
||||
$includedlinks = false;
|
||||
break;
|
||||
case 'google':
|
||||
$limit = 0;
|
||||
$markup = true;
|
||||
$includedlinks = false;
|
||||
break;
|
||||
case 'twitter':
|
||||
$limit = 140;
|
||||
$markup = false;
|
||||
$includedlinks = true;
|
||||
break;
|
||||
case 'linkedin':
|
||||
$limit = 700;
|
||||
$markup = false;
|
||||
$includedlinks = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$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"]);
|
||||
}
|
||||
|
||||
$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"]);
|
||||
|
||||
if (isset($post["preview"]))
|
||||
$post["preview"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($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"]))
|
||||
$post["text"] .= " ".$post["url"];
|
||||
|
||||
$message = array();
|
||||
$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"];
|
||||
|
||||
if (isset($post["url"]) AND ($post["type"] != "photo"))
|
||||
$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);
|
||||
$ret = $buffer->go('/updates/create', $message);
|
||||
logger("buffer_send: send message ".$b["id"]." result: ".print_r($ret, true), LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
205
buffer/bufferapp.php
Normal file
205
buffer/bufferapp.php
Normal file
|
@ -0,0 +1,205 @@
|
|||
<?
|
||||
class BufferApp {
|
||||
private $client_id;
|
||||
private $client_secret;
|
||||
private $code;
|
||||
public $access_token;
|
||||
|
||||
private $callback_url;
|
||||
private $authorize_url = 'https://bufferapp.com/oauth2/authorize';
|
||||
private $access_token_url = 'https://api.bufferapp.com/1/oauth2/token.json';
|
||||
private $buffer_url = 'https://api.bufferapp.com/1';
|
||||
|
||||
public $ok = false;
|
||||
|
||||
private $endpoints = array(
|
||||
'/user' => 'get',
|
||||
|
||||
'/profiles' => 'get',
|
||||
'/profiles/:id' => 'get',
|
||||
'/profiles/:id/schedules' => 'get',
|
||||
'/profiles/:id/schedules/update' => 'post', // Array schedules [0][days][]=mon, [0][times][]=12:00
|
||||
|
||||
'/updates/:id' => 'get',
|
||||
'/profiles/:id/updates/pending' => 'get',
|
||||
'/profiles/:id/updates/sent' => 'get',
|
||||
'/updates/:id/interactions' => 'get',
|
||||
|
||||
'/profiles/:id/updates/reorder' => 'post', // Array order, int offset, bool utc
|
||||
'/profiles/:id/updates/shuffle' => 'post',
|
||||
'/updates/create' => 'post', // String text, Array profile_ids, Aool shorten, Bool now, Array media ['link'], ['description'], ['picture']
|
||||
'/updates/:id/update' => 'post', // String text, Bool now, Array media ['link'], ['description'], ['picture'], Bool utc
|
||||
'/updates/:id/share' => 'post',
|
||||
'/updates/:id/destroy' => 'post',
|
||||
'/updates/:id/move_to_top' => 'post',
|
||||
|
||||
'/links/shares' => 'get',
|
||||
|
||||
'/info/configuration' => 'get',
|
||||
|
||||
);
|
||||
|
||||
public $errors = array(
|
||||
'invalid-endpoint' => 'The endpoint you supplied does not appear to be valid.',
|
||||
|
||||
'403' => 'Permission denied.',
|
||||
'404' => 'Endpoint not found.',
|
||||
'405' => 'Method not allowed.',
|
||||
'1000' => 'An unknown error occurred.',
|
||||
'1001' => 'Access token required.',
|
||||
'1002' => 'Not within application scope.',
|
||||
'1003' => 'Parameter not recognized.',
|
||||
'1004' => 'Required parameter missing.',
|
||||
'1005' => 'Unsupported response format.',
|
||||
'1006' => 'Parameter value not within bounds.',
|
||||
'1010' => 'Profile could not be found.',
|
||||
'1011' => 'No authorization to access profile.',
|
||||
'1012' => 'Profile did not save successfully.',
|
||||
'1013' => 'Profile schedule limit reached.',
|
||||
'1014' => 'Profile limit for user has been reached.',
|
||||
'1015' => 'Profile could not be destroyed.',
|
||||
'1016' => 'Profile buffer could not be emptied.',
|
||||
'1020' => 'Update could not be found.',
|
||||
'1021' => 'No authorization to access update.',
|
||||
'1022' => 'Update did not save successfully.',
|
||||
'1023' => 'Update limit for profile has been reached.',
|
||||
'1024' => 'Update limit for team profile has been reached.',
|
||||
'1025' => "Update was recently posted, can't post duplicate content.",
|
||||
'1026' => 'Update must be in error status to requeue.',
|
||||
'1027' => 'Update must be in buffer and not custom scheduled in order to move to top.',
|
||||
'1028' => 'Update soft limit for profile reached.',
|
||||
'1029' => 'Event type not supported.',
|
||||
'1030' => 'Media filetype not supported.',
|
||||
'1031' => 'Media filesize out of acceptable range.',
|
||||
'1032' => 'Unable to post image to LinkedIn group(s).',
|
||||
'1033' => 'Comments can only be posted to Facebook at this time.',
|
||||
'1034' => 'Cannot schedule updates in the past.',
|
||||
'1042' => 'User did not save successfully.',
|
||||
'1050' => 'Client could not be found.',
|
||||
'1051' => 'No authorization to access client.',
|
||||
);
|
||||
|
||||
function __construct($client_id = '', $client_secret = '', $callback_url = '', $access_token = '') {
|
||||
if ($client_id) $this->set_client_id($client_id);
|
||||
if ($client_secret) $this->set_client_secret($client_secret);
|
||||
if ($callback_url) $this->set_callback_url($callback_url);
|
||||
if ($access_token) $this->access_token = $access_token;
|
||||
|
||||
if (isset($_GET['code']) AND $_GET['code']) {
|
||||
$this->code = $_GET['code'];
|
||||
$this->create_access_token_url();
|
||||
}
|
||||
|
||||
if (!$access_token)
|
||||
$this->retrieve_access_token();
|
||||
}
|
||||
|
||||
function go($endpoint = '', $data = '') {
|
||||
if (in_array($endpoint, array_keys($this->endpoints))) {
|
||||
$done_endpoint = $endpoint;
|
||||
} else {
|
||||
$ok = false;
|
||||
|
||||
foreach (array_keys($this->endpoints) as $done_endpoint) {
|
||||
if (preg_match('/' . preg_replace('/(\:\w+)/i', '(\w+)', str_replace('/', '\/', $done_endpoint)) . '/i', $endpoint, $match)) {
|
||||
$ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$ok) return $this->error('invalid-endpoint');
|
||||
}
|
||||
|
||||
if (!$data || !is_array($data)) $data = array();
|
||||
$data['access_token'] = $this->access_token;
|
||||
|
||||
$method = $this->endpoints[$done_endpoint]; //get() or post()
|
||||
return $this->$method($this->buffer_url . $endpoint . '.json', $data);
|
||||
}
|
||||
|
||||
function store_access_token() {
|
||||
$_SESSION['oauth']['buffer']['access_token'] = $this->access_token;
|
||||
}
|
||||
|
||||
function retrieve_access_token() {
|
||||
$this->access_token = $_SESSION['oauth']['buffer']['access_token'];
|
||||
|
||||
if ($this->access_token) {
|
||||
$this->ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
function error($error) {
|
||||
return (object) array('error' => $this->errors[$error]);
|
||||
}
|
||||
|
||||
function create_access_token_url() {
|
||||
$data = array(
|
||||
'code' => $this->code,
|
||||
'grant_type' => 'authorization_code',
|
||||
'client_id' => $this->client_id,
|
||||
'client_secret' => $this->client_secret,
|
||||
'redirect_uri' => $this->callback_url,
|
||||
);
|
||||
|
||||
$obj = $this->post($this->access_token_url, $data);
|
||||
$this->access_token = $obj->access_token;
|
||||
|
||||
$this->store_access_token();
|
||||
}
|
||||
|
||||
function req($url = '', $data = '', $post = true) {
|
||||
if (!$url) return false;
|
||||
if (!$data || !is_array($data)) $data = array();
|
||||
|
||||
$options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false);
|
||||
|
||||
if ($post) {
|
||||
$options += array(
|
||||
CURLOPT_POST => $post,
|
||||
CURLOPT_POSTFIELDS => $data
|
||||
);
|
||||
} else {
|
||||
$url .= '?' . http_build_query($data);
|
||||
}
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, $options);
|
||||
$rs = curl_exec($ch);
|
||||
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($code >= 400) {
|
||||
return $this->error($code);
|
||||
}
|
||||
|
||||
return json_decode($rs);
|
||||
}
|
||||
|
||||
function get($url = '', $data = '') {
|
||||
return $this->req($url, $data, false);
|
||||
}
|
||||
|
||||
function post($url = '', $data = '') {
|
||||
return $this->req($url, $data, true);
|
||||
}
|
||||
|
||||
function get_login_url() {
|
||||
return $this->authorize_url . '?'
|
||||
. 'client_id=' . $this->client_id
|
||||
. '&redirect_uri=' . urlencode($this->callback_url)
|
||||
. '&response_type=code';
|
||||
}
|
||||
|
||||
function set_client_id($client_id) {
|
||||
$this->client_id = $client_id;
|
||||
}
|
||||
|
||||
function set_client_secret($client_secret) {
|
||||
$this->client_secret = $client_secret;
|
||||
}
|
||||
|
||||
function set_callback_url($callback_url) {
|
||||
$this->callback_url = $callback_url;
|
||||
}
|
||||
}
|
||||
?>
|
3
buffer/templates/admin.tpl
Normal file
3
buffer/templates/admin.tpl
Normal file
|
@ -0,0 +1,3 @@
|
|||
{{include file="field_input.tpl" field=$client_id}}
|
||||
{{include file="field_input.tpl" field=$client_secret}}
|
||||
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}" /></div>
|
|
@ -4,7 +4,7 @@
|
|||
* Version: 1.3
|
||||
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
|
||||
* Author: Tobias Hößl <https://github.com/CatoTH/>
|
||||
*
|
||||
* Status: Unsupported
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Description: Install this addon and Facebook users will not be able to link friends. Existing users that are linking friends will not be affected.
|
||||
* Version: 1.0
|
||||
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
|
||||
* Status: Unsupported
|
||||
*/
|
||||
|
||||
|
||||
|
|
|
@ -134,10 +134,6 @@ function fbpost_post(&$a) {
|
|||
$uid = local_user();
|
||||
if($uid){
|
||||
|
||||
|
||||
$fb_limited = get_config('facebook','crestrict');
|
||||
|
||||
|
||||
$value = ((x($_POST,'post_by_default')) ? intval($_POST['post_by_default']) : 0);
|
||||
set_pconfig($uid,'facebook','post_by_default', $value);
|
||||
|
||||
|
@ -193,15 +189,32 @@ function fbpost_content(&$a) {
|
|||
settings_init($a);
|
||||
|
||||
$o = '';
|
||||
$accounts = array();
|
||||
|
||||
$fb_installed = false;
|
||||
if (get_pconfig(local_user(),'facebook','post')) {
|
||||
$access_token = get_pconfig(local_user(),'facebook','access_token');
|
||||
if ($access_token) {
|
||||
$s = fetch_url('https://graph.facebook.com/me/feed?access_token=' . $access_token);
|
||||
// fetching the list of accounts to check, if facebook is working
|
||||
// The value is needed several lines below.
|
||||
$url = 'https://graph.facebook.com/me/accounts';
|
||||
$s = fetch_url($url."?access_token=".$access_token, false, $redirects, 10);
|
||||
if($s) {
|
||||
$j = json_decode($s);
|
||||
if (isset($j->data)) $fb_installed = true;
|
||||
$accounts = json_decode($s);
|
||||
if (isset($accounts->data))
|
||||
$fb_installed = true;
|
||||
}
|
||||
|
||||
// I'm not totally sure, if this above will work in every situation,
|
||||
// So this old code will be called as well.
|
||||
if (!$fb_installed) {
|
||||
$url ="https://graph.facebook.com/me/feed";
|
||||
$s = fetch_url($url."?access_token=".$access_token."&limit=1", false, $redirects, 10);
|
||||
if($s) {
|
||||
$j = json_decode($s);
|
||||
if (isset($j->data))
|
||||
$fb_installed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -265,9 +278,9 @@ function fbpost_content(&$a) {
|
|||
$post_to_page = get_pconfig(local_user(),'facebook','post_to_page');
|
||||
$page_access_token = get_pconfig(local_user(),'facebook','page_access_token');
|
||||
$fb_token = get_pconfig($a->user['uid'],'facebook','access_token');
|
||||
$url = 'https://graph.facebook.com/me/accounts';
|
||||
$x = fetch_url($url."?access_token=".$fb_token);
|
||||
$accounts = json_decode($x);
|
||||
//$url = 'https://graph.facebook.com/me/accounts';
|
||||
//$x = fetch_url($url."?access_token=".$fb_token, false, $redirects, 10);
|
||||
//$accounts = json_decode($x);
|
||||
|
||||
$o .= t("Post to page/group:")."<select name='post_to_page'>";
|
||||
if (intval($post_to_page) == 0)
|
||||
|
@ -284,7 +297,7 @@ function fbpost_content(&$a) {
|
|||
}
|
||||
|
||||
$url = 'https://graph.facebook.com/me/groups';
|
||||
$x = fetch_url($url."?access_token=".$fb_token);
|
||||
$x = fetch_url($url."?access_token=".$fb_token, false, $redirects, 10);
|
||||
$groups = json_decode($x);
|
||||
|
||||
foreach($groups->data as $group) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* Name: Facebook Sync
|
||||
* Description: Synchronizes the Facebook Newsfeed
|
||||
* Version: 0.0.1 alpha
|
||||
* Version: 1.0
|
||||
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
|
||||
*/
|
||||
|
||||
|
|
|
@ -321,6 +321,7 @@ function gpluspost_createmsg($b) {
|
|||
$image = htmlspecialchars_decode($image);
|
||||
|
||||
$body = $b["body"];
|
||||
|
||||
if ($b["title"] != "")
|
||||
$body = "*".$b["title"]."*\n\n".$body;
|
||||
|
||||
|
@ -558,6 +559,7 @@ function gpluspost_init() {
|
|||
function gpluspost_feeditem($pid, $uid) {
|
||||
global $a;
|
||||
|
||||
require_once('include/api.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once("include/html2plain.php");
|
||||
require_once("include/network.php");
|
||||
|
@ -569,6 +571,11 @@ function gpluspost_feeditem($pid, $uid) {
|
|||
|
||||
$item['body'] = bb_CleanPictureLinks($item['body']);
|
||||
|
||||
$item['body'] = bb_remove_share_information($item['body'], true);
|
||||
|
||||
if ($item["title"] != "")
|
||||
$item['body'] = "*".$item["title"]."*\n\n".$item['body'];
|
||||
|
||||
// Looking for the first image
|
||||
$image = '';
|
||||
if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$item['body'],$matches))
|
||||
|
@ -593,8 +600,12 @@ function gpluspost_feeditem($pid, $uid) {
|
|||
|
||||
$body = $item['body'];
|
||||
|
||||
$body = preg_replace("(\[b\](.*?)\[\/b\])ism",'*$1*',$body);
|
||||
$body = preg_replace("(\[i\](.*?)\[\/i\])ism",'_$1_',$body);
|
||||
$body = preg_replace("(\[s\](.*?)\[\/s\])ism",'-$1-',$body);
|
||||
|
||||
// At first convert the text to html
|
||||
$html = bbcode($body, false, false, 2);
|
||||
$html = bbcode(api_clean_plain_items($body), false, false, 2);
|
||||
|
||||
// Then convert it to plain text
|
||||
$msg = trim(html2plain($html, 0, true));
|
||||
|
@ -655,6 +666,11 @@ function gpluspost_feeditem($pid, $uid) {
|
|||
|
||||
$msglink = htmlspecialchars(html_entity_decode($msglink));
|
||||
|
||||
if (strpos($msg, $msglink) == 0)
|
||||
$msg .= "\n".$msglink;
|
||||
|
||||
$msg = nl2br($msg);
|
||||
|
||||
$title = str_replace("&", "&", $title);
|
||||
//$html = str_replace("&", "&", $html);
|
||||
|
||||
|
@ -668,7 +684,7 @@ function gpluspost_feeditem($pid, $uid) {
|
|||
echo "\t\t<author>\n\t\t\t<name><![CDATA[".$item["author-name"]."]]></name>\n";
|
||||
echo "\t\t\t<uri>".$item["author-link"]."</uri>\n\t\t</author>\n";
|
||||
//echo '<content type="image/png" src="http://media.example.org/the_beach.png"/>';
|
||||
echo "\t\t".'<content type="html" xml:space="preserve" xml:base="'.$item["plink"].'"><![CDATA['.$html."]]></content>\n";
|
||||
echo "\t\t".'<content type="html" xml:space="preserve" xml:base="'.$item["plink"].'"><![CDATA['.$msg."]]></content>\n";
|
||||
echo "\t</entry>\n";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,8 @@ function pumpio_content(&$a) {
|
|||
return '';
|
||||
}
|
||||
|
||||
if (function_exists("apc_delete")) {
|
||||
$toDelete = new APCIterator('user', APC_ITER_VALUE);
|
||||
apc_delete($toDelete);
|
||||
}
|
||||
require_once("mod/settings.php");
|
||||
settings_init($a);
|
||||
|
||||
if (isset($a->argv[1]))
|
||||
switch ($a->argv[1]) {
|
||||
|
@ -323,7 +321,7 @@ function pumpio_settings_post(&$a,&$b) {
|
|||
set_pconfig(local_user(),'pumpio','mirror',$_POST['pumpio_mirror']);
|
||||
set_pconfig(local_user(),'pumpio','post_by_default',intval($_POST['pumpio_bydefault']));
|
||||
|
||||
header("Location: ".$a->get_baseurl()."/pumpio/connect");
|
||||
//header("Location: ".$a->get_baseurl()."/pumpio/connect");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -410,6 +408,9 @@ function pumpio_send(&$a,&$b) {
|
|||
if($b['app'] == "pump.io")
|
||||
return;
|
||||
|
||||
// To-Do;
|
||||
// Support for native shares
|
||||
// http://<hostname>/api/<type>/shares?id=<the-object-id>
|
||||
|
||||
$oauth_token = get_pconfig($b['uid'], "pumpio", "oauth_token");
|
||||
$oauth_token_secret = get_pconfig($b['uid'], "pumpio", "oauth_token_secret");
|
||||
|
|
Loading…
Reference in a new issue