You are here

function xmlsitemap_user_get_priority in XML sitemap 6

Get the user priority in the sitemap.

Parameters

$user: The user object.

$load: TRUE, if priority_override must be loaded from the module table.

Return value

The priority for the user.

See also

xmlsitemap_user_set_priority()

1 call to xmlsitemap_user_get_priority()
xmlsitemap_user_xmlsitemap_links in xmlsitemap_user/xmlsitemap_user.module
Implementation of hook_xmlsitemap_links().

File

xmlsitemap_user/xmlsitemap_user.module, line 240
Adds user profiles to the sitemap.

Code

function xmlsitemap_user_get_priority($user, $load = FALSE) {
  if (!isset($user->priority_override) && $load && $user->uid) {
    $priority_override = db_result(db_query("SELECT xu.priority_override FROM {xmlsitemap_user} xu WHERE xu.uid = %d", $user->uid));
    if ($priority_override !== FALSE) {
      $user->priority_override = $priority_override;
    }
  }
  if (isset($user->priority_override) && $user->priority_override != -2.0) {
    $priority = $user->priority_override;
  }
  else {
    $default = db_fetch_object(db_query("SELECT MIN(xur.priority) AS min, SUM(xur.priority) AS sum\n        FROM {users_roles} ur\n        INNER JOIN {xmlsitemap_user_role} xur ON xur.rid = ur.rid\n        WHERE ur.uid = %d", $user->uid));
    if (isset($default->min) && isset($default->sum)) {
      $priority = $default->min < 0 ? -1.0 : round(min($default->sum, 1.0), 1);
    }
    else {
      $priority = variable_get('xmlsitemap_user_default_priority', 0.5);
    }
  }
  if (!isset($priority) || !$user->status || !$user->access) {
    $priority = -1.0;
  }
  return $priority;
}