Commit fb145d28 authored by profix898's avatar profix898

- task: complete support for i18n/multilingual sites

- task: switch G2 debug mode (buffered)
parent cead0a02
......@@ -267,7 +267,7 @@ function gallery_auth_validate($form, &$form_state) {
if (!$ret) {
// Authenticate the G2 user
if (GalleryUtilities::isCorrectPassword($password, $g2_user->hashedPassword)) {
// Does this user exist in Drupal, then override password
// If this user exists in Drupal then override password
// (so that next time the user can be authenticated directly)
if ($user = user_load(array('name' => $username, 'status' => 1))) {
user_save($user, array('pass' => $password));
......@@ -437,7 +437,6 @@ function gallery_page() {
$parent_title = str_replace('[/i]', '</i>', $parent_title);
// Still does not generate a clean url for /gallery (uses index.php?q=gallery)
$link = gallery_generate_url($parent['urlParams'], FALSE);
// TODO (#154507 + i18n-rewrite): $link = TRUE ? str_replace('?q=gallery', 'gallery', $link) : $link;
$breadcrumb[] = l($parent_title, $link);
}
}
......
......@@ -53,46 +53,39 @@ function gallery_logout() {
* (initialize embedded gallery)
*/
function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
global $user;
global $user, $language;
static $ready = array('half' => FALSE, 'full' => FALSE);
// Initialize only once
if ($ready[$full ? 'full' : 'half']) {
return TRUE;
}
$init_err_msg = t('Unable to initialize embedded Gallery. You need to <a href="@link"> configure your embedded Gallery</a>.',
array('@link' => url('admin/settings/gallery/install')));
$g2_dir = isset($vars['gallery_dir']) ? $vars['gallery_dir'] : variable_get('gallery_dir', './gallery2/');
$g2_uri = isset($vars['gallery_uri']) ? $vars['gallery_uri'] : variable_get('gallery_uri', '/gallery2/');
$embed_uri = isset($vars['gallery_embed_uri']) ? $vars['gallery_embed_uri'] : variable_get('gallery_embed_uri', '?q=gallery');
$gallery_valid = isset($vars) ? (isset($vars['gallery_valid']) ? $vars['gallery_valid'] : TRUE) : variable_get('gallery_valid', 0);
$uid = isset($vars) ? (isset($vars['uid']) ? $vars['uid'] : '') : (($user->uid > 0) ? $user->uid : '');
$init_err_msg = t('Unable to initialize embedded Gallery. You need to <a href="@link"> configure your embedded Gallery</a>.',
array('@link' => url('admin/settings/gallery/install')));
if (!$gallery_valid || !is_readable($g2_dir .'embed.php')) {
if ($report_error) {
gallery_error($init_err_msg);
}
return FALSE;
}
// Language-prefix url rewrite
$language = gallery_get_language($user);
if (module_exists('i18n')) {
// TODO
$embed_uri = preg_replace('/index.php\?q=/', i18n_path('index.php?q=', $language), $embed_uri);
if (function_exists('language_url_rewrite') && $language->prefix) {
$embed_uri = str_replace('index.php?q=', 'index.php?q='. $language->prefix .'/', $embed_uri);
}
// Prepare array with init parameters
$debug = variable_get('gallery_debug', 0) && user_access('administer site configuration');
$params = array('g2Dir' => $g2_dir,
'g2Uri' => $g2_uri,
'embedUri' => $embed_uri,
'loginRedirect' => url('user/login', array('query' => drupal_get_destination(), 'absolute' => TRUE)),
'activeUserId' => $uid,
'activeLanguage' => $language,
'apiVersion' => array(1, 3),
'activeLanguage' => gallery_get_language($language->language),
'apiVersion' => array(1, 4),
'debug' => $debug ? 'buffered' : FALSE,
'eventListeners' => array());
// Add theme to init parameters
......@@ -110,9 +103,17 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
drupal_alter('gallery_init', $params, array('fullInit' => $full, 'ready' => $ready));
$params['fullInit'] = $full;
// Debug output
// Debug output of init parameters
gallery_debug($params, t('Gallery Init'));
// Check for existence of 'embed.php'
if (!$gallery_valid || !is_readable($params['g2Dir'] .'embed.php')) {
if ($report_error) {
gallery_error($init_err_msg);
}
return FALSE;
}
// Initialize Gallery2
include_once($params['g2Dir'] .'embed.php');
$ret = GalleryEmbed::init($params);
......@@ -127,7 +128,7 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
}
return FALSE;
}
// Check if initialization was successful
if (!class_exists('GalleryEmbed') || !class_exists('GalleryCoreApi')) {
if ($report_error) {
......@@ -150,7 +151,7 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
// Register event listeners
if (count($params['eventListeners'])) {
require_once (drupal_get_path('module', 'gallery') .'/G2DrupalHelper.class');
require_once(drupal_get_path('module', 'gallery') .'/G2DrupalHelper.class');
$ret = G2DrupalHelper::registerEventListeners($params['eventListeners']);
if ($ret && $report_error) {
gallery_error(t('Failed to register event listeners.'), $ret);
......@@ -167,9 +168,15 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
* (handleRequest extension with error handling)
*/
function gallery_handle_request() {
global $language;
// Remove the language-prefix for G2
if (!empty($_GET['g2_path']) && module_exists('i18n')) {
i18n_get_lang_prefix($_GET['g2_path'], TRUE);
if (!empty($_GET['g2_path']) && function_exists('language_url_rewrite')) {
$args = explode('/', $_GET['g2_path']);
$prefix = array_shift($args);
if (!empty($language->prefix) && $language->prefix == $prefix) {
$_GET['g2_path'] = implode('/', $args);
}
}
// Handle the request
......@@ -210,13 +217,15 @@ function gallery_handle_request() {
/**
* Function gallery_get_language().
* (get the language for $user)
*/
function gallery_get_language($user) {
function gallery_get_language($lang = '', $user = NULL) {
global $language;
$lang = ($user->uid > 0 && !empty($user->language)) ? $user->language : $language->language;
// Convert certain lang codes, e.g. 'esl/spa es' => 'es' or 'fr-ca' => 'fr'
// Get language from $user object
$lang = (isset($user) && $user->uid > 0 && !empty($user->language)) ? $user->language : $lang;
// Use current global $language, if no other language is specified
$lang = empty($lang) ? $language->language : $lang;
// Convert certain language codes, e.g. 'esl/spa es' => 'es' or 'fr-ca' => 'fr'
$lang = preg_replace(array('/([\w\/]+) ([a-z]{2,3})/i', '/([a-z]{2,3})-(\w+)/i'), array('${2}', '${1}'), $lang);
return $lang;
......@@ -701,6 +710,7 @@ function _gallery_report_error($report = array()) {
*/
function gallery_debug($array, $label = 'Gallery Debug') {
if (variable_get('gallery_debug', 0) && user_access('administer site configuration')) {
// TODO: output to footer in a collapsible fieldset
drupal_set_message('<strong>'. $label .':</strong><br />'. nl2br(htmlspecialchars(print_r($array, TRUE))), 'error');
}
}
......
......@@ -742,6 +742,7 @@ function _gallery_install_step_usersync_skip($form, &$form_state) {
),
));
variable_set('gallery_valid', TRUE);
// Clear cache and rebuild menu
cache_clear_all('gallery', 'cache', TRUE);
menu_rebuild();
......@@ -771,6 +772,7 @@ function _gallery_install_step_usersync_sync($form, &$form_state) {
* Function _gallery_install_locations().
*/
function _gallery_install_locations($orig, $autodetect = TRUE) {
global $language;
include_once(drupal_get_path('module', 'gallery') .'/G2EmbedDiscoveryUtilities.class');
// Result status array
......@@ -800,14 +802,12 @@ function _gallery_install_locations($orig, $autodetect = TRUE) {
// Construct embed_uri value
$embed_uri = isset($orig['gallery_embed_uri']) ? $orig['gallery_embed_uri'] : '';
if ($autodetect || empty($embed_uri)) {
$embed_uri = url($vars['gallery_base']);
// TODO
// i18n/locale rewrites the link to gallery to include a ?q=en or something
/*if (function_exists('language_url_rewrite')) {
$embed_uri = trim(substr($embed_uri, strlen($prefix)), '/');
}*/
$options = array();
// prevent the language prefix from being added to $embed_uri
if (function_exists('language_url_rewrite')) {
$options['language'] = (object)array('language' => $language->language, 'prefix' => '', 'domain' => '');
}
$embed_uri = url($vars['gallery_base'], $options);
// Strip the end /gallery if present and replace with index.php?q=gallery to avoid any
// url rewrite issues. See http://gallery.menalto.com/node/46181
// Note the use of index.php in all cases. Not needed for Apache, but for IIS
......@@ -922,7 +922,7 @@ function _gallery_install_in_drupal_folder($gallery_dir) {
global $base_url;
static $warn = TRUE;
// Dont proceed if G2 was not initialized
// Dont proceed if G2 is not initialized
if (!isset($GLOBALS['gallery'])) {
return;
}
......
......@@ -44,7 +44,7 @@ function gallery_user_insert(&$edit, $user) {
* (update a user with new information)
*/
function gallery_user_update(&$edit, $user) {
$user->language = isset($edit['language']) ? $edit['language'] : gallery_get_language($user);
$user->language = isset($edit['language']) ? $edit['language'] : gallery_get_language('', $user);
$user->pass = !empty($edit['pass']) ? md5($edit['pass']) : $user->pass;
$user->status = isset($edit['status']) ? $edit['status'] : $user->status;
$user->mail = !empty($edit['mail']) ? $edit['mail'] : $user->mail;
......@@ -105,7 +105,7 @@ function gallery_user_modify($user, $action = 'create', $groups = FALSE, $vars =
array('username' => $user->name,
'fullname' => $fullname,
'email' => $user->mail,
'language' => gallery_get_language($user),
'language' => gallery_get_language('', $user),
'hashedpassword' => $pass,
'hashmethod' => 'md5'));
if ($ret) {
......@@ -137,7 +137,7 @@ function gallery_user_modify($user, $action = 'create', $groups = FALSE, $vars =
array('username' => $user->name,
'fullname' => $fullname,
'email' => $user->mail,
'language' => gallery_get_language($user),
'language' => gallery_get_language('', $user),
'hashedpassword' => $pass,
'hashmethod' => 'md5'));
if ($ret) {
......@@ -161,7 +161,7 @@ function gallery_user_modify($user, $action = 'create', $groups = FALSE, $vars =
array('username' => $user->name,
'email' => $user->mail,
'fullname' => $fullname,
'language' => gallery_get_language($user),
'language' => gallery_get_language('', $user),
'hashedpassword' => $pass,
'hashmethod' => 'md5'));
if ($ret) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment