PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/nicolasnm/divingbook
PHP | 398 lines | 215 code | 44 blank | 139 comment | 45 complexity | 1bb73dbf3cf548336e656e5f76359a4a MD5 | raw file
  1. <?php
  2. /**
  3. * @file
  4. * template.php for gamma theme
  5. */
  6. /*
  7. * Add any conditional stylesheets you will need for this sub-theme.
  8. *
  9. * To add stylesheets that ALWAYS need to be included, you should add them to
  10. * your .info file instead. Only use this section if you are including
  11. * stylesheets based on certain conditions.
  12. */
  13. /* -- Delete this line if you want to use and modify this code
  14. // Example: optionally add a fixed width CSS file.
  15. if (theme_get_setting('gamma_fixed')) {
  16. drupal_add_css(path_to_theme() . '/layout-fixed.css', 'theme', 'all');
  17. }
  18. // */
  19. /**
  20. * Automatically rebuild the theme registry.
  21. */
  22. /**
  23. * Implements hook_theme().
  24. */
  25. function gamma_theme(&$existing, $type, $theme, $path) {
  26. $hooks = omega_theme($existing, $type, $theme, $path);
  27. // Add your theme hooks like this:
  28. /*
  29. $hooks['hook_name_here'] = array( // Details go here );
  30. */
  31. // @TODO: Needs detailed comments. Patches welcome!
  32. return $hooks;
  33. }
  34. /**
  35. * Implements hook_preprocess().
  36. *
  37. * This function checks to see if a hook has a preprocess file associated with it
  38. * and if so, loads it.
  39. *
  40. * This makes it easier to keep sorted the preprocess functions that can be present
  41. * in the template.php file. You may still use hook_preprocess_page, etc in
  42. * template.php or create a file preprocess-page.inc in the preprocess folder to
  43. * include the appropriate logic to your preprocess functionality.
  44. *
  45. * @param $vars
  46. * @param $hook
  47. */
  48. function gamma_preprocess(&$vars, $hook) {
  49. }
  50. // */
  51. /**
  52. * Override or insert variables into the page templates.
  53. *
  54. * @param $vars
  55. * An array of variables to pass to the theme template.
  56. * @param $hook
  57. * The name of the template being rendered ("page" in this case.)
  58. */
  59. /* -- Delete this line if you want to use this function
  60. function gamma_preprocess_page(&$vars, $hook) {
  61. $vars['sample_variable'] = t('Lorem ipsum.');
  62. }
  63. // */
  64. /**
  65. * Override or insert variables into the node templates.
  66. *
  67. * @param $vars
  68. * An array of variables to pass to the theme template.
  69. * @param $hook
  70. * The name of the template being rendered ("node" in this case.)
  71. */
  72. /* -- Delete this line if you want to use this function
  73. function gamma_preprocess_node(&$vars, $hook) {
  74. $vars['sample_variable'] = t('Lorem ipsum.');
  75. }
  76. // */
  77. /**
  78. * Override or insert variables into the comment templates.
  79. *
  80. * @param $vars
  81. * An array of variables to pass to the theme template.
  82. * @param $hook
  83. * The name of the template being rendered ("comment" in this case.)
  84. */
  85. /* -- Delete this line if you want to use this function
  86. function gamma_preprocess_comment(&$vars, $hook) {
  87. $vars['sample_variable'] = t('Lorem ipsum.');
  88. }
  89. // */
  90. /**
  91. * Override or insert variables into the block templates.
  92. *
  93. * @param $vars
  94. * An array of variables to pass to the theme template.
  95. * @param $hook
  96. * The name of the template being rendered ("block" in this case.)
  97. */
  98. /* -- Delete this line if you want to use this function
  99. function gamma_preprocess_block(&$vars, $hook) {
  100. $vars['sample_variable'] = t('Lorem ipsum.');
  101. }
  102. // */
  103. function gamma_preprocess_field(&$vars) {
  104. //drupal_set_message('Calling <strong>gamma_preprocess_field()</strong>');
  105. // Add specific suggestions that can override the default implementation.
  106. array_unshift($vars['theme_hook_suggestions'], 'field__' . $vars['element']['#field_type']);
  107. }
  108. function gamma_preprocess_field_taxonomy_term_reference(&$vars) {
  109. drupal_set_message('Calling <strong>gamma_preprocess_field__taxonomy_term_reference()</strong>');
  110. }
  111. /**
  112. * Return a "traditional" format for taxonomy term links
  113. * This will render them as an unordered list rather than a series of divs and
  114. * also adding first and last classes, etc.
  115. * @param unknown_type $vars
  116. * @return string
  117. */
  118. function gamma_field__taxonomy_term_reference($vars) {
  119. $output = '';
  120. // Render the label, if it's not hidden.
  121. if (!$vars['label_hidden']) {
  122. $output .= '<div class="field-label"' . $vars['title_attributes'] . '>' . $vars['label'] . ':&nbsp;</div>';
  123. }
  124. // Render the items.
  125. $output .= '<ul class="field-items"' . $vars['content_attributes'] . '>';
  126. foreach ($vars['items'] as $delta => $item) {
  127. $classes = 'field-item ' . ($delta % 2 ? 'odd' : 'even');
  128. if (count($vars['items']) - 1 == $delta) {
  129. $classes .= ' last';
  130. }
  131. if ($delta == 0) {
  132. $classes .= ' first';
  133. }
  134. $output .= '<li class="' . $classes . '"' . $vars['item_attributes'][$delta] . '>' . drupal_render($item) . '</li>';
  135. }
  136. $output .= '</ul>';
  137. // Render the top-level DIV.
  138. $output = '<div class="' . $vars['classes'] . '"' . $vars['attributes'] . '>' . $output . '</div>';
  139. //krumo($vars);
  140. return $output;
  141. }
  142. function gamma_menu_tree($vars) {
  143. return '<ul class="menu">' . $vars['tree'] . '</ul>';
  144. }
  145. function gamma_menu_link(array $vars) {
  146. $element = $vars['element'];
  147. $sub_menu = '';
  148. if ($element['#below']) {
  149. $sub_menu = drupal_render($element['#below']);
  150. }
  151. $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  152. return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>";
  153. }
  154. function gamma_links($vars) {
  155. $links = $vars['links'];
  156. $attributes = $vars['attributes'];
  157. $heading = $vars['heading'];
  158. global $language_url;
  159. $output = '';
  160. if (count($links) > 0) {
  161. $output = '';
  162. // Treat the heading first if it is present to prepend it to the
  163. // list of links.
  164. if (!empty($heading)) {
  165. if (is_string($heading)) {
  166. // Prepare the array that will be used when the passed heading
  167. // is a string.
  168. $heading = array(
  169. 'text' => $heading,
  170. // Set the default level of the heading.
  171. 'level' => 'h2',
  172. );
  173. }
  174. $output .= '<' . $heading['level'];
  175. if (!empty($heading['class'])) {
  176. $output .= drupal_attributes(array('class' => $heading['class']));
  177. }
  178. $output .= '>' . check_plain($heading['text']) . '</' . $heading['level'] . '>';
  179. }
  180. $output .= '<ul' . drupal_attributes($attributes) . '>';
  181. $num_links = count($links);
  182. $i = 1;
  183. foreach ($links as $key => $link) {
  184. $class = array($key);
  185. // Add first, last and active classes to the list of links to help out themers.
  186. if ($i == 1) {
  187. $class[] = 'first';
  188. }
  189. if ($i == $num_links) {
  190. $class[] = 'last';
  191. }
  192. if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
  193. && (empty($link['language']) || $link['language']->language == $language_url->language)) {
  194. $class[] = 'active';
  195. }
  196. $output .= '<li' . drupal_attributes(array('class' => $class)) . '>';
  197. if (isset($link['href'])) {
  198. // Pass in $link as $options, they share the same keys.
  199. $output .= l($link['title'], $link['href'], $link);
  200. }
  201. elseif (!empty($link['title'])) {
  202. // Some links are actually not links, but we wrap these in <span> for adding title and class attributes.
  203. if (empty($link['html'])) {
  204. $link['title'] = check_plain($link['title']);
  205. }
  206. $span_attributes = '';
  207. if (isset($link['attributes'])) {
  208. $span_attributes = drupal_attributes($link['attributes']);
  209. }
  210. $output .= '<span' . $span_attributes . '>' . $link['title'] . '</span>';
  211. }
  212. $i++;
  213. $output .= "</li>";
  214. }
  215. $output .= '</ul>';
  216. }
  217. return $output;
  218. }
  219. function gamma_item_list($vars) {
  220. $items = $vars['items'];
  221. $title = $vars['title'];
  222. $type = $vars['type'];
  223. $attributes = $vars['attributes'];
  224. $output = '<div class="item-list">';
  225. if (isset($title)) {
  226. $output .= '<h3>' . $title . '</h3>';
  227. }
  228. if (!empty($items)) {
  229. $output .= "<$type" . drupal_attributes($attributes) . '>';
  230. $num_items = count($items);
  231. foreach ($items as $i => $item) {
  232. $attributes = array();
  233. $children = array();
  234. if (is_array($item)) {
  235. foreach ($item as $key => $value) {
  236. if ($key == 'data') {
  237. $data = $value;
  238. }
  239. elseif ($key == 'children') {
  240. $children = $value;
  241. }
  242. else {
  243. $attributes[$key] = $value;
  244. }
  245. }
  246. }
  247. else {
  248. $data = $item;
  249. }
  250. if (count($children) > 0) {
  251. // Render nested list.
  252. $data .= theme_item_list(array('items' => $children, 'title' => NULL, 'type' => $type, 'attributes' => $attributes));
  253. }
  254. if ($i == 0) {
  255. $attributes['class'][] = 'first';
  256. }
  257. if ($i == $num_items - 1) {
  258. $attributes['class'][] = 'last';
  259. }
  260. $output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>";
  261. }
  262. $output .= "</$type>";
  263. }
  264. $output .= '</div>';
  265. return $output;
  266. }
  267. /**
  268. * Implementation of theme_views_mini_pager
  269. *
  270. * This custom theming for views_mini_pager changes the previous/next
  271. * links to remove theme completely when not present to avoid the
  272. * &nbsp; messing up the spacing/theming in the list.
  273. */
  274. function gamma_views_mini_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
  275. global $pager_page_array, $pager_total;
  276. // Calculate various markers within this pager piece:
  277. // Middle is used to "center" pages around the current page.
  278. $pager_middle = ceil($quantity / 2);
  279. // current is the page we are currently paged to
  280. $pager_current = $pager_page_array[$element] + 1;
  281. // max is the maximum page number
  282. $pager_max = $pager_total[$element];
  283. // End of marker calculations.
  284. $li_previous = theme('pager_previous',
  285. array(
  286. 'text' => (isset($tags[1]) ? $tags[1] : t('‹‹')),
  287. 'limit' => $limit,
  288. 'element' => $element,
  289. 'interval' => 1,
  290. 'parameters' => $parameters,
  291. )
  292. );
  293. $li_next = theme('pager_next',
  294. array(
  295. 'text' => (isset($tags[3]) ? $tags[3] : t('››')),
  296. 'limit' => $limit,
  297. 'element' => $element,
  298. 'interval' => 1,
  299. 'parameters' => $parameters,
  300. )
  301. );
  302. if ($pager_total[$element] > 1) {
  303. if (!empty($li_previous)) {
  304. $items[] = array(
  305. 'class' => array('pager-previous'),
  306. 'data' => $li_previous,
  307. );
  308. }
  309. $items[] = array(
  310. 'class' => array('pager-current'),
  311. 'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)),
  312. );
  313. if (!empty($li_next)) {
  314. $items[] = array(
  315. 'class' => array('pager-next'),
  316. 'data' => $li_next,
  317. );
  318. }
  319. return theme('item_list',
  320. array(
  321. 'items' => $items,
  322. 'title' => NULL,
  323. 'type' => 'ul',
  324. 'attributes' => array('class' => array('pager')),
  325. )
  326. );
  327. }
  328. }
  329. function gamma_form_alter(&$form, &$form_state, $form_id) {
  330. switch ($form_id) {
  331. // for some reason the login form links are above the submit button
  332. // WTF
  333. case 'user_login_block':
  334. $form['links']['#weight'] = 100;
  335. break;
  336. }
  337. }
  338. /**
  339. * Implements hook_css_alter().
  340. * Alter CSS files before they are output on the page.
  341. *
  342. * @param $css
  343. * An array of all CSS items (files and inline CSS) being requested on the page.
  344. */
  345. function gamma_css_alter(&$css) {
  346. // fluid width option
  347. if (theme_get_setting('gamma_color_scheme')) {
  348. $css_gamma_color_css = drupal_get_path('theme', 'gamma') . '/css/dark.css';
  349. $css_gamma_color = theme_get_setting('gamma_color_scheme');
  350. if (isset($css[$css_gamma_color_css])) {
  351. $css[$css_gamma_color_css]['data'] = drupal_get_path('theme', 'gamma') . '/css/' . $css_gamma_color . '.css';
  352. }
  353. }
  354. }