Extract out Facebook app stuff into a plugin

This commit is contained in:
Zach Copley 2009-10-20 16:32:30 -07:00
parent 5e536a6614
commit 78e5a5980a
12 changed files with 209 additions and 80 deletions

View File

@ -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',

View File

@ -0,0 +1,151 @@
<?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;
}
}

5
plugins/Facebook/README Normal file
View File

@ -0,0 +1,5 @@
TODO:
- Integrate this and the FB Connect plugin

View 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);
@ -110,8 +98,6 @@ class FacebookAction extends Action
* 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.
*
* @param string $type MIME type to use; default is to do negotation.
*
* @return void
@ -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()

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{
@ -42,7 +44,6 @@ class FacebookinviteAction extends FacebookAction
}
}
function showContent()
{
@ -78,14 +79,11 @@ class FacebookinviteAction extends FacebookAction
function showSuccessContent()
{
}
function showFormContent()
{
}
function title()

View File

@ -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

View File

@ -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
{

View File

@ -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
{

View File

@ -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);

View File

@ -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')) {