xref: /plugin/mikioplugin/syntax/icon.php (revision d2d10ba751edcba51ab0218bce309115ad8eb3cd)
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();
10if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11
12require_once(dirname(__FILE__).'/core.php');
13
14class syntax_plugin_mikioplugin_icon extends syntax_plugin_mikioplugin_core {
15    public $tag                 = 'icon';
16    public $hasEndTag           = false;
17
18    // not declaring $options will return all options in the $data variable in lexer functions
19    public function getType() { return 'substition'; }
20    public function getPType() { return 'normal'; }
21
22    public function render_lexer_special(Doku_Renderer $renderer, $data) {
23        global $MIKIO_ICONS;
24
25        if(is_array($MIKIO_ICONS) && count($MIKIO_ICONS) > 0) {
26            foreach($MIKIO_ICONS as $icon) {
27                if(isset($icon['name']) && strcasecmp($icon['name'], $this->getFirstArrayKey($data)) == 0) {
28                    if(isset($icon['insert'])) {
29                        $insert = $icon['insert'];
30                        $keys = array_keys($data);
31                        $keys = array_pad($keys, 10, '');
32
33                        for($i = 1; $i < 10; $i++) {
34                            $insert = str_replace('$' . $i, $keys[$i], $insert);
35                        }
36
37                        $renderer->doc .= $insert;
38                    }
39                }
40
41                break;
42            }
43        }
44    }
45}
46?>