'),
),
'#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.'),
);
return $form['g2image'];
}
/**
* Settings for links section
*
*/
function _gallery_links_settings() {
if (variable_get('gallery_valid', 0)) {
$g2Uri = variable_get('gallery_embed_uri', '?q=gallery');
$desc = t('Here are some links to the parts of Gallery2 Site Admin most relevant to gallery.module.');
$desc .= '
';
$desc .= '- Modules : ' . t('To install, activate or configure the required and optional modules relating to gallery.module (Image Block, Image Frame, URL Rewrite, Album Select).') . '
';
$desc .= '- Themes : ' . t('To add/remove blocks in the sidebar.') . '
'; $desc .= '- Embedded URL Rewrite settings : ' . t('To configure the correct .htaccess path and define the rewrite rules.') . '
';
$desc .= '- Cookie Settings : '. t('Only needed for a small number of site configurations, such as the use of different subdomains for Gallery2 and Drupal.') . '
';
$desc .= '
';
} else {
$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.');
}
$form['links'] = array(
'#type' => 'fieldset',
'#title' => t('Links to Gallery2 Site Admin sections most relevant to Drupal (advanced)'),
'#description' => $desc,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
return $form['links'];
}
/**
* Validate the gallery form settings
*/
function gallery_admin_settings_validate($form_id, &$form) {
global $form_values;
include_once(drupal_get_path('module', 'gallery') . '/G2EmbedDiscoveryUtilities.class');
include_once(drupal_get_path('module', 'gallery') . '/G2EmbedTestUtilities.class');
$gallery_valid = 1;
// Store the original values for the variables
$orig['g2Uri'] = $form_values['gallery_uri'];
$orig['g2EmbedPath'] = $form_values['gallery_dir'];
$orig['embedUri'] = $form_values['gallery_embed_uri'];
// Check these variables
list($num_errors, $num_warnings, $new, $results) =
G2EmbedTestUtilities::checkLocations($orig, $form_values['gallery_autodetect_dir']);
if ($num_errors) {
$gallery_valid = 0;
}
// Update the variables with the new validated ones
$form_values['gallery_uri'] = $new['g2Uri'];
$form_values['gallery_dir'] = $new['g2EmbedPath'];
$form_values['gallery_embed_uri'] = $new['embedUri'];
// Perform pre-init tests. If they fail then do not init the gallery as there may be an issue
list($num_errors, $num_warnings, $pre_init_results) = G2EmbedTestUtilities::preInitTests();
$results = array_merge($results, $pre_init_results);
if ($num_errors) {
$gallery_valid = 0;
}
// If the filepaths seem correct then check Gallery2 works and has the correct module configs
// This code is modified from the WPG2 integration code -- Thanks.
if ($gallery_valid) {
// Gallery install is thought valid, so init it.
$title = t('Gallery2 Init:');
$vars['gallery_uri'] = $form_values['gallery_uri'];
$vars['gallery_dir'] = $form_values['gallery_dir'];
$vars['gallery_embed_uri'] = $form_values['gallery_embed_uri'];
$vars['gallery_valid'] = true;
list ($success, $ret) = _gallery_init(true, $vars);
if (!$success) {
// Gallery install was supposed to be valid, but it still failed. Something is wrong.
$results['gallery_init']['title'] = $title;
$results['gallery_init']['error'] = true;
$results['gallery_init']['notice'] = t('Everything seemed OK, but the Gallery could still not be initialised. Perhaps a manually entered value is incorrect.');
$gallery_valid = 0;
} else {
$results['gallery_init']['title'] = $title;
$results['gallery_init']['success'] = true;
list($num_errors, $num_warnings, $post_init_results) = G2EmbedTestUtilities::postInitTests();
if ($num_errors) {
$gallery_valid = 0;
}
// Check for changed embedUri
/* No longer needed as the URL Rewrite config below will do it
if ($form_values['gallery_embed_uri'] != variable_get('gallery_embed_uri', '?q=gallery')) {
$post_init_results['urlrewrite3']['title'] = t('Gallery2 URL Rewrite rules:');
$post_init_results['urlrewrite3']['warning'] = true;
$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).');
}*/
// Update the URL Rewrite Configuration
if ($post_init_results['urlrewrite']['success']) {
list($url_conf_num_errors, $url_conf_num_warnings, $post_init_results['urlrewrite2']) =
_gallery_configure_url_rewrite();
}
$results = array_merge($results, $post_init_results);
// Setup the cookie path - removed for now (see above)
/*
$path = $form_values['gallery_cookie_path'];
$ret = GalleryCoreApi::setPluginParameter('module', 'core', 'cookie.path', $path);
*/
GalleryEmbed::done();
}
}
// Validate the g2image settings
list($num_errors, $num_warnings, $results_g2image) =
_gallery_g2image_settings_form_validate($form_values);
if ($results_g2image) {
$results['gallery_g2image'] = $results_g2image;
}
// Test again for validity
if ($gallery_valid) {
$results['gallery_valid']['title'] = t('Overall Status:');
$results['gallery_valid']['success'] = true;
} else {
$results['gallery_valid']['title'] = t('Overall Status:');
$results['gallery_valid']['error'] = true;
$results['gallery_valid']['notice'] = t('You need to fix the above errors before Gallery2 will be embedded in Drupal.');
}
$message = t('Embedded Gallery2 Status: ').'
';
foreach ($results as $key=>$result) {
$message .= '- ' . t($result['title']) . ' ';
if (isset($result['success']) && $result['success']) {
$message .= '' . t('Success') . '';
} else if (isset($result['warning']) && $result['warning']) {
$message .= '' . t('Warning') . '';
$message .= '
- ' . t($result['notice']) . '
';
} else if (isset($result['error']) && $result['error']) {
$message .= '' . t('Error') . '';
$message .= '- ' . t($result['notice']) . '
';
} else if (isset($result['advise']) && $result['advise']) {
$message .= '' . t('Advisory') . '';
$message .= '- ' . t($result['notice']) . '
';
}
}
$message .= '
';
drupal_set_message($message);
$form_values['gallery_valid'] = $gallery_valid;
// Gallery Image Block Settings validation
// Need to truncate the gallery_block_block variable to the entered number of blocks
if (count($form_values['gallery_block_block']) != $form_values['gallery_block_num_images']) {
$form_values['gallery_block_block'] = array_slice(
$form_values['gallery_block_block'], 0, $form_values['gallery_block_num_images']);
}
}
/**
* Configure URL rewrite (from WPG2 code)
*/
function _gallery_configure_url_rewrite() {
$num_errors = 0;
$num_warnings = 0;
// Find the public path to drupal from the base_url
global $base_url;
$http = 'http' . (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] == 'on' ? 's' : '' : '');
$public_path = str_replace($http . '://' . $_SERVER['HTTP_HOST'],'', $base_url) . '/';
// Find the path to drupal. Will this always work?
$htaccess_path = realpath(".") . '/';
$title = t('Gallery2 URL Rewrite Module Auto-Configuration:');
$results['urlrewrite']['title'] = $title;
list ($ret, $rewriteApi) = GalleryCoreApi::newFactoryInstance('RewriteApi');
if ($ret) {
/* G2 Error handling */
// All other tests were run already
$results['urlrewrite']['error'] = true;
$results['urlrewrite']['notice'] = t(
'Gallery2 Error when trying to access URL Rewrite Module status. @ret',
array('@ret' => $ret->getAsHtml()));
}
list ($ret, $params) = $rewriteApi->fetchEmbedConfig();
// Check if .htaccess exists. If not and path is writable, create it.
// This should only occur for multi-site installs as the main drupal dir always has a .htaccess
if (!file_exists($htaccess_path . '.htaccess')) {
// Better to check for the file, not the dir as if not writable fopen returns a visible warning
if (is_writable($htaccess_path . '.htaccess')) {
$f = fopen($htaccess_path . '.htaccess', 'w');
fclose($f);
} else {
$results['urlrewrite']['error'] = true;
$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));
$num_errors++;
return array($num_errors, $num_warnings, $results['urlrewrite']);
}
}
if (file_exists($htaccess_path . '.htaccess')) {
if (is_writable($htaccess_path . '.htaccess')) {
// Set the G2 rewrite Values
$params['embeddedLocation'] = $public_path;
$params['embeddedHtaccess'] = $htaccess_path;
// Save the G2 rewrite Values
list ($ret, $code, $err) = $rewriteApi->saveEmbedConfig($params);
if ($code != REWRITE_STATUS_OK) {
list ($ret, $errstr) = $err;
$errstr = $code." - ".$errstr;
$results['urlrewrite']['error'] = true;
$results['urlrewrite']['notice'] = t('The Gallery2 URL Rewrite module returned the following error:') . '
' . $errstr . '
';
$num_errors++;
} else {
$results['urlrewrite']['success'] = true;
}
} else {
$results['urlrewrite']['error'] = true;
$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));
$num_errors++;
}
}
return array($num_errors, $num_warnings, $results['urlrewrite']);
}
/**
* Validate the gallery g2image settings and saves the config file if needed.
*/
function _gallery_g2image_settings_form_validate(&$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 array(0, 0, array());
}
$title = 'Gallery2 Image Assist (g2image) Status:';
// 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)) {
$results['gallery_g2image']['title'] = $title;
$results['gallery_g2image']['warning'] = true;
$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' => '
/'.$path));
$num_warnings++;
return array($num_errors, $num_warnings, $results['gallery_g2image']);
}
$cr = "\n";
$g2ic_gallery2_path = $form_values['gallery_dir'];
$g2ic_use_full_path = (substr($g2ic_gallery2_path, 0, 1) == '/') ? '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) {
$results['gallery_g2image']['title'] = $title;
$results['gallery_g2image']['warning'] = true;
$results['gallery_g2image']['notice'] = t('Could not write to g2image config file. Please check the permissions for @filename.', array('@filename' => $filename));
$num_warnings++;
return array($num_errors, $num_warnings, $results['gallery_g2image']);
}
$handle = fopen($filename, "w");
if (fwrite($handle, $content) === FALSE) {
$results['gallery_g2image']['title'] = $title;
$results['gallery_g2image']['warning'] = true;
$results['gallery_g2image']['notice'] = t('Could not write to g2image config file. Please check the permissions for @filename.', array('@filename' => $filename));
$num_warnings++;
return array($num_errors, $num_warnings, $results['gallery_g2image']);
} else {
$results['gallery_g2image']['title'] = $title;
$results['gallery_g2image']['success'] = true;
}
fclose($handle);
return array($num_errors, $num_warnings, $results['gallery_g2image']);
}
?>