preprocess.inc

  1. cis7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/preprocess.inc
  2. cle7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/preprocess.inc
  3. ecd7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/preprocess.inc
  4. elmsmedia7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/preprocess.inc
  5. harmony7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/preprocess.inc
  6. icor7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/preprocess.inc
  7. meedjum_blog7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/preprocess.inc
  8. mooc7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/preprocess.inc

All Preprocess functions for templates and theme fucntions. If you need to add or modify preprocess functions do it in your sub-theme.

Functions

Namesort descending Description
adaptivetheme_preprocess Preprocess variables for all templates.
adaptivetheme_preprocess_aggregator_item Preprocess variables for aggregator-item.tpl.php
adaptivetheme_preprocess_block Preprocess variables for block.tpl.php
adaptivetheme_preprocess_breadcrumb Preprocess variables for breadcrumbs
adaptivetheme_preprocess_comment Preprocess variables for comment.tpl.php
adaptivetheme_preprocess_field Preprocess variables for field.tpl.php
adaptivetheme_preprocess_html Preprocess variables for html.tpl.php
adaptivetheme_preprocess_image Preprocess variables for theme_image()
adaptivetheme_preprocess_maintenance_page Preprocess variables for maintenance-page.tpl.php
adaptivetheme_preprocess_menubar Preprocess variables for adaptivtheme_menubar()
adaptivetheme_preprocess_node Preprocess variables for node.tpl.php
adaptivetheme_preprocess_page Preprocess variables for page.tpl.php
adaptivetheme_preprocess_panels_pane Preprocess variables for panels_pane.tpl.php
adaptivetheme_preprocess_region Preprocess variables for region.tpl.php
adaptivetheme_preprocess_search_block_form Preprocess variables for the search block form.
adaptivetheme_preprocess_username Preprocess variables for the username.
adaptivetheme_preprocess_user_profile Preprocess variables for user-profile.tpl.php

File

sites/all/themes/ulmus/adaptivetheme/at_core/inc/preprocess.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * All Preprocess functions for templates and theme fucntions.
  5. * If you need to add or modify preprocess functions do it in your sub-theme.
  6. */
  7. /**
  8. * Preprocess variables for all templates.
  9. */
  10. function adaptivetheme_preprocess(&$vars) {
  11. // Provide variables to all templates to test for a mobile and tablet context, this
  12. // requires the Mobile Detect or Browscap modules. TRUE/FALSE mean the feature
  13. // was detected; NULL means the feature could not be properly detected.
  14. $browser = at_get_browser();
  15. $vars['is_mobile'] = $browser['is_mobile'];
  16. $vars['is_tablet'] = $browser['is_tablet'];
  17. }
  18. /**
  19. * Preprocess variables for html.tpl.php
  20. */
  21. function adaptivetheme_preprocess_html(&$vars) {
  22. global $theme_key, $language;
  23. $theme_name = $theme_key;
  24. // Set variable for the base path
  25. $vars['base_path'] = base_path();
  26. // Get the info file data
  27. $info = at_get_info($theme_name);
  28. // DOCTYPE
  29. // AT no longer uses doctype switching or $rdf_profile, these maintain
  30. // backwards compatibility with pre 7.x-2.1 versions of html.tpl.php
  31. $vars['doctype'] = '<!DOCTYPE html>' . "\n";
  32. $vars['rdf_profile'] = '';
  33. // Use a proper attributes array for the html attributes.
  34. // You can add more attributes to the html elment, for example in a sub-theme you can do this:
  35. // $vars['html_attributes_array']['xmlns:og'][] = 'http://opengraphprotocol.org/schema/';
  36. $vars['html_attributes_array']['lang'][] = $language->language;
  37. $vars['html_attributes_array']['dir'][] = $language->dir;
  38. // Convert RDF Namespaces into structured data using drupal_attributes.
  39. $vars['rdf_namespaces'] = array();
  40. if (function_exists('rdf_get_namespaces')) {
  41. foreach (rdf_get_namespaces() as $prefix => $uri) {
  42. $prefixes[] = $prefix . ': ' . $uri;
  43. }
  44. $vars['rdf_namespaces_array']['prefix'] = implode(' ', $prefixes);
  45. }
  46. // Get the path to the directory where our CSS files are saved
  47. $path = variable_get('theme_' . $theme_name . '_files_directory');
  48. // Load Layout
  49. at_load_layout_css($path, $theme_name);
  50. // Add layout settings as JS settings, we use this for responsive JS,
  51. // such as the Menu Toggle javascript.
  52. at_load_layout_js_settings($theme_name);
  53. // Load Responsive Styles.
  54. if (at_get_setting('disable_responsive_styles', $theme_name) === 0) {
  55. at_load_responsive_css($path, $theme_name);
  56. }
  57. // Load fonts and/or Custom CSS and the menu toggle files
  58. if (at_get_setting('enable_extensions', $theme_name) === 1) {
  59. // Fonts CSS
  60. if (at_get_setting('enable_font_settings', $theme_name) === 1) {
  61. at_load_fonts($path, $theme_name);
  62. }
  63. // Custom CSS
  64. if (at_get_setting('enable_custom_css', $theme_name) === 1) {
  65. at_load_custom_css($path, $theme_name);
  66. }
  67. // Load the menu toggle js and css files
  68. if (at_get_setting('enable_menu_toggle', $theme_name) === 1) {
  69. at_load_menu_toggle($path, $theme_name);
  70. }
  71. // Load Extension Settings CSS
  72. at_load_extensions_css($theme_name);
  73. }
  74. // Load conditional stylesheets declared in the info file
  75. if (isset($info['ie_stylesheets'])) {
  76. at_load_subtheme_conditional_styles($theme_name);
  77. }
  78. // Load specific subtheme scripts
  79. if (at_get_setting('load_onmediaqueryjs', $theme_name) === 1) {
  80. at_load_subtheme_script('scripts/media_queries.js', $theme_name, 'footer', '100');
  81. }
  82. // Load polyfills
  83. $vars['polyfills'] = at_load_polyfills($theme_name, $vars);
  84. // Set the skip navigation target ID
  85. $vars['skip_link_target'] = '#main-content';
  86. if (at_get_setting('skip_link_target', $theme_name)) {
  87. $skip_link_target = at_get_setting('skip_link_target', $theme_name);
  88. $vars['skip_link_target'] = check_plain($skip_link_target);
  89. }
  90. // Generate body classes
  91. if ($html_classes = at_generate_html_classes($vars, $theme_name)) {
  92. foreach ($html_classes as $class_name) {
  93. $vars['classes_array'][] = $class_name;
  94. }
  95. }
  96. // Do some legacy stuff for 7.x-2.x themes that have google webfonts running
  97. // on the old system. Scan for the existence of a "release" key and
  98. // conditionally load google.web.fonts.inc
  99. if (!isset($info['release']) || $info['release'] === '7.x-2.x') {
  100. include_once(drupal_get_path('theme', 'adaptivetheme') . '/inc/google.web.fonts.inc');
  101. }
  102. // Load debuggers if enabled.
  103. if (at_get_setting('expose_regions', $theme_name) === 1 || at_get_setting('show_window_size', $theme_name) === 1 || at_get_setting('load_all_panels', $theme_name) === 1) {
  104. at_load_debuggers($theme_name);
  105. }
  106. }
  107. /**
  108. * Preprocess variables for page.tpl.php
  109. */
  110. function adaptivetheme_preprocess_page(&$vars) {
  111. global $theme_key;
  112. $theme_name = $theme_key;
  113. // Set up logo element
  114. if (at_get_setting('toggle_logo', $theme_name) === 1) {
  115. $vars['site_logo'] = &drupal_static('adaptivetheme_preprocess_page_site_logo');
  116. if (empty($vars['site_logo'])) {
  117. $logo_image_path = check_url($vars['logo']);
  118. $logo_image_alt = check_plain(variable_get('site_name', t('Home page')));
  119. $logo_image_vars = array('path' => $logo_image_path, 'alt' => $logo_image_alt, 'attributes' => array('class' => 'site-logo'));
  120. $vars['logo_img'] = theme('image', $logo_image_vars);
  121. if (at_get_setting('logo_title') == 1) {
  122. $vars['site_logo'] = $vars['logo_img'] ? l($vars['logo_img'], '<front>', array('attributes' => array('title' => $logo_image_alt), 'html' => TRUE)) : '';
  123. }
  124. else {
  125. $vars['site_logo'] = $vars['logo_img'] ? l($vars['logo_img'], '<front>', array('html' => TRUE)) : '';
  126. }
  127. }
  128. // Maintain backwards compatibility with 7.x-2.x sub-themes
  129. $vars['linked_site_logo'] = $vars['site_logo'];
  130. }
  131. else {
  132. $vars['site_logo'] = '';
  133. $vars['logo_img'] = '';
  134. $vars['linked_site_logo'] = '';
  135. }
  136. // Site name
  137. $vars['site_name'] = &drupal_static('adaptivetheme_preprocess_page_site_name');
  138. if (empty($vars['site_name'])) {
  139. $vars['site_name_title'] = variable_get('site_name', 'Drupal');
  140. $vars['site_name'] = l($vars['site_name_title'], '<front>', array('attributes' => array('title' => t('Home page'))));
  141. $vars['site_name_unlinked'] = $vars['site_name_title'];
  142. }
  143. // Site name visibility and other classes and variables
  144. $vars['site_name_attributes_array'] = array();
  145. $vars['visibility'] = '';
  146. $vars['hide_site_name'] = FALSE;
  147. if (at_get_setting('toggle_name', $theme_name) === 0) {
  148. // Keep the visibility variable to maintain backwards compatibility
  149. $vars['visibility'] = 'element-invisible';
  150. $vars['site_name_attributes_array']['class'][] = $vars['visibility'];
  151. $vars['hide_site_name'] = TRUE;
  152. }
  153. // Build a variable for the main menu
  154. if (isset($vars['main_menu'])) {
  155. $main_menu_title = at_get_setting('menu_button_link_text') ? at_get_setting('menu_button_link_text') : t('Main menu');
  156. $vars['primary_navigation'] = theme('links', array(
  157. 'links' => $vars['main_menu'],
  158. 'attributes' => array(
  159. 'class' => array('menu', 'primary-menu', 'clearfix'),
  160. ),
  161. 'heading' => array(
  162. 'text' => $main_menu_title,
  163. 'level' => 'h2',
  164. 'class' => array('element-invisible'),
  165. 'id' => array('primary-menu'),
  166. )
  167. ));
  168. }
  169. // Build a variable for the secondary menu
  170. if (isset($vars['secondary_menu'])) {
  171. $vars['secondary_navigation'] = theme('links', array(
  172. 'links' => $vars['secondary_menu'],
  173. 'attributes' => array(
  174. 'class' => array('menu', 'secondary-menu', 'clearfix'),
  175. ),
  176. 'heading' => array(
  177. 'text' => t('Secondary menu'),
  178. 'level' => 'h2',
  179. 'class' => array('element-invisible'),
  180. 'id' => 'secondary-menu',
  181. )
  182. ));
  183. }
  184. // Build variables for Primary and Secondary local tasks
  185. $vars['primary_local_tasks'] = menu_primary_local_tasks();
  186. $vars['secondary_local_tasks'] = menu_secondary_local_tasks();
  187. // Add back the $search_box var to D7
  188. if (module_exists('search')) {
  189. $search_box = drupal_get_form('search_form');
  190. $vars['search_box'] = '<div id="search-box" role="search">' . drupal_render($search_box) . '</div>';
  191. }
  192. // Process enabled Extensions
  193. if (at_get_setting('enable_extensions', $theme_name) === 1) {
  194. // Generate page classes, in AT Core these are all Extensions
  195. if ($page_classes = at_generate_page_classes($vars, $theme_name)) {
  196. foreach ($page_classes as $class_name) {
  197. $vars['classes_array'][] = $class_name;
  198. }
  199. }
  200. // Process modify markup settings
  201. if (at_get_setting('enable_markup_overides', $theme_name) === 1) {
  202. // Remove the infernal feed icons
  203. if (at_get_setting('feed_icons_hide', $theme_name) === 1) {
  204. $vars['feed_icons'] = '';
  205. }
  206. }
  207. }
  208. // Strip stupid contextual-links-region class.
  209. //$vars['classes_array'] = array_values(array_diff($vars['classes_array'], array('contextual-links-region')));
  210. // page attributes
  211. $vars['page_attributes_array']['id'][] = 'page';
  212. $vars['page_attributes_array']['class'] = $vars['classes_array'];
  213. // header attributes
  214. $vars['header_attributes_array']['id'][] = 'header';
  215. $vars['header_attributes_array']['class'][] = 'clearfix';
  216. $vars['header_attributes_array']['role'][] = 'banner';
  217. // branding attributes
  218. $vars['branding_attributes_array']['id'][] = 'branding';
  219. $vars['branding_attributes_array']['class'][] = 'branding-elements';
  220. $vars['branding_attributes_array']['class'][] = 'clearfix';
  221. // site name and slogan attributes (wrapper div)
  222. // hgroup maintains BC layer for pre 7.x-3.2 themes
  223. $vars['hgroup_attributes_array'] = array();
  224. if (!$vars['site_slogan'] && $vars['hide_site_name']) {
  225. $vars['hgroup_attributes_array']['class'][] = $vars['visibility'];
  226. }
  227. $vars['hgroup_attributes_array']['class'][] = 'h-group';
  228. $vars['hgroup_attributes_array']['id'][] = 'name-and-slogan';
  229. // site name attributes
  230. $vars['site_name_attributes_array']['id'][] = 'site-name';
  231. // site slogan attributes
  232. $vars['site_slogan_attributes_array']['id'][] = 'site-slogan';
  233. // main content header attributes
  234. $vars['content_header_attributes_array']['id'][] = 'main-content-header';
  235. $vars['content_header_attributes_array']['class'][] = 'clearfix';
  236. // footer attributes
  237. $vars['footer_attributes_array']['id'][] = 'footer';
  238. $vars['footer_attributes_array']['class'][] = 'clearfix';
  239. $vars['footer_attributes_array']['role'][] = 'contentinfo';
  240. // Attribution variable used in admin theme and some others
  241. $vars['attribution'] = '';
  242. if (at_get_setting('attribution_toggle', $theme_name) === 1) {
  243. $vars['attribution'] = "<small class=\"attribution\">Premium Drupal Theme by <a href=\"http://adaptivethemes.com\">Adaptivethemes.com</a></small>";
  244. }
  245. // Work around a perculier bug/feature(?) in Drupal 7 which incorrectly sets
  246. // the page title to "User account" for all three of these pages.
  247. $title = drupal_get_title();
  248. if (arg(0) === 'user' && $title == t('User account')) {
  249. if (arg(1) === 'login' || arg(1) == '') {
  250. drupal_set_title(t('User login'));
  251. }
  252. if (arg(1) === 'password') {
  253. drupal_set_title(t('Request new password'));
  254. }
  255. if (arg(1) === 'register') {
  256. drupal_set_title(t('Create new account'));
  257. }
  258. }
  259. }
  260. /**
  261. * Preprocess variables for region.tpl.php
  262. */
  263. function adaptivetheme_preprocess_region(&$vars) {
  264. global $theme_key;
  265. $theme_name = $theme_key;
  266. $region = $vars['region'];
  267. // Add a "sidebar" class to sidebar regions
  268. if (strpos($region, 'sidebar_') === 0) {
  269. $vars['classes_array'][] = 'sidebar';
  270. // Allow a region-specific template to override the region--sidebar suggestion.
  271. array_unshift($vars['theme_hook_suggestions'], 'region__sidebar');
  272. }
  273. // Float region block classes
  274. if (at_get_setting('enable_extensions', $theme_name) === 1) {
  275. if (at_get_setting('enable_float_region_blocks', $theme_name) === 1) {
  276. // Make sure there is something set for the region, get the column count
  277. if ($float_blocks_regions_class = at_get_setting('float_block_' . $region)) {
  278. // Do nothing if its <none>
  279. if ($float_blocks_regions_class !== '<none>') {
  280. // Set a class for the number of columns selected, default to nothing
  281. $float_blocks_regions_class = isset($float_blocks_regions_class) ? check_plain($float_blocks_regions_class) : '';
  282. $vars['classes_array'][] = 'float-blocks-' . $float_blocks_regions_class;
  283. // Add the float direction class, default to left if the setting fails
  284. if ($float_block_direction_class = at_get_setting('float_block_direction_' . $region)) {
  285. $float_block_direction_class = isset($float_block_direction_class) ? check_plain($float_block_direction_class) : 'left';
  286. $vars['classes_array'][] = 'float-blocks-' . $float_block_direction_class;
  287. }
  288. }
  289. }
  290. }
  291. }
  292. // Add classes to conditional stack regions in Gpanel regions, in the Panels
  293. // layout plugins these are hard coded.
  294. $conditional_stack_regions = &drupal_static(__FUNCTION__, array());
  295. if (empty($conditional_stack_regions)) {
  296. $conditional_stack_regions = array(
  297. 'three_25_25_50_top',
  298. 'three_25_25_50_bottom',
  299. 'three_25_50_25_top',
  300. 'three_25_50_25_bottom',
  301. 'three_50_25_25_top',
  302. 'three_50_25_25_bottom',
  303. 'three_33_top',
  304. 'three_33_bottom',
  305. 'two_50_top',
  306. 'two_50_bottom',
  307. 'two_33_66_top',
  308. 'two_33_66_bottom',
  309. 'two_66_33_top',
  310. 'two_66_33_bottom',
  311. 'two_brick_top',
  312. 'two_brick_middle',
  313. 'two_brick_bottom',
  314. 'threecol_inset_left_top',
  315. 'threecol_inset_left_bottom',
  316. 'threecol_inset_right_top',
  317. 'threecol_inset_right_bottom',
  318. );
  319. }
  320. if (in_array($region, $conditional_stack_regions)) {
  321. $vars['classes_array'][] = 'region-conditional-stack';
  322. }
  323. }
  324. /**
  325. * Preprocess variables for block.tpl.php
  326. */
  327. function adaptivetheme_preprocess_block(&$vars) {
  328. global $theme_key;
  329. global $user;
  330. $theme_name = $theme_key;
  331. // Block subject, under certain conditions, is not set
  332. $vars['tag'] = 'div';
  333. $vars['title'] = '';
  334. if (isset($vars['block']->subject)) {
  335. if (!empty($vars['block']->subject)) {
  336. // Generate the wrapper element, if there's a title use section
  337. $vars['tag'] = 'section';
  338. // Use a $title variable instead of $block->subject
  339. $vars['title'] = $vars['block']->subject;
  340. }
  341. // subject can be set and empty, i.e. using <none>
  342. else {
  343. $vars['classes_array'][] = 'no-title';
  344. }
  345. }
  346. // sometimes subject is not set at all
  347. else {
  348. $vars['classes_array'][] = 'no-title';
  349. }
  350. // Search is never a section, its just a div
  351. if ($vars['block_html_id'] === 'block-search-form') {
  352. $vars['tag'] = 'div';
  353. }
  354. // Block inner attributes
  355. $vars['block_inner_attributes_array']['class'][] = 'block-inner';
  356. $vars['block_inner_attributes_array']['class'][] = 'clearfix';
  357. // Use nav element for menu blocks and provide a suggestion for all of them
  358. $nav_blocks = array('navigation', 'main-menu', 'management', 'user-menu');
  359. if (in_array($vars['block']->delta, $nav_blocks)) {
  360. $vars['tag'] = 'nav';
  361. array_unshift($vars['theme_hook_suggestions'], 'block__menu');
  362. }
  363. $nav_modules = array('superfish', 'nice_menus', 'menu_block', 'menu');
  364. if (in_array($vars['block']->module, $nav_modules)) {
  365. $vars['tag'] = 'nav';
  366. array_unshift($vars['theme_hook_suggestions'], 'block__menu');
  367. }
  368. // The menu bar region gets special treatment for the block template
  369. if ($vars['block']->region === 'menu_bar') {
  370. $vars['classes_array'][] = 'menu-wrapper';
  371. $vars['classes_array'][] = 'menu-bar-wrapper';
  372. $vars['classes_array'][] = 'clearfix';
  373. $vars['title_attributes_array']['class'][] = 'element-invisible';
  374. }
  375. // The menu bar region gets special treatment for the block template
  376. if (at_get_setting('enable_menu_toggle', $theme_name) === 1) {
  377. if (at_get_setting('menu_toggle_menu_bar', $theme_name) === 1) {
  378. if ($vars['block']->region === 'menu_bar') {
  379. $vars['classes_array'][] = 'at-menu-toggle';
  380. }
  381. }
  382. if (at_get_setting('menu_toggle_leaderboard', $theme_name) === 1 && $vars['block']->region === 'leaderboard') {
  383. $vars['classes_array'][] = 'at-menu-toggle';
  384. $vars['classes_array'][] = 'clearfix';
  385. }
  386. if (at_get_setting('menu_toggle_header', $theme_name) === 1 && $vars['block']->region === 'header') {
  387. $vars['classes_array'][] = 'at-menu-toggle';
  388. $vars['classes_array'][] = 'clearfix';
  389. }
  390. }
  391. // Add extra classes if required
  392. if (at_get_setting('extra_block_classes', $theme_name) === 1) {
  393. // Zebra
  394. $vars['classes_array'][] = $vars['block_zebra'];
  395. // Position?
  396. if ($vars['block_id'] === 1) {
  397. $vars['classes_array'][] = 'first';
  398. }
  399. if (isset($vars['block']->last_in_region)) {
  400. $vars['classes_array'][] = 'last';
  401. }
  402. // Count
  403. $vars['classes_array'][] = 'block-count-' . $vars['id'];
  404. // Region
  405. $vars['classes_array'][] = drupal_html_class('block-region-' . $vars['block']->region);
  406. // Delta
  407. $vars['classes_array'][] = drupal_html_class('block-' . $vars['block']->delta);
  408. }
  409. // Add classes to theme the horizontal block option
  410. if (at_get_setting('enable_extensions', $theme_name) === 1) {
  411. if (at_get_setting('enable_markup_overides', $theme_name) === 1) {
  412. // Change the user menu title to the user name.
  413. if (at_get_setting('user_block_user_name', $theme_name) === 1) {
  414. if ($vars['block']->module == 'system' && $vars['block']->delta == 'user-menu') {
  415. if (user_is_logged_in()) {
  416. $vars['title'] = check_plain($user->name);
  417. }
  418. }
  419. }
  420. // Horizontal block classes.
  421. if (at_get_setting('horizontal_login_block', $theme_name) === 1 && $vars['block']->module === 'user' && $vars['block']->delta === 'login') {
  422. $vars['classes_array'][] = 'lb-h';
  423. $vars['title_attributes_array']['class'][] = 'element-invisible';
  424. }
  425. if (at_get_setting('slider_login_block', $theme_name) === 1 && $vars['block']->module === 'user' && $vars['block']->delta === 'login') {
  426. $vars['classes_array'][] = 'lb-s';
  427. }
  428. }
  429. }
  430. // Give our block titles and content some additional class
  431. $vars['title_attributes_array']['class'][] = 'block-title';
  432. $vars['content_attributes_array']['class'] = array('block-content', 'content');
  433. // Support aria-describedby
  434. if ($vars['block']->subject && !empty($vars['attributes_array']['role'])) {
  435. $vars['title_attributes_array']['id'] = drupal_html_id($vars['block']->subject);
  436. $vars['attributes_array']['aria-describedby'] = $vars['title_attributes_array']['id'];
  437. }
  438. // Add Aria Roles via attributes
  439. switch ($vars['block']->module) {
  440. case 'system':
  441. switch ($vars['block']->delta) {
  442. case 'main':
  443. // Note: the "main" role goes in the page.tpl, not here.
  444. break;
  445. case 'help':
  446. case 'powered-by':
  447. $vars['attributes_array']['role'] = 'complementary';
  448. break;
  449. default:
  450. // Any other "system" block is a menu block.
  451. $vars['attributes_array']['role'] = 'navigation';
  452. break;
  453. }
  454. break;
  455. case 'menu':
  456. case 'menu_block':
  457. case 'blog':
  458. case 'book':
  459. case 'comment':
  460. case 'forum':
  461. case 'shortcut':
  462. case 'statistics':
  463. $vars['attributes_array']['role'] = 'navigation';
  464. break;
  465. case 'search':
  466. $vars['attributes_array']['role'] = 'search';
  467. break;
  468. case 'help':
  469. case 'aggregator':
  470. case 'locale':
  471. case 'poll':
  472. case 'profile':
  473. $vars['attributes_array']['role'] = 'complementary';
  474. break;
  475. case 'node':
  476. switch ($vars['block']->delta) {
  477. case 'syndicate':
  478. $vars['attributes_array']['role'] = 'complementary';
  479. break;
  480. case 'recent':
  481. $vars['attributes_array']['role'] = 'navigation';
  482. break;
  483. }
  484. break;
  485. case 'user':
  486. switch ($vars['block']->delta) {
  487. case 'login':
  488. $vars['attributes_array']['role'] = 'form';
  489. break;
  490. case 'new':
  491. case 'online':
  492. $vars['attributes_array']['role'] = 'complementary';
  493. break;
  494. }
  495. break;
  496. }
  497. }
  498. /**
  499. * Preprocess variables for panels_pane.tpl.php
  500. */
  501. function adaptivetheme_preprocess_panels_pane(&$vars) {
  502. // Top level wrapper
  503. $vars['tag'] = $vars['title'] ? 'section' : 'div';
  504. // Add the same classes as blocks
  505. if (empty($vars['title'])) {
  506. $vars['classes_array'][] = 'no-title';
  507. }
  508. $vars['classes_array'][] = 'block';
  509. // Use the attributes arrays to add classes.
  510. $vars['title_attributes_array']['class'][] = 'block-title';
  511. $vars['attributes_array']['class'] = $vars['classes_array'];
  512. $vars['content_attributes_array']['class'][] = 'block-content';
  513. }
  514. /**
  515. * Preprocess variables for field.tpl.php
  516. */
  517. function adaptivetheme_preprocess_field(&$vars) {
  518. global $theme_key;
  519. $theme_name = $theme_key;
  520. $element = $vars['element'];
  521. // Set the top level element as either <section> (if the field label is showing),
  522. // or <div> if the field label is hidden.
  523. $vars['tag'] = 'section';
  524. if (isset($vars['label_hidden']) && $vars['label_hidden'] == TRUE) {
  525. $vars['tag'] = 'div';
  526. }
  527. $vars['field_view_mode'] = '';
  528. if (isset($element['#view_mode'])) {
  529. // add a view mode class to fields
  530. $vars['classes_array'][] = 'view-mode-' . $element['#view_mode'];
  531. // Set variable for view mode, appears to be not gettable in a template
  532. $vars['field_view_mode'] = $element['#view_mode'];
  533. }
  534. // Image fields
  535. if ($element['#field_type'] === 'image') {
  536. // Set some vars for image captioning, these always need to be initialized
  537. $vars['image_caption_teaser'] = FALSE;
  538. $vars['image_caption_full'] = FALSE;
  539. // Dont run anything if extensions or image settings are disabled
  540. if (at_get_setting('enable_extensions', $theme_name) === 1) {
  541. if (at_get_setting('enable_image_settings', $theme_name) === 1) {
  542. // Reduce number of images in teaser view mode to single image
  543. if (at_get_setting('image_teaser', $theme_name) === 1) {
  544. if ($element['#view_mode'] == 'teaser') {
  545. $item = reset($vars['items']);
  546. $vars['items'] = array($item);
  547. }
  548. }
  549. // Captions
  550. if (at_get_setting('image_caption_teaser', $theme_name) === 1) {
  551. $vars['image_caption_teaser'] = TRUE;
  552. }
  553. if (at_get_setting('image_caption_full', $theme_name) === 1) {
  554. $vars['image_caption_full'] = TRUE;
  555. }
  556. }
  557. }
  558. }
  559. }
  560. /**
  561. * Preprocess variables for node.tpl.php
  562. */
  563. function adaptivetheme_preprocess_node(&$vars) {
  564. global $theme_key;
  565. $theme_name = $theme_key;
  566. // article class to attempt backwards compatibility
  567. $vars['classes_array'][] = 'article';
  568. // Extra classes if required
  569. if (at_get_setting('extra_article_classes', $theme_name) === 1) {
  570. // Zebra
  571. $vars['classes_array'][] = $vars['zebra'];
  572. // Langauge
  573. if (module_exists('translation')) {
  574. if ($vars['node']->language) {
  575. $vars['classes_array'][] = 'node-lang-' . $vars['node']->language;
  576. }
  577. }
  578. // User picture?
  579. // Should we all a check for the global settings here? SEE: https://drupal.org/node/2020687
  580. if (at_get_setting('toggle_node_user_picture', $theme_name) === 1) {
  581. if ($vars['display_submitted'] && !empty($vars['picture'])) {
  582. $vars['classes_array'][] = 'node-with-picture';
  583. }
  584. }
  585. // Class for each view mode, core assumes we only need to target teasers but neglects custom view modes or full
  586. if ($vars['view_mode'] !== 'teaser') {
  587. $vars['classes_array'][] = drupal_html_class('node-' . $vars['view_mode']);
  588. }
  589. }
  590. // Image alignment and caption classes
  591. if (at_get_setting('enable_extensions', $theme_name) === 1) {
  592. if (at_get_setting('enable_image_settings', $theme_name) === 1) {
  593. if ($vars['view_mode'] !== 'teaser') {
  594. if ($image_caption_full = at_get_setting('image_caption_full', $theme_name)) {
  595. $vars['classes_array'][] = $image_caption_full;
  596. }
  597. if ($image_alignment = at_get_setting('image_alignment', $theme_name)) {
  598. $vars['classes_array'][] = $image_alignment;
  599. }
  600. }
  601. if ($vars['view_mode'] == 'teaser') {
  602. if ($image_caption_teaser = at_get_setting('image_caption_teaser', $theme_name)) {
  603. $vars['classes_array'][] = $image_caption_teaser;
  604. }
  605. if ($image_alignment_teaser = at_get_setting('image_alignment_teaser', $theme_name)) {
  606. $vars['classes_array'][] = $image_alignment_teaser;
  607. }
  608. }
  609. }
  610. }
  611. // ARIA Role
  612. $vars['attributes_array']['role'][] = 'article';
  613. // Classes and attributes
  614. $vars['title_attributes_array']['class'][] = 'node-title';
  615. $vars['content_attributes_array']['class'][] = 'node-content';
  616. // header, submitted and links wrappers have their own attributes
  617. $vars['header_attributes_array']['class'][] = 'node-header';
  618. $vars['footer_attributes_array']['class'][] = 'submitted';
  619. if ($vars['user_picture']) {
  620. $vars['footer_attributes_array']['class'][] = 'with-user-picture';
  621. }
  622. $vars['links_attributes_array']['class'][] = 'clearfix';
  623. //
  624. // AT Core builds additional time and date variables for use in templates
  625. //
  626. // datetime stamp formatted correctly to ISO8601
  627. $vars['datetime'] = format_date($vars['created'], 'custom', 'Y-m-d\TH:i:sO'); // PHP 'c' format is not proper ISO8601!
  628. // Publication date, formatted with time element
  629. $vars['publication_date'] = '<time datetime="' . $vars['datetime'] . '" pubdate="pubdate">' . $vars['date'] . '</time>';
  630. // Last update variables
  631. $vars['datetime_updated'] = format_date($vars['node']->changed, 'custom', 'Y-m-d\TH:i:sO');
  632. $vars['custom_date_and_time'] = date('jS F, Y - g:ia', $vars['node']->changed);
  633. // Last updated formatted in time element
  634. $vars['last_update'] = '<time datetime="' . $vars['datetime_updated'] . '" pubdate="pubdate">' . $vars['custom_date_and_time'] . '</time>';
  635. // Build the submitted variable used by default in node templates
  636. if (variable_get('node_submitted_' . $vars['node']->type, TRUE)) {
  637. $vars['submitted'] = t('Submitted by !username on !datetime',
  638. array(
  639. '!username' => $vars['name'],
  640. '!datetime' => $vars['publication_date'],
  641. )
  642. );
  643. }
  644. else {
  645. $vars['submitted'] = '';
  646. }
  647. // Unpublished?
  648. $vars['unpublished'] = ''; // Initialize for backwards compatibility
  649. if (!$vars['status']) {
  650. // Use the title prefix to render the unpublished message
  651. $vars['title_prefix']['unpublished']['#markup'] = '<p class="unpublished">' . t('Unpublished') . '</p>';
  652. }
  653. // Add nofollow to Book module print/export links
  654. if (isset($vars['content']['links']['book']['#links']['book_printer'])) {
  655. $vars['content']['links']['book']['#links']['book_printer']['attributes'] = array('rel' => array('nofollow'));
  656. }
  657. }
  658. /**
  659. * Preprocess variables for comment.tpl.php
  660. */
  661. function adaptivetheme_preprocess_comment(&$vars) {
  662. global $theme_key;
  663. $theme_name = $theme_key;
  664. // Extra comment classes if required
  665. if (at_get_setting('extra_comment_classes', $theme_name) === 1) {
  666. // Zebra
  667. $vars['classes_array'][] = $vars['zebra'];
  668. // Position?
  669. if ($vars['id'] === 1) {
  670. $vars['classes_array'][] = 'first';
  671. }
  672. if ($vars['id'] === $vars['node']->comment_count) {
  673. $vars['classes_array'][] = 'last';
  674. }
  675. // Title hidden?
  676. if (at_get_setting('comments_hide_title', $theme_name) === 1) {
  677. $vars['classes_array'][] = 'comment-title-hidden';
  678. }
  679. // User picture?
  680. // Should we add a check for the global settings here? SEE: https://drupal.org/node/2020687
  681. if (at_get_setting('toggle_comment_user_picture', $theme_name) === 1) {
  682. if (!empty($vars['picture'])) {
  683. $vars['classes_array'][] = 'comment-with-picture';
  684. }
  685. }
  686. // Signature?
  687. if (!empty($vars['signature'])) {
  688. $vars['classes_array'][] = 'comment-with-signature';
  689. }
  690. }
  691. // Classes for comment title
  692. $vars['title_attributes_array']['class'][] = 'comment-title';
  693. // Title hidden?
  694. if (at_get_setting('enable_extensions', $theme_name) === 1) {
  695. if (at_get_setting('enable_markup_overides', $theme_name) === 1) {
  696. if (at_get_setting('comments_hide_title', $theme_name) === 1) {
  697. $vars['title_attributes_array']['class'][] = 'element-invisible';
  698. }
  699. }
  700. }
  701. // Classes for comment content
  702. $vars['content_attributes_array']['class'][] = 'comment-content';
  703. // header, submitted and links wrappers have their own attributes
  704. $vars['header_attributes_array']['class'][] = 'comment-header';
  705. $vars['footer_attributes_array']['class'][] = 'submitted';
  706. if ($vars['picture']) {
  707. $vars['footer_attributes_array']['class'][] = 'with-user-picture';
  708. }
  709. $vars['links_attributes_array']['class'][] = 'clearfix';
  710. // Build the submitted by, permalink, title and time elements
  711. $uri = entity_uri('comment', $vars['comment']);
  712. $uri['options'] += array('attributes' => array('rel' => 'bookmark'));
  713. $vars['title'] = l($vars['comment']->subject, $uri['path'], $uri['options']);
  714. // Don't rebuild the permalink variable if Advanced Forum is enabled
  715. if (!module_exists('advanced_forum')) {
  716. $vars['permalink'] = l(t('Permalink'), $uri['path'], $uri['options']);
  717. }
  718. $vars['created'] = '<span class="date-time">' . $vars['created'] . '</span>';
  719. $vars['datetime'] = format_date($vars['comment']->created, 'custom', 'Y-m-d\TH:i:s\Z'); // Generate the timestamp, PHP "c" format is wrong
  720. $vars['submitted'] = t('Submitted by !username on !datetime',
  721. array(
  722. '!username' => $vars['author'],
  723. '!datetime' => '<time datetime="' . $vars['datetime'] . '" pubdate="pubdate">' . $vars['created'] . '</time>',
  724. )
  725. );
  726. // Unpublished?
  727. $vars['unpublished'] = ''; // Initialize for backwards compatibility
  728. if ($vars['status'] === 'comment-unpublished') {
  729. // Use the title prefix to render the unpublished message
  730. $vars['title_prefix']['unpublished']['#markup'] = '<p class="unpublished">' . t('Unpublished') . '</p>';
  731. }
  732. }
  733. /**
  734. * Preprocess variables for the search block form.
  735. */
  736. function adaptivetheme_preprocess_search_block_form(&$vars) {
  737. // Changes the search form to use the "search" input element attribute (HTML5)
  738. // We have to replace the string because FAPI don't know what type=search is, i.e.
  739. // no way we can do this in a form alter hook.
  740. $vars['search_form'] = str_replace('type="text"', 'type="search"', $vars['search_form']);
  741. }
  742. /**
  743. * Preprocess variables for aggregator-item.tpl.php
  744. */
  745. function adaptivetheme_preprocess_aggregator_item(&$vars) {
  746. $item = $vars['item'];
  747. // We want the same highly accurate time stamp feature as nodes and comments
  748. $vars['datetime'] = format_date($item->timestamp, 'custom', 'Y-m-d\TH:i:sO');
  749. // Give our aggregator items some class
  750. $vars['classes_array'][] = 'feed-item clearfix';
  751. $vars['title_attributes_array']['class'][] = 'title feed-item-title';
  752. $vars['content_attributes_array']['class'][] = 'content feed-item-content';
  753. }
  754. /**
  755. * Preprocess variables for adaptivtheme_menubar()
  756. */
  757. function adaptivetheme_preprocess_menubar(&$vars) {
  758. global $theme_key;
  759. $theme_name = $theme_key;
  760. $type = $vars['type'];
  761. // menu bar id
  762. $vars['menubar_id'] = $type . '-menu-bar';
  763. // Add classes to the main wrapper
  764. $vars['classes_array'] = array('nav', 'clearfix');
  765. // Classes for toggle menus
  766. if (at_get_setting('enable_menu_toggle', $theme_name) === 1) {
  767. if (at_get_setting('menu_toggle_main_menu', $theme_name) === 1 && $type === 'primary') {
  768. $vars['classes_array'][] = 'at-menu-toggle';
  769. }
  770. if (at_get_setting('menu_toggle_secondary_menu', $theme_name) === 1 && $type === 'secondary') {
  771. $vars['classes_array'][] = 'at-menu-toggle';
  772. }
  773. }
  774. // Add classes to the inner wrapper
  775. $vars['content_attributes_array']['class'][] = $type . '-menu-wrapper';
  776. $vars['content_attributes_array']['class'][] = 'menu-wrapper';
  777. $vars['content_attributes_array']['class'][] = 'clearfix';
  778. // Aria
  779. $vars['content_attributes_array']['role'][] = 'navigation';
  780. $vars['content_attributes_array']['aria-labelledby'][] = $type . '-menu';
  781. // Add suggstions per menu type
  782. $vars['theme_hook_suggestions'][] = 'menubar__' . $type;
  783. }
  784. /**
  785. * Preprocess variables for the username.
  786. */
  787. function adaptivetheme_preprocess_username(&$vars) {
  788. global $theme_key;
  789. $theme_name = $theme_key;
  790. // Add rel=author for SEO and supporting search engines
  791. if (at_get_setting('enable_extensions', $theme_name) === 1) {
  792. if (at_get_setting('enable_markup_overides', $theme_name) === 1) {
  793. if (at_get_setting('rel_author', $theme_name) === 1) {
  794. if (isset($vars['link_path'])) {
  795. $vars['link_attributes']['rel'][] = 'author';
  796. }
  797. else {
  798. $vars['attributes_array']['rel'][] = 'author';
  799. }
  800. }
  801. }
  802. }
  803. }
  804. /**
  805. * Preprocess variables for theme_image()
  806. */
  807. function adaptivetheme_preprocess_image(&$vars) {
  808. // Initialize the variable if there isn't one
  809. if (!isset($vars['attributes']['class'])) {
  810. $vars['attributes']['class'] = array();
  811. }
  812. // Some modules set the style name even when its empty, such as User Badges
  813. // module, so initialize the class name variable with a "none" class
  814. $style_name_class = 'none';
  815. // If there really is a style name use it for the class
  816. if (isset($vars['style_name']) && !empty($vars['style_name'])) {
  817. $style_name_class = drupal_html_class($vars['style_name']);
  818. }
  819. // Check if the class attributes is an array. If we don't do this check and
  820. // the class attribute is string it can cause a fatal error.
  821. // See http://drupal.org/node/1722146 for an example
  822. if (is_array($vars['attributes']['class'])) {
  823. $vars['attributes']['class'][] = 'image-style-' . $style_name_class;
  824. }
  825. }
  826. /**
  827. * Preprocess variables for maintenance-page.tpl.php
  828. */
  829. function adaptivetheme_preprocess_maintenance_page(&$vars) {
  830. global $theme_key;
  831. $theme_name = $theme_key;
  832. // Get the path to the directory where our CSS files are saved
  833. $path = variable_get('theme_' . $theme_name . '_files_directory');
  834. // Load Layout
  835. at_load_layout_css($path, $theme_name);
  836. // Load Responsive Styles.
  837. if (at_get_setting('disable_responsive_styles', $theme_name) === 0) {
  838. at_load_responsive_css($path, $theme_name);
  839. }
  840. // Load fonts and/or Custom CSS
  841. if (at_get_setting('enable_extensions', $theme_name) === 1) {
  842. // Fonts CSS
  843. if (at_get_setting('enable_font_settings', $theme_name) === 1) {
  844. at_load_fonts($path, $theme_name);
  845. }
  846. // Custom CSS
  847. if (at_get_setting('enable_custom_css', $theme_name) === 1) {
  848. at_load_custom_css($path, $theme_name);
  849. }
  850. // Load Extension Settings CSS
  851. at_load_extensions_css($theme_name);
  852. }
  853. // Load polyfills
  854. $vars['polyfills'] = at_load_polyfills($theme_name, $vars);
  855. // Load the colors stylesheet for the active color scheme. This only works
  856. // for maintenance mode, when there is a database error the default color
  857. // scheme will be used.
  858. if (module_exists('color')) {
  859. $color_file = variable_get('color_' . $theme_name . '_stylesheets', NULL);
  860. if (file_exists($color_file[0])) {
  861. drupal_add_css($color_file[0], array(
  862. 'group' => CSS_THEME,
  863. 'weight' => 99,
  864. )
  865. );
  866. }
  867. }
  868. // Attribution variable used in admin theme and some others
  869. $vars['attribution'] = '';
  870. if (at_get_setting('attribution_toggle', $theme_name) === 1) {
  871. $vars['attribution'] = "<small class=\"attribution\">Premium Drupal Theme by <a href=\"http://adaptivethemes.com\">Adaptivethemes.com</a></small>";
  872. }
  873. }
  874. /**
  875. * Preprocess variables for user-profile.tpl.php
  876. */
  877. function adaptivetheme_preprocess_user_profile(&$vars) {
  878. $vars['classes_array'][] = 'profile';
  879. }
  880. /**
  881. * Preprocess variables for breadcrumbs
  882. */
  883. function adaptivetheme_preprocess_breadcrumb(&$vars) {
  884. // Add Google rich snippets to breadcrumbs using RDFa
  885. if (module_exists('rdf')) {
  886. $snippet_url = ' rel="v:url" ';
  887. $snippet_title = ' property="v:title" ';
  888. foreach ($vars['breadcrumb'] as $key => $breadcrumb) {
  889. preg_match_all('/<([\w]+)[^>]*>.*?<\/\\1>/', $breadcrumb, $matches);
  890. if (count($matches[0]) > 0) {
  891. $snippet = $snippet_title;
  892. if ($matches[1][count($matches[1]) - 1] == 'a') {
  893. $snippet = $snippet_url . $snippet_title;
  894. }
  895. $breadcrumb = substr_replace($breadcrumb, $snippet, strlen($matches[1][count($matches[1]) - 1]) + 1, 0);
  896. }
  897. else {
  898. $breadcrumb = '<span ' . $snippet_title . '>' . $breadcrumb . '</span>';
  899. }
  900. $vars['breadcrumb'][$key] = '<span typeof="v:Breadcrumb">' . $breadcrumb . '</span>';
  901. }
  902. }
  903. }