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