xref: /plugin/dw2pdf/syntax/pagesetting.php (revision 254467c4df7b98a07196afe423d78250051ab76f)
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 */
11if(!defined('DOKU_INC')) die();
12
13/**
14 * Syntax for page specific directions for mpdf library
15 */
16class syntax_plugin_dw2pdf_pagesetting 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 40;
36    }
37
38    /**
39     * Paragraph Type
40     *
41     * @see Doku_Handler_Block
42     *
43     * @return string
44     */
45    public function getPType() {
46        return 'block';
47    }
48
49    /**
50     * @param string $mode
51     */
52    public function connectTo($mode) {
53        $this->Lexer->addSpecialPattern('~~PDF:(?:LANDSCAPE|PORTRAIT)~~', $mode, 'plugin_dw2pdf_pagesetting');
54    }
55
56    /**
57     * Handler to prepare matched data for the rendering process
58     *
59     * @param   string       $match   The text matched by the patterns
60     * @param   int          $state   The lexer state for the match
61     * @param   int          $pos     The character position of the matched text
62     * @param   Doku_Handler $handler The Doku_Handler object
63     * @return  bool|array Return an array with all data you want to use in render, false don't add an instruction
64     */
65    public function handle($match, $state, $pos, Doku_Handler $handler) {
66        return array($match, $state, $pos);
67    }
68
69    /**
70     * Handles the actual output creation.
71     *
72     * @param string        $mode     output format being rendered
73     * @param Doku_Renderer $renderer the current renderer object
74     * @param array         $data     data created by handler()
75     * @return  boolean                 rendered correctly? (however, returned value is not used at the moment)
76     */
77    public function render($mode, Doku_Renderer $renderer, $data) {
78        if($mode == 'xhtml') {
79            $orientation = strtolower(substr($data[0], 6, -2));
80            $renderer->doc .= "<div class='dw2pdf-$orientation'></div>" . DOKU_LF;
81            return true;
82        }
83        return false;
84    }
85
86}