diff --git a/EVENTS.txt b/EVENTS.txt index 0c08a46478..49940e467f 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1450,3 +1450,9 @@ EndNoticeListPrefill: After pre-filling a list of notices with extra data - &$profiles: Profiles that were pre-filled - $avatarSize: The avatar size for the list +OtherAccountProfiles: Hook to add account profiles to a user account profile block +- $profile: the Profile being shown +- &$others: Modifiable array of profile info arrays. Each one has the following fields: + href: link to the profile + text: text for the profile + image: mini image for the profile diff --git a/lib/accountprofileblock.php b/lib/accountprofileblock.php index 4eca000c9e..f49c73aeab 100644 --- a/lib/accountprofileblock.php +++ b/lib/accountprofileblock.php @@ -94,6 +94,15 @@ class AccountProfileBlock extends ProfileBlock return $this->profile->bio; } + function otherProfiles() + { + $others = array(); + + Event::handle('OtherAccountProfiles', array($this->profile, &$others)); + + return $others; + } + function showTags() { $cur = common_current_user(); diff --git a/lib/defaultprofileblock.php b/lib/defaultprofileblock.php index b8af14ac21..78c7c4a118 100644 --- a/lib/defaultprofileblock.php +++ b/lib/defaultprofileblock.php @@ -86,4 +86,9 @@ class DefaultProfileBlock extends AccountProfileBlock { return null; } + + function otherProfiles() + { + return array(); + } } \ No newline at end of file diff --git a/lib/groupprofileblock.php b/lib/groupprofileblock.php index 58e553a4c2..87ec174dc6 100644 --- a/lib/groupprofileblock.php +++ b/lib/groupprofileblock.php @@ -85,6 +85,11 @@ class GroupProfileBlock extends ProfileBlock return $this->group->description; } + function otherProfiles() + { + return array(); + } + function showActions() { $cur = common_current_user(); diff --git a/lib/profileblock.php b/lib/profileblock.php index eb19a1a9aa..697ff8d340 100644 --- a/lib/profileblock.php +++ b/lib/profileblock.php @@ -61,6 +61,7 @@ abstract class ProfileBlock extends Widget $this->showName(); $this->showLocation(); $this->showHomepage(); + $this->showOtherProfiles(); $this->showDescription(); $this->showTags(); } @@ -133,6 +134,31 @@ abstract class ProfileBlock extends Widget } } + function showOtherProfiles() + { + $otherProfiles = $this->otherProfiles(); + + if (!empty($otherProfiles)) { + + $this->out->elementStart('ul', + array('class' => 'profile_block_otherprofile_list')); + + foreach ($otherProfiles as $otherProfile) { + $this->out->elementStart('li'); + $this->out->elementStart('a', + array('href' => $otherProfile['href'], + 'rel' => 'me', + 'class' => 'profile_block_otherprofile', + 'alt' => $otherProfile['text'])); + $this->out->element('img', + array('src' => $otherProfile['image'], + 'class' => 'profile_block_otherprofile_icon')); + $this->out->elementEnd('a'); + $this->out->elementEnd('li'); + } + } + } + function avatarSize() { return AVATAR_PROFILE_SIZE; diff --git a/plugins/FacebookBridge/FacebookBridgePlugin.php b/plugins/FacebookBridge/FacebookBridgePlugin.php index bf16da337d..289f219112 100644 --- a/plugins/FacebookBridge/FacebookBridgePlugin.php +++ b/plugins/FacebookBridge/FacebookBridgePlugin.php @@ -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 * diff --git a/plugins/FacebookBridge/images/f_logo.png b/plugins/FacebookBridge/images/f_logo.png new file mode 100644 index 0000000000..b54e21cadf Binary files /dev/null and b/plugins/FacebookBridge/images/f_logo.png differ diff --git a/plugins/OpenID/OpenIDPlugin.php b/plugins/OpenID/OpenIDPlugin.php index ed6d6534c0..d5c5c303c2 100644 --- a/plugins/OpenID/OpenIDPlugin.php +++ b/plugins/OpenID/OpenIDPlugin.php @@ -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; + } } diff --git a/plugins/OpenID/icons/openid-16x16.gif b/plugins/OpenID/icons/openid-16x16.gif new file mode 100644 index 0000000000..e2d8377db0 Binary files /dev/null and b/plugins/OpenID/icons/openid-16x16.gif differ diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index d733f71c56..25d8a423ca 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -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; + } } diff --git a/plugins/TwitterBridge/icons/twitter-bird-white-on-blue.png b/plugins/TwitterBridge/icons/twitter-bird-white-on-blue.png new file mode 100644 index 0000000000..2c42b0823e Binary files /dev/null and b/plugins/TwitterBridge/icons/twitter-bird-white-on-blue.png differ diff --git a/theme/base/css/display.css b/theme/base/css/display.css index d2d07c4cec..483aa15ff7 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -2549,6 +2549,11 @@ display:none; display:none; } +.profile_block_otherprofile_list li { + display: inline; + list-style-type: none; +} + /*end of @media screen, projection, tv*/