PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/sites/all/themes/pixture_mobile/template.php

https://gitlab.com/endomorphosis/superchooseday
PHP | 288 lines | 162 code | 29 blank | 97 comment | 53 complexity | 95579a4ef6b3d5b57f23f3912299f1ff MD5 | raw file
  1. <?php // $Id: template.php,v 1.8 2009/05/04 21:34:31 jmburnz Exp $
  2. /**
  3. * @file
  4. * template.php
  5. */
  6. /**
  7. * Initialize theme settings for page width.
  8. */
  9. $pixture_width = theme_get_setting('pixture_width');
  10. pixture_validate_page_width($pixture_width);
  11. /**
  12. * Check the page width theme settings and reset to default
  13. * if the value is null, or invalid value is specified
  14. */
  15. function pixture_validate_page_width($width) {
  16. global $theme_key;
  17. /**
  18. * The default values for the theme variables. Make sure $defaults exactly
  19. * matches the $defaults in the theme-settings.php file.
  20. */
  21. $defaults = array( // <-- change this array
  22. 'pixture_width' => '85%',
  23. );
  24. // check if it is liquid (%) or fixed width (px)
  25. if (preg_match("/(\d+)\s*%/", $width, $match)) {
  26. $liquid = 1;
  27. $num = intval($match[0]);
  28. if (50 <= $num && $num <= 100) {
  29. return $num ."%"; // OK!
  30. }
  31. }
  32. else if (preg_match("/(\d+)\s*px/", $width, $match)) {
  33. $fixed = 1;
  34. $num = intval($match[0]);
  35. if (800 <= $num && $num < 1600) {
  36. return $num ."px"; // OK
  37. }
  38. }
  39. // reset to default value
  40. variable_set(
  41. str_replace('/', '_', 'theme_'. $theme_key .'_settings'),
  42. array_merge($defaults, theme_get_settings($theme_key))
  43. );
  44. // Force refresh of Drupal internals
  45. theme_get_setting('', TRUE);
  46. return $defaults['pixture_width'];
  47. }
  48. /**
  49. * Initialize theme settings for superfish.
  50. */
  51. if (is_null(theme_get_setting('pixture_superfish'))) { // <-- change this line
  52. global $theme_key;
  53. /**
  54. * The default values for the theme variables. Make sure $defaults exactly
  55. * matches the $defaults in the theme-settings.php file.
  56. */
  57. $defaults = array( // <-- change this array
  58. 'pixture_superfish' => 0,
  59. );
  60. // Get default theme settings.
  61. $settings = theme_get_settings($theme_key);
  62. // Save default theme settings.
  63. variable_set(
  64. str_replace('/', '_', 'theme_'. $theme_key .'_settings'),
  65. array_merge($defaults, $settings)
  66. );
  67. // Force refresh of Drupal internals.
  68. theme_get_setting('', TRUE);
  69. return $defaults['pixture_superfish'];
  70. }
  71. // Conditionally load the Superfish JS
  72. if (theme_get_setting('pixture_superfish')) {
  73. drupal_add_css(drupal_get_path('theme', 'pixture_reloaded') .'/sf/css/superfish.css', 'theme', 'all', FALSE);
  74. drupal_add_js(drupal_get_path('theme', 'pixture_reloaded') .'/sf/js/superfish.js', 'theme');
  75. }
  76. /**
  77. * Override or insert PHPTemplate variables into the page templates.
  78. *
  79. * @param $vars
  80. * A sequential array of variables to pass to the theme template.
  81. * @param $hook
  82. * The name of the theme function being called ("page" in this case.)
  83. */
  84. function pixture_reloaded_preprocess_page(&$vars, $hook) {
  85. global $theme;
  86. // Hook into color.module
  87. if (module_exists('color')) {
  88. _color_page_alter($vars);
  89. }
  90. // Don't display empty help from node_help().
  91. if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
  92. $vars['help'] = '';
  93. }
  94. // Set variables for the logo and site_name.
  95. if (!empty($vars['logo'])) {
  96. $vars['site_logo'] = '<a href="'. $vars['front_page'] .'" title="'. t('Home page') .'" rel="home"><img src="'. $vars['logo'] .'" alt="'. $vars['site_name'] .' '. t('logo') .'" /></a>';
  97. }
  98. if (!empty($vars['site_name'])) {
  99. $vars['site_name'] = '<a href="'. $vars['front_page'] .'" title="'. t('Home page') .'" rel="home">'. $vars['site_name'] .'</a>';
  100. }
  101. // Set variables for the primary and secondary links.
  102. if (!empty($vars['primary_links'])) {
  103. $vars['primary_menu'] = theme('links', $vars['primary_links'], array('class' => 'links primary-links'));
  104. }
  105. if (!empty($vars['secondary_links'])) {
  106. $vars['primary_menu'] = theme('links', $vars['secondary_links'], array('class' => 'links secondary_links'));
  107. }
  108. // Classes for body element. Allows advanced theming based on context
  109. // (home page, node of certain type, etc.)
  110. $body_classes = array($vars['body_classes']);
  111. if (!$vars['is_front']) {
  112. // Add unique classes for each page and website section
  113. $path = drupal_get_path_alias($_GET['q']);
  114. list($section, ) = explode('/', $path, 2);
  115. $body_classes[] = pixture_reloaded_id_safe('page-'. $path);
  116. $body_classes[] = pixture_reloaded_id_safe('section-'. $section);
  117. if (arg(0) == 'node') {
  118. if (arg(1) == 'add') {
  119. if ($section == 'node') {
  120. array_pop($body_classes); // Remove 'section-node'
  121. }
  122. $body_classes[] = 'section-node-add'; // Add 'section-node-add'
  123. }
  124. elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
  125. if ($section == 'node') {
  126. array_pop($body_classes); // Remove 'section-node'
  127. }
  128. $body_classes[] = 'section-node-'. arg(2); // Add 'section-node-edit' or 'section-node-delete'
  129. }
  130. }
  131. // Add a unique class when viewing a node
  132. if (arg(0) == 'node' && is_numeric(arg(1))) {
  133. $body_classes[] = 'node-full-view'; // Add 'node-full-view'
  134. }
  135. }
  136. $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
  137. }
  138. /**
  139. * Override or insert PHPTemplate variables into the node templates.
  140. *
  141. * @param $vars
  142. * A sequential array of variables to pass to the theme template.
  143. * @param $hook
  144. * The name of the theme function being called ("node" in this case.)
  145. */
  146. function pixture_reloaded_preprocess_node(&$vars, $hook) {
  147. global $user;
  148. // Special classes for nodes
  149. $node_classes = array();
  150. if ($vars['sticky']) {
  151. $node_classes[] = 'sticky';
  152. }
  153. if (!$vars['node']->status) {
  154. $node_classes[] = 'node-unpublished';
  155. $vars['unpublished'] = TRUE;
  156. }
  157. else {
  158. $vars['unpublished'] = FALSE;
  159. }
  160. if ($vars['node']->uid && $vars['node']->uid == $user->uid) {
  161. // Node is authored by current user
  162. $node_classes[] = 'node-mine';
  163. }
  164. if ($vars['teaser']) {
  165. // Node is displayed as teaser
  166. $node_classes[] = 'node-teaser';
  167. }
  168. if ($vars['$is_front']) {
  169. // Node is displayed on the front page
  170. $node_classes[] = 'front-node';
  171. }
  172. // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
  173. $node_classes[] = 'node-type-'. $vars['node']->type;
  174. $vars['node_classes'] = implode(' ', $node_classes); // Concatenate with spaces
  175. }
  176. /**
  177. * Override or insert PHPTemplate variables into the comment templates.
  178. *
  179. * @param $vars
  180. * A sequential array of variables to pass to the theme template.
  181. * @param $hook
  182. * The name of the theme function being called ("comment" in this case.)
  183. */
  184. function pixture_reloaded_preprocess_comment(&$vars, $hook) {
  185. global $user;
  186. // We load the node object that the current comment is attached to
  187. $node = node_load($vars['comment']->nid);
  188. // If the author of this comment is equal to the author of the node, we
  189. // set a variable so we can theme this comment uniquely.
  190. $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
  191. $comment_classes = array();
  192. // Odd/even handling
  193. static $comment_odd = TRUE;
  194. $comment_classes[] = $comment_odd ? 'odd' : 'even';
  195. $comment_odd = !$comment_odd;
  196. if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
  197. $comment_classes[] = 'comment-unpublished';
  198. $vars['unpublished'] = TRUE;
  199. }
  200. else {
  201. $vars['unpublished'] = FALSE;
  202. }
  203. if ($vars['author_comment']) {
  204. // Comment is by the node author
  205. $comment_classes[] = 'comment-by-author';
  206. }
  207. if ($vars['comment']->uid == 0) {
  208. // Comment is by an anonymous user
  209. $comment_classes[] = 'comment-by-anon';
  210. }
  211. if ($user->uid && $vars['comment']->uid == $user->uid) {
  212. // Comment was posted by current user
  213. $comment_classes[] = 'comment-mine';
  214. }
  215. $vars['comment_classes'] = implode(' ', $comment_classes);
  216. // If comment subjects are disabled, don't display 'em
  217. if (variable_get('comment_subject_field', 1) == 0) {
  218. $vars['title'] = '';
  219. }
  220. }
  221. /**
  222. * Override or insert PHPTemplate variables into the block templates.
  223. *
  224. * @param $vars
  225. * A sequential array of variables to pass to the theme template.
  226. * @param $hook
  227. * The name of the theme function being called ("block" in this case.)
  228. */
  229. function pixture_reloaded_preprocess_block(&$vars, $hook) {
  230. $block = $vars['block'];
  231. // Special classes for blocks
  232. $block_classes = array();
  233. $block_classes[] = 'block-'. $block->module;
  234. $block_classes[] = 'region-'. $vars['block_zebra'];
  235. $block_classes[] = $vars['zebra'];
  236. $block_classes[] = 'region-count-'. $vars['block_id'];
  237. $block_classes[] = 'count-'. $vars['id'];
  238. $vars['block_classes'] = implode(' ', $block_classes);
  239. }
  240. /**
  241. * Converts a string to a suitable html ID attribute.
  242. *
  243. * - Preceeds initial numeric with 'n' character.
  244. * - Replaces space and underscore with dash.
  245. * - Converts entire string to lowercase.
  246. * - Works for classes too!
  247. *
  248. * @param string $string
  249. * The string
  250. * @return
  251. * The converted string
  252. */
  253. function pixture_reloaded_id_safe($string) {
  254. if (is_numeric($string{0})) {
  255. // If the first character is numeric, add 'n' in front
  256. $string = 'n'. $string;
  257. }
  258. return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
  259. }