]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - php5-patch.php
Update to reflect that configuration settings should go in config/config.ini not...
[SourceForge/phpwiki.git] / php5-patch.php
1 <?php
2   // ease PHP5 source file updates:
3   // each line with the special tag '/*PHP5 patch*/' will be commented or uncommented.
4
5 function check_php_version ($a = '0', $b = '0', $c = '0') {
6   global $PHP_VERSION;
7   if(!isset($PHP_VERSION))
8     $PHP_VERSION = substr( str_pad( preg_replace('/\D/','', PHP_VERSION), 3, '0'), 0, 3);
9   return $PHP_VERSION >= ($a.$b.$c);
10 }
11 function patch_into5 ($file) {
12   patch($file,'/^(\s+)(\/\*PHP5 patch\*\/)/',"\$1// \$2",'.php4');
13 }
14 function patch_into4 ($file) {
15   patch($file,'/^(\s+)\/\/ (\/\*PHP5 patch\*\/)/',"\$1\$2",'.php5');
16 }
17 function patch ($file,$from,$to,$bak='.bak') {
18   $tmpfile = $file.".tmp";
19   $in  = fopen($file,"rb");
20   $out = fopen($tmpfile,"wb");
21   $changed = 0;
22   while (!feof($in)) {
23     $s = fgets($in);
24     $new = preg_replace($from,$to,$s,1);
25     if ($new != $s) $changed++;
26     fputs($out,$new);
27   }
28   fclose($in);
29   fclose($out);
30   if ($changed) {
31     if (file_exists($file.$bak))
32       unlink($file.$bak);
33     rename($file,$file.$bak);
34     rename($tmpfile,$file);
35     echo "successfully patched $file, backup: $file$bak\n";
36   } else {
37     unlink($tmpfile);
38     echo "didn't patch $file\n";
39   }
40 }
41
42 $dir = dirname(__FILE__);
43 $patchfiles = array("lib/WikiUserNew.php");
44
45 // patch into which direction?
46 if (check_php_version(5)) $patchfunc = 'patch_into5';
47 else $patchfunc = 'patch_into4';
48
49 foreach ($patchfiles as $f) {
50   $file = $dir . "/" . $f;
51   if (!file_exists($f))
52     trigger_error("File $f not found");
53   $patchfunc($f);
54 }
55
56 ?>