1<?php
2/**
3 * fontfamily Plugin: control the font-family of your text
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Thorsten Stratmann <thorsten.stratmann@web.de>
7 * @link       http://wiki.splitbrain.org/plugin:fontfamily
8 * @version    0.3
9 */
10
11if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'syntax.php');
14
15/**
16 * All DokuWiki plugins to extend the parser/rendering mechanism
17 * need to inherit from this class
18 */
19class syntax_plugin_fontfamily extends DokuWiki_Syntax_Plugin {
20
21     // What kind of syntax are we?
22    function getType(){ return 'formatting'; }
23
24    // What kind of syntax do we allow (optional)
25    function getAllowedTypes() {
26        return array('formatting', 'substition', 'disabled');
27    }
28
29   // What about paragraphs? (optional)
30   function getPType(){ return 'normal'; }
31
32    // Where to sort in?
33    function getSort(){ return 92; }
34
35
36    // Connect pattern to lexer
37    function connectTo($mode) {
38      $this->Lexer->addEntryPattern('(?i)<ff(?: .+?)?>(?=.+</ff>)',$mode,'plugin_fontfamily');
39    }
40    function postConnect() {
41      $this->Lexer->addExitPattern('(?i)</ff>','plugin_fontfamily');
42    }
43
44
45    // Handle the match
46    function handle($match, $state, $pos, Doku_Handler $handler)
47    {
48        switch ($state)
49        {
50          case DOKU_LEXER_ENTER :
51            preg_match("/(?i)<ff (.+?)>/", $match, $ff);   // get the fontfamily
52           if ( $this->_isValid($ff[1]) ) return array($state, $ff[1]);
53			break;
54			case DOKU_LEXER_MATCHED :
55			break;
56			case DOKU_LEXER_UNMATCHED :
57			return array($state, $match);
58			break;
59			case DOKU_LEXER_EXIT :
60			break;
61			case DOKU_LEXER_SPECIAL :
62			break;
63		}
64		return array($state, "");
65	}
66
67    // Create output
68    function render($mode, Doku_Renderer $renderer, $data) {
69        if($mode == 'xhtml'){
70          list($state, $ff) = $data;
71          switch ($state) {
72            case DOKU_LEXER_ENTER :
73              $renderer->doc .= "<span style=\"font-family: $ff\">";
74              break;
75            case DOKU_LEXER_MATCHED :
76              break;
77            case DOKU_LEXER_UNMATCHED :
78              $renderer->doc .= $renderer->_xmlEntities($ff);
79              break;
80            case DOKU_LEXER_EXIT :
81              $renderer->doc .= "</span>";
82              break;
83            case DOKU_LEXER_SPECIAL :
84              break;
85          }
86          return true;
87        }
88        return false;
89    }
90    function _isValid($c) {
91
92        $c = trim($c);
93
94        $pattern = "/^(Arial|Brush Script MT|Comic Sans MS|Georgia|Impact|Times New Roman|Trebuchet|Verdana|Webdings])/x";
95
96  //      if (preg_match($pattern, $c)) return true;
97    return true;
98    }
99}
100