PageRenderTime 56ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/themes/mobile_jquery/theme-settings.php

https://bitbucket.org/ramsalt/dintaxi
PHP | 367 lines | 298 code | 35 blank | 34 comment | 12 complexity | 7192fff23de6654969d81890926c23c7 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. * Theme setting defaults
  4. */
  5. function mobile_jquery_default_theme_settings() {
  6. $defaults = array(
  7. 'rebuild_registry' => 1,
  8. 'use_global' => 1,
  9. 'global_icon' => 'arrow-r',
  10. 'global_inset' => 'true',
  11. 'global_theme' => 'a',
  12. 'global_spliticon' => 'plus',
  13. 'list_item_icon' => 'arrow-r',
  14. 'list_item_inset' => 'true',
  15. 'list_item_theme' => 'a',
  16. 'list_item_dividertheme' => 'a',
  17. 'list_item_counttheme' => 'a',
  18. 'list_item_splittheme' => 'a',
  19. 'list_item_spliticon' => 'plus',
  20. 'menu_item_icon' => 'arrow-r',
  21. 'menu_item_inset' => 'true',
  22. 'menu_item_theme' => 'a',
  23. 'menu_item_dividertheme' => 'a',
  24. 'menu_item_counttheme' => 'a',
  25. 'menu_item_splittheme' => 'a',
  26. 'menu_item_spliticon' => 'plus',
  27. 'header_data_theme' => 'a',
  28. 'header_data_position' => 'inline',
  29. 'content_data_theme' => 'a',
  30. 'footer_data_theme' => 'a',
  31. 'footer_data_position' => 'inline',
  32. );
  33. // Add site-wide theme settings
  34. $defaults = array_merge($defaults, theme_get_settings());
  35. return $defaults;
  36. }
  37. /**
  38. * Initialize theme settings
  39. */
  40. function mobile_jquery_initialize_theme_settings($theme_name) {
  41. global $user;
  42. $theme_settings = theme_get_settings($theme_name);
  43. if (!isset($theme_settings['global_theme']) || $theme_settings['rebuild_registry'] == 1) {
  44. static $registry_rebuilt = false; // avoid multiple rebuilds per page
  45. // Rebuild theme registry & notify user
  46. if (isset($theme_settings['rebuild_registry']) && $theme_settings['rebuild_registry'] == 1 && !$registry_rebuilt) {
  47. drupal_rebuild_theme_registry();
  48. if (in_array('administrator', array_values($user->roles))) {
  49. drupal_set_message(t('Theme registry has been rebuilt. This feature is only recommended for development sites. <a href="!link">Disable</a>.', array('!link' => url('admin/build/themes/settings/' . $GLOBALS['theme']))), 'warning');
  50. }
  51. $registry_rebuilt = TRUE;
  52. }
  53. // Retrieve saved or site-wide theme settings
  54. $theme_setting_name = str_replace('/', '_', 'theme_'. $theme_name .'_settings');
  55. $settings = (variable_get($theme_setting_name, FALSE)) ? theme_get_settings($theme_name) : theme_get_settings();
  56. // Skip toggle_node_info_ settings
  57. if (module_exists('node')) {
  58. foreach (node_get_types() as $type => $name) {
  59. unset($settings['toggle_node_info_'. $type]);
  60. }
  61. }
  62. // Combine default theme settings from .info file & theme-settings.php
  63. $theme_data = list_themes(); // get theme data for all themes
  64. $info_theme_settings = ($theme_name && isset($theme_data[$theme_name]->info['settings'])) ? $theme_data[$theme_name]->info['settings'] : array();
  65. $defaults = array_merge(mobile_jquery_default_theme_settings(), $info_theme_settings);
  66. // Set combined default & saved theme settings
  67. variable_set($theme_setting_name, array_merge($defaults, $settings));
  68. // Force theme settings refresh
  69. theme_get_setting('', TRUE);
  70. }
  71. }
  72. /**
  73. * Implementation of THEMEHOOK_settings() function.
  74. *
  75. * @param $saved_settings
  76. * array An array of saved settings for this theme.
  77. * @return
  78. * array A form array.
  79. */
  80. function mobile_jquery_settings($saved_settings) {
  81. global $base_url;
  82. //add some jquery awesomesauce to help the global style functionality
  83. drupal_add_js(drupal_get_path('theme', 'mobile_jquery') . '/scripts/mobile_jquery.settings.js');
  84. // Get theme name from url (admin/.../theme_name)
  85. $theme_name = arg(count(arg()) - 1);
  86. // Combine default theme settings from .info file & theme-settings.php
  87. $theme_data = list_themes(); // get data for all themes
  88. $info_theme_settings = ($theme_name && isset($theme_data[$theme_name]->info['settings'])) ? $theme_data[$theme_name]->info['settings'] : array();
  89. $defaults = array_merge(mobile_jquery_default_theme_settings(), $info_theme_settings);
  90. // Combine default and saved theme settings
  91. $settings = array_merge($defaults, $saved_settings);
  92. //Theming Styles
  93. $boolean_options = array(
  94. 'true' => t('True'),
  95. 'false' => t('False'),
  96. );
  97. $theme_options = array(
  98. 'a' => t('Black'),
  99. 'b' => t('Blue'),
  100. 'c' => t('White'),
  101. 'd' => t('Grey'),
  102. 'e' => t('Yellow')
  103. );
  104. if (module_exists('jquerymobile_ui')) {
  105. $theme_options = array_merge($theme_options, _jquerymobile_ui_get_custom_themes());
  106. }
  107. $icon_options = array(
  108. 'arrow-r' => t('Right arrow'),
  109. 'arrow-l' => t('Left arrow'),
  110. 'arrow-u' => t('Up arrow'),
  111. 'arrow-d' => t('Down arrow'),
  112. 'delete' => t('Delete'),
  113. 'plus' => t('Plus'),
  114. 'minus' => t('Minus'),
  115. 'check' => t('Check'),
  116. 'gear' => t('Gear'),
  117. 'refresh' => t('Refresh'),
  118. 'forward' => t('Forward'),
  119. 'back' => t('Back'),
  120. 'grid' => t('Grid'),
  121. 'star' => t('Star'),
  122. 'alert' => t('Alert'),
  123. 'info' => t('Info'),
  124. 'home' => t('Home'),
  125. 'search' => t('Search'),
  126. );
  127. $position_options = array(
  128. 'inline' => t('inline'),
  129. 'fixed' => t('fixed'),
  130. );
  131. // Theme Settings Fieldset
  132. $form['theme_options'] = array(
  133. '#type' => 'fieldset',
  134. '#title' => t('Theme Settings'),
  135. '#collapsible' => TRUE,
  136. '#collapsed' => FALSE,
  137. );
  138. $form['theme_options']['rebuild_registry'] = array(
  139. '#type' => 'checkbox',
  140. '#title' => t('Rebuild theme registry for every page.'),
  141. '#description' => t('<em>Note: Not recommended for production use.</em>'),
  142. '#default_value' => $settings['rebuild_registry'],
  143. );
  144. $form['theme_options']['use_global'] = array(
  145. '#type' => 'checkbox',
  146. '#title' => t('Use global theme'),
  147. '#description' => t('This option allows all items to be set to the same swatch rather than set each item individually.'),
  148. '#default_value' => $settings['use_global'],
  149. );
  150. // GLOBAL
  151. $form['theme_options']['global_styles'] = array(
  152. '#type' => 'fieldset',
  153. '#title' => t('Global Settings'),
  154. '#collapsible' => TRUE,
  155. '#collapsed' => !$settings['use_global'],
  156. );
  157. $form['theme_options']['global_styles']['global_theme'] = array(
  158. '#type' => 'select',
  159. '#title' => t('Global Theme (data-theme)'),
  160. '#default_value' => $settings['global_theme'],
  161. '#options' => $theme_options,
  162. );
  163. $form['theme_options']['global_styles']['global_inset'] = array(
  164. '#type' => 'radios',
  165. '#title' => t('Inset Style Lists/Menus (data-inset)'),
  166. '#default_value' => $settings['global_inset'],
  167. '#options' => $boolean_options,
  168. );
  169. $form['theme_options']['global_styles']['global_spliticon'] = array(
  170. '#type' => 'select',
  171. '#title' => t('Split Button Icon (data-split-icon)'),
  172. '#default_value' => $settings['global_spliticon'],
  173. '#options' => $icon_options,
  174. );
  175. $form['theme_options']['global_styles']['global_icon'] = array(
  176. '#type' => 'select',
  177. '#title' => t('List/Menu Item Icon (data-icon)'),
  178. '#default_value' => $settings['global_icon'],
  179. '#options' => $icon_options,
  180. );
  181. //ITEM LISTS
  182. $form['theme_options']['item_list_styles'] = array(
  183. '#type' => 'fieldset',
  184. '#title' => t('Item List settings'),
  185. '#collapsible' => TRUE,
  186. '#collapsed' => $settings['use_global'],
  187. );
  188. $form['theme_options']['item_list_styles']['list_item_theme'] = array(
  189. '#type' => 'select',
  190. '#title' => t('Theme (data-theme)'),
  191. '#default_value' => $settings['list_item_theme'],
  192. '#options' => $theme_options,
  193. );
  194. $form['theme_options']['item_list_styles']['list_item_inset'] = array(
  195. '#type' => 'radios',
  196. '#title' => t('Inset Lists (data-inset)'),
  197. '#default_value' => $settings['list_item_inset'],
  198. '#options' => $boolean_options,
  199. );
  200. $form['theme_options']['item_list_styles']['list_item_icon'] = array(
  201. '#type' => 'select',
  202. '#title' => t('List Item Icon (data-icon)'),
  203. '#default_value' => $settings['list_item_icon'],
  204. '#options' => $icon_options,
  205. );
  206. $form['theme_options']['item_list_styles']['list_item_dividertheme'] = array(
  207. '#type' => 'select',
  208. '#title' => t('List Divider Theme (data-divider-theme)'),
  209. '#default_value' => $settings['list_item_dividertheme'],
  210. '#options' => $theme_options,
  211. );
  212. $form['theme_options']['item_list_styles']['list_item_counttheme'] = array(
  213. '#type' => 'select',
  214. '#title' => t('Count Bubble Theme (data-count-theme)'),
  215. '#default_value' => $settings['list_item_counttheme'],
  216. '#options' => $theme_options,
  217. );
  218. $form['theme_options']['item_list_styles']['list_item_splittheme'] = array(
  219. '#type' => 'select',
  220. '#title' => t('Split Button Theme (data-split-theme)'),
  221. '#default_value' => $settings['list_item_splittheme'],
  222. '#options' => $theme_options,
  223. );
  224. $form['theme_options']['item_list_styles']['list_item_spliticon'] = array(
  225. '#type' => 'select',
  226. '#title' => t('Slit Button Icon (data-split-icon)'),
  227. '#default_value' => $settings['list_item_spliticon'],
  228. '#options' => $icon_options,
  229. );
  230. //MENU ITEM LIST
  231. $form['theme_options']['menu_item_list_styles'] = array(
  232. '#type' => 'fieldset',
  233. '#title' => t('Menu Item Settings'),
  234. '#collapsible' => TRUE,
  235. '#collapsed' => $settings['use_global'],
  236. );
  237. $form['theme_options']['menu_item_list_styles']['menu_item_theme'] = array(
  238. '#type' => 'select',
  239. '#title' => t('Theme (data-theme)'),
  240. '#default_value' => $settings['menu_item_theme'],
  241. '#options' => $theme_options,
  242. );
  243. $form['theme_options']['menu_item_list_styles']['menu_item_inset'] = array(
  244. '#type' => 'radios',
  245. '#title' => t('Menu Item Inset (data-inset)'),
  246. '#default_value' => $settings['menu_item_inset'],
  247. '#options' => $boolean_options,
  248. );
  249. $form['theme_options']['menu_item_list_styles']['menu_item_icon'] = array(
  250. '#type' => 'select',
  251. '#title' => t('Menu Item Icon (data-icon)'),
  252. '#default_value' => $settings['menu_item_icon'],
  253. '#options' => $icon_options,
  254. );
  255. $form['theme_options']['menu_item_list_styles']['menu_item_dividertheme'] = array(
  256. '#type' => 'select',
  257. '#title' => t('Menu Divider Theme (data-divider-theme)'),
  258. '#default_value' => $settings['menu_item_dividertheme'],
  259. '#options' => $theme_options,
  260. );
  261. $form['theme_options']['menu_item_list_styles']['menu_item_counttheme'] = array(
  262. '#type' => 'select',
  263. '#title' => t('Count Bubble Theme (data-count-theme)'),
  264. '#default_value' => $settings['menu_item_counttheme'],
  265. '#options' => $theme_options,
  266. );
  267. $form['theme_options']['menu_item_list_styles']['menu_item_splittheme'] = array(
  268. '#type' => 'select',
  269. '#title' => t('Split Button Theme (data-split-theme)'),
  270. '#default_value' => $settings['menu_item_splittheme'],
  271. '#options' => $theme_options,
  272. );
  273. $form['theme_options']['menu_item_list_styles']['menu_item_spliticon'] = array(
  274. '#type' => 'select',
  275. '#title' => t('Split Item Icon (data-split-icon)'),
  276. '#default_value' => $settings['menu_item_spliticon'],
  277. '#options' => $icon_options,
  278. );
  279. //HEADER
  280. $form['theme_options']['header_styles'] = array(
  281. '#type' => 'fieldset',
  282. '#title' => t('Header Settings'),
  283. '#collapsible' => TRUE,
  284. '#collapsed' => $settings['use_global'],
  285. );
  286. $form['theme_options']['header_styles']['header_data_theme'] = array(
  287. '#type' => 'select',
  288. '#title' => t('Theme (data-theme)'),
  289. '#default_value' => $settings['header_data_theme'],
  290. '#options' => $theme_options,
  291. );
  292. $form['theme_options']['header_styles']['header_data_position'] = array(
  293. '#type' => 'select',
  294. '#title' => t('Position (data-position)'),
  295. '#default_value' => $settings['header_data_position'],
  296. '#options' => $position_options,
  297. );
  298. //CONTENT
  299. $form['theme_options']['content_styles'] = array(
  300. '#type' => 'fieldset',
  301. '#title' => t('Content Settings'),
  302. '#collapsible' => TRUE,
  303. '#collapsed' => $settings['use_global'],
  304. );
  305. $form['theme_options']['content_styles']['content_data_theme'] = array(
  306. '#type' => 'select',
  307. '#title' => t('Theme (data-theme)'),
  308. '#default_value' => $settings['content_data_theme'],
  309. '#options' => $theme_options,
  310. );
  311. //FOOTER
  312. $form['theme_options']['footer_styles'] = array(
  313. '#type' => 'fieldset',
  314. '#title' => t('Footer Settings'),
  315. '#collapsible' => TRUE,
  316. '#collapsed' => $settings['use_global'],
  317. );
  318. $form['theme_options']['footer_styles']['footer_data_theme'] = array(
  319. '#type' => 'select',
  320. '#title' => t('Theme (data-theme)'),
  321. '#default_value' => $settings['footer_data_theme'],
  322. '#options' => $theme_options,
  323. );
  324. $form['theme_options']['footer_styles']['footer_data_position'] = array(
  325. '#type' => 'select',
  326. '#title' => t('Position (data-position)'),
  327. '#default_value' => $settings['footer_data_position'],
  328. '#options' => $position_options,
  329. );
  330. // Return theme settings form
  331. return $form;
  332. }