Commit 8ca4da91 authored by frjo's avatar frjo
Browse files

Improved the Colorbox user login feature.

parent 113dba1d
......@@ -109,12 +109,13 @@ function colorbox_admin_settings() {
'#default_value' => variable_get('colorbox_login', 0),
'#description' => t('Automatically activate Colorbox for links to user/login.'),
);
$form['colorbox_login_settings']['colorbox_login_form'] = array(
'#type' => 'select',
'#title' => t('Login form to use'),
'#options' => array('user_login' => t('User login'), 'user_login_block' => t('User login block')),
'#default_value' => variable_get('colorbox_login_form', 'user_login'),
'#description' => t('Select which form to use for login.'),
$form['colorbox_login_settings']['colorbox_login_links'] = array(
'#type' => 'radios',
'#title' => t('Display links'),
'#options' => array(0 => t('No links'), 1 => t('Show links'), 2 => t('Show links and open them in a Colorbox')),
'#default_value' => variable_get('colorbox_login_links', 0),
'#description' => t('Display the "Create new account" (if allowed) and "Request new password" links below the login form.'),
'#after_build' => array('_colorbox_admin_settings_login_links_load'),
'#states' => array(
'visible' => array(
':input[name="colorbox_login"]' => array('checked' => TRUE),
......@@ -352,3 +353,15 @@ function _colorbox_admin_settings_check_plugin_path($form_element) {
return $form_element;
}
/**
* Enable the Colorbox load feature of the login links are set to open in a Colorbox.
*/
function _colorbox_admin_settings_login_links_load($form_element) {
$login_links = $form_element['#value'];
if ($login_links == 2) {
variable_set('colorbox_load', 1);
}
return $form_element;
}
......@@ -44,27 +44,11 @@ function colorbox_uninstall() {
}
/**
* Provides a upgrade path for Thickbox users.
* Replaces "thickbox" with "colorbox" in
* content_node_field_instance -> display_settings
* Delete the unused colorbox_login_form variabel.
*/
// function colorbox_update_6001() {
// $ret = array();
//
// $result = db_query("SELECT * FROM {content_node_field_instance}");
// while ($type = db_fetch_array($result)) {
// $new_settings = array();
// $display_settings = unserialize($type['display_settings']);
// if (!empty($display_settings)) {
// foreach ($display_settings as $key => $val) {
// $new_settings[$key] = $val;
// if ($key == 'format' && is_array($val)) {
// $new_settings[$key]['exclude'] = 0;
// }
// }
// }
// db_query("UPDATE {content_node_field_instance} SET display_settings='%s' WHERE field_name='%s' AND type_name='%s'", serialize($new_settings), $type['field_name'], $type['type_name']);
// }
//
// return $ret;
// }
function colorbox_update_7001() {
$ret = array();
variable_del('colorbox_login_form');
return $ret;
}
......@@ -349,11 +349,44 @@ function colorbox_get_path() {
* Reformat the login form.
*/
function colorbox_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == variable_get('colorbox_login_form', '') && arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'colorbox') {
$destination = isset($_GET['destination']) ? urlencode($_GET['destination']) : 'user';
$form['#action'] = url('user/login', array('query' => array('destination' => $destination)));
$form['name']['#size'] = 25;
$form['pass']['#size'] = 25;
switch ($form_id) {
case 'user_login':
if (arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'colorbox') {
$form['name']['#size'] = 25;
$form['pass']['#size'] = 25;
// Add links as needed.
if (variable_get('colorbox_login_links', 0)) {
$items = array();
// Add standard links.
if (variable_get('colorbox_login_links', 0) == 1) {
if (variable_get('user_register', 1)) {
$items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.'))));
}
$items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
}
// Add links that opens in a Colorbox.
if (variable_get('colorbox_login_links', 0) == 2) {
if (variable_get('user_register', 1)) {
$items[] = l(t('Create new account'), 'colorbox/form/user_register', array('query' => 'width=300&height=auto', 'attributes' => array('title' => t('Create a new user account.'), 'class' => 'colorbox-load')));
}
$items[] = l(t('Request new password'), 'colorbox/form/user_pass', array('query' => 'width=300&height=150', 'attributes' => array('title' => t('Request new password via e-mail.'), 'class' => 'colorbox-load')));
}
$form['links'] = array('#value' => theme('item_list', $items));
}
}
break;
case 'user_register':
if (arg(0) == 'colorbox' && arg(1) == 'form') {
$form['name']['#size'] = 30;
$form['mail']['#size'] = 30;
}
break;
case 'user_pass':
if (arg(0) == 'colorbox' && arg(1) == 'form') {
$form['name']['#size'] = 30;
}
break;
}
}
......
......@@ -9,8 +9,12 @@
* Menu callback for colorbox_login.
*/
function colorbox_login() {
$form_id = variable_get('colorbox_login_form', '');
colorbox_form_page($form_id);
// Redirect failed logins to the standard user login form.
if (isset($_POST['form_id']) && $_POST['form_id'] == 'user_login') {
return drupal_get_form('user_login');
}
colorbox_form_page('user_login');
}
/**
......
......@@ -6,7 +6,17 @@ Drupal.behaviors.initColorboxLogin = {
return;
}
$("a[href*='/user/login'], a[href*='?q=user/login']", context).once('init-colorbox-login-processed', function () {
this.href = this.href.replace(/user\/login/,"user/login/colorbox");
var path = this.href;
var new_path = path.replace(/user\/login/,'user/login/colorbox')
var addquery = (path.indexOf('?') !=-1) ? '&' : '?';
// If no destination, add one to the current page.
if (path.indexOf('destination') !=-1) {
this.href = new_path;
}
else {
this.href = new_path + addquery + 'destination=' + window.location.pathname.substr(1);
}
}).colorbox({
initialWidth:200,
initialHeight:200,
......
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