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