'Replace', 'target' => $pagename, 'redirect' => 1, ); $opt = array_merge($defaults, ParseArgs($opt)); # echo $opt['target']; return "{$opt['label']}"; } Markup('replace','directives','/\(:stringreplace\\s+(.*?)\\s*:\)/e', "Keep(ReplaceLinkMarkup(\$pagename, PSS('$1')))"); # add stringreplace to actions $HandleActions['stringreplace'] = 'StringReplace'; function StringReplace($pagename) { global $EnableStringReplaceTarget; # initialise $currpage = $pagename; # security check if page has 'stringreplace' (in markup or Input) # $cpage = RetrieveAuthPage($currpage, "read"); # $ctext = $cpage['text']; # if(strstr($ctext,'stringreplace')==false) Redirect($currpage); # set optional target page if(isset($_POST['target']) OR isset($_GET['target'])) { if($EnableStringReplaceTarget==0) Redirect($currpage); //targets not allowed. stop. if(isset($_POST['target'])) $pagename = MakePageName($pagename, $_POST['target']); elseif($_GET['target']) $pagename = MakePageName($pagename, $_GET['target']); } # check edit permission $page = RetrieveAuthPage($pagename, 'edit', true); if (!$page) Abort("?cannot edit $pagename"); $newpage = $page; # get strings if(isset($_POST['str1'])) $str1 = stripmagic($_POST['str1']); else $str1 = stripmagic($_GET['str1']); if ($str1=="") HandleBrowse($currpage); if(isset($_POST['str2'])) $str2 = stripmagic($_POST['str2']); else $str2 = stripmagic($_GET['str2']); # do replacement in text $text = $page['text']; $textrows = explode("\n",$page['text']); foreach ($textrows as $nr => $line) { if(strstr($line,'(:stringreplace ')) continue; //don't replace in markup (:replace...:) if(strstr($line,'(:input ')) continue; //don't replace in any Input markup if(strstr($line,$str1)) { $textrows[$nr] = str_replace($str1, $str2, $textrows[$nr]); # break; //replace only first occurence } } $text = implode("\n",$textrows); # save page $newpage['text'] = $text; UpdatePage($pagename, $page, $newpage); # check redirect if(@$_POST['redir']==1 OR $_GET['redir']) Redirect($pagename); Redirect($currpage); }