forked from GNUsocial/gnu-social
Initial Facebook admin panel
This commit is contained in:
parent
1df8c2a44d
commit
40e1b249cf
@ -22,7 +22,7 @@
|
||||
* @category Plugin
|
||||
* @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/
|
||||
*/
|
||||
@ -32,12 +32,12 @@ if (!defined('STATUSNET')) {
|
||||
}
|
||||
|
||||
define("FACEBOOK_CONNECT_SERVICE", 3);
|
||||
define('FACEBOOKPLUGIN_VERSION', '0.9');
|
||||
|
||||
require_once INSTALLDIR . '/plugins/Facebook/facebookutil.php';
|
||||
|
||||
/**
|
||||
* Facebook plugin to add a StatusNet Facebook application
|
||||
* Facebook plugin to add a StatusNet Facebook canvas application
|
||||
* and allow registration and authentication via Facebook Connect
|
||||
*
|
||||
* @category Plugin
|
||||
* @package StatusNet
|
||||
@ -49,6 +49,36 @@ require_once INSTALLDIR . '/plugins/Facebook/facebookutil.php';
|
||||
class FacebookPlugin extends Plugin
|
||||
{
|
||||
|
||||
const VERSION = STATUSNET_VERSION;
|
||||
|
||||
/**
|
||||
* Initializer for the plugin.
|
||||
*/
|
||||
|
||||
function initialize()
|
||||
{
|
||||
// Allow the key and secret to be passed in
|
||||
// Control panel will override
|
||||
|
||||
if (isset($this->apikey)) {
|
||||
$key = common_config('facebook', 'apikey');
|
||||
if (empty($key)) {
|
||||
Config::save('facebook', 'apikey', $this->apikey);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->secret)) {
|
||||
$secret = common_config('facebook', 'secret');
|
||||
if (empty($secret)) {
|
||||
Config::save(
|
||||
'facebook',
|
||||
'secret',
|
||||
$this->secret
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Facebook app actions to the router table
|
||||
*
|
||||
@ -70,6 +100,7 @@ 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
|
||||
|
||||
@ -98,6 +129,7 @@ class FacebookPlugin extends Plugin
|
||||
case 'FacebookinviteAction':
|
||||
case 'FacebookremoveAction':
|
||||
case 'FacebooksettingsAction':
|
||||
case 'FacebookadminpanelAction':
|
||||
include_once INSTALLDIR . '/plugins/Facebook/' .
|
||||
strtolower(mb_substr($cls, 0, -6)) . '.php';
|
||||
return false;
|
||||
@ -122,6 +154,32 @@ class FacebookPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Facebook tab to the admin panels
|
||||
*
|
||||
* @param Widget $nav Admin panel nav
|
||||
*
|
||||
* @return boolean hook value
|
||||
*/
|
||||
|
||||
function onEndAdminPanelNav($nav)
|
||||
{
|
||||
if (AdminPanelAction::canAdmin('facebook')) {
|
||||
|
||||
$action_name = $nav->action->trimmed('action');
|
||||
|
||||
$nav->out->menuItem(
|
||||
common_local_url('facebookadminpanel'),
|
||||
_m('Facebook'),
|
||||
_m('Facebook integration configuration'),
|
||||
$action_name == 'facebookadminpanel',
|
||||
'nav_facebook_admin_panel'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override normal HTML output to force the content type to
|
||||
* text/html and add in xmlns:fb
|
||||
@ -523,15 +581,18 @@ class FacebookPlugin extends Plugin
|
||||
|
||||
function onPluginVersion(&$versions)
|
||||
{
|
||||
$versions[] = array('name' => 'Facebook',
|
||||
'version' => FACEBOOKPLUGIN_VERSION,
|
||||
$versions[] = array(
|
||||
'name' => 'Facebook',
|
||||
'version' => self::VERSION,
|
||||
'author' => 'Zach Copley',
|
||||
'homepage' => 'http://status.net/wiki/Plugin:Facebook',
|
||||
'rawdescription' =>
|
||||
_m('The Facebook plugin allows you to integrate ' .
|
||||
'rawdescription' => _m(
|
||||
'The Facebook plugin allows you to integrate ' .
|
||||
'your StatusNet instance with ' .
|
||||
'<a href="http://facebook.com/">Facebook</a> ' .
|
||||
'and Facebook Connect.'));
|
||||
'and Facebook Connect.'
|
||||
)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
223
plugins/Facebook/facebookadminpanel.php
Normal file
223
plugins/Facebook/facebookadminpanel.php
Normal file
@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* StatusNet, the distributed open-source microblogging tool
|
||||
*
|
||||
* Facebook integration administration panel
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Settings
|
||||
* @package StatusNet
|
||||
* @author Zach Copley <zach@status.net>
|
||||
* @copyright 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/
|
||||
*/
|
||||
|
||||
if (!defined('STATUSNET')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Administer global Facebook integration settings
|
||||
*
|
||||
* @category Admin
|
||||
* @package StatusNet
|
||||
* @author Zach Copley <zach@status.net>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://status.net/
|
||||
*/
|
||||
|
||||
class FacebookadminpanelAction extends AdminPanelAction
|
||||
{
|
||||
/**
|
||||
* Returns the page title
|
||||
*
|
||||
* @return string page title
|
||||
*/
|
||||
|
||||
function title()
|
||||
{
|
||||
return _m('Facebook');
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructions for using this form.
|
||||
*
|
||||
* @return string instructions
|
||||
*/
|
||||
|
||||
function getInstructions()
|
||||
{
|
||||
return _m('Facebook integration settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the Facebook admin panel form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function showForm()
|
||||
{
|
||||
$form = new FacebookAdminPanelForm($this);
|
||||
$form->show();
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings from the form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function saveSettings()
|
||||
{
|
||||
static $settings = array(
|
||||
'facebook' => array('apikey', 'secret'),
|
||||
);
|
||||
|
||||
$values = array();
|
||||
|
||||
foreach ($settings as $section => $parts) {
|
||||
foreach ($parts as $setting) {
|
||||
$values[$section][$setting]
|
||||
= $this->trimmed($setting);
|
||||
}
|
||||
}
|
||||
|
||||
// This throws an exception on validation errors
|
||||
|
||||
$this->validate($values);
|
||||
|
||||
// assert(all values are valid);
|
||||
|
||||
$config = new Config();
|
||||
|
||||
$config->query('BEGIN');
|
||||
|
||||
foreach ($settings as $section => $parts) {
|
||||
foreach ($parts as $setting) {
|
||||
Config::save($section, $setting, $values[$section][$setting]);
|
||||
}
|
||||
}
|
||||
|
||||
$config->query('COMMIT');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function validate(&$values)
|
||||
{
|
||||
// Validate consumer key and secret (can't be too long)
|
||||
|
||||
if (mb_strlen($values['facebook']['apikey']) > 255) {
|
||||
$this->clientError(
|
||||
_m("Invalid Facebook API key. Max length is 255 characters.")
|
||||
);
|
||||
}
|
||||
|
||||
if (mb_strlen($values['facebook']['secret']) > 255) {
|
||||
$this->clientError(
|
||||
_m("Invalid Facebook API secret. Max length is 255 characters.")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FacebookAdminPanelForm extends AdminForm
|
||||
{
|
||||
/**
|
||||
* ID of the form
|
||||
*
|
||||
* @return int ID of the form
|
||||
*/
|
||||
|
||||
function id()
|
||||
{
|
||||
return 'facebookadminpanel';
|
||||
}
|
||||
|
||||
/**
|
||||
* class of the form
|
||||
*
|
||||
* @return string class of the form
|
||||
*/
|
||||
|
||||
function formClass()
|
||||
{
|
||||
return 'form_settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* Action of the form
|
||||
*
|
||||
* @return string URL of the action
|
||||
*/
|
||||
|
||||
function action()
|
||||
{
|
||||
return common_local_url('facebookadminpanel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Data elements of the form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function formData()
|
||||
{
|
||||
$this->out->elementStart(
|
||||
'fieldset',
|
||||
array('id' => 'settings_facebook-application')
|
||||
);
|
||||
$this->out->element('legend', null, _m('Facebook application settings'));
|
||||
$this->out->elementStart('ul', 'form_data');
|
||||
|
||||
$this->li();
|
||||
$this->input(
|
||||
'apikey',
|
||||
_m('API key'),
|
||||
_m('API key provided by Facebook'),
|
||||
'facebook'
|
||||
);
|
||||
$this->unli();
|
||||
|
||||
$this->li();
|
||||
$this->input(
|
||||
'secret',
|
||||
_m('Secret'),
|
||||
_m('API secret provided by Facebook'),
|
||||
'facebook'
|
||||
);
|
||||
$this->unli();
|
||||
|
||||
$this->out->elementEnd('ul');
|
||||
$this->out->elementEnd('fieldset');
|
||||
}
|
||||
|
||||
/**
|
||||
* Action elements
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function formActions()
|
||||
{
|
||||
$this->out->submit('submit', _('Save'), 'submit', null, _('Save Facebook settings'));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user