Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの
Revision | 13eca4b212f1f1bc6114f0c6148cf531b48cce4e (tree) |
---|---|
Time | 2006-10-15 19:53:58 |
Author | hsur <hsur@1ca2...> |
Commiter | hsur |
クォートが含まれるオプションが保存されない問題を修正
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@449 1ca29b6e-896d-4ea0-84a5-967f57386b96
@@ -1,12 +1,13 @@ | ||
1 | 1 | <?php |
2 | 2 | |
3 | +define('NP_RETAIN_OPTIONS_LIFETIME', 86400); | |
3 | 4 | |
4 | 5 | class NP_RetainOptions extends NucleusPlugin { |
5 | 6 | |
6 | 7 | function getNAME() { return 'Retain Options'; } |
7 | 8 | function getAuthor() { return 'Andy'; } |
8 | 9 | function getURL() { return ''; } |
9 | - function getVersion() { return '0.5'; } | |
10 | + function getVersion() { return '0.6'; } | |
10 | 11 | function getDescription() { |
11 | 12 | return 'Retain plugin options while you update(uninstall and reinstall) plugins. Keep up to one day'; |
12 | 13 | } |
@@ -59,30 +60,30 @@ class NP_RetainOptions extends NucleusPlugin { | ||
59 | 60 | function event_PreDeletePlugin(&$data) { |
60 | 61 | if ($this->getOption('disable') == 'yes') return; |
61 | 62 | $plugid = $data['plugid']; |
62 | - $result = sql_query('SELECT pfile FROM '.sql_table('plugin'). ' WHERE pid='.$plugid); | |
63 | + $result = sql_query('SELECT pfile FROM '.sql_table('plugin'). ' WHERE pid='.intval($plugid)); | |
63 | 64 | $plugin = mysql_fetch_array($result); |
64 | 65 | $pname = strtolower($plugin['pfile']); |
65 | 66 | mysql_free_result($result); |
66 | 67 | if ($pname == get_class($this)) return; // don't retain this plugin |
67 | 68 | $currenttime = mysqldate(time()); |
68 | 69 | sql_query('INSERT INTO '.sql_table('plug_retainoptions_plugin') |
69 | - . " (pluginname, storetime) VALUES ('$pname', $currenttime)"); | |
70 | + . " (pluginname, storetime) VALUES ('" . mysql_real_escape_string($pname) . "', " . intval($currenttime) . ")"); | |
70 | 71 | $id = mysql_insert_id(); |
71 | 72 | $descs = sql_query('SELECT oid, oname, ocontext FROM '.sql_table('plugin_option_desc') |
72 | - . ' WHERE opid='.$plugid); | |
73 | + . ' WHERE opid='.intval($plugid)); | |
73 | 74 | while ($desc = mysql_fetch_array($descs)) { |
74 | 75 | sql_query('INSERT INTO '.sql_table('plug_retainoptions_options'). ' SET ' |
75 | - . "id=$id" | |
76 | - . ', optionname="'.$desc['oname'].'"' | |
77 | - . ', optioncontext="'.$desc['ocontext'].'"'); | |
76 | + . "id=" . intval($id) | |
77 | + . ", optionname='".mysql_real_escape_string($desc['oname'])."'" | |
78 | + . ", optioncontext='".mysql_real_escape_string($desc['ocontext'])."'"); | |
78 | 79 | $optionid = mysql_insert_id(); |
79 | 80 | $options = sql_query('SELECT ovalue, ocontextid FROM '.sql_table('plugin_option') |
80 | 81 | . ' WHERE oid='.$desc['oid']); |
81 | 82 | while ($option = mysql_fetch_array($options)) { |
82 | 83 | sql_query('INSERT INTO '.sql_table('plug_retainoptions'). ' SET ' |
83 | - . "optionid=$optionid" | |
84 | - . ', contextid='.$option['ocontextid'] | |
85 | - . ', optionvalue="'.$option['ovalue'].'"'); | |
84 | + . "optionid=". intval($optionid) | |
85 | + . ', contextid='.intval($option['ocontextid']) | |
86 | + . ", optionvalue='".mysql_real_escape_string($option['ovalue'])."'"); | |
86 | 87 | } |
87 | 88 | mysql_free_result($options); |
88 | 89 | } |
@@ -93,9 +94,9 @@ class NP_RetainOptions extends NucleusPlugin { | ||
93 | 94 | if ($this->getOption('disable') == 'yes') return; |
94 | 95 | $plugin = & $data['plugin']; |
95 | 96 | $pname = get_class($plugin); |
96 | - $oldesttimestamp = mysqldate(time() - 24*60*60); | |
97 | + $oldesttimestamp = mysqldate(time() - NP_RETAIN_OPTIONS_LIFETIME); | |
97 | 98 | $result = sql_query('SELECT id FROM '.sql_table('plug_retainoptions_plugin') |
98 | - ." WHERE pluginname='$pname' AND STORETIME>=$oldesttimestamp"); | |
99 | + ." WHERE pluginname='". mysql_real_escape_string($pname) . "' AND STORETIME>=". intval($oldesttimestamp)); | |
99 | 100 | $nums = mysql_num_rows($result); |
100 | 101 | if (!$nums) { $this->cleanup(); return; } |
101 | 102 | while ($nums--) $row = mysql_fetch_array($result); |
@@ -103,20 +104,19 @@ class NP_RetainOptions extends NucleusPlugin { | ||
103 | 104 | $id = $row['id']; |
104 | 105 | $options = sql_query('SELECT optionid, optionname, optioncontext FROM ' |
105 | 106 | . sql_table('plug_retainoptions_options') |
106 | - . " WHERE id=$id"); | |
107 | + . " WHERE id=".intval($id)); | |
107 | 108 | while ($option = mysql_fetch_array($options)) { |
108 | 109 | $optionname = $option['optionname']; |
109 | 110 | $contextname = $option['optioncontext']; |
110 | 111 | $odescs = sql_query('SELECT oid FROM '.sql_table('plugin_option_desc') |
111 | - . ' WHERE opid='.$plugin->plugid | |
112 | - . ' AND oname="'.$optionname.'"' | |
113 | - | |
114 | - . ' AND ocontext="'.$contextname.'"'); | |
112 | + . ' WHERE opid='.intval($plugin->plugid) | |
113 | + . " AND oname='".mysql_real_escape_string($optionname)."'" | |
114 | + . " AND ocontext='".mysql_real_escape_string($contextname)."'"); | |
115 | 115 | // restore values only when option name and option context are same |
116 | 116 | if ($odesc = mysql_fetch_array($odescs)) { |
117 | 117 | $values = sql_query('SELECT contextid, optionvalue FROM ' |
118 | 118 | . sql_table('plug_retainoptions') |
119 | - . ' WHERE optionid='.$option['optionid']); | |
119 | + . ' WHERE optionid='.intval($option['optionid'])); | |
120 | 120 | while ($value = mysql_fetch_array($values)) { |
121 | 121 | // call plugin function instead of directly store in DB |
122 | 122 | // because some items/blogs/categories might not exist |
@@ -132,24 +132,24 @@ class NP_RetainOptions extends NucleusPlugin { | ||
132 | 132 | } |
133 | 133 | |
134 | 134 | function cleanup() { |
135 | - $oldesttimestamp = time() - 24*60*60; | |
135 | + $oldesttimestamp = time() - NP_RETAIN_OPTIONS_LIFETIME; | |
136 | 136 | $result = sql_query('SELECT id FROM '.sql_table('plug_retainoptions_plugin') |
137 | - ." WHERE STORETIME<$oldesttimestamp"); | |
137 | + ." WHERE STORETIME < " . intval($oldesttimestamp)); | |
138 | 138 | while ($row = mysql_fetch_array($result)) { |
139 | 139 | $options = sql_query('SELECT optionid FROM ' |
140 | 140 | . sql_table('plug_retainoptions_options') |
141 | - . ' WHERE id='.$row['id']); | |
141 | + . ' WHERE id='.intval($row['id'])); | |
142 | 142 | while ($option = mysql_fetch_array($options)) { |
143 | 143 | sql_query('DELETE FROM '.sql_table('plug_retainoptions') |
144 | - . ' WHERE optionid='.$option['optionid']); | |
144 | + . ' WHERE optionid='.intval($option['optionid'])); | |
145 | 145 | } |
146 | 146 | mysql_free_result($options); |
147 | 147 | sql_query('DELETE FROM '. sql_table('plug_retainoptions_options') |
148 | - . ' WHERE id='.$row['id']); | |
148 | + . ' WHERE id='.intval($row['id'])); | |
149 | 149 | } |
150 | 150 | mysql_free_result($result); |
151 | 151 | sql_query('DELETE FROM '.sql_table('plug_retainoptions_plugin') |
152 | - ." WHERE STORETIME<$oldesttimestamp"); | |
152 | + ." WHERE STORETIME < " . intval($oldesttimestamp)); | |
153 | 153 | } |
154 | 154 | |
155 | 155 | } |