Passed
Branch feature/php-docs2 (ac7936)
by Michael
05:35
created

MyTextSanitizer::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * XOOPS TextSanitizer extension
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2021 XOOPS Project (https://xoops.org)
13
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             class
15
 * @since               2.0.0
16
 * @author              Kazumi Ono (http://www.myweb.ne.jp/, http://jp.xoops.org/)
17
 * @author              Goghs Cheng (http://www.eqiao.com, http://www.devbeez.com/)
18
 * @author              Taiwen Jiang <[email protected]>
19
 */
20
21
/**
22
 * Abstract class for extensions
23
 *
24
 * @author              Taiwen Jiang <[email protected]>
25
 * @copyright       (c) 2000-2021 XOOPS Project (https://xoops.org)
26
 */
27
class MyTextSanitizerExtension
28
{
29
    /**
30
     * @var \MyTextSanitizer
31
     */
32
    public $instance;
33
    /**
34
     * @var \MyTextSanitizer
35
     */
36
    public $ts;
37
    /**
38
     * @var \XoopsConfig
39
     */
40
    public $config;
41
    /**
42
     * @var string
43
     */
44
    public $image_path;
45
46
    /**
47
     * Constructor
48
     *
49
     * @param MyTextSanitizer $ts
50
     */
51
    public function __construct(MyTextSanitizer $ts)
52
    {
53
        $this->ts         = $ts;
54
        $this->image_path = XOOPS_URL . '/images/form';
55
    }
56
57
    /**
58
     * loadConfig
59
     *
60
     * @param string|null $path
61
     * @return string|array
62
     */
63
    public static function loadConfig($path = null)
64
    {
65
        $ts   = MyTextSanitizer::getInstance();
66
        $extensionName = (null === $path) ? '' : basename($path);
67
        $pathDist = $ts->path_basic;
68
        $pathConfig = $ts->path_config;
69
70
        if ('' !== $extensionName) {
71
            $configFileName = $pathConfig . '/config.' . $extensionName . '.php';
72
            $distFileName = $pathDist . '/' . $extensionName . '/config.' . $extensionName . '.dist.php';
73
        } else {
74
            $configFileName = $pathConfig . '/config.php';
75
            $distFileName = $pathDist . '/config.dist.php';
76
        }
77
        if (!file_exists($configFileName)) {
78
            if (false === copy($distFileName, $configFileName)) {
79
                trigger_error('Could not create textsanitizer config file ' . basename($configFileName));
80
                return $a = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $a is dead and can be removed.
Loading history...
81
            }
82
        }
83
        $configs = include $configFileName;
84
        return $configs;
85
    }
86
87
    /**
88
     * Merge Config
89
     *
90
     * @param  array $config_default
91
     * @param  array $config_custom
92
     * @return array
93
     */
94
    public static function mergeConfig($config_default, $config_custom)
95
    {
96
        if (is_array($config_custom)) {
0 ignored issues
show
introduced by
The condition is_array($config_custom) is always true.
Loading history...
97
            foreach ($config_custom as $key => $val) {
98
                if (is_array($config_default[$key])) {
99
                    $config_default[$key] = self::mergeConfig($config_default[$key], $config_custom[$key]);
100
                } else {
101
                    $config_default[$key] = $val;
102
                }
103
            }
104
        }
105
106
        return $config_default;
107
    }
108
109
    /**
110
     * encode
111
     *
112
     * @param string $textarea_id id attribute of text area
113
     *
114
     * @return array
115
     */
116
    public function encode($textarea_id)
0 ignored issues
show
Unused Code introduced by
The parameter $textarea_id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

116
    public function encode(/** @scrutinizer ignore-unused */ $textarea_id)

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

Loading history...
117
    {
118
        return array();
119
    }
120
121
    /**
122
     * decode
123
     *
124
     * @param string $url
125
     * @param string|int $width
126
     * @param string|int $height
127
     *
128
     * @return Null
129
     */
130
    public static function decode($url, $width, $height)
0 ignored issues
show
Unused Code introduced by
The parameter $height is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

130
    public static function decode($url, $width, /** @scrutinizer ignore-unused */ $height)

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

Loading history...
Unused Code introduced by
The parameter $width is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

130
    public static function decode($url, /** @scrutinizer ignore-unused */ $width, $height)

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

Loading history...
Unused Code introduced by
The parameter $url is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

130
    public static function decode(/** @scrutinizer ignore-unused */ $url, $width, $height)

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

Loading history...
131
    {
132
        return null;
133
    }
134
}
135
136
/**
137
 * Class to "clean up" text for various uses
138
 *
139
 * <strong>Singleton</strong>
140
 *
141
 * @package       kernel
142
 * @subpackage    core
143
 * @author        Kazumi Ono <[email protected]>
144
 * @author        Taiwen Jiang <[email protected]>
145
 * @author        Goghs Cheng
146
 * @copyright (c) 2000-2021 XOOPS Project (https://xoops.org)
147
 */
148
class MyTextSanitizer
149
{
150
    /**
151
     *
152
     * @var array
153
     */
154
    public $smileys = array();
155
156
    /**
157
     * @var \MytsCensor
158
     */
159
    public $censorConf;
160
161
    /**
162
     *
163
     * @var string holding reference to text
164
     */
165
    public $text         = '';
166
    /**
167
     * @var array
168
     */
169
    public $patterns     = array();
170
    /**
171
     * @var array
172
     */
173
    public $replacements = array();
174
175
    //mb------------------------------
176
    /**
177
     * @var array
178
     */
179
    public $callbackPatterns = array();
180
    /**
181
     * @var array
182
     */
183
    public $callbacks        = array();
184
    //mb------------------------------
185
    /**
186
     * @var string
187
     */
188
    public $path_basic;
189
    /**
190
     * @var string
191
     */
192
    public $path_config;
193
    /**
194
     * @var string
195
     */
196
    public $path_plugin;
197
    /**
198
     * @var \XoopsConfig
199
     */
200
    public $config;
201
202
    /**
203
     * Constructor of this class
204
     *
205
     * Gets allowed html tags from admin config settings
206
     * <br> should not be allowed since nl2br will be used
207
     * when storing data.
208
     *
209
     * @access private
210
     */
211
212
    public function __construct()
213
    {
214
        $this->path_basic  = XOOPS_ROOT_PATH . '/class/textsanitizer';
215
        $this->path_config = XOOPS_VAR_PATH . '/configs/textsanitizer';
216
        $this->path_plugin = XOOPS_ROOT_PATH . '/Frameworks/textsanitizer';
217
        $this->config      = $this->loadConfig();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->loadConfig() of type string or array is incompatible with the declared type XoopsConfig of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
218
    }
219
220
    /**
221
     * Enter description here...
222
     *
223
     * @param string|null $name
224
     * @return array|string
225
     */
226
    public function loadConfig($name = null)
227
    {
228
        // NB: sending a null name results in an infinite loop
229
        if (!empty($name)) {
230
            return MyTextSanitizerExtension::loadConfig($name);
231
        }
232
233
        $configFileName = $this->path_config . '/config.php';
234
        $distFileName = $this->path_basic . '/config.dist.php';
235
236
        if (!file_exists($configFileName)) {
237
            if (false===copy($distFileName, $configFileName)) {
238
                trigger_error('Could not create textsanitizer config file ' . basename($configFileName));
239
                return array();
240
            }
241
        }
242
        return include $configFileName;
243
    }
244
245
    /**
246
     * Enter description here...
247
     *
248
     * @param  array $config_default
249
     * @param  array $config_custom
250
     * @return array
251
     */
252
    public function mergeConfig($config_default, $config_custom)
253
    {
254
        if (is_array($config_custom)) {
0 ignored issues
show
introduced by
The condition is_array($config_custom) is always true.
Loading history...
255
            foreach ($config_custom as $key => $val) {
256
                if (isset($config_default[$key]) && is_array($config_default[$key])) {
257
                    $config_default[$key] = $this->mergeConfig($config_default[$key], $config_custom[$key]);
258
                } else {
259
                    $config_default[$key] = $val;
260
                }
261
            }
262
        }
263
264
        return $config_default;
265
    }
266
267
    /**
268
     * Access the only instance of this class
269
     *
270
     * @return MyTextSanitizer
271
     */
272
    public static function getInstance()
273
    {
274
        static $instance;
275
        if (!isset($instance)) {
276
            $instance = new MyTextSanitizer();
277
        }
278
279
        return $instance;
280
    }
281
282
    /**
283
     * Get the smileys
284
     *
285
     * @param bool $isAll TRUE for all smileys, FALSE for smileys with display = 1
286
     *
287
     * @return array
288
     */
289
    public function getSmileys($isAll = true)
290
    {
291
        if (count($this->smileys) == 0) {
292
            /* @var XoopsMySQLDatabase $xoopsDB */
293
            $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
294
            if ($getsmiles = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('smiles'))) {
295
                while (false !== ($smiles = $xoopsDB->fetchArray($getsmiles))) {
0 ignored issues
show
Bug introduced by
It seems like $getsmiles can also be of type true; however, parameter $result of XoopsMySQLDatabase::fetchArray() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

295
                while (false !== ($smiles = $xoopsDB->fetchArray(/** @scrutinizer ignore-type */ $getsmiles))) {
Loading history...
296
                    $this->smileys[] = $smiles;
297
                }
298
            }
299
        }
300
        if ($isAll) {
301
            return $this->smileys;
302
        }
303
304
        $smileys = array();
305
        foreach ($this->smileys as $smile) {
306
            if (empty($smile['display'])) {
307
                continue;
308
            }
309
            $smileys[] = $smile;
310
        }
311
312
        return $smileys;
313
    }
314
315
    /**
316
     * Replace emoticons in the message with smiley images
317
     *
318
     * @param  string $message
319
     * @return string
320
     */
321
    public function smiley($message)
322
    {
323
        $smileys = $this->getSmileys();
324
        foreach ($smileys as $smile) {
325
            $message = str_replace($smile['code'], '<img class="imgsmile" src="' . XOOPS_UPLOAD_URL . '/' . htmlspecialchars($smile['smile_url']) . '" alt="" />', $message);
326
        }
327
328
        return $message;
329
    }
330
331
    /**
332
     * @param array $match
333
     *
334
     * @return string
335
     */
336
    public function makeClickableCallback01($match)
337
    {
338
        return $match[1] . "<a href=\"$match[2]://$match[3]\" title=\"$match[2]://$match[3]\" rel=\"noopener external\">$match[2]://" . $this->truncate($match[3]) . '</a>';
339
    }
340
341
    /**
342
     * @param array $match
343
     *
344
     * @return string
345
     */
346
    public function makeClickableCallback02($match)
347
    {
348
        return $match[1] . "<a href=\"http://www.$match[2]$match[6]\" title=\"www.$match[2]$match[6]\" rel=\"noopener external\">" . $this->truncate('www.' . $match[2] . $match[6]) . '</a>';
349
    }
350
351
    /**
352
     * @param array $match
353
     *
354
     * @return string
355
     */
356
    public function makeClickableCallback03($match)
357
    {
358
        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>';
359
    }
360
361
    /**
362
     * @param array $match
363
     *
364
     * @return string
365
     */
366
    public function makeClickableCallback04($match)
367
    {
368
        return $match[1] . "<a href=\"mailto:$match[2]@$match[3]\" title=\"$match[2]@$match[3]\">" . $this->truncate($match[2] . '@' . $match[3]) . '</a>';
369
    }
370
371
    /**
372
     * Make links in the text clickable
373
     *
374
     * @param  string $text
375
     * @return string
376
     */
377
    public function makeClickable(&$text)
378
    {
379
        $text1 = $text;
380
381
        $valid_chars = 'a-z0-9\/\-_+=.~!%@?#&;:$\|';
382
        $end_chars   = 'a-z0-9\/\-_+=~!%@?#&;:$\|';
383
384
        //        $patterns   = array();
385
        //        $replacements   = array();
386
        //
387
        //        $patterns[]     = "/(^|[^]_a-z0-9-=\"'\/])([a-z]+?):\/\/([{$valid_chars}]+[{$end_chars}])/ei";
388
        //        $replacements[] = "'\\1<a href=\"\\2://\\3\" title=\"\\2://\\3\" rel=\"external\">\\2://'.MyTextSanitizer::truncate( '\\3' ).'</a>'";
389
        //
390
        //
391
        //        $patterns[]     = "/(^|[^]_a-z0-9-=\"'\/:\.])www\.((([a-zA-Z0-9\-]*\.){1,}){1}([a-zA-Z]{2,6}){1})((\/([a-zA-Z0-9\-\._\?\,\'\/\\+&%\$#\=~])*)*)/ei";
392
        //        $replacements[] = "'\\1<a href=\"http://www.\\2\\6\" title=\"www.\\2\\6\" rel=\"external\">'.MyTextSanitizer::truncate( 'www.\\2\\6' ).'</a>'";
393
        //
394
        //        $patterns[]     = "/(^|[^]_a-z0-9-=\"'\/])ftp\.([a-z0-9\-]+)\.([{$valid_chars}]+[{$end_chars}])/ei";
395
        //        $replacements[] = "'\\1<a href=\"ftp://ftp.\\2.\\3\" title=\"ftp.\\2.\\3\" rel=\"external\">'.MyTextSanitizer::truncate( 'ftp.\\2.\\3' ).'</a>'";
396
        //
397
        //        $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";
398
        //        $replacements[] = "'\\1<a href=\"mailto:\\2@\\3\" title=\"\\2@\\3\">'.MyTextSanitizer::truncate( '\\2@\\3' ).'</a>'";
399
        //
400
        //        $text = preg_replace($patterns, $replacements, $text);
401
        //
402
        //----------------------------------------------------------------------------------
403
404
        $pattern = "/(^|[^]_a-z0-9-=\"'\/])([a-z]+?):\/\/([{$valid_chars}]+[{$end_chars}])/i";
405
        $text1   = preg_replace_callback($pattern, 'self::makeClickableCallback01', $text1);
406
407
        $pattern = "/(^|[^]_a-z0-9-=\"'\/:\.])www\.((([a-zA-Z0-9\-]*\.){1,}){1}([a-zA-Z]{2,6}){1})((\/([a-zA-Z0-9\-\._\?\,\'\/\\+&%\$#\=~])*)*)/i";
408
        $text1   = preg_replace_callback($pattern, 'self::makeClickableCallback02', $text1);
409
410
        $pattern = "/(^|[^]_a-z0-9-=\"'\/])ftp\.([a-z0-9\-]+)\.([{$valid_chars}]+[{$end_chars}])/i";
411
        $text1   = preg_replace_callback($pattern, 'self::makeClickableCallback03', $text1);
412
413
        $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";
414
        $text1   = preg_replace_callback($pattern, 'self::makeClickableCallback04', $text1);
415
416
        return $text1;
417
    }
418
419
    /**
420
     * MyTextSanitizer::truncate()
421
     *
422
     * @param  mixed $text
423
     * @return mixed|string
424
     */
425
    public function truncate($text)
426
    {
427
        $instance = MyTextSanitizer::getInstance();
428
        if (empty($text) || empty($instance->config['truncate_length']) || strlen($text) < $instance->config['truncate_length']) {
429
            return $text;
430
        }
431
        $len = floor($instance->config['truncate_length'] / 2);
432
        $ret = substr($text, 0, $len) . ' ... ' . substr($text, 5 - $len);
0 ignored issues
show
Bug introduced by
$len of type double is incompatible with the type integer|null expected by parameter $length of substr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

432
        $ret = substr($text, 0, /** @scrutinizer ignore-type */ $len) . ' ... ' . substr($text, 5 - $len);
Loading history...
Bug introduced by
5 - $len of type double is incompatible with the type integer expected by parameter $offset of substr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

432
        $ret = substr($text, 0, $len) . ' ... ' . substr($text, /** @scrutinizer ignore-type */ 5 - $len);
Loading history...
433
434
        return $ret;
435
    }
436
437
    /**
438
     * Replace XoopsCodes with their equivalent HTML formatting
439
     *
440
     * @param  string   $text
441
     * @param  bool|int $allowimage Allow images in the text?
442
     *                              On FALSE, uses links to images.
443
     * @return string
444
     */
445
    public function &xoopsCodeDecode(&$text, $allowimage = 1)
446
    {
447
        $patterns       = array();
448
        $replacements   = array();
449
        $patterns[]     = "/\[siteurl=(['\"]?)([^\"'<>]*)\\1](.*)\[\/siteurl\]/sU";
450
        $replacements[] = '<a href="' . XOOPS_URL . '/\\2" title="">\\3</a>';
451
        $patterns[]     = "/\[url=(['\"]?)(http[s]?:\/\/[^\"'<>]*)\\1](.*)\[\/url\]/sU";
452
        $replacements[] = '<a href="\\2" rel="noopener external" title="">\\3</a>';
453
        $patterns[]     = "/\[url=(['\"]?)(ftp?:\/\/[^\"'<>]*)\\1](.*)\[\/url\]/sU";
454
        $replacements[] = '<a href="\\2" rel="external" title="">\\3</a>';
455
        $patterns[]     = "/\[url=(['\"]?)([^'\"<>]*)\\1](.*)\[\/url\]/sU";
456
        $replacements[] = '<a href="http://\\2" rel="noopener external" title="">\\3</a>';
457
        $patterns[]     = "/\[color=(['\"]?)([a-zA-Z0-9]*)\\1](.*)\[\/color\]/sU";
458
        $replacements[] = '<span style="color: #\\2;">\\3</span>';
459
        $patterns[]     = "/\[size=(['\"]?)([a-z0-9-]*)\\1](.*)\[\/size\]/sU";
460
        $replacements[] = '<span style="font-size: \\2;">\\3</span>';
461
        $patterns[]     = "/\[font=(['\"]?)([^;<>\*\(\)\"']*)\\1](.*)\[\/font\]/sU";
462
        $replacements[] = '<span style="font-family: \\2;">\\3</span>';
463
        $patterns[]     = "/\[email]([^;<>\*\(\)\"']*)\[\/email\]/sU";
464
        $replacements[] = '<a href="mailto:\\1" title="">\\1</a>';
465
466
        $patterns[]     = '/\[b](.*)\[\/b\]/sU';
467
        $replacements[] = '<strong>\\1</strong>';
468
        $patterns[]     = '/\[i](.*)\[\/i\]/sU';
469
        $replacements[] = '<em>\\1</em>';
470
        $patterns[]     = '/\[u](.*)\[\/u\]/sU';
471
        $replacements[] = '<span style="text-decoration: underline;">\\1</span>';
472
        $patterns[]     = '/\[d](.*)\[\/d\]/sU';
473
        $replacements[] = '<del>\\1</del>';
474
        $patterns[]     = '/\[center](.*)\[\/center\]/sU';
475
        $replacements[] = '<div style="text-align: center;">\\1</div>';
476
        $patterns[]     = '/\[left](.*)\[\/left\]/sU';
477
        $replacements[] = '<div style="text-align: left;">\\1</div>';
478
        $patterns[]     = '/\[right](.*)\[\/right\]/sU';
479
        $replacements[] = '<div style="text-align: right;">\\1</div>';
480
481
        $this->text         = $text;
482
        $this->patterns     = $patterns;
483
        $this->replacements = $replacements;
484
485
        $this->config['allowimage'] = $allowimage;
486
        $this->executeExtensions();
487
488
        $text = preg_replace($this->patterns, $this->replacements, $this->text);
489
        //-------------------------------------------------------------------------------
490
        $count = count($this->callbackPatterns);
491
492
        for ($i = 0; $i < $count; ++$i) {
493
            $text = preg_replace_callback($this->callbackPatterns[$i], $this->callbacks[$i], $text);
494
        }
495
        //------------------------------------------------------------------------------
496
        $text = $this->quoteConv($text);
497
498
        return $text;
499
    }
500
501
    /**
502
     * Convert quote tags
503
     *
504
     * @param  string $text
505
     * @return string
506
     */
507
    public function quoteConv($text)
508
    {
509
        //look for both open and closing tags in the correct order
510
        $pattern     = '/\[quote](.*)\[\/quote\]/sU';
511
        $replacement = _QUOTEC . '<div class="xoopsQuote"><blockquote>\\1</blockquote></div>';
512
513
        $text = preg_replace($pattern, $replacement, $text, -1, $count);
514
        //no more matches, return now
515
        if (!$count) {
516
            return $text;
517
        }
518
519
        //new matches could have been created, keep doing it until we have no matches
520
        return $this->quoteConv($text);
521
    }
522
523
    /**
524
     * A quick solution for filtering XSS scripts
525
     *
526
     * @TODO : To be improved
527
     * @param string $text
528
     * @return array|string|string[]|null
529
     */
530
    public function filterXss($text)
531
    {
532
        $patterns       = array();
533
        $replacements   = array();
534
        $text           = str_replace("\x00", '', $text);
535
        $c              = "[\x01-\x1f]*";
536
        $patterns[]     = "/\bj{$c}a{$c}v{$c}a{$c}s{$c}c{$c}r{$c}i{$c}p{$c}t{$c}[\s]*:/si";
537
        $replacements[] = 'javascript;';
538
        $patterns[]     = "/\ba{$c}b{$c}o{$c}u{$c}t{$c}[\s]*:/si";
539
        $replacements[] = 'about;';
540
        $patterns[]     = "/\bx{$c}s{$c}s{$c}[\s]*:/si";
541
        $replacements[] = 'xss;';
542
        $text           = preg_replace($patterns, $replacements, $text);
543
544
        return $text;
545
    }
546
547
    /**
548
     * Convert linebreaks to <br> tags
549
     *
550
     * @param  string $text
551
     * @return string
552
     */
553
    public function nl2Br($text)
554
    {
555
        return preg_replace('/(\015\012)|(\015)|(\012)/', '<br>', $text);
556
    }
557
558
    /**
559
     * Add slashes to the text if magic_quotes_gpc is turned off.
560
     *
561
     * @param  string $text
562
     * @return string
563
     */
564
    public function addSlashes($text)
565
    {
566
        if (!@get_magic_quotes_gpc()) {
567
            $text = addslashes($text);
568
        }
569
570
        return $text;
571
    }
572
573
    /**
574
     * Convert special characters to HTML entities
575
     *
576
     * @param  string $text    string being converted
577
     * @param  int|null    $quote_style
578
     * @param string|null $charset character set used in conversion
579
     * @param  bool   $double_encode
580
     * @return string
581
     */
582
    public function htmlSpecialChars($text, $quote_style = null, $charset = null, $double_encode = true)
583
    {
584
        if ($quote_style === null) {
585
            $quote_style = ENT_QUOTES;
586
        }
587
588
        if (version_compare(phpversion(), '5.2.3', '>=')) {
589
            $text = htmlspecialchars(isset($text) ? $text : '', $quote_style, $charset ?: (defined('_CHARSET') ? _CHARSET : 'UTF-8'), $double_encode);
590
        } else {
591
            $text = htmlspecialchars(isset($text) ? $text : '', $quote_style);
592
        }
593
594
        return preg_replace(array('/&amp;/i', '/&nbsp;/i'), array('&', '&amp;nbsp;'), $text);
595
    }
596
597
    /**
598
     * Reverses {@link htmlSpecialChars()}
599
     *
600
     * @param  string $text
601
     * @return string
602
     */
603
    public function undoHtmlSpecialChars($text)
604
    {
605
        return preg_replace(array('/&gt;/i', '/&lt;/i', '/&quot;/i', '/&#039;/i', '/&amp;nbsp;/i'), array('>', '<', '"', '\'', '&nbsp;'), $text);
606
    }
607
608
    /**
609
     * Filters textarea form data in DB for display
610
     *
611
     * @param  string   $text
612
     * @param  bool|int $html   allow html?
613
     * @param  bool|int $smiley allow smileys?
614
     * @param  bool|int $xcode  allow xoopscode?
615
     * @param  bool|int $image  allow inline images?
616
     * @param  bool|int $br     convert linebreaks?
617
     * @return string
618
     */
619
    public function &displayTarea($text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1)
620
    {
621
        $charset = (defined('_CHARSET') ? _CHARSET : 'UTF-8');
622
        if (function_exists('mb_convert_encoding')) {
623
            $text = mb_convert_encoding(isset($text) ? $text : '', $charset, mb_detect_encoding(isset($text) ? $text : '', mb_detect_order(), true));
0 ignored issues
show
Bug introduced by
It seems like mb_detect_order() can also be of type true; however, parameter $encodings of mb_detect_encoding() does only seem to accept array|null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

623
            $text = mb_convert_encoding(isset($text) ? $text : '', $charset, mb_detect_encoding(isset($text) ? $text : '', /** @scrutinizer ignore-type */ mb_detect_order(), true));
Loading history...
624
        }
625
        if ($html && $br) {
626
            $testText = strip_tags($text);
0 ignored issues
show
Bug introduced by
It seems like $text can also be of type array; however, parameter $string of strip_tags() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

626
            $testText = strip_tags(/** @scrutinizer ignore-type */ $text);
Loading history...
627
            if (mb_strlen($text) != mb_strlen($testText)) {
0 ignored issues
show
Bug introduced by
It seems like $text can also be of type array; however, parameter $string of mb_strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

627
            if (mb_strlen(/** @scrutinizer ignore-type */ $text) != mb_strlen($testText)) {
Loading history...
628
                $br = 0;
629
            }
630
            unset($testText);
631
        }
632
        if ($html != 1) {
633
            // html not allowed
634
            $text = $this->htmlSpecialChars($text, ENT_COMPAT, $charset);
0 ignored issues
show
Bug introduced by
It seems like $text can also be of type array; however, parameter $text of MyTextSanitizer::htmlSpecialChars() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

634
            $text = $this->htmlSpecialChars(/** @scrutinizer ignore-type */ $text, ENT_COMPAT, $charset);
Loading history...
635
        }
636
        $text = $this->codePreConv($text, $xcode); // Ryuji_edit(2003-11-18)
637
        if ($smiley != 0) {
638
            // process smiley
639
            $text = $this->smiley($text);
0 ignored issues
show
Bug introduced by
It seems like $text can also be of type array; however, parameter $message of MyTextSanitizer::smiley() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

639
            $text = $this->smiley(/** @scrutinizer ignore-type */ $text);
Loading history...
640
        }
641
        if ($xcode != 0) {
642
            // decode xcode
643
            if ($image != 0) {
644
                // image allowed
645
                $text =& $this->xoopsCodeDecode($text);
0 ignored issues
show
Bug introduced by
It seems like $text can also be of type array; however, parameter $text of MyTextSanitizer::xoopsCodeDecode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

645
                $text =& $this->xoopsCodeDecode(/** @scrutinizer ignore-type */ $text);
Loading history...
646
            } else {
647
                // image not allowed
648
                $text =& $this->xoopsCodeDecode($text, 0);
649
            }
650
        }
651
        if ($br != 0) {
652
            $text = $this->nl2Br($text);
0 ignored issues
show
Bug introduced by
It seems like $text can also be of type array; however, parameter $text of MyTextSanitizer::nl2Br() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

652
            $text = $this->nl2Br(/** @scrutinizer ignore-type */ $text);
Loading history...
653
        }
654
        $text = $this->codeConv($text, $xcode);
655
        $text = $this->makeClickable($text);
0 ignored issues
show
Bug introduced by
It seems like $text can also be of type array; however, parameter $text of MyTextSanitizer::makeClickable() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

655
        $text = $this->makeClickable(/** @scrutinizer ignore-type */ $text);
Loading history...
656
        if (!empty($this->config['filterxss_on_display'])) {
657
            $text = $this->filterXss($text);
658
        }
659
660
        return $text;
661
    }
662
663
    /**
664
     * Filters textarea form data submitted for preview
665
     *
666
     * @param  string   $text
667
     * @param  bool|int $html   allow html?
668
     * @param  bool|int $smiley allow smileys?
669
     * @param  bool|int $xcode  allow xoopscode?
670
     * @param  bool|int $image  allow inline images?
671
     * @param  bool|int $br     convert linebreaks?
672
     * @return string
673
     */
674
    public function &previewTarea($text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1)
675
    {
676
        $text = $this->stripSlashesGPC($text);
0 ignored issues
show
Deprecated Code introduced by
The function MyTextSanitizer::stripSlashesGPC() has been deprecated: as of XOOPS 2.5.11 and will be removed in next XOOPS version ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

676
        $text = /** @scrutinizer ignore-deprecated */ $this->stripSlashesGPC($text);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
677
        $text =& $this->displayTarea($text, $html, $smiley, $xcode, $image, $br);
678
679
        return $text;
680
    }
681
682
    /**
683
     * Replaces banned words in a string with their replacements
684
     *
685
     * @param  string $text
686
     * @return string
687
     * @deprecated
688
     */
689
    public function &censorString(&$text)
690
    {
691
        $ret = $this->executeExtension('censor', $text);
692
        if ($ret === false) {
693
            return $text;
694
        }
695
696
        return $ret;
697
    }
698
699
    /**
700
     * MyTextSanitizer::codePreConv()
701
     *
702
     * @param  mixed $text
703
     * @param  mixed $xcode
704
     * @return mixed
705
     */
706
    public function codePreConv($text, $xcode = 1)
707
    {
708
        if ($xcode != 0) {
709
            //            $patterns = "/\[code([^\]]*?)\](.*)\[\/code\]/esU";
710
            //            $replacements = "'[code\\1]'.base64_encode('\\2').'[/code]'";
711
712
            $patterns = '/\[code([^\]]*?)\](.*)\[\/code\]/sU';
713
            $text = preg_replace_callback(
714
                $patterns,
715
                function ($matches) {
716
                    return '[code'. $matches[1] . ']' . base64_encode($matches[2]) . '[/code]';
717
                },
718
                $text
719
            );
720
        }
721
722
        return $text;
723
    }
724
725
    /**
726
     * @param $match
727
     *
728
     * @return string
729
     */
730
    public function codeConvCallback($match)
731
    {
732
        return '<div class="xoopsCode">' . $this->executeExtension('syntaxhighlight', str_replace('\\\"', '\"', base64_decode($match[2])), $match[1]) . '</div>';
733
    }
734
735
    /**
736
     * MyTextSanitizer::codeConv()
737
     *
738
     * @param  mixed $text
739
     * @param  mixed $xcode
740
     * @return mixed
741
     */
742
    public function codeConv($text, $xcode = 1)
743
    {
744
        if (empty($xcode)) {
745
            return $text;
746
        }
747
        $patterns = '/\[code([^\]]*?)\](.*)\[\/code\]/sU';
748
        $text1    = preg_replace_callback($patterns, array(
749
            $this,
750
            'codeConvCallback',
751
        ),  $text);
752
753
        return $text1;
754
    }
755
756
    /**
757
     * MyTextSanitizer::executeExtensions()
758
     *
759
     * @return bool|null
760
     */
761
    public function executeExtensions()
762
    {
763
        $extensions = array_filter($this->config['extensions']);
764
        if (empty($extensions)) {
765
            return true;
766
        }
767
        foreach (array_keys($extensions) as $extension) {
768
            $this->executeExtension($extension);
769
        }
770
        return null;
771
    }
772
773
    /**
774
     * MyTextSanitizer::loadExtension()
775
     *
776
     * @param  mixed $name
777
     * @return MyTextSanitizerExtension|false
778
     */
779
    public function loadExtension($name)
780
    {
781
        if (file_exists($file = $this->path_basic . '/' . $name . '/' . $name . '.php')) {
782
            include_once $file;
783
        } elseif (file_exists($file = $this->path_plugin . '/' . $name . '/' . $name . '.php')) {
784
            include_once $file;
785
        } else {
786
            return false;
787
        }
788
        $class = 'Myts' . ucfirst($name);
789
        if (!class_exists($class)) {
790
            trigger_error("Extension '{$name}' does not exist", E_USER_WARNING);
791
792
            return false;
793
        }
794
        return new $class($this);
795
    }
796
797
    /**
798
     * MyTextSanitizer::executeExtension()
799
     *
800
     * @param  mixed $name
801
     * @return mixed
802
     */
803
    public function executeExtension($name)
804
    {
805
        $extension = $this->loadExtension($name);
806
        $args      = array_slice(func_get_args(), 1);
807
        array_unshift($args, $this);
808
809
        return call_user_func_array(array(
810
                                        $extension,
811
                                        'load',
812
                                    ), $args);
813
    }
814
815
    /**
816
     * Filter out possible malicious text
817
     * kses project at SF could be a good solution to check
818
     *
819
     * @param  string $text  text to filter
820
     * @param  bool   $force force filtering
821
     * @return string filtered text
822
     */
823
    public function textFilter($text, $force = false)
824
    {
825
        $ret = $this->executeExtension('textfilter', $text, $force);
826
        if ($ret === false) {
827
            return $text;
828
        }
829
830
        return $ret;
831
    }
832
833
    // #################### Deprecated Methods ######################
834
835
    /**
836
     * if magic_quotes_gpc is on, strip back slashes
837
     *
838
     * @param  string $text
839
     * @return string
840
     * @deprecated as of XOOPS 2.5.11 and will be removed in next XOOPS version
841
     *
842
     * This remains here until we officially drop support for PHP 5.3 in next release
843
     */
844
    public function stripSlashesGPC($text)
845
    {
846
        if (@get_magic_quotes_gpc()) {
847
            $text = stripslashes($text);
848
        }
849
850
        return $text;
851
    }
852
853
    /**
854
     * MyTextSanitizer::codeSanitizer()
855
     *
856
     * @param  mixed $str
857
     * @param  mixed $image
858
     * @return string
859
     * @deprecated will be removed in next XOOPS version
860
     */
861
    public function codeSanitizer($str, $image = 1)
862
    {
863
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
864
        $str = $this->htmlSpecialChars(str_replace('\"', '"', base64_decode($str)));
865
        $str =& $this->xoopsCodeDecode($str, $image);
866
867
        return $str;
868
    }
869
870
    /**
871
     * MyTextSanitizer::sanitizeForDisplay()
872
     *
873
     * @param  mixed   $text
874
     * @param int $allowhtml
875
     * @param int $smiley
876
     * @param  mixed   $bbcode
877
     * @return string
878
     * @deprecated will be removed in next XOOPS version
879
     */
880
    public function sanitizeForDisplay($text, $allowhtml = 0, $smiley = 1, $bbcode = 1)
881
    {
882
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
883
        if ($allowhtml == 0) {
884
            $text = $this->htmlSpecialChars($text);
885
        } else {
886
            // $config =& $GLOBALS['xoopsConfig'];
887
            // $allowed = $config['allowed_html'];
888
            // $text = strip_tags($text, $allowed);
889
            $text = $this->makeClickable($text);
890
        }
891
        if ($smiley == 1) {
892
            $text = $this->smiley($text);
893
        }
894
        if ($bbcode == 1) {
895
            $text =& $this->xoopsCodeDecode($text);
896
        }
897
        $text = $this->nl2Br($text);
898
899
        return $text;
900
    }
901
902
    /**
903
     * MyTextSanitizer::sanitizeForPreview()
904
     *
905
     * @param  mixed   $text
906
     * @param int $allowhtml
907
     * @param int $smiley
908
     * @param  mixed   $bbcode
909
     * @return string
910
     * @deprecated will be removed in next XOOPS version
911
     */
912
    public function sanitizeForPreview($text, $allowhtml = 0, $smiley = 1, $bbcode = 1)
913
    {
914
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
915
        $text = $this->oopsStripSlashesGPC($text);
0 ignored issues
show
Deprecated Code introduced by
The function MyTextSanitizer::oopsStripSlashesGPC() has been deprecated: will be removed in next XOOPS version ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

915
        $text = /** @scrutinizer ignore-deprecated */ $this->oopsStripSlashesGPC($text);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
916
        if ($allowhtml == 0) {
917
            $text = $this->htmlSpecialChars($text);
918
        } else {
919
            // $config =& $GLOBALS['xoopsConfig'];
920
            // $allowed = $config['allowed_html'];
921
            // $text = strip_tags($text, $allowed);
922
            $text = $this->makeClickable($text);
923
        }
924
        if ($smiley == 1) {
925
            $text = $this->smiley($text);
926
        }
927
        if ($bbcode == 1) {
928
            $text =& $this->xoopsCodeDecode($text);
929
        }
930
        $text = $this->nl2Br($text);
931
932
        return $text;
933
    }
934
935
    /**
936
     * MyTextSanitizer::makeTboxData4Save()
937
     *
938
     * @param  mixed $text
939
     * @return string
940
     * @deprecated will be removed in next XOOPS version
941
     */
942
    public function makeTboxData4Save($text)
943
    {
944
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
945
946
        // $text = $this->undoHtmlSpecialChars($text);
947
        return $this->addSlashes($text);
948
    }
949
950
    /**
951
     * MyTextSanitizer::makeTboxData4Show()
952
     *
953
     * @param  mixed $text
954
     * @param  mixed $smiley
955
     * @return string
956
     * @deprecated will be removed in next XOOPS version
957
     */
958
    public function makeTboxData4Show($text, $smiley = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $smiley is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

958
    public function makeTboxData4Show($text, /** @scrutinizer ignore-unused */ $smiley = 0)

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

Loading history...
959
    {
960
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
961
        $text = $this->htmlSpecialChars($text);
962
963
        return $text;
964
    }
965
966
    /**
967
     * MyTextSanitizer::makeTboxData4Edit()
968
     *
969
     * @param  mixed $text
970
     * @return string
971
     * @deprecated will be removed in next XOOPS version
972
     */
973
    public function makeTboxData4Edit($text)
974
    {
975
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
976
977
        return $this->htmlSpecialChars($text);
978
    }
979
980
    /**
981
     * MyTextSanitizer::makeTboxData4Preview()
982
     *
983
     * @param  mixed $text
984
     * @param  mixed $smiley
985
     * @return string
986
     * @deprecated will be removed in next XOOPS version
987
     */
988
    public function makeTboxData4Preview($text, $smiley = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $smiley is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

988
    public function makeTboxData4Preview($text, /** @scrutinizer ignore-unused */ $smiley = 0)

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

Loading history...
989
    {
990
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
991
        $text = $this->stripSlashesGPC($text);
0 ignored issues
show
Deprecated Code introduced by
The function MyTextSanitizer::stripSlashesGPC() has been deprecated: as of XOOPS 2.5.11 and will be removed in next XOOPS version ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

991
        $text = /** @scrutinizer ignore-deprecated */ $this->stripSlashesGPC($text);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
992
        $text = $this->htmlSpecialChars($text);
993
994
        return $text;
995
    }
996
997
    /**
998
     * MyTextSanitizer::makeTboxData4PreviewInForm()
999
     *
1000
     * @param  mixed $text
1001
     * @return string
1002
     * @deprecated will be removed in next XOOPS version
1003
     */
1004
    public function makeTboxData4PreviewInForm($text)
1005
    {
1006
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1007
        $text = $this->stripSlashesGPC($text);
0 ignored issues
show
Deprecated Code introduced by
The function MyTextSanitizer::stripSlashesGPC() has been deprecated: as of XOOPS 2.5.11 and will be removed in next XOOPS version ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1007
        $text = /** @scrutinizer ignore-deprecated */ $this->stripSlashesGPC($text);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1008
1009
        return $this->htmlSpecialChars($text);
1010
    }
1011
1012
    /**
1013
     * MyTextSanitizer::makeTareaData4Save()
1014
     *
1015
     * @param  mixed $text
1016
     * @return string
1017
     * @deprecated will be removed in next XOOPS version
1018
     */
1019
    public function makeTareaData4Save($text)
1020
    {
1021
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1022
1023
        return $this->addSlashes($text);
1024
    }
1025
1026
    /**
1027
     * MyTextSanitizer::makeTareaData4Show()
1028
     *
1029
     * @param  mixed   $text
1030
     * @param int $html
1031
     * @param int $smiley
1032
     * @param  mixed   $xcode
1033
     * @return string
1034
     * @deprecated will be removed in next XOOPS version
1035
     */
1036
    public function &makeTareaData4Show(&$text, $html = 1, $smiley = 1, $xcode = 1)
1037
    {
1038
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1039
        $text =& $this->displayTarea($text, $html, $smiley, $xcode);
1040
1041
        return $text;
1042
    }
1043
1044
    /**
1045
     * MyTextSanitizer::makeTareaData4Edit()
1046
     *
1047
     * @param  mixed $text
1048
     * @return string
1049
     * @deprecated will be removed in next XOOPS version
1050
     */
1051
    public function makeTareaData4Edit($text)
1052
    {
1053
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1054
1055
        return $this->htmlSpecialChars($text);
1056
    }
1057
1058
    /**
1059
     * MyTextSanitizer::makeTareaData4Preview()
1060
     *
1061
     * @param  mixed   $text
1062
     * @param int $html
1063
     * @param int $smiley
1064
     * @param  mixed   $xcode
1065
     * @return string
1066
     * @deprecated will be removed in next XOOPS version
1067
     */
1068
    public function &makeTareaData4Preview(&$text, $html = 1, $smiley = 1, $xcode = 1)
1069
    {
1070
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1071
        $text =& $this->previewTarea($text, $html, $smiley, $xcode);
1072
1073
        return $text;
1074
    }
1075
1076
    /**
1077
     * MyTextSanitizer::makeTareaData4PreviewInForm()
1078
     *
1079
     * @param  mixed $text
1080
     * @return string
1081
     * @deprecated will be removed in next XOOPS version
1082
     */
1083
    public function makeTareaData4PreviewInForm($text)
1084
    {
1085
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1086
        // if magic_quotes_gpc is on, do stipslashes
1087
        $text = $this->stripSlashesGPC($text);
0 ignored issues
show
Deprecated Code introduced by
The function MyTextSanitizer::stripSlashesGPC() has been deprecated: as of XOOPS 2.5.11 and will be removed in next XOOPS version ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1087
        $text = /** @scrutinizer ignore-deprecated */ $this->stripSlashesGPC($text);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1088
1089
        return $this->htmlSpecialChars($text);
1090
    }
1091
1092
    /**
1093
     * MyTextSanitizer::makeTareaData4InsideQuotes()
1094
     *
1095
     * @param  mixed $text
1096
     * @return string
1097
     * @deprecated will be removed in next XOOPS version
1098
     */
1099
    public function makeTareaData4InsideQuotes($text)
1100
    {
1101
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1102
1103
        return $this->htmlSpecialChars($text);
1104
    }
1105
1106
    /**
1107
     * MyTextSanitizer::oopsStripSlashesGPC()
1108
     *
1109
     * @param  mixed $text
1110
     * @return string
1111
     * @deprecated will be removed in next XOOPS version
1112
     */
1113
    public function oopsStripSlashesGPC($text)
1114
    {
1115
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1116
1117
        return $this->stripSlashesGPC($text);
0 ignored issues
show
Deprecated Code introduced by
The function MyTextSanitizer::stripSlashesGPC() has been deprecated: as of XOOPS 2.5.11 and will be removed in next XOOPS version ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1117
        return /** @scrutinizer ignore-deprecated */ $this->stripSlashesGPC($text);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1118
    }
1119
1120
    /**
1121
     * MyTextSanitizer::oopsStripSlashesRT()
1122
     *
1123
     * @param  mixed $text
1124
     * @return mixed|string
1125
     * @deprecated will be removed in next XOOPS version
1126
     */
1127
    public function oopsStripSlashesRT($text)
1128
    {
1129
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1130
        if (get_magic_quotes_runtime()) {
1131
            $text = stripslashes($text);
1132
        }
1133
1134
        return $text;
1135
    }
1136
1137
    /**
1138
     * MyTextSanitizer::oopsAddSlashes()
1139
     *
1140
     * @param  mixed $text
1141
     * @return string
1142
     * @deprecated will be removed in next XOOPS version
1143
     */
1144
    public function oopsAddSlashes($text)
1145
    {
1146
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1147
1148
        return $this->addSlashes($text);
1149
    }
1150
1151
    /**
1152
     * MyTextSanitizer::oopsHtmlSpecialChars()
1153
     *
1154
     * @param  mixed $text
1155
     * @return string
1156
     * @deprecated will be removed in next XOOPS version
1157
     */
1158
    public function oopsHtmlSpecialChars($text)
1159
    {
1160
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1161
1162
        return $this->htmlSpecialChars($text);
1163
    }
1164
1165
    /**
1166
     * MyTextSanitizer::oopsNl2Br()
1167
     *
1168
     * @param  mixed $text
1169
     * @return string
1170
     * @deprecated will be removed in next XOOPS version
1171
     */
1172
    public function oopsNl2Br($text)
1173
    {
1174
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated');
1175
1176
        return $this->nl2Br($text);
1177
    }
1178
}
1179