Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Helper class for creating an Atom feed
class AtomFeed
{
private $xml;
function __construct()
{
$this->xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" />');
}
function setFeedHeader($title, $uri, $updated, $author_name, $author_email, $author_uri)
{
$this->xml->addChild("id", $uri);
$this->xml->addChild("title", $title);
$this->xml->addChild("updated", $updated);
$atomlink = $this->xml->addChild("link");
$atomlink->addAttribute("href", $uri);
$atomlink->addAttribute("rel", "self");
$author = $this->xml->addChild("author");
$author->addChild("name", $author_name);
$author->addChild("email", $author_email);
$author->addChild("uri", $author_uri);
}
function pushEntry($title, $uri, $summary, $updated)
{
$entry = $this->xml->addChild("entry");
$entry->addChild("id", $uri);
$entry->addChild("title", $title);
$summary = $entry->addChild("summary", $summary);
$summary->addAttribute("type", "html");
$entry->addChild("updated", $updated);
$link = $entry->addChild("link");
$link->addAttribute("href", $uri);
}
function output()
{
header("Content-Type: application/atom+xml");
echo $this->xml->asXML();
}
function save($path)
{
file_put_contents($path, $this->xml->asXML());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.