summaryrefslogtreecommitdiff
path: root/vendor/miniflux/picofeed/lib/PicoFeed/Syndication/AtomFeedBuilder.php
blob: 34f37800d0ea7e797e35169ed82b249f5b40642f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

namespace PicoFeed\Syndication;

use DOMAttr;
use DOMElement;

/**
 * Atom Feed Builder
 *
 * @package PicoFeed\Syndication
 * @author  Frederic Guillot
 */
class AtomFeedBuilder extends FeedBuilder
{
    /**
     * @var DOMElement
     */
    protected $feedElement;

    /**
     * @var AtomHelper
     */
    protected $helper;

    /**
     * Build feed
     *
     * @access public
     * @param  string $filename
     * @return string
     */
    public function build($filename = '')
    {
        $this->helper = new AtomHelper($this->getDocument());

        $this->feedElement = $this->getDocument()->createElement('feed');
        $this->feedElement->setAttributeNodeNS(new DomAttr('xmlns', 'http://www.w3.org/2005/Atom'));

        $generator = $this->getDocument()->createElement('generator', 'PicoFeed');
        $generator->setAttribute('uri', 'https://github.com/miniflux/picoFeed');
        $this->feedElement->appendChild($generator);

        $this->helper
            ->buildTitle($this->feedElement, $this->feedTitle)
            ->buildId($this->feedElement, $this->feedUrl)
            ->buildDate($this->feedElement, $this->feedDate)
            ->buildLink($this->feedElement, $this->siteUrl)
            ->buildLink($this->feedElement, $this->feedUrl, 'self', 'application/atom+xml')
            ->buildAuthor($this->feedElement, $this->authorName, $this->authorEmail, $this->authorUrl)
        ;

        foreach ($this->items as $item) {
            $this->feedElement->appendChild($item->build());
        }

        $this->getDocument()->appendChild($this->feedElement);

        if ($filename !== '') {
            $this->getDocument()->save($filename);
        }

        return $this->getDocument()->saveXML();
    }
}