Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like MyTextSanitizer 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 MyTextSanitizer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
133 | class MyTextSanitizer |
||
134 | { |
||
135 | /** |
||
136 | * |
||
137 | * @var array |
||
138 | */ |
||
139 | public $smileys = array(); |
||
140 | |||
141 | /** |
||
142 | */ |
||
143 | public $censorConf; |
||
144 | |||
145 | /** |
||
146 | * |
||
147 | * @var holding reference to text |
||
148 | */ |
||
149 | public $text = ''; |
||
150 | public $patterns = array(); |
||
151 | public $replacements = array(); |
||
152 | |||
153 | //mb------------------------------ |
||
154 | public $callbackPatterns = array(); |
||
155 | public $callbacks = array(); |
||
156 | //mb------------------------------ |
||
157 | |||
158 | public $path_basic; |
||
159 | public $path_plugin; |
||
160 | |||
161 | public $config; |
||
162 | |||
163 | /** |
||
164 | * Constructor of this class |
||
165 | * |
||
166 | * Gets allowed html tags from admin config settings |
||
167 | * <br> should not be allowed since nl2br will be used |
||
168 | * when storing data. |
||
169 | * |
||
170 | * @access private |
||
171 | */ |
||
172 | |||
173 | public function __construct() |
||
174 | { |
||
175 | $this->path_basic = XOOPS_ROOT_PATH . '/class/textsanitizer'; |
||
176 | $this->path_plugin = XOOPS_ROOT_PATH . '/Frameworks/textsanitizer'; |
||
177 | $this->config = $this->loadConfig(); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Enter description here... |
||
182 | * |
||
183 | * @param string $name |
||
184 | * @return array |
||
185 | */ |
||
186 | public function loadConfig($name = null) |
||
187 | { |
||
188 | if (!empty($name)) { |
||
189 | return MyTextSanitizerExtension::loadConfig($name); |
||
190 | } |
||
191 | $config_default = include $this->path_basic . '/config.php'; |
||
192 | $config_custom = array(); |
||
193 | if (file_exists($file = $this->path_basic . '/config.custom.php')) { |
||
194 | $config_custom = include $file; |
||
195 | } |
||
196 | |||
197 | return $this->mergeConfig($config_default, $config_custom); |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * Enter description here... |
||
202 | * |
||
203 | * @param array $config_default |
||
204 | * @param array $config_custom |
||
205 | * @return unknown |
||
206 | */ |
||
207 | public function mergeConfig($config_default, $config_custom) |
||
208 | { |
||
209 | if (is_array($config_custom)) { |
||
210 | foreach ($config_custom as $key => $val) { |
||
211 | if (isset($config_default[$key]) && is_array($config_default[$key])) { |
||
212 | $config_default[$key] = $this->mergeConfig($config_default[$key], $config_custom[$key]); |
||
213 | } else { |
||
214 | $config_default[$key] = $val; |
||
215 | } |
||
216 | } |
||
217 | } |
||
218 | |||
219 | return $config_default; |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * Access the only instance of this class |
||
224 | * |
||
225 | * @return object |
||
226 | * @static |
||
227 | * @staticvar object |
||
228 | */ |
||
229 | public static function getInstance() |
||
230 | { |
||
231 | static $instance; |
||
232 | if (!isset($instance)) { |
||
233 | $instance = new MyTextSanitizer(); |
||
234 | } |
||
235 | |||
236 | return $instance; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Get the smileys |
||
241 | * |
||
242 | * @param bool $isAll TRUE for all smileys, FALSE for smileys with display = 1 |
||
243 | * |
||
244 | * @return array |
||
245 | */ |
||
246 | public function getSmileys($isAll = true) |
||
247 | { |
||
248 | if (count($this->smileys) == 0) { |
||
249 | $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); |
||
250 | if ($getsmiles = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('smiles'))) { |
||
251 | while ($smiles = $xoopsDB->fetchArray($getsmiles)) { |
||
252 | $this->smileys[] = $smiles; |
||
253 | } |
||
254 | } |
||
255 | } |
||
256 | if ($isAll) { |
||
257 | return $this->smileys; |
||
258 | } |
||
259 | |||
260 | $smileys = array(); |
||
261 | foreach ($this->smileys as $smile) { |
||
262 | if (empty($smile['display'])) { |
||
263 | continue; |
||
264 | } |
||
265 | $smileys[] = $smile; |
||
266 | } |
||
267 | |||
268 | return $smileys; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * Replace emoticons in the message with smiley images |
||
273 | * |
||
274 | * @param string $message |
||
275 | * @return string |
||
276 | */ |
||
277 | public function smiley($message) |
||
278 | { |
||
279 | $smileys = $this->getSmileys(); |
||
280 | foreach ($smileys as $smile) { |
||
281 | $message = str_replace($smile['code'], '<img class="imgsmile" src="' . XOOPS_UPLOAD_URL . '/' . htmlspecialchars($smile['smile_url']) . '" alt="" />', $message); |
||
282 | } |
||
283 | |||
284 | return $message; |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * @param $match |
||
289 | * |
||
290 | * @return string |
||
291 | */ |
||
292 | public function makeClickableCallback01($match) |
||
293 | { |
||
294 | return $match[1] . "<a href=\"$match[2]://$match[3]\" title=\"$match[2]://$match[3]\" rel=\"external\">$match[2]://" . $this->truncate($match[3]) . '</a>'; |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * @param $match |
||
299 | * |
||
300 | * @return string |
||
301 | */ |
||
302 | public function makeClickableCallback02($match) |
||
303 | { |
||
304 | return $match[1] . "<a href=\"http://www.$match[2]$match[6]\" title=\"www.$match[2]$match[6]\" rel=\"external\">" . $this->truncate('www.' . $match[2] . $match[6]) . '</a>'; |
||
305 | } |
||
306 | |||
307 | /** |
||
308 | * @param $match |
||
309 | * |
||
310 | * @return string |
||
311 | */ |
||
312 | public function makeClickableCallback03($match) |
||
313 | { |
||
314 | return $match[1] . "<a href=\"ftp://ftp.$match[2].$match[3]\" title=\"ftp.$match[2].$match[3]\" rel=\"external\">" . $this->truncate('ftp.' . $match[2] . $match[3]) . '</a>'; |
||
315 | } |
||
316 | |||
317 | /** |
||
318 | * @param $match |
||
319 | * |
||
320 | * @return string |
||
321 | */ |
||
322 | public function makeClickableCallback04($match) |
||
323 | { |
||
324 | return $match[1] . "<a href=\"mailto:$match[2]@$match[3]\" title=\"$match[2]@$match[3]\">" . $this->truncate($match[2] . '@' . $match[3]) . '</a>'; |
||
325 | } |
||
326 | |||
327 | /** |
||
328 | * Make links in the text clickable |
||
329 | * |
||
330 | * @param string $text |
||
331 | * @return string |
||
332 | */ |
||
333 | public function makeClickable(&$text) |
||
334 | { |
||
335 | $text1 = $text; |
||
336 | |||
337 | $valid_chars = "a-z0-9\/\-_+=.~!%@?#&;:$\|"; |
||
338 | $end_chars = "a-z0-9\/\-_+=~!%@?#&;:$\|"; |
||
339 | |||
340 | // $patterns = array(); |
||
341 | // $replacements = array(); |
||
342 | // |
||
343 | // $patterns[] = "/(^|[^]_a-z0-9-=\"'\/])([a-z]+?):\/\/([{$valid_chars}]+[{$end_chars}])/ei"; |
||
344 | // $replacements[] = "'\\1<a href=\"\\2://\\3\" title=\"\\2://\\3\" rel=\"external\">\\2://'.MyTextSanitizer::truncate( '\\3' ).'</a>'"; |
||
345 | // |
||
346 | // |
||
347 | // $patterns[] = "/(^|[^]_a-z0-9-=\"'\/:\.])www\.((([a-zA-Z0-9\-]*\.){1,}){1}([a-zA-Z]{2,6}){1})((\/([a-zA-Z0-9\-\._\?\,\'\/\\+&%\$#\=~])*)*)/ei"; |
||
348 | // $replacements[] = "'\\1<a href=\"http://www.\\2\\6\" title=\"www.\\2\\6\" rel=\"external\">'.MyTextSanitizer::truncate( 'www.\\2\\6' ).'</a>'"; |
||
349 | // |
||
350 | // $patterns[] = "/(^|[^]_a-z0-9-=\"'\/])ftp\.([a-z0-9\-]+)\.([{$valid_chars}]+[{$end_chars}])/ei"; |
||
351 | // $replacements[] = "'\\1<a href=\"ftp://ftp.\\2.\\3\" title=\"ftp.\\2.\\3\" rel=\"external\">'.MyTextSanitizer::truncate( 'ftp.\\2.\\3' ).'</a>'"; |
||
352 | // |
||
353 | // $patterns[] = "/(^|[^]_a-z0-9-=\"'\/:\.])([-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+)@((?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?)/ei"; |
||
354 | // $replacements[] = "'\\1<a href=\"mailto:\\2@\\3\" title=\"\\2@\\3\">'.MyTextSanitizer::truncate( '\\2@\\3' ).'</a>'"; |
||
355 | // |
||
356 | // $text = preg_replace($patterns, $replacements, $text); |
||
357 | // |
||
358 | //---------------------------------------------------------------------------------- |
||
359 | |||
360 | $pattern = "/(^|[^]_a-z0-9-=\"'\/])([a-z]+?):\/\/([{$valid_chars}]+[{$end_chars}])/i"; |
||
361 | $text1 = preg_replace_callback($pattern, 'self::makeClickableCallback01', $text1); |
||
362 | |||
363 | $pattern = "/(^|[^]_a-z0-9-=\"'\/:\.])www\.((([a-zA-Z0-9\-]*\.){1,}){1}([a-zA-Z]{2,6}){1})((\/([a-zA-Z0-9\-\._\?\,\'\/\\+&%\$#\=~])*)*)/i"; |
||
364 | $text1 = preg_replace_callback($pattern, 'self::makeClickableCallback02', $text1); |
||
365 | |||
366 | $pattern = "/(^|[^]_a-z0-9-=\"'\/])ftp\.([a-z0-9\-]+)\.([{$valid_chars}]+[{$end_chars}])/i"; |
||
367 | $text1 = preg_replace_callback($pattern, 'self::makeClickableCallback03', $text1); |
||
368 | |||
369 | $pattern = "/(^|[^]_a-z0-9-=\"'\/:\.])([-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+)@((?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?)/i"; |
||
370 | $text1 = preg_replace_callback($pattern, 'self::makeClickableCallback04', $text1); |
||
371 | |||
372 | return $text1; |
||
373 | } |
||
374 | |||
375 | /** |
||
376 | * MyTextSanitizer::truncate() |
||
377 | * |
||
378 | * @param mixed $text |
||
379 | * @return mixed|string |
||
380 | */ |
||
381 | public function truncate($text) |
||
382 | { |
||
383 | $instance = MyTextSanitizer::getInstance(); |
||
384 | if (empty($text) || empty($instance->config['truncate_length']) || strlen($text) < $instance->config['truncate_length']) { |
||
385 | return $text; |
||
386 | } |
||
387 | $len = floor($instance->config['truncate_length'] / 2); |
||
388 | $ret = substr($text, 0, $len) . ' ... ' . substr($text, 5 - $len); |
||
389 | |||
390 | return $ret; |
||
391 | } |
||
392 | |||
393 | /** |
||
394 | * Replace XoopsCodes with their equivalent HTML formatting |
||
395 | * |
||
396 | * @param string $text |
||
397 | * @param bool|int $allowimage Allow images in the text? |
||
398 | * On FALSE, uses links to images. |
||
399 | * @return string |
||
400 | */ |
||
401 | public function &xoopsCodeDecode(&$text, $allowimage = 1) |
||
402 | { |
||
403 | $patterns = array(); |
||
404 | $replacements = array(); |
||
405 | $patterns[] = "/\[siteurl=(['\"]?)([^\"'<>]*)\\1](.*)\[\/siteurl\]/sU"; |
||
406 | $replacements[] = '<a href="' . XOOPS_URL . '/\\2" title="">\\3</a>'; |
||
407 | $patterns[] = "/\[url=(['\"]?)(http[s]?:\/\/[^\"'<>]*)\\1](.*)\[\/url\]/sU"; |
||
408 | $replacements[] = '<a href="\\2" rel="external" title="">\\3</a>'; |
||
409 | $patterns[] = "/\[url=(['\"]?)(ftp?:\/\/[^\"'<>]*)\\1](.*)\[\/url\]/sU"; |
||
410 | $replacements[] = '<a href="\\2" rel="external" title="">\\3</a>'; |
||
411 | $patterns[] = "/\[url=(['\"]?)([^'\"<>]*)\\1](.*)\[\/url\]/sU"; |
||
412 | $replacements[] = '<a href="http://\\2" rel="external" title="">\\3</a>'; |
||
413 | $patterns[] = "/\[color=(['\"]?)([a-zA-Z0-9]*)\\1](.*)\[\/color\]/sU"; |
||
414 | $replacements[] = '<span style="color: #\\2;">\\3</span>'; |
||
415 | $patterns[] = "/\[size=(['\"]?)([a-z0-9-]*)\\1](.*)\[\/size\]/sU"; |
||
416 | $replacements[] = '<span style="font-size: \\2;">\\3</span>'; |
||
417 | $patterns[] = "/\[font=(['\"]?)([^;<>\*\(\)\"']*)\\1](.*)\[\/font\]/sU"; |
||
418 | $replacements[] = '<span style="font-family: \\2;">\\3</span>'; |
||
419 | $patterns[] = "/\[email]([^;<>\*\(\)\"']*)\[\/email\]/sU"; |
||
420 | $replacements[] = '<a href="mailto:\\1" title="">\\1</a>'; |
||
421 | |||
422 | $patterns[] = "/\[b](.*)\[\/b\]/sU"; |
||
423 | $replacements[] = '<strong>\\1</strong>'; |
||
424 | $patterns[] = "/\[i](.*)\[\/i\]/sU"; |
||
425 | $replacements[] = '<em>\\1</em>'; |
||
426 | $patterns[] = "/\[u](.*)\[\/u\]/sU"; |
||
427 | $replacements[] = '<span style="text-decoration: underline;">\\1</span>'; |
||
428 | $patterns[] = "/\[d](.*)\[\/d\]/sU"; |
||
429 | $replacements[] = '<del>\\1</del>'; |
||
430 | $patterns[] = "/\[center](.*)\[\/center\]/sU"; |
||
431 | $replacements[] = '<div style="text-align: center;">\\1</div>'; |
||
432 | $patterns[] = "/\[left](.*)\[\/left\]/sU"; |
||
433 | $replacements[] = '<div style="text-align: left;">\\1</div>'; |
||
434 | $patterns[] = "/\[right](.*)\[\/right\]/sU"; |
||
435 | $replacements[] = '<div style="text-align: right;">\\1</div>'; |
||
436 | |||
437 | $this->text = $text; |
||
438 | $this->patterns = $patterns; |
||
439 | $this->replacements = $replacements; |
||
440 | |||
441 | $this->config['allowimage'] = $allowimage; |
||
442 | $this->executeExtensions(); |
||
443 | |||
444 | $text = preg_replace($this->patterns, $this->replacements, $this->text); |
||
445 | //------------------------------------------------------------------------------- |
||
446 | $count = count($this->callbackPatterns); |
||
447 | |||
448 | for ($i = 0; $i < $count; ++$i) { |
||
449 | $text = preg_replace_callback($this->callbackPatterns[$i], $this->callbacks[$i], $text); |
||
450 | } |
||
451 | //------------------------------------------------------------------------------ |
||
452 | $text = $this->quoteConv($text); |
||
453 | |||
454 | return $text; |
||
455 | } |
||
456 | |||
457 | /** |
||
458 | * Convert quote tags |
||
459 | * |
||
460 | * @param string $text |
||
461 | * @return string |
||
462 | */ |
||
463 | public function quoteConv($text) |
||
464 | { |
||
465 | //look for both open and closing tags in the correct order |
||
466 | $pattern = "/\[quote](.*)\[\/quote\]/sU"; |
||
467 | $replacement = _QUOTEC . '<div class="xoopsQuote"><blockquote>\\1</blockquote></div>'; |
||
468 | |||
469 | $text = preg_replace($pattern, $replacement, $text, -1, $count); |
||
470 | //no more matches, return now |
||
471 | if (!$count) { |
||
472 | return $text; |
||
473 | } |
||
474 | |||
475 | //new matches could have been created, keep doing it until we have no matches |
||
476 | return $this->quoteConv($text); |
||
477 | } |
||
478 | |||
479 | /** |
||
480 | * A quick solution for filtering XSS scripts |
||
481 | * |
||
482 | * @TODO : To be improved |
||
483 | * @param $text |
||
484 | * @return mixed |
||
485 | */ |
||
486 | public function filterXss($text) |
||
502 | |||
503 | /** |
||
504 | * Convert linebreaks to <br> tags |
||
505 | * |
||
506 | * @param string $text |
||
507 | * @return string |
||
508 | */ |
||
509 | public function nl2Br($text) |
||
510 | { |
||
511 | return preg_replace('/(\015\012)|(\015)|(\012)/', '<br>', $text); |
||
512 | } |
||
513 | |||
514 | /** |
||
515 | * Add slashes to the text if magic_quotes_gpc is turned off. |
||
516 | * |
||
517 | * @param string $text |
||
518 | * @return string |
||
519 | */ |
||
520 | public function addSlashes($text) |
||
521 | { |
||
522 | if (!get_magic_quotes_gpc()) { |
||
523 | $text = addslashes($text); |
||
524 | } |
||
525 | |||
526 | return $text; |
||
527 | } |
||
528 | |||
529 | /** |
||
530 | * if magic_quotes_gpc is on, stirip back slashes |
||
531 | * |
||
532 | * @param string $text |
||
533 | * @return string |
||
534 | */ |
||
535 | public function stripSlashesGPC($text) |
||
536 | { |
||
537 | if (get_magic_quotes_gpc()) { |
||
538 | $text = stripslashes($text); |
||
539 | } |
||
540 | |||
541 | return $text; |
||
542 | } |
||
543 | |||
544 | /** |
||
545 | * Convert special characters to HTML entities |
||
546 | * |
||
547 | * @param string $text string being converted |
||
548 | * @param int $quote_style |
||
549 | * @param string $charset character set used in conversion |
||
550 | * @param bool $double_encode |
||
551 | * @return string |
||
552 | */ |
||
553 | public function htmlSpecialChars($text, $quote_style = ENT_QUOTES, $charset = null, $double_encode = true) |
||
554 | { |
||
555 | if (version_compare(phpversion(), '5.2.3', '>=')) { |
||
556 | $text = htmlspecialchars($text, $quote_style, $charset ?: (defined('_CHARSET') ? _CHARSET : 'UTF-8'), $double_encode); |
||
557 | } else { |
||
558 | $text = htmlspecialchars($text, $quote_style); |
||
559 | } |
||
560 | |||
561 | return preg_replace(array('/&/i', '/ /i'), array('&', '&nbsp;'), $text); |
||
562 | } |
||
563 | |||
564 | /** |
||
565 | * Reverses {@link htmlSpecialChars()} |
||
566 | * |
||
567 | * @param string $text |
||
568 | * @return string |
||
569 | */ |
||
570 | public function undoHtmlSpecialChars($text) |
||
571 | { |
||
572 | return preg_replace(array('/>/i', '/</i', '/"/i', '/'/i', '/&nbsp;/i'), array('>', '<', '"', '\'', ' '), $text); |
||
573 | } |
||
574 | |||
575 | /** |
||
576 | * Filters textarea form data in DB for display |
||
577 | * |
||
578 | * @param string $text |
||
579 | * @param bool|int $html allow html? |
||
580 | * @param bool|int $smiley allow smileys? |
||
581 | * @param bool|int $xcode allow xoopscode? |
||
582 | * @param bool|int $image allow inline images? |
||
583 | * @param bool|int $br convert linebreaks? |
||
584 | * @return string |
||
585 | */ |
||
586 | public function &displayTarea($text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1) |
||
622 | |||
623 | /** |
||
624 | * Filters textarea form data submitted for preview |
||
625 | * |
||
626 | * @param string $text |
||
627 | * @param bool|int $html allow html? |
||
628 | * @param bool|int $smiley allow smileys? |
||
629 | * @param bool|int $xcode allow xoopscode? |
||
630 | * @param bool|int $image allow inline images? |
||
631 | * @param bool|int $br convert linebreaks? |
||
632 | * @return string |
||
633 | */ |
||
634 | public function &previewTarea($text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1) |
||
635 | { |
||
636 | $text = $this->stripSlashesGPC($text); |
||
637 | $text =& $this->displayTarea($text, $html, $smiley, $xcode, $image, $br); |
||
638 | |||
639 | return $text; |
||
640 | } |
||
641 | |||
642 | /** |
||
643 | * Replaces banned words in a string with their replacements |
||
644 | * |
||
645 | * @param string $text |
||
646 | * @return string |
||
647 | * @deprecated |
||
648 | */ |
||
649 | public function &censorString(&$text) |
||
658 | |||
659 | /** |
||
660 | * MyTextSanitizer::codePreConv() |
||
661 | * |
||
662 | * @param mixed $text |
||
663 | * @param mixed $xcode |
||
664 | * @return mixed |
||
665 | */ |
||
666 | public function codePreConv($text, $xcode = 1) |
||
667 | { |
||
668 | if ($xcode != 0) { |
||
669 | // $patterns = "/\[code([^\]]*?)\](.*)\[\/code\]/esU"; |
||
670 | // $replacements = "'[code\\1]'.base64_encode('\\2').'[/code]'"; |
||
671 | |||
672 | $patterns = "/\[code([^\]]*?)\](.*)\[\/code\]/sU"; |
||
673 | $text = preg_replace_callback( |
||
674 | $patterns, |
||
675 | function ($matches) { |
||
676 | return '[code'. $matches[1] . ']' . base64_encode($matches[2]) . '[/code]'; |
||
677 | }, |
||
678 | $text |
||
679 | ); |
||
680 | } |
||
681 | |||
682 | return $text; |
||
683 | } |
||
684 | |||
685 | /** |
||
686 | * @param $match |
||
687 | * |
||
688 | * @return string |
||
689 | */ |
||
690 | public function codeConvCallback($match) |
||
694 | |||
695 | /** |
||
696 | * MyTextSanitizer::codeConv() |
||
697 | * |
||
698 | * @param mixed $text |
||
699 | * @param mixed $xcode |
||
700 | * @return mixed |
||
701 | */ |
||
702 | public function codeConv($text, $xcode = 1) |
||
712 | |||
713 | /** |
||
714 | * MyTextSanitizer::executeExtensions() |
||
715 | * |
||
716 | * @return bool |
||
717 | */ |
||
718 | public function executeExtensions() |
||
729 | |||
730 | /** |
||
731 | * MyTextSanitizer::loadExtension() |
||
732 | * |
||
733 | * @param mixed $name |
||
734 | * @return bool|null |
||
735 | */ |
||
736 | public function loadExtension($name) |
||
756 | |||
757 | /** |
||
758 | * MyTextSanitizer::executeExtension() |
||
759 | * |
||
760 | * @param mixed $name |
||
761 | * @return mixed |
||
762 | */ |
||
763 | public function executeExtension($name) |
||
770 | |||
771 | /** |
||
772 | * Filter out possible malicious text |
||
773 | * kses project at SF could be a good solution to check |
||
774 | * |
||
775 | * @param string $text text to filter |
||
776 | * @param bool $force force filtering |
||
777 | * @return string filtered text |
||
778 | */ |
||
779 | public function textFilter($text, $force = false) |
||
788 | |||
789 | // #################### Deprecated Methods ###################### |
||
790 | /** |
||
791 | * *#@+ |
||
792 | * |
||
793 | * @deprecated |
||
794 | */ |
||
795 | |||
796 | /** |
||
797 | * MyTextSanitizer::codeSanitizer() |
||
798 | * |
||
799 | * @param mixed $str |
||
800 | * @param mixed $image |
||
801 | * @return mixed|string |
||
802 | */ |
||
803 | public function codeSanitizer($str, $image = 1) |
||
811 | |||
812 | /** |
||
813 | * MyTextSanitizer::sanitizeForDisplay() |
||
814 | * |
||
815 | * @param mixed $text |
||
816 | * @param integer $allowhtml |
||
817 | * @param integer $smiley |
||
818 | * @param mixed $bbcode |
||
819 | * @return mixed|string |
||
820 | */ |
||
821 | View Code Duplication | public function sanitizeForDisplay($text, $allowhtml = 0, $smiley = 1, $bbcode = 1) |
|
842 | |||
843 | /** |
||
844 | * MyTextSanitizer::sanitizeForPreview() |
||
845 | * |
||
846 | * @param mixed $text |
||
847 | * @param integer $allowhtml |
||
848 | * @param integer $smiley |
||
849 | * @param mixed $bbcode |
||
850 | * @return mixed|string |
||
851 | */ |
||
852 | View Code Duplication | public function sanitizeForPreview($text, $allowhtml = 0, $smiley = 1, $bbcode = 1) |
|
874 | |||
875 | /** |
||
876 | * MyTextSanitizer::makeTboxData4Save() |
||
877 | * |
||
878 | * @param mixed $text |
||
879 | * @return string |
||
880 | */ |
||
881 | public function makeTboxData4Save($text) |
||
888 | |||
889 | /** |
||
890 | * MyTextSanitizer::makeTboxData4Show() |
||
891 | * |
||
892 | * @param mixed $text |
||
893 | * @param mixed $smiley |
||
894 | * @return mixed|string |
||
895 | */ |
||
896 | View Code Duplication | public function makeTboxData4Show($text, $smiley = 0) |
|
903 | |||
904 | /** |
||
905 | * MyTextSanitizer::makeTboxData4Edit() |
||
906 | * |
||
907 | * @param mixed $text |
||
908 | * @return string |
||
909 | */ |
||
910 | public function makeTboxData4Edit($text) |
||
916 | |||
917 | /** |
||
918 | * MyTextSanitizer::makeTboxData4Preview() |
||
919 | * |
||
920 | * @param mixed $text |
||
921 | * @param mixed $smiley |
||
922 | * @return mixed|string |
||
923 | */ |
||
924 | View Code Duplication | public function makeTboxData4Preview($text, $smiley = 0) |
|
932 | |||
933 | /** |
||
934 | * MyTextSanitizer::makeTboxData4PreviewInForm() |
||
935 | * |
||
936 | * @param mixed $text |
||
937 | * @return string |
||
938 | */ |
||
939 | View Code Duplication | public function makeTboxData4PreviewInForm($text) |
|
946 | |||
947 | /** |
||
948 | * MyTextSanitizer::makeTareaData4Save() |
||
949 | * |
||
950 | * @param mixed $text |
||
951 | * @return string |
||
952 | */ |
||
953 | public function makeTareaData4Save($text) |
||
959 | |||
960 | /** |
||
961 | * MyTextSanitizer::makeTareaData4Show() |
||
962 | * |
||
963 | * @param mixed $text |
||
964 | * @param integer $html |
||
965 | * @param integer $smiley |
||
966 | * @param mixed $xcode |
||
967 | * @return mixed|string |
||
968 | */ |
||
969 | View Code Duplication | public function &makeTareaData4Show(&$text, $html = 1, $smiley = 1, $xcode = 1) |
|
976 | |||
977 | /** |
||
978 | * MyTextSanitizer::makeTareaData4Edit() |
||
979 | * |
||
980 | * @param mixed $text |
||
981 | * @return string |
||
982 | */ |
||
983 | public function makeTareaData4Edit($text) |
||
989 | |||
990 | /** |
||
991 | * MyTextSanitizer::makeTareaData4Preview() |
||
992 | * |
||
993 | * @param mixed $text |
||
994 | * @param integer $html |
||
995 | * @param integer $smiley |
||
996 | * @param mixed $xcode |
||
997 | * @return mixed|string |
||
998 | */ |
||
999 | View Code Duplication | public function &makeTareaData4Preview(&$text, $html = 1, $smiley = 1, $xcode = 1) |
|
1006 | |||
1007 | /** |
||
1008 | * MyTextSanitizer::makeTareaData4PreviewInForm() |
||
1009 | * |
||
1010 | * @param mixed $text |
||
1011 | * @return string |
||
1012 | */ |
||
1013 | View Code Duplication | public function makeTareaData4PreviewInForm($text) |
|
1021 | |||
1022 | /** |
||
1023 | * MyTextSanitizer::makeTareaData4InsideQuotes() |
||
1024 | * |
||
1025 | * @param mixed $text |
||
1026 | * @return string |
||
1027 | */ |
||
1028 | public function makeTareaData4InsideQuotes($text) |
||
1034 | |||
1035 | /** |
||
1036 | * MyTextSanitizer::oopsStripSlashesGPC() |
||
1037 | * |
||
1038 | * @param mixed $text |
||
1039 | * @return string |
||
1040 | */ |
||
1041 | public function oopsStripSlashesGPC($text) |
||
1047 | |||
1048 | /** |
||
1049 | * MyTextSanitizer::oopsStripSlashesRT() |
||
1050 | * |
||
1051 | * @param mixed $text |
||
1052 | * @return mixed|string |
||
1053 | */ |
||
1054 | public function oopsStripSlashesRT($text) |
||
1063 | |||
1064 | /** |
||
1065 | * MyTextSanitizer::oopsAddSlashes() |
||
1066 | * |
||
1067 | * @param mixed $text |
||
1068 | * @return string |
||
1069 | */ |
||
1070 | public function oopsAddSlashes($text) |
||
1076 | |||
1077 | /** |
||
1078 | * MyTextSanitizer::oopsHtmlSpecialChars() |
||
1079 | * |
||
1080 | * @param mixed $text |
||
1081 | * @return string |
||
1082 | */ |
||
1083 | public function oopsHtmlSpecialChars($text) |
||
1089 | |||
1090 | /** |
||
1091 | * MyTextSanitizer::oopsNl2Br() |
||
1092 | * |
||
1093 | * @param mixed $text |
||
1094 | * @return string |
||
1095 | */ |
||
1096 | public function oopsNl2Br($text) |
||
1102 | } |
||
1103 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.