summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSheena Donnelly2012-03-28 15:21:51 (GMT)
committer Sheena Donnelly2012-03-28 15:21:51 (GMT)
commitfa062a5430c2ce6dba560d9d94eb87eac1018f47 (patch)
tree09bc4ab680795839286a45fd69b0d44fc74286d4
parent3f999327c91bf8eb1156ada3412c4f7d36ca900c (diff)
Switching to a more elegant solution for creating a CSS body class based on page URL. Backported drupal_clean_css_identifier from Drupal 7.x
-rw-r--r--fusion_core/template.php36
1 files changed, 33 insertions, 3 deletions
diff --git a/fusion_core/template.php b/fusion_core/template.php
index 1e7b1d8..76a8a07 100644
--- a/fusion_core/template.php
+++ b/fusion_core/template.php
@@ -77,9 +77,7 @@ function fusion_core_preprocess_page(&$vars) {
$vars['body_classes'] = implode(' ', $body_classes); // Create class list separated by spaces
// Add a unique css id for the body tag by converting / or + or _ in the current page alias into a dash (-).
- $body_id = preg_replace('/[_+\/ ]/', '-', drupal_get_path_alias($_GET['q']));
- $body_id = str_replace(array('"', "'", '>', '<', ';', ':', '='), '', $body_id);
- $vars['body_id'] = 'pid-' . strtolower(filter_xss($body_id, array()));
+ $vars['body_id'] = 'pid-' . fusion_core_clean_css_identifier(drupal_get_path_alias($_GET['q']));
// Generate links tree & add Superfish class if dropdown enabled, else make standard primary links
$vars['primary_links_tree'] = '';
@@ -557,3 +555,35 @@ function fusion_core_theme_paths($theme) {
function fusion_core_themesettings_link($prefix, $suffix, $text, $path, $options) {
return $prefix . (($text) ? l($text, $path, $options) : '') . $suffix;
}
+
+/**
+ * @function fusion_core_clean_css_identifier()
+ * backport of drupal_clean_css_identifier() from Drupal 7.x
+ *
+ * @param $identifier
+ * the identifier to clean
+ * @param $filter
+ * an array of string replacements to use on the identifier
+ *
+ * @return
+ * A string safe for use as a CSS class or ID
+ **/
+
+ function fusion_core_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;
+
+ }