PageRenderTime 132ms CodeModel.GetById 30ms RepoModel.GetById 3ms app.codeStats 0ms

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

https://github.com/kbasarab/d7-core
PHP | 375 lines | 277 code | 52 blank | 46 comment | 49 complexity | f35f829a5a8a111b928cf97b7eb097b9 MD5 | raw file
  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 (isset($vars['elements']['#grid']) || !empty($vars['elements']['#data']['wrapper_css'])) {
  59. if (isset($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']['#data']['css'])) {
  75. foreach (array_map('drupal_html_class', explode(' ', $vars['elements']['#data']['css'])) as $class) {
  76. $vars['content_attributes_array']['class'][] = $class;
  77. }
  78. $vars['content_attributes'] = $vars['content_attributes_array'] ? drupal_attributes($vars['content_attributes_array']) : '';
  79. }
  80. alpha_invoke('process', $hook, $vars);
  81. }
  82. /**
  83. * Implements hook_element_info_alter().
  84. */
  85. function alpha_element_info_alter(&$elements) {
  86. if (variable_get('preprocess_css', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update')) {
  87. array_unshift($elements['styles']['#pre_render'], 'alpha_grid_css_aggregate');
  88. }
  89. }
  90. /**
  91. * Implements hook_css_alter().
  92. */
  93. function alpha_css_alter(&$css) {
  94. $theme = alpha_get_theme();
  95. if ($theme->settings['exclude']) {
  96. foreach(array_filter($theme->settings['exclude']) as $item) {
  97. unset($css[$item]);
  98. }
  99. }
  100. }
  101. /**
  102. * Implements hook_page_alter().
  103. */
  104. function alpha_page_alter(&$vars) {
  105. $theme = alpha_get_theme();
  106. // If no module has taken care of the main content, add it to the page now.
  107. // This allows the site to still be usable even if no modules that
  108. // control page regions (for example, the Block module) are enabled.
  109. if (!drupal_static('system_main_content_added', FALSE)) {
  110. $vars['content']['system_main'] = drupal_set_page_content();
  111. }
  112. if ($theme->settings['debug']['access'] && ($theme->settings['debug']['grid'] || $theme->settings['debug']['block'])) {
  113. drupal_add_css(drupal_get_path('theme', 'alpha') . '/css/alpha-debug.css', array('group' => CSS_THEME, 'weight' => -5));
  114. drupal_add_js(drupal_get_path('theme', 'alpha') . '/js/alpha-debug.js', array('group' => JS_THEME, 'weight' => -5));
  115. if ($theme->settings['responsive']) {
  116. $vars['page_bottom']['alpha_resize_indicator'] = array(
  117. '#type' => 'markup',
  118. '#markup' => '<div class="alpha-resize-indicator"></div>',
  119. );
  120. }
  121. if ($theme->settings['debug']['grid']) {
  122. $vars['page_bottom']['alpha_grid_toggle'] = array(
  123. '#type' => 'markup',
  124. '#markup' => '<a class="alpha-grid-toggle" href="#"></a>',
  125. );
  126. }
  127. if ($theme->settings['debug']['block']) {
  128. $vars['page_bottom']['alpha_block_toggle'] = array(
  129. '#type' => 'markup',
  130. '#markup' => '<a class="alpha-block-toggle" href="#"></a>',
  131. );
  132. foreach ($theme->regions as $region => $item) {
  133. if ($item['enabled']) {
  134. if (empty($vars[$region])) {
  135. $vars[$region]['#region'] = $region;
  136. $vars[$region]['#theme_wrappers'] = array('region');
  137. }
  138. $vars[$region]['#sorted'] = FALSE;
  139. $vars[$region]['alpha_debug_' . $region] = array(
  140. '#type' => 'markup',
  141. '#markup' => '<div class="alpha-debug-block"><h2>' . $item['name'] . '</h2><p>' . t('This is a debugging block') . '</p></div>',
  142. '#weight' => -999,
  143. );
  144. }
  145. }
  146. }
  147. }
  148. if (!module_implements('alpha_page_structure_alter')) {
  149. alpha_alter('alpha_page_structure', $vars, $theme->theme);
  150. }
  151. else {
  152. drupal_alter('alpha_page_structure', $vars, $theme->theme);
  153. }
  154. }
  155. /**
  156. * Implements hook_alpha_page_alter().
  157. */
  158. function alpha_alpha_page_structure_alter(&$vars) {
  159. $theme = alpha_get_theme();
  160. $temporary = array();
  161. foreach ($theme->regions as $region => $item) {
  162. if ($item['enabled'] && $theme->zones[$item['zone']]['enabled'] && ($item['force'] || !empty($vars[$region]))) {
  163. $temporary[$item['section']][$item['zone']][$region] = !empty($vars[$region]) ? $vars[$region] : array();
  164. $temporary[$item['section']][$item['zone']][$region]['#weight'] = (int) $item['weight'];
  165. $temporary[$item['section']][$item['zone']][$region]['#position'] = $item['position'];
  166. $temporary[$item['section']][$item['zone']][$region]['#data'] = $item;
  167. $temporary[$item['section']][$item['zone']][$region]['#grid'] = array(
  168. 'prefix' => $item['prefix'],
  169. 'suffix' => $item['suffix'],
  170. 'push' => $item['push'],
  171. 'pull' => $item['pull'],
  172. 'columns' => $item['columns'],
  173. );
  174. $theme->regions[$region]['grid'] = &$temporary[$item['section']][$item['zone']][$region]['#grid'];
  175. if (empty($vars[$region])) {
  176. $temporary[$item['section']][$item['zone']][$region]['#region'] = $region;
  177. $temporary[$item['section']][$item['zone']][$region]['#theme_wrappers'] = array('region');
  178. }
  179. }
  180. else if (!empty($vars[$region])) {
  181. $vars['#excluded'][$region] = !empty($vars[$region]) ? $vars[$region] : array();
  182. $vars['#excluded'][$region]['#weight'] = (int) $item['weight'];
  183. $vars['#excluded'][$region]['#data'] = $item;
  184. $vars['#excluded'][$region]['#grid'] = array(
  185. 'prefix' => $item['prefix'],
  186. 'suffix' => $item['suffix'],
  187. 'push' => $item['push'],
  188. 'pull' => $item['pull'],
  189. 'columns' => $item['columns'],
  190. );
  191. }
  192. unset($vars[$region]);
  193. }
  194. foreach ($theme->zones as $zone => $item) {
  195. if ($item['enabled'] && ($item['force'] || !empty($temporary[$item['section']][$zone]))) {
  196. if (isset($item['primary']) && isset($temporary[$item['section']][$zone][$item['primary']])) {
  197. alpha_calculate_primary($temporary[$item['section']][$zone], $item['primary'], $item['columns']);
  198. }
  199. if ($item['order']) {
  200. alpha_calculate_position($temporary[$item['section']][$zone]);
  201. }
  202. $temporary[$item['section']][$zone]['#theme_wrappers'] = array('zone');
  203. $temporary[$item['section']][$zone]['#zone'] = $zone;
  204. $temporary[$item['section']][$zone]['#weight'] = (int) $item['weight'];
  205. $temporary[$item['section']][$zone]['#data'] = $item;
  206. }
  207. }
  208. foreach ($theme->sections as $section => $item) {
  209. if (isset($temporary[$section])) {
  210. $temporary[$section]['#theme_wrappers'] = array('section');
  211. $temporary[$section]['#section'] = $section;
  212. }
  213. }
  214. $vars = array_merge($vars, $temporary);
  215. }
  216. /**
  217. * Implements hook_preprocess_section().
  218. */
  219. function template_preprocess_section(&$vars) {
  220. $vars['theme_hook_suggestions'][] = 'section__' . $vars['elements']['#section'];
  221. $vars['section'] = $vars['elements']['#section'];
  222. $vars['content'] = $vars['elements']['#children'];
  223. $vars['attributes_array']['id'] = drupal_html_id('section-' . $vars['section']);
  224. $vars['classes_array'] = array('section', $vars['attributes_array']['id']);
  225. }
  226. /**
  227. * Implements hook_preprocess_zone().
  228. */
  229. function template_preprocess_zone(&$vars) {
  230. $vars['theme_hook_suggestions'] = array('zone__' . $vars['elements']['#zone']);
  231. $vars['zone'] = $vars['elements']['#zone'];
  232. $vars['content'] = $vars['elements']['#children'];
  233. $vars['wrapper'] = $vars['elements']['#data']['wrapper'];
  234. $vars['columns'] = $vars['elements']['#data']['columns'];
  235. $vars['content_attributes_array']['id'] = drupal_html_id('zone-' . $vars['zone']);
  236. $vars['content_attributes_array']['class'] = array('container-' . $vars['columns'], 'zone', $vars['content_attributes_array']['id'], 'clearfix');
  237. if ($vars['wrapper']) {
  238. $vars['attributes_array']['id'] = drupal_html_id($vars['content_attributes_array']['id'] . '-wrapper');
  239. $vars['classes_array'] = array('zone-wrapper', $vars['attributes_array']['id'], 'clearfix');
  240. }
  241. alpha_grid_include($vars['columns']);
  242. }
  243. /**
  244. * Implements hook_preprocess_block().
  245. */
  246. function alpha_preprocess_block(&$vars) {
  247. $vars['content_attributes_array']['class'][] = 'content';
  248. $vars['content_attributes_array']['class'][] = 'clearfix';
  249. $vars['attributes_array']['id'] = $vars['block_html_id'];
  250. $vars['attributes_array']['class'][] = drupal_html_class('block-' . $vars['block']->delta);
  251. $vars['attributes_array']['class'][] = $vars['block_html_id'];
  252. }
  253. /**
  254. * Implements hook_preprocess_html().
  255. */
  256. function alpha_preprocess_html(&$vars) {
  257. $theme = alpha_get_theme();
  258. foreach (array('two-sidebars', 'one-sidebar sidebar-first', 'one-sidebar sidebar-second', 'no-sidebars') as $exclude) {
  259. if ($index = array_search($exclude, $vars['attributes_array']['class'])) {
  260. unset($vars['attributes_array']['class'][$index]);
  261. }
  262. }
  263. // Add a CSS class based on the current page context.
  264. if (!drupal_is_front_page()) {
  265. $context = explode('/', drupal_get_path_alias());
  266. $context = reset($context);
  267. if (!empty($context)) {
  268. $vars['attributes_array']['class'][] = drupal_html_class('context-' . $context);
  269. }
  270. }
  271. if (($theme->settings['debug']['grid'] || $theme->settings['debug']['block']) && $theme->settings['debug']['access']) {
  272. if ($theme->settings['debug']['grid'] && $theme->settings['debug']['grid_active']) {
  273. $vars['attributes_array']['class'][] = 'alpha-grid-debug';
  274. }
  275. if ($theme->settings['debug']['block'] && $theme->settings['debug']['block_active']) {
  276. $vars['attributes_array']['class'][] = 'alpha-region-debug';
  277. }
  278. }
  279. if($theme->settings['responsive'] && $theme->settings['viewport']['enabled']) {
  280. $meta = array(
  281. '#tag' => 'meta',
  282. '#attributes' => array(
  283. 'name' => 'viewport',
  284. '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'),
  285. ),
  286. );
  287. drupal_add_html_head($meta, 'alpha-viewport');
  288. }
  289. alpha_css_include();
  290. alpha_libraries_include();
  291. }
  292. /**
  293. * Implements hook_preprocess_page().
  294. */
  295. function alpha_preprocess_page(&$vars) {
  296. $theme = alpha_get_theme();
  297. $theme->page = &$vars;
  298. $vars['feed_icons'] = $theme->settings['toggle']['feed_icons'] ? $vars['feed_icons'] : NULL;
  299. $vars['tabs'] = $theme->settings['toggle']['tabs'] ? $vars['tabs'] : NULL;
  300. $vars['action_links'] = $theme->settings['toggle']['action_links'] ? $vars['action_links'] : NULL;
  301. $vars['show_messages'] = $theme->settings['toggle']['messages'] ? $vars['show_messages'] : FALSE;
  302. $vars['site_name_hidden'] = $theme->settings['hidden']['site_name'];
  303. $vars['site_slogan_hidden'] = $theme->settings['hidden']['site_slogan'];
  304. $vars['title_hidden'] = $theme->settings['hidden']['title'];
  305. $vars['attributes_array']['id'] = 'page';
  306. $vars['attributes_array']['class'][] = 'clearfix';
  307. }
  308. /**
  309. * Implements hook_preprocess_region().
  310. */
  311. function alpha_preprocess_region(&$vars) {
  312. $vars['attributes_array']['id'] = drupal_html_id('region-' . $vars['region']);
  313. $vars['content_attributes_array']['class'][] = 'region-inner';
  314. $vars['content_attributes_array']['class'][] = $vars['attributes_array']['id'] . '-inner';
  315. }
  316. /**
  317. * Implements hook_process_page().
  318. */
  319. function alpha_process_page(&$vars) {
  320. $theme = alpha_get_theme();
  321. $vars['title'] = $theme->settings['toggle']['page_title'] ? $vars['title'] : NULL;
  322. $vars['breadcrumb'] = $theme->settings['toggle']['breadcrumb'] ? $vars['breadcrumb'] : NULL;
  323. }