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