X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FFacebookBridge%2FFacebookBridgePlugin.php;h=07a149785cf5db86aa1909dd0ad9af8def2c3c5f;hb=3ad3535cd8d12787d1af95969b9576620abce4a9;hp=62ae3813311fea419c2b2efdf1a3408c2c198a7e;hpb=d594c83a5a9a9d42fce917b544c28591fcadb1aa;p=quix0rs-gnu-social.git diff --git a/plugins/FacebookBridge/FacebookBridgePlugin.php b/plugins/FacebookBridge/FacebookBridgePlugin.php index 62ae381331..07a149785c 100644 --- a/plugins/FacebookBridge/FacebookBridgePlugin.php +++ b/plugins/FacebookBridge/FacebookBridgePlugin.php @@ -1,7 +1,7 @@ . * - * @category Pugin + * @category Plugin * @package StatusNet * @author Zach Copley * @copyright 2011 StatusNet, Inc. @@ -41,7 +41,7 @@ define("FACEBOOK_SERVICE", 2); * @category Plugin * @package StatusNet * @author Zach Copley - * @copyright 2010 StatusNet, Inc. + * @copyright 2010-2011 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ @@ -103,11 +103,10 @@ class FacebookBridgePlugin extends Plugin { $dir = dirname(__FILE__); - //common_debug("class = " . $cls); - switch ($cls) { case 'Facebook': // Facebook PHP SDK + include_once $dir . '/extlib/base_facebook.php'; include_once $dir . '/extlib/facebook.php'; return false; case 'FacebookloginAction': @@ -351,26 +350,35 @@ class FacebookBridgePlugin extends Plugin $action->script('https://connect.facebook.net/en_US/all.js'); $script = <<inlineScript( - sprintf($script, + sprintf( + $script, json_encode($this->facebook->getAppId()), - json_encode($this->facebook->getSession()), common_local_url('facebookfinishlogin') ) ); @@ -382,26 +390,30 @@ ENDOFSCRIPT; * * @param Action action the current action */ - function onEndLogout($action) + function onStartLogout($action) { if ($this->hasApplication()) { - $session = $this->facebook->getSession(); - $fbuser = null; - $fbuid = null; - - if ($session) { - try { - $fbuid = $this->facebook->getUser(); - $fbuser = $this->facebook->api('/me'); - } catch (FacebookApiException $e) { - common_log(LOG_ERROR, $e, __FILE__); - } - } - if (!empty($fbuser)) { + $cur = common_current_user(); + $flink = Foreign_link::getByUserID($cur->id, FACEBOOK_SERVICE); + + if (!empty($flink)) { + + $this->facebook->setAccessToken($flink->credentials); + + if (common_config('singleuser', 'enabled')) { + $user = User::singleUser(); + + $destination = common_local_url( + 'showstream', + array('nickname' => $user->nickname) + ); + } else { + $destination = common_local_url('public'); + } $logoutUrl = $this->facebook->getLogoutUrl( - array('next' => common_local_url('public')) + array('next' => $destination) ); common_log( @@ -412,9 +424,14 @@ ENDOFSCRIPT; ), __FILE__ ); - common_debug("LOGOUT URL = $logoutUrl"); + + $action->logout(); + common_redirect($logoutUrl, 303); + return false; // probably never get here, but hey } + + return true; } } @@ -542,6 +559,69 @@ ENDOFSCRIPT; return true; } + /** + * Add links in the user's profile block to their Facebook profile URL. + * + * @param Profile $profile The profile being shown + * @param Array &$links Writeable array of arrays (href, text, image). + * + * @return boolean hook value (true) + */ + + function onOtherAccountProfiles($profile, &$links) + { + $fuser = null; + + $flink = Foreign_link::getByUserID($profile->id, FACEBOOK_SERVICE); + + if (!empty($flink)) { + + $fuser = $this->getFacebookUser($flink->foreign_id); + + if (!empty($fuser)) { + $links[] = array("href" => $fuser->link, + "text" => sprintf(_("%s on Facebook"), $fuser->name), + "image" => $this->path("images/f_logo.png")); + } + } + + return true; + } + + function getFacebookUser($id) { + + $key = Cache::key(sprintf("FacebookBridgePlugin:userdata:%s", $id)); + + $c = Cache::instance(); + + if ($c) { + $obj = $c->get($key); + if ($obj) { + return $obj; + } + } + + $url = sprintf("https://graph.facebook.com/%s", $id); + $client = new HTTPClient(); + $resp = $client->get($url); + + if (!$resp->isOK()) { + return null; + } + + $user = json_decode($resp->getBody()); + + if ($user->error) { + return null; + } + + if ($c) { + $c->set($key, $user); + } + + return $user; + } + /* * Add version info for this plugin *