Index: modules/profile/profile-block.tpl.php =================================================================== RCS file: modules/profile/profile-block.tpl.php diff -N modules/profile/profile-block.tpl.php --- modules/profile/profile-block.tpl.php 6 Aug 2009 05:05:59 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,42 +0,0 @@ -title: Title of the profile field. - * - $field->value: Value of the profile field. - * - $field->type: Type of the profile field, i.e., checkbox, textfield, - * textarea, selection, list, url or date. - * - * Since $profile is keyed, a direct print of the field is possible. Not - * all accounts may have a value for a profile so do a check first. If a field - * of "last_name" was set for the site, the following can be used. - * - * - *
- * title; ?>:
- * value; ?> - *
- * - * - * @see template_preprocess_profile_block() - */ -?> - - - -

- type != 'checkbox') : ?> - title; ?>
- - value; ?> -

- Index: modules/profile/profile-listing.tpl.php =================================================================== RCS file: modules/profile/profile-listing.tpl.php diff -N modules/profile/profile-listing.tpl.php --- modules/profile/profile-listing.tpl.php 6 Aug 2009 05:05:59 -0000 1.7 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,53 +0,0 @@ -title: Title of the profile field. - * - $field->value: Value of the profile field. - * - $field->type: Type of the profile field, i.e., checkbox, textfield, - * textarea, selection, list, url or date. - * - * Since $profile is keyed, a direct print of the field is possible. Not - * all accounts may have a value for a profile so do a check first. If a field - * of "last_name" was set for the site, the following can be used. - * - * - *
- * title; ?>:
- * value; ?> - *
- * - * - * @see template_preprocess_profile_listing() - */ -?> -
- - -
- -
- - -
- value; ?> -
- - -
Index: modules/profile/profile-wrapper.tpl.php =================================================================== RCS file: modules/profile/profile-wrapper.tpl.php diff -N modules/profile/profile-wrapper.tpl.php --- modules/profile/profile-wrapper.tpl.php 13 Oct 2008 12:31:42 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,25 +0,0 @@ - -
- -
Index: modules/profile/profile.admin.inc =================================================================== RCS file: modules/profile/profile.admin.inc diff -N modules/profile/profile.admin.inc --- modules/profile/profile.admin.inc 3 Nov 2009 05:27:18 -0000 1.34 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,430 +0,0 @@ -category; - - // Save all field information - $form[$field->fid]['name'] = array('#markup' => check_plain($field->name)); - $form[$field->fid]['title'] = array('#markup' => check_plain($field->title)); - $form[$field->fid]['type'] = array('#markup' => $field->type); - $form[$field->fid]['category'] = array('#type' => 'select', '#default_value' => $field->category, '#options' => array()); - $form[$field->fid]['weight'] = array('#type' => 'weight', '#default_value' => $field->weight); - $form[$field->fid]['edit'] = array('#type' => 'link', '#title' => t('edit'), '#href' => "admin/config/people/profile/edit/$field->fid"); - $form[$field->fid]['delete'] = array('#type' => 'link', '#title' => t('delete'), '#href' => "admin/config/people/profile/delete/$field->fid"); - } - - // Add the category combo boxes - $categories = array_unique($categories); - foreach ($form as $fid => $field) { - foreach ($categories as $cat => $category) { - $form[$fid]['category']['#options'][$category] = $category; - } - } - - // Display the submit button only when there's more than one field - if (count($form) > 1) { - $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); - } - else { - // Disable combo boxes when there isn't a submit button - foreach ($form as $fid => $field) { - unset($form[$fid]['weight']); - $form[$fid]['category']['#type'] = 'value'; - } - } - $form['#tree'] = TRUE; - - // @todo: Any reason this isn't done using an element with #theme = 'links'? - $addnewfields = '

' . t('Add new field') . '

'; - $addnewfields .= ''; - $form['addnewfields'] = array('#markup' => $addnewfields); - - return $form; -} - -/** - * Submit handler to update changed profile field weights and categories. - * - * @see profile_admin_overview() - */ -function profile_admin_overview_submit($form, &$form_state) { - foreach (element_children($form_state['values']) as $fid) { - if (is_numeric($fid)) { - $weight = $form_state['values'][$fid]['weight']; - $category = $form_state['values'][$fid]['category']; - if ($weight != $form[$fid]['weight']['#default_value'] || $category != $form[$fid]['category']['#default_value']) { - db_update('profile_field') - ->fields(array( - 'weight' => $weight, - 'category' => $category, - )) - ->condition('fid', $fid) - ->execute(); - } - } - } - - drupal_set_message(t('Profile fields have been updated.')); - cache_clear_all(); - menu_rebuild(); -} - -/** - * Theme the profile field overview into a drag and drop enabled table. - * - * @ingroup themeable - * @see profile_admin_overview() - */ -function theme_profile_admin_overview($variables) { - $form = $variables['form']; - - drupal_add_css(drupal_get_path('module', 'profile') . '/profile.css'); - // Add javascript if there's more than one field. - if (isset($form['submit'])) { - drupal_add_js(drupal_get_path('module', 'profile') . '/profile.js'); - } - - $rows = array(); - $categories = array(); - $category_number = 0; - foreach (element_children($form) as $key) { - // Don't take form control structures. - if (array_key_exists('category', $form[$key])) { - $field = &$form[$key]; - $category = $field['category']['#default_value']; - - if (!isset($categories[$category])) { - // Category classes are given numeric IDs because there's no guarantee - // class names won't contain invalid characters. - $categories[$category] = $category_number; - $category_field['#attributes']['class'] = array('profile-category', 'profile-category-' . $category_number); - $rows[] = array(array('data' => $category, 'colspan' => 7, 'class' => array('category'))); - $rows[] = array('data' => array(array('data' => '' . t('No fields in this category. If this category remains empty when saved, it will be removed.') . '', 'colspan' => 7)), 'class' => array('category-' . $category_number . '-message', 'category-message', 'category-populated')); - - // Make it draggable only if there is more than one field - if (isset($form['submit'])) { - drupal_add_tabledrag('profile-fields', 'order', 'sibling', 'profile-weight', 'profile-weight-' . $category_number); - drupal_add_tabledrag('profile-fields', 'match', 'sibling', 'profile-category', 'profile-category-' . $category_number); - } - $category_number++; - } - - // Add special drag and drop classes that group fields together. - $field['weight']['#attributes']['class'] = array('profile-weight', 'profile-weight-' . $categories[$category]); - $field['category']['#attributes']['class'] = array('profile-category', 'profile-category-' . $categories[$category]); - - // Add the row - $row = array(); - $row[] = drupal_render($field['title']); - $row[] = drupal_render($field['name']); - $row[] = drupal_render($field['type']); - if (isset($form['submit'])) { - $row[] = drupal_render($field['category']); - $row[] = drupal_render($field['weight']); - } - $row[] = drupal_render($field['edit']); - $row[] = drupal_render($field['delete']); - $rows[] = array('data' => $row, 'class' => array('draggable')); - } - } - if (empty($rows)) { - $rows[] = array(array('data' => t('No fields available.'), 'colspan' => 7)); - } - - $header = array(t('Title'), t('Name'), t('Type')); - if (isset($form['submit'])) { - $header[] = t('Category'); - $header[] = t('Weight'); - } - $header[] = array('data' => t('Operations'), 'colspan' => 2); - - $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'profile-fields'))); - $output .= drupal_render_children($form); - - return $output; -} - -/** - * Menu callback: Generate a form to add/edit a user profile field. - * - * @ingroup forms - * @see profile_field_form_validate() - * @see profile_field_form_submit() - */ -function profile_field_form($form, &$form_state, $arg = NULL) { - if (arg(4) == 'edit') { - if (is_numeric($arg)) { - $fid = $arg; - - $edit = db_query('SELECT * FROM {profile_field} WHERE fid = :fid', array('fid' => $fid))->fetchAssoc(); - - if (!$edit) { - drupal_not_found(); - return; - } - drupal_set_title(t('edit %title', array('%title' => $edit['title'])), PASS_THROUGH); - $form['fid'] = array('#type' => 'value', - '#value' => $fid, - ); - $type = $edit['type']; - } - else { - drupal_not_found(); - return; - } - } - else { - $types = _profile_field_types(); - if (!isset($types[$arg])) { - drupal_not_found(); - return; - } - $type = $arg; - drupal_set_title(t('add new %type', array('%type' => $types[$type])), PASS_THROUGH); - $edit = array('name' => 'profile_'); - $form['type'] = array('#type' => 'value', '#value' => $type); - } - $edit += array( - 'category' => '', - 'title' => '', - 'explanation' => '', - 'weight' => 0, - 'page' => '', - 'autocomplete' => '', - 'required' => '', - 'register' => '', - ); - $form['fields'] = array('#type' => 'fieldset', - '#title' => t('Field settings'), - ); - $form['fields']['category'] = array('#type' => 'textfield', - '#title' => t('Category'), - '#default_value' => $edit['category'], - '#autocomplete_path' => 'admin/config/people/profile/autocomplete', - '#description' => t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'), - '#required' => TRUE, - ); - $form['fields']['title'] = array('#type' => 'textfield', - '#title' => t('Title'), - '#default_value' => $edit['title'], - '#description' => t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'), - '#required' => TRUE, - ); - $form['fields']['name'] = array('#type' => 'textfield', - '#title' => t('Form name'), - '#default_value' => $edit['name'], - '#description' => 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 profile_ 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".'), - '#required' => TRUE, - ); - $form['fields']['explanation'] = array('#type' => 'textarea', - '#title' => t('Explanation'), - '#default_value' => $edit['explanation'], - '#description' => t('An optional explanation to go with the new field. The explanation will be shown to the user.'), - ); - if ($type == 'selection') { - $form['fields']['options'] = array('#type' => 'textarea', - '#title' => t('Selection options'), - '#default_value' => isset($edit['options']) ? $edit['options'] : '', - '#description' => t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'), - ); - } - $form['fields']['visibility'] = array('#type' => 'radios', - '#title' => t('Visibility'), - '#default_value' => isset($edit['visibility']) ? $edit['visibility'] : PROFILE_PUBLIC, - '#options' => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')), - ); - if ($type == 'selection' || $type == 'list' || $type == 'textfield') { - $form['fields']['page'] = array('#type' => 'textfield', - '#title' => t('Page title'), - '#default_value' => $edit['page'], - '#description' => t('To enable browsing this field by value, enter a title for the resulting page. The word %value will be substituted with the corresponding value. An example page title is "People whose favorite color is %value" . This is only applicable for a public field.'), - ); - } - elseif ($type == 'checkbox') { - $form['fields']['page'] = array('#type' => 'textfield', - '#title' => t('Page title'), - '#default_value' => $edit['page'], - '#description' => t('To enable browsing this field by value, enter a title for the resulting page. An example page title is "People who are employed" . This is only applicable for a public field.'), - ); - } - $form['fields']['weight'] = array('#type' => 'weight', - '#title' => t('Weight'), - '#default_value' => $edit['weight'], - '#description' => t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'), - ); - $form['fields']['autocomplete'] = array('#type' => 'checkbox', - '#title' => t('Form will auto-complete while user is typing.'), - '#default_value' => $edit['autocomplete'], - '#description' => t('For security, auto-complete will be disabled if the user does not have access to user profiles.'), - ); - $form['fields']['required'] = array('#type' => 'checkbox', - '#title' => t('The user must enter a value.'), - '#default_value' => $edit['required'], - ); - $form['fields']['register'] = array('#type' => 'checkbox', - '#title' => t('Visible in user registration form.'), - '#default_value' => $edit['register'], - ); - $form['submit'] = array('#type' => 'submit', - '#value' => t('Save field'), - ); - return $form; -} - -/** - * Validate profile_field_form submissions. - */ -function profile_field_form_validate($form, &$form_state) { - // Validate the 'field name': - if (preg_match('/[^a-zA-Z0-9_-]/', $form_state['values']['name'])) { - form_set_error('name', t('The specified form name contains one or more illegal characters. Spaces or any other special characters except dash (-) and underscore (_) are not allowed.')); - } - - $users_table = drupal_get_schema('users'); - if (!empty($users_table['fields'][$form_state['values']['name']])) { - form_set_error('name', t('The specified form name is reserved for use by Drupal.')); - } - // Validate the category: - if (!$form_state['values']['category']) { - form_set_error('category', t('You must enter a category.')); - } - if (strtolower($form_state['values']['category']) == 'account') { - form_set_error('category', t('The specified category name is reserved for use by Drupal.')); - } - $query = db_select('profile_field'); - $query->fields('profile_field', array('fid')); - - if (isset($form_state['values']['fid'])) { - $query->condition('fid', $form_state['values']['fid']); - } - $query_name = clone $query; - - $title = $query - ->condition('title', $form_state['values']['title']) - ->condition('category', $form_state['values']['category']) - ->execute() - ->fetchField(); - if ($title) { - form_set_error('title', t('The specified title is already in use.')); - } - $name = $query_name - ->condition('name', $form_state['values']['name']) - ->execute() - ->fetchField(); - if ($name) { - form_set_error('name', t('The specified name is already in use.')); - } - if ($form_state['values']['visibility'] == PROFILE_HIDDEN) { - if ($form_state['values']['required']) { - form_set_error('required', t('A hidden field cannot be required.')); - } - if ($form_state['values']['register']) { - form_set_error('register', t('A hidden field cannot be set to visible on the user registration form.')); - } - } -} - -/** - * Process profile_field_form submissions. - */ -function profile_field_form_submit($form, &$form_state) { - if (!isset($form_state['values']['options'])) { - $form_state['values']['options'] = ''; - } - if (!isset($form_state['values']['page'])) { - $form_state['values']['page'] = ''; - } - if (!isset($form_state['values']['fid'])) { - // Remove all elements that are not profile_field columns. - $values = array_intersect_key($form_state['values'], array_flip(array('type', 'category', 'title', 'name', 'explanation', 'visibility', 'page', 'weight', 'autocomplete', 'required', 'register', 'options'))); - db_insert('profile_field') - ->fields($values) - ->execute(); - drupal_set_message(t('The field has been created.')); - watchdog('profile', 'Profile field %field added under category %category.', array('%field' => $form_state['values']['title'], '%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/config/people/profile')); - } - else { - db_update('profile_field') - ->fields($form_state['values']) - ->condition('fid', $form_state['values']['fid']) - ->exeucte(); - drupal_set_message(t('The field has been updated.')); - } - cache_clear_all(); - menu_rebuild(); - - $form_state['redirect'] = 'admin/config/people/profile'; - return; -} - -/** - * Menu callback; deletes a field from all user profiles. - */ -function profile_field_delete($form, &$form_state, $fid) { - $field = db_query("SELECT title FROM {profile_field} WHERE fid = :fid", array(':fid' => $fid))->fetchObject(); - if (!$field) { - drupal_not_found(); - return; - } - $form['fid'] = array('#type' => 'value', '#value' => $fid); - $form['title'] = array('#type' => 'value', '#value' => $field->title); - - return confirm_form($form, - t('Are you sure you want to delete the field %field?', array('%field' => $field->title)), 'admin/config/people/profile', - t('This action cannot be undone. If users have entered values into this field in their profile, these entries will also be deleted. If you want to keep the user-entered data, instead of deleting the field you may wish to edit this field and change it to a hidden profile field so that it may only be accessed by administrators.', array('@edit-field' => url('admin/config/people/profile/edit/' . $fid))), - t('Delete'), t('Cancel')); -} - -/** - * Process a field delete form submission. - */ -function profile_field_delete_submit($form, &$form_state) { - db_delete('profile_field') - ->condition('fid', $form_state['values']['fid']) - ->execute(); - db_delete('profile_value') - ->condition('fid', $form_state['values']['fid']) - ->execute(); - - cache_clear_all(); - - drupal_set_message(t('The field %field has been deleted.', array('%field' => $form_state['values']['title']))); - watchdog('profile', 'Profile field %field deleted.', array('%field' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/config/people/profile')); - - $form_state['redirect'] = 'admin/config/people/profile'; - return; -} - -/** - * Retrieve a pipe delimited string of autocomplete suggestions for profile categories - */ -function profile_admin_settings_autocomplete($string) { - $matches = array(); - $result = db_query_range("SELECT category FROM {profile_field} WHERE LOWER(category) LIKE LOWER(:category)", 0, 10, array(':category' => $string . '%')); - foreach ($result as $data) { - $matches[$data->category] = check_plain($data->category); - } - drupal_json_output($matches); -} Index: modules/profile/profile.css =================================================================== RCS file: modules/profile/profile.css diff -N modules/profile/profile.css --- modules/profile/profile.css 30 Nov 2007 09:02:51 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,11 +0,0 @@ -/* $Id: profile.css,v 1.3 2007-11-30 09:02:51 goba Exp $ */ - -#profile-fields td.category { - font-weight: bold; -} -#profile-fields tr.category-message { - color: #999; -} -#profile-fields tr.category-populated { - display: none; -} Index: modules/profile/profile.info =================================================================== RCS file: modules/profile/profile.info diff -N modules/profile/profile.info --- modules/profile/profile.info 8 Jun 2009 09:23:53 -0000 1.9 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,11 +0,0 @@ -; $Id: profile.info,v 1.9 2009-06-08 09:23:53 dries Exp $ -name = Profile -description = Supports configurable user profiles. -package = Core -version = VERSION -core = 7.x -files[] = profile.module -files[] = profile.admin.inc -files[] = profile.pages.inc -files[] = profile.install -files[] = profile.test Index: modules/profile/profile.install =================================================================== RCS file: modules/profile/profile.install diff -N modules/profile/profile.install --- modules/profile/profile.install 29 Sep 2009 15:13:56 -0000 1.22 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,156 +0,0 @@ - 'Stores profile field information.', - 'fields' => array( - 'fid' => array( - 'type' => 'serial', - 'not null' => TRUE, - 'description' => 'Primary Key: Unique profile field ID.', - ), - 'title' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'description' => 'Title of the field shown to the end user.', - ), - 'name' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Internal name of the field used in the form HTML and URLs.', - ), - 'explanation' => array( - 'type' => 'text', - 'not null' => FALSE, - 'description' => 'Explanation of the field to end users.', - ), - 'category' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'description' => 'Profile category that the field will be grouped under.', - ), - 'page' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'description' => "Title of page used for browsing by the field's value", - ), - 'type' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => FALSE, - 'description' => 'Type of form field.', - ), - 'weight' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - 'description' => 'Weight of field in relation to other profile fields.', - ), - 'required' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - 'description' => 'Whether the user is required to enter a value. (0 = no, 1 = yes)', - ), - 'register' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - 'description' => 'Whether the field is visible in the user registration form. (1 = yes, 0 = no)', - ), - 'visibility' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - 'description' => 'The level of visibility for the field. (0 = hidden, 1 = private, 2 = public on profile but not member list pages, 3 = public on profile and list pages)', - ), - 'autocomplete' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - 'description' => 'Whether form auto-completion is enabled. (0 = disabled, 1 = enabled)', - ), - 'options' => array( - 'type' => 'text', - 'not null' => FALSE, - 'description' => 'List of options to be used in a list selection field.', - ), - ), - 'indexes' => array( - 'category' => array('category'), - ), - 'unique keys' => array( - 'name' => array('name'), - ), - 'primary key' => array('fid'), - ); - - $schema['profile_value'] = array( - 'description' => 'Stores values for profile fields.', - 'fields' => array( - 'fid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The {profile_field}.fid of the field.', - ), - 'uid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The {users}.uid of the profile user.', - ), - 'value' => array( - 'type' => 'text', - 'not null' => FALSE, - 'description' => 'The value for the field.', - ), - ), - 'primary key' => array('uid', 'fid'), - 'indexes' => array( - 'fid' => array('fid'), - ), - 'foreign keys' => array( - 'fid' => array('profile_field' => 'fid'), - 'uid' => array('users' => 'uid'), - ), - ); - - return $schema; -} - -/** - * Rename {profile_fields} table to {profile_field} and {profile_values} to {profile_value}. - */ -function profile_update_7001() { - db_rename_table('profile_fields', 'profile_field'); - db_rename_table('profile_values', 'profile_value'); -} Index: modules/profile/profile.js =================================================================== RCS file: modules/profile/profile.js diff -N modules/profile/profile.js --- modules/profile/profile.js 27 Apr 2009 20:19:37 -0000 1.7 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,59 +0,0 @@ -// $Id: profile.js,v 1.7 2009-04-27 20:19:37 webchick Exp $ -(function ($) { - -/** - * Add functionality to the profile drag and drop table. - * - * This behavior is dependent on the tableDrag behavior, since it uses the - * objects initialized in that behavior to update the row. It shows and hides - * a warning message when removing the last field from a profile category. - */ -Drupal.behaviors.profileDrag = { - attach: function (context, settings) { - var table = $('#profile-fields'); - var tableDrag = Drupal.tableDrag['profile-fields']; // Get the profile tableDrag object. - - // Add a handler for when a row is swapped, update empty categories. - tableDrag.row.prototype.onSwap = function (swappedRow) { - var rowObject = this; - $('tr.category-message', table).each(function () { - // If the dragged row is in this category, but above the message row, swap it down one space. - if ($(this).prev('tr').get(0) == rowObject.element) { - // Prevent a recursion problem when using the keyboard to move rows up. - if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) { - rowObject.swap('after', this); - } - } - // This category has become empty - if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').size() == 0) { - $(this).removeClass('category-populated').addClass('category-empty'); - } - // This category has become populated. - else if ($(this).is('.category-empty')) { - $(this).removeClass('category-empty').addClass('category-populated'); - } - }); - }; - - // Add a handler so when a row is dropped, update fields dropped into new categories. - tableDrag.onDrop = function () { - dragObject = this; - if ($(dragObject.rowObject.element).prev('tr').is('.category-message')) { - var categoryRow = $(dragObject.rowObject.element).prev('tr').get(0); - var categoryNum = categoryRow.className.replace(/([^ ]+[ ]+)*category-([^ ]+)-message([ ]+[^ ]+)*/, '$2'); - var categoryField = $('select.profile-category', dragObject.rowObject.element); - var weightField = $('select.profile-weight', dragObject.rowObject.element); - var oldcategoryNum = weightField[0].className.replace(/([^ ]+[ ]+)*profile-weight-([^ ]+)([ ]+[^ ]+)*/, '$2'); - - if (!categoryField.is('.profile-category-' + categoryNum)) { - categoryField.removeClass('profile-category-' + oldcategoryNum).addClass('profile-category-' + categoryNum); - weightField.removeClass('profile-weight-' + oldcategoryNum).addClass('profile-weight-' + categoryNum); - - categoryField.val(categoryField[0].options[categoryNum].value); - } - } - }; - } -}; - -})(jQuery); \ No newline at end of file Index: modules/profile/profile.module =================================================================== RCS file: modules/profile/profile.module diff -N modules/profile/profile.module --- modules/profile/profile.module 1 Nov 2009 21:26:44 -0000 1.281 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,624 +0,0 @@ -' . t('The profile module allows custom fields (such as country, full name, or age) to be defined and displayed in the My Account section. This permits users of a site to share more information about themselves, and can help community-based sites organize users around specific information.') . '

'; - $output .= '

' . t('The following types of fields can be added to a user profile:') . '

'; - $output .= ''; - $output .= '

' . t('For more information, see the online handbook entry for Profile module.', array('@profile' => 'http://drupal.org/handbook/modules/profile/')) . '

'; - return $output; - case 'admin/config/people/profile': - return '

' . t("This page displays a list of the existing custom profile fields to be displayed on a user's My Account page. To provide structure, similar or related fields may be placed inside a category. To add a new category (or edit an existing one), edit a profile field and provide a new category name. Remember that your changes will not be saved until you click the Save configuration button at the bottom of the page.") . '

'; - } -} - -/** - * Implement hook_theme(). - */ -function profile_theme() { - return array( - 'profile_block' => array( - 'variables' => array('account' => NULL, 'fields' => array()), - 'template' => 'profile-block', - ), - 'profile_listing' => array( - 'variables' => array('account' => NULL, 'fields' => array()), - 'template' => 'profile-listing', - ), - 'profile_wrapper' => array( - 'variables' => array('content' => NULL), - 'template' => 'profile-wrapper', - ), - 'profile_admin_overview' => array( - 'render element' => 'form', - 'file' => 'profile.admin.inc', - ) - ); -} - -/** - * Implement hook_menu(). - */ -function profile_menu() { - $items['profile'] = array( - 'title' => 'User list', - 'page callback' => 'profile_browse', - 'access arguments' => array('access user profiles'), - 'file' => 'profile.pages.inc', - 'type' => MENU_SUGGESTED_ITEM, - ); - $items['admin/config/people/profile'] = array( - 'title' => 'Profiles', - 'description' => 'Create customizable fields for your users.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('profile_admin_overview'), - 'access arguments' => array('administer users'), - 'file' => 'profile.admin.inc', - ); - $items['admin/config/people/profile/add'] = array( - 'title' => 'Add field', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('profile_field_form'), - 'access arguments' => array('administer users'), - 'file' => 'profile.admin.inc', - 'type' => MENU_CALLBACK, - ); - $items['admin/config/people/profile/autocomplete'] = array( - 'title' => 'Profile category autocomplete', - 'page callback' => 'profile_admin_settings_autocomplete', - 'access arguments' => array('administer users'), - 'file' => 'profile.admin.inc', - 'type' => MENU_CALLBACK, - ); - $items['admin/config/people/profile/edit'] = array( - 'title' => 'Edit field', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('profile_field_form'), - 'access arguments' => array('administer users'), - 'file' => 'profile.admin.inc', - 'type' => MENU_CALLBACK, - ); - $items['admin/config/people/profile/delete'] = array( - 'title' => 'Delete field', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('profile_field_delete'), - 'access arguments' => array('administer users'), - 'file' => 'profile.admin.inc', - 'type' => MENU_CALLBACK, - ); - $items['profile/autocomplete'] = array( - 'title' => 'Profile autocomplete', - 'page callback' => 'profile_autocomplete', - 'access arguments' => array('access user profiles'), - 'file' => 'profile.pages.inc', - 'type' => MENU_CALLBACK, - ); - return $items; -} - -/** - * Implement hook_block_info(). - */ - function profile_block_info() { - $blocks['author-information']['info'] = t('Author information'); - $blocks['author-information']['cache'] = DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_ROLE; - return $blocks; -} - -/** - * Implement hook_block_configure(). - */ -function profile_block_configure($delta = '') { - // Compile a list of fields to show - $fields = array(); - $result = db_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS))); - foreach ($result as $record) { - $fields[$record->name] = check_plain($record->title); - } - $fields['user_profile'] = t('Link to full user profile'); - $form['profile_block_author_fields'] = array( - '#type' => 'checkboxes', - '#title' => t('Profile fields to display'), - '#default_value' => variable_get('profile_block_author_fields', array()), - '#options' => $fields, - '#description' => t('Select which profile fields you wish to display in the block. Only fields designated as public in the profile field configuration are available.', array('@profile-admin' => url('admin/config/people/profile'))), - ); - return $form; -} - -/** - * Implement hook_block_save(). - */ -function profile_block_save($delta = '', $edit = array()) { - variable_set('profile_block_author_fields', $edit['profile_block_author_fields']); -} - -/** - * Implement hook_block_view(). - */ -function profile_block_view($delta = '') { - if (user_access('access user profiles')) { - $output = ''; - if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL)) { - $node = node_load(arg(1)); - $account = user_load(array('uid' => $node->uid)); - - if ($use_fields = variable_get('profile_block_author_fields', array())) { - // Compile a list of fields to show. - $fields = array(); - $result = db_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS))); - foreach ($result as $record) { - // Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions. - if (isset($use_fields[$record->name]) && $use_fields[$record->name]) { - $fields[] = $record; - } - } - } - - if (!empty($fields)) { - $profile = _profile_update_user_fields($fields, $account); - $output .= theme('profile_block', array('account' => $account, 'fields' => $profile)); - } - - if (isset($use_fields['user_profile']) && $use_fields['user_profile']) { - $output .= '
' . l(t('View full user profile'), 'user/' . $account->uid) . '
'; - } - } - - if ($output) { - $block['subject'] = t('About %name', array('%name' => format_username($account))); - $block['content'] = $output; - return $block; - } - } -} - -/** - * Implement hook_user_presave(). - */ -function profile_user_presave(&$edit, $account, $category) { - if ($account->uid) { - profile_save_profile($edit, $account, $category); - } -} - -/** - * Implement hook_user_insert(). - */ -function profile_user_insert(&$edit, $account, $category) { - profile_save_profile($edit, $account, $category, TRUE); -} - -/** - * Implement hook_user_cancel(). - */ -function profile_user_cancel(&$edit, $account, $method) { - switch ($method) { - case 'user_cancel_reassign': - case 'user_cancel_delete': - db_delete('profile_value') - ->condition('uid', $account->uid) - ->execute(); - break; - } -} - -/** - * Implement hook_user_load(). - */ -function profile_user_load($users) { - $result = db_query('SELECT f.name, f.type, v.uid, v.value FROM {profile_field} f INNER JOIN {profile_value} v ON f.fid = v.fid WHERE uid IN (:uids)', array(':uids' => array_keys($users))); - foreach ($result as $record) { - if (empty($users[$record->uid]->{$record->name})) { - $users[$record->uid]->{$record->name} = _profile_field_serialize($record->type) ? unserialize($record->value) : $record->value; - } - } -} - -function profile_save_profile(&$edit, $account, $category, $register = FALSE) { - $result = _profile_get_fields($category, $register); - foreach ($result as $field) { - if (_profile_field_serialize($field->type)) { - $edit[$field->name] = serialize($edit[$field->name]); - } - db_merge('profile_value') - ->key(array( - 'fid' => $field->fid, - 'uid' => $account->uid, - )) - ->fields(array('value' => $edit[$field->name])) - ->execute(); - // Mark field as handled (prevents saving to user->data). - $edit[$field->name] = NULL; - } -} - -function profile_view_field($account, $field) { - // Only allow browsing of private fields for admins, if browsing is enabled, - // and if a user has permission to view profiles. Note that this check is - // necessary because a user may always see their own profile. - $browse = user_access('access user profiles') - && (user_access('administer users') || $field->visibility != PROFILE_PRIVATE) - && !empty($field->page); - - if (isset($account->{$field->name}) && $value = $account->{$field->name}) { - switch ($field->type) { - case 'textarea': - return check_markup($value, filter_default_format($account), '', TRUE); - case 'textfield': - case 'selection': - return $browse ? l($value, 'profile/' . $field->name . '/' . $value) : check_plain($value); - case 'checkbox': - return $browse ? l($field->title, 'profile/' . $field->name) : check_plain($field->title); - case 'url': - return '' . check_plain($value) . ''; - case 'date': - $format = substr(variable_get('date_format_short', 'm/d/Y - H:i'), 0, 5); - // Note: Avoid PHP's date() because it does not handle dates before - // 1970 on Windows. This would make the date field useless for e.g. - // birthdays. - $replace = array( - 'd' => sprintf('%02d', $value['day']), - 'j' => $value['day'], - 'm' => sprintf('%02d', $value['month']), - 'M' => map_month($value['month']), - 'Y' => $value['year'], - 'H:i' => NULL, - 'g:ia' => NULL, - ); - return strtr($format, $replace); - case 'list': - $values = preg_split("/[,\n\r]/", $value); - $fields = array(); - foreach ($values as $value) { - if ($value = trim($value)) { - $fields[] = $browse ? l($value, 'profile/' . $field->name . '/' . $value) : check_plain($value); - } - } - return implode(', ', $fields); - } - } -} - -/** - * Implement hook_user_view(). - */ -function profile_user_view($account) { - // Show private fields to administrators and people viewing their own account. - if (user_access('administer users') || $GLOBALS['user']->uid == $account->uid) { - $result = db_query('SELECT * FROM {profile_field} WHERE visibility <> :hidden ORDER BY category, weight', array(':hidden' => PROFILE_HIDDEN)); - } - else { - $result = db_query('SELECT * FROM {profile_field} WHERE visibility <> :private AND visibility <> :hidden ORDER BY category, weight', array(':private' => PROFILE_PRIVATE, ':hidden' => PROFILE_HIDDEN)); - } - - $fields = array(); - foreach ($result as $field) { - if ($value = profile_view_field($account, $field)) { - $title = ($field->type != 'checkbox') ? check_plain($field->title) : NULL; - - // Create a single fieldset for each category. - if (!isset($account->content[$field->category])) { - $account->content[$field->category] = array( - '#type' => 'user_profile_category', - '#title' => $field->category, - ); - } - - $account->content[$field->category][$field->name] = array( - '#type' => 'user_profile_item', - '#title' => $title, - '#markup' => $value, - '#weight' => $field->weight, - '#attributes' => array('class' => array('profile-' . $field->name)), - ); - } - } -} - -function _profile_form_explanation($field) { - $output = $field->explanation; - - if ($field->type == 'list') { - $output .= ' ' . t('Put each item on a separate line or separate them by commas. No HTML allowed.'); - } - - if ($field->visibility == PROFILE_PRIVATE) { - $output .= ' ' . t('The content of this field is kept private and will not be shown publicly.'); - } - - return $output; -} - -/** - * Implement hook_form_alter(). - */ -function profile_form_alter(&$form, &$form_state, $form_id) { - if (!($form_id == 'user_register_form' || $form_id == 'user_profile_form')) { - return; - } - $form['#validate'][] = 'profile_user_form_validate'; - $account = $form['#user']; - $result = _profile_get_fields($form['#user_category'], $form['#user_category'] == 'register'); - $weight = 1; - foreach ($result as $field) { - $category = $field->category; - if (!isset($form[$category])) { - $form[$category] = array('#type' => 'fieldset', '#title' => check_plain($category), '#weight' => $weight++); - } - switch ($field->type) { - case 'textfield': - case 'url': - $form[$category][$field->name] = array( - '#type' => 'textfield', - '#title' => check_plain($field->title), - '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '', - '#maxlength' => 255, - '#description' => _profile_form_explanation($field), - '#required' => $field->required, - ); - if ($field->autocomplete) { - $form[$category][$field->name]['#autocomplete_path'] = "profile/autocomplete/" . $field->fid; - } - break; - - case 'textarea': - $form[$category][$field->name] = array( - '#type' => 'textarea', - '#title' => check_plain($field->title), - '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '', - '#description' => _profile_form_explanation($field), - '#required' => $field->required, - ); - break; - - case 'list': - $form[$category][$field->name] = array( - '#type' => 'textarea', - '#title' => check_plain($field->title), - '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '', - '#description' => _profile_form_explanation($field), - '#required' => $field->required, - ); - break; - - case 'checkbox': - $form[$category][$field->name] = array( - '#type' => 'checkbox', - '#title' => check_plain($field->title), - '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '', - '#description' => _profile_form_explanation($field), - '#required' => $field->required, - ); - break; - - case 'selection': - $options = $field->required ? array() : array('--'); - $lines = preg_split("/[\n\r]/", $field->options); - foreach ($lines as $line) { - if ($line = trim($line)) { - $options[$line] = $line; - } - } - $form[$category][$field->name] = array( - '#type' => 'select', - '#title' => check_plain($field->title), - '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '', - '#options' => $options, - '#description' => _profile_form_explanation($field), - '#required' => $field->required, - ); - break; - - case 'date': - $form[$category][$field->name] = array( - '#type' => 'date', - '#title' => check_plain($field->title), - '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '', - '#description' => _profile_form_explanation($field), - '#required' => $field->required, - ); - break; - } - } -} - -/** - * Helper function: update an array of user fields by calling profile_view_field - */ -function _profile_update_user_fields($fields, $account) { - foreach ($fields as $key => $field) { - $fields[$key]->value = profile_view_field($account, $field); - } - return $fields; -} - -/** - * Form validation handler for the user register/profile form. - * - * @see profile_form_alter() - */ -function profile_user_form_validate($form, &$form_state) { - $result = _profile_get_fields($form['#user_category'], $form['#user_category'] == 'register'); - foreach ($result as $field) { - if (!empty($form_state['values'][$field->name])) { - if ($field->type == 'url' && !valid_url($form_state['values'][$field->name], TRUE)) { - form_set_error($field->name, t('The value provided for %field is not a valid URL.', array('%field' => $field->title))); - } - } - elseif ($field->required && !user_access('administer users')) { - form_set_error($field->name, t('The field %field is required.', array('%field' => $field->title))); - } - } -} - -/** - * Implement hook_user_categories(). - */ -function profile_user_categories() { - $result = db_query("SELECT DISTINCT(category) FROM {profile_field}"); - $data = array(); - foreach ($result as $category) { - $data[] = array( - 'name' => $category->category, - 'title' => $category->category, - 'weight' => 3, - 'access callback' => 'profile_category_access', - 'access arguments' => array(1, $category->category) - ); - } - return $data; -} - -/** - * Menu item access callback - check if a user has access to a profile category. - */ -function profile_category_access($account, $category) { - if (user_access('administer users') && $account->uid > 0) { - return TRUE; - } - else { - $category_visible = (bool) db_query_range('SELECT 1 FROM {profile_field} WHERE category = :category AND visibility <> :visibility', 0, 1, array( - ':category' => $category, - ':visibility' => PROFILE_HIDDEN - ))->fetchField(); - return user_edit_access($account) && $category_visible; - } -} - -/** - * Process variables for profile-block.tpl.php. - * - * The $variables array contains the following arguments: - * - $account - * - $fields - * - * @see profile-block.tpl.php - */ -function template_preprocess_profile_block(&$variables) { - - $variables['user_picture'] = theme('user_picture', array('account' => $variables['account'])); - $variables['profile'] = array(); - // Supply filtered version of $fields that have values. - foreach ($variables['fields'] as $field) { - if ($field->value) { - $variables['profile'][$field->name]->title = check_plain($field->title); - $variables['profile'][$field->name]->value = $field->value; - $variables['profile'][$field->name]->type = $field->type; - } - } - -} - -/** - * Process variables for profile-listing.tpl.php. - * - * The $variables array contains the following arguments: - * - $account - * - $fields - * - * @see profile-listing.tpl.php - */ -function template_preprocess_profile_listing(&$variables) { - - $variables['user_picture'] = theme('user_picture', array('account' => $variables['account'])); - $variables['name'] = theme('username', array('account' => $variables['account'])); - $variables['profile'] = array(); - // Supply filtered version of $fields that have values. - foreach ($variables['fields'] as $field) { - if ($field->value) { - $variables['profile'][$field->name]->title = $field->title; - $variables['profile'][$field->name]->value = $field->value; - $variables['profile'][$field->name]->type = $field->type; - } - } - -} - -/** - * Process variables for profile-wrapper.tpl.php. - * - * The $variables array contains the following arguments: - * - $content - * - * @see profile-wrapper.tpl.php - */ -function template_preprocess_profile_wrapper(&$variables) { - $variables['current_field'] = ''; - if ($field = arg(1)) { - $variables['current_field'] = $field; - // Supply an alternate template suggestion based on the browsable field. - $variables['template_files'][] = 'profile-wrapper-' . $field; - } -} - -function _profile_field_types($type = NULL) { - $types = array('textfield' => t('single-line textfield'), - 'textarea' => t('multi-line textfield'), - 'checkbox' => t('checkbox'), - 'selection' => t('list selection'), - 'list' => t('freeform list'), - 'url' => t('URL'), - 'date' => t('date')); - return isset($type) ? $types[$type] : $types; -} - -function _profile_field_serialize($type = NULL) { - return $type == 'date'; -} - -function _profile_get_fields($category, $register = FALSE) { - $query = db_select('profile_field'); - if ($register) { - $query->condition('register', 1); - } - else { - // Use LOWER(:category) instead of PHP's strtolower() to avoid UTF-8 conversion issues. - $query->where('LOWER(category) = LOWER(:category)', array(':category' => $category)); - } - if (!user_access('administer users')) { - $query->condition('visibility', PROFILE_HIDDEN, '<>'); - } - return $query - ->fields('profile_field') - ->orderBy('category', 'ASC') - ->orderBy('weight', 'ASC') - ->execute(); -} - Index: modules/profile/profile.pages.inc =================================================================== RCS file: modules/profile/profile.pages.inc diff -N modules/profile/profile.pages.inc --- modules/profile/profile.pages.inc 9 Oct 2009 01:00:02 -0000 1.21 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,138 +0,0 @@ - $name))->fetchObject(); - - if ($name && $field->fid) { - // Only allow browsing of fields that have a page title set. - if (empty($field->page)) { - drupal_not_found(); - return; - } - // Do not allow browsing of private and hidden fields by non-admins. - if (!user_access('administer users') && ($field->visibility == PROFILE_PRIVATE || $field->visibility == PROFILE_HIDDEN)) { - drupal_access_denied(); - return; - } - - // Compile a list of fields to show. - $fields = db_query('SELECT name, title, type, weight, page FROM {profile_field} WHERE fid <> :fid AND visibility = :visibility ORDER BY weight', array( - ':fid' => $field->fid, - ':visibility' => PROFILE_PUBLIC_LISTINGS, - ))->fetchAll(); - - $query = db_select('users')->extend('PagerDefault'); - $query->join('profile_value', 'v', 'u.uid = v.uid'); - $query - ->fields('u', array('uid', 'access')) - ->condition('v.fid', $field->fid) - ->condition('u.access', 0, '<>') - ->condition('u.status', 0, '<>') - ->orderBy('u.access', 'DESC'); - - // Determine what query to use: - $arguments = array($field->fid); - switch ($field->type) { - case 'checkbox': - $query->condition('v.value', 1); - break; - case 'textfield': - case 'selection': - $query->condition('v.value', $value); - break; - case 'list': - $query->condition('v.value', '%' . $value . '%', 'LIKE'); - break; - default: - drupal_not_found(); - return; - } - - $uids = $query - ->limit(20) - ->execute() - ->fetchCol(); - - // Load the users. - $users = user_load_multiple($uids); - - $content = ''; - foreach ($users as $account) { - $profile = _profile_update_user_fields($fields, $account); - $content .= theme('profile_listing', array('account' => $account, 'fields' => $profile)); - } - $output = theme('profile_wrapper', array('content' => $content)); - $output .= theme('pager', array('tags' => NULL)); - - if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') { - $title = strtr(check_plain($field->page), array('%value' => theme('placeholder', array('text' => $value)))); - } - else { - $title = check_plain($field->page); - } - - drupal_set_title($title, PASS_THROUGH); - return $output; - } - elseif ($name && !$field->fid) { - drupal_not_found(); - } - else { - // Compile a list of fields to show. - $fields = db_query('SELECT name, title, type, weight, page, visibility FROM {profile_field} WHERE visibility = :visibility ORDER BY category, weight', array(':visibility' => PROFILE_PUBLIC_LISTINGS))->fetchAll(); - - // Extract the affected users: - $query = db_select('users', 'u')->extend('PagerDefault'); - $uids = $query - ->fields('u', array('uid', 'access')) - ->condition('u.uid', 0, '>') - ->condition('u.status', 0, '>') - ->condition('u.access', 0, '>') - ->orderBy('u.access', 'DESC') - ->limit(20) - ->execute() - ->fetchCol(); - $users = user_load_multiple($uids); - $content = ''; - foreach ($users as $account) { - $profile = _profile_update_user_fields($fields, $account); - $content .= theme('profile_listing', array('account' => $account, 'fields' => $profile)); - } - $output = theme('profile_wrapper', array('content' => $content)); - $output .= theme('pager', array('tags' => NULL)); - - drupal_set_title(t('User list')); - return $output; - } -} - -/** - * Callback to allow autocomplete of profile text fields. - */ -function profile_autocomplete($field, $string) { - $matches = array(); - $autocomplete_field = (bool) db_query_range("SELECT 1 FROM {profile_field} WHERE fid = :fid AND autocomplete = 1", 0, 1, array(':fid' => $field))->fetchField(); - if ($autocomplete_field) { - $values = db_query_range("SELECT value FROM {profile_value} WHERE fid = :fid AND LOWER(value) LIKE LOWER(:value) GROUP BY value ORDER BY value ASC", 0, 10, array( - ':fid' => $field, - ':value' => $string . '%', - ))->fetchCol(); - foreach ($values as $value) { - $matches[$value] = check_plain($value); - } - } - - drupal_json_output($matches); -} Index: modules/profile/profile.test =================================================================== RCS file: modules/profile/profile.test diff -N modules/profile/profile.test --- modules/profile/profile.test 16 Oct 2009 23:48:38 -0000 1.22 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,335 +0,0 @@ -admin_user = $this->drupalCreateUser(array('administer users', 'access user profiles')); - - // This is the user whose profile will be edited. - $this->normal_user = $this->drupalCreateUser(); - } - - /** - * Create a profile field. - * - * @param $type - * The field type to be created. - * @param $category - * The category in which the field should be created. - * @param $edit - * Additional parameters to be submitted. - * @return - * The fid of the field that was just created. - */ - function createProfileField($type = 'textfield', $category = 'simpletest', $edit = array()) { - $edit['title'] = $title = $this->randomName(8); - $edit['name'] = $form_name = 'profile_' . $title; - $edit['category'] = $category; - $edit['explanation'] = $this->randomName(50); - - $this->drupalPost('admin/config/people/profile/add/' . $type, $edit, t('Save field')); - $fid = db_query("SELECT fid FROM {profile_field} WHERE title = :title", array(':title' => $title))->fetchField(); - $this->assertTrue($fid, t('New Profile field has been entered in the database')); - - // Check that the new field is appearing on the user edit form. - $this->drupalGet('user/' . $this->admin_user->uid . '/edit/' . $category); - - // Checking field. - if ($type == 'date') { - $this->assertField($form_name . '[month]', t('Found month selection field')); - $this->assertField($form_name . '[day]', t('Found day selection field')); - $this->assertField($form_name . '[year]', t('Found day selection field')); - } - else { - $this->assertField($form_name , t('Found form named @name', array('@name' => $form_name))); - } - - // Checking name. - $this->assertText($title, t('Checking title for field %title', array('%title' => $title))); - // Checking explanation. - $this->assertText($edit['explanation'], t('Checking explanation for field %title', array('%title' => $title))); - - return array( - 'fid' => $fid, - 'type' => $type, - 'form_name' => $form_name, - 'title' => $title, - 'category' => $category, - ); - } - - /** - * Set the profile field to a random value - * - * @param $field - * The field that should be set. - * @param $value - * The value for the field, defaults to a random string. - * @return - * The value that has been assigned to - */ - function setProfileField($field, $value = NULL) { - - if (!isset($value)) { - $value = $this->randomName(); - } - - $edit = array( - $field['form_name'] => $value, - ); - $this->drupalPost('user/' . $this->normal_user->uid . '/edit/' . $field['category'], $edit, t('Save')); - - // Check profile page. - $content = $this->drupalGet('user/' . $this->normal_user->uid); - $this->assertText($field['title'], t('Found profile field with title %title', array('%title' => $field['title']))); - - if ($field['type'] != 'checkbox') { - // $value must be cast to a string in order to be found by assertText. - $this->assertText("$value", t('Found profile field with value %value', array('%value' => $value))); - } - - return $value; - } - - /** - * Delete a profile field. - * - * @param $field - * The field to be deleted. - */ - function deleteProfileField($field) { - $this->drupalPost('admin/config/people/profile/delete/' . $field['fid'], array(), t('Delete')); - $this->drupalGet('admin/config/people/profile'); - $this->assertNoText($field['title'], t('Checking deleted field %title', array('%title' => $field['title']))); - } -} - -class ProfileTestFields extends ProfileTestCase { - public static function getInfo() { - return array( - 'name' => 'Test single fields', - 'description' => 'Testing profile module with add/edit/delete textfield, textarea, list, checkbox, and url fields into profile page', - 'group' => 'Profile' - ); - } - - /** - * Test each of the field types. List selection and date fields are tested - * separately because they need some special handling. - */ - function testProfileFields() { - $this->drupalLogin($this->admin_user); - - // Set test values for every field type. - $field_types = array( - 'textfield' => $this->randomName(), - 'textarea' => $this->randomName(), - 'list' => $this->randomName(), - 'checkbox' => 1, - // An underscore is an invalid character in a domain name. The method randomName can - // return an underscore. - 'url' => 'http://www.' . str_replace('_', '', $this->randomName(10)) . '.org', - ); - - // For each field type, create a field, give it a value and delete the field. - foreach ($field_types as $type => $value) { - $field = $this->createProfileField($type); - $this->setProfileField($field, $value); - $this->deleteProfileField($field); - } - } -} - -class ProfileTestSelect extends ProfileTestCase { - public static function getInfo() { - return array( - 'name' => 'Test select field', - 'description' => 'Testing profile module with add/edit/delete a select field', - 'group' => 'Profile' - ); - } - - /** - * Create a list selection field, give it a value, and delete the field. - */ - function testProfileSelectionField() { - $this->drupalLogin($this->admin_user); - - $edit = array( - 'options' => implode("\n", range(1, 10)), - ); - $field = $this->createProfileField('selection', 'simpletest', $edit); - - $this->setProfileField($field, rand(1, 10)); - - $this->deleteProfileField($field); - } -} - -class ProfileTestDate extends ProfileTestCase { - public static function getInfo() { - return array( - 'name' => 'Test date field', - 'description' => 'Testing profile module with add/edit/delete a date field', - 'group' => 'Profile' - ); - } - - /** - * Create a date field, give it a value, and delete the field. - */ - function testProfileDateField() { - $this->drupalLogin($this->admin_user); - - variable_set('date_format_short', 'm/d/Y - H:i'); - $field = $this->createProfileField('date'); - - // Set date to January 09, 1983 - $edit = array( - $field['form_name'] . '[month]' => 1, - $field['form_name'] . '[day]' => 9, - $field['form_name'] . '[year]' => 1983, - ); - - $this->drupalPost('user/' . $this->normal_user->uid . '/edit/' . $field['category'], $edit, t('Save')); - - // Check profile page. - $this->drupalGet('user/' . $this->normal_user->uid); - $this->assertText($field['title'], t('Found profile field with title %title', array('%title' => $field['title']))); - - $this->assertText('01/09/1983', t('Found date profile field.')); - - $this->deleteProfileField($field); - } -} - -class ProfileTestWeights extends ProfileTestCase { - public static function getInfo() { - return array( - 'name' => 'Test field weights', - 'description' => 'Testing profile modules weigting of fields', - 'group' => 'Profile' - ); - } - - function testProfileFieldWeights() { - $this->drupalLogin($this->admin_user); - - $category = $this->randomName(); - $field1 = $this->createProfileField('textfield', $category, array('weight' => 1)); - $field2 = $this->createProfileField('textfield', $category, array('weight' => -1)); - - $this->setProfileField($field1, $this->randomName(8)); - $this->setProfileField($field2, $this->randomName(8)); - - $profile_edit = $this->drupalGet('user/' . $this->normal_user->uid . '/edit/' . $category); - $this->assertTrue(strpos($profile_edit, $field1['title']) > strpos($profile_edit, $field2['title']), t('Profile field weights are respected on the user edit form.')); - - $profile_page = $this->drupalGet('user/' . $this->normal_user->uid); - $this->assertTrue(strpos($profile_page, $field1['title']) > strpos($profile_page, $field2['title']), t('Profile field weights are respected on the user profile page.')); - } -} - -/** - * Test profile field autocompletion and access. - */ -class ProfileTestAutocomplete extends ProfileTestCase { - public static function getInfo() { - return array( - 'name' => 'Autocompletion', - 'description' => 'Test profile fields with autocompletion.', - 'group' => 'Profile' - ); - } - - /** - * Tests profile field autocompletion and access. - */ - function testAutocomplete() { - $this->drupalLogin($this->admin_user); - - // Create a new profile field with autocompletion enabled. - $category = $this->randomName(); - $field = $this->createProfileField('textfield', $category, array('weight' => 1, 'autocomplete' => 1)); - - // Enter profile field value. - $field['value'] = $this->randomName(); - $this->setProfileField($field, $field['value']); - - // Set some html for what we want to see in the page output later. - $autocomplete_html = ''; - $field_html = ''; - - // Check that autocompletion html is found on the user's profile edit page. - $this->drupalGet('user/' . $this->admin_user->uid . '/edit/' . $category); - $this->assertRaw($autocomplete_html, t('Autocomplete found.')); - $this->assertRaw('misc/autocomplete.js', t('Autocomplete JavaScript found.')); - $this->assertRaw('class="form-text form-autocomplete"', t('Autocomplete form element class found.')); - - // Check the autocompletion path using the first letter of our user's profile - // field value to make sure access is allowed and a valid result if found. - $this->drupalGet('profile/autocomplete/' . $field['fid'] . '/' . $field['value'][0]); - $this->assertResponse(200, t('Autocomplete path allowed to user with permission.')); - $this->assertRaw($field['value'], t('Autocomplete value found.')); - - // Logout and login with a user without the 'access user profiles' permission. - $this->drupalLogout(); - $this->drupalLogin($this->normal_user); - - // Check that autocompletion html is not found on the user's profile edit page. - $this->drupalGet('user/' . $this->normal_user->uid . '/edit/' . $category); - $this->assertNoRaw($autocomplete_html, t('Autocomplete not found.')); - - // User should be denied access to the profile autocomplete path. - $this->drupalGet('profile/autocomplete/' . $field['fid'] . '/' . $field['value'][0]); - $this->assertResponse(403, t('Autocomplete path denied to user without permission.')); - } -} - -class ProfileBlockTestCase extends DrupalWebTestCase { - public static function getInfo() { - return array( - 'name' => 'Block availability', - 'description' => 'Check if the author-information block is available.', - 'group' => 'Profile', - ); - } - - function setUp() { - parent::setUp('profile'); - - // Create and login user - $admin_user = $this->drupalCreateUser(array('administer blocks')); - $this->drupalLogin($admin_user); - } - - function testAuthorInformationBlock() { - // Set block title to confirm that the interface is availble. - $this->drupalPost('admin/structure/block/manage/profile/author-information/configure', array('title' => $this->randomName(8)), t('Save block')); - $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.')); - - // Set the block to a region to confirm block is availble. - $edit = array(); - $edit['profile_author-information[region]'] = 'footer'; - $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); - $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.')); - } -} - - /** - * TODO: - * - Test field visibility - * - Test profile browsing - * - Test required fields - * - Test fields on registration form - * - Test updating fields - */ Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.1077 diff -u -p -r1.1077 user.module --- modules/user/user.module 7 Nov 2009 14:27:20 -0000 1.1077 +++ modules/user/user.module 8 Nov 2009 12:20:40 -0000 @@ -95,10 +95,6 @@ function user_entity_info() { 'bundles' => array( 'user' => array( 'label' => t('User'), - 'admin' => array( - 'path' => 'admin/config/people/accounts', - 'access arguments' => array('administer users'), - ), ), ), ), @@ -2747,10 +2743,6 @@ function user_help($path, $arg) {
  • Anonymous user: this role is used for users that don\'t have a user account or that are not authenticated.
  • Authenticated user: this role is automatically granted to all logged in users.
  • ', array('@permissions' => url('admin/config/people/permissions'))); - case 'admin/config/people/accounts/fields': - return '

    ' . t('This form lets administrators add, edit, and arrange fields for storing user data.') . '

    '; - case 'admin/config/people/accounts/display': - return '

    ' . t('This form lets administrators configure how fields should be displayed when rendering a user profile page.') . '

    '; case 'admin/people/search': return '

    ' . t('Enter a simple pattern ("*" may be used as a wildcard match) to search for a username or e-mail address. For example, one may search for "br" and Drupal might return "brian", "brad", and "brenda@example.com".') . '

    '; }