1<?php
2/**
3 * DokuWiki Plugin skilltagicon (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Michael Große <grosse@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class action_plugin_skilltagicon_icon extends DokuWiki_Action_Plugin {
13
14    /**
15     * Registers a callback function for a given event
16     *
17     * @param Doku_Event_Handler $controller DokuWiki's event controller object
18     * @return void
19     */
20    public function register(Doku_Event_Handler $controller) {
21
22       $controller->register_hook('TPL_CONTENT_DISPLAY', 'BEFORE', $this, 'handle_tpl_content_display');
23
24    }
25
26    /**
27     * [Custom event handler which performs action]
28     *
29     * @param Doku_Event $event  event object by reference
30     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
31     *                           handler was registered]
32     * @return mixed, false if tagging plugin is missing, void otherwise.
33     */
34
35    public function handle_tpl_content_display(Doku_Event &$event, $param) {
36        global $ID,$ACT;
37
38        if ($ACT != 'show'){
39            return;
40        }
41
42        $tags = plugin_load('helper', 'tagging');
43        if(is_null($tags)) {
44            msg($this->getLang('tagging_missing'), -1);
45            return false;
46        }
47        $tags = $tags->findItems(array('pid' => $ID),'tag');
48
49        $easy_tag = $this->getConf('easy_tag');
50        $intermediate_tag = $this->getConf('intermediate_tag');
51        $expert_tag = $this->getConf('expert_tag');
52
53        $icon = false;
54        if (array_key_exists($easy_tag,$tags)) {
55            $icon = 'easy.png';
56            $icon_title = $this->getLang('easy_page');
57        } elseif (array_key_exists($intermediate_tag,$tags)) {
58            $icon = 'intermediate.png';
59            $icon_title = $this->getLang('intermediate_page');
60        } elseif (array_key_exists($expert_tag,$tags)) {
61            $icon = 'expert.png';
62            $icon_title = $this->getLang('expert_page');
63        }
64
65        if ($icon !== false) {
66            $icon_html = '<img src="lib/plugins/skilltagicon/icon/' . $icon . '" alt="" title="' . $icon_title . '" class="skilltagicon">';
67            $event->data = $icon_html . $event->data;
68        }
69    }
70
71}
72
73// vim:ts=4:sw=4:et:
74