From 03352761e51b7cdc034c745818baaa9b931f2797 Mon Sep 17 00:00:00 2001 From: Kirsten Roschanski Date: Thu, 27 Apr 2017 18:17:17 +0200 Subject: [PATCH] Make global --- action.php | 62 +++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/action.php b/action.php index 941475d6..a17c5d37 100644 --- a/action.php +++ b/action.php @@ -24,13 +24,17 @@ class action_plugin_dw2pdf extends DokuWiki_Action_Plugin { */ protected $exportConfig = null; protected $tpl; + protected $title; protected $list = array(); /** * Constructor. Sets the correct template + * + * @param string $title */ - public function __construct() { - $this->tpl = $this->getExportConfig('template'); + public function __construct($title=null) { + $this->tpl = $this->getExportConfig('template'); + $this->title = $title ? $title : ''; } /** @@ -60,7 +64,7 @@ public function convert(Doku_Event $event) { if(auth_quickaclcheck($ID) < AUTH_READ) return false; if($data = $this->collectExportPages($event)) { - list($title, $this->list) = $data; + list($this->title, $this->list) = $data; } else { return false; } @@ -70,18 +74,18 @@ public function convert(Doku_Event $event) { // prepare cache and its dependencies $depends = array(); - $cache = $this->prepareCache($title, $depends); + $cache = $this->prepareCache($depends); // hard work only when no cache available or needed for debugging if(!$this->getConf('usecache') || $this->getExportConfig('isDebug') || !$cache->useCache($depends)) { // generating the pdf may take a long time for larger wikis / namespaces with many pages set_time_limit(0); - $this->generatePDF($cache->cache, $title); + $this->generatePDF($cache->cache); } // deliver the file - $this->sendPDFFile($cache->cache, $title); + $this->sendPDFFile($cache->cache); return true; } @@ -103,15 +107,15 @@ protected function collectExportPages(Doku_Event $event) { if($ACT == 'export_pdf') { $list[0] = $ID; - $title = $INPUT->str('pdftitle'); //DEPRECATED - $title = $INPUT->str('book_title', $title, true); - if(empty($title)) { - $title = p_get_first_heading($ID); + $this->title = $INPUT->str('pdftitle'); //DEPRECATED + $this->title = $INPUT->str('book_title', $this->title, true); + if(empty($this->title)) { + $this->title = p_get_first_heading($ID); } } elseif($ACT == 'export_pdfns') { //check input for title and ns - if(!$title = $INPUT->str('book_title')) { + if(!$this->title = $INPUT->str('book_title')) { $this->showPageWithErrorMsg($event, 'needtitle'); return false; } @@ -164,9 +168,9 @@ protected function collectExportPages(Doku_Event $event) { } elseif(isset($_COOKIE['list-pagelist']) && !empty($_COOKIE['list-pagelist'])) { /** @deprecated April 2016 replaced by localStorage version of Bookcreator*/ //is in Bookmanager of bookcreator plugin a title given? - $title = $INPUT->str('pdfbook_title'); //DEPRECATED - $title = $INPUT->str('book_title', $title, true); - if(empty($title)) { + $this->title = $INPUT->str('pdfbook_title'); //DEPRECATED + $this->title = $INPUT->str('book_title', $this->title, true); + if(empty($this->title)) { $this->showPageWithErrorMsg($event, 'needtitle'); return false; } else { @@ -189,9 +193,9 @@ protected function collectExportPages(Doku_Event $event) { exit(); } - $title = $INPUT->str('pdfbook_title'); //DEPRECATED - $title = $INPUT->str('book_title', $title, true); - if(empty($title)) { + $this->title = $INPUT->str('pdfbook_title'); //DEPRECATED + $this->title = $INPUT->str('book_title', $this->title, true); + if(empty($this->title)) { http_status(400); print $this->getLang('needtitle'); exit(); @@ -228,17 +232,16 @@ protected function collectExportPages(Doku_Event $event) { } - return array($title, $list); + return array($this->title, $list); } /** * Prepare cache * - * @param string $title * @param array $depends (reference) array with dependencies * @return cache */ - protected function prepareCache($title, &$depends) { + protected function prepareCache(&$depends) { global $REV; $cachekey = join(',', $this->list) @@ -249,7 +252,7 @@ protected function prepareCache($title, &$depends) { . $this->getExportConfig('font-size') . $this->getExportConfig('doublesided') . ($this->getExportConfig('hasToC') ? join('-', $this->getExportConfig('levels')) : '0') - . $title; + . $this->title; $cache = new cache($cachekey, '.dw2.pdf'); $dependencies = array(); @@ -312,9 +315,8 @@ private function showPageWithErrorMsg(Doku_Event $event, $msglangkey, $replaceme * Build a pdf from the html * * @param string $cachefile - * @param string $title */ - protected function generatePDF($cachefile, $title) { + protected function generatePDF($cachefile) { global $ID; global $REV; global $INPUT; @@ -340,7 +342,7 @@ protected function generatePDF($cachefile, $title) { $mpdf->setBasePath($url); // Set the title - $mpdf->SetTitle($title); + $mpdf->SetTitle($this->title); // some default document settings //note: double-sided document, starts at an odd page (first page is a right-hand side page) @@ -357,7 +359,7 @@ protected function generatePDF($cachefile, $title) { } // load the template - $template = $this->load_template($title); + $template = $this->load_template(); // prepare HTML header styles $html = ''; @@ -469,15 +471,14 @@ protected function generatePDF($cachefile, $title) { /** * @param string $cachefile - * @param string $title */ - protected function sendPDFFile($cachefile, $title) { + protected function sendPDFFile($cachefile) { header('Content-Type: application/pdf'); header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0'); header('Pragma: public'); http_conditionalRequest(filemtime($cachefile)); - $filename = rawurlencode(cleanID(strtr($title, ':/;"', ' '))); + $filename = rawurlencode(cleanID(strtr($this->title, ':/;"', ' '))); if($this->getConf('output') == 'file') { header('Content-Disposition: attachment; filename="' . $filename . '.pdf";'); } else { @@ -503,10 +504,9 @@ protected function sendPDFFile($cachefile, $title) { /** * Load the various template files and prepare the HTML/CSS for insertion * - * @param string $title * @return array */ - protected function load_template($title) { + protected function load_template() { global $ID; global $conf; @@ -547,7 +547,7 @@ protected function load_template($title) { $replace = array( '@PAGE@' => '{PAGENO}', '@PAGES@' => '{nbpg}', //see also $mpdf->pagenumSuffix = ' / ' - '@TITLE@' => hsc($title), + '@TITLE@' => hsc($this->title), '@WIKI@' => $conf['title'], '@WIKIURL@' => DOKU_URL, '@DATE@' => dformat(time()),