function sbp_users_sbp_paths in Search by Page 7
Same name and namespace in other branches
- 6 sbp_users.module \sbp_users_sbp_paths()
Implements 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')
->fetchAll();
}
else {
$rids = array();
foreach ($rolelist as $key => $item) {
if ($item) {
$rids[] = $key;
}
}
if (!count($rids)) {
return array();
}
$query = db_select('users', 'u')
->fields('u', array(
'uid',
'language',
));
$query
->join('users_roles', 'ur', 'u.uid = ur.uid');
$query
->condition('u.status', 1)
->condition('ur.rid', $rids, 'IN');
$res = $query
->execute()
->fetchAll();
}
// 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();
foreach ($res as $item) {
$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;
}