| 1 |
<?php
|
| 2 |
// $Id: profile.pages.inc,v 1.20 2009/09/21 07:56:08 dries Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* User page callbacks for the profile module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Menu callback; display a list of user information.
|
| 11 |
*/
|
| 12 |
function profile_browse() {
|
| 13 |
// Ensure that the path is converted to 3 levels always.
|
| 14 |
list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
|
| 15 |
|
| 16 |
$field = db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_field} WHERE name = :name", array(':name' => $name))->fetchObject();
|
| 17 |
|
| 18 |
if ($name && $field->fid) {
|
| 19 |
// Only allow browsing of fields that have a page title set.
|
| 20 |
if (empty($field->page)) {
|
| 21 |
drupal_not_found();
|
| 22 |
return;
|
| 23 |
}
|
| 24 |
// Do not allow browsing of private and hidden fields by non-admins.
|
| 25 |
if (!user_access('administer users') && ($field->visibility == PROFILE_PRIVATE || $field->visibility == PROFILE_HIDDEN)) {
|
| 26 |
drupal_access_denied();
|
| 27 |
return;
|
| 28 |
}
|
| 29 |
|
| 30 |
// Compile a list of fields to show.
|
| 31 |
$fields = db_query('SELECT name, title, type, weight, page FROM {profile_field} WHERE fid <> :fid AND visibility = :visibility ORDER BY weight', array(
|
| 32 |
':fid' => $field->fid,
|
| 33 |
':visibility' => PROFILE_PUBLIC_LISTINGS,
|
| 34 |
))->fetchAll();
|
| 35 |
|
| 36 |
$query = db_select('users')->extend('PagerDefault');
|
| 37 |
$query->join('profile_value', 'v', 'u.uid = v.uid');
|
| 38 |
$query
|
| 39 |
->fields('u', array('uid', 'access'))
|
| 40 |
->condition('v.fid', $field->fid)
|
| 41 |
->condition('u.access', 0, '<>')
|
| 42 |
->condition('u.status', 0, '<>')
|
| 43 |
->orderBy('u.access', 'DESC');
|
| 44 |
|
| 45 |
// Determine what query to use:
|
| 46 |
$arguments = array($field->fid);
|
| 47 |
switch ($field->type) {
|
| 48 |
case 'checkbox':
|
| 49 |
$query->condition('v.value', 1);
|
| 50 |
break;
|
| 51 |
case 'textfield':
|
| 52 |
case 'selection':
|
| 53 |
$query->condition('v.value', $value);
|
| 54 |
break;
|
| 55 |
case 'list':
|
| 56 |
$query->condition('v.value', '%' . $value . '%', 'LIKE');
|
| 57 |
break;
|
| 58 |
default:
|
| 59 |
drupal_not_found();
|
| 60 |
return;
|
| 61 |
}
|
| 62 |
|
| 63 |
$uids = $query
|
| 64 |
->limit(20)
|
| 65 |
->execute()
|
| 66 |
->fetchCol();
|
| 67 |
|
| 68 |
// Load the users.
|
| 69 |
$users = user_load_multiple($uids);
|
| 70 |
|
| 71 |
$content = '';
|
| 72 |
foreach ($users as $account) {
|
| 73 |
$profile = _profile_update_user_fields($fields, $account);
|
| 74 |
$content .= theme('profile_listing', array('account' => $account, 'fields' => $profile));
|
| 75 |
}
|
| 76 |
$output = theme('profile_wrapper', array('content' => $content));
|
| 77 |
$output .= theme('pager', array('tags' => NULL));
|
| 78 |
|
| 79 |
if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
|
| 80 |
$title = strtr(check_plain($field->page), array('%value' => theme('placeholder', array('text' => $value))));
|
| 81 |
}
|
| 82 |
else {
|
| 83 |
$title = check_plain($field->page);
|
| 84 |
}
|
| 85 |
|
| 86 |
drupal_set_title($title, PASS_THROUGH);
|
| 87 |
return $output;
|
| 88 |
}
|
| 89 |
elseif ($name && !$field->fid) {
|
| 90 |
drupal_not_found();
|
| 91 |
}
|
| 92 |
else {
|
| 93 |
// Compile a list of fields to show.
|
| 94 |
$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();
|
| 95 |
|
| 96 |
// Extract the affected users:
|
| 97 |
$query = db_select('users', 'u')->extend('PagerDefault');
|
| 98 |
$uids = $query
|
| 99 |
->fields('u', array('uid', 'access'))
|
| 100 |
->condition('u.uid', 0, '>')
|
| 101 |
->condition('u.status', 0, '>')
|
| 102 |
->condition('u.access', 0, '>')
|
| 103 |
->orderBy('u.access', 'DESC')
|
| 104 |
->limit(20)
|
| 105 |
->execute()
|
| 106 |
->fetchCol();
|
| 107 |
$users = user_load_multiple($uids);
|
| 108 |
$content = '';
|
| 109 |
foreach ($users as $account) {
|
| 110 |
$profile = _profile_update_user_fields($fields, $account);
|
| 111 |
$content .= theme('profile_listing', array('account' => $account, 'fields' => $profile));
|
| 112 |
}
|
| 113 |
$output = theme('profile_wrapper', array('content' => $content));
|
| 114 |
$output .= theme('pager', array('tags' => NULL));
|
| 115 |
|
| 116 |
drupal_set_title(t('User list'));
|
| 117 |
return $output;
|
| 118 |
}
|
| 119 |
}
|
| 120 |
|
| 121 |
/**
|
| 122 |
* Callback to allow autocomplete of profile text fields.
|
| 123 |
*/
|
| 124 |
function profile_autocomplete($field, $string) {
|
| 125 |
$matches = array();
|
| 126 |
$autocomplete_field = (bool) db_query_range("SELECT 1 FROM {profile_field} WHERE fid = :fid AND autocomplete = 1", 0, 1, array(':fid' => $field))->fetchField();
|
| 127 |
if ($autocomplete_field) {
|
| 128 |
$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(
|
| 129 |
':fid' => $field,
|
| 130 |
':value' => $string . '%',
|
| 131 |
))->fetchCol();
|
| 132 |
foreach ($values as $value) {
|
| 133 |
$matches[$value] = check_plain($value);
|
| 134 |
}
|
| 135 |
}
|
| 136 |
|
| 137 |
drupal_json_output($matches);
|
| 138 |
}
|