You are here

function xmlsitemap_user_user in XML sitemap 6

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

Implementation of hook_user().

File

xmlsitemap_user/xmlsitemap_user.module, line 100
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\n        FROM {xmlsitemap_user}\n        WHERE uid = %d", $account->uid));
      $options = xmlsitemap_priority_options('both');
      if (isset($account->roles)) {
        $roles = array_keys($account->roles);
        $default = db_fetch_object(db_query("SELECT MIN(priority) AS min, SUM(priority) AS sum\n            FROM {xmlsitemap_user_role}\n            WHERE rid IN (" . db_placeholders($roles, 'varchar') . ")", $roles));
      }
      if (isset($default->min) && isset($default->sum)) {
        $default_priority = $default->min < 0 ? -1.0 : round(min($default->sum, 1), 1);
      }
      else {
        $default_priority = variable_get('xmlsitemap_user_default_priority', 0.5);
      }
      $form = xmlsitemap_user_form_fieldset();
      $form['xmlsitemap']['xmlsitemap_user_priority'] = array(
        '#type' => 'select',
        '#title' => t('User priority'),
        '#description' => t('The default priority is %priority.', array(
          '%priority' => $options[(string) $default_priority],
        )),
        '#default_value' => $priority !== FALSE ? $priority : -2.0,
        '#options' => $options,
      );
      return $form;
    case 'insert':
      if ($account->status) {
        $row = new stdClass();
        $row->uid = $account->uid;
        $row->changed = !empty($account->access) ? $account->access : REQUEST_TIME;
        $row->previously_changed = $account->created;
        $row->priority_override = isset($edit['xmlsitemap_user_priority']) ? $edit['xmlsitemap_user_priority'] : -2.0;
        drupal_write_record('xmlsitemap_user', $row);
        $edit['xmlsitemap_user_priority'] = NULL;
        xmlsitemap_flag_sitemap();
      }
      break;
    case 'update':
      if ($account->status) {
        if (($result = db_fetch_object(db_query("SELECT uid, changed, previously_changed, priority_override FROM {xmlsitemap_user} WHERE uid = %d", $account->uid))) === FALSE) {
          $row = new stdClass();
          $row->uid = $account->uid;
          $row->previously_changed = $account->created;
          $row->changed = !empty($account->access) ? $account->access : REQUEST_TIME;
        }
        else {
          $row = $result;
          if (!empty($account->access)) {
            if ($row->changed < $account->access) {
              $row->previously_changed = $row->changed;
              $row->changed = $account->access;
            }
          }
          else {
            $row->previously_changed = $row->changed;
            $row->changed = REQUEST_TIME;
          }
        }
        if (isset($edit['xmlsitemap_user_priority'])) {
          $row->priority_override = $edit['xmlsitemap_user_priority'];
        }
        drupal_write_record('xmlsitemap_user', $row, $result !== FALSE ? 'uid' : NULL);
        xmlsitemap_flag_sitemap();
      }
      break;
    case 'delete':
      db_query("DELETE FROM {xmlsitemap_user} WHERE uid = %d", $account->uid);
      db_query("DELETE FROM {xmlsitemap} WHERE type = 'user' AND id = %d", $account->uid);
      xmlsitemap_flag_sitemap();
      break;
  }
}