| 1 |
<?php |
<?php |
| 2 |
// $Id: xmlsitemap_custom.admin.inc,v 1.1.2.8 2009/08/20 06:20:55 davereid Exp $ |
// $Id: xmlsitemap_custom.admin.inc,v 1.1.2.9 2009/08/20 06:26:01 davereid Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 69 |
'#default_value' => number_format($link['priority'], 1), |
'#default_value' => number_format($link['priority'], 1), |
| 70 |
'#description' => t('The priority of this URL relative to other URLs on your site.'), |
'#description' => t('The priority of this URL relative to other URLs on your site.'), |
| 71 |
); |
); |
| 72 |
if (module_exists('locale') && $languages = locale_language_list()) { |
$languages = module_exists('locale') ? locale_language_list() : array(); |
| 73 |
$form['language'] = array( |
$form['language'] = array( |
| 74 |
'#type' => 'select', |
'#type' => 'select', |
| 75 |
'#title' => t('Language'), |
'#title' => t('Language'), |
| 76 |
'#default_value' => $link['language'], |
'#default_value' => $link['language'], |
| 77 |
'#options' => array('' => t('Language neutral')) + $languages, |
'#options' => array('' => t('Language neutral')) + $languages, |
| 78 |
'#access' => count($languages) > 1, |
'#access' => $languages, |
| 79 |
); |
); |
|
} |
|
| 80 |
|
|
| 81 |
$form['submit'] = array( |
$form['submit'] = array( |
| 82 |
'#type' => 'submit', |
'#type' => 'submit', |
| 93 |
return $form; |
return $form; |
| 94 |
} |
} |
| 95 |
|
|
| 96 |
function xmlsitemap_custom_edit_link_form_validate($form, &$form_state) { |
function xmlsitemap_custom_edit_link_form_validate(&$form, &$form_state) { |
| 97 |
$link = &$form_state['values']; |
$link = &$form_state['values']; |
|
$link['loc'] = trim($link['loc']); |
|
| 98 |
|
|
| 99 |
|
// Make sure we trim and normalize the path first. |
| 100 |
|
$link['loc'] = trim($link['loc']); |
| 101 |
$normal_path = drupal_get_normal_path($link['loc']); |
$normal_path = drupal_get_normal_path($link['loc']); |
| 102 |
if ($link['loc'] != $normal_path) { |
if ($link['loc'] != $normal_path) { |
| 103 |
drupal_set_message(t('The sitemap system stores system paths only, but will use the URL alias in the sitemap output. The custom link %link has been stored as %normal_path.', array('%link' => $link['loc'], '%normal_path' => $normal_path))); |
drupal_set_message(t('The sitemap system stores system paths only, but will use the URL alias in the sitemap output. The custom link %link has been stored as %normal_path.', array('%link' => $link['loc'], '%normal_path' => $normal_path))); |
| 105 |
} |
} |
| 106 |
|
|
| 107 |
// Test anonymous user access to the custom link paths. |
// Test anonymous user access to the custom link paths. |
|
$menu_item = NULL; |
|
| 108 |
xmlsitemap_switch_user(0); |
xmlsitemap_switch_user(0); |
| 109 |
$menu_item = menu_get_item($link['loc']); |
$menu_item = menu_get_item($link['loc']); |
| 110 |
xmlsitemap_restore_user(); |
xmlsitemap_restore_user(); |
| 111 |
|
|
| 112 |
// Since the menu item access results are cached, manually check the current path. |
// Since the menu item access results are cached, manually check the current path. |
| 113 |
if (strpos($link['loc'], 'admin/settings/xmlsitemap/custom') === 0 && !user_access('administer xmlsitemap', drupal_anonymous_user())) { |
if ($menu_item && strpos($link['loc'], 'admin/settings/xmlsitemap/custom') === 0 && !user_access('administer xmlsitemap', drupal_anonymous_user())) { |
| 114 |
$menu_item['access'] = FALSE; |
$menu_item['access'] = FALSE; |
| 115 |
} |
} |
| 116 |
|
|
| 117 |
if (db_result(db_query_range("SELECT 1 FROM {xmlsitemap} WHERE loc = '%s' AND status = 1 AND type <> 'custom'", $link['loc'], 0, 1))) { |
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))) { |
| 118 |
form_set_error('loc', t('There is already an existing link in the sitemap with the path %link.', array('%link' => $link['loc']))); |
form_set_error('loc', t('There is already an existing link in the sitemap with the path %link.', array('%link' => $link['loc']))); |
| 119 |
} |
} |
| 120 |
elseif (empty($menu_item['access'])) { |
elseif (empty($menu_item['access']) && !is_readable('./' . $link['loc'])) { |
| 121 |
|
// @todo Harden this file exists check to make sure we can't link to files |
| 122 |
|
// like .htaccess. |
| 123 |
form_set_error('loc', t('The custom link %link is either invalid or it cannot be accessed by anonymous users.', array('%link' => $link['loc']))); |
form_set_error('loc', t('The custom link %link is either invalid or it cannot be accessed by anonymous users.', array('%link' => $link['loc']))); |
| 124 |
} |
} |
| 125 |
} |
} |
| 126 |
|
|
| 127 |
function xmlsitemap_custom_edit_link_form_submit($form, $form_state) { |
function xmlsitemap_custom_edit_link_form_submit(&$form, &$form_state) { |
| 128 |
$link = $form_state['values']; |
$link = $form_state['values']; |
| 129 |
xmlsitemap_save_link($link); |
xmlsitemap_save_link($link); |
| 130 |
drupal_set_message(t('The custom link for %loc was saved.', array('%loc' => $link['loc']))); |
drupal_set_message(t('The custom link for %loc was saved.', array('%loc' => $link['loc']))); |
| 131 |
} |
} |
| 132 |
|
|
| 133 |
function xmlsitemap_custom_delete_link_form($form_state, $link) { |
function xmlsitemap_custom_delete_link_form($form_state, array $link) { |
| 134 |
$form['link'] = array( |
$form['link'] = array( |
| 135 |
'#type' => 'value', |
'#type' => 'value', |
| 136 |
'#value' => $link, |
'#value' => $link, |