PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/sites/all/themes/omega/alpha/template.php

https://bitbucket.org/frazras/higgler
PHP | 384 lines | 285 code | 53 blank | 46 comment | 54 complexity | 3a2983c833174aeace3318399b5a0c64 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. require_once dirname(__FILE__) . '/includes/alpha.inc';
  3. require_once dirname(__FILE__) . '/includes/base.inc';
  4. /**
  5. * Implements hook_theme().
  6. */
  7. function alpha_theme($existing, $type, $theme, $path) {
  8. return array(
  9. 'section' => array(
  10. 'template' => 'section',
  11. 'path' => $path . '/templates',
  12. 'render element' => 'elements',
  13. 'pattern' => 'section__',
  14. 'preprocess functions' => array(
  15. 'template_preprocess',
  16. 'template_preprocess_section',
  17. 'alpha_preprocess',
  18. 'alpha_preprocess_section',
  19. ),
  20. 'process functions' => array(
  21. 'template_process',
  22. 'template_process_section',
  23. 'alpha_process',
  24. 'alpha_process_section'
  25. ),
  26. ),
  27. 'zone' => array(
  28. 'template' => 'zone',
  29. 'path' => $path . '/templates',
  30. 'render element' => 'elements',
  31. 'pattern' => 'zone__',
  32. 'preprocess functions' => array(
  33. 'template_preprocess',
  34. 'template_preprocess_zone',
  35. 'alpha_preprocess',
  36. 'alpha_preprocess_zone',
  37. ),
  38. 'process functions' => array(
  39. 'template_process',
  40. 'template_process_zone',
  41. 'alpha_process',
  42. 'alpha_process_zone'
  43. ),
  44. ),
  45. );
  46. }
  47. /**
  48. * Implements hook_preprocess().
  49. */
  50. function alpha_preprocess(&$vars, $hook) {
  51. $vars['attributes_array']['class'] = $vars['classes_array'];
  52. alpha_invoke('preprocess', $hook, $vars);
  53. }
  54. /**
  55. * Implements hook_process().
  56. */
  57. function alpha_process(&$vars, $hook) {
  58. if (!empty($vars['elements']['#grid']) || !empty($vars['elements']['#data']['wrapper_css'])) {
  59. if (!empty($vars['elements']['#grid'])) {
  60. foreach (array('prefix', 'suffix', 'push', 'pull') as $quality) {
  61. if (!empty($vars['elements']['#grid'][$quality])) {
  62. array_unshift($vars['attributes_array']['class'], $quality . '-' . $vars['elements']['#grid'][$quality]);
  63. }
  64. }
  65. array_unshift($vars['attributes_array']['class'], 'grid-' . $vars['elements']['#grid']['columns']);
  66. }
  67. if (!empty($vars['elements']['#data']['wrapper_css'])) {
  68. foreach (array_map('drupal_html_class', explode(' ', $vars['elements']['#data']['wrapper_css'])) as $class) {
  69. $vars['attributes_array']['class'][] = $class;
  70. }
  71. }
  72. $vars['attributes'] = $vars['attributes_array'] ? drupal_attributes($vars['attributes_array']) : '';
  73. }
  74. if (!empty($vars['elements']['#grid_container']) || !empty($vars['elements']['#data']['css'])) {
  75. if (!empty($vars['elements']['#data']['css'])) {
  76. foreach (array_map('drupal_html_class', explode(' ', $vars['elements']['#data']['css'])) as $class) {
  77. $vars['content_attributes_array']['class'][] = $class;
  78. }
  79. }
  80. if (!empty($vars['elements']['#grid_container'])) {
  81. $vars['content_attributes_array']['class'][] = 'container-' . $vars['elements']['#grid_container'];
  82. }
  83. $vars['content_attributes'] = $vars['content_attributes_array'] ? drupal_attributes($vars['content_attributes_array']) : '';
  84. }
  85. alpha_invoke('process', $hook, $vars);
  86. }
  87. /**
  88. * Implements hook_element_info_alter().
  89. */
  90. function alpha_element_info_alter(&$elements) {
  91. if (variable_get('preprocess_css', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update')) {
  92. array_unshift($elements['styles']['#pre_render'], 'alpha_css_preprocessor');
  93. }
  94. }
  95. /**
  96. * Implements hook_css_alter().
  97. */
  98. function alpha_css_alter(&$css) {
  99. $theme = alpha_get_theme();
  100. if ($theme->settings['exclude']) {
  101. foreach(array_filter($theme->settings['exclude']) as $item) {
  102. unset($css[$item]);
  103. }
  104. }
  105. }
  106. /**
  107. * Implements hook_page_alter().
  108. */
  109. function alpha_page_alter(&$vars) {
  110. $theme = alpha_get_theme();
  111. $theme->settings['debug']['access'] = alpha_debug_access($GLOBALS['user'], $theme->settings['debug']['roles']);
  112. // If no module has taken care of the main content, add it to the page now.
  113. // This allows the site to still be usable even if no modules that
  114. // control page regions (for example, the Block module) are enabled.
  115. if (!drupal_static('system_main_content_added', FALSE)) {
  116. $vars['content']['system_main'] = drupal_set_page_content();
  117. }
  118. if ($theme->settings['debug']['access'] && ($theme->settings['debug']['grid'] || $theme->settings['debug']['block'])) {
  119. drupal_add_css(drupal_get_path('theme', 'alpha') . '/css/alpha-debug.css', array('group' => CSS_THEME, 'weight' => -5));
  120. drupal_add_js(drupal_get_path('theme', 'alpha') . '/js/alpha-debug.js', array('group' => JS_THEME, 'weight' => -5));
  121. if ($theme->settings['responsive']) {
  122. $vars['page_bottom']['alpha_resize_indicator'] = array(
  123. '#type' => 'markup',
  124. '#markup' => '<div class="alpha-resize-indicator"></div>',
  125. );
  126. }
  127. if ($theme->settings['debug']['grid']) {
  128. $vars['page_bottom']['alpha_grid_toggle'] = array(
  129. '#type' => 'markup',
  130. '#markup' => '<a class="alpha-grid-toggle" href="#"></a>',
  131. );
  132. }
  133. if ($theme->settings['debug']['block']) {
  134. $vars['page_bottom']['alpha_block_toggle'] = array(
  135. '#type' => 'markup',
  136. '#markup' => '<a class="alpha-block-toggle" href="#"></a>',
  137. );
  138. foreach ($theme->regions as $region => $item) {
  139. if ($item['enabled']) {
  140. if (empty($vars[$region])) {
  141. $vars[$region]['#region'] = $region;
  142. $vars[$region]['#theme_wrappers'] = array('region');
  143. }
  144. if (isset($vars[$region]['#theme_wrappers']) && array_search('region', $vars[$region]['#theme_wrappers']) !== FALSE) {
  145. $vars[$region] = array('alpha_debug_' . $region => array(
  146. '#type' => 'markup',
  147. '#markup' => '<div class="alpha-debug-block"><h2>' . $item['name'] . '</h2><p>' . t('This is a debugging block') . '</p></div>',
  148. '#weight' => -999,
  149. )) + $vars[$region];
  150. }
  151. }
  152. }
  153. }
  154. }
  155. if (!module_implements('alpha_page_structure_alter')) {
  156. alpha_alter('alpha_page_structure', $vars, $theme->theme);
  157. }
  158. else {
  159. drupal_alter('alpha_page_structure', $vars, $theme->theme);
  160. }
  161. }
  162. /**
  163. * Implements hook_alpha_page_alter().
  164. */
  165. function alpha_alpha_page_structure_alter(&$vars) {
  166. $theme = alpha_get_theme();
  167. $temporary = array();
  168. foreach ($theme->regions as $region => $item) {
  169. if ($item['enabled'] && $theme->zones[$item['zone']]['enabled'] && ($item['force'] || !empty($vars[$region]))) {
  170. $temporary[$item['section']][$item['zone']][$region] = !empty($vars[$region]) ? $vars[$region] : array();
  171. $temporary[$item['section']][$item['zone']][$region]['#weight'] = (int) $item['weight'];
  172. $temporary[$item['section']][$item['zone']][$region]['#position'] = $item['position'];
  173. $temporary[$item['section']][$item['zone']][$region]['#data'] = $item;
  174. $temporary[$item['section']][$item['zone']][$region]['#grid'] = array(
  175. 'prefix' => $item['prefix'],
  176. 'suffix' => $item['suffix'],
  177. 'push' => $item['push'],
  178. 'pull' => $item['pull'],
  179. 'columns' => $item['columns'],
  180. );
  181. $theme->regions[$region]['grid'] = &$temporary[$item['section']][$item['zone']][$region]['#grid'];
  182. if (empty($vars[$region])) {
  183. $temporary[$item['section']][$item['zone']][$region]['#region'] = $region;
  184. $temporary[$item['section']][$item['zone']][$region]['#theme_wrappers'] = array('region');
  185. }
  186. }
  187. else if (!empty($vars[$region])) {
  188. $vars['#excluded'][$region] = !empty($vars[$region]) ? $vars[$region] : array();
  189. $vars['#excluded'][$region]['#weight'] = (int) $item['weight'];
  190. $vars['#excluded'][$region]['#data'] = $item;
  191. $vars['#excluded'][$region]['#grid'] = array(
  192. 'prefix' => $item['prefix'],
  193. 'suffix' => $item['suffix'],
  194. 'push' => $item['push'],
  195. 'pull' => $item['pull'],
  196. 'columns' => $item['columns'],
  197. );
  198. }
  199. unset($vars[$region]);
  200. }
  201. foreach ($theme->zones as $zone => $item) {
  202. if ($item['enabled'] && ($item['force'] || !empty($temporary[$item['section']][$zone]))) {
  203. if (isset($item['primary']) && isset($temporary[$item['section']][$zone][$item['primary']])) {
  204. alpha_calculate_primary($temporary[$item['section']][$zone], $item['primary'], $item['columns']);
  205. }
  206. if ($item['order']) {
  207. alpha_calculate_position($temporary[$item['section']][$zone]);
  208. }
  209. $temporary[$item['section']][$zone]['#theme_wrappers'] = array('zone');
  210. $temporary[$item['section']][$zone]['#zone'] = $zone;
  211. $temporary[$item['section']][$zone]['#weight'] = (int) $item['weight'];
  212. $temporary[$item['section']][$zone]['#data'] = $item;
  213. $temporary[$item['section']][$zone]['#grid_container'] = $item['columns'];
  214. }
  215. }
  216. foreach ($theme->sections as $section => $item) {
  217. if (isset($temporary[$section])) {
  218. $temporary[$section]['#theme_wrappers'] = array('section');
  219. $temporary[$section]['#section'] = $section;
  220. }
  221. }
  222. $vars = array_merge($vars, $temporary);
  223. }
  224. /**
  225. * Implements hook_preprocess_section().
  226. */
  227. function template_preprocess_section(&$vars) {
  228. $vars['theme_hook_suggestions'][] = 'section__' . $vars['elements']['#section'];
  229. $vars['section'] = $vars['elements']['#section'];
  230. $vars['content'] = $vars['elements']['#children'];
  231. $vars['attributes_array']['id'] = drupal_html_id('section-' . $vars['section']);
  232. $vars['classes_array'] = array('section', $vars['attributes_array']['id']);
  233. }
  234. /**
  235. * Implements hook_preprocess_zone().
  236. */
  237. function template_preprocess_zone(&$vars) {
  238. $vars['theme_hook_suggestions'] = array('zone__' . $vars['elements']['#zone']);
  239. $vars['zone'] = $vars['elements']['#zone'];
  240. $vars['content'] = $vars['elements']['#children'];
  241. $vars['wrapper'] = $vars['elements']['#data']['wrapper'];
  242. $vars['columns'] = $vars['elements']['#data']['columns'];
  243. $vars['content_attributes_array']['id'] = drupal_html_id('zone-' . $vars['zone']);
  244. $vars['content_attributes_array']['class'] = array('zone', $vars['content_attributes_array']['id'], 'clearfix');
  245. if ($vars['wrapper']) {
  246. $vars['attributes_array']['id'] = drupal_html_id($vars['content_attributes_array']['id'] . '-wrapper');
  247. $vars['classes_array'] = array('zone-wrapper', $vars['attributes_array']['id'], 'clearfix');
  248. }
  249. alpha_grid_include($vars['columns']);
  250. }
  251. /**
  252. * Implements hook_preprocess_block().
  253. */
  254. function alpha_alpha_preprocess_block(&$vars) {
  255. $vars['content_attributes_array']['class'][] = 'content';
  256. $vars['content_attributes_array']['class'][] = 'clearfix';
  257. $vars['attributes_array']['id'] = $vars['block_html_id'];
  258. $vars['attributes_array']['class'][] = drupal_html_class('block-' . $vars['block']->delta);
  259. $vars['attributes_array']['class'][] = $vars['block_html_id'];
  260. }
  261. /**
  262. * Implements hook_preprocess_html().
  263. */
  264. function alpha_alpha_preprocess_html(&$vars) {
  265. $theme = alpha_get_theme();
  266. foreach (array('two-sidebars', 'one-sidebar sidebar-first', 'one-sidebar sidebar-second', 'no-sidebars') as $exclude) {
  267. if ($index = array_search($exclude, $vars['attributes_array']['class'])) {
  268. unset($vars['attributes_array']['class'][$index]);
  269. }
  270. }
  271. // Add a CSS class based on the current page context.
  272. if (!drupal_is_front_page()) {
  273. $context = explode('/', drupal_get_path_alias());
  274. $context = reset($context);
  275. if (!empty($context)) {
  276. $vars['attributes_array']['class'][] = drupal_html_class('context-' . $context);
  277. }
  278. }
  279. if (($theme->settings['debug']['grid'] || $theme->settings['debug']['block']) && $theme->settings['debug']['access']) {
  280. if ($theme->settings['debug']['grid'] && $theme->settings['debug']['grid_active']) {
  281. $vars['attributes_array']['class'][] = 'alpha-grid-debug';
  282. }
  283. if ($theme->settings['debug']['block'] && $theme->settings['debug']['block_active']) {
  284. $vars['attributes_array']['class'][] = 'alpha-region-debug';
  285. }
  286. }
  287. if($theme->settings['responsive'] && $theme->settings['viewport']['enabled']) {
  288. $meta = array(
  289. '#tag' => 'meta',
  290. '#attributes' => array(
  291. 'name' => 'viewport',
  292. 'content' => 'width=device-width, initial-scale=' . $theme->settings['viewport']['initial'] . ', maximum-scale=' . $theme->settings['viewport']['max'] . ', minimum-scale=' . $theme->settings['viewport']['min'] . ', user-scalable=' . ($theme->settings['viewport']['user'] ? 'yes' : 'no'),
  293. ),
  294. );
  295. drupal_add_html_head($meta, 'alpha-viewport');
  296. }
  297. alpha_css_include();
  298. alpha_libraries_include();
  299. }
  300. /**
  301. * Implements hook_preprocess_page().
  302. */
  303. function alpha_alpha_preprocess_page(&$vars) {
  304. $theme = alpha_get_theme();
  305. $theme->page = &$vars;
  306. $vars['feed_icons'] = $theme->settings['toggle']['feed_icons'] ? $vars['feed_icons'] : NULL;
  307. $vars['tabs'] = $theme->settings['toggle']['tabs'] ? $vars['tabs'] : NULL;
  308. $vars['action_links'] = $theme->settings['toggle']['action_links'] ? $vars['action_links'] : NULL;
  309. $vars['show_messages'] = $theme->settings['toggle']['messages'] ? $vars['show_messages'] : FALSE;
  310. $vars['site_name_hidden'] = $theme->settings['hidden']['site_name'];
  311. $vars['site_slogan_hidden'] = $theme->settings['hidden']['site_slogan'];
  312. $vars['title_hidden'] = $theme->settings['hidden']['title'];
  313. $vars['attributes_array']['id'] = 'page';
  314. $vars['attributes_array']['class'][] = 'clearfix';
  315. }
  316. /**
  317. * Implements hook_preprocess_region().
  318. */
  319. function alpha_alpha_preprocess_region(&$vars) {
  320. $vars['attributes_array']['id'] = drupal_html_id('region-' . $vars['region']);
  321. $vars['content_attributes_array']['class'][] = 'region-inner';
  322. $vars['content_attributes_array']['class'][] = $vars['attributes_array']['id'] . '-inner';
  323. }
  324. /**
  325. * Implements hook_process_page().
  326. */
  327. function alpha_alpha_process_page(&$vars) {
  328. $theme = alpha_get_theme();
  329. $vars['title'] = $theme->settings['toggle']['page_title'] ? $vars['title'] : NULL;
  330. $vars['breadcrumb'] = $theme->settings['toggle']['breadcrumb'] ? $vars['breadcrumb'] : NULL;
  331. }