1<?php
2
3/**
4 * AtomCreator03 is a FeedCreator that implements the atom specification,
5 * as in http://www.intertwingly.net/wiki/pie/FrontPage.
6 * Please note that just by using AtomCreator03 you won't automatically
7 * produce valid atom files. For example, you have to specify either an editor
8 * for the feed or an author for every single feed item.
9 * Some elements have not been implemented yet. These are (incomplete list):
10 * author URL, item author's email and URL, item contents, alternate links,
11 * other link content types than text/html. Some of them may be created with
12 * AtomCreator03::additionalElements.
13 *
14 * @see     FeedCreator#additionalElements
15 * @since   1.6
16 * @author  Kai Blankenhorn <kaib@bitfolge.de>, Scott Reynen <scott@randomchaos.com>
17 */
18class AtomCreator03 extends FeedCreator
19{
20
21    /**
22     * AtomCreator03 constructor.
23     */
24    public function __construct()
25    {
26        $this->contentType = "application/atom+xml";
27        $this->encoding = "utf-8";
28    }
29
30    /** @inheritdoc */
31    public function createFeed()
32    {
33        $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
34        $feed .= $this->_createGeneratorComment();
35        $feed .= $this->_createStylesheetReferences();
36        $feed .= "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\"";
37        if ($this->format == 'TOOLBAR') {
38            $feed .= " xmlns:gtb=\"http://toolbar.google.com/custombuttons/\"";
39        }
40        if ($this->language != "") {
41            $feed .= " xml:lang=\"".$this->language."\"";
42        }
43        $feed .= ">\n";
44        $feed .= "    <title>".htmlspecialchars($this->title)."</title>\n";
45        $feed .= "    <tagline>".htmlspecialchars($this->description)."</tagline>\n";
46        $feed .= "    <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->link)."\"/>\n";
47        $feed .= "    <id>".htmlspecialchars($this->link)."</id>\n";
48        $now = new FeedDate();
49        $feed .= "    <modified>".htmlspecialchars($now->iso8601())."</modified>\n";
50        if ($this->editor != "") {
51            $feed .= "    <author>\n";
52            $feed .= "        <name>".$this->editor."</name>\n";
53            if ($this->editorEmail != "") {
54                $feed .= "        <email>".$this->editorEmail."</email>\n";
55            }
56            $feed .= "    </author>\n";
57        }
58        $feed .= "    <generator>".FEEDCREATOR_VERSION."</generator>\n";
59        $feed .= $this->_createAdditionalElements($this->additionalElements, "    ");
60        for ($i = 0; $i < count($this->items); $i++) {
61            $feed .= "    <entry>\n";
62            $feed .= "        <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n";
63            $feed .= "        <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars(
64                    $this->items[$i]->link
65                )."\"/>\n";
66            if ($this->items[$i]->date == "") {
67                $this->items[$i]->date = time();
68            }
69            $itemDate = new FeedDate($this->items[$i]->date);
70            $feed .= "        <created>".htmlspecialchars($itemDate->iso8601())."</created>\n";
71            $feed .= "        <issued>".htmlspecialchars($itemDate->iso8601())."</issued>\n";
72            $feed .= "        <modified>".htmlspecialchars($itemDate->iso8601())."</modified>\n";
73            $feed .= "        <id>".htmlspecialchars($this->items[$i]->link)."</id>\n";
74            $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, "        ");
75            if ($this->items[$i]->author != "") {
76                $feed .= "        <author>\n";
77                $feed .= "            <name>".htmlspecialchars($this->items[$i]->author)."</name>\n";
78                $feed .= "        </author>\n";
79            }
80            if ($this->items[$i]->description != "") {
81                $feed .= "        <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n";
82            }
83            if (isset($this->items[$i]->thumbdata)) {
84                $feed .= "        <gtb:icon mode=\"base64\" type=\"image/jpeg\">\n";
85                $feed .= chunk_split(base64_encode($this->items[$i]->thumbdata))."\n";
86                $feed .= "        </gtb:icon>\n";
87            }
88            $feed .= "    </entry>\n";
89        }
90        $feed .= "</feed>\n";
91
92        return $feed;
93    }
94}
95