Commit 78e5a598 authored by Zach Copley's avatar Zach Copley

Extract out Facebook app stuff into a plugin

parent 5e536a66
......@@ -86,14 +86,6 @@ class Router
$m->connect('doc/:title', array('action' => 'doc'));
// facebook
$m->connect('facebook', array('action' => 'facebookhome'));
$m->connect('facebook/index.php', array('action' => 'facebookhome'));
$m->connect('facebook/settings.php', array('action' => 'facebooksettings'));
$m->connect('facebook/invite.php', array('action' => 'facebookinvite'));
$m->connect('facebook/remove', array('action' => 'facebookremove'));
// main stuff is repetitive
$main = array('login', 'logout', 'register', 'subscribe',
......
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Plugin to add a StatusNet Facebook application
*
* 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 Plugin
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2009 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);
}
/**
* Facebook plugin to add a StatusNet Facebook application
*
* @category Plugin
* @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 FacebookPlugin extends Plugin
{
/**
* Add Facebook app actions to the router table
*
* Hook for RouterInitialized event.
*
* @param Net_URL_Mapper &$m path-to-action mapper
*
* @return boolean hook return
*/
function onRouterInitialized(&$m)
{
$m->connect('facebook', array('action' => 'facebookhome'));
$m->connect('facebook/index.php', array('action' => 'facebookhome'));
$m->connect('facebook/settings.php', array('action' => 'facebooksettings'));
$m->connect('facebook/invite.php', array('action' => 'facebookinvite'));
$m->connect('facebook/remove', array('action' => 'facebookremove'));
return true;
}
/**
* Automatically load the actions and libraries used by the Facebook app
*
* @param Class $cls the class
*
* @return boolean hook return
*
*/
function onAutoload($cls)
{
switch ($cls) {
case 'FacebookAction':
case 'FacebookhomeAction':
case 'FacebookinviteAction':
case 'FacebookremoveAction':
case 'FacebooksettingsAction':
include_once INSTALLDIR . '/plugins/Facebook/' .
strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
default:
return true;
}
}
/**
* Add a Facebook queue item for each notice
*
* @param Notice $notice the notice
* @param array &$transports the list of transports (queues)
*
* @return boolean hook return
*/
function onStartEnqueueNotice($notice, &$transports)
{
array_push($transports, 'facebook');
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 == 'facebook') && ($this->_isLocal($notice))) {
facebookBroadcastNotice($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 Facebook queuehandler to the list of daemons to start
*
* @param array $daemons the list fo daemons to run
*
* @return boolean hook return
*
*/
function onGetValidDaemons($daemons)
{
array_push($daemons, INSTALLDIR .
'/plugins/Facebook/facebookqueuehandler.php');
return true;
}
}
\ No newline at end of file
TODO:
- Integrate this and the FB Connect plugin
\ No newline at end of file
......@@ -2,7 +2,7 @@
/**
* StatusNet, the distributed open-source microblogging tool
*
* Low-level generator for HTML
* Base Facebook Action
*
* PHP version 5
*
......@@ -22,18 +22,17 @@
* @category Faceboook
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2008 StatusNet, Inc.
* @copyright 2008-2009 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') && !defined('LACONICA'))
{
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/facebookutil.php';
require_once INSTALLDIR.'/lib/noticeform.php';
require_once INSTALLDIR . '/plugins/Facebook/facebookutil.php';
require_once INSTALLDIR . '/lib/noticeform.php';
class FacebookAction extends Action
{
......@@ -45,17 +44,6 @@ class FacebookAction extends Action
var $app_uri = null;
var $app_name = null;
/**
* Constructor
*
* Just wraps the HTMLOutputter constructor.
*
* @param string $output URI to output to, default = stdout
* @param boolean $indent Whether to indent output, default true
*
* @see XMLOutputter::__construct
* @see HTMLOutputter::__construct
*/
function __construct($output='php://output', $indent=true, $facebook=null, $flink=null)
{
parent::__construct($output, $indent);
......@@ -107,10 +95,8 @@ class FacebookAction extends Action
/**
* Start an Facebook ready HTML document
*
* For Facebook we don't want to actually output any headers,
* DTD info, etc. Just Stylesheet and JavaScript links.
*
* If $type isn't specified, will attempt to do content negotiation.
* For Facebook we don't want to actually output any headers,
* DTD info, etc. Just Stylesheet and JavaScript links.
*
* @param string $type MIME type to use; default is to do negotation.
*
......@@ -139,8 +125,6 @@ class FacebookAction extends Action
/**
* Show notice form.
*
* MAY overload if no notice form needed... or direct message box????
*
* @return nothing
*/
function showNoticeForm()
......@@ -157,10 +141,6 @@ class FacebookAction extends Action
$this->elementEnd('div');
}
function showAside()
{
}
function showHead($error, $success)
{
......@@ -214,8 +194,6 @@ class FacebookAction extends Action
/**
* Show header of the page.
*
* Calls template methods
*
* @return nothing
*/
function showHeader()
......@@ -257,7 +235,7 @@ class FacebookAction extends Action
$this->element('a',
array('href' => common_local_url('register')), _('Register'));
$this->text($loginmsg_part2);
$this->elementEnd('p');
$this->elementEnd('p');
$this->elementEnd('dd');
$this->elementEnd('dl');
......@@ -295,7 +273,7 @@ class FacebookAction extends Action
$this->elementEnd('ul');
$this->submit('submit', _('Login'));
$this->elementEnd('fieldset');
$this->elementEnd('fieldset');
$this->elementEnd('form');
$this->elementStart('p');
......@@ -313,8 +291,8 @@ class FacebookAction extends Action
// Need to include inline CSS for styling the Profile box
$app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url'));
$icon_url = $app_props['icon_url'];
$app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url'));
$icon_url = $app_props['icon_url'];
$style = '<style>
.entry-title *,
......
......@@ -17,9 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/facebookaction.php';
require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php';
class FacebookhomeAction extends FacebookAction
{
......
......@@ -21,7 +21,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once(INSTALLDIR.'/lib/facebookaction.php');
require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php';
class FacebookinviteAction extends FacebookAction
{
......
......@@ -17,9 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once(INSTALLDIR.'/lib/facebookaction.php');
require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php';
class FacebookinviteAction extends FacebookAction
{
......@@ -27,25 +29,24 @@ class FacebookinviteAction extends FacebookAction
function handle($args)
{
parent::handle($args);
$this->error = $error;
if ($this->flink) {
if (!$this->facebook->api_client->users_hasAppPermission('publish_stream') &&
$this->facebook->api_client->data_getUserPreference(
FACEBOOK_PROMPTED_UPDATE_PREF) == 'true') {
echo '<h1>REDIRECT TO HOME</h1>';
}
} else {
} else {
$this->showPage();
}
}
function showContent()
{
// If the user has opted not to initially allow the app to have
// Facebook status update permission, store that preference. Only
// promt the user the first time she uses the app
......@@ -68,34 +69,31 @@ class FacebookinviteAction extends FacebookAction
return;
}
}
} else {
$this->showLoginForm();
}
}
function showSuccessContent()
{
}
function showFormContent()
{
}
function title()
function title()
{
return sprintf(_('Login'));
}
function redirectHome()
function redirectHome()
{
}
}
......@@ -32,7 +32,7 @@ END_OF_FACEBOOK_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/facebookutil.php';
require_once INSTALLDIR . '/plugins/Facebook/facebookutil.php';
require_once INSTALLDIR . '/lib/queuehandler.php';
class FacebookQueueHandler extends QueueHandler
......
......@@ -17,9 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/facebookaction.php';
require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php';
class FacebookremoveAction extends FacebookAction
{
......
......@@ -17,9 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/facebookaction.php';
require_once INSTALLDIR . '/lib/facebookaction.php';
class FacebooksettingsAction extends FacebookAction
{
......@@ -91,16 +93,16 @@ class FacebooksettingsAction extends FacebookAction
'id' => 'facebook_settings'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'),
($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('replysync', _('Send "@" replies to Facebook.'),
($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
......@@ -115,15 +117,15 @@ class FacebooksettingsAction extends FacebookAction
_('A string to prefix notices with.'));
$this->elementEnd('li');
$this->elementStart('li');
$this->submit('save', _('Save'));
$this->elementEnd('li');
$this->elementEnd('ul');
$this->elementEnd('form');
} else {
......@@ -148,8 +150,8 @@ class FacebooksettingsAction extends FacebookAction
}
}
function title()
function title()
{
return _('Sync preferences');
}
......
......@@ -17,9 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once INSTALLDIR.'/extlib/facebook/facebook.php';
require_once INSTALLDIR.'/lib/facebookaction.php';
require_once INSTALLDIR.'/lib/noticelist.php';
require_once INSTALLDIR . '/extlib/facebook/facebook.php';
require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php';
require_once INSTALLDIR . '/lib/noticelist.php';
define("FACEBOOK_SERVICE", 2); // Facebook is foreign_service ID 2
define("FACEBOOK_NOTICE_PREFIX", 1);
......
......@@ -39,7 +39,6 @@ $daemons = array();
$daemons[] = INSTALLDIR.'/scripts/pluginqueuehandler.php';
$daemons[] = INSTALLDIR.'/scripts/ombqueuehandler.php';
$daemons[] = INSTALLDIR.'/scripts/facebookqueuehandler.php';
$daemons[] = INSTALLDIR.'/scripts/pingqueuehandler.php';
if(common_config('xmpp','enabled')) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment