.../ckeditor/Plugin/ckeditor/plugin/Internal.php | 8 +-- core/modules/filter/filter.api.php | 25 +++++----- core/modules/filter/filter.module | 52 ++++++++++---------- .../lib/Drupal/filter/Tests/FilterAPITest.php | 18 +++---- .../filter/tests/filter_test/filter_test.module | 6 +-- 5 files changed, 55 insertions(+), 54 deletions(-) diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/Internal.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/Internal.php index 1973790..da24179 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/Internal.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/Internal.php @@ -295,13 +295,13 @@ protected function generateAllowedContentSetting(Editor $editor) { } // Generate setting that accurately reflects allowed tags and attributes. else { - $allowed_tags = filter_get_allowed_tags_by_format($editor->format); - // When all tags are allowed, also set allowedContent to true. - if ($allowed_tags === TRUE) { + $allowed_html = filter_get_allowed_html_by_format($editor->format); + // When all HTML is allowed, also set allowedContent to true. + if ($allowed_html === TRUE) { return TRUE; } $setting = array(); - foreach($allowed_tags as $tag => $attributes) { + foreach($allowed_html as $tag => $attributes) { if ($attributes === TRUE) { $setting[] = $tag . '[*]'; } diff --git a/core/modules/filter/filter.api.php b/core/modules/filter/filter.api.php index eaba0e3..cb929fa 100644 --- a/core/modules/filter/filter.api.php +++ b/core/modules/filter/filter.api.php @@ -82,11 +82,10 @@ * - tips callback: The name of a function that returns end-user-facing * filter usage guidelines for the filter. See hook_filter_FILTER_tips() * for details. - * - allowed tags callback: The name of a function that returns a nested array - * with the allowed tags as keys, and for each of those tags (keys) the - * corresponding allowed attributes. An empty array for allowed attributes - * means no attributes are allowed, TRUE means all attributes are allowed. - * This is only needed for filters of the type FILTER_TYPE_HTML_RESTRICTOR. + * - allowed html callback: The name of a function that returns allowed HTML + * tags and attributes for the filter. May be implemented by filters of the + * type FILTER_TYPE_HTML_RESTRICTOR. See hook_filter_FILTER_allowed_html() + * for details. * - weight: A default weight for the filter in new text formats. * * @see filter_example.module @@ -189,11 +188,11 @@ function hook_filter_FILTER_settings($form, &$form_state, $filter, $format, $def } /** - * Filter allowed tags callback for hook_filter_info(). + * Filter allowed HTML callback for hook_filter_info(). * * Note: This is not really a hook. The function name is manually specified via - * 'allowed tags callback' in hook_filter_info(), with this recommended callback - * name pattern. It is called from filter_get_allowed_tags_by_format(). + * 'allowed html callback' in hook_filter_info(), with this recommended callback + * name pattern. It is called from filter_get_allowed_html_by_format(). * * This callback function is only necessary for filters that strip away HTML * tags (and possibly attributes) and allows other modules to gain insight in a @@ -203,12 +202,14 @@ function hook_filter_FILTER_settings($form, &$form_state, $filter, $format, $def * The filter object containing settings for the given format. * * @return array - * An array of allowed tags, or the empty array in case no tags are allowed. - * A valid return value is e.g. array('p' => TRUE, 'a' => array('href')). + * A nested array with the allowed tags as keys, and for each of those tags + * (keys) the corresponding allowed attributes. An empty array for allowed + * attributes means no attributes are allowed, TRUE means all attributes are + * allowed. * - * @see filter_get_allowed_tags_by_format() + * @see filter_get_allowed_html_by_format() */ -function hook_filter_FILTER_allowed_tags($filter) { +function hook_filter_FILTER_allowed_html($filter) { return array( // Allows no attributes on the

tag. 'p' => array(), diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 94527b0..16ea536 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -495,7 +495,7 @@ function filter_get_filter_types_by_format($format_id) { } /** - * Retrieve all tags and attributes that are allowed by a given text format. + * Retrieve all HTML tags and attributes allowed by a given text format. * * @param string $format_id * A text format ID. @@ -505,16 +505,16 @@ function filter_get_filter_types_by_format($format_id) { * text format. The empty array implies no tags are allowed. TRUE implies all * tags are allowed. */ -function filter_get_allowed_tags_by_format($format_id) { +function filter_get_allowed_html_by_format($format_id) { $filters = filter_list_format($format_id); - // Ignore filters that are disabled or don't have an "allowed tags" setting. + // Ignore filters that are disabled or don't have an "allowed html" setting. $filters_info = filter_get_filters(); $filters = array_filter($filters, function($filter) use ($filters_info) { if (!$filter->status) { return FALSE; } - if (!empty($filters_info[$filter->name]['allowed tags callback'])) { + if (!empty($filters_info[$filter->name]['allowed html callback'])) { return TRUE; } return FALSE; @@ -527,31 +527,31 @@ function filter_get_allowed_tags_by_format($format_id) { // From the set of remaining filters (they were filtered by array_filter() // above), collect the list of tags and attributes that are allowed by all // filters, i.e. the intersection of all allowed tags and attributes. - $allowed_tags = array_reduce($filters, function($intersection, $filter) { + $allowed_html = array_reduce($filters, function($intersection, $filter) { $filters_info = filter_get_filters(); - $function = $filters_info[$filter->name]['allowed tags callback']; - $new_allowed_tags = $function($filter); + $function = $filters_info[$filter->name]['allowed html callback']; + $new_allowed_html = $function($filter); - // The first filter with an "allowed tags" setting provides the initial + // The first filter with an "allowed html" setting provides the initial // set. if (!isset($intersection)) { - return $new_allowed_tags; + return $new_allowed_html; } - // Subsequent filters with an "allowed tags" setting must be intersected + // Subsequent filters with an "allowed html" setting must be intersected // with the existing set, to ensure we only end up with the tags that are - // allowed by *all* filters with an "allowed tags" setting. + // allowed by *all* filters with an "allowed html" setting. else { foreach ($intersection as $tag => $attributes) { // If the current tag is disallowed by the new filter, then it's // outside of the intersection. - if (!array_key_exists($tag, $new_allowed_tags)) { + if (!array_key_exists($tag, $new_allowed_html)) { unset($intersection[$tag]); } // The tag is in the intersection, but now we most calculate the // intersection of the allowed attributes. else { $current_attributes = $intersection[$tag]; - $new_attributes = $new_allowed_tags[$tag]; + $new_attributes = $new_allowed_html[$tag]; // The new filter allows less attributes; assign new. if ($current_attributes == TRUE && is_array($new_attributes)) { $intersection[$tag] = $new_attributes; @@ -574,7 +574,7 @@ function filter_get_allowed_tags_by_format($format_id) { } }, NULL); - return $allowed_tags; + return $allowed_html; } } @@ -1313,7 +1313,7 @@ function filter_filter_info() { 'filter_html_nofollow' => 0, ), 'tips callback' => '_filter_html_tips', - 'allowed tags callback' => '_filter_html_allowed_tags', + 'allowed html callback' => '_filter_html_allowed_html', 'weight' => -10, ); $filters['filter_autop'] = array( @@ -1352,7 +1352,7 @@ function filter_filter_info() { 'type' => FILTER_TYPE_HTML_RESTRICTOR, 'process callback' => '_filter_html_escape', 'tips callback' => '_filter_html_escape_tips', - 'allowed tags callback' => '_filter_html_escape_allowed_tags', + 'allowed html callback' => '_filter_html_escape_allowed_html', 'weight' => -10, ); return $filters; @@ -1388,25 +1388,25 @@ function _filter_html_settings($form, &$form_state, $filter, $format, $defaults) } /** - * Filter allowed tags callback for the HTML content filter. + * Filter allowed HTML callback for the HTML content filter. * - * See hook_filter_FILTER_allowed_tags() for documentation of parameters and + * See hook_filter_FILTER_allowed_html() for documentation of parameters and * return value. */ -function _filter_html_allowed_tags($filter) { - $allowed_tags = array(); +function _filter_html_allowed_html($filter) { + $allowed_html = array(); $tags = preg_split('/\s+|<|>/', $filter->settings['allowed_html'], -1, PREG_SPLIT_NO_EMPTY); foreach ($tags as $tag) { - $allowed_tags[$tag] = TRUE; + $allowed_html[$tag] = TRUE; } - return $allowed_tags; + return $allowed_html; } /** * Provides filtering of input into accepted HTML. */ function _filter_html($text, $filter) { - $allowed_tags = array_keys(_filter_html_allowed_tags($filter)); + $allowed_tags = array_keys(_filter_html_allowed_html($filter)); $text = filter_xss($text, $allowed_tags); if ($filter->settings['filter_html_nofollow']) { @@ -1864,12 +1864,12 @@ function _filter_autop_tips($filter, $format, $long = FALSE) { } /** - * Filter allowed tags callback for the HTML content filter. + * Filter allowed HTML callback for the HTML content filter. * - * See hook_filter_FILTER_allowed_tags() for documentation of parameters and + * See hook_filter_FILTER_allowed_html() for documentation of parameters and * return value. */ -function _filter_html_escape_allowed_tags($filter) { +function _filter_html_escape_allowed_html($filter) { return array(); } diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php index 674af92..c57280f 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php @@ -91,15 +91,15 @@ function testCheckMarkup() { /** * Tests the following functions for a variety of formats: - * - filter_get_allowed_tags_by_format() + * - filter_get_allowed_html_by_format() * - filter_get_filter_types_by_format() */ function testFilterFormatAPI() { // Test on filtered_html. $this->assertEqual( - filter_get_allowed_tags_by_format('filtered_html'), + filter_get_allowed_html_by_format('filtered_html'), array('p' => TRUE, 'br' => TRUE, 'strong' => TRUE, 'a' => TRUE), - 'filter_get_allowed_tags_by_format() works as expected for the filtered_html format.' + 'filter_get_allowed_html_by_format() works as expected for the filtered_html format.' ); $this->assertEqual( filter_get_filter_types_by_format('filtered_html'), @@ -109,9 +109,9 @@ function testFilterFormatAPI() { // Test on full_html. $this->assertEqual( - filter_get_allowed_tags_by_format('full_html'), + filter_get_allowed_html_by_format('full_html'), TRUE, // Every tag is allowed. - 'filter_get_allowed_tags_by_format() works as expected for the full_html format.' + 'filter_get_allowed_html_by_format() works as expected for the full_html format.' ); $this->assertEqual( filter_get_filter_types_by_format('full_html'), @@ -134,9 +134,9 @@ function testFilterFormatAPI() { )); $stupid_filtered_html_format->save(); $this->assertEqual( - filter_get_allowed_tags_by_format('stupid_filtered_html'), + filter_get_allowed_html_by_format('stupid_filtered_html'), array(), // No tag is allowed. - 'filter_get_allowed_tags_by_format() works as expected for the stupid_filtered_html format.' + 'filter_get_allowed_html_by_format() works as expected for the stupid_filtered_html format.' ); $this->assertEqual( filter_get_filter_types_by_format('stupid_filtered_html'), @@ -170,9 +170,9 @@ function testFilterFormatAPI() { )); $very_restricted_html->save(); $this->assertEqual( - filter_get_allowed_tags_by_format('very_restricted_html'), + filter_get_allowed_html_by_format('very_restricted_html'), array('p' => TRUE, 'br' => array(), 'a' => array('href')), - 'filter_get_allowed_tags_by_format() works as expected for the very_restricted_html format.' + 'filter_get_allowed_html_by_format() works as expected for the very_restricted_html format.' ); $this->assertEqual( filter_get_filter_types_by_format('very_restricted_html'), diff --git a/core/modules/filter/tests/filter_test/filter_test.module b/core/modules/filter/tests/filter_test/filter_test.module index 95eb5e3..4cd9ddb 100644 --- a/core/modules/filter/tests/filter_test/filter_test.module +++ b/core/modules/filter/tests/filter_test/filter_test.module @@ -45,7 +45,7 @@ function filter_test_filter_info() { $filters['filter_test_restrict_tags_and_attributes'] = array( 'title' => 'Tag & attribute restricting filter', 'type' => FILTER_TYPE_HTML_RESTRICTOR, - 'allowed tags callback' => '_filter_html_restrict_tags_and_attributes', + 'allowed html callback' => '_filter_restrict_tags_and_attributes_allowed_html', ); return $filters; } @@ -68,8 +68,8 @@ function _filter_test_replace($text, $filter, $format, $langcode, $cache, $cache } /** - * Filter allowed tags callback. + * Filter allowed HTML callback. */ -function _filter_html_restrict_tags_and_attributes($filter) { +function _filter_restrict_tags_and_attributes_allowed_html($filter) { return $filter->settings['restrictions']; }