function xmlsitemap_custom_edit_link_form_validate in XML sitemap 7.2
Same name and namespace in other branches
- 6.2 xmlsitemap_custom/xmlsitemap_custom.admin.inc \xmlsitemap_custom_edit_link_form_validate()
Edit Link Form Validate.
File
- xmlsitemap_custom/
xmlsitemap_custom.admin.inc, line 143 - Administrative page callbacks for the xmlsitemap_custom.
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/config/search/xmlsitemap/custom') === 0 && !user_access('administer xmlsitemap', drupal_anonymous_user())) {
$menu_item['access'] = FALSE;
}
if (db_query_range("SELECT 1 FROM {xmlsitemap} WHERE type <> 'custom' AND loc = :loc AND status = 1 AND access = 1 AND language IN (:languages)", 0, 1, array(
':loc' => $link['loc'],
':languages' => array(
LANGUAGE_NONE,
$link['language'],
),
))
->fetchField()) {
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'],
)));
}
}