mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
Merge branch 'MDL-82790-404' of https://github.com/andrewnicols/moodle into MOODLE_404_STABLE
This commit is contained in:
commit
8864cfdcb8
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<COMPATIBILITY_MATRIX>
|
||||
<PLUGIN name="filter_tidy">
|
||||
<PHP_EXTENSIONS>
|
||||
<PHP_EXTENSION name="tidy" level="optional">
|
||||
<FEEDBACK>
|
||||
<ON_CHECK message="tidyextensionrequired" plugin="filter_tidy" />
|
||||
</FEEDBACK>
|
||||
</PHP_EXTENSION>
|
||||
</PHP_EXTENSIONS>
|
||||
</PLUGIN>
|
||||
</COMPATIBILITY_MATRIX>
|
@ -16,58 +16,20 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* HTML tidy text filter.
|
||||
* HTML tidy text filter.
|
||||
*
|
||||
* Note: This plugin has been disabled as the underlying library is known to break content in a many cases.
|
||||
*
|
||||
* See MDL-82790 for more information.
|
||||
*
|
||||
* @package filter
|
||||
* @subpackage tiny
|
||||
* @subpackage tidy
|
||||
* @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()) {
|
||||
|
||||
/// 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
|
||||
if (strpos($text, '<') === false) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
/// 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');
|
||||
} finally {
|
||||
\core\locale::set_locale(LC_ALL, $currentlocale);
|
||||
}
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function filter($text, array $options = []]) {
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
@ -1,112 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace filter_tidy;
|
||||
|
||||
/**
|
||||
* Tests for HTML tidy.
|
||||
*
|
||||
* @package filter_tidy
|
||||
* @category test
|
||||
* @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \filter_tidy
|
||||
*/
|
||||
final class filter_tidy_test extends \advanced_testcase {
|
||||
/** @var string Locale */
|
||||
protected string $locale;
|
||||
|
||||
#[\Override]
|
||||
public static function setUpBeforeClass(): void {
|
||||
parent::setUpBeforeClass();
|
||||
require_once(__DIR__ . '/../filter.php');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->locale = \core\locale::get_locale();
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
\core\locale::set_locale(LC_ALL, $this->locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the filter method.
|
||||
*
|
||||
* @requires extension tidy
|
||||
* @dataProvider filter_provider
|
||||
* @param string $text The text to filter.
|
||||
* @param string $expected The expected value
|
||||
*/
|
||||
public function test_filter(
|
||||
string $text,
|
||||
string $expected,
|
||||
): void {
|
||||
$filter = new \filter_tidy(\core\context\system::instance(), []);
|
||||
$this->assertEquals($expected, $filter->filter($text));
|
||||
$this->assertEquals(
|
||||
\core\locale::standardise_locale($this->locale),
|
||||
\core\locale::standardise_locale(\core\locale::get_locale()),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for the filter test.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function filter_provider(): array {
|
||||
return [
|
||||
// No HTML tags.
|
||||
[
|
||||
'The cat is in the hat',
|
||||
'The cat is in the hat',
|
||||
],
|
||||
// Partial HTML.
|
||||
[
|
||||
'<p>The cat is in the hat',
|
||||
<<<EOF
|
||||
<p>
|
||||
The cat is in the hat
|
||||
</p>
|
||||
EOF,
|
||||
],
|
||||
// Return only the body, repairing the closing tag.
|
||||
[
|
||||
<<<EOF
|
||||
<html>
|
||||
<head>
|
||||
<title>test</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>error</i>
|
||||
</body>
|
||||
</html>
|
||||
EOF,
|
||||
<<<EOF
|
||||
<p>
|
||||
error
|
||||
</p>
|
||||
EOF,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user