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