1 | <?php |
---|
2 | |
---|
3 | if (!defined('HIPE_PATH')) define('HIPE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
4 | |
---|
5 | include_once (HIPE_PATH.'include/functions.inc.php'); |
---|
6 | |
---|
7 | function plugin_install() |
---|
8 | { |
---|
9 | global $conf; |
---|
10 | |
---|
11 | // Set plugin parameters |
---|
12 | $default= array(); |
---|
13 | |
---|
14 | $query = ' |
---|
15 | SELECT param |
---|
16 | FROM '.CONFIG_TABLE.' |
---|
17 | WHERE param = "HistoryIPExcluder" |
---|
18 | ;'; |
---|
19 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
20 | |
---|
21 | if ($count == 0) |
---|
22 | { |
---|
23 | $q = ' |
---|
24 | INSERT INTO '.CONFIG_TABLE.' (param,value,comment) |
---|
25 | VALUES ("HistoryIPExcluder","","History IP Excluder parameters"); |
---|
26 | '; |
---|
27 | |
---|
28 | pwg_query($q); |
---|
29 | } |
---|
30 | |
---|
31 | // Set plugin config |
---|
32 | $plugin = HIPE_infos(HIPE_PATH); |
---|
33 | $version = $plugin['version']; |
---|
34 | |
---|
35 | $default = array ( |
---|
36 | 'Blacklist' => "0", |
---|
37 | 'Version'=> $version, |
---|
38 | ); |
---|
39 | |
---|
40 | $query = ' |
---|
41 | SELECT param |
---|
42 | FROM '.CONFIG_TABLE.' |
---|
43 | WHERE param = "HistoryIPConfig" |
---|
44 | ;'; |
---|
45 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
46 | |
---|
47 | if ($count == 0) |
---|
48 | { |
---|
49 | $q = ' |
---|
50 | INSERT INTO '.CONFIG_TABLE.' (param,value,comment) |
---|
51 | VALUES ("HistoryIPConfig","'.addslashes(serialize($default)).'","History IP Excluder options"); |
---|
52 | '; |
---|
53 | pwg_query($q); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | function plugin_activate() |
---|
59 | { |
---|
60 | global $conf; |
---|
61 | |
---|
62 | /* Check for upgrade from 2.0.0 to 2.0.1 */ |
---|
63 | /* *************************************** */ |
---|
64 | $query = ' |
---|
65 | SELECT param |
---|
66 | FROM '.CONFIG_TABLE.' |
---|
67 | WHERE param = "nbc_HistoryIPExcluder" |
---|
68 | ;'; |
---|
69 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
70 | |
---|
71 | if ($count == 1) |
---|
72 | { |
---|
73 | /* upgrade from version 2.0.0 to 2.0.1 */ |
---|
74 | /* ************************************ */ |
---|
75 | upgrade_200(); |
---|
76 | } |
---|
77 | |
---|
78 | $query = ' |
---|
79 | SELECT param |
---|
80 | FROM '.CONFIG_TABLE.' |
---|
81 | WHERE param = "HistoryIPConfig" |
---|
82 | ;'; |
---|
83 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
84 | |
---|
85 | if ($count == 0) |
---|
86 | { |
---|
87 | /* upgrade from version 2.1.0 to 2.1.1 */ |
---|
88 | /* ************************************ */ |
---|
89 | upgrade_210(); |
---|
90 | } |
---|
91 | |
---|
92 | /* upgrade from version 2.1.1 to 2.2.0 */ |
---|
93 | /* *********************************** */ |
---|
94 | $HIPE_Config = unserialize($conf['HistoryIPConfig']); |
---|
95 | if ($HIPE_Config['Version'] != '2.2.0') |
---|
96 | { |
---|
97 | upgrade_211(); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | function plugin_uninstall() |
---|
103 | { |
---|
104 | global $conf; |
---|
105 | |
---|
106 | if (isset($conf['HistoryIPExcluder'])) |
---|
107 | { |
---|
108 | $q = ' |
---|
109 | DELETE FROM '.CONFIG_TABLE.' |
---|
110 | WHERE param="HistoryIPExcluder" LIMIT 1; |
---|
111 | '; |
---|
112 | |
---|
113 | pwg_query($q); |
---|
114 | } |
---|
115 | if (isset($conf['HistoryIPConfig'])) |
---|
116 | { |
---|
117 | $q = ' |
---|
118 | DELETE FROM '.CONFIG_TABLE.' |
---|
119 | WHERE param="HistoryIPConfig" LIMIT 1; |
---|
120 | '; |
---|
121 | |
---|
122 | pwg_query($q); |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | function upgrade_200() |
---|
128 | { |
---|
129 | global $conf; |
---|
130 | |
---|
131 | $q = ' |
---|
132 | UPDATE '.CONFIG_TABLE.' |
---|
133 | SET param = "HistoryIPExcluder" |
---|
134 | WHERE param = "nbc_HistoryIPExcluder" |
---|
135 | ;'; |
---|
136 | pwg_query($q); |
---|
137 | |
---|
138 | $q = ' |
---|
139 | UPDATE '.CONFIG_TABLE.' |
---|
140 | SET comment = "History IP Excluder parameters" |
---|
141 | WHERE comment = "Parametres nbc History IP Excluder" |
---|
142 | ;'; |
---|
143 | pwg_query($q); |
---|
144 | |
---|
145 | upgrade_210(); |
---|
146 | } |
---|
147 | |
---|
148 | function upgrade_210() |
---|
149 | { |
---|
150 | global $conf; |
---|
151 | |
---|
152 | $default = array ( |
---|
153 | 'Blacklist' => "0", |
---|
154 | 'Version'=> "2.1.1", |
---|
155 | ); |
---|
156 | |
---|
157 | $q = ' |
---|
158 | INSERT INTO '.CONFIG_TABLE.' (param,value,comment) |
---|
159 | VALUES ("HistoryIPConfig","'.addslashes(serialize($default)).'","History IP Excluder options"); |
---|
160 | '; |
---|
161 | |
---|
162 | pwg_query($q); |
---|
163 | } |
---|
164 | |
---|
165 | function upgrade_211() |
---|
166 | { |
---|
167 | global $conf; |
---|
168 | |
---|
169 | // Update plugin version |
---|
170 | $query = ' |
---|
171 | SELECT value |
---|
172 | FROM '.CONFIG_TABLE.' |
---|
173 | WHERE param = "HistoryIPConfig" |
---|
174 | ;'; |
---|
175 | $result = pwg_query($query); |
---|
176 | |
---|
177 | $conf_HIPE = pwg_db_fetch_assoc($result); |
---|
178 | |
---|
179 | $Newconf_HIPE = unserialize($conf_HIPE['value']); |
---|
180 | |
---|
181 | $Newconf_HIPE['Version'] = '2.2.0'; |
---|
182 | |
---|
183 | $update_conf = serialize($Newconf_HIPE); |
---|
184 | |
---|
185 | $query = ' |
---|
186 | UPDATE '.CONFIG_TABLE.' |
---|
187 | SET value="'.addslashes($update_conf).'" |
---|
188 | WHERE param="HistoryIPConfig" |
---|
189 | LIMIT 1 |
---|
190 | ;'; |
---|
191 | |
---|
192 | pwg_query($query); |
---|
193 | |
---|
194 | // Create new HIPE entry in plugins table |
---|
195 | $query = ' |
---|
196 | INSERT INTO '.PLUGINS_TABLE.' (id, state, version) |
---|
197 | VALUES ("HistoryIPExcluder","active","2.2.0") |
---|
198 | ;'; |
---|
199 | |
---|
200 | pwg_query($query); |
---|
201 | |
---|
202 | // Delete old plugin entry in plugins table |
---|
203 | $query = ' |
---|
204 | DELETE FROM '.PLUGINS_TABLE.' |
---|
205 | WHERE id="nbc_HistoryIPExcluder" |
---|
206 | LIMIT 1 |
---|
207 | ;'; |
---|
208 | |
---|
209 | pwg_query($query); |
---|
210 | |
---|
211 | // rename directory |
---|
212 | if (!rename(PHPWG_PLUGINS_PATH.'nbc_HistoryIPExcluder', PHPWG_PLUGINS_PATH.'HistoryIPExcluder')) |
---|
213 | { |
---|
214 | die('Fatal error on plugin upgrade process : Unable to rename directory ! Please, rename manualy the plugin directory name from ../plugins/nbc_HistoryIPExcluder to ../plugins/HistoryIPExcluder.'); |
---|
215 | } |
---|
216 | } |
---|
217 | ?> |
---|