Skip to content

Commit

Permalink
fix save_config() problem
Browse files Browse the repository at this point in the history
cache/pukiwiki.ini.php のファイルサイズが大きい場合、正規表現でのテキスト置換では、正常に置換できないことが起こりうるので str_replace() 及び explode() を使用した実装に変更した。
  • Loading branch information
nao-pon committed Jan 8, 2013
1 parent c437f71 commit 29748c9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions xoops_trust_path/modules/xpwiki/class/func/xpwiki_func.php
Expand Up @@ -1758,18 +1758,22 @@ function save_config ($file = '', $section = '', $data = '') {
$org = '';
} else {
$org = file_get_contents($file);
$org = preg_replace('/^<\?php\n(.*)\n\?>$/s', '$1', $org);
$org = trim(str_replace(array('<?php', '?>'), '', $org));
}

$section_q = preg_quote($section,'#');
$org = preg_replace('#//<'.$section_q.'>.*?//<'.$section_q.'/>\n#s', '', $org);
$org .= '//<'.$section_q.'>'."\n".$data."\n".'//<'.$section_q.'/>'."\n";
$data = '//<'.$section.'>' . "\n" . $data . "\n" . '//<'.$section.'/>';
if (strpos($org, '//<'.$section.'>') !== false) {
list($pre) = array_pad(explode('//<'.$section.'>'."\n", $org, 2), 2, '');
list(,$aft) = array_pad(explode("\n".'//<'.$section.'/>', $org, 2), 2, '');
$org = $pre . $data . $aft;
} else {
$org .= "\n" . $data;
}

$org = '<?php' . "\n" . $org . "\n" . '?>';

if ($fp = fopen($file, 'wb')) {
fwrite($fp, $org);
fclose($fp);

if (file_put_contents($file.'.tmp', $org, LOCK_EX)) {
rename($file.'.tmp', $file);
}
}

Expand Down

0 comments on commit 29748c9

Please sign in to comment.