1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8function wikiplugin_regex_info() 9{ 10 return [ 11 'name' => tra('Regular Expression'), 12 'documentation' => 'PluginRegex', 13 'validate' => 'all', 14 'description' => tra('Perform a regular expression search and replace'), 15 'prefs' => [ 'wikiplugin_regex' ], 16 'body' => tra('Each line of content is evaluated separately'), 17 'iconname' => 'search', 18 'introduced' => 1, 19 'params' => [ 20 'pageName' => [ 21 'required' => true, 22 'name' => tra('Page name'), 23 'description' => tra('Name of page containing search and replace expressions separated by two colons. 24 Example of syntax on that page:') . ' <code>/search pattern/::replacement text</code>', 25 'since' => '1', 26 'default' => 'pageName', 27 'profile_reference' => 'wiki_page', 28 ], 29 ], 30 ]; 31} 32 33function wikiplugin_regex($data, $params) 34{ 35 global $tikilib; 36 37 extract($params, EXTR_SKIP); 38 $pageName = (isset($pageName)) ? $pageName : 'pageName';//gets a page 39 $info = $tikilib->get_page_info($pageName); 40 $content = $info['data']; 41 $lines = explode("\n", $content); // separate lines into array no emtpy lines at beginning mid or end 42 $i = 0; 43 foreach ($lines as $line) { 44 list($pattern[$i],$replace[$i]) = explode("::", $line);// use two colons to separate your find and replace 45 $i++; 46 } 47 48 $data = preg_replace($pattern, $replace, $data); 49 $data = trim($data); 50 return $data; 51} 52