template.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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' => FALSE));
  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' => FALSE));
  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' => FALSE));
  32. // Add theme name to body class.
  33. $vars['classes_array'][] = 'adminimal-theme';
  34. // Add icons to the admin configuration page.
  35. if (theme_get_setting('display_icons_config')) {
  36. drupal_add_css($adminimal_path . '/css/icons-config.css', array('group' => CSS_THEME, 'weight' => 10, 'preprocess' => FALSE));
  37. }
  38. // Define Default media queries.
  39. $media_query_mobile = 'only screen and (max-width: 480px)';
  40. $media_query_tablet = 'only screen and (min-width : 481px) and (max-width : 1024px)';
  41. // Get custom media queries if set.
  42. if (theme_get_setting('use_custom_media_queries')) {
  43. $media_query_mobile = theme_get_setting('media_query_mobile');
  44. $media_query_tablet = theme_get_setting('media_query_tablet');
  45. }
  46. // Add responsive styles.
  47. drupal_add_css($adminimal_path . '/css/mobile.css', array('group' => CSS_THEME, 'media' => $media_query_mobile, 'weight' => 1000));
  48. drupal_add_css($adminimal_path . '/css/tablet.css', array('group' => CSS_THEME, 'media' => $media_query_tablet, 'weight' => 1000));
  49. // Add custom CSS.
  50. $custom_css_path = 'public://adminimal-custom.css';
  51. if (theme_get_setting('custom_css') && file_exists($custom_css_path)) {
  52. drupal_add_css($custom_css_path, array('group' => CSS_THEME, 'weight' => 9999, 'preprocess' => FALSE));
  53. }
  54. // Fix the viewport and zooming in mobile devices.
  55. $viewport = array(
  56. '#tag' => 'meta',
  57. '#attributes' => array(
  58. 'name' => 'viewport',
  59. 'content' => 'width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no, initial-scale=1',
  60. ),
  61. );
  62. drupal_add_html_head($viewport, 'viewport');
  63. }
  64. /**
  65. * Override or insert variables into the page template.
  66. */
  67. function adminimal_preprocess_page(&$vars) {
  68. $vars['primary_local_tasks'] = $vars['tabs'];
  69. unset($vars['primary_local_tasks']['#secondary']);
  70. $vars['secondary_local_tasks'] = array(
  71. '#theme' => 'menu_local_tasks',
  72. '#secondary' => $vars['tabs']['#secondary'],
  73. );
  74. }
  75. /**
  76. * Display the list of available node types for node creation.
  77. */
  78. function adminimal_node_add_list($variables) {
  79. $content = $variables['content'];
  80. $output = '';
  81. if ($content) {
  82. $output = '<ul class="admin-list">';
  83. foreach ($content as $item) {
  84. $output .= '<li class="clearfix">';
  85. $output .= '<span class="label">' . l($item['title'], $item['href'], $item['localized_options']) . '</span>';
  86. $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
  87. $output .= '</li>';
  88. }
  89. $output .= '</ul>';
  90. }
  91. else {
  92. $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>';
  93. }
  94. return $output;
  95. }
  96. /**
  97. * Implements theme_adminimal_block_content().
  98. *
  99. * Use unordered list markup in both compact and extended mode.
  100. */
  101. function adminimal_adminimal_block_content($variables) {
  102. $content = $variables['content'];
  103. $output = '';
  104. if (!empty($content)) {
  105. $output = system_adminimal_compact_mode() ? '<ul class="admin-list compact">' : '<ul class="admin-list">';
  106. foreach ($content as $item) {
  107. $output .= '<li class="leaf">';
  108. $output .= l($item['title'], $item['href'], $item['localized_options']);
  109. if (isset($item['description']) && !system_adminimal_compact_mode()) {
  110. $output .= '<div class="description">' . filter_xss_admin($item['description']) . '</div>';
  111. }
  112. $output .= '</li>';
  113. }
  114. $output .= '</ul>';
  115. }
  116. return $output;
  117. }
  118. /**
  119. * Implements theme_tablesort_indicator().
  120. *
  121. * Use our own image versions, so they show up as black and not gray on gray.
  122. */
  123. function adminimal_tablesort_indicator($variables) {
  124. $style = $variables['style'];
  125. $theme_path = drupal_get_path('theme', 'adminimal');
  126. if ($style == 'asc') {
  127. return theme('image', array('path' => $theme_path . '/images/arrow-asc.png', 'alt' => t('sort ascending'), 'width' => 13, 'height' => 13, 'title' => t('sort ascending')));
  128. }
  129. else {
  130. return theme('image', array('path' => $theme_path . '/images/arrow-desc.png', 'alt' => t('sort descending'), 'width' => 13, 'height' => 13, 'title' => t('sort descending')));
  131. }
  132. }
  133. /**
  134. * Implements hook_css_alter().
  135. */
  136. function adminimal_css_alter(&$css) {
  137. // Use Seven's vertical tabs style instead of the default one.
  138. if (isset($css['misc/vertical-tabs.css'])) {
  139. $css['misc/vertical-tabs.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs.css';
  140. }
  141. if (isset($css['misc/vertical-tabs-rtl.css'])) {
  142. $css['misc/vertical-tabs-rtl.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/vertical-tabs-rtl.css';
  143. }
  144. // Use Seven's jQuery UI theme style instead of the default one.
  145. if (isset($css['misc/ui/jquery.ui.theme.css'])) {
  146. $css['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('theme', 'adminimal') . '/css/jquery.ui.theme.css';
  147. }
  148. }
  149. /**
  150. * Implements theme_admin_block().
  151. * Adding classes to the administration blocks see issue #1869690.
  152. */
  153. function adminimal_admin_block($variables) {
  154. $block = $variables['block'];
  155. $output = '';
  156. // Don't display the block if it has no content to display.
  157. if (empty($block['show'])) {
  158. return $output;
  159. }
  160. if (!empty($block['path'])) {
  161. $output .= '<div class="admin-panel ' . check_plain(str_replace("/", " ", $block['path'])) . ' ">';
  162. }
  163. elseif (!empty($block['title'])) {
  164. $output .= '<div class="admin-panel ' . check_plain(strtolower($block['title'])) . '">';
  165. }
  166. else {
  167. $output .= '<div class="admin-panel">';
  168. }
  169. if (!empty($block['title'])) {
  170. $output .= '<h3 class="title">' . $block['title'] . '</h3>';
  171. }
  172. if (!empty($block['content'])) {
  173. $output .= '<div class="body">' . $block['content'] . '</div>';
  174. }
  175. else {
  176. $output .= '<div class="description">' . $block['description'] . '</div>';
  177. }
  178. $output .= '</div>';
  179. return $output;
  180. }
  181. /**
  182. * Implements theme_admin_block_content().
  183. * Adding classes to the administration blocks see issue #1869690.
  184. */
  185. function adminimal_admin_block_content($variables) {
  186. $content = $variables['content'];
  187. $output = '';
  188. if (!empty($content)) {
  189. $class = 'admin-list';
  190. if ($compact = system_admin_compact_mode()) {
  191. $class .= ' compact';
  192. }
  193. $output .= '<dl class="' . $class . '">';
  194. foreach ($content as $item) {
  195. if (!isset($item['path'])) {
  196. $item['path']='';
  197. }
  198. $output .= '<div class="admin-block-item ' . check_plain(str_replace("/", "-", $item['path'])) . '"><dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
  199. if (!$compact && isset($item['description'])) {
  200. $output .= '<dd class="description">' . filter_xss_admin($item['description']) . '</dd>';
  201. }
  202. $output .= '</div>';
  203. }
  204. $output .= '</dl>';
  205. }
  206. return $output;
  207. }
  208. /**
  209. * Implements theme_table().
  210. */
  211. function adminimal_table($variables) {
  212. $header = $variables['header'];
  213. $rows = $variables['rows'];
  214. $attributes = $variables['attributes'];
  215. $caption = $variables['caption'];
  216. $colgroups = $variables['colgroups'];
  217. $sticky = $variables['sticky'];
  218. $empty = $variables['empty'];
  219. // Add sticky headers, if applicable.
  220. if (count($header) && $sticky) {
  221. drupal_add_js('misc/tableheader.js');
  222. // Add 'sticky-enabled' class to the table to identify it for JS.
  223. // This is needed to target tables constructed by this function.
  224. $attributes['class'][] = 'sticky-enabled';
  225. }
  226. $output = '<div class="overflow-fix">';
  227. $output .= '<table' . drupal_attributes($attributes) . ">\n";
  228. if (isset($caption)) {
  229. $output .= '<caption>' . $caption . "</caption>\n";
  230. }
  231. // Format the table columns:
  232. if (count($colgroups)) {
  233. foreach ($colgroups as $number => $colgroup) {
  234. $attributes = array();
  235. // Check if we're dealing with a simple or complex column
  236. if (isset($colgroup['data'])) {
  237. foreach ($colgroup as $key => $value) {
  238. if ($key == 'data') {
  239. $cols = $value;
  240. }
  241. else {
  242. $attributes[$key] = $value;
  243. }
  244. }
  245. }
  246. else {
  247. $cols = $colgroup;
  248. }
  249. // Build colgroup
  250. if (is_array($cols) && count($cols)) {
  251. $output .= ' <colgroup' . drupal_attributes($attributes) . '>';
  252. $i = 0;
  253. foreach ($cols as $col) {
  254. $output .= ' <col' . drupal_attributes($col) . ' />';
  255. }
  256. $output .= " </colgroup>\n";
  257. }
  258. else {
  259. $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n";
  260. }
  261. }
  262. }
  263. // Add the 'empty' row message if available.
  264. if (!count($rows) && $empty) {
  265. $header_count = 0;
  266. foreach ($header as $header_cell) {
  267. if (is_array($header_cell)) {
  268. $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
  269. }
  270. else {
  271. ++$header_count;
  272. }
  273. }
  274. $rows[] = array(array(
  275. 'data' => $empty,
  276. 'colspan' => $header_count,
  277. 'class' => array('empty', 'message'),
  278. ));
  279. }
  280. // Format the table header:
  281. if (count($header)) {
  282. $ts = tablesort_init($header);
  283. // HTML requires that the thead tag has tr tags in it followed by tbody
  284. // tags. Using ternary operator to check and see if we have any rows.
  285. $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
  286. foreach ($header as $cell) {
  287. $cell = tablesort_header($cell, $header, $ts);
  288. $output .= _theme_table_cell($cell, TRUE);
  289. }
  290. // Using ternary operator to close the tags based on whether or not there are rows
  291. $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
  292. }
  293. else {
  294. $ts = array();
  295. }
  296. // Format the table rows:
  297. if (count($rows)) {
  298. $output .= "<tbody>\n";
  299. $flip = array(
  300. 'even' => 'odd',
  301. 'odd' => 'even',
  302. );
  303. $class = 'even';
  304. foreach ($rows as $number => $row) {
  305. // Check if we're dealing with a simple or complex row
  306. if (isset($row['data'])) {
  307. $cells = $row['data'];
  308. $no_striping = isset($row['no_striping']) ? $row['no_striping'] : FALSE;
  309. // Set the attributes array and exclude 'data' and 'no_striping'.
  310. $attributes = $row;
  311. unset($attributes['data']);
  312. unset($attributes['no_striping']);
  313. }
  314. else {
  315. $cells = $row;
  316. $attributes = array();
  317. $no_striping = FALSE;
  318. }
  319. if (count($cells)) {
  320. // Add odd/even class
  321. if (!$no_striping) {
  322. $class = $flip[$class];
  323. $attributes['class'][] = $class;
  324. }
  325. // Build row
  326. $output .= ' <tr' . drupal_attributes($attributes) . '>';
  327. $i = 0;
  328. foreach ($cells as $cell) {
  329. $cell = tablesort_cell($cell, $header, $ts, $i++);
  330. $output .= _theme_table_cell($cell);
  331. }
  332. $output .= " </tr>\n";
  333. }
  334. }
  335. $output .= "</tbody>\n";
  336. }
  337. $output .= "</table>\n";
  338. $output .= "</div>\n";
  339. return $output;
  340. }