1<?php
2/**
3 * PDF-Tools
4 *
5 * @license    MIT
6 * @author     Gero Gothe <practical@medizin-lernen.de>
7 */
8
9
10# must be run within Dokuwiki
11if(!defined('DOKU_INC')) die();
12
13
14class action_plugin_pdftools extends DokuWiki_Action_Plugin {
15
16    public function register(Doku_Event_Handler $controller) {
17
18        $controller->register_hook('PLUGIN_DW2PDF_REPLACE', 'BEFORE', $this, 'replacement_before', null, 100);
19        $controller->register_hook('TPL_CONTENT_DISPLAY', 'AFTER',  $this, 'printbutton');
20
21    }
22
23    function printbutton(Doku_Event $event, $param) {
24        global $conf;
25        global $ID;
26
27        if ($ID=="start") return;
28
29        $show_button = !$this->getConf("print hide");
30        $hide_on_start = $this->getConf("print hide on start");
31
32        if ($hide_on_start==true &&
33            strpos($ID,'start')!==false &&
34           (strlen($ID)-strpos($ID,'start'))==5) $show_button = false;
35        #echo $ID;
36        #var_dump($hide_on_start);
37
38        if ($show_button) {
39
40            # Check for local <pdf>-Button FUNKTIONIERT noch nicht
41            $page = rawwiki($ID);
42            $pdf_button = preg_match('/\<pdf (.*?)\>/', $page, $matches);
43
44            echo '<div class="pdftools_print_area">';
45            echo '<div class="pdftools_print_icon"><img src="'.DOKU_URL.'lib/plugins/pdftools/img/printer.png" alt="Print"></div>';
46
47            echo '<div class="pdftools_templates">';
48                for ($c=1;$c<5;$c++) {
49                    $d = strval($conf['plugin']['pdftools']['print template'.$c]);
50                    if (strlen($d)>1){
51                        $t = explode(';',$d);
52
53                        if ($pdf_button && $t[0] == $matches[1]){
54                            $chosen="2";
55                            $match=true;
56                        } else {$chosen="";$match=false;}
57
58                        echo "<i>".($t[1])."</i><span class='pdftools_printButton$chosen' onclick=\"location.href='doku.php?id=".$ID."&do=export_pdf&toc=0&tpl=".($t[0])."&rev=".($_GET['rev'])."'\"><a style='color:white' href='doku.php?id=".$ID."&do=export_pdf&toc=0&tpl=".($t[0])."&rev=".($_GET['rev'])."'>".ucfirst($t[0])."</a></span><hr>";
59                    }
60                }
61            echo '</div>';
62
63            echo '</div>';
64        }
65    }
66
67    function replacement_before(Doku_Event $event, $param) {
68		global $conf;
69		global $INFO;
70
71        $event->data['replace']['@COMPANY@'] = $conf['plugin']['pdftools']['company'];
72        $event->data['replace']['@AUTHOR@'] = $INFO['meta']['contributor'][$INFO['user']];
73
74        # Compatibility with approve-plus-plugin: if not installed, the @APPROVER@-Tag is "removed"
75        if (!isset($event->data['replace']['@APPROVER@'])) $event->data['replace']['@APPROVER@'] = '';
76
77        # Remove Approve-Tag also, if author = approver
78        if (strpos($event->data['replace']['@APPROVER@'],$event->data['replace']['@AUTHOR@']) > 0) $event->data['replace']['@APPROVER@'] = '';
79
80	}
81
82}
83
84//Setup VIM: ex: et ts=4 enc=utf-8 :