Squashed commit of the following:

commit 7ef19ab918cc9805abb8d01e8220ae4ed63155d7
Author: Evan Prodromou <evan@status.net>
Date:   Mon Jul 9 12:53:29 2012 -0400

    Show link to facebook account on profile block

    If you've logged in with Facebook, show a link to that account on the profile block.

commit b56967479c009d702150791944dbd80746ee3ba1
Author: Evan Prodromou <evan@status.net>
Date:   Mon Jul 9 12:28:34 2012 -0400

    Add profile link from profile block to Twitter account

    Add a profile link to Twitter for accounts that are linked via Twitter login.

commit 181e441fd03c6034e737f6a3dae115557aa3e1aa
Author: Evan Prodromou <evan@status.net>
Date:   Mon Jul 9 11:57:56 2012 -0400

    OpenID shows other account links

commit ef7357883dad9e34af2746e1c6a41ea826d7c992
Author: Evan Prodromou <evan@status.net>
Date:   Mon Jul 9 11:53:12 2012 -0400

    Add a profile link for OpenIDs

    OpenID plugin now adds a profile link for each OpenID on the account.

commit 093d26b95bc453686d24c42f5a8f4739cb338fd2
Author: Evan Prodromou <evan@status.net>
Date:   Mon Jul 9 11:15:18 2012 -0400

    Better array access

commit 49d47257efdcae2101b589a1f825872bdd70667c
Author: Evan Prodromou <evan@status.net>
Date:   Mon Jul 9 10:57:16 2012 -0400

    Show list of other accounts in profile block

    We add a group of "rel-me" links to other user accounts on the Web.

    This is mostly useful for when you've used OpenID, Twitter, or
    Facebook login to associate a remote account.

    There's an extension to the profileblock recipe to show the links as
    little icons; there's a new hook in accountprofileblock to get such
    links from plugins.

    There's a modification to the base theme to show the icons correctly
    (I think).
This commit is contained in:
Evan Prodromou
2012-07-09 12:55:05 -04:00
parent b4dbd23ed2
commit 206c090688
12 changed files with 173 additions and 0 deletions

View File

@@ -559,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:%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
*

Binary file not shown.

After

Width:  |  Height:  |  Size: 481 B

View File

@@ -814,4 +814,30 @@ class OpenIDPlugin extends Plugin
return true;
}
/**
* Add links in the user's profile block to their OpenID URLs.
*
* @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)
{
$oid = new User_openid();
$oid->user_id = $profile->id;
if ($oid->find()) {
while ($oid->fetch()) {
$links[] = array('href' => $oid->display,
'text' => _('OpenID'),
'image' => $this->path("icons/openid-16x16.gif"));
}
}
return true;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

View File

@@ -557,4 +557,32 @@ class TwitterBridgePlugin extends Plugin
}
return true;
}
/**
* Add links in the user's profile block to their Twitter 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, TWITTER_SERVICE);
if (!empty($flink)) {
$fuser = $flink->getForeignUser();
if (!empty($fuser)) {
$links[] = array("href" => $fuser->uri,
"text" => sprintf(_("@%s on Twitter"), $fuser->nickname),
"image" => $this->path("icons/twitter-bird-white-on-blue.png"));
}
}
return true;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B