X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fatomnoticefeed.php;h=b7e1ed1b41c1178cb8b1ff1f44c4b670f3f06f19;hb=8b78e01d4c4b9512a7b74efa52fcaf37de0dc6f1;hp=d2bf2a416f3bb26be64e0857b2ae43970239d7cc;hpb=273c0e036347891570a02502715345f5bbb7b143;p=quix0rs-gnu-social.git diff --git a/lib/atomnoticefeed.php b/lib/atomnoticefeed.php index d2bf2a416f..b7e1ed1b41 100644 --- a/lib/atomnoticefeed.php +++ b/lib/atomnoticefeed.php @@ -44,9 +44,24 @@ if (!defined('STATUSNET')) */ class AtomNoticeFeed extends Atom10Feed { - function __construct($indent = true) { + var $cur; + protected $scoped=null; + + /** + * 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); + $this->cur = $cur ?: common_current_user(); + $this->scoped = !is_null($this->cur) ? $this->cur->getProfile() : null; + // Feeds containing notice info use these namespaces $this->addNamespace( @@ -64,6 +79,11 @@ class AtomNoticeFeed extends Atom10Feed 'http://activitystrea.ms/spec/1.0/' ); + $this->addNamespace( + 'media', + 'http://purl.org/syndication/atommedia' + ); + $this->addNamespace( 'poco', 'http://portablecontacts.net/spec/1.0' @@ -74,6 +94,11 @@ class AtomNoticeFeed extends Atom10Feed 'ostatus', 'http://ostatus.org/schema/1.0' ); + + $this->addNamespace( + 'statusnet', + 'http://status.net/schema/api/1/' + ); } /** @@ -88,10 +113,12 @@ class AtomNoticeFeed extends Atom10Feed foreach ($notices as $notice) { $this->addEntryFromNotice($notice); } - } else { + } elseif ($notices instanceof Notice) { while ($notices->fetch()) { $this->addEntryFromNotice($notices); } + } else { + throw new ServerException('addEntryFromNotices got neither an array nor a Notice object'); } } @@ -100,11 +127,26 @@ class AtomNoticeFeed extends Atom10Feed * * @param Notice $notice a Notice to add */ - function addEntryFromNotice($notice) + function addEntryFromNotice(Notice $notice) { - $this->addEntryRaw($notice->asAtomEntry()); - } + try { + $source = $this->showSource(); + $author = $this->showAuthor(); -} + $this->addEntryRaw($notice->asAtomEntry(false, $source, $author, $this->scoped)); + } catch (Exception $e) { + common_log(LOG_ERR, $e->getMessage()); + // we continue on exceptions + } + } + function showSource() + { + return true; + } + function showAuthor() + { + return true; + } +}