- 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
This commit is contained in:
parent
09705a1e98
commit
ca21f1da86
|
@ -20,7 +20,7 @@ on Twitter (http://twitter.com/apps). During the application
|
||||||
registration process your application will be assigned a "consumer" key
|
registration process your application will be assigned a "consumer" key
|
||||||
and secret, which the plugin will use to make OAuth requests to Twitter.
|
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
|
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"
|
When registering your application with Twitter set the type to "Browser"
|
||||||
and your Callback URL to:
|
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
|
* Note: The plugin will still push notices to Twitter for users who
|
||||||
have previously set up the Twitter bridge using their Twitter name and
|
have previously set up the Twitter bridge using their Twitter name and
|
||||||
password under an older version of StatusNet, but all new Twitter
|
password under an older version of StatusNet, but all new Twitter
|
||||||
bridge connections will use OAuth.
|
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
|
Administration panel
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,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
|
* Add Twitter-related paths to the router table
|
||||||
*
|
*
|
||||||
|
@ -91,14 +115,22 @@ class TwitterBridgePlugin extends Plugin
|
||||||
|
|
||||||
function onRouterInitialized($m)
|
function onRouterInitialized($m)
|
||||||
{
|
{
|
||||||
|
if (self::hasKeys()) {
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'twitter/authorization',
|
'twitter/authorization',
|
||||||
array('action' => 'twitterauthorization')
|
array('action' => 'twitterauthorization')
|
||||||
);
|
);
|
||||||
$m->connect('settings/twitter', array('action' => 'twittersettings'));
|
$m->connect(
|
||||||
|
'settings/twitter', array(
|
||||||
|
'action' => 'twittersettings'
|
||||||
|
)
|
||||||
|
);
|
||||||
if (common_config('twitter', 'signin')) {
|
if (common_config('twitter', 'signin')) {
|
||||||
$m->connect('main/twitterlogin', array('action' => 'twitterlogin'));
|
$m->connect(
|
||||||
|
'main/twitterlogin',
|
||||||
|
array('action' => 'twitterlogin')
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$m->connect('admin/twitter', array('action' => 'twitteradminpanel'));
|
$m->connect('admin/twitter', array('action' => 'twitteradminpanel'));
|
||||||
|
@ -117,7 +149,7 @@ class TwitterBridgePlugin extends Plugin
|
||||||
{
|
{
|
||||||
$action_name = $action->trimmed('action');
|
$action_name = $action->trimmed('action');
|
||||||
|
|
||||||
if (common_config('twitter', 'signin')) {
|
if (self::hasKeys() && common_config('twitter', 'signin')) {
|
||||||
$action->menuItem(
|
$action->menuItem(
|
||||||
common_local_url('twitterlogin'),
|
common_local_url('twitterlogin'),
|
||||||
_m('Twitter'),
|
_m('Twitter'),
|
||||||
|
@ -138,6 +170,7 @@ class TwitterBridgePlugin extends Plugin
|
||||||
*/
|
*/
|
||||||
function onEndConnectSettingsNav(&$action)
|
function onEndConnectSettingsNav(&$action)
|
||||||
{
|
{
|
||||||
|
if (self::hasKeys()) {
|
||||||
$action_name = $action->trimmed('action');
|
$action_name = $action->trimmed('action');
|
||||||
|
|
||||||
$action->menuItem(
|
$action->menuItem(
|
||||||
|
@ -146,7 +179,7 @@ class TwitterBridgePlugin extends Plugin
|
||||||
_m('Twitter integration options'),
|
_m('Twitter integration options'),
|
||||||
$action_name === 'twittersettings'
|
$action_name === 'twittersettings'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,12 +221,12 @@ class TwitterBridgePlugin extends Plugin
|
||||||
*/
|
*/
|
||||||
function onStartEnqueueNotice($notice, &$transports)
|
function onStartEnqueueNotice($notice, &$transports)
|
||||||
{
|
{
|
||||||
|
if (self::hasKeys()) {
|
||||||
// Avoid a possible loop
|
// Avoid a possible loop
|
||||||
|
|
||||||
if ($notice->source != 'twitter') {
|
if ($notice->source != 'twitter') {
|
||||||
array_push($transports, 'twitter');
|
array_push($transports, 'twitter');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,12 +239,12 @@ class TwitterBridgePlugin extends Plugin
|
||||||
*/
|
*/
|
||||||
function onGetValidDaemons($daemons)
|
function onGetValidDaemons($daemons)
|
||||||
{
|
{
|
||||||
|
if (self::hasKeys()) {
|
||||||
array_push(
|
array_push(
|
||||||
$daemons,
|
$daemons,
|
||||||
INSTALLDIR
|
INSTALLDIR
|
||||||
. '/plugins/TwitterBridge/daemons/synctwitterfriends.php'
|
. '/plugins/TwitterBridge/daemons/synctwitterfriends.php'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (common_config('twitterimport', 'enabled')) {
|
if (common_config('twitterimport', 'enabled')) {
|
||||||
array_push(
|
array_push(
|
||||||
$daemons,
|
$daemons,
|
||||||
|
@ -219,6 +252,7 @@ class TwitterBridgePlugin extends Plugin
|
||||||
. '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php'
|
. '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +266,9 @@ class TwitterBridgePlugin extends Plugin
|
||||||
*/
|
*/
|
||||||
function onEndInitializeQueueManager($manager)
|
function onEndInitializeQueueManager($manager)
|
||||||
{
|
{
|
||||||
|
if (self::hasKeys()) {
|
||||||
$manager->connect('twitter', 'TwitterQueueHandler');
|
$manager->connect('twitter', 'TwitterQueueHandler');
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
* @category Integration
|
* @category Integration
|
||||||
* @package StatusNet
|
* @package StatusNet
|
||||||
* @author Zach Copley <zach@status.net>
|
* @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
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
@ -61,8 +61,23 @@ class TwitterOAuthClient extends OAuthClient
|
||||||
$consumer_key = common_config('twitter', 'consumer_key');
|
$consumer_key = common_config('twitter', 'consumer_key');
|
||||||
$consumer_secret = common_config('twitter', 'consumer_secret');
|
$consumer_secret = common_config('twitter', 'consumer_secret');
|
||||||
|
|
||||||
parent::__construct($consumer_key, $consumer_secret,
|
if (empty($consumer_key) && empty($consumer_secret)) {
|
||||||
$oauth_token, $oauth_token_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
|
// XXX: the following two functions are to support the horrible hack
|
||||||
|
|
Loading…
Reference in New Issue
Block a user