protected function buildAtomPagination() { // Feed paging. See IETF RFC 5005. $total_photos = $this->tag_list->getPhotoCount(); $tag_string = (string) $this->tag_list; if ($tag_string != '') { $tag_string .= '/'; } $uri = sprintf('%sfeed/%s%s%s', $this->getPinholeBaseHref(), $this->dimension->shortname, strlen($tag_string) > 0 ? '?' : '', $tag_string); $this->feed->addLink($uri, 'first', 'application/atom+xml'); if ($tag_string == '') { $uri .= '?'; } $last = ceil($total_photos / $this->page_size); if ($last > 0) { $this->feed->addLink($uri . 'page.number=' . $last, 'last', 'application/atom+xml'); $num = $this->page_number; if ($num > 1) { $this->feed->addLink($uri . 'page.number=' . ($num - 1), 'previous', 'application/atom+xml'); } if ($num != $last) { $this->feed->addLink($uri . 'page.number=' . ($num + 1), 'next', 'application/atom+xml'); } } }
protected function buildPost(XML_Atom_Feed $feed, BlorgPost $post) { $site_base_href = $this->app->getBaseHref(); $blorg_base_href = $site_base_href . $this->app->config->blorg->path; $path = $blorg_base_href . 'archive'; $date = clone $post->publish_date; $date->convertTZ($this->app->default_time_zone); $year = $date->getYear(); $month_name = BlorgPageFactory::$month_names[$date->getMonth()]; $post_uri = sprintf('%s/%s/%s/%s', $path, $year, $month_name, $post->shortname); $entry = new XML_Atom_Entry($post_uri, $post->getTitle(), $post->publish_date); if ($post->extended_bodytext != '') { $full_bodytext = $post->bodytext . $post->extended_bodytext; $entry->setSummary($post->bodytext, 'html'); $entry->setContent($full_bodytext, 'html'); } else { $entry->setContent($post->bodytext, 'html'); } foreach ($post->getTags() as $tag) { $entry->addCategory($tag->shortname, $blorg_base_href, $tag->title); } $entry->addLink($post_uri, 'alternate', 'text/html'); foreach ($post->getVisibleFiles() as $file) { $link = new XML_Atom_Link($site_base_href . $file->getRelativeUri($this->app->config->blorg->path), 'enclosure', $file->mime_type); $link->setTitle($file->getDescription()); $link->setLength($file->filesize); $entry->addLink($link); } if ($post->author->visible) { $author_uri = $blorg_base_href . 'author/' . $post->author->shortname; } else { $author_uri = ''; } $entry->addAuthor($post->author->name, $author_uri, $post->author->email); $visible_comment_count = $post->getVisibleCommentCount(); if ($post->comment_status == SiteCommentStatus::OPEN || $post->comment_status == SiteCommentStatus::MODERATED || $post->comment_status == SiteCommentStatus::LOCKED && $visible_comment_count > 0) { $entry->addLink($post_uri . '#comments', 'comments', 'text/html'); } $feed->addEntry($entry); }
protected function buildComment(XML_Atom_Feed $feed, BlorgComment $comment) { $post = $comment->post; $path = $this->getBlorgBaseHref() . 'archive'; $date = clone $post->publish_date; $date->convertTZ($this->app->default_time_zone); $year = $date->getYear(); $month_name = BlorgPageFactory::$month_names[$date->getMonth()]; $post_uri = sprintf('%s/%s/%s/%s', $path, $year, $month_name, $post->shortname); $comment_uri = $post_uri . '#comment' . $comment->id; if ($comment->author !== null) { $author_name = $comment->author->name; if ($comment->author->visible) { $author_uri = $this->getBlorgBaseHref() . 'author/' . $comment->author->shortname; $author_email = $comment->author->email; } else { $author_uri = ''; $author_email = ''; } } else { $author_name = $comment->fullname; $author_uri = $comment->link; // don't show anonymous author email $author_email = ''; } $entry = new XML_Atom_Entry($comment_uri, sprintf(Blorg::_('%s on “%s”'), $author_name, $post->getTitle()), $comment->createdate); $entry->setContent(SiteCommentFilter::toXhtml($comment->bodytext), 'html'); $entry->addAuthor($author_name, $author_uri, $author_email); $entry->addLink($comment_uri, 'alternate', 'text/html'); $feed->addEntry($entry); }
protected function buildHeader(XML_Atom_Feed $feed) { $feed->setGenerator('Blörg'); $feed->setBase($this->app->getBaseHref()); $feed->addLink($this->app->getBaseHref() . $this->source, 'self', 'application/atom+xml'); }
protected function buildComment(XML_Atom_Feed $feed, BlorgComment $comment) { $comment_uri = $this->getPostUri($this->post) . '#comment' . $comment->id; if ($comment->author !== null) { $author_name = $comment->author->name; if ($comment->author->visible) { $author_uri = $this->getBlorgBaseHref() . 'author/' . $this->post->author->shortname; $author_email = $this->post->author->email; } else { $author_uri = ''; $author_email = ''; } } else { $author_name = $comment->fullname; $author_uri = $comment->link; // don't show anonymous author email $author_email = ''; } $entry = new XML_Atom_Entry($comment_uri, sprintf(Blorg::_('By: %s'), $author_name), $comment->createdate); $entry->setContent(SiteCommentFilter::toXhtml($comment->bodytext), 'html'); $entry->addAuthor($author_name, $author_uri, $author_email); $entry->addLink($comment_uri, 'alternate', 'text/html'); $feed->addEntry($entry); }
protected function buildPagination(XML_Atom_Feed $feed) { $page = $this->getArgument('page'); $type = 'application/atom+xml'; $last = intval(ceil($this->getTotalCount() / $this->getPageSize())); $base_href = $this->getPinholeBaseHref() . 'feed/comments'; $feed->addLink($base_href, 'first', $type); $feed->addLink($base_href . '/page' . $last, 'last', $type); if ($page > 1) { $feed->addLink($base_href . '/page' . ($page - 1), 'previous', $type); } if ($page < $last) { $feed->addLink($base_href . '/page' . ($page + 1), 'next', $type); } }
<?php require_once 'XML/Atom/Feed.php'; $feed = new XML_Atom_Feed('http://example.com/', 'Example Feed'); $feed->addAuthor('Michael Gauthier', '', '*****@*****.**'); $feed->setGenerator('PEAR::XML_Atom'); $entry = new XML_Atom_Entry('http://example.com/archive/2008/january/test-post', 'Test Post'); $entry->setContent('Hello, World!', 'html'); $feed->addEntry($entry); $entry = new XML_Atom_Entry('http://example.com/archive/2008/february/atom-test', 'Lorem Ipsum Dolor'); $entry->setSummary('<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec eu tellus ut sapien pharetra hendrerit. Suspendisse sed risus. Donec a sapien eget quam malesuada blandit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Proin quis elit eget quam convallis dictum. Integer lorem quam, laoreet a, bibendum quis, eleifend at, orci. Ut sed est in sem congue lacinia. Praesent cursus feugiat ante. Cras enim. Duis venenatis rutrum tellus. Aliquam erat volutpat. Vestibulum volutpat orci nec lorem. Nunc elit est, gravida eget, mattis vitae, vestibulum at, quam. Aliquam ultrices lacinia tellus. Sed eu metus.</p>', 'html'); $entry->setContent('<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec eu tellus ut sapien pharetra hendrerit. Suspendisse sed risus. Donec a sapien eget quam malesuada blandit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Proin quis elit eget quam convallis dictum. Integer lorem quam, laoreet a, bibendum quis, eleifend at, orci. Ut sed est in sem congue lacinia. Praesent cursus feugiat ante. Cras enim. Duis venenatis rutrum tellus. Aliquam erat volutpat. Vestibulum volutpat orci nec lorem. Nunc elit est, gravida eget, mattis vitae, vestibulum at, quam. Aliquam ultrices lacinia tellus. Sed eu metus.</p><p>Ut non nisi vitae eros tempus nonummy. Etiam accumsan aliquam erat. Praesent magna pede, rhoncus eu, dictum non, vestibulum in, purus. Sed egestas ultrices sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis suscipit justo a sapien. Mauris gravida, tellus a dignissim congue, nisi magna vehicula lorem, sollicitudin viverra ligula augue et mi. Aliquam auctor. Sed faucibus lacus nec nisl. Nulla arcu lorem, dapibus eu, accumsan eu, pulvinar at, risus. Curabitur imperdiet urna sed erat. Vestibulum id nulla. Donec magna risus, egestas ac, imperdiet malesuada, accumsan in, velit. Etiam elementum, eros in tempor sodales, massa nisl vulputate ligula, id semper lectus justo vel enim. Sed nisi mi, tristique in, molestie vel, fermentum nec, nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Proin lacus erat, tristique nec, tempus sed, consectetuer ut, orci.</p>', 'html'); $feed->addEntry($entry); $document = $feed->getDocument(); echo formatXmlString($document->saveXML()); // =========================================================================== function formatXmlString($xml) { // add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries) $xml = preg_replace('/(>)(<)(\\/*)/', "\$1\n\$2\$3", $xml); // now indent the tags $token = strtok($xml, "\n"); $result = ''; // holds formatted version as it is built $pad = 0; // initial indent $matches = array(); // returns from preg_matches() // scan each line and adjust indent based on opening/closing tags while ($token !== false) { // test for the various tag states