You are here

function xmlsitemap_settings_additional_submit in XML sitemap 5

Submit additional links form.

Related topics

File

./xmlsitemap.module, line 242
Creates a site map compatible with the sitemaps.org schema.

Code

function xmlsitemap_settings_additional_submit($form_id, $form_values) {
  $update = FALSE;
  if ($form_values['op'] == t('Save configuration')) {
    if ($form_values['xmlsitemap_additional_links_priority'] != variable_get('xmlsitemap_additional_links_priority', 0.1)) {
      $update = TRUE;
    }
    if (!empty($form_values['delete'])) {
      foreach ($form_values['delete'] as $id => $delete) {
        if ($delete || $form_values['path'][$id] == trim($form_values['link']['new'])) {
          db_query("DELETE FROM {xmlsitemap_additional} WHERE path = '%s'", $form_values['path'][$id]);
          unset($form_values['priority'][$id]);
          $update = TRUE;
        }
      }
      unset($form_values['delete']);
    }
    $path = trim($form_values['link']['new']);
    $pid = db_result(db_query("SELECT pid FROM {url_alias} WHERE src = '%s'", $path));
    if (!empty($path)) {
      db_query("\n        INSERT INTO {xmlsitemap_additional} (path, pid, last_changed, priority) VALUES ('%s', %s, %d, %s)\n      ", $path, empty($pid) ? 'NULL' : $pid, time(), $form_values['priority']['new']);
      unset($form_values['link'], $form_values['priority']['new']);
      $update = TRUE;
    }
    if (!empty($form_values['priority'])) {
      foreach ($form_values['priority'] as $id => $priority) {
        if ($priority != $form_values['old_priority'][$id]) {
          $pid = db_result(db_query("SELECT pid FROM {url_alias} WHERE src = '%s'", $form_values['path'][$id]));
          db_query("\n            UPDATE {xmlsitemap_additional}\n            SET pid = %s, previously_changed = last_changed, last_changed = %d, priority = %s\n            WHERE path = '%s'\n          ", empty($pid) ? 'NULL' : $pid, time(), $priority, $form_values['path'][$id]);
          $update = TRUE;
        }
      }
      unset($form_values['path'], $form_values['priority'], $form_values['old_priority']);
    }
  }
  elseif (variable_get('xmlsitemap_additional_links_priority', 0.1) != 0.1) {
    if (in_array('NULL', $form_values['old_priority'])) {
      $update = TRUE;
    }
    unset($form_values['delete'], $form_values['path'], $form_values['link'], $form_values['old_priority'], $form_values['priority']);
  }
  system_settings_form_submit($form_id, $form_values);
  if ($update) {
    xmlsitemap_update_sitemap();
  }
}