Merge branch 'MDL-54034-master' of git://github.com/FMCorz/moodle
This commit is contained in:
@@ -2179,6 +2179,7 @@ class core_course_external extends external_api {
|
||||
'requiredcapabilities' => $requiredcapabilities
|
||||
);
|
||||
$params = self::validate_parameters(self::search_courses_parameters(), $parameters);
|
||||
self::validate_context(context_system::instance());
|
||||
|
||||
$allowedcriterianames = array('search', 'modulelist', 'blocklist', 'tagid');
|
||||
if (!in_array($params['criterianame'], $allowedcriterianames)) {
|
||||
|
||||
@@ -41,6 +41,13 @@ if ($requests === null) {
|
||||
}
|
||||
$responses = array();
|
||||
|
||||
// Defines the external settings required for Ajax processing.
|
||||
$settings = external_settings::get_instance();
|
||||
$settings->set_file('pluginfile.php');
|
||||
$settings->set_fileurl(true);
|
||||
$settings->set_filter(true);
|
||||
$settings->set_raw(false);
|
||||
|
||||
foreach ($requests as $request) {
|
||||
$response = array();
|
||||
$methodname = clean_param($request['methodname'], PARAM_ALPHANUMEXT);
|
||||
|
||||
+8
-4
@@ -853,6 +853,11 @@ function external_validate_format($format) {
|
||||
* The caller can change the format (raw) with the external_settings singleton
|
||||
* All web service servers must set this singleton when parsing the $_GET and $_POST.
|
||||
*
|
||||
* <pre>
|
||||
* Options are the same that in {@link format_string()} with some changes:
|
||||
* filter : Can be set to false to force filters off, else observes {@link external_settings}.
|
||||
* </pre>
|
||||
*
|
||||
* @param string $str The string to be filtered. Should be plain text, expect
|
||||
* possibly for multilang tags.
|
||||
* @param boolean $striplinks To strip any link in the result text. Moodle 1.8 default changed from false to true! MDL-8713
|
||||
@@ -872,7 +877,7 @@ function external_format_string($str, $contextid, $striplinks = true, $options =
|
||||
if (!$settings->get_raw()) {
|
||||
$context = context::instance_by_id($contextid);
|
||||
$options['context'] = $context;
|
||||
$options['filter'] = $settings->get_filter();
|
||||
$options['filter'] = isset($options['filter']) && !$options['filter'] ? false : $settings->get_filter();
|
||||
$str = format_string($str, $striplinks, $options);
|
||||
}
|
||||
|
||||
@@ -890,8 +895,7 @@ function external_format_string($str, $contextid, $striplinks = true, $options =
|
||||
* trusted : If true the string won't be cleaned. Default false.
|
||||
* noclean : If true the string won't be cleaned only if trusted is also true. Default false.
|
||||
* nocache : If true the string will not be cached and will be formatted every call. Default false.
|
||||
* filter : If true the string will be run through applicable filters as well. Default (different from format_text)
|
||||
* got form settings.
|
||||
* filter : Can be set to false to force filters off, else observes {@link external_settings}.
|
||||
* para : If true then the returned string will be wrapped in div tags. Default (different from format_text) false.
|
||||
* Default changed because div tags are not commonly needed.
|
||||
* newlines : If true then lines newline breaks will be converted to HTML newline breaks. Default true.
|
||||
@@ -935,7 +939,7 @@ function external_format_text($text, $textformat, $contextid, $component, $filea
|
||||
}
|
||||
}
|
||||
|
||||
$options['filter'] = isset($options['filter']) ? $options['filter'] : $settings->get_filter();
|
||||
$options['filter'] = isset($options['filter']) && !$options['filter'] ? false : $settings->get_filter();
|
||||
$options['para'] = isset($options['para']) ? $options['para'] : false;
|
||||
$options['context'] = context::instance_by_id($contextid);
|
||||
$options['allowid'] = isset($options['allowid']) ? $options['allowid'] : true;
|
||||
|
||||
@@ -96,6 +96,13 @@ class core_externallib_testcase extends advanced_testcase {
|
||||
</span></span>', FORMAT_HTML);
|
||||
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0), $correct);
|
||||
|
||||
// Filters can be opted out from by the developer.
|
||||
$test = '$$ \pi $$';
|
||||
$testformat = FORMAT_MARKDOWN;
|
||||
$correct = array('<p>$$ \pi $$</p>
|
||||
', FORMAT_HTML);
|
||||
$this->assertSame(external_format_text($test, $testformat, $context->id, 'core', '', 0, ['filter' => false]), $correct);
|
||||
|
||||
$test = '<p><a id="test"></a><a href="#test">Text</a></p>';
|
||||
$testformat = FORMAT_HTML;
|
||||
$correct = array($test, FORMAT_HTML);
|
||||
@@ -135,23 +142,47 @@ class core_externallib_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
public function test_external_format_string() {
|
||||
$this->resetAfterTest();
|
||||
$settings = external_settings::get_instance();
|
||||
|
||||
$currentraw = $settings->get_raw();
|
||||
$currentfilter = $settings->get_filter();
|
||||
|
||||
// Enable multilang filter to on content and heading.
|
||||
filter_set_global_state('multilang', TEXTFILTER_ON);
|
||||
filter_set_applies_to_strings('multilang', 1);
|
||||
$filtermanager = filter_manager::instance();
|
||||
$filtermanager->reset_caches();
|
||||
|
||||
$settings->set_raw(true);
|
||||
$settings->set_filter(true);
|
||||
$context = context_system::instance();
|
||||
|
||||
$test = '$$ \pi $$ <script>hi</script> <h3>there</h3>';
|
||||
$test = '<span lang="en" class="multilang">EN</span><span lang="fr" class="multilang">FR</span> ' .
|
||||
'<script>hi</script> <h3>there</h3>!';
|
||||
$correct = $test;
|
||||
$this->assertSame(external_format_string($test, $context->id), $correct);
|
||||
$this->assertSame($correct, external_format_string($test, $context->id));
|
||||
|
||||
$settings->set_raw(false);
|
||||
$settings->set_filter(false);
|
||||
|
||||
$test = '<span lang="en" class="multilang">EN</span><span lang="fr" class="multilang">FR</span> ' .
|
||||
'<script>hi</script> <h3>there</h3>?';
|
||||
$correct = 'ENFR hi there?';
|
||||
$this->assertSame($correct, external_format_string($test, $context->id));
|
||||
|
||||
$settings->set_filter(true);
|
||||
|
||||
$test = '<span lang="en" class="multilang">EN</span><span lang="fr" class="multilang">FR</span> ' .
|
||||
'<script>hi</script> <h3>there</h3>@';
|
||||
$correct = 'EN hi there@';
|
||||
$this->assertSame($correct, external_format_string($test, $context->id));
|
||||
|
||||
// Filters can be opted out.
|
||||
$test = '<span lang="en" class="multilang">EN</span><span lang="fr" class="multilang">FR</span> ' .
|
||||
'<script>hi</script> <h3>there</h3>%';
|
||||
$correct = 'ENFR hi there%';
|
||||
$this->assertSame($correct, external_format_string($test, $context->id, false, ['filter' => false]));
|
||||
|
||||
$test = '$$ \pi $$<script>hi</script> <h3>there</h3>';
|
||||
$correct = '$$ \pi $$hi there';
|
||||
$this->assertSame(external_format_string($test, $context->id), $correct);
|
||||
|
||||
$settings->set_raw($currentraw);
|
||||
$settings->set_filter($currentfilter);
|
||||
|
||||
Reference in New Issue
Block a user