Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function phptemplate_preprocess_page(&$vars, $hook) {
- // Classes for body element. Allows advanced theming based on context
- // (home page, node of certain type, etc.)
- $body_classes = array($vars['body_classes']);
- if (!$vars['is_front']) {
- // Add unique classes for each page and website section
- $path = drupal_get_path_alias($_GET['q']);
- list($section, ) = explode('/', $path, 2);
- $body_classes[] = mytheme_id_safe('page-' . $path);
- $body_classes[] = mytheme_id_safe('section-' . $section);
- if (arg(0) == 'node') {
- if (arg(1) == 'add') {
- if ($section == 'node') {
- array_pop($body_classes); // Remove 'section-node'
- }
- $body_classes[] = 'section-node-add'; // Add 'section-node-add'
- }
- elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
- if ($section == 'node') {
- array_pop($body_classes); // Remove 'section-node'
- }
- $body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete'
- }
- }
- }
- $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
- }
- /**
- * Converts a string to a suitable html ID attribute.
- *
- * - Preceeds initial numeric with 'n' character.
- * - Replaces any character except A-Z, numbers, and underscores with dashes.
- * - Converts entire string to lowercase.
- * - Works for classes too!
- *
- * @param $string
- * The string
- * @return
- * The converted string
- */
- function mytheme_id_safe($string) {
- if (is_numeric($string{0})) {
- // If the first character is numeric, add 'n' in front
- $string = 'n'. $string;
- }
- return strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
- }
- ?>
Add Comment
Please, Sign In to add comment