1<?php
2/**
3 * DokuWiki Plugin hidepages (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Matthias Schulte <dokuwiki@lupo49.de>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15
16require_once DOKU_PLUGIN.'action.php';
17
18class action_plugin_hidepages extends DokuWiki_Action_Plugin {
19
20    public function register(Doku_Event_Handler $controller) {
21        $controller->register_hook('PAGEUTILS_ID_HIDEPAGE', 'BEFORE', $this, 'handle_hidepages');
22    }
23
24    public function handle_hidepages(Doku_Event &$event, $param) {
25        global $ACT;
26        global $conf;
27        global $INPUT;
28
29        // get page id from current result
30        $pageID = $event->data['id'];
31        $isHidden = $event->data['hidden'];
32
33        // skip if page is already marked as hidden or when the admin wants to see all pages
34        if($isHidden || $this->getConf('ignorepattern')) return true;
35
36        $metaHidden = p_get_metadata($pageID, 'hidepage');
37        $metaHiddenSearch = (isset($metaHidden['search']) ? true : false);
38        $metaHiddenSitemap = (isset($metaHidden['sitemap']) ? true : false);
39
40        // check if event is fired by quicksearch or sitemap ajax request
41        $isQsearch = ($INPUT->post->str('call') == 'qsearch' ? true : false);
42        $isAjaxIndex = ($INPUT->post->str('call') == 'index' ? true : false);
43
44        // Hide pages from quicksearch and search result page
45        if(($ACT == 'search' || $isQsearch) && $metaHiddenSearch == true) {
46            if($conf['allowdebug']) dbg("hidepages plugin - suppressed page: " . $pageID);
47            $event->data['hidden'] = true;
48        }
49
50        if(($ACT == 'index' || $isAjaxIndex) && $metaHiddenSitemap   == true) {
51            if($conf['allowdebug']) dbg("hidepages plugin - suppressed page: " . $pageID);
52            $event->data['hidden'] = true;
53        }
54
55        return true;
56    }
57}
58
59// vim:ts=4:sw=4:et:
60