Hi there
I'm very new to DokuWiki and plugin development. At the moment I'm trying to implement a syntax plugin for use with the dw2pdf plugin like the pagesetting plugin for dw2pdf (see pagesetting.php in yourwiki/dw2pdf/syntax folder).
In this .php file the specialPattern '~~PDF:(?:LANDSCAPE|PORTRAIT)~~' is implemented, which can be used to set the orientation for single pages in the wiki.
I was now wondering, if I could implement another option for setting the template that should be used for the PDF export... So I used the pagesetting.php file as a pattern for creating a new syntax plugin that implements a new specialPattern '~~PDFTPL:(?:.*?)~~' (see code below). The problem is that I have no idea how to set the entered template name/value/whatever to the config, so that this entered template will be used for this page, when I click the 'Export to PDF' button. Can someone help me?
<?php
/**
* DokuWiki Plugin dw2pdf (Syntax Component)
*
* For defining the export template on the page.
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Marc Beutler
*/
/* Must be run within Dokuwiki */
if(!defined('DOKU_INC')) die();
/**
* Syntax for page specific directions for mpdf library
*/
class syntax_plugin_dw2pdf_exporttemplate extends DokuWiki_Syntax_Plugin {
/**
* Syntax Type
*
* Needs to return one of the mode types defined in $PARSER_MODES in parser.php
*
* @return string
*/
public function getType() {
return 'substition';
}
/**
* Sort for applying this mode
*
* @return int
*/
public function getSort() {
return 42;
}
/**
* @param string $mode
*/
public function connectTo($mode) {
$this->Lexer->addSpecialPattern('~~PDFTPL:(?:.*?)~~', $mode, 'plugin_dw2pdf_exporttemplate');
}
/**
* Handler to prepare matched data for the rendering process
*
* @param string $match The text matched by the patterns
* @param int $state The lexer state for the match
* @param int $pos The character position of the matched text
* @param Doku_Handler $handler The Doku_Handler object
* @return bool|array Return an array with all data you want to use in render, false don't add an instruction
*/
public function handle($match, $state, $pos, Doku_Handler $handler) {
return array($match, $state, $pos);
}
/**
* Handles the actual output creation.
*
* @param string $mode output format being rendered
* @param Doku_Renderer $renderer the current renderer object
* @param array $data data created by handler()
* @return boolean rendered correctly? (however, returned value is not used at the moment)
*/
public function render($mode, Doku_Renderer $renderer, $data) {
if($mode == 'xhtml') {
$tpl = substr($data[0], 9, -2);
$renderer->doc .= "<div class='dw2pdf-$tpl'></div>" . DOKU_LF;
return true;
}
return false;
}
}