From 206c09068884f701d9dc295c851a1216c5839ff3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 9 Jul 2012 12:55:05 -0400 Subject: [PATCH] Squashed commit of the following: commit 7ef19ab918cc9805abb8d01e8220ae4ed63155d7 Author: Evan Prodromou 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 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 Date: Mon Jul 9 11:57:56 2012 -0400 OpenID shows other account links commit ef7357883dad9e34af2746e1c6a41ea826d7c992 Author: Evan Prodromou 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 Date: Mon Jul 9 11:15:18 2012 -0400 Better array access commit 49d47257efdcae2101b589a1f825872bdd70667c Author: Evan Prodromou 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). --- EVENTS.txt | 6 ++ lib/accountprofileblock.php | 9 +++ lib/defaultprofileblock.php | 5 ++ lib/groupprofileblock.php | 5 ++ lib/profileblock.php | 26 ++++++++ .../FacebookBridge/FacebookBridgePlugin.php | 63 ++++++++++++++++++ plugins/FacebookBridge/images/f_logo.png | Bin 0 -> 481 bytes plugins/OpenID/OpenIDPlugin.php | 26 ++++++++ plugins/OpenID/icons/openid-16x16.gif | Bin 0 -> 328 bytes plugins/TwitterBridge/TwitterBridgePlugin.php | 28 ++++++++ .../icons/twitter-bird-white-on-blue.png | Bin 0 -> 433 bytes theme/base/css/display.css | 5 ++ 12 files changed, 173 insertions(+) create mode 100644 plugins/FacebookBridge/images/f_logo.png create mode 100644 plugins/OpenID/icons/openid-16x16.gif create mode 100644 plugins/TwitterBridge/icons/twitter-bird-white-on-blue.png 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 0000000000000000000000000000000000000000..b54e21cadfa783b0c258d71328640ad813b587a8 GIT binary patch literal 481 zcmV<70UrK|P)Uq4o)@Q^;dz+fe9)`+-;PcyOoac1s+RgA>8)1PG;`jA8DSu`Mn`(6o%0i8 zL-RAw1_z42liJ6PA5kcBuiE>$sqxh}FY+|0G}bKLy39aCZJV84)HCM+ zG%xMxMI#JMezAul-E0p)UnF$r-b|Di12M%o5HSGSom7Z0`s7hxD0ji4NB|6!3ln3* zV%T~A>o^frWSO_@ZW}<=db#x1 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..e2d8377db023a3915cc9e8c2f1f5c7462622f0a1 GIT binary patch literal 328 zcmZ?wbhEHb6krfwxXQrr>({UQ_wR4qxN*;(J#*&FS-N!TvSrKGuV4S?%F;i7{_Nbj z^V6qK`}XadJ9qBs)2Dx~3p;V*#MZ4_j~qF&aN)v#|Nb2~aNyvg9 ztXT2$=g%EGcI@80`{m1*Z{NOs{rdIFl`EeF4W-ruOthu2f ztl_Mdp@*QzZPDcui{^-N`o3xq@(UMrZh5FF-w`Y#$*8QNq^Zf+5a!Y$(d{Fk$;RMZ d?jf!z+?DC8mZr!$-G@O{mX$wbm9ry*H2@d`j5z=R literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..2c42b0823e1ad7f11567c60de6e1ddbdfe8600cd GIT binary patch literal 433 zcmV;i0Z#sjP)Y5S_W*csVav z9BM*9h*(&Og^i%Z*3LpJe}R>Sou!R}SctXw1H{fo3p=&2GLTvjf*3r#Q{-+h+1;@? z-F%7!oMIPd_RX93c5wRi5e5kh28=%d^c#SP%xMb6VK(71j^J`Md7fU8q?4tw&09Z3 z2&oU|M^{TOBGzMdS&I&q;s_)lzVPTK0ZpPZ08Cfa01&0HGA_^0| zR|(D@KC`^zb1~f|A{t`o+03&Ux4;)FNOUB1d+!bgL~LrP$Lcwf1b~2u(EGXtfHrgR bf4B7uTuzHLl#7Af00000NkvXXu0mjfFlet2 literal 0 HcmV?d00001 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*/