| @@ 119-145 (lines=27) @@ | ||
| 116 | $path .= '/'; |
|
| 117 | if (!@copy($path . $sourceName, $path . $fileName)) { |
|
| 118 | return sprintf(ERR_COPY_MAINFILE, $fileName); |
|
| 119 | } else { |
|
| 120 | clearstatcache(); |
|
| 121 | if (!$file = fopen($path . $fileName, 'r')) { |
|
| 122 | return sprintf(ERR_READ_MAINFILE, $fileName); |
|
| 123 | } else { |
|
| 124 | $content = fread($file, filesize($path . $fileName)); |
|
| 125 | fclose($file); |
|
| 126 | ||
| 127 | foreach ($vars as $key => $val) { |
|
| 128 | if (is_int($val) && preg_match("/(define\()([\"'])(XOOPS_{$key})\\2,\s*(\d+)\s*\)/", $content)) { |
|
| 129 | $content = preg_replace("/(define\()([\"'])(XOOPS_{$key})\\2,\s*(\d+)\s*\)/", "define('XOOPS_{$key}', {$val})", $content); |
|
| 130 | } elseif (preg_match("/(define\()([\"'])(XOOPS_{$key})\\2,\s*([\"'])(.*?)\\4\s*\)/", $content)) { |
|
| 131 | $val = str_replace('$', '\$', addslashes($val)); |
|
| 132 | $content = preg_replace("/(define\()([\"'])(XOOPS_{$key})\\2,\s*([\"'])(.*?)\\4\s*\)/", "define('XOOPS_{$key}', '{$val}')", $content); |
|
| 133 | } |
|
| 134 | } |
|
| 135 | $file = fopen($path . $fileName, 'w'); |
|
| 136 | if (false === $file) { |
|
| 137 | return sprintf(ERR_WRITE_MAINFILE, $fileName); |
|
| 138 | } |
|
| 139 | $writeResult = fwrite($file, $content); |
|
| 140 | fclose($file); |
|
| 141 | if (false === $writeResult) { |
|
| 142 | return sprintf(ERR_WRITE_MAINFILE, $fileName); |
|
| 143 | } |
|
| 144 | } |
|
| 145 | } |
|
| 146 | return true; |
|
| 147 | } |
|
| 148 | ||
| @@ 107-130 (lines=24) @@ | ||
| 104 | { |
|
| 105 | $path .= '/'; |
|
| 106 | clearstatcache(); |
|
| 107 | if (!$inFile = fopen($path . $sourceName, 'r')) { |
|
| 108 | return sprintf(_FILE_ACCESS_ERROR, $sourceName); |
|
| 109 | } else { |
|
| 110 | $content = fread($inFile, filesize($path . $sourceName)); |
|
| 111 | fclose($inFile); |
|
| 112 | ||
| 113 | foreach ($vars as $key => $val) { |
|
| 114 | if (is_int($val) && preg_match("/(define\()([\"'])({$key})\\2,\s*(\d+)\s*\)/", $content)) { |
|
| 115 | $content = preg_replace("/(define\()([\"'])({$key})\\2,\s*(\d+)\s*\)/", "define('{$key}', {$val})", $content); |
|
| 116 | } elseif (preg_match("/(define\()([\"'])({$key})\\2,\s*([\"'])(.*?)\\4\s*\)/", $content)) { |
|
| 117 | $val = str_replace('$', '\$', addslashes($val)); |
|
| 118 | $content = preg_replace("/(define\()([\"'])({$key})\\2,\s*([\"'])(.*?)\\4\s*\)/", "define('{$key}', '{$val}')", $content); |
|
| 119 | } |
|
| 120 | } |
|
| 121 | $outFile = fopen($path . $fileName, 'w'); |
|
| 122 | if (false === $outFile) { |
|
| 123 | return sprintf(_FILE_ACCESS_ERROR, $fileName); |
|
| 124 | } |
|
| 125 | $writeResult = fwrite($outFile, $content); |
|
| 126 | fclose($outFile); |
|
| 127 | if (false === $writeResult) { |
|
| 128 | return sprintf(_FILE_ACCESS_ERROR, $fileName); |
|
| 129 | } |
|
| 130 | } |
|
| 131 | return true; |
|
| 132 | } |
|
| 133 | ||