1<?php
2/**
3 * DokuWiki Plugin nsiconinsearch (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Christoph Ziehr <info@einsatzleiterwiki.de>
7 */
8
9// TO DO
10// Höhe selbst festlegen per conf, Hinweis dass kleine Bilder verwendet werden sollten
11
12// must be run within Dokuwiki
13if (!defined('DOKU_INC')) {
14    die();
15}
16
17class action_plugin_nsiconinsearch extends DokuWiki_Action_Plugin
18{
19
20    public function register(Doku_Event_Handler $controller)
21    {
22        $controller->register_hook('SEARCH_RESULT_PAGELOOKUP', 'BEFORE', $this, 'pagelookup',array());
23        $controller->register_hook('SEARCH_RESULT_FULLPAGE', 'BEFORE', $this, 'fullpage',array());
24    }
25
26    public function pagelookup(Doku_Event $event, $param)
27    {
28        // get the first level namespace
29        $actual_ns = strtok ( $event->data['page'] , (':') );
30        // check if an icon exists for the first level namespace, if yes show it for the search result
31        if (file_exists('data/media/'.$actual_ns.'/'.$this->getConf('iconfile'))) {
32            $icon = " <img src=\"lib/exe/fetch.php?media=". $actual_ns .":". $this->getConf('iconfile') ."\" alt=\"". $actual_ns ."\" width=\"". $this->getConf('iconwidth') ."\" height=\"". $this->getConf('iconheight') ."\">";
33            $event->data['listItemContent'][] = $icon;
34        }
35    }
36
37    public function fullpage(Doku_Event $event, $param)
38    {
39        // get the first level namespace
40        $actual_ns = strtok ( $event->data['page'] , (':') );
41        // check if an icon exists for the first level namespace, if yes show it for the search result
42        if (file_exists('data/media/'.$actual_ns.'/'.$this->getConf('iconfile'))) {
43            $icon = " <img src=\"lib/exe/fetch.php?media=". $actual_ns .":". $this->getConf('iconfile') ."\" alt=\"". $actual_ns ."\" width=\"". $this->getConf('iconwidth') ."\" height=\"". $this->getConf('iconheight') ."\">";
44        		$event->data['resultHeader'][] = $icon;
45        }
46    }
47}
48