|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Grandstream-XMLApp |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2017 pudelek.org.pl |
|
6
|
|
|
* |
|
7
|
|
|
* @license MIT License (MIT) |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view source file |
|
10
|
|
|
* that is bundled with this package in the file LICENSE |
|
11
|
|
|
* |
|
12
|
|
|
* @author Marcin Pudełek <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace mrcnpdlk\Grandstream\XMLApp\Application\Model\Components; |
|
16
|
|
|
|
|
17
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Application\ModelInterface; |
|
18
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Helper\Font; |
|
19
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Helper\Point; |
|
20
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Helper\Rectangle; |
|
21
|
|
|
use mrcnpdlk\Grandstream\XMLApp\MyXML; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class ElemString |
|
25
|
|
|
* |
|
26
|
|
|
* This element is used for displaying string information on the screen |
|
27
|
|
|
* |
|
28
|
|
|
* <ElemString font="unifont" width="width of the string" height="height of the string" halign="center/left/right" color="color of the string" bgcolor="color of the background" > |
|
29
|
|
|
* <X>X location</X> |
|
30
|
|
|
* <Y>Y location </Y> |
|
31
|
|
|
* <DisplayStr>Display String</DisplayStr> |
|
32
|
|
|
* </ElemString> |
|
33
|
|
|
* |
|
34
|
|
|
* @package mrcnpdlk\Grandstream\XMLApp\CustomScreen\Model |
|
35
|
|
|
*/ |
|
36
|
|
|
class ElemString extends ElemAbstract implements ModelInterface, ElemInterface |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private $sString; |
|
42
|
|
|
/** |
|
43
|
|
|
* Font type |
|
44
|
|
|
* |
|
45
|
|
|
* @var Font |
|
46
|
|
|
*/ |
|
47
|
|
|
private $oFont; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* ElemString constructor. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $sString |
|
53
|
|
|
* @param Rectangle $oRectangle |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct(string $sString, Rectangle $oRectangle = null) |
|
56
|
|
|
{ |
|
57
|
|
|
parent::__construct(new Point(0, 0), $oRectangle); |
|
58
|
|
|
$this->sString = $sString; |
|
59
|
|
|
$this->setFont(); |
|
60
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param \mrcnpdlk\Grandstream\XMLApp\Helper\Font|null $oFont |
|
65
|
|
|
* |
|
66
|
|
|
* @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Components\ElemString |
|
67
|
|
|
*/ |
|
68
|
|
|
public function setFont(Font $oFont = null) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->oFont = $oFont ?? new Font(); |
|
71
|
|
|
|
|
72
|
|
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return MyXML |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getXml(): MyXML |
|
79
|
|
|
{ |
|
80
|
|
|
$oXml = new MyXML('DisplayString'); |
|
81
|
|
|
|
|
82
|
|
|
$oXml->asObject()->addAttribute('font', $this->getFont()->getType()); |
|
83
|
|
|
if ($this->getRectangle()->getWidth()) { |
|
84
|
|
|
$oXml->setWidth($this->getRectangle()->getWidth()); |
|
85
|
|
|
} |
|
86
|
|
|
if ($this->getRectangle()->getHeight()) { |
|
87
|
|
|
$oXml->setHeight($this->getRectangle()->getHeight()); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$oXml->setColor($this->getFont()->getColor()->get()); |
|
91
|
|
|
$oXml->setColorBg($this->getColorBg()->get()); |
|
92
|
|
|
$oXml->asObject()->addAttribute('halign', $this->getFont()->getHorizontalAlign()); |
|
93
|
|
|
$oXml->asObject()->addChild('X', $this->getPoint()->getX()); |
|
94
|
|
|
$oXml->asObject()->addChild('Y', $this->getPoint()->getY()); |
|
95
|
|
|
$oXml->asObject()->addChild('DisplayStr', $this->cleanString($this->sString)); |
|
96
|
|
|
|
|
97
|
|
|
return $oXml; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return \mrcnpdlk\Grandstream\XMLApp\Helper\Font |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getFont() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->oFont; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Escape chars |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $str |
|
112
|
|
|
* |
|
113
|
|
|
* @return string |
|
114
|
|
|
*/ |
|
115
|
|
|
private function cleanString(string $str) |
|
116
|
|
|
{ |
|
117
|
|
|
$str = str_replace('&', '&', $str); |
|
118
|
|
|
$str = str_replace('"', '"', $str); |
|
119
|
|
|
$str = str_replace('\'', ''', $str); |
|
120
|
|
|
$str = str_replace('<', '<', $str); |
|
121
|
|
|
$str = str_replace('>', '>', $str); |
|
122
|
|
|
|
|
123
|
|
|
return $str; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|