You are here

function sbp_users_sbp_paths in Search by Page 6

Same name and namespace in other branches
  1. 7 sbp_users.module \sbp_users_sbp_paths()

Implementation of Search by Page hook_sbp_paths().

Returns a list of all the user pages that should be indexed.

File

./sbp_users.module, line 16
Module file for Search by Page Users, a sub-module for Search by Page.

Code

function sbp_users_sbp_paths($environment) {

  // What user roles do they want to index?
  $rolelist = search_by_page_setting_get('sbp_users_roles_indexed', $environment, array());
  if (!is_array($rolelist) || !count($rolelist)) {
    return array();
  }

  // This variable comes from a checkbox array form element. So it
  // gives us an array like '3' => '3', '4' => 0
  // meaning role ID 3 should be indexed, but not 4,
  // so pick out the ones to actually index
  // Special case: if they chose Authenticated User, they want all users,
  // but only non-blocked and skip user 0 (non-logged-in user placeholder).
  $doall = $rolelist[DRUPAL_AUTHENTICATED_RID];
  if ($doall) {
    $res = db_query('SELECT u.uid, u.language FROM {users} u WHERE u.status=1 AND u.uid > 0');
  }
  else {
    $args = array();
    foreach ($rolelist as $key => $item) {
      if ($item) {
        $args[] = $key;
      }
    }
    if (!count($args)) {
      return array();
    }
    $res = db_query('SELECT u.uid, u.language FROM {users} u JOIN {users_roles} ur ON u.uid = ur.uid WHERE u.status=1 AND ur.rid IN (' . db_placeholders($args, 'int') . ')', $args);
  }

  // Build an array of paths
  $min_time = search_by_page_setting_get('sbp_users_min_time', $environment, 1);
  $max_time = search_by_page_setting_get('sbp_users_max_time', $environment, 0);
  $langs = language_list();
  $langs = array_keys($langs);
  $lang_opt = 'all';
  if (count($langs) > 1) {
    $lang_opt = search_by_page_setting_get('sbp_users_language', $environment, 'all');
  }
  $role = search_by_page_setting_get('sbp_users_role', $environment, DRUPAL_ANONYMOUS_RID);
  $ret = array();
  while ($item = db_fetch_object($res)) {
    $stuff = array(
      'id' => $item->uid,
      'role' => $role,
      'min_time' => $min_time,
      'max_time' => $max_time,
    );
    if ($lang_opt == 'user') {
      $stuff['languages'] = array(
        $item->language,
      );
    }
    else {
      $stuff['languages'] = $langs;
    }
    $ret['user/' . $item->uid] = $stuff;
  }
  return $ret;
}