/[drupal]/contributions/modules/profileplus/profileplus.module
ViewVC logotype

Contents of /contributions/modules/profileplus/profileplus.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Fri Apr 11 03:45:37 2008 UTC (19 months, 2 weeks ago) by incrn8
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +36 -15 lines
File MIME type: text/x-php
Initial release for Drupal 6.x.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Allows full searching of all user profile fields for Drupal 6
7 *
8 * @author Mike Carter <mike@ixis.co.uk>
9 * @author Dave Myburgh <dave@mybesinformatik.com>
10 *
11 */
12
13
14 /**
15 * Implementation of hook_help().
16 */
17 function profileplus_help($path, $arg) {
18 switch ($path) {
19 case 'admin/modules#description':
20 return t('Makes user profiles searchable');
21 }
22 }
23
24
25 /**
26 * Implementation of hook_perm().
27 */
28 function profileplus_perm() {
29 return array('search user profiles');
30 }
31
32
33 /*
34 * Implementation of hook_search().
35 */
36 function profile_search($op = 'search', $keys = null) {
37 switch ($op) {
38 case 'name':
39 if (user_access('access user profiles')) {
40 return t('User Profiles');
41 }
42 case 'search':
43 if (user_access('access user profiles')) {
44 $find = array();
45 $keywords = explode(' ', check_plain(strip_tags($keys)));
46 $i = count($keywords);
47 $keys = preg_replace('!\*+!', '%', $keys);
48
49 if ($i > 0) {
50 $users = array();
51 $match = array();
52 while ($i > 0) {
53 $j = $i - 1;
54 if (user_access('administer users')) {
55 // administrators don't have restrictions
56 $sql = "FROM {users} u INNER JOIN {profile_values} pv ON u.uid = pv.uid INNER JOIN {profile_fields} pf ON pv.fid = pf.fid WHERE pv.value LIKE '%%%s%%' OR u.name LIKE '%%%s%%'";
57 $result = db_query('SELECT DISTINCT u.* ' . $sql, $keywords[$j], $keywords[$j]);
58 }
59 elseif (user_access('search user profiles')) {
60 // non-administrators can only search public fields and active users
61 $sql = "FROM {users} u INNER JOIN {profile_values} pv ON u.uid = pv.uid INNER JOIN {profile_fields} pf ON pv.fid = pf.fid WHERE pv.value LIKE '%%%s%%' OR u.name LIKE '%%%s%%' AND pf.visibility IN (%d, %d) AND u.status = 1";
62 $result = db_query('SELECT DISTINCT u.* ' . $sql, $keywords[$j], $keywords[$j], PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
63 }
64
65 while ($auser = db_fetch_object($result)) {
66 if (in_array($auser->uid, $users) && !in_array($auser->uid, $match)) {
67 $match[] = $auser->uid;
68 }
69 else {
70 $users[] = $auser->uid;
71 }
72 }
73 $i = $i - 1;
74 }
75
76 if ($match) {
77 $items = $match;
78 }
79 else {
80 $items = $users;
81 }
82
83 if ($items) {
84 $finalsql = pager_query('SELECT * FROM {users} WHERE uid IN (' . implode(', ', $items) . ')');
85 while ($pageditems = db_fetch_object($finalsql)) {
86 // load the user object
87 $user = user_load(array('uid'=>$pageditems->uid));
88
89 // create the profile fields array
90 // Show private fields to administrators and people viewing their own account.
91 if (user_access('administer users') || $GLOBALS['user']->uid == $user->uid) {
92 $result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d ORDER BY category, weight', PROFILE_HIDDEN);
93 }
94 else {
95 $result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d AND visibility != %d ORDER BY category, weight', PROFILE_PRIVATE, PROFILE_HIDDEN);
96 }
97
98 $profile_fields = array();
99 while ($field = db_fetch_object($result)) {
100 if ($value = profile_view_field($user, $field)) {
101 $title = ($field->type != 'checkbox') ? check_plain($field->title) : NULL;
102 $item = array(
103 'title' => $title,
104 'value' => $value,
105 'class' => $field->name,
106 );
107 $profile_fields[$field->category][$field->name] = $item;
108 }
109 }
110
111 $entry = array();
112 foreach ($profile_fields as $category => $fields) {
113 foreach ($fields as $field) {
114 $entry[] = $field['value'];
115 }
116 $view = implode(' | ', $entry);
117 }
118 $find[] = array('title' => $user->name, 'link' => url("user/$user->uid"), 'snippet' => search_excerpt($keys, $view));
119 }
120 }
121 return $find;
122 }
123 } // end search case
124 }
125 }

  ViewVC Help
Powered by ViewVC 1.1.2