summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2006-03-10 15:11:07 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2006-03-10 15:11:07 +0000
commit9c944c2d5871db0e3058f7a1c18b858ca03c05e4 (patch)
tree8cccef4152e51cebd4ce88a0ac59acbbb16049e9
parent9fd6dc58182ca07e106924b0c7c1b6c51350d515 (diff)
downloadbrdo-9c944c2d5871db0e3058f7a1c18b858ca03c05e4.tar.gz
brdo-9c944c2d5871db0e3058f7a1c18b858ca03c05e4.tar.bz2
- Code cleanup
-rw-r--r--modules/profile.module39
-rw-r--r--modules/profile/profile.module39
-rw-r--r--modules/user.module13
-rw-r--r--modules/user/user.module13
4 files changed, 90 insertions, 14 deletions
diff --git a/modules/profile.module b/modules/profile.module
index 34fbb55f0..887f80763 100644
--- a/modules/profile.module
+++ b/modules/profile.module
@@ -614,6 +614,45 @@ function profile_admin_delete($fid) {
}
}
+function profile_search($op = 'search', $keys = null) {
+ switch ($op) {
+ case 'name':
+ if (user_access('access user profiles')) {
+ return t('users');
+ }
+ case 'search':
+ if (user_access('access user profiles')) {
+ $find = array();
+ // Replace wildcards with MySQL/PostgreSQL wildcards.
+ $keys = preg_replace('!\*+!', '%', $keys);
+ if (user_access('administer users')) {
+ // administrators don't have restrictions
+ $result = pager_query("SELECT u.* FROM {users} u INNER JOIN {profile_values} pv ON u.uid = pv.uid WHERE LOWER(pv.value) LIKE LOWER('%%%s%%') OR LOWER(u.name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys, $keys);
+ }
+ else {
+ // non-administrators can only search public fields and active users
+ $result = pager_query("SELECT u.* FROM {users} u INNER JOIN {profile_values} pv ON u.uid = pv.uid INNER JOIN {profile_fields} pf ON pv.fid = pf.fid WHERE ((LOWER(pv.value) LIKE LOWER('%%%s%%') AND pf.visibility IN (%d, %d)) OR LOWER(u.name) LIKE LOWER('%%%s%%')) AND u.status = 1", 15, 0, NULL, $keys, PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS, $keys);
+ }
+
+ while ($account = db_fetch_object($result)) {
+ $user = user_load(array('uid' => $account->uid));
+ $profile_fields = profile_view_profile($user);
+
+ $entry = array();
+ foreach ($profile_fields as $category => $fields) {
+ foreach ($fields as $field) {
+ $entry[] = $field['value'];
+ }
+ }
+
+ $view = implode(' | ', $entry);
+ $find[] = array('title' => $account->name, 'link' => url("user/$account->uid/view"), 'snippet' => search_excerpt($keys, $view));
+ }
+ return $find;
+ }
+ }
+}
+
function _profile_field_form($type, $edit = array()) {
$form['fields'] = array('#type' => 'fieldset',
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 34fbb55f0..887f80763 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -614,6 +614,45 @@ function profile_admin_delete($fid) {
}
}
+function profile_search($op = 'search', $keys = null) {
+ switch ($op) {
+ case 'name':
+ if (user_access('access user profiles')) {
+ return t('users');
+ }
+ case 'search':
+ if (user_access('access user profiles')) {
+ $find = array();
+ // Replace wildcards with MySQL/PostgreSQL wildcards.
+ $keys = preg_replace('!\*+!', '%', $keys);
+ if (user_access('administer users')) {
+ // administrators don't have restrictions
+ $result = pager_query("SELECT u.* FROM {users} u INNER JOIN {profile_values} pv ON u.uid = pv.uid WHERE LOWER(pv.value) LIKE LOWER('%%%s%%') OR LOWER(u.name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys, $keys);
+ }
+ else {
+ // non-administrators can only search public fields and active users
+ $result = pager_query("SELECT u.* FROM {users} u INNER JOIN {profile_values} pv ON u.uid = pv.uid INNER JOIN {profile_fields} pf ON pv.fid = pf.fid WHERE ((LOWER(pv.value) LIKE LOWER('%%%s%%') AND pf.visibility IN (%d, %d)) OR LOWER(u.name) LIKE LOWER('%%%s%%')) AND u.status = 1", 15, 0, NULL, $keys, PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS, $keys);
+ }
+
+ while ($account = db_fetch_object($result)) {
+ $user = user_load(array('uid' => $account->uid));
+ $profile_fields = profile_view_profile($user);
+
+ $entry = array();
+ foreach ($profile_fields as $category => $fields) {
+ foreach ($fields as $field) {
+ $entry[] = $field['value'];
+ }
+ }
+
+ $view = implode(' | ', $entry);
+ $find[] = array('title' => $account->name, 'link' => url("user/$account->uid/view"), 'snippet' => search_excerpt($keys, $view));
+ }
+ return $find;
+ }
+ }
+}
+
function _profile_field_form($type, $edit = array()) {
$form['fields'] = array('#type' => 'fieldset',
diff --git a/modules/user.module b/modules/user.module
index ca7239f96..859c6aa9c 100644
--- a/modules/user.module
+++ b/modules/user.module
@@ -508,7 +508,6 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
$form['user_block_seconds_online'] = array('#type' => 'select', '#title' => t('User activity'), '#default_value' => variable_get('user_block_seconds_online', 900), '#options' => $period, '#description' => t('A user is considered online for this long after they have last viewed a page.'));
$form['user_block_max_list_count'] = array('#type' => 'select', '#title' => t('User list length'), '#default_value' => variable_get('user_block_max_list_count', 10), '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), '#description' => t('Maximum number of currently online users to display.'));
- //return drupal_get_form('user_block', $form);
return $form;
}
else if ($op == 'save' && $delta == 3) {
@@ -561,7 +560,7 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
case 2:
if (user_access('access content')) {
- //Retrieve a list of new users who have subsequently accessed the site successfully.
+ // Retrieve a list of new users who have subsequently accessed the site successfully.
$result = db_query_range('SELECT uid, name FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC', 0, 5);
while ($account = db_fetch_object($result)) {
$items[] = $account;
@@ -687,7 +686,7 @@ function user_menu($may_cache) {
$admin_access = user_access('administer users');
$access_access = user_access('administer access control');
- // users should always be allowed to see their own user page
+ // Users should always be allowed to see their own user page
$view_access = (user_access('access user profiles') || ($user->uid == arg(1)));
if ($may_cache) {
@@ -697,7 +696,7 @@ function user_menu($may_cache) {
$items[] = array('path' => 'user/autocomplete', 'title' => t('user autocomplete'),
'callback' => 'user_autocomplete', 'access' => $view_access, 'type' => MENU_CALLBACK);
- //registration and login pages.
+ // Registration and login pages.
$items[] = array('path' => 'user/login', 'title' => t('log in'),
'callback' => 'user_login', 'type' => MENU_DEFAULT_LOCAL_TASK);
$items[] = array('path' => 'user/register', 'title' => t('register'),
@@ -709,7 +708,7 @@ function user_menu($may_cache) {
$items[] = array('path' => 'user/help', 'title' => t('help'),
'callback' => 'user_help_page', 'type' => MENU_CALLBACK);
- //admin user pages
+ // Admin user pages
$items[] = array('path' => 'admin/user', 'title' => t('users'),
'callback' => 'user_admin', 'access' => $admin_access);
$items[] = array('path' => 'admin/user/list', 'title' => t('list'),
@@ -720,7 +719,7 @@ function user_menu($may_cache) {
$items[] = array('path' => 'admin/settings/user', 'title' => t('users'),
'callback' => 'user_configure');
- //admin access pages
+ // Admin access pages
$items[] = array('path' => 'admin/access', 'title' => t('access control'),
'callback' => 'user_admin_perm', 'access' => $access_access);
$items[] = array('path' => 'admin/access/permissions', 'title' => t('permissions'),
@@ -756,7 +755,7 @@ function user_menu($may_cache) {
'type' => MENU_LOCAL_TASK);
}
- //Your personal page
+ // Your personal page
if ($user->uid) {
$items[] = array('path' => 'user/'. $user->uid, 'title' => t('my account'),
'callback' => 'user_view', 'callback arguments' => array(arg(1)), 'access' => TRUE,
diff --git a/modules/user/user.module b/modules/user/user.module
index ca7239f96..859c6aa9c 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -508,7 +508,6 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
$form['user_block_seconds_online'] = array('#type' => 'select', '#title' => t('User activity'), '#default_value' => variable_get('user_block_seconds_online', 900), '#options' => $period, '#description' => t('A user is considered online for this long after they have last viewed a page.'));
$form['user_block_max_list_count'] = array('#type' => 'select', '#title' => t('User list length'), '#default_value' => variable_get('user_block_max_list_count', 10), '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), '#description' => t('Maximum number of currently online users to display.'));
- //return drupal_get_form('user_block', $form);
return $form;
}
else if ($op == 'save' && $delta == 3) {
@@ -561,7 +560,7 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
case 2:
if (user_access('access content')) {
- //Retrieve a list of new users who have subsequently accessed the site successfully.
+ // Retrieve a list of new users who have subsequently accessed the site successfully.
$result = db_query_range('SELECT uid, name FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC', 0, 5);
while ($account = db_fetch_object($result)) {
$items[] = $account;
@@ -687,7 +686,7 @@ function user_menu($may_cache) {
$admin_access = user_access('administer users');
$access_access = user_access('administer access control');
- // users should always be allowed to see their own user page
+ // Users should always be allowed to see their own user page
$view_access = (user_access('access user profiles') || ($user->uid == arg(1)));
if ($may_cache) {
@@ -697,7 +696,7 @@ function user_menu($may_cache) {
$items[] = array('path' => 'user/autocomplete', 'title' => t('user autocomplete'),
'callback' => 'user_autocomplete', 'access' => $view_access, 'type' => MENU_CALLBACK);
- //registration and login pages.
+ // Registration and login pages.
$items[] = array('path' => 'user/login', 'title' => t('log in'),
'callback' => 'user_login', 'type' => MENU_DEFAULT_LOCAL_TASK);
$items[] = array('path' => 'user/register', 'title' => t('register'),
@@ -709,7 +708,7 @@ function user_menu($may_cache) {
$items[] = array('path' => 'user/help', 'title' => t('help'),
'callback' => 'user_help_page', 'type' => MENU_CALLBACK);
- //admin user pages
+ // Admin user pages
$items[] = array('path' => 'admin/user', 'title' => t('users'),
'callback' => 'user_admin', 'access' => $admin_access);
$items[] = array('path' => 'admin/user/list', 'title' => t('list'),
@@ -720,7 +719,7 @@ function user_menu($may_cache) {
$items[] = array('path' => 'admin/settings/user', 'title' => t('users'),
'callback' => 'user_configure');
- //admin access pages
+ // Admin access pages
$items[] = array('path' => 'admin/access', 'title' => t('access control'),
'callback' => 'user_admin_perm', 'access' => $access_access);
$items[] = array('path' => 'admin/access/permissions', 'title' => t('permissions'),
@@ -756,7 +755,7 @@ function user_menu($may_cache) {
'type' => MENU_LOCAL_TASK);
}
- //Your personal page
+ // Your personal page
if ($user->uid) {
$items[] = array('path' => 'user/'. $user->uid, 'title' => t('my account'),
'callback' => 'user_view', 'callback arguments' => array(arg(1)), 'access' => TRUE,