Guest User

Untitled

a guest
Jul 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <?php
  2. function phptemplate_preprocess_page(&$vars, $hook) {
  3.  
  4. // Classes for body element. Allows advanced theming based on context
  5. // (home page, node of certain type, etc.)
  6. $body_classes = array($vars['body_classes']);
  7. if (!$vars['is_front']) {
  8. // Add unique classes for each page and website section
  9. $path = drupal_get_path_alias($_GET['q']);
  10. list($section, ) = explode('/', $path, 2);
  11. $body_classes[] = mytheme_id_safe('page-' . $path);
  12. $body_classes[] = mytheme_id_safe('section-' . $section);
  13. if (arg(0) == 'node') {
  14. if (arg(1) == 'add') {
  15. if ($section == 'node') {
  16. array_pop($body_classes); // Remove 'section-node'
  17. }
  18. $body_classes[] = 'section-node-add'; // Add 'section-node-add'
  19. }
  20. elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
  21. if ($section == 'node') {
  22. array_pop($body_classes); // Remove 'section-node'
  23. }
  24. $body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete'
  25. }
  26. }
  27. }
  28. $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
  29. }
  30.  
  31. /**
  32. * Converts a string to a suitable html ID attribute.
  33. *
  34. * - Preceeds initial numeric with 'n' character.
  35. * - Replaces any character except A-Z, numbers, and underscores with dashes.
  36. * - Converts entire string to lowercase.
  37. * - Works for classes too!
  38. *
  39. * @param $string
  40. * The string
  41. * @return
  42. * The converted string
  43. */
  44. function mytheme_id_safe($string) {
  45. if (is_numeric($string{0})) {
  46. // If the first character is numeric, add 'n' in front
  47. $string = 'n'. $string;
  48. }
  49. return strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
  50. }
  51. ?>
Add Comment
Please, Sign In to add comment