editmenu.admin.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /**
  3. * @file
  4. * Settings of the editmenu.
  5. */
  6. /**
  7. * EditMenu settings page.
  8. */
  9. function editmenu_admin_settings() {
  10. $editmenu_path = drupal_get_path('module', 'editmenu');
  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']['editmenu_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('editmenu_menu', 'management:0'),
  24. '#description' => t('Select the menu to display.'),
  25. '#weight' => -1,
  26. );
  27. }
  28. $themes = file_scan_directory($editmenu_path . '/themes', '%.*%',
  29. array('key' => 'filename', 'recurse' => FALSE));
  30. $theme_selection = array('custom' => 'custom');
  31. foreach ($themes as $name => $ignore) {
  32. $theme_selection[$name] = $name;
  33. }
  34. $form['default_menu']['editmenu_theme'] = array(
  35. '#type' => 'select',
  36. '#title' => t('Theme'),
  37. '#options' => $theme_selection,
  38. '#default_value' => variable_get('editmenu_theme', 'original'),
  39. '#description' => t('Select which theme to use. If you specify custom, you need to define CSS in your theme.'),
  40. );
  41. // standard settings
  42. $form['settings'] = array(
  43. '#type' => 'fieldset',
  44. '#title' => t('Editmenu settings'),
  45. '#collapsible' => TRUE,
  46. '#collapsed' => TRUE,
  47. );
  48. $fix_options = array(
  49. 'scroll' => t('Scroll with page'),
  50. 'top' => t('Fix at the Top (Forces Body, Prepend)'),
  51. //'bottom' => t('Fix at the Bottom (Forces Body, Append)'), -- this requires another CSS... hmmm...
  52. );
  53. $form['settings']['editmenu_fix'] = array(
  54. '#type' => 'radios',
  55. '#title' => t('Scroll or fix menu'),
  56. '#options' => $fix_options,
  57. '#default_value' => variable_get('editmenu_fix', 'scroll'),
  58. '#description' => t('Select the mode to use. The default is to let the menu scroll with the page.')
  59. . '<br /><span style="color: red;">' . t('WARNING') . ':</span> '
  60. . t('The At the Top option prevents you from ever seeing the bottom of your drop-down menus when they are too long. In other words, if you have many modules installed, it is not unlikely that some drop down menus will not fit the height of the screen and the last few entries won\'t be accessible via Editmenu.'),
  61. );
  62. $form['settings']['editmenu_hide_delay'] = array(
  63. '#type' => 'textfield',
  64. '#title' => t('Hide delay'),
  65. '#size' => 4,
  66. '#default_value' => variable_get('editmenu_hide_delay', 800),
  67. '#description' => t('How long (in milliseconds) should a menu still appear after losing focus.'),
  68. );
  69. $form['settings']['editmenu_effect'] = array(
  70. '#type' => 'radios',
  71. '#title' => t('Show effect'),
  72. '#options' => array(
  73. 'opacity' => t('Fade'),
  74. 'height' => t('Slide'),
  75. 'none' => t('None')
  76. ),
  77. '#default_value' => variable_get('editmenu_effect', 'opacity'),
  78. '#description' => t('The effect used when displaying a menu.'),
  79. );
  80. $form['settings']['editmenu_effect_speed'] = array(
  81. '#type' => 'radios',
  82. '#title' => t('Show speed'),
  83. '#options' => array('slow' => t('Slow'), 'medium' => t('Medium'), 'fast' => t('Fast')),
  84. '#default_value' => variable_get('editmenu_effect_speed', 'fast'),
  85. '#description' => t('The speed of the effect, not used when "none" is set to show effect.'),
  86. );
  87. // advanced options
  88. $form['advanced'] = array(
  89. '#type' => 'fieldset',
  90. '#title' => t('Advanced settings'),
  91. '#collapsible' => TRUE,
  92. '#collapsed' => TRUE,
  93. );
  94. $form['advanced']['editmenu_uid1'] = array(
  95. '#type' => 'checkbox',
  96. '#title' => t('Show to User ID 1'),
  97. '#description' => t('Check this option to enable editmenu 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 editmenu for others.'),
  98. '#default_value' => variable_get('editmenu_uid1', 1),
  99. );
  100. $superfish_js = file_scan_directory($editmenu_path, '%^superfish-[0-9.]*\.js$%',
  101. array('key' => 'filename', 'recurse' => FALSE));
  102. $superfish = array('custom' => 'custom or theme');
  103. foreach ($superfish_js as $name => $ignore) {
  104. $superfish[$name] = $name;
  105. }
  106. $form['advanced']['editmenu_superfish_version'] = array(
  107. '#type' => 'select',
  108. '#title' => t('SuperFish Version'),
  109. '#options' => $superfish,
  110. '#description' => t('Select which version of SuperFish you prefer using. The choice "custom or theme" means that Editmenu does not include one of its own version of Superfish. It is expected that another module or your theme does so already.'),
  111. '#default_value' => variable_get('editmenu_superfish_version', 'superfish-1.4.1.js'),
  112. );
  113. $scope = array(
  114. 'header' => 'Header',
  115. 'footer' => 'Footer',
  116. );
  117. $form['advanced']['editmenu_menu_scope'] = array(
  118. '#type' => 'select',
  119. '#title' => t('Scope of editmenu variable'),
  120. '#options' => $scope,
  121. '#description' => t('By default, the <code>editmenu</code> variable is put in the footer (backward compatible.) It is possible to put it in the header instead.'),
  122. '#default_value' => variable_get('editmenu_menu_scope', 'footer'),
  123. );
  124. $form['advanced']['editmenu_cache_menu'] = array(
  125. '#type' => 'checkbox',
  126. '#title' => t('Cache the editmenu variable'),
  127. '#description' => t('The Editmenu now has the capability to cache the editmenu variable in a .js file. This accelerate the transfer by using the Browser cache.'),
  128. '#default_value' => variable_get('editmenu_cache_menu', TRUE),
  129. );
  130. $form['advanced']['editmenu_menubar_zindex'] = array(
  131. '#type' => 'textfield',
  132. '#title' => t('Menubar CSS z-index value'),
  133. '#description' => t('By default, the menubar CSS z-index is set to 9999. Some themes or other modules may require you to change this value. Use -1 to completely disable the z-index in the menubar. If this value is not set to -1, then the following z-index will not have any effect and can as well be set to -1.'),
  134. '#default_value' => variable_get('editmenu_menubar_zindex', 9999),
  135. );
  136. $form['advanced']['editmenu_dropdown_zindex'] = array(
  137. '#type' => 'textfield',
  138. '#title' => t('Dropdown CSS z-index value'),
  139. '#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 Editmenu 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.'),
  140. '#default_value' => variable_get('editmenu_dropdown_zindex', 9999),
  141. );
  142. $form['advanced']['editmenu_element'] = array(
  143. '#type' => 'textfield',
  144. '#title' => t('CSS selector to attach menu to'),
  145. '#default_value' => variable_get('editmenu_element', 'body'),
  146. '#description' => t('A valid CSS selector to attach the menu to. <em>Example: body, #primary, div.my-class</em>'),
  147. '#required' => TRUE,
  148. );
  149. $form['advanced']['editmenu_element_method'] = array(
  150. '#type' => 'radios',
  151. '#title' => t('Attach method'),
  152. '#options' => array(
  153. 'prepend' => t('Prepend'),
  154. 'append' => t('Append'),
  155. 'replace' => t('Replace'),
  156. ),
  157. '#default_value' => variable_get('editmenu_element_method', 'prepend'),
  158. '#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!'),
  159. '#required' => TRUE,
  160. );
  161. // when someone has many themes, this list grows big!
  162. $themes = list_themes();
  163. $use_list = count($themes) > 15;
  164. $form['advanced']['editmenu_exclusions'] = array(
  165. '#type' => $use_list ? 'select' : 'checkboxes',
  166. '#title' => t('Theme exclusions'),
  167. '#options' => drupal_map_assoc(array_keys($themes)),
  168. '#multiple' => $use_list,
  169. '#default_value' => variable_get('editmenu_exclusions', array()),
  170. '#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.'),
  171. );
  172. $form['advanced']['editmenu_detect_popup'] = array(
  173. '#type' => 'checkbox',
  174. '#title' => t('Detect pop-up windows'),
  175. '#default_value' => variable_get('editmenu_detect_popup', 1),
  176. '#description' => t("Choose whether EditMenu should attempt to detect if it is inside of a pop-up window. If enabled, EditMenu will not display if it is inside of a pop-up window."),
  177. );
  178. $form['advanced']['editmenu_visibility_operator'] = array(
  179. '#type' => 'radios',
  180. '#title' => t('Show block on specific pages'),
  181. '#default_value' => variable_get('editmenu_visibility_operator', 0),
  182. '#options' => array(
  183. 0 => t('Show on every page except the listed pages.'),
  184. 1 => t('Show on only the listed pages.'),
  185. ),
  186. );
  187. $form['advanced']['editmenu_visibility_pages'] = array(
  188. '#type' => 'textarea',
  189. '#title' => t('Pages'),
  190. '#default_value' => variable_get('editmenu_visibility_pages', ''),
  191. '#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.",
  192. array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
  193. '#wysiwyg' => FALSE,
  194. );
  195. $form['#validate'][] = 'editmenu_admin_settings_validate';
  196. $form['#submit'][] = 'editmenu_admin_settings_submit';
  197. return system_settings_form($form);
  198. }
  199. /**
  200. * Verify that we have settings that are sensical.
  201. */
  202. function editmenu_admin_settings_validate($form, &$form_state) {
  203. $values = &$form_state['values'];
  204. if ($values['editmenu_fix'] != 'scroll' && $values['editmenu_menubar_zindex'] < 1) {
  205. form_set_error('editmenu_menubar_zindex', t('In order to use a Fix mode, you want to increase the menubar z-index value to 1 or more.'));
  206. }
  207. }
  208. /**
  209. * Handle some special cases.
  210. */
  211. function editmenu_admin_settings_submit($form, $form_state) {
  212. // make sure we regenerate the CSS file
  213. variable_set('editmenu_css_filename', '');
  214. }
  215. // vim: ts=2 sw=2 et syntax=php