Completed
Pull Request — development (#2329)
by Joshua
10:12
created

Codes::getDefault()   D

Complexity

Conditions 17
Paths 8

Size

Total Lines 600
Code Lines 498

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 500
CRAP Score 17.0576

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 600
ccs 500
cts 531
cp 0.9416
rs 4.8362
c 1
b 0
f 0
cc 17
eloc 498
nc 8
nop 0
crap 17.0576

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 *
5
 * @name      ElkArte Forum
6
 * @copyright ElkArte Forum contributors
7
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
8
 *
9
 * This software is a derived product, based on:
10
 *
11
 * Simple Machines Forum (SMF)
12
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
13
 * license:		BSD, See included LICENSE.TXT for terms and conditions.
14
 *
15
 *
16
 */
17
18
namespace BBC;
19
20
// @todo add attribute for TEST_PARAM_STRING and TEST_CONTENT so people can test the content
21
// @todo change ATTR_TEST to be able to test the entire message with the current offset
22
23
class Codes
24
{
25
	/** the tag's name - must be lowercase */
26
	const ATTR_TAG = 1;
27
	/** One of self::TYPE_* */
28
	const ATTR_TYPE = 2;
29
	/**
30
	 * An optional array of parameters, for the form
31
	 * [tag abc=123]content[/tag].  The array is an associative array
32
	 * where the keys are the parameter names, and the values are an
33
	 * array which *may* contain any of self::PARAM_ATTR_*
34
	 */
35
	const ATTR_PARAM = 3;
36
	/**
37
	 * A regular expression to test immediately after the tag's
38
	 * '=', ' ' or ']'.  Typically, should have a \] at the end.
39
	 * Optional.
40
	 */
41
	const ATTR_TEST = 4;
42
	/**
43
	 * Only available for unparsed_content, closed, unparsed_commas_content, and unparsed_equals_content.
44
	 * $1 is replaced with the content of the tag.
45
	 * Parameters are replaced in the form {param}.
46
	 * For unparsed_commas_content, $2, $3, ..., $n are replaced.
47
	 */
48
	const ATTR_CONTENT = 5;
49
	/**
50
	 * Only when content is not used, to go before any content.
51
	 * For unparsed_equals, $1 is replaced with the value.
52
	 * For unparsed_commas, $1, $2, ..., $n are replaced.
53
	 */
54
	const ATTR_BEFORE = 6;
55
	/**
56
	 * Similar to before in every way, except that it is used when the tag is closed.
57
	 */
58
	const ATTR_AFTER = 7;
59
	/**
60
	 * Used in place of content when the tag is disabled.
61
	 * For closed, default is '', otherwise it is '$1' if block_level is false, '<div>$1</div>' elsewise.
62
	 */
63
	const ATTR_DISABLED_CONTENT = 8;
64
	/**
65
	 * Used in place of before when disabled.
66
	 * Defaults to '<div>' if block_level, '' if not.
67
	 */
68
	const ATTR_DISABLED_BEFORE = 9;
69
	/**
70
	 * Used in place of after when disabled.
71
	 * Defaults to '</div>' if block_level, '' if not.
72
	 */
73
	const ATTR_DISABLED_AFTER = 10;
74
	/**
75
	 * Set to true the tag is a "block level" tag, similar to HTML.
76
	 * Block level tags cannot be nested inside tags that are not block level, and will not be implicitly closed as easily.
77
	 * One break following a block level tag may also be removed.
78
	 */
79
	const ATTR_BLOCK_LEVEL = 11;
80
	/**
81
	 * Trim the whitespace after the opening tag or the closing tag or both.
82
	 * One of self::TRIM_*
83
	 * Optional
84
	 */
85
	const ATTR_TRIM = 12;
86
	/**
87
	 * Except when type is missing or 'closed', a callback to validate the data as $data.
88
	 * Depending on the tag's type, $data may be a string or an array of strings (corresponding to the replacement.)
89
	 */
90
	const ATTR_VALIDATE = 13;
91
	/**
92
	 * When type is unparsed_equals or parsed_equals only, may be not set,
93
	 * 'optional', or 'required' corresponding to if the content may be quoted.
94
	 * This allows the parser to read [tag="abc]def[esdf]"] properly.
95
	 */
96
	const ATTR_QUOTED = 14;
97
	/**
98
	 * An array of tag names, or not set.
99
	 * If set, the enclosing tag *must* be one of the listed tags, or parsing won't	occur.
100
	 */
101
	const ATTR_REQUIRE_PARENTS = 15;
102
	/**
103
	 * similar to require_parents, if set children won't be parsed if they are not in the list.
104
	 */
105
	const ATTR_REQUIRE_CHILDREN = 16;
106
	/**
107
	 * Similar to, but very different from, require_parents.
108
	 * If it is set the listed tags will not be parsed inside the tag.
109
	 */
110
	const ATTR_DISALLOW_PARENTS = 17;
111
	/**
112
	 * Similar to, but very different from, require_children.
113
	 * If it is set the listed tags will not be parsed inside the tag.
114
	 */
115
	const ATTR_DISALLOW_CHILDREN = 18;
116
	/**
117
	 * When ATTR_DISALLOW_PARENTS is used, this gets put before the tag.
118
	 */
119
	const ATTR_DISALLOW_BEFORE = 19;
120
	/**
121
	 * * When ATTR_DISALLOW_PARENTS is used, this gets put after the tag.
122
	 */
123
	const ATTR_DISALLOW_AFTER = 20;
124
	/**
125
	 * an array restricting what BBC can be in the parsed_equals parameter, if desired.
126
	 */
127
	const ATTR_PARSED_TAGS_ALLOWED = 21;
128
	/**
129
	 * (bool) Turn uris like http://www.google.com in to links
130
	 */
131
	const ATTR_AUTOLINK = 22;
132
	/**
133
	 * The length of the tag
134
	 */
135
	const ATTR_LENGTH = 23;
136
	/**
137
	 * Whether the tag is disabled
138
	 */
139
	const ATTR_DISABLED = 24;
140
	/**
141
	 * If the message contains a code with this, the message should not be cached
142
	 */
143
	const ATTR_NO_CACHE = 25;
144
145
	/** [tag]parsed content[/tag] */
146
	const TYPE_PARSED_CONTENT = 0;
147
	/** [tag=xyz]parsed content[/tag] */
148
	const TYPE_UNPARSED_EQUALS = 1;
149
	/** [tag=parsed data]parsed content[/tag] */
150
	const TYPE_PARSED_EQUALS = 2;
151
	/** [tag]unparsed content[/tag] */
152
	const TYPE_UNPARSED_CONTENT = 3;
153
	/** [tag], [tag/], [tag /] */
154
	const TYPE_CLOSED = 4;
155
	/** [tag=1,2,3]parsed content[/tag] */
156
	const TYPE_UNPARSED_COMMAS = 5;
157
	/** [tag=1,2,3]unparsed content[/tag] */
158
	const TYPE_UNPARSED_COMMAS_CONTENT = 6;
159
	/** [tag=...]unparsed content[/tag] */
160
	const TYPE_UNPARSED_EQUALS_CONTENT = 7;
161
	/** [*] */
162
	const TYPE_ITEMCODE = 8;
163
164
	/** a regular expression to validate and match the value. */
165
	const PARAM_ATTR_MATCH = 0;
166
	/** true if the value should be quoted. */
167
	const PARAM_ATTR_QUOTED = 1;
168
	/** callback to evaluate on the data, which is $data. */
169
	const PARAM_ATTR_VALIDATE = 2;
170
	/** a string in which to replace $1 with the data. Either it or validate may be used, not both. */
171
	const PARAM_ATTR_VALUE = 3;
172
	/** true if the parameter is optional. */
173
	const PARAM_ATTR_OPTIONAL = 4;
174
175
	/**  */
176
	const TRIM_NONE = 0;
177
	/**  */
178
	const TRIM_INSIDE = 1;
179
	/**  */
180
	const TRIM_OUTSIDE = 2;
181
	/**  */
182
	const TRIM_BOTH = 3;
183
184
	// These are mainly for *ATTR_QUOTED since there are 3 options
185
	const OPTIONAL = -1;
186
	const NONE = 0;
187
	const REQUIRED = 1;
188
189
190
	/**
191
	 * An array of self::ATTR_*
192
	 * ATTR_TAG and ATTR_TYPE are required for every tag.
193
	 * The rest of the attributes depend on the type and other options.
194
	 */
195
	protected $bbc = array();
196
	protected $itemcodes = array();
197
	protected $additional_bbc = array();
198
	protected $disabled = array();
199
	protected $parsing_codes = array();
200
201 1
	public function __construct(array $tags = array(), array $disabled = array())
202
	{
203 1
		$this->additional_bbc = $tags;
204
205 1
		foreach ($disabled as $tag)
206
		{
207
			$this->disable($tag);
208 1
		}
209
210 1
		foreach ($tags as $tag)
211
		{
212
			$this->add($tag);
213 1
		}
214
215 1
		$this->bbc = $this->getDefault();
216 1
	}
217
218
	/**
219
	 * Add a code
220
	 * @param array $code
221
	 */
222
	public function add(array $code)
223
	{
224
		$first_char = $code[self::ATTR_TAG][0];
225
226
		if (!isset($this->bbc[$first_char]))
227
		{
228
			$this->bbc[$first_char] = array();
229
		}
230
231
		$this->bbc[$first_char][] = $code;
232
	}
233
234
	public function remove($tag)
235
	{
236
		foreach ($this->bbc as $k => $v)
237
		{
238
			if ($tag === $v[self::ATTR_TAG])
239
			{
240
				unset($this->bbc[$k]);
241
			}
242
		}
243
	}
244
245 1
	public function getDefault()
246
	{
247 1
		global $modSettings, $txt, $scripturl;
248
249
		// This array can be arranged in any order.
250
		return array(
251
			array(
252 1
				self::ATTR_TAG => 'abbr',
253 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
254 1
				self::ATTR_BEFORE => '<abbr title="$1">',
255 1
				self::ATTR_AFTER => '</abbr>',
256 1
				self::ATTR_QUOTED => self::OPTIONAL,
257 1
				self::ATTR_DISABLED_AFTER => ' ($1)',
258 1
				self::ATTR_BLOCK_LEVEL => false,
259 1
				self::ATTR_AUTOLINK => true,
260 1
				self::ATTR_LENGTH => 4,
261 1
			),
262
			array(
263 1
				self::ATTR_TAG => 'anchor',
264 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
265 1
				self::ATTR_TEST => '[#]?([A-Za-z][A-Za-z0-9_\-]*)$',
266 1
				self::ATTR_BEFORE => '<span id="post_$1">',
267 1
				self::ATTR_AFTER => '</span>',
268 1
				self::ATTR_BLOCK_LEVEL => false,
269 1
				self::ATTR_AUTOLINK => true,
270 1
				self::ATTR_LENGTH => 6,
271 1
			),
272
			array(
273 1
				self::ATTR_TAG => 'b',
274 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
275 1
				self::ATTR_BEFORE => '<strong class="bbc_strong">',
276 1
				self::ATTR_AFTER => '</strong>',
277 1
				self::ATTR_BLOCK_LEVEL => false,
278 1
				self::ATTR_AUTOLINK => true,
279 1
				self::ATTR_LENGTH => 1,
280 1
			),
281
			array(
282 1
				self::ATTR_TAG => 'br',
283 1
				self::ATTR_TYPE => self::TYPE_CLOSED,
284 1
				self::ATTR_CONTENT => '<br />',
285 1
				self::ATTR_BLOCK_LEVEL => false,
286 1
				self::ATTR_AUTOLINK => false,
287 1
				self::ATTR_LENGTH => 2,
288 1
			),
289
			array(
290 1
				self::ATTR_TAG => 'center',
291 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
292 1
				self::ATTR_BEFORE => '<div class="centertext">',
293 1
				self::ATTR_AFTER => '</div>',
294 1
				self::ATTR_BLOCK_LEVEL => true,
295 1
				self::ATTR_AUTOLINK => true,
296 1
				self::ATTR_LENGTH => 6,
297 1
			),
298
			array(
299 1
				self::ATTR_TAG => 'code',
300 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT,
301 1
				self::ATTR_CONTENT => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return elkSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div><pre class="bbc_code prettyprint">$1</pre>',
302
				self::ATTR_VALIDATE => $this->isDisabled('code') ? null : function(&$tag, &$data, $disabled) {
0 ignored issues
show
Unused Code introduced by
The parameter $disabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
303
					$data = tabToHtmlTab($data);
304 1
				},
305 1
				self::ATTR_BLOCK_LEVEL => true,
306 1
				self::ATTR_AUTOLINK => false,
307 1
				self::ATTR_LENGTH => 4,
308 1
			),
309
			array(
310 1
				self::ATTR_TAG => 'code',
311 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS_CONTENT,
312 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>',
313
				self::ATTR_VALIDATE => $this->isDisabled('code') ? null : function(&$tag, &$data, $disabled) {
0 ignored issues
show
Unused Code introduced by
The parameter $disabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
314
					$data[0] = tabToHtmlTab($data[0]);
315 1
				},
316 1
				self::ATTR_BLOCK_LEVEL => true,
317 1
				self::ATTR_AUTOLINK => false,
318 1
				self::ATTR_LENGTH => 4,
319 1
			),
320
			array(
321 1
				self::ATTR_TAG => 'color',
322 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
323 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]?)\))',
324 1
				self::ATTR_BEFORE => '<span style="color: $1;" class="bbc_color">',
325 1
				self::ATTR_AFTER => '</span>',
326 1
				self::ATTR_BLOCK_LEVEL => false,
327 1
				self::ATTR_AUTOLINK => true,
328 1
				self::ATTR_LENGTH => 5,
329 1
			),
330
			array(
331 1
				self::ATTR_TAG => 'email',
332 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT,
333 1
				self::ATTR_CONTENT => '<a href="mailto:$1" class="bbc_email">$1</a>',
334 1
				self::ATTR_BLOCK_LEVEL => false,
335 1
				self::ATTR_AUTOLINK => false,
336 1
				self::ATTR_LENGTH => 5,
337 1
			),
338
			array(
339 1
				self::ATTR_TAG => 'email',
340 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
341 1
				self::ATTR_BEFORE => '<a href="mailto:$1" class="bbc_email">',
342 1
				self::ATTR_AFTER => '</a>',
343 1
				self::ATTR_DISALLOW_CHILDREN => array(
344 1
					'email' => 1,
345 1
					'url' => 1,
346 1
					'iurl' => 1,
347 1
				),
348 1
				self::ATTR_DISABLED_AFTER => ' ($1)',
349 1
				self::ATTR_BLOCK_LEVEL => false,
350 1
				self::ATTR_AUTOLINK => false,
351 1
				self::ATTR_LENGTH => 5,
352 1
			),
353
			array(
354 1
				self::ATTR_TAG => 'footnote',
355 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
356 1
				self::ATTR_BEFORE => '<sup class="bbc_footnotes">%fn%',
357 1
				self::ATTR_AFTER => '%fn%</sup>',
358 1
				self::ATTR_DISALLOW_PARENTS => array(
359 1
					'footnote' => 1,
360 1
					'code' => 1,
361 1
					'anchor' => 1,
362 1
					'url' => 1,
363 1
					'iurl' => 1,
364 1
				),
365 1
				self::ATTR_DISALLOW_BEFORE => '',
366 1
				self::ATTR_DISALLOW_AFTER => '',
367 1
				self::ATTR_BLOCK_LEVEL => true,
368 1
				self::ATTR_AUTOLINK => true,
369 1
				self::ATTR_LENGTH => 8,
370 1
			),
371
			array(
372 1
				self::ATTR_TAG => 'font',
373 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
374 1
				self::ATTR_TEST => '[A-Za-z0-9_,\-\s]+?',
375 1
				self::ATTR_BEFORE => '<span style="font-family: $1;" class="bbc_font">',
376 1
				self::ATTR_AFTER => '</span>',
377 1
				self::ATTR_BLOCK_LEVEL => false,
378 1
				self::ATTR_AUTOLINK => true,
379 1
				self::ATTR_LENGTH => 4,
380 1
			),
381
			array(
382 1
				self::ATTR_TAG => 'hr',
383 1
				self::ATTR_TYPE => self::TYPE_CLOSED,
384 1
				self::ATTR_CONTENT => '<hr />',
385 1
				self::ATTR_BLOCK_LEVEL => true,
386 1
				self::ATTR_AUTOLINK => false,
387 1
				self::ATTR_LENGTH => 2,
388 1
			),
389
			array(
390 1
				self::ATTR_TAG => 'i',
391 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
392 1
				self::ATTR_BEFORE => '<em>',
393 1
				self::ATTR_AFTER => '</em>',
394 1
				self::ATTR_BLOCK_LEVEL => false,
395 1
				self::ATTR_AUTOLINK => true,
396 1
				self::ATTR_LENGTH => 1,
397 1
			),
398
			array(
399 1
				self::ATTR_TAG => 'img',
400 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT,
401 1
				self::ATTR_PARAM => array(
402
					'alt' => array(
403 1
						self::PARAM_ATTR_OPTIONAL => true,
404 1
					),
405
					'width' => array(
406 1
						self::PARAM_ATTR_OPTIONAL => true,
407 1
						self::PARAM_ATTR_VALUE => 'width:100%;max-width:$1px;',
408 1
						self::PARAM_ATTR_MATCH => '(\d+)',
409 1
					),
410
					'height' => array(
411 1
						self::PARAM_ATTR_OPTIONAL => true,
412 1
						self::PARAM_ATTR_VALUE => 'max-height:$1px;',
413 1
						self::PARAM_ATTR_MATCH => '(\d+)',
414 1
					),
415 1
				),
416 1
				self::ATTR_CONTENT => '<img src="$1" alt="{alt}" style="{width}{height}" class="bbc_img resized" />',
417
				self::ATTR_VALIDATE => function(&$tag, &$data, $disabled) {
0 ignored issues
show
Unused Code introduced by
The parameter $disabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
418
					if (strpos($data, 'http://') !== 0 && strpos($data, 'https://') !== 0)
419
					{
420
						$data = 'http://' . $data;
421
					}
422 1
				},
423 1
				self::ATTR_DISABLED_CONTENT => '($1)',
424 1
				self::ATTR_BLOCK_LEVEL => false,
425 1
				self::ATTR_AUTOLINK => false,
426 1
				self::ATTR_LENGTH => 3,
427 1
			),
428
			array(
429 1
				self::ATTR_TAG => 'img',
430 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT,
431 1
				self::ATTR_CONTENT => '<img src="$1" alt="" class="bbc_img" />',
432
				self::ATTR_VALIDATE => function(&$tag, &$data, $disabled) {
0 ignored issues
show
Unused Code introduced by
The parameter $disabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
433
					if (strpos($data, 'http://') !== 0 && strpos($data, 'https://') !== 0)
434
					{
435
						$data = 'http://' . $data;
436
					}
437 1
				},
438 1
				self::ATTR_DISABLED_CONTENT => '($1)',
439 1
				self::ATTR_BLOCK_LEVEL => false,
440 1
				self::ATTR_AUTOLINK => false,
441 1
				self::ATTR_LENGTH => 3,
442 1
			),
443
			array(
444 1
				self::ATTR_TAG => 'iurl',
445 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT,
446 1
				self::ATTR_CONTENT => '<a href="$1" class="bbc_link">$1</a>',
447
				self::ATTR_VALIDATE => function(&$tag, &$data, $disabled) {
0 ignored issues
show
Unused Code introduced by
The parameter $disabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
448
					//$data = removeBr($data);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
449
					if (strpos($data, 'http://') !== 0 && strpos($data, 'https://') !== 0)
450
					{
451
						$data = 'http://' . $data;
452
					}
453 1
				},
454 1
				self::ATTR_BLOCK_LEVEL => false,
455 1
				self::ATTR_AUTOLINK => false,
456 1
				self::ATTR_LENGTH => 4,
457 1
			),
458
			array(
459 1
				self::ATTR_TAG => 'iurl',
460 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
461 1
				self::ATTR_BEFORE => '<a href="$1" class="bbc_link">',
462 1
				self::ATTR_AFTER => '</a>',
463
				self::ATTR_VALIDATE => function(&$tag, &$data, $disabled) {
0 ignored issues
show
Unused Code introduced by
The parameter $disabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
464
					if ($data[0] === '#')
465
					{
466
						$data = '#post_' . substr($data, 1);
467
					}
468
					elseif (strpos($data, 'http://') !== 0 && strpos($data, 'https://') !== 0)
469
					{
470
						$data = 'http://' . $data;
471
					}
472 1
				},
473 1
				self::ATTR_DISALLOW_CHILDREN => array(
474 1
					'email' => 1,
475 1
					'url' => 1,
476 1
					'iurl' => 1,
477 1
				),
478 1
				self::ATTR_DISABLED_AFTER => ' ($1)',
479 1
				self::ATTR_BLOCK_LEVEL => false,
480 1
				self::ATTR_AUTOLINK => false,
481 1
				self::ATTR_LENGTH => 4,
482 1
			),
483
			array(
484 1
				self::ATTR_TAG => 'left',
485 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
486 1
				self::ATTR_BEFORE => '<div style="text-align: left;">',
487 1
				self::ATTR_AFTER => '</div>',
488 1
				self::ATTR_BLOCK_LEVEL => true,
489 1
				self::ATTR_AUTOLINK => true,
490 1
				self::ATTR_LENGTH => 4,
491 1
			),
492
			array(
493 1
				self::ATTR_TAG => 'li',
494 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
495 1
				self::ATTR_BEFORE => '<li>',
496 1
				self::ATTR_AFTER => '</li>',
497 1
				self::ATTR_TRIM => self::TRIM_OUTSIDE,
498 1
				self::ATTR_REQUIRE_PARENTS => array(
499 1
					'list' => 1,
500 1
				),
501 1
				self::ATTR_BLOCK_LEVEL => true,
502 1
				self::ATTR_DISABLED_BEFORE => '',
503 1
				self::ATTR_DISABLED_AFTER => '<br />',
504 1
				self::ATTR_AUTOLINK => true,
505 1
				self::ATTR_LENGTH => 2,
506 1
			),
507
			array(
508 1
				self::ATTR_TAG => 'list',
509 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
510 1
				self::ATTR_BEFORE => '<ul class="bbc_list">',
511 1
				self::ATTR_AFTER => '</ul>',
512 1
				self::ATTR_TRIM => self::TRIM_INSIDE,
513 1
				self::ATTR_REQUIRE_CHILDREN => array(
514 1
					'li' => 1,
515 1
					'list' => 1,
516 1
				),
517 1
				self::ATTR_BLOCK_LEVEL => true,
518 1
				self::ATTR_AUTOLINK => true,
519 1
				self::ATTR_LENGTH => 4,
520 1
			),
521
			array(
522 1
				self::ATTR_TAG => 'list',
523 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
524 1
				self::ATTR_PARAM => array(
525
					'type' => array(
526 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)',
527 1
					),
528 1
				),
529 1
				self::ATTR_BEFORE => '<ul class="bbc_list" style="list-style-type: {type};">',
530 1
				self::ATTR_AFTER => '</ul>',
531 1
				self::ATTR_TRIM => self::TRIM_INSIDE,
532 1
				self::ATTR_REQUIRE_CHILDREN => array(
533 1
					'li' => 1,
534 1
				),
535 1
				self::ATTR_BLOCK_LEVEL => true,
536 1
				self::ATTR_AUTOLINK => true,
537 1
				self::ATTR_LENGTH => 4,
538 1
			),
539
			array(
540 1
				self::ATTR_TAG => 'me',
541 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
542 1
				self::ATTR_BEFORE => '<div class="meaction">&nbsp;$1 ',
543 1
				self::ATTR_AFTER => '</div>',
544 1
				self::ATTR_QUOTED => self::OPTIONAL,
545 1
				self::ATTR_BLOCK_LEVEL => true,
546 1
				self::ATTR_DISABLED_BEFORE => '/me ',
547 1
				self::ATTR_DISABLED_AFTER => '<br />',
548 1
				self::ATTR_AUTOLINK => true,
549 1
				self::ATTR_LENGTH => 2,
550 1
			),
551
			array(
552 1
				self::ATTR_TAG => 'member',
553 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
554 1
				self::ATTR_TEST => '[\d*]',
555 1
				self::ATTR_BEFORE => '<span class="bbc_mention"><a href="' . $scripturl . '?action=profile;u=$1">@',
556 1
				self::ATTR_AFTER => '</a></span>',
557 1
				self::ATTR_DISABLED_BEFORE => '@',
558 1
				self::ATTR_DISABLED_AFTER => '',
559 1
				self::ATTR_BLOCK_LEVEL => false,
560 1
				self::ATTR_AUTOLINK => true,
561 1
				self::ATTR_LENGTH => 6,
562 1
			),
563
			array(
564 1
				self::ATTR_TAG => 'nobbc',
565 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT,
566 1
				self::ATTR_CONTENT => '$1',
567 1
				self::ATTR_BLOCK_LEVEL => false,
568 1
				self::ATTR_AUTOLINK => true,
569 1
				self::ATTR_LENGTH => 5,
570 1
			),
571
			array(
572 1
				self::ATTR_TAG => 'pre',
573 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
574 1
				self::ATTR_BEFORE => '<pre class="bbc_pre">',
575 1
				self::ATTR_AFTER => '</pre>',
576 1
				self::ATTR_BLOCK_LEVEL => false,
577 1
				self::ATTR_AUTOLINK => true,
578 1
				self::ATTR_LENGTH => 3,
579 1
			),
580
			array(
581 1
				self::ATTR_TAG => 'quote',
582 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
583 1
				self::ATTR_BEFORE => '<div class="quoteheader">' . $txt['quote'] . '</div><blockquote>',
584 1
				self::ATTR_AFTER => '</blockquote>',
585 1
				self::ATTR_BLOCK_LEVEL => true,
586 1
				self::ATTR_AUTOLINK => true,
587 1
				self::ATTR_LENGTH => 5,
588 1
			),
589
			array(
590 1
				self::ATTR_TAG => 'quote',
591 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
592 1
				self::ATTR_PARAM => array(
593
					'author' => array(
594 1
						self::PARAM_ATTR_MATCH => '(.{1,192}?)',
595 1
						self::PARAM_ATTR_QUOTED => self::OPTIONAL,
596 1
					),
597 1
				),
598 1
				self::ATTR_BEFORE => '<div class="quoteheader">' . $txt['quote_from'] . ': {author}</div><blockquote>',
599 1
				self::ATTR_AFTER => '</blockquote>',
600 1
				self::ATTR_BLOCK_LEVEL => true,
601 1
				self::ATTR_AUTOLINK => true,
602 1
				self::ATTR_LENGTH => 5,
603 1
			),
604
			array(
605 1
				self::ATTR_TAG => 'quote',
606 1
				self::ATTR_TYPE => self::TYPE_PARSED_EQUALS,
607 1
				self::ATTR_BEFORE => '<div class="quoteheader">' . $txt['quote_from'] . ': $1</div><blockquote>',
608 1
				self::ATTR_AFTER => '</blockquote>',
609 1
				self::ATTR_QUOTED => self::OPTIONAL,
610 1
				self::ATTR_PARSED_TAGS_ALLOWED => array(
611 1
					'url',
612 1
					'iurl',
613 1
				),
614 1
				self::ATTR_BLOCK_LEVEL => true,
615 1
				self::ATTR_AUTOLINK => true,
616 1
				self::ATTR_LENGTH => 5,
617 1
			),
618
			array(
619 1
				self::ATTR_TAG => 'quote',
620 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
621 1
				self::ATTR_PARAM => array(
622
					'author' => array(
623 1
						self::PARAM_ATTR_MATCH => '([^<>]{1,192}?)',
624 1
					),
625
					'link' => array(
626 1
						self::PARAM_ATTR_MATCH => '(?:board=\d+;)?((?:topic|threadid)=[\dmsg#\./]{1,40}(?:;start=[\dmsg#\./]{1,40})?|msg=\d{1,40}|action=profile;u=\d+)',
627 1
					),
628
					'date' => array(
629 1
						self::PARAM_ATTR_MATCH => '(\d+)',
630 1
						self::ATTR_VALIDATE => 'htmlTime',
631 1
					),
632 1
				),
633 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>',
634 1
				self::ATTR_AFTER => '</blockquote>',
635 1
				self::ATTR_BLOCK_LEVEL => true,
636 1
				self::ATTR_AUTOLINK => true,
637 1
				self::ATTR_LENGTH => 5,
638 1
			),
639
			array(
640 1
				self::ATTR_TAG => 'quote',
641 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
642 1
				self::ATTR_PARAM => array(
643 1
					'author' => array(self::PARAM_ATTR_MATCH => '(.{1,192}?)'),
644 1
				),
645 1
				self::ATTR_BEFORE => '<div class="quoteheader">' . $txt['quote_from'] . ': {author}</div><blockquote>',
646 1
				self::ATTR_AFTER => '</blockquote>',
647 1
				self::ATTR_BLOCK_LEVEL => true,
648 1
				self::ATTR_AUTOLINK => true,
649 1
				self::ATTR_LENGTH => 5,
650 1
			),
651
			array(
652 1
				self::ATTR_TAG => 'right',
653 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
654 1
				self::ATTR_BEFORE => '<div style="text-align: right;">',
655 1
				self::ATTR_AFTER => '</div>',
656 1
				self::ATTR_BLOCK_LEVEL => true,
657 1
				self::ATTR_AUTOLINK => true,
658 1
				self::ATTR_LENGTH => 5,
659 1
			),
660
			array(
661 1
				self::ATTR_TAG => 's',
662 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
663 1
				self::ATTR_BEFORE => '<del>',
664 1
				self::ATTR_AFTER => '</del>',
665 1
				self::ATTR_BLOCK_LEVEL => false,
666 1
				self::ATTR_AUTOLINK => true,
667 1
				self::ATTR_LENGTH => 1,
668 1
			),
669
			array(
670 1
				self::ATTR_TAG => 'size',
671 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
672 1
				self::ATTR_TEST => '[1-7]{1}$',
673 1
				self::ATTR_BEFORE => '<span style="font-size: $1;" class="bbc_size">',
674 1
				self::ATTR_AFTER => '</span>',
675
				self::ATTR_VALIDATE => function(&$tag, &$data, $disabled) {
0 ignored issues
show
Unused Code introduced by
The parameter $disabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
676
					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
677
					$data = $sizes[(int) $data] . 'em';
678 1
				},
679 1
				self::ATTR_DISALLOW_PARENTS => array(
680 1
					'size' => 1,
681 1
				),
682 1
				self::ATTR_DISALLOW_BEFORE => '<span>',
683 1
				self::ATTR_DISALLOW_AFTER => '</span>',
684 1
				self::ATTR_BLOCK_LEVEL => false,
685 1
				self::ATTR_AUTOLINK => true,
686 1
				self::ATTR_LENGTH => 4,
687 1
			),
688
			array(
689 1
				self::ATTR_TAG => 'size',
690 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
691 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)',
692 1
				self::ATTR_BEFORE => '<span style="font-size: $1;" class="bbc_size">',
693 1
				self::ATTR_AFTER => '</span>',
694 1
				self::ATTR_DISALLOW_PARENTS => array('size' => 1),
695 1
				self::ATTR_DISALLOW_BEFORE => '<span>',
696 1
				self::ATTR_DISALLOW_AFTER => '</span>',
697 1
				self::ATTR_BLOCK_LEVEL => false,
698 1
				self::ATTR_AUTOLINK => true,
699 1
				self::ATTR_LENGTH => 4,
700 1
			),
701
			array(
702 1
				self::ATTR_TAG => 'spoiler',
703 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
704 1
				self::ATTR_BEFORE => '<span class="spoilerheader">' . $txt['spoiler'] . '</span><div class="spoiler"><div class="bbc_spoiler" style="display: none;">',
705 1
				self::ATTR_AFTER => '</div></div>',
706 1
				self::ATTR_BLOCK_LEVEL => true,
707 1
				self::ATTR_AUTOLINK => true,
708 1
				self::ATTR_LENGTH => 7,
709 1
			),
710
			array(
711 1
				self::ATTR_TAG => 'sub',
712 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
713 1
				self::ATTR_BEFORE => '<sub>',
714 1
				self::ATTR_AFTER => '</sub>',
715 1
				self::ATTR_BLOCK_LEVEL => false,
716 1
				self::ATTR_AUTOLINK => true,
717 1
				self::ATTR_LENGTH => 3,
718 1
			),
719
			array(
720 1
				self::ATTR_TAG => 'sup',
721 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
722 1
				self::ATTR_BEFORE => '<sup>',
723 1
				self::ATTR_AFTER => '</sup>',
724 1
				self::ATTR_BLOCK_LEVEL => false,
725 1
				self::ATTR_AUTOLINK => true,
726 1
				self::ATTR_LENGTH => 3,
727 1
			),
728
			array(
729 1
				self::ATTR_TAG => 'table',
730 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
731 1
				self::ATTR_BEFORE => '<div class="bbc_table_container"><table class="bbc_table">',
732 1
				self::ATTR_AFTER => '</table></div>',
733 1
				self::ATTR_TRIM => self::TRIM_INSIDE,
734 1
				self::ATTR_REQUIRE_CHILDREN => array(
735 1
					'tr' => 1,
736 1
				),
737 1
				self::ATTR_BLOCK_LEVEL => true,
738 1
				self::ATTR_AUTOLINK => true,
739 1
				self::ATTR_LENGTH => 5,
740 1
			),
741
			array(
742 1
				self::ATTR_TAG => 'td',
743 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
744 1
				self::ATTR_BEFORE => '<td>',
745 1
				self::ATTR_AFTER => '</td>',
746 1
				self::ATTR_REQUIRE_PARENTS => array(
747 1
					'tr' => 1,
748 1
				),
749 1
				self::ATTR_TRIM => self::TRIM_OUTSIDE,
750 1
				self::ATTR_BLOCK_LEVEL => true,
751 1
				self::ATTR_DISABLED_BEFORE => '',
752 1
				self::ATTR_DISABLED_AFTER => '',
753 1
				self::ATTR_AUTOLINK => true,
754 1
				self::ATTR_LENGTH => 2,
755 1
			),
756
			array(
757 1
				self::ATTR_TAG => 'th',
758 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
759 1
				self::ATTR_BEFORE => '<th>',
760 1
				self::ATTR_AFTER => '</th>',
761 1
				self::ATTR_REQUIRE_PARENTS => array(
762 1
					'tr' => 1,
763 1
				),
764 1
				self::ATTR_TRIM => self::TRIM_OUTSIDE,
765 1
				self::ATTR_BLOCK_LEVEL => true,
766 1
				self::ATTR_DISABLED_BEFORE => '',
767 1
				self::ATTR_DISABLED_AFTER => '',
768 1
				self::ATTR_AUTOLINK => true,
769 1
				self::ATTR_LENGTH => 2,
770 1
			),
771
			array(
772 1
				self::ATTR_TAG => 'tr',
773 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
774 1
				self::ATTR_BEFORE => '<tr>',
775 1
				self::ATTR_AFTER => '</tr>',
776 1
				self::ATTR_REQUIRE_PARENTS => array(
777 1
					'table' => 1,
778 1
				),
779 1
				self::ATTR_REQUIRE_CHILDREN => array(
780 1
					'td' => 1,
781 1
					'th' => 1,
782 1
				),
783 1
				self::ATTR_TRIM => self::TRIM_BOTH,
784 1
				self::ATTR_BLOCK_LEVEL => true,
785 1
				self::ATTR_DISABLED_BEFORE => '',
786 1
				self::ATTR_DISABLED_AFTER => '',
787 1
				self::ATTR_AUTOLINK => true,
788 1
				self::ATTR_LENGTH => 2,
789 1
			),
790
			array(
791 1
				self::ATTR_TAG => 'tt',
792 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
793 1
				self::ATTR_BEFORE => '<span class="bbc_tt">',
794 1
				self::ATTR_AFTER => '</span>',
795 1
				self::ATTR_BLOCK_LEVEL => false,
796 1
				self::ATTR_AUTOLINK => true,
797 1
				self::ATTR_LENGTH => 2,
798 1
			),
799
			array(
800 1
				self::ATTR_TAG => 'u',
801 1
				self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
802 1
				self::ATTR_BEFORE => '<span class="bbc_u">',
803 1
				self::ATTR_AFTER => '</span>',
804 1
				self::ATTR_BLOCK_LEVEL => false,
805 1
				self::ATTR_AUTOLINK => true,
806 1
				self::ATTR_LENGTH => 1,
807 1
			),
808
			array(
809 1
				self::ATTR_TAG => 'url',
810 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_CONTENT,
811 1
				self::ATTR_CONTENT => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
812
				self::ATTR_VALIDATE => function(&$tag, &$data, $disabled) {
0 ignored issues
show
Unused Code introduced by
The parameter $disabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
813
					if (strpos($data, 'http://') !== 0 && strpos($data, 'https://') !== 0)
814
					{
815
						$data = 'http://' . $data;
816
					}
817 1
				},
818 1
				self::ATTR_BLOCK_LEVEL => false,
819 1
				self::ATTR_AUTOLINK => false,
820 1
				self::ATTR_LENGTH => 3,
821 1
			),
822
			array(
823 1
				self::ATTR_TAG => 'url',
824 1
				self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
825 1
				self::ATTR_BEFORE => '<a href="$1" class="bbc_link" target="_blank">',
826 1
				self::ATTR_AFTER => '</a>',
827 1
				self::ATTR_VALIDATE => function(&$tag, &$data, $disabled) {
0 ignored issues
show
Unused Code introduced by
The parameter $disabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
828
					if (strpos($data, 'http://') !== 0 && strpos($data, 'https://') !== 0)
829
					{
830
						$data = 'http://' . $data;
831
					}
832 1
				},
833 1
				self::ATTR_DISALLOW_CHILDREN => array(
834 1
					'email' => 1,
835 1
					'url' => 1,
836 1
					'iurl' => 1,
837 1
				),
838 1
				self::ATTR_DISABLED_AFTER => ' ($1)',
839 1
				self::ATTR_BLOCK_LEVEL => false,
840 1
				self::ATTR_AUTOLINK => false,
841 1
				self::ATTR_LENGTH => 3,
842 1
			),
843 1
		);
844
	}
845
846 1
	public function getItemCodes()
847
	{
848
		$item_codes = array(
849 1
			'*' => 'disc',
850 1
			'@' => 'disc',
851 1
			'+' => 'square',
852 1
			'x' => 'square',
853 1
			'#' => 'decimal',
854 1
			'0' => 'decimal',
855 1
			'o' => 'circle',
856 1
			'O' => 'circle',
857 1
		);
858
859 1
		call_integration_hook('integrate_item_codes', array(&$item_codes));
860
861 1
		return $item_codes;
862
	}
863
864
	public function getCodes()
865
	{
866
		return $this->bbc;
867
	}
868
869
	public function getCodesGroupedByTag()
870
	{
871
		$bbc = array();
872
		foreach ($this->bbc as $code)
873
		{
874
			if (!isset($bbc[$code[self::ATTR_TAG]]))
875
			{
876
				$bbc[$code[self::ATTR_TAG]] = array();
877
			}
878
			$bbc[$code[self::ATTR_TAG]][] = $code;
879
		}
880
		return $bbc;
881
	}
882
883
	public function getTags()
884
	{
885
		$tags = array();
886
		foreach ($this->bbc as $tag)
887
		{
888
			$tags[$tag[self::ATTR_TAG]] = $tag[self::ATTR_TAG];
889
		}
890
891
		return $tags;
892
	}
893
894
	// @todo besides the itemcodes (just add a arg $with_itemcodes), this way should be standard and saved like that.
895
	// Even, just remove the itemcodes when needed
896 1
	public function getForParsing()
897
	{
898 1
		$bbc = $this->bbc;
899 1
		$item_codes = $this->getItemCodes();
900 1
		call_integration_hook('bbc_codes_parsing', array(&$bbc, &$item_codes));
901
902 1
		if (!$this->isDisabled('li') && !$this->isDisabled('list'))
903 1
		{
904 1
			foreach ($item_codes as $c => $dummy)
905
			{
906
				// Skip anything "bad"
907 1
				if (!is_string($c) || (is_string($c) && trim($c) === ''))
908 1
				{
909 1
					continue;
910
				}
911
912 1
				$bbc[$c] = $this->getItemCodeTag($c);
913 1
			}
914 1
		}
915
916 1
		$return = array();
917
		// Find the first letter of the tag faster
918 1
		foreach ($bbc as &$code)
919
		{
920 1
			$return[$code[self::ATTR_TAG][0]][] = $code;
921 1
		}
922
923 1
		return $return;
924
	}
925
926
	public function setParsingCodes()
927
	{
928
		$this->parsing_bbc = $this->getForParsing();
0 ignored issues
show
Bug introduced by
The property parsing_bbc does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
929
		return $this;
930
	}
931
932
	public function hasChar($char)
933
	{
934
		return isset($this->parsing_codes[$char]);
935
	}
936
937
	public function getCodesByChar($char)
938
	{
939
		return $this->parsing_codes[$char];
940
	}
941
942 1
	protected function getItemCodeTag($code)
943
	{
944
		return array(
945 1
			self::ATTR_TAG => $code,
946 1
			self::ATTR_TYPE => self::TYPE_ITEMCODE,
947 1
			self::ATTR_BLOCK_LEVEL => true,
948 1
			self::ATTR_LENGTH => 1,
949 1
		);
950
	}
951
952
	public function setForPrinting()
0 ignored issues
show
Coding Style introduced by
setForPrinting uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
953
	{
954
		// Colors can't well be displayed... supposed to be black and white.
955
		$this->disable('color');
956
		$this->disable('me');
957
958
		// Links are useless on paper... just show the link.
959
		$this->disable('url');
960
		$this->disable('iurl');
961
		$this->disable('email');
962
963
		// @todo Change maybe?
964
		if (!isset($_GET['images']))
965
		{
966
			$this->disable('img');
967
		}
968
969
		// @todo Interface/setting to add more?
970
		call_integration_hook('integrate_bbc_set_printing', array($this));
971
972
		return $this;
973
	}
974
975 1
	public function isDisabled($tag)
976
	{
977 1
		return isset($this->disabled[$tag]);
978
	}
979
980
	public function getDisabled()
981
	{
982
		return $this->disabled;
983
	}
984
985
	public function disable($tag)
986
	{
987
		// It was already disabled.
988
		if (isset($this->disabled[$tag]))
989
		{
990
			return true;
991
		}
992
993
		$this->disabled[$tag] = $tag;
994
	}
995
996
	public function setParsedTags($parse_tags)
997
	{
998
		foreach ($this->bbc as $k => $code)
999
		{
1000
			if (!in_array($code[self::ATTR_TAG], $parse_tags))
1001
			{
1002
				//$this->remove($code);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1003
				unset($this->bbc[$k]);
1004
1005
				$this->disabled[$code[self::ATTR_TAG]] = $code[self::ATTR_TAG];
1006
			}
1007
		}
1008
	}
1009
}