Newer
Older
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
// $Id$
require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc');
/**
* gallery.module : gallery_block_admin.inc
* Block settings functions
*/
/**
* Function _gallery_block_admin_navigation().
*/
function _gallery_block_admin_navigation() {
$form['gallery_block_navigation_cache'] = array(
'#type' => 'select',
'#title' => t('Block cache'),
'#default_value' => variable_get('gallery_block_navigation_cache', BLOCK_CACHE_PER_USER),
'#options' => array(
BLOCK_NO_CACHE => t('Cache disabled'),
BLOCK_CACHE_PER_USER => t('Cache per user')
),
'#description' => t('Configure cache settings for this block. It\'s usually safe to set this to \'Cache per user\'.')
);
return $form;
}
/**
* Function _gallery_block_admin_block().
*/
function _gallery_block_admin_block($delta) {
$block_map = _gallery_block_map(TRUE);
$block_type = variable_get('gallery_block_'. $delta .'_type', 'imageblock');
$plugin = $block_map[$block_type]['plugin'];
$plugin_block = $block_map[$block_type]['block'];
// General block settings (common for all G2 block types)
$form['gallery_block_'. $delta .'_blockid'] = array(
'#type' => 'textfield',
'#title' => t('Block Identifier [Block @id]', array('@id' => $delta)),
'#default_value' => variable_get('gallery_block_'. $delta .'_blockid', ''),
'#size' => 30,
'#maxlength' => 255,
'#description' => t('A short identifier to distinguish blocks of the same type. (Blocks are numbered by default)')
);
$form['gallery_block_'. $delta .'_cache'] = array(
'#type' => 'select',
'#title' => t('Block cache'),
'#default_value' => variable_get('gallery_block_'. $delta .'_cache', BLOCK_CACHE_PER_USER),
'#options' => array(
BLOCK_NO_CACHE => t('Cache disabled'),
BLOCK_CACHE_PER_USER => t('Cache per user'),
BLOCK_CACHE_PER_ROLE => t('Cache per role')
),
'#description' => _gallery_block_admin_description($block_type .'_cache'),
);
// Block type selector
$block_list = array();
foreach ($block_map as $type => $details) {
$block_list[$type] = $details['block'];
}
$form['gallery_block_'. $delta .'_type'] = array(
'#type' => 'select',
'#title' => t('Block type'),
'#default_value' => $block_type,
'#options' => $block_list,
'#description' => t('Select the Gallery2 block to be used in this Drupal block. In previous versions only
\'ImageBlock\' was available, but now you can embed any Gallery2 block in Drupal.'),
);
// Block specific settings
$form[$block_type] = array(
'#type' => 'fieldset',
'#title' => t('%block settings', array('%block' => $plugin_block)),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form[$block_type][] = _gallery_block_admin_block_params($delta, $plugin, $plugin_block);
return $form;
}
/**
* Function _gallery_block_admin_description().
*/
function _gallery_block_admin_description($element) {
// TODO
switch($element) {
case 'imageblock_cache':
return t('Configure cache settings for this block. Unless random images are used you can safely keep this to
\'Cache per user\' (default). If you dont have per-user permissions configured in your gallery you
can improve performance by setting to \'Cache per role\'.');
default:
return '';
}
}
/**
* Function _gallery_block_admin_block_params().
*/
function _gallery_block_admin_block_params($delta, $plugin, $plugin_block) {
$g2_blocks = gallery_get_blocks();
if ($plugin_block == 'ImageBlock') {
// Image block specific settings
_gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blocks, $form);
}
else {
// Generate a Drupal form element for each G2 block variable
foreach ($g2_blocks[$plugin][$plugin_block]['vars'] as $parameter => $options) {
$block = strtolower($plugin_block .'_'. $parameter);
$element = 'gallery_block_'. $delta .'_'. $block;
// Common form element properties
$form[$element] = array(
'#title' => $options['description'],
'#default_value' => variable_get($element, $options['default']),
'#description' => _gallery_block_admin_description($block),
);
// Form element type specific properties
switch ($options['type']) {
case 'boolean':
$form[$element]['#type'] = 'checkbox';
break;
case 'text':
$form[$element]['#type'] = 'textfield';
$form[$element]['#size'] = max(10, min(80, strlen($options['default'])));
$form[$element]['#maxlength'] = 255;
break;
case 'choice':
$form[$element]['#type'] = 'select';
$form[$element]['#options'] = $options['choices'];
break;
default:
}
}
}
return $form;
}
/**
* Function _gallery_block_admin_imageblock().
*/
function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blocks, &$form) {
$plugin_status = gallery_plugin_status(array('imageblock', 'imageframe'));
$form['imageblock']['#description'] = t('The Gallery Image/Grid Block requires the Gallery2 Image Block plugin
(!imageblock_status) and optionally the Gallery2 Image Frame plugin
(!imageframe_status).', array(
'!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
'!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))
);
$element = 'gallery_block_'. $delta .'_'. strtolower($plugin_block);
$num_cols = variable_get($element .'_num_cols', 2);
$num_rows = variable_get($element .'_num_rows', 2);
$numimages = $num_cols * $num_rows;
$form[$element .'_num_cols'] = array(
'#type' => 'select',
'#title' => t('Number of columns'),
'#default_value' => variable_get($element .'_num_cols', 2),
'#options' => _gallery_range_array(1, 10),
'#description' => t('Select the number of columns in the grid.'),
);
$form[$element .'_num_rows'] = array(
'#type' => 'select',
'#title' => t('Number of rows'),
'#default_value' => variable_get($element .'_num_rows', 2),
'#options' => _gallery_range_array(1, 10),
'#description' => t('Select the number of rows in the grid.'),
);
$form[$element .'_block_block'] = array(
'#type' => 'fieldset',
'#title' => t('Image types'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
'#description' => t('Pick the type of images you would like to see. You can select the same type more than once.'),
);
$gallery_block_block = variable_get($element .'_block_block', array('randomImage'));
for ($i=0; $i<$numimages; $i++) {
$form[$element .'_block_block'][$i] = array(
'#type' => 'select',
'#title' => '',
'#default_value' => isset($gallery_block_block[$i]) ? $gallery_block_block[$i] : NULL,
'#options' => array_merge(array(NULL => t('None')), $g2_blocks[$plugin][$plugin_block]['vars']['blocks']['choices']),
);
}
$form[$element .'_item_id'] = array(
'#type' => 'textfield',
'#title' => t('Album or Item ID'),
'#default_value' => variable_get($element .'_item_id', ''),
'#size' => 20,
'#maxlength' => 20,
'#description' => t('Enter the Gallery image or album ID (or blank). If an album or item ID is specified, random
images will only be selected from that album and its sub-albums. If \'user\' (or \'user:123\')
is entered, items will be taken from the current (or specified) user\'s useralbum.')
);
$form[$element .'_block_show'] = array(
'#type' => 'checkboxes',
'#title' => t('Image data'),
'#default_value' => variable_get($element .'_block_show', array('title', 'heading')),
'#options' => array(
'title' => t('Title'),
'date' => t('Date'),
'views' => t('View Count'),
'owner' => t('Item owner'),
'heading' => t('Heading')
),
'#description' => t('Choose the item metadata you would like to display.'),
);
$form[$element .'_size_method'] = array(
'#type' => 'select',
'#title' => t('Image size method'),
'#default_value' => variable_get($element .'_size_method', GALLERY_IMAGEBLOCK_SIZE_METHOD_DEFAULT),
'#options' => array(
'maxsize' => t('Max Size'),
'exactsize' => t('Exact Size'),
),
'#description' => t('\'Max Size\' gives faster image downloading, but the image size
may be smaller than the size defined below. <br />\'Exact Size\' may be slower
(as a larger image is downloaded and then scaled by the browser) but the image
will be guaranteed to be the size defined below.'),
);
$form[$element .'_size'] = array(
'#type' => 'textfield',
'#title' => t('Image size'),
'#default_value' => variable_get($element .'_size', GALLERY_IMAGEBLOCK_SIZE_DEFAULT),
'#size' => 10,
'#maxlength' => 10,
'#description' => t('Sets the size (in pixels) of the longest side of the image according to the method defined above.'),
);
$imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
$image_frames = gallery_get_image_frames();
$form[$element .'_album_frame'] = array(
'#type' => 'select',
'#title' => t('Album frame'),
'#default_value' => variable_get($element .'_album_frame', 'none'),
'#options' => $image_frames,
'#description' => $imageframe_desc,
);
$form[$element .'_item_frame'] = array(
'#type' => 'select',
'#title' => t('Item frame'),
'#default_value' => variable_get($element .'_item_frame', 'none'),
'#options' => $image_frames,
'#description' => $imageframe_desc,
);
$form[$element .'_link_target'] = array(
'#type' => 'textfield',
'#title' => t('Link target'),
'#default_value' => variable_get($element .'_link_target', ''),
'#size' => 20,
'#maxlength' => 20,
'#description' => t('Enter a link target (e.g. \'_blank\' to open in a new window).'),
);
$form[$element .'_link'] = array(
'#type' => 'textfield',
'#title' => t('Image Link'),
'#default_value' => variable_get($element .'_link', ''),
'#size' => 60,
'#maxlength' => 255,
'#description' => t('By default the image has a link to the item in the Gallery. This
can be overridden here (or leave empty for the default). Use \'none\' for no link, or a URL
to link somewhere else instead.'),
);
$form['element'] = array('#type' => 'value', '#value' => $element);
$form['update_btn'] = array(
'#type' => 'submit',
'#value' => t('Save and Edit'),
'#submit' => array('_gallery_block_admin_update')
);
return $form;
}
/**
* Function _gallery_block_admin_update().
*/
function _gallery_block_admin_update($form, &$form_state) {
_gallery_block_admin_save(0, $form_state['values']);
}
/**
* Function _gallery_block_admin_save().
*/
function _gallery_block_admin_save($delta, $values) {
$element = $values['element'];
unset($values['element']);
// Validate variable values
if (isset($values[$element .'_size'])) {
if (!is_numeric($values[$element .'_size']) || $values[$element .'_size'] < 10) {
$values[$element .'_size'] = 10;
drupal_set_message(t('Image size must be a number greater than ten pixels.
(The value has been updated to \'10\' for your convenience.)'), 'error');
}
}
// Save variables
foreach ($values as $key => $value) {
if (strpos($key, $element) == 0) {
if (is_array($value)) {
$value = array_values(array_filter($value));
}
variable_set($key, $value);
}
}
}