You are here

function xmlsitemap_user_user in XML sitemap 5.2

Same name and namespace in other branches
  1. 5 xmlsitemap_user/xmlsitemap_user.module \xmlsitemap_user_user()
  2. 6.2 xmlsitemap_user/xmlsitemap_user.module \xmlsitemap_user_user()
  3. 6 xmlsitemap_user/xmlsitemap_user.module \xmlsitemap_user_user()

Implementation of hook_user().

File

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

Code

function xmlsitemap_user_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'form':
      if ($category != 'account') {
        return array();
      }
    case 'register':
      $priority = db_result(db_query("SELECT priority_override FROM {xmlsitemap_user} WHERE uid = %d", $account->uid));
      if (isset($account->roles)) {
        $roles = array_keys($account->roles);
        $default = db_fetch_object(db_query("SELECT MIN(priority) AS min, SUM(priority) AS sum FROM {xmlsitemap_user_role} WHERE rid IN (" . xmlsitemap_placeholders($roles, 'int') . ")", $roles));
      }
      if (isset($default->min) && isset($default->sum)) {
        $default_priority = $default->min < 0 ? -1 : round(min($default->sum, 1), 1);
      }
      else {
        $default_priority = variable_get('xmlsitemap_user_default_priority', '0.5');
      }
      $disabled = !user_access('administer users');
      $form = array();
      if (user_access('override profile settings')) {
        $form['xmlsitemap_user'] = array(
          '#type' => 'fieldset',
          '#title' => t('sitemap settings'),
          '#collapsible' => TRUE,
          '#weight' => 7,
        );
        $options = xmlsitemap_priority_options('both');
        $form['xmlsitemap']['xmlsitemap_user_priority'] = array(
          '#type' => 'select',
          '#title' => t('Priority'),
          '#default_value' => $priority !== FALSE ? $priority : 'NULL',
          '#options' => $options,
          '#disabled' => $disabled,
          '#description' => t('The default priority is %priority.', array(
            '%priority' => $options[(string) $default_priority],
          )),
        );
        $form['xmlsitemap_user']['xmlsitemap_user_priority'] = array(
          '#type' => 'select',
          '#title' => t('sitemap priority'),
          '#default_value' => isset($priority) ? $priority : 'NULL',
          '#options' => $options,
          '#description' => t('The default priority is %priority.', array(
            '%priority' => $options[$default],
          )),
        );
      }
      else {
        $form['xmlsitemap_user_priority'] = array(
          '#type' => 'value',
          '#value' => isset($priority) ? $priority : 'NULL',
        );
      }
      return $form;
    case 'insert':
      if (isset($edit['xmlsitemap_user_priority'])) {
        $priority = $edit['xmlsitemap_user_priority'];
      }
      else {
        $priority = db_result(db_query("SELECT priority_override FROM {xmlsitemap_user} WHERE uid = %d", $account->uid));
      }
      db_query("INSERT INTO {xmlsitemap_user} (uid, last_changed, priority_override) VALUES (%d, %d, %s)", $account->uid, REQUEST_TIME, isset($priority) && $priority !== FALSE ? $priority : 'NULL');
      xmlsitemap_flag_sitemap();
      break;
    case 'update':
      if (isset($edit['xmlsitemap_user_priority'])) {
        $priority = $edit['xmlsitemap_user_priority'];
      }
      else {
        $priority = db_result(db_query("SELECT priority_override FROM {xmlsitemap_user} WHERE uid = %d", $account->uid));
      }
      db_query("UPDATE {xmlsitemap_user}\n        SET previously_changed = last_changed, last_changed = %d, priority_override = %s\n        WHERE uid = %d", REQUEST_TIME, $priority !== FALSE ? $priority : 'NULL', $account->uid);
      xmlsitemap_flag_sitemap();
      break;
    case 'delete':
      db_query("DELETE FROM {xmlsitemap_user} WHERE uid = %d", $account->uid);
      xmlsitemap_flag_sitemap();
      break;
  }
}