From 3ef4f251acbe8ebdfd9d7f1ea43b7344b7332b73 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 22 Mar 2009 16:58:38 -0400 Subject: One function for producing Atom entry for a Notice Took the various places that we create an atom entry for a notice, and jammed them together into one function of the notice class, and then used that function. Also, added Atom threading extension and categories for hashtags. --- classes/Notice.php | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 3087e39a7..44a6aeb98 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -799,4 +799,98 @@ class Notice extends Memcached_DataObject } } } + + function asAtomEntry($namespace=false, $source=false) + { + $profile = $this->getProfile(); + + $xs = new XMLStringer(true); + + if ($namespace) { + $attrs = array('xmlns' => 'http://www.w3.org/2005/Atom', + 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0'); + } else { + $attrs = array(); + } + + $xs->elementStart('entry', $attrs); + + if ($source) { + $xs->elementStart('source'); + $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name')); + $xs->element('link', array('href' => $profile->profileurl)); + $user = User::staticGet('id', $profile->id); + if (!empty($user)) { + $atom_feed = common_local_url('api', + array('apiaction' => 'statuses', + 'method' => 'user_timeline', + 'argument' => $profile->nickname.'.atom')); + $xs->element('link', array('rel' => 'self', + 'type' => 'application/atom+xml', + 'href' => $profile->profileurl)); + $xs->element('link', array('rel' => 'license', + 'href' => common_config('license', 'url'))); + } + + $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE)); + } + + $xs->elementStart('author'); + $xs->element('name', null, $profile->nickname); + $xs->element('uri', null, $profile->profileurl); + $xs->elementEnd('author'); + + if ($source) { + $xs->elementEnd('source'); + } + + $xs->element('title', null, $this->content); + $xs->element('summary', null, $this->content); + + $xs->element('link', array('rel' => 'alternate', + 'href' => $this->bestUrl())); + + $xs->element('id', null, $this->uri); + + $xs->element('published', null, common_date_w3dtf($this->created)); + $xs->element('updated', null, common_date_w3dtf($this->modified)); + + if ($this->reply_to) { + $reply_notice = Notice::staticGet('id', $this->reply_to); + if (!empty($reply_notice)) { + $xs->element('link', array('rel' => 'related', + 'href' => $reply_notice->bestUrl())); + $xs->element('thr:in-reply-to', + array('ref' => $reply_notice->uri, + 'href' => $reply_notice->bestUrl())); + } + } + + $xs->element('content', array('type' => 'html'), $this->rendered); + + $tag = new Notice_tag(); + $tag->notice_id = $this->id; + if ($tag->find()) { + while ($tag->fetch()) { + $xs->element('category', array('term' => $tag->tag)); + } + } + $tag->free(); + + $xs->elementEnd('entry'); + + return $xs->getString(); + } + + function bestUrl() + { + if (!empty($this->url)) { + return $this->url; + } else if (!empty($this->uri) && preg_match('/^https?:/', $this->uri)) { + return $this->uri; + } else { + return common_local_url('shownotice', + array('notice' => $this->id)); + } + } } -- cgit v1.2.3-54-g00ecf