diff --git a/.gitignore b/.gitignore index 1cde3a6254..217622c84d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,4 @@ config-*.php good-config.php lac08.log php.log - +.DS_Store diff --git a/EVENTS.txt b/EVENTS.txt index 02b11a8a67..5d34a9e13b 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -291,3 +291,167 @@ EndShowHeadElements: Right before the tag; put ', $apikey, - $login_url, $logout_url); + // The below function alters the logout link so that it logs the user out + // of Facebook Connect as well as the site. However, for some pages + // (FB Connect Settings) we need to output the FB Connect scripts (to + // show an existing FB connection even if the user isn't authenticated + // with Facebook connect) but NOT alter the logout link. And the only + // way to reliably do that is with the FB Connect .js libs. Crazy. - $action->raw($html); + $js .= ' FB.ensureInit(function() {'; + $js .= ' FB.Connect.ifUserConnected('; + $js .= ' function() { '; + $js .= ' $(\'#nav_logout a\').attr(\'href\', \'#\');'; + $js .= ' $(\'#nav_logout a\').click(function() {'; + $js .= ' FB.Connect.logoutAndRedirect(\'%3$s\');'; + $js .= ' return false;'; + $js .= ' })'; + $js .= ' },'; + $js .= ' function() {'; + $js .= ' return false;'; + $js .= ' }'; + $js .= ' );'; + $js .= ' });'; + $js .= ''; + + $js = sprintf($js, $apikey, $login_url, $logout_url); + + // Compress the bugger down a bit + + $js = str_replace(' ', '', $js); + + $action->raw(" $js"); // leading two spaces to make it line up } } - // Note: this script needs to appear as close as possible to + /** + * Add in an additional Facebook Connect script that's supposed to + * appear as close as possible to + * + * @param Action $action the current action + * + * @return void + * + */ function onEndShowFooter($action) { if ($this->reqFbScripts($action)) { - $action->script('http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php'); + $action->script('http://static.ak.connect.facebook.com' . + '/js/api_lib/v0.4/FeatureLoader.js.php'); } } + /** + * Output Facebook Connect specific CSS link + * + * @param Action $action the current action + * + * @return void + * + */ + function onEndShowStatusNetStyles($action) { - if ($this->reqFbScripts($action)) { - $action->cssLink('plugins/FBConnect/FBConnectPlugin.css'); + $action->cssLink('plugins/Facebook/FBConnect.css'); } } @@ -161,12 +271,13 @@ class FBConnectPlugin extends Plugin * want to output FB namespace, scripts, CSS, etc. on the pages that * really need them. * - * @param Action the action in question + * @param Action $action the current action * * @return boolean true */ - function reqFbScripts($action) { + function reqFbScripts($action) + { // If you're logged in w/FB Connect, you always need the FB stuff @@ -228,10 +339,19 @@ class FBConnectPlugin extends Plugin return null; } + /** + * Add in a Facebook Connect avatar to the primary nav menu + * + * @param Action $action the current action + * + * @return void + * + */ + function onStartPrimaryNav($action) { - $user = common_current_user(); + $connect = 'FBConnectSettings'; if (common_config('xmpp', 'enabled')) { $connect = 'imsettings'; @@ -262,78 +382,31 @@ class FBConnectPlugin extends Plugin 'alt' => 'Facebook Connect User', 'width' => '16'), ''); - $iconurl = common_path('plugins/FBConnect/fbfavicon.ico'); + $iconurl = common_path('plugins/Facebook/fbfavicon.ico'); $action->element('img', array('id' => 'fb_favicon', 'src' => $iconurl)); $action->elementEnd('li'); } + } - $action->menuItem(common_local_url('all', array('nickname' => $user->nickname)), - _('Home'), _('Personal profile and friends timeline'), false, 'nav_home'); - $action->menuItem(common_local_url('profilesettings'), - _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account'); - $action->menuItem(common_local_url($connect), - _('Connect'), _('Connect to services'), false, 'nav_connect'); - if (common_config('invite', 'enabled')) { - $action->menuItem(common_local_url('invite'), - _('Invite'), - sprintf(_('Invite friends and colleagues to join you on %s'), - common_config('site', 'name')), - false, 'nav_invitecontact'); - } - - // Need to override the Logout link to make it do FB stuff - if (!empty($fbuid)) { - - $logout_url = common_local_url('logout'); - $title = _('Logout from the site'); - $text = _('Logout'); - - $html = sprintf('', - $title, $logout_url, $text); - - $action->raw($html); - - } else { - $action->menuItem(common_local_url('logout'), - _('Logout'), _('Logout from the site'), false, 'nav_logout'); - } - } - else { - if (!common_config('site', 'openidonly')) { - if (!common_config('site', 'closed')) { - $action->menuItem(common_local_url('register'), - _('Register'), _('Create an account'), false, 'nav_register'); - } - $action->menuItem(common_local_url('login'), - _('Login'), _('Login to the site'), false, 'nav_login'); - } else { - $this->menuItem(common_local_url('openidlogin'), - _('OpenID'), _('Login with OpenID'), false, 'nav_openid'); - } - } - - $action->menuItem(common_local_url('doc', array('title' => 'help')), - _('Help'), _('Help me!'), false, 'nav_help'); - if ($user || !common_config('site', 'private')) { - $action->menuItem(common_local_url('peoplesearch'), - _('Search'), _('Search for people or text'), false, 'nav_search'); - } - - // We are replacing the primary nav entirely; give other - // plugins a chance to handle it here. - - Event::handle('EndPrimaryNav', array($action)); - - return false; + return true; } + /** + * Alter the local nav menu to have a Facebook Connect login and + * settings pages + * + * @param Action $action the current action + * + * @return void + * + */ + function onStartShowLocalNavBlock($action) { - $action_name = get_class($action); + $action_name = get_class($action); $login_actions = array('LoginAction', 'RegisterAction', 'OpenidloginAction', 'FBConnectLoginAction'); @@ -356,8 +429,16 @@ class FBConnectPlugin extends Plugin return true; } + /** + * Have the logout process do some Facebook Connect cookie cleanup + * + * @param Action $action the current action + * + * @return void + */ + function onStartLogout($action) -{ + { $action->logout(); $fbuid = $this->loggedIn(); @@ -375,9 +456,16 @@ class FBConnectPlugin extends Plugin return true; } + /** + * Get the URL of the user's Facebook avatar + * + * @param int $fbuid the Facebook user ID + * + * @return string $url the url for the user's Facebook avatar + */ + function getProfilePicURL($fbuid) { - $facebook = getFacebook(); $url = null; @@ -396,8 +484,70 @@ class FBConnectPlugin extends Plugin "Facebook client failure requesting profile pic!"); } - return $url; + return $url; + } + /** + * 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 the 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; } } diff --git a/plugins/Facebook/README b/plugins/Facebook/README new file mode 100644 index 0000000000..bf2f4a1800 --- /dev/null +++ b/plugins/Facebook/README @@ -0,0 +1,129 @@ +This plugin allows you to use Facebook Connect with StatusNet, provides a +Facebook application for your users, and allows them to update their +Facebook statuses from StatusNet. + +Facebook Connect +---------------- + +Facebook connect allows users to register and login using nothing but their +Facebook credentials. With Facebook Connect, your users can: + +- Authenticate (register/login/logout -- works similar to OpenID) +- Associate an existing StatusNet account with a Facebook account +- Disconnect a Facebook account from a StatusNet account + +Built-in Facebook Application +----------------------------- + +The plugin also installs a StatusNet Facebook application that allows your +users to automatically update their Facebook statuses with their latest +notices, invite their friends to use the app (and thus your site), view +their notice timelines, and post notices -- all from within Facebook. The +application is built into the StatusNet Facebook plugin and runs on your +host. + +Quick setup instructions* +------------------------- + +Install the Facebook Developer application on Facebook: + + http://www.facebook.com/developers/ + +Use it to create a new application and generate an API key and secret. Add a +Facebook app section of your config.php and copy in the key and secret, +e.g.: + + // Config section for the built-in Facebook application + $config['facebook']['apikey'] = 'APIKEY'; + $config['facebook']['secret'] = 'SECRET'; + +In Facebook's application editor, specify the following URLs for your app: + +- Canvas Callback URL : http://example.net/mublog/facebook/app/ +- Post-Remove Callback URL: http://example.net/mublog/facebook/app/remove +- Post-Add Redirect URL : http://apps.facebook.com/yourapp/ +- Canvas Page URL : http://apps.facebook.com/yourapp/ +- Connect URL : http://example.net/mublog/ + + *** ATTENTION *** + These URLs have changed slightly since StatusNet version 0.8.1, + so if you have been using the Facebook app previously, you will + need to update your configuration! + +Replace "example.net" with your host's URL, "mublog" with the path to your +StatusNet installation, and 'yourapp' with the name of the Facebook +application you created. (If you don't have "Fancy URLs" on, you'll need to +change http://example.net/mublog/ to http://example.net/mublog/index.php/). + +Additionally, Choose "Web" for Application type in the Advanced tab. In the +"Canvas setting" section, choose the "FBML" for Render Method, "Smart Size" +for IFrame size, and "Full width (760px)" for Canvas Width. Everything else +can be left with default values. + +* NOTE: For more under-the-hood detailed instructions about setting up a + Facebook application and getting an API key, check out the + following pages on the Facebook wiki: + + http://wiki.developers.facebook.com/index.php/Connect/Setting_Up_Your_Site + http://wiki.developers.facebook.com/index.php/Creating_your_first_application + +Finally you must activate the plugin by adding the following line to your +config.php: + + addPlugin('Facebook'); + +Testing It Out +-------------- + +If the Facebook plugin is enabled and working, there will be a new Facebook +Connect Settings tab under each user's Connect menu. Users can connect and +disconnect* to their Facebook accounts from it. + +To try out the plugin, fire up your browser and connect to: + + http://SITE/PATH_TO_STATUSNET/main/facebooklogin + +or, if you do not have fancy URLs turned on: + + http://SITE/PATH_TO_STATUSNET/index.php/main/facebooklogin + +You should see a page with a blue button that says: "Connect with Facebook" +and you should be able to login or register. + +From within Facebook, you should also be able to get to the Facebook +application, and run it by hitting the link you specified above when +configuring it: + + http://apps.facebook.com/yourapp/ + +That link should be present you with a login screen. After logging in to +the app, you are given the option to update their Facebook status via +StatusNet. + +* Note: Before a user can disconnect from Facebook, she must set a normal + StatusNet password. Otherwise, she might not be able to login in to her + account in the future. This is usually only required for users who have + used Facebook Connect to register their StatusNet account, and therefore + haven't already set a local password. + +Offline Queue Handling +---------------------- + +For larger sites needing better performance it's possible to enable queuing +and have users' notices posted to Facebook via a separate "offline" +FacebookQueueHandler (facebookqueuhandler.php in the Facebook plugin +directory), which will be started by the plugin along with their other +daemons when you run scripts/startdaemons.sh. See the StatusNet README for +more about queuing and daemons. + +TODO +---- + +- Invite Facebook friends to use your StatusNet installation via Facebook + Connect +- Auto-subscribe Facebook friends already using StatusNet +- Share StatusNet favorite notices to your Facebook stream +- Allow users to update their Facebook statuses once they have authenticated + with Facebook Connect (no need for them to use the Facebook app if they + don't want to). +- Re-design the whole thing to support multiple instances of StatusNet diff --git a/extlib/facebook/facebook.php b/plugins/Facebook/facebook/facebook.php similarity index 100% rename from extlib/facebook/facebook.php rename to plugins/Facebook/facebook/facebook.php diff --git a/extlib/facebook/facebook_desktop.php b/plugins/Facebook/facebook/facebook_desktop.php similarity index 100% rename from extlib/facebook/facebook_desktop.php rename to plugins/Facebook/facebook/facebook_desktop.php diff --git a/extlib/facebook/facebookapi_php5_restlib.php b/plugins/Facebook/facebook/facebookapi_php5_restlib.php similarity index 100% rename from extlib/facebook/facebookapi_php5_restlib.php rename to plugins/Facebook/facebook/facebookapi_php5_restlib.php diff --git a/extlib/facebook/jsonwrapper/JSON/JSON.php b/plugins/Facebook/facebook/jsonwrapper/JSON/JSON.php similarity index 100% rename from extlib/facebook/jsonwrapper/JSON/JSON.php rename to plugins/Facebook/facebook/jsonwrapper/JSON/JSON.php diff --git a/extlib/facebook/jsonwrapper/JSON/LICENSE b/plugins/Facebook/facebook/jsonwrapper/JSON/LICENSE similarity index 100% rename from extlib/facebook/jsonwrapper/JSON/LICENSE rename to plugins/Facebook/facebook/jsonwrapper/JSON/LICENSE diff --git a/extlib/facebook/jsonwrapper/jsonwrapper.php b/plugins/Facebook/facebook/jsonwrapper/jsonwrapper.php similarity index 100% rename from extlib/facebook/jsonwrapper/jsonwrapper.php rename to plugins/Facebook/facebook/jsonwrapper/jsonwrapper.php diff --git a/extlib/facebook/jsonwrapper/jsonwrapper_inner.php b/plugins/Facebook/facebook/jsonwrapper/jsonwrapper_inner.php similarity index 100% rename from extlib/facebook/jsonwrapper/jsonwrapper_inner.php rename to plugins/Facebook/facebook/jsonwrapper/jsonwrapper_inner.php diff --git a/lib/facebookaction.php b/plugins/Facebook/facebookaction.php similarity index 94% rename from lib/facebookaction.php rename to plugins/Facebook/facebookaction.php index 3f3a8d3b09..f5ad3d06b4 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 - * @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 = '