background deliver plugins

This commit is contained in:
Friendika 2011-10-11 18:46:33 -07:00
parent ce7b6d6bb2
commit 754941e42b
8 changed files with 239 additions and 154 deletions

View file

@ -48,20 +48,26 @@ define('FACEBOOK_MAXPOSTLEN', 420);
function facebook_install() {
register_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
register_hook('post_local', 'addon/facebook/facebook.php', 'facebook_post_local');
register_hook('notifier_normal', 'addon/facebook/facebook.php', 'facebook_post_hook');
register_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets');
register_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
register_hook('connector_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
register_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron');
register_hook('queue_predeliver', 'addon/facebook/facebook.php', 'fb_queue_hook');
}
function facebook_uninstall() {
unregister_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
unregister_hook('post_local', 'addon/facebook/facebook.php', 'facebook_post_local');
unregister_hook('notifier_normal', 'addon/facebook/facebook.php', 'facebook_post_hook');
unregister_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets');
unregister_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
unregister_hook('connector_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
unregister_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron');
unregister_hook('queue_predeliver', 'addon/facebook/facebook.php', 'fb_queue_hook');
// hook moved
unregister_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
unregister_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
}
@ -481,6 +487,10 @@ function facebook_jot_nets(&$a,&$b) {
function facebook_post_hook(&$a,&$b) {
if($b['deleted'] || ($b['created'] !== $b['edited']))
return;
/**
* Post to Facebook stream
*/
@ -492,18 +502,16 @@ function facebook_post_hook(&$a,&$b) {
$reply = false;
$likes = false;
if((local_user()) && (local_user() == $b['uid'])) {
$toplevel = (($b['id'] == $b['parent']) ? true : false);
// Facebook is not considered a private network
if($b['prvnets'] && $b['private'])
return;
if(strstr($b['postopts'],'facebook')) {
$linking = ((get_pconfig(local_user(),'facebook','no_linking')) ? 0 : 1);
$linking = ((get_pconfig($b['uid'],'facebook','no_linking')) ? 0 : 1);
if(($b['parent']) && ($linking)) {
if((! $toplevel) && ($linking)) {
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($b['parent']),
intval(local_user())
intval($b['uid'])
);
if(count($r) && substr($r[0]['uri'],0,4) === 'fb::')
$reply = substr($r[0]['uri'],4);
@ -571,24 +579,14 @@ function facebook_post_hook(&$a,&$b) {
logger('facebook: have appid+secret');
$fb_post = intval(get_pconfig(local_user(),'facebook','post'));
$fb_enable = (($fb_post && x($_POST,'facebook_enable')) ? intval($_POST['facebook_enable']) : 0);
$fb_token = get_pconfig(local_user(),'facebook','access_token');
$fb_token = get_pconfig($b['uid'],'facebook','access_token');
// if API is used, default to the chosen settings
if($_POST['api_source'] && intval(get_pconfig(local_user(),'facebook','post_by_default')))
$fb_enable = 1;
logger('facebook: $fb_post: ' . $fb_post . ' $fb_enable: ' . $fb_enable . ' $fb_token: ' . $fb_token,LOGGER_DEBUG);
// post to facebook if it's a public post and we've ticked the 'post to Facebook' box,
// or it's a private message with facebook participants
// or it's a reply or likes action to an existing facebook post
if($fb_post && $fb_token && ($fb_enable || $b['private'] || $reply)) {
if($fb_token && ($toplevel || $b['private'] || $reply)) {
logger('facebook: able to post');
require_once('library/facebook.php');
require_once('include/bbcode.php');
@ -741,6 +739,32 @@ function facebook_post_hook(&$a,&$b) {
}
function facebook_post_local(&$a,&$b) {
// Figure out if Facebook posting is enabled for this post and file it in 'postopts'
// where we will discover it during background delivery.
// This can only be triggered by a local user posting to their own wall.
if((local_user()) && (local_user() == $b['uid'])) {
$fb_post = intval(get_pconfig(local_user(),'facebook','post'));
$fb_enable = (($fb_post && x($_POST,'facebook_enable')) ? intval($_POST['facebook_enable']) : 0);
// if API is used, default to the chosen settings
if($_POST['api_source'] && intval(get_pconfig(local_user(),'facebook','post_by_default')))
$fb_enable = 1;
if(! $fb_enable)
return;
if(strlen($b['postopts']))
$b['postopts'] .= ',';
$b['postopts'] .= 'facebook';
}
}
function fb_queue_hook(&$a,&$b) {
$qi = q("SELECT * FROM `queue` WHERE `network` = '%s'",