PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/themes/omega/template.php

https://github.com/opportunitylinks/Support-For-Me
PHP | 359 lines | 199 code | 20 blank | 140 comment | 51 complexity | 2e3079640cbda432cb32be955361493d MD5 | raw file
  1. <?php
  2. //$Id: template.php,v 1.7.2.10 2010/07/22 14:30:03 himerus Exp $
  3. // Report all PHP errors (see changelog)
  4. //ini_set('error_reporting', E_ALL);
  5. /**
  6. * Implementation of hook_preprocess()
  7. *
  8. * This function checks to see if a hook has a preprocess file associated with
  9. * it, and if so, loads it.
  10. *
  11. * This makes it easier to keep sorted the preprocess functions that can be present in the
  12. * template.php file. You may still use hook_preprocess_page in template.php
  13. * or create a file preprocess-page.inc in the preprocess folder to include the appropriate
  14. * logic to your preprocess functionality
  15. *
  16. * @param $vars
  17. * @param $hook
  18. * @return Array
  19. */
  20. function omega_preprocess(&$vars, $hook) {
  21. // Collect all information for the active theme.
  22. $themes_active = array();
  23. global $theme_info;
  24. // If there is a base theme, collect the names of all themes that may have
  25. // preprocess files to load.
  26. if($theme_info->base_theme) {
  27. global $base_theme_info;
  28. foreach($base_theme_info as $base){
  29. $themes_active[] = $base->name;
  30. }
  31. }
  32. // Add the active theme to the list of themes that may have preprocess files.
  33. $themes_active[] = $theme_info->name;
  34. // Check all active themes for preprocess files that will need to be loaded.
  35. foreach($themes_active as $name) {
  36. if(is_file(drupal_get_path('theme', $name) . '/preprocess/preprocess-' . str_replace('_', '-', $hook) . '.inc')) {
  37. include(drupal_get_path('theme', $name) . '/preprocess/preprocess-' . str_replace('_', '-', $hook) . '.inc');
  38. }
  39. }
  40. }
  41. /**
  42. * Preprocessor for page.tpl.php template file.
  43. * The default functionality can be found in preprocess/preprocess-page.inc
  44. */
  45. function omega_preprocess_page(&$vars, $hook) {
  46. // Prepare 960gs CSS. Fixed width is default, fluid is optional via theme-settings
  47. if(theme_get_setting('omega_fixed_fluid') == 'fluid') {
  48. $css_960 = drupal_get_path('theme', 'omega') .'/css/960-fluid.css';
  49. }
  50. else {
  51. $css_960 = drupal_get_path('theme', 'omega') .'/css/960.css';
  52. }
  53. drupal_add_css($css_960, 'module', 'all');
  54. // enable/disable optional CSS files
  55. if (theme_get_setting('reset_css') == '1') {
  56. drupal_add_css(drupal_get_path('theme', 'omega') .'/css/reset.css', 'module', 'all');
  57. }
  58. if (theme_get_setting('text_css') == '1') {
  59. drupal_add_css(drupal_get_path('theme', 'omega') .'/css/text.css', 'module', 'all');
  60. }
  61. if (theme_get_setting('regions_css') == '1') {
  62. drupal_add_css(drupal_get_path('theme', 'omega') .'/css/regions.css', 'module', 'all');
  63. }
  64. if (theme_get_setting('defaults_css') == '1') {
  65. drupal_add_css(drupal_get_path('theme', 'omega') .'/css/defaults.css', 'module', 'all');
  66. }
  67. if (theme_get_setting('custom_css') == '1') {
  68. drupal_add_css(drupal_get_path('theme', 'omega') .'/css/custom.css', 'module', 'all');
  69. }
  70. // redeclare $styles
  71. //krumo($vars['styles']);
  72. $vars['styles'] = drupal_get_css();
  73. //krumo($vars['styles']);
  74. } // end preprocess_page
  75. function omega_preprocess_node(&$vars, $hook) {
  76. } // end preprocess_node
  77. /**
  78. * NINESIXTY - Contextually adds 960 Grid System classes.
  79. *
  80. * The first parameter passed is the *default class*. All other parameters must
  81. * be set in pairs like so: "$variable, 3". The variable can be anything available
  82. * within a template file and the integer is the width set for the adjacent box
  83. * containing that variable.
  84. *
  85. * class="<?php print ns('grid-16', $var_a, 6); ?>"
  86. *
  87. * If $var_a contains data, the next parameter (integer) will be subtracted from
  88. * the default class. See the README.txt file.
  89. */
  90. function ns() {
  91. $args = func_get_args();
  92. $default = array_shift($args);
  93. // Get the type of class, i.e., 'grid', 'pull', 'push', etc.
  94. // Also get the default unit for the type to be procesed and returned.
  95. list($type, $return_unit) = explode('-', $default);
  96. // Process the conditions.
  97. $flip_states = array('var' => 'int', 'int' => 'var');
  98. $state = 'var';
  99. foreach ($args as $arg) {
  100. if ($state == 'var') {
  101. $var_state = !empty($arg);
  102. }
  103. elseif ($var_state) {
  104. $return_unit = $return_unit - $arg;
  105. }
  106. $state = $flip_states[$state];
  107. }
  108. $output = '';
  109. // Anything below a value of 1 is not needed.
  110. if ($return_unit > 0) {
  111. $output = $type . '-' . $return_unit;
  112. }
  113. return $output;
  114. }
  115. /**
  116. * The region_builder function will create the variables needed to create
  117. * a dynamic group of regions. This function is simply a quick pass-thru
  118. * that will create either inline or stacked regions. This function will
  119. * not do any advanced functionality, but simply assing the appropriate
  120. * classes based on the settings for the theme.
  121. *
  122. * For a more advanced set of regions, dynamic_region_builder() will be used.
  123. */
  124. function static_region_builder($region_data, $container_width, $vars) {
  125. // let's cycle the region data, and determine what we have
  126. foreach ($region_data AS $region => $info) {
  127. // if we do have content for this region, let's create it.
  128. if ($info['data']) {
  129. $vars[$region .'_classes'] = ns('grid-'. $info['width']);
  130. }
  131. if (is_array($info['spacing'])) {
  132. foreach ($info['spacing'] AS $attribute => $value) {
  133. if ($value) {
  134. $vars[$region .'_classes'] .= ' '. $attribute .'-'. $value;
  135. }
  136. }
  137. }
  138. }
  139. return $vars;
  140. }
  141. function _omega_dynamic_zones($width, $conditions, $vars) {
  142. foreach($conditions AS $variable => $reaction) {
  143. if(($reaction['type'] && $vars[$variable]) || (!$reaction['type'] && !$vars[$variable])) {
  144. $width = $width - $reaction['value'];
  145. }
  146. }
  147. return $width;
  148. }
  149. function _omega_dynamic_widths($width, $conditions, $vars) {
  150. foreach($conditions AS $variable => $zone) {
  151. if(($vars[$variable])) {
  152. $width = $width - $zone['width'];
  153. }
  154. }
  155. return $width;
  156. }
  157. /**
  158. * The dynamic_region_builder function will be used to pass important zones
  159. * like the content regions where the regions sent to the function MUST appear
  160. * inline, and advanced calculations need to be done in order to display the as such
  161. *
  162. * Stacked regions are not possible using this function, and should be passed through
  163. * static_region_builder() instead.
  164. */
  165. function dynamic_region_builder($region_data, $container_width, $vars) {
  166. // let's cycle the region data, and determine what we have
  167. foreach ($region_data AS $region => $info) {
  168. // if we do have content for this region, let's create it.
  169. if ($info['data']) {
  170. $width = $info['primary'] ? $container_width : $info['width'];
  171. $vars[$region .'_classes'] = $info['primary'] ? ns('grid-'. _omega_dynamic_widths($width, $info['related'], $vars)) : ns('grid-'. $info['width']);
  172. // we know we have stuff to put here, so we can check for push & pull options
  173. if($info['pull']) {
  174. // looks like we do wanna pull, or this value would have been false, so let's boogie
  175. $vars[$region .'_classes'] .= ' '. ns('pull-'. _omega_dynamic_zones($info['pull']['width'], $info['pull']['conditions'], $vars));
  176. //krumo('Pulling '. $region .' '. $vars[$region .'_classes']);
  177. }
  178. if($info['push']) {
  179. // looks like a push
  180. $vars[$region .'_classes'] .= ' '. ns('push-'. _omega_dynamic_zones($info['push']['width'], $info['push']['conditions'], $vars));
  181. //krumo('Pushing '. $region .' '. $vars[$region .'_classes']);
  182. //krumo('Should be pushing '. $info['push']['width'] .' grids.');
  183. //krumo($info['push']['conditions']);
  184. }
  185. }
  186. // currently ignored becuase we have not given prefix/suffix class options
  187. // to the primary content zones... this will become active again later
  188. if (is_array($info['spacing'])) {
  189. foreach ($info['spacing'] AS $attribute => $value) {
  190. if ($value) {
  191. $vars[$region .'_classes'] .= ' '. $attribute .'-'. $value;
  192. }
  193. }
  194. }
  195. // \unused prefix/suffix stuffs
  196. }
  197. return $vars;
  198. }
  199. /**
  200. * The rfilter function takes one argument, an array of values for the regions
  201. * for a "group" of regions like preface or postscript
  202. * @param $vars
  203. */
  204. function rfilter($vars) {
  205. return count(array_filter($vars));
  206. }
  207. /**
  208. * OMEGA - A function to return the alpha and or omega classes based on context
  209. * This function is not currently being used.
  210. * @param $vars
  211. * @param $elements
  212. * @param $current
  213. * @param $alpha
  214. * @param $omega
  215. * @return classes
  216. */
  217. function ao($vars, $elements, $current, $alpha = FALSE, $omega = FALSE){
  218. $classes = array();
  219. $regions = array();
  220. // let's get rid of empty elements first
  221. foreach($elements AS $k => $r) {
  222. if($vars[$r]) {
  223. $regions[$k] = $r;
  224. }
  225. }
  226. // now we do another fast loop since we emptied out any blank zones to determine what
  227. // regions are alpha & omega
  228. foreach($regions AS $k => $r) {
  229. $classes[$r] = '';
  230. if(!$alpha){
  231. $alpha = TRUE;
  232. $classes[$r] .= ' alpha';
  233. }
  234. if(!$omega && ($k == count($regions) - 1 || count($regions) == 1 )) {
  235. $omega = TRUE;
  236. $classes[$r] .= ' omega';
  237. }
  238. }
  239. return $classes[$current];
  240. }
  241. /**
  242. * Converts a string to a suitable html ID attribute.
  243. *
  244. * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
  245. * valid ID attribute in HTML. This function:
  246. *
  247. * - Ensure an ID starts with an alpha character by optionally adding an 'id'.
  248. * - Replaces any character except alphanumeric characters with dashes.
  249. * - Converts entire string to lowercase.
  250. *
  251. * @param $string
  252. * The string
  253. * @return
  254. * The converted string
  255. */
  256. function omega_id_safe($string) {
  257. // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
  258. $string = strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
  259. // If the first character is not a-z, add 'id' in front.
  260. if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
  261. $string = 'id' . $string;
  262. }
  263. return $string;
  264. }
  265. /**
  266. * ZEN - Return a themed breadcrumb trail.
  267. *
  268. * @param $breadcrumb
  269. * An array containing the breadcrumb links.
  270. * @return
  271. * A string containing the breadcrumb output.
  272. */
  273. function omega_breadcrumb($breadcrumb) {
  274. // Determine if we are to display the breadcrumb.
  275. $show_breadcrumb = theme_get_setting('omega_breadcrumb');
  276. if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
  277. // Optionally get rid of the homepage link.
  278. $show_breadcrumb_home = theme_get_setting('omega_breadcrumb_home');
  279. if (!$show_breadcrumb_home) {
  280. array_shift($breadcrumb);
  281. }
  282. // Return the breadcrumb with separators.
  283. if (!empty($breadcrumb)) {
  284. $breadcrumb_separator = theme_get_setting('omega_breadcrumb_separator');
  285. $trailing_separator = $title = '';
  286. if (theme_get_setting('omega_breadcrumb_title')) {
  287. $trailing_separator = $breadcrumb_separator;
  288. $title = menu_get_active_title();
  289. }
  290. elseif (theme_get_setting('omega_breadcrumb_trailing')) {
  291. $trailing_separator = $breadcrumb_separator;
  292. }
  293. return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator$title</div>";
  294. }
  295. }
  296. // Otherwise, return an empty string.
  297. return '';
  298. }
  299. /**
  300. * Create a string of attributes form a provided array.
  301. *
  302. * @param $attributes
  303. * @return string
  304. */
  305. function omega_render_attributes($attributes) {
  306. if ($attributes) {
  307. $items = array();
  308. foreach($attributes as $attribute => $data) {
  309. if(is_array($data)) {
  310. $data = implode(' ', $data);
  311. }
  312. $items[] = $attribute . '="' . $data . '"';
  313. }
  314. $output = ' ' . implode(' ', $items);
  315. }
  316. return $output;
  317. }
  318. /**
  319. * Implementation of hook_theme().
  320. *
  321. * @return
  322. */
  323. function omega_theme(&$existing, $type, $theme, $path) {
  324. if (!db_is_active()) {
  325. return array();
  326. }
  327. include_once './' . drupal_get_path('theme', 'omega') . '/theme-functions.inc';
  328. // Since we are rebuilding the theme registry and the theme settings' default
  329. // values may have changed, make sure they are saved in the database properly.
  330. omega_theme_get_default_settings($theme);
  331. return array(
  332. 'id_safe' => array(
  333. 'arguments' => array('string'),
  334. ),
  335. 'render_attributes' => array(
  336. 'arguments' => array('attributes'),
  337. ),
  338. );
  339. }// */