Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 20... Línea 20...
20
 * @package   core
20
 * @package   core
21
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
21
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
Línea 24... Línea -...
24
 
-
 
25
defined('MOODLE_INTERNAL') || die();
-
 
26
 
24
 
27
/** The states a filter can be in, stored in the filter_active table. */
25
/** The states a filter can be in, stored in the filter_active table. */
28
define('TEXTFILTER_ON', 1);
26
define('TEXTFILTER_ON', 1);
29
/** The states a filter can be in, stored in the filter_active table. */
27
/** The states a filter can be in, stored in the filter_active table. */
30
define('TEXTFILTER_INHERIT', 0);
28
define('TEXTFILTER_INHERIT', 0);
Línea 40... Línea 38...
40
 */
38
 */
41
define('TEXTFILTER_EXCL_SEPARATOR', chr(0x1F) . '%' . chr(0x1F));
39
define('TEXTFILTER_EXCL_SEPARATOR', chr(0x1F) . '%' . chr(0x1F));
Línea 42... Línea 40...
42
 
40
 
43
 
-
 
44
/**
-
 
45
 * Class to manage the filtering of strings. It is intended that this class is
-
 
46
 * only used by weblib.php. Client code should probably be using the
-
 
47
 * format_text and format_string functions.
-
 
48
 *
-
 
49
 * This class is a singleton.
-
 
50
 *
-
 
51
 * @copyright  1999 onwards Martin Dougiamas  {@link http://moodle.com}
-
 
52
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
53
 */
-
 
54
class filter_manager {
-
 
55
    /**
-
 
56
     * @var moodle_text_filter[][] This list of active filters, by context, for filtering content.
-
 
57
     * An array contextid => ordered array of filter name => filter objects.
-
 
58
     */
-
 
59
    protected $textfilters = array();
-
 
60
 
-
 
61
    /**
-
 
62
     * @var moodle_text_filter[][] This list of active filters, by context, for filtering strings.
-
 
63
     * An array contextid => ordered array of filter name => filter objects.
-
 
64
     */
-
 
65
    protected $stringfilters = array();
-
 
66
 
-
 
67
    /** @var array Exploded version of $CFG->stringfilters. */
-
 
68
    protected $stringfilternames = array();
-
 
69
 
-
 
70
    /** @var filter_manager Holds the singleton instance. */
-
 
71
    protected static $singletoninstance;
-
 
72
 
-
 
73
    /**
-
 
74
     * Constructor. Protected. Use {@link instance()} instead.
-
 
75
     */
-
 
76
    protected function __construct() {
-
 
77
        $this->stringfilternames = filter_get_string_filters();
-
 
78
    }
-
 
79
 
-
 
80
    /**
-
 
81
     * Factory method. Use this to get the filter manager.
-
 
82
     *
-
 
83
     * @return filter_manager the singleton instance.
-
 
84
     */
-
 
85
    public static function instance() {
-
 
86
        global $CFG;
-
 
87
        if (is_null(self::$singletoninstance)) {
-
 
88
            if (!empty($CFG->perfdebug) and $CFG->perfdebug > 7) {
-
 
89
                self::$singletoninstance = new performance_measuring_filter_manager();
-
 
90
            } else {
-
 
91
                self::$singletoninstance = new self();
-
 
92
            }
-
 
93
        }
-
 
94
        return self::$singletoninstance;
-
 
95
    }
-
 
96
 
-
 
97
    /**
-
 
98
     * Resets the caches, usually to be called between unit tests
-
 
99
     */
-
 
100
    public static function reset_caches() {
-
 
101
        if (self::$singletoninstance) {
-
 
102
            self::$singletoninstance->unload_all_filters();
-
 
103
        }
-
 
104
        self::$singletoninstance = null;
-
 
105
    }
-
 
106
 
-
 
107
    /**
-
 
108
     * Unloads all filters and other cached information
-
 
109
     */
-
 
110
    protected function unload_all_filters() {
-
 
111
        $this->textfilters = array();
-
 
112
        $this->stringfilters = array();
-
 
113
        $this->stringfilternames = array();
-
 
114
    }
-
 
115
 
-
 
116
    /**
-
 
117
     * Load all the filters required by this context.
-
 
118
     *
-
 
119
     * @param context $context the context.
-
 
120
     */
-
 
121
    protected function load_filters($context) {
-
 
122
        $filters = filter_get_active_in_context($context);
-
 
123
        $this->textfilters[$context->id] = array();
-
 
124
        $this->stringfilters[$context->id] = array();
-
 
125
        foreach ($filters as $filtername => $localconfig) {
-
 
126
            $filter = $this->make_filter_object($filtername, $context, $localconfig);
-
 
127
            if (is_null($filter)) {
-
 
128
                continue;
-
 
129
            }
-
 
130
            $this->textfilters[$context->id][$filtername] = $filter;
-
 
131
            if (in_array($filtername, $this->stringfilternames)) {
-
 
132
                $this->stringfilters[$context->id][$filtername] = $filter;
-
 
133
            }
-
 
134
        }
-
 
135
    }
-
 
136
 
-
 
137
    /**
-
 
138
     * Factory method for creating a filter.
-
 
139
     *
-
 
140
     * @param string $filtername The filter name, for example 'tex'.
-
 
141
     * @param context $context context object.
-
 
142
     * @param array $localconfig array of local configuration variables for this filter.
-
 
143
     * @return ?moodle_text_filter The filter, or null, if this type of filter is
-
 
144
     *      not recognised or could not be created.
-
 
145
     */
-
 
146
    protected function make_filter_object($filtername, $context, $localconfig) {
-
 
147
        global $CFG;
-
 
148
        $path = $CFG->dirroot .'/filter/'. $filtername .'/filter.php';
-
 
149
        if (!is_readable($path)) {
-
 
150
            return null;
-
 
151
        }
-
 
152
        include_once($path);
-
 
153
 
-
 
154
        $filterclassname = 'filter_' . $filtername;
-
 
155
        if (class_exists($filterclassname)) {
-
 
156
            return new $filterclassname($context, $localconfig);
-
 
157
        }
-
 
158
 
-
 
159
        return null;
-
 
160
    }
-
 
161
 
-
 
162
    /**
-
 
163
     * Apply a list of filters to some content.
-
 
164
     * @param string $text
-
 
165
     * @param moodle_text_filter[] $filterchain array filter name => filter object.
-
 
166
     * @param array $options options passed to the filters.
-
 
167
     * @param array $skipfilters of filter names. Any filters that should not be applied to this text.
-
 
168
     * @return string $text
-
 
169
     */
-
 
170
    protected function apply_filter_chain($text, $filterchain, array $options = array(),
-
 
171
            array $skipfilters = null) {
-
 
172
        if (!isset($options['stage'])) {
-
 
173
            $filtermethod = 'filter';
-
 
174
        } else if (in_array($options['stage'], ['pre_format', 'pre_clean', 'post_clean', 'string'], true)) {
-
 
175
            $filtermethod = 'filter_stage_' . $options['stage'];
-
 
176
        } else {
-
 
177
            $filtermethod = 'filter';
-
 
178
            debugging('Invalid filter stage specified in options: ' . $options['stage'], DEBUG_DEVELOPER);
-
 
179
        }
-
 
180
        if ($text === null || $text === '') {
-
 
181
            // Nothing to filter.
-
 
182
            return '';
-
 
183
        }
-
 
184
        foreach ($filterchain as $filtername => $filter) {
-
 
185
            if ($skipfilters !== null && in_array($filtername, $skipfilters)) {
-
 
186
                continue;
-
 
187
            }
-
 
188
            $text = $filter->$filtermethod($text, $options);
-
 
189
        }
-
 
190
        return $text;
-
 
191
    }
-
 
192
 
-
 
193
    /**
-
 
194
     * Get all the filters that apply to a given context for calls to format_text.
-
 
195
     *
-
 
196
     * @param context $context
-
 
197
     * @return moodle_text_filter[] A text filter
-
 
198
     */
-
 
199
    protected function get_text_filters($context) {
-
 
200
        if (!isset($this->textfilters[$context->id])) {
-
 
201
            $this->load_filters($context);
-
 
202
        }
-
 
203
        return $this->textfilters[$context->id];
-
 
204
    }
-
 
205
 
-
 
206
    /**
-
 
207
     * Get all the filters that apply to a given context for calls to format_string.
-
 
208
     *
-
 
209
     * @param context $context the context.
-
 
210
     * @return moodle_text_filter[] A text filter
-
 
211
     */
-
 
212
    protected function get_string_filters($context) {
-
 
213
        if (!isset($this->stringfilters[$context->id])) {
-
 
214
            $this->load_filters($context);
-
 
215
        }
-
 
216
        return $this->stringfilters[$context->id];
-
 
217
    }
-
 
218
 
-
 
219
    /**
-
 
220
     * Filter some text
-
 
221
     *
-
 
222
     * @param string $text The text to filter
-
 
223
     * @param context $context the context.
-
 
224
     * @param array $options options passed to the filters
-
 
225
     * @param array $skipfilters of filter names. Any filters that should not be applied to this text.
-
 
226
     * @return string resulting text
-
 
227
     */
-
 
228
    public function filter_text($text, $context, array $options = array(),
-
 
229
            array $skipfilters = null) {
-
 
230
        $text = $this->apply_filter_chain($text, $this->get_text_filters($context), $options, $skipfilters);
-
 
231
        if (!isset($options['stage']) || $options['stage'] === 'post_clean') {
-
 
232
            // Remove <nolink> tags for XHTML compatibility after the last filtering stage.
-
 
233
            $text = str_replace(array('<nolink>', '</nolink>'), '', $text);
-
 
234
        }
-
 
235
        return $text;
-
 
236
    }
-
 
237
 
-
 
238
    /**
-
 
239
     * Filter a piece of string
-
 
240
     *
-
 
241
     * @param string $string The text to filter
-
 
242
     * @param context $context the context.
-
 
243
     * @return string resulting string
-
 
244
     */
-
 
245
    public function filter_string($string, $context) {
-
 
246
        return $this->apply_filter_chain($string, $this->get_string_filters($context), ['stage' => 'string']);
-
 
247
    }
-
 
248
 
-
 
249
    /**
-
 
250
     * @deprecated Since Moodle 3.0 MDL-50491. This was used by the old text filtering system, but no more.
-
 
251
     */
-
 
252
    public function text_filtering_hash() {
-
 
253
        throw new coding_exception('filter_manager::text_filtering_hash() can not be used any more');
-
 
254
    }
-
 
255
 
-
 
256
    /**
-
 
257
     * Setup page with filters requirements and other prepare stuff.
-
 
258
     *
-
 
259
     * This method is used by {@see format_text()} and {@see format_string()}
-
 
260
     * in order to allow filters to setup any page requirement (js, css...)
-
 
261
     * or perform any action needed to get them prepared before filtering itself
-
 
262
     * happens by calling to each every active setup() method.
-
 
263
     *
-
 
264
     * Note it's executed for each piece of text filtered, so filter implementations
-
 
265
     * are responsible of controlling the cardinality of the executions that may
-
 
266
     * be different depending of the stuff to prepare.
-
 
267
     *
-
 
268
     * @param moodle_page $page the page we are going to add requirements to.
-
 
269
     * @param context $context the context which contents are going to be filtered.
-
 
270
     * @since Moodle 2.3
-
 
271
     */
-
 
272
    public function setup_page_for_filters($page, $context) {
-
 
273
        $filters = $this->get_text_filters($context);
-
 
274
        foreach ($filters as $filter) {
-
 
275
            $filter->setup($page, $context);
-
 
276
        }
-
 
277
    }
-
 
278
 
-
 
279
    /**
-
 
280
     * Setup the page for globally available filters.
-
 
281
     *
-
 
282
     * This helps setting up the page for filters which may be applied to
-
 
283
     * the page, even if they do not belong to the current context, or are
-
 
284
     * not yet visible because the content is lazily added (ajax). This method
-
 
285
     * always uses to the system context which determines the globally
-
 
286
     * available filters.
-
 
287
     *
-
 
288
     * This should only ever be called once per request.
-
 
289
     *
-
 
290
     * @param moodle_page $page The page.
-
 
291
     * @since Moodle 3.2
-
 
292
     */
-
 
293
    public function setup_page_for_globally_available_filters($page) {
-
 
294
        $context = context_system::instance();
-
 
295
        $filterdata = filter_get_globally_enabled_filters_with_config();
-
 
296
        foreach ($filterdata as $name => $config) {
-
 
297
            if (isset($this->textfilters[$context->id][$name])) {
-
 
298
                $filter = $this->textfilters[$context->id][$name];
-
 
299
            } else {
-
 
300
                $filter = $this->make_filter_object($name, $context, $config);
-
 
301
                if (is_null($filter)) {
-
 
302
                    continue;
-
 
303
                }
-
 
304
            }
-
 
305
            $filter->setup($page, $context);
-
 
306
        }
-
 
307
    }
-
 
308
}
-
 
309
 
-
 
310
 
-
 
311
/**
-
 
312
 * Filter manager subclass that does nothing. Having this simplifies the logic
-
 
313
 * of format_text, etc.
-
 
314
 *
-
 
315
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
-
 
316
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
317
 */
-
 
318
class null_filter_manager {
-
 
319
    /**
-
 
320
     * As for the equivalent {@link filter_manager} method.
-
 
321
     *
-
 
322
     * @param string $text The text to filter
-
 
323
     * @param context $context not used.
-
 
324
     * @param array $options not used
-
 
325
     * @param array $skipfilters not used
-
 
326
     * @return string resulting text.
-
 
327
     */
-
 
328
    public function filter_text($text, $context, array $options = array(),
-
 
329
            array $skipfilters = null) {
-
 
330
        return $text;
-
 
331
    }
-
 
332
 
-
 
333
    /**
-
 
334
     * As for the equivalent {@link filter_manager} method.
-
 
335
     *
-
 
336
     * @param string $string The text to filter
-
 
337
     * @param context $context not used.
-
 
338
     * @return string resulting string
-
 
339
     */
-
 
340
    public function filter_string($string, $context) {
-
 
341
        return $string;
-
 
342
    }
-
 
343
 
-
 
344
    /**
-
 
345
     * As for the equivalent {@link filter_manager} method.
-
 
346
     *
-
 
347
     * @deprecated Since Moodle 3.0 MDL-50491.
-
 
348
     */
-
 
349
    public function text_filtering_hash() {
-
 
350
        throw new coding_exception('filter_manager::text_filtering_hash() can not be used any more');
-
 
351
    }
-
 
352
}
-
 
353
 
-
 
354
 
-
 
355
/**
-
 
356
 * Filter manager subclass that tracks how much work it does.
-
 
357
 *
-
 
358
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
-
 
359
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
360
 */
-
 
361
class performance_measuring_filter_manager extends filter_manager {
-
 
362
    /** @var int number of filter objects created. */
-
 
363
    protected $filterscreated = 0;
-
 
364
 
-
 
365
    /** @var int number of calls to filter_text. */
-
 
366
    protected $textsfiltered = 0;
-
 
367
 
-
 
368
    /** @var int number of calls to filter_string. */
-
 
369
    protected $stringsfiltered = 0;
-
 
370
 
-
 
371
    protected function unload_all_filters() {
-
 
372
        parent::unload_all_filters();
-
 
373
        $this->filterscreated = 0;
-
 
374
        $this->textsfiltered = 0;
-
 
375
        $this->stringsfiltered = 0;
-
 
376
    }
-
 
377
 
-
 
378
    protected function make_filter_object($filtername, $context, $localconfig) {
-
 
379
        $this->filterscreated++;
-
 
380
        return parent::make_filter_object($filtername, $context, $localconfig);
-
 
381
    }
-
 
382
 
-
 
383
    public function filter_text($text, $context, array $options = array(),
-
 
384
            array $skipfilters = null) {
-
 
385
        if (!isset($options['stage']) || $options['stage'] === 'post_clean') {
-
 
386
            $this->textsfiltered++;
-
 
387
        }
-
 
388
        return parent::filter_text($text, $context, $options, $skipfilters);
-
 
389
    }
-
 
390
 
-
 
391
    public function filter_string($string, $context) {
-
 
392
        $this->stringsfiltered++;
-
 
393
        return parent::filter_string($string, $context);
-
 
394
    }
-
 
395
 
-
 
396
    /**
-
 
397
     * Return performance information, in the form required by {@link get_performance_info()}.
-
 
398
     * @return array the performance info.
-
 
399
     */
-
 
400
    public function get_performance_summary() {
-
 
401
        return array(array(
-
 
402
            'contextswithfilters' => count($this->textfilters),
-
 
403
            'filterscreated' => $this->filterscreated,
-
 
404
            'textsfiltered' => $this->textsfiltered,
-
 
405
            'stringsfiltered' => $this->stringsfiltered,
-
 
406
        ), array(
-
 
407
            'contextswithfilters' => 'Contexts for which filters were loaded',
-
 
408
            'filterscreated' => 'Filters created',
-
 
409
            'textsfiltered' => 'Pieces of content filtered',
-
 
410
            'stringsfiltered' => 'Strings filtered',
-
 
411
        ));
-
 
412
    }
-
 
413
}
-
 
414
 
-
 
415
 
-
 
416
/**
-
 
417
 * Base class for text filters. You just need to override this class and
-
 
418
 * implement the filter method.
-
 
419
 *
-
 
420
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
-
 
421
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
422
 */
-
 
423
abstract class moodle_text_filter {
-
 
424
    /** @var context The context we are in. */
-
 
425
    protected $context;
-
 
426
 
-
 
427
    /** @var array Any local configuration for this filter in this context. */
-
 
428
    protected $localconfig;
-
 
429
 
-
 
430
    /**
-
 
431
     * Set any context-specific configuration for this filter.
-
 
432
     *
-
 
433
     * @param context $context The current context.
-
 
434
     * @param array $localconfig Any context-specific configuration for this filter.
-
 
435
     */
-
 
436
    public function __construct($context, array $localconfig) {
-
 
437
        $this->context = $context;
-
 
438
        $this->localconfig = $localconfig;
-
 
439
    }
-
 
440
 
-
 
441
    /**
-
 
442
     * @deprecated Since Moodle 3.0 MDL-50491. This was used by the old text filtering system, but no more.
-
 
443
     */
-
 
444
    public function hash() {
-
 
445
        throw new coding_exception('moodle_text_filter::hash() can not be used any more');
-
 
446
    }
-
 
447
 
-
 
448
    /**
-
 
449
     * Setup page with filter requirements and other prepare stuff.
-
 
450
     *
-
 
451
     * Override this method if the filter needs to setup page
-
 
452
     * requirements or needs other stuff to be executed.
-
 
453
     *
-
 
454
     * Note this method is invoked from {@see setup_page_for_filters()}
-
 
455
     * for each piece of text being filtered, so it is responsible
-
 
456
     * for controlling its own execution cardinality.
-
 
457
     *
-
 
458
     * @param moodle_page $page the page we are going to add requirements to.
-
 
459
     * @param context $context the context which contents are going to be filtered.
-
 
460
     * @since Moodle 2.3
-
 
461
     */
-
 
462
    public function setup($page, $context) {
-
 
463
        // Override me, if needed.
-
 
464
    }
-
 
465
 
-
 
466
    /**
-
 
467
     * Override this function to actually implement the filtering.
-
 
468
     *
-
 
469
     * Filter developers must make sure that filtering done after text cleaning
-
 
470
     * does not introduce security vulnerabilities.
-
 
471
     *
-
 
472
     * @param string $text some HTML content to process.
-
 
473
     * @param array $options options passed to the filters
-
 
474
     * @return string the HTML content after the filtering has been applied.
-
 
475
     */
-
 
476
    abstract public function filter($text, array $options = array());
-
 
477
 
-
 
478
    /**
-
 
479
     * Filter text before changing format to HTML.
-
 
480
     *
-
 
481
     * @param string $text
-
 
482
     * @param array $options
-
 
483
     * @return string
-
 
484
     */
-
 
485
    public function filter_stage_pre_format(string $text, array $options): string {
-
 
486
        // NOTE: override if necessary.
-
 
487
        return $text;
-
 
488
    }
-
 
489
 
-
 
490
    /**
-
 
491
     * Filter HTML text before sanitising text.
-
 
492
     *
-
 
493
     * NOTE: this is called even if $options['noclean'] is true and text is not cleaned.
-
 
494
     *
-
 
495
     * @param string $text
-
 
496
     * @param array $options
-
 
497
     * @return string
-
 
498
     */
-
 
499
    public function filter_stage_pre_clean(string $text, array $options): string {
-
 
500
        // NOTE: override if necessary.
-
 
501
        return $text;
-
 
502
    }
-
 
503
 
-
 
504
    /**
-
 
505
     * Filter HTML text at the very end after text is sanitised.
-
 
506
     *
-
 
507
     * NOTE: this is called even if $options['noclean'] is true and text is not cleaned.
-
 
508
     *
-
 
509
     * @param string $text
-
 
510
     * @param array $options
-
 
511
     * @return string
-
 
512
     */
-
 
513
    public function filter_stage_post_clean(string $text, array $options): string {
-
 
514
        // NOTE: override if necessary.
-
 
515
        return $this->filter($text, $options);
-
 
516
    }
-
 
517
 
-
 
518
    /**
-
 
519
     * Filter simple text coming from format_string().
-
 
520
     *
-
 
521
     * Note that unless $CFG->formatstringstriptags is disabled
-
 
522
     * HTML tags are not expected in returned value.
-
 
523
     *
-
 
524
     * @param string $text
-
 
525
     * @param array $options
-
 
526
     * @return string
-
 
527
     */
-
 
528
    public function filter_stage_string(string $text, array $options): string {
-
 
529
        // NOTE: override if necessary.
-
 
530
        return $this->filter($text, $options);
-
 
531
    }
-
 
532
}
-
 
533
 
-
 
534
 
-
 
535
/**
-
 
536
 * This is just a little object to define a phrase and some instructions
-
 
537
 * for how to process it.  Filters can create an array of these to pass
-
 
538
 * to the @{link filter_phrases()} function below.
-
 
539
 *
-
 
540
 * Note that although the fields here are public, you almost certainly should
-
 
541
 * never use that. All that is supported is contructing new instances of this
-
 
542
 * class, and then passing an array of them to filter_phrases.
-
 
543
 *
-
 
544
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
-
 
545
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
546
 */
-
 
547
class filterobject {
-
 
548
    /** @var string this is the phrase that should be matched. */
-
 
549
    public $phrase;
-
 
550
 
-
 
551
    /** @var bool whether to match complete words. If true, 'T' won't be matched in 'Tim'. */
-
 
552
    public $fullmatch;
-
 
553
 
-
 
554
    /** @var bool whether the match needs to be case sensitive. */
-
 
555
    public $casesensitive;
-
 
556
 
-
 
557
    /** @var string HTML to insert before any match. */
-
 
558
    public $hreftagbegin;
-
 
559
    /** @var string HTML to insert after any match. */
-
 
560
    public $hreftagend;
-
 
561
 
-
 
562
    /** @var null|string replacement text to go inside begin and end. If not set,
-
 
563
     * the body of the replacement will be the original phrase.
-
 
564
     */
-
 
565
    public $replacementphrase;
-
 
566
 
-
 
567
    /** @var null|string once initialised, holds the regexp for matching this phrase. */
-
 
568
    public $workregexp = null;
-
 
569
 
-
 
570
    /** @var null|string once initialised, holds the mangled HTML to replace the regexp with. */
-
 
571
    public $workreplacementphrase = null;
-
 
572
 
-
 
573
    /** @var null|callable hold a replacement function to be called. */
-
 
574
    public $replacementcallback;
-
 
575
 
-
 
576
    /** @var null|array data to be passed to $replacementcallback. */
-
 
577
    public $replacementcallbackdata;
-
 
578
 
-
 
579
    /**
-
 
580
     * Constructor.
-
 
581
     *
-
 
582
     * @param string $phrase this is the phrase that should be matched.
-
 
583
     * @param string $hreftagbegin HTML to insert before any match. Default '<span class="highlight">'.
-
 
584
     * @param string $hreftagend HTML to insert after any match. Default '</span>'.
-
 
585
     * @param bool $casesensitive whether the match needs to be case sensitive
-
 
586
     * @param bool $fullmatch whether to match complete words. If true, 'T' won't be matched in 'Tim'.
-
 
587
     * @param mixed $replacementphrase replacement text to go inside begin and end. If not set,
-
 
588
     * the body of the replacement will be the original phrase.
-
 
589
     * @param callback $replacementcallback if set, then this will be called just before
-
 
590
     * $hreftagbegin, $hreftagend and $replacementphrase are needed, so they can be computed only if required.
-
 
591
     * The call made is
-
 
592
     * list($linkobject->hreftagbegin, $linkobject->hreftagend, $linkobject->replacementphrase) =
-
 
593
     *         call_user_func_array($linkobject->replacementcallback, $linkobject->replacementcallbackdata);
-
 
594
     * so the return should be an array [$hreftagbegin, $hreftagend, $replacementphrase], the last of which may be null.
-
 
595
     * @param array $replacementcallbackdata data to be passed to $replacementcallback (optional).
-
 
596
     */
-
 
597
    public function __construct($phrase, $hreftagbegin = '<span class="highlight">',
-
 
598
            $hreftagend = '</span>',
-
 
599
            $casesensitive = false,
-
 
600
            $fullmatch = false,
-
 
601
            $replacementphrase = null,
-
 
602
            $replacementcallback = null,
-
 
603
            array $replacementcallbackdata = null) {
-
 
604
 
-
 
605
        $this->phrase                  = $phrase;
-
 
606
        $this->hreftagbegin            = $hreftagbegin;
-
 
607
        $this->hreftagend              = $hreftagend;
-
 
608
        $this->casesensitive           = !empty($casesensitive);
-
 
609
        $this->fullmatch               = !empty($fullmatch);
-
 
610
        $this->replacementphrase       = $replacementphrase;
-
 
611
        $this->replacementcallback     = $replacementcallback;
-
 
612
        $this->replacementcallbackdata = $replacementcallbackdata;
-
 
613
    }
-
 
614
}
-
 
615
 
41
 
616
/**
42
/**
617
 * Look up the name of this filter
43
 * Look up the name of this filter
618
 *
44
 *
619
 * @param string $filter the filter name
45
 * @param string $filter the filter name
Línea 642... Línea 68...
642
 * sorted in alphabetical order of name.
68
 * sorted in alphabetical order of name.
643
 */
69
 */
644
function filter_get_all_installed() {
70
function filter_get_all_installed() {
645
    $filternames = array();
71
    $filternames = array();
646
    foreach (core_component::get_plugin_list('filter') as $filter => $fulldir) {
72
    foreach (core_component::get_plugin_list('filter') as $filter => $fulldir) {
647
        if (is_readable("$fulldir/filter.php")) {
73
        if (class_exists("\\filter_{$filter}\\text_filter") || is_readable("$fulldir/filter.php")) {
648
            $filternames[$filter] = filter_get_name($filter);
74
            $filternames[$filter] = filter_get_name($filter);
649
        }
75
        }
650
    }
76
    }
651
    core_collator::asort($filternames);
77
    core_collator::asort($filternames);
652
    return $filternames;
78
    return $filternames;