Skip to content

Commit 5a48d4b

Browse files
committed
Merge pull request #190 from micgro42/nsexport
Add syntax to export namespace to pdf
2 parents 889f225 + 5112ddd commit 5a48d4b

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

_test/syntax_exportlink.test.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* General tests for the imagemap plugin
5+
*
6+
* @group plugin_dw2pdf
7+
* @group plugins
8+
*/
9+
class dw2pdf_syntax_exportlink_test extends DokuWikiTest {
10+
11+
public function setUp() {
12+
parent::setUp();
13+
}
14+
15+
protected $pluginsEnabled = array('dw2pdf');
16+
17+
function test_parser () {
18+
global $ID;
19+
$ID = 'foo:bar:start';
20+
$parser_response = p_get_instructions('~~PDFNS>.:|Foo~~');
21+
$expected_parser_response = array(
22+
'plugin',
23+
array(
24+
'dw2pdf_exportlink',
25+
array(
26+
'link' => '?do=export_pdfns&pdfns_ns=foo:bar&pdfns_title=Foo',
27+
'title' => 'Export namespace "foo:bar:" to file Foo.pdf',
28+
5,
29+
1,
30+
),
31+
5,
32+
'~~PDFNS>.:|Foo~~',
33+
),
34+
1,
35+
);
36+
$this->assertEquals($expected_parser_response,$parser_response[2]);
37+
$renderer_response = p_render('xhtml',$parser_response,$info);
38+
$expected_renderer_response = 'doku.php?id=foo:bar:start&amp;do=export_pdfns&amp;pdfns_ns=foo:bar&amp;pdfns_title=Foo" class="wikilink2" title="foo:bar:start" rel="nofollow">Export namespace &quot;foo:bar:&quot; to file Foo.pdf</a>';
39+
$trimmed_renderer_response = substr($renderer_response,strpos($renderer_response,'doku.php'),-5);
40+
$trimmed_renderer_response = trim($trimmed_renderer_response);
41+
$this->assertEquals($expected_renderer_response,$trimmed_renderer_response);
42+
}
43+
}
44+

lang/de/lang.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
/**
44
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
5-
*
5+
*
66
* @author Juergen-aus-Koeln <h-j-schuemmer@web.de>
77
*/
88
$lang['export_pdf_button'] = 'PDF exportieren';
99
$lang['needtitle'] = 'Bitte Titel angeben!';
1010
$lang['needns'] = 'Bitte geben Sie einen vorhandenen Namensraum an.';
1111
$lang['empty'] = 'Sie haben noch keine Seiten gewählt.';
1212
$lang['tocheader'] = 'Inhaltsverzeichnis';
13+
$lang['export_ns'] = 'Exportiere Namensraum "%s:" in Datei %s.pdf';

lang/en/lang.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
$lang['needns'] = "Please provide an existing namespace.";
66
$lang['empty'] = "You don't have pages selected yet.";
77
$lang['tocheader'] = "Table of Contents";
8+
$lang['export_ns'] = 'Export namespace "%s:" to file %s.pdf';

syntax/exportlink.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* DokuWiki Plugin dw2pdf (Syntax Component)
4+
*
5+
* For marking changes in page orientation.
6+
*
7+
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
8+
* @author Sam Wilson <sam@samwilson.id.au>
9+
*/
10+
/* Must be run within Dokuwiki */
11+
if(!defined('DOKU_INC')) die();
12+
13+
/**
14+
* Syntax for page specific directions for mpdf library
15+
*/
16+
class syntax_plugin_dw2pdf_exportlink extends DokuWiki_Syntax_Plugin {
17+
18+
/**
19+
* Syntax Type
20+
*
21+
* Needs to return one of the mode types defined in $PARSER_MODES in parser.php
22+
*
23+
* @return string
24+
*/
25+
public function getType() {
26+
return 'substition';
27+
}
28+
29+
/**
30+
* Sort for applying this mode
31+
*
32+
* @return int
33+
*/
34+
public function getSort() {
35+
return 41;
36+
}
37+
38+
/**
39+
* @param string $mode
40+
*/
41+
public function connectTo($mode) {
42+
$this->Lexer->addSpecialPattern('~~PDFNS>(?:.*?)\|(?:.*?)~~', $mode, 'plugin_dw2pdf_exportlink');
43+
}
44+
45+
/**
46+
* Handler to prepare matched data for the rendering process
47+
*
48+
* @param string $match The text matched by the patterns
49+
* @param int $state The lexer state for the match
50+
* @param int $pos The character position of the matched text
51+
* @param Doku_Handler $handler The Doku_Handler object
52+
* @return bool|array Return an array with all data you want to use in render, false don't add an instruction
53+
*/
54+
public function handle($match, $state, $pos, Doku_Handler $handler) {
55+
global $ID;
56+
$ns = substr($match,8,strpos($match,'|')-8);
57+
$id = $ns . ':start';
58+
resolve_pageid(getNS($ID),$id,$exists);
59+
$ns = getNS($id);
60+
$title = substr($match,strpos($match,'|')+1,-2);
61+
$link = '?do=export_pdfns&pdfns_ns=' . $ns . '&pdfns_title=' . $title;
62+
return array('link' => $link, 'title' => sprintf($this->getLang('export_ns'),$ns,$title),$state, $pos);
63+
}
64+
65+
/**
66+
* Handles the actual output creation.
67+
*
68+
* @param string $mode output format being rendered
69+
* @param Doku_Renderer $renderer the current renderer object
70+
* @param array $data data created by handler()
71+
* @return boolean rendered correctly? (however, returned value is not used at the moment)
72+
*/
73+
public function render($mode, Doku_Renderer $renderer, $data) {
74+
if($mode == 'xhtml') {
75+
$renderer->internallink($data['link'],$data['title']);
76+
return true;
77+
}
78+
return false;
79+
}
80+
81+
}

0 commit comments

Comments
 (0)