PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/themes/acquia/builderbase/template.php

https://github.com/rtdean93/tbytam
PHP | 176 lines | 108 code | 19 blank | 49 comment | 18 complexity | 87a7c12356e71ada795c1f603ed0cbab MD5 | raw file
  1. <?php
  2. /**
  3. * Implement hook_preprocess_html().
  4. */
  5. function builderbase_preprocess_html(&$vars) {
  6. $vars['classes_array'][] = 'theme-markup-2';
  7. $vars['classes_array'][] = _builderbase_get_layout();
  8. }
  9. /**
  10. * Implements hook_html_head_alter().
  11. */
  12. function builderbase_html_head_alter(&$head_elements) {
  13. // If the theme's info file contains the custom theme setting
  14. // default_favicon_path, change the favicon <link> tag to reflect that path.
  15. if (($default_favicon_path = theme_get_setting('default_favicon_path')) && theme_get_setting('default_favicon')) {
  16. $favicon_url = file_create_url(path_to_theme() . '/' . $default_favicon_path);
  17. }
  18. else {
  19. if (module_exists('gardens_misc')) {
  20. $favicon_url = file_create_url(drupal_get_path('module', 'gardens_misc') . '/images/gardens.ico');
  21. }
  22. }
  23. if (!empty($favicon_url)) {
  24. $favicon_mimetype = file_get_mimetype($favicon_url);
  25. foreach ($head_elements as &$element) {
  26. if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'shortcut icon') {
  27. $element['#attributes']['href'] = $favicon_url;
  28. $element['#attributes']['type'] = $favicon_mimetype;
  29. }
  30. }
  31. }
  32. }
  33. /**
  34. * Implements hook_preprocess_page().
  35. */
  36. function builderbase_preprocess_page(&$variables) {
  37. $is_front = $variables['is_front'];
  38. // Adjust the html element that wraps the site name. h1 on front page, p on other pages
  39. $variables['wrapper_site_name_prefix'] = ($is_front ? '<h1' : '<p');
  40. $variables['wrapper_site_name_prefix'] .= ' id="site-name"';
  41. $variables['wrapper_site_name_prefix'] .= ' class="site-name'.($is_front ? ' site-name-front' : '').'"';
  42. $variables['wrapper_site_name_prefix'] .= '>';
  43. $variables['wrapper_site_name_suffix'] = ($is_front ? '</h1>' : '</p>');
  44. // If the theme's info file contains the custom theme setting
  45. // default_logo_path, set the $logo variable to that path.
  46. $default_logo_path = theme_get_setting('default_logo_path');
  47. if (!empty($default_logo_path) && theme_get_setting('default_logo')) {
  48. $variables['logo'] = file_create_url(path_to_theme() . '/' . $default_logo_path);
  49. }
  50. else {
  51. $variables['logo'] = null;
  52. }
  53. //Arrange the elements of the main content area (content and sidebars) based on the layout class
  54. $layoutClass = _builderbase_get_layout();
  55. $layout = substr(strrchr($layoutClass, '-'), 1); //Get the last bit of the layout class, the 'abc' string
  56. $contentPos = strpos($layout, 'c');
  57. $sidebarsLeft = substr($layout,0,$contentPos);
  58. $sidebarsRight = strrev(substr($layout,($contentPos+1))); // Reverse the string so that the floats are correct.
  59. $sidebarsHidden = ''; // Create a string of sidebars that are hidden to render and then display:none
  60. if(stripos($layout, 'a') === false) { $sidebarsHidden .= 'a'; }
  61. if(stripos($layout, 'b') === false) { $sidebarsHidden .= 'b'; }
  62. $variables['sidebars']['left'] = str_split($sidebarsLeft);
  63. $variables['sidebars']['right'] = str_split($sidebarsRight);
  64. $variables['sidebars']['hidden'] = str_split($sidebarsHidden);
  65. }
  66. /**
  67. * Implement hook_preprocess_block().
  68. */
  69. function builderbase_preprocess_block(&$vars) {
  70. $vars['content_attributes_array']['class'][] = 'content';
  71. }
  72. /**
  73. * Retrieves the value associated with the specified key from the current theme.
  74. * If the key is not found, the specified default value will be returned instead.
  75. *
  76. * @param <string> $key
  77. * The name of the key.
  78. * @param <mixed> $default
  79. * The default value, returned if the property key is not found in the current
  80. * theme.
  81. * @return <mixed>
  82. * The value associated with the specified key, or the default value.
  83. */
  84. function _builderbase_variable_get($key, $default) {
  85. global $theme;
  86. $themes_info =& drupal_static(__FUNCTION__);
  87. if (!isset($themes_info[$theme])) {
  88. $themes_info = system_get_info('theme');
  89. }
  90. $value = $themes_info[$theme];
  91. foreach (explode('/', $key) as $part) {
  92. if (!isset($value[$part])) {
  93. return $default;
  94. }
  95. $value = $value[$part];
  96. }
  97. return $value;
  98. }
  99. /**
  100. * Returns the name of the layout class associated with the current path. The
  101. * layout name is used as a body class, which causes the page to be styled
  102. * with the corresponding layout. This function makes it possible to use
  103. * different layouts on various pages of a site.
  104. *
  105. * @return <string>
  106. * The name of the layout associated with the current page.
  107. */
  108. function _builderbase_get_layout() {
  109. $layout_patterns = _builderbase_variable_get('layout', array('<global>' => 'body-layout-fixed-abc'));
  110. $global_layout = $layout_patterns['<global>'];
  111. unset($layout_patterns['<global>']);
  112. $alias_path = drupal_get_path_alias($_GET['q']);
  113. $path = $_GET['q'];
  114. foreach ($layout_patterns as $pattern => $layout) {
  115. if (drupal_match_path($alias_path, $pattern) ||
  116. drupal_match_path($path, $pattern)) {
  117. return $layout;
  118. }
  119. }
  120. return $global_layout;
  121. }
  122. /**
  123. * Implements hook_node_view_alter().
  124. */
  125. function builderbase_node_view_alter(&$build) {
  126. if (isset($build['links']) && isset($build['links']['comment']) &&
  127. isset($build['links']['comment']['#attributes']) &&
  128. isset($build['links']['comment']['#attributes']['class'])) {
  129. $classes = $build['links']['comment']['#attributes']['class'];
  130. array_push($classes, 'actions');
  131. $build['links']['comment']['#attributes']['class'] = $classes;
  132. }
  133. }
  134. /**
  135. * Implements hook_preprocess_forum_topic_list
  136. */
  137. function builderbase_preprocess_forum_topic_list(&$vars) {
  138. // Recreate the topic list header
  139. $list = array(
  140. array('data' => t('Topic'), 'field' => 'f.title'),
  141. array('data' => t('Replies'), 'field' => 'f.comment_count'),
  142. array('data' => t('Created'), 'field' => 't.created'),
  143. array('data' => t('Last reply'), 'field' => 'f.last_comment_timestamp'),
  144. );
  145. $ts = tablesort_init($list);
  146. $header = '';
  147. foreach ($list as $cell) {
  148. $cell = tablesort_header($cell, $list, $ts);
  149. $header .= _theme_table_cell($cell, TRUE);
  150. }
  151. $vars['header'] = $header;
  152. }
  153. /*
  154. * Implements hook_preprocess_media_gallery_license().
  155. */
  156. function builderbase_preprocess_media_gallery_license(&$vars) {
  157. }