1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Installation actions for FlexSlider
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
/**
|
8 |
|
|
* Implements hook_schema().
|
9 |
|
|
*/
|
10 |
|
|
function flexslider_schema() {
|
11 |
|
|
$schema = array();
|
12 |
|
|
|
13 |
|
|
$schema['flexslider_optionset'] = array(
|
14 |
|
|
'description' => 'Store option sets for flexslider instances.',
|
15 |
|
|
'export' => array(
|
16 |
|
|
'key' => 'name',
|
17 |
|
|
'identifier' => 'preset',
|
18 |
|
|
'default hook' => 'flexslider_default_presets',
|
19 |
|
|
'api' => array(
|
20 |
|
|
'owner' => 'flexslider',
|
21 |
|
|
'api' => 'flexslider_default_preset',
|
22 |
|
|
'minimum_version' => 1,
|
23 |
|
|
'current_version' => 1,
|
24 |
|
|
),
|
25 |
|
|
),
|
26 |
|
|
'fields' => array(
|
27 |
|
|
'name' => array(
|
28 |
|
|
'description' => 'The machine-readable option set name.',
|
29 |
|
|
'type' => 'varchar',
|
30 |
|
|
'length' => 255,
|
31 |
|
|
'not null' => TRUE,
|
32 |
|
|
),
|
33 |
|
|
'title' => array(
|
34 |
|
|
'description' => 'The human-readable title for this option set.',
|
35 |
|
|
'type' => 'varchar',
|
36 |
|
|
'length' => 255,
|
37 |
|
|
'not null' => TRUE,
|
38 |
|
|
),
|
39 |
|
|
'theme' => array(
|
40 |
|
|
'description' => 'The flexslider theme.',
|
41 |
|
|
'type' => 'varchar',
|
42 |
|
|
'length' => 255,
|
43 |
|
|
'not null' => TRUE,
|
44 |
|
|
'default' => 'classic',
|
45 |
|
|
),
|
46 |
|
|
'imagestyle_normal' => array(
|
47 |
|
|
'description' => 'The image style for normal images.',
|
48 |
|
|
'type' => 'varchar',
|
49 |
|
|
'length' => 255,
|
50 |
|
|
'not null' => TRUE,
|
51 |
|
|
'default' => 'flexslider_full',
|
52 |
|
|
),
|
53 |
|
|
'imagestyle_thumbnail' => array(
|
54 |
|
|
'description' => 'The image style for thumbnail images.',
|
55 |
|
|
'type' => 'varchar',
|
56 |
|
|
'length' => 255,
|
57 |
|
|
'not null' => TRUE,
|
58 |
|
|
'default' => 'flexslider_thumbnail',
|
59 |
|
|
),
|
60 |
|
|
'options' => array(
|
61 |
|
|
'description' => 'The options array.',
|
62 |
|
|
'type' => 'blob',
|
63 |
|
|
'size' => 'big',
|
64 |
|
|
'serialize' => TRUE,
|
65 |
|
|
),
|
66 |
|
|
),
|
67 |
|
|
'primary key' => array('name'),
|
68 |
|
|
);
|
69 |
|
|
|
70 |
|
|
return $schema;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
/**
|
74 |
|
|
* Implements hook_install().
|
75 |
|
|
*
|
76 |
|
|
* Adds a 'default' option set for fresh installs.
|
77 |
|
|
*/
|
78 |
|
|
function flexslider_install() {
|
79 |
|
|
// Do nothing for now
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
/**
|
83 |
|
|
* Implements hook_uninstall().
|
84 |
|
|
*/
|
85 |
|
|
function flexslider_uninstall() {
|
86 |
|
|
variable_del('flexslider_debug');
|
87 |
|
|
variable_del('flexslider_version');
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
/**
|
91 |
|
|
* Implements hook_requirements().
|
92 |
|
|
*/
|
93 |
|
|
function flexslider_requirements($phase) {
|
94 |
|
|
$requirements = array();
|
95 |
|
|
// Ensure translations don't break at install time
|
96 |
|
|
$t = get_t();
|
97 |
|
|
|
98 |
|
|
// Check to see if the flexslider library is available
|
99 |
|
|
if ($phase == 'runtime') {
|
100 |
|
|
$requirements['flexslider'] = array(
|
101 |
|
|
'title' => $t('FlexSlider'),
|
102 |
|
|
// @todo have the version automatically detected
|
103 |
|
|
'description' => $t('Version 2.0 installed'),
|
104 |
|
|
'severity' => REQUIREMENT_OK,
|
105 |
|
|
);
|
106 |
|
|
_flexslider_requirements_library_installed($requirements);
|
107 |
|
|
}
|
108 |
|
|
return $requirements;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
/**
|
112 |
|
|
* Implements hook_update_N().
|
113 |
|
|
*
|
114 |
|
|
* Remove/Update table fields to better suit FlexSlider
|
115 |
|
|
*/
|
116 |
|
|
function flexslider_update_7001(&$sandbox) {
|
117 |
|
|
$field_new = array(
|
118 |
|
|
'description' => 'The image style for normal images.',
|
119 |
|
|
'type' => 'varchar',
|
120 |
|
|
'length' => 255,
|
121 |
|
|
'not null' => TRUE,
|
122 |
|
|
'default' => 'flexslider_full',
|
123 |
|
|
);
|
124 |
|
|
// Change the default image style
|
125 |
|
|
db_change_field('flexslider_optionset', 'imagestyle_normal', $field_new, array());
|
126 |
|
|
// Drop the unused table column
|
127 |
|
|
db_drop_field('flexslider_optionset', 'imagestyle_thumb');
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
/**
|
131 |
|
|
* Implements hook_update_N().
|
132 |
|
|
*
|
133 |
|
|
* Enables the Image module since it is now explicitly listed as a
|
134 |
|
|
* dependency.
|
135 |
|
|
*/
|
136 |
|
|
function flexslider_update_7002(&$sandbox) {
|
137 |
|
|
module_enable(array('image'));
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
/**
|
141 |
|
|
* Implements hook_update_N().
|
142 |
|
|
*
|
143 |
|
|
* Migrate settings from FlexSlider v1 to v2
|
144 |
|
|
*/
|
145 |
|
|
function flexslider_update_7200(&$sandbox) {
|
146 |
|
|
$t = get_t();
|
147 |
|
|
|
148 |
|
|
$optionsets = flexslider_optionset_load_all();
|
149 |
|
|
|
150 |
|
|
foreach ($optionsets as $optionset) {
|
151 |
|
|
// Map old options to new keys/values
|
152 |
|
|
$optionset->options['animationSpeed'] = $optionset->options['animationDuration'];
|
153 |
|
|
$optionset->options['direction'] = $optionset->options['slidedirection'];
|
154 |
|
|
$optionset->options['keyboard'] = $optionset->options['keyboardnav'];
|
155 |
|
|
$optionset->options['startAt'] = $optionset->options['slidetostart'];
|
156 |
|
|
$optionset->options['start'] = $optionset->options['startCallback'];
|
157 |
|
|
$optionset->options['before'] = $optionset->options['beforeCallback'];
|
158 |
|
|
$optionset->options['after'] = $optionset->options['afterCallback'];
|
159 |
|
|
$optionset->options['end'] = $optionset->options['endCallback'];
|
160 |
|
|
|
161 |
|
|
// Delete any options which no longer exist
|
162 |
|
|
unset($optionset->options['animationDuration']);
|
163 |
|
|
unset($optionset->options['slidedirection']);
|
164 |
|
|
unset($optionset->options['keyboardnav']);
|
165 |
|
|
unset($optionset->options['startCallback']);
|
166 |
|
|
unset($optionset->options['beforeCallback']);
|
167 |
|
|
unset($optionset->options['afterCallback']);
|
168 |
|
|
unset($optionset->options['endCallback']);
|
169 |
|
|
unset($optionset->options['controlsContainer']); // This value changed in the new version. We have to reset it to the default value
|
170 |
|
|
|
171 |
|
|
// Merge in defaults for new options
|
172 |
|
|
$optionset->options += _flexslider_optionset_defaults();
|
173 |
|
|
|
174 |
|
|
// Save the updated optionset
|
175 |
|
|
flexslider_optionset_save($optionset);
|
176 |
|
|
}
|
177 |
|
|
drupal_set_message($t('Optionsets migrated. However it is recommended to go validate all your settings manually. Especially if you have callback functions defined. They may reference functions which no longer exist.'), 'warning');
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
function flexslider_update_7201(&$sandbox) {
|
181 |
|
|
$field_new = array(
|
182 |
|
|
'description' => 'The image style for thumbnail images.',
|
183 |
|
|
'type' => 'varchar',
|
184 |
|
|
'length' => 255,
|
185 |
|
|
'not null' => TRUE,
|
186 |
|
|
'default' => 'flexslider_thumbnail',
|
187 |
|
|
);
|
188 |
|
|
// Change the default image style
|
189 |
|
|
db_add_field('flexslider_optionset', 'imagestyle_thumbnail', $field_new, array());
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
/**
|
193 |
|
|
* Check if the library is available
|
194 |
|
|
*
|
195 |
|
|
* @param array $requirements
|
196 |
|
|
* Requirements definition
|
197 |
|
|
*/
|
198 |
|
|
function _flexslider_requirements_library_installed(&$requirements) {
|
199 |
|
|
$t = get_t();
|
200 |
|
|
|
201 |
|
|
$path = libraries_get_path('flexslider');
|
202 |
|
|
$installed = file_exists($path . '/jquery.flexslider-min.js') && file_exists($path . '/jquery.flexslider.js');
|
203 |
|
|
|
204 |
|
|
// Check the results of the test
|
205 |
|
|
if (!$installed) {
|
206 |
|
|
$requirements['flexslider']['description'] = $t('FlexSlider library not found. Please consult the README.txt for installation instructions.');
|
207 |
|
|
$requirements['flexslider']['severity'] = REQUIREMENT_ERROR;
|
208 |
|
|
$requirements['flexslider']['value'] = $t('FlexSlider library not found.');
|
209 |
|
|
return;
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
$js = file_exists($path . '/jquery.flexslider-min.js') ? fopen($path . '/jquery.flexslider-min.js', 'r') : fopen($path . '/jquery.flexslider.js', 'r');
|
213 |
|
|
$header = fread($js, 64);
|
214 |
|
|
$matches = array();
|
215 |
|
|
if (preg_match("/ v([0-9]+)\.([0-9]+)/", $header, $matches)) {
|
216 |
|
|
if (!($matches[1] == 2 and $matches[2] >= 0)) {
|
217 |
|
|
$requirements['flexslider']['description'] = $t('FlexSlider must be version 2.0 or higher, but lower than version 3.0. Please consult the README.txt for installation instructions.');
|
218 |
|
|
$requirements['flexslider']['severity'] = REQUIREMENT_WARNING;
|
219 |
|
|
$requirements['flexslider']['value'] = $t('Incorrect version detected.');
|
220 |
|
|
return;
|
221 |
|
|
}
|
222 |
|
|
else {
|
223 |
|
|
$version = $matches[1] . "." . $matches[2];
|
224 |
|
|
variable_set('flexslider_version', $version);
|
225 |
|
|
$requirements['flexslider']['description'] = $t('Version %version installed', array( '%version' => $version));
|
226 |
|
|
$requirements['flexslider']['value'] = $t('FlexSlider library installed.');
|
227 |
|
|
return;
|
228 |
|
|
}
|
229 |
|
|
}
|
230 |
|
|
else {
|
231 |
|
|
$requirements['flexslider']['description'] = $t('FlexSlider version could not be determined. Please consult the README.txt for installation instructions.');
|
232 |
|
|
$requirements['flexslider']['severity'] = REQUIREMENT_WARNING;
|
233 |
|
|
$requirements['flexslider']['value'] = $t('Unable to detect version.');
|
234 |
|
|
}
|
235 |
|
|
}
|
236 |
|
|
|
237 |
|
|
// @todo add hook_update_N function to migrate old option set data to new values |