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