xref: /dokuwiki/vendor/openpsa/universalfeedcreator/lib/Creator/RSSCreator10.php (revision 3a97d936870170491bdd7d03d71143143b10191d)
1<?php
2
3/**
4 * RSSCreator10 is a FeedCreator that implements RDF Site Summary (RSS) 1.0.
5 *
6 * @see     http://www.purl.org/rss/1.0/
7 * @since   1.3
8 * @author  Kai Blankenhorn <kaib@bitfolge.de>
9 * @package de.bitfolge.feedcreator
10 */
11class RSSCreator10 extends FeedCreator
12{
13
14    /** @inheritdoc */
15    public function createFeed()
16    {
17        $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
18        $feed .= $this->_createGeneratorComment();
19        if (empty($this->cssStyleSheet)) {
20            $this->cssStyleSheet = "http://www.w3.org/2000/08/w3c-synd/style.css";
21        }
22        $feed .= $this->_createStylesheetReferences();
23        $feed .= "<rdf:RDF\n";
24        $feed .= "    xmlns=\"http://purl.org/rss/1.0/\"\n";
25        $feed .= "    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
26        $feed .= "    xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n";
27        if (!empty($this->items[0]->thumb)) {
28            $feed .= "    xmlns:photo=\"http://www.pheed.com/pheed/\"\n";
29        }
30        if (!empty($this->items[0]->lat)) {
31            $feed .= "    xmlns:georss=\"http://www.georss.org/georss\"\n";
32        }
33        $feed .= "    xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
34        $feed .= "    <channel rdf:about=\"".$this->syndicationURL."\">\n";
35        $feed .= "        <title>".htmlspecialchars($this->title)."</title>\n";
36        $feed .= "        <description>".htmlspecialchars($this->description)."</description>\n";
37        $feed .= "        <link>".$this->link."</link>\n";
38        if ($this->image != null) {
39            $feed .= "        <image rdf:resource=\"".$this->image->url."\" />\n";
40        }
41        $now = new FeedDate();
42        $feed .= "       <dc:date>".htmlspecialchars($now->iso8601())."</dc:date>\n";
43        $feed .= "        <items>\n";
44        $feed .= "            <rdf:Seq>\n";
45        for ($i = 0; $i < count($this->items); $i++) {
46            $feed .= "                <rdf:li rdf:resource=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n";
47        }
48        $feed .= "            </rdf:Seq>\n";
49        $feed .= "        </items>\n";
50        $feed .= "    </channel>\n";
51        if ($this->image != null) {
52            $feed .= "    <image rdf:about=\"".$this->image->url."\">\n";
53            $feed .= "        <title>".$this->image->title."</title>\n";
54            $feed .= "        <link>".$this->image->link."</link>\n";
55            $feed .= "        <url>".$this->image->url."</url>\n";
56            $feed .= "    </image>\n";
57        }
58        $feed .= $this->_createAdditionalElements($this->additionalElements, "    ");
59
60        for ($i = 0; $i < count($this->items); $i++) {
61            $feed .= "    <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n";
62            $feed .= "        <dc:format>text/html</dc:format>\n";
63            if ($this->items[$i]->date != null) {
64                $itemDate = new FeedDate($this->items[$i]->date);
65                $feed .= "        <dc:date>".htmlspecialchars($itemDate->iso8601())."</dc:date>\n";
66            }
67            if ($this->items[$i]->source != "") {
68                $feed .= "        <dc:source>".htmlspecialchars($this->items[$i]->source)."</dc:source>\n";
69            }
70            $creator = $this->getAuthor($this->items[$i]->author, $this->items[$i]->authorEmail);
71            if ($creator) {
72                $feed .= "        <dc:creator>".htmlspecialchars($creator)."</dc:creator>\n";
73            }
74            if ($this->items[$i]->lat != "") {
75                $feed .= "        <georss:point>".$this->items[$i]->lat." ".$this->items[$i]->long."</georss:point>\n";
76            }
77            if ($this->items[$i]->thumb != "") {
78                $feed .= "        <photo:thumbnail>".htmlspecialchars($this->items[$i]->thumb)."</photo:thumbnail>\n";
79            }
80            $feed .= "        <title>".htmlspecialchars(
81                    strip_tags(strtr($this->items[$i]->title, "\n\r", "  "))
82                )."</title>\n";
83            $feed .= "        <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
84            $feed .= "        <description>".htmlspecialchars($this->items[$i]->description)."</description>\n";
85            $feed .= $this->_createAdditionalElements($this->items[$i]->additionalElements, "        ");
86            $feed .= "    </item>\n";
87        }
88        $feed .= "</rdf:RDF>\n";
89
90        return $feed;
91    }
92
93    /**
94     * Compose the RSS-1.0 author field.
95     *
96     * @author Joe Lapp <joe.lapp@pobox.com>
97     * @param string $author
98     * @param string $email
99     * @return string
100     */
101    protected function getAuthor($author, $email)
102    {
103        if ($author) {
104            if ($email) {
105                return $author.' ('.$email.')';
106            }
107
108            return $author;
109        }
110
111        return $email;
112    }
113}
114