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