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