1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Functions that are only called on the admin pages.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Generate the default path for the Superfish library.
|
10 |
|
|
*/
|
11 |
|
|
function slp_default() {
|
12 |
|
|
// Ensure the Libraries API module is installed and working.
|
13 |
|
|
if (module_exists('libraries') && function_exists('libraries_get_path')) {
|
14 |
|
|
$directory = libraries_get_path('superfish');
|
15 |
|
|
}
|
16 |
|
|
// Otherwise use the default directory.
|
17 |
|
|
else {
|
18 |
|
|
$directory = 'sites/all/libraries/superfish';
|
19 |
|
|
}
|
20 |
|
|
if (file_exists($directory)) {
|
21 |
|
|
$output = $directory . "/jquery.hoverIntent.minified.js\n" .
|
22 |
|
|
$directory . "/jquery.bgiframe.min.js\n" .
|
23 |
|
|
$directory . "/superfish.js\n" .
|
24 |
|
|
$directory . "/supersubs.js\n" .
|
25 |
|
|
$directory . "/supposition.js\n" .
|
26 |
|
|
$directory . "/sftouchscreen.js\n" .
|
27 |
|
|
$directory . "/sfsmallscreen.js";
|
28 |
|
|
}
|
29 |
|
|
else {
|
30 |
|
|
$output = '';
|
31 |
|
|
}
|
32 |
|
|
return $output;
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
/**
|
36 |
|
|
* Overriding system settings form.
|
37 |
|
|
*/
|
38 |
|
|
function superfish_system_settings_form($form, $automatic_defaults = TRUE) {
|
39 |
|
|
$form['actions']['#type'] = 'container';
|
40 |
|
|
$form['actions']['#attributes']['class'][] = 'form-actions';
|
41 |
|
|
$form['actions']['#weight'] = 100;
|
42 |
|
|
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
|
43 |
|
|
|
44 |
|
|
if ($automatic_defaults) {
|
45 |
|
|
$form = _system_settings_form_automatic_defaults($form);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
if (!empty($_POST) && form_get_errors()) {
|
49 |
|
|
drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
|
50 |
|
|
}
|
51 |
|
|
$form['#submit'][] = 'system_settings_form_submit';
|
52 |
|
|
// By default, render the form using theme_system_settings_form().
|
53 |
|
|
if (!isset($form['#theme'])) {
|
54 |
|
|
$form['#theme'] = 'system_settings_form';
|
55 |
|
|
}
|
56 |
|
|
return $form;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Module settings form.
|
61 |
|
|
*/
|
62 |
|
|
function superfish_admin_settings() {
|
63 |
|
|
$form['superfish_number'] = array(
|
64 |
|
|
'#type' => 'select',
|
65 |
|
|
'#title' => t('Number of blocks'),
|
66 |
|
|
'#multiple' => FALSE,
|
67 |
|
|
'#options' => drupal_map_assoc(range(1, 50)),
|
68 |
|
|
'#description' => t('The number of Superfish menu blocks.'),
|
69 |
|
|
'#default_value' => variable_get('superfish_number', 4),
|
70 |
|
|
);
|
71 |
|
|
$form['superfish_slp'] = array(
|
72 |
|
|
'#type' => 'textarea',
|
73 |
|
|
'#title' => t('Path to Superfish library'),
|
74 |
|
|
'#description' => t('Edit only if you are sure of what you are doing.'),
|
75 |
|
|
'#default_value' => variable_get('superfish_slp', slp_default()),
|
76 |
|
|
'#rows' => 7,
|
77 |
|
|
);
|
78 |
|
|
return superfish_system_settings_form($form, FALSE);
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
/**
|
82 |
|
|
* Implements hook_validate().
|
83 |
|
|
*/
|
84 |
|
|
function superfish_admin_settings_validate($form, &$form_state) {
|
85 |
|
|
$error = array();
|
86 |
|
|
$sf_library = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", trim($form_state['values']['superfish_slp']));
|
87 |
|
|
if (empty($sf_library)) {
|
88 |
|
|
form_set_error('superfish_slp', t('<strong>Path to Superfish library</strong> field cannot be empty. Please try the below list:<br />' . '<pre>' . slp_default() . '</pre>'));
|
89 |
|
|
}
|
90 |
|
|
else {
|
91 |
|
|
// Trimming blank lines and such
|
92 |
|
|
$sf_library = explode("\n", $sf_library);
|
93 |
|
|
// Crystal clear
|
94 |
|
|
foreach ($sf_library as $s) {
|
95 |
|
|
if (!file_exists($s)) {
|
96 |
|
|
$error[] = $s;
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
if (!empty($error)) {
|
100 |
|
|
$error_message = '';
|
101 |
|
|
if (count($error) > 1) {
|
102 |
|
|
foreach ($error as $e) {
|
103 |
|
|
$error_message .= '<li>' . $e . '</li>';
|
104 |
|
|
}
|
105 |
|
|
$error_message = t('Files not found') . ': <ul>' . $error_message . '</ul>';
|
106 |
|
|
}
|
107 |
|
|
else {
|
108 |
|
|
$error_message = t('File not found') . ': ' . $error[0];
|
109 |
|
|
}
|
110 |
|
|
form_set_error('superfish_slp', $error_message);
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
} |