PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/sites/all/themes/yaml/template.php

https://github.com/rentasite/drupal6_sandbox
PHP | 273 lines | 167 code | 37 blank | 69 comment | 35 complexity | ae15bfaadd76a3348af52f3837449b68 MD5 | raw file
  1. <?php
  2. // $Id: template.php,v 3.1.0.12 2009/06/07 00:00:00 hass Exp $
  3. /**
  4. * "Yet Another Multicolumn Layout" for Drupal
  5. *
  6. * (en) Central template for theme specific functions
  7. * (de) Zentrales Template für theme spezifische Funktionen
  8. *
  9. * @copyright Copyright 2006-2009, Alexander Hass
  10. * @license http://www.yaml-fuer-drupal.de/en/terms-of-use
  11. * @link http://www.yaml-for-drupal.com
  12. * @package yaml-for-drupal
  13. * @version 6.x-3.1.0.12
  14. * @lastmodified 2009-06-07
  15. */
  16. /**
  17. * Include the central template.inc with global theme functions
  18. */
  19. include_once(realpath(dirname(__FILE__) .'/template.inc'));
  20. /**
  21. * Alter some Drupal variables required by Theme.
  22. */
  23. function yaml_preprocess_page(&$vars) {
  24. global $user, $theme;
  25. // Install default theme settings. Need to run first of all.
  26. $yaml_theme_settings_install_function = '_'. $theme .'_theme_settings_install';
  27. if (function_exists($yaml_theme_settings_install_function)) {
  28. $yaml_theme_settings_install_function($theme);
  29. }
  30. // Load the XML prolog for standard compliant browsers if caching is inactive.
  31. // The function page_set_cache() does not cache pages if $user->uid has a value.
  32. // Additional the XML prolog can only added to YAML for Drupal if a user is
  33. // logged into Drupal (caching inactive) or caching is globaly disabled on the site.
  34. if ((_browser_xml_prolog_compliant() && $user->uid) || (_browser_xml_prolog_compliant() && !(variable_get('cache', 0)))) {
  35. $vars['xml_prolog'] = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  36. }
  37. // Add gfxborder to the page layout.
  38. if (theme_get_setting('yaml_layout_page_gfxborder')) {
  39. $vars['border_top'] = '<div id="border-top"><div id="edge-tl"> </div><div id="edge-tr"> </div></div>' . "\n";
  40. $vars['border_bottom'] = '<div id="border-bottom"><div id="edge-bl"> </div><div id="edge-br"> </div></div>' . "\n";
  41. }
  42. // Dynamic sidebar switching.
  43. // Limit code execution to "base theme". Code inside the below switch statement
  44. // is only executed for the specific theme or subtheme.
  45. switch ($theme) {
  46. case 'yaml':
  47. case 'yaml_3col_standard':
  48. if ($vars['layout'] == 'none') {
  49. $vars['body_classes'] = $vars['body_classes'] .' hideboth';
  50. }
  51. elseif ($vars['layout'] == 'left') {
  52. $vars['body_classes'] = $vars['body_classes'] .' hidecol2';
  53. }
  54. elseif ($vars['layout'] == 'right') {
  55. $vars['body_classes'] = $vars['body_classes'] .' hidecol1';
  56. }
  57. break;
  58. case 'yaml_2col_13':
  59. case 'yaml_2col_31':
  60. if ($vars['layout'] == 'none') {
  61. $vars['body_classes'] = $vars['body_classes'] .' hideboth';
  62. }
  63. break;
  64. }
  65. // Add YAML Theme styles.
  66. $yaml_css_function = '_'. $theme .'_add_css';
  67. if (function_exists($yaml_css_function)) {
  68. $vars['css'] = $yaml_css_function($vars);
  69. }
  70. $yaml_styles_function = '_'. $theme .'_add_styles';
  71. if (function_exists($yaml_styles_function)) {
  72. $vars['styles'] = $yaml_styles_function($vars);
  73. }
  74. }
  75. /**
  76. * Alter some Drupal variables required by maintenance theme.
  77. */
  78. function phptemplate_preprocess_maintenance_page(&$vars) {
  79. // Dynamic sidebar switching. Turn off sidebars in maintenance mode.
  80. $vars['body_classes'] = $vars['body_classes'] .' hideboth';
  81. $vars['css'] = _yaml_add_css($vars);
  82. $vars['styles'] = _yaml_add_styles($vars);
  83. }
  84. /**
  85. * Implementation of hook_theme().
  86. */
  87. function yaml_theme() {
  88. return array(
  89. 'links_secondary' => array(
  90. 'arguments' => array(
  91. 'links' => NULL,
  92. 'attributes' => array('class' => 'links'),
  93. 'settings' => array(
  94. 'delimiter' => ' | ',
  95. 'leftcab' => NULL,
  96. 'rightcab' => NULL,
  97. )
  98. ),
  99. 'template' => 'links-secondary',
  100. ),
  101. );
  102. }
  103. /**
  104. * Theme CSS files
  105. *
  106. * Workaround for CSS aggregate and compress feature in Drupal 6.x
  107. */
  108. function _yaml_add_css($vars = array()) {
  109. $base_theme_directory = $vars['directory'];
  110. // Add core and layout specific styles
  111. drupal_add_css($base_theme_directory .'/yaml/core/base.css', 'theme');
  112. drupal_add_css($base_theme_directory .'/css/screen/basemod.css', 'theme');
  113. drupal_add_css($base_theme_directory .'/css/screen/basemod_dynamic_layout_switching.css', 'theme');
  114. drupal_add_css($base_theme_directory .'/css/screen/basemod_drupal.css', 'theme');
  115. if (theme_get_setting('yaml_layout_page_gfxborder')) {
  116. drupal_add_css($base_theme_directory .'/css/screen/basemod_gfxborder.css', 'theme');
  117. }
  118. // Add horizontal navigations
  119. $yaml_nav_primary = theme_get_setting('yaml_nav_primary');
  120. if ($yaml_nav_primary == 1) {
  121. drupal_add_css($base_theme_directory .'/css/navigation/nav_shinybuttons.css', 'theme');
  122. }
  123. else {
  124. drupal_add_css($base_theme_directory .'/css/navigation/nav_slidingdoor.css', 'theme');
  125. }
  126. // Add vertical navigations
  127. $yaml_nav_vertical = theme_get_setting('yaml_nav_vertical');
  128. if ($yaml_nav_vertical == 1) {
  129. // There are currently no additional navigations available, add here if you create your own.
  130. }
  131. else {
  132. drupal_add_css($base_theme_directory .'/css/navigation/nav_vlist_drupal.css', 'theme');
  133. }
  134. // Content CSS files
  135. drupal_add_css($base_theme_directory .'/css/screen/content.css', 'theme');
  136. // Add custom module styles
  137. _yaml_add_css_modules($base_theme_directory);
  138. // Add print CSS files
  139. drupal_add_css($base_theme_directory .'/yaml/core/print_base.css', 'theme');
  140. drupal_add_css($base_theme_directory .'/css/print/print_003.css', 'theme');
  141. drupal_add_css($base_theme_directory .'/css/print/print_drupal.css', 'theme');
  142. // Add debug CSS files
  143. if (theme_get_setting('yaml_debug') == 1) {
  144. drupal_add_css($base_theme_directory .'/yaml/debug/debug.css', 'theme', 'all', FALSE);
  145. }
  146. // Remove the style.css added as first array item and move it to the end
  147. // of the styles array. This allows to use themes style.css and keep
  148. // the required CSS cascading order intact for CSS overriding.
  149. $css = drupal_add_css();
  150. if (isset($css['all']['theme'][$vars['directory'] .'/style.css'])) {
  151. unset($css['all']['theme'][$vars['directory'] .'/style.css']);
  152. $css['all']['theme'][$vars['directory'] .'/style.css'] = TRUE;
  153. }
  154. if (isset($css['all']['theme'][$vars['directory'] .'/style-rtl.css'])) {
  155. unset($css['all']['theme'][$vars['directory'] .'/style-rtl.css']);
  156. $css['all']['theme'][$vars['directory'] .'/style-rtl.css'] = TRUE;
  157. }
  158. // Return CSS array
  159. return $css;
  160. }
  161. function _yaml_add_styles($vars = array()) {
  162. global $language;
  163. $base_theme_directory = $vars['directory'];
  164. $styles = drupal_get_css($vars['css']);
  165. // Page settings
  166. $styles .= _yaml_get_css_themesettings('132');
  167. // The styles array is complete, get the styled css and append the
  168. // IE Hacks. Additional this allows to dynamically add packed or other iehacks.
  169. $styles .= "<!--[if lte IE 7]>\n";
  170. $styles .= '<style type="text/css" media="all">' . "\n";
  171. $styles .= '@import "'. base_path() . $base_theme_directory .'/yaml/core/iehacks'. (variable_get('preprocess_css', FALSE) ? '.pack' : '') .'.css";' . "\n";
  172. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
  173. $styles .= '@import "'. base_path() . $base_theme_directory .'/yaml/core/iehacks-rtl'. (variable_get('preprocess_css', FALSE) ? '.pack' : '') .'.css";' . "\n";
  174. }
  175. $styles .= '@import "'. base_path() . $base_theme_directory .'/css/patches/patch_nav_vlist_drupal.css";' . "\n";
  176. $styles .= '@import "'. base_path() . $base_theme_directory .'/css/patches/patch_3col_standard.css";' . "\n";
  177. $styles .= '@import "'. base_path() . $base_theme_directory .'/css/patches/patch_drupal.css";' . "\n";
  178. // IE page settings.
  179. $styles_ie = _yaml_get_css_ie_themesettings('132');
  180. if (!empty($styles_ie)) {
  181. $styles .= $styles_ie . "\n";
  182. }
  183. $styles .= "</style>\n";
  184. $styles .= "<![endif]-->\n";
  185. // IE 6 settings and styles.
  186. $styles_ie6 = _yaml_get_css_ie6_themesettings('132', $base_theme_directory);
  187. if (!empty($styles_ie6)) {
  188. $styles .= "<!--[if lte IE 6]>\n";
  189. $styles .= '<style type="text/css" media="all">'. $styles_ie6 ."</style>\n";
  190. $styles .= "<![endif]-->\n";
  191. }
  192. // Return themed styles
  193. return $styles;
  194. }
  195. /**
  196. * There is currently no .install support available for themes and the
  197. * following is a workaround to initialize new theme settings.
  198. *
  199. * - 'yaml_layout_page_width' is a new setting in 6.x-3.0.6.9
  200. */
  201. function _yaml_theme_settings_install($theme) {
  202. if ((is_null(theme_get_setting('yaml_layout_page_width')) || theme_get_setting('yaml_layout_page_width_col3') === 'auto')) {
  203. // Save default theme settings.
  204. $defaults = array(
  205. 'yaml_nav_primary' => 0,
  206. 'yaml_nav_vertical' => 0,
  207. 'yaml_layout_page_width' => 'auto',
  208. 'yaml_layout_page_width_min' => '740px',
  209. 'yaml_layout_page_width_max' => '80em',
  210. 'yaml_layout_page_width_col1' => '25%',
  211. 'yaml_layout_page_width_col2' => 'auto',
  212. 'yaml_layout_page_width_col3' => '25%',
  213. 'yaml_layout_page_align' => 'center',
  214. 'yaml_layout_page_gfxborder' => 0,
  215. 'yaml_msie_hack_pngfix' => 1,
  216. 'yaml_msie_hack_minmaxwidth' => 1,
  217. 'yaml_debug' => 0,
  218. 'yaml_display_link_validation_xhtml' => 0,
  219. 'yaml_display_link_validation_css' => 0,
  220. 'yaml_display_link_license_yaml' => 1,
  221. 'yaml_display_link_license_yamlfd' => 1,
  222. );
  223. $merged_settings = array_merge($defaults, theme_get_settings($theme));
  224. // Upgrade 'yaml' from 6.x-3.0.4.8 to 6.x-3.0.6.9.
  225. if (theme_get_setting('yaml_layout_page_width_col3') == 'auto') {
  226. $merged_settings['yaml_layout_page_width_col2'] = 'auto';
  227. $merged_settings['yaml_layout_page_width_col3'] = '25%';
  228. }
  229. variable_set(
  230. str_replace('/', '_', 'theme_'. $theme .'_settings'),
  231. $merged_settings
  232. );
  233. // Force refresh of Drupal internals.
  234. theme_get_setting('', TRUE);
  235. }
  236. }