summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klier <chi@chimeric.de>2008-08-28 22:03:21 +0200
committerMichael Klier <chi@chimeric.de>2008-08-28 22:03:21 +0200
commitf6dad9fdc0860d080d2807e2ae50f5a046332ba8 (patch)
treec2946e149502ff18816095244c2037e702038c29
parent9893039086053905baf471e51eee86a5aa704483 (diff)
downloadrpg-f6dad9fdc0860d080d2807e2ae50f5a046332ba8.tar.gz
rpg-f6dad9fdc0860d080d2807e2ae50f5a046332ba8.tar.bz2
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
-rw-r--r--inc/actions.php118
1 files changed, 71 insertions, 47 deletions
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 <andi@splitbrain.org>
+ * @author Michael Klier <chi@chimeric.de>
*/
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 .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . DOKU_LF;
+ $pre .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . DOKU_LF;
+ $pre .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"' . DOKU_LF;
+ $pre .= ' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">' . DOKU_LF;
+ $pre .= '<head>' . DOKU_LF;
+ $pre .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . DOKU_LF;
+ $pre .= ' <title>'.$ID.'</title>' . DOKU_LF;
+
+ // get metaheaders
+ ob_start();
+ tpl_metaheaders();
+ $pre .= ob_get_clean();
+
+ $pre .= '</head>' . DOKU_LF;
+ $pre .= '<body>' . DOKU_LF;
+ $pre .= '<div class="dokuwiki export">' . DOKU_LF;
+
+ // get toc
+ $pre .= tpl_toc(true);
+
+ $headers['Content-Type'] = 'text/html; charset=utf-8';
+ $output = p_wiki_xhtml($ID,$REV,false);
+
+ $post .= '</div>' . DOKU_LF;
+ $post .= '</body>' . DOKU_LF;
+ $post .= '</html>' . 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('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
- ptln(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
- ptln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$conf['lang'].'"');
- ptln(' lang="'.$conf['lang'].'" dir="'.$lang['direction'].'">');
- ptln('<head>');
- ptln(' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
- ptln(' <title>'.$ID.'</title>');
- tpl_metaheaders();
- ptln('</head>');
- ptln('<body>');
- ptln('<div class="dokuwiki export">');
- $html = p_wiki_xhtml($ID,$REV,false);
- tpl_toc();
- echo $html;
- ptln('</div>');
- ptln('</body>');
- ptln('</html>');
- 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';
}