1<?php
2/**
3 * Mikio Syntax Plugin: Icon
4 *
5 * @link    http://github.com/nomadjimbob/mikioplugin
6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author  James Collins <james.collins@outlook.com.au>
8 */
9if (!defined('DOKU_INC')) { die();
10}
11if (!defined('DOKU_PLUGIN')) { define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
12}
13
14require_once dirname(__FILE__).'/core.php';
15
16class syntax_plugin_mikioplugin_icon extends syntax_plugin_mikioplugin_core
17{
18    public $tag                 = 'icon';
19    public $hasEndTag           = false;
20
21    // not declaring $options will return all options in the $data variable in lexer functions
22    public function getType()
23    {
24        return 'substition';
25    }
26    public function getPType()
27    {
28        return 'normal';
29    }
30
31    public function render_lexer_special(Doku_Renderer $renderer, $data)
32    {
33        global $MIKIO_ICONS;
34
35        if(is_array($MIKIO_ICONS) && count($MIKIO_ICONS) > 0) {
36            foreach($MIKIO_ICONS as $icon) {
37                if(isset($icon['name']) && strcasecmp($icon['name'], array_key_first($data)) == 0) {
38                    if(isset($icon['insert'])) {
39                        $insert = $icon['insert'];
40                        $keys = array_keys($data);
41                        $keys = array_pad($keys, 10, '');
42
43                        for($i = 1; $i < 10; $i++) {
44                            $insert = str_replace('$' . $i, $keys[$i], $insert);
45                        }
46
47                        $renderer->doc .= $insert;
48                    }
49                }
50
51                break;
52            }
53        }
54    }
55}
56?>