xref: /plugin/nodetailsxhtml/syntax/acronym.php (revision a6f86da8c6fbe8573be3be2b2e27a1954a2b3f3c)
1b07cf47aSGerry Weißbach<?php
2b07cf47aSGerry Weißbach/**
3b07cf47aSGerry Weißbach * iReflect Plugin
4b07cf47aSGerry Weißbach *
5b07cf47aSGerry Weißbach * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6b07cf47aSGerry Weißbach * @author     i-net software <tools@inetsoftware.de>
7b07cf47aSGerry Weißbach * @author     Gerry Weissbach <gweissbach@inetsoftware.de>
8b07cf47aSGerry Weißbach */
9b07cf47aSGerry Weißbach
10b07cf47aSGerry Weißbachif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
11b07cf47aSGerry Weißbachif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12b07cf47aSGerry Weißbachrequire_once(DOKU_PLUGIN.'syntax.php');
13b07cf47aSGerry Weißbach
14b07cf47aSGerry Weißbach/**
15b07cf47aSGerry Weißbach * All DokuWiki plugins to extend the parser/rendering mechanism
16b07cf47aSGerry Weißbach * need to inherit from this class
17b07cf47aSGerry Weißbach */
18b07cf47aSGerry Weißbachclass syntax_plugin_nodetailsxhtml_acronym extends DokuWiki_Syntax_Plugin {
19b07cf47aSGerry Weißbach
20*a6f86da8SGerry Weißbach    private $acronyms = array();
21*a6f86da8SGerry Weißbach    private $pattern = '';
22b07cf47aSGerry Weißbach
23b07cf47aSGerry Weißbach    function getInfo() {
24b07cf47aSGerry Weißbach        if ( method_exists(parent, 'getInfo')) {
25b07cf47aSGerry Weißbach            $info = parent::getInfo();
26b07cf47aSGerry Weißbach        }
27b07cf47aSGerry Weißbach        return array_merge(is_array($info) ? $info : confToHash(dirname(__FILE__).'/../plugin.info.txt'), array(
28b07cf47aSGerry Weißbach                'desc' => 'Acronym Extension to enable acronyms with whitespaces (represented as "_")',
29b07cf47aSGerry Weißbach        ));
30b07cf47aSGerry Weißbach    }
31b07cf47aSGerry Weißbach
32b07cf47aSGerry Weißbach    function getType(){ return 'substition';}
33b07cf47aSGerry Weißbach
34b07cf47aSGerry Weißbach    function getSort(){ return 230; }
35b07cf47aSGerry Weißbach
36b07cf47aSGerry Weißbach    function syntax_plugin_nodetailsxhtml_acronym() {
37b07cf47aSGerry Weißbach        global $conf;
38b07cf47aSGerry Weißbach
39b07cf47aSGerry Weißbach        if ( $conf['renderer_xhtml'] != 'nodetailsxhtml' ) { return; }
40b07cf47aSGerry Weißbach        $this->acronyms = getAcronyms();
41b07cf47aSGerry Weißbach    }
42b07cf47aSGerry Weißbach
43b07cf47aSGerry Weißbach    function preConnect() {
44b07cf47aSGerry Weißbach
45b07cf47aSGerry Weißbach        $acronyms = array();
46b07cf47aSGerry Weißbach        foreach( $this->acronyms as $key => $value ) {
47b07cf47aSGerry Weißbach                if ( !strstr($key, '_') ) { unset($this->acronyms[$key]); continue; }
48b07cf47aSGerry Weißbach                $acronyms[] = str_replace('_', ' ', $key);
49b07cf47aSGerry Weißbach        }
50b07cf47aSGerry Weißbach
51b07cf47aSGerry Weißbach        if(!count($acronyms)) return;
52b07cf47aSGerry Weißbach
53b07cf47aSGerry Weißbach        $bound = '[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]';
54b07cf47aSGerry Weißbach        $acronyms = array_map('Doku_Lexer_Escape',$acronyms);
55b07cf47aSGerry Weißbach        $this->pattern = '(?<=^|'.$bound.')(?:'.join('|',$acronyms).')(?='.$bound.')';
56b07cf47aSGerry Weißbach    }
57b07cf47aSGerry Weißbach
58b07cf47aSGerry Weißbach    function connectTo($mode){
59b07cf47aSGerry Weißbach        if(!count($this->acronyms)) return;
60b07cf47aSGerry Weißbach
61b07cf47aSGerry Weißbach        if ( strlen($this->pattern) > 0 ) {
62b07cf47aSGerry Weißbach            $this->Lexer->addSpecialPattern($this->pattern,$mode,'acronym');
63b07cf47aSGerry Weißbach        }
64b07cf47aSGerry Weißbach    }
65b07cf47aSGerry Weißbach}
66b07cf47aSGerry Weißbach
67b07cf47aSGerry Weißbach//Setup VIM: ex: et ts=4 enc=utf-8 :