Ignore:
Timestamp:
Dec 9, 2013, 5:34:37 PM (10 years ago)
Author:
mistic100
Message:

update for 2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/ContactForm/maintain.inc.php

    r24348 r25872  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 defined('CONTACT_FORM_ID') or define('CONTACT_FORM_ID', basename(dirname(__FILE__)));
    5 include_once(PHPWG_PLUGINS_PATH . CONTACT_FORM_ID . '/include/install.inc.php');
     4class ContactForm_maintain extends PluginMaintain
     5{
     6  private $installed = false;
    67
    7 function plugin_install()
    8 {
    9   contact_form_install();
    10   define('contact_form_installed', true);
    11 }
     8  function install($plugin_version, &$errors=array())
     9  {
     10    global $conf, $prefixeTable;
    1211
    13 function plugin_activate()
    14 {
    15   if (!defined('contact_form_installed'))
     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', $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
     114  function activate($plugin_version, &$errors=array())
    16115  {
    17     contact_form_install();
     116    if (!$this->installed)
     117    {
     118      $this->install($plugin_version, $errors);
     119    }
     120  }
     121
     122  function deactivate()
     123  {
     124  }
     125
     126
     127  function uninstall()
     128  {
     129    global $prefixeTable;
     130
     131    pwg_query('DROP TABLE IF EXISTS `'. $prefixeTable .'contact_form`;');
     132
     133    conf_delete_param(array('ContactForm','ContactForm_before','ContactForm_after'));
    18134  }
    19135}
    20 
    21 function plugin_uninstall()
    22 {
    23   global $prefixeTable, $conf;
    24  
    25   pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param LIKE "ContactForm%";');
    26   pwg_query('DROP TABLE IF EXISTS `'. $prefixeTable .'contact_form`;');
    27  
    28   unset($conf['ContactForm'], $conf['ContactForm_before'], $conf['ContactForm_after']);
    29 }
    30 
    31 ?>
Note: See TracChangeset for help on using the changeset viewer.