function xmlsitemap_user_xmlsitemap_links in XML sitemap 5.2
Same name and namespace in other branches
- 5 xmlsitemap_user/xmlsitemap_user.module \xmlsitemap_user_xmlsitemap_links()
- 6 xmlsitemap_user/xmlsitemap_user.module \xmlsitemap_user_xmlsitemap_links()
Implementation of hook_xmlsitemap_links().
File
- xmlsitemap_user/
xmlsitemap_user.module, line 158 - Adds user profiles to the sitemap.
Code
function xmlsitemap_user_xmlsitemap_links() {
$anonymous = user_load(array(
'uid' => 0,
));
if (user_access('access user profiles', $anonymous)) {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$coalesce = 'COALESCE';
break;
case 'pgsql':
$coalesce = 'FIRST';
break;
}
$uid = 0;
$frontpage = explode('/', drupal_get_normal_path(variable_get('site_frontpage', 'node')));
if (count($frontpage) == 2 && $frontpage[0] == 'user' && is_numeric($frontpage[1])) {
$uid = $frontpage[1];
}
$result = db_query("SELECT u.uid, xu.last_changed, xu.previously_changed, xu.priority_override, SUM(xur.priority) as priority, {$coalesce}(ua.dst) AS alias\n FROM {users} u\n LEFT JOIN {users_roles} ur ON u.uid = ur.uid\n LEFT JOIN {xmlsitemap_user_role} xur ON ur.rid = xur.rid\n LEFT JOIN {xmlsitemap_user} xu ON u.uid = xu.uid\n LEFT JOIN {url_alias} ua ON ua.src = CONCAT('user/', u.uid)\n WHERE (xu.priority_override IS NULL OR xu.priority_override >= 0) AND u.uid <> %d AND u.uid > 0 AND u.status <> 0\n GROUP BY u.uid, xu.last_changed, xu.previously_changed, xu.priority_override\n HAVING COUNT(xu.priority_override) > 0 OR (SUM(xur.priority) IS NULL AND %f <> -1 OR MIN(xur.priority) <> -1)", $uid, variable_get('xmlsitemap_user_default_priority', 0.5));
while ($user = db_fetch_object($result)) {
$age = REQUEST_TIME - $user->last_changed;
$interval = empty($user->previously_changed) ? 0 : $user->last_changed - $user->previously_changed;
if (isset($user->priority_override)) {
$priority = $user->priority_override;
}
else {
$priority = min(isset($user->priority) ? $user->priority : variable_get('xmlsitemap_user_default_priority', 0.5), 1);
}
db_query("INSERT INTO {xmlsitemap} (loc, lastmod, changefreq, priority) VALUES ('%s', %d, %d, %f)", xmlsitemap_url("user/{$user->uid}", $user->alias, NULL, NULL, TRUE), $user->last_changed, max($age, $interval), $priority);
}
}
}