From 5bbd1782f8b45292e4fd708557f3f69c963c3e5d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 12 Dec 2018 13:37:21 +0100 Subject: [PATCH 1/2] added namespace export button --- MenuNSItem.php | 51 ++++++++++++++++++++++++++++++++++++++++++++ action.php | 13 ++++++++--- conf/default.php | 1 + conf/metadata.php | 1 + lang/en/lang.php | 1 + lang/en/settings.php | 1 + 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 MenuNSItem.php diff --git a/MenuNSItem.php b/MenuNSItem.php new file mode 100644 index 00000000..a850c053 --- /dev/null +++ b/MenuNSItem.php @@ -0,0 +1,51 @@ +params['at'] = $DATE_AT; + } elseif ($REV) { + $this->params['rev'] = $REV; + } + + $this->params['book_ns'] = getNS($ID); + $this->params['book_title'] = noNS(getNS($ID)); + } + + /** + * Get label from plugin language file + * + * @return string + */ + public function getLabel() + { + $hlp = plugin_load('action', 'dw2pdf'); + return $hlp->getLang('export_pdfns_button'); + } +} diff --git a/action.php b/action.php index a3b98a90..f243cf4b 100644 --- a/action.php +++ b/action.php @@ -975,8 +975,9 @@ public function addbutton(Doku_Event $event) { * @param Doku_Event $event */ public function addsvgbutton(Doku_Event $event) { - global $INFO; - if($event->data['view'] != 'page' || !$this->getConf('showexportbutton')) { + global $INFO, $ID; + + if($event->data['view'] != 'page') { return; } @@ -984,6 +985,12 @@ public function addsvgbutton(Doku_Event $event) { return; } - array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\dw2pdf\MenuItem()]); + if( $this->getConf('showexportbutton') ) { + array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\dw2pdf\MenuItem()]); + } + + if( $this->getConf('showexportnsbutton') && getNS($ID) ) { + array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\dw2pdf\MenuNSItem()]); + } } } diff --git a/conf/default.php b/conf/default.php index ccac4255..32cf40c2 100644 --- a/conf/default.php +++ b/conf/default.php @@ -12,3 +12,4 @@ $conf['usestyles'] = 'wrap,'; $conf['qrcodesize'] = '120x120'; $conf['showexportbutton'] = 1; +$conf['showexportnsbutton'] = 0; diff --git a/conf/metadata.php b/conf/metadata.php index e726daf7..a041e427 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -12,3 +12,4 @@ $meta['usestyles'] = array('string'); $meta['qrcodesize'] = array('string', '_pattern' => '/^(|\d+x\d+)$/'); $meta['showexportbutton'] = array('onoff'); +$meta['showexportnsbutton'] = array('onoff'); diff --git a/lang/en/lang.php b/lang/en/lang.php index 96af0c3d..5871e28b 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -1,6 +1,7 @@ style.css or screen.css should be used for PDF generation. By default only print.css and pdf.css are used.'; $lang['qrcodesize'] = 'Size of embedded QR code (in pixels <width>x<height>). Empty to disable'; $lang['showexportbutton'] = 'Show PDF export button (only when supported by your template)'; +$lang['showexportnsbutton'] = 'Show PDF Namespace export button (only when supported by your template)'; From 32c16e79eff116d800ae46df35511c379c397390 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 12 Dec 2018 13:54:54 +0100 Subject: [PATCH 2/2] support legacy menu event for NS export --- action.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/action.php b/action.php index f243cf4b..4e11ff99 100644 --- a/action.php +++ b/action.php @@ -948,7 +948,11 @@ public function getExportConfig($name, $notset = false) { public function addbutton(Doku_Event $event) { global $ID, $REV, $DATE_AT; - if($this->getConf('showexportbutton') && $event->data['view'] == 'main') { + if(!$event->data['view'] == 'main') { + return; + } + + if($this->getConf('showexportbutton')) { $params = array('do' => 'export_pdf'); if($DATE_AT) { $params['at'] = $DATE_AT; @@ -967,6 +971,28 @@ public function addbutton(Doku_Event $event) { ) + array_slice($event->data['items'], -1, 1, true); } + + if($this->getConf('showexportnsbutton') && getNS($ID)) { + $params = array('do' => 'export_pdf'); + if($DATE_AT) { + $params['at'] = $DATE_AT; + } elseif($REV) { + $params['rev'] = $REV; + } + $params['book_ns'] = getNS($ID); + $params['book_title'] = noNS(getNS($ID)); + + // insert button at position before last (up to top) + $event->data['items'] = array_slice($event->data['items'], 0, -1, true) + + array('export_pdfns' => + '
  • ' + . '' + . '' . $this->getLang('export_pdfns_button') . '' + . '' + . '
  • ' + ) + + array_slice($event->data['items'], -1, 1, true); + } } /**