- Make Twitter bridge work with unqueuemanager

- Add README
This commit is contained in:
Zach Copley 2009-10-20 06:05:35 +00:00
parent 109a54c4f0
commit 7539e26951
4 changed files with 124 additions and 11 deletions

View File

@ -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';

View File

@ -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.

View File

@ -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
*

View File

@ -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.'),