From f841dd6af4a0367f5589fa2b18a0043c0133cdd2 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 20 May 2009 00:55:59 +0000 Subject: Fixed sporatic problem with logout. --- plugins/FBConnect/FBConnectPlugin.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php index 342a62492..191cede76 100644 --- a/plugins/FBConnect/FBConnectPlugin.php +++ b/plugins/FBConnect/FBConnectPlugin.php @@ -120,22 +120,28 @@ class FBConnectPlugin extends Plugin $apikey = common_config('facebook', 'apikey'); $plugin_path = common_path('plugins/FBConnect'); - $url = common_get_returnto(); + $login_url = common_get_returnto(); - if ($url) { + if ($login_url) { // We don't have to return to it again common_set_returnto(null); } else { $url = common_local_url('public'); } + + $logout_url = common_local_url('logout'); $html = sprintf('', $apikey, $plugin_path, $url); + ', $apikey, $plugin_path, $login_url, $logout_url); $action->raw($html); @@ -170,8 +176,8 @@ class FBConnectPlugin extends Plugin $text = _('Logout'); $html = sprintf('', - $logout_url, $title, $logout_url, $text); + 'onclick="FB.Connect.logout(function() { goto_logout() })">%s', + $logout_url, $title, $text); $action->raw($html); @@ -198,7 +204,7 @@ class FBConnectPlugin extends Plugin if (!$user) { $action->elementStart('li'); - $action->element('fb:login-button', array('onlogin' => 'refresh_page()', + $action->element('fb:login-button', array('onlogin' => 'goto_login()', 'length' => 'long')); $action->elementEnd('li'); } -- cgit v1.2.3-54-g00ecf From 8545a1c5fe65e056b4dd7fca5464cc927a43b38a Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 20 May 2009 06:46:11 +0000 Subject: Reorganized some stuff and made new Facebook Login tab --- plugins/FBConnect/FBCLoginGroupNav.php | 112 ++++++++++ plugins/FBConnect/FBConnectAuth.php | 370 +++++++++++++++++++++++++++++++++ plugins/FBConnect/FBConnectLogin.php | 358 +++---------------------------- plugins/FBConnect/FBConnectPlugin.php | 39 +++- 4 files changed, 544 insertions(+), 335 deletions(-) create mode 100644 plugins/FBConnect/FBCLoginGroupNav.php create mode 100644 plugins/FBConnect/FBConnectAuth.php diff --git a/plugins/FBConnect/FBCLoginGroupNav.php b/plugins/FBConnect/FBCLoginGroupNav.php new file mode 100644 index 000000000..9aa01a094 --- /dev/null +++ b/plugins/FBConnect/FBCLoginGroupNav.php @@ -0,0 +1,112 @@ +. + * + * @category Menu + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR . '/lib/widget.php'; + +/** + * Menu for login group of actions + * + * @category Output + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class FBCLoginGroupNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + common_debug('FBCLoginGroupNav'); + + $this->action->elementStart('dl', array('id' => 'site_nav_local_views')); + $this->action->element('dt', null, _('Local views')); + $this->action->elementStart('dd'); + + // action => array('prompt', 'title') + $menu = array(); + + $menu['login'] = array(_('Login'), + _('Login with a username and password')); + + if (!(common_config('site','closed') || common_config('site','inviteonly'))) { + $menu['register'] = array(_('Register'), + _('Sign up for a new account')); + } + + $menu['openidlogin'] = array(_('OpenID'), + _('Login or register with OpenID')); + + $menu['FBConnectLogin'] = array(_('Facebook'), + _('Login or register using Facebook')); + + $action_name = $this->action->trimmed('action'); + $this->action->elementStart('ul', array('class' => 'nav')); + + foreach ($menu as $menuaction => $menudesc) { + $this->action->menuItem(common_local_url($menuaction), + $menudesc[0], + $menudesc[1], + $action_name === $menuaction); + } + + $this->action->elementEnd('ul'); + + $this->action->elementEnd('dd'); + $this->action->elementEnd('dl'); + } +} diff --git a/plugins/FBConnect/FBConnectAuth.php b/plugins/FBConnect/FBConnectAuth.php new file mode 100644 index 000000000..0dc016c05 --- /dev/null +++ b/plugins/FBConnect/FBConnectAuth.php @@ -0,0 +1,370 @@ +. + * + * @category Plugin + * @package Laconica + * @author Zach Copley + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +require_once INSTALLDIR . '/plugins/FBConnect/FBConnectPlugin.php'; + +class FbconnectauthAction extends Action +{ + + var $fbuid = null; + var $fb_fields = null; + + function prepare($args) { + parent::prepare($args); + + $this->fbuid = getFacebook()->get_loggedin_user(); + $this->fb_fields = $this->getFacebookFields($this->fbuid, + array('first_name', 'last_name', 'name')); + + return true; + } + + function handle($args) + { + parent::handle($args); + + if (common_is_real_login()) { + $this->clientError(_('Already logged in.')); + } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. Try again, please.')); + return; + } + if ($this->arg('create')) { + if (!$this->boolean('license')) { + $this->showForm(_('You can\'t register if you don\'t agree to the license.'), + $this->trimmed('newname')); + return; + } + $this->createNewUser(); + } else if ($this->arg('connect')) { + $this->connectUser(); + } else { + common_debug(print_r($this->args, true), __FILE__); + $this->showForm(_('Something weird happened.'), + $this->trimmed('newname')); + } + } else { + $this->tryLogin(); + } + } + + function showPageNotice() + { + if ($this->error) { + $this->element('div', array('class' => 'error'), $this->error); + } else { + $this->element('div', 'instructions', + sprintf(_('This is the first time you\'ve logged into %s so we must connect your Facebook to a local account. You can either create a new account, or connect with your existing account, if you have one.'), common_config('site', 'name'))); + } + } + + function title() + { + return _('Facebook Account Setup'); + } + + function showForm($error=null, $username=null) + { + $this->error = $error; + $this->username = $username; + + $this->showPage(); + } + + function showPage() + { + parent::showPage(); + } + + function showContent() + { + if (!empty($this->message_text)) { + $this->element('p', null, $this->message); + return; + } + + $this->elementStart('form', array('method' => 'post', + 'id' => 'account_connect', + 'action' => common_local_url('fbconnectlogin'))); + $this->hidden('token', common_session_token()); + $this->element('h2', null, + _('Create new account')); + $this->element('p', null, + _('Create a new user with this nickname.')); + $this->input('newname', _('New nickname'), + ($this->username) ? $this->username : '', + _('1-64 lowercase letters or numbers, no punctuation or spaces')); + $this->elementStart('p'); + $this->element('input', array('type' => 'checkbox', + 'id' => 'license', + 'name' => 'license', + 'value' => 'true')); + $this->text(_('My text and files are available under ')); + $this->element('a', array('href' => common_config('license', 'url')), + common_config('license', 'title')); + $this->text(_(' except this private data: password, email address, IM address, phone number.')); + $this->elementEnd('p'); + $this->submit('create', _('Create')); + $this->element('h2', null, + _('Connect existing account')); + $this->element('p', null, + _('If you already have an account, login with your username and password to connect it to your Facebook.')); + $this->input('nickname', _('Existing nickname')); + $this->password('password', _('Password')); + $this->submit('connect', _('Connect')); + $this->elementEnd('form'); + } + + function message($msg) + { + $this->message_text = $msg; + $this->showPage(); + } + + function createNewUser() + { + + if (common_config('site', 'closed')) { + $this->clientError(_('Registration not allowed.')); + return; + } + + $invite = null; + + if (common_config('site', 'inviteonly')) { + $code = $_SESSION['invitecode']; + if (empty($code)) { + $this->clientError(_('Registration not allowed.')); + return; + } + + $invite = Invitation::staticGet($code); + + if (empty($invite)) { + $this->clientError(_('Not a valid invitation code.')); + return; + } + } + + $nickname = $this->trimmed('newname'); + + if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { + $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.')); + return; + } + + if (!User::allowed_nickname($nickname)) { + $this->showForm(_('Nickname not allowed.')); + return; + } + + if (User::staticGet('nickname', $nickname)) { + $this->showForm(_('Nickname already in use. Try another one.')); + return; + } + + $fullname = trim($this->fb_fields['firstname'] . + ' ' . $this->fb_fields['lastname']); + + $args = array('nickname' => $nickname, 'fullname' => $fullname); + + if (!empty($invite)) { + $args['code'] = $invite->code; + } + + $user = User::register($args); + + $result = $this->flinkUser($user->id, $this->fbuid); + + if (!$result) { + $this->serverError(_('Error connecting user to Facebook.')); + return; + } + + common_set_user($user); + common_real_login(true); + + common_debug("Registered new user $user->id from Facebook user $this->fbuid"); + + common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)), + 303); + } + + function connectUser() + { + $nickname = $this->trimmed('nickname'); + $password = $this->trimmed('password'); + + if (!common_check_user($nickname, $password)) { + $this->showForm(_('Invalid username or password.')); + return; + } + + $user = User::staticGet('nickname', $nickname); + + if ($user) { + common_debug("Legit user to connect to Facebook: $nickname"); + } + + $result = $this->flinkUser($user->id, $this->fbuid); + + if (!$result) { + $this->serverError(_('Error connecting user to Facebook.')); + return; + } + + common_debug("Connected Facebook user $this->fbuid to local user $user->id"); + + common_set_user($user); + common_real_login(true); + + $this->goHome($user->nickname); + } + + function tryLogin() + { + common_debug("Trying Facebook Login..."); + + $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); + + if ($flink) { + $user = $flink->getUser(); + + if ($user) { + + common_debug("Logged in Facebook user $flink->foreign_id as user $user->id ($user->nickname)"); + + common_set_user($user); + common_real_login(true); + $this->goHome($user->nickname); + } + + } else { + $this->showForm(null, $this->bestNewNickname()); + } + } + + function goHome($nickname) + { + $url = common_get_returnto(); + if ($url) { + // We don't have to return to it again + common_set_returnto(null); + } else { + $url = common_local_url('all', + array('nickname' => + $nickname)); + } + + common_redirect($url, 303); + } + + function flinkUser($user_id, $fbuid) + { + $flink = new Foreign_link(); + $flink->user_id = $user_id; + $flink->foreign_id = $fbuid; + $flink->service = FACEBOOK_SERVICE; + $flink->created = common_sql_now(); + + $flink_id = $flink->insert(); + + return $flink_id; + } + + function bestNewNickname() + { + if (!empty($this->fb_fields['name'])) { + $nickname = $this->nicknamize($this->fb_fields['name']); + if ($this->isNewNickname($nickname)) { + return $nickname; + } + } + + // Try the full name + + $fullname = trim($this->fb_fields['firstname'] . + ' ' . $this->fb_fields['lastname']); + + if (!empty($fullname)) { + $fullname = $this->nicknamize($fullname); + if ($this->isNewNickname($fullname)) { + return $fullname; + } + } + + return null; + } + + // Given a string, try to make it work as a nickname + + function nicknamize($str) + { + $str = preg_replace('/\W/', '', $str); + return strtolower($str); + } + + function isNewNickname($str) + { + if (!Validate::string($str, array('min_length' => 1, + 'max_length' => 64, + 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { + return false; + } + if (!User::allowed_nickname($str)) { + return false; + } + if (User::staticGet('nickname', $str)) { + return false; + } + return true; + } + + // XXX: Consider moving this to lib/facebookutil.php + function getFacebookFields($fb_uid, $fields) { + try { + $infos = getFacebook()->api_client->users_getInfo($fb_uid, $fields); + + if (empty($infos)) { + return null; + } + return reset($infos); + + } catch (Exception $e) { + error_log("Failure in the api when requesting " . join(",", $fields) + ." on uid " . $fb_uid . " : ". $e->getMessage()); + return null; + } + } + +} diff --git a/plugins/FBConnect/FBConnectLogin.php b/plugins/FBConnect/FBConnectLogin.php index c2a288571..70710eb70 100644 --- a/plugins/FBConnect/FBConnectLogin.php +++ b/plugins/FBConnect/FBConnectLogin.php @@ -1,12 +1,9 @@ . - * - * @category Plugin - * @package Laconica - * @author Zach Copley - * @copyright 2009 Control Yourself, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ */ -require_once INSTALLDIR . '/plugins/FBConnect/FBConnectLogin.php'; -require_once INSTALLDIR . '/lib/facebookutil.php'; - -class FBConnectloginAction extends Action -{ - - var $fbuid = null; - var $fb_fields = null; - - function prepare($args) { - parent::prepare($args); +if (!defined('LACONICA')) { + exit(1); +} - $this->fbuid = getFacebook()->get_loggedin_user(); - $this->fb_fields = $this->getFacebookFields($this->fbuid, - array('first_name', 'last_name', 'name')); - - return true; - } +require_once INSTALLDIR . '/plugins/FBConnect/FBConnectPlugin.php'; +class FBConnectLoginAction extends Action +{ function handle($args) { parent::handle($args); if (common_is_real_login()) { $this->clientError(_('Already logged in.')); - } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $token = $this->trimmed('token'); - if (!$token || $token != common_session_token()) { - $this->showForm(_('There was a problem with your session token. Try again, please.')); - return; - } - if ($this->arg('create')) { - if (!$this->boolean('license')) { - $this->showForm(_('You can\'t register if you don\'t agree to the license.'), - $this->trimmed('newname')); - return; - } - $this->createNewUser(); - } else if ($this->arg('connect')) { - $this->connectUser(); - } else { - common_debug(print_r($this->args, true), __FILE__); - $this->showForm(_('Something weird happened.'), - $this->trimmed('newname')); - } - } else { - $this->tryLogin(); - } - } - - function showPageNotice() - { - if ($this->error) { - $this->element('div', array('class' => 'error'), $this->error); - } else { - $this->element('div', 'instructions', - sprintf(_('This is the first time you\'ve logged into %s so we must connect your Facebook to a local account. You can either create a new account, or connect with your existing account, if you have one.'), common_config('site', 'name'))); - } - } - - function title() - { - return _('Facebook Account Setup'); - } - - function showForm($error=null, $username=null) - { - $this->error = $error; - $this->username = $username; - - $this->showPage(); - } - - function showPage() - { - parent::showPage(); - } - - function showContent() - { - if (!empty($this->message_text)) { - $this->element('p', null, $this->message); - return; - } - - $this->elementStart('form', array('method' => 'post', - 'id' => 'account_connect', - 'action' => common_local_url('fbconnectlogin'))); - $this->hidden('token', common_session_token()); - $this->element('h2', null, - _('Create new account')); - $this->element('p', null, - _('Create a new user with this nickname.')); - $this->input('newname', _('New nickname'), - ($this->username) ? $this->username : '', - _('1-64 lowercase letters or numbers, no punctuation or spaces')); - $this->elementStart('p'); - $this->element('input', array('type' => 'checkbox', - 'id' => 'license', - 'name' => 'license', - 'value' => 'true')); - $this->text(_('My text and files are available under ')); - $this->element('a', array('href' => common_config('license', 'url')), - common_config('license', 'title')); - $this->text(_(' except this private data: password, email address, IM address, phone number.')); - $this->elementEnd('p'); - $this->submit('create', _('Create')); - $this->element('h2', null, - _('Connect existing account')); - $this->element('p', null, - _('If you already have an account, login with your username and password to connect it to your Facebook.')); - $this->input('nickname', _('Existing nickname')); - $this->password('password', _('Password')); - $this->submit('connect', _('Connect')); - $this->elementEnd('form'); - } - - function message($msg) - { - $this->message_text = $msg; + } + $this->showPage(); } - function createNewUser() - { - - if (common_config('site', 'closed')) { - $this->clientError(_('Registration not allowed.')); - return; - } - - $invite = null; - - if (common_config('site', 'inviteonly')) { - $code = $_SESSION['invitecode']; - if (empty($code)) { - $this->clientError(_('Registration not allowed.')); - return; - } - - $invite = Invitation::staticGet($code); - - if (empty($invite)) { - $this->clientError(_('Not a valid invitation code.')); - return; - } - } - - $nickname = $this->trimmed('newname'); - - if (!Validate::string($nickname, array('min_length' => 1, - 'max_length' => 64, - 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { - $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.')); - return; - } - - if (!User::allowed_nickname($nickname)) { - $this->showForm(_('Nickname not allowed.')); - return; - } - - if (User::staticGet('nickname', $nickname)) { - $this->showForm(_('Nickname already in use. Try another one.')); - return; - } - - $fullname = trim($this->fb_fields['firstname'] . - ' ' . $this->fb_fields['lastname']); - - $args = array('nickname' => $nickname, 'fullname' => $fullname); - - if (!empty($invite)) { - $args['code'] = $invite->code; - } - - $user = User::register($args); - - $result = $this->flinkUser($user->id, $this->fbuid); - - if (!$result) { - $this->serverError(_('Error connecting user to Facebook.')); - return; - } - - common_set_user($user); - common_real_login(true); - - common_debug("Registered new user $user->id from Facebook user $this->fbuid"); - - common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)), - 303); - } - - function connectUser() - { - $nickname = $this->trimmed('nickname'); - $password = $this->trimmed('password'); - - if (!common_check_user($nickname, $password)) { - $this->showForm(_('Invalid username or password.')); - return; - } - - $user = User::staticGet('nickname', $nickname); - - if ($user) { - common_debug("Legit user to connect to Facebook: $nickname"); - } - - $result = $this->flinkUser($user->id, $this->fbuid); - - if (!$result) { - $this->serverError(_('Error connecting user to Facebook.')); - return; - } - - common_debug("Connected Facebook user $this->fbuid to local user $user->id"); - - common_set_user($user); - common_real_login(true); - - $this->goHome($user->nickname); - } - - function tryLogin() + function getInstructions() { - common_debug("Trying Facebook Login..."); - - $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); - - if ($flink) { - $user = $flink->getUser(); - - if ($user) { - - common_debug("Logged in Facebook user $flink->foreign_id as user $user->id ($user->nickname)"); - - common_set_user($user); - common_real_login(true); - $this->goHome($user->nickname); - } - - } else { - $this->showForm(null, $this->bestNewNickname()); - } + return _('Login with your Facebook Account'); } - function goHome($nickname) - { - $url = common_get_returnto(); - if ($url) { - // We don't have to return to it again - common_set_returnto(null); - } else { - $url = common_local_url('all', - array('nickname' => - $nickname)); - } - - common_redirect($url, 303); - } - - function flinkUser($user_id, $fbuid) + function showPageNotice() { - $flink = new Foreign_link(); - $flink->user_id = $user_id; - $flink->foreign_id = $fbuid; - $flink->service = FACEBOOK_SERVICE; - $flink->created = common_sql_now(); - - $flink_id = $flink->insert(); - - return $flink_id; + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); } - function bestNewNickname() + function title() { - if (!empty($this->fb_fields['name'])) { - $nickname = $this->nicknamize($this->fb_fields['name']); - if ($this->isNewNickname($nickname)) { - return $nickname; - } - } - - // Try the full name - - $fullname = trim($this->fb_fields['firstname'] . - ' ' . $this->fb_fields['lastname']); - - if (!empty($fullname)) { - $fullname = $this->nicknamize($fullname); - if ($this->isNewNickname($fullname)) { - return $fullname; - } - } - - return null; + return _('Facebook Login'); } - // Given a string, try to make it work as a nickname - - function nicknamize($str) - { - $str = preg_replace('/\W/', '', $str); - return strtolower($str); - } - - function isNewNickname($str) - { - if (!Validate::string($str, array('min_length' => 1, - 'max_length' => 64, - 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) { - return false; - } - if (!User::allowed_nickname($str)) { - return false; - } - if (User::staticGet('nickname', $str)) { - return false; - } - return true; - } + function showContent() { - // XXX: Consider moving this to lib/facebookutil.php - function getFacebookFields($fb_uid, $fields) { - try { - $infos = getFacebook()->api_client->users_getInfo($fb_uid, $fields); + $this->elementStart('fieldset'); + - if (empty($infos)) { - return null; - } - return reset($infos); + $this->element('fb:login-button', array('onlogin' => 'goto_login()', + 'length' => 'long')); - } catch (Exception $e) { - error_log("Failure in the api when requesting " . join(",", $fields) - ." on uid " . $fb_uid . " : ". $e->getMessage()); - return null; - } + $this->elementEnd('fieldset'); } } diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php index 191cede76..079270510 100644 --- a/plugins/FBConnect/FBConnectPlugin.php +++ b/plugins/FBConnect/FBConnectPlugin.php @@ -31,8 +31,10 @@ if (!defined('LACONICA')) { exit(1); } -require_once INSTALLDIR . '/plugins/FBConnect/FBConnectLogin.php'; require_once INSTALLDIR . '/lib/facebookutil.php'; +require_once INSTALLDIR . '/plugins/FBConnect/FBConnectAuth.php'; +require_once INSTALLDIR . '/plugins/FBConnect/FBConnectLogin.php'; +require_once INSTALLDIR . '/plugins/FBConnect/FBCLoginGroupNav.php'; /** * Plugin to enable Facebook Connect @@ -54,7 +56,11 @@ class FBConnectPlugin extends Plugin // Hook in new actions function onRouterInitialized(&$m) { - $m->connect('main/facebookconnect', array('action' => 'fbconnectlogin')); + + common_debug("onRouterIntialized()"); + + $m->connect('main/facebookconnect', array('action' => 'FBConnectAuth')); + $m->connect('main/facebooklogin', array('action' => 'FBConnectLogin')); } // Add in xmlns:fb @@ -67,8 +73,10 @@ class FBConnectPlugin extends Plugin $name = get_class($action); + common_debug("onStartShowHTML: action = $name"); + // Avoid a redirect loop - if (!in_array($name, array('FBConnectloginAction', 'ClientErrorAction'))) { + if (!in_array($name, array('FBConnectAuthAction', 'ClientErrorAction'))) { $this->checkFacebookUser($action); @@ -246,7 +254,7 @@ class FBConnectPlugin extends Plugin } else { common_debug("Facebook user is NOT logged in."); - common_redirect(common_local_url('fbconnectlogin'), 303); + common_redirect(common_local_url('FBConnectAuth'), 303); } } else { @@ -259,7 +267,28 @@ class FBConnectPlugin extends Plugin } } - + + function onStartShowLocalNavBlock($action) + { + $action_name = get_class($action); + + common_debug($action_name); + + $login_actions = array('LoginAction', 'RegisterAction', + 'OpenidloginAction', 'FacebookStart'); + + if (in_array($action_name, $login_actions)) { + + common_debug("LoginAction found!"); + + $nav = new FBCLoginGroupNav($action); + $nav->show(); + return false; + } + + return true; + + } } -- cgit v1.2.3-54-g00ecf From 1a5ef90ea0fbdfa01c47671980402d0264839f27 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 20 May 2009 22:08:08 +0000 Subject: Preserve order of imported Tweets --- scripts/twitterstatusfetcher.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php index 9dfadc760..a61ce1b0d 100755 --- a/scripts/twitterstatusfetcher.php +++ b/scripts/twitterstatusfetcher.php @@ -214,7 +214,8 @@ class TwitterStatusFetcher extends Daemon return; } - foreach ($timeline as $status) { + // Reverse to preserve order + foreach (array_reverse($timeline) as $status) { // Hacktastic: filter out stuff coming from this Laconica $source = mb_strtolower(common_config('integration', 'source')); -- cgit v1.2.3-54-g00ecf From b561962b59e8194e6622f87394e7b8565d78c182 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 20 May 2009 23:11:35 +0000 Subject: Color picker reset: Resetting form values will also dynamically update the page colors back to their original. --- actions/designsettings.php | 3 +- js/farbtastic/farbtastic.go.js | 108 ++++++++++++++++++++++------------------- 2 files changed, 61 insertions(+), 50 deletions(-) diff --git a/actions/designsettings.php b/actions/designsettings.php index a85b36a25..8a7c26104 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -141,7 +141,8 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementEnd('fieldset'); $this->submit('save', _('Save')); - $this->element('input', array('type' => 'reset', + $this->element('input', array('id' => 'settings_design_reset', + 'type' => 'reset', 'value' => 'Reset', 'class' => 'form_action-secondary')); diff --git a/js/farbtastic/farbtastic.go.js b/js/farbtastic/farbtastic.go.js index e298c1dab..6a0a5c56b 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/farbtastic/farbtastic.go.js @@ -1,29 +1,22 @@ $(document).ready(function() { - function UpdateColors(e) { - var S = f.linked; - var C = f.color; - - if (S && S.value && S.value != C) { - UpdateSwatch(S); - - switch (parseInt(f.linked.id.slice(-1))) { - case 0: default: - $('body').css({'background-color':C}); - break; - case 1: - $('#content').css({'background-color':C}); - break; - case 2: - $('#aside_primary').css({'background-color':C}); - break; - case 3: - $('body').css({'color':C}); - break; - case 4: - $('a').css({'color':C}); - break; - } - S.value = C; + function UpdateColors(S) { + C = $(S).val(); + switch (parseInt(S.id.slice(-1))) { + case 0: default: + $('body').css({'background-color':C}); + break; + case 1: + $('#content').css({'background-color':C}); + break; + case 2: + $('#aside_primary').css({'background-color':C}); + break; + case 3: + $('body').css({'color':C}); + break; + case 4: + $('a').css({'color':C}); + break; } } @@ -33,35 +26,52 @@ $(document).ready(function() { } function UpdateSwatch(e) { - $(e).css({ - "background-color": e.value, - "color": f.hsl[2] > 0.5 ? "#000": "#fff" - }); + $(e).css({"background-color": e.value, + "color": f.hsl[2] > 0.5 ? "#000": "#fff"}); } - $('#settings_design_color').append('
'); - $('#color-picker').hide(); - - var f = $.farbtastic('#color-picker', UpdateColors); - var swatches = $('#settings_design_color .swatch'); - - swatches - .each(UpdateColors) + function SynchColors(e) { + var S = f.linked; + var C = f.color; - .blur(function() { - $(this).val($(this).val().toUpperCase()); - }) + if (S && S.value && S.value != C) { + S.value = C; + UpdateSwatch(S); + UpdateColors(S); + } + } - .focus(function() { - $('#color-picker').show(); - UpdateFarbtastic(this); - }) + function Init() { + $('#settings_design_color').append('
'); + $('#color-picker').hide(); - .change(function() { - UpdateFarbtastic(this); - UpdateSwatch(this); - }).change() + f = $.farbtastic('#color-picker', SynchColors); + swatches = $('#settings_design_color .swatch'); - ; + swatches + .each(SynchColors) + .blur(function() { + $(this).val($(this).val().toUpperCase()); + }) + .focus(function() { + $('#color-picker').show(); + UpdateFarbtastic(this); + }) + .change(function() { + UpdateFarbtastic(this); + UpdateSwatch(this); + UpdateColors(this); + }).change(); + } + var f, swatches; + Init(); + $('#form_settings_design').bind('reset', function(){ + setTimeout(function(){ + swatches.each(function(){UpdateColors(this);}); + $('#color-picker').remove(); + swatches.unbind(); + Init(); + },10); + }); }); -- cgit v1.2.3-54-g00ecf From b23d4230811db02266b9df0a3cefc5e54c36d169 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 20 May 2009 23:37:20 +0000 Subject: Added licensing information for jcrop.go and farbtastic.go scripts --- js/farbtastic/farbtastic.go.js | 8 +++++ js/jcrop/jquery.Jcrop.go.js | 77 +++++++++++++++++++++++------------------- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/js/farbtastic/farbtastic.go.js b/js/farbtastic/farbtastic.go.js index 6a0a5c56b..0149eca7d 100644 --- a/js/farbtastic/farbtastic.go.js +++ b/js/farbtastic/farbtastic.go.js @@ -1,3 +1,11 @@ +/** Init for Farbtastic library and page setup + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ $(document).ready(function() { function UpdateColors(S) { C = $(S).val(); diff --git a/js/jcrop/jquery.Jcrop.go.js b/js/jcrop/jquery.Jcrop.go.js index a0399d540..4e1cbfd1e 100644 --- a/js/jcrop/jquery.Jcrop.go.js +++ b/js/jcrop/jquery.Jcrop.go.js @@ -1,39 +1,48 @@ - $(function(){ - var x = ($('#avatar_crop_x').val()) ? $('#avatar_crop_x').val() : 0; - var y = ($('#avatar_crop_y').val()) ? $('#avatar_crop_y').val() : 0; - var w = ($('#avatar_crop_w').val()) ? $('#avatar_crop_w').val() : $("#avatar_original img").attr("width"); - var h = ($('#avatar_crop_h').val()) ? $('#avatar_crop_h').val() : $("#avatar_original img").attr("height"); +/** Init for Jcrop library and page setup + * + * @package Laconica + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ - jQuery("#avatar_original img").Jcrop({ - onChange: showPreview, - setSelect: [ x, y, w, h ], - onSelect: updateCoords, - aspectRatio: 1, - boxWidth: 480, - boxHeight: 480, - bgColor: '#000', - bgOpacity: .4 - }); - }); +$(function(){ + var x = ($('#avatar_crop_x').val()) ? $('#avatar_crop_x').val() : 0; + var y = ($('#avatar_crop_y').val()) ? $('#avatar_crop_y').val() : 0; + var w = ($('#avatar_crop_w').val()) ? $('#avatar_crop_w').val() : $("#avatar_original img").attr("width"); + var h = ($('#avatar_crop_h').val()) ? $('#avatar_crop_h').val() : $("#avatar_original img").attr("height"); - function showPreview(coords) { - var rx = 96 / coords.w; - var ry = 96 / coords.h; + jQuery("#avatar_original img").Jcrop({ + onChange: showPreview, + setSelect: [ x, y, w, h ], + onSelect: updateCoords, + aspectRatio: 1, + boxWidth: 480, + boxHeight: 480, + bgColor: '#000', + bgOpacity: .4 + }); +}); - var img_width = $("#avatar_original img").attr("width"); - var img_height = $("#avatar_original img").attr("height"); +function showPreview(coords) { + var rx = 96 / coords.w; + var ry = 96 / coords.h; - $('#avatar_preview img').css({ - width: Math.round(rx *img_width) + 'px', - height: Math.round(ry * img_height) + 'px', - marginLeft: '-' + Math.round(rx * coords.x) + 'px', - marginTop: '-' + Math.round(ry * coords.y) + 'px' - }); - }; + var img_width = $("#avatar_original img").attr("width"); + var img_height = $("#avatar_original img").attr("height"); - function updateCoords(c) { - $('#avatar_crop_x').val(c.x); - $('#avatar_crop_y').val(c.y); - $('#avatar_crop_w').val(c.w); - $('#avatar_crop_h').val(c.h); - }; + $('#avatar_preview img').css({ + width: Math.round(rx *img_width) + 'px', + height: Math.round(ry * img_height) + 'px', + marginLeft: '-' + Math.round(rx * coords.x) + 'px', + marginTop: '-' + Math.round(ry * coords.y) + 'px' + }); +}; + +function updateCoords(c) { + $('#avatar_crop_x').val(c.x); + $('#avatar_crop_y').val(c.y); + $('#avatar_crop_w').val(c.w); + $('#avatar_crop_h').val(c.h); +}; -- cgit v1.2.3-54-g00ecf From 56a8a255fff0037c29db09d4abf6631e9c45c730 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 21 May 2009 00:12:48 +0000 Subject: Changed No/Yes and Reset/Save locations. They are now a little more usable by first offering the option to undo and than do. --- actions/deletenotice.php | 4 ++-- actions/designsettings.php | 5 +++-- theme/base/css/display.css | 4 +++- theme/default/css/display.css | 4 ++-- theme/identica/css/display.css | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/actions/deletenotice.php b/actions/deletenotice.php index 6c350b33a..e733f9650 100644 --- a/actions/deletenotice.php +++ b/actions/deletenotice.php @@ -112,8 +112,8 @@ class DeletenoticeAction extends DeleteAction $this->hidden('token', common_session_token()); $this->hidden('notice', $this->trimmed('notice')); $this->element('p', null, _('Are you sure you want to delete this notice?')); - $this->submit('form_action-yes', _('Yes'), 'submit form_action-primary', 'yes'); - $this->submit('form_action-no', _('No'), 'submit form_action-secondary', 'no'); + $this->submit('form_action-no', _('No'), 'submit form_action-primary', 'no', _("Do not delete this notice")); + $this->submit('form_action-yes', _('Yes'), 'submit form_action-secondary', 'yes', _('Delete this notice')); $this->elementEnd('fieldset'); $this->elementEnd('form'); } diff --git a/actions/designsettings.php b/actions/designsettings.php index 8a7c26104..315e5a199 100644 --- a/actions/designsettings.php +++ b/actions/designsettings.php @@ -140,11 +140,12 @@ class DesignsettingsAction extends AccountSettingsAction $this->elementEnd('ul'); $this->elementEnd('fieldset'); - $this->submit('save', _('Save')); $this->element('input', array('id' => 'settings_design_reset', 'type' => 'reset', 'value' => 'Reset', - 'class' => 'form_action-secondary')); + 'class' => 'submit form_action-primary', + 'title' => _('Reset back to default'))); + $this->submit('save', _('Save'), 'submit form_action-secondary', 'save', _('Save design')); /*TODO: Check submitted form values: json_encode(form values) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 8bd0ae1c4..edec14163 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -198,9 +198,11 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } #form_search .submit { diff --git a/theme/default/css/display.css b/theme/default/css/display.css index e4b57ef49..fce2e7e29 100644 --- a/theme/default/css/display.css +++ b/theme/default/css/display.css @@ -33,7 +33,7 @@ border-color:#aaa; border-color:#C3D6DF; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -60,7 +60,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#002E6E; } diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css index 9d625848f..df114417e 100644 --- a/theme/identica/css/display.css +++ b/theme/identica/css/display.css @@ -33,7 +33,7 @@ border-color:#aaa; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -60,7 +60,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#002E6E; } -- cgit v1.2.3-54-g00ecf From 689dd9ee5f81e3e2472e92b10248fecd39638160 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 21 May 2009 00:18:11 +0000 Subject: Updated primary and secondary styles for biz, cloudy, h4ck3r, otalk, pigeonthoughts themes. --- theme/biz/css/base.css | 5 ++++- theme/biz/css/display.css | 4 ++-- theme/cloudy/css/display.css | 8 +++++--- theme/h4ck3r/css/base.css | 4 +++- theme/h4ck3r/css/display.css | 4 ++-- theme/otalk/css/base.css | 4 +++- theme/otalk/css/display.css | 4 ++-- theme/pigeonthoughts/css/base.css | 4 +++- theme/pigeonthoughts/css/display.css | 4 ++-- 9 files changed, 26 insertions(+), 15 deletions(-) diff --git a/theme/biz/css/base.css b/theme/biz/css/base.css index 22bbced08..0e37a6ee4 100644 --- a/theme/biz/css/base.css +++ b/theme/biz/css/base.css @@ -198,11 +198,14 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } + #form_search .submit { margin-left:11px; } diff --git a/theme/biz/css/display.css b/theme/biz/css/display.css index a7d360c53..14092d964 100644 --- a/theme/biz/css/display.css +++ b/theme/biz/css/display.css @@ -36,7 +36,7 @@ border-color:#aaa; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -65,7 +65,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#002E6E; } diff --git a/theme/cloudy/css/display.css b/theme/cloudy/css/display.css index e97889685..12f186a56 100644 --- a/theme/cloudy/css/display.css +++ b/theme/cloudy/css/display.css @@ -199,9 +199,11 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } #form_search .submit { @@ -1267,7 +1269,7 @@ border-color:#aaa; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -1296,7 +1298,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#0084B4; } diff --git a/theme/h4ck3r/css/base.css b/theme/h4ck3r/css/base.css index 5060bbb8b..41b3a77e6 100644 --- a/theme/h4ck3r/css/base.css +++ b/theme/h4ck3r/css/base.css @@ -189,9 +189,11 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } #form_search .submit { diff --git a/theme/h4ck3r/css/display.css b/theme/h4ck3r/css/display.css index c7631a8eb..31d49a58e 100644 --- a/theme/h4ck3r/css/display.css +++ b/theme/h4ck3r/css/display.css @@ -38,7 +38,7 @@ color:#ccc; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -65,7 +65,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#0f0; } diff --git a/theme/otalk/css/base.css b/theme/otalk/css/base.css index 32e8891d2..b39992570 100644 --- a/theme/otalk/css/base.css +++ b/theme/otalk/css/base.css @@ -198,9 +198,11 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } #form_search .submit { diff --git a/theme/otalk/css/display.css b/theme/otalk/css/display.css index 6c646791b..d2a4719a8 100644 --- a/theme/otalk/css/display.css +++ b/theme/otalk/css/display.css @@ -37,7 +37,7 @@ border-color:#aaa; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -64,7 +64,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#8F0000; } diff --git a/theme/pigeonthoughts/css/base.css b/theme/pigeonthoughts/css/base.css index 179719820..08427d3c8 100644 --- a/theme/pigeonthoughts/css/base.css +++ b/theme/pigeonthoughts/css/base.css @@ -199,9 +199,11 @@ padding:0 7px; } +.form_settings input.form_action-primary { +padding:0; +} .form_settings input.form_action-secondary { margin-left:29px; -padding:0; } #form_search .submit { diff --git a/theme/pigeonthoughts/css/display.css b/theme/pigeonthoughts/css/display.css index 19341ef7f..af31cf78d 100644 --- a/theme/pigeonthoughts/css/display.css +++ b/theme/pigeonthoughts/css/display.css @@ -36,7 +36,7 @@ border-color:#aaa; border-color:#ddd; } -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { background:none; } @@ -63,7 +63,7 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-secondary { +.form_settings input.form_action-primary { color:#000; } -- cgit v1.2.3-54-g00ecf From 54cd0a2046c417fd072bb4cf79aeda163cf760af Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 21 May 2009 05:43:11 +0000 Subject: - Reworked login / logout workflow - Added Facebook Connect tab to login nav - Show Facebook mini-avatar when logged in - Added Facebook Connect tab to connect settings nav - Option to disconnect from Facebook --- db/foreign_services.sql | 3 +- plugins/FBConnect/FBCSettingsNav.php | 113 ++++++++++++++++++++ plugins/FBConnect/FBConnectAuth.php | 31 ++++-- plugins/FBConnect/FBConnectLogin.php | 10 +- plugins/FBConnect/FBConnectPlugin.php | 179 +++++++++++-------------------- plugins/FBConnect/FBConnectSettings.php | 184 ++++++++++++++++++++++++++++++++ 6 files changed, 393 insertions(+), 127 deletions(-) create mode 100644 plugins/FBConnect/FBCSettingsNav.php create mode 100644 plugins/FBConnect/FBConnectSettings.php diff --git a/db/foreign_services.sql b/db/foreign_services.sql index 557ede024..79c04cee5 100644 --- a/db/foreign_services.sql +++ b/db/foreign_services.sql @@ -2,4 +2,5 @@ insert into foreign_service (id, name, description, created) values ('1','Twitter', 'Twitter Micro-blogging service', now()), - ('2','Facebook', 'Facebook', now()); + ('2','Facebook', 'Facebook', now()), + ('3','FacebookConnect', 'Facebook Connect', now()); diff --git a/plugins/FBConnect/FBCSettingsNav.php b/plugins/FBConnect/FBCSettingsNav.php new file mode 100644 index 000000000..8b8411853 --- /dev/null +++ b/plugins/FBConnect/FBCSettingsNav.php @@ -0,0 +1,113 @@ +. + * + * @category Menu + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR . '/lib/widget.php'; + +/** + * A widget for showing the connect group local nav menu + * + * @category Output + * @package Laconica + * @author Evan Prodromou + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class FBCSettingsNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + + $this->action->elementStart('dl', array('id' => 'site_nav_local_views')); + $this->action->element('dt', null, _('Local views')); + $this->action->elementStart('dd'); + + # action => array('prompt', 'title') + $menu = + array('imsettings' => + array(_('IM'), + _('Updates by instant messenger (IM)')), + 'smssettings' => + array(_('SMS'), + _('Updates by SMS')), + 'twittersettings' => + array(_('Twitter'), + _('Twitter integration options')), + 'FBConnectSettings' => + array(_('Facebook'), + _('Facebook Connect settings'))); + + $action_name = $this->action->trimmed('action'); + $this->action->elementStart('ul', array('class' => 'nav')); + + foreach ($menu as $menuaction => $menudesc) { + if ($menuaction == 'imsettings' && + !common_config('xmpp', 'enabled')) { + continue; + } + $this->action->menuItem(common_local_url($menuaction), + $menudesc[0], + $menudesc[1], + $action_name === $menuaction); + } + + $this->action->elementEnd('ul'); + + $this->action->elementEnd('dd'); + $this->action->elementEnd('dl'); + } +} diff --git a/plugins/FBConnect/FBConnectAuth.php b/plugins/FBConnect/FBConnectAuth.php index 0dc016c05..e8724cdf9 100644 --- a/plugins/FBConnect/FBConnectAuth.php +++ b/plugins/FBConnect/FBConnectAuth.php @@ -29,7 +29,7 @@ require_once INSTALLDIR . '/plugins/FBConnect/FBConnectPlugin.php'; -class FbconnectauthAction extends Action +class FBConnectauthAction extends Action { var $fbuid = null; @@ -38,9 +38,20 @@ class FbconnectauthAction extends Action function prepare($args) { parent::prepare($args); - $this->fbuid = getFacebook()->get_loggedin_user(); - $this->fb_fields = $this->getFacebookFields($this->fbuid, - array('first_name', 'last_name', 'name')); + try { + + $this->fbuid = getFacebook()->get_loggedin_user(); + + if ($this->fbuid > 0) { + $this->fb_fields = $this->getFacebookFields($this->fbuid, + array('first_name', 'last_name', 'name')); + } else { + common_debug("No Facebook User found."); + } + + } catch (Exception $e) { + common_debug("Problem getting fbuid."); + } return true; } @@ -52,6 +63,7 @@ class FbconnectauthAction extends Action if (common_is_real_login()) { $this->clientError(_('Already logged in.')); } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->showForm(_('There was a problem with your session token. Try again, please.')); @@ -113,7 +125,7 @@ class FbconnectauthAction extends Action $this->elementStart('form', array('method' => 'post', 'id' => 'account_connect', - 'action' => common_local_url('fbconnectlogin'))); + 'action' => common_local_url('FBConnectAuth'))); $this->hidden('token', common_session_token()); $this->element('h2', null, _('Create new account')); @@ -255,7 +267,7 @@ class FbconnectauthAction extends Action { common_debug("Trying Facebook Login..."); - $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); + $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_CONNECT_SERVICE); if ($flink) { $user = $flink->getUser(); @@ -270,6 +282,9 @@ class FbconnectauthAction extends Action } } else { + + common_debug("no flink found for fbuid: $this->fbuid"); + $this->showForm(null, $this->bestNewNickname()); } } @@ -291,10 +306,12 @@ class FbconnectauthAction extends Action function flinkUser($user_id, $fbuid) { + common_debug("flinkUser()"); + $flink = new Foreign_link(); $flink->user_id = $user_id; $flink->foreign_id = $fbuid; - $flink->service = FACEBOOK_SERVICE; + $flink->service = FACEBOOK_CONNECT_SERVICE; $flink->created = common_sql_now(); $flink_id = $flink->insert(); diff --git a/plugins/FBConnect/FBConnectLogin.php b/plugins/FBConnect/FBConnectLogin.php index 70710eb70..7989dc854 100644 --- a/plugins/FBConnect/FBConnectLogin.php +++ b/plugins/FBConnect/FBConnectLogin.php @@ -17,8 +17,8 @@ * along with this program. If not, see . */ -if (!defined('LACONICA')) { - exit(1); +if (!defined('LACONICA')) { + exit(1); } require_once INSTALLDIR . '/plugins/FBConnect/FBConnectPlugin.php'; @@ -31,8 +31,8 @@ class FBConnectLoginAction extends Action if (common_is_real_login()) { $this->clientError(_('Already logged in.')); - } - + } + $this->showPage(); } @@ -58,7 +58,7 @@ class FBConnectLoginAction extends Action function showContent() { $this->elementStart('fieldset'); - + $this->element('fb:login-button', array('onlogin' => 'goto_login()', 'length' => 'long')); diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php index 079270510..36dee0448 100644 --- a/plugins/FBConnect/FBConnectPlugin.php +++ b/plugins/FBConnect/FBConnectPlugin.php @@ -31,10 +31,15 @@ if (!defined('LACONICA')) { exit(1); } +define("FACEBOOK_CONNECT_SERVICE", 3); + require_once INSTALLDIR . '/lib/facebookutil.php'; require_once INSTALLDIR . '/plugins/FBConnect/FBConnectAuth.php'; require_once INSTALLDIR . '/plugins/FBConnect/FBConnectLogin.php'; +require_once INSTALLDIR . '/plugins/FBConnect/FBConnectSettings.php'; require_once INSTALLDIR . '/plugins/FBConnect/FBCLoginGroupNav.php'; +require_once INSTALLDIR . '/plugins/FBConnect/FBCSettingsNav.php'; + /** * Plugin to enable Facebook Connect @@ -56,32 +61,14 @@ class FBConnectPlugin extends Plugin // Hook in new actions function onRouterInitialized(&$m) { - - common_debug("onRouterIntialized()"); - $m->connect('main/facebookconnect', array('action' => 'FBConnectAuth')); $m->connect('main/facebooklogin', array('action' => 'FBConnectLogin')); + $m->connect('settings/facebook', array('action' => 'FBConnectSettings')); } // Add in xmlns:fb function onStartShowHTML($action) { - - // XXX: This is probably a bad place to do general processing - // so maybe I need to make some new events? Maybe in - // Action::prepare? - - $name = get_class($action); - - common_debug("onStartShowHTML: action = $name"); - - // Avoid a redirect loop - if (!in_array($name, array('FBConnectAuthAction', 'ClientErrorAction'))) { - - $this->checkFacebookUser($action); - - } - $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; @@ -128,15 +115,7 @@ class FBConnectPlugin extends Plugin $apikey = common_config('facebook', 'apikey'); $plugin_path = common_path('plugins/FBConnect'); - $login_url = common_get_returnto(); - - if ($login_url) { - // We don't have to return to it again - common_set_returnto(null); - } else { - $url = common_local_url('public'); - } - + $login_url = common_local_url('FBConnectAuth'); $logout_url = common_local_url('logout'); $html = sprintf('