DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:regexreplacer

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
plugin:regexreplacer [2012-01-26 16:47]
141.48.70.171 created
plugin:regexreplacer [2015-04-04 06:23]
PatrickBrown Remove bad download link
Line 5: Line 5:
 author ​    : Robert Jäckel / MLU Halle-Wittenberg author ​    : Robert Jäckel / MLU Halle-Wittenberg
 email      : robert.jaeckel@verwaltung.uni-halle.de email      : robert.jaeckel@verwaltung.uni-halle.de
-type       : plugin-creator+type       : plugin-creator,syntax
 lastupdate : 2012-01-26 lastupdate : 2012-01-26
 compatible : Rincewind, maybe more compatible : Rincewind, maybe more
Line 11: Line 11:
 conflicts ​ :  conflicts ​ : 
 similar ​   : plugin:​replace similar ​   : plugin:​replace
-tags       : replace macro regex plugin+tags       : replace macro regex plugins
  
-downloadurl:​ http://​wiki.verwaltung.uni-halle.de/​_export/​code/​wiki/​mlu-plugin?​codeblock=0 
-bugtracker : # eg. http://​github.com//​dokuwiki-plugin-regexreplacer/​issues 
-sourcerepo : # eg. http://​github.com//​dokuwiki-plugin-regexreplacer/​ 
-donationurl: ​ 
 ---- ----
 +
 +The Code was adapted from [[plugin:​replace]].
 +
 +This Plugin creates a syntax-plugin for each row in your config-file.
  
 ===== Installation ===== ===== Installation =====
Line 54: Line 54:
 </​file>​ </​file>​
  
 +===== plugin-script =====
 +
 +<file php syntax.php>​
 +
 +<?php
 +/**
 + * Plugin modMLU: regular expressions to generate a standarized wiki-syntax.
 + */
 +
 +if(!defined('​DOKU_INC'​)) define('​DOKU_INC',​realpath(dirname(__FILE__).'/​../​../'​).'/'​);​
 +if(!defined('​DOKU_PLUGIN'​)) define('​DOKU_PLUGIN',​DOKU_INC.'​lib/​plugins/'​);​
 +require_once(DOKU_PLUGIN.'​syntax.php'​);​
 +
 +class Syntax_Plugin_modMLU extends DokuWiki_Syntax_Plugin {
 +    public static $subs=0;
 +    protected static $modMLUconf;​
 +    public static $classDir;
 +    protected $realClassName = 'wiki mods @ mlu';
 +    function getInfo() {
 +        return array(
 +            '​author'​ => '​Robert Jäckel',​
 +            '​email' ​ => '​robert.jaeckel@verwaltung.uni-halle.de',​
 +            '​date' ​  => '​2012-01-12',​
 +            '​name' ​  ​=> ​ $this->​realClassName,​
 +            '​desc' ​  => '​Anpassungen des Wikis an der MLU Halle-Wittenberg',​
 +            '​url' ​   => '​http://​verwaltung.uni-halle.de',​
 +        );
 +    }
 +    function getType() { return '​substition';​ }
 +    function getAllowedTypes() { return array('​container','​substition','​protected','​disabled','​formatting','​paragraphs'​);​ }
 +    function render($mode,​ &​$renderer,​ $data) { return true; }
 +    function getSort() { return 999; }
 +    function generateReplaceClass($setup/​*=array($pattern,​$search,​$replace)*/​) {
 +        $dir = self::​$classDir.'​modMLU_'​.($idx=static::​$subs++);​
 +        @mkdir($dir);​
 + $file = $dir.'​\\syntax.php';​
 + $fHandle = fopen($file,'​w+'​);​
 + $generateStr = "<?​php \r\n";
 + $generateStr .="// file: $file\r\n\r\n";​
 + $generateStr .="// this file was generated automatically by modMLU-Syntax-Plugin\r\n\r\n";​
 + $generateStr .='​if(!defined(\'​DOKU_INC\'​)) define(\'​DOKU_INC\',​realpath(dirname(__FILE__).\'/​../​../​\'​).\'/​\'​);​if(!defined(\'​DOKU_PLUGIN\'​)) define(\'​DOKU_PLUGIN\',​DOKU_INC.\'​lib/​plugins/​\'​);';​
 + $generateStr .='​require_once(\''​.__FILE__."'​);​\r\n\r\n";​
 + $generateStr .= 'class Syntax_Plugin_modMLU_'​.$idx.'​ extends '​.get_class($this)."​{\r\n";​
 + foreach($setup as $k=>$v) $generateStr.='​protected $'​.$k.'​ = \''​.str_replace('​\'','​\\\'',​$v)."';​\r\n";​
 + $generateStr .= '​protected $subIDX='​.$idx.";​\r\n}\r\n\r\n";​
 + fwrite($fHandle,​$generateStr);​
 + fclose($fHandle);​
 + return $idx;
 +        // generate subclass
 +    }
 +    function Syntax_Plugin_modMLU() {
 +        //read cfg-file and create subclasses
 + if(isset(self::​$modMLUconf)) return true;
 + self::​$classDir = dirname(__FILE__).'​\\..\\';​
 + $cfg = self::​$modMLUconf = confToHash(DOKU_CONF . '​replaceMLU.conf'​);​
 + $requires = '';​
 + foreach($cfg as $pMatch=>​$sAction) {
 +            $aAction = explode("​\t",​$sAction,​2);​
 +     $idx=$this->​generateReplaceClass(array('​pattern'​=>​$pMatch,'​search'​=>​$aAction[0],'​replace'​=>​$aAction[1],'​realClassName'​=>​$this->​realClassName.'​_'​.self::​$subs));​
 + }
 +
 +    }
 +    function connectTo($mode) {
 + if(!$this->​pattern) return;
 + $this->​Lexer->​addSpecialPattern($this->​pattern,​$mode,​ '​plugin_modMLU_'​.$this->​subIDX);​
 +        //check for search string else return
 +    }
 +    function handle($match,​ $state, $pos, &​$handler) {
 + if ($this->​nesting) {
 +     $handler->​_addCall('​cdata',​ array($match),​ $pos);
 +        }
 +        else {
 +            $this->​nesting = true;
 +            $nestedWriter = & new Doku_Handler_Nest($handler->​CallWriter);​
 +            $handler->​CallWriter = & $nestedWriter;​
 +     /* add magic here */
 +     $this->​Lexer->​parse(preg_replace('/'​.$this->​search.'/',​$this->​replace,​$match)."​ \\\\ ");
 +
 +            $nestedWriter->​process();​
 +            $handler->​CallWriter = & $nestedWriter->​CallWriter;​
 +            $handler->​calls[count($handler->​calls) - 1][2] = $pos;
 +            $this->​nesting = false;
 +        }
 +        return false;
 +    }
 +}
 +
 +</​file>​
 +
 +===== Problem =====
 +  * How can I use this plugin? The download link is somewhat yield, so cannot install it.
 +  * However I've //mkdir regexreplacer//​ in the plugin directory and //mv modMLU.php syntax.php//​ and insert it into the new directory. Finally the plugin manager can recognize it but it doesn'​t work with its config file yet. (i.e. //​replaceMLU.conf//​ file in the dokuwiki //conf// directory). Actually the //conf// directory of my server is not in the default location because I'd moved it for security. What is the problem? Why it doesn'​t work?
plugin/regexreplacer.txt · Last modified: 2018-06-05 22:54 by Klap-in