1<?php
2/**
3 * DokuWiki Plugin HowHard (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Fabrice DEJAIGHER <fabrice@chtiland.com>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC'))
11{
12	die();
13}
14
15if (!defined('DOKU_LF'))
16{
17	define('DOKU_LF', "\n");
18}
19
20if (!defined('DOKU_TAB'))
21{
22	define('DOKU_TAB', "\t");
23}
24
25if (!defined('DOKU_PLUGIN'))
26{
27	define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
28}
29
30require_once DOKU_PLUGIN.'syntax.php';
31
32class syntax_plugin_howhard extends DokuWiki_Syntax_Plugin
33{
34
35    var $notes_hh = array('1','2','3','4','5');
36
37    var $note_defaut = '1';
38
39
40
41    public function getType()
42    {
43        return 'container';
44    }
45
46    public function getPType()
47    {
48        return 'normal';
49    }
50    public function getAllowedTypes()
51    {
52        return array('container','substition','protected','disabled','formatting','paragraphs');
53    }
54
55    public function getSort()
56    {
57        return 195;
58    }
59
60
61    public function connectTo($mode)
62    {
63        $this->Lexer->addSpecialPattern('\{\{howhard>.*?\}\}',$mode,'plugin_howhard');
64    }
65
66    public function handle($match, $state, $pos, Doku_Handler $handler)
67    {
68		switch ($state)
69		{
70		    case DOKU_LEXER_ENTER :
71		    break;
72
73		    case DOKU_LEXER_UNMATCHED :
74		        return array($state,$this->note_defaut);
75		    break;
76
77		    case DOKU_LEXER_SPECIAL :
78			$retour = substr($match,-3,1);
79			if(!in_array("$retour",$this->notes_hh) or empty($retour))
80			{
81				$retour=$this->note_defaut;
82			}
83			return array($state,$retour);
84		    break;
85
86		    default :
87			return array($state);
88
89
90		}
91
92
93    }
94
95    public function render($mode, Doku_Renderer $renderer, $indata)
96    {
97        list($state, $data) = $indata;
98
99        if($mode == 'xhtml')
100        {
101			// Compact mode ?
102			$isCompact = false;
103			if($this->getConf('confhowhardcompact')					// Activated
104					&& $this->getConf('confhowhardstyle') != 1)		// But not for style '1'
105			{
106				$isCompact = '_compact';
107			}
108
109			// vars
110			$text_level = 'level'.$data;
111            $style = $this->getConf('confhowhardstyle');
112
113			// Render
114            $renderer->doc.= '<div class="howhard'.$isCompact.'">';
115
116			if(!$isCompact)	// If not compact, add title.
117			{
118			    $renderer->doc.= '<div class="howhard_title">'.$this->getLang('howhardtitle').'</div>';
119			}
120
121
122            $renderer->doc.= '<div class="howhard_img_compact">';
123            $renderer->doc.= '<img src="'.DOKU_BASE.'lib/plugins/howhard/images/style'.$style.'/'.$data.'.png" border="0" rel="'.$this->getLang($text_level).'">';
124            $renderer->doc.= '</div>';
125            $renderer->doc.= '<div class="howhard_txt'.$isCompact.'">'.$this->getLang($text_level).'</div>';
126            $renderer->doc.= '</div>';
127
128            return true;
129
130        }
131        else
132        {
133            return false;
134		}
135    }
136}