1<?php
2/**
3 * DokuWiki Plugin inetmodifications (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  i-net /// software <tools@inetsoftware.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class action_plugin_siteexport_pdfstyles extends DokuWiki_Action_Plugin {
13
14    /**
15     * Registers a callback function for a given event
16     *
17     * @param Doku_Event_Handler $controller DokuWiki's event controller object
18     * @return void
19     */
20    public function register(Doku_Event_Handler $controller) {
21        global $INPUT;
22        if ( !strrpos( $_SERVER['SCRIPT_FILENAME'], 'css.php', -7 ) ) { return; }
23        if ( !$INPUT->has('pdfExport') ) { return true; }
24
25        $controller->register_hook('CSS_STYLES_INCLUDED', 'BEFORE', $this, 'handle_css_styles');
26        $controller->register_hook('CSS_CACHE_USE', 'BEFORE', $this, 'handle_use_cache');
27    }
28
29    /**
30     * This function serves debugging purposes and has to be enabled in the register phase
31     *
32     * @param Doku_Event $event  event object by reference
33     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
34     *                           handler was registered]
35     * @return void
36     */
37    public function handle_use_cache(Doku_Event &$event, $param) {
38        global $INPUT;
39
40        // We need different keys for each style sheet.
41        $event->data->key .= $INPUT->str('pdfExport', '0');
42        $event->data->cache = getCacheName( $event->data->key, $event->data->ext );
43    }
44
45    /**
46     * Finally, handle the JS script list. The script would be fit to do even more stuff / types
47     * but handles only admin and default currently.
48     *
49     * @param Doku_Event $event  event object by reference
50     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
51     *                           handler was registered]
52     * @return void
53     */
54    public function handle_css_styles(Doku_Event &$event, $param) {
55        global $INPUT, $conf;
56
57        $conf['cssdatauri'] = false;
58
59        switch( $event->data['mediatype'] ) {
60
61            case 'print':
62            case 'all':
63                // Keep the styles
64                break;
65            case 'screen':
66            case 'speech':
67            case 'DW_DEFAULT':
68                // throw away
69                $event->preventDefault();
70                break;
71        }
72    }
73}
74
75// vim:ts=4:sw=4:et:
76