|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: ninoskopac |
|
5
|
|
|
* Date: 01/05/2018 |
|
6
|
|
|
* Time: 21:12 |
|
7
|
|
|
*/ |
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
namespace iTunesPodcastFeed; |
|
10
|
|
|
|
|
11
|
|
|
use iTunesPodcastFeed\Interfaces\Channel as ChannelInterface; |
|
12
|
|
|
use iTunesPodcastFeed\Traits\RssEscape; |
|
13
|
|
|
|
|
14
|
|
|
class Channel implements ChannelInterface |
|
15
|
|
|
{ |
|
16
|
|
|
use RssEscape; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
private $title; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private $link; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $author; |
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $email; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
private $image; |
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private $explicit; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var iterable |
|
44
|
|
|
*/ |
|
45
|
|
|
private $categories; |
|
46
|
|
|
/** |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
private $description; |
|
50
|
|
|
/** |
|
51
|
|
|
* @var string |
|
52
|
|
|
*/ |
|
53
|
|
|
private $lang; |
|
54
|
|
|
/** |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
private $copyright; |
|
58
|
|
|
/** |
|
59
|
|
|
* @var int |
|
60
|
|
|
*/ |
|
61
|
|
|
private $ttl; |
|
62
|
|
|
|
|
63
|
|
|
public function __construct( |
|
64
|
|
|
string $title, string $link, string $author, string $email, string $image, bool $explicit, |
|
65
|
|
|
iterable $categories, string $description, string $lang, string $copyright, int $ttl |
|
66
|
|
|
) { |
|
67
|
|
|
$this->title = $this->escape($title); |
|
68
|
|
|
$this->link = $link; |
|
69
|
|
|
$this->author = $author; |
|
70
|
|
|
$this->email = $email; |
|
71
|
|
|
$this->image = $image; |
|
72
|
|
|
$this->explicit = $explicit ? 'yes' : 'no'; |
|
73
|
|
|
$this->categories = $categories; |
|
74
|
|
|
$this->description = $this->escape($description); |
|
75
|
|
|
$this->lang = $lang; |
|
76
|
|
|
$this->copyright = $copyright; |
|
77
|
|
|
$this->ttl = $ttl; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getXml(): string |
|
84
|
|
|
{ |
|
85
|
|
|
$template = file_get_contents(__DIR__ . '/templates/channel.xml'); |
|
86
|
|
|
|
|
87
|
|
|
foreach (get_object_vars($this) as $propName => $propValue) { |
|
88
|
|
|
if ($propName == 'categories') { |
|
89
|
|
|
$template = str_replace('{{categories}}', $this->getCategories(), $template); |
|
90
|
|
|
} else { |
|
91
|
|
|
$template = str_replace(sprintf('{{%s}}', $propName), $propValue, $template); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return $template; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
private function getCategories(): string { |
|
99
|
|
|
$categories = []; |
|
100
|
|
|
|
|
101
|
|
|
foreach ($this->categories as $category) { |
|
102
|
|
|
$categories[] = sprintf('<itunes:category text="%s"/>', htmlspecialchars($category)); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return implode("\n", $categories); |
|
106
|
|
|
} |
|
107
|
|
|
} |