Projet

Général

Profil

Paste
Télécharger (94,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / superfish / superfish.module @ 13755f8d

1
<?php
2

    
3
/**
4
 * @file
5
 * Enables the use of jQuery Superfish plugin for Drupal menus.
6
 */
7

    
8
/**
9
 * Implements hook_menu().
10
 */
11
function superfish_menu() {
12
  $items['admin/config/user-interface/superfish'] = array(
13
    'title' => 'Superfish',
14
    'description' => 'Configure Superfish Menus',
15
    'page callback' => 'drupal_get_form',
16
    'page arguments' => array('superfish_admin_settings'),
17
    'access arguments' => array('administer superfish'),
18
    'file' => 'superfish.admin.inc',
19
  );
20
  return $items;
21
}
22

    
23
/**
24
 * Implements hook_permission().
25
 */
26
function superfish_permission() {
27
  return array(
28
    'administer superfish' => array(
29
      'title' => t('Administer Superfish'),
30
    ),
31
  );
32
}
33

    
34
/**
35
 * Implements hook_help().
36
 */
37
function superfish_help($path, $arg) {
38
  $output = '';
39
  switch ($path) {
40
    case 'admin/modules#description':
41
      $output .= t('jQuery Superfish plugin for your Drupal menus.');
42
      break;
43
    case 'admin/config/user-interface/superfish':
44
      $output .= t('<p>Block-specific Superfish settings could be found at !link</p>', array('!link' => l('admin/structure/block', 'admin/structure/block')));
45
      break;
46
  }
47
  return $output;
48
}
49

    
50
/**
51
 * Implements hook_block_info().
52
 */
53
function superfish_block_info() {
54
  $blocks = array();
55
  $number = variable_get('superfish_number', 4);
56
  for ($i = 1; $i <= $number; $i++) {
57
    $blocks[$i] = array(
58
      'info' => variable_get('superfish_name_' . $i, 'Superfish ' . $i) . ' (Superfish)',
59
      'cache' => DRUPAL_NO_CACHE,
60
    );
61
  }
62
  return $blocks;
63
}
64

    
65
/**
66
 * Implements hook_block_configure().
67
 */
68
function superfish_block_configure($delta = 0) {
69
  $form = array();
70
  $form['superfish_name_' . $delta] = array(
71
    '#type' => 'textfield',
72
    '#title' => t('Block description'),
73
    '#description' => t('A brief description of your block. Used on the !link', array('!link' => l(t('Blocks administration page'), 'admin/structure/block'))),
74
    '#default_value' => variable_get('superfish_name_' . $delta, 'Superfish ' . $delta),
75
  );
76
  $form['sf-menu'] = array(
77
    '#type' => 'fieldset',
78
    '#title' => t('Menu'),
79
    '#collapsible' => TRUE,
80
    '#collapsed' => FALSE,
81
  );
82
  $form['sf-menu']['superfish_menu_' . $delta] = array(
83
    '#type' => 'select',
84
    '#title' => t('Menu parent'),
85
    '#description' => t('The menu you want to be displayed using Superfish.') . ' <em>(' . t('Default') . ': &lt;Main menu&gt;)</em>',
86
    '#default_value' => variable_get('superfish_menu_' . $delta, 'main-menu:0'),
87
    '#options' => menu_parent_options(menu_get_menus(), array('mlid' => 0)),
88
  );
89
  $form['sf-menu']['superfish_depth_' . $delta] = array(
90
    '#type' => 'select',
91
    '#title' => t('Menu depth'),
92
    '#description' => t('The number of child levels starting with the parent selected above. <strong>-1</strong> means all of them, <strong>0</strong> means none of them.') . ' <em>(' . t('Default') . ': -1)</em>',
93
    '#default_value' => variable_get('superfish_depth_' . $delta, -1),
94
    '#options' => drupal_map_assoc(range(-1, 50)),
95
  );
96
  $form['sf-menu']['superfish_expanded_' . $delta] = array(
97
    '#type' => 'checkbox',
98
    '#title' => t('Take "Expanded" option into effect.'),
99
    '#description' => t('By enabling this option, only parent menu items with <em>Expanded</em> option enabled will have their submenus appear.') . ' <em>(' . t('Default') . ': ' . t('disabled') . ')</em>',
100
    '#default_value' => variable_get('superfish_expanded_' . $delta, 0),
101
  );
102
  $form['sf-settings'] = array(
103
    '#type' => 'fieldset',
104
    '#title' => t('Superfish settings'),
105
    '#collapsible' => TRUE,
106
    '#collapsed' => FALSE,
107
  );
108
  $form['sf-settings']['superfish_type_' . $delta] = array(
109
    '#type' => 'select',
110
    '#title' => t('Menu type'),
111
    '#description' => '<em>(' . t('Default') . ': ' . t('Horizontal') . ')</em>',
112
    '#default_value' => variable_get('superfish_type_' . $delta, 'horizontal'),
113
    '#options' => array(
114
      'horizontal' => t('Horizontal'),
115
      'vertical' => t('Vertical'),
116
      'navbar' => t('NavBar'),
117
    ),
118
  );
119
  $form['sf-settings']['superfish_style_' . $delta] = array(
120
    '#type' => 'select',
121
    '#title' => t('Style'),
122
    '#description' => '<em>(' . t('Default') . ': ' . t('None') . ')</em>',
123
    '#default_value' => variable_get('superfish_style_' . $delta, 'none'),
124
    '#options' => superfish_styles(),
125
  );
126
  $form['sf-settings']['superfish_speed_' . $delta] = array(
127
    '#type' => 'textfield',
128
    '#title' => t('Animation speed'),
129
    '#description' => t('The speed of the animation either in <strong>milliseconds</strong> or pre-defined values (<strong>slow, normal, fast</strong>).') . ' <em>(' . t('Default') . ': fast)</em>',
130
    '#default_value' => variable_get('superfish_speed_' . $delta, 'fast'),
131
    '#size' => 15,
132
    '#required' => TRUE,
133
  );
134
  $form['sf-settings']['superfish_delay_' . $delta] = array(
135
    '#type' => 'textfield',
136
    '#title' => t('Mouse delay'),
137
    '#description' => t('The delay in <strong>milliseconds</strong> that the mouse can remain outside a sub-menu without it closing.') . ' <em>(' . t('Default') . ': 800)</em>',
138
    '#default_value' => variable_get('superfish_delay_' . $delta, 800),
139
    '#size' => 15,
140
  );
141
  $form['sf-settings']['superfish_pathclass_' . $delta] = array(
142
    '#type' => 'textfield',
143
    '#title' => t('Path class'),
144
    '#description' =>  t('The class you have applied to list items that lead to the current page.') . ' <em>(' . t('Default') . ': active-trail)</em><br />' . t('Change this <strong>only</strong> if you are <strong>totally sure</strong> of what you are doing.'),
145
    '#default_value' => variable_get('superfish_pathclass_' . $delta, 'active-trail'),
146
    '#size' => 15,
147
  );
148
  $form['sf-settings']['superfish_pathlevels_' . $delta] = array(
149
    '#type' => 'select',
150
    '#title' => t('Path levels'),
151
    '#description' => t('The amount of sub-menu levels that remain open or are restored using <strong>Path class</strong>.') . ' <em>(' . t('Default') . ': 1)</em>',
152
    '#default_value' => variable_get('superfish_pathlevels_' . $delta, 1),
153
    '#options' => drupal_map_assoc(range(0, 10)),
154
  );
155
  $form['sf-settings']['superfish_slide_' . $delta] = array(
156
    '#type' => 'select',
157
    '#title' => t('Slide-in effect'),
158
    '#description' => '<em>(' . t('Default') . ': ' . t('Vertical') . ')</em><br />' . ((count(superfish_effects()) == 4) ? t('jQuery Easing plugin is not installed.') . '<br />' . t('The plugin provides a handful number of animation effects, they can be used by uploading the \'jquery.easing.js\' file to the libraries directory within the \'easing\' directory (for example: sites/all/libraries/easing/jquery.easing.js). Refresh this page after the plugin is uploaded, this will make more effects available in the above list.') . '<br />' : '') . '<strong>' . t('Important') . ':</strong> ' . t('Easing effects require jQuery 1.6.1 or higher. If you need to update your jQuery to version 1.6.1 or higher, please use the jQuery Update module.'),
159
    '#default_value' => variable_get('superfish_slide_' . $delta, 'vertical'),
160
    '#options' => superfish_effects(),
161
  );
162
  $form['sf-settings']['superfish_arrow_' . $delta] = array(
163
    '#type' => 'checkbox',
164
    '#title' => t('Auto-arrows'),
165
    '#default_value' => variable_get('superfish_arrow_' . $delta, 1),
166
  );
167
  $form['sf-settings']['superfish_shadow_' . $delta] = array(
168
    '#type' => 'checkbox',
169
    '#title' => t('Drop shadows'),
170
    '#default_value' => variable_get('superfish_shadow_' . $delta, 1),
171
  );
172
  $form['sf-settings']['sf-more']  = array(
173
    '#type' => 'fieldset',
174
    '#title' => t('More options'),
175
    '#collapsible' => TRUE,
176
    '#collapsed' => TRUE,
177
  );
178
  $form['sf-settings']['sf-more']['superfish_use_link_theme_' . $delta] = array(
179
    '#type' => 'checkbox',
180
    '#title' => t('Use a theme function for hyperlinks.') . ' <em>(' . t('Default') . ': ' . t('enabled') . ')</em><br /><small>' . t('(Disabling this feature can result in performance improvements, depending on the number of hyperlinks in the menu.)') . '</small>',
181
    '#default_value' => variable_get('superfish_use_link_theme_' . $delta, 1),
182
  );
183
  $form['sf-settings']['sf-more']['superfish_use_item_theme_' . $delta] = array(
184
    '#type' => 'checkbox',
185
    '#title' => t('Use a theme function for menu items.') . ' <em>(' . t('Default') . ': ' . t('enabled') . ')</em><br /><small>' . t('(Disabling this feature can result in performance improvements, depending on the number of items in the menu.)') . '</small>',
186
    '#default_value' => variable_get('superfish_use_item_theme_' . $delta, 1),
187
  );
188
  $form['sf-plugins'] = array(
189
    '#type' => 'fieldset',
190
    '#title' => t('Superfish plugins'),
191
    '#collapsible' => TRUE,
192
    '#collapsed' => TRUE,
193
  );
194
  $form['sf-plugins']['superfish_bgf_' . $delta] = array(
195
    '#type' => 'checkbox',
196
    '#title' => t('Use jQuery BgiFrame plugin for this menu.'),
197
    '#description' => t('Helps ease the pain when having to deal with IE z-index issues.') . ' <em>(' . t('Default') . ': ' . t('disabled') . ')</em>',
198
    '#default_value' => variable_get('superfish_bgf_' . $delta, 0),
199
  );
200
  $form['sf-plugins']['superfish_spp_' . $delta] = array(
201
    '#type' => 'checkbox',
202
    '#title' => t('Use jQuery Supposition plugin for this menu.') . ' <sup>(' . t('Beta') . ')</sup>',
203
    '#description' => t('Relocates sub-menus when they would otherwise appear outside the browser window area.') . ' <em>(' . t('Default') . ': ' . t('enabled') . ')</em>',
204
    '#default_value' => variable_get('superfish_spp_' . $delta, 1),
205
  );
206
  $form['sf-plugins']['superfish_hid_' . $delta] = array(
207
    '#type' => 'checkbox',
208
    '#title' => t('Enable hoverIntent detection.'),
209
    '#description' => t('Prevents accidental firing of animations by waiting until the user\'s mouse slows down enough, hence determinig user\'s <em>intent</em>.') . ' <em>(' . t('Default') . ': ' . t('enabled') . ')</em>',
210
    '#default_value' => variable_get('superfish_hid_' . $delta, 1),
211
  );
212
  $form['sf-plugins']['sf-touchscreen'] = array(
213
    '#type' => 'fieldset',
214
    '#title' => t('sf-Touchscreen') . ' <sup>(' . t('Beta') . ')</sup>',
215
    '#description' => t('<strong>sf-Touchscreen</strong> provides touchscreen compatibility for your menus.') . ' <sup>(' . t('The first click on a parent hyperlink shows its children and the second click opens the hyperlink.') . ')</sup>',
216
    '#collapsible' => TRUE,
217
    '#collapsed' => FALSE,
218
  );
219
  $form['sf-plugins']['sf-touchscreen']['superfish_touch_' . $delta] = array(
220
    '#type' => 'radios',
221
    '#default_value' => variable_get('superfish_touch_' . $delta, 0),
222
    '#options' => array(
223
      0 => t('Disable') . '. <sup>(' . t('Default') . ')</sup>',
224
      1 => t('Enable jQuery sf-Touchscreen plugin for this menu.'),
225
      2 => t('Enable jQuery sf-Touchscreen plugin for this menu depending on the user\'s Web browser <strong>window width</strong>.'),
226
      3 => t('Enable jQuery sf-Touchscreen plugin for this menu depending on the user\'s Web browser <strong>user agent</strong>.'),
227
    ),
228
  );
229
  $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-windowwidth'] = array(
230
    '#type' => 'fieldset',
231
    '#title' => t('Window width settings'),
232
    '#description' => t('sf-Touchscreen will be enabled only if the width of user\'s Web browser window is smaller than the below value.') . '<br /><br />' . t('Please note that in most cases such a meta tag is necessary for this feature to work properly:') . '<br /><code>&lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;</code>',
233
    '#collapsible' => TRUE,
234
    '#collapsed' => TRUE,
235
  );
236
  $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-windowwidth']['superfish_touchbp_' . $delta] = array(
237
    '#type' => 'textfield',
238
    '#description' => t('Also known as "Breakpoint".') . ' <em>(' . t('Default') . ': 768)</em>',
239
    '#default_value' => variable_get('superfish_touchbp_' . $delta, 768),
240
    '#field_suffix' => t('pixels'),
241
    '#size' => 10,
242
  );
243
  $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent'] = array(
244
    '#type' => 'fieldset',
245
    '#title' => t('User agent settings'),
246
    '#collapsible' => TRUE,
247
    '#collapsed' => TRUE,
248
  );
249
  $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent']['superfish_touchua_' . $delta] = array(
250
    '#type' => 'radios',
251
    '#default_value' => variable_get('superfish_touchua_' . $delta, 0),
252
    '#options' => array(
253
      0 => t('Use the pre-defined list of the <strong>user agents</strong>.') . '<sup>(' . t('Default') . ') (' . t('Recommended') . ')</sup>',
254
      1 => t('Use the custom list of the <strong>user agents</strong>.'),
255
    ),
256
  );
257
  $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent']['superfish_touchual_' . $delta] = array(
258
    '#type' => 'textfield',
259
    '#title' => t('Custom list of the user agents'),
260
    '#description' => t('Could be partial or complete. (Asterisk separated)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Examples') . ':<ul><li>iPhone*Android*iPad <sup>(' . t('Recommended') . ')</sup></li><li>Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.0 * Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405</li></ul>' . ((isset($_SERVER['HTTP_USER_AGENT'])) ? '<br />' . t('<strong>UA string of the current Web browser:</strong>') . ' ' . $_SERVER['HTTP_USER_AGENT'] : ''),
261
    '#default_value' => variable_get('superfish_touchual_' . $delta, ''),
262
    '#size' => 100,
263
    '#maxlength' => 2000,
264
  );
265
  $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent']['superfish_touchuam_' . $delta] = array(
266
    '#type' => 'select',
267
    '#title' => t('<strong>User agent</strong> detection method'),
268
    '#description' => '<em>(' . t('Default') . ': ' . t('Client-side (JavaScript)') . ')</em>',
269
    '#default_value' => variable_get('superfish_touchuam_' . $delta, 0),
270
    '#options' => array(
271
      0 => t('Client-side (JavaScript)'),
272
      1 => t('Server-side (PHP)')
273
    ),
274
  );
275
  $form['sf-plugins']['sf-smallscreen'] = array(
276
    '#type' => 'fieldset',
277
    '#title' => t('sf-Smallscreen') . ' <sup>(' . t('Beta') . ')</sup>',
278
    '#description' => t('<strong>sf-Smallscreen</strong> provides small-screen compatibility for your menus.') . ' <sup>(' . t('Converts the dropdown into a &lt;select&gt; element.') . ')</sup>',
279
    '#collapsible' => TRUE,
280
    '#collapsed' => FALSE,
281
  );
282
  $form['sf-plugins']['sf-smallscreen']['superfish_small_' . $delta] = array(
283
    '#type' => 'radios',
284
    '#default_value' => variable_get('superfish_small_' . $delta, 2),
285
    '#options' => array(
286
      0 => t('Disable') . '.',
287
      1 => t('Enable jQuery sf-Smallscreen plugin for this menu.'),
288
      2 => t('Enable jQuery sf-Smallscreen plugin for this menu depending on the user\'s Web browser <strong>window width</strong>.') . ' <sup>(' . t('Default') . ')</sup>',
289
      3 => t('Enable jQuery sf-Smallscreen plugin for this menu depending on the user\'s Web browser <strong>user agent</strong>.'),
290
    ),
291
  );
292
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-windowwidth'] = array(
293
    '#type' => 'fieldset',
294
    '#title' => t('Window width settings'),
295
    '#description' => t('sf-Smallscreen will be enabled only if the width of user\'s Web browser window is smaller than the below value.') . '<br /><br />' . t('Please note that in most cases such a meta tag is necessary for this feature to work properly:') . '<br /><code>&lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;</code>',
296
    '#collapsible' => TRUE,
297
    '#collapsed' => TRUE,
298
  );
299
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-windowwidth']['superfish_smallbp_' . $delta] = array(
300
    '#type' => 'textfield',
301
    '#description' => t('Also known as "Breakpoint".') . ' <em>(' . t('Default') . ': 768)</em>',
302
    '#default_value' => variable_get('superfish_smallbp_' . $delta, 768),
303
    '#field_suffix' => t('pixels'),
304
    '#size' => 10,
305
  );
306
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent'] = array(
307
    '#type' => 'fieldset',
308
    '#title' => t('User agent settings'),
309
    '#collapsible' => TRUE,
310
    '#collapsed' => TRUE,
311
  );
312
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent']['superfish_smallua_' . $delta] = array(
313
    '#type' => 'radios',
314
    '#default_value' => variable_get('superfish_smallua_' . $delta, 0),
315
    '#options' => array(
316
      0 => t('Use the pre-defined list of the <strong>user agents</strong>.') . '<sup>(' . t('Default') . ') (' . t('Recommended') . ')</sup>',
317
      1 => t('Use the custom list of the <strong>user agents</strong>.'),
318
    ),
319
  );
320
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent']['superfish_smallual_' . $delta] = array(
321
    '#type' => 'textfield',
322
    '#title' => t('Custom list of the user agents'),
323
    '#description' => t('Could be partial or complete. (Asterisk separated)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Examples') . ':<ul><li>iPhone*Android*iPad <sup>(' . t('Recommended') . ')</sup></li><li>Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.0 * Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405</li></ul>' . ((isset($_SERVER['HTTP_USER_AGENT'])) ? '<br />' . t('<strong>UA string of the current Web browser:</strong>') . ' ' . $_SERVER['HTTP_USER_AGENT'] : ''),
324
    '#default_value' => variable_get('superfish_smallual_' . $delta, ''),
325
    '#size' => 100,
326
    '#maxlength' => 2000,
327
  );
328
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent']['superfish_smalluam_' . $delta] = array(
329
    '#type' => 'select',
330
    '#title' => t('<strong>User agent</strong> detection method:'),
331
    '#description' => '<em>(' . t('Default') . ': ' . t('Client-side (JavaScript)') . ')</em>',
332
    '#default_value' => variable_get('superfish_smalluam_' . $delta, 0),
333
    '#options' => array(
334
      0 => t('Client-side (JavaScript)'),
335
      1 => t('Server-side (PHP)')
336
    ),
337
  );
338
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select'] = array(
339
    '#type' => 'fieldset',
340
    '#title' => t('&lt;select&gt; settings'),
341
    '#collapsible' => TRUE,
342
    '#collapsed' => TRUE,
343
  );
344
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['superfish_smallset_' . $delta] = array(
345
    '#type' => 'textfield',
346
    '#title' => t('&lt;select&gt; title'),
347
    '#description' => t('By default the first item in the &lt;select&gt; element will be the name of the parent menu or the title of this block, you can change this by setting a custom title.') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Example') . ': <em> - ' . t('Main Menu') . ' - </em>.',
348
    '#default_value' => variable_get('superfish_smallset_' . $delta, ''),
349
    '#size' => 50,
350
    '#maxlength' => 500,
351
  );
352
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['superfish_smallasa_' . $delta] = array(
353
    '#type' => 'checkbox',
354
    '#title' => t('Add <em>selected</em> attribute to the &lt;option&gt; element with the class <strong>active</strong>'),
355
    '#description' => t('Makes pre-selected the item linked to the active page when the page loads.'),
356
    '#default_value' => variable_get('superfish_smallasa_' . $delta, 0),
357
  );
358
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more'] = array(
359
    '#type' => 'fieldset',
360
    '#title' => t('More'),
361
    '#collapsible' => TRUE,
362
    '#collapsed' => FALSE,
363
  );
364
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallcmc_' . $delta] = array(
365
    '#type' => 'checkbox',
366
    '#title' => t('Copy the main &lt;ul&gt; classes to the &lt;select&gt;.'),
367
    '#description' => ' <em>(' . t('Default') . ': ' . t('disabled') . ')</em>',
368
    '#default_value' => variable_get('superfish_smallcmc_' . $delta, 0),
369
  );
370
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallecm_' . $delta] = array(
371
    '#type' => 'textfield',
372
    '#title' => t('Exclude these classes from the &lt;select&gt; element'),
373
    '#description' => t('Comma separated') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em>',
374
    '#default_value' => variable_get('superfish_smallecm_' . $delta, ''),
375
    '#size' => 100,
376
    '#maxlength' => 1000,
377
    '#states' => array(
378
      'enabled' => array(
379
       ':input[name="superfish_smallcmc_' . $delta . '"]' => array('checked' => TRUE),
380
      ),
381
    ),
382
  );
383
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallchc_' . $delta] = array(
384
    '#type' => 'checkbox',
385
    '#title' => t('Copy the hyperlink classes to the &lt;option&gt; elements of the &lt;select&gt;.'),
386
    '#description' => ' <em>(' . t('Default') . ': ' . t('disabled') . ')</em>',
387
    '#default_value' => variable_get('superfish_smallchc_' . $delta, 0),
388
  );
389
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallech_' . $delta] = array(
390
    '#type' => 'textfield',
391
    '#title' => t('Exclude these classes from the &lt;option&gt; elements of the &lt;select&gt;'),
392
    '#description' => t('Comma separated') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em>',
393
    '#default_value' => variable_get('superfish_smallech_' . $delta, ''),
394
    '#size' => 100,
395
    '#maxlength' => 1000,
396
    '#states' => array(
397
      'enabled' => array(
398
       ':input[name="superfish_smallchc_' . $delta . '"]' => array('checked' => TRUE),
399
      ),
400
    ),
401
  );
402
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallicm_' . $delta] = array(
403
    '#type' => 'textfield',
404
    '#title' => t('Include these classes in the &lt;select&gt; element'),
405
    '#description' => t('Comma separated') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em>',
406
    '#default_value' => variable_get('superfish_smallicm_' . $delta, ''),
407
    '#size' => 100,
408
    '#maxlength' => 1000,
409
  );
410
  $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallich_' . $delta] = array(
411
    '#type' => 'textfield',
412
    '#title' => t('Include these classes in the &lt;option&gt; elements of the &lt;select&gt;'),
413
    '#description' => t('Comma separated') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em>',
414
    '#default_value' => variable_get('superfish_smallich_' . $delta, ''),
415
    '#size' => 100,
416
    '#maxlength' => 1000,
417
  );
418
  $form['sf-plugins']['sf-supersubs'] = array(
419
    '#type' => 'fieldset',
420
    '#title' => t('Supersubs'),
421
    '#description' => t('<strong>Supersubs</strong> makes it possible to define custom widths for your menus.'),
422
    '#collapsible' => TRUE,
423
    '#collapsed' => FALSE,
424
  );
425
  $form['sf-plugins']['sf-supersubs']['superfish_supersubs_' . $delta] = array(
426
    '#type' => 'checkbox',
427
    '#title' => t('Enable Supersubs for this menu.'),
428
    '#default_value' => variable_get('superfish_supersubs_' . $delta, 1),
429
  );
430
  $form['sf-plugins']['sf-supersubs']['superfish_minwidth_' . $delta] = array(
431
    '#type' => 'textfield',
432
    '#title' => t('Minimum width'),
433
    '#description' => t('Minimum width for sub-menus, in <strong>em</strong> units.') . ' <em>(' . t('Default') . ': 12)</em>',
434
    '#default_value' => variable_get('superfish_minwidth_' . $delta, '12'),
435
    '#size' => 20,
436
    '#required' => TRUE,
437
  );
438
  $form['sf-plugins']['sf-supersubs']['superfish_maxwidth_' . $delta] = array(
439
    '#type' => 'textfield',
440
    '#title' => t('Maximum width'),
441
    '#description' => t('Maximum width for sub-menus, in <strong>em</strong> units.') . ' <em>(' . t('Default') . ': 27)</em>',
442
    '#default_value' => variable_get('superfish_maxwidth_' . $delta, '27'),
443
    '#size' => 20,
444
    '#required' => TRUE,
445
  );
446
  $form['sf-megamenu'] = array(
447
    '#type' => 'fieldset',
448
    '#title' => t('Multi-column sub-menus') . ' <sup>(' . t('Beta') . ')</sup>',
449
    '#collapsible' => TRUE,
450
    '#collapsed' => TRUE,
451
  );
452
  $form['sf-megamenu']['superfish_multicolumn_' . $delta] = array(
453
    '#type' => 'checkbox',
454
    '#title' => t('Enable multi-column sub-menus.'),
455
    '#default_value' => variable_get('superfish_multicolumn_' . $delta, 0),
456
  );
457
  $form['sf-megamenu']['superfish_mcexclude_' . $delta] = array(
458
    '#type' => 'textfield',
459
    '#title' => t('Exclude below menu items'),
460
    '#description' => t('Enter the ID number of the parent menu item you <strong>do not</strong> want multi-column sub-menus for. (Comma separated)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Example') . ': 5,10,20',
461
    '#default_value' => variable_get('superfish_mcexclude_' . $delta, ''),
462
    '#size' => 50,
463
  );
464
  $form['sf-megamenu']['superfish_mcdepth_' . $delta] = array(
465
    '#type' => 'select',
466
    '#title' => t('Start from depth'),
467
    '#description' => t('The depth of the first instance of multi-column sub-menus.') . ' <em>(' . t('Default') . ': 1)</em>',
468
    '#default_value' => variable_get('superfish_mcdepth_' . $delta, 1),
469
    '#options' => drupal_map_assoc(range(1, 10)),
470
  );
471
  $form['sf-megamenu']['superfish_mclevels_' . $delta] = array(
472
    '#type' => 'select',
473
    '#title' => t('Levels'),
474
    '#description' => t('The amount of sub-menu levels that will be included in the multi-column sub-menu.') . ' <em>(' . t('Default') . ': 1)</em>',
475
    '#default_value' => variable_get('superfish_mclevels_' . $delta, 1),
476
    '#options' => drupal_map_assoc(range(1, 10)),
477
  );
478
  $form['sf-advanced-html'] = array(
479
    '#type' => 'fieldset',
480
    '#title' => t('Advanced HTML settings'),
481
    '#collapsible' => TRUE,
482
    '#collapsed' => TRUE,
483
  );
484
  $form['sf-advanced-html']['sf-hyperlinks'] = array(
485
    '#type' => 'fieldset',
486
    '#title' => t('Hyperlinks'),
487
    '#collapsible' => TRUE,
488
    '#collapsed' => FALSE,
489
  );
490
  $form['sf-advanced-html']['sf-hyperlinks']['superfish_hhldescription_' . $delta] = array(
491
    '#type' => 'checkbox',
492
    '#title' => t('Hide hyperlink descriptions ("title" attribute)') . ' <em>(' . t('Default') . ': ' . t('disabled') . ')</em>',
493
    '#description' => t('(Enabling this feature makes the below settings ineffective.)'),
494
    '#default_value' => variable_get('superfish_hhldescription_' . $delta, 0),
495
  );
496
  $form['sf-advanced-html']['sf-hyperlinks']['sf-hyperlinktexts'] = array(
497
    '#type' => 'fieldset',
498
    '#title' => t('Hyperlink texts'),
499
    '#collapsible' => TRUE,
500
    '#collapsed' => FALSE,
501
  );
502
  $form['sf-advanced-html']['sf-hyperlinks']['sf-hyperlinktexts']['superfish_hldescription_' . $delta] = array(
503
    '#type' => 'checkbox',
504
    '#title' => t('Insert hyperlink descriptions ("title" attribute) into hyperlink texts.'),
505
    '#default_value' => variable_get('superfish_hldescription_' . $delta, 0),
506
  );
507
  $form['sf-advanced-html']['sf-hyperlinks']['sf-hyperlinktexts']['superfish_hldmenus_' . $delta] = array(
508
    '#type' => 'textfield',
509
    '#title' => t('Limit to below menu items'),
510
    '#description' => t('Enter menu item ID\'s. Leave empty to include all menus. (Comma separated)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Example') . ': 5,10,20',
511
    '#default_value' => variable_get('superfish_hldmenus_' . $delta, ''),
512
    '#size' => 50,
513
  );
514
  $form['sf-advanced-html']['sf-hyperlinks']['sf-hyperlinktexts']['superfish_hldexclude_' . $delta] = array(
515
    '#type' => 'textfield',
516
    '#title' => t('Exclude below menu items'),
517
    '#description' => t('Enter the ID of the menu items you <strong>do not</strong> want to link descriptions for. (Comma separated)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Example') . ': 5,10,20',
518
    '#default_value' => variable_get('superfish_hldexclude_' . $delta, ''),
519
    '#size' => 50,
520
  );
521
  $form['sf-advanced-html']['sf-html-wrappers'] = array(
522
    '#type' => 'fieldset',
523
    '#title' => t('HTML wrappers'),
524
    '#collapsible' => TRUE,
525
    '#collapsed' => FALSE,
526
  );
527
  $form['sf-advanced-html']['sf-html-wrappers']['superfish_wrapmul_' . $delta] = array(
528
    '#type' => 'textfield',
529
    '#title' => t('Around the main &lt;UL&gt;'),
530
    '#description' => t('Insert extra codes <strong>before</strong> and\or <strong>after</strong> the main UL. (Comma separated).') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Examples') . ': <ul><li>&lt;h3&gt;Discover the universe!&lt;/h3&gt;,</li><li>&lt;h3&gt;Hello there!&lt;/h3&gt;,&lt;div style="clear:both"&gt;&lt;/div&gt;</li><li>,&lt;div style="clear:both"&gt;&lt;/div&gt;</li></ul>',
531
    '#default_value' => variable_get('superfish_wrapmul_' . $delta, ''),
532
    '#size' => 100,
533
    '#maxlength' => 1000,
534
  );
535
  $form['sf-advanced-html']['sf-html-wrappers']['superfish_wrapul_' . $delta] = array(
536
    '#type' => 'textfield',
537
    '#title' => t('Around the &lt;UL&gt; content'),
538
    '#description' => t('Insert extra codes <strong>before</strong> and\or <strong>after</strong> the ULs. (Comma separated).') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Examples') . ': <ul><li>&lt;h3&gt;Discover the universe!&lt;/h3&gt;,</li><li>&lt;h3&gt;Hello there!&lt;/h3&gt;,&lt;div style="clear:both"&gt;&lt;/div&gt;</li><li>,&lt;div style="clear:both"&gt;&lt;/div&gt;</li></ul>',
539
    '#default_value' => variable_get('superfish_wrapul_' . $delta, ''),
540
    '#size' => 100,
541
    '#maxlength' => 1000,
542
  );
543
  $form['sf-advanced-html']['sf-html-wrappers']['superfish_wraphl_' . $delta] = array(
544
    '#type' => 'textfield',
545
    '#title' => t('Around the hyperlinks'),
546
    '#description' => t('Insert HTML objects <strong>before</strong> and\or <strong>after</strong> hyperlinks. (Comma separated)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Examples') . ': <ul><li>&lt;span class="background-left"&gt;&lt;span class="background-right"&gt;,&lt;/span&gt;&lt;/span&gt;</li><li>&lt;img src="example.jpg" width="24" height="24" alt="example" title="example" /&gt;,</li><li>,&lt;span class="custom-arrow"&gt;>&lt;/span&gt;</li></ul>',
547
    '#default_value' => variable_get('superfish_wraphl_' . $delta, ''),
548
    '#size' => 100,
549
    '#maxlength' => 1000,
550
  );
551
  $form['sf-advanced-html']['sf-html-wrappers']['superfish_wraphlt_' . $delta] = array(
552
    '#type' => 'textfield',
553
    '#title' => t('Around the hyperlinks content'),
554
    '#description' => t('Insert extra codes <strong>before</strong> and\or <strong>after</strong> the text in hyperlinks. (Comma separated)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Examples') . ': <ul><li>&lt;span class="background-left"&gt;&lt;span class="background-right"&gt;,&lt;/span&gt;&lt;/span&gt;</li><li>&lt;img src="example.jpg" width="24" height="24" alt="example" title="example" /&gt;,</li><li>,&lt;span class="custom-arrow"&gt;>&lt;/span&gt;</li></ul>',
555
    '#default_value' => variable_get('superfish_wraphlt_' . $delta, ''),
556
    '#size' => 100,
557
    '#maxlength' => 1000,
558
  );
559
  $form['sf-advanced-css'] = array(
560
    '#type' => 'fieldset',
561
    '#title' => t('Advanced CSS settings'),
562
    '#collapsible' => TRUE,
563
    '#collapsed' => TRUE,
564
  );
565
  $form['sf-advanced-css']['sf-helper-classes'] = array(
566
    '#type' => 'fieldset',
567
    '#title' => t('Helper classes'),
568
    '#collapsible' => TRUE,
569
    '#collapsed' => FALSE,
570
  );
571
  $form['sf-advanced-css']['sf-helper-classes']['superfish_firstlast_' . $delta] = array(
572
    '#type' => 'checkbox',
573
    '#title' => t('Add <strong>first \ middle \ last</strong> classes.'),
574
    '#default_value' => variable_get('superfish_firstlast_' . $delta, 1),
575
  );
576
  $form['sf-advanced-css']['sf-helper-classes']['superfish_zebra_' . $delta] = array(
577
    '#type' => 'checkbox',
578
    '#title' => t('Add <strong>odd \ even</strong> classes.'),
579
    '#default_value' => variable_get('superfish_zebra_' . $delta, 1),
580
  );
581
  $form['sf-advanced-css']['sf-helper-classes']['superfish_dfirstlast_' . $delta] = array(
582
    '#type' => 'checkbox',
583
    '#title' => t('Do <strong>not</strong> add <strong>first \ middle \ last</strong> classes to single menu items.'),
584
    '#default_value' => variable_get('superfish_dfirstlast_' . $delta, 0),
585
  );
586
  $form['sf-advanced-css']['sf-helper-classes']['superfish_dzebra_' . $delta] = array(
587
    '#type' => 'checkbox',
588
    '#title' => t('Do <strong>not</strong> add <strong>odd \ even</strong> classes to single menu items.'),
589
    '#default_value' => variable_get('superfish_dzebra_' . $delta, 0),
590
  );
591
  $form['sf-advanced-css']['sf-helper-classes']['superfish_itemcount_' . $delta] = array(
592
    '#type' => 'checkbox',
593
    '#title' => t('Add <strong>item count</strong> class to menu items.') . '<em>(sf-item-1, sf-item-2, sf-item-3, ...)</em>',
594
    '#default_value' => variable_get('superfish_itemcount_' . $delta, 1),
595
  );
596
  $form['sf-advanced-css']['sf-helper-classes']['superfish_itemcounter_' . $delta] = array(
597
    '#type' => 'checkbox',
598
    '#title' => t('Add <strong>children counter</strong> classes to menu items.') . '<em>(sf-total-children-7 sf-parent-children-4 sf-single-children-3, ...)</em>',
599
    '#default_value' => variable_get('superfish_itemcounter_' . $delta, 1),
600
  );
601
  $form['sf-advanced-css']['sf-helper-classes']['superfish_itemdepth_' . $delta] = array(
602
    '#type' => 'checkbox',
603
    '#title' => t('Add <strong>item depth</strong> class to menu items and their hyperlinks.') . '<em>(sf-depth-1, sf-depth-2, sf-depth-3, ...)</em>',
604
    '#default_value' => variable_get('superfish_itemdepth_' . $delta, 1),
605
  );
606
  $form['sf-advanced-css']['sf-custom-classes'] = array(
607
    '#type' => 'fieldset',
608
    '#title' => t('Custom classes'),
609
    '#collapsible' => TRUE,
610
    '#collapsed' => FALSE,
611
  );
612
  $form['sf-advanced-css']['sf-custom-classes']['superfish_ulclass_' . $delta] = array(
613
    '#type' => 'textfield',
614
    '#title' => t('For the main UL'),
615
    '#description' => t('(Space separated, without dots)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Example') . ': top-menu category-science',
616
    '#default_value' => variable_get('superfish_ulclass_' . $delta, ''),
617
    '#size' => 50,
618
    '#maxlength' => 1000,
619
  );
620
  $form['sf-advanced-css']['sf-custom-classes']['superfish_liclass_' . $delta] = array(
621
    '#type' => 'textfield',
622
    '#title' => t('For the list items'),
623
    '#description' => t('(Space separated, without dots)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Example') . ': science-sub',
624
    '#default_value' => variable_get('superfish_liclass_' . $delta, ''),
625
    '#size' => 50,
626
    '#maxlength' => 1000,
627
  );
628
  $form['sf-advanced-css']['sf-custom-classes']['superfish_hlclass_' . $delta] = array(
629
    '#type' => 'textfield',
630
    '#title' => t('For the hyperlinks'),
631
    '#description' => t('(Space separated, without dots)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Example') . ': science-link',
632
    '#default_value' => variable_get('superfish_hlclass_' . $delta, ''),
633
    '#size' => 50,
634
    '#maxlength' => 1000,
635
  );
636
  $form['sf-advanced-css']['sf-extra-css'] = array(
637
    '#type' => 'fieldset',
638
    '#title' => t('Extra CSS'),
639
    '#collapsible' => TRUE,
640
    '#collapsed' => FALSE,
641
  );
642
  $form['sf-advanced-css']['sf-extra-css']['superfish_pathcss_' . $delta] = array(
643
    '#type' => 'textfield',
644
    '#title' => t('Path to CSS file(s)'),
645
    '#description' => t('Include extra CSS file(s). (Comma separated)') . ' <em>(' . t('Default') . ': ' . t('empty') . ')</em><br />' . t('Examples') . ': <ul><li>sites/all/files/example.css</li><li>sites/all/files/example.css,sites/all/files/example2.css</li></ul>',
646
    '#default_value' => variable_get('superfish_pathcss_' . $delta, ''),
647
    '#size' => 100,
648
    '#maxlength' => 1000,
649
  );
650
  return $form;
651
}
652

    
653
/**
654
 * Implements hook_block_save().
655
 */
656
function superfish_block_save($delta = 0, $edit = array()) {
657
  variable_set('superfish_name_' . $delta, $edit['superfish_name_' . $delta]);
658
  variable_set('superfish_menu_' . $delta, $edit['superfish_menu_' . $delta]);
659
  variable_set('superfish_depth_' . $delta, $edit['superfish_depth_' . $delta]);
660
  variable_set('superfish_type_' . $delta, $edit['superfish_type_' . $delta]);
661
  variable_set('superfish_style_' . $delta, $edit['superfish_style_' . $delta]);
662
  variable_set('superfish_speed_' . $delta, $edit['superfish_speed_' . $delta]);
663
  variable_set('superfish_delay_' . $delta, $edit['superfish_delay_' . $delta]);
664
  variable_set('superfish_pathclass_' . $delta, $edit['superfish_pathclass_' . $delta]);
665
  variable_set('superfish_pathlevels_' . $delta, $edit['superfish_pathlevels_' . $delta]);
666
  variable_set('superfish_slide_' . $delta, $edit['superfish_slide_' . $delta]);
667
  variable_set('superfish_shadow_' . $delta, $edit['superfish_shadow_' . $delta]);
668
  variable_set('superfish_arrow_' . $delta, $edit['superfish_arrow_' . $delta]);
669
  variable_set('superfish_expanded_' . $delta, $edit['superfish_expanded_' . $delta]);
670
  variable_set('superfish_bgf_' . $delta, $edit['superfish_bgf_' . $delta]);
671
  variable_set('superfish_spp_' . $delta, $edit['superfish_spp_' . $delta]);
672
  variable_set('superfish_hid_' . $delta, $edit['superfish_hid_' . $delta]);
673
  variable_set('superfish_touch_' . $delta, $edit['superfish_touch_' . $delta]);
674
  variable_set('superfish_touchbp_' . $delta, $edit['superfish_touchbp_' . $delta]);
675
  variable_set('superfish_touchua_' . $delta, $edit['superfish_touchua_' . $delta]);
676
  variable_set('superfish_touchual_' . $delta, $edit['superfish_touchual_' . $delta]);
677
  variable_set('superfish_touchuam_' . $delta, $edit['superfish_touchuam_' . $delta]);
678
  variable_set('superfish_small_' . $delta, $edit['superfish_small_' . $delta]);
679
  variable_set('superfish_smallbp_' . $delta, $edit['superfish_smallbp_' . $delta]);
680
  variable_set('superfish_smallua_' . $delta, $edit['superfish_smallua_' . $delta]);
681
  variable_set('superfish_smallual_' . $delta, $edit['superfish_smallual_' . $delta]);
682
  variable_set('superfish_smalluam_' . $delta, $edit['superfish_smalluam_' . $delta]);
683
  variable_set('superfish_smallset_' . $delta, $edit['superfish_smallset_' . $delta]);
684
  variable_set('superfish_smallasa_' . $delta, $edit['superfish_smallasa_' . $delta]);
685
  variable_set('superfish_smallcmc_' . $delta, $edit['superfish_smallcmc_' . $delta]);
686
  variable_set('superfish_smallecm_' . $delta, $edit['superfish_smallecm_' . $delta]);
687
  variable_set('superfish_smallchc_' . $delta, $edit['superfish_smallchc_' . $delta]);
688
  variable_set('superfish_smallech_' . $delta, $edit['superfish_smallech_' . $delta]);
689
  variable_set('superfish_smallicm_' . $delta, $edit['superfish_smallicm_' . $delta]);
690
  variable_set('superfish_smallich_' . $delta, $edit['superfish_smallich_' . $delta]);
691
  variable_set('superfish_supersubs_' . $delta, $edit['superfish_supersubs_' . $delta]);
692
  variable_set('superfish_minwidth_' . $delta, $edit['superfish_minwidth_' . $delta]);
693
  variable_set('superfish_maxwidth_' . $delta, $edit['superfish_maxwidth_' . $delta]);
694
  variable_set('superfish_multicolumn_' . $delta, $edit['superfish_multicolumn_' . $delta]);
695
  variable_set('superfish_mcexclude_' . $delta, $edit['superfish_mcexclude_' . $delta]);
696
  variable_set('superfish_mcdepth_' . $delta, $edit['superfish_mcdepth_' . $delta]);
697
  variable_set('superfish_mclevels_' . $delta, $edit['superfish_mclevels_' . $delta]);
698
  variable_set('superfish_firstlast_' . $delta, $edit['superfish_firstlast_' . $delta]);
699
  variable_set('superfish_zebra_' . $delta, $edit['superfish_zebra_' . $delta]);
700
  variable_set('superfish_dfirstlast_' . $delta, $edit['superfish_dfirstlast_' . $delta]);
701
  variable_set('superfish_dzebra_' . $delta, $edit['superfish_dzebra_' . $delta]);
702
  variable_set('superfish_itemcount_' . $delta, $edit['superfish_itemcount_' . $delta]);
703
  variable_set('superfish_itemcounter_' . $delta, $edit['superfish_itemcounter_' . $delta]);
704
  variable_set('superfish_itemdepth_' . $delta, $edit['superfish_itemdepth_' . $delta]);
705
  variable_set('superfish_use_link_theme_' . $delta, $edit['superfish_use_link_theme_' . $delta]);
706
  variable_set('superfish_use_item_theme_' . $delta, $edit['superfish_use_item_theme_' . $delta]);
707
  variable_set('superfish_hhldescription_' . $delta, $edit['superfish_hhldescription_' . $delta]);
708
  variable_set('superfish_hldescription_' . $delta, $edit['superfish_hldescription_' . $delta]);
709
  variable_set('superfish_hldmenus_' . $delta, $edit['superfish_hldmenus_' . $delta]);
710
  variable_set('superfish_hldexclude_' . $delta, $edit['superfish_hldexclude_' . $delta]);
711
  variable_set('superfish_wrapmul_' . $delta, $edit['superfish_wrapmul_' . $delta]);
712
  variable_set('superfish_wrapul_' . $delta, $edit['superfish_wrapul_' . $delta]);
713
  variable_set('superfish_wraphl_' . $delta, $edit['superfish_wraphl_' . $delta]);
714
  variable_set('superfish_wraphlt_' . $delta, $edit['superfish_wraphlt_' . $delta]);
715
  variable_set('superfish_ulclass_' . $delta, $edit['superfish_ulclass_' . $delta]);
716
  variable_set('superfish_liclass_' . $delta, $edit['superfish_liclass_' . $delta]);
717
  variable_set('superfish_hlclass_' . $delta, $edit['superfish_hlclass_' . $delta]);
718
  variable_set('superfish_pathcss_' . $delta, $edit['superfish_pathcss_' . $delta]);
719
  return;
720
}
721

    
722
/**
723
 * Implements hook_block_contents().
724
 */
725
function superfish_contents($delta = 0) {
726
  global $language;
727
  $block_css = $block_js = array();
728

    
729
  list($menu_name, $mlid) = explode(':', variable_get('superfish_menu_' . $delta, 'main-menu:0'));
730

    
731
  $sfsettings = $sfoptions = $sfplugins = array();
732
  $sfsettings['depth'] = variable_get('superfish_depth_' . $delta, '-1');
733
  $sfsettings['type'] = variable_get('superfish_type_' . $delta, 'horizontal');
734
  $sfsettings['style'] = variable_get('superfish_style_' . $delta, 'default');
735
  $sfsettings['expanded'] = variable_get('superfish_expanded_' . $delta, 0);
736
  $sfsettings['firstlast'] = variable_get('superfish_firstlast_' . $delta, 1);
737
  $sfsettings['zebra'] = variable_get('superfish_zebra_' . $delta, 1);
738
  $sfsettings['dfirstlast'] = variable_get('superfish_dfirstlast_' . $delta, 0);
739
  $sfsettings['dzebra'] = variable_get('superfish_dzebra_' . $delta, 0);
740
  $sfsettings['itemcount'] = variable_get('superfish_itemcount_' . $delta, 1);
741
  $sfsettings['itemcounter'] = variable_get('superfish_itemcounter_' . $delta, 1);
742
  $sfsettings['itemdepth'] = variable_get('superfish_itemdepth' . $delta, 1);
743
  $sfsettings['ulclass'] = variable_get('superfish_ulclass_' . $delta, '');
744
  $sfsettings['liclass'] = variable_get('superfish_liclass_' . $delta, '');
745
  $sfsettings['hlclass'] = variable_get('superfish_hlclass_' . $delta, '');
746
  $sfsettings['wrapmul'] = variable_get('superfish_wrapmul_' . $delta, '');
747
  $sfsettings['wrapul'] = variable_get('superfish_wrapul_' . $delta, '');
748
  $sfsettings['wraphl'] = variable_get('superfish_wraphl_' . $delta, '');
749
  $sfsettings['wraphlt'] = variable_get('superfish_wraphlt_' . $delta, '');
750
  $sfsettings['use_link_theme'] = variable_get('superfish_use_link_theme_' . $delta, 1);
751
  $sfsettings['use_item_theme'] = variable_get('superfish_use_item_theme_' . $delta, 1);
752
  $sfsettings['hidelinkdescription'] = variable_get('superfish_hhldescription_' . $delta, 0);
753
  $sfsettings['linkdescription'] = variable_get('superfish_hldescription_' . $delta, 0);
754
  $sfsettings['hldmenus'] = variable_get('superfish_hldmenus_' . $delta, '');
755
  $sfsettings['hldmenus'] = (strpos($sfsettings['hldmenus'], ',')) ? array_remove_empty(explode(',', $sfsettings['hldmenus'])) : $sfsettings['hldmenus'];
756
  $sfsettings['hldexclude'] = variable_get('superfish_hldexclude_' . $delta, '');
757
  $sfsettings['hldexclude'] = (strpos($sfsettings['hldexclude'], ',')) ? array_remove_empty(explode(',', $sfsettings['hldexclude'])) : $sfsettings['hldexclude'];
758
  $sfsettings['megamenu'] = variable_get('superfish_multicolumn_' . $delta, 0);
759
  $sfsettings['megamenu_depth'] = variable_get('superfish_mcdepth_' . $delta, 1);
760
  $sfsettings['megamenu_depth'] = ($sfsettings['type'] == 'navbar' && $sfsettings['megamenu_depth'] == 1) ? 2 : $sfsettings['megamenu_depth'];
761
  $sfsettings['megamenu_levels'] = variable_get('superfish_mclevels_' . $delta, 1) + $sfsettings['megamenu_depth'];
762
  $sfsettings['megamenu_exclude'] = variable_get('superfish_mcexclude_' . $delta, '');
763
  $sfsettings['megamenu_exclude'] = (strpos($sfsettings['megamenu_exclude'], ',')) ? array_remove_empty(explode(',', $sfsettings['megamenu_exclude'])) : $sfsettings['megamenu_exclude'];
764

    
765
  $sfoptions['pathClass'] = ($sfsettings['type'] == 'navbar') ? variable_get('superfish_pathclass_' . $delta, 'active-trail') : '';
766
  $sfoptions['pathLevels'] = (variable_get('superfish_pathlevels_' . $delta, 1) != 1) ? variable_get('superfish_pathlevels_' . $delta, 1) : '';
767
  $sfoptions['delay'] = (variable_get('superfish_delay_' . $delta, 800) != 800) ? variable_get('superfish_delay_' . $delta, 800) : '';
768
  $sfoptions['animation']['opacity'] = 'show';
769
  $slide = variable_get('superfish_slide_' . $delta, 'vertical');
770
  if (strpos($slide, '_') && superfish_library('javascript', 'jquery.easing.js', 'check')) {
771
    $slide = explode('_', $slide);
772
    switch ($slide[1]) {
773
      case 'vertical':
774
        $sfoptions['animation']['height'] = array('show', $slide[0]);
775
      break;
776
      case 'horizontal':
777
        $sfoptions['animation']['width'] = array('show', $slide[0]);
778
      break;
779
      case 'diagonal':
780
        $sfoptions['animation']['height'] = array('show', $slide[0]);
781
        $sfoptions['animation']['width'] = array('show', $slide[0]);
782
      break;
783
    }
784
    $block_js = array_merge($block_js, superfish_library('javascript', 'easing', 'add'));
785
  }
786
  else {
787
    switch ($slide) {
788
      case 'vertical':
789
        $sfoptions['animation']['height'] = 'show';
790
      break;
791
      case 'horizontal':
792
        $sfoptions['animation']['width'] = 'show';
793
      break;
794
      case 'diagonal':
795
        $sfoptions['animation']['height'] = 'show';
796
        $sfoptions['animation']['width'] = 'show';
797
      break;
798
    }
799
  }
800
  $speed = variable_get('superfish_speed_' . $delta, 'fast');
801
  $sfoptions['speed'] = ((is_numeric($speed)) ? (int)$speed : (($speed == ('slow' || 'normal' || 'fast')) ? '\'' . $speed . '\'': ''));
802
  $sfoptions['autoArrows'] = (variable_get('superfish_arrow_' . $delta, 1) == 1) ? TRUE : FALSE;
803
  $sfoptions['dropShadows'] = (variable_get('superfish_shadow_' . $delta, 1) == 1) ? TRUE : FALSE;
804
  if (variable_get('superfish_hid_' . $delta, 1) == 1 && superfish_library('javascript', 'jquery.hoverIntent.minified.js', 'check')) {
805
    $sfoptions['disableHI'] = FALSE;
806
    $block_js = array_merge($block_js, superfish_library('javascript', 'hoverIntent', 'add'));
807
  }
808
  else {
809
    $sfoptions['disableHI'] = FALSE;
810
  }
811
  $sfoptions = array_remove_empty($sfoptions);
812

    
813
  $touchscreen = variable_get('superfish_touch_' . $delta, 0);
814
  if ($touchscreen > 0  && superfish_library('javascript', 'sftouchscreen.js', 'check')) {
815
    $block_js = array_merge($block_js, superfish_library('javascript', 'sftouchscreen', 'add'));
816
    switch ($touchscreen) {
817
      case 1 :
818
        $sfplugins['touchscreen']['mode'] = 'always_active';
819
      break;
820
      case 2 :
821
        $sfplugins['touchscreen']['mode'] = 'window_width';
822
        $tsbp = variable_get('superfish_touchbp_' . $delta, 768);
823
        $sfplugins['touchscreen']['breakpoint'] = ($tsbp != 768) ? (int)$tsbp : '';
824
      break;
825
      case 3 :
826
        // Which method to use for UA detection.
827
        $tsuam = variable_get('superfish_touchuam_' . $delta, 0);
828
        $tsua = variable_get('superfish_touchua_' . $delta, 0);
829
        switch ($tsuam) {
830
          // Client-side.
831
          case 0 :
832
            switch ($tsua) {
833
              case 0 :
834
                $sfplugins['touchscreen']['mode'] = 'useragent_predefined';
835
              break;
836
              case 1 :
837
                $sfplugins['touchscreen']['mode'] = 'useragent_custom';
838
                $tsual = drupal_strtolower(variable_get('superfish_touchual_' . $delta, ''));
839
                if (strpos($tsual, '*')) {
840
                  $tsual = str_replace('*', '|', $tsual);
841
                }
842
                $sfplugins['touchscreen']['useragent'] = $tsual;
843
              break;
844
            }
845
          break;
846
          // Server-side.
847
          case 1 :
848
            if (isset($_SERVER['HTTP_USER_AGENT'])) {
849
              $hua = drupal_strtolower($_SERVER['HTTP_USER_AGENT']);
850
              switch ($tsua) {
851
                // Use the pre-defined list of mobile UA strings.
852
                case 0 :
853
                  if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $hua)) {
854
                    $sfplugins['touchscreen']['mode'] = 'always_active';
855
                  }
856
                break;
857
                // Use the custom list of UA strings.
858
                case 1 :
859
                  $tsual = drupal_strtolower(variable_get('superfish_touchual_' . $delta, ''));
860
                  $tsuac = array();
861
                  if (strpos($tsual, '*')) {
862
                    $tsual = explode('*', $tsual);
863
                    foreach ($tsual as $ua) {
864
                      $tsuac[] = (strpos($hua, $ua)) ? 1 : 0;
865
                    }
866
                  }
867
                  else {
868
                    $tsuac[] = (strpos($hua, $tsual)) ? 1 : 0;
869
                  }
870
                  if (in_array(1, $tsuac)) {
871
                    $sfplugins['touchscreen']['mode'] = 'always_active';
872
                  }
873
                break;
874
              }
875
            }
876
          break;
877
        }
878
      break;
879
    }
880
  }
881

    
882
  $smallscreen = variable_get('superfish_small_' . $delta, 2);
883
  if ($smallscreen > 0 && superfish_library('javascript', 'sfsmallscreen.js', 'check') == 1) {
884
    $block_js = array_merge($block_js, superfish_library('javascript', 'sfsmallscreen', 'add'));
885
    switch ($smallscreen) {
886
      case 1 :
887
        $sfplugins['smallscreen']['mode'] = 'always_active';
888
      break;
889
      case 2 :
890
        $sfplugins['smallscreen']['mode'] = 'window_width';
891
        $ssbp = variable_get('superfish_smallbp_' . $delta, 768);
892
        $sfplugins['smallscreen']['breakpoint'] = ($ssbp != 768) ? (int)$ssbp : '';
893
      break;
894
      case 3 :
895
        // Which method to use for UA detection.
896
        $ssuam = variable_get('superfish_smalluam_' . $delta, 0);
897
        $ssua = variable_get('superfish_smallua_' . $delta, 0);
898
        switch ($ssuam) {
899
          // Client-side.
900
          case 0 :
901
            switch ($ssua) {
902
              case 0 :
903
                $sfplugins['smallscreen']['mode'] = 'useragent_predefined';
904
              break;
905
              case 1 :
906
                $sfplugins['smallscreen']['mode'] = 'useragent_custom';
907
                $ssual = drupal_strtolower(variable_get('superfish_smallual_' . $delta, ''));
908
                if (strpos($ssual, '*')) {
909
                  $ssual = str_replace('*', '|', $ssual);
910
                }
911
                $sfplugins['smallscreen']['useragent'] = $ssual;
912
              break;
913
            }
914

    
915
          break;
916
          // Server-side.
917
          case 1 :
918
            if (isset($_SERVER['HTTP_USER_AGENT'])) {
919
              $hua = drupal_strtolower($_SERVER['HTTP_USER_AGENT']);
920
              switch ($ssua) {
921
                // Use the pre-defined list of mobile UA strings.
922
                case 0 :
923
                  if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $hua)) {
924
                    $sfplugins['smallscreen']['mode'] = 'always_active';
925
                  }
926
                break;
927
                // Use the custom list of UA strings.
928
                case 1 :
929
                  $ssual = drupal_strtolower(variable_get('superfish_smallual_' . $delta, ''));
930
                  $ssuac = array();
931
                  if (strpos($ssual, '*')) {
932
                    $ssual = explode('*', $ssual);
933
                    foreach ($ssual as $ua) {
934
                      $ssuac[] = (strpos($hua, $ua)) ? 1 : 0;
935
                    }
936
                  }
937
                  else {
938
                    $ssuac[] = (strpos($hua, $ssual)) ? 1 : 0;
939
                  }
940
                  if (in_array(1, $ssuac)) {
941
                    $sfplugins['smallscreen']['mode'] = 'always_active';
942
                  }
943
                break;
944
              }
945
            }
946
          break;
947
        }
948
      break;
949
    }
950
    $addselected = variable_get('superfish_smallasa_' . $delta, 0);
951
    $menuclasses = variable_get('superfish_smallcmc_' . $delta, 0);
952
    $hyperlinkclasses = variable_get('superfish_smallchc_' . $delta, 0);
953
    $excludeclass_menu = variable_get('superfish_smallecm_' . $delta, '');
954
    $excludeclass_hyperlink = variable_get('superfish_smallech_' . $delta, '');
955
    $includeclass_menu = variable_get('superfish_smallicm_' . $delta, '');
956
    $includeclass_hyperlink = variable_get('superfish_smallich_' . $delta, '');
957
    $sfplugins['smallscreen']['addSelected'] = ($addselected == 1) ? TRUE : FALSE;
958
    $sfplugins['smallscreen']['menuClasses'] = ($menuclasses == 1) ? TRUE : FALSE;
959
    $sfplugins['smallscreen']['hyperlinkClasses'] = ($hyperlinkclasses == 1) ? TRUE : FALSE;
960
    if ($menuclasses == 1 && !empty($excludeclass_menu)) {
961
      $sfplugins['smallscreen']['excludeClass_menu'] = $excludeclass_menu;
962
    }
963
    if ($hyperlinkclasses == 1 && !empty($excludeclass_hyperlink)) {
964
      $sfplugins['smallscreen']['excludeClass_hyperlink'] = $excludeclass_hyperlink;
965
    }
966
    if (!empty($includeclass_menu)) {
967
      $sfplugins['smallscreen']['includeClass_menu'] = $includeclass_menu;
968
    }
969
    if (!empty($includeclass_hyperlink)) {
970
      $sfplugins['smallscreen']['includeClass_hyperlink'] = $includeclass_hyperlink;
971
    }
972
  }
973

    
974
  if (variable_get('superfish_spp_' . $delta, 1) == 1 && superfish_library('javascript', 'supposition.js', 'check')) {
975
    $sfplugins['supposition'] = TRUE;
976
    $block_js = array_merge($block_js, superfish_library('javascript', 'supposition', 'add'));
977
  }
978
  else {
979
    $sfplugins['supposition'] = FALSE;
980
  }
981

    
982
  if (variable_get('superfish_bgf_' . $delta, 0) == 1 && superfish_library('javascript', 'jquery.bgiframe.min.js', 'check')) {
983
    $sfplugins['bgiframe'] = TRUE;
984
    $block_js = array_merge($block_js, superfish_library('javascript', 'bgiframe', 'add'));
985
  }
986
  else {
987
    $sfplugins['bgiframe'] = FALSE;
988
  }
989

    
990
  if (variable_get('superfish_supersubs_' . $delta, 1) == 1 && superfish_library('javascript', 'supersubs.js', 'check')) {
991
    $sfplugins['supersubs']['minWidth'] = variable_get('superfish_minwidth_' . $delta, '12');
992
    $sfplugins['supersubs']['maxWidth'] = variable_get('superfish_maxwidth_' . $delta, '27');
993
    $sfplugins['supersubs']['extraWidth'] = 1;
994
    $block_js = array_merge($block_js, superfish_library('javascript', 'supersubs', 'add'));
995
  }
996

    
997
  $vars = array(
998
    'id' => $delta,
999
    'menu_name' => $menu_name,
1000
    'mlid' => $mlid,
1001
    'sfsettings' => $sfsettings
1002
  );
1003
  if ($output = theme('superfish', $vars)) {
1004
    if (!empty($output['content'])) {
1005
      $output['content'] = array(
1006
        '#type' => 'markup',
1007
        '#markup' => filter_xss($output['content'], $allowed_tags = array('a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'big', 'blockquote', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'command', 'datalist', 'dd', 'del', 'details', 'dfn', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'legend', 'li', 'map', 'mark', 'meter', 'nav', 'noframes', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'ul', 'var', 'video', 'wbr')),
1008
        '#contextual_links' => array(
1009
          'superfish' => array('admin/structure/menu/manage', array($menu_name)),
1010
        )
1011
      );
1012

    
1013
      // Creating a title for the <select> title.
1014
      if ($smallscreen > 0 && superfish_library('javascript', 'sfsmallscreen.js', 'check')) {
1015
        $smallset = variable_get('superfish_smallset_' . $delta, '');
1016
        if (empty($smallset)) {
1017
          $sfplugins['smallscreen']['title'] = $output['subject'];
1018
        }
1019
        else {
1020
          $sfplugins['smallscreen']['title'] = $smallset;
1021
        }
1022
      }
1023
      $sfplugins = array_remove_empty($sfplugins);
1024

    
1025
      // Prepare the JavaScript settings.
1026
      $javascript['superfish'][$delta]['id'] = $delta;
1027
      $javascript['superfish'][$delta]['sf'] = isset($sfoptions) ? $sfoptions : array();
1028
      if (!empty($sfplugins)) {
1029
        $javascript['superfish'][$delta]['plugins'] = $sfplugins;
1030
      }
1031
      // Adding required Javascript.
1032
      if (superfish_library('javascript', 'superfish.js', 'check')) {
1033
        $block_js = array_merge($block_js, superfish_library('javascript', 'superfish.js', 'add'));
1034
        if (superfish_library('javascript', 'drupal_behavior', 'check')) {
1035
          $block_js = array_merge($block_js, array(array('data' => $javascript, 'type' => 'setting')));
1036
          $block_js = array_merge($block_js, superfish_library('javascript', 'drupal_behavior', 'add'));
1037
        }
1038
      }
1039

    
1040
      // Adding required CSS files
1041
      if (superfish_library('CSS', 'superfish', 'check')) {
1042
        $block_css = array_merge($block_css, superfish_library('CSS', 'superfish', 'add'));
1043
      }
1044
      if (superfish_library('CSS', $sfsettings['type'], 'check')) {
1045
        $block_css = array_merge($block_css, superfish_library('CSS', $sfsettings['type'], 'add'));
1046
      }
1047
      if ($sfsettings['style'] != 'none' && superfish_styles('path', $sfsettings['style']) != '') {
1048
        $block_css = array_merge($block_css, array(superfish_styles('path', $sfsettings['style']) => array('type' => 'file', 'weight' => 500)));
1049
      }
1050
      $extracss = variable_get('superfish_pathcss_' . $delta, '');
1051
      if ($extracss) {
1052
        if (strpos($extracss, ',')) {
1053
          $extracss = explode(',', $extracss);
1054
          foreach ($extracss as $c) {
1055
            $block_css = array_merge($block_css, array($c => array('type' => 'file', 'weight' => 510)));
1056
          }
1057
        }
1058
        else {
1059
          $block_css = array_merge($block_css, array($extracss => array('type' => 'file', 'weight' => 510)));
1060
        }
1061
      }
1062
      $output['content']['#attached'] = array(
1063
        'css' => $block_css,
1064
        'js' => $block_js,
1065
      );
1066
    }
1067
  }
1068
  return $output;
1069
}
1070

    
1071
/**
1072
 * Implements hook_block_view().
1073
 */
1074
function superfish_block_view($delta = 0) {
1075
  $block = superfish_contents($delta);
1076
  return $block;
1077
}
1078

    
1079
/**
1080
 * Implements hook_form_FORM_ID_alter().
1081
 */
1082
function superfish_form_block_admin_configure_alter(&$form, $form_state) {
1083
  $form['#validate'][] = 'superfish_block_validate';
1084
}
1085

    
1086
/**
1087
 * Validation function for the block configuration form.
1088
 */
1089
function superfish_block_validate($form, &$form_state) {
1090
  if ($form_state['values']['module'] == 'superfish') {
1091
    $supersubs_error = FALSE;
1092
    $delta = $form_state['values']['delta'];
1093
    $style = $form_state['values']['superfish_style_' . $delta];
1094
    $speed = $form_state['values']['superfish_speed_' . $delta];
1095
    $delay = $form_state['values']['superfish_delay_' . $delta];
1096
    $pathclass = $form_state['values']['superfish_pathclass_' . $delta];
1097
    $touch = $form_state['values']['superfish_touch_' . $delta];
1098
    $touchbp = $form_state['values']['superfish_touchbp_' . $delta];
1099
    $touchua = $form_state['values']['superfish_touchua_' . $delta];
1100
    $touchual = $form_state['values']['superfish_touchual_' . $delta];
1101
    $small = $form_state['values']['superfish_small_' . $delta];
1102
    $smallbp = $form_state['values']['superfish_smallbp_' . $delta];
1103
    $smallua = $form_state['values']['superfish_smallua_' . $delta];
1104
    $smallual = $form_state['values']['superfish_smallual_' . $delta];
1105
    $minwidth = $form_state['values']['superfish_minwidth_' . $delta];
1106
    $maxwidth = $form_state['values']['superfish_maxwidth_' . $delta];
1107
    $mcexclude = $form_state['values']['superfish_mcexclude_' . $delta];
1108
    $hldmenus = $form_state['values']['superfish_hldmenus_' . $delta];
1109
    $hldexclude = $form_state['values']['superfish_hldexclude_' . $delta];
1110
    $extracss = $form_state['values']['superfish_pathcss_' . $delta];
1111

    
1112
    if ($style != 'none' && superfish_styles('path', $style) == '') {
1113
      form_set_error('superfish_style_' . $delta, t('Cannot find the CSS file of the selected style.'));
1114
    }
1115
    elseif (!is_numeric($speed) && !in_array($speed, array('slow', 'normal', 'fast'))) {
1116
      form_set_error('superfish_speed_' . $delta, t('<strong>Animation speed</strong>: unacceptable value entered.'));
1117
    }
1118
    if (!is_numeric($delay)) {
1119
      form_set_error('superfish_delay_' . $delta, t('<strong>Mouse delay</strong>: unacceptable value entered.'));
1120
    }
1121
    if (is_numeric($pathclass)) {
1122
      form_set_error('superfish_pathclass_' . $delta, t('<strong>Path class</strong>: unacceptable value entered.'));
1123
    }
1124
    if ($touch == 2 && $touchbp == '') {
1125
      form_set_error('superfish_touchbp_' . $delta, t('<strong>sf-Touchscreen Breakpoint</strong>: field cannot be empty.'));
1126
    }
1127
    if (!is_numeric($touchbp)) {
1128
      form_set_error('superfish_touchbp_' . $delta, t('<strong>sf-Touchscreen Breakpoint</strong>: unacceptable value entered.'));
1129
    }
1130
    if ($touch == 3 && $touchua == 1 && $touchual == '') {
1131
      form_set_error('superfish_touchual_' . $delta, t('<strong>sf-Touchscreen Custom list of user agents</strong>: field cannot be empty.'));
1132
    }
1133
    if ($small == 2 && $smallbp == '') {
1134
      form_set_error('superfish_smallbp_' . $delta, t('<strong>sf-Smallscreen Breakpoint</strong>: field cannot be empty.'));
1135
    }
1136
    if (!is_numeric($smallbp)) {
1137
      form_set_error('superfish_smallbp_' . $delta, t('<strong>sf-Smallscreen Breakpoint</strong>: unacceptable value entered.'));
1138
    }
1139
    if ($small == 3 && $smallua == 1 && $smallual == '') {
1140
      form_set_error('superfish_smallual_' . $delta, t('<strong>sf-Smallscreen Custom list of user agents</strong>: field cannot be empty.'));
1141
    }
1142
    if (!is_numeric($minwidth)) {
1143
      form_set_error('superfish_minwidth_' . $delta, t('<strong>Supersubs minimum width</strong>: unacceptable value entered.'));
1144
      $supersubs_error = TRUE;
1145
    }
1146
    if (!is_numeric($maxwidth)) {
1147
      form_set_error('superfish_maxwidth_' . $delta, t('<strong>Supersubs maximum width</strong>: unacceptable value entered.'));
1148
      $supersubs_error = TRUE;
1149
    }
1150
    if ($supersubs_error !== TRUE && $minwidth > $maxwidth) {
1151
      form_set_error('superfish_maxwidth_' . $delta, t('Supersubs <strong>maximum width</strong> has to be bigger than the <strong>minimum width</strong>.'));
1152
    }
1153
    if (!empty($mcexclude) && (!is_numeric(str_replace(',', '', $mcexclude)) || strpos($mcexclude, ' .'))) {
1154
      form_set_error('superfish_mcexclude_' . $delta, t('<strong>Multi-column subs-menus</strong>: unacceptable value entered.'));
1155
    }
1156
    if (!empty($hldmenus) && (!is_numeric(str_replace(',', '', $hldmenus)) || strpos($hldmenus, ' .'))) {
1157
      form_set_error('superfish_hldmenus_' . $delta, t('<strong>Hyperlinks</strong>: unacceptable value entered.'));
1158
    }
1159
    if (!empty($hldexclude) && (!is_numeric(str_replace(',', '', $hldexclude)) || strpos($hldexclude, ' .'))) {
1160
      form_set_error('superfish_hldexclude_' . $delta, t('<strong>Hyperlinks</strong>: unacceptable value entered.'));
1161
    }
1162
    if (!empty($extracss)) {
1163
      if (strpos($extracss, ',')) {
1164
        $error = array();
1165
        $extracss = array_remove_empty(explode(',', $extracss));
1166
        foreach ($extracss as $c) {
1167
          if (!file_exists($c)) {
1168
            $error[] = $c;
1169
          }
1170
        }
1171
        if (!empty($error)) {
1172
          form_set_error('superfish_pathcss_' . $delta, t('Cannot find the CSS file mentioned in <strong>Extra CSS</strong>'));
1173
        }
1174
      }
1175
      elseif (!file_exists($extracss)) {
1176
        form_set_error('superfish_pathcss_' . $delta, t('Cannot find the CSS file mentioned in <strong>Extra CSS</strong>'));
1177
      }
1178
    }
1179
  }
1180
}
1181

    
1182
/**
1183
 * Get a list of CSS files that can be used for styles.
1184
 */
1185
function superfish_styles($display = 'list', $style = NULL) {
1186
  $output = '';
1187
  // Ensure the Libraries API module is installed and working.
1188
  if (module_exists('libraries') && function_exists('libraries_get_path')) {
1189
    $directory = libraries_get_path('superfish') . '/style';
1190
  }
1191
  // Otherwise use the default directory.
1192
  else {
1193
    $directory = 'sites/all/libraries/superfish/style';
1194
  }
1195
  $files = (file_exists($directory)) ? file_scan_directory($directory, '/.*\.css$/', array('key' => 'name')) : '';
1196
  if ($display == 'list') {
1197
    $output = array('none' => '- ' . t('None') . ' -');
1198
    if (is_array($files)) {
1199
      foreach ($files as $file) {
1200
        $output[$file->name] = drupal_ucfirst($file->name);
1201
      }
1202
    }
1203
    natcasesort($output);
1204
  }
1205
  if ($display == 'path' && $style) {
1206
    if (isset($files[$style])) {
1207
      $output = $files[$style]->uri;
1208
    }
1209
    else {
1210
      watchdog('page not found', 'Required files for the Superfish \'%style\' style cannot be found.', array('%style' => $style), WATCHDOG_WARNING);
1211
      $output = '';
1212
    }
1213
  }
1214
  return $output;
1215
}
1216

    
1217
/**
1218
 * Generate a list of available slide-in effects.
1219
 */
1220
function superfish_effects() {
1221
  $output = array(
1222
    'none' => '- ' . t('None') . ' -',
1223
    'vertical' => t('Vertical'),
1224
    'horizontal' => t('Horizontal'),
1225
    'diagonal' => t('Diagonal'));
1226
  // Ensure the Libraries API module is installed and working.
1227
  if (module_exists('libraries') && function_exists('libraries_get_path') && libraries_get_path('easing') != '') {
1228
    $file = libraries_get_path('easing') . '/jquery.easing.js';
1229
  }
1230
  // Otherwise look for the file in the default location.
1231
  else {
1232
    $file = 'sites/all/libraries/easing/jquery.easing.js';
1233
  }
1234
  if (file_exists($file)) {
1235
    $easing_types = array(
1236
      'easeInSine_vertical' => 'easeInSine (' . t('Vertical') . ')',
1237
      'easeInSine_horizontal' => 'easeInSine (' . t('Horizontal') . ')',
1238
      'easeInSine_diagonal' => 'easeInSine (' . t('Diagonal') . ')',
1239
      'easeInQuint_vertical' => 'easeInQuint (' . t('Vertical') . ')',
1240
      'easeInQuint_horizontal' => 'easeInQuint (' . t('Horizontal') . ')',
1241
      'easeInQuint_diagonal' => 'easeInQuint (' . t('Diagonal') . ')',
1242
      'easeInQuart_vertical' => 'easeInQuart (' . t('Vertical') . ')',
1243
      'easeInQuart_horizontal' => 'easeInQuart (' . t('Horizontal') . ')',
1244
      'easeInQuart_diagonal' => 'easeInQuart (' . t('Diagonal') . ')',
1245
      'easeInQuad_vertical' => 'easeInQuad (' . t('Vertical') . ')',
1246
      'easeInQuad_horizontal' => 'easeInQuad (' . t('Horizontal') . ')',
1247
      'easeInQuad_diagonal' => 'easeInQuad (' . t('Diagonal') . ')',
1248
      'easeInExpo_vertical' => 'easeInExpo (' . t('Vertical') . ')',
1249
      'easeInExpo_horizontal' => 'easeInExpo (' . t('Horizontal') . ')',
1250
      'easeInExpo_diagonal' => 'easeInExpo (' . t('Diagonal') . ')',
1251
      'easeInElastic_vertical' => 'easeInElastic (' . t('Vertical') . ')',
1252
      'easeInElastic_horizontal' => 'easeInElastic (' . t('Horizontal') . ')',
1253
      'easeInElastic_diagonal' => 'easeInElastic (' . t('Diagonal') . ')',
1254
      'easeInCubic_vertical' => 'easeInCubic (' . t('Vertical') . ')',
1255
      'easeInCubic_horizontal' => 'easeInCubic (' . t('Horizontal') . ')',
1256
      'easeInCubic_diagonal' => 'easeInCubic (' . t('Diagonal') . ')',
1257
      'easeInCirc_vertical' => 'easeInCirc (' . t('Vertical') . ')',
1258
      'easeInCirc_horizontal' => 'easeInCirc (' . t('Horizontal') . ')',
1259
      'easeInCirc_diagonal' => 'easeInCirc (' . t('Diagonal') . ')',
1260
      'easeInBounce_vertical' => 'easeInBounce (' . t('Vertical') . ')',
1261
      'easeInBounce_horizontal' => 'easeInBounce (' . t('Horizontal') . ')',
1262
      'easeInBounce_diagonal' => 'easeInBounce (' . t('Diagonal') . ')',
1263
      'easeInBack_vertical' => 'easeInBack (' . t('Vertical') . ')',
1264
      'easeInBack_horizontal' => 'easeInBack (' . t('Horizontal') . ')',
1265
      'easeInBack_diagonal' => 'easeInBack (' . t('Diagonal') . ')',
1266
      'easeOutQuint_vertical' => 'easeOutQuint (' . t('Vertical') . ')',
1267
      'easeOutQuint_horizontal' => 'easeOutQuint (' . t('Horizontal') . ')',
1268
      'easeOutQuint_diagonal' => 'easeOutQuint (' . t('Diagonal') . ')',
1269
      'easeOutQuart_vertical' => 'easeOutQuart (' . t('Vertical') . ')',
1270
      'easeOutQuart_horizontal' => 'easeOutQuart (' . t('Horizontal') . ')',
1271
      'easeOutQuart_diagonal' => 'easeOutQuart (' . t('Diagonal') . ')',
1272
      'easeOutQuad_vertical' => 'easeOutQuad (' . t('Vertical') . ')',
1273
      'easeOutQuad_horizontal' => 'easeOutQuad (' . t('Horizontal') . ')',
1274
      'easeOutQuad_diagonal' => 'easeOutQuad (' . t('Diagonal') . ')',
1275
      'easeOutExpo_vertical' => 'easeOutExpo (' . t('Vertical') . ')',
1276
      'easeOutExpo_horizontal' => 'easeOutExpo (' . t('Horizontal') . ')',
1277
      'easeOutExpo_diagonal' => 'easeOutExpo (' . t('Diagonal') . ')',
1278
      'easeOutElastic_vertical' => 'easeOutElastic (' . t('Vertical') . ')',
1279
      'easeOutElastic_horizontal' => 'easeOutElastic (' . t('Horizontal') . ')',
1280
      'easeOutElastic_diagonal' => 'easeOutElastic (' . t('Diagonal') . ')',
1281
      'easeOutCubic_vertical' => 'easeOutCubic (' . t('Vertical') . ')',
1282
      'easeOutCubic_horizontal' => 'easeOutCubic (' . t('Horizontal') . ')',
1283
      'easeOutCubic_diagonal' => 'easeOutCubic (' . t('Diagonal') . ')',
1284
      'easeOutCirc_vertical' => 'easeOutCirc (' . t('Vertical') . ')',
1285
      'easeOutCirc_horizontal' => 'easeOutCirc (' . t('Horizontal') . ')',
1286
      'easeOutCirc_diagonal' => 'easeOutCirc (' . t('Diagonal') . ')',
1287
      'easeOutBounce_vertical' => 'easeOutBounce (' . t('Vertical') . ')',
1288
      'easeOutBounce_horizontal' => 'easeOutBounce (' . t('Horizontal') . ')',
1289
      'easeOutBounce_diagonal' => 'easeOutBounce (' . t('Diagonal') . ')',
1290
      'easeOutBack_vertical' => 'easeOutBack (' . t('Vertical') . ')',
1291
      'easeOutBack_horizontal' => 'easeOutBack (' . t('Horizontal') . ')',
1292
      'easeOutBack_diagonal' => 'easeOutBack (' . t('Diagonal') . ')',
1293
      'easeInOutQuint_vertical' => 'easeInOutQuint (' . t('Vertical') . ')',
1294
      'easeInOutQuint_horizontal' => 'easeInOutQuint (' . t('Horizontal') . ')',
1295
      'easeInOutQuint_diagonal' => 'easeInOutQuint (' . t('Diagonal') . ')',
1296
      'easeInOutQuart_vertical' => 'easeInOutQuart (' . t('Vertical') . ')',
1297
      'easeInOutQuart_horizontal' => 'easeInOutQuart (' . t('Horizontal') . ')',
1298
      'easeInOutQuart_diagonal' => 'easeInOutQuart (' . t('Diagonal') . ')',
1299
      'easeInOutQuad_vertical' => 'easeInOutQuad (' . t('Vertical') . ')',
1300
      'easeInOutQuad_horizontal' => 'easeInOutQuad (' . t('Horizontal') . ')',
1301
      'easeInOutQuad_diagonal' => 'easeInOutQuad (' . t('Diagonal') . ')',
1302
      'easeInOutExpo_vertical' => 'easeInOutExpo (' . t('Vertical') . ')',
1303
      'easeInOutExpo_horizontal' => 'easeInOutExpo (' . t('Horizontal') . ')',
1304
      'easeInOutExpo_diagonal' => 'easeInOutExpo (' . t('Diagonal') . ')',
1305
      'easeInOutElastic_vertical' => 'easeInOutElastic (' . t('Vertical') . ')',
1306
      'easeInOutElastic_horizontal' => 'easeInOutElastic (' . t('Horizontal') . ')',
1307
      'easeInOutElastic_diagonal' => 'easeInOutElastic (' . t('Diagonal') . ')',
1308
      'easeInOutCubic_vertical' => 'easeInOutCubic (' . t('Vertical') . ')',
1309
      'easeInOutCubic_horizontal' => 'easeInOutCubic (' . t('Horizontal') . ')',
1310
      'easeInOutCubic_diagonal' => 'easeInOutCubic (' . t('Diagonal') . ')',
1311
      'easeInOutCirc_vertical' => 'easeInOutCirc (' . t('Vertical') . ')',
1312
      'easeInOutCirc_horizontal' => 'easeInOutCirc (' . t('Horizontal') . ')',
1313
      'easeInOutCirc_diagonal' => 'easeInOutCirc (' . t('Diagonal') . ')',
1314
      'easeInOutBounce_vertical' => 'easeInOutBounce (' . t('Vertical') . ')',
1315
      'easeInOutBounce_horizontal' => 'easeInOutBounce (' . t('Horizontal') . ')',
1316
      'easeInOutBounce_diagonal' => 'easeInOutBounce (' . t('Diagonal') . ')',
1317
      'easeInOutBack_vertical' => 'easeInOutBack (' . t('Vertical') . ')',
1318
      'easeInOutBack_horizontal' => 'easeInOutBack (' . t('Horizontal') . ')',
1319
      'easeInOutBack_diagonal' => 'easeInOutBack (' . t('Diagonal') . ')');
1320
    $output = array_merge($output, $easing_types);
1321
  }
1322
  return $output;
1323
}
1324

    
1325
/**
1326
 * Add require JavaScript and CSS files from the Superfish library.
1327
 */
1328
function superfish_library($type = NULL, $name = NULL, $action = 'add') {
1329
  // Ensure the Libraries API module is installed and working and is able to find the library.
1330
  if (module_exists('libraries') && function_exists('libraries_get_path') && libraries_get_path('superfish') != '') {
1331
    $directory = libraries_get_path('superfish');
1332
    $directory_easing = libraries_get_path('easing');
1333
  }
1334
  // Otherwise use the default directory.
1335
  else {
1336
    $directory = 'sites/all/libraries/superfish';
1337
    $directory_easing = 'sites/all/libraries/easing';
1338
  }
1339
  $slp_default = $directory . "/jquery.hoverIntent.minified.js\n" .
1340
    $directory . "/jquery.bgiframe.min.js\n" .
1341
    $directory . "/superfish.js\n" .
1342
    $directory . "/supersubs.js\n" .
1343
    $directory . "/supposition.js\n" .
1344
    $directory . "/sftouchscreen.js\n" .
1345
    $directory . "/sfsmallscreen.js";
1346

    
1347
  $sf_library = variable_get('superfish_slp', $slp_default);
1348
  $sf_library = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", trim($sf_library));
1349
  $sf_library = explode("\n", $sf_library);
1350

    
1351
  if ($action == 'check') {
1352
    switch ($type) {
1353
      case  'javascript':
1354
        switch ($name) {
1355
          case 'drupal_behavior':
1356
            $name = 'superfish.js';
1357
            $sf_library = array(drupal_get_path('module', 'superfish') . '/' . $name);
1358
          break;
1359
          case 'jquery.easing.js':
1360
            $name = 'jquery.easing.js';
1361
            $sf_library = array($directory_easing . '/' . $name);
1362
          break;
1363
        }
1364
        foreach ($sf_library as $s) {
1365
          if (strpos($s, $name) !== FALSE) {
1366
            if (file_exists($s)) {
1367
              return TRUE;
1368
            }
1369
            else {
1370
              $file = $directory . (($type == 'CSS') ? '/css' : '') . '/' . $name;
1371
              watchdog('page not found', '%file', array('%file' => $file), WATCHDOG_ERROR);
1372
              return FALSE;
1373
            }
1374
          }
1375
        }
1376
      break;
1377
      case 'CSS':
1378
        $directory .= '/css';
1379
        switch ($name) {
1380
          case 'superfish':
1381
          case 'horizontal':
1382
            if (file_exists($directory . '/superfish.css')) {
1383
              return TRUE;
1384
            }
1385
            else {
1386
              watchdog('page not found', '%directory/superfish.css', array('%directory' => $directory), WATCHDOG_WARNING);
1387
              return FALSE;
1388
            }
1389
          break;
1390
          case 'navbar':
1391
          case 'vertical':
1392
            if (file_exists($directory . '/superfish-' . $name . '.css')) {
1393
              return TRUE;
1394
            }
1395
            else {
1396
              watchdog('page not found', '%directory/superfish-%name.css', array('%directory' => $directory, '%name' => $name), WATCHDOG_WARNING);
1397
              return FALSE;
1398
            }
1399
          break;
1400
        }
1401
      break;
1402
    }
1403
  }
1404
  if ($action == 'add') {
1405
    switch ($type) {
1406
      case 'javascript':
1407
        switch ($name) {
1408
          case 'easing':
1409
            $output = array($directory_easing . '/jquery.easing.js' => array('type' => 'file', 'weight' => 490));
1410
            return $output;
1411
          break;
1412
          case 'drupal_behavior':
1413
            $output = array(drupal_get_path('module', 'superfish') . '/superfish.js' => array('type' => 'file', 'weight' => 495));
1414
            return $output;
1415
          break;
1416
          default:
1417
            if (file_exists($directory . '/superfish.js')) {
1418
              foreach ($sf_library as $s) {
1419
                if (strpos($s, $name) !== FALSE) {
1420
                  switch ($name) {
1421
                    case 'superfish':
1422
                      $weight = 480;
1423
                    break;
1424
                    case 'supersubs':
1425
                      $weight = 490;
1426
                    break;
1427
                    default:
1428
                      $weight = 470;
1429
                    break;  
1430
                  }
1431
                  $output = array($s => array('type' => 'file', 'weight' => $weight));
1432
                  return $output;
1433
                }
1434
              }
1435
              // If the required file did not exist in the library files list.
1436
              if (empty($output)) {
1437
                watchdog('page not found', '%name cannot be found.', array('%name' => $name), WATCHDOG_WARNING);
1438
              }
1439
            }
1440
            else {
1441
              watchdog('page not found', '%directory/superfish.js', array('%directory' => $directory), WATCHDOG_ERROR);
1442
            }
1443
          break;
1444
        }
1445
      break;
1446
      case 'CSS':
1447
        $directory .= '/css';
1448
        switch ($name) {
1449
          case 'superfish':
1450
          case 'horizontal':
1451
            $output = array($directory . '/superfish.css' => array('type' => 'file', 'weight' => 480));
1452
            return $output;
1453
          break;
1454
          case 'navbar':
1455
          case 'vertical':
1456
            $output = array($directory . '/superfish-' . $name . '.css' => array('type' => 'file', 'weight' => 490));
1457
            return $output;
1458
          break;
1459
        }
1460
      break;
1461
    }
1462
  }
1463
}
1464

    
1465
/**
1466
 * Helper function to clean up arrays.
1467
 */
1468
function array_remove_empty($haystack) {
1469
  foreach ($haystack as $key => $value) {
1470
    if (is_array($value)) {
1471
      $haystack[$key] = array_remove_empty($haystack[$key]);
1472
    }
1473
    elseif (empty($value) && is_bool($value) !== TRUE) {
1474
      if ($haystack[$key] != '0') {
1475
        unset($haystack[$key]);
1476
      }
1477
    }
1478
  }
1479
  return $haystack;
1480
}
1481

    
1482
/**
1483
 * Implements hook_theme().
1484
 */
1485
function superfish_theme() {
1486
  return array(
1487
    'superfish' => array(
1488
      'variables' => array(
1489
        'id' => NULL,
1490
        'menu_name' => NULL,
1491
        'mlid' => NULL,
1492
        'sfsettings' => NULL
1493
      ),
1494
    ),
1495
    'superfish_build' => array(
1496
      'variables' => array(
1497
        'id' => NULL,
1498
        'menu' => NULL,
1499
        'depth' => -1,
1500
        'trail' => NULL,
1501
        'sfsettings' => NULL
1502
      ),
1503
    ),
1504
    'superfish_menu_item' => array(
1505
      'variables' => array(
1506
        'element' => NULL,
1507
        'properties' => NULL,
1508
      ),
1509
    ),
1510
    'superfish_menu_item_link' => array(
1511
      'variables' => array(
1512
        'menu_item' => NULL,
1513
        'link_options' => NULL,
1514
      ),
1515
    ),
1516
  );
1517
}
1518

    
1519
/**
1520
 * Builds the active trail from the page's menu data.
1521
 */
1522
function superfish_build_page_trail($page_menu) {
1523
  $trail = array();
1524
  foreach ($page_menu as $item) {
1525
    if ($item['link']['in_active_trail'] || ($item['link']['href'] == '<front>' && drupal_is_front_page())) {
1526
      $trail[] = $item['link']['mlid'];
1527
    }
1528
    if ($item['below']) {
1529
      $trail = array_merge($trail, superfish_build_page_trail($item['below']));
1530
    }
1531
  }
1532
  // Allows other modules to alter the active trail.
1533
  drupal_alter('superfish_active_trail', $trail);
1534
  return $trail;
1535
}
1536

    
1537
/**
1538
 * Theme function to allow any menu tree to be themed as a Superfish menu.
1539
 */
1540
function theme_superfish($variables) {
1541
  global $user, $language;
1542

    
1543
  $id = $variables['id'];
1544
  $menu_name = $variables['menu_name'];
1545
  $mlid = $variables['mlid'];
1546
  $sfsettings = $variables['sfsettings'];
1547

    
1548
  $menu = menu_tree_all_data($menu_name);
1549

    
1550
  if (function_exists('i18n_menu_localize_tree')) {
1551
    $menu = i18n_menu_localize_tree($menu);
1552
  }
1553

    
1554
  // For custom $menus and menus built all the way from the top-level we
1555
  // don't need to "create" the specific sub-menu and we need to get the title
1556
  // from the $menu_name since there is no "parent item" array.
1557
  // Create the specific menu if we have a mlid.
1558
  if (!empty($mlid)) {
1559
    // Load the parent menu item.
1560
    $item = menu_link_load($mlid);
1561
    $title = check_plain($item['title']);
1562
    $parent_depth = $item['depth'];
1563
    // Narrow down the full menu to the specific sub-tree we need.
1564
    for ($p = 1; $p < 10; $p++) {
1565
      if ($sub_mlid = $item["p$p"]) {
1566
        $subitem = menu_link_load($sub_mlid);
1567
        $key = (50000 + $subitem['weight']) . ' ' . $subitem['title'] . ' ' . $subitem['mlid'];
1568
        $menu = (isset($menu[$key]['below'])) ? $menu[$key]['below'] : $menu;
1569
      }
1570
    }
1571
  }
1572
  else {
1573
    $result = db_query("SELECT title FROM {menu_custom} WHERE menu_name = :a", array(':a' => $menu_name))->fetchField();
1574
    $title = check_plain($result);
1575
  }
1576

    
1577
  $output['content'] = '';
1578
  $output['subject'] = $title;
1579
  if ($menu) {
1580
    // Set the total menu depth counting from this parent if we need it.
1581
    $depth = $sfsettings['depth'];
1582
    $depth = ($sfsettings['depth'] > 0 && isset($parent_depth)) ? $parent_depth + $depth : $depth;
1583

    
1584
    $var = array(
1585
      'id' => $id,
1586
      'menu' => $menu,
1587
      'depth' => $depth,
1588
      'trail' => superfish_build_page_trail(menu_tree_page_data($menu_name)),
1589
      'sfsettings' => $sfsettings
1590
    );
1591
    if ($menu_tree = theme('superfish_build', $var)) {
1592
      if ($menu_tree['content']) {
1593
        // Add custom HTML codes around the main menu.
1594
        if ($sfsettings['wrapmul'] && strpos($sfsettings['wrapmul'], ',') !== FALSE) {
1595
          $wmul = explode(',', $sfsettings['wrapmul']);
1596
          // In case you just wanted to add something after the element.
1597
          if (drupal_substr($sfsettings['wrapmul'], 0) == ',') {
1598
            array_unshift($wmul, '');
1599
          }
1600
        }
1601
        else {
1602
          $wmul = array();
1603
        }
1604
        $output['content'] = isset($wmul[0]) ? $wmul[0] : '';
1605
        $output['content'] .= '<ul id="superfish-' . $id . '"';
1606
        $output['content'] .= ' class="menu sf-menu sf-' . $menu_name . ' sf-' . $sfsettings['type'] . ' sf-style-' . $sfsettings['style'];
1607
        $output['content'] .= ($sfsettings['itemcounter']) ? ' sf-total-items-' . $menu_tree['total_children'] : '';
1608
        $output['content'] .= ($sfsettings['itemcounter']) ? ' sf-parent-items-' . $menu_tree['parent_children'] : '';
1609
        $output['content'] .= ($sfsettings['itemcounter']) ? ' sf-single-items-' . $menu_tree['single_children'] : '';
1610
        $output['content'] .= ($sfsettings['ulclass']) ? ' ' . $sfsettings['ulclass'] : '';
1611
        $output['content'] .= ($language->direction == 1) ? ' rtl' : '';
1612
        $output['content'] .= '">' . $menu_tree['content'] . '</ul>';
1613
        $output['content'] .= isset($wmul[1]) ? $wmul[1] : '';
1614
      }
1615
    }
1616
  }
1617
  return $output;
1618
}
1619

    
1620
/**
1621
 * Helper function that builds the nested lists of a Superfish menu.
1622
 */
1623
function theme_superfish_build($variables) {
1624
  $output = array('content' => '');
1625
  $id = $variables['id'];
1626
  $menu = $variables['menu'];
1627
  $depth = $variables['depth'];
1628
  $trail = $variables['trail'];
1629
  // Keep $sfsettings untouched as we need to pass it to the child menus.
1630
  $settings = $sfsettings = $variables['sfsettings'];
1631
  $megamenu = $megamenu_below = $settings['megamenu'];
1632
  $total_children = $parent_children = $single_children = 0;
1633
  $i = 1;
1634

    
1635
  // Reckon the total number of available menu items.
1636
  foreach ($menu as $menu_item) {
1637
    if (!isset($menu_item['link']['hidden']) || $menu_item['link']['hidden'] == 0) {
1638
      $total_children++;
1639
    }
1640
  }
1641

    
1642
  foreach ($menu as $menu_item) {
1643

    
1644
    $show_children = $megamenu_wrapper = $megamenu_column = $megamenu_content = FALSE;
1645
    $item_class = $link_options = $link_class = array();
1646
    $mlid = $menu_item['link']['mlid'];
1647

    
1648
    if (!isset($menu_item['link']['hidden']) || $menu_item['link']['hidden'] == 0) {
1649
      $item_class[] = ($trail && in_array($mlid, $trail)) ? 'active-trail' : '';
1650

    
1651
      // Add helper classes to the menu items and hyperlinks.
1652
      $settings['firstlast'] = ($settings['dfirstlast'] == 1 && $total_children == 1) ? 0 : $settings['firstlast'];
1653
      $item_class[] = ($settings['firstlast'] == 1) ? (($i == 1 && $i == $total_children) ? 'firstandlast' : (($i == 1) ? 'first' : (($i == $total_children) ? 'last' : 'middle'))) : '';
1654
      $settings['zebra'] = ($settings['dzebra'] == 1 && $total_children == 1) ? 0 : $settings['zebra'];
1655
      $item_class[] = ($settings['zebra'] == 1) ? (($i % 2) ? 'odd' : 'even') : '';
1656
      $item_class[] = ($settings['itemcount'] == 1) ? 'sf-item-' . $i : '';
1657
      $item_class[] = ($settings['itemdepth'] == 1) ? 'sf-depth-' . $menu_item['link']['depth'] : '';
1658
      $link_class[] = ($settings['itemdepth'] == 1) ? 'sf-depth-' . $menu_item['link']['depth'] : '';
1659
      $item_class[] = ($settings['liclass']) ? $settings['liclass'] : '';
1660
      if (strpos($settings['hlclass'], ' ')) {
1661
        $l = explode(' ', $settings['hlclass']);
1662
        foreach ($l as $c) {
1663
          $link_class[] = $c;
1664
        }
1665
      }
1666
      else {
1667
        $link_class[] = $settings['hlclass'];
1668
      }
1669
      $i++;
1670

    
1671
      // Hide hyperlink descriptions ("title" attribute).
1672
      if ($settings['hidelinkdescription'] == 1) {
1673
        unset($menu_item['link']['localized_options']['attributes']['title']);
1674
      }
1675

    
1676
      // Insert hyperlink description ("title" attribute) into the text.
1677
      $show_linkdescription = ($settings['linkdescription'] == 1 && !empty($menu_item['link']['localized_options']['attributes']['title'])) ? TRUE : FALSE;
1678
      if ($show_linkdescription) {
1679
        if (!empty($settings['hldmenus'])) {
1680
          $show_linkdescription = (is_array($settings['hldmenus'])) ? ((in_array($mlid, $settings['hldmenus'])) ? TRUE : FALSE) : (($mlid == $settings['hldmenus']) ? TRUE : FALSE);
1681
        }
1682
        if (!empty($settings['hldexclude'])) {
1683
          $show_linkdescription = (is_array($settings['hldexclude'])) ? ((in_array($mlid, $settings['hldexclude'])) ? FALSE : $show_linkdescription) : (($settings['hldexclude'] == $mlid) ? FALSE : $show_linkdescription);
1684
        }
1685
        if ($show_linkdescription) {
1686
          $menu_item['link']['title'] .= ' <span class="sf-description">';
1687
          $menu_item['link']['title'] .= (!empty($menu_item['link']['localized_options']['attributes']['title'])) ? $menu_item['link']['localized_options']['attributes']['title'] : array();
1688
          $menu_item['link']['title'] .= '</span>';
1689
          $link_options['html'] = TRUE;
1690
        }
1691
      }
1692

    
1693
      // Add custom HTML codes around the menu items.
1694
      if ($sfsettings['wrapul'] && strpos($sfsettings['wrapul'], ',') !== FALSE) {
1695
        $wul = explode(',', $sfsettings['wrapul']);
1696
        // In case you just wanted to add something after the element.
1697
        if (drupal_substr($sfsettings['wrapul'], 0) == ',') {
1698
          array_unshift($wul, '');
1699
        }
1700
      }
1701
      else {
1702
        $wul = array();
1703
      }
1704

    
1705
      // Add custom HTML codes around the hyperlinks.
1706
      if ($settings['wraphl'] && strpos($settings['wraphl'], ',') !== FALSE) {
1707
        $whl = explode(',', $settings['wraphl']);
1708
        // The same as above
1709
        if (drupal_substr($settings['wraphl'], 0) == ',') {
1710
          array_unshift($whl, '');
1711
        }
1712
      }
1713
      else {
1714
        $whl = array();
1715
      }
1716

    
1717
      // Add custom HTML codes around the hyperlinks text.
1718
      if ($settings['wraphlt'] && strpos($settings['wraphlt'], ',') !== FALSE) {
1719
        $whlt = explode(',', $settings['wraphlt']);
1720
        // The same as above
1721
        if (drupal_substr($settings['wraphlt'], 0) == ',') {
1722
          array_unshift($whlt, '');
1723
        }
1724
        $menu_item['link']['title'] = $whlt[0] . check_plain($menu_item['link']['title']) . $whlt[1];
1725
        $link_options['html'] = TRUE;
1726
      }
1727

    
1728
      $expanded = ($sfsettings['expanded'] == 1) ? (($menu_item['link']['expanded'] == 1) ? TRUE : FALSE) : TRUE;
1729

    
1730
      if (!empty($menu_item['link']['has_children']) && !empty($menu_item['below']) && $depth != 0 && $expanded === TRUE) {
1731

    
1732
        // Megamenu is still beta, there is a good chance much of this will be changed.
1733
        if (!empty($settings['megamenu_exclude'])) {
1734
          if (is_array($settings['megamenu_exclude'])) {
1735
            $megamenu_below = (in_array($mlid, $settings['megamenu_exclude'])) ? 0 : $megamenu;
1736
          }
1737
          else {
1738
            $megamenu_below = ($settings['megamenu_exclude'] == $mlid) ? 0 : $megamenu;
1739
          }
1740
          // Send the result to the sub-menu.
1741
          $sfsettings['megamenu'] = $megamenu_below;
1742
        }
1743
        if ($megamenu_below == 1) {
1744
          $megamenu_wrapper = ($menu_item['link']['depth'] == $settings['megamenu_depth']) ? TRUE : FALSE;
1745
          $megamenu_column = ($menu_item['link']['depth'] == $settings['megamenu_depth'] + 1) ? TRUE : FALSE;
1746
          $megamenu_content = ($menu_item['link']['depth'] >= $settings['megamenu_depth'] && $menu_item['link']['depth'] <= $settings['megamenu_levels']) ? TRUE : FALSE;
1747
        }
1748
        // Render the sub-menu.
1749
        $var = array(
1750
          'id' => $id,
1751
          'menu' => $menu_item['below'],
1752
          'depth' => $depth,
1753
          'trail' => $trail,
1754
          'sfsettings' => $sfsettings
1755
        );
1756
        $children = theme('superfish_build', $var);
1757
        // Check to see whether it should be displayed.
1758
        $show_children = (($menu_item['link']['depth'] <= $depth || $depth == -1) && $children['content']) ? TRUE : FALSE;
1759
        if ($show_children) {
1760
          // Add item counter classes.
1761
          if ($settings['itemcounter']) {
1762
            $item_class[] = 'sf-total-children-' . $children['total_children'];
1763
            $item_class[] = 'sf-parent-children-' . $children['parent_children'];
1764
            $item_class[] = 'sf-single-children-' . $children['single_children'];
1765
          }
1766
          // More helper classes.
1767
          $item_class[] = ($megamenu_column) ? 'sf-megamenu-column' : '';
1768
          $item_class[] = $link_class[] = 'menuparent';
1769
        }
1770
        $parent_children++;
1771
      }
1772
      else {
1773
        $item_class[] = 'sf-no-children';
1774
        $single_children++;
1775
      }
1776

    
1777
      $item_class = implode(' ', array_remove_empty($item_class));
1778

    
1779
      if (isset($menu_item['link']['localized_options']['attributes']['class'])) {
1780
        $link_class_current = $menu_item['link']['localized_options']['attributes']['class'];
1781
        $link_class = array_merge($link_class_current, array_remove_empty($link_class));
1782
      }
1783
      $menu_item['link']['localized_options']['attributes']['class'] = array_remove_empty($link_class);
1784

    
1785
      // The Context module uses theme_menu_link, Superfish does not, this is why we have to do this.
1786
      if (function_exists('context_active_contexts')) {
1787
        if ($contexts = context_active_contexts()) {
1788
          foreach ($contexts as $context) {
1789
            if ((isset($context->reactions['menu']))) {
1790
              if ($menu_item['link']['href'] == $context->reactions['menu']) {
1791
                $menu_item['link']['localized_options']['attributes']['class'][] = 'active';
1792
              }
1793
            }
1794
          }
1795
        }
1796
      }
1797

    
1798
      $link_options += $menu_item['link']['localized_options'];
1799

    
1800
      // Render the menu item.
1801
      // Should a theme be used for menu items?
1802
      if ($settings['use_item_theme']) {
1803
        $item_variables = array(
1804
          'element' => array(
1805
            'attributes' => array(
1806
              'id' => 'menu-' . $mlid . '-' . $id,
1807
              'class' => trim($item_class),
1808
            ),
1809
            'below' => ($show_children) ? $children['content'] : NULL,
1810
            'item' => $menu_item,
1811
            'localized_options' => $link_options,
1812
          ),
1813
          'properties' => array(
1814
            'megamenu' => array(
1815
              'megamenu_column' => $megamenu_column,
1816
              'megamenu_wrapper' => $megamenu_wrapper,
1817
              'megamenu_content' => $megamenu_content,
1818
            ),
1819
            'use_link_theme' => $settings['use_link_theme'],
1820
            'wrapper' => $whl,
1821
          ),
1822
        );
1823
        $output['content'] .= theme('superfish_menu_item', $item_variables);
1824
      }
1825
      else {
1826
        $output['content'] .= '<li id="menu-' . $mlid . '-' . $id . '"';
1827
        $output['content'] .= ($item_class) ? ' class="' . trim($item_class) . '">' : '>';
1828
        $output['content'] .= ($megamenu_column) ? '<div class="sf-megamenu-column">' : '';
1829
        $output['content'] .= isset($whl[0]) ? $whl[0] : '';
1830
        if ($settings['use_link_theme']) {
1831
          $link_variables = array(
1832
            'menu_item' => $menu_item,
1833
            'link_options' => $link_options,
1834
          );
1835
          $output['content'] .= theme('superfish_menu_item_link', $link_variables);
1836
        }
1837
        else {
1838
          $output['content'] .= l($menu_item['link']['title'], $menu_item['link']['href'], $link_options);
1839
        }
1840
        $output['content'] .= isset($whl[1]) ? $whl[1] : '';
1841
        $output['content'] .= ($megamenu_wrapper) ? '<ul class="sf-megamenu"><li class="sf-megamenu-wrapper ' . $item_class . '">' : '';
1842
        $output['content'] .= ($show_children) ? (isset($wul[0]) ? $wul[0] : '') : '';
1843
        $output['content'] .= ($show_children) ? (($megamenu_content) ? '<ol>' : '<ul>') : '';
1844
        $output['content'] .= ($show_children) ? $children['content'] : '';
1845
        $output['content'] .= ($show_children) ? (($megamenu_content) ? '</ol>' : '</ul>') : '';
1846
        $output['content'] .= ($show_children) ? (isset($wul[1]) ? $wul[1] : '') : '';
1847
        $output['content'] .= ($megamenu_wrapper) ? '</li></ul>' : '';
1848
        $output['content'] .= ($megamenu_column) ? '</div>' : '';
1849
        $output['content'] .= '</li>';
1850
      }
1851
    }
1852
  }
1853
  $output['total_children'] = $total_children;
1854
  $output['parent_children'] = $parent_children;
1855
  $output['single_children'] = $single_children;
1856
  return $output;
1857
}
1858
/**
1859
 * Returns HTML for a menu item.
1860
 *
1861
 * @param $variables
1862
 *   An associative array containing:
1863
 *   - element: Structured array data for a menu item.
1864
 *   - properties: Various properties of a menu item.
1865
 *
1866
 * @ingroup themeable
1867
 */
1868
function theme_superfish_menu_item($variables) {
1869
  $element = $variables['element'];
1870
  $properties = $variables['properties'];
1871
  $sub_menu = '';
1872

    
1873
  if ($element['below']) {
1874
    $sub_menu .= isset($variables['wrapper']['wul'][0]) ? $variables['wrapper']['wul'][0] : '';
1875
    $sub_menu .= ($properties['megamenu']['megamenu_content']) ? '<ol>' : '<ul>';
1876
    $sub_menu .= $element['below'];
1877
    $sub_menu .= ($properties['megamenu']['megamenu_content']) ? '</ol>' : '</ul>';
1878
    $sub_menu .= isset($variables['wrapper']['wul'][1]) ? $variables['wrapper']['wul'][1] : '';
1879
  }
1880

    
1881
  $output = '<li' . drupal_attributes($element['attributes']) . '>';
1882
  $output .= ($properties['megamenu']['megamenu_column']) ? '<div class="sf-megamenu-column">' : '';
1883
  $output .= isset($properties['wrapper']['whl'][0]) ? $properties['wrapper']['whl'][0] : '';
1884
  if ($properties['use_link_theme']) {
1885
    $link_variables = array(
1886
      'menu_item' => $element['item'],
1887
      'link_options' => $element['localized_options']
1888
    );
1889
    $output .= theme('superfish_menu_item_link', $link_variables);
1890
  }
1891
  else {
1892
    $output .= l($element['item']['link']['title'], $element['item']['link']['href'], $element['localized_options']);
1893
  }
1894
  $output .= isset($properties['wrapper']['whl'][1]) ? $properties['wrapper']['whl'][1] : '';
1895
  $output .= ($properties['megamenu']['megamenu_wrapper']) ? '<ul class="sf-megamenu"><li class="sf-megamenu-wrapper ' . $element['attributes']['class'] . '">' : '';
1896
  $output .= $sub_menu;
1897
  $output .= ($properties['megamenu']['megamenu_wrapper']) ? '</li></ul>' : '';
1898
  $output .= ($properties['megamenu']['megamenu_column']) ? '</div>' : '';
1899
  $output .= '</li>';
1900

    
1901
  return $output;
1902
}
1903
/**
1904
 * Theme a menu item link.
1905
 *
1906
 * @param $variables
1907
 *   An array of variables containing:
1908
 *    - menu_item: The menu item array.
1909
 *    - link_options: An array of link options.
1910
 *
1911
 * @ingroup themeable
1912
 */
1913
function theme_superfish_menu_item_link($variables) {
1914
  $menu_item = $variables['menu_item'];
1915
  $link_options = $variables['link_options'];
1916
  return l($menu_item['link']['title'], $menu_item['link']['href'], $link_options);
1917
}