Make Facebook plugin look for API key and secret before doing anything

This commit is contained in:
Zach Copley 2010-03-02 18:27:37 -08:00
parent ecccb344e0
commit 4aa516db45

View File

@ -79,6 +79,25 @@ class FacebookPlugin extends Plugin
}
}
/**
* Check to see if there is an API key and secret defined
* for Facebook integration.
*
* @return boolean result
*/
static function hasKeys()
{
$apiKey = common_config('facebook', 'apikey');
$apiSecret = common_config('facebook', 'secret');
if (!empty($apiKey) && !empty($apiSecret)) {
return true;
}
return false;
}
/**
* Add Facebook app actions to the router table
*
@ -91,6 +110,9 @@ class FacebookPlugin extends Plugin
function onStartInitializeRouter($m)
{
$m->connect('admin/facebook', array('action' => 'facebookadminpanel'));
if (self::hasKeys()) {
// Facebook App stuff
@ -100,7 +122,6 @@ class FacebookPlugin extends Plugin
array('action' => 'facebooksettings'));
$m->connect('facebook/app/invite.php', array('action' => 'facebookinvite'));
$m->connect('facebook/app/remove', array('action' => 'facebookremove'));
$m->connect('admin/facebook', array('action' => 'facebookadminpanel'));
// Facebook Connect stuff
@ -108,6 +129,7 @@ class FacebookPlugin extends Plugin
$m->connect('main/facebooklogin', array('action' => 'FBConnectLogin'));
$m->connect('settings/facebook', array('action' => 'FBConnectSettings'));
$m->connect('xd_receiver.html', array('action' => 'FBC_XDReceiver'));
}
return true;
}
@ -338,6 +360,9 @@ class FacebookPlugin extends Plugin
function reqFbScripts($action)
{
if (!self::hasKeys()) {
return false;
}
// If you're logged in w/FB Connect, you always need the FB stuff
@ -410,6 +435,8 @@ class FacebookPlugin extends Plugin
function onStartPrimaryNav($action)
{
if (self::hasKeys()) {
$user = common_current_user();
$connect = 'FBConnectSettings';
@ -448,6 +475,7 @@ class FacebookPlugin extends Plugin
}
}
}
return true;
}
@ -462,6 +490,7 @@ class FacebookPlugin extends Plugin
function onEndLoginGroupNav(&$action)
{
if (self::hasKeys()) {
$action_name = $action->trimmed('action');
@ -469,7 +498,7 @@ class FacebookPlugin extends Plugin
_m('Facebook'),
_m('Login or register using Facebook'),
'FBConnectLogin' === $action_name);
}
return true;
}
@ -483,13 +512,15 @@ class FacebookPlugin extends Plugin
function onEndConnectSettingsNav(&$action)
{
if (self::hasKeys()) {
$action_name = $action->trimmed('action');
$action->menuItem(common_local_url('FBConnectSettings'),
_m('Facebook'),
_m('Facebook Connect Settings'),
$action_name === 'FBConnectSettings');
}
return true;
}
@ -503,6 +534,8 @@ class FacebookPlugin extends Plugin
function onStartLogout($action)
{
if (self::hasKeys()) {
$action->logout();
$fbuid = $this->loggedIn();
@ -516,7 +549,7 @@ class FacebookPlugin extends Plugin
$e->getMessage());
}
}
}
return true;
}
@ -562,7 +595,9 @@ class FacebookPlugin extends Plugin
function onStartEnqueueNotice($notice, &$transports)
{
if (self::hasKeys()) {
array_push($transports, 'facebook');
}
return true;
}
@ -575,7 +610,9 @@ class FacebookPlugin extends Plugin
*/
function onEndInitializeQueueManager($manager)
{
if (self::hasKeys()) {
$manager->connect('facebook', 'FacebookQueueHandler');
}
return true;
}