1<?php 2/** 3 * TeXit-Plugin 4 * Copyright (C) 2013 Elie Roux <elie.roux@telecom-bretagne.eu> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * -------------------------------------------------------------------- 20 * 21 */ 22 23// must be run within Dokuwiki 24if(!defined('DOKU_INC')) die(); 25if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 26require_once(DOKU_PLUGIN.'texit/config.php'); 27 28class action_plugin_texit extends DokuWiki_Action_Plugin { 29 /** 30 * Registers a callback function for action (?do=foo in the URL) handling 31 * 32 * @param Doku_Event_Handler $controller DokuWiki's event controller object 33 * @return void 34 */ 35 public function register(Doku_Event_Handler &$controller) { 36 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 37 'handle_action_act_preprocess'); 38 } 39 /** 40 * This is the main function, call at every action. 41 * 42 * @param Doku_Event $event event object by reference 43 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 44 * handler was registered] 45 * @return void 46 */ 47 48 public function handle_action_act_preprocess(Doku_Event &$event, $param) { 49 // first check if it's a texit event 50 if ($event->data != "texit" && $event->data != "texitns") { 51 return false; 52 } 53 // check user's rights 54 if ( auth_quickaclcheck(getID()) < AUTH_READ ) { 55 return false; 56 } 57 $this->loadConfig(); // we need to get the usual plugin config 58 $pdfurl = $this->generate_pdf($event->data); 59 $this->redirect_to_pdf($pdfurl); 60 $event->preventDefault(); 61 $event->stopPropagation(); 62 exit(); 63 } 64 65 /* A bit hackish, but I don't know any other way... (I cannot call getConf in 66 * a non-Dukuwiki plugin class) 67 */ 68 function get_plugin_config() { 69 global $conf; 70 if (!$this->configloaded){ $this->loadConfig();} 71 return $conf['plugin']['texit']; 72 } 73 /* Generates the pdf and returns the URL. 74 * $action is the action name (texit or texitns) 75 */ 76 function generate_pdf($action) { 77 global $conf; 78 $namespace_mode = false; 79 if ($action == "texitns") { 80 $namespace_mode = true; 81 } 82 // we want to have a nsbpc instance in config.php, but as it's not 83 // a Dokuwiki plugin, we can't... so we get it here and pass it 84 // to config.php 85 $nsbpc_obj = $this->loadHelper('nsbpc'); 86 $texit = new config_plugin_texit(getID(), $namespace_mode, $this->get_plugin_config(), $nsbpc_obj); 87 $pdfurl = $texit->process(); 88 return $pdfurl; 89 } 90 91 /* A simple function to redirect the client to the PDF. 92 */ 93 function redirect_to_pdf($pdfurl) { 94 //header("Status: 200"); // TODO: see if it's necessary in Chrome 95 header("Location: ".$pdfurl, true, 303); 96 print("Redirecting to <a href=\"".$pdfurl."\">".$pdfurl."</a>"); 97 } 98} 99?> 100