Complex classes like Codes often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Codes, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class Codes |
||
28 | { |
||
29 | /** the tag's name - must be lowercase */ |
||
30 | const ATTR_TAG = 1; |
||
31 | |||
32 | /** One of self::TYPE_* */ |
||
33 | const ATTR_TYPE = 2; |
||
34 | |||
35 | /** |
||
36 | * An optional array of parameters, for the form |
||
37 | * [tag abc=123]content[/tag]. The array is an associative array |
||
38 | * where the keys are the parameter names, and the values are an |
||
39 | * array which *may* contain any of self::PARAM_ATTR_* |
||
40 | */ |
||
41 | const ATTR_PARAM = 3; |
||
42 | |||
43 | /** |
||
44 | * A regular expression to test immediately after the tag's |
||
45 | * '=', ' ' or ']'. Typically, should have a \] at the end. |
||
46 | * Optional. |
||
47 | */ |
||
48 | const ATTR_TEST = 4; |
||
49 | |||
50 | /** |
||
51 | * Only available for unparsed_content, closed, unparsed_commas_content, and unparsed_equals_content. |
||
52 | * $1 is replaced with the content of the tag. |
||
53 | * Parameters are replaced in the form {param}. |
||
54 | * For unparsed_commas_content, $2, $3, ..., $n are replaced. |
||
55 | */ |
||
56 | const ATTR_CONTENT = 5; |
||
57 | |||
58 | /** |
||
59 | * Only when content is not used, to go before any content. |
||
60 | * For unparsed_equals, $1 is replaced with the value. |
||
61 | * For unparsed_commas, $1, $2, ..., $n are replaced. |
||
62 | */ |
||
63 | const ATTR_BEFORE = 6; |
||
64 | |||
65 | /** |
||
66 | * Similar to before in every way, except that it is used when the tag is closed. |
||
67 | */ |
||
68 | const ATTR_AFTER = 7; |
||
69 | |||
70 | /** |
||
71 | * Used in place of content when the tag is disabled. |
||
72 | * For closed, default is '', otherwise it is '$1' if block_level is false, '<div>$1</div>' elsewise. |
||
73 | */ |
||
74 | const ATTR_DISABLED_CONTENT = 8; |
||
75 | |||
76 | /** |
||
77 | * Used in place of before when disabled. |
||
78 | * Defaults to '<div>' if block_level, '' if not. |
||
79 | */ |
||
80 | const ATTR_DISABLED_BEFORE = 9; |
||
81 | |||
82 | /** |
||
83 | * Used in place of after when disabled. |
||
84 | * Defaults to '</div>' if block_level, '' if not. |
||
85 | */ |
||
86 | const ATTR_DISABLED_AFTER = 10; |
||
87 | |||
88 | /** |
||
89 | * Set to true the tag is a "block level" tag, similar to HTML. |
||
90 | * Block level tags cannot be nested inside tags that are not block level, and will not be implicitly closed as easily. |
||
91 | * One break following a block level tag may also be removed. |
||
92 | */ |
||
93 | const ATTR_BLOCK_LEVEL = 11; |
||
94 | |||
95 | /** |
||
96 | * Trim the whitespace after the opening tag or the closing tag or both. |
||
97 | * One of self::TRIM_* |
||
98 | * Optional |
||
99 | */ |
||
100 | const ATTR_TRIM = 12; |
||
101 | |||
102 | /** |
||
103 | * Except when type is missing or 'closed', a callback to validate the data as $data. |
||
104 | * Depending on the tag's type, $data may be a string or an array of strings (corresponding to the replacement.) |
||
105 | */ |
||
106 | const ATTR_VALIDATE = 13; |
||
107 | |||
108 | /** |
||
109 | * When type is unparsed_equals or parsed_equals only, may be not set, |
||
110 | * 'optional', or 'required' corresponding to if the content may be quoted. |
||
111 | * This allows the parser to read [tag="abc]def[esdf]"] properly. |
||
112 | */ |
||
113 | const ATTR_QUOTED = 14; |
||
114 | |||
115 | /** |
||
116 | * An array of tag names, or not set. |
||
117 | * If set, the enclosing tag *must* be one of the listed tags, or parsing won't occur. |
||
118 | */ |
||
119 | const ATTR_REQUIRE_PARENTS = 15; |
||
120 | |||
121 | /** |
||
122 | * similar to require_parents, if set children won't be parsed if they are not in the list. |
||
123 | */ |
||
124 | const ATTR_REQUIRE_CHILDREN = 16; |
||
125 | |||
126 | /** |
||
127 | * Similar to, but very different from, require_parents. |
||
128 | * If it is set the listed tags will not be parsed inside the tag. |
||
129 | */ |
||
130 | const ATTR_DISALLOW_PARENTS = 17; |
||
131 | |||
132 | /** |
||
133 | * Similar to, but very different from, require_children. |
||
134 | * If it is set the listed tags will not be parsed inside the tag. |
||
135 | */ |
||
136 | const ATTR_DISALLOW_CHILDREN = 18; |
||
137 | |||
138 | /** |
||
139 | * When ATTR_DISALLOW_PARENTS is used, this gets put before the tag. |
||
140 | */ |
||
141 | const ATTR_DISALLOW_BEFORE = 19; |
||
142 | |||
143 | /** |
||
144 | * * When ATTR_DISALLOW_PARENTS is used, this gets put after the tag. |
||
145 | */ |
||
146 | const ATTR_DISALLOW_AFTER = 20; |
||
147 | |||
148 | /** |
||
149 | * an array restricting what BBC can be in the parsed_equals parameter, if desired. |
||
150 | */ |
||
151 | const ATTR_PARSED_TAGS_ALLOWED = 21; |
||
152 | |||
153 | /** |
||
154 | * (bool) Turn uris like http://www.google.com in to links |
||
155 | */ |
||
156 | const ATTR_AUTOLINK = 22; |
||
157 | |||
158 | /** |
||
159 | * The length of the tag |
||
160 | */ |
||
161 | const ATTR_LENGTH = 23; |
||
162 | |||
163 | /** |
||
164 | * Whether the tag is disabled |
||
165 | */ |
||
166 | const ATTR_DISABLED = 24; |
||
167 | |||
168 | /** |
||
169 | * If the message contains a code with this, the message should not be cached |
||
170 | */ |
||
171 | const ATTR_NO_CACHE = 25; |
||
172 | |||
173 | /** [tag]parsed content[/tag] */ |
||
174 | const TYPE_PARSED_CONTENT = 0; |
||
175 | |||
176 | /** [tag=xyz]parsed content[/tag] */ |
||
177 | const TYPE_UNPARSED_EQUALS = 1; |
||
178 | |||
179 | /** [tag=parsed data]parsed content[/tag] */ |
||
180 | const TYPE_PARSED_EQUALS = 2; |
||
181 | |||
182 | /** [tag]unparsed content[/tag] */ |
||
183 | const TYPE_UNPARSED_CONTENT = 3; |
||
184 | |||
185 | /** [tag], [tag/], [tag /] */ |
||
186 | const TYPE_CLOSED = 4; |
||
187 | |||
188 | /** [tag=1,2,3]parsed content[/tag] */ |
||
189 | const TYPE_UNPARSED_COMMAS = 5; |
||
190 | |||
191 | /** [tag=1,2,3]unparsed content[/tag] */ |
||
192 | const TYPE_UNPARSED_COMMAS_CONTENT = 6; |
||
193 | |||
194 | /** [tag=...]unparsed content[/tag] */ |
||
195 | const TYPE_UNPARSED_EQUALS_CONTENT = 7; |
||
196 | |||
197 | /** [*] */ |
||
198 | const TYPE_ITEMCODE = 8; |
||
199 | |||
200 | /** a regular expression to validate and match the value. */ |
||
201 | const PARAM_ATTR_MATCH = 0; |
||
202 | /** true if the value should be quoted. */ |
||
203 | const PARAM_ATTR_QUOTED = 1; |
||
204 | /** callback to evaluate on the data, which is $data. */ |
||
205 | const PARAM_ATTR_VALIDATE = 2; |
||
206 | /** a string in which to replace $1 with the data. Either it or validate may be used, not both. */ |
||
207 | const PARAM_ATTR_VALUE = 3; |
||
208 | /** true if the parameter is optional. */ |
||
209 | const PARAM_ATTR_OPTIONAL = 4; |
||
210 | |||
211 | /** */ |
||
212 | const TRIM_NONE = 0; |
||
213 | /** */ |
||
214 | const TRIM_INSIDE = 1; |
||
215 | /** */ |
||
216 | const TRIM_OUTSIDE = 2; |
||
217 | /** */ |
||
218 | const TRIM_BOTH = 3; |
||
219 | |||
220 | // These are mainly for *ATTR_QUOTED since there are 3 options |
||
221 | const OPTIONAL = -1; |
||
222 | const NONE = 0; |
||
223 | const REQUIRED = 1; |
||
224 | |||
225 | /** |
||
226 | * An array of self::ATTR_* |
||
227 | * ATTR_TAG and ATTR_TYPE are required for every tag. |
||
228 | * The rest of the attributes depend on the type and other options. |
||
229 | */ |
||
230 | protected $bbc = array(); |
||
231 | protected $itemcodes = array(); |
||
232 | protected $additional_bbc = array(); |
||
233 | protected $disabled = array(); |
||
234 | protected $parsing_codes = array(); |
||
235 | |||
236 | /** |
||
237 | * Codes constructor. |
||
238 | * |
||
239 | * @param array $tags |
||
240 | * @param array $disabled |
||
241 | */ |
||
242 | 1 | public function __construct(array $tags = array(), array $disabled = array()) |
|
243 | { |
||
244 | 1 | $this->additional_bbc = $tags; |
|
245 | |||
246 | 1 | foreach ($disabled as $tag) |
|
247 | { |
||
248 | $this->disable($tag); |
||
249 | } |
||
250 | |||
251 | 1 | foreach ($tags as $tag) |
|
252 | { |
||
253 | $this->add($tag); |
||
254 | } |
||
255 | |||
256 | 1 | $this->bbc = $this->getDefault(); |
|
257 | 1 | } |
|
258 | |||
259 | /** |
||
260 | * Add a code |
||
261 | * |
||
262 | * @param array $code |
||
263 | */ |
||
264 | public function add(array $code) |
||
276 | |||
277 | /** |
||
278 | * Remove a BBC code from the render stack |
||
279 | * |
||
280 | * @param $tag |
||
281 | */ |
||
282 | public function remove($tag) |
||
283 | { |
||
284 | foreach ($this->bbc as $k => $v) |
||
285 | { |
||
286 | if ($tag === $v[self::ATTR_TAG]) |
||
287 | { |
||
288 | unset($this->bbc[$k]); |
||
289 | } |
||
290 | } |
||
291 | } |
||
292 | |||
293 | /** |
||
294 | * Load all of the default BBC codes |
||
295 | * |
||
296 | * @return mixed |
||
297 | */ |
||
298 | 4 | public function getDefault() |
|
299 | { |
||
300 | 1 | global $modSettings, $txt, $scripturl; |
|
301 | |||
302 | // This array can be arranged in any order. |
||
303 | 1 | return array_merge($this->bbc, array( |
|
304 | array( |
||
305 | 1 | self::ATTR_TAG => 'abbr', |
|
306 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
307 | 1 | self::ATTR_TEST => '([A-Za-z][A-Za-z0-9_\-\s&;]*)', |
|
308 | 1 | self::ATTR_BEFORE => '<abbr title="$1">', |
|
309 | 1 | self::ATTR_AFTER => '</abbr>', |
|
310 | 1 | self::ATTR_QUOTED => self::OPTIONAL, |
|
311 | 1 | self::ATTR_DISABLED_AFTER => ' ($1)', |
|
312 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
313 | 1 | self::ATTR_AUTOLINK => true, |
|
314 | 1 | self::ATTR_LENGTH => 4, |
|
315 | ), |
||
316 | array( |
||
317 | 1 | self::ATTR_TAG => 'anchor', |
|
318 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
319 | 1 | self::ATTR_TEST => '[#]?([A-Za-z][A-Za-z0-9_\-]*)', |
|
320 | 1 | self::ATTR_BEFORE => '<span id="post_$1">', |
|
321 | 1 | self::ATTR_AFTER => '</span>', |
|
322 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
323 | 1 | self::ATTR_AUTOLINK => true, |
|
324 | 1 | self::ATTR_LENGTH => 6, |
|
325 | ), |
||
326 | array( |
||
327 | 1 | self::ATTR_TAG => 'b', |
|
328 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
329 | 1 | self::ATTR_BEFORE => '<strong class="bbc_strong">', |
|
330 | 1 | self::ATTR_AFTER => '</strong>', |
|
331 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
332 | 1 | self::ATTR_AUTOLINK => true, |
|
333 | 1 | self::ATTR_LENGTH => 1, |
|
334 | ), |
||
335 | array( |
||
336 | 1 | self::ATTR_TAG => 'br', |
|
337 | 1 | self::ATTR_TYPE => self::TYPE_CLOSED, |
|
338 | 1 | self::ATTR_CONTENT => '<br />', |
|
339 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
340 | 1 | self::ATTR_AUTOLINK => false, |
|
341 | 1 | self::ATTR_LENGTH => 2, |
|
342 | ), |
||
343 | array( |
||
344 | 1 | self::ATTR_TAG => 'center', |
|
345 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
346 | 1 | self::ATTR_BEFORE => '<div class="centertext">', |
|
347 | 1 | self::ATTR_AFTER => '</div>', |
|
348 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
349 | 1 | self::ATTR_AUTOLINK => true, |
|
350 | 1 | self::ATTR_LENGTH => 6, |
|
351 | ), |
||
352 | array( |
||
353 | 1 | self::ATTR_TAG => 'code', |
|
354 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT, |
|
355 | 1 | self::ATTR_CONTENT => '<div class="codeheader">' . $txt['code'] . ': <a href="#" onclick="return elkSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><pre class="bbc_code prettyprint">$1</pre>', |
|
356 | 3 | self::ATTR_VALIDATE => $this->isDisabled('code') ? null : function (&$tag, &$data) { |
|
357 | 2 | $data = tabToHtmlTab(strtr($data, array('[' => '[', ']' => ']'))); |
|
358 | 3 | }, |
|
359 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
360 | 1 | self::ATTR_AUTOLINK => false, |
|
361 | 1 | self::ATTR_LENGTH => 4, |
|
362 | ), |
||
363 | array( |
||
364 | 1 | self::ATTR_TAG => 'code', |
|
365 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS_CONTENT, |
|
366 | 1 | self::ATTR_CONTENT => '<div class="codeheader">' . $txt['code'] . ': ($2) <a href="#" onclick="return elkSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><pre class="bbc_code prettyprint">$1</pre>', |
|
367 | 2 | self::ATTR_VALIDATE => $this->isDisabled('code') ? null : function (&$tag, &$data) { |
|
368 | 1 | $data[0] = tabToHtmlTab(strtr($data[0], array('[' => '[', ']' => ']'))); |
|
369 | 2 | }, |
|
370 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
371 | 1 | self::ATTR_AUTOLINK => false, |
|
372 | 1 | self::ATTR_LENGTH => 4, |
|
373 | ), |
||
374 | array( |
||
375 | 1 | self::ATTR_TAG => 'color', |
|
376 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
377 | 1 | self::ATTR_TEST => '(#[\da-fA-F]{3}|#[\da-fA-F]{6}|[A-Za-z]{1,20}|rgb\((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\s?,\s?){2}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\))', |
|
378 | 1 | self::ATTR_BEFORE => '<span style="color: $1;" class="bbc_color">', |
|
379 | 1 | self::ATTR_AFTER => '</span>', |
|
380 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
381 | 1 | self::ATTR_AUTOLINK => true, |
|
382 | 1 | self::ATTR_LENGTH => 5, |
|
383 | ), |
||
384 | array( |
||
385 | 1 | self::ATTR_TAG => 'email', |
|
386 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT, |
|
387 | 1 | self::ATTR_CONTENT => '<a href="mailto:$1" class="bbc_email">$1</a>', |
|
388 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
389 | 1 | self::ATTR_AUTOLINK => false, |
|
390 | 1 | self::ATTR_LENGTH => 5, |
|
391 | ), |
||
392 | array( |
||
393 | 1 | self::ATTR_TAG => 'email', |
|
394 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
395 | 1 | self::ATTR_BEFORE => '<a href="mailto:$1" class="bbc_email">', |
|
396 | 1 | self::ATTR_AFTER => '</a>', |
|
397 | 1 | self::ATTR_DISALLOW_CHILDREN => array( |
|
398 | 'email' => 1, |
||
399 | 'url' => 1, |
||
400 | 'iurl' => 1, |
||
401 | ), |
||
402 | 1 | self::ATTR_DISABLED_AFTER => ' ($1)', |
|
403 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
404 | 1 | self::ATTR_AUTOLINK => false, |
|
405 | 1 | self::ATTR_LENGTH => 5, |
|
406 | ), |
||
407 | array( |
||
408 | 1 | self::ATTR_TAG => 'footnote', |
|
409 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
410 | 1 | self::ATTR_BEFORE => '<sup class="bbc_footnotes">%fn%', |
|
411 | 1 | self::ATTR_AFTER => '%fn%</sup>', |
|
412 | 1 | self::ATTR_TRIM => self::TRIM_NONE, |
|
413 | 1 | self::ATTR_DISALLOW_PARENTS => array( |
|
414 | 'footnote' => 1, |
||
415 | 'code' => 1, |
||
416 | 'anchor' => 1, |
||
417 | 'url' => 1, |
||
418 | 'iurl' => 1, |
||
419 | ), |
||
420 | 1 | self::ATTR_DISALLOW_BEFORE => '', |
|
421 | 1 | self::ATTR_DISALLOW_AFTER => '', |
|
422 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
423 | 1 | self::ATTR_AUTOLINK => true, |
|
424 | 1 | self::ATTR_LENGTH => 8, |
|
425 | ), |
||
426 | array( |
||
427 | 1 | self::ATTR_TAG => 'font', |
|
428 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
429 | 1 | self::ATTR_TEST => '[A-Za-z0-9_,\-\s]+?', |
|
430 | 1 | self::ATTR_BEFORE => '<span style="font-family: $1;" class="bbc_font">', |
|
431 | 1 | self::ATTR_AFTER => '</span>', |
|
432 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
433 | 1 | self::ATTR_AUTOLINK => true, |
|
434 | 1 | self::ATTR_LENGTH => 4, |
|
435 | ), |
||
436 | array( |
||
437 | 1 | self::ATTR_TAG => 'hr', |
|
438 | 1 | self::ATTR_TYPE => self::TYPE_CLOSED, |
|
439 | 1 | self::ATTR_CONTENT => '<hr />', |
|
440 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
441 | 1 | self::ATTR_AUTOLINK => false, |
|
442 | 1 | self::ATTR_LENGTH => 2, |
|
443 | ), |
||
444 | array( |
||
445 | 1 | self::ATTR_TAG => 'i', |
|
446 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
447 | 1 | self::ATTR_BEFORE => '<em>', |
|
448 | 1 | self::ATTR_AFTER => '</em>', |
|
449 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
450 | 1 | self::ATTR_AUTOLINK => true, |
|
451 | 1 | self::ATTR_LENGTH => 1, |
|
452 | ), |
||
453 | array( |
||
454 | 1 | self::ATTR_TAG => 'img', |
|
455 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT, |
|
456 | 1 | self::ATTR_PARAM => array( |
|
457 | 'width' => array( |
||
458 | 1 | self::PARAM_ATTR_VALUE => 'width:100%;max-width:$1px;', |
|
459 | 1 | self::PARAM_ATTR_MATCH => '(\d+)', |
|
460 | 1 | self::PARAM_ATTR_OPTIONAL => true, |
|
461 | ), |
||
462 | 'height' => array( |
||
463 | 1 | self::PARAM_ATTR_VALUE => 'max-height:$1px;', |
|
464 | 1 | self::PARAM_ATTR_MATCH => '(\d+)', |
|
465 | 1 | self::PARAM_ATTR_OPTIONAL => true, |
|
466 | ), |
||
467 | 'title' => array( |
||
468 | 1 | self::PARAM_ATTR_MATCH => '(.+?)', |
|
469 | 1 | self::PARAM_ATTR_OPTIONAL => true, |
|
470 | ), |
||
471 | 'alt' => array( |
||
472 | 1 | self::PARAM_ATTR_MATCH => '(.+?)', |
|
473 | 1 | self::PARAM_ATTR_OPTIONAL => true, |
|
474 | ), |
||
475 | ), |
||
476 | 1 | self::ATTR_CONTENT => '<img src="$1" title="{title}" alt="{alt}" style="{width}{height}" class="bbc_img resized" />', |
|
477 | 2 | self::ATTR_VALIDATE => function (&$tag, &$data) { |
|
478 | 1 | $data = addProtocol($data); |
|
479 | 2 | }, |
|
480 | 1 | self::ATTR_DISABLED_CONTENT => '($1)', |
|
481 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
482 | 1 | self::ATTR_AUTOLINK => false, |
|
483 | 1 | self::ATTR_LENGTH => 3, |
|
484 | ), |
||
485 | array( |
||
486 | 1 | self::ATTR_TAG => 'img', |
|
487 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT, |
|
488 | 1 | self::ATTR_CONTENT => '<img src="$1" alt="" class="bbc_img" />', |
|
489 | 2 | self::ATTR_VALIDATE => function (&$tag, &$data) { |
|
490 | 1 | $data = addProtocol($data); |
|
491 | 2 | }, |
|
492 | 1 | self::ATTR_DISABLED_CONTENT => '($1)', |
|
493 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
494 | 1 | self::ATTR_AUTOLINK => false, |
|
495 | 1 | self::ATTR_LENGTH => 3, |
|
496 | ), |
||
497 | array( |
||
498 | 1 | self::ATTR_TAG => 'iurl', |
|
499 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT, |
|
500 | 1 | self::ATTR_CONTENT => '<a href="$1" class="bbc_link">$1</a>', |
|
501 | 1 | self::ATTR_VALIDATE => function (&$tag, &$data) { |
|
502 | //$data = removeBr($data); |
||
503 | $data = addProtocol($data); |
||
504 | 1 | }, |
|
505 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
506 | 1 | self::ATTR_AUTOLINK => false, |
|
507 | 1 | self::ATTR_LENGTH => 4, |
|
508 | ), |
||
509 | array( |
||
510 | 1 | self::ATTR_TAG => 'iurl', |
|
511 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
512 | 1 | self::ATTR_BEFORE => '<a href="$1" class="bbc_link">', |
|
513 | 1 | self::ATTR_AFTER => '</a>', |
|
514 | 2 | self::ATTR_VALIDATE => function (&$tag, &$data) { |
|
515 | 1 | if ($data[0] === '#') |
|
516 | { |
||
517 | $data = '#post_' . substr($data, 1); |
||
518 | } |
||
519 | else |
||
520 | { |
||
521 | 1 | $data = addProtocol($data); |
|
522 | } |
||
523 | 2 | }, |
|
524 | 1 | self::ATTR_DISALLOW_CHILDREN => array( |
|
525 | 'email' => 1, |
||
526 | 'url' => 1, |
||
527 | 'iurl' => 1, |
||
528 | ), |
||
529 | 1 | self::ATTR_DISABLED_AFTER => ' ($1)', |
|
530 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
531 | 1 | self::ATTR_AUTOLINK => false, |
|
532 | 1 | self::ATTR_LENGTH => 4, |
|
533 | ), |
||
534 | array( |
||
535 | 1 | self::ATTR_TAG => 'left', |
|
536 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
537 | 1 | self::ATTR_BEFORE => '<div style="text-align: left;">', |
|
538 | 1 | self::ATTR_AFTER => '</div>', |
|
539 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
540 | 1 | self::ATTR_AUTOLINK => true, |
|
541 | 1 | self::ATTR_LENGTH => 4, |
|
542 | ), |
||
543 | array( |
||
544 | 1 | self::ATTR_TAG => 'li', |
|
545 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
546 | 1 | self::ATTR_BEFORE => '<li>', |
|
547 | 1 | self::ATTR_AFTER => '</li>', |
|
548 | 1 | self::ATTR_TRIM => self::TRIM_OUTSIDE, |
|
549 | 1 | self::ATTR_REQUIRE_PARENTS => array( |
|
550 | 'list' => 1, |
||
551 | ), |
||
552 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
553 | 1 | self::ATTR_DISABLED_BEFORE => '', |
|
554 | 1 | self::ATTR_DISABLED_AFTER => '<br />', |
|
555 | 1 | self::ATTR_AUTOLINK => true, |
|
556 | 1 | self::ATTR_LENGTH => 2, |
|
557 | ), |
||
558 | array( |
||
559 | 1 | self::ATTR_TAG => 'list', |
|
560 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
561 | 1 | self::ATTR_BEFORE => '<ul class="bbc_list">', |
|
562 | 1 | self::ATTR_AFTER => '</ul>', |
|
563 | 1 | self::ATTR_TRIM => self::TRIM_INSIDE, |
|
564 | 1 | self::ATTR_REQUIRE_CHILDREN => array( |
|
565 | 'li' => 1, |
||
566 | 'list' => 1, |
||
567 | ), |
||
568 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
569 | 1 | self::ATTR_AUTOLINK => true, |
|
570 | 1 | self::ATTR_LENGTH => 4, |
|
571 | ), |
||
572 | array( |
||
573 | 1 | self::ATTR_TAG => 'list', |
|
574 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
575 | 1 | self::ATTR_PARAM => array( |
|
576 | 'type' => array( |
||
577 | 1 | self::PARAM_ATTR_MATCH => '(none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha)', |
|
578 | ), |
||
579 | ), |
||
580 | 1 | self::ATTR_BEFORE => '<ul class="bbc_list" style="list-style-type: {type};">', |
|
581 | 1 | self::ATTR_AFTER => '</ul>', |
|
582 | 1 | self::ATTR_TRIM => self::TRIM_INSIDE, |
|
583 | 1 | self::ATTR_REQUIRE_CHILDREN => array( |
|
584 | 'li' => 1, |
||
585 | ), |
||
586 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
587 | 1 | self::ATTR_AUTOLINK => true, |
|
588 | 1 | self::ATTR_LENGTH => 4, |
|
589 | ), |
||
590 | array( |
||
591 | 1 | self::ATTR_TAG => 'me', |
|
592 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
593 | 1 | self::ATTR_BEFORE => '<div class="meaction"> $1 ', |
|
594 | 1 | self::ATTR_AFTER => '</div>', |
|
595 | 1 | self::ATTR_QUOTED => self::OPTIONAL, |
|
596 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
597 | 1 | self::ATTR_DISABLED_BEFORE => '/me ', |
|
598 | 1 | self::ATTR_DISABLED_AFTER => '<br />', |
|
599 | 1 | self::ATTR_AUTOLINK => true, |
|
600 | 1 | self::ATTR_LENGTH => 2, |
|
601 | ), |
||
602 | array( |
||
603 | 1 | self::ATTR_TAG => 'member', |
|
604 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
605 | 1 | self::ATTR_TEST => '\d*', |
|
606 | 1 | self::ATTR_BEFORE => '<span class="bbc_mention"><a href="' . $scripturl . '?action=profile;u=$1">@', |
|
607 | 1 | self::ATTR_AFTER => '</a></span>', |
|
608 | 1 | self::ATTR_DISABLED_BEFORE => '@', |
|
609 | 1 | self::ATTR_DISABLED_AFTER => '', |
|
610 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
611 | 1 | self::ATTR_AUTOLINK => true, |
|
612 | 1 | self::ATTR_LENGTH => 6, |
|
613 | ), |
||
614 | array( |
||
615 | 1 | self::ATTR_TAG => 'nobbc', |
|
616 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT, |
|
617 | 1 | self::ATTR_CONTENT => '$1', |
|
618 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
619 | 1 | self::ATTR_AUTOLINK => true, |
|
620 | 1 | self::ATTR_LENGTH => 5, |
|
621 | ), |
||
622 | array( |
||
623 | 1 | self::ATTR_TAG => 'pre', |
|
624 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
625 | 1 | self::ATTR_BEFORE => '<pre class="bbc_pre">', |
|
626 | 1 | self::ATTR_AFTER => '</pre>', |
|
627 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
628 | 1 | self::ATTR_AUTOLINK => true, |
|
629 | 1 | self::ATTR_LENGTH => 3, |
|
630 | ), |
||
631 | array( |
||
632 | 1 | self::ATTR_TAG => 'quote', |
|
633 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
634 | 1 | self::ATTR_BEFORE => '<div class="quoteheader">' . $txt['quote'] . '</div><blockquote>', |
|
635 | 1 | self::ATTR_AFTER => '</blockquote>', |
|
636 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
637 | 1 | self::ATTR_AUTOLINK => true, |
|
638 | 1 | self::ATTR_LENGTH => 5, |
|
639 | ), |
||
640 | array( |
||
641 | 1 | self::ATTR_TAG => 'quote', |
|
642 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
643 | 1 | self::ATTR_PARAM => array( |
|
644 | 'author' => array( |
||
645 | 1 | self::PARAM_ATTR_MATCH => '([^<>&"\'=\\\\]{1,192}?)', |
|
646 | 1 | self::PARAM_ATTR_QUOTED => self::OPTIONAL, |
|
647 | ), |
||
648 | ), |
||
649 | 1 | self::ATTR_BEFORE => '<div class="quoteheader">' . $txt['quote_from'] . ': {author}</div><blockquote>', |
|
650 | 1 | self::ATTR_AFTER => '</blockquote>', |
|
651 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
652 | 1 | self::ATTR_AUTOLINK => true, |
|
653 | 1 | self::ATTR_LENGTH => 5, |
|
654 | ), |
||
655 | array( |
||
656 | 1 | self::ATTR_TAG => 'quote', |
|
657 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_EQUALS, |
|
658 | 1 | self::ATTR_BEFORE => '<div class="quoteheader">' . $txt['quote_from'] . ': $1</div><blockquote>', |
|
659 | 1 | self::ATTR_AFTER => '</blockquote>', |
|
660 | 1 | self::ATTR_QUOTED => self::OPTIONAL, |
|
661 | 1 | self::ATTR_PARSED_TAGS_ALLOWED => array( |
|
662 | 'url', |
||
663 | 'iurl', |
||
664 | ), |
||
665 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
666 | 1 | self::ATTR_AUTOLINK => true, |
|
667 | 1 | self::ATTR_LENGTH => 5, |
|
668 | ), |
||
669 | array( |
||
670 | 1 | self::ATTR_TAG => 'quote', |
|
671 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
672 | 1 | self::ATTR_PARAM => array( |
|
673 | 'author' => array( |
||
674 | 1 | self::PARAM_ATTR_MATCH => '([^<>&"\'=\\\\]{1,192}?)' |
|
675 | ), |
||
676 | 'link' => array( |
||
677 | 1 | self::PARAM_ATTR_MATCH => '(?:board=\d+;)?((?:topic|threadid)=[\dmsg#\./]{1,40}(?:;start=[\dmsg#\./]{1,40})?|msg=\d{1,40}|action=profile;u=\d+)', |
|
678 | ), |
||
679 | 'date' => array( |
||
680 | 1 | self::PARAM_ATTR_MATCH => '(\d+)', |
|
681 | 1 | self::PARAM_ATTR_VALIDATE => 'htmlTime', |
|
682 | ), |
||
683 | ), |
||
684 | 1 | self::ATTR_BEFORE => '<div class="quoteheader"><a href="' . $scripturl . '?{link}">' . $txt['quote_from'] . ': {author} ' . ($modSettings['todayMod'] == 3 ? ' - ' : $txt['search_on']) . ' {date}</a></div><blockquote>', |
|
685 | 1 | self::ATTR_AFTER => '</blockquote>', |
|
686 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
687 | 1 | self::ATTR_AUTOLINK => true, |
|
688 | 1 | self::ATTR_LENGTH => 5, |
|
689 | ), |
||
690 | array( |
||
691 | 1 | self::ATTR_TAG => 'quote', |
|
692 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
693 | 1 | self::ATTR_PARAM => array( |
|
694 | 'author' => array( |
||
695 | 1 | self::PARAM_ATTR_MATCH => '([^<>&"\'=\\\\]{1,192}?)' |
|
696 | ), |
||
697 | ), |
||
698 | 1 | self::ATTR_BEFORE => '<div class="quoteheader">' . $txt['quote_from'] . ': {author}</div><blockquote>', |
|
699 | 1 | self::ATTR_AFTER => '</blockquote>', |
|
700 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
701 | 1 | self::ATTR_AUTOLINK => true, |
|
702 | 1 | self::ATTR_LENGTH => 5, |
|
703 | ), |
||
704 | array( |
||
705 | 1 | self::ATTR_TAG => 'right', |
|
706 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
707 | 1 | self::ATTR_BEFORE => '<div style="text-align: right;">', |
|
708 | 1 | self::ATTR_AFTER => '</div>', |
|
709 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
710 | 1 | self::ATTR_AUTOLINK => true, |
|
711 | 1 | self::ATTR_LENGTH => 5, |
|
712 | ), |
||
713 | array( |
||
714 | 1 | self::ATTR_TAG => 's', |
|
715 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
716 | 1 | self::ATTR_BEFORE => '<del>', |
|
717 | 1 | self::ATTR_AFTER => '</del>', |
|
718 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
719 | 1 | self::ATTR_AUTOLINK => true, |
|
720 | 1 | self::ATTR_LENGTH => 1, |
|
721 | ), |
||
722 | array( |
||
723 | 1 | self::ATTR_TAG => 'size', |
|
724 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
725 | 1 | self::ATTR_TEST => '[1-7]{1}', |
|
726 | 1 | self::ATTR_BEFORE => '<span style="font-size: $1;" class="bbc_size">', |
|
727 | 1 | self::ATTR_AFTER => '</span>', |
|
728 | 2 | self::ATTR_VALIDATE => function (&$tag, &$data) { |
|
729 | 1 | $sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95); |
|
730 | 1 | $data = $sizes[(int) $data] . 'em'; |
|
731 | 2 | }, |
|
732 | 1 | self::ATTR_DISALLOW_PARENTS => array( |
|
733 | 'size' => 1, |
||
734 | ), |
||
735 | 1 | self::ATTR_DISALLOW_BEFORE => '<span>', |
|
736 | 1 | self::ATTR_DISALLOW_AFTER => '</span>', |
|
737 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
738 | 1 | self::ATTR_AUTOLINK => true, |
|
739 | 1 | self::ATTR_LENGTH => 4, |
|
740 | ), |
||
741 | array( |
||
742 | 1 | self::ATTR_TAG => 'size', |
|
743 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
744 | 1 | self::ATTR_TEST => '([1-9][\d]?p[xt]|small(?:er)?|large[r]?|x[x]?-(?:small|large)|medium|(0\.[1-9]|[1-9](\.[\d][\d]?)?)?em)', |
|
745 | 1 | self::ATTR_BEFORE => '<span style="font-size: $1;" class="bbc_size">', |
|
746 | 1 | self::ATTR_AFTER => '</span>', |
|
747 | 1 | self::ATTR_DISALLOW_PARENTS => array('size' => 1), |
|
748 | 1 | self::ATTR_DISALLOW_BEFORE => '<span>', |
|
749 | 1 | self::ATTR_DISALLOW_AFTER => '</span>', |
|
750 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
751 | 1 | self::ATTR_AUTOLINK => true, |
|
752 | 1 | self::ATTR_LENGTH => 4, |
|
753 | ), |
||
754 | array( |
||
755 | 1 | self::ATTR_TAG => 'spoiler', |
|
756 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
757 | 1 | self::ATTR_BEFORE => '<span class="spoilerheader">' . $txt['spoiler'] . '</span><div class="spoiler"><div class="bbc_spoiler" style="display: none;">', |
|
758 | 1 | self::ATTR_AFTER => '</div></div>', |
|
759 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
760 | 1 | self::ATTR_AUTOLINK => true, |
|
761 | 1 | self::ATTR_LENGTH => 7, |
|
762 | ), |
||
763 | array( |
||
764 | 1 | self::ATTR_TAG => 'sub', |
|
765 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
766 | 1 | self::ATTR_BEFORE => '<sub>', |
|
767 | 1 | self::ATTR_AFTER => '</sub>', |
|
768 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
769 | 1 | self::ATTR_AUTOLINK => true, |
|
770 | 1 | self::ATTR_LENGTH => 3, |
|
771 | ), |
||
772 | array( |
||
773 | 1 | self::ATTR_TAG => 'sup', |
|
774 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
775 | 1 | self::ATTR_BEFORE => '<sup>', |
|
776 | 1 | self::ATTR_AFTER => '</sup>', |
|
777 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
778 | 1 | self::ATTR_AUTOLINK => true, |
|
779 | 1 | self::ATTR_LENGTH => 3, |
|
780 | ), |
||
781 | array( |
||
782 | 1 | self::ATTR_TAG => 'table', |
|
783 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
784 | 1 | self::ATTR_BEFORE => '<div class="bbc_table_container"><table class="bbc_table">', |
|
785 | 1 | self::ATTR_AFTER => '</table></div>', |
|
786 | 1 | self::ATTR_TRIM => self::TRIM_INSIDE, |
|
787 | 1 | self::ATTR_REQUIRE_CHILDREN => array( |
|
788 | 'tr' => 1, |
||
789 | ), |
||
790 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
791 | 1 | self::ATTR_AUTOLINK => true, |
|
792 | 1 | self::ATTR_LENGTH => 5, |
|
793 | ), |
||
794 | array( |
||
795 | 1 | self::ATTR_TAG => 'td', |
|
796 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
797 | 1 | self::ATTR_BEFORE => '<td>', |
|
798 | 1 | self::ATTR_AFTER => '</td>', |
|
799 | 1 | self::ATTR_REQUIRE_PARENTS => array( |
|
800 | 'tr' => 1, |
||
801 | ), |
||
802 | 1 | self::ATTR_TRIM => self::TRIM_OUTSIDE, |
|
803 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
804 | 1 | self::ATTR_DISABLED_BEFORE => '', |
|
805 | 1 | self::ATTR_DISABLED_AFTER => '', |
|
806 | 1 | self::ATTR_AUTOLINK => true, |
|
807 | 1 | self::ATTR_LENGTH => 2, |
|
808 | ), |
||
809 | array( |
||
810 | 1 | self::ATTR_TAG => 'th', |
|
811 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
812 | 1 | self::ATTR_BEFORE => '<th>', |
|
813 | 1 | self::ATTR_AFTER => '</th>', |
|
814 | 1 | self::ATTR_REQUIRE_PARENTS => array( |
|
815 | 'tr' => 1, |
||
816 | ), |
||
817 | 1 | self::ATTR_TRIM => self::TRIM_OUTSIDE, |
|
818 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
819 | 1 | self::ATTR_DISABLED_BEFORE => '', |
|
820 | 1 | self::ATTR_DISABLED_AFTER => '', |
|
821 | 1 | self::ATTR_AUTOLINK => true, |
|
822 | 1 | self::ATTR_LENGTH => 2, |
|
823 | ), |
||
824 | array( |
||
825 | 1 | self::ATTR_TAG => 'tr', |
|
826 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
827 | 1 | self::ATTR_BEFORE => '<tr>', |
|
828 | 1 | self::ATTR_AFTER => '</tr>', |
|
829 | 1 | self::ATTR_REQUIRE_PARENTS => array( |
|
830 | 'table' => 1, |
||
831 | ), |
||
832 | 1 | self::ATTR_REQUIRE_CHILDREN => array( |
|
833 | 'td' => 1, |
||
834 | 'th' => 1, |
||
835 | ), |
||
836 | 1 | self::ATTR_TRIM => self::TRIM_BOTH, |
|
837 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
838 | 1 | self::ATTR_DISABLED_BEFORE => '', |
|
839 | 1 | self::ATTR_DISABLED_AFTER => '', |
|
840 | 1 | self::ATTR_AUTOLINK => true, |
|
841 | 1 | self::ATTR_LENGTH => 2, |
|
842 | ), |
||
843 | array( |
||
844 | 1 | self::ATTR_TAG => 'tt', |
|
845 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
846 | 1 | self::ATTR_BEFORE => '<span class="bbc_tt">', |
|
847 | 1 | self::ATTR_AFTER => '</span>', |
|
848 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
849 | 1 | self::ATTR_AUTOLINK => true, |
|
850 | 1 | self::ATTR_LENGTH => 2, |
|
851 | ), |
||
852 | array( |
||
853 | 1 | self::ATTR_TAG => 'u', |
|
854 | 1 | self::ATTR_TYPE => self::TYPE_PARSED_CONTENT, |
|
855 | 1 | self::ATTR_BEFORE => '<span class="bbc_u">', |
|
856 | 1 | self::ATTR_AFTER => '</span>', |
|
857 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
858 | 1 | self::ATTR_AUTOLINK => true, |
|
859 | 1 | self::ATTR_LENGTH => 1, |
|
860 | ), |
||
861 | array( |
||
862 | 1 | self::ATTR_TAG => 'url', |
|
863 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT, |
|
864 | 1 | self::ATTR_CONTENT => '<a href="$1" class="bbc_link" target="_blank">$1</a>', |
|
865 | 2 | self::ATTR_VALIDATE => function (&$tag, &$data) { |
|
866 | 1 | $data = addProtocol($data); |
|
867 | 2 | }, |
|
868 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
869 | 1 | self::ATTR_AUTOLINK => false, |
|
870 | 1 | self::ATTR_LENGTH => 3, |
|
871 | ), |
||
872 | array( |
||
873 | 1 | self::ATTR_TAG => 'url', |
|
874 | 1 | self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS, |
|
875 | 1 | self::ATTR_BEFORE => '<a href="$1" class="bbc_link" target="_blank">', |
|
876 | 1 | self::ATTR_AFTER => '</a>', |
|
877 | 4 | self::ATTR_VALIDATE => function (&$tag, &$data) { |
|
878 | 3 | $data = addProtocol($data); |
|
879 | 4 | }, |
|
880 | 1 | self::ATTR_DISALLOW_CHILDREN => array( |
|
881 | 'email' => 1, |
||
882 | 'url' => 1, |
||
883 | 'iurl' => 1, |
||
884 | ), |
||
885 | 1 | self::ATTR_DISABLED_AFTER => ' ($1)', |
|
886 | 1 | self::ATTR_BLOCK_LEVEL => false, |
|
887 | 1 | self::ATTR_AUTOLINK => false, |
|
888 | 1 | self::ATTR_LENGTH => 3, |
|
889 | ), |
||
890 | )); |
||
891 | } |
||
892 | |||
893 | /** |
||
894 | * Returns the item codes array, used for simple lists, e.g. [*] |
||
895 | * |
||
896 | * @return array |
||
897 | */ |
||
898 | 2 | public function getItemCodes() |
|
899 | { |
||
900 | $item_codes = array( |
||
901 | 2 | '*' => 'disc', |
|
902 | '@' => 'disc', |
||
903 | '+' => 'square', |
||
904 | 'x' => 'square', |
||
905 | '#' => 'decimal', |
||
906 | '0' => 'decimal', |
||
907 | 'o' => 'circle', |
||
908 | 'O' => 'circle', |
||
909 | ); |
||
910 | |||
911 | // Want to add some more ? |
||
912 | 2 | call_integration_hook('integrate_item_codes', array(&$item_codes)); |
|
913 | |||
914 | 2 | return $item_codes; |
|
915 | } |
||
916 | |||
917 | /** |
||
918 | * Return the current Default BBC codes and those added by modifications |
||
919 | * |
||
920 | * @return array|mixed |
||
921 | */ |
||
922 | public function getCodes() |
||
923 | { |
||
924 | return $this->bbc; |
||
925 | } |
||
926 | |||
927 | /** |
||
928 | * Returns an array of installed bbc codes grouped by attr type e.g. quote[0], quote[1] |
||
929 | * |
||
930 | * @return array |
||
931 | */ |
||
932 | public function getCodesGroupedByTag() |
||
947 | |||
948 | /** |
||
949 | * Return the list of BBC tags, like b, i, spoiler |
||
950 | * |
||
951 | * @return array |
||
952 | */ |
||
953 | 2 | public function getTags() |
|
954 | { |
||
955 | 2 | $tags = array(); |
|
956 | 2 | foreach ($this->bbc as $tag) |
|
957 | { |
||
958 | 2 | $tags[$tag[self::ATTR_TAG]] = $tag[self::ATTR_TAG]; |
|
959 | } |
||
960 | |||
961 | 2 | return $tags; |
|
962 | } |
||
963 | |||
964 | /** |
||
965 | * @todo besides the itemcodes (just add a arg $with_itemcodes), this way should be standard and saved like that. |
||
966 | * Even, just remove the itemcodes when needed |
||
967 | * |
||
968 | * @return array |
||
969 | */ |
||
970 | 2 | public function getForParsing() |
|
971 | { |
||
972 | 2 | $bbc = $this->bbc; |
|
973 | 2 | $item_codes = $this->getItemCodes(); |
|
974 | 2 | call_integration_hook('bbc_codes_parsing', array(&$bbc, &$item_codes)); |
|
975 | |||
976 | 2 | if (!$this->isDisabled('li') && !$this->isDisabled('list')) |
|
977 | { |
||
978 | 1 | foreach ($item_codes as $c => $dummy) |
|
979 | { |
||
980 | // Skip anything "bad" |
||
981 | 1 | if (!is_string($c) || (is_string($c) && trim($c) === '')) |
|
982 | { |
||
983 | 1 | continue; |
|
984 | } |
||
985 | |||
986 | 1 | $bbc[$c] = $this->getItemCodeTag($c); |
|
987 | } |
||
988 | } |
||
989 | |||
990 | 2 | $return = array(); |
|
991 | |||
992 | // Find the first letter of the tag faster |
||
993 | 2 | foreach ($bbc as &$code) |
|
994 | { |
||
995 | 2 | $return[$code[self::ATTR_TAG][0]][] = $code; |
|
996 | } |
||
997 | |||
998 | 2 | return $return; |
|
999 | } |
||
1000 | |||
1001 | /** |
||
1002 | * Returns the first letter of all valid bbc codes for the parser |
||
1003 | * |
||
1004 | * @todo not used |
||
1005 | * |
||
1006 | * @return $this |
||
1007 | */ |
||
1008 | public function setParsingCodes() |
||
1014 | |||
1015 | /** |
||
1016 | * Return if the found code [X is possibly a valid one by checking |
||
1017 | * if we have a code that begins with X |
||
1018 | * |
||
1019 | * @todo not used |
||
1020 | * |
||
1021 | * @param $char |
||
1022 | * |
||
1023 | * @return bool |
||
1024 | */ |
||
1025 | public function hasChar($char) |
||
1029 | |||
1030 | /** |
||
1031 | * Get BCC codes by character start |
||
1032 | * |
||
1033 | * @todo not used |
||
1034 | * |
||
1035 | * @param $char |
||
1036 | * |
||
1037 | * @return mixed |
||
1038 | */ |
||
1039 | public function getCodesByChar($char) |
||
1043 | |||
1044 | /** |
||
1045 | * Generates item code tags |
||
1046 | * |
||
1047 | * @param $code |
||
1048 | * |
||
1049 | * @return array |
||
1050 | */ |
||
1051 | 1 | protected function getItemCodeTag($code) |
|
1052 | { |
||
1053 | return array( |
||
1054 | 1 | self::ATTR_TAG => $code, |
|
1055 | 1 | self::ATTR_TYPE => self::TYPE_ITEMCODE, |
|
1056 | 1 | self::ATTR_BLOCK_LEVEL => true, |
|
1057 | 1 | self::ATTR_LENGTH => 1, |
|
1058 | ); |
||
1059 | } |
||
1060 | |||
1061 | /** |
||
1062 | * Disables certain tags when we are going to print |
||
1063 | * |
||
1064 | * @return $this |
||
1065 | */ |
||
1066 | public function setForPrinting() |
||
1067 | { |
||
1068 | // Colors can't well be displayed... supposed to be black and white. |
||
1069 | $this->disable('color'); |
||
1070 | $this->disable('me'); |
||
1071 | |||
1072 | // Links are useless on paper... just show the link. |
||
1073 | $this->disable('url'); |
||
1074 | $this->disable('iurl'); |
||
1075 | $this->disable('email'); |
||
1076 | |||
1077 | // @todo Change maybe? |
||
1078 | if (!isset($_GET['images'])) |
||
1079 | { |
||
1080 | $this->disable('img'); |
||
1081 | } |
||
1082 | |||
1083 | // @todo Interface/setting to add more? |
||
1084 | call_integration_hook('integrate_bbc_set_printing', array($this)); |
||
1085 | |||
1086 | return $this; |
||
1087 | } |
||
1088 | |||
1089 | /** |
||
1090 | * Return if a tag is enable |
||
1091 | * |
||
1092 | * @param string $tag |
||
1093 | * |
||
1094 | * @return bool |
||
1095 | */ |
||
1096 | 4 | public function isDisabled($tag) |
|
1100 | |||
1101 | /** |
||
1102 | * If BBC Parsing is enabled |
||
1103 | * |
||
1104 | * @return array |
||
1105 | */ |
||
1106 | 3 | public function getDisabled() |
|
1110 | |||
1111 | /** |
||
1112 | * Disable a tag from parsing |
||
1113 | * |
||
1114 | * @param $tag |
||
1115 | * |
||
1116 | * @return bool |
||
1117 | */ |
||
1118 | public function disable($tag) |
||
1124 | |||
1125 | /** |
||
1126 | * Restore a disabled tag |
||
1127 | * |
||
1128 | * @param $tag |
||
1129 | * |
||
1130 | * @return bool |
||
1131 | */ |
||
1132 | public function restore($tag) |
||
1141 | |||
1142 | /** |
||
1143 | * Set the tags that will be parsed |
||
1144 | * |
||
1145 | * @param $parse_tags |
||
1146 | */ |
||
1147 | 1 | public function setParsedTags($parse_tags) |
|
1160 | } |
||
1161 |