From b5869e7961dd284c542f32769391f69d0a78c3de Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 5 Jun 2014 17:45:13 +0200 Subject: [PATCH] Facebook: First changes to make the connector maybe work with the second version of the Facebook API Twitter/Facebook: New functions for expiring of imported posts from twitter and facebook. --- fbpost/fbpost.php | 15 ++++++++------- fbsync/fbsync.php | 27 ++++++++++++++++++++++++++- twitter/twitter.php | 32 +++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/fbpost/fbpost.php b/fbpost/fbpost.php index b5e320fc5..60c8e9392 100644 --- a/fbpost/fbpost.php +++ b/fbpost/fbpost.php @@ -248,7 +248,7 @@ function fbpost_content(&$a) { //read_stream,publish_stream,manage_pages,photo_upload,user_groups,offline_access $o .= '' . t('Install Facebook Post connector for this account.') . ''; + . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,share_item,video_upload,status_update">' . t('Install Facebook Post connector for this account.') . ''; $o .= ''; } @@ -260,7 +260,7 @@ function fbpost_content(&$a) { $o .= '
'; $o .= '' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . ''; + . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,share_item,video_upload,status_update">' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . ''; $o .= '
'; $o .= '
'; @@ -666,11 +666,13 @@ function fbpost_post_hook(&$a,&$b) { $postvars['message'] = $msg; $url = 'https://graph.facebook.com/'.$target.'/photos'; - } else if (($link != "") or ($image != "") or ($b['title'] == '') or (strlen($msg) < 500)) { + //} else if (($link != "") or ($image != "") or ($b['title'] == '') or (strlen($msg) < 500)) { + } else { $url = 'https://graph.facebook.com/'.$target.'/feed'; if (!get_pconfig($b['uid'],'facebook','suppress_view_on_friendica') and $b['plink']) $postvars['actions'] = '{"name": "' . t('View on Friendica') . '", "link": "' . $b['plink'] . '"}'; - } else { + } +/* } else { // if its only a message and a subject and the message is larger than 500 characters then post it as note $postvars = array( 'access_token' => $fb_token, @@ -678,7 +680,7 @@ function fbpost_post_hook(&$a,&$b) { 'subject' => $b['title'], ); $url = 'https://graph.facebook.com/'.$target.'/notes'; - } + } */ // Post to page? if (!$reply and ($target != "me") and $page_access_token) @@ -946,6 +948,7 @@ function fbpost_cron($a,$b) { function fbpost_fetchwall($a, $uid) { require_once("include/oembed.php"); + require_once('mod/item.php'); $access_token = get_pconfig($uid,'facebook','access_token'); $post_to_page = get_pconfig($uid,'facebook','post_to_page'); @@ -1081,8 +1084,6 @@ function fbpost_fetchwall($a, $uid) { //print_r($_REQUEST); logger('facebook: posting for user '.$uid); - - require_once('mod/item.php'); item_post($a); } diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index 21779769e..858591519 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -26,6 +26,7 @@ function fbsync_install() { register_hook('connector_settings_post', 'addon/fbsync/fbsync.php', 'fbsync_settings_post'); register_hook('cron', 'addon/fbsync/fbsync.php', 'fbsync_cron'); register_hook('follow', 'addon/fbsync/fbsync.php', 'fbsync_follow'); + register_hook('expire', 'addon/fbsync/fbsync.php', 'fbsync_expire'); } function fbsync_uninstall() { @@ -33,6 +34,7 @@ function fbsync_uninstall() { unregister_hook('connector_settings_post', 'addon/fbsync/fbsync.php', 'fbsync_settings_post'); unregister_hook('cron', 'addon/fbsync/fbsync.php', 'fbsync_cron'); unregister_hook('follow', 'addon/fbsync/fbsync.php', 'fbsync_follow'); + unregister_hook('expire', 'addon/fbsync/fbsync.php', 'fbsync_expire'); } function fbsync_follow($a, &$contact) { @@ -185,6 +187,30 @@ function fbsync_cron($a,$b) { set_config('fbsync','last_poll', time()); } +function fbsync_expire($a,$b) { + + $days = get_config('fbsync', 'expire'); + + if ($days == 0) + return; + + $r = q("DELETE FROM `item` WHERE `deleted` AND `network` = '%s'", dbesc(NETWORK_FACEBOOK)); + + require_once("include/items.php"); + + logger('fbsync_expire: expire_start'); + + $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'fbsync' AND `k` = 'sync' AND `v` = '1' ORDER BY RAND()"); + if(count($r)) { + foreach($r as $rr) { + logger('fbsync_expire: user '.$rr['uid']); + item_expire($rr['uid'], $days, NETWORK_FACEBOOK, true); + } + } + + logger('fbsync_expire: expire_end'); +} + function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $create_user) { require_once("include/oembed.php"); @@ -1018,7 +1044,6 @@ function fbsync_fetchfeed($a, $uid) { foreach ($post_data AS $post) { if ($post->updated_time > $last_updated) $last_updated = $post->updated_time; - fbsync_createpost($a, $uid, $self, $contacts, $application_data, $post, $create_user); } diff --git a/twitter/twitter.php b/twitter/twitter.php index 8a80f471b..16debcb7c 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -64,7 +64,7 @@ define('TWITTER_DEFAULT_POLL_INTERVAL', 5); // given in minutes function twitter_install() { // we need some hooks, for the configuration and for sending tweets - register_hook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings'); + register_hook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings'); register_hook('connector_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post'); register_hook('post_local', 'addon/twitter/twitter.php', 'twitter_post_local'); register_hook('notifier_normal', 'addon/twitter/twitter.php', 'twitter_post_hook'); @@ -72,12 +72,13 @@ function twitter_install() { register_hook('cron', 'addon/twitter/twitter.php', 'twitter_cron'); register_hook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook'); register_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow'); + register_hook('expire', 'addon/twitter/twitter.php', 'twitter_expire'); logger("installed twitter"); } function twitter_uninstall() { - unregister_hook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings'); + unregister_hook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings'); unregister_hook('connector_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post'); unregister_hook('post_local', 'addon/twitter/twitter.php', 'twitter_post_local'); unregister_hook('notifier_normal', 'addon/twitter/twitter.php', 'twitter_post_hook'); @@ -85,10 +86,11 @@ function twitter_uninstall() { unregister_hook('cron', 'addon/twitter/twitter.php', 'twitter_cron'); unregister_hook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook'); unregister_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow'); + unregister_hook('expire', 'addon/twitter/twitter.php', 'twitter_expire'); // old setting - remove only unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook'); - unregister_hook('plugin_settings', 'addon/twitter/twitter.php', 'twitter_settings'); + unregister_hook('plugin_settings', 'addon/twitter/twitter.php', 'twitter_settings'); unregister_hook('plugin_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post'); } @@ -624,6 +626,30 @@ function twitter_cron($a,$b) { set_config('twitter','last_poll', time()); } +function twitter_expire($a,$b) { + + $days = get_config('twitter', 'expire'); + + if ($days == 0) + return; + + $r = q("DELETE FROM `item` WHERE `deleted` AND `network` = '%s'", dbesc(NETWORK_TWITTER)); + + require_once("include/items.php"); + + logger('twitter_expire: expire_start'); + + $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()"); + if(count($r)) { + foreach($r as $rr) { + logger('twitter_expire: user '.$rr['uid']); + item_expire($rr['uid'], $days, NETWORK_TWITTER, true); + } + } + + logger('twitter_expire: expire_end'); +} + function twitter_fetchtimeline($a, $uid) { $ckey = get_config('twitter', 'consumerkey'); $csecret = get_config('twitter', 'consumersecret');