diff --git a/colorbox.admin.inc b/colorbox.admin.inc index 8a272b511a424ec819f6903216ed730c5aa542a2..d1ded3da49ad44fc1e21143b380ed942bc1219d1 100644 --- a/colorbox.admin.inc +++ b/colorbox.admin.inc @@ -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; +} diff --git a/colorbox.install b/colorbox.install index 43e40309fe0ef09446ffc813f07755c8d34ca9b5..c975c7f7d98fcd188b597cfb3c01b72205bfe27f 100644 --- a/colorbox.install +++ b/colorbox.install @@ -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; +} diff --git a/colorbox.module b/colorbox.module index c23db24c6b8fb1174b617b33c2c1bef07c1ce26a..7fa57ff2a081a022fb02ae54dcd4eb2a5c2cc369 100644 --- a/colorbox.module +++ b/colorbox.module @@ -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; } } diff --git a/colorbox.pages.inc b/colorbox.pages.inc index 0d70c3cc214fddd302e85a4d08850490165fa8cf..1e0dc9ee2cff8c00f644b540df1a9adcbc5bc5c9 100644 --- a/colorbox.pages.inc +++ b/colorbox.pages.inc @@ -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'); } /** diff --git a/js/colorbox_login.js b/js/colorbox_login.js index b8fe650fd83f759a01fce731baaab36ee0aca24f..c5e153c5c1db7946e8b4c421284b2988c5bbdc3f 100644 --- a/js/colorbox_login.js +++ b/js/colorbox_login.js @@ -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,