4 * gallery.module : gallery_settings.inc
9 * Implementation of hook_settings
11 function _gallery_settings() {
13 $extra = l(t('More information about directory settings (including examples).'),
14 'admin/help/gallery');
15 $form['directory'] = array(
16 '#type' => 'fieldset',
17 '#title' => t('Directory settings'),
18 '#description' => $extra,
19 '#collapsible' => TRUE
,
20 '#collapsed' => variable_get('gallery_valid', 0),
23 $form['directory']['gallery_uri'] = array(
24 '#type' => 'textfield',
25 '#title' => t('URI of Gallery2'),
26 '#default_value' => variable_get('gallery_uri', '/gallery2/'),
29 '#description' => t('URI of the G2 standalone location. Path from docroot to the
30 Gallery2 directory where main.php is located. Protocol/hostname are
34 $form['directory']['gallery_autodetect_dir'] = array(
35 '#type' => 'checkbox',
36 '#title' => t('Autodetect Settings'),
38 '#default_value' => variable_get('gallery_autodetect_dir', 1),
39 '#description' => t('Autodetect the Gallery2 and Drupal settings (recommended). When
40 selected the values below are updated with the autodetect settings
41 when the submit button is clicked.'),
44 if (variable_get('gallery_autodetect_dir', 1)) {
45 $extra = t(' (Autodetected value)');
47 $extra = t(' (Manually entered value)');
49 $form['directory']['gallery_dir'] = array(
50 '#type' => 'textfield',
51 '#title' => t('Location of Gallery2') .
$extra,
52 '#default_value' => variable_get('gallery_dir', './gallery2/'),
55 '#description' => t('Location of your gallery2 directory (absolute path or relative to the root
56 directory of your drupal installation).'),
59 $form['directory']['gallery_embed_uri'] = array(
60 '#type' => 'textfield',
61 '#title' => t('Embed URI') .
$extra,
62 '#default_value' => variable_get('gallery_embed_uri', '?q=gallery'),
65 '#description' => t('URI to access G2 via drupal. Don\'t worry if you are using clean urls in drupal and this still ends in \'index.php?q=gallery\'. This is needed to get the Gallery2 URL rewrite module to work correctly and will not be visible.'),
69 * Remove this for now. It is not necessary when URL rewrite is working. Without URL rewrite there
70 * can still be issues, but these will be addressed in the documentation for now.
73 $form['directory']['gallery_cookie_path'] = array(
74 '#type' => 'textfield',
75 '#title' => t('Cookie Path') . $extra,
76 '#default_value' => variable_get('gallery_cookie_path', ''),
79 '#description' => t('Cookie path for embedded Gallery2 sessions.'),
83 if (module_exist('profile')) {
84 $form['fullname'] = array(
85 '#type' => 'fieldset',
86 '#title' => t('Full Name settings'),
88 '#collapsible' => TRUE
,
92 $form['fullname']['gallery_use_full_name'] = array(
93 '#type' => 'checkbox',
94 '#title' => t('Enable Full Name support'),
96 '#default_value' => variable_get('gallery_use_full_name', 0),
97 '#description' => t('Use full name from profile module in Gallery2 user data. Note that
98 enabling/disabling this only updates Gallery2 user data when the
99 Drupal user is updated (ie no sync is done immediately).'),
102 $form['fullname']['gallery_profile_full_name_field'] = array(
103 '#type' => 'textfield',
104 '#title' => t('Full name profile field'),
105 '#default_value' => variable_get('gallery_profile_full_name_field', 'profile_full_name'),
108 '#description' => t('Name of "Full Name" field in profile module.'),
111 $form['fullname'] = array(
112 '#type' => 'fieldset',
113 '#title' => t('Full Name settings'),
114 '#description' => t('Full names in G2 can be supported using the profile module
115 with a "Full Name" field. However the profile module is not
116 installed, so this functionality is not available. If you install
117 it you will have more options here.'),
118 '#collapsible' => TRUE
,
119 '#collapsed' => FALSE
,
123 // Image Block settings
125 'randomImage' => t('Random image'),
126 'recentImage' => t('Recent image'),
127 'viewedImage' => t('Viewed image'),
128 'randomAlbum' => t('Random album'),
129 'recentAlbum' => t('Recent album'),
130 'viewedAlbum' => t('Viewed album'),
131 'dailyImage' => t('Daily image'),
132 'weeklyImage' => t('Weekly image'),
133 'monthlyImage' => t('Monthly image'),
134 'dailyAlbum' => t('Daily album'),
135 'weeklyAlbum' => t('Weekly album'),
136 'monthlyAlbum' => t('Monthly album'),
140 'title' => t('Title'),
142 'views' => t('View Count'),
143 'owner' => t('Item owner'),
144 'heading' => t('Heading'),
145 'fullSize' => t('Full Size'),
148 $form['block'] = _gallery_block_settings($typeMap , $paramMap);
149 $form['grid'] = _gallery_grid_block_settings($typeMap , $paramMap);
150 $form['filter'] = _gallery_filter_settings($typeMap , $paramMap);
151 $form['g2image'] = _gallery_g2image_settings();
152 $form['search'] = _gallery_search_settings($typeMap , $paramMap);
153 $form['links'] = _gallery_links_settings();
156 $form['error'] = array(
157 '#type' => 'fieldset',
158 '#title' => t('Error Logging settings'),
159 '#description' => '',
160 '#collapsible' => TRUE
,
161 '#collapsed' => TRUE
,
164 $form['error']['gallery_error_mode'] = array(
165 '#type' => 'checkboxes',
166 '#title' => t('Error logging'),
167 '#default_value' => variable_get('gallery_error_mode', array(1)),
168 '#options' => array(1 => t('Watchdog'),
169 2 => t('Output to the browser')),
170 '#description' => t('Choose where errors are displayed.'),
173 $form['gallery_valid'] = array(
175 '#value' => variable_get('gallery_valid', 0),
182 * Settings for gallery image block
185 function _gallery_block_settings($typeMap , $paramMap) {
186 $form['block'] = array(
187 '#type' => 'fieldset',
188 '#title' => t('Gallery Image Block settings'),
189 '#description' => '',
190 '#collapsible' => TRUE
,
191 '#collapsed' => TRUE
,
194 $numimages = variable_get('gallery_block_num_images', 3);
195 $form['block']['gallery_block_num_images'] = array(
196 '#type' => 'textfield',
197 '#title' => t('Number of images in block'),
198 '#default_value' => $numimages,
201 '#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.'),
204 $gallery_block_block = variable_get('gallery_block_block', array('randomImage'));
205 $form['block']['gallery_block_block'] = array(
208 $typeMap2 = array_merge(array('none' => t('None')), $typeMap);
209 for ($i=0; $i<$numimages; $i++) {
210 $form['block']['gallery_block_block'][$i] = array(
213 '#default_value' => $gallery_block_block[$i],
214 '#options' => $typeMap2,
215 '#description' => '',
218 $form['block']['gallery_block_block'][0]['#title'] = t('Image types');
219 $form['block']['gallery_block_block'][$i-1]['#description'] =
220 t('Pick the type of images you\'d like to see. You can select the same type more than once.');
222 $form['block']['gallery_item_id'] = array(
223 '#type' => 'textfield',
224 '#title' => t('Album or Item ID'),
225 '#default_value' => variable_get('gallery_item_id', ''),
228 '#description' => t('Enter the Gallery image or album ID (or blank). If an album or item ID is specified, random images will only be selected from that album and its sub-albums.'),
231 $form['block']['gallery_block_show'] = array(
232 '#type' => 'checkboxes',
233 '#title' => t('Image data'),
234 '#default_value' => variable_get('gallery_block_show', array('title', 'heading')),
235 '#options' => $paramMap,
236 '#description' => t('Choose the item metadata you\'d like to display.'),
239 $form['block']['gallery_maxsize'] = array(
240 '#type' => 'textfield',
241 '#title' => t('Thumbnail size'),
242 '#default_value' => variable_get('gallery_maxsize', 150),
245 '#description' => t('If you want your size to be bigger than the thumbnail size for that image as defined in your Gallery2, you must select "Full Size" above (but note that the full image will be returned and then resized by the browser, so it may take a while to download).'),
248 $form['block']['gallery_album_frame'] = array(
249 '#type' => 'textfield',
250 '#title' => t('Album frame'),
251 '#default_value' => variable_get('gallery_album_frame', 'none'),
254 '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your Gallery2 install for a complete list. Use "none" or blank for no frame.'),
257 $form['block']['gallery_item_frame'] = array(
258 '#type' => 'textfield',
259 '#title' => t('Item frame'),
260 '#default_value' => variable_get('gallery_item_frame', 'none'),
263 '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your Gallery2 install for a complete list. Use "none" or blank for no frame.'),
266 $form['block']['gallery_link_target'] = array(
267 '#type' => 'textfield',
268 '#title' => t('Link target'),
269 '#default_value' => variable_get('gallery_link_target', ''),
272 '#description' => t('Enter a link target (eg "_blank", "_new").'),
274 return $form['block'];
278 * Settings for gallery grid block
281 function _gallery_grid_block_settings($typeMap , $paramMap) {
282 $form['grid'] = array(
283 '#type' => 'fieldset',
284 '#title' => t('Gallery Grid Image Block settings'),
285 '#description' => '',
286 '#collapsible' => TRUE
,
287 '#collapsed' => TRUE
,
290 $form['grid']['gallery_grid_num_cols'] = array(
292 '#title' => t('Number of columns'),
293 '#default_value' => variable_get('gallery_grid_num_cols', 2),
294 '#options' => array(1=>1, 2=>2, 3=>3, 4=>4, 5=>5),
295 '#description' => t('Enter the number of columns in the grid.'),
298 $form['grid']['gallery_grid_num_rows'] = array(
300 '#title' => t('Number of rows'),
301 '#default_value' => variable_get('gallery_grid_num_rows', 2),
302 '#options' => array(1=>1, 2=>2, 3=>3, 4=>4, 5=>5),
303 '#description' => t('Enter the number of rows in the grid.'),
306 $form['grid']['gallery_grid_block_block'] = array(
308 '#title' => 'Image types',
309 '#default_value' => variable_get('gallery_grid_block_block', 'randomImage'),
310 '#options' => $typeMap,
311 '#description' => 'Pick the type of images you\'d like to see in the grid.',
314 $form['grid']['gallery_grid_item_id'] = array(
315 '#type' => 'textfield',
316 '#title' => t('Album or Item ID'),
317 '#default_value' => variable_get('gallery_grid_item_id', ''),
320 '#description' => t('Enter the Gallery image or album ID (or blank). If an album or item ID is specified, random images will only be selected from that album and its sub-albums.'),
323 $form['grid']['gallery_grid_block_show'] = array(
324 '#type' => 'checkboxes',
325 '#title' => t('Image data'),
326 '#default_value' => variable_get('gallery_grid_block_show', array()),
327 '#options' => $paramMap,
328 '#description' => t('Choose the item metadata you\'d like to display.'),
331 $form['grid']['gallery_grid_maxsize'] = array(
332 '#type' => 'textfield',
333 '#title' => t('Thumbnail size'),
334 '#default_value' => variable_get('gallery_grid_maxsize', 90),
337 '#description' => t('If you want your size to be bigger than the thumbnail size for that image as defined in your Gallery2, you must select "Full Size" above (but note that the full image will be returned and then resized by the browser, so it may take a while to download).'),
340 $form['grid']['gallery_grid_album_frame'] = array(
341 '#type' => 'textfield',
342 '#title' => t('Album frame'),
343 '#default_value' => variable_get('gallery_grid_album_frame', 'none'),
346 '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your Gallery2 install for a complete list. Use "none" or blank for no frame.'),
349 $form['grid']['gallery_grid_item_frame'] = array(
350 '#type' => 'textfield',
351 '#title' => t('Item frame'),
352 '#default_value' => variable_get('gallery_grid_item_frame', 'none'),
355 '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your Gallery2 install for a complete list. Use "none" or blank for no frame.'),
358 $form['grid']['gallery_grid_link_target'] = array(
359 '#type' => 'textfield',
360 '#title' => t('Link target'),
361 '#default_value' => variable_get('gallery_grid_link_target', ''),
364 '#description' => t('Enter a link target (eg "_blank", "_new").'),
370 * Settings for gallery filter
373 function _gallery_filter_settings($typeMap , $paramMap) {
374 $form['filter'] = array(
375 '#type' => 'fieldset',
376 '#title' => t('Gallery Filter settings'),
377 '#description' => '',
378 '#collapsible' => TRUE
,
379 '#collapsed' => TRUE
,
381 //we don't include specificItem, since it can be selected automatically if n=1
382 $form['filter']['gallery_filter_prefix'] = array(
383 '#type' => 'textfield',
384 '#title' => t('Filter prefix'),
385 '#default_value' => variable_get('gallery_filter_prefix', 'G2'),
388 '#description' => t('Prefix to use with filter. Example: \'G2\' means you use [G2: 999].'),
391 $form['filter']['gallery_filter_default_block_type'] = array(
393 '#title' => t('Image Block Type'),
394 '#default_value' => variable_get('gallery_filter_default_block_type', 'viewedImage'),
395 '#options' => $typeMap,
396 '#description' => t('Pick default type of image block you\'d like to use, default is Recent image. Viewed image is by most clicks.'),
399 $form['filter']['gallery_filter_can_cache'] = array(
400 '#type' => 'checkbox',
401 '#title' => t('Cache gallery filter pages'),
402 '#default_value' => variable_get('gallery_filter_can_cache', 1),
403 '#description' => t('By default the gallery filter output is cached by Drupal to speed up page loading. However, it will not cache the css class info for the frames. The best approach is the make sure that the sidebar image block and the gallery filter images use the same frames. If you are unable to do this you will have to deselect this option to force Drupal not to cache the pages, or else your frames will not appear. If you change this option you will need to go to <a href="%link">admin/filters</a> and re-save the image formats that use gallery filter.', array('%link' => url('admin/filters'))),
406 $form['filter']['gallery_filter_n_images'] = array(
407 '#type' => 'textfield',
408 '#title' => t('Default Number of Images'),
409 '#default_value' => variable_get('gallery_filter_n_images', 1),
412 '#description' => t('How many images you want the default block to show. Best to keep at 1 and use the n parameter.'),
414 //////*********in fact, should we remove this option all together? because the way it is now, if you change this to n>1
415 //then instances where n was not specified and item_id is a specific item, the block breaks and nothing is shown.
416 $form['filter']['gallery_filter_default_show'] = array(
417 '#type' => 'checkboxes',
418 '#title' => t('Default Image Block Settings'),
419 '#default_value' => variable_get('gallery_filter_default_show', array('none')),
420 '#options' => $paramMap,
421 '#description' => t('Choose the item metadata you\'d like to display by default. This will change all instances where show parameter was not specified.'),
424 $form['filter']['gallery_filter_default_size'] = array(
425 '#type' => 'textfield',
426 '#title' => t('Default thumbnail size'),
427 '#default_value' => variable_get("gallery_filter_default_size", "150"),
430 '#description' => t('If no size is specified when calling the filter, this size will be used. If you want your size to be bigger than the thumbnail size for that image as defined in your Gallery2, you must select "Full Size" above (but note that the full image will be returned and then resized by the browser, so it may take a while to download).'),
433 $form['filter']['gallery_filter_default_album_frame'] = array(
434 '#type' => 'textfield',
435 '#title' => t('Default album frame'),
436 '#default_value' => variable_get('gallery_filter_default_album_frame', 'none'),
439 '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your G2 install for a complete list. Use \'none\' or blank for no frame. '),
442 $form['filter']['gallery_filter_default_item_frame'] = array(
443 '#type' => 'textfield',
444 '#title' => t('Default item frame'),
445 '#default_value' => variable_get('gallery_filter_default_item_frame', 'none'),
448 '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your G2 install for a complete list. Use \'none\' or blank for no frame.'),
451 $form['filter']['gallery_filter_default_link_target'] = array(
452 '#type' => 'textfield',
453 '#title' => t('Default Link target'),
454 '#default_value' => variable_get('gallery_filter_default_link_target', ''),
457 '#description' => t('Enter a link target (eg "_blank", "_new").'),
460 $form['filter']['gallery_filter_default_div_class'] = array(
461 '#type' => 'textfield',
462 '#title' => t('Default class'),
463 '#default_value' => variable_get('gallery_filter_default_div_class', 'nowrap'),
466 '#description' => t('left, right, or nowrap. (See gallery_filter.css to add more or modify these.)'),
468 return $form['filter'];
472 * Settings for gallery search
475 function _gallery_search_settings($typeMap , $paramMap) {
476 $form['search'] = array(
477 '#type' => 'fieldset',
478 '#title' => t('Search settings'),
479 '#description' => '',
480 '#collapsible' => TRUE
,
481 '#collapsed' => TRUE
,
484 $form['search']['gallery_search_max_items'] = array(
486 '#title' => t('Max number of search results'),
487 '#default_value' => variable_get('gallery_search_max_items', 50),
488 '#options' => array(25=>25, 50=>50, 100=>100, 250=>250),
489 '#description' => t('Enter the maximum number of search results returned per Gallery2 Module. Higher numbers will give slower searching.'),
492 $form['search']['gallery_search_num_per_row'] = array(
494 '#title' => t('Number of search results per table row'),
495 '#default_value' => variable_get('gallery_search_num_per_row', 3),
496 '#options' => array(1=>1, 2=>2, 3=>3, 4=>4, 5=>5),
497 '#description' => t('Enter the number of search results per row in the paged table.'),
500 $form['search']['gallery_search_max_rows_per_pager'] = array(
501 '#type' => 'textfield',
502 '#title' => t('Number of rows per page'),
503 '#default_value' => variable_get('gallery_search_max_rows_per_pager', 5),
506 '#description' => t('Enter the number of search results per row in the paged table.'),
509 $form['search']['gallery_search_show_thumbs'] = array(
510 '#type' => 'checkbox',
511 '#title' => t('Display thumbnails'),
512 '#default_value' => variable_get('gallery_search_show_thumbs', 1),
513 '#description' => t('Display thumbnail images for the search results.'),
516 $form['search']['gallery_search_block_show'] = array(
517 '#type' => 'checkboxes',
518 '#title' => t('Image data'),
519 '#default_value' => variable_get('gallery_search_block_show', array('title' => t('Title'))),
520 '#options' => $paramMap,
521 '#description' => t('Choose the item metadata you\'d like to display.'),
524 $form['search']['gallery_search_maxsize'] = array(
525 '#type' => 'textfield',
526 '#title' => t('Thumbnail size'),
527 '#default_value' => variable_get('gallery_search_maxsize', 150),
530 '#description' => t('If you want your size to be bigger than the thumbnail size for that image as defined in your G2, you must select "Full Size" above (but note that the full image will be returned and then resized by the browser, so it may take a while to download).'),
533 // Add album frames, item frames and link target (using modified code from MichelleC)
534 $form['search']['gallery_search_album_frame'] = array(
535 '#type' => 'textfield',
536 '#title' => t('Album frame'),
537 '#default_value' => variable_get('gallery_search_album_frame', 'none'),
540 '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your G2 install for a complete list. Use "none" or blank for no frame.'),
543 $form['search']['gallery_search_item_frame'] = array(
544 '#type' => 'textfield',
545 '#title' => t('Item frame'),
546 '#default_value' => variable_get('gallery_search_item_frame', 'none'),
549 '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your G2 install for a complete list. Use "none" or blank for no frame.'),
552 $form['search']['gallery_search_link_target'] = array(
553 '#type' => 'textfield',
554 '#title' => t('Link target'),
555 '#default_value' => variable_get('gallery_search_link_target', ''),
558 '#description' => t('Enter a link target (eg "_blank", "_new").'),
560 return $form['search'];
564 * Settings for g2image
567 function _gallery_g2image_settings() {
568 $form['g2image'] = array(
569 '#type' => 'fieldset',
570 '#title' => t('Gallery Image Assist (g2image) settings'),
571 '#description' => '',
572 '#collapsible' => TRUE
,
573 '#collapsed' => TRUE
,
576 $form['g2image']['gallery_g2image_mode'] = array(
578 '#title' => t('Mode'),
579 '#default_value' => variable_get('gallery_g2image_mode', 'disabled'),
581 'disabled' => t('Disabled'),
582 'standalone' => t('Standalone'),
583 'tinymce' => t('TinyMCE'),
585 '#description' => t('Determines the mode of operation. For anything other than \'Disabled\' the g2image application has to be installed. See the INSTALL.txt instructions. In \'Standalone\' mode a button will be visible under textfields to launch the g2image window. In \'TinyMCE\' mode the g2image button can be used in the tinymce toolbar. Note that the TinyMCE version will NOT work wih Safari - use the standalone version instead.'),
589 t('Show on every page except the listed pages.'),
590 t('Show on only the listed pages.')
592 $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => theme('placeholder', 'blog'), '%blog-wildcard' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>')));
594 $form['g2image']['gallery_g2image_only_listed_pages'] = array(
596 '#title' => t('Show g2image link on specific pages (Standalone mode only)'),
597 '#default_value' => variable_get('gallery_g2image_only_listed_pages', 1),
598 '#options' => $options,
601 $form['g2image']['gallery_g2image_std_pages'] = array(
602 '#type' => 'textarea',
603 '#title' => t('Pages (Standalone mode only)'),
604 '#default_value' => variable_get('gallery_g2image_std_pages', gallery_help('admin/settings/gallery_g2image#pages')),
605 '#description' => $description
608 $form['g2image']['gallery_g2image_regex'] = array(
609 '#type' => 'textfield',
610 '#title' => t('Image Types Regular Expression'),
611 '#default_value' => variable_get('gallery_g2image_regex', '@(jpg|jpeg|png|gif|bmp|svg|mov|mpg|mpeg)$@i'),
614 '#description' => t('Images with these file extensions will be displayed in g2image'),
617 $form['g2image']['gallery_g2image_sortby'] = array(
619 '#title' => t('Default Sort Order'),
620 '#default_value' => variable_get('gallery_g2image_sortby', 'title_asc'),
622 'title_asc' => t('Gallery2 Title (A-z)'),
623 'title_desc' => t('Gallery2 Title (z-A)'),
624 'name_asc' => t('Filename (A-z)'),
625 'name_desc' => t('Filename (z-A)'),
626 'mtime_desc' => t('Last Modification (newest first)'),
627 'mtime_asc' => t('Last Modification (oldest first)'),
629 '#description' => t('Determines the default sorting order.'),
632 $form['g2image']['gallery_g2image_images_per_page'] = array(
634 '#title' => t('Default Number of images per page'),
635 '#default_value' => variable_get('gallery_g2image_images_per_page', 20),
636 '#options' => array(10=>10, 20=>20, 30=>30, 40=>40, 50=>50, 60=>60),
637 '#description' => t('Choose the default number of images per page.'),
640 $form['g2image']['gallery_g2image_display_filenames'] = array(
642 '#title' => t('Default Display Options'),
643 '#default_value' => variable_get('gallery_g2image_display_filenames', 'thumbnails'),
645 'thumbnails' => t('Thumbnails only'),
646 'filenames' => t('Thumbnails with title and filename'),
648 '#description' => t('Choose the default display option for images.'),
651 $form['g2image']['gallery_g2image_click_mode'] = array(
653 '#title' => t('Default Click Mode'),
654 '#default_value' => variable_get('gallery_g2image_click_mode', 'one_click_insert'),
656 'one_click_insert' => t('Insert using Default settings'),
657 'show_advanced_options' => t('Open the Advanced Options Menu'),
659 '#description' => t('The default settings for the "Results of clicking on an image:" option'),
662 $form['g2image']['gallery_g2image_click_mode_variable'] = array(
663 '#type' => 'checkbox',
664 '#title' => t('"Results of clicking on an image:" option is available to user'),
665 '#default_value' => variable_get('gallery_g2image_click_mode_variable', 1),
666 '#description' => t('Determines if the user can change the "Results of clicking on an image:" option.'),
669 $form['g2image']['gallery_g2image_default_action'] = array(
671 '#title' => t('Default Action'),
672 '#default_value' => variable_get('gallery_g2image_default_action', 'drupal_g2_filter'),
674 'drupal_g2_filter' => t('Gallery Filter ID'),
675 'thumbnail_image' => t('Thumbnail with link to image'),
676 'thumbnail_album' => t('Thumbnail with link to parent album'),
677 'thumbnail_custom_url' => t('Thumbnail with link to custom URL'),
678 'thumbnail_only' => t('Thumbnail only'),
679 'link_image' => t('Text link to image'),
680 'link_parent' => t('Text link to parent album'),
682 '#description' => t('Choose the default method of inserting the image info.'),
685 $form['g2image']['gallery_g2image_custom_url'] = array(
686 '#type' => 'textfield',
687 '#title' => t('Default custom url'),
688 '#default_value' => variable_get('gallery_g2image_custom_url', 'http://'),
691 '#description' => t('The default custom url. Used with \'Thumbnail with link to custom URL\' action setting'),
696 $gallery_g2image_custom_class = variable_get('gallery_g2image_custom_class', array());
697 $css_options = array(
699 'g2image_normal' => t('Normal'),
700 'g2image_float_left' => t('Float Left'),
701 'g2image_float_right' => t('Float Right'),
702 'g2image_centered' => t('Centered'),
705 $add_css_options = array();
706 foreach ($gallery_g2image_custom_class as
$key => $value) {
708 $add_css_options[$value] = $value;
711 $css_options = array_merge($css_options, $add_css_options);
713 $form['g2image']['gallery_g2image_default_alignment'] = array(
715 '#title' => t('Default Alignment'),
716 '#default_value' => variable_get('gallery_g2image_default_alignment', 'none'),
717 '#options' => $css_options,
718 '#description' => t('Choose the default alignment of images.'),
721 $form['g2image']['gallery_g2image_custom_class'] = array(
725 for ($i=1; $i<=4; $i++) {
726 $form['g2image']['gallery_g2image_custom_class'][$i] = array(
727 '#type' => 'textfield',
728 '#title' => t('Custom Class %index', array('%index' => $i)),
729 '#default_value' => $gallery_g2image_custom_class[$i],
734 $form['g2image']['gallery_g2image_custom_class'][$i-1]['#description'] =
735 t('Additional css classes to be available for selection (must be defined in .css file).');
737 $form['g2image']['gallery_g2image_class_mode'] = array(
739 '#title' => t('Alignment Class Insertion Point'),
740 '#default_value' => variable_get('gallery_g2image_class_mode', 'img'),
742 'img' => t('<img class=...>'),
743 'div' => t('<div class=...><img ...>'),
745 '#description' => t('Determines where the alignment class will be inserted. If you choose \'<div class=...><img ...>\', you will have to manually delete any <div> tags manually after deleting images from the TinyMCE window.'),
747 return $form['g2image'];
751 * Settings for links section
754 function _gallery_links_settings() {
755 if (variable_get('gallery_valid', 0)) {
756 $g2Uri = variable_get('gallery_embed_uri', '?q=gallery');
757 $desc = t('Here are some links to the parts of Gallery2 Site Admin most relevant to gallery.module.');
759 $desc .
= '<li><a href= "' .
$g2Uri .
'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules">Modules</a> : ' .
t('To install, activate or configure the required and optional modules relating to gallery.module (Image Block, Image Frame, URL Rewrite, Album Select).') .
'</li>';
760 $desc .
= '<li><a href= "' .
$g2Uri .
'&g2_view=core.SiteAdmin&g2_subView=core.AdminThemes&g2_mode=defaults">Themes</a> : ' .
t('To add/remove blocks in the sidebar.') .
'</li>'; $desc .
= '<li><a href= "' .
$g2Uri .
'&g2_view=core.SiteAdmin&g2_subView=rewrite.AdminRewrite&g2_mode=setup">Embedded URL Rewrite settings</a> : ' .
t('To configure the correct .htaccess path and define the rewrite rules.') .
'</li>';
761 $desc .
= '<li><a href= "' .
$g2Uri .
'&g2_view=core.SiteAdmin&g2_subView=core.AdminCore">Cookie Settings</a> : '.
t('Only needed for a small number of site configurations, such as the use of different subdomains for Gallery2 and Drupal.') .
'</li>';
764 $desc = t('This section will contain links to the parts of Gallery2 Site Admin most relevant to gallery.module. It is only available when your Embedded Gallery installation is valid, which it currently is not.');
766 $form['links'] = array(
767 '#type' => 'fieldset',
768 '#title' => t('Links to Gallery2 Site Admin sections most relevant to Drupal (advanced)'),
769 '#description' => $desc,
770 '#collapsible' => TRUE
,
771 '#collapsed' => TRUE
,
773 return $form['links'];
778 * Validate the gallery form settings
780 function gallery_settings_form_validate($form_id, &$form) {
782 include_once(drupal_get_path('module', 'gallery') .
'/G2EmbedDiscoveryUtilities.class');
783 include_once(drupal_get_path('module', 'gallery') .
'/G2EmbedTestUtilities.class');
787 // Store the original values for the variables
788 $orig['g2Uri'] = $form_values['gallery_uri'];
789 $orig['g2EmbedPath'] = $form_values['gallery_dir'];
790 $orig['embedUri'] = $form_values['gallery_embed_uri'];
792 // Check these variables
793 list($num_errors, $num_warnings, $new, $results) =
794 G2EmbedTestUtilities
::checkLocations($orig, $form_values['gallery_autodetect_dir']);
799 // Update the variables with the new validated ones
800 $form_values['gallery_uri'] = $new['g2Uri'];
801 $form_values['gallery_dir'] = $new['g2EmbedPath'];
802 $form_values['gallery_embed_uri'] = $new['embedUri'];
804 // Perform pre-init tests. If they fail then do not init the gallery as there may be an issue
805 list($num_errors, $num_warnings, $pre_init_results) = G2EmbedTestUtilities
::preInitTests();
806 $results = array_merge($results, $pre_init_results);
811 // If the filepaths seem correct then check Gallery2 works and has the correct module configs
812 // This code is modified from the WPG2 integration code -- Thanks.
813 if ($gallery_valid) {
814 // Gallery install is thought valid, so init it.
815 $title = t('Gallery2 Init:');
816 $vars['gallery_uri'] = $form_values['gallery_uri'];
817 $vars['gallery_dir'] = $form_values['gallery_dir'];
818 $vars['gallery_embed_uri'] = $form_values['gallery_embed_uri'];
819 $vars['gallery_valid'] = true
;
820 list ($success, $ret) = _gallery_init(true
, $vars);
822 // Gallery install was supposed to be valid, but it still failed. Something is wrong.
823 $results['gallery_init']['title'] = $title;
824 $results['gallery_init']['error'] = true
;
825 $results['gallery_init']['notice'] = t('Everything seemed OK, but the Gallery could still not be initialised. Perhaps a manually entered value is incorrect.');
828 $results['gallery_init']['title'] = $title;
829 $results['gallery_init']['success'] = true
;
831 list($num_errors, $num_warnings, $post_init_results) = G2EmbedTestUtilities
::postInitTests();
835 // Check for changed embedUri
836 /* No longer needed as the URL Rewrite config below will do it
837 if ($form_values['gallery_embed_uri'] != variable_get('gallery_embed_uri', '?q=gallery')) {
838 $post_init_results['urlrewrite3']['title'] = t('Gallery2 URL Rewrite rules:');
839 $post_init_results['urlrewrite3']['warning'] = true;
840 $post_init_results['urlrewrite3']['notice'] = t('The \'Embed URI\' setting has changed. If you are using the URL Rewrite module in Gallery2 you will need to regenerate the rules (just click the \'save\' button on the Embedded URL Rewrite page).');
843 // Update the URL Rewrite Configuration
844 if ($post_init_results['urlrewrite']['success']) {
845 list($url_conf_num_errors, $url_conf_num_warnings, $post_init_results['urlrewrite2']) =
846 _gallery_configure_url_rewrite();
849 $results = array_merge($results, $post_init_results);
851 // Setup the cookie path - removed for now (see above)
853 $path = $form_values['gallery_cookie_path'];
854 $ret = GalleryCoreApi::setPluginParameter('module', 'core', 'cookie.path', $path);
857 GalleryEmbed
::done();
860 // Validate the g2image settings
861 list($num_errors, $num_warnings, $results_g2image) =
862 _gallery_g2image_settings_form_validate($form_values);
863 if ($results_g2image) {
864 $results['gallery_g2image'] = $results_g2image;
867 // Test again for validity
868 if ($gallery_valid) {
869 $results['gallery_valid']['title'] = t('Overall Status:');
870 $results['gallery_valid']['success'] = true
;
872 $results['gallery_valid']['title'] = t('Overall Status:');
873 $results['gallery_valid']['error'] = true
;
874 $results['gallery_valid']['notice'] = t('You need to fix the above errors before Gallery2 will be embedded in Drupal.');
877 $message = t('Embedded Gallery2 Status: ').
'<ul>';
878 foreach ($results as
$key=>$result) {
879 $message .
= '<li>' .
t($result['title']) .
' ';
880 if (isset($result['success']) && $result['success']) {
881 $message .
= '<span class=\'g2_embed_success\'>' .
t('Success') .
'</span>';
882 } else if (isset($result['warning']) && $result['warning']) {
883 $message .
= '<span class=\'g2_embed_warning\'>' .
t('Warning') .
'</span>';
884 $message .
= '<ul><li>' .
t($result['notice']) .
'</li></ul>';
885 } else if (isset($result['error']) && $result['error']) {
886 $message .
= '<span class=\'g2_embed_error\'>' .
t('Error') .
'</span>';
887 $message .
= '<ul><li>' .
t($result['notice']) .
'</li></ul>';
888 } else if (isset($result['advise']) && $result['advise']) {
889 $message .
= '<span class=\'g2_embed_warning\'>' .
t('Advisory') .
'</span>';
890 $message .
= '<ul><li>' .
t($result['notice']) .
'</li></ul>';
894 drupal_set_message($message);
895 $form_values['gallery_valid'] = $gallery_valid;
897 // Gallery Image Block Settings validation
898 // Need to truncate the gallery_block_block variable to the entered number of blocks
899 if (count($form_values['gallery_block_block']) != $form_values['gallery_block_num_images']) {
900 $form_values['gallery_block_block'] = array_slice(
901 $form_values['gallery_block_block'], 0, $form_values['gallery_block_num_images']);
906 * Configure URL rewrite (from WPG2 code)
908 function _gallery_configure_url_rewrite() {
912 // Find the public path to drupal from the base_url
914 $http = 'http' .
(isset($_SERVER['HTTPS']) ?
$_SERVER['HTTPS'] == 'on' ?
's' : '' : '');
915 $public_path = str_replace($http .
'://' .
$_SERVER['HTTP_HOST'],'', $base_url) .
'/';
917 // Find the path to drupal. Will this always work?
918 $htaccess_path = realpath(".") .
'/';
920 $title = t('Gallery2 URL Rewrite Module Auto-Configuration:');
921 $results['urlrewrite']['title'] = $title;
923 list ($ret, $rewriteApi) = GalleryCoreApi
::newFactoryInstance('RewriteApi');
925 /* G2 Error handling */
926 // All other tests were run already
927 $results['urlrewrite']['error'] = true
;
928 $results['urlrewrite']['notice'] =t(
929 'Gallery2 Error when trying to access URL Rewrite Module status. %ret',
930 array('%ret' => $ret->getAsHtml()));
932 list ($ret, $params) = $rewriteApi->fetchEmbedConfig();
934 // Check if .htaccess exists. If not and path is writable, create it.
935 // This should only occur for multi-site installs as the main drupal dir always has a .htaccess
936 if (!file_exists($htaccess_path .
'.htaccess')) {
937 // Better to check for the file, not the dir as if not writable fopen returns a visible warning
938 if (is_writable($htaccess_path .
'.htaccess')) {
939 $f = fopen($htaccess_path .
'.htaccess', 'w');
942 $results['urlrewrite']['error'] = true
;
943 $results['urlrewrite']['notice'] = t('There is no .htaccess file in your defined Drupal directory (%dir) and the directory is not writable. Please create a writable .htaccess file in that directory.', array('%dir' => $htaccess_path));
945 return array($num_errors, $num_warnings, $results['urlrewrite']);
949 if (file_exists($htaccess_path .
'.htaccess')) {
950 if (is_writable($htaccess_path .
'.htaccess')) {
952 // Set the G2 rewrite Values
953 $params['embeddedLocation'] = $public_path;
954 $params['embeddedHtaccess'] = $htaccess_path;
956 // Save the G2 rewrite Values
957 list ($ret, $code, $err) = $rewriteApi->saveEmbedConfig($params);
958 if ($code != REWRITE_STATUS_OK
) {
959 list ($ret, $errstr) = $err;
960 $errstr = $code.
" - ".
$errstr;
961 $results['urlrewrite']['error'] = true
;
962 $results['urlrewrite']['notice'] = t('The Gallery2 URL Rewrite module returned the following error:') .
'<pre>' .
$errstr .
'</pre>';
965 $results['urlrewrite']['success'] = true
;
968 $results['urlrewrite']['error'] = true
;
969 $results['urlrewrite']['notice'] = t('The .htaccess file in your defined Drupal directory (%dir) is not writable. Please CHMOD it to 644 (or 666 if 644 does not work).', array('%dir' => $htaccess_path));
973 return array($num_errors, $num_warnings, $results['urlrewrite']);
977 * Validate the gallery g2image settings and saves the config file if needed.
979 function _gallery_g2image_settings_form_validate(&$form_values) {
980 switch ($form_values['gallery_g2image_mode']) {
982 $mode = t('TinyMCE');
983 $path = drupal_get_path('module', 'tinymce');
984 $path .
= '/tinymce/jscripts/tiny_mce/plugins/g2image';
987 $mode = t('Standalone');
988 $path = drupal_get_path('module', 'gallery');
992 return array(0, 0, array());
994 $title = 'Gallery2 Image Assist (g2image) Status:';
995 // Note that file_check_directory uses &$path and will strip the trailing '/'
996 $filename = $path .
'/config.php';
997 if (is_writable($filename) == false
&& !file_check_directory($path)) {
998 $results['gallery_g2image']['title'] = $title;
999 $results['gallery_g2image']['warning'] = true
;
1000 $results['gallery_g2image']['notice'] = t('g2image does not seem to be installed for %mode mode in the required directory (%dir), or the directory is not writable. Please see the INSTALL.txt for instructions.', array('%mode' => $mode, '%dir' => '<drupal_path>'.
$path));
1002 return array($num_errors, $num_warnings, $results['gallery_g2image']);
1005 $g2ic_gallery2_path = $form_values['gallery_dir'];
1006 $g2ic_use_full_path = (substr($g2ic_gallery2_path, 0, 1) == '/') ?
'TRUE' : 'FALSE';
1007 $form_values['gallery_g2image_custom_url'] =
1008 check_url($form_values['gallery_g2image_custom_url']);
1009 $g2ic_display_filenames = ($form_values['gallery_g2image_display_filenames'] == 'filenames') ?
1011 $g2ic_custom_class = array();
1012 foreach ($form_values['gallery_g2image_custom_class'] as
$key => $value) {
1013 $g2ic_custom_class[$key] = ($value) ?
$value : 'not_used';
1016 $g2ic_custom_class_1 = ($form_values['gallery_g2image_custom_class_1']) ?
1017 $form_values['gallery_g2image_custom_class_1'] : 'not_used';
1018 $g2ic_custom_class_2 = ($form_values['gallery_g2image_custom_class_2']) ?
1019 $form_values['gallery_g2image_custom_class_2'] : 'not_used';
1020 $g2ic_custom_class_3 = ($form_values['gallery_g2image_custom_class_3']) ?
1021 $form_values['gallery_g2image_custom_class_3'] : 'not_used';
1022 $g2ic_custom_class_4 = ($form_values['gallery_g2image_custom_class_4']) ?
1023 $form_values['gallery_g2image_custom_class_4'] : 'not_used';
1025 $content = '<?php' .
$cr;
1026 $content .
= '// Configuration File for Gallery 2 Image Chooser for TinyMCE' .
$cr;
1027 $content .
= '// Version 2.0 RC4 and above' .
$cr;
1028 $content .
= '// By Kirk Steffensen - http://g2image.steffensenfamily.com/' .
$cr;
1029 $content .
= '// Released under the GPL version 2.' .
$cr;
1030 $content .
= '// A copy of the license is in the root folder of this plugin.' .
$cr;
1031 $content .
= $cr .
'// Automatically generated by gallery.module (admin/settings/gallery).' .
$cr;
1032 $content .
= '// DO NOT EDIT' .
$cr;
1033 $content .
= '$g2ic_image_ext_regex = \'' .
$form_values['gallery_g2image_regex'] .
'\';' .
$cr;
1034 $content .
= '$g2ic_gallery2_path = \'' .
$g2ic_gallery2_path .
'\';' .
$cr;
1035 $content .
= '$g2ic_embedded_mode = TRUE;' .
$cr;
1036 $content .
= '$g2ic_use_full_path = ' .
$g2ic_use_full_path.
';' .
$cr;
1037 $content .
= '$g2ic_gallery2_uri = \'' .
$form_values['gallery_uri'] .
'\';' .
$cr;
1038 $content .
= '$g2ic_embed_uri = \'' .
$form_values['gallery_embed_uri'] .
'\';' .
$cr;
1039 $content .
= '$g2ic_drupal_g2_filter = TRUE;' .
$cr;
1040 $content .
= '$g2ic_drupal_g2_filter_prefix = \'' .
$form_values['gallery_filter_prefix'] .
'\';' .
$cr;
1041 $content .
= '$g2ic_language = \'en\';' .
$cr;
1042 $content .
= '$g2ic_images_per_page = ' .
$form_values['gallery_g2image_images_per_page'] .
';' .
$cr;
1043 $content .
= '$g2ic_display_filenames = ' .
$g2ic_display_filenames .
';' .
$cr;
1044 $content .
= '$g2ic_default_alignment = \'' .
$form_values['gallery_g2image_default_alignment'] .
'\';' .
$cr;
1045 $content .
= '$g2ic_custom_class_1 = \'' .
$g2ic_custom_class[1] .
'\';' .
$cr;
1046 $content .
= '$g2ic_custom_class_2 = \'' .
$g2ic_custom_class[2] .
'\';' .
$cr;
1047 $content .
= '$g2ic_custom_class_3 = \'' .
$g2ic_custom_class[3] .
'\';' .
$cr;
1048 $content .
= '$g2ic_custom_class_4 = \'' .
$g2ic_custom_class[4] .
'\';' .
$cr;
1049 $content .
= '$g2ic_class_mode = \'' .
$form_values['gallery_g2image_class_mode'] .
'\';' .
$cr;
1050 $content .
= '$g2ic_click_mode = \'' .
$form_values['gallery_g2image_click_mode'] .
'\';' .
$cr;
1051 $content .
= '$g2ic_click_mode_variable = ' .
$form_values['gallery_g2image_click_mode_variable'] .
';' .
$cr;
1052 $content .
= '$g2ic_default_action = \'' .
$form_values['gallery_g2image_default_action'] .
'\';' .
$cr;
1053 $content .
= '$g2ic_sortby = \'' .
$form_values['gallery_g2image_sortby'] .
'\';' .
$cr;
1054 $content .
= '$g2ic_custom_url = \'' .
$form_values['gallery_g2image_custom_url'] .
'\';' .
$cr;
1055 $content .
= '?>' .
$cr;
1057 $filename = $path .
'/config.php';
1058 if (is_writable($filename) == false
) {
1059 $results['gallery_g2image']['title'] = $title;
1060 $results['gallery_g2image']['warning'] = true
;
1061 $results['gallery_g2image']['notice'] = t('Could not write to g2image config file. Please check the permissions for %filename.', array('%filename' => $filename));
1063 return array($num_errors, $num_warnings, $results['gallery_g2image']);
1065 $handle = fopen($filename, "w");
1066 if (fwrite($handle, $content) === FALSE
) {
1067 $results['gallery_g2image']['title'] = $title;
1068 $results['gallery_g2image']['warning'] = true
;
1069 $results['gallery_g2image']['notice'] = t('Could not write to g2image config file. Please check the permissions for %filename.', array('%filename' => $filename));
1071 return array($num_errors, $num_warnings, $results['gallery_g2image']);
1073 $results['gallery_g2image']['title'] = $title;
1074 $results['gallery_g2image']['success'] = true
;
1077 return array($num_errors, $num_warnings, $results['gallery_g2image']);