summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFredrik Jonsson2011-03-23 06:58:50 (GMT)
committer Fredrik Jonsson2011-03-23 06:58:50 (GMT)
commit8ca4da91d6b612d1598a6be3817b6a7f61cc6037 (patch)
tree20ef7232c68a4c4f40f449523929decffcfbfde9
parent113dba1dd455db7b08f7a2a1197dcf36943a49c8 (diff)
Improved the Colorbox user login feature.
-rw-r--r--colorbox.admin.inc25
-rw-r--r--colorbox.install30
-rw-r--r--colorbox.module43
-rw-r--r--colorbox.pages.inc8
-rw-r--r--js/colorbox_login.js12
5 files changed, 81 insertions, 37 deletions
diff --git a/colorbox.admin.inc b/colorbox.admin.inc
index 8a272b5..d1ded3d 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 43e4030..c975c7f 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 c23db24..7fa57ff 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 0d70c3c..1e0dc9e 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 b8fe650..c5e153c 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,