xref: /plugin/struct/syntax/table.php (revision 15929be2d8f1b3ae684ef1e73b344ee5c125512e)
1549a0837SAndreas Gohr<?php
2549a0837SAndreas Gohr/**
3549a0837SAndreas Gohr * DokuWiki Plugin struct (Syntax Component)
4549a0837SAndreas Gohr *
5549a0837SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6549a0837SAndreas Gohr * @author  Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
7549a0837SAndreas Gohr */
8549a0837SAndreas Gohr
9549a0837SAndreas Gohr// must be run within Dokuwiki
10*15929be2SAndreas Gohruse plugin\struct\meta\Search;
11*15929be2SAndreas Gohruse plugin\struct\meta\SearchException;
12*15929be2SAndreas Gohr
13549a0837SAndreas Gohrif (!defined('DOKU_INC')) die();
14549a0837SAndreas Gohr
15549a0837SAndreas Gohrclass syntax_plugin_struct_table extends DokuWiki_Syntax_Plugin {
16549a0837SAndreas Gohr    /**
17549a0837SAndreas Gohr     * @return string Syntax mode type
18549a0837SAndreas Gohr     */
19549a0837SAndreas Gohr    public function getType() {
20*15929be2SAndreas Gohr        return 'substition';
21549a0837SAndreas Gohr    }
22549a0837SAndreas Gohr    /**
23549a0837SAndreas Gohr     * @return string Paragraph type
24549a0837SAndreas Gohr     */
25549a0837SAndreas Gohr    public function getPType() {
26*15929be2SAndreas Gohr        return 'block';
27549a0837SAndreas Gohr    }
28549a0837SAndreas Gohr    /**
29549a0837SAndreas Gohr     * @return int Sort order - Low numbers go before high numbers
30549a0837SAndreas Gohr     */
31549a0837SAndreas Gohr    public function getSort() {
32*15929be2SAndreas Gohr        return 500;
33549a0837SAndreas Gohr    }
34549a0837SAndreas Gohr
35549a0837SAndreas Gohr    /**
36549a0837SAndreas Gohr     * Connect lookup pattern to lexer.
37549a0837SAndreas Gohr     *
38549a0837SAndreas Gohr     * @param string $mode Parser mode
39549a0837SAndreas Gohr     */
40549a0837SAndreas Gohr    public function connectTo($mode) {
41*15929be2SAndreas Gohr        $this->Lexer->addSpecialPattern('STRUCT',$mode,'plugin_struct_table');
42549a0837SAndreas Gohr    }
43549a0837SAndreas Gohr
44549a0837SAndreas Gohr
45549a0837SAndreas Gohr    /**
46549a0837SAndreas Gohr     * Handle matches of the struct syntax
47549a0837SAndreas Gohr     *
48549a0837SAndreas Gohr     * @param string $match The match of the syntax
49549a0837SAndreas Gohr     * @param int    $state The state of the handler
50549a0837SAndreas Gohr     * @param int    $pos The position in the document
51549a0837SAndreas Gohr     * @param Doku_Handler    $handler The handler
52549a0837SAndreas Gohr     * @return array Data for the renderer
53549a0837SAndreas Gohr     */
54ab466032SAndreas Gohr    public function handle($match, $state, $pos, Doku_Handler $handler){
55549a0837SAndreas Gohr        $data = array();
56549a0837SAndreas Gohr
57549a0837SAndreas Gohr        return $data;
58549a0837SAndreas Gohr    }
59549a0837SAndreas Gohr
60549a0837SAndreas Gohr    /**
61549a0837SAndreas Gohr     * Render xhtml output or metadata
62549a0837SAndreas Gohr     *
63549a0837SAndreas Gohr     * @param string         $mode      Renderer mode (supported modes: xhtml)
64549a0837SAndreas Gohr     * @param Doku_Renderer  $renderer  The renderer
65549a0837SAndreas Gohr     * @param array          $data      The data from the handler() function
66549a0837SAndreas Gohr     * @return bool If rendering was successful.
67549a0837SAndreas Gohr     */
68ab466032SAndreas Gohr    public function render($mode, Doku_Renderer $renderer, $data) {
69549a0837SAndreas Gohr        if($mode != 'xhtml') return false;
70549a0837SAndreas Gohr
71*15929be2SAndreas Gohr        try {
72*15929be2SAndreas Gohr            $search = new Search();
73*15929be2SAndreas Gohr            $search->addSchema('foo');
74*15929be2SAndreas Gohr            $search->addSchema('try1');
75*15929be2SAndreas Gohr            $search->addColumn('try1.first');
76*15929be2SAndreas Gohr            $sql = $search->getSQL();
77*15929be2SAndreas Gohr
78*15929be2SAndreas Gohr            $renderer->doc = $sql;
79*15929be2SAndreas Gohr        } catch (SearchException $e) {
80*15929be2SAndreas Gohr            msg($e->getMessage(), -1, $e->getLine(), $e->getFile());
81*15929be2SAndreas Gohr        }
82*15929be2SAndreas Gohr
83*15929be2SAndreas Gohr
84*15929be2SAndreas Gohr
85*15929be2SAndreas Gohr
86*15929be2SAndreas Gohr
87549a0837SAndreas Gohr        return true;
88549a0837SAndreas Gohr    }
89549a0837SAndreas Gohr}
90549a0837SAndreas Gohr
91549a0837SAndreas Gohr// vim:ts=4:sw=4:et:
92