checkRequiredProperties();
$dom = new \DomDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
//
$feed = $dom->createElement('feed');
$feed->setAttributeNodeNS(new \DomAttr('xmlns', 'http://www.w3.org/2005/Atom'));
//
$generator = $dom->createElement('generator', 'PicoFeed');
$generator->setAttribute('url', 'https://github.com/fguillot/picoFeed');
$feed->appendChild($generator);
//
$feed->appendChild($dom->createElement('title', $this->title));
//
$feed->appendChild($dom->createElement('updated', date(DATE_ATOM, isset($this->updated) ? $this->updated : time())));
//
$link = $dom->createElement('link');
$link->setAttribute('rel', 'alternate');
$link->setAttribute('type', 'text/html');
$link->setAttribute('href', $this->site_url);
$feed->appendChild($link);
//
$link = $dom->createElement('link');
$link->setAttribute('rel', 'self');
$link->setAttribute('type', 'application/atom+xml');
$link->setAttribute('href', $this->feed_url);
$feed->appendChild($link);
//
if (isset($this->author)) {
$name = $dom->createElement('name', $this->author);
$author = $dom->createElement('author');
$author->appendChild($name);
$feed->appendChild($author);
}
//
foreach ($this->items as $item) {
$entry = $dom->createElement('entry');
//
$entry->appendChild($dom->createElement('title', $item['title']));
//
$entry->appendChild($dom->createElement('updated', date(DATE_ATOM, isset($item['updated']) ? $item['updated'] : time())));
//
if (isset($item['published'])) {
$entry->appendChild($dom->createElement('published', date(DATE_ATOM, $item['published'])));
}
//
$link = $dom->createElement('link');
$link->setAttribute('rel', 'alternate');
$link->setAttribute('type', 'text/html');
$link->setAttribute('href', $item['url']);
$entry->appendChild($link);
//
if (isset($item['summary'])) {
$entry->appendChild($dom->createElement('summary', $item['summary']));
}
//
if (isset($item['content'])) {
$content = $dom->createElement('content');
$content->setAttribute('type', 'html');
$content->appendChild($dom->createCDATASection($item['content']));
$entry->appendChild($content);
}
//
if (isset($item['author'])) {
$name = $dom->createElement('name', $item['author']);
$author = $dom->createElement('author');
$author->appendChild($name);
$entry->appendChild($author);
}
$feed->appendChild($entry);
}
$dom->appendChild($feed);
if ($filename) {
$dom->save($filename);
}
else {
return $dom->saveXML();
}
}
}