1<?php
2
3/**
4 * DokuWiki Plugin struct (Filter Syntax Component)
5 *
6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
7 * @author  Andreas Gohr, Anna Dabrowska <dokuwiki@cosmocode.de>
8 */
9
10use dokuwiki\plugin\struct\meta\AggregationFilter;
11use dokuwiki\plugin\struct\meta\SearchConfig;
12use dokuwiki\plugin\struct\meta\StructException;
13
14class syntax_plugin_struct_filter extends syntax_plugin_struct_table
15{
16    /**
17     * Connect lookup pattern to lexer.
18     *
19     * @param string $mode Parser mode
20     */
21    public function connectTo($mode)
22    {
23        $this->Lexer->addSpecialPattern('----+ *struct filter *-+\n.*?\n----+', $mode, 'plugin_struct_filter');
24    }
25
26    /**
27     * @inheritDoc
28     */
29    public function render($format, Doku_Renderer $renderer, $config)
30    {
31        if ($format != 'xhtml') return false;
32        if (!$config) return false;
33
34        global $conf;
35        global $INFO;
36
37        try {
38            $search = new SearchConfig($config, false);
39            $filter = new AggregationFilter($INFO['id'], $format, $renderer, $search);
40
41            $filter->startScope();
42            $filter->render();
43            $filter->finishScope();
44
45            if ($format === 'metadata') {
46                /** @var Doku_Renderer_metadata $renderer */
47                $renderer->meta['plugin']['struct']['hasaggregation'] = $search->getCacheFlag();
48            }
49        } catch (StructException $e) {
50            msg($e->getMessage(), -1, $e->getLine(), $e->getFile());
51            if ($conf['allowdebug']) msg('<pre>' . hsc($e->getTraceAsString()) . '</pre>', -1);
52        }
53
54        return true;
55    }
56}
57