1 | <?php |
---|
2 | |
---|
3 | if(!defined('UAM_PATH')) |
---|
4 | { |
---|
5 | define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
6 | } |
---|
7 | |
---|
8 | include_once (UAM_PATH.'include/constants.php'); |
---|
9 | include_once (UAM_PATH.'include/functions.inc.php'); |
---|
10 | |
---|
11 | load_language('plugin.lang', UAM_PATH); |
---|
12 | |
---|
13 | |
---|
14 | function plugin_install() |
---|
15 | { |
---|
16 | global $conf; |
---|
17 | |
---|
18 | /* ****************************************************************** */ |
---|
19 | /* **************** BEGIN - Data preparation in vars **************** */ |
---|
20 | /* ****************************************************************** */ |
---|
21 | |
---|
22 | // Default global parameters for UserAdvManager conf |
---|
23 | // ------------------------------------------------- |
---|
24 | $defaultUAM = array( |
---|
25 | 'MAIL_INFO' => 'false', |
---|
26 | 'CONFIRM_MAIL' => 'false', |
---|
27 | 'NO_CONFIRM_GROUP' => '-1', |
---|
28 | 'VALIDATED_GROUP' => '-1', |
---|
29 | 'VALIDATED_STATUS' => '-1', |
---|
30 | 'USERNAME_CHAR' => 'false', |
---|
31 | 'USERNAME_CHAR_LIST' => '', |
---|
32 | 'NO_CONFIRM_STATUS' => '-1', |
---|
33 | 'MAILINFO_TEXT' => l10n('UAM_Default_InfoMail_Txt'), |
---|
34 | 'CONFIRMMAIL_TEXT' => l10n('UAM_Default_ConfirmMail_Txt'), |
---|
35 | 'MAILEXCLUSION' => 'false', |
---|
36 | 'MAILEXCLUSION_LIST' => '', |
---|
37 | 'ADMINPASSWENF' => 'false', |
---|
38 | 'GHOSTRACKER' => 'false', |
---|
39 | 'GHOSTRACKER_DAYLIMIT' => '10', |
---|
40 | 'GHOSTRACKER_REMINDERTEXT' => l10n('UAM_Default_GhstReminder_Txt'), |
---|
41 | 'ADDLASTVISIT' => 'false', |
---|
42 | 'ADMINCONFMAIL' => 'false', |
---|
43 | 'REDIRTOPROFILE' => 'false', |
---|
44 | 'GTAUTO' => 'false', |
---|
45 | 'GTAUTOMAIL' => 'false', |
---|
46 | 'GTAUTODEL' => l10n('UAM_Default_GhstDeletion_Txt'), |
---|
47 | 'GTAUTOMAILTEXT' => l10n('UAM_Default_GhstDemotion_Txt'), |
---|
48 | 'DOWNGRADE_GROUP' => '-1', |
---|
49 | 'DOWNGRADE_STATUS' => '-1', |
---|
50 | 'ADMINVALIDATIONMAIL' => l10n('UAM_Default_AdminValidation_Txt'), |
---|
51 | 'CUSTOMPASSWRETR' => 'false', |
---|
52 | 'CUSTOMPASSWRETR_TEXT' => l10n('UAM_Default_PwdRequest_Txt'), |
---|
53 | 'USRAUTO' => 'false', |
---|
54 | 'USRAUTODEL' => l10n('UAM_Default_ValidationTimeout_Txt'), |
---|
55 | 'USRAUTOMAIL' => 'false', |
---|
56 | 'STUFFS' => 'false', |
---|
57 | 'HIDEPASSW' => 'false', |
---|
58 | 'NO_VALID_LEVEL' => '-1', |
---|
59 | 'VALID_LEVEL' => '-1', |
---|
60 | 'DOWNGRADE_LEVEL' => '-1', |
---|
61 | 'REJECTCONNECT' => 'false', |
---|
62 | 'REJECTCONNECT_TEXT' => l10n('UAM_Default_RejectConnexion_Txt'), |
---|
63 | 'CONFIRMMAIL_SUBJECT' => l10n('UAM_Default_ConfirmMail_Subject'), |
---|
64 | 'CONFIRMMAIL_REMAIL_SUBJECT' => l10n('UAM_Default_ConfirmMail_Remail_Subject'), |
---|
65 | 'INFOMAIL_SUBJECT' => l10n('UAM_Default_InfoMail_Subject'), |
---|
66 | 'GTAUTOMAIL_SUBJECT' => l10n('UAM_Default_GTAutoMail_Subject'), |
---|
67 | 'GTREMINDER_SUBJECT' => l10n('UAM_Default_GTReminder_Subject'), |
---|
68 | 'ADMINVALIDATIONMAIL_SUBJECT' => l10n('UAM_Default_AdminValidationMail_Subject'), |
---|
69 | 'ADD_GALLERY_URL_TO_EMAILS' => 'false' |
---|
70 | ); |
---|
71 | |
---|
72 | // Default specific parameters for UserAdvManager ConfirmMail conf |
---|
73 | // --------------------------------------------------------------- |
---|
74 | $defaultConfirmMail = array( |
---|
75 | 'CONFIRMMAIL_TIMEOUT' => 'false', |
---|
76 | 'CONFIRMMAIL_DELAY' => '5', |
---|
77 | 'CONFIRMMAIL_REMAIL_TXT1' => l10n('UAM_Default_CfmMail_Remail_Txt1'), |
---|
78 | 'CONFIRMMAIL_REMAIL' => 'false', |
---|
79 | 'CONFIRMMAIL_REMAIL_TXT2' => l10n('UAM_Default_CfmMail_Remail_Txt2'), |
---|
80 | 'CONFIRMMAIL_CUSTOM_TXT1' => l10n('UAM_Default_CfmMail_Custom_Txt1'), |
---|
81 | 'CONFIRMMAIL_CUSTOM_TXT2' => l10n('UAM_Default_CfmMail_Custom_Txt2') |
---|
82 | ); |
---|
83 | |
---|
84 | // Set current plugin version in config table |
---|
85 | // ------------------------------------------ |
---|
86 | $plugin = PluginInfos(UAM_PATH); |
---|
87 | $version = $plugin['version']; |
---|
88 | |
---|
89 | /* **************************************************************** */ |
---|
90 | /* **************** END - Data preparation in vars **************** */ |
---|
91 | /* **************************************************************** */ |
---|
92 | |
---|
93 | |
---|
94 | /* ***************************************************************************** */ |
---|
95 | /* **************** BEGIN - Database actions and initialization **************** */ |
---|
96 | /* ***************************************************************************** */ |
---|
97 | |
---|
98 | // Create UserAdvManager conf if not already exists |
---|
99 | // ------------------------------------------------ |
---|
100 | $query = ' |
---|
101 | SELECT param |
---|
102 | FROM '.CONFIG_TABLE.' |
---|
103 | WHERE param = "UserAdvManager" |
---|
104 | ;'; |
---|
105 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
106 | |
---|
107 | if ($count == 0) |
---|
108 | { |
---|
109 | $q = ' |
---|
110 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
111 | VALUES ("UserAdvManager","'.pwg_db_real_escape_string(serialize($defaultUAM)).'","UAM parameters") |
---|
112 | ;'; |
---|
113 | pwg_query($q); |
---|
114 | } |
---|
115 | |
---|
116 | // Create UserAdvManager_ConfirmMail conf if not already exists |
---|
117 | // ------------------------------------------------------------ |
---|
118 | $query = ' |
---|
119 | SELECT param |
---|
120 | FROM '.CONFIG_TABLE.' |
---|
121 | WHERE param = "UserAdvManager_ConfirmMail" |
---|
122 | ;'; |
---|
123 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
124 | |
---|
125 | if ($count == 0) |
---|
126 | { |
---|
127 | $q = ' |
---|
128 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
129 | VALUES ("UserAdvManager_ConfirmMail","'.pwg_db_real_escape_string(serialize($defaultConfirmMail)).'","UAM ConfirmMail parameters") |
---|
130 | ;'; |
---|
131 | pwg_query($q); |
---|
132 | } |
---|
133 | |
---|
134 | // Create UserAdvManager_Redir conf if not already exists |
---|
135 | // ------------------------------------------------------ |
---|
136 | $query = ' |
---|
137 | SELECT param |
---|
138 | FROM '.CONFIG_TABLE.' |
---|
139 | WHERE param = "UserAdvManager_Redir" |
---|
140 | ;'; |
---|
141 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
142 | |
---|
143 | if ($count == 0) |
---|
144 | { |
---|
145 | $q = ' |
---|
146 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
147 | VALUES ("UserAdvManager_Redir","0","UAM Redirections") |
---|
148 | ;'; |
---|
149 | pwg_query($q); |
---|
150 | } |
---|
151 | |
---|
152 | // Create UserAdvManager_Version conf if not already exists |
---|
153 | // -------------------------------------------------------- |
---|
154 | $query = ' |
---|
155 | SELECT param |
---|
156 | FROM '.CONFIG_TABLE.' |
---|
157 | WHERE param = "UserAdvManager_Version" |
---|
158 | ;'; |
---|
159 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
160 | |
---|
161 | if ($count == 0) |
---|
162 | { |
---|
163 | $q = ' |
---|
164 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
165 | VALUES ("UserAdvManager_Version","'.$version.'","UAM version check") |
---|
166 | ;'; |
---|
167 | pwg_query($q); |
---|
168 | } |
---|
169 | |
---|
170 | // Create USER_CONFIRM_MAIL_TABLE |
---|
171 | // ------------------------------ |
---|
172 | $q = ' |
---|
173 | CREATE TABLE IF NOT EXISTS '.USER_CONFIRM_MAIL_TABLE.' ( |
---|
174 | id varchar(50) NOT NULL default "", |
---|
175 | user_id smallint(5) NOT NULL default "0", |
---|
176 | mail_address varchar(255) default NULL, |
---|
177 | status enum("webmaster","admin","normal","generic","guest") default NULL, |
---|
178 | date_check datetime default NULL, |
---|
179 | reminder ENUM("true","false") NULL, |
---|
180 | PRIMARY KEY (id) |
---|
181 | ) |
---|
182 | ENGINE=MyISAM;'; |
---|
183 | pwg_query($q); |
---|
184 | |
---|
185 | // Create USER_LASTVISIT_TABLE |
---|
186 | // --------------------------- |
---|
187 | $q = ' |
---|
188 | CREATE TABLE IF NOT EXISTS '.USER_LASTVISIT_TABLE.' ( |
---|
189 | user_id SMALLINT(5) NOT NULL DEFAULT "0", |
---|
190 | lastvisit DATETIME NULL DEFAULT NULL, |
---|
191 | reminder ENUM("true","false") NULL, |
---|
192 | PRIMARY KEY (`user_id`) |
---|
193 | ) |
---|
194 | ENGINE=MyISAM;'; |
---|
195 | pwg_query($q); |
---|
196 | |
---|
197 | |
---|
198 | // Piwigo's native tables modifications for validation status |
---|
199 | // ---------------------------------------------------------- |
---|
200 | $query = ' |
---|
201 | SHOW COLUMNS FROM '.USERS_TABLE.' |
---|
202 | LIKE "UAM_validated" |
---|
203 | ;'; |
---|
204 | |
---|
205 | $result = pwg_query($query); |
---|
206 | |
---|
207 | if(!pwg_db_fetch_row($result)) |
---|
208 | { |
---|
209 | $q = ' |
---|
210 | ALTER TABLE '.USERS_TABLE.' |
---|
211 | ADD UAM_validated enum("true","false") |
---|
212 | ;'; |
---|
213 | pwg_query($q); |
---|
214 | } |
---|
215 | |
---|
216 | /* *************************************************************************** */ |
---|
217 | /* **************** END - Database actions and initialization **************** */ |
---|
218 | /* *************************************************************************** */ |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | function plugin_activate() |
---|
223 | { |
---|
224 | global $conf; |
---|
225 | |
---|
226 | /* Cleaning obsolete files */ |
---|
227 | /* *********************** */ |
---|
228 | clean_obsolete_files(); |
---|
229 | |
---|
230 | include_once (UAM_PATH.'include/upgradedb.inc.php'); |
---|
231 | |
---|
232 | /* Check if old version is < 2.15 */ |
---|
233 | /* ****************************** */ |
---|
234 | $query = ' |
---|
235 | SELECT param |
---|
236 | FROM '.CONFIG_TABLE.' |
---|
237 | WHERE param = "nbc_UserAdvManager" |
---|
238 | ;'; |
---|
239 | $count1 = pwg_db_num_rows(pwg_query($query)); |
---|
240 | |
---|
241 | $query = ' |
---|
242 | SELECT * |
---|
243 | FROM '.CONFIG_TABLE.' |
---|
244 | WHERE param = "nbc_UserAdvManager_ConfirmMail" |
---|
245 | ;'; |
---|
246 | $count2 = pwg_db_num_rows(pwg_query($query)); |
---|
247 | |
---|
248 | /* If old params exist an upgrade is needed */ |
---|
249 | /* **************************************** */ |
---|
250 | if ($count1 == 1) |
---|
251 | { |
---|
252 | /* Check for upgrade from 2.10 to 2.11 */ |
---|
253 | /* *********************************** */ |
---|
254 | if ($count1 == 1 and $count2 == 0) |
---|
255 | { |
---|
256 | /* upgrade from branch 2.10 to 2.11 */ |
---|
257 | /* ******************************** */ |
---|
258 | upgrade_210_211(); |
---|
259 | } |
---|
260 | |
---|
261 | |
---|
262 | /* Check for upgrade from 2.11 to 2.12 */ |
---|
263 | /* *********************************** */ |
---|
264 | if (!table_exist(USER_LASTVISIT_TABLE)) |
---|
265 | { |
---|
266 | /* upgrade from branch 2.11 to 2.12 */ |
---|
267 | /* ******************************** */ |
---|
268 | upgrade_211_212(); |
---|
269 | } |
---|
270 | |
---|
271 | |
---|
272 | /* Check for upgrade from 2.12 to 2.13 */ |
---|
273 | /* *********************************** */ |
---|
274 | $fields = pwg_query('SHOW COLUMNS FROM '.USER_CONFIRM_MAIL_TABLE.';'); |
---|
275 | $nb_fields = pwg_db_num_rows($fields); |
---|
276 | |
---|
277 | if ($nb_fields < 6) |
---|
278 | { |
---|
279 | /* upgrade from branch 2.12 to 2.13 */ |
---|
280 | /* ******************************** */ |
---|
281 | upgrade_212_213(); |
---|
282 | } |
---|
283 | |
---|
284 | |
---|
285 | /* Serializing conf parameters - Available since 2.14.0 */ |
---|
286 | /* **************************************************** */ |
---|
287 | if (unserialize($conf['nbc_UserAdvManager']) === false) |
---|
288 | { |
---|
289 | /* upgrade from branch 2.13 to 2.14 */ |
---|
290 | /* ******************************** */ |
---|
291 | upgrade_213_214(); |
---|
292 | } |
---|
293 | |
---|
294 | /* upgrade from branch 2.14 to 2.15 */ |
---|
295 | /* ******************************** */ |
---|
296 | upgrade_214_215(); |
---|
297 | } |
---|
298 | |
---|
299 | /* Old version is > 2.15 */ |
---|
300 | /* ********************* */ |
---|
301 | $query = ' |
---|
302 | SELECT param |
---|
303 | FROM '.CONFIG_TABLE.' |
---|
304 | WHERE param = "UserAdvManager_Redir" |
---|
305 | ;'; |
---|
306 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
307 | |
---|
308 | if ($count == 0) |
---|
309 | { |
---|
310 | upgrade_2153_2154(); |
---|
311 | } |
---|
312 | |
---|
313 | /* Check for upgrade from 2.15 to 2.16 */ |
---|
314 | /* *********************************** */ |
---|
315 | $query = ' |
---|
316 | SELECT param |
---|
317 | FROM '.CONFIG_TABLE.' |
---|
318 | WHERE param = "UserAdvManager_Version" |
---|
319 | ;'; |
---|
320 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
321 | |
---|
322 | if ($count == 0) |
---|
323 | { |
---|
324 | /* upgrade from branch 2.15 to 2.16 */ |
---|
325 | /* ******************************** */ |
---|
326 | upgrade_215_2160(); |
---|
327 | } |
---|
328 | |
---|
329 | /* Check database upgrade since version 2.16.0 */ |
---|
330 | /* ******************************************* */ |
---|
331 | if (isset($conf['UserAdvManager_Version'])) |
---|
332 | { |
---|
333 | if (version_compare($conf['UserAdvManager_Version'], '2.20.0') < 0) |
---|
334 | { |
---|
335 | /* upgrade from branch 2.16 to 2.20 */ |
---|
336 | /* ******************************** */ |
---|
337 | upgrade_216_220(); |
---|
338 | } |
---|
339 | |
---|
340 | if (version_compare($conf['UserAdvManager_Version'], '2.20.4') < 0) |
---|
341 | { |
---|
342 | /* upgrade from version 2.20.3 to 2.20.4 */ |
---|
343 | /* ************************************* */ |
---|
344 | upgrade_2203_2204(); |
---|
345 | } |
---|
346 | |
---|
347 | if (version_compare($conf['UserAdvManager_Version'], '2.20.7') < 0) |
---|
348 | { |
---|
349 | /* upgrade from version 2.20.4 to 2.20.7 */ |
---|
350 | /* ************************************* */ |
---|
351 | upgrade_2204_2207(); |
---|
352 | } |
---|
353 | |
---|
354 | if (version_compare($conf['UserAdvManager_Version'], '2.20.8') < 0) |
---|
355 | { |
---|
356 | /* upgrade from version 2.20.7 to 2.20.8 */ |
---|
357 | /* ************************************* */ |
---|
358 | upgrade_2207_2208(); |
---|
359 | } |
---|
360 | |
---|
361 | if (version_compare($conf['UserAdvManager_Version'], '2.30.0') < 0) |
---|
362 | { |
---|
363 | /* upgrade from version 2.20.8 to 2.30.0 */ |
---|
364 | /* ************************************* */ |
---|
365 | upgrade_2208_2300(); |
---|
366 | } |
---|
367 | |
---|
368 | if (version_compare($conf['UserAdvManager_Version'], '2.30.2') < 0) |
---|
369 | { |
---|
370 | /* upgrade from version 2.30.x to 2.30.2 */ |
---|
371 | /* ************************************* */ |
---|
372 | upgrade_2300_2302(); |
---|
373 | } |
---|
374 | |
---|
375 | if (version_compare($conf['UserAdvManager_Version'], '2.40.0') < 0) |
---|
376 | { |
---|
377 | /* upgrade from version 2.30.x to 2.40.0 */ |
---|
378 | /* ************************************* */ |
---|
379 | upgrade_2300_2400(); |
---|
380 | } |
---|
381 | |
---|
382 | if (version_compare($conf['UserAdvManager_Version'], '2.41.0') < 0) |
---|
383 | { |
---|
384 | /* upgrade from version 2.40.x to 2.41.0 */ |
---|
385 | /* ************************************* */ |
---|
386 | upgrade_2400_2410(); |
---|
387 | } |
---|
388 | |
---|
389 | if (version_compare($conf['UserAdvManager_Version'], '2.50.0') < 0) |
---|
390 | { |
---|
391 | /* upgrade from version 2.41.x to 2.50.0 */ |
---|
392 | /* ************************************* */ |
---|
393 | upgrade_2410_2500(); |
---|
394 | } |
---|
395 | |
---|
396 | if (version_compare($conf['UserAdvManager_Version'], '2.50.11') < 0) |
---|
397 | { |
---|
398 | /* upgrade from version 2.50.x to 2.50.11 */ |
---|
399 | /* ************************************** */ |
---|
400 | upgrade_2500_25011(); |
---|
401 | } |
---|
402 | |
---|
403 | if (version_compare($conf['UserAdvManager_Version'], '2.51.0') < 0) |
---|
404 | { |
---|
405 | /* upgrade from version 2.50.x to 2.51.0 */ |
---|
406 | /* *************************************** */ |
---|
407 | upgrade_2500_2510(); |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | // Update plugin version number in #_config table and check consistency of #_plugins table |
---|
412 | // --------------------------------------------------------------------------------------- |
---|
413 | UAM_version_update(); |
---|
414 | |
---|
415 | load_conf_from_db('param like \'UserAdvManager\\_%\''); |
---|
416 | } |
---|
417 | |
---|
418 | |
---|
419 | function plugin_uninstall() |
---|
420 | { |
---|
421 | global $conf; |
---|
422 | |
---|
423 | if (isset($conf['UserAdvManager'])) |
---|
424 | { |
---|
425 | $q = ' |
---|
426 | DELETE FROM '.CONFIG_TABLE.' |
---|
427 | WHERE param="UserAdvManager" |
---|
428 | ;'; |
---|
429 | |
---|
430 | pwg_query($q); |
---|
431 | } |
---|
432 | |
---|
433 | if (isset($conf['UserAdvManager_ConfirmMail'])) |
---|
434 | { |
---|
435 | $q = ' |
---|
436 | DELETE FROM '.CONFIG_TABLE.' |
---|
437 | WHERE param="UserAdvManager_ConfirmMail" |
---|
438 | ;'; |
---|
439 | |
---|
440 | pwg_query($q); |
---|
441 | } |
---|
442 | |
---|
443 | if (isset($conf['UserAdvManager_Redir'])) |
---|
444 | { |
---|
445 | $q = ' |
---|
446 | DELETE FROM '.CONFIG_TABLE.' |
---|
447 | WHERE param="UserAdvManager_Redir" |
---|
448 | ;'; |
---|
449 | |
---|
450 | pwg_query($q); |
---|
451 | } |
---|
452 | |
---|
453 | if (isset($conf['UserAdvManager_Version'])) |
---|
454 | { |
---|
455 | $q = ' |
---|
456 | DELETE FROM '.CONFIG_TABLE.' |
---|
457 | WHERE param="UserAdvManager_Version" |
---|
458 | ;'; |
---|
459 | |
---|
460 | pwg_query($q); |
---|
461 | } |
---|
462 | |
---|
463 | $q = ' |
---|
464 | DROP TABLE '.USER_CONFIRM_MAIL_TABLE.' |
---|
465 | ;'; |
---|
466 | pwg_query( $q ); |
---|
467 | |
---|
468 | $q = ' |
---|
469 | DROP TABLE '.USER_LASTVISIT_TABLE.' |
---|
470 | ;'; |
---|
471 | pwg_query( $q ); |
---|
472 | |
---|
473 | $q = ' |
---|
474 | ALTER TABLE '.USERS_TABLE.' |
---|
475 | DROP UAM_validated |
---|
476 | ;'; |
---|
477 | pwg_query($q); |
---|
478 | } |
---|
479 | ?> |
---|