You are here

function xmlsitemap_link_save in XML sitemap 6.2

Same name and namespace in other branches
  1. 7.2 xmlsitemap.module \xmlsitemap_link_save()

Saves or updates a sitemap link.

Parameters

$link: An array with a sitemap link.

Related topics

15 calls to xmlsitemap_link_save()
XMLSitemapTestHelper::addSitemapLink in ./xmlsitemap.test
XMLSitemapUnitTest::testSaveLink in ./xmlsitemap.test
Tests for xmlsitemap_link_save().
xmlsitemap_custom_edit_link_form_submit in xmlsitemap_custom/xmlsitemap_custom.admin.inc
xmlsitemap_menu_xmlsitemap_process_menu_links in xmlsitemap_menu/xmlsitemap_menu.module
Process menu sitemap links.
xmlsitemap_node_comment in xmlsitemap_node/xmlsitemap_node.module
Implements hook_comment().

... See full list

File

./xmlsitemap.module, line 564
Main file for the xmlsitemap module.

Code

function xmlsitemap_link_save(array $link) {
  xmlsitemap_load_all_includes();
  module_load_include('inc', 'xmlsitemap');
  $link += array(
    'access' => 1,
    'status' => 1,
    'status_override' => 0,
    'lastmod' => 0,
    'priority' => XMLSITEMAP_PRIORITY_DEFAULT,
    'priority_override' => 0,
    'changefreq' => 0,
    'changecount' => 0,
    'language' => '',
  );

  // Allow other modules to alter the link before saving.
  drupal_alter('xmlsitemap_link', $link);

  // Temporary validation checks.
  // @todo Remove in final?
  if ($link['priority'] < 0 || $link['priority'] > 1) {
    trigger_error(t('Invalid sitemap link priority %priority.<br />@link', array(
      '%priority' => $link['priority'],
      '@link' => var_export($link, TRUE),
    )), E_USER_ERROR);
  }
  if ($link['changecount'] < 0) {
    trigger_error(t('Negative changecount value. Please report this to <a href="@516928">@516928</a>.<br />@link', array(
      '@516928' => 'http://drupal.org/node/516928',
      '@link' => var_export($link, TRUE),
    )), E_USER_ERROR);
    $link['changecount'] = 0;
  }
  $existing = db_fetch_array(db_query_range("SELECT loc, access, status, lastmod, priority, changefreq, changecount, language FROM {xmlsitemap} WHERE type = '%s' AND id = %d", $link['type'], $link['id'], 0, 1));

  // Check if this is a changed link and set the regenerate flag if necessary.
  if (!variable_get('xmlsitemap_regenerate_needed', FALSE)) {
    _xmlsitemap_check_changed_link($link, $existing, TRUE);
  }

  // Save the link and allow other modules to respond to the link being saved.
  if ($existing) {
    xmlsitemap_write_record('xmlsitemap', $link, array(
      'type',
      'id',
    ));
    module_invoke_all('xmlsitemap_link_update', $link);
  }
  else {
    xmlsitemap_write_record('xmlsitemap', $link);
    module_invoke_all('xmlsitemap_link_insert', $link);
  }
  return $link;
}