source: extensions/ContactForm/maintain.inc.php @ 28566

Last change on this file since 28566 was 28343, checked in by mistic100, 10 years ago

fix escaping

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