1<?php
2/**
3 * Plugin Insert Icon: Inserts little icons
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Adolfo González Blázquez <code@infinicode.org>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'syntax.php');
13
14// Plugin path
15define('PLUGIN_DIR',DOKU_BASE.'lib/plugins/inserticon/');
16
17/**
18 * All DokuWiki plugins to extend the parser/rendering mechanism
19 * need to inherit from this class
20 */
21class syntax_plugin_inserticon extends DokuWiki_Syntax_Plugin {
22
23	function getInfo(){
24		return array(
25			'author' => 'Adolfo González Blázquez',
26			'email'  => 'code@infinicode.org',
27			'date'   => '2008-10-09',
28			'name'   => 'Insert Icon Plugin',
29			'desc'   => 'Inserts little icons',
30			'url'    => 'http://www.infinicode.org/code/dw/',
31		);
32    }
33
34    function getType() { return 'substition'; }
35    function getSort() { return 138; }
36
37    function connectTo($mode) {
38		$this->Lexer->addSpecialPattern('\{soundicon\}',$mode,'plugin_inserticon');
39		$this->Lexer->addSpecialPattern('\{videoicon\}',$mode,'plugin_inserticon');
40		$this->Lexer->addSpecialPattern('\{foldericon\}',$mode,'plugin_inserticon');
41		$this->Lexer->addSpecialPattern('\{zipicon\}',$mode,'plugin_inserticon');
42		$this->Lexer->addSpecialPattern('\{imageicon\}',$mode,'plugin_inserticon');
43		$this->Lexer->addSpecialPattern('\{peopleicon\}',$mode,'plugin_inserticon');
44    }
45
46    function handle($match, $state, $pos, &$handler) {
47    	return array($match, $state, $pos);
48    }
49
50    function render($mode, &$renderer, $data) {
51
52		if ($mode == 'xhtml') {
53			if ($data[0] == '{soundicon}') {
54				$renderer->doc .= '<img src="'.PLUGIN_DIR.'/images/sound.png" alt="MP3" title="Sound" align="top" />';
55				return true;
56			}
57			else if ($data[0] == '{videoicon}') {
58				$renderer->doc .= '<img src="'.PLUGIN_DIR.'/images/video.png" alt="Video" title="Video" align="top" />';
59				return true;
60			}
61			else if ($data[0] == '{foldericon}') {
62				$renderer->doc .= '<img src="'.PLUGIN_DIR.'/images/folder.png" alt="Carpeta" title="Folder" align="top" />';
63				return true;
64			}
65			else if ($data[0] == '{zipicon}') {
66				$renderer->doc .= '<img src="'.PLUGIN_DIR.'/images/zip.png" alt="ZIP" title="ZIP" align="top" />';
67				return true;
68			}
69			else if ($data[0] == '{imageicon}') {
70                $renderer->doc .= '<img src="'.PLUGIN_DIR.'/images/image.png" alt="Image" title="Image" align="top" />';
71                return true;
72            }
73            else if ($data[0] == '{peopleicon}') {
74                $renderer->doc .= '<img src="'.PLUGIN_DIR.'/images/people.png" alt="People" title="People" align="top" />';
75                return true;
76            }
77		}
78			return false;
79		}
80	}
81?>
82