1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Template; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Asset; |
5
|
|
|
use Redaxscript\Header; |
6
|
|
|
use Redaxscript\Language; |
7
|
|
|
use Redaxscript\Model; |
8
|
|
|
use Redaxscript\Registry; |
9
|
|
|
use function base64_encode; |
10
|
|
|
use function file_get_contents; |
11
|
|
|
use function is_file; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* helper class to provide template helper |
15
|
|
|
* |
16
|
|
|
* @since 3.0.0 |
17
|
|
|
* |
18
|
|
|
* @package Redaxscript |
19
|
|
|
* @category Template |
20
|
|
|
* @author Henry Ruhs |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
class Helper |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* get the registry |
27
|
|
|
* |
28
|
|
|
* @since 2.6.0 |
29
|
|
|
* |
30
|
|
|
* @param string $key |
31
|
|
|
* |
32
|
|
|
* @return string|array|null |
33
|
1 |
|
*/ |
34
|
|
|
|
35
|
1 |
|
public static function getRegistry(string $key = null) |
36
|
1 |
|
{ |
37
|
|
|
$registry = Registry::getInstance(); |
38
|
|
|
return $registry->get($key); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* get the language |
43
|
|
|
* |
44
|
|
|
* @since 2.6.0 |
45
|
|
|
* |
46
|
|
|
* @param string $key |
47
|
|
|
* |
48
|
|
|
* @return string|array|null |
49
|
1 |
|
*/ |
50
|
|
|
|
51
|
1 |
|
public static function getLanguage(string $key = null) |
52
|
1 |
|
{ |
53
|
|
|
$language = Language::getInstance(); |
54
|
|
|
return $language->get($key); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* get the setting |
59
|
|
|
* |
60
|
|
|
* @since 2.6.0 |
61
|
|
|
* |
62
|
|
|
* @param string $key |
63
|
|
|
* |
64
|
|
|
* @return string|null |
65
|
1 |
|
*/ |
66
|
|
|
|
67
|
1 |
|
public static function getSetting(string $key = null) : ?string |
68
|
1 |
|
{ |
69
|
|
|
$settingModel = new Model\Setting(); |
70
|
|
|
return $settingModel->get($key); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* get the title |
75
|
|
|
* |
76
|
|
|
* @since 3.0.0 |
77
|
|
|
* |
78
|
|
|
* @return string|null |
79
|
18 |
|
*/ |
80
|
|
|
|
81
|
18 |
|
public static function getTitle() : ?string |
82
|
18 |
|
{ |
83
|
|
|
$title = new Helper\Title(Registry::getInstance(), Language::getInstance()); |
84
|
|
|
return $title->process(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* get the canonical |
89
|
|
|
* |
90
|
|
|
* @since 3.0.0 |
91
|
|
|
* |
92
|
|
|
* @return string|null |
93
|
6 |
|
*/ |
94
|
|
|
|
95
|
6 |
|
public static function getCanonical() : ?string |
96
|
6 |
|
{ |
97
|
|
|
$canonical = new Helper\Canonical(Registry::getInstance(), Language::getInstance()); |
98
|
|
|
return $canonical->process(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* get the description |
103
|
|
|
* |
104
|
|
|
* @since 3.0.0 |
105
|
|
|
* |
106
|
|
|
* @return string|null |
107
|
8 |
|
*/ |
108
|
|
|
|
109
|
8 |
|
public static function getDescription() : ?string |
110
|
8 |
|
{ |
111
|
|
|
$description = new Helper\Description(Registry::getInstance(), Language::getInstance()); |
112
|
|
|
return $description->process(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* get the keywords |
117
|
|
|
* |
118
|
|
|
* @since 3.0.0 |
119
|
|
|
* |
120
|
|
|
* @return string|null |
121
|
8 |
|
*/ |
122
|
|
|
|
123
|
8 |
|
public static function getKeywords() : ?string |
124
|
8 |
|
{ |
125
|
|
|
$keywords = new Helper\Keywords(Registry::getInstance(), Language::getInstance()); |
126
|
|
|
return $keywords->process(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* get the robots |
131
|
|
|
* |
132
|
|
|
* @since 3.0.0 |
133
|
|
|
* |
134
|
|
|
* @return string|null |
135
|
6 |
|
*/ |
136
|
|
|
|
137
|
6 |
|
public static function getRobots() : ?string |
138
|
6 |
|
{ |
139
|
|
|
$robots = new Helper\Robots(Registry::getInstance(), Language::getInstance()); |
140
|
|
|
return $robots->process(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* get the transport |
145
|
|
|
* |
146
|
|
|
* @since 3.0.0 |
147
|
|
|
* |
148
|
|
|
* @return array |
149
|
1 |
|
*/ |
150
|
|
|
|
151
|
1 |
|
public static function getTransport() : array |
152
|
1 |
|
{ |
153
|
|
|
$transport = new Asset\Transport(Registry::getInstance(), Language::getInstance()); |
154
|
|
|
return $transport->getArray(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* get the direction |
159
|
|
|
* |
160
|
|
|
* @since 3.0.0 |
161
|
|
|
* |
162
|
|
|
* @return string|null |
163
|
3 |
|
*/ |
164
|
|
|
|
165
|
3 |
|
public static function getDirection() : ?string |
166
|
3 |
|
{ |
167
|
|
|
$direction = new Helper\Direction(Registry::getInstance(), Language::getInstance()); |
168
|
|
|
return $direction->process(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* get the class |
173
|
|
|
* |
174
|
|
|
* @since 3.0.0 |
175
|
|
|
* |
176
|
|
|
* @param string $prefix |
177
|
|
|
* |
178
|
|
|
* @return string|null |
179
|
4 |
|
*/ |
180
|
|
|
|
181
|
4 |
|
public static function getClass(string $prefix = null) : ?string |
182
|
4 |
|
{ |
183
|
|
|
$client = new Helper\Client(Registry::getInstance(), Language::getInstance()); |
184
|
|
|
return $client->process($prefix); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* get the response code |
189
|
|
|
* |
190
|
|
|
* @since 4.0.0 |
191
|
|
|
* |
192
|
|
|
* @return int |
193
|
|
|
*/ |
194
|
|
|
|
195
|
|
|
public static function getResponseCode() : int |
196
|
|
|
{ |
197
|
|
|
return Header::responseCode(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* get the icon |
202
|
|
|
* |
203
|
|
|
* @since 4.3.0 |
204
|
|
|
* |
205
|
|
|
* @param string $path |
206
|
|
|
* @param string $type |
207
|
|
|
* |
208
|
|
|
* @return string |
209
|
|
|
*/ |
210
|
|
|
|
211
|
|
|
public static function getIcon(string $path = null, string $type = 'image/svg+xml') : string |
212
|
|
|
{ |
213
|
|
|
if (is_file($path)) |
214
|
|
|
{ |
215
|
|
|
return 'data:' . $type . ';base64,' . base64_encode(file_get_contents($path)); |
216
|
|
|
} |
217
|
|
|
return 'data:,'; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* get the content |
222
|
|
|
* |
223
|
|
|
* @since 4.0.0 |
224
|
|
|
* |
225
|
|
|
* @param string|array $path |
226
|
|
|
* |
227
|
|
|
* @return string|null |
228
|
|
|
*/ |
229
|
|
|
|
230
|
|
|
public static function getContent($path = null) : ?string |
231
|
|
|
{ |
232
|
|
|
$output = null; |
233
|
|
|
|
234
|
|
|
/* process file */ |
235
|
|
|
|
236
|
|
|
foreach ((array)$path as $value) |
237
|
|
|
{ |
238
|
|
|
$output .= file_get_contents($value); |
239
|
|
|
} |
240
|
|
|
return $output; |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|