simplemenu.admin.inc 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Settings of the simplemenu.
  6. */
  7. /**
  8. * SimpleMenu settings page.
  9. */
  10. function simplemenu_admin_settings() {
  11. // menu selection
  12. $form['default_menu'] = array(
  13. '#type' => 'fieldset',
  14. '#title' => t('Menu settings'),
  15. '#collapsible' => TRUE,
  16. '#collapsed' => FALSE,
  17. );
  18. if (module_exists('menu')) {
  19. $form['default_menu']['simplemenu_menu'] = array(
  20. '#type' => 'select',
  21. '#title' => t('Menu'),
  22. '#options' => menu_parent_options(menu_get_menus(), array( 'mlid' => 0 )), // return complete tree;
  23. '#default_value' => variable_get('simplemenu_menu', 'navigation:0'),
  24. '#description' => t('Select the menu to display.'),
  25. );
  26. }
  27. if (module_exists('devel')) {
  28. $form['default_menu']['simplemenu_devel'] = array(
  29. '#type' => 'checkbox',
  30. '#title' => t('Add devel module links'),
  31. '#default_value' => variable_get('simplemenu_devel', 0),
  32. '#description' => t('Add devel module links for those users that can access the devel module.'),
  33. );
  34. }
  35. $form['default_menu']['simplemenu_theme'] = array(
  36. '#type' => 'select',
  37. '#title' => t('Theme'),
  38. '#options' => array(
  39. 'original' => t('original'),
  40. 'blackblue' => t('black & blue'),
  41. 'custom' => t('custom'),
  42. ),
  43. '#default_value' => variable_get('simplemenu_theme', 'original'),
  44. '#description' => t('Select which theme to use. If you specify custom, you need to define CSS in your theme.'),
  45. );
  46. // standard settings
  47. $form['settings'] = array(
  48. '#type' => 'fieldset',
  49. '#title' => t('Simplemenu settings'),
  50. '#collapsible' => TRUE,
  51. '#collapsed' => TRUE,
  52. );
  53. $fix_options = array(
  54. 'scroll' => t('Scroll with page'),
  55. 'top' => t('Fix at the Top (Forces Body, Prepend)'),
  56. //'bottom' => t('Fix at the Bottom (Forces Body, Append)'), -- this requires another CSS... hmmm...
  57. );
  58. $form['settings']['simplemenu_fix'] = array(
  59. '#type' => 'radios',
  60. '#title' => t('Scroll or fix menu'),
  61. '#options' => $fix_options,
  62. '#default_value' => variable_get('simplemenu_fix', 'scroll'),
  63. '#description' => t('Select the mode to use. The default is to let the menu scroll with the page.<br /><span style="color: red;">WARNING:</span> The At the Top/Bottom options prevent you from ever seeing the bottom of your drop-down menus. In other words, if you have many modules installed, it is not unlikely that your <em>Site configuration</em> menu will not fit the screen and the last few entries won\'t be accessible via Simplemenu.'),
  64. );
  65. $form['settings']['simplemenu_hide_delay'] = array(
  66. '#type' => 'textfield',
  67. '#title' => t('Hide delay'),
  68. '#size' => 4,
  69. '#default_value' => variable_get('simplemenu_hide_delay', 800),
  70. '#description' => t('How long (in milliseconds) should a menu still appear after losing focus.'),
  71. );
  72. $form['settings']['simplemenu_effect'] = array(
  73. '#type' => 'radios',
  74. '#title' => t('Show effect'),
  75. '#options' => array(
  76. 'opacity' => t('Fade'),
  77. 'height' => t('Slide'),
  78. 'none' => t('None')
  79. ),
  80. '#default_value' => variable_get('simplemenu_effect', 'opacity'),
  81. '#description' => t('The effect used when displaying a menu.'),
  82. );
  83. $form['settings']['simplemenu_effect_speed'] = array(
  84. '#type' => 'radios',
  85. '#title' => t('Show speed'),
  86. '#options' => array('slow' => t('Slow'), 'medium' => t('Medium'), 'fast' => t('Fast')),
  87. '#default_value' => variable_get('simplemenu_effect_speed', 'fast'),
  88. '#description' => t('The speed of the effect, not used when "none" is set to show effect.'),
  89. );
  90. // advanced options
  91. $form['advanced'] = array(
  92. '#type' => 'fieldset',
  93. '#title' => t('Advanced settings'),
  94. '#collapsible' => TRUE,
  95. '#collapsed' => TRUE,
  96. );
  97. $form['advanced']['simplemenu_uid1'] = array(
  98. '#type' => 'checkbox',
  99. '#title' => t('Show to User ID 1'),
  100. '#description' => t('Check this option to enable simplemenu for user 1 (superuser/administration). This is useful if you want to use a different menu (such as admin_menu) for the superuser/admin and simplemenu for others.'),
  101. '#default_value' => variable_get('simplemenu_uid1', 1),
  102. );
  103. $simplemenu_path = drupal_get_path('module', 'simplemenu');
  104. $superfish = file_scan_directory($simplemenu_path, '^superfish-[0-9.]*\.js$',
  105. array('.', '..', 'CVS', '.svn'), 0, FALSE, 'basename');
  106. foreach ($superfish as $name => $ignore) {
  107. $superfish[$name] = $name;
  108. }
  109. $form['advanced']['simplemenu_superfish_version'] = array(
  110. '#type' => 'select',
  111. '#title' => t('SuperFish Version'),
  112. '#options' => $superfish,
  113. '#description' => t('Select which version of SuperFish you prefer using.') .$simplemenu_path,
  114. '#default_value' => variable_get('simplemenu_superfish_version', 'superfish-1.4.1.js'),
  115. );
  116. $form['advanced']['simplemenu_menubar_zindex'] = array(
  117. '#type' => 'textfield',
  118. '#title' => t('Menubar CSS z-index value'),
  119. '#description' => t('By default, the menubar CSS z-index is set to 1. Some themes or other modules may require you to change this value. Use -1 to completely disable the z-index in the menubar.'),
  120. '#default_value' => variable_get('simplemenu_menubar_zindex', 9999),
  121. );
  122. $form['advanced']['simplemenu_dropdown_zindex'] = array(
  123. '#type' => 'textfield',
  124. '#title' => t('Dropdown CSS z-index value'),
  125. '#description' => t('By default, the dropdown CSS z-index is set to 9999. However, some themes and modules use an even larger z-index. For instance, the AddThis overlay is put at z-index 100,000 (although from my tests, it seems that they use a much higher z-index...). So if you want the Simplemenu to appear over the AddThis pop-up, you want to use a z-index which is even larger (i.e. 2,000,000 [do not enter the commas!].) On the other hand, 9999 may be too large for your site. You can use a smaller number if that works better for you. Use -1 to not remove the z-index from your dropdown.'),
  126. '#default_value' => variable_get('simplemenu_dropdown_zindex', 9999),
  127. );
  128. $form['advanced']['simplemenu_element'] = array(
  129. '#type' => 'textfield',
  130. '#title' => t('CSS selector to attach menu to'),
  131. '#default_value' => variable_get('simplemenu_element', 'body'),
  132. '#description' => t('A valid CSS selector to attach the menu to. <em>Example: body, #primary, div.my-class</em>'),
  133. '#required' => TRUE,
  134. );
  135. $form['advanced']['simplemenu_element_method'] = array(
  136. '#type' => 'radios',
  137. '#title' => t('Attach method'),
  138. '#options' => array(
  139. 'prepend' => t('Prepend'),
  140. 'append' => t('Append'),
  141. 'replace' => t('Replace'),
  142. ),
  143. '#default_value' => variable_get('simplemenu_element_method', 'prepend'),
  144. '#description' => t('Choose how the menu should be attached to the above selector.<br /><span style="color: red;">WARNING:</span> The Replace option should only be used with a specialized theme that offers a tag that is to be replaced by the simple menu. Make sure you don\'t use that option with your body!'),
  145. '#required' => TRUE,
  146. );
  147. // when someone has many themes, this list grows big!
  148. $themes = list_themes();
  149. $use_list = count($themes) > 15;
  150. $form['advanced']['simplemenu_exclusions'] = array(
  151. '#type' => $use_list ? 'select' : 'checkboxes',
  152. '#title' => t('Theme exclusions'),
  153. '#options' => drupal_map_assoc(array_keys($themes)),
  154. '#multiple' => $use_list,
  155. '#default_value' => variable_get('simplemenu_exclusions', array()),
  156. '#description' => t('Select which themes to <strong>not</strong> display the menu. Use this when you have a theme that displays its own admin navigation.'),
  157. );
  158. $form['advanced']['simplemenu_detect_popup'] = array(
  159. '#type' => 'checkbox',
  160. '#title' => t('Detect pop-up windows'),
  161. '#default_value' => variable_get('simplemenu_detect_popup', 1),
  162. '#description' => t("Choose whether SimpleMenu should attempt to detect if it is inside of a pop-up window. If enabled, SimpleMenu will not display if it is inside of a pop-up window."),
  163. );
  164. $form['advanced']['simplemenu_visibility_operator'] = array(
  165. '#type' => 'radios',
  166. '#title' => t('Show block on specific pages'),
  167. '#default_value' => variable_get('simplemenu_visibility_operator', 0),
  168. '#options' => array(
  169. 0 => t('Show on every page except the listed pages.'),
  170. 1 => t('Show on only the listed pages.'),
  171. ),
  172. );
  173. $form['advanced']['simplemenu_visibility_pages'] = array(
  174. '#type' => 'textarea',
  175. '#title' => t('Pages'),
  176. '#default_value' => variable_get('simplemenu_visibility_pages', ''),
  177. '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.",
  178. array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
  179. '#wysiwyg' => FALSE,
  180. );
  181. $form['#validate'][] = 'simplemenu_admin_settings_validate';
  182. $form['#submit'][] = 'simplemenu_admin_settings_submit';
  183. return system_settings_form($form);
  184. }
  185. /**
  186. * Verify that we have settings that are sensical.
  187. */
  188. function simplemenu_admin_settings_validate($form, &$form_state) {
  189. $values = &$form_state['values'];
  190. if ($values['simplemenu_fix'] != 'scroll' && $values['simplemenu_menubar_zindex'] < 1) {
  191. form_set_error('simplemenu_menubar_zindex', t('In order to use a Fix mode, you want to increase the menubar z-index value to 1 or more.'));
  192. }
  193. }
  194. /**
  195. * Handle some special cases.
  196. */
  197. function simplemenu_admin_settings_submit($form, $form_state) {
  198. // make sure we regenerate the CSS file
  199. variable_set('simplemenu_css_filename', '');
  200. }
  201. // vim: ts=2 sw=2 et syntax=php