xref: /dokuwiki/vendor/openpsa/universalfeedcreator/lib/Creator/OPMLCreator.php (revision a087da71ea972d05ca659a1e9406c87aa7ae258b)
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 * @package de.bitfolge.feedcreator
10 */
11class OPMLCreator extends FeedCreator
12{
13
14    /**
15     * OPMLCreator constructor.
16     */
17    public function __construct()
18    {
19        $this->encoding = "utf-8";
20    }
21
22    /** @inheritdoc */
23    public function createFeed()
24    {
25        $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
26        $feed .= $this->_createGeneratorComment();
27        $feed .= $this->_createStylesheetReferences();
28        $feed .= "<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";
29        $feed .= "    <head>\n";
30        $feed .= "        <title>".htmlspecialchars($this->title)."</title>\n";
31        if ($this->pubDate != "") {
32            $date = new FeedDate($this->pubDate);
33            $feed .= "         <dateCreated>".$date->rfc822()."</dateCreated>\n";
34        }
35        if ($this->lastBuildDate != "") {
36            $date = new FeedDate($this->lastBuildDate);
37            $feed .= "         <dateModified>".$date->rfc822()."</dateModified>\n";
38        }
39        if ($this->editor != "") {
40            $feed .= "         <ownerName>".$this->editor."</ownerName>\n";
41        }
42        if ($this->editorEmail != "") {
43            $feed .= "         <ownerEmail>".$this->editorEmail."</ownerEmail>\n";
44        }
45        $feed .= "    </head>\n";
46        $feed .= "    <body>\n";
47        for ($i = 0; $i < count($this->items); $i++) {
48            $feed .= "    <outline type=\"rss\" ";
49            $title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title, "\n\r", "  ")));
50            $feed .= " title=\"".$title."\"";
51            $feed .= " text=\"".$title."\"";
52
53            if (isset($this->items[$i]->xmlUrl)) {
54                $feed .= " xmlUrl=\"".htmlspecialchars($this->items[$i]->xmlUrl)."\"";
55            }
56
57            if (isset($this->items[$i]->link)) {
58                $feed .= " url=\"".htmlspecialchars($this->items[$i]->link)."\"";
59            }
60
61            $feed .= "/>\n";
62        }
63        $feed .= "    </body>\n";
64        $feed .= "</opml>\n";
65
66        return $feed;
67    }
68}
69