Skip to content

Instantly share code, notes, and snippets.

@omichelsen
Created November 24, 2015 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omichelsen/ceac624943cb92a88da4 to your computer and use it in GitHub Desktop.
Save omichelsen/ceac624943cb92a88da4 to your computer and use it in GitHub Desktop.
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