You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

69 lines
1.7 KiB

  1. <?php
  2. namespace dokuwiki\Action;
  3. use dokuwiki\Action\Exception\FatalException;
  4. use dokuwiki\Sitemap\Mapper;
  5. use dokuwiki\Utf8\PhpString;
  6. /**
  7. * Class Sitemap
  8. *
  9. * Generate an XML sitemap for search engines. Do not confuse with Index
  10. *
  11. * @package dokuwiki\Action
  12. */
  13. class Sitemap extends AbstractAction
  14. {
  15. /** @inheritdoc */
  16. public function minimumPermission()
  17. {
  18. return AUTH_NONE;
  19. }
  20. /**
  21. * Handle sitemap delivery
  22. *
  23. * @author Michael Hamann <michael@content-space.de>
  24. * @throws FatalException
  25. * @inheritdoc
  26. */
  27. public function preProcess()
  28. {
  29. global $conf;
  30. if ($conf['sitemap'] < 1 || !is_numeric($conf['sitemap'])) {
  31. throw new FatalException('Sitemap generation is disabled', 404);
  32. }
  33. $sitemap = Mapper::getFilePath();
  34. if (Mapper::sitemapIsCompressed()) {
  35. $mime = 'application/x-gzip';
  36. } else {
  37. $mime = 'application/xml; charset=utf-8';
  38. }
  39. // Check if sitemap file exists, otherwise create it
  40. if (!is_readable($sitemap)) {
  41. Mapper::generate();
  42. }
  43. if (is_readable($sitemap)) {
  44. // Send headers
  45. header('Content-Type: ' . $mime);
  46. header('Content-Disposition: attachment; filename=' . PhpString::basename($sitemap));
  47. http_conditionalRequest(filemtime($sitemap));
  48. // Send file
  49. //use x-sendfile header to pass the delivery to compatible webservers
  50. http_sendfile($sitemap);
  51. readfile($sitemap);
  52. exit;
  53. }
  54. throw new FatalException('Could not read the sitemap file - bad permissions?');
  55. }
  56. }