Pass auth user into Atom feed generators (needed for outputting favorited status in statusnet:notice_info tag)

This commit is contained in:
Zach Copley 2010-05-27 13:49:23 -07:00
parent 3e9b356777
commit c5b61078e1
12 changed files with 30 additions and 15 deletions

View File

@ -150,7 +150,7 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
header('Content-Type: application/atom+xml; charset=utf-8'); header('Content-Type: application/atom+xml; charset=utf-8');
$atom = new AtomNoticeFeed(); $atom = new AtomNoticeFeed($this->auth_user);
$atom->setId($id); $atom->setId($id);
$atom->setTitle($title); $atom->setTitle($title);

View File

@ -152,7 +152,7 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction
header('Content-Type: application/atom+xml; charset=utf-8'); header('Content-Type: application/atom+xml; charset=utf-8');
$atom = new AtomNoticeFeed(); $atom = new AtomNoticeFeed($this->auth_user);
$atom->setId($id); $atom->setId($id);
$atom->setTitle($title); $atom->setTitle($title);

View File

@ -105,7 +105,7 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
function showTimeline() function showTimeline()
{ {
// We'll pull common formatting out of this for other formats // We'll pull common formatting out of this for other formats
$atom = new AtomGroupNoticeFeed($this->group); $atom = new AtomGroupNoticeFeed($this->group, $this->auth_user);
$self = $this->getSelfUri(); $self = $this->getSelfUri();

View File

@ -151,7 +151,7 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
header('Content-Type: application/atom+xml; charset=utf-8'); header('Content-Type: application/atom+xml; charset=utf-8');
$atom = new AtomNoticeFeed(); $atom = new AtomNoticeFeed($this->auth_user);
$atom->setId($id); $atom->setId($id);
$atom->setTitle($title); $atom->setTitle($title);

View File

@ -151,7 +151,7 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
header('Content-Type: application/atom+xml; charset=utf-8'); header('Content-Type: application/atom+xml; charset=utf-8');
$atom = new AtomNoticeFeed(); $atom = new AtomNoticeFeed($this->auth_user);
$atom->setId($id); $atom->setId($id);
$atom->setTitle($title); $atom->setTitle($title);

View File

@ -130,7 +130,7 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction
header('Content-Type: application/atom+xml; charset=utf-8'); header('Content-Type: application/atom+xml; charset=utf-8');
$atom = new AtomNoticeFeed(); $atom = new AtomNoticeFeed($this->auth_user);
$atom->setId($id); $atom->setId($id);
$atom->setTitle($title); $atom->setTitle($title);

View File

@ -117,7 +117,7 @@ class ApiTimelineRetweetsOfMeAction extends ApiAuthAction
header('Content-Type: application/atom+xml; charset=utf-8'); header('Content-Type: application/atom+xml; charset=utf-8');
$atom = new AtomNoticeFeed(); $atom = new AtomNoticeFeed($this->auth_user);
$atom->setId($id); $atom->setId($id);
$atom->setTitle($title); $atom->setTitle($title);

View File

@ -138,7 +138,7 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
header('Content-Type: application/atom+xml; charset=utf-8'); header('Content-Type: application/atom+xml; charset=utf-8');
$atom = new AtomNoticeFeed(); $atom = new AtomNoticeFeed($this->auth_user);
$atom->setId($id); $atom->setId($id);
$atom->setTitle($title); $atom->setTitle($title);

View File

@ -115,7 +115,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
// We'll use the shared params from the Atom stub // We'll use the shared params from the Atom stub
// for other feed types. // for other feed types.
$atom = new AtomUserNoticeFeed($this->user); $atom = new AtomUserNoticeFeed($this->user, $this->auth_user);
$link = common_local_url( $link = common_local_url(
'showstream', 'showstream',

View File

@ -50,12 +50,13 @@ class AtomGroupNoticeFeed extends AtomNoticeFeed
* Constructor * Constructor
* *
* @param Group $group the group for the feed * @param Group $group the group for the feed
* @param User $cur the current authenticated user, if any
* @param boolean $indent flag to turn indenting on or off * @param boolean $indent flag to turn indenting on or off
* *
* @return void * @return void
*/ */
function __construct($group, $indent = true) { function __construct($group, $cur = null, $indent = true) {
parent::__construct($indent); parent::__construct($cur, $indent);
$this->group = $group; $this->group = $group;
$title = sprintf(_("%s timeline"), $group->nickname); $title = sprintf(_("%s timeline"), $group->nickname);

View File

@ -44,9 +44,22 @@ if (!defined('STATUSNET'))
*/ */
class AtomNoticeFeed extends Atom10Feed class AtomNoticeFeed extends Atom10Feed
{ {
function __construct($indent = true) { var $cur;
/**
* Constructor - adds a bunch of XML namespaces we need in our
* notice-specific Atom feeds, and allows setting the current
* authenticated user (useful for API methods).
*
* @param User $cur the current authenticated user (optional)
* @param boolean $indent Whether to indent XML output
*
*/
function __construct($cur = null, $indent = true) {
parent::__construct($indent); parent::__construct($indent);
$this->cur = $cur;
// Feeds containing notice info use these namespaces // Feeds containing notice info use these namespaces
$this->addNamespace( $this->addNamespace(
@ -115,7 +128,7 @@ class AtomNoticeFeed extends Atom10Feed
$source = $this->showSource(); $source = $this->showSource();
$author = $this->showAuthor(); $author = $this->showAuthor();
$cur = common_current_user(); $cur = empty($this->cur) ? common_current_user() : $this->cur;
$this->addEntryRaw($notice->asAtomEntry(false, $source, $author, $cur)); $this->addEntryRaw($notice->asAtomEntry(false, $source, $author, $cur));
} }

View File

@ -50,13 +50,14 @@ class AtomUserNoticeFeed extends AtomNoticeFeed
* Constructor * Constructor
* *
* @param User $user the user for the feed * @param User $user the user for the feed
* @param User $cur the current authenticated user, if any
* @param boolean $indent flag to turn indenting on or off * @param boolean $indent flag to turn indenting on or off
* *
* @return void * @return void
*/ */
function __construct($user, $indent = true) { function __construct($user, $cur = null, $indent = true) {
parent::__construct($indent); parent::__construct($cur, $indent);
$this->user = $user; $this->user = $user;
if (!empty($user)) { if (!empty($user)) {
$profile = $user->getProfile(); $profile = $user->getProfile();