diff --git a/handlers/views_handler_field.inc b/handlers/views_handler_field.inc index 5578fbb..24348bc 100644 --- a/handlers/views_handler_field.inc +++ b/handlers/views_handler_field.inc @@ -241,8 +241,11 @@ class views_handler_field extends views_handler { * Return the class of the field. */ function element_classes($row_index = NULL) { - $classes = explode(' ', $this->tokenize_value($this->options['element_class'], $row_index)); - $classes = array_map('drupal_clean_css_identifier', $classes); + $classes = explode(' ', $this->options['element_class']); + foreach ($classes as &$class) { + $class = $this->tokenize_value($class, $row_index); + $class = views_clean_css_identifier($class); + } return implode(' ', $classes); } @@ -289,7 +292,10 @@ class views_handler_field extends views_handler { */ function element_label_classes() { $classes = explode(' ', $this->options['element_label_class']); - $classes = array_map('drupal_clean_css_identifier', $classes); + foreach ($classes as &$class) { + $class = $this->tokenize_value($class); + $class = views_clean_css_identifier($class); + } return implode(' ', $classes); } @@ -298,7 +304,10 @@ class views_handler_field extends views_handler { */ function element_wrapper_classes() { $classes = explode(' ', $this->options['element_wrapper_class']); - $classes = array_map('drupal_clean_css_identifier', $classes); + foreach ($classes as &$class) { + $class = $this->tokenize_value($class); + $class = views_clean_css_identifier($class); + } return implode(' ', $classes); } diff --git a/plugins/views_plugin_display.inc b/plugins/views_plugin_display.inc index 7ffa70d..2819bd4 100644 --- a/plugins/views_plugin_display.inc +++ b/plugins/views_plugin_display.inc @@ -1881,7 +1881,7 @@ class views_plugin_display extends views_plugin { switch ($form_state['section']) { case 'css_class': $css_class = $form_state['values']['css_class']; - if (preg_match('/[^a-zA-Z0-9- ]/', $css_class)) { + if (preg_match('/[^a-zA-Z0-9-_ ]/', $css_class)) { form_error($form['css_class'], t('CSS classes must be alphanumeric or dashes only.')); } break; diff --git a/theme/theme.inc b/theme/theme.inc index 04b92b9..4fa75c3 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -678,10 +678,10 @@ function template_preprocess_views_view_list(&$vars) { $handler = $vars['view']->style_plugin; $class = explode(' ', $handler->options['class']); - $class = array_map('drupal_clean_css_identifier', $class); + $class = array_map('views_clean_css_identifier', $class); $wrapper_class = explode(' ', $handler->options['wrapper_class']); - $wrapper_class = array_map('drupal_clean_css_identifier', $wrapper_class); + $wrapper_class = array_map('views_clean_css_identifier', $wrapper_class); $vars['class'] = implode(' ', $class); $vars['wrapper_class'] = implode(' ', $wrapper_class); diff --git a/views.module b/views.module index 81bae5a..32bdf22 100644 --- a/views.module +++ b/views.module @@ -1782,6 +1782,39 @@ function views_var_export($var, $prefix = '', $init = TRUE) { } /** + * Prepare a string for use as a valid CSS identifier (element, class or ID name). + * This function is similar to a core version but with more sane filter values. + * + * http://www.w3.org/TR/CSS21/syndata.html#characters shows the syntax for valid + * CSS identifiers (including element names, classes, and IDs in selectors.) + * + * @param $identifier + * The identifier to clean. + * @param $filter + * An array of string replacements to use on the identifier. + * @return + * The cleaned identifier. + * + * @see drupal_clean_css_identifier + */ +function views_clean_css_identifier($identifier, $filter = array(' ' => '-', '/' => '-', '[' => '-', ']' => '')) { + // By default, we filter using Drupal's coding standards. + $identifier = strtr($identifier, $filter); + + // Valid characters in a CSS identifier are: + // - the hyphen (U+002D) + // - a-z (U+0030 - U+0039) + // - A-Z (U+0041 - U+005A) + // - the underscore (U+005F) + // - 0-9 (U+0061 - U+007A) + // - ISO 10646 characters U+00A1 and higher + // We strip out any character not in the above list. + $identifier = preg_replace('/[^\x{002D}\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u', '', $identifier); + + return $identifier; +} + +/** * Implement hook_views_exportables(). */ function views_views_exportables($op = 'list', $views = NULL, $name = 'foo') {