@@ -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 = '' ;
@@ -470,15 +472,14 @@ protected function generatePDF($cachefile, $title) {
470472
471473 /**
472474 * @param string $cachefile
473- * @param string $title
474475 */
475- protected function sendPDFFile ($ cachefile, $ title ) {
476+ protected function sendPDFFile ($ cachefile ) {
476477 header ('Content-Type: application/pdf ' );
477478 header ('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0 ' );
478479 header ('Pragma: public ' );
479480 http_conditionalRequest (filemtime ($ cachefile ));
480481
481- $ filename = rawurlencode (cleanID (strtr ($ title , ':/;" ' , ' ' )));
482+ $ filename = rawurlencode (cleanID (strtr ($ this -> title , ':/;" ' , ' ' )));
482483 if ($ this ->getConf ('output ' ) == 'file ' ) {
483484 header ('Content-Disposition: attachment; filename=" ' . $ filename . '.pdf"; ' );
484485 } else {
@@ -504,10 +505,9 @@ protected function sendPDFFile($cachefile, $title) {
504505 /**
505506 * Load the various template files and prepare the HTML/CSS for insertion
506507 *
507- * @param string $title
508508 * @return array
509509 */
510- protected function load_template ($ title ) {
510+ protected function load_template () {
511511 global $ ID ;
512512 global $ conf ;
513513
@@ -548,7 +548,7 @@ protected function load_template($title) {
548548 $ replace = array (
549549 '@PAGE@ ' => '{PAGENO} ' ,
550550 '@PAGES@ ' => '{nbpg} ' , //see also $mpdf->pagenumSuffix = ' / '
551- '@TITLE@ ' => hsc ($ title ),
551+ '@TITLE@ ' => hsc ($ this -> title ),
552552 '@WIKI@ ' => $ conf ['title ' ],
553553 '@WIKIURL@ ' => DOKU_URL ,
554554 '@DATE@ ' => dformat (time ()),
0 commit comments