1<?php
2
3/**
4 * OPMLCreator is a FeedCreator that implements OPML 1.0.
5 *
6 * @see     http://opml.scripting.com/spec
7 * @author  Dirk Clemens, Kai Blankenhorn
8 * @since   1.5
9 */
10class OPMLCreator extends FeedCreator
11{
12
13    /**
14     * OPMLCreator constructor.
15     */
16    public function __construct()
17    {
18        $this->encoding = "utf-8";
19    }
20
21    /** @inheritdoc */
22    public function createFeed()
23    {
24        $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
25        $feed .= $this->_createGeneratorComment();
26        $feed .= $this->_createStylesheetReferences();
27        $feed .= "<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";
28        $feed .= "    <head>\n";
29        $feed .= "        <title>".htmlspecialchars($this->title)."</title>\n";
30        if ($this->pubDate != "") {
31            $date = new FeedDate($this->pubDate);
32            $feed .= "         <dateCreated>".$date->rfc822()."</dateCreated>\n";
33        }
34        if ($this->lastBuildDate != "") {
35            $date = new FeedDate($this->lastBuildDate);
36            $feed .= "         <dateModified>".$date->rfc822()."</dateModified>\n";
37        }
38        if ($this->editor != "") {
39            $feed .= "         <ownerName>".$this->editor."</ownerName>\n";
40        }
41        if ($this->editorEmail != "") {
42            $feed .= "         <ownerEmail>".$this->editorEmail."</ownerEmail>\n";
43        }
44        $feed .= "    </head>\n";
45        $feed .= "    <body>\n";
46        for ($i = 0; $i < count($this->items); $i++) {
47            $feed .= "    <outline type=\"rss\" ";
48            $title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title, "\n\r", "  ")));
49            $feed .= " title=\"".$title."\"";
50            $feed .= " text=\"".$title."\"";
51
52            if (isset($this->items[$i]->xmlUrl)) {
53                $feed .= " xmlUrl=\"".htmlspecialchars($this->items[$i]->xmlUrl)."\"";
54            }
55
56            if (isset($this->items[$i]->link)) {
57                $feed .= " url=\"".htmlspecialchars($this->items[$i]->link)."\"";
58            }
59
60            $feed .= "/>\n";
61        }
62        $feed .= "    </body>\n";
63        $feed .= "</opml>\n";
64
65        return $feed;
66    }
67}
68