2 /*******************************************
3 * mysql_xxx => nucleus_mysql_xxx converter *
5 * ver 0.8.5 Written by Katsumi *
6 *******************************************/
8 // The license of this script is GPL
10 function modifyConfigInstall(){
14 array_push($pattern,'/^([\s\S]*?)include([^\(]*?)\(([\s\S]*?)\$([\s\S]+)\'globalfunctions.php\'([\s\S]*?)$/');
15 array_push($replace,'$1include$2($3\$DIR_NUCLEUS.\'sqlite/sqlite.php\'$5'.'$1include$2($3\$$4\'globalfunctions.php\'$5');
16 if (file_exists('./config.php')) {
17 $before=read_from_file('./config.php');
18 if (strpos($before,'sqlite.php')===false) {
19 $before=file('./config.php');
21 foreach($before as $line) $after.=preg_replace($pattern,$replace,$line);
22 if (!write_to_file(realpath('./config.php'),$after)) ExitWithError();
27 if (file_exists('./install.php')) {
28 $before=read_from_file('./install.php');
29 if (strpos($before,'sqlite.php')===false) {
31 // The same pattern/replce is also used for install.php
32 array_push($pattern,'/aConfPlugsToInstall([\s\S]+)\'NP_SkinFiles\'/i');
33 array_push($replace,'aConfPlugsToInstall$1\'NP_SkinFiles\',\'NP_SQLite\'');
34 array_push($pattern,'/<input[^>]+name="mySQL_host"([^\/]+)\/>/i');
35 array_push($replace,'<input name="mySQL_host" type="hidden" value="dummy" />Not needed for SQLite');
36 array_push($pattern,'/<input[^>]+name="mySQL_user"([^\/]+)\/>/i');
37 array_push($replace,'<input name="mySQL_user" type="hidden" value="dummy" />Not needed for SQLite');
38 array_push($pattern,'/<input[^>]+name="mySQL_password"([^\/]+)\/>/i');
39 array_push($replace,'<input name="mySQL_password" type="hidden" value="dummy" />Not needed for SQLite');
40 array_push($pattern,'/<input[^>]+name="mySQL_database"([^\/]+)\/>/i');
41 array_push($replace,'<input name="mySQL_database" type="hidden" value="dummy" />Not needed for SQLite');
42 array_push($pattern,'/<input[^>]+name="mySQL_create"([^\)]+)<\/label>/i');
43 array_push($replace,'Database will be created if not exist.');
44 $before=file('./install.php');
45 $after='<?php include("nucleus/sqlite/sqlite.php"); ?>';
46 foreach($before as $line) $after.=preg_replace($pattern,$replace,$line);
47 if (!write_to_file(realpath('./install.php'),$after)) ExitWithError();
52 if (!modifyBackup('./nucleus/libs/backup.php')) // less than version 3.3
53 modifyBackup('./nucleus/plugins/backup/NP_BackupAdmin.php','class'); // more than version 3.4 (??)
56 if (file_exists('./install.sql')) {
57 $before=file('./install.sql');
58 $pluginoptiontable=false;
60 foreach($before as $line){
61 if ($pluginoptiontable) {
62 if (preg_match('/TYPE\=MyISAM;/i',$line)) $pluginoptiontable=false;
63 else if (preg_match('/`oid`[\s]+int\(11\)[\s]+NOT[\s]+NULL[\s]+auto_increment/i',$line))
64 $line=preg_replace('/[\s]+auto_increment/i'," default '0'",$line);
66 if (preg_match('/CREATE[\s]+TABLE[\s]+`nucleus_plugin_option`/i',$line)) $pluginoptiontable=true;
68 if (strlen($after)==0) {
69 $replace='PRAGMA synchronous = off;';
70 if (!strstr($line,$replace)) $after=preg_replace('/^[^\r\n]*([\r\n]*)$/',$replace.'$1$1',$line);
74 if ($after!=$before) {
75 if (!write_to_file(realpath('./install.sql'),$after)) ExitWithError();
80 function modifyBackup($file,$type='global'){
81 if (!file_exists($file)) return false;
82 $before=read_from_file($file);
83 if (strpos($before,'sqlite_restore_execute_queries')===false) {
84 $pattern='/_execute_queries[\s]*\(([^\)]+)\)[\s]*;/i';
85 if ($type=='class') $pattern='/\$this->_execute_queries[\s]*\(([^\)]+)\)[\s]*;/i';
86 $replace='sqlite_restore_execute_queries($1);';
87 $after=preg_replace($pattern,$replace,$before);
88 if (!write_to_file(realpath($file),$after)) ExitWithError();
93 function seekPhpFiles($dir,&$phpfiles,$myself){
94 if (!is_dir($dir)) return;
96 $dirpath=realpath($d->path);
98 if (substr($dirpath,-1)!='/' && substr($dirpath,-1)!="\\") $dirpath.='/';
99 while (false !== ($entry = $d->read())) {
100 if ($entry=='.' || $entry=='..') continue;
101 if (is_file($dirpath.$entry) && substr($entry,-4)=='.php' && $entry!==$myself) array_push($phpfiles,realpath($dirpath.$entry));
102 if (is_dir($dirpath.$entry) && $entry!='language' && $entry!='sqlite' ) array_push($dirs,realpath($dirpath.$entry));
105 foreach($dirs as $dir) seekPhpFiles($dir,$phpfiles,$myself);
107 function changeFunctions($file){
108 if (!is_file($file=realpath($file))) return false;
109 if (!is_readable($file)) {
110 echo "Cannot read: $file<br />\n";
113 $before=read_from_file($file);
114 $after=do_replace($before);
115 if ($before!=$after) return write_to_file($file,$after);
118 function do_replace(&$text) {
119 // Do this process until change does not occur any more...
120 // Otherwise, sometime file is not completely modified.
121 // This is indeed the case for BLOG.php.
123 do $after=preg_replace('/([^_])mysql_([_a-z]+)([\s]*?)\(/','$1nucleus_mysql_$2(',($before=$after));
124 while ($before!=$after);
127 function read_from_file($file) {
128 if (function_exists('file_get_contents') ) $ret=file_get_contents($file);
132 $ret=ob_get_contents();
137 function write_to_file($file,&$text){
138 if (!$handle = @fopen($file, 'w')) {
139 echo "Cannot change: $file<br />\n";
142 fwrite($handle,$text);
144 echo "Changed: $file<br />\n";
147 function ExitWithError($text='Error occured.') {
148 echo "$text</body></html>";