Skip to content
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
22 changes: 22 additions & 0 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@
*/
class action_plugin_dw2pdf extends ActionPlugin
{
/**
* action_plugin_dw2pdf constructor.
*/
public function __construct()
{
global $JSINFO;

$this->loadConfig();

$JSINFO['plugins']['dw2pdf']['showexporttemplate'] = $this->getConf('showexporttemplate');

if ($this->getConf('showexporttemplate')) {
$templates = [$this->getConf('template')];
$dir = scandir(DOKU_PLUGIN . 'dw2pdf' . DIRECTORY_SEPARATOR . 'tpl');
foreach ($dir as $value) {
if (is_dir(DOKU_PLUGIN . 'dw2pdf' . DIRECTORY_SEPARATOR . 'tpl' . DIRECTORY_SEPARATOR . $value) && !in_array($value, array(".", "..", $this->getConf('template')))) {
$templates[] = $value;
}
}
$JSINFO['plugins']['dw2pdf']['templates'] = json_encode($templates);
}
}
/**
* Register the events
*
Expand Down
1 change: 1 addition & 0 deletions conf/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
$conf['usestyles'] = 'wrap,';
$conf['qrcodescale'] = '1';
$conf['showexportbutton'] = 1;
$conf['showexporttemplate'] = 0;
1 change: 1 addition & 0 deletions conf/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
$meta['usestyles'] = array('string');
$meta['qrcodescale'] = array('string', '_pattern' => '/^(|\d+(\.\d+)?)$/');
$meta['showexportbutton'] = array('onoff');
$meta['showexporttemplate'] = array('onoff');
4 changes: 4 additions & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
$lang['forbidden'] = "You have no read access to the selected pages.";
$lang['exportfailed'] = "The PDF could not be created.";
$lang['missingbookcreator'] = 'The Bookcreator Plugin is not installed or is disabled';
$lang['js']['export_pdf_modal'] = "Export to PDF";
$lang['js']['template'] = 'Which template should be used for formatting the PDFs?';
$lang['js']['cancel'] = 'Cancel';
$lang['js']['export'] = 'Export';
1 change: 1 addition & 0 deletions lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
$lang['usestyles'] = 'You can give a comma separated list of plugins of which the <code>style.css</code> or <code>screen.css</code> should be used for PDF generation. By default only <code>print.css</code> and <code>pdf.css</code> are used.';
$lang['qrcodescale'] = 'Size scaling of the embedded QR code. Empty or <code>0</code> to disable.';
$lang['showexportbutton'] = 'Show PDF export button (only when supported by your template)';
$lang['showexporttemplate'] = 'Show PDF export template selection';
4 changes: 4 additions & 0 deletions lang/pt-br/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
$lang['tocheader'] = 'Índice';
$lang['export_ns'] = 'Exportar domínio "%s:" para o arquivo %s.pdf';
$lang['missingbookcreator'] = 'O plugin Bookcreator não está instalado ou está desativado';
$lang['js']['export_pdf_modal'] = 'Exportar para PDF';
$lang['js']['template'] = 'Qual modelo deve ser usado para formatar os PDFs?';
$lang['js']['cancel'] = 'Cancelar';
$lang['js']['export'] = 'Exportar';
1 change: 1 addition & 0 deletions lang/pt-br/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
$lang['usestyles'] = 'Você pode gerar uma lista de plugins separadas por vírgula nos quais <code>style.css</code> ou <code>screen.css</code> devem ser usadas para a gerar um PDF.';
$lang['qrcodescale'] = 'Escala de tamanho do código QR incorporado. Vazio ou <code>0</code> para desativar.';
$lang['showexportbutton'] = 'Mostrar botão de exportação de PDF (se suportado pelo modelo)';
$lang['showexporttemplate'] = 'Mostrar seleção de template de exportação de PDF';
9 changes: 9 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* includes all needed JavaScript for the dw2pdf plugin
*
* be sure to touch this file when one of the scripts has been updated to refresh caching
*/

jQuery(function() {
/* DOKUWIKI:include script/template.js */
});
107 changes: 107 additions & 0 deletions script/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* Template dialog for end users
*
* @author Eduardo Mozart de Oliveira <eduardomozart182@gmail.com>
*/
(function () {
if (!JSINFO || !JSINFO.plugins.dw2pdf.showexporttemplate) return;


// basic dialog template
let $dialogSelect = '<select name="template" style="width:100%">';
jQuery.each(JSON.parse(JSINFO.plugins.dw2pdf.templates),function(index, value){
$dialogSelect += '<option value="' + value + '">' + value + '</option>'
});
$dialogSelect += '</select>';

const $dialog = jQuery(
'<div>' +
'<form>' +
'<label>' + LANG.plugins.dw2pdf.template + '<br>' +
$dialogSelect +
'</label>' +
'</form>' +
'</div>'
);

/**
* Executes the renaming based on the form contents
* @return {boolean}
*/
const templateFN = function () {
window.location.href = jQuery('#dokuwiki__pagetools .action.export_pdf a').attr("href") + "&tpl=" + $dialog.find('select').find(':selected').text();

return true;
};

/**
* Create the actual dialog modal and show it
*/
const showDialog = function () {
$dialog.dialog({
title: LANG.plugins.dw2pdf.export_pdf_modal + ' ' + JSINFO.id,
width: 800,
height: 200,
dialogClass: 'plugin_dw2pdf_dialog',
modal: true,
buttons: [
{
text: LANG.plugins.dw2pdf.cancel,
click: function () {
$dialog.dialog("close");
}
},
{
text: LANG.plugins.dw2pdf.export,
click: templateFN
}
],
// remove HTML from DOM again
close: function () {
jQuery(this).remove();
}
});
};

/**
* Bind an event handler as the first handler
*
* @param {jQuery} $owner
* @param {string} event
* @param {function} handler
* @link https://stackoverflow.com/a/4700103
*/
const bindFirst = function ($owner, event, handler) {
$owner.unbind(event, handler);
$owner.bind(event, handler);

const events = jQuery._data($owner[0])['events'][event];
events.unshift(events.pop());

jQuery._data($owner[0])['events'][event] = events;
};


// attach handler to menu item
jQuery('#dokuwiki__pagetools .action.export_pdf a')
.show()
.click(function (e) {
e.preventDefault();
showDialog();
});

// attach handler to mobile menu entry
const $mobileMenuOption = jQuery('form select[name=do] option[value=export_pdf]');
if ($mobileMenuOption.length === 1) {
bindFirst($mobileMenuOption.closest('select[name=do]'), 'change', function (e) {
const $select = jQuery(this);
if ($select.val() !== 'export_pdf') return;
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
$select.val('');
showDialog();
});
}

})();