You are here

function xmlsitemap_custom_edit_link_form_validate in XML sitemap 6.2

Same name and namespace in other branches
  1. 7.2 xmlsitemap_custom/xmlsitemap_custom.admin.inc \xmlsitemap_custom_edit_link_form_validate()

File

xmlsitemap_custom/xmlsitemap_custom.admin.inc, line 134
Administrative page callbacks for the xmlsitemap_custom module.

Code

function xmlsitemap_custom_edit_link_form_validate($form, &$form_state) {
  $link =& $form_state['values'];

  // Make sure we trim and normalize the path first.
  $link['loc'] = trim($link['loc']);
  $link['loc'] = drupal_get_normal_path($link['loc'], $link['language']);

  // Test anonymous user access to the custom link paths.
  xmlsitemap_switch_user(0);
  $menu_item = menu_get_item($link['loc']);
  xmlsitemap_restore_user();

  // Since the menu item access results are cached, manually check the current path.
  if ($menu_item && strpos($link['loc'], 'admin/settings/xmlsitemap/custom') === 0 && !user_access('administer xmlsitemap', drupal_anonymous_user())) {
    $menu_item['access'] = FALSE;
  }
  if (db_result(db_query_range("SELECT 1 FROM {xmlsitemap} WHERE type <> 'custom' AND loc = '%s' AND status = 1 AND access = 1 AND language IN ('%s', '')", $link['loc'], $link['language'], 0, 1))) {
    form_set_error('loc', t('There is already an existing link in the sitemap with the path %link.', array(
      '%link' => $link['loc'],
    )));
  }
  elseif (empty($menu_item['access']) && !is_readable('./' . $link['loc'])) {

    // @todo Harden this file exists check to make sure we can't link to files
    // like .htaccess.
    form_set_error('loc', t('The custom link %link is either invalid or it cannot be accessed by anonymous users.', array(
      '%link' => $link['loc'],
    )));
  }
}