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        $this->truncSize = 500;
28        $feed .= "  \$feedDescription='".addslashes($this->getDescription())."';\n";
29        $feed .= "  \$feedLink='".$this->link."';\n";
30        $feed .= "  \$feedItem = array();\n";
31        for ($i = 0; $i < count($this->items); $i++) {
32            $feed .= "   \$feedItem[$i] = new FeedItem();\n";
33            if ($this->items[$i]->guid != "") {
34                $feed .= "    \$feedItem[$i]->id='".htmlspecialchars($this->items[$i]->guid)."';\n";
35            }
36            $feed .= "    \$feedItem[$i]->title='".addslashes(
37                    FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100)
38                )."';\n";
39            $feed .= "    \$feedItem[$i]->link='".htmlspecialchars($this->items[$i]->link)."';\n";
40            $feed .= "    \$feedItem[$i]->date=".htmlspecialchars($this->items[$i]->date).";\n";
41            if ($this->items[$i]->author != "") {
42                $feed .= "    \$feedItem[$i]->author='".htmlspecialchars($this->items[$i]->author)."';\n";
43                if ($this->items[$i]->authorEmail != "") {
44                    $feed .= "    \$feedItem[$i]->authorEmail='".$this->items[$i]->authorEmail."';\n";
45                }
46            }
47            $feed .= "    \$feedItem[$i]->description='".addslashes($this->items[$i]->getDescription())."';\n";
48            if ($this->items[$i]->thumb != "") {
49                $feed .= "    \$feedItem[$i]->thumbURL='".htmlspecialchars($this->items[$i]->thumb)."';\n";
50            }
51        }
52        $feed .= "?>\n";
53
54        return $feed;
55    }
56}
57