mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-82445 filter_tidy: Coding style fixes
This commit is contained in:
parent
7bb9d60dee
commit
6570855cf6
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -16,50 +15,47 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* HTML tidy text filter.
|
||||
* HTML tidy text filter.
|
||||
*
|
||||
* @package filter
|
||||
* This class looks for text including markup and
|
||||
* applies tidy's repair function to it.
|
||||
* Tidy is a HTML clean and
|
||||
* repair utility, which is currently available for PHP 4.3.x and PHP 5 as a
|
||||
* PECL extension from http://pecl.php.net/package/tidy, in PHP 5 you need only
|
||||
* to compile using the --with-tidy option.
|
||||
* If you don't have the tidy extension installed or don't know, you can enable
|
||||
* or disable this filter, it just won't have any effect.
|
||||
* If you want to know what you can set in $tidyoptions and what their default
|
||||
* values are, see http://php.net/manual/en/function.tidy-get-config.php.
|
||||
*
|
||||
* @package filter_tidy
|
||||
* @subpackage tiny
|
||||
* @copyright 2004 Hannes Gassert <hannes at mediagonal dot ch>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// This class looks for text including markup and
|
||||
// applies tidy's repair function to it.
|
||||
// Tidy is a HTML clean and
|
||||
// repair utility, which is currently available for PHP 4.3.x and PHP 5 as a
|
||||
// PECL extension from http://pecl.php.net/package/tidy, in PHP 5 you need only
|
||||
// to compile using the --with-tidy option.
|
||||
// If you don't have the tidy extension installed or don't know, you can enable
|
||||
// or disable this filter, it just won't have any effect.
|
||||
// If you want to know what you can set in $tidyoptions and what their default
|
||||
// values are, see http://php.net/manual/en/function.tidy-get-config.php.
|
||||
|
||||
class filter_tidy extends moodle_text_filter {
|
||||
function filter($text, array $options = array()) {
|
||||
#[\Override]
|
||||
public function filter($text, array $options = []) {
|
||||
// Configuration for tidy. Feel free to tune for your needs, e.g. to allow
|
||||
// proprietary markup.
|
||||
$tidyoptions = [
|
||||
'output-xhtml' => true,
|
||||
'show-body-only' => true,
|
||||
'tidy-mark' => false,
|
||||
'drop-proprietary-attributes' => true,
|
||||
'drop-empty-paras' => true,
|
||||
'indent' => true,
|
||||
'quiet' => true,
|
||||
];
|
||||
|
||||
/// Configuration for tidy. Feel free to tune for your needs, e.g. to allow
|
||||
/// proprietary markup.
|
||||
$tidyoptions = array(
|
||||
'output-xhtml' => true,
|
||||
'show-body-only' => true,
|
||||
'tidy-mark' => false,
|
||||
'drop-proprietary-attributes' => true,
|
||||
'drop-empty-paras' => true,
|
||||
'indent' => true,
|
||||
'quiet' => true,
|
||||
);
|
||||
|
||||
/// Do a quick check using strpos to avoid unnecessary work
|
||||
// Do a quick check using strpos to avoid unnecessary work.
|
||||
if (strpos($text, '<') === false) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
/// If enabled: run tidy over the entire string
|
||||
if (function_exists('tidy_repair_string')){
|
||||
// If enabled: run tidy over the entire string.
|
||||
if (function_exists('tidy_repair_string')) {
|
||||
$currentlocale = \core\locale::get_locale();
|
||||
try {
|
||||
$text = tidy_repair_string($text, $tidyoptions, 'utf8');
|
||||
|
@ -108,5 +108,4 @@ final class filter_tidy_test extends \advanced_testcase {
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user