summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-03-02 16:49:29 -0800
committerZach Copley <zach@status.net>2010-03-02 16:49:29 -0800
commitca21f1da8603be348c1a34a8bcc3e7610b9a395d (patch)
tree229d0837009b03a8afef6eb4934f0f03d39502ad /plugins
parent09705a1e989d202859d637f8a84383f365b7906a (diff)
- Have Twitter bridge check for a global key and secret if it can't
find one in the local config - Refuse to work at all if the consumer key and secret aren't set
Diffstat (limited to 'plugins')
-rw-r--r--plugins/TwitterBridge/README17
-rw-r--r--plugins/TwitterBridge/TwitterBridgePlugin.php98
-rw-r--r--plugins/TwitterBridge/twitteroauthclient.php21
3 files changed, 101 insertions, 35 deletions
diff --git a/plugins/TwitterBridge/README b/plugins/TwitterBridge/README
index 72278b32e..5117cf69a 100644
--- a/plugins/TwitterBridge/README
+++ b/plugins/TwitterBridge/README
@@ -20,7 +20,7 @@ on Twitter (http://twitter.com/apps). During the application
registration process your application will be assigned a "consumer" key
and secret, which the plugin will use to make OAuth requests to Twitter.
You can either pass the consumer key and secret in when you enable the
-plugin, or set it using the Twitter administration panel.
+plugin, or set it using the Twitter administration panel**.
When registering your application with Twitter set the type to "Browser"
and your Callback URL to:
@@ -42,11 +42,26 @@ To enable the plugin, add the following to your config.php:
)
);
+or just:
+
+ addPlugin('TwitterBridge');
+
+if you want to set the consumer key and secret from the Twitter bridge
+administration panel. (The Twitter bridge wont work at all
+unless you configure it with a consumer key and secret.)
+
* Note: The plugin will still push notices to Twitter for users who
have previously set up the Twitter bridge using their Twitter name and
password under an older version of StatusNet, but all new Twitter
bridge connections will use OAuth.
+** For multi-site setups you can also set a global consumer key and and
+ secret. The Twitter bridge will fall back on the global key pair if
+ it can't find a local pair, e.g.:
+
+ $config['twitter']['global_consumer_key'] = 'YOUR_CONSUMER_KEY'
+ $config['twitter']['global_consumer_secret'] = 'YOUR_CONSUMER_SECRET'
+
Administration panel
--------------------
diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php
index 6ce69d5e2..bc702e745 100644
--- a/plugins/TwitterBridge/TwitterBridgePlugin.php
+++ b/plugins/TwitterBridge/TwitterBridgePlugin.php
@@ -80,6 +80,30 @@ class TwitterBridgePlugin extends Plugin
}
/**
+ * Check to see if there is a consumer key and secret defined
+ * for Twitter integration.
+ *
+ * @return boolean result
+ */
+
+ static function hasKeys()
+ {
+ $key = common_config('twitter', 'consumer_key');
+ $secret = common_config('twitter', 'consumer_secret');
+
+ if (empty($key) && empty($secret)) {
+ $key = common_config('twitter', 'global_consumer_key');
+ $secret = common_config('twitter', 'global_consumer_secret');
+ }
+
+ if (!empty($key) && !empty($secret)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
* Add Twitter-related paths to the router table
*
* Hook for RouterInitialized event.
@@ -91,14 +115,22 @@ class TwitterBridgePlugin extends Plugin
function onRouterInitialized($m)
{
- $m->connect(
- 'twitter/authorization',
- array('action' => 'twitterauthorization')
- );
- $m->connect('settings/twitter', array('action' => 'twittersettings'));
-
- if (common_config('twitter', 'signin')) {
- $m->connect('main/twitterlogin', array('action' => 'twitterlogin'));
+ if (self::hasKeys()) {
+ $m->connect(
+ 'twitter/authorization',
+ array('action' => 'twitterauthorization')
+ );
+ $m->connect(
+ 'settings/twitter', array(
+ 'action' => 'twittersettings'
+ )
+ );
+ if (common_config('twitter', 'signin')) {
+ $m->connect(
+ 'main/twitterlogin',
+ array('action' => 'twitterlogin')
+ );
+ }
}
$m->connect('admin/twitter', array('action' => 'twitteradminpanel'));
@@ -117,7 +149,7 @@ class TwitterBridgePlugin extends Plugin
{
$action_name = $action->trimmed('action');
- if (common_config('twitter', 'signin')) {
+ if (self::hasKeys() && common_config('twitter', 'signin')) {
$action->menuItem(
common_local_url('twitterlogin'),
_m('Twitter'),
@@ -138,15 +170,16 @@ class TwitterBridgePlugin extends Plugin
*/
function onEndConnectSettingsNav(&$action)
{
- $action_name = $action->trimmed('action');
-
- $action->menuItem(
- common_local_url('twittersettings'),
- _m('Twitter'),
- _m('Twitter integration options'),
- $action_name === 'twittersettings'
- );
+ if (self::hasKeys()) {
+ $action_name = $action->trimmed('action');
+ $action->menuItem(
+ common_local_url('twittersettings'),
+ _m('Twitter'),
+ _m('Twitter integration options'),
+ $action_name === 'twittersettings'
+ );
+ }
return true;
}
@@ -188,12 +221,12 @@ class TwitterBridgePlugin extends Plugin
*/
function onStartEnqueueNotice($notice, &$transports)
{
- // Avoid a possible loop
-
- if ($notice->source != 'twitter') {
- array_push($transports, 'twitter');
+ if (self::hasKeys()) {
+ // Avoid a possible loop
+ if ($notice->source != 'twitter') {
+ array_push($transports, 'twitter');
+ }
}
-
return true;
}
@@ -206,18 +239,19 @@ class TwitterBridgePlugin extends Plugin
*/
function onGetValidDaemons($daemons)
{
- array_push(
- $daemons,
- INSTALLDIR
- . '/plugins/TwitterBridge/daemons/synctwitterfriends.php'
- );
-
- if (common_config('twitterimport', 'enabled')) {
+ if (self::hasKeys()) {
array_push(
$daemons,
INSTALLDIR
- . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php'
+ . '/plugins/TwitterBridge/daemons/synctwitterfriends.php'
);
+ if (common_config('twitterimport', 'enabled')) {
+ array_push(
+ $daemons,
+ INSTALLDIR
+ . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php'
+ );
+ }
}
return true;
@@ -232,7 +266,9 @@ class TwitterBridgePlugin extends Plugin
*/
function onEndInitializeQueueManager($manager)
{
- $manager->connect('twitter', 'TwitterQueueHandler');
+ if (self::hasKeys()) {
+ $manager->connect('twitter', 'TwitterQueueHandler');
+ }
return true;
}
diff --git a/plugins/TwitterBridge/twitteroauthclient.php b/plugins/TwitterBridge/twitteroauthclient.php
index ba45b533d..93f6aadd1 100644
--- a/plugins/TwitterBridge/twitteroauthclient.php
+++ b/plugins/TwitterBridge/twitteroauthclient.php
@@ -22,7 +22,7 @@
* @category Integration
* @package StatusNet
* @author Zach Copley <zach@status.net>
- * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009-2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
@@ -61,8 +61,23 @@ class TwitterOAuthClient extends OAuthClient
$consumer_key = common_config('twitter', 'consumer_key');
$consumer_secret = common_config('twitter', 'consumer_secret');
- parent::__construct($consumer_key, $consumer_secret,
- $oauth_token, $oauth_token_secret);
+ if (empty($consumer_key) && empty($consumer_secret)) {
+ $consumer_key = common_config(
+ 'twitter',
+ 'global_consumer_key'
+ );
+ $consumer_secret = common_config(
+ 'twitter',
+ 'global_consumer_secret'
+ );
+ }
+
+ parent::__construct(
+ $consumer_key,
+ $consumer_secret,
+ $oauth_token,
+ $oauth_token_secret
+ );
}
// XXX: the following two functions are to support the horrible hack