Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to active multiple templates #371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -31,6 +34,11 @@ public function __construct() {
} elseif($REV) {
$this->params['rev'] = $REV;
}

if(!is_null($template)) {
$this->template = $template;
$this->params['template'] = $template;
}
}

/**
Expand All @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strlen() is not needed to check whether $this->template is empty.

$suffix = ' ('.$this->template.')';
}

return $hlp->getLang('export_pdf_button').$suffix;
}
}
35 changes: 23 additions & 12 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include all this logic in the loadExportConfig() function. The getExportConfig() should return the value which is used during the generation of the pdf.

btw, template is the wrong url-parameter, for the template this is actually tpl. But if you update loadExportConfig() this line is not needed anymore.

$this->title = $title ? $title : '';
}

Expand Down Expand Up @@ -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' =>
'<li>'
. '<a href="' . wl($ID, $params) . '" class="action export_pdf" rel="nofollow" title="' . $this->getLang('export_pdf_button') . '">'
. '<span>' . $this->getLang('export_pdf_button') . '</span>'
. '</a>'
. '</li>'
) +
array_slice($event->data['items'], -1, 1, true);
foreach($this->getExportConfig('template') AS $template){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use here $this->getConf('template'), not getExportConfig(). Please note that $this->getConf('showexportbutton') is also only configurable from configuration manager. It is not useful to change the GUI by looking to the url-parameter value of tpl.


$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 =>
'<li>'
. '<a href="' . wl($ID, $params) . '" class="action export_pdf" rel="nofollow" title="' . $this->getLang('export_pdf_button') . ' ('. $template .'">'
. '<span>' . $this->getLang('export_pdf_button') . '</span>'
. '</a>'
. '</li>'
) +
array_slice($event->data['items'], -1, 1, true);
}
}
}

Expand All @@ -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)]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that the MenuItem($template) is only set to a specific template, if it is needed. So if more than one template is set in the config 'template'.

}
}
}
2 changes: 1 addition & 1 deletion conf/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$conf['toc'] = 0;
$conf['toclevels'] = '';
$conf['maxbookmarks'] = 5;
$conf['template'] = 'default';
$conf['template'] = array('default');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a string.
Since I did not save yet my config manager, this throws a warning, because the conf returns the default array instead of a string.

PHP Warning: explode() expects parameter 2 to be string, array given in /path/dokuwiki/dokuwiki/lib/plugins/dw2pdf/action.php on line 37

$conf['output'] = 'file';
$conf['usecache'] = 1;
$conf['usestyles'] = 'wrap,';
Expand Down
2 changes: 1 addition & 1 deletion conf/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admin can not set the order of the selected templates. So the first template is, for people using multiple templates, relative random the first of these selected templates.

I like the automatic addition of all available templates.

$meta['output'] = array('multichoice', '_choices' => array('browser', 'file'));
$meta['usecache'] = array('onoff');
$meta['usestyles'] = array('string');
Expand Down