* @version SVN: $Id: sfAtom1Feed.class.php 2092 2008-11-18 19:28:41Z michal $ */ class sfAtom1Feed extends sfFeed { public function getFeed() { header('Content-Type: application/atom+xml'); $xml = array(); $xml[] = 'getEncoding().'" ?>'; if ($this->getLanguage()) { $xml[] = sprintf('', 'http://www.w3.org/2005/Atom', $this->getLanguage()); } else { $xml[] = sprintf('', 'http://www.w3.org/2005/Atom'); } $xml[] = ' '.$this->getTitle().''; $xml[] = ' '; if ($this->getFeedUrl()) { $xml[] = ' '; } $xml[] = ' '.sfContext::getInstance()->getController()->genUrl($this->getLink(), true).''; $xml[] = ' '.strftime('%Y-%m-%dT%H:%M:%SZ', $this->getLatestPostDate()).''; if ($this->getAuthorName()) { $xml[] = ' '; $xml[] = ' '.$this->getAuthorName().''; if ($this->getAuthorEmail()) { $xml[] = ' '.$this->getAuthorEmail().''; } if ($this->getAuthorLink()) { $xml[] = ' '.$this->getAuthorLink().''; } $xml[] = ' '; } if ($this->getSubtitle()) { $xml[] = ' '.$this->getSubtitle().''; } foreach ($this->getCategories() as $category) { $xml[] = ' '; } $xml[] = $this->getFeedElements(); $xml[] = ''; return implode("\n", $xml); } private function getFeedElements() { $xml = array(); foreach ($this->getItems() as $item) { $xml[] = ''; $xml[] = ' '.htmlspecialchars($this->getItemFeedTitle($item)).''; $xml[] = ' '; if ($this->getItemFeedPubdate($item)) { $xml[] = ' '.strftime('%Y-%m-%dT%H:%M:%SZ', $this->getItemFeedPubdate($item)).''; } // author information if ($this->getItemFeedAuthorName($item)) { $xml[] = ' '; $xml[] = ' '.$this->getItemFeedAuthorName($item).''; if ($this->getItemFeedAuthorEmail($item)) { $xml[] = ' '.$this->getItemFeedAuthorEmail($item).''; } if ($this->getItemFeedAuthorLink($item)) { $xml[] = ' '.sfContext::getInstance()->getController()->genUrl($this->getItemFeedAuthorLink($item), true).''; } $xml[] = ' '; } // unique id if ($this->getItemFeedUniqueId($item)) { $uniqueId = $this->getItemFeedUniqueId($item); } else { $uniqueId = $this->getTagUri($this->getItemFeedLink($item), $this->getItemFeedPubdate($item)); } $xml[] = ' '.$uniqueId.''; // summary if ($this->getItemFeedDescription($item)) { $xml[] = sprintf(' %s', htmlspecialchars($this->getItemFeedDescription($item))); } // enclosure if ((method_exists($item, 'getFeedEnclosure')) && ($enclosure = $item->getFeedEnclosure())) { $xml[] = sprintf(' ', $enclosure->getUrl(), $enclosure->getLength(), $enclosure->getMimeType()); } // categories foreach ($this->getItemFeedCategories($item) as $category) { $xml[] = ' '; } $xml[] = ''; } return implode("\n", $xml); } // Creates a TagURI. See http://diveintomark.org/archives/2004/05/28/howto-atom-id private function getTagUri($url, $date) { $tag = preg_replace('#^http\://#', '', $url); if ($date) { $tag = preg_replace('#/#', ','.strftime('%Y-%m-%d', $date).':/', $tag, 1); } $tag = preg_replace('/#/', '/', $tag); return 'tag:'.$tag; } private function getLatestPostDate() { $updates = array(); foreach ($this->getItems() as $item) { if ($this->getItemFeedPubdate($item)) { $updates[] = $this->getItemFeedPubdate($item); } } if ($updates) { sort($updates); return $updates[count($updates) - 1]; } else { return time(); } } } ?>