1<?php
2/**
3 *
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Myron Turner <turnermm02@shaw.ca>
7 */
8
9// Syntax: <color somecolour/somebackgroundcolour>
10
11// must be run within Dokuwiki
12if(!defined('DOKU_INC')) die();
13
14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15require_once(DOKU_PLUGIN.'syntax.php');
16
17/**
18 * All DokuWiki plugins to extend the parser/rendering mechanism
19 * need to inherit from this class
20 */
21class syntax_plugin_fckg_font extends DokuWiki_Syntax_Plugin {
22
23
24
25    function getType(){ return 'formatting'; }
26    function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
27    function getSort(){ return 158; }
28    function connectTo($mode) { $this->Lexer->addEntryPattern('<font.*?>(?=.*?</font>)',$mode,'plugin_fckg_font'); }
29    function postConnect() { $this->Lexer->addExitPattern('</font>','plugin_fckg_font'); }
30
31
32    /**
33     * Handle the match
34     */
35    function handle($match, $state, $pos, Doku_Handler $handler){
36
37
38        switch ($state) {
39          case DOKU_LEXER_ENTER :
40                list($size, $face) = preg_split("/\//u", substr($match, 6, -1), 2);
41                if(isset($size)) {
42                        list($size,$weight) = explode(':',$size);
43                        $size = "font-size:$size;";
44                        if(isset($weight) && $weight) {
45                           $size .= " font-weight:$weight; ";
46                        }
47
48                }
49
50                return array($state, array($size, $face));
51
52          case DOKU_LEXER_UNMATCHED :  return array($state, $match);
53          case DOKU_LEXER_EXIT :       return array($state, '');
54        }
55        return array();
56    }
57
58    /**
59     * Create output
60     */
61    function render($mode, Doku_Renderer $renderer, $data) {
62        if($mode == 'xhtml'){
63            list($state, $match) = $data;
64
65            switch ($state) {
66              case DOKU_LEXER_ENTER :
67                list($style, $face) = $match;
68                if(isset($face)) {
69                    list($face,$fg,$bg) = explode(';;',$face);
70                    if(isset($fg)) {
71                         $color = " color: $fg; ";
72                         $style .= $color;
73
74                    }
75                    if(isset($bg)) {
76                         $color = " background-color: $bg ";
77                         $style .= $color;
78
79                    }
80
81                }
82                $style = "font-family: $face; $style";
83                $renderer->doc .= "<span face='$face' style='$style'>";
84                break;
85
86              case DOKU_LEXER_UNMATCHED :  $renderer->doc .= $renderer->_xmlEntities($match); break;
87              case DOKU_LEXER_EXIT :       $renderer->doc .= "</span>"; break;
88            }
89            return true;
90        }
91        return false;
92    }
93
94
95}
96?>
97