Commit 1b1c4702 authored by Dries's avatar Dries

I refactored quite a bit of the user.module:

$ diffstat user.patch
database/database.mysql |    4
database/database.pgsql |    2
database/updates.inc    |   10 -
modules/block.module    |   20 +-
modules/locale.module   |    9
modules/profile.module  |  108 +++++++----
modules/system.module   |    8
modules/user.module     |  456 +++++++++++++++++++-----------------------------
8 files changed, 289 insertions(+), 328 deletions(-)

More functionality, less code.  Here is a list of the changes:

- Some user API changes:
   + When $type is 'form', you have to return an associative array of groups.  In turn, each group is an array with a 'title', 'data' and 'weight'.
   + A new $type has been added, namely 'categories'.  User settings can be organized in categories.  Categories can be sorted, as can the groups within a category.  (Ordering 'categories' is somewhat broken due to a bug in the menu system.)

- The 'my account > edit' page will use subtabs for each 'category'.  Read: you can break down the account settings into multiple subpages.

- Profile module improvements:
   + Added support for private fields to the profile module!
   + Improved workflow of profile administration pages.
   + Improved the form descriptions.

- Code improvements:
   + Unified user_edit() and user_admin_edit().
   + Unified and cleaned up the validation code.  Fixed some validation glitches too.
parent 83851509
......@@ -151,7 +151,7 @@ CREATE TABLE boxes (
info varchar(128) NOT NULL default '',
type tinyint(2) NOT NULL default '0',
PRIMARY KEY (bid),
UNIQUE KEY subject (title),
UNIQUE KEY title (title),
UNIQUE KEY info (info)
) TYPE=MyISAM;
......@@ -363,7 +363,7 @@ CREATE TABLE profile_fields (
type varchar(128) default NULL,
weight tinyint(1) DEFAULT '0' NOT NULL,
required tinyint(1) DEFAULT '0' NOT NULL,
overview tinyint(1) DEFAULT '0' NOT NULL,
visibility tinyint(1) DEFAULT '0' NOT NULL,
options text,
KEY category (category),
UNIQUE KEY name (name),
......
......@@ -379,7 +379,7 @@ CREATE TABLE profile_fields (
type varchar(128) default NULL,
weight smallint DEFAULT '0' NOT NULL,
required smallint DEFAULT '0' NOT NULL,
overview smallint DEFAULT '0' NOT NULL,
visibility smallint DEFAULT '0' NOT NULL,
options text,
UNIQUE (name),
PRIMARY KEY (fid)
......
......@@ -60,7 +60,8 @@
"2004-05-10" => "update_86",
"2004-05-18" => "update_87",
"2004-06-11" => "update_88",
"2004-06-18" => "update_89"
"2004-06-18" => "update_89",
"2004-06-27" => "update_90"
);
function update_32() {
......@@ -1120,6 +1121,13 @@ function update_89() {
return $ret;
}
function update_90() {
$ret[] = update_sql("ALTER TABLE {profile_fields} CHANGE overview visibility INT(1) UNSIGNED DEFAULT '0' NOT NULL");
$ret[] = update_sql("UPDATE {profile_fields} SET visibility = 2 WHERE visibility = 1");
$ret[] = update_sql("UPDATE {profile_fields} SET visibility = 1 WHERE visibility = 0");
return $ret;
}
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);
......
......@@ -357,20 +357,22 @@ function block_admin() {
* Allow users to decide which custom blocks to display when they visit
* the site.
*/
function block_user($type, $edit, &$user) {
function block_user($type, $edit, &$user, $category = NULL) {
switch ($type) {
case 'form':
$result = db_query('SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta', 1);
while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, 'block', 'list');
if ($data[$block->delta]['info']) {
$form .= form_checkbox($data[$block->delta]['info'], "block][$block->module][$block->delta", 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : $block->status);
if ($category == 'account') {
$result = db_query('SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta', 1);
while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, 'block', 'list');
if ($data[$block->delta]['info']) {
$form .= form_checkbox($data[$block->delta]['info'], "block][$block->module][$block->delta", 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : $block->status);
}
}
}
if (isset($form)) {
return array(t('Block configuration') => $form);
if (isset($form)) {
return array(array('title' => t('Block configuration'), 'data' => $form, 'weight' => 2));
}
}
break;
......
......@@ -357,20 +357,22 @@ function block_admin() {
* Allow users to decide which custom blocks to display when they visit
* the site.
*/
function block_user($type, $edit, &$user) {
function block_user($type, $edit, &$user, $category = NULL) {
switch ($type) {
case 'form':
$result = db_query('SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta', 1);
while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, 'block', 'list');
if ($data[$block->delta]['info']) {
$form .= form_checkbox($data[$block->delta]['info'], "block][$block->module][$block->delta", 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : $block->status);
if ($category == 'account') {
$result = db_query('SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta', 1);
while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, 'block', 'list');
if ($data[$block->delta]['info']) {
$form .= form_checkbox($data[$block->delta]['info'], "block][$block->module][$block->delta", 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : $block->status);
}
}
}
if (isset($form)) {
return array(t('Block configuration') => $form);
if (isset($form)) {
return array(array('title' => t('Block configuration'), 'data' => $form, 'weight' => 2));
}
}
break;
......
......@@ -92,10 +92,13 @@ function locale_menu() {
/**
* Implementation of hook_user(). Allows each user to select an interface language.
*/
function locale_user($type, &$edit, &$user) {
function locale_user($type, &$edit, &$user, $category = NULL) {
global $languages;
if ($type == 'form' && count($languages) > 1) {
return array(t('Locale settings') => form_radios(t('Language'), 'language', $user->language, $languages, t('Selecting a different language will change the language of the site.')));
if ($type == 'form' && count($languages) > 1 && $category == 'account') {
return array(array(
'title' => t('Locale settings'),
'data' => form_radios(t('Language'), 'language', $user->language, $languages, t('Selecting a different language will change the language of the site.')),
'weight' => 2));
}
}
......
......@@ -92,10 +92,13 @@ function locale_menu() {
/**
* Implementation of hook_user(). Allows each user to select an interface language.
*/
function locale_user($type, &$edit, &$user) {
function locale_user($type, &$edit, &$user, $category = NULL) {
global $languages;
if ($type == 'form' && count($languages) > 1) {
return array(t('Locale settings') => form_radios(t('Language'), 'language', $user->language, $languages, t('Selecting a different language will change the language of the site.')));
if ($type == 'form' && count($languages) > 1 && $category == 'account') {
return array(array(
'title' => t('Locale settings'),
'data' => form_radios(t('Language'), 'language', $user->language, $languages, t('Selecting a different language will change the language of the site.')),
'weight' => 2));
}
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -94,14 +94,14 @@ function system_menu() {
*
* Allows users to individually set their theme and time zone.
*/
function system_user($type, $edit, &$user) {
if ($type == 'form') {
function system_user($type, $edit, &$user, $category = NULL) {
if ($type == 'form' && $category == 'account') {
$options = '<option value="">'. t('Default theme') ."</option>\n";
if (count($themes = list_themes()) > 1) {
foreach ($themes as $key => $value) {
$options .= "<option value=\"$key\"". (($edit['theme'] == $key) ? ' selected="selected"' : '') .">$key - $value->description</option>\n";
}
$data[t('Theme settings')] = form_item(t('Theme'), "<select name=\"edit[theme]\">$options</select>", t('Selecting a different theme will change the look and feel of the site.'));
$data[] = array('title' => t('Theme settings'), 'data' => form_item(t('Theme'), "<select name=\"edit[theme]\">$options</select>", t('Selecting a different theme will change the look and feel of the site.')), 'weight' => 2);
}
if (!variable_get('sitewide_timezone', 0)) {
......@@ -111,7 +111,7 @@ function system_user($type, $edit, &$user) {
$zone = $offset * 3600;
$zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone);
}
$data[t('Locale settings')] = form_select(t('Time zone'), 'timezone', $edit['timezone'], $zones, t('Select what time you currently have and your time zone settings will be set appropriately.'));
$data[] = array('title' => t('Locale settings'), 'data' => form_select(t('Time zone'), 'timezone', $edit['timezone'], $zones, t('Select what time you currently have and your time zone settings will be set appropriately.')), 'weight' => 2);
}
return $data;
}
......
......@@ -94,14 +94,14 @@ function system_menu() {
*
* Allows users to individually set their theme and time zone.
*/
function system_user($type, $edit, &$user) {
if ($type == 'form') {
function system_user($type, $edit, &$user, $category = NULL) {
if ($type == 'form' && $category == 'account') {
$options = '<option value="">'. t('Default theme') ."</option>\n";
if (count($themes = list_themes()) > 1) {
foreach ($themes as $key => $value) {
$options .= "<option value=\"$key\"". (($edit['theme'] == $key) ? ' selected="selected"' : '') .">$key - $value->description</option>\n";
}
$data[t('Theme settings')] = form_item(t('Theme'), "<select name=\"edit[theme]\">$options</select>", t('Selecting a different theme will change the look and feel of the site.'));
$data[] = array('title' => t('Theme settings'), 'data' => form_item(t('Theme'), "<select name=\"edit[theme]\">$options</select>", t('Selecting a different theme will change the look and feel of the site.')), 'weight' => 2);
}
if (!variable_get('sitewide_timezone', 0)) {
......@@ -111,7 +111,7 @@ function system_user($type, $edit, &$user) {
$zone = $offset * 3600;
$zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone);
}
$data[t('Locale settings')] = form_select(t('Time zone'), 'timezone', $edit['timezone'], $zones, t('Select what time you currently have and your time zone settings will be set appropriately.'));
$data[] = array('title' => t('Locale settings'), 'data' => form_select(t('Time zone'), 'timezone', $edit['timezone'], $zones, t('Select what time you currently have and your time zone settings will be set appropriately.')), 'weight' => 2);
}
return $data;
}
......
This diff is collapsed.
This diff is collapsed.
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