xmlsitemap_engines.admin.inc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 604800 * 2, 604800 * 4), 'format_interval'),
  27. '#default_value' => variable_get('xmlsitemap_engines_minimum_lifetime', 86400),
  28. );
  29. $form['xmlsitemap_engines_submit_updated'] = array(
  30. '#type' => 'checkbox',
  31. '#title' => t('Only submit if the sitemap has been updated since the last submission.'),
  32. '#default_value' => variable_get('xmlsitemap_engines_submit_updated', TRUE),
  33. );
  34. $form['xmlsitemap_engines_custom_urls'] = array(
  35. '#type' => 'textarea',
  36. '#title' => t('Custom submission URLs'),
  37. '#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('%example-before' => 'http://example.com/ping?[sitemap]', '%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', url('sitemap.xml', array('absolute' => TRUE))))),
  38. '#default_value' => variable_get('xmlsitemap_engines_custom_urls', ''),
  39. '#rows' => 2,
  40. '#wysiwyg' => FALSE,
  41. '#element_validate' => array('xmlsitemap_engines_validate_custom_urls'),
  42. );
  43. // Ensure the xmlsitemap_engines variable gets filterd to a simple array.
  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 URL %url.', array('%url' => $custom_url)));
  56. }
  57. }
  58. $form_state['values']['xmlsitemap_engines_custom_urls'] = implode("\n", $custom_urls);
  59. }