'),
),
'#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'] = array('_gallery_g2image_settings_validate');
return system_settings_form($form);
}
/**
* Function _gallery_g2image_settings_validate().
* (saves the G2Image config file)
*/
function _gallery_g2image_settings_validate($form, &$form_state) {
switch ($form_state['values']['gallery_g2image_mode']) {
case 'tinymce':
$mode = t('TinyMCE');
if (module_exists('tinymce')) {
$path = drupal_get_path('module', 'tinymce');
}
else if (module_exists('wysiwyg')) {
$path = drupal_get_path('module', 'wysiwyg');
}
$path .= '/tinymce/jscripts/tiny_mce/plugins/g2image';
break;
case 'standalone':
$mode = t('Standalone');
$path = drupal_get_path('module', 'gallery_g2image');
$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_state['values']['gallery_g2image_custom_url'] = check_url($form_state['values']['gallery_g2image_custom_url']);
$g2ic_display_filenames = ($form_state['values']['gallery_g2image_display_filenames'] == 'filenames') ? 'TRUE' : 'FALSE';
$g2ic_custom_class = array();
foreach ($form_state['values']['gallery_g2image_custom_class'] as $key => $value) {
$g2ic_custom_class[$key] = ($value) ? $value : '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_g2image_path().
*/
function _gallery_g2image_path($path = NULL) {
if (!isset($path)) {
// Standalone G2Image folder
$path = drupal_get_path('module', 'gallery_g2image') .'/g2image';
if (!file_exists($path .'/config.php') && !file_check_directory($path)) {
$path = NULL;
// TinyMCE folder for G2Image plugin
if (module_exists('tinymce')) {
$path = drupal_get_path('module', 'tinymce');
$path .= '/tinymce/jscripts/tiny_mce/plugins/g2image';
if (!file_exists($path .'/config.php') && !file_check_directory($path)) {
$path = NULL;
}
}
else if (module_exists('wysiwyg')) {
// WYSIWYG folder for G2Image plugin
$path = drupal_get_path('module', 'wysiwyg');
$path .= '/tinymce/jscripts/tiny_mce/plugins/g2image';
if (!file_exists($path .'/config.php') && !file_check_directory($path)) {
$path = NULL;
}
}
}
}
// Store location of G2Image
variable_set('gallery_g2image_path', isset($path) ? $path : FALSE);
return $path;
}