1<?php
2/**
3 * DokuWiki Plugin acronym4glossary (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Michael Schuh <mike.schuh@gmx.at>
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.'syntax.php';
17
18class syntax_plugin_acronym4glossary extends DokuWiki_Syntax_Plugin {
19
20		var $acrData = array();
21
22    function getInfo() {
23      return array(
24              'author' => 'Michael Schuh',
25              'email'  => 'mike.schuh@gmx.at',
26              'date'   => '2010-06-16',
27              'name'   => 'acronym4glossary plugin (syntax component)',
28              'desc'   => 'This plugin uses the acronyms to build a glossary',
29              'url'    => 'http://blog.imho.at/20100819/artikel/dokuwiki-plugin-acronym4glossary',
30              );
31    }
32
33		function getType() {
34			return 'container';
35			//return 'FIXME: container|baseonly|formatting|substition|protected|disabled|paragraphs';
36		}
37
38		function getPType() {
39			return 'normal';
40			//return 'FIXME: normal|block|stack';
41		}
42
43    function getSort() {
44        return 190;
45    }
46
47
48    function connectTo($mode) {
49        $this->Lexer->addSpecialPattern('<GLOSSARY>',$mode,'plugin_acronym4glossary');
50    }
51
52		function handle($match, $state, $pos, Doku_Handler $handler){
53			$this->acrData = getAcronyms();
54			return $data;
55    }
56
57		function render($mode, Doku_Renderer $renderer, $data) {
58			if($mode != 'xhtml') return false;
59			$renderer->doc .= "<ul>\n";
60			$actLetter = "a";
61			foreach($this->acrData as $key => $value) {
62				if(strtolower($key{0}) != $actLetter) {
63					$actLetter = strtolower($key{0});
64					$renderer->doc .= "<br />";
65				}
66				$renderer->doc .= "<li>\n".$key." - " . $value."</li>";
67			}
68			$renderer->doc .= "</ul>";
69			return true;
70		}
71}
72
73// vim:ts=4:sw=4:et:enc=utf-8:
74