X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FFBConnect%2FFBConnectPlugin.php;h=0dacf90122dcfa8653337a98324f1d73d2aee7f3;hb=9cdd77625e25e7c506121d42b28c1ec870c2d4e4;hp=cd6e9cecfbdfb5bf667d9e30a24f9207a723b074;hpb=4405648afb3417baa1cf3808fb91cf979a76b553;p=quix0rs-gnu-social.git diff --git a/plugins/FBConnect/FBConnectPlugin.php b/plugins/FBConnect/FBConnectPlugin.php index cd6e9cecfb..0dacf90122 100644 --- a/plugins/FBConnect/FBConnectPlugin.php +++ b/plugins/FBConnect/FBConnectPlugin.php @@ -1,6 +1,6 @@ . * * @category Plugin - * @package Laconica - * @author Zach Copley - * @copyright 2009 Control Yourself, Inc. + * @package StatusNet + * @author Zach Copley + * @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://laconi.ca/ + * @link http://status.net/ */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } @@ -45,10 +45,10 @@ require_once INSTALLDIR . '/plugins/FBConnect/FBC_XDReceiver.php'; * Plugin to enable Facebook Connect * * @category Plugin - * @package Laconica - * @author Zach Copley + * @package StatusNet + * @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/ + * @link http://status.net/ */ class FBConnectPlugin extends Plugin @@ -70,7 +70,7 @@ class FBConnectPlugin extends Plugin function onStartShowHTML($action) { - if ($this->requiresFB($action)) { + if ($this->reqFbScripts($action)) { // XXX: Horrible hack to make Safari, FF2, and Chrome work with // Facebook Connect. These browser cannot use Facebook's @@ -82,9 +82,7 @@ class FBConnectPlugin extends Plugin $action->extraHeaders(); - $action->startXML('html', - '-//W3C//DTD XHTML 1.0 Strict//EN', - 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); + $action->startXML('html'); $language = $action->getLanguage(); @@ -104,9 +102,9 @@ class FBConnectPlugin extends Plugin // Note: this script needs to appear in the - function onStartShowHeader($action) + function onEndShowScripts($action) { - if ($this->requiresFB($action)) { + if ($this->reqFbScripts($action)) { $apikey = common_config('facebook', 'apikey'); $plugin_path = common_path('plugins/FBConnect'); @@ -117,26 +115,48 @@ class FBConnectPlugin extends Plugin // XXX: Facebook says we don't need this FB_RequireFeatures(), // but we actually do, for IE and Safari. Gar. - $html = sprintf('', $apikey, - $login_url, $logout_url); - - $action->raw($html); + $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 } } @@ -145,23 +165,15 @@ class FBConnectPlugin extends Plugin function onEndShowFooter($action) { - if ($this->requiresFB($action)) { - - $action->element('script', - array('type' => 'text/javascript', - 'src' => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php'), - ''); + if ($this->reqFbScripts($action)) { + $action->script('http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php'); } } - function onEndShowLaconicaStyles($action) + function onEndShowStatusNetStyles($action) { - - if ($this->requiresFB($action)) { - - $action->element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => common_path('plugins/FBConnect/FBConnectPlugin.css'))); + if ($this->reqFbScripts($action)) { + $action->cssLink('plugins/FBConnect/FBConnectPlugin.css'); } } @@ -175,7 +187,7 @@ class FBConnectPlugin extends Plugin * @return boolean true */ - function requiresFB($action) { + function reqFbScripts($action) { // If you're logged in w/FB Connect, you always need the FB stuff @@ -220,11 +232,11 @@ class FBConnectPlugin extends Plugin try { $facebook = getFacebook(); - $fbuid = getFacebook()->get_loggedin_user(); + $fbuid = $facebook->get_loggedin_user(); } catch (Exception $e) { - common_log(LOG_WARNING, - 'Problem getting Facebook client: ' . + common_log(LOG_WARNING, 'Facebook Connect Plugin - ' . + 'Problem getting Facebook user: ' . $e->getMessage()); } @@ -241,6 +253,14 @@ class FBConnectPlugin extends Plugin { $user = common_current_user(); + $connect = 'FBConnectSettings'; + if (common_config('xmpp', 'enabled')) { + $connect = 'imsettings'; + } else if (common_config('sms', 'enabled')) { + $connect = 'smssettings'; + } else if (common_config('twitter', 'enabled')) { + $connect = 'twittersettings'; + } if (!empty($user)) { @@ -248,77 +268,36 @@ class FBConnectPlugin extends Plugin if (!empty($fbuid)) { - $action->elementStart('li', array('id' => 'nav_fb')); - $action->elementStart('fb:profile-pic', array('uid' => $fbuid, - 'linked' => 'false', - 'width' => 16, - 'height' => 16)); - $action->elementEnd('fb:profile-pic'); + /* Default FB silhouette pic for FB users who haven't + uploaded a profile pic yet. */ - $iconurl = common_path('/plugins/FBConnect/fbfavicon.ico'); - $action->element('img', array('src' => $iconurl)); + $silhouetteUrl = + 'http://static.ak.fbcdn.net/pics/q_silhouette.gif'; - $action->elementEnd('li'); + $url = $this->getProfilePicURL($fbuid); - } + $action->elementStart('li', array('id' => 'nav_fb')); - $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'); - if (common_config('xmpp', 'enabled')) { - $action->menuItem(common_local_url('imsettings'), - _('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect'); - } else { - $action->menuItem(common_local_url('smssettings'), - _('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect'); - } - $action->menuItem(common_local_url('invite'), - _('Invite'), - sprintf(_('Invite friends and colleagues to join you on %s'), - common_config('site', 'name')), - false, 'nav_invitecontact'); + $action->element('img', array('id' => 'fbc_profile-pic', + 'src' => (!empty($url)) ? $url : $silhouetteUrl, + 'alt' => 'Facebook Connect User', + 'width' => '16'), ''); - // Need to override the Logout link to make it do FB stuff - if (!empty($fbuid)) { + $iconurl = common_path('plugins/FBConnect/fbfavicon.ico'); + $action->element('img', array('id' => 'fb_favicon', + 'src' => $iconurl)); - $logout_url = common_local_url('logout'); - $title = _('Logout from the site'); - $text = _('Logout'); - - $html = sprintf('', - $logout_url, $title, $text); - - $action->raw($html); - - } else { - $action->menuItem(common_local_url('logout'), - _('Logout'), _('Logout from the site'), false, 'nav_logout'); - } - } - else { - if (!common_config('site', 'closed')) { - $action->menuItem(common_local_url('register'), - _('Register'), _('Create an account'), false, 'nav_register'); - } - $action->menuItem(common_local_url('openidlogin'), - _('OpenID'), _('Login with OpenID'), false, 'nav_openid'); - $action->menuItem(common_local_url('login'), - _('Login'), _('Login to the site'), false, 'nav_login'); - } - - $action->menuItem(common_local_url('doc', array('title' => 'help')), - _('Help'), _('Help me!'), false, 'nav_help'); - $action->menuItem(common_local_url('peoplesearch'), - _('Search'), _('Search for people or text'), false, 'nav_search'); + $action->elementEnd('li'); - return false; + } + } + + return true; } function onStartShowLocalNavBlock($action) { - $action_name = get_class($action); + $action_name = get_class($action); $login_actions = array('LoginAction', 'RegisterAction', 'OpenidloginAction', 'FBConnectLoginAction'); @@ -351,12 +330,38 @@ class FBConnectPlugin extends Plugin $facebook = getFacebook(); $facebook->expire_session(); } catch (Exception $e) { - common_log(LOG_WARNING, 'Could\'t logout of Facebook: ' . - $e->getMessage()); + common_log(LOG_WARNING, 'Facebook Connect Plugin - ' . + 'Could\'t logout of Facebook: ' . + $e->getMessage()); } } return true; } + function getProfilePicURL($fbuid) + { + + $facebook = getFacebook(); + $url = null; + + try { + + $fqry = 'SELECT pic_square FROM user WHERE uid = %s'; + + $result = $facebook->api_client->fql_query(sprintf($fqry, $fbuid)); + + if (!empty($result)) { + $url = $result[0]['pic_square']; + } + + } catch (Exception $e) { + common_log(LOG_WARNING, 'Facebook Connect Plugin - ' . + "Facebook client failure requesting profile pic!"); + } + + return $url; + + } + }