From 59e5958d3afa0a5613efbc1ed4546ce63946fe43 Mon Sep 17 00:00:00 2001 From: Hue Bastard Date: Tue, 8 Dec 2009 21:28:11 +1000 Subject: ticket 2055: added logos to Atom and RSS feeds --- actions/apitimelinefavorites.php | 6 ++++-- actions/apitimelinefriends.php | 6 ++++-- actions/apitimelinegroup.php | 7 +++++-- actions/apitimelinementions.php | 6 ++++-- actions/apitimelinepublic.php | 5 +++-- actions/apitimelinetag.php | 6 ++++-- actions/apitimelineuser.php | 6 ++++-- lib/api.php | 27 +++++++++++++++++++++------ 8 files changed, 49 insertions(+), 20 deletions(-) diff --git a/actions/apitimelinefavorites.php b/actions/apitimelinefavorites.php index f84d7b4cb..77e5cea1b 100644 --- a/actions/apitimelinefavorites.php +++ b/actions/apitimelinefavorites.php @@ -101,6 +101,7 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction function showTimeline() { $profile = $this->user->getProfile(); + $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); $sitename = common_config('site', 'name'); $title = sprintf( @@ -121,20 +122,21 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction $profile->getBestName(), $this->user->nickname ); + $logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE); switch($this->format) { case 'xml': $this->showXmlTimeline($this->notices); break; case 'rss': - $this->showRssTimeline($this->notices, $title, $link, $subtitle); + $this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $logo, null, $logo); break; case 'atom': $selfuri = common_root_url() . ltrim($_SERVER['QUERY_STRING'], 'p='); $this->showAtomTimeline( $this->notices, $title, $id, $link, $subtitle, - null, $selfuri + null, $selfuri, $logo ); break; case 'json': diff --git a/actions/apitimelinefriends.php b/actions/apitimelinefriends.php index e84f77372..09ba7a969 100644 --- a/actions/apitimelinefriends.php +++ b/actions/apitimelinefriends.php @@ -110,6 +110,7 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction function showTimeline() { $profile = $this->user->getProfile(); + $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); $sitename = common_config('site', 'name'); $title = sprintf(_("%s and friends"), $this->user->nickname); $taguribase = common_config('integration', 'taguri'); @@ -121,13 +122,14 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction _('Updates from %1$s and friends on %2$s!'), $this->user->nickname, $sitename ); + $logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE); switch($this->format) { case 'xml': $this->showXmlTimeline($this->notices); break; case 'rss': - $this->showRssTimeline($this->notices, $title, $link, $subtitle); + $this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $logo); break; case 'atom': @@ -144,7 +146,7 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction $this->showAtomTimeline( $this->notices, $title, $id, $link, - $subtitle, null, $selfuri + $subtitle, null, $selfuri, $logo ); break; case 'json': diff --git a/actions/apitimelinegroup.php b/actions/apitimelinegroup.php index de13e7eb9..22c577f39 100644 --- a/actions/apitimelinegroup.php +++ b/actions/apitimelinegroup.php @@ -105,6 +105,7 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction function showTimeline() { $sitename = common_config('site', 'name'); + $avatar = $this->group->homepage_logo; $title = sprintf(_("%s timeline"), $this->group->nickname); $taguribase = common_config('integration', 'taguri'); $id = "tag:$taguribase:GroupTimeline:" . $this->group->id; @@ -117,13 +118,14 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction $this->group->nickname, $sitename ); + $logo = ($avatar) ? $avatar : User_group::defaultLogo(AVATAR_PROFILE_SIZE); switch($this->format) { case 'xml': $this->showXmlTimeline($this->notices); break; case 'rss': - $this->showRssTimeline($this->notices, $title, $link, $subtitle); + $this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $logo); break; case 'atom': $selfuri = common_root_url() . @@ -136,7 +138,8 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction $link, $subtitle, null, - $selfuri + $selfuri, + $logo ); break; case 'json': diff --git a/actions/apitimelinementions.php b/actions/apitimelinementions.php index 0956ccdce..19f40aebc 100644 --- a/actions/apitimelinementions.php +++ b/actions/apitimelinementions.php @@ -110,6 +110,7 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction function showTimeline() { $profile = $this->user->getProfile(); + $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); $sitename = common_config('site', 'name'); $title = sprintf( @@ -126,20 +127,21 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction _('%1$s updates that reply to updates from %2$s / %3$s.'), $sitename, $this->user->nickname, $profile->getBestName() ); + $logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE); switch($this->format) { case 'xml': $this->showXmlTimeline($this->notices); break; case 'rss': - $this->showRssTimeline($this->notices, $title, $link, $subtitle); + $this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $logo); break; case 'atom': $selfuri = common_root_url() . ltrim($_SERVER['QUERY_STRING'], 'p='); $this->showAtomTimeline( $this->notices, $title, $id, $link, $subtitle, - null, $selfuri + null, $selfuri, $logo ); break; case 'json': diff --git a/actions/apitimelinepublic.php b/actions/apitimelinepublic.php index 7a8504259..633f3c36e 100644 --- a/actions/apitimelinepublic.php +++ b/actions/apitimelinepublic.php @@ -103,6 +103,7 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction function showTimeline() { $sitename = common_config('site', 'name'); + $sitelogo = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'); $title = sprintf(_("%s public timeline"), $sitename); $taguribase = common_config('integration', 'taguri'); $id = "tag:$taguribase:PublicTimeline"; @@ -114,13 +115,13 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction $this->showXmlTimeline($this->notices); break; case 'rss': - $this->showRssTimeline($this->notices, $title, $link, $subtitle); + $this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $sitelogo); break; case 'atom': $selfuri = common_root_url() . 'api/statuses/public_timeline.atom'; $this->showAtomTimeline( $this->notices, $title, $id, $link, - $subtitle, null, $selfuri + $subtitle, null, $selfuri, $sitelogo ); break; case 'json': diff --git a/actions/apitimelinetag.php b/actions/apitimelinetag.php index 452593c11..1a50520f4 100644 --- a/actions/apitimelinetag.php +++ b/actions/apitimelinetag.php @@ -98,6 +98,7 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction function showTimeline() { $sitename = common_config('site', 'name'); + $sitelogo = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'); $title = sprintf(_("Notices tagged with %s"), $this->tag); $link = common_local_url( 'tag', @@ -116,7 +117,7 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction $this->showXmlTimeline($this->notices); break; case 'rss': - $this->showRssTimeline($this->notices, $title, $link, $subtitle); + $this->showRssTimeline($this->notices, $title, $link, $subtitle, null, $sitelogo); break; case 'atom': $selfuri = common_root_url() . @@ -129,7 +130,8 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction $link, $subtitle, null, - $selfuri + $selfuri, + $sitelogo ); break; case 'json': diff --git a/actions/apitimelineuser.php b/actions/apitimelineuser.php index ca1d21772..14c62a52e 100644 --- a/actions/apitimelineuser.php +++ b/actions/apitimelineuser.php @@ -112,6 +112,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction function showTimeline() { $profile = $this->user->getProfile(); + $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); $sitename = common_config('site', 'name'); $title = sprintf(_("%s timeline"), $this->user->nickname); @@ -125,6 +126,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction _('Updates from %1$s on %2$s!'), $this->user->nickname, $sitename ); + $logo = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE); // FriendFeed's SUP protocol // Also added RSS and Atom feeds @@ -139,7 +141,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction case 'rss': $this->showRssTimeline( $this->notices, $title, $link, - $subtitle, $suplink + $subtitle, $suplink, $logo ); break; case 'atom': @@ -153,7 +155,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction } $this->showAtomTimeline( $this->notices, $title, $id, $link, - $subtitle, $suplink, $selfuri + $subtitle, $suplink, $selfuri, $logo ); break; case 'json': diff --git a/lib/api.php b/lib/api.php index eacb80dbe..7ebe65dbb 100644 --- a/lib/api.php +++ b/lib/api.php @@ -134,17 +134,19 @@ class ApiAction extends Action $twitter_user['protected'] = false; # not supported by StatusNet yet $twitter_user['followers_count'] = $profile->subscriberCount(); - $user = $profile->getUser(); $design = null; + $user = $profile->getUser(); // Note: some profiles don't have an associated user - $defaultDesign = Design::siteDesign(); - if (!empty($user)) { $design = $user->getDesign(); } + if (empty($design)) { + $design = Design::siteDesign(); + } + $color = Design::toWebColor(empty($design->backgroundcolor) ? $defaultDesign->backgroundcolor : $design->backgroundcolor); $twitter_user['profile_background_color'] = ($color == null) ? '' : '#'.$color->hexValue(); $color = Design::toWebColor(empty($design->textcolor) ? $defaultDesign->textcolor : $design->textcolor); @@ -163,7 +165,7 @@ class ApiAction extends Action $timezone = 'UTC'; - if (!empty($user) && !empty($user->timezone)) { + if ($user->timezone) { $timezone = $user->timezone; } @@ -586,7 +588,7 @@ class ApiAction extends Action $this->endDocument('xml'); } - function showRssTimeline($notice, $title, $link, $subtitle, $suplink=null) + function showRssTimeline($notice, $title, $link, $subtitle, $suplink=null, $logo=null) { $this->initDocument('rss'); @@ -600,6 +602,15 @@ class ApiAction extends Action 'href' => $suplink, 'type' => 'application/json')); } + + if (!is_null($logo)) { + $this->elementStart('image'); + $this->element('link', null, $link); + $this->element('title', null, $title); + $this->element('url', null, $logo); + $this->elementEnd('image'); + } + $this->element('description', null, $subtitle); $this->element('language', null, 'en-us'); $this->element('ttl', null, '40'); @@ -619,7 +630,7 @@ class ApiAction extends Action $this->endTwitterRss(); } - function showAtomTimeline($notice, $title, $id, $link, $subtitle=null, $suplink=null, $selfuri=null) + function showAtomTimeline($notice, $title, $id, $link, $subtitle=null, $suplink=null, $selfuri=null, $logo=null) { $this->initDocument('atom'); @@ -628,6 +639,10 @@ class ApiAction extends Action $this->element('id', null, $id); $this->element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), null); + if (!is_null($logo)) { + $this->element('logo',null,$logo); + } + if (!is_null($suplink)) { # For FriendFeed's SUP protocol $this->element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup', -- cgit v1.2.3-54-g00ecf