Skip to content

Commit 0335276

Browse files
author
Kirsten Roschanski
committed
Make global
1 parent 579ddb9 commit 0335276

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

action.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ class action_plugin_dw2pdf extends DokuWiki_Action_Plugin {
2424
*/
2525
protected $exportConfig = null;
2626
protected $tpl;
27+
protected $title;
2728
protected $list = array();
2829

2930
/**
3031
* Constructor. Sets the correct template
32+
*
33+
* @param string $title
3134
*/
32-
public function __construct() {
33-
$this->tpl = $this->getExportConfig('template');
35+
public function __construct($title=null) {
36+
$this->tpl = $this->getExportConfig('template');
37+
$this->title = $title ? $title : '';
3438
}
3539

3640
/**
@@ -60,7 +64,7 @@ public function convert(Doku_Event $event) {
6064
if(auth_quickaclcheck($ID) < AUTH_READ) return false;
6165

6266
if($data = $this->collectExportPages($event)) {
63-
list($title, $this->list) = $data;
67+
list($this->title, $this->list) = $data;
6468
} else {
6569
return false;
6670
}
@@ -70,18 +74,18 @@ public function convert(Doku_Event $event) {
7074

7175
// prepare cache and its dependencies
7276
$depends = array();
73-
$cache = $this->prepareCache($title, $depends);
77+
$cache = $this->prepareCache($depends);
7478

7579
// hard work only when no cache available or needed for debugging
7680
if(!$this->getConf('usecache') || $this->getExportConfig('isDebug') || !$cache->useCache($depends)) {
7781
// generating the pdf may take a long time for larger wikis / namespaces with many pages
7882
set_time_limit(0);
7983

80-
$this->generatePDF($cache->cache, $title);
84+
$this->generatePDF($cache->cache);
8185
}
8286

8387
// deliver the file
84-
$this->sendPDFFile($cache->cache, $title);
88+
$this->sendPDFFile($cache->cache);
8589
return true;
8690
}
8791

@@ -103,15 +107,15 @@ protected function collectExportPages(Doku_Event $event) {
103107

104108
if($ACT == 'export_pdf') {
105109
$list[0] = $ID;
106-
$title = $INPUT->str('pdftitle'); //DEPRECATED
107-
$title = $INPUT->str('book_title', $title, true);
108-
if(empty($title)) {
109-
$title = p_get_first_heading($ID);
110+
$this->title = $INPUT->str('pdftitle'); //DEPRECATED
111+
$this->title = $INPUT->str('book_title', $this->title, true);
112+
if(empty($this->title)) {
113+
$this->title = p_get_first_heading($ID);
110114
}
111115

112116
} elseif($ACT == 'export_pdfns') {
113117
//check input for title and ns
114-
if(!$title = $INPUT->str('book_title')) {
118+
if(!$this->title = $INPUT->str('book_title')) {
115119
$this->showPageWithErrorMsg($event, 'needtitle');
116120
return false;
117121
}
@@ -164,9 +168,9 @@ protected function collectExportPages(Doku_Event $event) {
164168
} elseif(isset($_COOKIE['list-pagelist']) && !empty($_COOKIE['list-pagelist'])) {
165169
/** @deprecated April 2016 replaced by localStorage version of Bookcreator*/
166170
//is in Bookmanager of bookcreator plugin a title given?
167-
$title = $INPUT->str('pdfbook_title'); //DEPRECATED
168-
$title = $INPUT->str('book_title', $title, true);
169-
if(empty($title)) {
171+
$this->title = $INPUT->str('pdfbook_title'); //DEPRECATED
172+
$this->title = $INPUT->str('book_title', $this->title, true);
173+
if(empty($this->title)) {
170174
$this->showPageWithErrorMsg($event, 'needtitle');
171175
return false;
172176
} else {
@@ -189,9 +193,9 @@ protected function collectExportPages(Doku_Event $event) {
189193
exit();
190194
}
191195

192-
$title = $INPUT->str('pdfbook_title'); //DEPRECATED
193-
$title = $INPUT->str('book_title', $title, true);
194-
if(empty($title)) {
196+
$this->title = $INPUT->str('pdfbook_title'); //DEPRECATED
197+
$this->title = $INPUT->str('book_title', $this->title, true);
198+
if(empty($this->title)) {
195199
http_status(400);
196200
print $this->getLang('needtitle');
197201
exit();
@@ -228,17 +232,16 @@ protected function collectExportPages(Doku_Event $event) {
228232

229233
}
230234

231-
return array($title, $list);
235+
return array($this->title, $list);
232236
}
233237

234238
/**
235239
* Prepare cache
236240
*
237-
* @param string $title
238241
* @param array $depends (reference) array with dependencies
239242
* @return cache
240243
*/
241-
protected function prepareCache($title, &$depends) {
244+
protected function prepareCache(&$depends) {
242245
global $REV;
243246

244247
$cachekey = join(',', $this->list)
@@ -249,7 +252,7 @@ protected function prepareCache($title, &$depends) {
249252
. $this->getExportConfig('font-size')
250253
. $this->getExportConfig('doublesided')
251254
. ($this->getExportConfig('hasToC') ? join('-', $this->getExportConfig('levels')) : '0')
252-
. $title;
255+
. $this->title;
253256
$cache = new cache($cachekey, '.dw2.pdf');
254257

255258
$dependencies = array();
@@ -312,9 +315,8 @@ private function showPageWithErrorMsg(Doku_Event $event, $msglangkey, $replaceme
312315
* Build a pdf from the html
313316
*
314317
* @param string $cachefile
315-
* @param string $title
316318
*/
317-
protected function generatePDF($cachefile, $title) {
319+
protected function generatePDF($cachefile) {
318320
global $ID;
319321
global $REV;
320322
global $INPUT;
@@ -340,7 +342,7 @@ protected function generatePDF($cachefile, $title) {
340342
$mpdf->setBasePath($url);
341343

342344
// Set the title
343-
$mpdf->SetTitle($title);
345+
$mpdf->SetTitle($this->title);
344346

345347
// some default document settings
346348
//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) {
357359
}
358360

359361
// load the template
360-
$template = $this->load_template($title);
362+
$template = $this->load_template();
361363

362364
// prepare HTML header styles
363365
$html = '';
@@ -469,15 +471,14 @@ protected function generatePDF($cachefile, $title) {
469471

470472
/**
471473
* @param string $cachefile
472-
* @param string $title
473474
*/
474-
protected function sendPDFFile($cachefile, $title) {
475+
protected function sendPDFFile($cachefile) {
475476
header('Content-Type: application/pdf');
476477
header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0');
477478
header('Pragma: public');
478479
http_conditionalRequest(filemtime($cachefile));
479480

480-
$filename = rawurlencode(cleanID(strtr($title, ':/;"', ' ')));
481+
$filename = rawurlencode(cleanID(strtr($this->title, ':/;"', ' ')));
481482
if($this->getConf('output') == 'file') {
482483
header('Content-Disposition: attachment; filename="' . $filename . '.pdf";');
483484
} else {
@@ -503,10 +504,9 @@ protected function sendPDFFile($cachefile, $title) {
503504
/**
504505
* Load the various template files and prepare the HTML/CSS for insertion
505506
*
506-
* @param string $title
507507
* @return array
508508
*/
509-
protected function load_template($title) {
509+
protected function load_template() {
510510
global $ID;
511511
global $conf;
512512

@@ -547,7 +547,7 @@ protected function load_template($title) {
547547
$replace = array(
548548
'@PAGE@' => '{PAGENO}',
549549
'@PAGES@' => '{nbpg}', //see also $mpdf->pagenumSuffix = ' / '
550-
'@TITLE@' => hsc($title),
550+
'@TITLE@' => hsc($this->title),
551551
'@WIKI@' => $conf['title'],
552552
'@WIKIURL@' => DOKU_URL,
553553
'@DATE@' => dformat(time()),

0 commit comments

Comments
 (0)