From 9b9d80cd97704426e54434d8777c5c15154014ad Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 25 Aug 2009 14:52:25 -0700 Subject: [PATCH 1/8] Pluginized Twitter settings stuff --- lib/connectsettingsaction.php | 49 +++++---- lib/router.php | 6 +- plugins/TwitterBridge/TwitterBridgePlugin.php | 101 ++++++++++++++++++ .../TwitterBridge}/twitterauthorization.php | 0 .../TwitterBridge}/twitteroauthclient.php | 0 .../TwitterBridge}/twittersettings.php | 5 - 6 files changed, 128 insertions(+), 33 deletions(-) create mode 100644 plugins/TwitterBridge/TwitterBridgePlugin.php rename {actions => plugins/TwitterBridge}/twitterauthorization.php (100%) rename {lib => plugins/TwitterBridge}/twitteroauthclient.php (100%) rename {actions => plugins/TwitterBridge}/twittersettings.php (97%) diff --git a/lib/connectsettingsaction.php b/lib/connectsettingsaction.php index 02c468a359..7902931e03 100644 --- a/lib/connectsettingsaction.php +++ b/lib/connectsettingsaction.php @@ -98,34 +98,37 @@ class ConnectSettingsNav extends Widget function show() { - # action => array('prompt', 'title') - $menu = array(); - if (common_config('xmpp', 'enabled')) { - $menu['imsettings'] = - array(_('IM'), - _('Updates by instant messenger (IM)')); - } - if (common_config('sms', 'enabled')) { - $menu['smssettings'] = - array(_('SMS'), - _('Updates by SMS')); - } - if (common_config('twitter', 'enabled')) { - $menu['twittersettings'] = - array(_('Twitter'), - _('Twitter integration options')); - } - $action_name = $this->action->trimmed('action'); $this->action->elementStart('ul', array('class' => 'nav')); - foreach ($menu as $menuaction => $menudesc) { - $this->action->menuItem(common_local_url($menuaction), - $menudesc[0], - $menudesc[1], - $action_name === $menuaction); + if (Event::handle('StartConnectSettingsNav', array(&$this->action))) { + + # action => array('prompt', 'title') + $menu = array(); + if (common_config('xmpp', 'enabled')) { + $menu['imsettings'] = + array(_('IM'), + _('Updates by instant messenger (IM)')); + } + if (common_config('sms', 'enabled')) { + $menu['smssettings'] = + array(_('SMS'), + _('Updates by SMS')); + } + + foreach ($menu as $menuaction => $menudesc) { + $this->action->menuItem(common_local_url($menuaction), + $menudesc[0], + $menudesc[1], + $action_name === $menuaction); + } + + Event::handle('EndConnectSettingsNav', array(&$this->action)); } $this->action->elementEnd('ul'); } + } + + diff --git a/lib/router.php b/lib/router.php index 08bc0566dd..5bffdb16bf 100644 --- a/lib/router.php +++ b/lib/router.php @@ -86,10 +86,6 @@ class Router $m->connect('doc/:title', array('action' => 'doc')); - // Twitter - - $m->connect('twitter/authorization', array('action' => 'twitterauthorization')); - // facebook $m->connect('facebook', array('action' => 'facebookhome')); @@ -136,7 +132,7 @@ class Router // settings foreach (array('profile', 'avatar', 'password', 'im', - 'email', 'sms', 'twitter', 'userdesign', 'other') as $s) { + 'email', 'sms', 'userdesign', 'other') as $s) { $m->connect('settings/'.$s, array('action' => $s.'settings')); } diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php new file mode 100644 index 0000000000..f7daa9a222 --- /dev/null +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -0,0 +1,101 @@ +. + * + * @category Plugin + * @package Laconica + * @author Zach Copley + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Plugin for sending and importing Twitter statuses + * + * This class allows users to link their Twitter accounts + * + * @category Plugin + * @package Laconica + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * @link http://twitter.com/ + */ + +class TwitterBridgePlugin extends Plugin +{ + /** + * Initializer for the plugin. + */ + + function __construct() + { + parent::__construct(); + } + + /** + * Add Twitter-related paths to the router table + * + * Hook for RouterInitialized event. + * + * @return boolean hook return + */ + + function onRouterInitialized(&$m) + { + $m->connect('twitter/authorization', array('action' => 'twitterauthorization')); + $m->connect('settings/twitter', array('action' => 'twittersettings')); + + return true; + } + + function onEndConnectSettingsNav(&$action) + { + $action_name = $action->trimmed('action'); + + $action->menuItem(common_local_url('twittersettings'), + _('Twitter'), + _('Twitter integration options'), + $action_name === 'twittersettings'); + + return true; + } + + function onAutoload($cls) + { + switch ($cls) + { + case 'TwittersettingsAction': + case 'TwitterauthorizationAction': + require_once(INSTALLDIR.'/plugins/TwitterBridge/' . strtolower(mb_substr($cls, 0, -6)) . '.php'); + return false; + case 'TwitterOAuthClient': + require_once(INSTALLDIR.'/plugins/TwitterBridge/twitteroAuthclient.php'); + return false; + default: + return true; + } + } + + +} \ No newline at end of file diff --git a/actions/twitterauthorization.php b/plugins/TwitterBridge/twitterauthorization.php similarity index 100% rename from actions/twitterauthorization.php rename to plugins/TwitterBridge/twitterauthorization.php diff --git a/lib/twitteroauthclient.php b/plugins/TwitterBridge/twitteroauthclient.php similarity index 100% rename from lib/twitteroauthclient.php rename to plugins/TwitterBridge/twitteroauthclient.php diff --git a/actions/twittersettings.php b/plugins/TwitterBridge/twittersettings.php similarity index 97% rename from actions/twittersettings.php rename to plugins/TwitterBridge/twittersettings.php index 0859ab9d34..a3e02e1256 100644 --- a/actions/twittersettings.php +++ b/plugins/TwitterBridge/twittersettings.php @@ -82,11 +82,6 @@ class TwittersettingsAction extends ConnectSettingsAction function showContent() { - if (!common_config('twitter', 'enabled')) { - $this->element('div', array('class' => 'error'), - _('Twitter is not available.')); - return; - } $user = common_current_user(); From 5efe588174c71979fc1970353c9a556ea441f138 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 26 Aug 2009 00:59:06 +0000 Subject: [PATCH 2/8] Moved the rest of the Twitter stuff into the TwitterBridge plugin --- lib/common.php | 1 - plugins/TwitterBridge/TwitterBridgePlugin.php | 2 +- .../TwitterBridge/daemons}/synctwitterfriends.php | 3 ++- .../TwitterBridge/daemons}/twitterqueuehandler.php | 7 +++---- .../TwitterBridge/daemons}/twitterstatusfetcher.php | 5 +++-- {lib => plugins/TwitterBridge}/twitter.php | 0 plugins/TwitterBridge/twitterauthorization.php | 2 ++ plugins/TwitterBridge/twittersettings.php | 4 ++-- 8 files changed, 13 insertions(+), 11 deletions(-) rename {scripts => plugins/TwitterBridge/daemons}/synctwitterfriends.php (98%) rename {scripts => plugins/TwitterBridge/daemons}/twitterqueuehandler.php (90%) rename {scripts => plugins/TwitterBridge/daemons}/twitterstatusfetcher.php (98%) rename {lib => plugins/TwitterBridge}/twitter.php (100%) diff --git a/lib/common.php b/lib/common.php index 62cf5640d6..d23d9da7d1 100644 --- a/lib/common.php +++ b/lib/common.php @@ -409,7 +409,6 @@ require_once INSTALLDIR.'/lib/theme.php'; require_once INSTALLDIR.'/lib/mail.php'; require_once INSTALLDIR.'/lib/subs.php'; require_once INSTALLDIR.'/lib/Shorturl_api.php'; -require_once INSTALLDIR.'/lib/twitter.php'; require_once INSTALLDIR.'/lib/clientexception.php'; require_once INSTALLDIR.'/lib/serverexception.php'; diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index f7daa9a222..a8de1c6644 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -90,7 +90,7 @@ class TwitterBridgePlugin extends Plugin require_once(INSTALLDIR.'/plugins/TwitterBridge/' . strtolower(mb_substr($cls, 0, -6)) . '.php'); return false; case 'TwitterOAuthClient': - require_once(INSTALLDIR.'/plugins/TwitterBridge/twitteroAuthclient.php'); + require_once(INSTALLDIR.'/plugins/TwitterBridge/twitteroauthclient.php'); return false; default: return true; diff --git a/scripts/synctwitterfriends.php b/plugins/TwitterBridge/daemons/synctwitterfriends.php similarity index 98% rename from scripts/synctwitterfriends.php rename to plugins/TwitterBridge/daemons/synctwitterfriends.php index 2de464bccc..b7be5d043a 100755 --- a/scripts/synctwitterfriends.php +++ b/plugins/TwitterBridge/daemons/synctwitterfriends.php @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); $shortoptions = 'di::'; $longoptions = array('id::', 'debug'); @@ -32,6 +32,7 @@ END_OF_TRIM_HELP; require_once INSTALLDIR . '/scripts/commandline.inc'; require_once INSTALLDIR . '/lib/parallelizingdaemon.php'; +require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; /** * Daemon to sync local friends with Twitter friends diff --git a/scripts/twitterqueuehandler.php b/plugins/TwitterBridge/daemons/twitterqueuehandler.php similarity index 90% rename from scripts/twitterqueuehandler.php rename to plugins/TwitterBridge/daemons/twitterqueuehandler.php index 00e735d983..9aa9d1ed0a 100755 --- a/scripts/twitterqueuehandler.php +++ b/plugins/TwitterBridge/daemons/twitterqueuehandler.php @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); $shortoptions = 'i::'; $longoptions = array('id::'); @@ -30,10 +30,9 @@ Daemon script for pushing new notices to Twitter. END_OF_ENJIT_HELP; -require_once INSTALLDIR.'/scripts/commandline.inc'; - -require_once INSTALLDIR . '/lib/twitter.php'; +require_once INSTALLDIR . '/scripts/commandline.inc'; require_once INSTALLDIR . '/lib/queuehandler.php'; +require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; class TwitterQueueHandler extends QueueHandler { diff --git a/scripts/twitterstatusfetcher.php b/plugins/TwitterBridge/daemons/twitterstatusfetcher.php similarity index 98% rename from scripts/twitterstatusfetcher.php rename to plugins/TwitterBridge/daemons/twitterstatusfetcher.php index f5289c5f4b..3023bf423b 100755 --- a/scripts/twitterstatusfetcher.php +++ b/plugins/TwitterBridge/daemons/twitterstatusfetcher.php @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); // Tune number of processes and how often to poll Twitter // XXX: Should these things be in config.php? @@ -36,8 +36,9 @@ Batch script for retrieving Twitter messages from foreign service. END_OF_TRIM_HELP; -require_once INSTALLDIR .'/scripts/commandline.inc'; +require_once INSTALLDIR . '/scripts/commandline.inc'; require_once INSTALLDIR . '/lib/daemon.php'; +require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; /** * Fetcher for statuses from Twitter diff --git a/lib/twitter.php b/plugins/TwitterBridge/twitter.php similarity index 100% rename from lib/twitter.php rename to plugins/TwitterBridge/twitter.php diff --git a/plugins/TwitterBridge/twitterauthorization.php b/plugins/TwitterBridge/twitterauthorization.php index b04f353278..a545284342 100644 --- a/plugins/TwitterBridge/twitterauthorization.php +++ b/plugins/TwitterBridge/twitterauthorization.php @@ -31,6 +31,8 @@ if (!defined('LACONICA')) { exit(1); } +require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; + /** * Class for doing OAuth authentication against Twitter * diff --git a/plugins/TwitterBridge/twittersettings.php b/plugins/TwitterBridge/twittersettings.php index a3e02e1256..b3d4a971f6 100644 --- a/plugins/TwitterBridge/twittersettings.php +++ b/plugins/TwitterBridge/twittersettings.php @@ -31,8 +31,8 @@ if (!defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/connectsettingsaction.php'; -require_once INSTALLDIR.'/lib/twitter.php'; +require_once INSTALLDIR . '/lib/connectsettingsaction.php'; +require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; /** * Settings for Twitter integration From 876f56254d3ccdcc7ba3e9c7693345cef8a6e22b Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 8 Sep 2009 16:07:01 -0700 Subject: [PATCH 3/8] Moved basic auth client into plugin dir --- {lib => plugins/TwitterBridge}/twitterbasicauthclient.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {lib => plugins/TwitterBridge}/twitterbasicauthclient.php (100%) diff --git a/lib/twitterbasicauthclient.php b/plugins/TwitterBridge/twitterbasicauthclient.php similarity index 100% rename from lib/twitterbasicauthclient.php rename to plugins/TwitterBridge/twitterbasicauthclient.php From 0fd8e758ade32204b452cc9fd40e071f0ec8c0f6 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 14 Oct 2009 04:50:16 +0000 Subject: [PATCH 4/8] Make queuing and daemons work via events --- classes/Avatar.php | 2 +- plugins/TwitterBridge/TwitterBridgePlugin.php | 17 +++++++++++++++++ .../daemons/synctwitterfriends.php | 10 ++-------- .../daemons/twitterstatusfetcher.php | 9 ++++----- plugins/TwitterBridge/twitter.php | 3 +++ scripts/getvaliddaemons.php | 9 --------- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/classes/Avatar.php b/classes/Avatar.php index 5e8b315fe6..64f105179c 100644 --- a/classes/Avatar.php +++ b/classes/Avatar.php @@ -81,7 +81,7 @@ class Avatar extends Memcached_DataObject if (empty($server)) { $server = common_config('site', 'server'); } - + common_debug('path = ' . $path); // XXX: protocol return 'http://'.$server.$path.$filename; diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index a8de1c6644..69bec06511 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -97,5 +97,22 @@ class TwitterBridgePlugin extends Plugin } } + function onStartEnqueueNotice($notice, $transports) + { + array_push($transports, 'twitter'); + return true; + } + + function onGetValidDaemons($daemons) + { + array_push($daemons, INSTALLDIR . '/plugins/TwitterBridge/daemons/twitterqueuehandler.php'); + array_push($daemons, INSTALLDIR . '/plugins/TwitterBridge/daemons/synctwitterfriends.php'); + + if (common_config('twitterbridge', 'enabled')) { + array_push($daemons, INSTALLDIR . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php'); + } + + return true; + } } \ No newline at end of file diff --git a/plugins/TwitterBridge/daemons/synctwitterfriends.php b/plugins/TwitterBridge/daemons/synctwitterfriends.php index 0668c6222f..ed2bf48a22 100755 --- a/plugins/TwitterBridge/daemons/synctwitterfriends.php +++ b/plugins/TwitterBridge/daemons/synctwitterfriends.php @@ -33,6 +33,8 @@ END_OF_TRIM_HELP; require_once INSTALLDIR . '/scripts/commandline.inc'; require_once INSTALLDIR . '/lib/parallelizingdaemon.php'; require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; +require_once INSTALLDIR . '/plugins/TwitterBridge/twitterbasicauthclient.php'; +require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php'; /** * Daemon to sync local friends with Twitter friends @@ -45,14 +47,6 @@ require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; * @link http://status.net/ */ -$helptext = <<filename = $filename; $avatar->url = Avatar::url($filename); - common_debug($this->name() . " - New filename: $avatar->url"); - $avatar->created = common_sql_now(); $id = $avatar->insert(); @@ -516,9 +517,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon function fetchAvatar($url, $filename) { - $avatar_dir = INSTALLDIR . '/avatar/'; - - $avatarfile = $avatar_dir . $filename; + $avatarfile = Avatar::path($filename); $out = fopen($avatarfile, 'wb'); if (!$out) { diff --git a/plugins/TwitterBridge/twitter.php b/plugins/TwitterBridge/twitter.php index afc3f55bab..ac1f49c363 100644 --- a/plugins/TwitterBridge/twitter.php +++ b/plugins/TwitterBridge/twitter.php @@ -23,6 +23,9 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { define('TWITTER_SERVICE', 1); // Twitter is foreign_service ID 1 +require_once INSTALLDIR . '/plugins/TwitterBridge/twitterbasicauthclient.php'; +require_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php'; + function updateTwitter_user($twitter_id, $screen_name) { $uri = 'http://twitter.com/' . $screen_name; diff --git a/scripts/getvaliddaemons.php b/scripts/getvaliddaemons.php index 6dd0197129..7caea1bb75 100755 --- a/scripts/getvaliddaemons.php +++ b/scripts/getvaliddaemons.php @@ -49,15 +49,6 @@ if(common_config('xmpp','enabled')) { $daemons[] = INSTALLDIR.'/scripts/xmppconfirmhandler.php'; } -if(common_config('twitterbridge','enabled')) { - $daemons[] = INSTALLDIR.'/scripts/twitterstatusfetcher.php'; -} - -if (common_config('twitter', 'enabled')) { - $daemons[] = INSTALLDIR.'/scripts/twitterqueuehandler.php'; - $daemons[] = INSTALLDIR.'/scripts/synctwitterfriends.php'; -} - if (common_config('sms', 'enabled')) { $daemons[] = INSTALLDIR.'/scripts/smsqueuehandler.php'; } From 109a54c4f08177cce82ef0f4a4ec8cd41ed2ecec Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sat, 17 Oct 2009 00:32:02 +0000 Subject: [PATCH 5/8] Changed config flag for importing friends' timeline and added some comments --- lib/default.php | 2 +- plugins/TwitterBridge/TwitterBridgePlugin.php | 77 ++++++++++++++----- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/lib/default.php b/lib/default.php index 9f3d4b1f9d..68029c9778 100644 --- a/lib/default.php +++ b/lib/default.php @@ -140,7 +140,7 @@ $default = array('enabled' => true), 'sms' => array('enabled' => true), - 'twitterbridge' => + 'twitterimport' => array('enabled' => false), 'integration' => array('source' => 'StatusNet', # source attribute for Twitter diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index 69bec06511..1a27c30cd2 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -1,6 +1,6 @@ . * * @category Plugin - * @package Laconica - * @author Zach Copley + * @package StatusNet + * @author Zach Copley * @copyright 2009 Control Yourself, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET')) { exit(1); } @@ -35,8 +35,8 @@ if (!defined('LACONICA')) { * This class allows users to link their Twitter accounts * * @category Plugin - * @package Laconica - * @author Zach Copley + * @package StatusNet + * @author Zach Copley * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://laconi.ca/ * @link http://twitter.com/ @@ -58,17 +58,27 @@ class TwitterBridgePlugin extends Plugin * * Hook for RouterInitialized event. * + * @param Net_URL_Mapper &$m path-to-action mapper + * * @return boolean hook return */ function onRouterInitialized(&$m) { - $m->connect('twitter/authorization', array('action' => 'twitterauthorization')); + $m->connect('twitter/authorization', + array('action' => 'twitterauthorization')); $m->connect('settings/twitter', array('action' => 'twittersettings')); return true; } + /** + * Add the Twitter Settings page to the Connect Settings menu + * + * @param Action &$action The calling page + * + * @return boolean hook return + */ function onEndConnectSettingsNav(&$action) { $action_name = $action->trimmed('action'); @@ -81,38 +91,65 @@ class TwitterBridgePlugin extends Plugin return true; } + /** + * Automatically load the actions and libraries used by the Twitter bridge + * + * @param Class $cls the class + * + * @return boolean hook return + * + */ function onAutoload($cls) { - switch ($cls) - { - case 'TwittersettingsAction': - case 'TwitterauthorizationAction': - require_once(INSTALLDIR.'/plugins/TwitterBridge/' . strtolower(mb_substr($cls, 0, -6)) . '.php'); + switch ($cls) { + case 'TwittersettingsAction': + case 'TwitterauthorizationAction': + include_once INSTALLDIR.'/plugins/TwitterBridge/' . + strtolower(mb_substr($cls, 0, -6)) . '.php'; return false; - case 'TwitterOAuthClient': - require_once(INSTALLDIR.'/plugins/TwitterBridge/twitteroauthclient.php'); + case 'TwitterOAuthClient': + include_once INSTALLDIR.'/plugins/TwitterBridge/twitteroauthclient.php'; return false; - default: + default: return true; } } + /** + * Add a Twitter queue item for each notice + * + * @param Notice $notice the notice + * @param array $transports the list of transports (queues) + * + * @return boolean hook return + */ function onStartEnqueueNotice($notice, $transports) { array_push($transports, 'twitter'); return true; } + /** + * Add Twitter bridge daemons to the list of daemons to start + * + * @param array $daemons the list fo daemons to run + * + * @return boolean hook return + * + */ function onGetValidDaemons($daemons) { - array_push($daemons, INSTALLDIR . '/plugins/TwitterBridge/daemons/twitterqueuehandler.php'); - array_push($daemons, INSTALLDIR . '/plugins/TwitterBridge/daemons/synctwitterfriends.php'); + array_push($daemons, INSTALLDIR . + '/plugins/TwitterBridge/daemons/twitterqueuehandler.php'); + array_push($daemons, INSTALLDIR . + '/plugins/TwitterBridge/daemons/synctwitterfriends.php'); - if (common_config('twitterbridge', 'enabled')) { - array_push($daemons, INSTALLDIR . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php'); + if (common_config('twitterimport', 'enabled')) { + array_push($daemons, INSTALLDIR + . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php'); } return true; } -} \ No newline at end of file +} From 9cdd77625e25e7c506121d42b28c1ec870c2d4e4 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 20 Oct 2009 00:49:11 +0000 Subject: [PATCH 6/8] Less intrusive, more reliable way for FB Connect plugin to modify the primary nav in order to show FB mini-avatar and have the logout link logout of FB as well as StatusNet. --- plugins/FBConnect/FBConnectPlugin.php | 120 +++++++++----------------- 1 file changed, 42 insertions(+), 78 deletions(-) diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php index b31f69d81a..0dacf90122 100644 --- a/plugins/FBConnect/FBConnectPlugin.php +++ b/plugins/FBConnect/FBConnectPlugin.php @@ -115,26 +115,48 @@ class FBConnectPlugin extends Plugin // XXX: Facebook says we don't need this FB_RequireFeatures(), // but we actually do, for IE and Safari. Gar. - $html = sprintf('', $apikey, - $login_url, $logout_url); + // The below function alters the logout link so that it logs the user out + // of Facebook Connect as well as the site. However, for some pages + // (FB Connect Settings) we need to output the FB Connect scripts (to + // show an existing FB connection even if the user isn't authenticated + // with Facebook connect) but NOT alter the logout link. And the only + // way to reliably do that is with the FB Connect .js libs. Crazy. - $action->raw($html); + $js .= ' FB.ensureInit(function() {'; + $js .= ' FB.Connect.ifUserConnected('; + $js .= ' function() { '; + $js .= ' $(\'#nav_logout a\').attr(\'href\', \'#\');'; + $js .= ' $(\'#nav_logout a\').click(function() {'; + $js .= ' FB.Connect.logoutAndRedirect(\'%3$s\');'; + $js .= ' return false;'; + $js .= ' })'; + $js .= ' },'; + $js .= ' function() {'; + $js .= ' return false;'; + $js .= ' }'; + $js .= ' );'; + $js .= ' });'; + $js .= ''; + + $js = sprintf($js, $apikey, $login_url, $logout_url); + + // Compress the bugger down a bit + $js = str_replace(' ', '', $js); + + $action->raw(" $js"); // leading two spaces to make it line up } } @@ -150,7 +172,6 @@ class FBConnectPlugin extends Plugin function onEndShowStatusNetStyles($action) { - if ($this->reqFbScripts($action)) { $action->cssLink('plugins/FBConnect/FBConnectPlugin.css'); } @@ -269,66 +290,9 @@ class FBConnectPlugin extends Plugin $action->elementEnd('li'); } + } - $action->menuItem(common_local_url('all', array('nickname' => $user->nickname)), - _('Home'), _('Personal profile and friends timeline'), false, 'nav_home'); - $action->menuItem(common_local_url('profilesettings'), - _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account'); - $action->menuItem(common_local_url($connect), - _('Connect'), _('Connect to services'), false, 'nav_connect'); - if (common_config('invite', 'enabled')) { - $action->menuItem(common_local_url('invite'), - _('Invite'), - sprintf(_('Invite friends and colleagues to join you on %s'), - common_config('site', 'name')), - false, 'nav_invitecontact'); - } - - // Need to override the Logout link to make it do FB stuff - if (!empty($fbuid)) { - - $logout_url = common_local_url('logout'); - $title = _('Logout from the site'); - $text = _('Logout'); - - $html = sprintf('', - $title, $logout_url, $text); - - $action->raw($html); - - } else { - $action->menuItem(common_local_url('logout'), - _('Logout'), _('Logout from the site'), false, 'nav_logout'); - } - } - else { - if (!common_config('site', 'openidonly')) { - if (!common_config('site', 'closed')) { - $action->menuItem(common_local_url('register'), - _('Register'), _('Create an account'), false, 'nav_register'); - } - $action->menuItem(common_local_url('login'), - _('Login'), _('Login to the site'), false, 'nav_login'); - } else { - $this->menuItem(common_local_url('openidlogin'), - _('OpenID'), _('Login with OpenID'), false, 'nav_openid'); - } - } - - $action->menuItem(common_local_url('doc', array('title' => 'help')), - _('Help'), _('Help me!'), false, 'nav_help'); - if ($user || !common_config('site', 'private')) { - $action->menuItem(common_local_url('peoplesearch'), - _('Search'), _('Search for people or text'), false, 'nav_search'); - } - - // We are replacing the primary nav entirely; give other - // plugins a chance to handle it here. - - Event::handle('EndPrimaryNav', array($action)); - - return false; + return true; } function onStartShowLocalNavBlock($action) @@ -357,7 +321,7 @@ class FBConnectPlugin extends Plugin } function onStartLogout($action) -{ + { $action->logout(); $fbuid = $this->loggedIn(); From 7539e26951ba9e1529d9a24a7a634861b7d080fe Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 20 Oct 2009 06:05:35 +0000 Subject: [PATCH 7/8] - Make Twitter bridge work with unqueuemanager - Add README --- lib/unqueuemanager.php | 5 -- plugins/TwitterBridge/README | 86 +++++++++++++++++++ plugins/TwitterBridge/TwitterBridgePlugin.php | 42 +++++++-- plugins/TwitterBridge/twittersettings.php | 2 +- 4 files changed, 124 insertions(+), 11 deletions(-) create mode 100644 plugins/TwitterBridge/README diff --git a/lib/unqueuemanager.php b/lib/unqueuemanager.php index 6cfe5bcbd3..51261bcd71 100644 --- a/lib/unqueuemanager.php +++ b/lib/unqueuemanager.php @@ -48,11 +48,6 @@ class UnQueueManager jabber_public_notice($notice); } break; - case 'twitter': - if ($this->_isLocal($notice)) { - broadcast_twitter($notice); - } - break; case 'facebook': if ($this->_isLocal($notice)) { require_once INSTALLDIR . '/lib/facebookutil.php'; diff --git a/plugins/TwitterBridge/README b/plugins/TwitterBridge/README new file mode 100644 index 0000000000..09352188ed --- /dev/null +++ b/plugins/TwitterBridge/README @@ -0,0 +1,86 @@ +This Twitter "bridge" plugin allows you to integrate your StatusNet +instance with Twitter. Installing it will allow your users to: + + - automatically post notices to thier Twitter accounts + - automatically subscribe to other Twitter users who are also using + your StatusNet install, if possible (requires running a daemon) + - import their Twitter friends' tweets (requires running a daemon) + +Installation +------------ + +To enable the plugin, add the following to your config.php: + + require_once(INSTALLDIR . '/plugins/TwitterBridge/TwitterBridgePlugin.php'); + $tb = new TwitterBridgePlugin(); + +OAuth is used to to access protected resources on Twitter (as opposed to +HTTP Basic Auth)*. To use Twitter bridging you will need to register +your instance of StatusNet as an application on Twitter +(http://twitter.com/apps), and update the following variables in your +config.php with the consumer key and secret Twitter generates for you: + + $config['twitter']['consumer_key'] = 'YOURKEY'; + $config['twitter']['consumer_secret'] = 'YOURSECRET'; + +When registering your application with Twitter set the type to "Browser" +and your Callback URL to: + + http://example.org/mublog/twitter/authorization + +The default access type should be, "Read & Write". + +* Note: The plugin will still push notices to Twitter for users who + have previously setup the Twitter bridge using their Twitter name and + password under an older versions of StatusNet, but all new Twitter + bridge connections will use OAuth. + +Deamons +------- + +For friend syncing and importing notices running two additional daemon +scripts is necessary (synctwitterfriends.php and +twitterstatusfetcher.php). + +In the daemons subidrectory of the plugin are three scripts: + +* Twitter Friends Syncing (daemons/synctwitterfriends.php) + +Users may set a flag in their settings ("Subscribe to my Twitter friends +here" under the Twitter tab) to have StatusNet attempt to locate and +subscribe to "friends" (people they "follow") on Twitter who also have +accounts on your StatusNet system, and who have previously set up a link +for automatically posting notices to Twitter. + +The plugin will try to start this daemon when you run +scripts/startdaemons.sh. + +* Importing statuses from Twitter (daemons/twitterstatusfetcher.php) + +To allow your users to import their friends' Twitter statuses, you will +need to enable the bidirectional Twitter bridge in your config.php: + + $config['twitterimport']['enabled'] = true; + +The plugin will then start the TwitterStatusFetcher daemon along with the +other daemons when you run scripts/startdaemons.sh. + +Additionally, you will want to set the integration source variable, +which will keep notices posted to Twitter via StatusNet from looping +back. The integration source should be set to the name of your +application, exactly as you specified it on the settings page for your +StatusNet application on Twitter, e.g.: + + $config['integration']['source'] = 'YourApp'; + +* TwitterQueueHandler (daemons/twitterqueuehandler.php) + +This script sends queued notices to Twitter for user who have opted to +set up Twitter bridging. + +It's not strictly necessary to run this queue handler, and sites that +haven't enabled queuing are still able to push notices to Twitter, but +for larger sites and sites that wish to improve performance, this +script allows notices to be sent "offline" via a separate process. + +The plugin will start this script when you run scripts/startdaemons.sh. diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index 1a27c30cd2..e69567fc7b 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -29,6 +29,8 @@ if (!defined('STATUSNET')) { exit(1); } +require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php'; + /** * Plugin for sending and importing Twitter statuses * @@ -104,11 +106,11 @@ class TwitterBridgePlugin extends Plugin switch ($cls) { case 'TwittersettingsAction': case 'TwitterauthorizationAction': - include_once INSTALLDIR.'/plugins/TwitterBridge/' . + include_once INSTALLDIR . '/plugins/TwitterBridge/' . strtolower(mb_substr($cls, 0, -6)) . '.php'; return false; case 'TwitterOAuthClient': - include_once INSTALLDIR.'/plugins/TwitterBridge/twitteroauthclient.php'; + include_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php'; return false; default: return true; @@ -118,17 +120,47 @@ class TwitterBridgePlugin extends Plugin /** * Add a Twitter queue item for each notice * - * @param Notice $notice the notice - * @param array $transports the list of transports (queues) + * @param Notice $notice the notice + * @param array &$transports the list of transports (queues) * * @return boolean hook return */ - function onStartEnqueueNotice($notice, $transports) + function onStartEnqueueNotice($notice, &$transports) { array_push($transports, 'twitter'); return true; } + /** + * broadcast the message when not using queuehandler + * + * @param Notice &$notice the notice + * @param array $queue destination queue + * + * @return boolean hook return + */ + function onUnqueueHandleNotice(&$notice, $queue) + { + if (($queue == 'twitter') && ($this->_isLocal($notice))) { + broadcast_twitter($notice); + return false; + } + return true; + } + + /** + * Determine whether the notice was locally created + * + * @param Notice $notice + * + * @return boolean locality + */ + function _isLocal($notice) + { + return ($notice->is_local == Notice::LOCAL_PUBLIC || + $notice->is_local == Notice::LOCAL_NONPUBLIC); + } + /** * Add Twitter bridge daemons to the list of daemons to start * diff --git a/plugins/TwitterBridge/twittersettings.php b/plugins/TwitterBridge/twittersettings.php index 2afa85ba4c..ca22c95535 100644 --- a/plugins/TwitterBridge/twittersettings.php +++ b/plugins/TwitterBridge/twittersettings.php @@ -152,7 +152,7 @@ class TwittersettingsAction extends ConnectSettingsAction false); $this->elementEnd('li'); - if (common_config('twitterbridge','enabled')) { + if (common_config('twitterimport','enabled')) { $this->elementStart('li'); $this->checkbox('noticerecv', _('Import my Friends Timeline.'), From 5e536a66141fac332e77c5ea6e85aee6a9347ace Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 20 Oct 2009 06:11:40 +0000 Subject: [PATCH 8/8] Remove Twitter bridge stuff. The relevant info has been moved to /plugins/TwitterBridge/README --- README | 72 ---------------------------------------------------------- 1 file changed, 72 deletions(-) diff --git a/README b/README index a8b83fc178..ee75b802ea 100644 --- a/README +++ b/README @@ -526,8 +526,6 @@ This will run eight (for now) queue handlers: of registered users. * xmppconfirmhandler.php - sends confirmation messages to registered users. -* twitterqueuehandler.php - sends queued notices to Twitter for user - who have opted to set up Twitter bridging. * facebookqueuehandler.php - sends queued notices to Facebook for users of the built-in Facebook application. @@ -547,54 +545,6 @@ our kind of hacky home-grown DB-based queue solution. See the "queues" config section below for how to configure to use STOMP. As of this writing, the software has been tested with ActiveMQ ( -Twitter Bridge --------------- - -* OAuth - -As of 0.8.1, OAuth is used to to access protected resources on Twitter -instead of HTTP Basic Auth. To use Twitter bridging you will need -to register your instance of StatusNet as an application on Twitter -(http://twitter.com/apps), and update the following variables in your -config.php with the consumer key and secret Twitter generates for you: - - $config['twitter']['consumer_key'] = 'YOURKEY'; - $config['twitter']['consumer_secret'] = 'YOURSECRET'; - -When registering your application with Twitter set the type to "Browser" -and your Callback URL to: - - http://example.org/mublog/twitter/authorization - -The default access type should be, "Read & Write". - -* Importing statuses from Twitter - -To allow your users to import their friends' Twitter statuses, you will -need to enable the bidirectional Twitter bridge in config.php: - - $config['twitterbridge']['enabled'] = true; - -and run the TwitterStatusFetcher daemon (scripts/twitterstatusfetcher.php). -Additionally, you will want to set the integration source variable, -which will keep notices posted to Twitter via StatusNet from looping -back. The integration source should be set to the name of your -application, exactly as you specified it on the settings page for your -StatusNet application on Twitter, e.g.: - - $config['integration']['source'] = 'YourApp'; - -* Twitter Friends Syncing - -Users may set a flag in their settings ("Subscribe to my Twitter friends -here" under the Twitter tab) to have StatusNet attempt to locate and -subscribe to "friends" (people they "follow") on Twitter who also have -accounts on your StatusNet system, and who have previously set up a link -for automatically posting notices to Twitter. - -As of 0.8.0, this is no longer accomplished via a cron job. Instead you -must run the SyncTwitterFriends daemon (scripts/synctwitterfreinds.php). - Built-in Facebook Application ----------------------------- @@ -1251,24 +1201,11 @@ For SMS integration. enabled: Whether to enable SMS integration. Defaults to true. Queues should also be enabled. -twitter -------- - -For Twitter integration - -enabled: Whether to enable Twitter integration. Defaults to true. - Queues should also be enabled. - integration ----------- A catch-all for integration with other systems. -source: The name to use for the source of posts to Twitter. Defaults - to 'statusnet', but if you request your own source name from - Twitter , you can use - that here instead. Status updates on Twitter will then have - links to your site. taguri: base for tag:// URIs. Defaults to site-server + ',2009'. inboxes @@ -1446,15 +1383,6 @@ dir: directory to write backgrounds too. Default is '/background/' path: path to backgrounds. Default is sub-path of install path; note that you may need to change this if you change site-path too. -twitterbridge -------------- - -A bi-direction bridge to Twitter (http://twitter.com/). - -enabled: default false. If true, will show user's Twitter friends' - notices in their inbox and faves pages, only to the user. You - must also run the twitterstatusfetcher.php script. - ping ----