function securepages_form_alter in Secure Pages 6.2
Same name and namespace in other branches
- 5 securepages.module \securepages_form_alter()
- 6 securepages.module \securepages_form_alter()
- 7 securepages.module \securepages_form_alter()
Implements hook_form_alter().
File
- ./
securepages.module, line 71 - Provide method of creating allowing certain pages to only viewable from https pages
Code
function securepages_form_alter(&$form, &$form_state, $form_id) {
$is_https = securepages_is_secure();
global $user;
if (!variable_get('securepages_enable', 0)) {
return;
}
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()));
$url = @parse_url($url);
$path = drupal_get_normal_path($url['path']);
$page_match = securepages_match($path);
$role_match = securepages_roles($user);
if ($role_match) {
if (!$is_https) {
$form['#action'] = url($path, array(
'absolute' => TRUE,
'base_url' => securepages_baseurl(TRUE),
));
}
return;
}
if ($page_match && !$is_https) {
$form['#action'] = url($path, array(
'absolute' => TRUE,
'base_url' => securepages_baseurl(TRUE),
));
}
elseif ($page_match === 0 && $is_https && variable_get('securepages_switch', FALSE)) {
$form['#action'] = url($path, array(
'absolute' => TRUE,
'base_url' => securepages_baseurl(FALSE),
));
}
}
// If the user/login path matches, also secure the login block.
if (securepages_match('user/login') && $form_id == 'user_login_block' && !$is_https) {
$form['#action'] = url($path, array(
'absolute' => TRUE,
'base_url' => securepages_baseurl(TRUE),
));
}
}