1 | <?php |
||
7 | class TemplateParser |
||
8 | { |
||
9 | const DATA_TRANSLATE = 'data-translate'; |
||
10 | |||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | private $viewData; |
||
15 | |||
16 | /** |
||
17 | * List of simple tags |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $allowedTags = [ |
||
22 | 'legend' => 'Caption for the fieldset element', |
||
23 | 'label' => 'Label for an input element.', |
||
24 | 'button' => 'Push button', |
||
25 | 'a' => 'Link label', |
||
26 | 'b' => 'Bold text', |
||
27 | 'strong' => 'Strong emphasized text', |
||
28 | 'i' => 'Italic text', |
||
29 | 'em' => 'Emphasized text', |
||
30 | 'u' => 'Underlined text', |
||
31 | 'sup' => 'Superscript text', |
||
32 | 'sub' => 'Subscript text', |
||
33 | 'span' => 'Span element', |
||
34 | 'small' => 'Smaller text', |
||
35 | 'big' => 'Bigger text', |
||
36 | 'address' => 'Contact information', |
||
37 | 'blockquote' => 'Long quotation', |
||
38 | 'q' => 'Short quotation', |
||
39 | 'cite' => 'Citation', |
||
40 | 'caption' => 'Table caption', |
||
41 | 'abbr' => 'Abbreviated phrase', |
||
42 | 'acronym' => 'An acronym', |
||
43 | 'var' => 'Variable part of a text', |
||
44 | 'dfn' => 'Term', |
||
45 | 'strike' => 'Strikethrough text', |
||
46 | 'del' => 'Deleted text', |
||
47 | 'ins' => 'Inserted text', |
||
48 | 'h1' => 'Heading level 1', |
||
49 | 'h2' => 'Heading level 2', |
||
50 | 'h3' => 'Heading level 3', |
||
51 | 'h4' => 'Heading level 4', |
||
52 | 'h5' => 'Heading level 5', |
||
53 | 'h6' => 'Heading level 6', |
||
54 | 'center' => 'Centered text', |
||
55 | 'select' => 'List options', |
||
56 | 'img' => 'Image', |
||
57 | 'input' => 'Form element', |
||
58 | 'p' => 'Generic Paragraph', |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * TemplateParser constructor. |
||
63 | * @param array $viewData |
||
64 | */ |
||
65 | public function __construct(array $viewData = []) |
||
69 | |||
70 | public function parseTranslationTags(string &$viewContent) |
||
123 | |||
124 | /** |
||
125 | * Format translation for simple tags. Added translate mode attribute for vde requests. |
||
126 | * |
||
127 | * @param string $tagHtml |
||
128 | * @param string $tagName |
||
129 | * @param array $trArr |
||
130 | * @return string |
||
131 | */ |
||
132 | protected function applyTranslationTags($tagHtml, $tagName, $trArr) |
||
146 | |||
147 | /** |
||
148 | * Get html element attribute |
||
149 | * |
||
150 | * @param string $name |
||
151 | * @param string $value |
||
152 | * @return string |
||
153 | */ |
||
154 | private function getHtmlAttribute($name, $value) |
||
158 | |||
159 | /** |
||
160 | * Get translate data by regexp |
||
161 | * |
||
162 | * @param string $regexp |
||
163 | * @param string $text |
||
164 | * @param array $options |
||
165 | * @return array |
||
166 | */ |
||
167 | private function getTranslateData($regexp, $text, $options = []) |
||
194 | |||
195 | /** |
||
196 | * Get tag location |
||
197 | * |
||
198 | * @param array $matches |
||
199 | * @param array $options |
||
200 | * @return string |
||
201 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
202 | */ |
||
203 | protected function getTagLocation($matches, $options) |
||
211 | |||
212 | private function _returnViewData() |
||
223 | |||
224 | /** |
||
225 | * @param string $localizationParameters |
||
226 | * @return array|mixed |
||
227 | */ |
||
228 | private function extractVariablesFromLocalizationParameters($localizationParameters) |
||
239 | |||
240 | /** |
||
241 | * Find end of tag |
||
242 | * |
||
243 | * @param string $body |
||
244 | * @param string $tagName |
||
245 | * @param int $from |
||
246 | * @return bool|int return false if end of tag is not found |
||
247 | */ |
||
248 | private function findEndOfTag($body, $tagName, $from) |
||
270 | } |
||
271 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.