1f21dad39SAndreas Gohr<?php 2f21dad39SAndreas Gohr 3f21dad39SAndreas Gohrnamespace dokuwiki\Action; 4f21dad39SAndreas Gohr 5f21dad39SAndreas Gohruse dokuwiki\Action\Exception\ActionAbort; 6f21dad39SAndreas Gohr 7ab583a1bSAndreas Gohr/** 8ab583a1bSAndreas Gohr * Class Export 9ab583a1bSAndreas Gohr * 10ab583a1bSAndreas Gohr * Handle exporting by calling the appropriate renderer 11ab583a1bSAndreas Gohr * 12ab583a1bSAndreas Gohr * @package dokuwiki\Action 13ab583a1bSAndreas Gohr */ 14f21dad39SAndreas Gohrclass Export extends AbstractAction { 15f21dad39SAndreas Gohr 16f21dad39SAndreas Gohr /** @inheritdoc */ 17f21dad39SAndreas Gohr function minimumPermission() { 18f21dad39SAndreas Gohr return AUTH_READ; 19f21dad39SAndreas Gohr } 20f21dad39SAndreas Gohr 21f21dad39SAndreas Gohr /** 22f21dad39SAndreas Gohr * Export a wiki page for various formats 23f21dad39SAndreas Gohr * 24f21dad39SAndreas Gohr * Triggers ACTION_EXPORT_POSTPROCESS 25f21dad39SAndreas Gohr * 26f21dad39SAndreas Gohr * Event data: 27f21dad39SAndreas Gohr * data['id'] -- page id 28f21dad39SAndreas Gohr * data['mode'] -- requested export mode 29f21dad39SAndreas Gohr * data['headers'] -- export headers 30f21dad39SAndreas Gohr * data['output'] -- export output 31f21dad39SAndreas Gohr * 32f21dad39SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 33f21dad39SAndreas Gohr * @author Michael Klier <chi@chimeric.de> 34ab583a1bSAndreas Gohr * @inheritdoc 35f21dad39SAndreas Gohr */ 36f21dad39SAndreas Gohr public function preProcess() { 37f21dad39SAndreas Gohr global $ID; 38f21dad39SAndreas Gohr global $REV; 39f21dad39SAndreas Gohr global $conf; 40f21dad39SAndreas Gohr global $lang; 41f21dad39SAndreas Gohr 42f21dad39SAndreas Gohr $pre = ''; 43f21dad39SAndreas Gohr $post = ''; 44f21dad39SAndreas Gohr $headers = array(); 45f21dad39SAndreas Gohr 46f21dad39SAndreas Gohr // search engines: never cache exported docs! (Google only currently) 47f21dad39SAndreas Gohr $headers['X-Robots-Tag'] = 'noindex'; 48f21dad39SAndreas Gohr 49*73522543SAndreas Gohr $mode = substr($this->actionname, 7); 50f21dad39SAndreas Gohr switch($mode) { 51f21dad39SAndreas Gohr case 'raw': 52f21dad39SAndreas Gohr $headers['Content-Type'] = 'text/plain; charset=utf-8'; 53f21dad39SAndreas Gohr $headers['Content-Disposition'] = 'attachment; filename=' . noNS($ID) . '.txt'; 54f21dad39SAndreas Gohr $output = rawWiki($ID, $REV); 55f21dad39SAndreas Gohr break; 56f21dad39SAndreas Gohr case 'xhtml': 57f21dad39SAndreas Gohr $pre .= '<!DOCTYPE html>' . DOKU_LF; 58f21dad39SAndreas Gohr $pre .= '<html lang="' . $conf['lang'] . '" dir="' . $lang['direction'] . '">' . DOKU_LF; 59f21dad39SAndreas Gohr $pre .= '<head>' . DOKU_LF; 60f21dad39SAndreas Gohr $pre .= ' <meta charset="utf-8" />' . DOKU_LF; // FIXME improve wrapper 61f21dad39SAndreas Gohr $pre .= ' <title>' . $ID . '</title>' . DOKU_LF; 62f21dad39SAndreas Gohr 63f21dad39SAndreas Gohr // get metaheaders 64f21dad39SAndreas Gohr ob_start(); 65f21dad39SAndreas Gohr tpl_metaheaders(); 66f21dad39SAndreas Gohr $pre .= ob_get_clean(); 67f21dad39SAndreas Gohr 68f21dad39SAndreas Gohr $pre .= '</head>' . DOKU_LF; 69f21dad39SAndreas Gohr $pre .= '<body>' . DOKU_LF; 70f21dad39SAndreas Gohr $pre .= '<div class="dokuwiki export">' . DOKU_LF; 71f21dad39SAndreas Gohr 72f21dad39SAndreas Gohr // get toc 73f21dad39SAndreas Gohr $pre .= tpl_toc(true); 74f21dad39SAndreas Gohr 75f21dad39SAndreas Gohr $headers['Content-Type'] = 'text/html; charset=utf-8'; 76f21dad39SAndreas Gohr $output = p_wiki_xhtml($ID, $REV, false); 77f21dad39SAndreas Gohr 78f21dad39SAndreas Gohr $post .= '</div>' . DOKU_LF; 79f21dad39SAndreas Gohr $post .= '</body>' . DOKU_LF; 80f21dad39SAndreas Gohr $post .= '</html>' . DOKU_LF; 81f21dad39SAndreas Gohr break; 82f21dad39SAndreas Gohr case 'xhtmlbody': 83f21dad39SAndreas Gohr $headers['Content-Type'] = 'text/html; charset=utf-8'; 84f21dad39SAndreas Gohr $output = p_wiki_xhtml($ID, $REV, false); 85f21dad39SAndreas Gohr break; 86f21dad39SAndreas Gohr default: 87f21dad39SAndreas Gohr $output = p_cached_output(wikiFN($ID, $REV), $mode, $ID); 88f21dad39SAndreas Gohr $headers = p_get_metadata($ID, "format $mode"); 89f21dad39SAndreas Gohr break; 90f21dad39SAndreas Gohr } 91f21dad39SAndreas Gohr 92f21dad39SAndreas Gohr // prepare event data 93f21dad39SAndreas Gohr $data = array(); 94f21dad39SAndreas Gohr $data['id'] = $ID; 95f21dad39SAndreas Gohr $data['mode'] = $mode; 96f21dad39SAndreas Gohr $data['headers'] = $headers; 97f21dad39SAndreas Gohr $data['output'] =& $output; 98f21dad39SAndreas Gohr 99f21dad39SAndreas Gohr trigger_event('ACTION_EXPORT_POSTPROCESS', $data); 100f21dad39SAndreas Gohr 101f21dad39SAndreas Gohr if(!empty($data['output'])) { 102f21dad39SAndreas Gohr if(is_array($data['headers'])) foreach($data['headers'] as $key => $val) { 103f21dad39SAndreas Gohr header("$key: $val"); 104f21dad39SAndreas Gohr } 105f21dad39SAndreas Gohr print $pre . $data['output'] . $post; 106f21dad39SAndreas Gohr exit; 107f21dad39SAndreas Gohr } 108f21dad39SAndreas Gohr 109f21dad39SAndreas Gohr throw new ActionAbort(); 110f21dad39SAndreas Gohr } 111f21dad39SAndreas Gohr 112f21dad39SAndreas Gohr} 113