1<?php
2/**
3 * DokuWiki Plugin hidepages (Syntax Component)
4 *
5 * Syntax: ~~NOSIDEBAR~~
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     Matthias Schulte <dokuwiki@lupo49.de>
9 * @version    2013-08-02
10 */
11
12if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14require_once(DOKU_PLUGIN.'syntax.php');
15
16class syntax_plugin_hidepages extends DokuWiki_Syntax_Plugin {
17
18    function getType(){ return 'substition'; }
19    function getPType(){ return 'normal'; }
20    function getSort(){ return 990; }
21
22    function connectTo($mode) {
23        $this->Lexer->addSpecialPattern('~~HIDEPAGE.*?~~', $mode, 'plugin_hidepages');
24    }
25
26    function handle($match, $state, $pos, Doku_Handler $handler){
27        $data = array();
28        $match = hsc(trim($match));
29
30        if($match == '~~HIDEPAGE~~') {
31            if($this->getConf('hidefromsearch')) array_push($data, 'search');
32            if($this->getConf('hidefromsitemap')) array_push($data, 'sitemap');
33        } else {
34            // extract parameters search and sitemap if passed
35            $param = utf8_substr($match, 11, -2);
36
37            // $param could be "sitemap" or "sitemap;search"
38            if(utf8_strpos($param, ';') !== false) {
39                $param = explode(';', $param);
40            }
41
42            if($param == 'sitemap' || (is_array($param) && in_array('sitemap', $param))) {
43                array_push($data, 'sitemap');
44            }
45
46            if($param == 'search' || (is_array($param) && in_array('search', $param))) {
47                array_push($data, 'search');
48            }
49        }
50
51        return $data;
52    }
53
54    function render($mode, Doku_Renderer $renderer, $data) {
55        if($mode == "metadata") {
56            // set flag in metadata to hide page in action component
57            if(!is_array($data)) {
58                $renderer->meta['hidepage']['sitemap'] = true;
59                $renderer->meta['hidepage']['search'] = true;
60            } else {
61                if(in_array('sitemap', $data)) $renderer->meta['hidepage']['sitemap'] = true;
62                if(in_array('search', $data))  $renderer->meta['hidepage']['search'] = true;
63            }
64        }
65        return true;
66    }
67}
68
69//Setup VIM: ex: et ts=4 enc=utf-8 :
70