xmlsitemap_engines.admin.inc 2.8 KB

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