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:%d", $id));
+
+ $c = Cache::instance();
+
+ if ($c) {
+ $obj = $c->get($key);
+ if ($obj) {
+ return $obj;
+ }
+ }
+
+ $url = sprintf("https://graph.facebook.com/%s", $id);
+ $client = new HTTP_Client();
+ $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
*