Avoid error in multilanguages environments
This commit is contained in:
parent
80752683a8
commit
d9e5c06131
1 changed files with 12 additions and 8 deletions
|
@ -70,7 +70,7 @@ function securepages_menu() {
|
|||
*/
|
||||
function securepages_form_alter(&$form, &$form_state, $form_id) {
|
||||
$is_https = securepages_is_secure();
|
||||
global $user;
|
||||
global $user, $language;
|
||||
|
||||
if (!variable_get('securepages_enable', 0)) {
|
||||
return;
|
||||
|
@ -79,6 +79,13 @@ function securepages_form_alter(&$form, &$form_state, $form_id) {
|
|||
if (isset($form['#action']) && securepages_can_alter_url($form['#action'])) {
|
||||
// Remove the base_path, and extract the path component.
|
||||
$url = substr($form['#action'], strlen(base_path()));
|
||||
|
||||
// Filter out any language prefixes as it will be automatically added to
|
||||
// the URL again (https://www.drupal.org/node/1145292#comment-8154241)..
|
||||
if (!empty($language->language) && preg_match('/^' . $language->language . '/', $url) >= 0) {
|
||||
$url = preg_replace('/^' . $language->language . '\//', '', $url);
|
||||
}
|
||||
|
||||
$url = @parse_url($url);
|
||||
$path = drupal_get_normal_path($url['path']);
|
||||
|
||||
|
@ -97,6 +104,9 @@ function securepages_form_alter(&$form, &$form_state, $form_id) {
|
|||
elseif ($page_match === 0 && $is_https && variable_get('securepages_switch', FALSE)) {
|
||||
$form['#action'] = url($path, array('absolute' => TRUE, 'base_url' => securepages_baseurl(FALSE)));
|
||||
}
|
||||
elseif ($form_id == 'user_login') {
|
||||
$form['#action'] = $path; // Workaround for user login form.
|
||||
}
|
||||
}
|
||||
|
||||
// If the user/login path matches, also secure the login block.
|
||||
|
@ -309,12 +319,10 @@ function _securepages_unicode_caseflip($matches) {
|
|||
* URL to check.
|
||||
*/
|
||||
function securepages_can_alter_url($url) {
|
||||
global $base_path, $base_url;
|
||||
|
||||
$url = @parse_url($url);
|
||||
|
||||
// If there is no scheme then it is a relative url and can be altered
|
||||
if (!isset($url['scheme']) && $base_path == '/') {
|
||||
if (!isset($url['scheme'])) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -323,9 +331,5 @@ function securepages_can_alter_url($url) {
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (strlen($base_path) > 1 && substr($base_url, -1) != substr($url['path'], 1, strlen($base_path))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Reference in a new issue