xmlsitemap_engines.admin.inc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @file
  4. * Administrative page callbacks for the xmlsitemap_engines module.
  5. */
  6. /**
  7. * Form builder; Administration settings form.
  8. */
  9. function xmlsitemap_engines_settings_form() {
  10. // Build the list of support engines for the checkboxes options.
  11. $engines = xmlsitemap_engines_get_engine_info();
  12. $engine_options = array();
  13. foreach ($engines as $engine => $engine_info) {
  14. $engine_options[$engine] = $engine_info['name'];
  15. }
  16. asort($engine_options);
  17. $form['xmlsitemap_engines_engines'] = array(
  18. '#type' => 'checkboxes',
  19. '#title' => t('Submit the sitemap to the following engines'),
  20. '#default_value' => variable_get('xmlsitemap_engines_engines', array()),
  21. '#options' => $engine_options,
  22. );
  23. $form['xmlsitemap_engines_minimum_lifetime'] = array(
  24. '#type' => 'select',
  25. '#title' => t('Do not submit more often than every'),
  26. '#options' => drupal_map_assoc(array(
  27. 3600,
  28. 10800,
  29. 21600,
  30. 32400,
  31. 43200,
  32. 86400,
  33. 172800,
  34. 259200,
  35. 604800,
  36. 604800 * 2,
  37. 604800 * 4,
  38. ), 'format_interval'),
  39. '#default_value' => variable_get('xmlsitemap_engines_minimum_lifetime', 86400),
  40. );
  41. $form['xmlsitemap_engines_submit_updated'] = array(
  42. '#type' => 'checkbox',
  43. '#title' => t('Only submit if the sitemap has been updated since the last submission.'),
  44. '#default_value' => variable_get('xmlsitemap_engines_submit_updated', TRUE),
  45. );
  46. $form['xmlsitemap_engines_custom_urls'] = array(
  47. '#type' => 'textarea',
  48. '#title' => t('Custom submission URLs'),
  49. '#description' => t('Enter one URL per line. The token [sitemap] will be replaced with the URL to your sitemap. For example: %example-before would become %example-after.', array(
  50. '%example-before' => 'http://example.com/ping?[sitemap]',
  51. '%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', url('sitemap.xml', array(
  52. 'absolute' => TRUE,
  53. ))),
  54. )),
  55. '#default_value' => variable_get('xmlsitemap_engines_custom_urls', ''),
  56. '#rows' => 2,
  57. '#wysiwyg' => FALSE,
  58. '#element_validate' => array('xmlsitemap_engines_validate_custom_urls'),
  59. );
  60. // Ensure the xmlsitemap_engines variable gets filterd to a simple array.
  61. $form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
  62. return system_settings_form($form);
  63. }
  64. /**
  65. * Validate the custom submission URL element.
  66. */
  67. function xmlsitemap_engines_validate_custom_urls($element, &$form_state) {
  68. $custom_urls = preg_split('/[\r\n]+/', $element['#value'], -1, PREG_SPLIT_NO_EMPTY);
  69. foreach ($custom_urls as $custom_url) {
  70. $url = xmlsitemap_engines_prepare_url($custom_url, '');
  71. if (!valid_url($url, TRUE)) {
  72. form_error($element, t('Invalid URL %url.', array('%url' => $custom_url)));
  73. }
  74. }
  75. $form_state['values']['xmlsitemap_engines_custom_urls'] = implode("\n", $custom_urls);
  76. }