View source
<?php
function fancy_login_menu() {
$menu['admin/settings/fancy_login'] = array(
'title' => 'Fancy Login',
'description' => 'Settings for Fancy Login Page',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'fancy_login_settings',
),
'access arguments' => array(
'Administer fancy login',
),
'file' => 'includes/fancy_login.pages.inc',
);
$menu['fancy_login/ajax/%'] = array(
'title' => '',
'page callback' => 'fancy_login_ajax_callback',
'page arguments' => array(
2,
),
'access callback' => 'user_is_anonymous',
'file' => 'includes/fancy_login.pages.inc',
'type' => MENU_CALLBACK,
);
$menu['fancy_login/ahah/%'] = array(
'title' => 'Fancy Login #ahah callback',
'page callback' => 'fancy_login_ahah',
'page arguments' => array(
2,
),
'access callback' => TRUE,
'file' => 'includes/fancy_login.pages.inc',
'type' => MENU_CALLBACK,
);
return $menu;
}
function fancy_login_perm() {
return array(
'Administer fancy login',
);
}
function fancy_login_forms($form_id, $args) {
$forms = array();
if ($form_id == 'fancy_login_user_login_block') {
$forms['fancy_login_user_login_block'] = array(
'callback' => 'user_login_block',
);
}
elseif ($form_id == 'fancy_login_user_pass') {
$forms['fancy_login_user_pass'] = array(
'callback' => 'user_pass',
);
}
elseif ($form_id == 'fancy_login_user_register') {
$forms['fancy_login_user_register'] = array(
'callback' => 'user_register',
);
}
return $forms;
}
function fancy_login_footer() {
if (user_is_anonymous()) {
return theme('fancy_login_modal', drupal_get_form('fancy_login_user_login_block'));
}
}
function fancy_login_form_alter(&$form, &$form_state, $form_id) {
global $base_url;
if ($form_id == 'fancy_login_user_login_block') {
foreach (module_implements('form_user_login_block_alter') as $module) {
$function = $module . '_form_user_login_block_alter';
$function($form, $form_state);
}
$id = 'user_login_block';
foreach (module_implements('form_alter') as $module) {
$function = $module . '_form_alter';
$function($form, $form_state, $id);
}
$icon_position = variable_get('fancy_login_icon_position', 0);
if ($icon_position && strpos($base_url, 'https:') !== 0) {
$icon = theme('ssl_icon', array(
'base_url' => $base_url,
));
$form['ssl_logo'] = array(
'#value' => $icon,
);
if ($icon_position == 1) {
$form['ssl_logo']['#weight'] = -100;
$form['#attributes'] = array(
'class' => 'ssl_icon_above',
);
}
elseif ($icon_position == 2) {
$form['ssl_logo']['#weight'] = 100;
$form['#attributes'] = array(
'class' => 'ssl_icon_below',
);
}
}
$form['current_path'] = array(
'#type' => 'value',
'#value' => drupal_get_path_alias($_GET['q']),
);
array_unshift($form['#validate'], 'fancy_login_insert_current_path');
if (!isset($form['#prefix'])) {
$form['#prefix'] = '';
}
$form['#prefix'] = '<div id="fancy_login_user_login_block_wrapper">';
if (!isset($form['#suffix'])) {
$form['#suffix'] = '';
}
$form['#suffix'] = '</div>';
if (variable_get('fancy_login_https', 0) && strpos($base_url, 'https:') !== 0) {
if (strpos($form['#action'], 'https') !== 0) {
if (strpos($form['#action'], 'http') === 0) {
$form['#action'] = preg_replace('/^http:/', 'https:', $form['#action']);
}
elseif (strpos($form['#action'], '//') === 0) {
$form['#action'] = 'https:' . $form['#action'];
}
else {
$form['#action'] = preg_replace('/^http:/', 'https:', $base_url) . $form['#action'];
}
}
}
else {
$form['submit']['#ahah'] = array(
'wrapper' => 'fancy_login_user_login_block_wrapper',
'path' => 'fancy_login/ahah/fancy_login_user_login_block_ahah_callback',
);
$form['submit_' . time()] = $form['submit'];
$form['submit']['#access'] = FALSE;
}
}
elseif ($form_id == 'fancy_login_user_pass') {
module_load_include('inc', 'user', 'user.pages');
if (!isset($form['#validate'])) {
$form['#validate'][] = 'user_pass_validate';
}
if (!isset($form['#submit'])) {
$form['#submit'][] = 'user_pass_submit';
}
foreach (module_implements('form_user_pass_alter') as $module) {
$function = $module . '_form_user_pass_alter';
$function($form, $form_state);
}
$id = 'user_pass';
foreach (module_implements('form_alter') as $module) {
$function = $module . '_form_alter';
$function($form, $form_state, $id);
}
if (!isset($form['#prefix'])) {
$form['#prefix'] = '';
}
$form['#prefix'] = '<div id="fancy_login_user_pass_block_wrapper">';
if (!isset($form['#suffix'])) {
$form['#suffix'] = '';
}
$form['#suffix'] = '</div>';
$form['current_path'] = array(
'#type' => 'value',
'#value' => drupal_get_path_alias($_GET['q']),
);
array_unshift($form['#validate'], 'fancy_login_insert_current_path');
$items = array();
$items[] = l(t('Sign in'), 'user/login', array(
'attributes' => array(
'title' => t('Log in to !site_name.', array(
'!site_name' => variable_get('site_name', t('this site')),
)),
),
));
if (variable_get('user_register', 1)) {
$items[] = l(t('Create new account'), 'user/register', array(
'attributes' => array(
'title' => t('Create a new user account.'),
),
));
}
$form['links'] = array(
'#value' => theme('item_list', $items),
);
if (variable_get('fancy_login_https', 0) && strpos($base_url, 'https:') !== 0) {
if (strpos($form['#action'], 'https') !== 0) {
if (strpos($form['#action'], 'http') === 0) {
$form['#action'] = preg_replace('/^http:/', 'https:', $form['#action']);
}
elseif (strpos($form['#action'], '//') === 0) {
$form['#action'] = 'https:' . $form['#action'];
}
else {
$form['#action'] = preg_replace('/^http:/', 'https:', $base_url) . $form['#action'];
}
}
}
else {
$form['submit']['#ahah'] = array(
'wrapper' => 'fancy_login_user_pass_block_wrapper',
'path' => 'fancy_login/ahah/fancy_login_user_pass_ahah_callback',
);
$form['submit_' . time()] = $form['submit'];
$form['submit']['#access'] = FALSE;
}
}
elseif ($form_id == 'fancy_login_user_register') {
if (!isset($form['#validate'])) {
$form['#validate'][] = 'user_register_validate';
}
if (!isset($form['#submit'])) {
$form['#submit'][] = 'user_register_submit';
}
foreach (module_implements('form_user_register_alter') as $module) {
$function = $module . '_form_user_register_alter';
$function($form, $form_state);
}
$id = 'user_register';
foreach (module_implements('form_alter') as $module) {
$function = $module . '_form_alter';
$function($form, $form_state, $id);
}
if (!isset($form['#prefix'])) {
$form['#prefix'] = '';
}
$form['#prefix'] = '<div id="fancy_login_user_register_block_wrapper">';
if (!isset($form['#suffix'])) {
$form['#suffix'] = '';
}
$form['#suffix'] = '</div>';
$form['current_path'] = array(
'#type' => 'value',
'#value' => drupal_get_path_alias($_GET['q']),
);
array_unshift($form['#validate'], 'fancy_login_insert_current_path');
$items = array();
$items[] = l(t('Sign in'), 'user/login', array(
'attributes' => array(
'title' => t('Log in to !site_name.', array(
'!site_name' => variable_get('site_name', t('this site')),
)),
),
));
$items[] = l(t('Request new password'), 'user/password', array(
'attributes' => array(
'title' => t('Request new password via e-mail.'),
),
));
$form['links'] = array(
'#value' => theme('item_list', $items),
);
if (variable_get('fancy_login_https', 0) && strpos($base_url, 'https:') !== 0) {
if (strpos($form['#action'], 'https') !== 0) {
if (strpos($form['#action'], 'http') === 0) {
$form['#action'] = preg_replace('/^http:/', 'https:', $form['#action']);
}
elseif (strpos($form['#action'], '//') === 0) {
$form['#action'] = 'https:' . $form['#action'];
}
else {
$form['#action'] = preg_replace('/^http:/', 'https:', $base_url) . $form['#action'];
}
}
}
else {
$form['submit']['#ahah'] = array(
'wrapper' => 'fancy_login_user_register_block_wrapper',
'path' => 'fancy_login/ahah/fancy_login_user_register_ahah_callback',
);
$form['submit_' . time()] = $form['submit'];
$form['submit']['#access'] = FALSE;
}
}
}
function fancy_login_insert_current_path($form, &$form_state) {
$_GET['q'] = $form_state['values']['current_path'];
}
function fancy_login_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == "list") {
$block = array();
$block[0]['info'] = t('Fancy Login Link');
return $block;
}
elseif ($op == 'view') {
if (!$delta && user_is_anonymous()) {
$block['subject'] = t('Login');
$block['content'] = l(t('Login'), 'user/login');
return $block;
}
}
}
function fancy_login_theme($existing, $type, $theme, $path) {
return array(
'ssl_icon' => array(
'arguments' => array(
'base_url' => NULL,
),
'path' => $path . '/templates',
'template' => 'ssl-icon',
),
'fancy_login_modal' => array(
'arguments' => array(
'form' => NULL,
),
),
);
}
function theme_fancy_login_modal($form) {
$output = '<div id="fancy_login_dim_screen"></div>';
$output .= '<div id="fancy_login_login_box">';
$output .= '<div id="fancy_login_form_contents">';
$output .= '<a href="#" id="fancy_login_close_button">X</a>';
$output .= $form;
$output .= '</div>';
$output .= '</div>';
return $output;
}
function fancy_login_init() {
if (user_is_anonymous()) {
$path = drupal_get_path('module', 'fancy_login');
$login_path = drupal_get_path_alias('user/login');
$fl_settings = array(
'screenFadeColor' => variable_get('screen_fade_color', 'white'),
'screenFadeZIndex' => variable_get('screen_fade_z_index', '10'),
'loginBoxBackgroundColor' => variable_get('login_box_background_color', 'white'),
'loginBoxTextColor' => variable_get('login_box_text_color', 'black'),
'loginBoxBorderColor' => variable_get('login_box_border_color', 'black'),
'loginBoxBorderWidth' => variable_get('login_box_border_width', '3px'),
'loginBoxBorderStyle' => variable_get('login_box_border_style', 'solid'),
'loginPath' => $login_path,
'dimFadeSpeed' => (int) variable_get('fancy_login_dim_fade_speed', 500),
'boxFadeSpeed' => (int) variable_get('fancy_login_box_fade_speed', 1000),
'hideObjects' => variable_get('fancy_login_hide_objects', 0),
'disableRegistration' => variable_get('fancy_login_disable_registration', 0),
);
drupal_add_js(array(
'fancyLogin' => $fl_settings,
), 'setting');
drupal_add_js($path . '/js/fancy_login.js');
drupal_add_css($path . '/css/fancy_login.css');
}
}