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ßbach 13b07cf47aSGerry Weißbach/** 14b07cf47aSGerry Weißbach * All DokuWiki plugins to extend the parser/rendering mechanism 15b07cf47aSGerry Weißbach * need to inherit from this class 16b07cf47aSGerry Weißbach */ 17b07cf47aSGerry Weißbachclass syntax_plugin_nodetailsxhtml_acronym extends DokuWiki_Syntax_Plugin { 18b07cf47aSGerry Weißbach 19a6f86da8SGerry Weißbach private $acronyms = array(); 20a6f86da8SGerry Weißbach private $pattern = ''; 21b07cf47aSGerry Weißbach 22b07cf47aSGerry Weißbach function getInfo() { 23b07cf47aSGerry Weißbach if ( method_exists(parent, 'getInfo')) { 24b07cf47aSGerry Weißbach $info = parent::getInfo(); 25b07cf47aSGerry Weißbach } 26b07cf47aSGerry Weißbach return array_merge(is_array($info) ? $info : confToHash(dirname(__FILE__).'/../plugin.info.txt'), array( 27b07cf47aSGerry Weißbach 'desc' => 'Acronym Extension to enable acronyms with whitespaces (represented as "_")', 28b07cf47aSGerry Weißbach )); 29b07cf47aSGerry Weißbach } 30b07cf47aSGerry Weißbach 31b07cf47aSGerry Weißbach function getType(){ return 'substition';} 32b07cf47aSGerry Weißbach 33b07cf47aSGerry Weißbach function getSort(){ return 230; } 34b07cf47aSGerry Weißbach 35b07cf47aSGerry Weißbach function syntax_plugin_nodetailsxhtml_acronym() { 36b07cf47aSGerry Weißbach global $conf; 37b07cf47aSGerry Weißbach 38b07cf47aSGerry Weißbach if ( $conf['renderer_xhtml'] != 'nodetailsxhtml' ) { return; } 39b07cf47aSGerry Weißbach $this->acronyms = getAcronyms(); 40b07cf47aSGerry Weißbach } 41b07cf47aSGerry Weißbach 42b07cf47aSGerry Weißbach function preConnect() { 43b07cf47aSGerry Weißbach 44b07cf47aSGerry Weißbach $acronyms = array(); 45b07cf47aSGerry Weißbach foreach( $this->acronyms as $key => $value ) { 46b07cf47aSGerry Weißbach if ( !strstr($key, '_') ) { unset($this->acronyms[$key]); continue; } 47b07cf47aSGerry Weißbach $acronyms[] = str_replace('_', ' ', $key); 48b07cf47aSGerry Weißbach } 49b07cf47aSGerry Weißbach 50b07cf47aSGerry Weißbach if(!count($acronyms)) return; 51b07cf47aSGerry Weißbach 52b07cf47aSGerry Weißbach $bound = '[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]'; 53b07cf47aSGerry Weißbach $acronyms = array_map('Doku_Lexer_Escape',$acronyms); 54b07cf47aSGerry Weißbach $this->pattern = '(?<=^|'.$bound.')(?:'.join('|',$acronyms).')(?='.$bound.')'; 55b07cf47aSGerry Weißbach } 56b07cf47aSGerry Weißbach 57b07cf47aSGerry Weißbach function connectTo($mode){ 58b07cf47aSGerry Weißbach if(!count($this->acronyms)) return; 59b07cf47aSGerry Weißbach 60b07cf47aSGerry Weißbach if ( strlen($this->pattern) > 0 ) { 61b07cf47aSGerry Weißbach $this->Lexer->addSpecialPattern($this->pattern,$mode,'acronym'); 62b07cf47aSGerry Weißbach } 63b07cf47aSGerry Weißbach } 64*e20cc6f7SGerry Weißbach 65*e20cc6f7SGerry Weißbach function handle($match, $state, $pos, Doku_Handler $handler) { 66*e20cc6f7SGerry Weißbach return $match; 67*e20cc6f7SGerry Weißbach } 68*e20cc6f7SGerry Weißbach 69*e20cc6f7SGerry Weißbach function render($mode, Doku_Renderer $renderer, $data) { 70*e20cc6f7SGerry Weißbach return true; 71*e20cc6f7SGerry Weißbach } 72b07cf47aSGerry Weißbach} 73b07cf47aSGerry Weißbach 74b07cf47aSGerry Weißbach//Setup VIM: ex: et ts=4 enc=utf-8 :