'),
),
'#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.'),
);
}
$form['#validate']['_gallery_g2image_settings_validate'] = array();
return system_settings_form($form);
}
/**
* Function _gallery_settings_search().
*/
function _gallery_settings_search() {
require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
$plugin_status = gallery_plugin_status(array('imageblock', 'imageframe', 'search'));
$search_desc = t('The Gallery Search requires the Gallery2 Search plugin (!search_status) and
optionally the Gallery2 Image Block plugin (!imageblock_status) and Gallery2 Image Frame
plugin (!imageframe_status).',
array(
'!search_status' => theme('gallery_plugin_status_message', $plugin_status['search']),
'!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
'!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
)
);
$g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
$g2_plugins_page = (variable_get('gallery_valid', 0)) ?
t('
Gallery2 Plugins',
array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
: t('Gallery2 Site Admin -> Plugins');
$thumbs_desc = '';
if ($plugin_status['search'] != GALLERY_PLUGIN_ENABLED) {
$search_desc .= t(' However the Search plugin is unavailable, so the search is
not available and these settings are disabled. To use the search feature please go to
the !g2_plugins page and install/activate the Image Block plugin.',
array('!g2_plugins' => $g2_plugins_page));
}
if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
$thumbs_desc = t('To display search results with thumbnail images requires the Gallery2 Image
Block plugin (!imageblock_status) and optionally the and Gallery2 Image Frame
plugin (!imageframe_status).',
array(
'!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
'!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']),
)
);
$thumbs_desc .= t(' However the Image Block plugin is unavailable, so the thumbnails are
not available and these settings are disabled. To use this feature please go to
the !g2_plugins page and install/activate the Image Block plugin.',
array('!g2_plugins' => $g2_plugins_page));
}
$imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
$form['search'] = array(
'#type' => 'fieldset',
'#title' => t('Search settings'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#description' => $search_desc,
);
$image_frames = gallery_get_image_frames();
_gallery_block_options($type_map, $param_map);
if ($plugin_status['search'] == GALLERY_PLUGIN_ENABLED) {
$form['search']['gallery_search_advanced'] = array(
'#type' => 'checkbox',
'#title' => t('Display advanced search options'),
'#default_value' => variable_get('gallery_search_advanced', 1),
'#description' => t('Adds options to the search form to select which Gallery fields to search in.'),
);
$form['search']['gallery_search_num_per_row'] = array(
'#type' => 'select',
'#title' => t('Number of search results per table row'),
'#default_value' => variable_get('gallery_search_num_per_row', 3),
'#options' => _gallery_range_array(1, 5),
'#description' => t('Select the number of search results per row in the paged table.'),
);
$form['search']['gallery_search_rows_per_pager'] = array(
'#type' => 'select',
'#title' => t('Number of rows per page'),
'#default_value' => variable_get('gallery_search_rows_per_pager', 4),
'#options' => _gallery_range_array(1, 10),
'#description' => t('Select the number of rows in the paged table.'),
);
$form['search']['thumbs'] = array(
'#type' => 'fieldset',
'#title' => t('Search thumbnail settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => $thumbs_desc,
);
if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED) {
$form['search']['thumbs']['gallery_search_show_thumbs'] = array(
'#type' => 'checkbox',
'#title' => t('Display thumbnails'),
'#default_value' => variable_get('gallery_search_show_thumbs', 1),
'#description' => t('Display thumbnail images for the search results.'),
);
$form['search']['thumbs']['gallery_search_block_show'] = array(
'#type' => 'checkboxes',
'#title' => t('Image data'),
'#default_value' => variable_get('gallery_search_block_show', array('title' => t('Title'))),
'#options' => $param_map,
'#description' => t('Choose the item metadata you would like to display.'),
);
$form['search']['thumbs']['gallery_search_size_method'] = array(
'#type' => 'select',
'#title' => t('Image size method'),
'#default_value' => variable_get('gallery_search_size_method', GALLERY_SEARCH_SIZE_METHOD_DEFAULT),
'#options' => array(
'maxsize' => t('Max Size'),
'exactsize' => t('Exact Size'),
),
'#description' => t('\'Max Size\' gives faster image downloading, but the image size
may be smaller than the size defined below.
\'Exact Size\' may be slower
(as a larger image is downloaded and then scaled by the browser) but the image
will be guaranteed to be the size defined below. Only supported for G2.2+.'),
);
$form['search']['thumbs']['gallery_search_size'] = array(
'#type' => 'textfield',
'#title' => t('Image size'),
'#default_value' => variable_get('gallery_search_size', GALLERY_SEARCH_SIZE_DEFAULT),
'#size' => 10,
'#maxlength' => 10,
'#description' => t('Sets the size (in pixels) of the longest side of the image
according to the method defined above.'),
);
$form['search']['thumbs']['gallery_search_album_frame'] = array(
'#type' => 'select',
'#title' => t('Album frame'),
'#default_value' => variable_get('gallery_search_album_frame', 'none'),
'#options' => $image_frames,
'#description' => $imageframe_desc,
);
$form['search']['thumbs']['gallery_search_item_frame'] = array(
'#type' => 'select',
'#title' => t('Item frame'),
'#default_value' => variable_get('gallery_search_item_frame', 'none'),
'#options' => $image_frames,
'#description' => $imageframe_desc,
);
$form['search']['thumbs']['gallery_search_link_target'] = array(
'#type' => 'textfield',
'#title' => t('Link target'),
'#default_value' => variable_get('gallery_search_link_target', ''),
'#size' => 20,
'#maxlength' => 20,
'#description' => t('Enter a link target (e.g. "_blank", "_new").'),
);
$form['search']['thumbs']['gallery_search_default_link'] = array(
'#type' => 'textfield',
'#title' => t('Image Link'),
'#default_value' => variable_get('gallery_search_default_link', ''),
'#size' => 20,
'#maxlength' => 20,
'#description' => t('By default the image has a link to the item in the Gallery. This
can be overridden here (or leave empty for the default). Use \'none\' for no link, or a
URL to link somewhere else instead.'),
);
}
}
return system_settings_form($form);
}
/**
* Function _gallery_settings_search_validate().
*/
function _gallery_settings_search_validate($form_id, $form_values) {
if (isset($form_values['gallery_search_size']) &&
(!is_numeric($form_values['gallery_search_size']) || $form_values['gallery_search_size'] < 1)) {
form_set_error('gallery_search_size',
t('Image size must be a number greater than zero.'));
}
}
/**
* Function _gallery_g2image_settings_validate().
* (saves the G2Image config file)
*/
function _gallery_g2image_settings_validate($form_id, $form_values) {
switch ($form_values['gallery_g2image_mode']) {
case 'tinymce':
$mode = t('TinyMCE');
$path = drupal_get_path('module', 'tinymce');
$path .= '/tinymce/jscripts/tiny_mce/plugins/g2image';
break;
case 'standalone':
$mode = t('Standalone');
$path = drupal_get_path('module', 'gallery');
$path .= '/g2image';
break;
default:
return;
}
// Note that file_check_directory uses &$path and will strip the trailing '/'
$filename = $path .'/config.php';
if (is_writable($filename) == FALSE && !file_check_directory($path)) {
form_set_error('', 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' => '
/'. $path)));
return;
}
$cr = "\n";
$g2ic_gallery2_path = str_replace('\\', '/', variable_get('gallery_dir', './gallery2/'));
$g2ic_use_full_path = (substr($g2ic_gallery2_path, 0, 1) == '/' || substr($g2ic_gallery2_path, $_SERVER['DOCUMENT_ROOT']) !== FALSE) ?
'TRUE' : 'FALSE';
$form_values['gallery_g2image_custom_url'] = check_url($form_values['gallery_g2image_custom_url']);
$g2ic_display_filenames = ($form_values['gallery_g2image_display_filenames'] == 'filenames') ? 'TRUE' : 'FALSE';
$g2ic_custom_class = array();
foreach ($form_values['gallery_g2image_custom_class'] as $key => $value) {
$g2ic_custom_class[$key] = ($value) ? $value : 'not_used';
}
$g2ic_custom_class_1 = ($form_values['gallery_g2image_custom_class_1']) ?
$form_values['gallery_g2image_custom_class_1'] : 'not_used';
$g2ic_custom_class_2 = ($form_values['gallery_g2image_custom_class_2']) ?
$form_values['gallery_g2image_custom_class_2'] : 'not_used';
$g2ic_custom_class_3 = ($form_values['gallery_g2image_custom_class_3']) ?
$form_values['gallery_g2image_custom_class_3'] : 'not_used';
$g2ic_custom_class_4 = ($form_values['gallery_g2image_custom_class_4']) ?
$form_values['gallery_g2image_custom_class_4'] : 'not_used';
$content = ''. $cr;
$filename = $path .'/config.php';
if (is_writable($filename) == FALSE) {
form_set_error('', t('Could not write to G2Image config file. Please check the permissions for @filename.',
array('@filename' => $filename)));
return;
}
$handle = fopen($filename, "w");
if (fwrite($handle, $content) === FALSE) {
form_set_error('', t('Could not write to G2Image config file. Please check the permissions for @filename.',
array('@filename' => $filename)));
return;
}
else {
drupal_set_message(t('G2Image configuration file successfully created.'));
}
fclose($handle);
}
/**
* Function _gallery_range_array().
* (create an associative range array
* like array($min=>$min, ..., $max=>$max))
*/
function _gallery_range_array($min, $max) {
$range_array = array();
for ($i=$min; $i<=$max; $i++) {
$range_array[$i] = $i;
}
return $range_array;
}
/**
* Function _gallery_php_mem_check().
* (check the amount of PHP memory)
*/
function _gallery_php_mem_check($min_memory = 24) {
$mem_limit = trim(ini_get('memory_limit'));
$mem_limit_bytes = parse_size($mem_limit);
if (empty($mem_limit)) {
return array(
'status' => TRUE,
'info' => t('There is no memory limit restricting your PHP installation.'),
);
}
elseif (($mem_limit_bytes / (1024 * 1024)) < $min_memory) {
return array(
'status' => FALSE,
'info' => t('Your PHP is configured to limit the memory to @mem_limit
(memory_limit parameter in php.ini). You must raise this limit
to at least @min_mem_limitM for proper embedded Gallery2 operation.',
array(
'@mem_limit' => $mem_limit,
'@min_mem_limit' => $min_memory,
)
)
);
}
else {
return array(
'status' => TRUE,
'info' => t('Your PHP is configured to limit the memory to @mem_limit
(memory_limit parameter in php.ini). This should be fine for embedded Gallery2 operation.',
array(
'@mem_limit' => $mem_limit,
)
)
);
}
}
/**
* Function gallery_wanted_plugin_info().
*/
function gallery_wanted_plugin_info() {
return array(
'imageblock' => array(
'title' => 'Image Block',
'info' => t('Allows images to be included in the Drupal sidebar or in nodes.'),
'severity' => GALLERY_SEVERITY_ERROR,
'status' => gallery_single_plugin_status('imageblock'),
),
'imageframe' => array(
'title' => 'ImageFrame',
'info' => t('Provides a variety of frames around the images.'),
'severity' => GALLERY_SEVERITY_WARNING,
'status' => gallery_single_plugin_status('imageframe'),
),
'search' => array(
'title' => 'Search',
'info' => t('Allow the Drupal search to also search the Gallery.'),
'severity' => GALLERY_SEVERITY_WARNING,
'status' => gallery_single_plugin_status('search'),
),
'rewrite' => array(
'title' => 'URL Rewrite',
'info' => t('Allow short URLs (clean URLs).'),
'severity' => GALLERY_SEVERITY_ADVISE,
'status' => gallery_single_plugin_status('rewrite'),
),
);
}
/**
* Function gallery_unwanted_plugin_info().
*/
function gallery_unwanted_plugin_info() {
return array(
'register' => array(
'title' => 'Registration',
'info' => t('All user registration must take place via Drupal to ensure that the users
are synchronized between Drupal and Gallery2. This plugin would allow a user to register
only in Gallery2 and not in Drupal and so should not be used.'),
'severity' => GALLERY_SEVERITY_WARNING,
'status' => gallery_single_plugin_status('register'),
),
);
}
/**
* Function gallery_wanted_module_info().
*/
function gallery_wanted_module_info() {
return array(
'gsitemap' => array(
'title' => 'Google Sitemap',
'status' => module_exists('gsitemap'),
'severity' => GALLERY_SEVERITY_ADVISE,
'info' => t('Allows the Drupal and Gallery2 Google Sitemaps to be merged which allows for
a single sitemap to be sent to Google (and other web search sites).'),
),
'profile' => array(
'title' => 'Profile',
'status' => module_exists('profile'),
'severity' => GALLERY_SEVERITY_ADVISE,
'info' => t('Allows support of the \'Full Name\' field in Gallery2.'),
),
);
}
/**
* Function gallery_plugin_set_status().
*/
function gallery_plugin_set_status($plugin_names) {
$plugins_status = gallery_plugin_status($plugin_names);
$plugin_info = gallery_wanted_plugin_info();
// Generate array containing module status
$status = array();
foreach ($plugins_status as $plugin => $plugin_status) {
if ($plugin_status == GALLERY_PLUGIN_ENABLED) {
$status[$plugin] = '';
}
else {
$status[$plugin]['title'] = t('Gallery2 plugin \'@plugin\' is not available',
array('@plugin' => isset($plugin_info[$plugin]) ? $plugin_info[$plugin]['title'] : drupal_ucfirst($plugin)));
$status[$plugin]['severity'] = isset($plugin_info[$plugin]['severity']) ? $plugin_info[$plugin]['severity'] : GALLERY_SEVERITY_WARNING;
$status[$plugin]['url'] = url('admin/settings/gallery/install', NULL, $plugin);
}
}
gallery_set_status($status);
}
/**
* Function gallery_format_status().
*/
function gallery_format_status($status = array(), $title = 'Gallery message(s):') {
$message = $title .'';
if (count($status)) {
foreach ($status as $item) {
$message .= '- ';
$message .= empty($item['url']) ? t($item['title']) : ''. t($item['title']) .'';
$message .= (isset($item['info']) && !empty($item['info'])) ? (': '. t($item['info'])) : '';
$message .= isset($item['severity']) ? (' ['. theme('gallery_severity_message', $item['severity']) .']') : '';
$message .= '
';
}
}
else {
$message = t('Status not available');
}
$message .= '
';
return $message;
}
/**
* Theme function : theme_gallery_module_status_message().
*/
function theme_gallery_module_status_message($status) {
if ($status) {
return ''. t('enabled') .'';
}
else {
return ''. t('disabled') .'';
}
}
/**
* Theme function : theme_gallery_severity_message().
*/
function theme_gallery_severity_message($severity = NULL) {
switch ($severity) {
case GALLERY_SEVERITY_SUCCESS:
return ''. t('OK') .'';
case GALLERY_SEVERITY_ERROR:
return ''. t('Error') .'';
case GALLERY_SEVERITY_WARNING:
return ''. t('Warning') .'';
case GALLERY_SEVERITY_ADVISE:
return ''. t('Advisory') .'';
case GALLERY_SEVERITY_UNKNOWN:
return ''. t('Unknown') .'';
default:
}
}
/**
* Theme function : theme_gallery_plugin_status_message().
*/
function theme_gallery_plugin_status_message($status, $invert = FALSE) {
if ($invert) {
$enabled_class = 'admin-disabled';
$disabled_class = 'admin-enabled';
}
else {
$enabled_class = 'admin-enabled';
$disabled_class = 'admin-disabled';
}
$unknown_class = 'admin-disabled';
switch ($status) {
case GALLERY_PLUGIN_ENABLED:
return ''. t('activated') .'';
case GALLERY_PLUGIN_DISABLED:
return ''. t('disabled') .'';
case GALLERY_PLUGIN_NOT_ACTIVE:
return ''. t('deactivated') .'';
case GALLERY_PLUGIN_NOT_INSTALLED:
return ''. t('not installed') .'';
case GALLERY_PLUGIN_MISSING:
return ''. t('missing') .'';
case GALLERY_PLUGIN_STATUS_UNKNOWN:
default:
return ''. t('unknown') .'';
}
}
/**
* Theme function : theme_gallery_severity_status_message().
*/
function theme_gallery_severity_status_message($severity, $status, $full_msg = FALSE, $invert = FALSE) {
// In some cases (e.g. unwanted plugins) it makes sense to return the full 2 part message
// even on a success, but in most cases a simple "OK" is sufficient.
if ($full_msg) {
return theme('gallery_severity_message', $severity) .' ('. theme('gallery_plugin_status_message', $module['status'], $invert) .')';
}
switch ($severity) {
case GALLERY_SEVERITY_SUCCESS:
return theme('gallery_severity_message', $severity);
default:
return theme('gallery_severity_message', $severity) .' ('. theme('gallery_plugin_status_message', $module['status'], $invert) .')';
}
}