summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2009-10-20 16:32:30 -0700
committerZach Copley <zach@status.net>2009-10-20 16:32:30 -0700
commit78e5a5980a21c04cfdacb993ca3c37bf65d21783 (patch)
tree6d4ef5e8b55ecd50607a7aebe556b961a37be842
parent5e536a66141fac332e77c5ea6e85aee6a9347ace (diff)
Extract out Facebook app stuff into a plugin
-rw-r--r--lib/router.php8
-rw-r--r--plugins/Facebook/FacebookPlugin.php151
-rw-r--r--plugins/Facebook/README5
-rw-r--r--plugins/Facebook/facebookaction.php (renamed from lib/facebookaction.php)44
-rw-r--r--plugins/Facebook/facebookhome.php (renamed from actions/facebookhome.php)6
-rw-r--r--plugins/Facebook/facebookinvite.php (renamed from actions/facebookinvite.php)2
-rw-r--r--plugins/Facebook/facebooklogin.php (renamed from actions/facebooklogin.php)34
-rwxr-xr-xplugins/Facebook/facebookqueuehandler.php (renamed from scripts/facebookqueuehandler.php)2
-rw-r--r--plugins/Facebook/facebookremove.php (renamed from actions/facebookremove.php)6
-rw-r--r--plugins/Facebook/facebooksettings.php (renamed from actions/facebooksettings.php)24
-rw-r--r--plugins/Facebook/facebookutil.php (renamed from lib/facebookutil.php)6
-rwxr-xr-xscripts/getvaliddaemons.php1
12 files changed, 209 insertions, 80 deletions
diff --git a/lib/router.php b/lib/router.php
index a5b6a9a30..4fb0834fd 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -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',
diff --git a/plugins/Facebook/FacebookPlugin.php b/plugins/Facebook/FacebookPlugin.php
new file mode 100644
index 000000000..127cf96e6
--- /dev/null
+++ b/plugins/Facebook/FacebookPlugin.php
@@ -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;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/Facebook/README b/plugins/Facebook/README
new file mode 100644
index 000000000..a350c5b5b
--- /dev/null
+++ b/plugins/Facebook/README
@@ -0,0 +1,5 @@
+
+
+TODO:
+
+- Integrate this and the FB Connect plugin \ No newline at end of file
diff --git a/lib/facebookaction.php b/plugins/Facebook/facebookaction.php
index 3f3a8d3b0..f5ad3d06b 100644
--- a/lib/facebookaction.php
+++ b/plugins/Facebook/facebookaction.php
@@ -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 *,
diff --git a/actions/facebookhome.php b/plugins/Facebook/facebookhome.php
index 70f205205..91c0cc6b8 100644
--- a/actions/facebookhome.php
+++ b/plugins/Facebook/facebookhome.php
@@ -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
{
diff --git a/actions/facebookinvite.php b/plugins/Facebook/facebookinvite.php
index 6dfc9d688..ecda1717c 100644
--- a/actions/facebookinvite.php
+++ b/plugins/Facebook/facebookinvite.php
@@ -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
{
diff --git a/actions/facebooklogin.php b/plugins/Facebook/facebooklogin.php
index 8ac2477ab..f77aecca3 100644
--- a/actions/facebooklogin.php
+++ b/plugins/Facebook/facebooklogin.php
@@ -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()
{
-
+
}
}
diff --git a/scripts/facebookqueuehandler.php b/plugins/Facebook/facebookqueuehandler.php
index e13ac4e85..30de59efb 100755
--- a/scripts/facebookqueuehandler.php
+++ b/plugins/Facebook/facebookqueuehandler.php
@@ -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
diff --git a/actions/facebookremove.php b/plugins/Facebook/facebookremove.php
index ae231c0fb..8531a8e6e 100644
--- a/actions/facebookremove.php
+++ b/plugins/Facebook/facebookremove.php
@@ -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
{
diff --git a/actions/facebooksettings.php b/plugins/Facebook/facebooksettings.php
index b2b1d6807..4bfdfc0ef 100644
--- a/actions/facebooksettings.php
+++ b/plugins/Facebook/facebooksettings.php
@@ -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');
}
diff --git a/lib/facebookutil.php b/plugins/Facebook/facebookutil.php
index c991c5439..9817837f7 100644
--- a/lib/facebookutil.php
+++ b/plugins/Facebook/facebookutil.php
@@ -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);
diff --git a/scripts/getvaliddaemons.php b/scripts/getvaliddaemons.php
index 7caea1bb7..99ad41b37 100755
--- a/scripts/getvaliddaemons.php
+++ b/scripts/getvaliddaemons.php
@@ -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')) {