template.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the main theme functions hooks and overrides.
  5. */
  6. /**
  7. * Override or insert variables into the maintenance page template.
  8. */
  9. function adminimal_preprocess_maintenance_page(&$vars) {
  10. // While markup for normal pages is split into page.tpl.php and html.tpl.php,
  11. // the markup for the maintenance page is all in the single
  12. // maintenance-page.tpl.php template. So, to have what's done in
  13. // adminimal_preprocess_html() also happen on the maintenance page, it has to be
  14. // called here.
  15. adminimal_preprocess_html($vars);
  16. }
  17. /**
  18. * Override or insert variables into the html template.
  19. */
  20. function adminimal_preprocess_html(&$vars) {
  21. // Get adminimal folder path.
  22. $adminimal_path = drupal_get_path('theme', 'adminimal');
  23. // Add default styles.
  24. drupal_add_css($adminimal_path . '/css/reset.css', array('group' => CSS_THEME, 'media' => 'all', 'weight' => -999));
  25. drupal_add_css($adminimal_path . '/css/style.css', array('group' => CSS_THEME, 'media' => 'all', 'weight' => 1));
  26. // Add conditional CSS for IE8 and below.
  27. drupal_add_css($adminimal_path . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE), 'weight' => 999, 'preprocess' => TRUE));
  28. // Add conditional CSS for IE7 and below.
  29. drupal_add_css($adminimal_path . '/css/ie7.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE), 'weight' => 999, 'preprocess' => TRUE));
  30. // Add conditional CSS for IE6.
  31. drupal_add_css($adminimal_path . '/css/ie6.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 6', '!IE' => FALSE), 'weight' => 999, 'preprocess' => TRUE));
  32. //Add Homebox module support
  33. if (module_exists('homebox')) {
  34. drupal_add_css($adminimal_path . '/css/homebox_custom.css', array('group' => CSS_THEME, 'media' => 'all', 'weight' => 1));
  35. }
  36. // Add theme name to body class.
  37. $vars['classes_array'][] = 'adminimal-theme';
  38. // Style checkbox and radio buttons in Webkit Browsers.
  39. if (theme_get_setting('style_checkboxes')) {
  40. $vars['classes_array'][] = 'style-checkboxes';
  41. }
  42. // Disable rounded buttons setting.
  43. if (!theme_get_setting('rounded_buttons')) {
  44. $vars['classes_array'][] = 'no-rounded-buttons';
  45. }
  46. // Enable sticky action buttons.
  47. if (theme_get_setting('sticky_actions')) {
  48. $vars['classes_array'][] = 'sticky-actions';
  49. }
  50. // Add icons to the admin configuration page.
  51. if (theme_get_setting('display_icons_config')) {
  52. drupal_add_css($adminimal_path . '/css/icons-config.css', array('group' => CSS_THEME, 'weight' => 10, 'preprocess' => TRUE));
  53. }
  54. // Add icons to the admin configuration page.
  55. if (theme_get_setting('avoid_custom_font')) {
  56. drupal_add_css($adminimal_path . '/css/avoid_custom_font.css', array('group' => CSS_THEME, 'weight' => 9000, 'preprocess' => TRUE));
  57. }
  58. // Load CKEditor styles if enabled in settings.
  59. if (theme_get_setting('adminimal_ckeditor')) {
  60. drupal_add_css($adminimal_path . '/css/ckeditor-adminimal.css', array('group' => CSS_THEME, 'media' => 'all', 'weight' => 2));
  61. }
  62. // Define Default media queries.
  63. $media_query_mobile = 'only screen and (max-width: 480px)';
  64. $media_query_tablet = 'only screen and (min-width : 481px) and (max-width : 1024px)';
  65. // Get custom media queries if set.
  66. if (theme_get_setting('use_custom_media_queries')) {
  67. $media_query_mobile = theme_get_setting('media_query_mobile');
  68. $media_query_tablet = theme_get_setting('media_query_tablet');
  69. }
  70. // Load custom Adminimal skin.
  71. $adminimal_skin = theme_get_setting('adminimal_theme_skin');
  72. if ((!is_null($adminimal_skin))) {
  73. drupal_add_css($adminimal_path . '/skins/' . $adminimal_skin . '/' . $adminimal_skin . '.css', array('group' => CSS_THEME, 'weight' => 900, 'preprocess' => TRUE));
  74. // Add conditional CSS for Mac OS X.
  75. drupal_add_css($adminimal_path . '/skins/' . $adminimal_skin . '/mac_os_x.css', array('group' => CSS_THEME, 'weight' => 950, 'preprocess' => TRUE));
  76. drupal_add_js($adminimal_path . '/skins/' . $adminimal_skin . '/' . $adminimal_skin . '.js');
  77. $vars['classes_array'][] = 'adminimal-skin-' . $adminimal_skin ;
  78. }
  79. else {
  80. drupal_add_css($adminimal_path . '/skins/default/default.css', array('group' => CSS_THEME, 'weight' => 900, 'preprocess' => TRUE));
  81. // Add conditional CSS for Mac OS X.
  82. drupal_add_css($adminimal_path . '/skins/default/mac_os_x.css', array('group' => CSS_THEME, 'weight' => 950, 'preprocess' => TRUE));
  83. drupal_add_js($adminimal_path . '/skins/default/default.js');
  84. $vars['classes_array'][] = 'adminimal-skin-default' ;
  85. }
  86. // Add responsive styles.
  87. drupal_add_css($adminimal_path . '/css/mobile.css', array('group' => CSS_THEME, 'media' => $media_query_mobile, 'weight' => 1000));
  88. drupal_add_css($adminimal_path . '/css/tablet.css', array('group' => CSS_THEME, 'media' => $media_query_tablet, 'weight' => 1000));
  89. // Add custom CSS.
  90. $custom_css_path = 'public://adminimal-custom.css';
  91. if (theme_get_setting('custom_css') && file_exists($custom_css_path)) {
  92. drupal_add_css($custom_css_path, array('group' => CSS_THEME, 'weight' => 9999, 'preprocess' => TRUE));
  93. }
  94. // Fix the viewport and zooming in mobile devices.
  95. $viewport = array(
  96. '#tag' => 'meta',
  97. '#attributes' => array(
  98. 'name' => 'viewport',
  99. 'content' => 'width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no, initial-scale=1',
  100. ),
  101. );
  102. drupal_add_html_head($viewport, 'viewport');
  103. // Remove the no-sidebars class which is always added by core. Core assumes
  104. // the sidebar regions are called sidebar_first and sidebar_second, which
  105. // is not the case in this theme.
  106. $key = array_search('no-sidebars', $vars['classes_array']);
  107. if ($key !== FALSE) {
  108. unset($vars['classes_array'][$key]);
  109. }
  110. // Add information about the number of sidebars.
  111. if (!empty($vars['page']['sidebar_left']) && !empty($vars['page']['sidebar_right'])) {
  112. $vars['classes_array'][] = 'two-sidebars';
  113. }
  114. elseif (!empty($vars['page']['sidebar_left'])) {
  115. $vars['classes_array'][] = 'one-sidebar sidebar-left';
  116. }
  117. elseif (!empty($vars['page']['sidebar_right'])) {
  118. $vars['classes_array'][] = 'one-sidebar sidebar-right';
  119. }
  120. else {
  121. $vars['classes_array'][] = 'no-sidebars';
  122. }
  123. }
  124. /**
  125. * Override or insert variables into the page template.
  126. */
  127. function adminimal_preprocess_page(&$vars) {
  128. $vars['primary_local_tasks'] = $vars['tabs'];
  129. unset($vars['primary_local_tasks']['#secondary']);
  130. $vars['secondary_local_tasks'] = array(
  131. '#theme' => 'menu_local_tasks',
  132. '#secondary' => $vars['tabs']['#secondary'],
  133. );
  134. unset($vars['page']['hidden']);
  135. }
  136. /**
  137. * Display the list of available node types for node creation.
  138. */
  139. function adminimal_node_add_list($variables) {
  140. $content = $variables['content'];
  141. $output = '';
  142. if ($content) {
  143. $output = '<ul class="admin-list">';
  144. foreach ($content as $item) {
  145. $output .= '<li class="clearfix">';
  146. $output .= '<span class="label">' . l($item['title'], $item['href'], $item['localized_options']) . '</span>';
  147. $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
  148. $output .= '</li>';
  149. }
  150. $output .= '</ul>';
  151. }
  152. else {
  153. $output = '<p>' . t('You have not created any content types yet. Go to the <a href="@create-content">content type creation page</a> to add a new content type.', array('@create-content' => url('admin/structure/types/add'))) . '</p>';
  154. }
  155. return $output;
  156. }
  157. /**
  158. * Implements theme_adminimal_block_content().
  159. *
  160. * Use unordered list markup in both compact and extended mode.
  161. */
  162. function adminimal_adminimal_block_content($variables) {
  163. $content = $variables['content'];
  164. $output = '';
  165. if (!empty($content)) {
  166. $output = system_adminimal_compact_mode() ? '<ul class="admin-list compact">' : '<ul class="admin-list">';
  167. foreach ($content as $item) {
  168. $output .= '<li class="leaf">';
  169. $output .= l($item['title'], $item['href'], $item['localized_options']);
  170. if (isset($item['description']) && !system_adminimal_compact_mode()) {
  171. $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
  172. }
  173. $output .= '</li>';
  174. }
  175. $output .= '</ul>';
  176. }
  177. return $output;
  178. }
  179. /**
  180. * Implements theme_tablesort_indicator().
  181. *
  182. * Use our own image versions, so they show up as black and not gray on gray.
  183. */
  184. function adminimal_tablesort_indicator($variables) {
  185. $style = $variables['style'];
  186. $theme_path = drupal_get_path('theme', 'adminimal');
  187. if ($style == 'asc') {
  188. return theme('image', array('path' => $theme_path . '/images/arrow-asc.png', 'alt' => t('sort ascending'), 'width' => 13, 'height' => 13, 'title' => t('sort ascending')));
  189. }
  190. else {
  191. return theme('image', array('path' => $theme_path . '/images/arrow-desc.png', 'alt' => t('sort descending'), 'width' => 13, 'height' => 13, 'title' => t('sort descending')));
  192. }
  193. }
  194. /**
  195. * Implements hook_css_alter().
  196. */
  197. function adminimal_css_alter(&$css) {
  198. // Use Seven's vertical tabs style instead of the default one.
  199. if (isset($css['misc/vertical-tabs.css'])) {
  200. $css['misc/vertical-tabs.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs.css';
  201. }
  202. if (isset($css['misc/vertical-tabs-rtl.css'])) {
  203. $css['misc/vertical-tabs-rtl.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs-rtl.css';
  204. }
  205. // Use Seven's jQuery UI theme style instead of the default one.
  206. if (isset($css['misc/ui/jquery.ui.theme.css'])) {
  207. $css['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/jquery.ui.theme.css';
  208. }
  209. }
  210. /**
  211. * Implements hook_js_alter().
  212. */
  213. function adminimal_js_alter(&$javascript) {
  214. // Fix module filter available updates page.
  215. if (isset($javascript[drupal_get_path('module','module_filter').'/js/update_status.js'])) {
  216. $javascript[drupal_get_path('module','module_filter').'/js/update_status.js']['data'] = drupal_get_path('theme', 'adminimal') . '/js/update_status.js';
  217. }
  218. }
  219. /**
  220. * Implements theme_admin_block().
  221. * Adding classes to the administration blocks see issue #1869690.
  222. */
  223. function adminimal_admin_block($variables) {
  224. $block = $variables['block'];
  225. $output = '';
  226. // Don't display the block if it has no content to display.
  227. if (empty($block['show'])) {
  228. return $output;
  229. }
  230. if (!empty($block['path'])) {
  231. $output .= '<div class="admin-panel ' . check_plain(str_replace("/", " ", $block['path'])) . ' ">';
  232. }
  233. elseif (!empty($block['title'])) {
  234. $output .= '<div class="admin-panel ' . check_plain(strtolower($block['title'])) . '">';
  235. }
  236. else {
  237. $output .= '<div class="admin-panel">';
  238. }
  239. if (!empty($block['title'])) {
  240. $output .= '<h3 class="title">' . $block['title'] . '</h3>';
  241. }
  242. if (!empty($block['content'])) {
  243. $output .= '<div class="body">' . $block['content'] . '</div>';
  244. }
  245. else {
  246. $output .= '<div class="description">' . $block['description'] . '</div>';
  247. }
  248. $output .= '</div>';
  249. return $output;
  250. }
  251. /**
  252. * Implements theme_admin_block_content().
  253. * Adding classes to the administration blocks see issue #1869690.
  254. */
  255. function adminimal_admin_block_content($variables) {
  256. $content = $variables['content'];
  257. $output = '';
  258. if (!empty($content)) {
  259. $class = 'admin-list';
  260. if ($compact = system_admin_compact_mode()) {
  261. $class .= ' compact';
  262. }
  263. $output .= '<dl class="' . $class . '">';
  264. foreach ($content as $item) {
  265. if (!isset($item['path'])) {
  266. $item['path']='';
  267. }
  268. $output .= '<div class="admin-block-item ' . check_plain(str_replace("/", "-", $item['path'])) . '"><dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
  269. if (!$compact && isset($item['description'])) {
  270. $output .= '<dd class="description">' . filter_xss_admin($item['description']) . '</dd>';
  271. }
  272. $output .= '</div>';
  273. }
  274. $output .= '</dl>';
  275. }
  276. return $output;
  277. }
  278. /**
  279. * Implements theme_table().
  280. */
  281. function adminimal_table($variables) {
  282. $header = $variables['header'];
  283. $rows = $variables['rows'];
  284. $attributes = $variables['attributes'];
  285. $caption = $variables['caption'];
  286. $colgroups = $variables['colgroups'];
  287. $sticky = $variables['sticky'];
  288. $empty = $variables['empty'];
  289. // Add sticky headers, if applicable.
  290. if (count($header) && $sticky) {
  291. drupal_add_js('misc/tableheader.js');
  292. // Add 'sticky-enabled' class to the table to identify it for JS.
  293. // This is needed to target tables constructed by this function.
  294. $attributes['class'][] = 'sticky-enabled';
  295. }
  296. $output = '<div class="overflow-fix">';
  297. $output .= '<table' . drupal_attributes($attributes) . ">\n";
  298. if (isset($caption)) {
  299. $output .= '<caption>' . $caption . "</caption>\n";
  300. }
  301. // Format the table columns:
  302. if (count($colgroups)) {
  303. foreach ($colgroups as $number => $colgroup) {
  304. $attributes = array();
  305. // Check if we're dealing with a simple or complex column
  306. if (isset($colgroup['data'])) {
  307. foreach ($colgroup as $key => $value) {
  308. if ($key == 'data') {
  309. $cols = $value;
  310. }
  311. else {
  312. $attributes[$key] = $value;
  313. }
  314. }
  315. }
  316. else {
  317. $cols = $colgroup;
  318. }
  319. // Build colgroup
  320. if (is_array($cols) && count($cols)) {
  321. $output .= ' <colgroup' . drupal_attributes($attributes) . '>';
  322. $i = 0;
  323. foreach ($cols as $col) {
  324. $output .= ' <col' . drupal_attributes($col) . ' />';
  325. }
  326. $output .= " </colgroup>\n";
  327. }
  328. else {
  329. $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n";
  330. }
  331. }
  332. }
  333. // Add the 'empty' row message if available.
  334. if (!count($rows) && $empty) {
  335. $header_count = 0;
  336. foreach ($header as $header_cell) {
  337. if (is_array($header_cell)) {
  338. $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
  339. }
  340. else {
  341. ++$header_count;
  342. }
  343. }
  344. $rows[] = array(array(
  345. 'data' => $empty,
  346. 'colspan' => $header_count,
  347. 'class' => array('empty', 'message'),
  348. ));
  349. }
  350. // Format the table header:
  351. if (count($header)) {
  352. $ts = tablesort_init($header);
  353. // HTML requires that the thead tag has tr tags in it followed by tbody
  354. // tags. Using ternary operator to check and see if we have any rows.
  355. $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
  356. foreach ($header as $cell) {
  357. $cell = tablesort_header($cell, $header, $ts);
  358. $output .= _theme_table_cell($cell, TRUE);
  359. }
  360. // Using ternary operator to close the tags based on whether or not there are rows
  361. $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
  362. }
  363. else {
  364. $ts = array();
  365. }
  366. // Format the table rows:
  367. if (count($rows)) {
  368. $output .= "<tbody>\n";
  369. $flip = array(
  370. 'even' => 'odd',
  371. 'odd' => 'even',
  372. );
  373. $class = 'even';
  374. foreach ($rows as $number => $row) {
  375. // Check if we're dealing with a simple or complex row
  376. if (isset($row['data'])) {
  377. $cells = $row['data'];
  378. $no_striping = isset($row['no_striping']) ? $row['no_striping'] : FALSE;
  379. // Set the attributes array and exclude 'data' and 'no_striping'.
  380. $attributes = $row;
  381. unset($attributes['data']);
  382. unset($attributes['no_striping']);
  383. }
  384. else {
  385. $cells = $row;
  386. $attributes = array();
  387. $no_striping = FALSE;
  388. }
  389. if (count($cells)) {
  390. // Add odd/even class
  391. if (!$no_striping) {
  392. $class = $flip[$class];
  393. $attributes['class'][] = $class;
  394. }
  395. // Build row
  396. $output .= ' <tr' . drupal_attributes($attributes) . '>';
  397. $i = 0;
  398. foreach ($cells as $cell) {
  399. $cell = tablesort_cell($cell, $header, $ts, $i++);
  400. $output .= _theme_table_cell($cell);
  401. }
  402. $output .= " </tr>\n";
  403. }
  404. }
  405. $output .= "</tbody>\n";
  406. }
  407. $output .= "</table>\n";
  408. $output .= "</div>\n";
  409. return $output;
  410. }