|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Nexendrie\Rss; |
|
5
|
|
|
|
|
6
|
|
|
use Nexendrie\Utils\Numbers; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Image |
|
10
|
|
|
* |
|
11
|
|
|
* @author Jakub Konečný |
|
12
|
|
|
* @property int $width |
|
13
|
|
|
* @property int $height |
|
14
|
|
|
*/ |
|
15
|
1 |
|
final class Image implements IXmlConvertible { |
|
16
|
|
|
use \Nette\SmartObject; |
|
17
|
|
|
|
|
18
|
|
|
public string $url; |
|
19
|
|
|
public string $title; |
|
20
|
|
|
public string $link; |
|
21
|
|
|
private int $width; |
|
22
|
|
|
private int $height; |
|
23
|
|
|
public string $description; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct(string $url, string $title, string $link, string $description = "") { |
|
26
|
1 |
|
$this->url = $url; |
|
27
|
1 |
|
$this->title = $title; |
|
28
|
1 |
|
$this->link = $link; |
|
29
|
1 |
|
$this->description = $description; |
|
30
|
1 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function getWidth(): int { |
|
33
|
1 |
|
return $this->width; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function setWidth(int $width): void { |
|
37
|
1 |
|
$this->width = Numbers::range($width, 0, 144); |
|
38
|
1 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function getHeight(): int { |
|
41
|
1 |
|
return $this->height; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function setHeight(int $height): void { |
|
45
|
1 |
|
$this->height = Numbers::range($height, 0, 400); |
|
46
|
1 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function appendToXml(\SimpleXMLElement &$parent): void { |
|
49
|
1 |
|
$element = $parent->addChild("image"); |
|
50
|
1 |
|
$element->addChild("url", $this->url); |
|
51
|
1 |
|
$element->addChild("title", $this->title); |
|
52
|
1 |
|
$element->addChild("link", $this->link); |
|
53
|
1 |
|
if($this->description !== "") { |
|
54
|
1 |
|
$element->addChild("description", $this->description); |
|
55
|
|
|
} |
|
56
|
1 |
|
if(isset($this->width)) { |
|
57
|
1 |
|
$element->addChild("width", (string) $this->width); |
|
58
|
|
|
} |
|
59
|
1 |
|
if(isset($this->height)) { |
|
60
|
1 |
|
$element->addChild("height", (string) $this->height); |
|
61
|
|
|
} |
|
62
|
1 |
|
} |
|
63
|
|
|
} |
|
64
|
|
|
?> |