profile.pages.inc

  1. 7.x drupal-7.x/modules/profile/profile.pages.inc
  2. 6.x drupal-6.x/modules/profile/profile.pages.inc

User page callbacks for the profile module.

File

drupal-6.x/modules/profile/profile.pages.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * User page callbacks for the profile module.
  5. */
  6. /**
  7. * Menu callback; display a list of user information.
  8. */
  9. function profile_browse() {
  10. // Ensure that the path is converted to 3 levels always.
  11. list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
  12. $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
  13. if ($name && $field->fid) {
  14. // Only allow browsing of fields that have a page title set.
  15. if (empty($field->page)) {
  16. drupal_not_found();
  17. return;
  18. }
  19. // Do not allow browsing of private and hidden fields by non-admins.
  20. if (!user_access('administer users') && ($field->visibility == PROFILE_PRIVATE || $field->visibility == PROFILE_HIDDEN)) {
  21. drupal_access_denied();
  22. return;
  23. }
  24. // Compile a list of fields to show.
  25. $fields = array();
  26. $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);
  27. while ($record = db_fetch_object($result)) {
  28. $fields[] = $record;
  29. }
  30. // Determine what query to use:
  31. $arguments = array($field->fid);
  32. switch ($field->type) {
  33. case 'checkbox':
  34. $query = 'v.value = 1';
  35. break;
  36. case 'textfield':
  37. case 'selection':
  38. $query = "v.value = '%s'";
  39. $arguments[] = $value;
  40. break;
  41. case 'list':
  42. $query = "v.value LIKE '%%%s%%'";
  43. $arguments[] = $value;
  44. break;
  45. default:
  46. drupal_not_found();
  47. return;
  48. }
  49. // Extract the affected users:
  50. $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);
  51. $content = '';
  52. while ($account = db_fetch_object($result)) {
  53. $account = user_load(array('uid' => $account->uid));
  54. $profile = _profile_update_user_fields($fields, $account);
  55. $content .= theme('profile_listing', $account, $profile);
  56. }
  57. $output = theme('profile_wrapper', $content);
  58. $output .= theme('pager', NULL, 20);
  59. if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
  60. $title = strtr(check_plain($field->page), array('%value' => theme('placeholder', $value)));
  61. }
  62. else {
  63. $title = check_plain($field->page);
  64. }
  65. drupal_set_title($title);
  66. return $output;
  67. }
  68. else if ($name && !$field->fid) {
  69. drupal_not_found();
  70. }
  71. else {
  72. // Compile a list of fields to show.
  73. $fields = array();
  74. $result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);
  75. while ($record = db_fetch_object($result)) {
  76. $fields[] = $record;
  77. }
  78. // Extract the affected users:
  79. $result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
  80. $content = '';
  81. while ($account = db_fetch_object($result)) {
  82. $account = user_load(array('uid' => $account->uid));
  83. $profile = _profile_update_user_fields($fields, $account);
  84. $content .= theme('profile_listing', $account, $profile);
  85. }
  86. $output = theme('profile_wrapper', $content);
  87. $output .= theme('pager', NULL, 20);
  88. drupal_set_title(t('User list'));
  89. return $output;
  90. }
  91. }
  92. /**
  93. * Callback to allow autocomplete of profile text fields.
  94. */
  95. function profile_autocomplete($field, $string) {
  96. $matches = array();
  97. if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) {
  98. $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);
  99. while ($data = db_fetch_object($result)) {
  100. $matches[$data->value] = check_plain($data->value);
  101. }
  102. }
  103. drupal_json($matches);
  104. }