From f6dad9fdc0860d080d2807e2ae50f5a046332ba8 Mon Sep 17 00:00:00 2001 From: Michael Klier Date: Thu, 28 Aug 2008 22:03:21 +0200 Subject: new event ACTION_EXPORT_POSTPROCESS This event allows action plugins to postprocess the output of a page requested for export. Event data: data[id] -- the page id data[mode] -- requested export mode data[headers] -- headers of the requested export mode data[output] -- export output darcs-hash:20080828200321-23886-6676682f33fa5c2d9f0c0a21fa26154baf4e137a.gz --- inc/actions.php | 118 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 47 deletions(-) (limited to 'inc') diff --git a/inc/actions.php b/inc/actions.php index 59cdd2415..41cad5c00 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -392,69 +392,93 @@ function act_edit($act){ } /** - * Handle 'edit', 'preview' + * Export a wiki page for various formats + * + * Triggers ACTION_EXPORT_POSTPROCESS + * + * Event data: + * data['id'] -- page id + * data['mode'] -- requested export mode + * data['headers'] -- export headers + * data['output'] -- export output * * @author Andreas Gohr + * @author Michael Klier */ function act_export($act){ global $ID; global $REV; + global $conf; + global $lang; + + $pre = ''; + $post = ''; + $output = ''; + $headers = array(); // search engines: never cache exported docs! (Google only currently) - header('X-Robots-Tag: noindex'); + $headers['X-Robots-Tag'] = 'noindex'; - // no renderer for this - if($act == 'export_raw'){ - header('Content-Type: text/plain; charset=utf-8'); - print rawWiki($ID,$REV); - exit; + $mode = substr($act,7); + switch($mode) { + case 'raw': + $headers['Content-Type'] = 'text/plain; charse=utf-8'; + $output = rawWiki($ID,$REV); + break; + case 'xhtml': + $pre .= '' . DOKU_LF; + $pre .= '' . DOKU_LF; + $pre .= '' . DOKU_LF; + $pre .= ' ' . DOKU_LF; + $pre .= ' '.$ID.'' . DOKU_LF; + + // get metaheaders + ob_start(); + tpl_metaheaders(); + $pre .= ob_get_clean(); + + $pre .= '' . DOKU_LF; + $pre .= '' . DOKU_LF; + $pre .= '
' . DOKU_LF; + + // get toc + $pre .= tpl_toc(true); + + $headers['Content-Type'] = 'text/html; charset=utf-8'; + $output = p_wiki_xhtml($ID,$REV,false); + + $post .= '
' . DOKU_LF; + $post .= '' . DOKU_LF; + $post .= '' . DOKU_LF; + break; + case 'xhtmlbody': + $headers['Content-Type'] = 'text/html; charset=utf-8'; + $output = p_wiki_xhtml($ID,$REV,false); + break; + default: + $headers = p_get_metadata($ID,"format $mode"); + $output = p_cached_output(wikiFN($ID,$REV), $mode); + break; } - // html export #FIXME what about the template's style? - if($act == 'export_xhtml'){ - global $conf; - global $lang; - header('Content-Type: text/html; charset=utf-8'); - ptln(''); - ptln(''); - ptln(''); - ptln(' '); - ptln(' '.$ID.''); - tpl_metaheaders(); - ptln(''); - ptln(''); - ptln('
'); - $html = p_wiki_xhtml($ID,$REV,false); - tpl_toc(); - echo $html; - ptln('
'); - ptln(''); - ptln(''); - exit; - } + // prepare event data + $data = array(); + $data['id'] = $ID; + $data['mode'] = $mode; + $data['headers'] = $headers; + $data['output'] =& $output; - // html body only - if($act == 'export_xhtmlbody'){ - $html = p_wiki_xhtml($ID,$REV,false); - tpl_toc(); - echo $html; - exit; - } + trigger_event('ACTION_EXPORT_POSTPROCESS', $data); - // try to run renderer - $mode = substr($act,7); - $text = p_cached_output(wikiFN($ID,$REV), $mode); - $headers = p_get_metadata($ID,"format $mode"); - if(!is_null($text)){ - if(is_array($headers)) foreach($headers as $key => $val){ - header("$key: $val"); + if(!empty($data['output'])){ + if(is_array($data['headers'])) foreach($data['headers'] as $key => $val){ + header("$key: $val"); } - print $text; + print $pre.$data['output'].$post; exit; } - return 'show'; } -- cgit v1.2.3