diff options
Diffstat (limited to 'modules/profile/profile.module')
-rw-r--r-- | modules/profile/profile.module | 99 |
1 files changed, 65 insertions, 34 deletions
diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 9663342d3..d3b2c6201 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -3,31 +3,47 @@ // TODO: add a 'date' field so we can migrate the birthday information. +/** + * Implementation of hook_help(). + */ function profile_help($section) { switch ($section) { - case 'admin/system/modules#description': - $output = t("Support for configurable user profiles."); - break; + case 'admin/modules#description': + return t('Support for configurable user profiles.'); } - return $output; - - } /** - * Implementation of hook_link(). + * Implementation of hook_menu(). */ -function profile_link($type) { - if ($type == 'system') { - menu('profile', t('browse'), 'profile_browse', 0, MENU_HIDE); - - menu('admin/system/modules/profile', t('profile'), user_access('administer users') ? 'profile_admin_overview' : MENU_DENIED); - menu('admin/system/modules/profile/add', NULL, user_access('administer users') ? 'profile_admin_add' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); - menu('admin/system/modules/profile/edit', NULL, user_access('administer users') ? 'profile_admin_edit' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); - menu('admin/system/modules/profile/delete', NULL, user_access('administer users') ? 'profile_admin_delete' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); - } +function profile_menu() { + $items = array(); + $items[] = array('path' => 'profile', 'title' => t('browse'), + 'callback' => 'profile_browse', + 'access' => TRUE, + 'type' => MENU_SUGGESTED_ITEM); + $items[] = array('path' => 'admin/user/configure/profile', 'title' => t('profiles'), + 'callback' => 'profile_admin_overview', + 'access' => user_access('administer users'), + 'type' => MENU_LOCAL_SUBTASK); + $items[] = array('path' => 'admin/user/configure/profile/add', 'title' => t('add field'), + 'callback' => 'profile_browse', + 'access' => user_access('administer users'), + 'type' => MENU_CALLBACK); + $items[] = array('path' => 'admin/user/configure/profile/edit', 'title' => t('edit field'), + 'callback' => 'profile_browse', + 'access' => user_access('administer users'), + 'type' => MENU_CALLBACK); + $items[] = array('path' => 'admin/user/configure/profile/delete', 'title' => t('delete field'), + 'callback' => 'profile_browse', + 'access' => user_access('administer users'), + 'type' => MENU_CALLBACK); + return $items; } +/** + * Menu callback; display a list of user information. + */ function profile_browse() { $name = strip_tags(arg(1)); @@ -38,7 +54,7 @@ function profile_browse() { if ($field->fid) { // Compile a list of fields to show $fields = array(); - $result = db_query("SELECT name, title, type FROM {profile_fields} WHERE fid != %d AND overview = 1", $field->fid); + $result = db_query('SELECT name, title, type FROM {profile_fields} WHERE fid != %d AND overview = 1', $field->fid); while ($record = db_fetch_object($result)) { $fields[] = $record; } @@ -71,7 +87,7 @@ function profile_browse() { else { $title = $field->page; } - $output .= "</div>"; + $output .= '</div>'; print theme('page', $output, $title); } @@ -111,7 +127,7 @@ function profile_view_field($user, $field) { case 'checkbox': return l($field->title, "profile/$field->name"); case 'url': - return "<a href=\"". check_url(strip_tags($value)) ."\">". strip_tags($value) ."</a>"; case 'list': + return '<a href="'. check_url(strip_tags($value)) .'">'. strip_tags($value) .'</a>'; case 'list': $values = split("[\n\r]", $value); $fields = array(); foreach ($values as $value) { @@ -157,7 +173,7 @@ function profile_edit_profile($edit, $user) { $fields[$field->category] .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, $field->explanation, NULL, $field->required); break; case 'list': - $fields[$field->category] .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, $field->explanation ." ". t('Put each entry on a separate line. No HTML allowed.'), NULL, $field->required); + $fields[$field->category] .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, $field->explanation .' '. t('Put each entry on a separate line. No HTML allowed.'), NULL, $field->required); break; case 'checkbox': $fields[$field->category] .= form_checkbox($field->title, $field->name, 1, $edit[$field->name], $field->explanation, NULL, $field->required); @@ -185,17 +201,20 @@ function profile_validate_profile($edit) { while ($field = db_fetch_object($result)) { if ($edit[$field->name]) { if ($field->type == 'url' && !valid_url($edit[$field->name], true)) { - form_set_error($field->name, t("The value provided for '%field' is not a valid URL.", array('%field' => $field->title))); + form_set_error($field->name, t('The value provided for "%field" is not a valid URL.', array('%field' => $field->title))); } } else if ($field->required) { - form_set_error($field->name, t("The field '%field' is required.", array('%field' => $field->title))); + form_set_error($field->name, t('The field "%field" is required.', array('%field' => $field->title))); } } return $edit; } +/** + * Implementation of hook_user(). + */ function profile_user($type, &$edit, &$user) { switch ($type) { case 'load': @@ -236,6 +255,9 @@ function profile_validate_form($edit) { } } +/** + * Menu callback; adds a new field to all user profiles. + */ function profile_admin_add($type) { $type = _profile_field_types($type); @@ -267,6 +289,9 @@ function profile_admin_add($type) { print theme('page', _profile_field_form($type, $data), t('Add new %type', array('%type' => $type))); } +/** + * Menu callback; displays the profile field editing form. + */ function profile_admin_edit($fid) { if ($_POST['op']) { @@ -288,6 +313,9 @@ function profile_admin_edit($fid) { print theme('page', _profile_field_form($data['type'], $data), t('Edit %type', array('%type' => $edit['type']))); } +/** + * Menu callback; deletes a field from all user profiles. + */ function profile_admin_delete($fid) { db_query('DELETE FROM {profile_fields} WHERE fid = %d', $fid); drupal_set_message(t('the field has been deleted.')); @@ -296,24 +324,24 @@ function profile_admin_delete($fid) { function _profile_field_form($type, $edit = array()) { - $group = form_textfield(t('Category'), 'category', $edit['category'], 70, 128, t("The category the new field should be part of. Categories are used to group fields logically. An example category is 'Personal information'.")); - $group .= form_textfield(t('Title'), 'title', $edit['title'], 70, 128, t("The title of the new field. The title will be shown to the user. An example title is 'Favorite color'.")); - $group .= form_textfield(t('Form name'), 'name', $edit['name'], 70, 128, t("The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs. -Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is 'profile_favorite_color' or perhaps just 'profile_color'.")); - $group .= form_textarea(t('Explanation'), 'explanation', $edit['explanation'], 70, 3, t("An optional explanation to go with the new field. The explanation will be shown to the user.")); + $group = form_textfield(t('Category'), 'category', $edit['category'], 70, 128, t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".')); + $group .= form_textfield(t('Title'), 'title', $edit['title'], 70, 128, t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".')); + $group .= form_textfield(t('Form name'), 'name', $edit['name'], 70, 128, t('The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs. +Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is "profile_favorite_color" or perhaps just "profile_color".')); + $group .= form_textarea(t('Explanation'), 'explanation', $edit['explanation'], 70, 3, t('An optional explanation to go with the new field. The explanation will be shown to the user.')); if ($type == 'selection') { - $group .= form_textarea(t('Selection options'), 'options', $edit['options'], 70, 8, t("A list of all options. Put each option on a separate line. Example options are 'red', 'blue', 'green', etc.")); + $group .= form_textarea(t('Selection options'), 'options', $edit['options'], 70, 8, t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.')); } - $group .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t("The weights define the order in which the form fields are shown. Lighter fields \"float up\" towards the top of the category.")); + $group .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.')); $group .= form_checkbox(t('Required field.'), 'required', 1, $edit['required']); $output = form_group(t('Field settings'), $group); $group = ''; if ($type == 'selection' || $type == 'list') { - $group .= form_textfield(t('Page title'), 'page', $edit['page'], 70, 128, t("The title of the page showing all users with the specified field. The word <code>%value</code> will be substituted with the corresponding value. An example page title is 'People whose favorite color is %value'.")); + $group .= form_textfield(t('Page title'), 'page', $edit['page'], 70, 128, t('The title of the page showing all users with the specified field. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value".')); } else { - $group .= form_textfield(t('Page title'), 'page', $edit['page'], 70, 128, t("The title of the page showing all users with the specified field.")); + $group .= form_textfield(t('Page title'), 'page', $edit['page'], 70, 128, t('The title of the page showing all users with the specified field.')); } $group .= form_checkbox(t('Should this field be shown on the member listing pages.'), 'overview', 1, $edit['overview']); @@ -323,11 +351,14 @@ Unless you know what you are doing, it is highly recommended that you prefix the return form($output); } +/** + * Menu callback; display a listing of all editable profile fields. + */ function profile_admin_overview() { $result = db_query('SELECT * FROM {profile_fields} ORDER BY category, weight'); while ($field = db_fetch_object($result)) { - $rows[] = array($field->title, $field->name, $field->type, $field->category, l(t('edit'), "admin/system/modules/profile/edit/$field->fid"), l(t('delete'), "admin/system/modules/profile/delete/$field->fid")); + $rows[] = array($field->title, $field->name, $field->type, $field->category, l(t('edit'), "admin/user/configure/profile/edit/$field->fid"), l(t('delete'), "admin/user/configure/profile/delete/$field->fid")); } $header = array(t('title'), t('name'), t('type'), t('category'), array('data' => t('operations'), 'colspan' => '2')); @@ -336,7 +367,7 @@ function profile_admin_overview() { $output .= '<h2>'. t('Create new field') .'</h2>'; $output .= '<ul>'; foreach (_profile_field_types() as $key => $value) { - $output .= "<li>". l(t('Add new %type', array('%type' => $value)), "admin/system/modules/profile/add/$key") ."</li>"; + $output .= '<li>'. l(t('Add new %type', array('%type' => $value)), "admin/user/configure/profile/add/$key") .'</li>'; } $output .= '</ul>'; @@ -347,7 +378,7 @@ function theme_profile_profile($user, $fields = array()) { $output = "<div class=\"profile\">\n"; $output .= theme('user_picture', $user); - $output .= " <div class=\"name\">". format_name($user) ."</div>\n"; + $output .= ' <div class="name">'. format_name($user) ."</div>\n"; foreach ($fields as $field) { if ($value = profile_view_field($user, $field)) { |