Stripping CVS keywords
[project/gallery.git] / gallery_settings.inc
CommitLineData
c15e9178 1<?php
c15e9178 2
3/**
4 * gallery.module : gallery_settings.inc
5 * Settings functions
6 */
e65698fe 7
c15e9178 8/**
e65698fe 9 * Function _gallery_settings_general().
c15e9178 10 */
e65698fe
TW
11function _gallery_settings_general() {
12 // Short Status
13 gallery_version();
14 gallery_plugin_set_status(array('imageblock', 'imageframe', 'search'));
15 $status = gallery_get_status();
c15e9178 16
e65698fe
TW
17 $form['status'] = array(
18 '#type' => 'fieldset',
19 '#title' => t('Status'),
20 '#description' => gallery_format_status($status, ''),
21 '#collapsible' => FALSE,
22 '#collapsed' => FALSE,
eebfd4f9 23 );
e65698fe
TW
24
25 // Theme Settings
26 $form['theme'] = array(
c15e9178 27 '#type' => 'fieldset',
e65698fe 28 '#title' => t('Theme settings'),
c15e9178 29 '#description' => '',
e65698fe 30 '#collapsible' => TRUE,
c15e9178 31 '#collapsed' => TRUE,
c15e9178 32 );
e65698fe
TW
33 $themes = system_theme_data();
34 ksort($themes);
35 $options = array('default' => t('System default'));
36 foreach ($themes as $theme) {
dccc293a 37 $options[$theme->name] = $theme->info['name'];
e65698fe
TW
38 }
39 $form['theme']['gallery_page_theme'] = array(
40 '#type' => 'select',
41 '#title' => t('Gallery page theme'),
42 '#default_value' => variable_get('gallery_page_theme', 'default'),
43 '#options' => $options,
44 '#description' => t('Drupal theme to be used for all gallery pages (gallery/*).'),
c15e9178 45 );
e65698fe
TW
46
47 // Gallery Block Settings
48 $form['blocks'] = array(
c15e9178 49 '#type' => 'fieldset',
e65698fe
TW
50 '#title' => t('Gallery block settings'),
51 '#collapsible' => TRUE,
c15e9178 52 '#collapsed' => TRUE,
e65698fe
TW
53 '#description' => t('You can now have multiple image blocks and grid blocks. Use these settings to determine
54 the number of available blocks.<br /><strong>Warning: If you decrease the number of blocks,
55 always the last block (with the highest ID) will be removed.</strong>'),
c15e9178 56 );
e65698fe 57 $form['blocks']['gallery_block_image_num'] = array(
c15e9178 58 '#type' => 'textfield',
e65698fe
TW
59 '#title' => t('Number of image blocks'),
60 '#default_value' => variable_get('gallery_block_image_num', 1),
c15e9178 61 '#size' => 10,
62 '#maxlength' => 10,
e65698fe 63 '#description' => t('Select how many image blocks should be available.'),
55260521 64 );
e65698fe 65 $form['blocks']['gallery_block_grid_num'] = array(
55260521 66 '#type' => 'textfield',
e65698fe
TW
67 '#title' => t('Number of grid image blocks'),
68 '#default_value' => variable_get('gallery_block_grid_num', 1),
55260521 69 '#size' => 10,
70 '#maxlength' => 10,
e65698fe 71 '#description' => t('Select how many grid image blocks should be available.'),
55260521 72 );
e65698fe
TW
73
74 // Gallery2 Sidebar Settings
75 $form['sidebar'] = array(
c15e9178 76 '#type' => 'fieldset',
e65698fe 77 '#title' => t('Sidebar settings'),
c15e9178 78 '#description' => '',
e65698fe 79 '#collapsible' => TRUE,
c15e9178 80 '#collapsed' => TRUE,
c15e9178 81 );
e65698fe 82 $form['sidebar']['gallery_move_sidebar_to_block'] = array(
c15e9178 83 '#type' => 'checkbox',
e65698fe
TW
84 '#title' => t('Move Gallery2 sidebar to Drupal Gallery Navigation block'),
85 '#default_value' => variable_get('gallery_move_sidebar_to_block', 1),
86 '#description' => t('When selected, the Gallery2 sidebar will be moved into
87 the Drupal "Gallery Navigation" block. This typically allows
88 for a much cleaner embedded gallery and is generally
89 recommended. Note that you will need to enable the Gallery
90 Navigation block.'),
eebfd4f9 91 );
e65698fe
TW
92 $form['sidebar']['gallery_move_admin_sidebar_to_block'] = array(
93 '#type' => 'checkbox',
94 '#title' => t('Move Gallery2 Admin sidebar to Drupal Gallery Navigation block'),
95 '#default_value' => variable_get('gallery_move_admin_sidebar_to_block', 0),
96 '#description' => t('When selected, the Gallery2 Admin sidebar will be moved into
97 the Drupal "Gallery Navigation" block. This is not normally
98 recommended since the Admin Sitebar is very long and the
99 formatting does not always fit with the rest of the block
100 (but cannot be changed in the current Gallery2 versions).'),
101 '#disabled' => !variable_get('gallery_move_sidebar_to_block', 1),
eebfd4f9 102 );
dccc293a 103
e65698fe
TW
104 // Gallery2 Google Sitemap Settings
105 $gallery2_sitemap_status = gallery_single_plugin_status('sitemap');
106 $gallery2_sitemap_status_str = theme('gallery_plugin_status_message', $gallery2_sitemap_status);
dccc293a 107 $gsitemap_status = module_exists('gsitemap');
e65698fe 108 $gsitemap_status_str = theme('gallery_module_status_message', $gsitemap_status);
eebfd4f9 109
dccc293a
TW
110 $desc = t('Allows the Gallery2 Google (XML) sitemap to be merged
111 with the Drupal one so that only one URL
112 needs to be supplied to Google (or other search site). Requires the
113 Drupal gsitemap module (!gsitemap_status) and the Gallery2 sitemap module
114 (!gallery2_sitemap_status) to be installed/activated.',
e65698fe
TW
115 array(
116 '!gsitemap_status' => $gsitemap_status_str,
117 '!gallery2_sitemap_status' => $gallery2_sitemap_status_str,
118 )
eebfd4f9 119 );
dccc293a 120
e65698fe
TW
121 $form['sitemap'] = array(
122 '#type' => 'fieldset',
dccc293a 123 '#title' => t('Google (XML) sitemap settings'),
e65698fe
TW
124 '#description' => '',
125 '#collapsible' => TRUE,
126 '#collapsed' => TRUE,
127 '#description' => $desc,
c15e9178 128 );
e65698fe
TW
129 $form['sitemap']['gallery_enable_sitemap'] = array(
130 '#type' => 'checkbox',
131 '#title' => t('Enable merge of Gallery2 sitemap with Drupal sitemap'),
dccc293a
TW
132 '#default_value' => variable_get('gallery_enable_sitemap', 1),
133 '#disabled' => !($gsitemap_status && ($gallery2_sitemap_status == GALLERY_PLUGIN_ENABLED)),
c15e9178 134 );
dccc293a 135
e65698fe
TW
136 // Error logging / Debug Settings
137 $form['error'] = array(
c15e9178 138 '#type' => 'fieldset',
e65698fe 139 '#title' => t('Error logging / Debug settings'),
c15e9178 140 '#description' => '',
e65698fe 141 '#collapsible' => TRUE,
c15e9178 142 '#collapsed' => TRUE,
c15e9178 143 );
e65698fe
TW
144 $form['error']['gallery_error_mode'] = array(
145 '#type' => 'checkboxes',
146 '#title' => t('Error logging'),
147 '#default_value' => variable_get('gallery_error_mode', array(GALLERY_ERROR_WATCHDOG)),
148 '#options' => array(GALLERY_ERROR_WATCHDOG => t('Watchdog'),
149 GALLERY_ERROR_BROWSER => t('Output to the browser'),
150 GALLERY_ERROR_VERBOSE => t('Verbose error messages')),
151 '#description' => t('Choose where errors are displayed and how detailed they are.'),
c15e9178 152 );
e65698fe
TW
153 $form['error']['gallery_report'] = array(
154 '#type' => 'checkbox',
155 '#title' => t('Enable bug report assistant'),
156 '#default_value' => variable_get('gallery_report', 1),
157 '#description' => t('In case of errors the module can automatically assemble useful data (system info and debug
158 traces) to help you with detailed bug reports. Only available to users with \'administer
159 site configuration\' permission.')
c15e9178 160 );
e65698fe
TW
161 $search_status = module_exists('search') && (gallery_single_plugin_status('search') == GALLERY_PLUGIN_ENABLED);
162 $form['error']['gallery_error_redirect'] = array(
c15e9178 163 '#type' => 'checkbox',
e65698fe
TW
164 '#title' => t('Redirect to Gallery search form for invalid paths'),
165 '#default_value' => $search_status ? variable_get('gallery_error_redirect', 0) : 0,
166 '#description' => t('Instead of showing a message that the requested Gallery URL does not exist the user is redirected to the search form.'),
167 '#disabled' => !$search_status,
c15e9178 168 );
e65698fe
TW
169 $form['error']['gallery_debug'] = array(
170 '#type' => 'checkbox',
171 '#title' => t('Enable debug mode'),
172 '#default_value' => variable_get('gallery_debug', 0),
173 '#description' => t('Print out debug variables and verbose error messages. Only visible to users with \'administer site configuration\' permission.')
c15e9178 174 );
175
e65698fe
TW
176 // Relevant links
177 $form['links'] = array(
c15e9178 178 '#type' => 'fieldset',
e65698fe
TW
179 '#title' => t('Links to the most relevant Drupal & Gallery2 pages'),
180 '#collapsible' => TRUE,
c15e9178 181 '#collapsed' => TRUE,
55260521 182 );
e65698fe
TW
183 // Drupal links
184 $desc = '<ul>';
185 $desc .= '<li><a href="@gallery-users">Gallery users</a> : Gallery2 user integration and synchronization.</li>';
186 $desc .= '<li><a href="@gallery-report">Report Generator</a> : Collect information about your installation. Useful especially for bug reports.</li>';
187 $desc .= '</ul>';
188 $form['links']['drupal'] = array(
189 '#type' => 'fieldset',
190 '#title' => t('Links to Drupal paths'),
191 '#description' => t($desc, array(
192 '@gallery-users' => url('admin/user/gallery'),
193 '@gallery-report' => url('admin/settings/gallery/report/download'))),
194 '#collapsible' => FALSE,
195 '#collapsed' => FALSE,
c15e9178 196 );
e65698fe
TW
197 // Gallery2 links
198 $desc = '<ul>';
199 $desc .= '<li><a href="@g2-modules">Plugins</a> : To install, activate or configure the required and optional plugins relating to gallery.module (Image Block, Image Frame, URL Rewrite, Sitemap, Search).</li>';
200 $desc .= '<li><a href="@g2-themes">Themes</a> : To add/remove blocks in the sidebar.</li>';
dccc293a 201 $desc .= '<li><a href="@g2-rewrite">Embedded URL Rewrite settings</a> : To define the rewrite rules.</li>';
e65698fe
TW
202 $desc .= '<li><a href="@g2-cookie">Cookie Settings</a> : Only needed for a small number of site configurations, such as the use of different subdomains for Gallery2 and Drupal.</li>';
203 $desc .= '</ul>';
204 $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
205 $form['links']['gallery'] = array(
206 '#type' => 'fieldset',
207 '#title' => t('Links to Gallery2 Site Admin sections'),
208 '#description' => t($desc, array(
209 '@g2-modules' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules',
210 '@g2-themes' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminThemes&g2_mode=defaults',
211 '@g2-rewrite' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=rewrite.AdminRewrite&g2_mode=setup',
212 '@g2-cookie' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminCore')),
213 '#collapsible' => FALSE,
214 '#collapsed' => FALSE,
c15e9178 215 );
216
dccc293a
TW
217 $form = system_settings_form($form);
218 $form['#validate'] = array('_gallery_settings_general_validate');
219 $form['#submit'] = array('_gallery_settings_general_submit', 'system_settings_form_submit');
220 return $form;
e65698fe 221}
c15e9178 222
e65698fe
TW
223/**
224 * Function _gallery_settings_general_validate().
225 */
dccc293a
TW
226function _gallery_settings_general_validate($form, &$form_state) {
227 if (!is_numeric($form_state['values']['gallery_block_image_num']) || $form_state['values']['gallery_block_image_num'] < 1) {
e65698fe 228 form_set_error('gallery_block_image_num', t('Number of image blocks must be a positiv integer greater zero.'));
c15e9178 229 }
dccc293a 230 if (!is_numeric($form_state['values']['gallery_block_grid_num']) || $form_state['values']['gallery_block_grid_num'] < 1) {
e65698fe 231 form_set_error('gallery_block_grid_num', t('Number of grid blocks must be a positiv integer greater zero.'));
c15e9178 232 }
c15e9178 233}
234
235/**
e65698fe 236 * Function _gallery_settings_general_submit().
c15e9178 237 */
dccc293a
TW
238function _gallery_settings_general_submit($form, &$form_state) {
239 if ($form_state['values']['gallery_enable_sitemap'] != variable_get('gallery_enable_sitemap', 0)) {
240 drupal_set_message('The Google (XML) sitemap setting has been updated, but the new sitemap may not be generated immediately (controlled by gsitemap).');
e65698fe 241 }
c15e9178 242}
243
c15e9178 244/**
e65698fe 245 * Function _gallery_settings_block_image().
c15e9178 246 */
e65698fe
TW
247function _gallery_settings_block_image($delta) {
248 $plugin_status = gallery_plugin_status(array('imageblock', 'imageframe'));
c15e9178 249
e65698fe
TW
250 $imageblock_desc = t('The Gallery Image Block requires the Gallery2
251 Image Block plugin (!imageblock_status) and optionally the Gallery2 Image Frame
252 plugin (!imageframe_status).', array(
253 '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
254 '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
255 )
256 );
257 if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
258 $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
259 $g2_plugins_page = (variable_get('gallery_valid', 0)) ?
260 t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
261 array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
262 : t('Gallery2 Site Admin -> Plugins');
263 $g2_imageblock_desc = t(' However the Image Block plugin is unavailable, so this block is
264 not available and the settings are disabled. To use this block please go to
265 the !g2_plugins page and install/activate the Image Block plugin.', array(
266 '!g2_plugins' => $g2_plugins_page));
267 $imageblock_desc .= $g2_imageblock_desc;
c15e9178 268 }
269
e65698fe 270 $form['#description'] = $imageblock_desc;
c15e9178 271
e65698fe
TW
272 $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
273 t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
274 array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
275
276 $image_frames = gallery_get_image_frames();
277 _gallery_block_options($type_map, $param_map);
c15e9178 278
e65698fe
TW
279 if (variable_get('gallery_block_image_num', 1) > 1) {
280 $form['gallery_block_image_'. $delta .'_blockid'] = array(
281 '#type' => 'textfield',
282 '#title' => t('Block Identifier [Block @id]', array('@id' => $delta+1)),
283 '#default_value' => variable_get('gallery_block_image_'. $delta .'_blockid', ''),
284 '#size' => 25,
285 '#maxlength' => 30,
286 '#description' => t('A short identifier to distinguish blocks of the same type. (Blocks are numbered by default)'),
287 );
c15e9178 288 }
c15e9178 289
dccc293a 290 if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {
e65698fe
TW
291 $numimages = variable_get('gallery_block_image_'. $delta .'_num_images', 3);
292
293 $form['gallery_block_image_'. $delta .'_num_images'] = array(
294 '#type' => 'select',
295 '#title' => t('Number of images in block'),
296 '#default_value' => $numimages,
297 '#options' => _gallery_range_array(1, 20),
298 '#description' => t('Choose the number of images to appear. You will need to submit the form if you have increased the number in order to choose the image types.'),
299 );
300
301 $gallery_block_block = variable_get('gallery_block_image_'. $delta .'_block_block', array('randomImage'));
302
303 $form['gallery_block_image_'. $delta .'_block_block'] = array(
304 '#type' => 'fieldset',
305 '#title' => t('Image types'),
306 '#collapsible' => FALSE,
307 '#collapsed' => FALSE,
308 '#tree' => TRUE,
309 '#description' => t('Pick the type of images you would like to see. You can select the same type more than once.'),
310 );
311 for ($i=0; $i<$numimages; $i++) {
312 $form['gallery_block_image_'. $delta .'_block_block'][$i] = array(
313 '#type' => 'select',
314 '#title' => '',
dccc293a
TW
315 '#default_value' => isset($gallery_block_block[$i]) ? $gallery_block_block[$i] : '',
316 '#options' => array_merge(array('none' => t('None')), $type_map),
e65698fe
TW
317 );
318 }
319
320 $form['gallery_block_image_'. $delta .'_item_id'] = array(
321 '#type' => 'textfield',
322 '#title' => t('Album or Item ID'),
323 '#default_value' => variable_get('gallery_block_image_'. $delta .'_item_id', ''),
324 '#size' => 20,
325 '#maxlength' => 20,
326 '#description' => t('Enter the Gallery image or album ID (or blank). If an album or item ID is specified, random
dccc293a
TW
327 images will only be selected from that album and its sub-albums. If %user is specified,
328 items will be taken from the visitor\'s useralbum (if possible).')
e65698fe
TW
329 );
330
331 $form['gallery_block_image_'. $delta .'_block_show'] = array(
332 '#type' => 'checkboxes',
333 '#title' => t('Image data'),
334 '#default_value' => variable_get('gallery_block_image_'. $delta .'_block_show', array('title', 'heading')),
335 '#options' => $param_map,
336 '#description' => t('Choose the item metadata you would like to display.'),
337 );
338
339 $form['gallery_block_image_'. $delta .'_size_method'] = array(
340 '#type' => 'select',
341 '#title' => t('Image size method'),
342 '#default_value' => variable_get('gallery_block_image_'. $delta .'_size_method', GALLERY_IMAGEBLOCK_SIZE_METHOD_DEFAULT),
343 '#options' => array(
344 'maxsize' => t('Max Size'),
345 'exactsize' => t('Exact Size'),
346 ),
347 '#description' => t('\'Max Size\' gives faster image downloading, but the image size
348 may be smaller than the size defined below. <br />\'Exact Size\' may be slower
349 (as a larger image is downloaded and then scaled by the browser) but the image
350 will be guaranteed to be the size defined below. Only supported for G2.2+.'),
351 );
352
353 $form['gallery_block_image_'. $delta .'_size'] = array(
354 '#type' => 'textfield',
355 '#title' => t('Image size'),
356 '#default_value' => variable_get('gallery_block_image_'. $delta .'_size', GALLERY_IMAGEBLOCK_SIZE_DEFAULT),
357 '#size' => 10,
358 '#maxlength' => 10,
359 '#description' => t('Sets the size (in pixels) of the longest side of the image according to the method defined above.'),
360 );
361
362 $form['gallery_block_image_'. $delta .'_album_frame'] = array(
363 '#type' => 'select',
364 '#title' => t('Album frame'),
365 '#default_value' => variable_get('gallery_block_image_'. $delta .'_album_frame', 'none'),
366 '#options' => $image_frames,
367 '#description' => $imageframe_desc,
368 );
369
370 $form['gallery_block_image_'. $delta .'_item_frame'] = array(
371 '#type' => 'select',
372 '#title' => t('Item frame'),
373 '#default_value' => variable_get('gallery_block_image_'. $delta .'_item_frame', 'none'),
374 '#options' => $image_frames,
375 '#description' => $imageframe_desc,
376 );
377
378 $form['gallery_block_image_'. $delta .'_link_target'] = array(
379 '#type' => 'textfield',
380 '#title' => t('Link target'),
381 '#default_value' => variable_get('gallery_block_image_'. $delta .'_link_target', ''),
382 '#size' => 20,
383 '#maxlength' => 20,
384 '#description' => t('Enter a link target (e.g. \'_blank\' to open in a new window).'),
385 );
386
387 $form['gallery_block_image_'. $delta .'_link'] = array(
388 '#type' => 'textfield',
389 '#title' => t('Image Link'),
390 '#default_value' => variable_get('gallery_block_image_'. $delta .'_link', ''),
391 '#size' => 60,
392 '#maxlength' => 255,
393 '#description' => t('By default the image has a link to the item in the Gallery. This
394 can be overridden here (or leave empty for the default). Use \'none\' for no link, or a URL
395 to link somewhere else instead.'),
396 );
397 }
398
399 return $form;
400}
401
402/**
403 * Function _gallery_settings_block_grid().
c15e9178 404 */
e65698fe
TW
405function _gallery_settings_block_grid($delta) {
406 $plugin_status = gallery_plugin_status(array('imageblock', 'imageframe'));
407
408 $gridblock_desc = t('The Gallery Grid Block requires the Gallery2
409 Image Block plugin (!imageblock_status) and optionally the Gallery2 Image Frame
410 plugin (!imageframe_status).', array(
411 '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
412 '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
413 ));
414 if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
415 $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
416 $g2_plugins_page = (variable_get('gallery_valid', 0)) ?
417 t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
418 array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
419 : t('Gallery2 Site Admin -> Plugins');
420 $g2_imageblock_desc = t(' However the Image Block plugin is unavailable, so this block is
421 not available and the settings are disabled. To use this block please go to
422 the !g2_plugins page and install/activate the Image Block plugin.',
423 array('!g2_plugins' => $g2_plugins_page));
424 $gridblock_desc .= $g2_imageblock_desc;
425 }
c15e9178 426
e65698fe 427 $form['#description'] = $gridblock_desc;
c15e9178 428
e65698fe
TW
429 $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
430 t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
431 array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
c15e9178 432
e65698fe
TW
433 $image_frames = gallery_get_image_frames();
434 _gallery_block_options($type_map, $param_map);
435
436 if (variable_get('gallery_block_grid_num', 1) > 1) {
437 $form['gallery_block_grid_'. $delta .'_blockid'] = array(
438 '#type' => 'textfield',
439 '#title' => t('Block Identifier [Block @id]', array('@id' => $delta+1)),
440 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_blockid', ''),
441 '#size' => 25,
442 '#maxlength' => 30,
443 '#description' => t('A short identifier to distinguish blocks of the same type. (Blocks are numbered by default)'),
444 );
445 }
446
447 if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {
448 $form['gallery_block_grid_'. $delta .'_num_cols'] = array(
449 '#type' => 'select',
450 '#title' => t('Number of columns'),
451 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_num_cols', 2),
452 '#options' => _gallery_range_array(1, 5),
453 '#description' => t('Enter the number of columns in the grid.'),
454 );
455
456 $form['gallery_block_grid_'. $delta .'_num_rows'] = array(
457 '#type' => 'select',
458 '#title' => t('Number of rows'),
459 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_num_rows', 2),
460 '#options' => _gallery_range_array(1, 5),
461 '#description' => t('Enter the number of rows in the grid.'),
462 );
463
464 $form['gallery_block_grid_'. $delta .'_block_block'] = array(
465 '#type' => 'select',
466 '#title' => 'Image types',
467 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_block_block', 'randomImage'),
468 '#options' => $type_map,
469 '#description' => 'Pick the type of images you would like to see in the grid.',
470 );
471
472 $form['gallery_block_grid_'. $delta .'_item_id'] = array(
473 '#type' => 'textfield',
474 '#title' => t('Album or Item ID'),
475 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_item_id', ''),
476 '#size' => 20,
477 '#maxlength' => 20,
478 '#description' => t('Enter the Gallery image or album ID (or blank). If an album or item ID is specified, random
dccc293a
TW
479 images will only be selected from that album and its sub-albums. If %user is specified,
480 items will be taken from the visitor\'s useralbum (if possible).')
e65698fe
TW
481 );
482
483 $form['gallery_block_grid_'. $delta .'_block_show'] = array(
484 '#type' => 'checkboxes',
485 '#title' => t('Image data'),
486 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_block_show', array()),
487 '#options' => $param_map,
488 '#description' => t('Choose the item metadata you would like to display.'),
489 );
490
491 $form['gallery_block_grid_'. $delta .'_size_method'] = array(
492 '#type' => 'select',
493 '#title' => t('Image size method'),
494 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_size_method', GALLERY_GRID_SIZE_METHOD_DEFAULT),
495 '#options' => array(
496 'maxsize' => t('Max Size'),
497 'exactsize' => t('Exact Size'),
498 ),
499 '#description' => t('\'Max Size\' gives faster image downloading, but the image size
500 may be smaller than the size defined below. <br />\'Exact Size\' may be slower
501 (as a larger image is downloaded and then scaled by the browser) but the image
502 will be guaranteed to be the size defined below. Only supported for G2.2+.'),
503 );
504
505 $form['gallery_block_grid_'. $delta .'_size'] = array(
506 '#type' => 'textfield',
507 '#title' => t('Image size'),
508 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_size', GALLERY_GRID_SIZE_DEFAULT),
509 '#size' => 10,
510 '#maxlength' => 10,
511 '#description' => t('Sets the size (in pixels) of the longest side of the image according
512 to the method defined above.'),
513 );
514
515 $form['gallery_block_grid_'. $delta .'_album_frame'] = array(
516 '#type' => 'select',
517 '#title' => t('Album frame'),
518 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_album_frame', 'none'),
519 '#options' => $image_frames,
520 '#description' => $imageframe_desc,
521 );
522
523 $form['gallery_block_grid_'. $delta .'_item_frame'] = array(
524 '#type' => 'select',
525 '#title' => t('Item frame'),
526 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_item_frame', 'none'),
527 '#options' => $image_frames,
528 '#description' => $imageframe_desc,
529 );
530
531 $form['gallery_block_grid_'. $delta .'_link_target'] = array(
532 '#type' => 'textfield',
533 '#title' => t('Link target'),
534 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_link_target', ''),
535 '#size' => 20,
536 '#maxlength' => 20,
537 '#description' => t('Enter a link target (e.g. \'_blank\' to open in a new window).'),
538 );
c15e9178 539
e65698fe
TW
540 $form['gallery_block_grid_'. $delta .'_link'] = array(
541 '#type' => 'textfield',
542 '#title' => t('Image Link'),
543 '#default_value' => variable_get('gallery_block_grid_'. $delta .'_link', ''),
544 '#size' => 60,
545 '#maxlength' => 255,
546 '#description' => t('By default the image has a link to the item in the Gallery. This
547 can be overridden here (or leave empty for the default). Use \'none\' for no link, or a URL
548 to link somewhere else instead.'),
549 );
c15e9178 550 }
e65698fe
TW
551
552 return $form;
553}
c15e9178 554
e65698fe
TW
555/**
556 * Function _gallery_settings_block_save().
557 */
dccc293a 558function _gallery_settings_block_save($delta, $values) {
e65698fe 559 // Validate variable values
dccc293a
TW
560 if (isset($values['gallery_block_image_'.$delta.'_size'])) {
561 if (!is_numeric($values['gallery_block_image_'.$delta.'_size']) || $values['gallery_block_image_'.$delta.'_size'] < 10) {
562 $values['gallery_block_image_'.$delta.'_size'] = 10;
e65698fe 563 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');
c15e9178 564 }
565 }
dccc293a
TW
566 if (isset($values['gallery_block_grid_'.$delta.'_size'])) {
567 if (!is_numeric($values['gallery_block_grid_'.$delta.'_size']) || $values['gallery_block_grid_'.$delta.'_size'] < 10) {
568 $values['gallery_block_grid_'.$delta.'_size'] = 10;
e65698fe
TW
569 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');
570 }
571 }
572 // Save variables
dccc293a 573 foreach ($values as $key => $value) {
e65698fe 574 if (strpos($key, 'gallery_block_') == 0) {
dccc293a
TW
575 if (is_array($value) && isset($values['array_filter'])) {
576 $value = array_keys(array_filter($value));
e65698fe
TW
577 }
578 variable_set($key, $value);
579 }
580 }
581}
582
583/**
584 * Function _gallery_settings_filter().
585 */
586function _gallery_settings_filter() {
587 require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
588 $plugin_status = gallery_plugin_status(array('imageblock', 'imageframe'));
589
590 $desc = t('Note that changing the defaults here will change the all the gallery filter images
591 on the site, not just new images. ');
592 $desc .= t('The Gallery Filter requires the Gallery2 Image Block plugin (!imageblock_status) and
593 optionally the Gallery2 Image Frame plugin (!imageframe_status).',
594 array(
595 '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
596 '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
597 ));
598 if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
599 $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
600 $g2_plugins_page = (variable_get('gallery_valid', 0)) ?
601 t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
602 array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
603 : t('Gallery2 Site Admin -> Plugins');
604 $desc .= t(' However the Image Block plugin is unavailable, so the Gallery Filter is
605 not available and the settings are disabled. To use the filter please go to
606 the !g2_plugins page and install/activate the Image Block plugin.',
607 array('!g2_plugins' => $g2_plugins_page));
608 }
609
610 $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
611 t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
612 array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
c15e9178 613
e65698fe
TW
614 $form['filter'] = array(
615 '#type' => 'fieldset',
616 '#title' => t('Gallery Filter settings'),
617 '#collapsible' => FALSE,
618 '#collapsed' => FALSE,
619 '#description' => $desc,
620 );
621
622 $image_frames = gallery_get_image_frames();
623 _gallery_block_options($type_map, $param_map);
624
625 if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {
626 $form['filter']['gallery_filter_prefix'] = array(
627 '#type' => 'textfield',
628 '#title' => t('Filter prefix'),
629 '#default_value' => variable_get('gallery_filter_prefix', 'G2'),
630 '#size' => 10,
631 '#maxlength' => 10,
632 '#description' => t('Prefix to use with filter. Example: \'G2\' means you use [G2: 999].
633 Be careful when changing this as any pages using the previous prefix will not be changed
634 and so will not be filtered correctly.'),
635 );
636
637 $form['filter']['gallery_filter_default_block_type'] = array(
638 '#type' => 'select',
639 '#title' => t('Default image type'),
640 '#default_value' => variable_get('gallery_filter_default_block_type', 'viewedImage'),
641 '#options' => $type_map,
642 '#description' => t('Pick the default type of image you would like to use.'),
643 );
644
645 $form['filter']['gallery_filter_can_cache'] = array(
646 '#type' => 'checkbox',
647 '#title' => t('Cache gallery filter pages'),
648 '#default_value' => variable_get('gallery_filter_can_cache', 1),
649 '#description' => t('By default the gallery filter output is cached by Drupal to speed up page loading.
650 However, it will not cache the css class info for the frames. The best approach is the
651 make sure that the sidebar image block and the gallery filter images use the same frames.
652 If you are unable to do this you will have to deselect this option to force Drupal not to
653 cache the pages, or else your frames will not appear. If you change this option you will
654 need to go to <a href="@link">admin/settings/filters</a> and re-save the image formats
655 that use gallery filter.', array('@link' => url('admin/settings/filters'))),
656 );
657
658 $form['filter']['gallery_filter_n_images'] = array(
659 '#type' => 'textfield',
660 '#title' => t('Default number of images'),
661 '#default_value' => variable_get('gallery_filter_n_images', 1),
662 '#size' => 3,
663 '#maxlength' => 3,
664 '#description' => t('How many images you want the default block to show. Best to keep at 1 and use the n parameter.'),
665 );
666
667 $form['filter']['gallery_filter_default_show'] = array(
668 '#type' => 'checkboxes',
669 '#title' => t('Default image data'),
670 '#default_value' => variable_get('gallery_filter_default_show', array('none')),
671 '#options' => $param_map,
672 '#description' => t('Choose the item metadata you would like to display by default. This will change all instances where show parameter was not specified.'),
673 );
674
dccc293a 675 // Parse gallery_filter.css and extract classes
e65698fe
TW
676 $css = implode('', file(drupal_get_path('module', 'gallery') .'/gallery_filter.css'));
677 preg_match_all('/div.giImageBlock.(\w+) {/', $css, $matches);
678 if (count($matches[1])) {
679 $classes = array();
680 foreach ($matches[1] as $class) {
681 $classes[$class] = $class;
682 }
683 $form['filter']['gallery_filter_default_div_class'] = array(
684 '#type' => 'select',
685 '#title' => t('Default class'),
686 '#default_value' => variable_get('gallery_filter_default_div_class', 'nowrap'),
687 '#options' => $classes,
688 );
689 }
690 else {
691 $form['filter']['gallery_filter_default_div_class'] = array(
692 '#type' => 'textfield',
693 '#title' => t('Default class'),
694 '#default_value' => variable_get('gallery_filter_default_div_class', 'nowrap'),
695 '#size' => 20,
696 '#maxlength' => 20,
697 '#description' => t('left, right, or nowrap. (See gallery_filter.css to add more or modify these.)'),
698 );
699 }
700
701 $form['filter']['gallery_filter_default_maxsize'] = array(
702 '#type' => 'textfield',
703 '#title' => t('Default \'Max Size\' thumbnail size'),
704 '#default_value' => variable_get('gallery_filter_default_maxsize', GALLERY_FILTER_MAXSIZE_DEFAULT),
705 '#size' => 10,
706 '#maxlength' => 10,
707 );
708
709 $form['filter']['gallery_filter_default_exactsize'] = array(
710 '#type' => 'textfield',
711 '#title' => t('Default \'Exact Size\' thumbnail size'),
712 '#default_value' => variable_get('gallery_filter_default_exactsize', GALLERY_FILTER_EXACTSIZE_DEFAULT),
713 '#size' => 10,
714 '#maxlength' => 10,
715 '#description' => t('If no size is specified when calling the filter, one of
716 these sizes (and implied method) will be used. <br />\'Max Size\' gives faster
717 image downloading, but the image size
718 may be smaller than the size defined. <br />\'Exact Size\' may be slower
719 (as a larger image is downloaded and then scaled by the browser) but the image
720 will be guaranteed to be the size defined. Only supported for G2.2+.
721 Only fill in one size box (not both) to set the default method.'),
722 );
723
724 $form['filter']['gallery_filter_default_album_frame'] = array(
725 '#type' => 'select',
726 '#title' => t('Default album frame'),
727 '#default_value' => variable_get('gallery_filter_default_album_frame', 'none'),
728 '#options' => $image_frames,
729 '#description' => $imageframe_desc,
730 );
731
732 $form['filter']['gallery_filter_default_item_frame'] = array(
733 '#type' => 'select',
734 '#title' => t('Default item frame'),
735 '#default_value' => variable_get('gallery_filter_default_item_frame', 'none'),
736 '#options' => $image_frames,
737 '#description' => $imageframe_desc,
738 );
739
740 $form['filter']['gallery_filter_default_link_target'] = array(
741 '#type' => 'textfield',
742 '#title' => t('Default link target'),
743 '#default_value' => variable_get('gallery_filter_default_link_target', ''),
744 '#size' => 20,
745 '#maxlength' => 20,
746 '#description' => t('Enter a link target (e.g. "_blank", "_new").'),
747 );
748
749 $form['filter']['gallery_filter_default_link'] = array(
750 '#type' => 'textfield',
751 '#title' => t('Default Image Link'),
752 '#default_value' => variable_get('gallery_filter_default_link', ''),
753 '#size' => 20,
754 '#maxlength' => 20,
755 '#description' => t('By default the image has a link to the item in the Gallery. This
756 can be overridden here (or leave empty for the default). Use \'none\' for no link, or a URL
757 to link somewhere else instead.'),
758 );
759 }
760
dccc293a
TW
761 $form = system_settings_form($form);
762 $form['#validate'] = array('_gallery_settings_filter_validate');
763 $form['#submit'] = array('_gallery_settings_filter_submit', 'system_settings_form_submit');
764 return $form;
e65698fe 765}
c15e9178 766
e65698fe
TW
767/**
768 * Function _gallery_settings_filter_validate().
769 */
dccc293a 770function _gallery_settings_filter_validate($form, &$form_state) {
e65698fe 771 // Only validate if a setting was returned
dccc293a
TW
772 if (isset($form_state['values']['gallery_filter_default_maxsize'])) {
773 if ((strlen($form_state['values']['gallery_filter_default_maxsize']) > 0) &&
774 (strlen($form_state['values']['gallery_filter_default_exactsize']) > 0)) {
e65698fe
TW
775 form_set_error('gallery_filter_default_maxsize',
776 t('You must set either the Max Size or the Exact Size, not both.'));
777 }
dccc293a
TW
778 elseif ((strlen($form_state['values']['gallery_filter_default_maxsize']) == 0) &&
779 (strlen($form_state['values']['gallery_filter_default_exactsize']) == 0)) {
e65698fe
TW
780 form_set_error('gallery_filter_default_maxsize',
781 t('You must set either the Max Size or the Exact Size.'));
782 }
dccc293a
TW
783 if ((strlen($form_state['values']['gallery_filter_default_maxsize']) > 0) &&
784 (!is_numeric($form_state['values']['gallery_filter_default_maxsize']) ||
785 $form_state['values']['gallery_filter_default_maxsize'] < 1)) {
e65698fe
TW
786 form_set_error('gallery_filter_default_maxsize',
787 t('Max Size must be a number greater than zero.'));
788 }
dccc293a
TW
789 if ((strlen($form_state['values']['gallery_filter_default_exactsize']) > 0) &&
790 (!is_numeric($form_state['values']['gallery_filter_default_exactsize']) ||
791 $form_state['values']['gallery_filter_default_exactsize'] < 1)) {
e65698fe
TW
792 form_set_error('gallery_filter_default_exactsize',
793 t('Exact Size must be a number greater than zero.'));
794 }
dccc293a
TW
795 if ((strlen($form_state['values']['gallery_filter_n_images']) > 0) &&
796 (!is_numeric($form_state['values']['gallery_filter_n_images']) ||
797 $form_state['values']['gallery_filter_n_images'] < 1)) {
e65698fe
TW
798 form_set_error('gallery_filter_n_images',
799 t('Number of images must be a number greater than zero.'));
800 }
801 }
802}
c15e9178 803
e65698fe
TW
804/**
805 * Function _gallery_settings_filter_submit().
806 */
dccc293a 807function _gallery_settings_filter_submit($form, &$form_state) {
e65698fe
TW
808 // The default values have changed, so the pages containing the gallery filter need
809 // to be updated (or else it would only occur on an edit), so empty the filter cache.
810
811 // Find out which formats are using the gallery filter
812 $result = db_query("SELECT format FROM {filters} WHERE module = 'gallery'");
813 while ($format = db_fetch_object($result)) {
814 cache_clear_all($format->format .':', 'cache_filter', TRUE);
815 }
816
817 drupal_set_message('The gallery filter cache has been cleared so that the new defaults apply.');
c15e9178 818}
819
820/**
e65698fe 821 * Function _gallery_settings_g2image().
c15e9178 822 */
e65698fe
TW
823function _gallery_settings_g2image() {
824 $plugin_status = gallery_plugin_status(array('imageblock'));
825
826 $desc = t('G2Image requires the Gallery2 Image Block plugin (!imageblock_status) and
827 the g2image application to be installed.',
828 array('!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock'])));
829 if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
830 $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
831 $g2_plugins_page = (variable_get('gallery_valid', 0)) ?
832 t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
833 array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
834 : t('Gallery2 Site Admin -> Plugins');
835 $desc .= t(' However the Image Block plugin is unavailable, so G2Image is
836 not available and the settings are disabled. To use G2Image please go to
837 the !g2_plugins page and install/activate the Image Block plugin.', array(
838 '!g2_plugins' => $g2_plugins_page));
839 }
840
841 $form['g2image'] = array(
842 '#type' => 'fieldset',
843 '#title' => t('Gallery Image Assist (G2Image) settings'),
844 '#collapsible' => FALSE,
845 '#collapsed' => FALSE,
846 '#description' => $desc,
847 );
848
849 if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {
850 $form['g2image']['gallery_g2image_mode'] = array(
851 '#type' => 'select',
852 '#title' => t('Mode'),
853 '#default_value' => variable_get('gallery_g2image_mode', 'disabled'),
854 '#options' => array(
855 'disabled' => t('Disabled'),
856 'standalone' => t('Standalone'),
857 'tinymce' => t('TinyMCE'),
858 ),
859 '#description' => t('Determines the mode of operation. For anything other than \'Disabled\' the g2image
860 application has to be installed. See the INSTALL.txt instructions. In \'Standalone\'
861 mode a button will be visible under textfields to launch the g2image window. In
862 \'TinyMCE\' mode the g2image button can be used in the TinyMCE toolbar. Note that the
863 TinyMCE version will NOT work wih Safari - use the standalone version instead.'),
864 );
865
866 $form['g2image']['gallery_g2image_only_listed_pages'] = array(
867 '#type' => 'radios',
868 '#title' => t('Show g2image link on specific pages (Standalone mode only)'),
869 '#default_value' => variable_get('gallery_g2image_only_listed_pages', 1),
870 '#options' => array(
871 t('Show on every page except the listed pages.'),
872 t('Show on only the listed pages.')
873 )
874 );
875
876 require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc');
877 $form['g2image']['gallery_g2image_std_pages'] = array(
878 '#type' => 'textarea',
879 '#title' => t('Pages (Standalone mode only)'),
880 '#default_value' => variable_get('gallery_g2image_std_pages', gallery_help('admin/settings/gallery_g2image#pages')),
881 '#description' => t('Enter one page per line as Drupal paths. The \'*\' character is a wildcard. Example paths are
882 \'%blog\' for the blog page and %blog-wildcard for every personal blog. %front is the front page.',
883 array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'))
884 );
885
886 $form['g2image']['gallery_g2image_sortby'] = array(
887 '#type' => 'select',
888 '#title' => t('Default Sort Order'),
889 '#default_value' => variable_get('gallery_g2image_sortby', 'title_asc'),
890 '#options' => array(
891 'title_asc' => t('Gallery2 Title (A-z)'),
892 'title_desc' => t('Gallery2 Title (z-A)'),
893 'name_asc' => t('Filename (A-z)'),
894 'name_desc' => t('Filename (z-A)'),
895 'mtime_desc' => t('Last Modification (newest first)'),
896 'mtime_asc' => t('Last Modification (oldest first)'),
897 ),
898 '#description' => t('Determines the default sorting order.'),
899 );
900
901 $form['g2image']['gallery_g2image_images_per_page'] = array(
902 '#type' => 'select',
903 '#title' => t('Default Number of images per page'),
904 '#default_value' => variable_get('gallery_g2image_images_per_page', 20),
905 '#options' => _gallery_range_array(10, 60, 10),
906 '#description' => t('Choose the default number of images per page.'),
907 );
908
909 $form['g2image']['gallery_g2image_display_filenames'] = array(
910 '#type' => 'select',
911 '#title' => t('Default Display Options'),
912 '#default_value' => variable_get('gallery_g2image_display_filenames', 'thumbnails'),
913 '#options' => array(
914 'thumbnails' => t('Thumbnails only'),
915 'filenames' => t('Thumbnails with title and filename'),
916 ),
917 '#description' => t('Choose the default display option for images.'),
918 );
919
920 $form['g2image']['gallery_g2image_default_action'] = array(
921 '#type' => 'select',
922 '#title' => t('Default Action'),
923 '#default_value' => variable_get('gallery_g2image_default_action', 'drupal_g2_filter'),
924 '#options' => array(
925 'drupal_g2_filter' => t('Gallery Filter ID'),
926 'thumbnail_image' => t('Thumbnail with link to image'),
927 'thumbnail_album' => t('Thumbnail with link to parent album'),
928 'thumbnail_custom_url' => t('Thumbnail with link to custom URL'),
929 'thumbnail_only' => t('Thumbnail only'),
930 'link_image' => t('Text link to image'),
931 'link_parent' => t('Text link to parent album'),
932 ),
933 '#description' => t('Choose the default method of inserting the image info.'),
934 );
935
936 $form['g2image']['gallery_g2image_custom_url'] = array(
937 '#type' => 'textfield',
938 '#title' => t('Default custom url'),
939 '#default_value' => variable_get('gallery_g2image_custom_url', 'http://'),
940 '#size' => 50,
941 '#maxlength' => 50,
942 '#description' => t('The default custom url. Used with \'Thumbnail with link to custom URL\' action setting'),
943 );
944
945 $css_options = array(
946 'none' => t('None'),
947 'g2image_normal' => t('Normal'),
948 'g2image_float_left' => t('Float Left'),
949 'g2image_float_right' => t('Float Right'),
950 'g2image_centered' => t('Centered'),
951 );
dccc293a 952
e65698fe
TW
953 // Merge in custom class options
954 $gallery_g2image_custom_class = array_filter(variable_get('gallery_g2image_custom_class', array()));
955 $css_options = array_merge($css_options, drupal_map_assoc($gallery_g2image_custom_class));
956
957 $form['g2image']['gallery_g2image_default_alignment'] = array(
958 '#type' => 'select',
959 '#title' => t('Default Alignment'),
960 '#default_value' => variable_get('gallery_g2image_default_alignment', 'none'),
961 '#options' => $css_options,
962 '#description' => t('Choose the default alignment of images.'),
963 );
dccc293a 964
e65698fe
TW
965 $form['g2image']['gallery_g2image_custom_class'] = array('#tree' => TRUE);
966 for ($i=1; $i<=4; $i++) {
967 $form['g2image']['gallery_g2image_custom_class'][$i] = array(
968 '#type' => 'textfield',
969 '#title' => t('Custom Class @index', array('@index' => $i)),
970 '#default_value' => isset($gallery_g2image_custom_class[$i]) ? $gallery_g2image_custom_class[$i] : '',
971 '#size' => 20,
972 '#maxlength' => 50,
973 );
974 }
975 $form['g2image']['gallery_g2image_custom_class'][$i-1]['#description'] = t('Additional css classes to be available for selection (must be defined in .css file).');
dccc293a 976
e65698fe
TW
977 $form['g2image']['gallery_g2image_class_mode'] = array(
978 '#type' => 'select',
979 '#title' => t('Alignment Class Insertion Point'),
980 '#default_value' => variable_get('gallery_g2image_class_mode', 'img'),
981 '#options' => array(
982 'img' => t('<img class=...>'),
983 'div' => t('<div class=...><img ...>'),
984 ),
985 '#description' => t('Determines where the alignment class will be inserted. If you choose \'&lt;div
986 class=...&gt;&lt;img ...&gt;\', you will have to manually delete any &lt;div&gt; tags
987 manually after deleting images from the TinyMCE window.'),
988 );
989 }
990
dccc293a 991 $form['#validate'] = array('_gallery_g2image_settings_validate');
e65698fe
TW
992 return system_settings_form($form);
993}
994
995/**
996 * Function _gallery_g2image_settings_validate().
997 * (saves the G2Image config file)
998 */
dccc293a
TW
999function _gallery_g2image_settings_validate($form, &$form_state) {
1000 switch ($form_state['values']['gallery_g2image_mode']) {
c15e9178 1001 case 'tinymce':
1002 $mode = t('TinyMCE');
1003 $path = drupal_get_path('module', 'tinymce');
1004 $path .= '/tinymce/jscripts/tiny_mce/plugins/g2image';
1005 break;
1006 case 'standalone':
1007 $mode = t('Standalone');
1008 $path = drupal_get_path('module', 'gallery');
1009 $path .= '/g2image';
1010 break;
e65698fe
TW
1011 default:
1012 return;
c15e9178 1013 }
dccc293a 1014
c15e9178 1015 // Note that file_check_directory uses &$path and will strip the trailing '/'
e65698fe
TW
1016 $filename = $path .'/config.php';
1017 if (is_writable($filename) == FALSE && !file_check_directory($path)) {
1018 form_set_error('', t('G2Image does not seem to be installed for @mode mode in the required directory (@dir), or the
1019 directory is not writable. Please see the INSTALL.txt for instructions.',
1020 array('@mode' => $mode, '@dir' => '<drupal_path>/'. $path)));
1021 return;
1022 }
1023
c15e9178 1024 $cr = "\n";
e65698fe
TW
1025 $g2ic_gallery2_path = str_replace('\\', '/', variable_get('gallery_dir', './gallery2/'));
1026 $g2ic_use_full_path = (substr($g2ic_gallery2_path, 0, 1) == '/' || substr($g2ic_gallery2_path, $_SERVER['DOCUMENT_ROOT']) !== FALSE) ?
c15e9178 1027 'TRUE' : 'FALSE';
dccc293a
TW
1028 $form_state['values']['gallery_g2image_custom_url'] = check_url($form_state['values']['gallery_g2image_custom_url']);
1029 $g2ic_display_filenames = ($form_state['values']['gallery_g2image_display_filenames'] == 'filenames') ? 'TRUE' : 'FALSE';
c15e9178 1030 $g2ic_custom_class = array();
dccc293a 1031 foreach ($form_state['values']['gallery_g2image_custom_class'] as $key => $value) {
c15e9178 1032 $g2ic_custom_class[$key] = ($value) ? $value : 'not_used';
1033 }
e65698fe 1034
dccc293a
TW
1035 $g2ic_custom_class_1 = ($form_state['values']['gallery_g2image_custom_class_1']) ?
1036 $form_state['values']['gallery_g2image_custom_class_1'] : 'not_used';
1037 $g2ic_custom_class_2 = ($form_state['values']['gallery_g2image_custom_class_2']) ?
1038 $form_state['values']['gallery_g2image_custom_class_2'] : 'not_used';
1039 $g2ic_custom_class_3 = ($form_state['values']['gallery_g2image_custom_class_3']) ?
1040 $form_state['values']['gallery_g2image_custom_class_3'] : 'not_used';
1041 $g2ic_custom_class_4 = ($form_state['values']['gallery_g2image_custom_class_4']) ?
1042 $form_state['values']['gallery_g2image_custom_class_4'] : 'not_used';
c15e9178 1043
e65698fe
TW
1044 $content = '<?php'. $cr;
1045 $content .= '/*'. $cr;
1046 $content .= ' Gallery 2 Image Chooser'. $cr;
1047 $content .= ' Version 3.0 - updated 16 SEP 2007'. $cr;
1048 $content .= ' Documentation: http://g2image.steffensenfamily.com/'. $cr;
1049 $content .= $cr;
1050 $content .= ' Author: Kirk Steffensen with inspiration, code snippets,'. $cr;
1051 $content .= ' and assistance as listed in CREDITS.HTML'. $cr;
1052 $content .= $cr;
1053 $content .= ' Released under the GPL version 2.'. $cr;
1054 $content .= ' A copy of the license is in the root folder of this plugin.'. $cr;
1055 $content .= $cr;
1056 $content .= ' See README.HTML for installation info.'. $cr;
1057 $content .= ' See CHANGELOG.HTML for a history of changes.'. $cr;
1058 $content .= '*/'. $cr;
1059 $content .= $cr;
1060 $content .= '// Automatically generated by gallery.module (admin/settings/gallery/g2image).'. $cr;
1061 $content .= '// DO NOT EDIT'. $cr;
1062 $content .= $cr;
1063
1064 $content .= '$g2ic_embedded_mode = TRUE;'. $cr;
1065 $content .= '$g2ic_gallery2_path = \''. $g2ic_gallery2_path .'\';'. $cr;
1066 $content .= '$g2ic_use_full_path = '. $g2ic_use_full_path .';'. $cr;
1067 $content .= '$g2ic_gallery2_uri = \''. variable_get('gallery_uri', '/gallery2/') .'\';'. $cr;
1068 $content .= '$g2ic_embed_uri = \''. variable_get('gallery_embed_uri', '?q=gallery') .'\';'. $cr;
1069
1070 $content .= '$g2ic_drupal_g2_filter = TRUE;'. $cr;
1071 $content .= '$g2ic_drupal_g2_filter_prefix = \''. variable_get('gallery_filter_prefix', 'G2') .'\';'. $cr;
1072
1073 $content .= '$g2ic_language = \'en\';'. $cr;
dccc293a 1074 $content .= '$g2ic_images_per_page = '. $form_state['values']['gallery_g2image_images_per_page'] .';'. $cr;
e65698fe
TW
1075 $content .= '$g2ic_display_filenames = '. $g2ic_display_filenames .';'. $cr;
1076
dccc293a 1077 $content .= '$g2ic_default_alignment = \''. $form_state['values']['gallery_g2image_default_alignment'] .'\';'. $cr;
e65698fe
TW
1078 $content .= '$g2ic_custom_class_1 = \''. $g2ic_custom_class[1] .'\';'. $cr;
1079 $content .= '$g2ic_custom_class_2 = \''. $g2ic_custom_class[2] .'\';'. $cr;
1080 $content .= '$g2ic_custom_class_3 = \''. $g2ic_custom_class[3] .'\';'. $cr;
1081 $content .= '$g2ic_custom_class_4 = \''. $g2ic_custom_class[4] .'\';'. $cr;
dccc293a 1082 $content .= '$g2ic_class_mode = \''. $form_state['values']['gallery_g2image_class_mode'] .'\';'. $cr;
e65698fe 1083
dccc293a
TW
1084 $content .= '$g2ic_default_action = \''. $form_state['values']['gallery_g2image_default_action'] .'\';'. $cr;
1085 $content .= '$g2ic_sortby = \''. $form_state['values']['gallery_g2image_sortby'] .'\';'. $cr;
1086 $content .= '$g2ic_custom_url = \''. $form_state['values']['gallery_g2image_custom_url'] .'\';'. $cr;
e65698fe
TW
1087 $content .= $cr;
1088 $content .= '?>'. $cr;
1089
1090 $filename = $path .'/config.php';
1091 if (is_writable($filename) == FALSE) {
1092 form_set_error('', t('Could not write to G2Image config file. Please check the permissions for @filename.',
1093 array('@filename' => $filename)));
1094 return;
c15e9178 1095 }
1096 $handle = fopen($filename, "w");
1097 if (fwrite($handle, $content) === FALSE) {
e65698fe
TW
1098 form_set_error('', t('Could not write to G2Image config file. Please check the permissions for @filename.',
1099 array('@filename' => $filename)));
1100 return;
1101 }
1102 else {
1103 drupal_set_message(t('G2Image configuration file successfully created.'));
1104 }
1105 fclose($handle);
1106}
1107
1108/**
1109 * Function _gallery_settings_search().
1110 */
1111function _gallery_settings_search() {
1112 require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
1113 $plugin_status = gallery_plugin_status(array('imageblock', 'imageframe', 'search'));
1114
1115 $search_desc = t('The Gallery Search requires the Gallery2 Search plugin (!search_status) and
dccc293a 1116 optionally the Gallery2 Image Block plugin (!imageblock_status) and Gallery2 Image Frame
e65698fe
TW
1117 plugin (!imageframe_status).',
1118 array(
dccc293a 1119 '!search_status' => theme('gallery_plugin_status_message', $plugin_status['search']),
e65698fe
TW
1120 '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
1121 '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
1122 )
1123 );
1124 $g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
1125 $g2_plugins_page = (variable_get('gallery_valid', 0)) ?
1126 t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
1127 array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
1128 : t('Gallery2 Site Admin -> Plugins');
1129 $thumbs_desc = '';
1130 if ($plugin_status['search'] != GALLERY_PLUGIN_ENABLED) {
1131 $search_desc .= t(' However the Search plugin is unavailable, so the search is
1132 not available and these settings are disabled. To use the search feature please go to
1133 the !g2_plugins page and install/activate the Image Block plugin.',
1134 array('!g2_plugins' => $g2_plugins_page));
1135 }
1136 if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
1137 $thumbs_desc = t('To display search results with thumbnail images requires the Gallery2 Image
1138 Block plugin (!imageblock_status) and optionally the and Gallery2 Image Frame
1139 plugin (!imageframe_status).',
1140 array(
1141 '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
1142 '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
1143 )
1144 );
1145 $thumbs_desc .= t(' However the Image Block plugin is unavailable, so the thumbnails are
1146 not available and these settings are disabled. To use this feature please go to
1147 the !g2_plugins page and install/activate the Image Block plugin.',
1148 array('!g2_plugins' => $g2_plugins_page));
1149 }
1150
1151 $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
1152 t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
1153 array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
1154
1155 $form['search'] = array(
1156 '#type' => 'fieldset',
1157 '#title' => t('Search settings'),
1158 '#collapsible' => FALSE,
1159 '#collapsed' => FALSE,
1160 '#description' => $search_desc,
1161 );
1162
1163 $image_frames = gallery_get_image_frames();
1164 _gallery_block_options($type_map, $param_map);
1165
dccc293a 1166 if ($plugin_status['search'] == GALLERY_PLUGIN_ENABLED) {
e65698fe
TW
1167 $form['search']['gallery_search_advanced'] = array(
1168 '#type' => 'checkbox',
1169 '#title' => t('Display advanced search options'),
1170 '#default_value' => variable_get('gallery_search_advanced', 1),
1171 '#description' => t('Adds options to the search form to select which Gallery fields to search in.'),
1172 );
1173
1174 $form['search']['gallery_search_num_per_row'] = array(
1175 '#type' => 'select',
1176 '#title' => t('Number of search results per table row'),
1177 '#default_value' => variable_get('gallery_search_num_per_row', 3),
1178 '#options' => _gallery_range_array(1, 5),
1179 '#description' => t('Select the number of search results per row in the paged table.'),
1180 );
1181
1182 $form['search']['gallery_search_rows_per_pager'] = array(
1183 '#type' => 'select',
1184 '#title' => t('Number of rows per page'),
1185 '#default_value' => variable_get('gallery_search_rows_per_pager', 4),
1186 '#options' => _gallery_range_array(1, 10),
1187 '#description' => t('Select the number of rows in the paged table.'),
1188 );
1189
1190 $form['search']['thumbs'] = array(
1191 '#type' => 'fieldset',
1192 '#title' => t('Search thumbnail settings'),
1193 '#collapsible' => TRUE,
1194 '#collapsed' => FALSE,
1195 '#description' => $thumbs_desc,
1196 );
1197
1198 if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {
1199 $form['search']['thumbs']['gallery_search_show_thumbs'] = array(
1200 '#type' => 'checkbox',
1201 '#title' => t('Display thumbnails'),
1202 '#default_value' => variable_get('gallery_search_show_thumbs', 1),
1203 '#description' => t('Display thumbnail images for the search results.'),
1204 );
1205
1206 $form['search']['thumbs']['gallery_search_block_show'] = array(
1207 '#type' => 'checkboxes',
1208 '#title' => t('Image data'),
1209 '#default_value' => variable_get('gallery_search_block_show', array('title' => t('Title'))),
1210 '#options' => $param_map,
1211 '#description' => t('Choose the item metadata you would like to display.'),
1212 );
1213
1214 $form['search']['thumbs']['gallery_search_size_method'] = array(
1215 '#type' => 'select',
1216 '#title' => t('Image size method'),
1217 '#default_value' => variable_get('gallery_search_size_method', GALLERY_SEARCH_SIZE_METHOD_DEFAULT),
1218 '#options' => array(
1219 'maxsize' => t('Max Size'),
1220 'exactsize' => t('Exact Size'),
1221 ),
1222 '#description' => t('\'Max Size\' gives faster image downloading, but the image size
1223 may be smaller than the size defined below. <br />\'Exact Size\' may be slower
1224 (as a larger image is downloaded and then scaled by the browser) but the image
1225 will be guaranteed to be the size defined below. Only supported for G2.2+.'),
1226 );
1227
1228 $form['search']['thumbs']['gallery_search_size'] = array(
1229 '#type' => 'textfield',
1230 '#title' => t('Image size'),
1231 '#default_value' => variable_get('gallery_search_size', GALLERY_SEARCH_SIZE_DEFAULT),
1232 '#size' => 10,
1233 '#maxlength' => 10,
1234 '#description' => t('Sets the size (in pixels) of the longest side of the image
1235 according to the method defined above.'),
1236 );
1237
1238 $form['search']['thumbs']['gallery_search_album_frame'] = array(
1239 '#type' => 'select',
1240 '#title' => t('Album frame'),
1241 '#default_value' => variable_get('gallery_search_album_frame', 'none'),
1242 '#options' => $image_frames,
1243 '#description' => $imageframe_desc,
1244 );
1245
1246 $form['search']['thumbs']['gallery_search_item_frame'] = array(
1247 '#type' => 'select',
1248 '#title' => t('Item frame'),
1249 '#default_value' => variable_get('gallery_search_item_frame', 'none'),
1250 '#options' => $image_frames,
1251 '#description' => $imageframe_desc,
1252 );
1253
1254 $form['search']['thumbs']['gallery_search_link_target'] = array(
1255 '#type' => 'textfield',
1256 '#title' => t('Link target'),
1257 '#default_value' => variable_get('gallery_search_link_target', ''),
1258 '#size' => 20,
1259 '#maxlength' => 20,
1260 '#description' => t('Enter a link target (e.g. "_blank", "_new").'),
1261 );
1262
1263 $form['search']['thumbs']['gallery_search_default_link'] = array(
1264 '#type' => 'textfield',
1265 '#title' => t('Image Link'),
1266 '#default_value' => variable_get('gallery_search_default_link', ''),
1267 '#size' => 20,
1268 '#maxlength' => 20,
1269 '#description' => t('By default the image has a link to the item in the Gallery. This
1270 can be overridden here (or leave empty for the default). Use \'none\' for no link, or a
1271 URL to link somewhere else instead.'),
1272 );
1273 }
1274 }
1275
dccc293a 1276 $form['#validate'] = array('_gallery_settings_search_validate');
e65698fe
TW
1277 return system_settings_form($form);
1278}
1279
1280/**
1281 * Function _gallery_settings_search_validate().
1282 */
dccc293a
TW
1283function _gallery_settings_search_validate($form, &$form_state) {
1284 if (isset($form_state['values']['gallery_search_size']) &&
1285 (!is_numeric($form_state['values']['gallery_search_size']) || $form_state['values']['gallery_search_size'] < 1)) {
e65698fe
TW
1286 form_set_error('gallery_search_size',
1287 t('Image size must be a number greater than zero.'));
1288 }
1289}
1290
1291/**
1292 * Function _gallery_range_array().
1293 * (create an associative range array
1294 * like array($min=>$min, ..., $max=>$max))
1295 */
1296function _gallery_range_array($min, $max, $interval = 1) {
1297 $range_array = array();
1298 for ($i=$min; $i<=$max; $i+=$interval) {
dccc293a 1299 $range_array[$i] = $i;
e65698fe 1300 }
dccc293a 1301
e65698fe
TW
1302 return $range_array;
1303}
1304
1305/**
dccc293a 1306 * Function _gallery_php_memcheck().
e65698fe
TW
1307 * (check the amount of PHP memory)
1308 */
dccc293a 1309function _gallery_php_memcheck($min_memory = 24) {
e65698fe
TW
1310 $mem_limit = trim(ini_get('memory_limit'));
1311 $mem_limit_bytes = parse_size($mem_limit);
1312
1313 if (empty($mem_limit)) {
1314 return array(
1315 'status' => TRUE,
1316 'info' => t('There is no memory limit restricting your PHP installation.'),
1317 );
1318 }
1319 elseif (($mem_limit_bytes / (1024 * 1024)) < $min_memory) {
1320 return array(
1321 'status' => FALSE,
1322 'info' => t('Your PHP is configured to limit the memory to @mem_limit
1323 (memory_limit parameter in php.ini). You must raise this limit
1324 to at least @min_mem_limitM for proper embedded Gallery2 operation.',
1325 array(
1326 '@mem_limit' => $mem_limit,
1327 '@min_mem_limit' => $min_memory,
1328 )
1329 )
1330 );
1331 }
1332 else {
1333 return array(
1334 'status' => TRUE,
1335 'info' => t('Your PHP is configured to limit the memory to @mem_limit
1336 (memory_limit parameter in php.ini). This should be fine for embedded Gallery2 operation.',
1337 array(
1338 '@mem_limit' => $mem_limit,
1339 )
1340 )
1341 );
1342 }
1343}
1344
1345/**
dccc293a 1346 * Implementation of hook_gallery_plugin_info().
e65698fe 1347 */
dccc293a
TW
1348function gallery_gallery_plugin_info($type) {
1349 switch ($type) {
1350 case GALLERY_PLUGIN_WANTED:
1351 return array(
1352 'imageblock' => array(
1353 'title' => 'Image Block',
1354 'info' => t('Allows images to be included in the Drupal sidebar or in nodes.'),
1355 'severity' => GALLERY_SEVERITY_ERROR,
1356 'status' => gallery_single_plugin_status('imageblock'),
1357 ),
1358 'imageframe' => array(
1359 'title' => 'ImageFrame',
1360 'info' => t('Provides a variety of frames around the images.'),
1361 'severity' => GALLERY_SEVERITY_WARNING,
1362 'status' => gallery_single_plugin_status('imageframe'),
1363 ),
1364 'search' => array(
1365 'title' => 'Search',
1366 'info' => t('Allow the Drupal search to also search the Gallery.'),
1367 'severity' => GALLERY_SEVERITY_WARNING,
1368 'status' => gallery_single_plugin_status('search'),
1369 ),
1370 'rewrite' => array(
1371 'title' => 'URL Rewrite',
1372 'info' => t('Allow short URLs (clean URLs).'),
1373 'severity' => GALLERY_SEVERITY_ADVISE,
1374 'status' => gallery_single_plugin_status('rewrite'),
1375 ),
1376 );
1377 case GALLERY_PLUGIN_UNWANTED:
1378 return array(
1379 'register' => array(
1380 'title' => 'Registration',
1381 'info' => t('All user registration must take place via Drupal to ensure that the users
1382 are synchronized between Drupal and Gallery2. This plugin would allow a user to register
1383 only in Gallery2 and not in Drupal and so should not be used.'),
1384 'severity' => GALLERY_SEVERITY_WARNING,
1385 'status' => gallery_single_plugin_status('register'),
1386 ),
1387 );
1388 case GALLERY_PLUGIN_DRUPAL:
1389 return array(
1390 'gsitemap' => array(
1391 'title' => 'Google Sitemap',
1392 'status' => module_exists('gsitemap'),
1393 'severity' => GALLERY_SEVERITY_ADVISE,
1394 'info' => t('Allows the Drupal and Gallery2 Google Sitemaps to be merged which allows for
1395 a single sitemap to be sent to Google (and other web search sites).'),
1396 ),
1397 'profile' => array(
1398 'title' => 'Profile',
1399 'status' => module_exists('profile'),
1400 'severity' => GALLERY_SEVERITY_ADVISE,
1401 'info' => t('Allows support of the \'Full Name\' field in Gallery2.'),
1402 ),
1403 );
1404 default:
1405 return array();
1406 }
e65698fe
TW
1407}
1408
1409/**
1410 * Function gallery_plugin_set_status().
1411 */
1412function gallery_plugin_set_status($plugin_names) {
1413 $plugins_status = gallery_plugin_status($plugin_names);
dccc293a 1414 $plugin_info = module_invoke_all('gallery_plugin_info', GALLERY_PLUGIN_WANTED);
e65698fe
TW
1415 // Generate array containing module status
1416 $status = array();
1417 foreach ($plugins_status as $plugin => $plugin_status) {
1418 if ($plugin_status == GALLERY_PLUGIN_ENABLED) {
1419 $status[$plugin] = '';
1420 }
1421 else {
1422 $status[$plugin]['title'] = t('Gallery2 plugin \'@plugin\' is not available',
1423 array('@plugin' => isset($plugin_info[$plugin]) ? $plugin_info[$plugin]['title'] : drupal_ucfirst($plugin)));
1424 $status[$plugin]['severity'] = isset($plugin_info[$plugin]['severity']) ? $plugin_info[$plugin]['severity'] : GALLERY_SEVERITY_WARNING;
1425 $status[$plugin]['url'] = url('admin/settings/gallery/install', NULL, $plugin);
1426 }
1427 }
1428 gallery_set_status($status);
1429}
1430
1431/**
1432 * Function gallery_format_status().
1433 */
1434function gallery_format_status($status = array(), $title = 'Gallery message(s):') {
1435 $message = $title .'<ul>';
1436 if (count($status)) {
1437 foreach ($status as $item) {
1438 $message .= '<li>';
1439 $message .= empty($item['url']) ? t($item['title']) : '<a href="'. $item['url'] .'">'. t($item['title']) .'</a>';
1440 $message .= (isset($item['info']) && !empty($item['info'])) ? (': '. t($item['info'])) : '';
1441 $message .= isset($item['severity']) ? (' ['. theme('gallery_severity_message', $item['severity']) .']') : '';
1442 $message .= '</li>';
1443 }
1444 }
1445 else {
1446 $message = t('Status not available');
1447 }
1448 $message .= '</ul>';
1449
1450 return $message;
1451}
1452
1453/**
1454 * Theme function : theme_gallery_module_status_message().
1455 */
1456function theme_gallery_module_status_message($status) {
1457 if ($status) {
1458 return '<span class="admin-enabled">'. t('enabled') .'</span>';
1459 }
1460 else {
1461 return '<span class="admin-disabled">'. t('disabled') .'</span>';
1462 }
1463}
1464
1465/**
1466 * Theme function : theme_gallery_severity_message().
1467 */
1468function theme_gallery_severity_message($severity = NULL) {
1469 switch ($severity) {
1470 case GALLERY_SEVERITY_SUCCESS:
1471 return '<span class=\'g2_embed_success\'>'. t('OK') .'</span>';
1472 case GALLERY_SEVERITY_ERROR:
1473 return '<span class=\'g2_embed_error\'>'. t('Error') .'</span>';
1474 case GALLERY_SEVERITY_WARNING:
1475 return '<span class=\'g2_embed_warning\'>'. t('Warning') .'</span>';
1476 case GALLERY_SEVERITY_ADVISE:
1477 return '<span class=\'g2_embed_warning\'>'. t('Advisory') .'</span>';
1478 case GALLERY_SEVERITY_UNKNOWN:
1479 return '<span class=\'g2_embed_warning\'>'. t('Unknown') .'</span>';
1480 default:
1481 }
1482}
1483
1484/**
1485 * Theme function : theme_gallery_plugin_status_message().
1486 */
1487function theme_gallery_plugin_status_message($status, $invert = FALSE) {
1488 $classes = array('enabled' => 'admin-enabled', 'disabled' => 'admin-disabled');
1489 if ($invert) {
1490 $classes = array_reverse($classes, TRUE);
1491 }
1492
1493 switch ($status) {
1494 case GALLERY_PLUGIN_ENABLED:
1495 return '<span class="'. $classes['enabled'] .'">'. t('activated') .'</span>';
1496 case GALLERY_PLUGIN_DISABLED:
1497 return '<span class="'. $classes['disabled'] .'">'. t('disabled') .'</span>';
1498 case GALLERY_PLUGIN_NOT_ACTIVE:
1499 return '<span class="'. $classes['disabled'] .'">'. t('deactivated') .'</span>';
1500 case GALLERY_PLUGIN_NOT_INSTALLED:
1501 return '<span class="'. $classes['disabled'] .'">'. t('not installed') .'</span>';
1502 case GALLERY_PLUGIN_MISSING:
1503 return '<span class="'. $classes['disabled'] .'">'. t('missing') .'</span>';
1504 case GALLERY_PLUGIN_STATUS_UNKNOWN:
1505 default:
1506 return '<span class="'. $classes['disabled'] .'">'. t('unknown') .'</span>';
dccc293a 1507 }
e65698fe
TW
1508}
1509
1510/**
1511 * Theme function : theme_gallery_severity_status_message().
1512 */
1513function theme_gallery_severity_status_message($severity, $status, $full_msg = FALSE, $invert = FALSE) {
1514 // In some cases (e.g. unwanted plugins) it makes sense to return the full 2 part message
1515 // even on a success, but in most cases a simple "OK" is sufficient.
1516 if ($full_msg) {
1517 return theme('gallery_severity_message', $severity) .' ('. theme('gallery_plugin_status_message', $status, $invert) .')';
dccc293a 1518 }
e65698fe
TW
1519 switch ($severity) {
1520 case GALLERY_SEVERITY_SUCCESS:
1521 return theme('gallery_severity_message', $severity);
1522 default:
1523 return theme('gallery_severity_message', $severity) .' ('. theme('gallery_plugin_status_message', $status, $invert) .')';
dccc293a 1524 }
c15e9178 1525}