2 /***********************************
3 * NP_SQLite plugin ver 0.8.0 *
5 * This plugin modifies the plugins *
6 * when these are installed. *
9 ***********************************/
10 // The licence of this script is GPL
11 class NP_SQLite extends NucleusPlugin {
12 function getName() { return 'NP_SQLite'; }
13 function getMinNucleusVersion() { return 320; }
14 function getAuthor() { $this->install(); return 'Katsumi'; }
15 function getVersion() { global $SQLITECONF; return $SQLITECONF['VERSION']; }
16 function getURL() {return 'http://hp.vector.co.jp/authors/VA016157/';}
17 function getDescription() { return $this->showinfo(); }
18 function supportsFeature($what) { return (int)($what=='SqlTablePrefix'); }
19 function getEventList() { return array('PreAddPlugin','PreSkinParse','QuickMenu'); }
20 function hasAdminArea() { return 1; }
23 if (!$this->getOption('allowsql')) {
24 $this->createOption('allowsql',$this->translated('Allow SQL query during the management?'),'yesno','no');
26 if (!$this->getOption('numatonce')) {
27 $this->createOption('numatonce',$this->translated('Number of SQL queries at once when DB restore.'),'text','20','datatype=numerical');
28 $this->createOption('refreshwait',$this->translated('Wating tile (seconds) when DB restore.'),'text','1','datatype=numerical');
35 if ($this->infostr) echo "<b>".$this->infostr."</b><hr />\n";
36 return $this->translated('NP_SQLite plugin. Filesize of DB is now ').filesize($SQLITECONF['DBFILENAME']).' bytes.';
42 function event_QuickMenu(&$data){
44 $this->_showDebugMessage();
46 // only show to admins
47 if (!($member->isLoggedIn() && $member->isAdmin())) return;
49 array_push($data['options'], array(
51 'url' => $this->getAdminURL(),
52 'tooltip' => $this->translated('SQLite management')
55 function event_PreSkinParse(&$data){
56 $this->_showDebugMessage();
58 function _showDebugMessage(){
60 if (isset($SQLITECONF['DEBUGMESSAGE'])) sqlite_DebugMessage();
61 unset($SQLITECONF['DEBUGMESSAGE']);
64 function event_PreAddPlugin(&$data){
65 // This event happens before loading "NP_XXXX.php" file.
66 // Therefore, modification is possible here.
67 $this->modify_plugin($data['file'],true);
69 function modify_plugin($pluginfile,$install=false){
70 global $DIR_PLUGINS,$SQLITECONF;
71 if ($SQLITECONF['OVERRIDEMODE']) return true;
73 $admindir=$DIR_PLUGINS.strtolower(substr($pluginfile,3));
74 $pluginfile=$DIR_PLUGINS.$pluginfile;
76 // List up all PHP files.
78 array_push($phpfiles,$pluginfile.'.php');
79 $this->seekPhpFiles($admindir,$phpfiles);
81 // Modify the PHP files.
83 foreach ($phpfiles as $file) {
84 if (!$this->changeFunctions($file)) {
89 if ($install) $this->infostr=$this->translated('Pluing was installed sucessfully');
93 if (!$install) return false;
94 if ($this->is_japanese()) {
95 echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" /></head>';
96 echo '<body><h3>PHP ¥Õ¥¡¥¤¥ë¤ò¼êÆ°¤ÇÊѹ¹¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£</h3>';
97 } else echo '<html><body><h3>Need to modify PHP file(s) manually.</h3>';
98 foreach ($phpfiles as $file) echo $this->show_Lines($file);
99 exit ('</body></html>');
102 function seekPhpFiles($dir,&$phpfiles){
103 if (!is_dir($dir)) return;
105 $dirpath=realpath($d->path);
107 if (substr($dirpath,-1)!='/' && substr($dirpath,-1)!="\\") $dirpath.='/';
108 while (false !== ($entry = $d->read())) {
109 if ($entry=='.' || $entry=='..') continue;
110 if (is_file($dirpath.$entry) && substr($entry,-4)=='.php') array_push($phpfiles,realpath($dirpath.$entry));
111 if (is_dir($dirpath.$entry)) array_push($dirs,realpath($dirpath.$entry));
114 foreach($dirs as $dir) $this->seekPhpFiles($dir,$phpfiles);
116 function changeFunctions($file){
117 if (!is_file($file=realpath($file))) return false;
118 if (!is_readable($file)) return false;
119 $before=$this->read_from_file($file);
120 // Do this process until change does not occur..
121 // Otherwise, sometime file is not completely modified.
122 $after=$this->do_replace($before);
123 if ($before!=$after) return $this->write_to_file($file,$after);
126 function do_replace(&$text) {
127 // Do this process until change does not occur..
128 // Otherwise, sometime file is not completely modified.
130 do $after=preg_replace('/([^_])mysql_([_a-z]+)([\s]*?)\(/','$1nucleus_mysql_$2(',($before=$after));
131 while ($before!=$after);
134 function show_Lines($file){
135 if (!is_file($file=realpath($file))) return '';
136 if (!is_readable($file)) return '';
140 foreach($lines as $num=>$before) {
141 $after=$this->do_replace($before);
142 if ($after!=$before) {
143 if ($firsttime) $result.="<hr />\nFile: <b>$file</b><br /><br />\n";
145 $result.="Modify line <b>".($num+1)."</b> like: "\n";
146 $result.=str_replace('nucleus_mysql_','<font color="#ff0000">nucleus_</font>mysql_',htmlspecialchars($after)).""<br /><br />\n";
151 function read_from_file($file) {
152 if (function_exists('file_get_contents') ) $ret=file_get_contents($file);
156 $ret=ob_get_contents();
161 function write_to_file($file,&$text){
162 if (!$handle = @fopen($file, 'w')) return false;
163 fwrite($handle,$text);
167 function is_japanese(){
168 $language = str_replace( array('\\','/'), array('',''), getLanguageName());
169 return (strpos($language,'japanese')===0);
174 function translated($english){
175 if (!is_array($this->langArray)) {
176 $this->langArray=array();
177 $language=$this->getDirectory().'language/'.str_replace( array('\\','/'), array('',''), getLanguageName()).'.php';
178 if (file_exists($language)) include($language);
180 if (!($ret=$this->langArray[$english])) $ret=$english;