[28839] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | class ContactForm_maintain extends PluginMaintain |
---|
| 5 | { |
---|
| 6 | private $table; |
---|
| 7 | |
---|
| 8 | private $default_conf = array( |
---|
| 9 | 'cf_must_initialize' => true, |
---|
| 10 | 'cf_menu_link' => true, |
---|
| 11 | 'cf_subject_prefix' => '%gallery_title%', |
---|
| 12 | 'cf_default_subject' => 'A comment on your site', |
---|
| 13 | 'cf_allow_guest' => true, |
---|
| 14 | 'cf_mandatory_mail' => true, |
---|
| 15 | 'cf_mandatory_name' => true, |
---|
| 16 | 'cf_mail_type' => 'text/html', |
---|
| 17 | 'cf_redirect_url' => null, |
---|
| 18 | ); |
---|
| 19 | |
---|
| 20 | function __construct($id) |
---|
| 21 | { |
---|
| 22 | global $prefixeTable; |
---|
| 23 | |
---|
| 24 | parent::__construct($id); |
---|
| 25 | $this->table = $prefixeTable.'contact_form'; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | function install($plugin_version, &$errors=array()) |
---|
| 29 | { |
---|
| 30 | global $conf; |
---|
| 31 | |
---|
| 32 | // email table |
---|
| 33 | $query = ' |
---|
| 34 | CREATE TABLE IF NOT EXISTS `'. $this->table .'` ( |
---|
| 35 | `id` smallint(5) NOT NULL AUTO_INCREMENT, |
---|
| 36 | `name` varchar(128) NOT NULL, |
---|
| 37 | `email` varchar(128) NOT NULL, |
---|
| 38 | `active` enum("true","false") NOT NULL DEFAULT "true", |
---|
| 39 | `group_name` varchar(128) DEFAULT NULL, |
---|
| 40 | PRIMARY KEY (`id`), |
---|
| 41 | UNIQUE KEY `UNIQUE` (`email`,`group_name`) |
---|
| 42 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8;'; |
---|
| 43 | pwg_query($query); |
---|
| 44 | |
---|
| 45 | // configuration |
---|
| 46 | if (empty($conf['ContactForm'])) |
---|
| 47 | { |
---|
| 48 | conf_update_param('ContactForm', $this->default_conf, true); |
---|
| 49 | conf_update_param('ContactForm_before', '', true); |
---|
| 50 | conf_update_param('ContactForm_after', '', true); |
---|
| 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
| 54 | $new_conf = safe_unserialize($conf['ContactForm']); |
---|
| 55 | |
---|
| 56 | // migration 2.4 -> 2.5 |
---|
| 57 | if (!isset($new_conf['cf_must_initialize'])) |
---|
| 58 | { |
---|
| 59 | // new params |
---|
| 60 | $new_conf['cf_default_subject'] = 'A comment on your site'; |
---|
| 61 | $new_conf['cf_mail_type'] = 'text/html'; |
---|
| 62 | $new_conf['cf_redirect_url'] = null; |
---|
| 63 | |
---|
| 64 | // move emails to database |
---|
| 65 | $emails = array(); |
---|
| 66 | foreach ($new_conf['cf_admin_mails'] as $email => $data) |
---|
| 67 | { |
---|
| 68 | $emails[] = array( |
---|
| 69 | 'email' => $email, |
---|
| 70 | 'name' => $data['NAME'], |
---|
| 71 | 'active' => boolean_to_string($data['ACTIVE']), |
---|
| 72 | ); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | $new_conf['cf_must_initialize'] = empty($emails); |
---|
| 76 | |
---|
| 77 | mass_inserts( |
---|
| 78 | $this->table, |
---|
| 79 | array('name','email','active'), |
---|
| 80 | $emails |
---|
| 81 | ); |
---|
| 82 | |
---|
| 83 | // old params |
---|
| 84 | unset( |
---|
| 85 | $new_conf['comment'], $new_conf['cf_redirect_delay'], |
---|
| 86 | $new_conf['cf_separator'], $new_conf['cf_separator_length'], |
---|
| 87 | $new_conf['cf_admin_mails'] |
---|
| 88 | ); |
---|
| 89 | |
---|
| 90 | // save config |
---|
| 91 | conf_update_param('ContactForm', $new_conf, true); |
---|
| 92 | conf_update_param('ContactForm_before', stripslashes(@$conf['persoformtop']), true); |
---|
| 93 | conf_update_param('ContactForm_after', stripslashes(@$conf['persoformbottom']), true); |
---|
| 94 | conf_delete_param(array('persoformtop','persoformbottom')); |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | // just in case something went wrong in a previous version |
---|
| 99 | if (empty($conf['ContactForm_before'])) |
---|
| 100 | { |
---|
| 101 | conf_update_param('ContactForm_before', '', true); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | if (empty($conf['ContactForm_after'])) |
---|
| 105 | { |
---|
| 106 | conf_update_param('ContactForm_after', '', true); |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | function update($old_version, $new_version, &$errors=array()) |
---|
| 111 | { |
---|
| 112 | $this->install($new_version, $errors); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | function uninstall() |
---|
| 116 | { |
---|
| 117 | pwg_query('DROP TABLE IF EXISTS `'. $this->table .'`;'); |
---|
| 118 | |
---|
| 119 | conf_delete_param(array('ContactForm','ContactForm_before','ContactForm_after')); |
---|
| 120 | } |
---|
| 121 | } |
---|