-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgalleria.install
236 lines (229 loc) · 7.51 KB
/
galleria.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
/**
* @file
* Install, update and uninstall functions for the galleria module.
*/
/**
* Implements hook_schema().
* Always returns the latest schema version!
*/
function galleria_schema() {
return array(
'galleria_optionset' => array(
'description' => 'Store option sets for Galleria instances.',
'export' => array(
'key' => 'name',
'identifier' => 'preset',
'default hook' => 'galleria_default_presets',
'api' => array(
'owner' => 'galleria',
'api' => 'galleria_default_preset',
'minimum_version' => 1,
'current_version' => 1,
),
),
'fields' => array(
'name' => array(
'description' => 'The machine-readable option set name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'title' => array(
'description' => 'The human-readable title for this option set.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'theme' => array(
'description' => 'The Galleria theme.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'classic',
),
'plugins' => array(
'description' => 'The Galleria plugins to be loaded.',
'type' => 'blob',
'size' => 'big',
'serialize' => TRUE,
),
'imagestyle_thumb' => array(
'description' => 'The image style for thumbnails.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'galleria_thumb',
),
'imagestyle_normal' => array(
'description' => 'The image style for normal images.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'galleria_zoom',
),
'imagestyle_big' => array(
'description' => 'The image style for big images (lightbox and fullscreen).',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '', // original image
),
'options' => array(
'description' => 'The options array.',
'type' => 'blob',
'size' => 'big',
'serialize' => TRUE,
),
),
'primary key' => array('name'),
),
);
}
/**
* Create the first version of the new database schema.
*/
function galleria_update_7000() {
// Warning: Code duplication intended! Do not use galleria_schema() here, see http://drupal.org/node/150220
if (!db_table_exists('galleria_optionset')) {
// Create optionset table
db_create_table('galleria_optionset', array(
'description' => 'Store option sets for Galleria instances.',
'fields' => array(
'name' => array(
'description' => 'The machine-readable option set name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'title' => array(
'description' => 'The human-readable title for this option set.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'options' => array(
'description' => 'The options array.',
'type' => 'blob',
'size' => 'big',
'serialize' => TRUE,
),
),
'primary key' => array('name'),
));
// Migrate old variable-based options into the optionset table
$oldvars = array(
// old_var_name => array(old_default_value, new_var_name, new_default_value),
'height' => array( 300, 'height', NULL),
'width' => array( 450, 'width', NULL),
'autoplay' => array( 0, 'autoplay', 0),
'clicknext' => array(TRUE, 'clicknext', FALSE),
'imagecrop' => array('on', 'imageCrop', 'false'),
'max_scale_ratio' => array( 1, 'maxScaleRatio', NULL),
'min_scale_ratio' => array( 1, 'minScaleRatio', NULL),
'overlay_opacity' => array(0.85, 'overlayOpacity', 0.85),
'preload' => array( 3, 'preload', 2),
'queue' => array(TRUE, 'queue', TRUE),
'show_counter' => array(TRUE, 'showCounter', TRUE),
'show_imagenav' => array(TRUE, 'showImagenav', TRUE),
'show_info' => array(TRUE, 'showInfo', TRUE),
'thumbnails' => array('on', 'thumbnails', 'true'),
'transition' => array('fade', 'transition', 'fade'),
'lib_file' => FALSE, // just delete this variable
);
$options = array();
foreach ($oldvars as $oldvar => $data) {
if (is_array($data)) {
$value = variable_get('galleria_' . $oldvar, $data[0]);
$value = ($value == 'on') ? 'true' : ($value == 'off' ? 'false' : $value);
if ($value != $data[2])
$options[$data[1]] = $value;
}
variable_del('galleria_' . $oldvar);
}
db_insert('galleria_optionset')->fields(array(
'name' => 'default',
'title' => 'Default',
'options' => serialize($options),
))->execute();
}
}
/**
* Integrate image style settings into the option sets.
*/
function galleria_update_7001() {
$new_fields = array(
'theme' => array(
'description' => 'The Galleria theme.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'classic',
),
'imagestyle_thumb' => array(
'description' => 'The image style for thumbnails.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'galleria_thumb',
),
'imagestyle_normal' => array(
'description' => 'The image style for normal images.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'galleria_zoom',
),
'imagestyle_big' => array(
'description' => 'The image style for big images (lightbox and fullscreen).',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '', // original image
),
);
foreach ($new_fields as $field => $spec) {
db_add_field('galleria_optionset', $field, $spec);
}
return t('You have to re-adjust the theme and image styles for your Galleria instances.');
}
/**
* Updates renamed field formatter settings.
*/
function galleria_update_7002() {
drupal_load('module', 'field');
foreach (field_info_instances('node') as $node_type => $field_instances) {
foreach ($field_instances as $field_instance) {
$changed = FALSE;
foreach ($field_instance['display'] as &$display) {
if (($display['module'] == 'galleria') && ($display['type'] == 'galleria')) {
$settings = &$display['settings'];
$settings['optionset'] = $settings['galleria_optionset'];
unset($settings['galleria_optionset']);
unset($settings['galleria_reference_img_src']);
$changed = TRUE;
}
}
if ($changed) {
field_update_instance($field_instance);
}
}
}
}
/**
* Add support for Galleria plugins.
*/
function galleria_update_7003() {
$new_fields = array(
'plugins' => array(
'description' => 'The Galleria plugins to be loaded.',
'type' => 'blob',
'size' => 'big',
'serialize' => TRUE,
),
);
foreach ($new_fields as $field => $spec) {
db_add_field('galleria_optionset', $field, $spec);
}
return t('You may now select plugins to be loaded with each Galleria instance.');
}