Skip to content
Permalink
Browse files

[plugin:replacer] support str_rules replacement

ページ保存時に str_rules によるユーザー定義置換を行うようにした。
  • Loading branch information
nao-pon committed Oct 27, 2013
1 parent e076e40 commit 7ea2aa8695248033eb577a39f0f62a061c3a772a
Showing with 37 additions and 1 deletion.
  1. +37 −1 xoops_trust_path/modules/xpwiki/plugin/replacer.inc.php
@@ -1,7 +1,6 @@
<?php
/*
* Created on 2008/03/25 by nao-pon http://hypweb.net/
* $Id: replacer.inc.php,v 1.5 2011/11/26 12:03:10 nao-pon Exp $
*/

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

if ($dh = opendir($base)) {
$root =& $this->root;

// save for reload rules.ini.php
$_saves = array(
'page' => $root->vars['page'],
'datetime_rules' => $root->datetime_rules,
'str_rules' => $root->str_rules,
'str_rules_callback' => $root->str_rules_callback,
);

while (($file = readdir($dh)) !== false && $max > $this->found) {
if (preg_match('/^([a-f0-9]+)\.txt$/i', $file, $match)) {
$page = $this->func->decode($match[1]);
@@ -250,6 +259,11 @@ function doit() {
$src = file_get_contents($base . $file);
$src = $this->func->remove_pginfo($src);
if (preg_match_all($reg, $src, $target, PREG_PATTERN_ORDER)) {
$root->vars['page'] = $page;

// reload rules.ini.php for make_str_rules()
require($this->cont['DATA_HOME'] . 'private/ini/rules.ini.php');

$this->found++;
$ret[$page]['src'] = $src;
$ret[$page]['from'] = array();
@@ -266,6 +280,7 @@ function doit() {
}
$ret[$page]['src'] = $src;
$src = preg_replace($reg, $rep, $src);
$src = $this->func->make_str_rules($src);
$ret[$page]['result'] = $src;
if ($this->vars['pcmd'] === 'do') {
$this->func->page_write($page, $src, $this->vars['nt']);
@@ -275,6 +290,12 @@ function doit() {
}
}
closedir($dh);

// restore
$root->vars['page'] = $_saves['page'];
$root->datetime_rules = $_saves['datetime_rules'];
$root->str_rules = $_saves['str_rules'];
$root->str_rules_callback = $_saves['str_rules_callback'];
}
if ($this->found) {
if ($this->vars['pcmd'] === 'test') {
@@ -360,5 +381,20 @@ function myErrorHandler($errno, $errstr) {
}
return false;
}

////////////////////////////////
// functions for rules.ini.php

private function format_date($var) {
return $this->func->format_date($var);
}

private function get_date($var) {
return $this->func->get_date($var);
}

private function htmlspecialchars($str, $flags = ENT_COMPAT, $encoding = null, $double_encode = true) {
return $this->func->get_date($str, $flags, $encoding, $double_encode);
}
}
?>

0 comments on commit 7ea2aa8

Please sign in to comment.
You can’t perform that action at this time.