Hi all,

I am a newbie and i do not have experience to PHP just a normal end user. I managed to install Drupal 5.1 by following the instructions and everything is going well so far. however there is one module that i need to implement in my alumni website.

to be short, I am making a website for alumni where users can go and register their names and info. i managed to add required fields that they have to fill in, like first name, last name, company name, etc. using the portfolio and user modules. now i need to allow other users to search for any of those alumni on the website. i found a module called user search but it does not work on version 5.1 of Drupal.

Is there any one who's upgrading this module or developing similar module? what do you recommend??

I appreciate if the information you provide me is basic info :)

thanks

Comments

davemybes’s picture

Gee, whaddyaknow, I'm doing the exact same thing as you, and I also need that functionality. I am busy looking at the profileplus module, which works pretty well. There is a patch to upgrade it to 5.0 which supposedly works. I haven't tried it out yet as I need it for 4.7 at the moment. The main problem with it is that it only works with single search words - type in two words and you get no results (I believe that user search module also does not work with multiple keywords).

In its current form, the module removes the user tab from search page and adds a profile tab. However, the module does not actually search usernames. I have just provided a patch to fix that in the HEAD version. This patch will have to be implemented in the 5.0 version too if you want to be able to search for usernames as well as profile fields.

______________________________________________________________________________________________________
Need help? Check the FAQ and the Handbooks first.

______________________________________________________________________________________________________

pixel13’s picture

I'm also interested in this (so I bookmark this page). Anyway, I think there's no module to do this for Drupal 5, since both User Search and Profileplus are for Drupal 4 only. Have a look at this:

http://drupal.org/node/119088

There are some tips to upgrade Profileplus to Drupal 5, but I don't tried it yet.

kash82’s picture

hi

I am currently reading how to apply patches and i will try to apply this patch. I'll try to see if there are any solutions and i will inform you guys if i find anything. keep me posted as well

thax

designwork’s picture

Hi folks

it´s already done. Take this code an called it profileplus.module, Than you need to add an info file like this.

Dirk

here is the info

name = ProfilePlus
description = Search custom profile fields
package = Social networking

here is the module

<?php
// profileplus.module,v 1.2 2006/04/23 01:07:50 budda Exp
/*
* ProfilePlus adds additional functionality to the core profile.module
*
* @author Mike Carter
*/

/**
* Implementation of hook_help().
*/
function profileplus_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Makes user profiles searchable');
}
}

/**
* Hide the default 'users' tab from the search page as it is useless
*/
function profileplus_menu($may_cache) {
$items = array();

if ($may_cache) {
// Settings page
$items[] = array('path' => 'admin/settings/profileplus',
'title' => t('Fotografen Suche'),
'description' => t('Profile Plus Configuration Settings'),
'callback' => 'drupal_get_form',
'callback arguments' => 'profileplus_admin_settings',
'access' => user_access('administer site configuration'),
);
}
return $items;
}

/*
* Implementation of hook_search()
*/
function profileplus_search($op = 'search', $keys = null) {
global $user;
switch ($op) {
case 'name':
if (user_access('access user profiles')) {
return t('Profiles');
}
case 'search':
if (user_access('access user profiles')) {
// Check if a browse option was submitted
$result = profileplus_get_browse_fields();
while ($field = db_fetch_object($result)) {
if ($value = search_query_extract($keys, $field->name)) {
drupal_goto('profile/'.$field->name.'/'.urldecode($value));
exit();
}
}
//If not browsing do a normal search
$find = array();
// Replace wildcards with MySQL/PostgreSQL wildcards.
$keys = preg_replace('!\*+!', '%', $keys);
if (user_access('administer users')) {
// administrators don't have restrictions
$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 LOWER(pv.value) LIKE LOWER('%%%s%%')";
$result = pager_query('SELECT DISTINCT u.uid, u.access '.$sql, variable_get('profileplus_results_per_page', 5), 0, 'SELECT COUNT(DISTINCT u.uid) '.$sql, $keys);
}
else {
// non-administrators can only search public fields and active users
$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 LOWER(pv.value) LIKE LOWER('%%%s%%') AND pf.visibility IN (%d) AND u.status = 1 AND u.uid != %d";
$result = pager_query('SELECT DISTINCT u.uid, u.access '.$sql, variable_get('profileplus_results_per_page', 5), 0, 'SELECT COUNT(DISTINCT u.uid) '.$sql, $keys, PROFILE_PUBLIC_LISTINGS, $user->uid);
}

$fields = array();
$fieldsresult = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE visibility = %d ORDER BY weight', PROFILE_PUBLIC_LISTINGS);
while ($record = db_fetch_object($fieldsresult)) {
$fields[] = $record;
}

while ($account = db_fetch_object($result)) {
$account = user_load(array('uid' => $account->uid));
$profile = _profile_update_user_fields($fields, $account);
$find[] = array('snippet' => theme('profile_listing', $account, $profile));
}

if (count($find) == 0)
$find[] = array('snippet' => "No matches were found.");

return $find;
}
}
}

/**
* Administration settings page
*/
function profileplus_admin_settings() {
$form['search_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Search Options'),
);
$form['search_settings']['profileplus_results_per_page'] = array(
'#type' => 'select',
'#title' => t('Number of matches to show per page'),
'#default_value' => variable_get('profileplus_results_per_page', 5),
'#options' => drupal_map_assoc(range(0, 10)),
'#description' => t('User matches per page'),
);

return system_settings_form($form);
}

function profileplus_get_browse_fields() {
$sql = 'SELECT * FROM {profile_fields} WHERE ';
$filters = array();
$filters[] = 'visibility = %d';
$args[] = PROFILE_PUBLIC_LISTINGS;
$filters[] = 'page IS NOT null';
$filters[] = 'page != ""';
$sql .= implode(' AND ', $filters);
$sql .= ' ORDER BY category, weight';
return db_query($sql, $args);
}

/**
* Implementation of hook_form_alter().
*/
function profileplus_form_alter($form_id, &$form) {
// Advanced node search form
if ($form_id == 'search_form' && arg(1) == 'profileplus') {
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Browse by Category'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#attributes' => array('class' => 'search-advanced'),
);
$form['advanced']['browse'] = array(
'#prefix' => '

You can browse members in any of the following categories.',
'#suffix' => '

',
);

$result = profileplus_get_browse_fields();
while ($field = db_fetch_object($result)) {
switch ($field->type) {
case 'textfield':
case 'url':
$form['advanced']['browse'][$field->name] = array('#type' => 'textfield',
'#title' => check_plain($field->title),
'#default_value' => NULL,
'#maxlength' => 255,
'#description' => _profile_form_explanation($field),
);
if ($field->autocomplete) {
$form['advanced']['browse'][$field->name]['#autocomplete_path'] = "profile/autocomplete/". $field->fid;
}
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;
}
}
$form['advanced']['browse'][$field->name] = array('#type' => 'select',
'#title' => check_plain($field->title),
'#default_value' => NULL,
'#options' => $options,
'#description' => _profile_form_explanation($field),
);
break;
}
$form['advanced']['browse'][$field->name.'_submit'] = array(
'#type' => 'submit',
'#name' => 'go_'.$field->name,
'#value' => t('Browse by '.$field->title),
);
}

$form['#validate']['profileplus_search_validate'] = array();
$form['clear'] = array('#value' => '

');
}
}

/**
* Form API callback for the profile browse form. Registered in profileplus_form_alter().
*/
function profileplus_search_validate($form_id, $form_values, $form) {
//drupal_set_message(drupal_to_js($form_values));
$result = profileplus_get_browse_fields();
while ($field = db_fetch_object($result)) {
if (isset($form_values['go_'.$field->name])) {
$keys = search_query_insert('', $field->name, urlencode($form_values[$field->name]));
break;
}
}
if (!empty($keys)) {
form_set_value($form['basic']['inline']['processed_keys'], trim($keys));
}
}

davemybes’s picture

Thanks for the Drupal 5.x version, it works fine, but only if you have a single keyword - multiple keywords give no results.

For those of you who want multiple keyword searching, I have gotten my 4.7 version to work now and have the paging working too. Maybe we can merge the two versions somehow?

Here's the code for the 4.7.x version (save it as profileplus.module), all comments/criticisms/etc. welcome:

// profileplus.module,v 1.3 2007/03/20 18:23:33 budda Exp
/*
 * ProfilePlus adds additional functionality to the core profile.module
 *
 * @author Mike Carter <mike@ixis.co.uk>
 */

/**
 * Implementation of hook_help().
 */
function profileplus_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Makes user profiles searchable');
   }
}


/**
 * Implementation of hook_perm().
 */
function profileplus_perm() {
  return array('search user profiles');
}


/*
 * Implementation of hook_search()
 */
function profile_search($op = 'search', $keys = null) {
  switch ($op) {
    case 'name':
      if (user_access('access user profiles')) {
        return t('profiles');
      }
    case 'search':
      if (user_access('access user profiles')) {
        $find = array();
        $keywords = explode(' ', check_plain(strip_tags($keys)));
        $i = count($keywords);
        $keys = preg_replace('!\*+!', '%', $keys);

        if ($i > 0){
          $users = array();
          while ($i > 0) {
            $j = $i - 1;
            if (user_access('administer users')) {
            // administrators don't have restrictions
              $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%%'";
              $result = db_query('SELECT DISTINCT u.* '.$sql, $keywords[$j], $keywords[$j]);
            }
            elseif (user_access('search user profiles')) {
            // non-administrators can only search public fields and active users
              $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";
              $result = db_query('SELECT DISTINCT u.* '.$sql, $keywords[$j], $keywords[$j], PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
            }

            while ($auser = db_fetch_object($result)) {
              if (in_array($auser->uid,$users) && !in_array($auser->uid,$match)){
                $match[] = $auser->uid;
              }
              else {
                $users[] = $auser->uid;
              }
            }
            $i = $i - 1;
          }

          if ($match) {
            $items = $match;
          }
          else {
            $items = $users;
          }

          $finalsql = pager_query('SELECT * FROM {users} WHERE uid IN ('.implode(', ', $items).')');
            while ($pageditems = db_fetch_object($finalsql)) {
              $user = user_load(array('uid'=>$pageditems->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' => $user->name, 'link' => url("user/$user->uid/view"), 'snippet' => search_excerpt($keys, $view));
              }
            }

          return $find;
        }
      } // end search case
  }
}

function profileplus_install() {
  // new module weights in core: put profileplus after user.module
  $ret[] = db_query("UPDATE {system} SET weight = 2 WHERE name = 'profileplus'");
  return $ret;
}

This is also available on my website: http://mybesinformatik.com/profileplus, where I will post updates as (and when) I do them.

If someone has a better way of doing the multiple keyword search, I would love to know it. I've got the feeling that my way is a slow and clunky way to do it, but I can't think of another way to do it at the moment.

______________________________________________________________________________________________________
Need help? Check the FAQ and the Handbooks first.

______________________________________________________________________________________________________

kash82’s picture

hi ...
isn't this exactly the same code that comes with profileplus module or are there any changes in it ??

now i can see both the profiles and the user tab and the profiles search returns no value when i search by user name for example when i enter the username in the text field and i search it doe not work.

I added some fields like first name and last name but i cannot search both at the same time and also what is annoying is the search results because it gives the results with no titles and not organized.

is there any other module that you recommend for searching user profiles or may be any update of the current one?

thank you

davemybes’s picture

I have made some changes, and have posted a patch in the issue for this module. Until the module developer does something with my patch, I am providing the module from my own website. I have added multi-keyword searching, and modified the output a bit. You can get it here: http://mybesinformatik.com/profileplus.

______________________________________________________________________________________________________
Need help? Check the FAQ and the Handbooks first.

______________________________________________________________________________________________________

designwork’s picture

Hi incrn8,

i´m still in this module, but i was busy with an other webpage for a client. I´m new to drupal (only four weeks) so it takes some time for me to see how all this stuff works together. Now i´m trying to hack the profile.module its not realy good module at all. I want to have a gallery tab in my user profile. And even a cool gallery.module is missing.

Maybe you have some advice for me how to to a profile.page with different tabs like my profile, my gallery, my publications.

Im not shure if i have to hacck the hook_menu() or if there is a different way to do this.

Dirk

spooky69’s picture

The code posted above by incrn8 does appear to manage to search on multiple keywords, but there are the following errors:

1. Searching on more than one keyword gives the following error:

warning: in_array(): Wrong datatype for second argument in /myhoststuff/modules/profileplus/profileplus.module on line 60.

In the code I am using, line 60 would be around here:

while ($auser = db_fetch_object($result)) {
if (in_array($auser->uid,$users) && !in_array($auser->uid,$match)){ // LINE 60
$match[] = $auser->uid;
}

I have one user on the system that registered himself. This user was not showing in the results at all. Various errors were being shown (2 errors in your sql sort of thing). I went to the users profile, went to the edit page and then submitted an update without making any changes. Now the user is included in search results. This makes me wonder if custom profile fields completed on initial registration are being made available to the search.

2. When a search is done from the search box under the 'profile' tab the page gets reloaded on the 'content' tab instead of remaining on the 'profile' tab.

3. The 'user' tab is still showing, but this would seem somewhat redundant.

Finally, I would like to add that this really is a huge step forwards. I was astounded that drupal 5 had these great features to add fields and get a really good profile going but that the resulting profile could not be searched. Good stuff!!

I would be interested in your thoughts in relation to the above.

reggie75’s picture

to get rid of this error:

edit profileplus.module

add this line on line 46: (i.e. just below $users = array();)
$match = array();

the error is coming becuase $match is not defined before using it, so all you ahave to do is define it the way $user is defined.

someone has posted the whole code sippet here too:
http://mybesinformatik.com/profileplus

all the best!