1<?php
2
3/**
4 * PHPCreator is a FeedCreator that implements a PHP output, suitable for an include
5 *
6 * @since   1.7.3
7 * @author  Barry Hunter <geo@barryhunter.co.uk>
8 */
9class PHPCreator extends FeedCreator
10{
11
12    /**
13     * PHPCreator constructor.
14     */
15    public function __construct()
16    {
17        $this->contentType = "text/plain";
18        $this->encoding = "utf-8";
19    }
20
21    /** @inheritdoc */
22    public function createFeed()
23    {
24        $feed = "<?php\n";
25        $feed .= "class FeedItem {}\n";
26        $feed .= "  \$feedTitle='".addslashes(FeedCreator::iTrunc(htmlspecialchars($this->title), 100))."';\n";
27        $feed .= "  \$feedDescription='".addslashes($this->getDescription())."';\n";
28        $feed .= "  \$feedLink='".$this->link."';\n";
29        $feed .= "  \$feedItem = array();\n";
30        for ($i = 0; $i < count($this->items); $i++) {
31            $feed .= "   \$feedItem[$i] = new FeedItem();\n";
32            if ($this->items[$i]->guid != "") {
33                $feed .= "    \$feedItem[$i]->id='".htmlspecialchars($this->items[$i]->guid)."';\n";
34            }
35            $feed .= "    \$feedItem[$i]->title='".addslashes(
36                    FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100)
37                )."';\n";
38            $feed .= "    \$feedItem[$i]->link='".htmlspecialchars($this->items[$i]->link)."';\n";
39            $feed .= "    \$feedItem[$i]->date=".htmlspecialchars($this->items[$i]->date).";\n";
40            if ($this->items[$i]->author != "") {
41                $feed .= "    \$feedItem[$i]->author='".htmlspecialchars($this->items[$i]->author)."';\n";
42                if ($this->items[$i]->authorEmail != "") {
43                    $feed .= "    \$feedItem[$i]->authorEmail='".$this->items[$i]->authorEmail."';\n";
44                }
45            }
46            $feed .= "    \$feedItem[$i]->description='".addslashes($this->items[$i]->getDescription())."';\n";
47            if ($this->items[$i]->thumb != "") {
48                $feed .= "    \$feedItem[$i]->thumbURL='".htmlspecialchars($this->items[$i]->thumb)."';\n";
49            }
50        }
51        $feed .= "?>\n";
52
53        return $feed;
54    }
55}
56