Skip to content

Commit 7ea2aa8

Browse files
committed
[plugin:replacer] support str_rules replacement
ページ保存時に str_rules によるユーザー定義置換を行うようにした。
1 parent e076e40 commit 7ea2aa8

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

xoops_trust_path/modules/xpwiki/plugin/replacer.inc.php

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
/*
33
* Created on 2008/03/25 by nao-pon http://hypweb.net/
4-
* $Id: replacer.inc.php,v 1.5 2011/11/26 12:03:10 nao-pon Exp $
54
*/
65

76
class xpwiki_plugin_replacer extends xpwiki_plugin {
@@ -241,6 +240,16 @@ function doit() {
241240
}
242241

243242
if ($dh = opendir($base)) {
243+
$root =& $this->root;
244+
245+
// save for reload rules.ini.php
246+
$_saves = array(
247+
'page' => $root->vars['page'],
248+
'datetime_rules' => $root->datetime_rules,
249+
'str_rules' => $root->str_rules,
250+
'str_rules_callback' => $root->str_rules_callback,
251+
);
252+
244253
while (($file = readdir($dh)) !== false && $max > $this->found) {
245254
if (preg_match('/^([a-f0-9]+)\.txt$/i', $file, $match)) {
246255
$page = $this->func->decode($match[1]);
@@ -250,6 +259,11 @@ function doit() {
250259
$src = file_get_contents($base . $file);
251260
$src = $this->func->remove_pginfo($src);
252261
if (preg_match_all($reg, $src, $target, PREG_PATTERN_ORDER)) {
262+
$root->vars['page'] = $page;
263+
264+
// reload rules.ini.php for make_str_rules()
265+
require($this->cont['DATA_HOME'] . 'private/ini/rules.ini.php');
266+
253267
$this->found++;
254268
$ret[$page]['src'] = $src;
255269
$ret[$page]['from'] = array();
@@ -266,6 +280,7 @@ function doit() {
266280
}
267281
$ret[$page]['src'] = $src;
268282
$src = preg_replace($reg, $rep, $src);
283+
$src = $this->func->make_str_rules($src);
269284
$ret[$page]['result'] = $src;
270285
if ($this->vars['pcmd'] === 'do') {
271286
$this->func->page_write($page, $src, $this->vars['nt']);
@@ -275,6 +290,12 @@ function doit() {
275290
}
276291
}
277292
closedir($dh);
293+
294+
// restore
295+
$root->vars['page'] = $_saves['page'];
296+
$root->datetime_rules = $_saves['datetime_rules'];
297+
$root->str_rules = $_saves['str_rules'];
298+
$root->str_rules_callback = $_saves['str_rules_callback'];
278299
}
279300
if ($this->found) {
280301
if ($this->vars['pcmd'] === 'test') {
@@ -360,5 +381,20 @@ function myErrorHandler($errno, $errstr) {
360381
}
361382
return false;
362383
}
384+
385+
////////////////////////////////
386+
// functions for rules.ini.php
387+
388+
private function format_date($var) {
389+
return $this->func->format_date($var);
390+
}
391+
392+
private function get_date($var) {
393+
return $this->func->get_date($var);
394+
}
395+
396+
private function htmlspecialchars($str, $flags = ENT_COMPAT, $encoding = null, $double_encode = true) {
397+
return $this->func->get_date($str, $flags, $encoding, $double_encode);
398+
}
363399
}
364400
?>

0 commit comments

Comments
 (0)