1<?php 2/** 3 * Created by IntelliJ IDEA. 4 * User: andi 5 * Date: 2/10/17 6 * Time: 3:18 PM 7 */ 8 9namespace dokuwiki\Action; 10 11use dokuwiki\Action\Exception\FatalException; 12 13class Sitemap extends AbstractAction { 14 15 /** @inheritdoc */ 16 function minimumPermission() { 17 return AUTH_NONE; 18 } 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 global $conf; 29 30 if ($conf['sitemap'] < 1 || !is_numeric($conf['sitemap'])) { 31 throw new FatalException(404, 'Sitemap generation is disabled'); 32 } 33 34 $sitemap = \Sitemapper::getFilePath(); 35 if (\Sitemapper::sitemapIsCompressed()) { 36 $mime = 'application/x-gzip'; 37 }else{ 38 $mime = 'application/xml; charset=utf-8'; 39 } 40 41 // Check if sitemap file exists, otherwise create it 42 if (!is_readable($sitemap)) { 43 \Sitemapper::generate(); 44 } 45 46 if (is_readable($sitemap)) { 47 // Send headers 48 header('Content-Type: '.$mime); 49 header('Content-Disposition: attachment; filename='.utf8_basename($sitemap)); 50 51 http_conditionalRequest(filemtime($sitemap)); 52 53 // Send file 54 //use x-sendfile header to pass the delivery to compatible webservers 55 http_sendfile($sitemap); 56 57 readfile($sitemap); 58 exit; 59 } 60 61 throw new FatalException(500, 'Could not read the sitemap file - bad permissions?'); 62 } 63 64} 65