Initial code using Drupal 6.38
This commit is contained in:
commit
4824608a33
467 changed files with 90887 additions and 0 deletions
41
modules/profile/profile-block.tpl.php
Normal file
41
modules/profile/profile-block.tpl.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file profile-block.tpl.php
|
||||
* Default theme implementation for displaying a users profile within a
|
||||
* block. It only shows in relation to a node displayed as a full page.
|
||||
*
|
||||
* Available variables:
|
||||
* - $picture: Image configured for the account linking to the users page.
|
||||
* - $profile: Keyed array of all profile fields that have a value.
|
||||
*
|
||||
* Each $field in $profile contains:
|
||||
* - $field->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.
|
||||
*
|
||||
* <?php if (isset($profile['last_name'])): ?>
|
||||
* <div class="field last-name">
|
||||
* <?php print $profile['last_name']->title; ?>:<br />
|
||||
* <?php print $profile['last_name']->value; ?>
|
||||
* </div>
|
||||
* <?php endif; ?>
|
||||
*
|
||||
* @see template_preprocess_profile_block()
|
||||
*/
|
||||
?>
|
||||
<?php print $picture; ?>
|
||||
|
||||
<?php foreach ($profile as $field) : ?>
|
||||
<p>
|
||||
<?php if ($field->type != 'checkbox') : ?>
|
||||
<strong><?php print $field->title; ?></strong><br />
|
||||
<?php endif; ?>
|
||||
<?php print $field->value; ?>
|
||||
</p>
|
||||
<?php endforeach; ?>
|
51
modules/profile/profile-listing.tpl.php
Normal file
51
modules/profile/profile-listing.tpl.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file profile-listing.tpl.php
|
||||
* Default theme implementation for displaying a user and their profile data
|
||||
* for member listing pages.
|
||||
*
|
||||
* @see profile-wrapper.tpl.php
|
||||
* where all the data is collected and printed out.
|
||||
*
|
||||
* Available variables:
|
||||
* - $picture: Image configured for the account linking to the users page.
|
||||
* - $name: User's account name linking to the users page.
|
||||
* - $profile: Keyed array of all profile fields that are set as visible
|
||||
* in member list pages (configured by site administrators). It also needs
|
||||
* to have a value in order to be present.
|
||||
*
|
||||
* Each $field in $profile contains:
|
||||
* - $field->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.
|
||||
*
|
||||
* <?php if (isset($profile['last_name'])): ?>
|
||||
* <div class="field last-name">
|
||||
* <?php print $profile['last_name']->title; ?>:<br />
|
||||
* <?php print $profile['last_name']->value; ?>
|
||||
* </div>
|
||||
* <?php endif; ?>
|
||||
*
|
||||
* @see template_preprocess_profile_listing()
|
||||
*/
|
||||
?>
|
||||
<div class="profile">
|
||||
<?php print $picture; ?>
|
||||
|
||||
<div class="name">
|
||||
<?php print $name; ?>
|
||||
</div>
|
||||
|
||||
<?php foreach ($profile as $field) : ?>
|
||||
<div class="field">
|
||||
<?php print $field->value; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</div>
|
24
modules/profile/profile-wrapper.tpl.php
Normal file
24
modules/profile/profile-wrapper.tpl.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file profile-wrapper.tpl.php
|
||||
* Default theme implementation for wrapping member listings and their
|
||||
* profiles.
|
||||
*
|
||||
* This template is used when viewing a list of users. It can be a general
|
||||
* list for viewing all users with the URL of "example.com/profile" or when
|
||||
* viewing a set of users who share a specific value for a profile such
|
||||
* as "example.com/profile/country/belgium".
|
||||
*
|
||||
* Available variables:
|
||||
* - $content: User account profiles iterated through profile-listing.tpl.php.
|
||||
* - $current_field: The named field being browsed. Provided here for context.
|
||||
* The above example would result in "last_name". An alternate template name
|
||||
* is also based on this, e.g., "profile-wrapper-last_name.tpl.php".
|
||||
*
|
||||
* @see template_preprocess_profile_wrapper()
|
||||
*/
|
||||
?>
|
||||
<div id="profile">
|
||||
<?php print $content; ?>
|
||||
</div>
|
403
modules/profile/profile.admin.inc
Normal file
403
modules/profile/profile.admin.inc
Normal file
|
@ -0,0 +1,403 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Administrative page callbacks for the profile module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form builder to display a listing of all editable profile fields.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see profile_admin_overview_submit()
|
||||
*/
|
||||
function profile_admin_overview() {
|
||||
$result = db_query('SELECT title, name, type, category, fid, weight FROM {profile_fields} ORDER BY category, weight');
|
||||
|
||||
$form = array();
|
||||
$categories = array();
|
||||
while ($field = db_fetch_object($result)) {
|
||||
// Collect all category information
|
||||
$categories[] = $field->category;
|
||||
|
||||
// Save all field information
|
||||
$form[$field->fid]['name'] = array('#value' => check_plain($field->name));
|
||||
$form[$field->fid]['title'] = array('#value' => check_plain($field->title));
|
||||
$form[$field->fid]['type'] = array('#value' => $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('#value' => l(t('edit'), "admin/user/profile/edit/$field->fid"));
|
||||
$form[$field->fid]['delete'] = array('#value' => l(t('delete'), "admin/user/profile/delete/$field->fid"));
|
||||
}
|
||||
|
||||
// Add the cateogory 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;
|
||||
|
||||
$addnewfields = '<h2>'. t('Add new field') .'</h2>';
|
||||
$addnewfields .= '<ul>';
|
||||
foreach (_profile_field_types() as $key => $value) {
|
||||
$addnewfields .= '<li>'. l($value, "admin/user/profile/add/$key") .'</li>';
|
||||
}
|
||||
$addnewfields .= '</ul>';
|
||||
$form['addnewfields'] = array('#value' => $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_query("UPDATE {profile_fields} SET weight = %d, category = '%s' WHERE fid = %d", $weight, $category, $fid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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($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'] = 'profile-category profile-category-'. $category_number;
|
||||
$rows[] = array(array('data' => $category, 'colspan' => 7, 'class' => 'category'));
|
||||
$rows[] = array('data' => array(array('data' => '<em>'. t('No fields in this category. If this category remains empty when saved, it will be removed.') .'</em>', 'colspan' => 7)), 'class' => 'category-'. $category_number .'-message category-message category-populated');
|
||||
|
||||
// Make it dragable 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'] = 'profile-weight profile-weight-'. $categories[$category];
|
||||
$field['category']['#attributes']['class'] = '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' => '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', $header, $rows, array('id' => 'profile-fields'));
|
||||
$output .= drupal_render($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_state, $arg = NULL) {
|
||||
if (arg(3) == 'edit') {
|
||||
if (is_numeric($arg)) {
|
||||
$fid = $arg;
|
||||
|
||||
$edit = db_fetch_array(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
|
||||
|
||||
if (!$edit) {
|
||||
drupal_not_found();
|
||||
return;
|
||||
}
|
||||
drupal_set_title(t('edit %title', array('%title' => $edit['title'])));
|
||||
$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])));
|
||||
$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/user/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 <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".'),
|
||||
'#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 <code>%value</code> 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.'),
|
||||
);
|
||||
}
|
||||
else if ($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.'));
|
||||
}
|
||||
|
||||
if (in_array($form_state['values']['name'], user_fields())) {
|
||||
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.'));
|
||||
}
|
||||
$args1 = array($form_state['values']['title'], $form_state['values']['category']);
|
||||
$args2 = array($form_state['values']['name']);
|
||||
$query_suffix = '';
|
||||
|
||||
if (isset($form_state['values']['fid'])) {
|
||||
$args1[] = $args2[] = $form_state['values']['fid'];
|
||||
$query_suffix = ' AND fid != %d';
|
||||
}
|
||||
|
||||
if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s' AND category = '%s'". $query_suffix, $args1))) {
|
||||
form_set_error('title', t('The specified title is already in use.'));
|
||||
}
|
||||
if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'". $query_suffix, $args2))) {
|
||||
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'])) {
|
||||
db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['type'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page']);
|
||||
|
||||
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/user/profile'));
|
||||
}
|
||||
else {
|
||||
db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, options = '%s', page = '%s' WHERE fid = %d", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page'], $form_state['values']['fid']);
|
||||
|
||||
drupal_set_message(t('The field has been updated.'));
|
||||
}
|
||||
cache_clear_all();
|
||||
menu_rebuild();
|
||||
|
||||
$form_state['redirect'] = 'admin/user/profile';
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback; deletes a field from all user profiles.
|
||||
*/
|
||||
function profile_field_delete(&$form_state, $fid) {
|
||||
$field = db_fetch_object(db_query("SELECT title FROM {profile_fields} WHERE fid = %d", $fid));
|
||||
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/user/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 <a href="@edit-field">edit this field</a> and change it to a hidden profile field so that it may only be accessed by administrators.', array('@edit-field' => url('admin/user/profile/edit/'. $fid))),
|
||||
t('Delete'), t('Cancel'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a field delete form submission.
|
||||
*/
|
||||
function profile_field_delete_submit($form, &$form_state) {
|
||||
db_query('DELETE FROM {profile_fields} WHERE fid = %d', $form_state['values']['fid']);
|
||||
db_query('DELETE FROM {profile_values} WHERE fid = %d', $form_state['values']['fid']);
|
||||
|
||||
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/user/profile'));
|
||||
|
||||
$form_state['redirect'] = 'admin/user/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_fields} WHERE LOWER(category) LIKE LOWER('%s%%')", $string, 0, 10);
|
||||
while ($data = db_fetch_object($result)) {
|
||||
$matches[$data->category] = check_plain($data->category);
|
||||
}
|
||||
drupal_json($matches);
|
||||
}
|
10
modules/profile/profile.css
Normal file
10
modules/profile/profile.css
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
#profile-fields td.category {
|
||||
font-weight: bold;
|
||||
}
|
||||
#profile-fields tr.category-message {
|
||||
color: #999;
|
||||
}
|
||||
#profile-fields tr.category-populated {
|
||||
display: none;
|
||||
}
|
11
modules/profile/profile.info
Normal file
11
modules/profile/profile.info
Normal file
|
@ -0,0 +1,11 @@
|
|||
name = Profile
|
||||
description = Supports configurable user profiles.
|
||||
package = Core - optional
|
||||
version = VERSION
|
||||
core = 6.x
|
||||
|
||||
; Information added by Drupal.org packaging script on 2016-02-24
|
||||
version = "6.38"
|
||||
project = "drupal"
|
||||
datestamp = "1456343372"
|
||||
|
146
modules/profile/profile.install
Normal file
146
modules/profile/profile.install
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
*/
|
||||
function profile_install() {
|
||||
// Create tables.
|
||||
drupal_install_schema('profile');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
*/
|
||||
function profile_uninstall() {
|
||||
// Remove tables
|
||||
drupal_uninstall_schema('profile');
|
||||
|
||||
variable_del('profile_block_author_fields');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_schema().
|
||||
*/
|
||||
function profile_schema() {
|
||||
$schema['profile_fields'] = array(
|
||||
'description' => '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_values'] = array(
|
||||
'description' => 'Stores values for profile fields.',
|
||||
'fields' => array(
|
||||
'fid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The {profile_fields}.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'),
|
||||
),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
53
modules/profile/profile.js
Normal file
53
modules/profile/profile.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
|
||||
/**
|
||||
* 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 = function(context) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
578
modules/profile/profile.module
Normal file
578
modules/profile/profile.module
Normal file
|
@ -0,0 +1,578 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Support for configurable user profiles.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Private field, content only available to privileged users.
|
||||
*/
|
||||
define('PROFILE_PRIVATE', 1);
|
||||
|
||||
/**
|
||||
* Public field, content shown on profile page but not used on member list pages.
|
||||
*/
|
||||
define('PROFILE_PUBLIC', 2);
|
||||
|
||||
/**
|
||||
* Public field, content shown on profile page and on member list pages.
|
||||
*/
|
||||
define('PROFILE_PUBLIC_LISTINGS', 3);
|
||||
|
||||
/**
|
||||
* Hidden profile field, only accessible by administrators, modules and themes.
|
||||
*/
|
||||
define('PROFILE_HIDDEN', 4);
|
||||
|
||||
/**
|
||||
* Implementation of hook_help().
|
||||
*/
|
||||
function profile_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/help#profile':
|
||||
$output = '<p>'. t('The profile module allows custom fields (such as country, full name, or age) to be defined and displayed in the <em>My Account</em> section. This permits users of a site to share more information about themselves, and can help community-based sites organize users around specific information.') .'</p>';
|
||||
$output .= '<p>'. t('The following types of fields can be added to a user profile:') .'</p>';
|
||||
$output .= '<ul><li>'. t('single-line textfield') .'</li>';
|
||||
$output .= '<li>'. t('multi-line textfield') .'</li>';
|
||||
$output .= '<li>'. t('checkbox') .'</li>';
|
||||
$output .= '<li>'. t('list selection') .'</li>';
|
||||
$output .= '<li>'. t('freeform list') .'</li>';
|
||||
$output .= '<li>'. t('URL') .'</li>';
|
||||
$output .= '<li>'. t('date') .'</li></ul>';
|
||||
$output .= '<p>'. t('For more information, see the online handbook entry for <a href="@profile">Profile module</a>.', array('@profile' => 'http://drupal.org/handbook/modules/profile/')) .'</p>';
|
||||
return $output;
|
||||
case 'admin/user/profile':
|
||||
return '<p>'. t("This page displays a list of the existing custom profile fields to be displayed on a user's <em>My Account</em> 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. To change the category of a field or the order of fields within a category, grab a drag-and-drop handle under the Title column and drag the field to a new location in the list. (Grab a handle by clicking and holding the mouse while hovering over a handle icon.) Remember that your changes will not be saved until you click the <em>Save configuration</em> button at the bottom of the page.") .'</p>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_theme()
|
||||
*/
|
||||
function profile_theme() {
|
||||
return array(
|
||||
'profile_block' => array(
|
||||
'arguments' => array('account' => NULL, 'fields' => array()),
|
||||
'template' => 'profile-block',
|
||||
),
|
||||
'profile_listing' => array(
|
||||
'arguments' => array('account' => NULL, 'fields' => array()),
|
||||
'template' => 'profile-listing',
|
||||
),
|
||||
'profile_wrapper' => array(
|
||||
'arguments' => array('content' => NULL),
|
||||
'template' => 'profile-wrapper',
|
||||
),
|
||||
'profile_admin_overview' => array(
|
||||
'arguments' => array('form' => NULL),
|
||||
'file' => 'profile.admin.inc',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_menu().
|
||||
*/
|
||||
function profile_menu() {
|
||||
$items['profile'] = array(
|
||||
'title' => 'User list',
|
||||
'page callback' => 'profile_browse',
|
||||
'access arguments' => array('access user profiles'),
|
||||
'type' => MENU_SUGGESTED_ITEM,
|
||||
'file' => 'profile.pages.inc',
|
||||
);
|
||||
$items['admin/user/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/user/profile/add'] = array(
|
||||
'title' => 'Add field',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('profile_field_form'),
|
||||
'access arguments' => array('administer users'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'profile.admin.inc',
|
||||
);
|
||||
$items['admin/user/profile/autocomplete'] = array(
|
||||
'title' => 'Profile category autocomplete',
|
||||
'page callback' => 'profile_admin_settings_autocomplete',
|
||||
'access arguments' => array('administer users'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'profile.admin.inc',
|
||||
);
|
||||
$items['admin/user/profile/edit'] = array(
|
||||
'title' => 'Edit field',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('profile_field_form'),
|
||||
'access arguments' => array('administer users'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'profile.admin.inc',
|
||||
);
|
||||
$items['admin/user/profile/delete'] = array(
|
||||
'title' => 'Delete field',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('profile_field_delete'),
|
||||
'access arguments' => array('administer users'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'profile.admin.inc',
|
||||
);
|
||||
$items['profile/autocomplete'] = array(
|
||||
'title' => 'Profile autocomplete',
|
||||
'page callback' => 'profile_autocomplete',
|
||||
'access arguments' => array('access user profiles'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'profile.pages.inc',
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_block().
|
||||
*/
|
||||
function profile_block($op = 'list', $delta = 0, $edit = array()) {
|
||||
|
||||
if ($op == 'list') {
|
||||
$blocks[0]['info'] = t('Author information');
|
||||
$blocks[0]['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE;
|
||||
return $blocks;
|
||||
}
|
||||
else if ($op == 'configure' && $delta == 0) {
|
||||
// Compile a list of fields to show
|
||||
$fields = array();
|
||||
$result = db_query('SELECT name, title, weight, visibility FROM {profile_fields} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
|
||||
while ($record = db_fetch_object($result)) {
|
||||
$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 <a href="@profile-admin">profile field configuration</a> are available.', array('@profile-admin' => url('admin/user/profile'))),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
else if ($op == 'save' && $delta == 0) {
|
||||
variable_set('profile_block_author_fields', $edit['profile_block_author_fields']);
|
||||
}
|
||||
else if ($op == 'view') {
|
||||
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, type, visibility, weight FROM {profile_fields} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
|
||||
while ($record = db_fetch_object($result)) {
|
||||
// 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', $account, $profile, TRUE);
|
||||
}
|
||||
|
||||
if (isset($use_fields['user_profile']) && $use_fields['user_profile']) {
|
||||
$output .= '<div>'. l(t('View full user profile'), 'user/'. $account->uid) .'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($output) {
|
||||
$block['subject'] = t('About %name', array('%name' => $account->name));
|
||||
$block['content'] = $output;
|
||||
return $block;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_user().
|
||||
*/
|
||||
function profile_user($type, &$edit, &$user, $category = NULL) {
|
||||
switch ($type) {
|
||||
case 'load':
|
||||
return profile_load_profile($user);
|
||||
case 'register':
|
||||
return profile_form_profile($edit, $user, $category, TRUE);
|
||||
case 'update':
|
||||
return profile_save_profile($edit, $user, $category);
|
||||
case 'insert':
|
||||
return profile_save_profile($edit, $user, $category, TRUE);
|
||||
case 'view':
|
||||
return profile_view_profile($user);
|
||||
case 'form':
|
||||
return profile_form_profile($edit, $user, $category);
|
||||
case 'validate':
|
||||
return profile_validate_profile($edit, $category);
|
||||
case 'categories':
|
||||
return profile_categories();
|
||||
case 'delete':
|
||||
db_query('DELETE FROM {profile_values} WHERE uid = %d', $user->uid);
|
||||
}
|
||||
}
|
||||
|
||||
function profile_load_profile(&$user) {
|
||||
$result = db_query('SELECT f.name, f.type, v.value FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE uid = %d', $user->uid);
|
||||
while ($field = db_fetch_object($result)) {
|
||||
if (empty($user->{$field->name})) {
|
||||
$user->{$field->name} = _profile_field_serialize($field->type) ? unserialize($field->value) : $field->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function profile_save_profile(&$edit, &$user, $category, $register = FALSE) {
|
||||
$result = _profile_get_fields($category, $register);
|
||||
while ($field = db_fetch_object($result)) {
|
||||
if (_profile_field_serialize($field->type)) {
|
||||
$edit[$field->name] = serialize($edit[$field->name]);
|
||||
}
|
||||
db_query("DELETE FROM {profile_values} WHERE fid = %d AND uid = %d", $field->fid, $user->uid);
|
||||
db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $edit[$field->name]);
|
||||
// Mark field as handled (prevents saving to user->data).
|
||||
$edit[$field->name] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function profile_view_field($user, $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($user->{$field->name}) && $value = $user->{$field->name}) {
|
||||
switch ($field->type) {
|
||||
case 'textarea':
|
||||
return check_markup($value);
|
||||
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 '<a href="'. check_url($value) .'">'. check_plain($value) .'</a>';
|
||||
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 = 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function profile_view_profile(&$user) {
|
||||
|
||||
profile_load_profile($user);
|
||||
|
||||
// Show private fields to administrators and people viewing their own account.
|
||||
if (user_access('administer users') || $GLOBALS['user']->uid == $user->uid) {
|
||||
$result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d ORDER BY category, weight', PROFILE_HIDDEN);
|
||||
}
|
||||
else {
|
||||
$result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d AND visibility != %d ORDER BY category, weight', PROFILE_PRIVATE, PROFILE_HIDDEN);
|
||||
}
|
||||
|
||||
$fields = array();
|
||||
while ($field = db_fetch_object($result)) {
|
||||
if ($value = profile_view_field($user, $field)) {
|
||||
$title = ($field->type != 'checkbox') ? check_plain($field->title) : NULL;
|
||||
|
||||
// Create a single fieldset for each category.
|
||||
if (!isset($user->content[$field->category])) {
|
||||
$user->content[$field->category] = array(
|
||||
'#type' => 'user_profile_category',
|
||||
'#title' => $field->category,
|
||||
);
|
||||
}
|
||||
|
||||
$user->content[$field->category][$field->name] = array(
|
||||
'#type' => 'user_profile_item',
|
||||
'#title' => $title,
|
||||
'#value' => $value,
|
||||
'#weight' => $field->weight,
|
||||
'#attributes' => array('class' => '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;
|
||||
}
|
||||
|
||||
function profile_form_profile($edit, $user, $category, $register = FALSE) {
|
||||
$result = _profile_get_fields($category, $register);
|
||||
$weight = 1;
|
||||
$fields = array();
|
||||
while ($field = db_fetch_object($result)) {
|
||||
$category = $field->category;
|
||||
if (!isset($fields[$category])) {
|
||||
$fields[$category] = array('#type' => 'fieldset', '#title' => check_plain($category), '#weight' => $weight++);
|
||||
}
|
||||
switch ($field->type) {
|
||||
case 'textfield':
|
||||
case 'url':
|
||||
$fields[$category][$field->name] = array('#type' => 'textfield',
|
||||
'#title' => check_plain($field->title),
|
||||
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
|
||||
'#maxlength' => 255,
|
||||
'#description' => _profile_form_explanation($field),
|
||||
'#required' => $field->required,
|
||||
);
|
||||
if ($field->autocomplete) {
|
||||
$fields[$category][$field->name]['#autocomplete_path'] = "profile/autocomplete/". $field->fid;
|
||||
}
|
||||
break;
|
||||
case 'textarea':
|
||||
$fields[$category][$field->name] = array('#type' => 'textarea',
|
||||
'#title' => check_plain($field->title),
|
||||
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
|
||||
'#description' => _profile_form_explanation($field),
|
||||
'#required' => $field->required,
|
||||
);
|
||||
break;
|
||||
case 'list':
|
||||
$fields[$category][$field->name] = array('#type' => 'textarea',
|
||||
'#title' => check_plain($field->title),
|
||||
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
|
||||
'#description' => _profile_form_explanation($field),
|
||||
'#required' => $field->required,
|
||||
);
|
||||
break;
|
||||
case 'checkbox':
|
||||
$fields[$category][$field->name] = array('#type' => 'checkbox',
|
||||
'#title' => check_plain($field->title),
|
||||
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
|
||||
'#description' => _profile_form_explanation($field),
|
||||
'#required' => $field->required,
|
||||
);
|
||||
break;
|
||||
case 'selection':
|
||||
$options = $field->required ? array() : array('--');
|
||||
$lines = split("[\n\r]", $field->options);
|
||||
foreach ($lines as $line) {
|
||||
if ($line = trim($line)) {
|
||||
$options[$line] = $line;
|
||||
}
|
||||
}
|
||||
$fields[$category][$field->name] = array('#type' => 'select',
|
||||
'#title' => check_plain($field->title),
|
||||
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
|
||||
'#options' => $options,
|
||||
'#description' => _profile_form_explanation($field),
|
||||
'#required' => $field->required,
|
||||
);
|
||||
break;
|
||||
case 'date':
|
||||
$fields[$category][$field->name] = array('#type' => 'date',
|
||||
'#title' => check_plain($field->title),
|
||||
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
|
||||
'#description' => _profile_form_explanation($field),
|
||||
'#required' => $field->required,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
function profile_validate_profile($edit, $category) {
|
||||
$result = _profile_get_fields($category);
|
||||
while ($field = db_fetch_object($result)) {
|
||||
if ($edit[$field->name]) {
|
||||
if ($field->type == 'url') {
|
||||
if (!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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($field->required && !user_access('administer users')) {
|
||||
form_set_error($field->name, t('The field %field is required.', array('%field' => $field->title)));
|
||||
}
|
||||
}
|
||||
|
||||
return $edit;
|
||||
}
|
||||
|
||||
function profile_categories() {
|
||||
$result = db_query("SELECT DISTINCT(category) FROM {profile_fields}");
|
||||
$data = array();
|
||||
while ($category = db_fetch_object($result)) {
|
||||
$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 {
|
||||
return user_edit_access($account) && db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE category = '%s' AND visibility <> %d", $category, PROFILE_HIDDEN));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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['picture'] = theme('user_picture', $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['picture'] = theme('user_picture', $variables['account']);
|
||||
$variables['name'] = theme('username', $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) {
|
||||
$args = array();
|
||||
$sql = 'SELECT * FROM {profile_fields} WHERE ';
|
||||
$filters = array();
|
||||
if ($register) {
|
||||
$filters[] = 'register = 1';
|
||||
}
|
||||
else {
|
||||
// Use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
|
||||
$filters[] = "LOWER(category) = LOWER('%s')";
|
||||
$args[] = $category;
|
||||
}
|
||||
if (!user_access('administer users')) {
|
||||
$filters[] = 'visibility != %d';
|
||||
$args[] = PROFILE_HIDDEN;
|
||||
}
|
||||
$sql .= implode(' AND ', $filters);
|
||||
$sql .= ' ORDER BY category, weight';
|
||||
return db_query($sql, $args);
|
||||
}
|
||||
|
119
modules/profile/profile.pages.inc
Normal file
119
modules/profile/profile.pages.inc
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* User page callbacks for the profile module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Menu callback; display a list of user information.
|
||||
*/
|
||||
function profile_browse() {
|
||||
// Ensure that the path is converted to 3 levels always.
|
||||
list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
|
||||
|
||||
$field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
|
||||
|
||||
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 = array();
|
||||
$result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE fid != %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS);
|
||||
while ($record = db_fetch_object($result)) {
|
||||
$fields[] = $record;
|
||||
}
|
||||
|
||||
// Determine what query to use:
|
||||
$arguments = array($field->fid);
|
||||
switch ($field->type) {
|
||||
case 'checkbox':
|
||||
$query = 'v.value = 1';
|
||||
break;
|
||||
case 'textfield':
|
||||
case 'selection':
|
||||
$query = "v.value = '%s'";
|
||||
$arguments[] = $value;
|
||||
break;
|
||||
case 'list':
|
||||
$query = "v.value LIKE '%%%s%%'";
|
||||
$arguments[] = $value;
|
||||
break;
|
||||
default:
|
||||
drupal_not_found();
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract the affected users:
|
||||
$result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments);
|
||||
|
||||
$content = '';
|
||||
while ($account = db_fetch_object($result)) {
|
||||
$account = user_load(array('uid' => $account->uid));
|
||||
$profile = _profile_update_user_fields($fields, $account);
|
||||
$content .= theme('profile_listing', $account, $profile);
|
||||
}
|
||||
$output = theme('profile_wrapper', $content);
|
||||
$output .= theme('pager', NULL, 20);
|
||||
|
||||
if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
|
||||
$title = strtr(check_plain($field->page), array('%value' => theme('placeholder', $value)));
|
||||
}
|
||||
else {
|
||||
$title = check_plain($field->page);
|
||||
}
|
||||
|
||||
drupal_set_title($title);
|
||||
return $output;
|
||||
}
|
||||
else if ($name && !$field->fid) {
|
||||
drupal_not_found();
|
||||
}
|
||||
else {
|
||||
// Compile a list of fields to show.
|
||||
$fields = array();
|
||||
$result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);
|
||||
while ($record = db_fetch_object($result)) {
|
||||
$fields[] = $record;
|
||||
}
|
||||
|
||||
// Extract the affected users:
|
||||
$result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
|
||||
|
||||
$content = '';
|
||||
while ($account = db_fetch_object($result)) {
|
||||
$account = user_load(array('uid' => $account->uid));
|
||||
$profile = _profile_update_user_fields($fields, $account);
|
||||
$content .= theme('profile_listing', $account, $profile);
|
||||
}
|
||||
$output = theme('profile_wrapper', $content);
|
||||
$output .= theme('pager', NULL, 20);
|
||||
|
||||
drupal_set_title(t('User list'));
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to allow autocomplete of profile text fields.
|
||||
*/
|
||||
function profile_autocomplete($field, $string) {
|
||||
$matches = array();
|
||||
if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) {
|
||||
$result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND LOWER(value) LIKE LOWER('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10);
|
||||
while ($data = db_fetch_object($result)) {
|
||||
$matches[$data->value] = check_plain($data->value);
|
||||
}
|
||||
}
|
||||
|
||||
drupal_json($matches);
|
||||
}
|
Reference in a new issue