1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ____ _ _ _ _ |
5
|
|
|
* | _ \| |__ | |_ ___ _ __ ___ __ _(_) | |
6
|
|
|
* | |_) | '_ \| __/ _ \ '_ ` _ \ / _` | | | |
7
|
|
|
* | __/| | | | || __/ | | | | | (_| | | | |
8
|
|
|
* |_| |_| |_|\__\___|_| |_| |_|\__,_|_|_| |
9
|
|
|
* |
10
|
|
|
* This file is part of Kristuff\Phtemail. |
11
|
|
|
* |
12
|
|
|
* (c) Kristuff <[email protected]> |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
15
|
|
|
* file that was distributed with this source code. |
16
|
|
|
* |
17
|
|
|
* @version 0.2.0 |
18
|
|
|
* @copyright 2017-2020 Kristuff |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Kristuff\Phtemail\HtmlElements; |
22
|
|
|
|
23
|
|
|
use Kristuff\Phtemail\Core\HtmlBuilder; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class RowButton |
27
|
|
|
* Represents a row with centered button. Button will take full container width |
28
|
|
|
* in mobile, and normal width otherwise. |
29
|
|
|
*/ |
30
|
|
|
class RowButton extends Row |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @access private |
34
|
|
|
* @var string $buttonText |
35
|
|
|
*/ |
36
|
|
|
private $buttonText = ''; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @access private |
40
|
|
|
* @var string $buttonSrc |
41
|
|
|
*/ |
42
|
|
|
private $buttonSrc = ''; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Constructor |
46
|
|
|
* |
47
|
|
|
* @access public |
48
|
|
|
* @param string $content The html content string |
49
|
|
|
*/ |
50
|
|
|
public function __construct(string $content, string $src = '') |
51
|
|
|
{ |
52
|
|
|
$this->buttonText = $content; |
53
|
|
|
$this->buttonSrc = $src; |
54
|
|
|
$this->styles['button_background'] = '#DA5A20'; |
55
|
|
|
$this->styles['button_color'] = '#EEEEEE'; |
56
|
|
|
$this->styles['button_padding'] = '15'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Sets the button background color |
61
|
|
|
* |
62
|
|
|
* @access public |
63
|
|
|
* @param string $value |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
* @throws \InvalidArgumentException if the color is not a valid hex color |
67
|
|
|
*/ |
68
|
|
|
public function setButtonBackground(string $value) |
69
|
|
|
{ |
70
|
|
|
$this->styles['button_background'] = HtmlBuilder::validateColor($value); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Sets the button text color |
75
|
|
|
* |
76
|
|
|
* @access public |
77
|
|
|
* @param string $value |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
* @throws \InvalidArgumentException if the color is not a valid hex color |
81
|
|
|
*/ |
82
|
|
|
public function setButtonColor(string $value) |
83
|
|
|
{ |
84
|
|
|
$this->styles['button_color'] = HtmlBuilder::validateColor($value); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Sets the button padding |
89
|
|
|
* |
90
|
|
|
* @access public |
91
|
|
|
* @param string $value The padding in pixels. Value must have the 'px' extension |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
public function setButtonPadding(string $value) |
96
|
|
|
{ |
97
|
|
|
$this->styles['button_padding'] = $value; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Gets the HTML |
102
|
|
|
* |
103
|
|
|
* @access public |
104
|
|
|
* @param string $indent |
105
|
|
|
* |
106
|
|
|
* @return string The html string content |
107
|
|
|
*/ |
108
|
|
|
public function getHtml(string $indent) |
109
|
|
|
{ |
110
|
|
|
// html result. start with an empty string or a html comment |
111
|
|
|
$html = $this->getBuilder()->getHtmlComment('ROW BUTTON ' . ' //', $indent); |
112
|
|
|
|
113
|
|
|
$html .= $indent . '<tr>'.PHP_EOL; |
114
|
|
|
$html .= $indent . ' <td align="center" valign="top">'.PHP_EOL; |
115
|
|
|
|
116
|
|
|
$html .= $this->getBuilder()->getHtmlComment('CENTERING TABLE //', $indent . ' '); |
117
|
|
|
|
118
|
|
|
$html .= $indent . ' <table border="0" cellpadding="0" cellspacing="0" width="100%">'.PHP_EOL; |
119
|
|
|
$html .= $indent . ' <tr '. $this->getRowStyle() .'>'.PHP_EOL; |
120
|
|
|
$html .= $indent . ' <td align="center" valign="top">'.PHP_EOL; |
121
|
|
|
|
122
|
|
|
$html .= $this->getBuilder()->getHtmlComment('FLEXIBLE CONTAINER //', $indent . ' '); |
123
|
|
|
|
124
|
|
|
$html .= $indent . ' <table border="0" cellpadding="' . $this->cellPadding. |
125
|
|
|
'" cellspacing="0" width="'. $this->getBuilder()->emailBodyWidth() . |
126
|
|
|
'" class="flexibleContainer">'.PHP_EOL; |
127
|
|
|
|
128
|
|
|
$html .= $indent . ' <tr>'.PHP_EOL; |
129
|
|
|
$html .= $indent . ' <td '. $this->getRowStyle() . |
130
|
|
|
' align="center" valign="top" width="'. $this->getBuilder()->emailBodyWidth() . |
131
|
|
|
'" class="flexibleContainerCell">'.PHP_EOL; |
132
|
|
|
|
133
|
|
|
$html .= $this->getBuilder()->getHtmlComment('CONTENT TABLE //', $indent . ' '); |
134
|
|
|
|
135
|
|
|
$html .= $indent . ' <table border="0" cellpadding="0" cellspacing="0" width="50%"'. |
136
|
|
|
' class="emailButton" style="background-color: '. |
137
|
|
|
$this->getEffectiveStyle('background-color') . ';">'.PHP_EOL; |
138
|
|
|
|
139
|
|
|
$html .= $indent . ' <tr>'.PHP_EOL; |
140
|
|
|
$html .= $indent . ' <td align="center" valign="middle" class="buttonContent" cellpadding="0" '. |
141
|
|
|
'bgcolor="'.$this->getEffectiveStyle('button_background').'"'. |
142
|
|
|
' style="'. |
143
|
|
|
'padding-top:' . $this->getEffectiveStyle('button_padding'). 'px;'. |
144
|
|
|
'padding-bottom:' . $this->getEffectiveStyle('button_padding'). 'px;'. |
145
|
|
|
'padding-left:' . $this->getEffectiveStyle('button_padding'). 'px;'. |
146
|
|
|
'padding-right:' . $this->getEffectiveStyle('button_padding'). 'px;'. |
147
|
|
|
'"'. |
148
|
|
|
'>'.PHP_EOL; |
149
|
|
|
$html .= $indent . ' <a style="color:'. $this->getEffectiveStyle('button_color') . |
150
|
|
|
';text-decoration:none;font-family:' . $this->getEffectiveStyle('font') . |
151
|
|
|
';font-size:20px;line-height:135%;" ' . |
152
|
|
|
'href="' . $this->buttonSrc . '" target="_blank">' . |
153
|
|
|
$this->buttonText . |
154
|
|
|
'</a>'.PHP_EOL; |
155
|
|
|
|
156
|
|
|
$html .= $indent . ' </td>'.PHP_EOL; |
157
|
|
|
$html .= $indent . ' </tr>'.PHP_EOL; |
158
|
|
|
$html .= $indent . ' </table>'.PHP_EOL; |
159
|
|
|
|
160
|
|
|
$html .= $this->getBuilder()->getHtmlComment('// CONTENT TABLE', $indent . ' '); |
161
|
|
|
|
162
|
|
|
$html .= $indent . ' </td>'.PHP_EOL; |
163
|
|
|
$html .= $indent . ' </tr>'.PHP_EOL; |
164
|
|
|
$html .= $indent . ' </table>'.PHP_EOL; |
165
|
|
|
|
166
|
|
|
$html .= $this->getBuilder()->getHtmlComment('// FLEXIBLE CONTAINER', $indent . ' '); |
167
|
|
|
|
168
|
|
|
$html .= $indent . ' </td>'.PHP_EOL; |
169
|
|
|
$html .= $indent . ' </tr>'.PHP_EOL; |
170
|
|
|
$html .= $indent . ' </table>'.PHP_EOL; |
171
|
|
|
|
172
|
|
|
$html .= $this->getBuilder()->getHtmlComment('// CENTERING TABLE', $indent . ' '); |
173
|
|
|
|
174
|
|
|
$html .= $indent . ' </td>'.PHP_EOL; |
175
|
|
|
$html .= $indent . '</tr>'.PHP_EOL; |
176
|
|
|
|
177
|
|
|
$html .= $this->getBuilder()->getHtmlComment('// ' . 'ROW BUTTON', $indent); |
178
|
|
|
return $html; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
} |