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

Add exporting full namespace as menu button #364

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
51 changes: 51 additions & 0 deletions MenuNSItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace dokuwiki\plugin\dw2pdf;

use dokuwiki\Menu\Item\AbstractItem;

/**
* Class MenuItem
*
* Implements the PDF namespace export button for DokuWiki's menu system
*
* @package dokuwiki\plugin\dw2pdf
*/
class MenuNSItem extends AbstractItem
{

/** @var string do action for this plugin */
protected $type = 'export_pdfns';

/** @var string icon file */
protected $svg = __DIR__ . '/file-pdf.svg';

/**
* MenuItem constructor.
*/
public function __construct()
{
parent::__construct();
global $REV, $DATE_AT, $ID;

if ($DATE_AT) {
$this->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');
}
}
41 changes: 37 additions & 4 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Copy link
Collaborator

@Klap-in Klap-in Oct 8, 2022

Choose a reason for hiding this comment

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

Is this tested? I guess this should be export_pdfns instead of 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' =>
'<li>'
. '<a href="' . wl($ID, $params) . '" class="action export_pdf" rel="nofollow" title="' . $this->getLang('export_pdfns_button') . '">'
. '<span>' . $this->getLang('export_pdfns_button') . '</span>'
. '</a>'
. '</li>'
) +
array_slice($event->data['items'], -1, 1, true);
}
}

/**
Expand All @@ -975,15 +1001,22 @@ 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;
}

if(!$INFO['exists']) {
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()]);
}
}
}
1 change: 1 addition & 0 deletions conf/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
$conf['usestyles'] = 'wrap,';
$conf['qrcodesize'] = '120x120';
$conf['showexportbutton'] = 1;
$conf['showexportnsbutton'] = 0;
1 change: 1 addition & 0 deletions conf/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
$meta['usestyles'] = array('string');
$meta['qrcodesize'] = array('string', '_pattern' => '/^(|\d+x\d+)$/');
$meta['showexportbutton'] = array('onoff');
$meta['showexportnsbutton'] = array('onoff');
1 change: 1 addition & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$lang['export_pdf_button'] = "Export to PDF";
$lang['export_pdfns_button'] = "Export Namespace to PDF";
$lang['needtitle'] = "Please provide a title.";
$lang['needns'] = "Please provide an existing namespace.";
$lang['notexist'] = "Requested page doesn't exist.";
Expand Down
1 change: 1 addition & 0 deletions lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,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['qrcodesize'] = 'Size of embedded QR code (in pixels <code><i>&lt;width&gt;</i><b>x</b><i>&lt;height&gt;</i></code>). 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)';