• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの


Commit MetaInfo

Revision13eca4b212f1f1bc6114f0c6148cf531b48cce4e (tree)
Time2006-10-15 19:53:58
Authorhsur <hsur@1ca2...>
Commiterhsur

Log Message

クォートが含まれるオプションが保存されない問題を修正

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@449 1ca29b6e-896d-4ea0-84a5-967f57386b96

Change Summary

Incremental Difference

--- a/trunk/NP_RetainOptions/NP_RetainOptions.php
+++ b/trunk/NP_RetainOptions/NP_RetainOptions.php
@@ -1,12 +1,13 @@
11 <?php
22
3+define('NP_RETAIN_OPTIONS_LIFETIME', 86400);
34
45 class NP_RetainOptions extends NucleusPlugin {
56
67 function getNAME() { return 'Retain Options'; }
78 function getAuthor() { return 'Andy'; }
89 function getURL() { return ''; }
9- function getVersion() { return '0.5'; }
10+ function getVersion() { return '0.6'; }
1011 function getDescription() {
1112 return 'Retain plugin options while you update(uninstall and reinstall) plugins. Keep up to one day';
1213 }
@@ -59,30 +60,30 @@ class NP_RetainOptions extends NucleusPlugin {
5960 function event_PreDeletePlugin(&$data) {
6061 if ($this->getOption('disable') == 'yes') return;
6162 $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));
6364 $plugin = mysql_fetch_array($result);
6465 $pname = strtolower($plugin['pfile']);
6566 mysql_free_result($result);
6667 if ($pname == get_class($this)) return; // don't retain this plugin
6768 $currenttime = mysqldate(time());
6869 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) . ")");
7071 $id = mysql_insert_id();
7172 $descs = sql_query('SELECT oid, oname, ocontext FROM '.sql_table('plugin_option_desc')
72- . ' WHERE opid='.$plugid);
73+ . ' WHERE opid='.intval($plugid));
7374 while ($desc = mysql_fetch_array($descs)) {
7475 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'])."'");
7879 $optionid = mysql_insert_id();
7980 $options = sql_query('SELECT ovalue, ocontextid FROM '.sql_table('plugin_option')
8081 . ' WHERE oid='.$desc['oid']);
8182 while ($option = mysql_fetch_array($options)) {
8283 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'])."'");
8687 }
8788 mysql_free_result($options);
8889 }
@@ -93,9 +94,9 @@ class NP_RetainOptions extends NucleusPlugin {
9394 if ($this->getOption('disable') == 'yes') return;
9495 $plugin = & $data['plugin'];
9596 $pname = get_class($plugin);
96- $oldesttimestamp = mysqldate(time() - 24*60*60);
97+ $oldesttimestamp = mysqldate(time() - NP_RETAIN_OPTIONS_LIFETIME);
9798 $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));
99100 $nums = mysql_num_rows($result);
100101 if (!$nums) { $this->cleanup(); return; }
101102 while ($nums--) $row = mysql_fetch_array($result);
@@ -103,20 +104,19 @@ class NP_RetainOptions extends NucleusPlugin {
103104 $id = $row['id'];
104105 $options = sql_query('SELECT optionid, optionname, optioncontext FROM '
105106 . sql_table('plug_retainoptions_options')
106- . " WHERE id=$id");
107+ . " WHERE id=".intval($id));
107108 while ($option = mysql_fetch_array($options)) {
108109 $optionname = $option['optionname'];
109110 $contextname = $option['optioncontext'];
110111 $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)."'");
115115 // restore values only when option name and option context are same
116116 if ($odesc = mysql_fetch_array($odescs)) {
117117 $values = sql_query('SELECT contextid, optionvalue FROM '
118118 . sql_table('plug_retainoptions')
119- . ' WHERE optionid='.$option['optionid']);
119+ . ' WHERE optionid='.intval($option['optionid']));
120120 while ($value = mysql_fetch_array($values)) {
121121 // call plugin function instead of directly store in DB
122122 // because some items/blogs/categories might not exist
@@ -132,24 +132,24 @@ class NP_RetainOptions extends NucleusPlugin {
132132 }
133133
134134 function cleanup() {
135- $oldesttimestamp = time() - 24*60*60;
135+ $oldesttimestamp = time() - NP_RETAIN_OPTIONS_LIFETIME;
136136 $result = sql_query('SELECT id FROM '.sql_table('plug_retainoptions_plugin')
137- ." WHERE STORETIME<$oldesttimestamp");
137+ ." WHERE STORETIME < " . intval($oldesttimestamp));
138138 while ($row = mysql_fetch_array($result)) {
139139 $options = sql_query('SELECT optionid FROM '
140140 . sql_table('plug_retainoptions_options')
141- . ' WHERE id='.$row['id']);
141+ . ' WHERE id='.intval($row['id']));
142142 while ($option = mysql_fetch_array($options)) {
143143 sql_query('DELETE FROM '.sql_table('plug_retainoptions')
144- . ' WHERE optionid='.$option['optionid']);
144+ . ' WHERE optionid='.intval($option['optionid']));
145145 }
146146 mysql_free_result($options);
147147 sql_query('DELETE FROM '. sql_table('plug_retainoptions_options')
148- . ' WHERE id='.$row['id']);
148+ . ' WHERE id='.intval($row['id']));
149149 }
150150 mysql_free_result($result);
151151 sql_query('DELETE FROM '.sql_table('plug_retainoptions_plugin')
152- ." WHERE STORETIME<$oldesttimestamp");
152+ ." WHERE STORETIME < " . intval($oldesttimestamp));
153153 }
154154
155155 }
Show on old repository browser