Skip to content

Commit 260742f

Browse files
authored
Merge branch 'master' into patch-1
2 parents e5f6c2c + 8814f69 commit 260742f

File tree

7 files changed

+53
-11
lines changed

7 files changed

+53
-11
lines changed

DokuPDF.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class DokuPDF extends mpdf {
2121

22-
function __construct($pagesize='A4', $orientation='portrait'){
22+
function __construct($pagesize='A4', $orientation='portrait', $fontsize){
2323
global $conf;
2424

2525
io_mkdir_p(_MPDF_TTFONTDATAPATH);
@@ -43,7 +43,7 @@ function __construct($pagesize='A4', $orientation='portrait'){
4343
}
4444

4545
// we're always UTF-8
46-
parent::__construct($mode, $format);
46+
parent::__construct($mode, $format, $fontsize);
4747
$this->autoScriptToLang = true;
4848
$this->baseScript = 1;
4949
$this->autoVietnamese = true;

action.php

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function convert(Doku_Event $event) {
7373
$cache = $this->prepareCache($title, $depends);
7474

7575
// hard work only when no cache available
76-
if(!$this->getConf('usecache') || !$cache->useCache($depends)) {
76+
if(!$this->getConf('usecache') || $this->getExportConfig('isDebug') || !$cache->useCache($depends)) {
7777
// generating the pdf may take a long time for larger wikis / namespaces with many pages
7878
set_time_limit(0);
7979

@@ -204,6 +204,30 @@ protected function collectExportPages(Doku_Event $event) {
204204
}
205205

206206
$list = array_map('cleanID', $list);
207+
208+
$skippedpages = array();
209+
foreach($list as $index => $pageid) {
210+
if(auth_quickaclcheck($pageid) < AUTH_READ) {
211+
$skippedpages[] = $pageid;
212+
unset($list[$index]);
213+
}
214+
}
215+
$list = array_filter($list); //removes also pages mentioned '0'
216+
217+
//if selection contains forbidden pages throw (overridable) warning
218+
if(!$INPUT->bool('book_skipforbiddenpages') && !empty($skippedpages)) {
219+
$msg = hsc(join(', ', $skippedpages));
220+
if($INPUT->has('selection')) {
221+
http_status(400);
222+
print sprintf($this->getLang('forbidden'), $msg);
223+
exit();
224+
} else {
225+
$this->showPageWithErrorMsg($event, 'forbidden', $msg);
226+
return false;
227+
}
228+
229+
}
230+
207231
return array($title, $list);
208232
}
209233

@@ -222,6 +246,7 @@ protected function prepareCache($title, &$depends) {
222246
. $this->getExportConfig('template')
223247
. $this->getExportConfig('pagesize')
224248
. $this->getExportConfig('orientation')
249+
. $this->getExportConfig('font-size')
225250
. $this->getExportConfig('doublesided')
226251
. ($this->getExportConfig('hasToC') ? join('-', $this->getExportConfig('levels')) : '0')
227252
. $title;
@@ -268,10 +293,16 @@ protected function prepareCache($title, &$depends) {
268293
* Set error notification and reload page again
269294
*
270295
* @param Doku_Event $event
271-
* @param string $msglangkey key of translation key
296+
* @param string $msglangkey key of translation key
297+
* @param string $replacement
272298
*/
273-
private function showPageWithErrorMsg(Doku_Event $event, $msglangkey) {
274-
msg($this->getLang($msglangkey), -1);
299+
private function showPageWithErrorMsg(Doku_Event $event, $msglangkey, $replacement=null) {
300+
if(empty($replacement)) {
301+
$msg = $this->getLang($msglangkey);
302+
} else {
303+
$msg = sprintf($this->getLang($msglangkey), $replacement);
304+
}
305+
msg($msg, -1);
275306

276307
$event->data = 'show';
277308
$_SERVER['REQUEST_METHOD'] = 'POST'; //clears url
@@ -296,7 +327,9 @@ protected function generatePDF($cachefile, $title) {
296327
// initialize PDF library
297328
require_once(dirname(__FILE__) . "/DokuPDF.class.php");
298329

299-
$mpdf = new DokuPDF($this->getExportConfig('pagesize'), $this->getExportConfig('orientation'));
330+
$mpdf = new DokuPDF($this->getExportConfig('pagesize'),
331+
$this->getExportConfig('orientation'),
332+
$this->getExportConfig('font-size'));
300333

301334
// let mpdf fix local links
302335
$self = parse_url(DOKU_URL);
@@ -380,9 +413,10 @@ protected function generatePDF($cachefile, $title) {
380413
$keep = $ID;
381414

382415
// loop over all pages
383-
$cnt = count($this->list);
384-
for($n = 0; $n < $cnt; $n++) {
385-
$page = $this->list[$n];
416+
$counter = 0;
417+
$no_pages = count($this->list);
418+
foreach($this->list as $page) {
419+
$counter++;
386420
$filename = wikiFN($page, $REV);
387421

388422
if(!file_exists($filename)) {
@@ -394,7 +428,7 @@ protected function generatePDF($cachefile, $title) {
394428

395429
$pagehtml = p_cached_output($filename, 'dw2pdf', $page);
396430
$pagehtml .= $this->page_depend_replacements($template['cite'], $page);
397-
if($n < ($cnt - 1)) {
431+
if($counter < $no_pages) {
398432
$pagehtml .= '<pagebreak />';
399433
}
400434

@@ -734,6 +768,9 @@ protected function loadExportConfig() {
734768
$this->exportConfig['pagesize'] = $INPUT->str('pagesize', $this->getConf('pagesize'), true);
735769
$this->exportConfig['orientation'] = $INPUT->str('orientation', $this->getConf('orientation'), true);
736770

771+
// decide on the font-size from param or config
772+
$this->exportConfig['font-size'] = $INPUT->str('font-size', $this->getConf('font-size'), true);
773+
737774
$doublesided = $INPUT->bool('doublesided', (bool) $this->getConf('doublesided'));
738775
$this->exportConfig['doublesided'] = $doublesided ? '1' : '0';
739776

conf/default.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
$conf['pagesize'] = 'A4';
33
$conf['orientation'] = 'portrait';
4+
$conf['font-size'] = 11;
45
$conf['doublesided'] = 1;
56
$conf['toc'] = 0;
67
$conf['toclevels'] = '';

conf/metadata.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
$meta['pagesize'] = array('string');
33
$meta['orientation'] = array('multichoice', '_choices' => array('portrait', 'landscape'));
4+
$meta['font-size'] = array('numeric');
45
$meta['doublesided'] = array('onoff');
56
$meta['toc'] = array('onoff');
67
$meta['toclevels'] = array('string', '_pattern' => '/^(|[1-5]-[1-5])$/');

lang/de/settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
$lang['orientation'] = 'Die Seiten-Ausrichtung';
1111
$lang['orientation_o_portrait'] = 'Hochformat';
1212
$lang['orientation_o_landscape'] = 'Querformat';
13+
$lang['font-size'] = 'Die Schriftgröße für normalen Text in Punkten.';
1314
$lang['doublesided'] = 'Doppelseitige Dokumente beginnen mit einer ungeraden Seite und werden fortgeführt mit Paaren von geraden und ungeraden Seiten. Einseitige Dokumente haben nur ungerade Seiten.';
1415
$lang['toc'] = 'Hinzufügen eines automatisch generierten Inhaltsverzeichnisses am Anfand der PDF-Datei (Anmerkungen: kann dazu führen, dass eine leere Seite eingefügt wird, damit der Text bei einer ungeraden Seitenzahl beginnt; das Inhaltsverzeichnis selbst wird bei der Seitennummerierung nicht mitgezählt)';
1516
$lang['toclevels'] = 'Oberste Ebene und maximale Tiefe des Inhaltsverzeichnisses. Standardmäßig werden die Werte aus der Wiki-Konfiguration <a href="#config___toptoclevel">toptoclevel</a> und <a href="#config___maxtoclevel">maxtoclevel</a> benutzt. Format: <code><i>&lt;top&gt;</i>-<i>&lt;max&gt;</i></code>';

lang/en/lang.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
$lang['empty'] = "You don't have pages selected yet.";
77
$lang['tocheader'] = "Table of Contents";
88
$lang['export_ns'] = 'Export namespace "%s:" to file %s.pdf';
9+
$lang['forbidden'] = "You have no access to these pages: %s.<br/><br/>Use option 'Skip Forbidden Pages' to create your book with the available pages.";

lang/en/settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
$lang['orientation'] = 'The page orientation.';
1111
$lang['orientation_o_portrait'] = 'Portrait';
1212
$lang['orientation_o_landscape'] = 'Landscape';
13+
$lang['font-size'] = 'The font-size for normal text in points.';
1314
$lang['doublesided'] = 'Double-sided document starts add odd page, and has pairs of even and odd pages. Single-side document has only odd pages.';
1415
$lang['toc'] = 'Add an autogenerated Table of Content in PDF (note: Can add blank pages due to start at an odd page and ToC always include on even number of pages, ToC pages itself has no pagenumbers)';
1516
$lang['toclevels'] = 'Define top level and maximum level depth which are added to ToC. Default wiki ToC levels <a href="#config___toptoclevel">toptoclevel</a> and <a href="#config___maxtoclevel">maxtoclevel</a> are used. Format: <code><i>&lt;top&gt;</i>-<i>&lt;max&gt;</i></code>';

0 commit comments

Comments
 (0)