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 5c4b9fd1..074e1081 100644 --- a/action.php +++ b/action.php @@ -1013,7 +1013,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; @@ -1032,6 +1036,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); + } } /** @@ -1040,8 +1066,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; } @@ -1049,6 +1076,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 cbb2c216..4931261d 100644 --- a/conf/default.php +++ b/conf/default.php @@ -13,3 +13,4 @@ $conf['usestyles'] = 'wrap,'; $conf['qrcodesize'] = '120x120'; $conf['showexportbutton'] = 1; +$conf['showexportnsbutton'] = 0; diff --git a/conf/metadata.php b/conf/metadata.php index b79cf4cd..762a1f93 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -13,4 +13,4 @@ $meta['usestyles'] = array('string'); $meta['qrcodesize'] = array('string', '_pattern' => '/^(|\d+x\d+)$/'); $meta['showexportbutton'] = array('onoff'); - +$meta['showexportnsbutton'] = array('onoff'); \ No newline at end of file diff --git a/lang/en/lang.php b/lang/en/lang.php index 9d24c289..9eb20986 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)';