From 3123f4979757227d6ce0af715d74799bf2bde5dc Mon Sep 17 00:00:00 2001 From: Matthias Choules Date: Thu, 14 Feb 2019 15:35:25 +0100 Subject: [PATCH] Added option to active multiple templates --- MenuItem.php | 19 +++++++++++++++++-- action.php | 35 +++++++++++++++++++++++------------ conf/default.php | 2 +- conf/metadata.php | 2 +- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/MenuItem.php b/MenuItem.php index 6aaf6b5d..f0ac3b40 100644 --- a/MenuItem.php +++ b/MenuItem.php @@ -19,10 +19,13 @@ class MenuItem extends AbstractItem { /** @var string icon file */ protected $svg = __DIR__ . '/file-pdf.svg'; + /** @var string template name */ + protected $template = ''; + /** * MenuItem constructor. */ - public function __construct() { + public function __construct($template = null) { parent::__construct(); global $REV, $DATE_AT; @@ -31,6 +34,11 @@ public function __construct() { } elseif($REV) { $this->params['rev'] = $REV; } + + if(!is_null($template)) { + $this->template = $template; + $this->params['template'] = $template; + } } /** @@ -40,6 +48,13 @@ public function __construct() { */ public function getLabel() { $hlp = plugin_load('action', 'dw2pdf'); - return $hlp->getLang('export_pdf_button'); + + $suffix = ''; + + if(strlen($this->template) > 0) { + $suffix = ' ('.$this->template.')'; + } + + return $hlp->getLang('export_pdf_button').$suffix; } } diff --git a/action.php b/action.php index a3b98a90..854d522a 100644 --- a/action.php +++ b/action.php @@ -34,7 +34,11 @@ class action_plugin_dw2pdf extends DokuWiki_Action_Plugin { * @param string $title */ public function __construct($title=null) { - $this->tpl = $this->getExportConfig('template'); + $templates = explode(',', $this->getExportConfig('template')); + global $INPUT; + $requestedTemplate = $INPUT->str('template', $templates[0]); // exp + + $this->tpl = $requestedTemplate; $this->title = $title ? $title : ''; } @@ -956,16 +960,21 @@ public function addbutton(Doku_Event $event) { $params['rev'] = $REV; } - // insert button at position before last (up to top) - $event->data['items'] = array_slice($event->data['items'], 0, -1, true) + - array('export_pdf' => - '
  • ' - . '' - . '' . $this->getLang('export_pdf_button') . '' - . '' - . '
  • ' - ) + - array_slice($event->data['items'], -1, 1, true); + foreach($this->getExportConfig('template') AS $template){ + + $params['template'] = $template; + + // insert button at position before last (up to top) + $event->data['items'] = array_slice($event->data['items'], 0, -1, true) + + array('export_pdf_'.$template => + '
  • ' + . '' + . '' . $this->getLang('export_pdf_button') . '' + . '' + . '
  • ' + ) + + array_slice($event->data['items'], -1, 1, true); + } } } @@ -984,6 +993,8 @@ public function addsvgbutton(Doku_Event $event) { return; } - array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\dw2pdf\MenuItem()]); + foreach(explode(',', $this->getExportConfig('template')) AS $template){ + array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\dw2pdf\MenuItem($template)]); + } } } diff --git a/conf/default.php b/conf/default.php index ccac4255..060cddda 100644 --- a/conf/default.php +++ b/conf/default.php @@ -6,7 +6,7 @@ $conf['toc'] = 0; $conf['toclevels'] = ''; $conf['maxbookmarks'] = 5; -$conf['template'] = 'default'; +$conf['template'] = array('default'); $conf['output'] = 'file'; $conf['usecache'] = 1; $conf['usestyles'] = 'wrap,'; diff --git a/conf/metadata.php b/conf/metadata.php index e726daf7..273b6018 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -6,7 +6,7 @@ $meta['toc'] = array('onoff'); $meta['toclevels'] = array('string', '_pattern' => '/^(|[1-5]-[1-5])$/'); $meta['maxbookmarks'] = array('numeric'); -$meta['template'] = array('dirchoice', '_dir' => DOKU_PLUGIN . 'dw2pdf/tpl/'); +$meta['template'] = array('multicheckbox', '_other' => 'exists', '_choices' => array_map(function($path) { return basename($path); }, glob(DOKU_PLUGIN . 'dw2pdf/tpl/*', GLOB_ONLYDIR))); $meta['output'] = array('multichoice', '_choices' => array('browser', 'file')); $meta['usecache'] = array('onoff'); $meta['usestyles'] = array('string');