[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-admin/includes/install/ -> mailpress.php (source)

   1  <?php
   2  
   3  global $wp_version; 
   4  
   5  $m = array();
   6  
   7  if (version_compare($wp_version, $min_ver_wp , '<'))    $m[] = sprintf(__('Your %1$s version is \'%2$s\', at least version \'%3$s\' required.', MP_TXTDOM), __('WordPress'), $wp_version , $min_ver_wp );
   8  if (!is_writable(MP_ABSPATH . 'tmp'))            $m[] = sprintf(__('The directory \'%1$s\' is not writable.', MP_TXTDOM), MP_ABSPATH . 'tmp');
   9  if (!extension_loaded('simplexml'))                $m[] = __("Default php extension 'simplexml' not loaded.", MP_TXTDOM);
  10  
  11  if (!empty($m))
  12  {
  13      $err  = sprintf(__('<b>Sorry, but you can\'t run this plugin : %1$s. </b>', MP_TXTDOM), $_GET['plugin']);
  14      $err .= '<ol><li>' . implode('</li><li>', $m) . '</li></ol>';
  15  
  16      if (isset($_GET['plugin'])) deactivate_plugins($_GET['plugin']);    
  17      trigger_error($err, E_USER_ERROR);
  18      return false;
  19  }
  20  
  21  /* MailPress install */
  22  
  23  global $wpdb;
  24  
  25  // theme init
  26  if (!get_option('MailPress_current_theme'))
  27  {
  28      add_option ('MailPress_template',         'twentyten');
  29      add_option ('MailPress_stylesheet',     'twentyten');
  30      add_option ('MailPress_current_theme',     'MailPress Twenty Ten');
  31  }
  32  
  33  //////////////////////////////////
  34  //// Upgrade to MailPress 4.0 ////
  35  //////////////////////////////////
  36  
  37  if ( $x = get_option('MailPress_widget') ) 
  38  {
  39      if (isset($x['jQ'])) $x['jq'] = $x['jQ'];
  40      unset($x['jQ']);
  41      add_option('widget_mailpress', $x);
  42      delete_option('MailPress_widget');
  43  }
  44  
  45  if ( !get_option(MailPress::option_name_logs) )
  46  {
  47      $parms = array('level', 'lognbr', 'lastpurge');
  48      $_settings = array('MailPress_general' => 'general', 'MailPress_batch_send' => 'batch_send', 'MailPress_import' => 'import', 'MailPress_autoresponder' => 'autoresponder');    
  49      $logs = array();
  50      foreach($_settings as $_setting => $_target)
  51      {
  52          $x = get_option($_setting);
  53          if ($x)
  54          {
  55              foreach($parms as $parm)
  56              {
  57                  if (isset($x[$parm])) $logs[$_target][$parm] = $x[$parm];
  58                  unset($x[$parm]);
  59              }
  60              if (empty($x))     delete_option($_setting);
  61              else            update_option($_setting, $x);
  62          }
  63      }
  64      if (empty($logs)) $logs['general'] = MailPress::$default_option_logs;
  65      add_option(MailPress::option_name_logs, $logs);
  66  }
  67  
  68  global $mp_general, $mp_subscriptions;
  69  $mp_general = get_option(MailPress::option_name_general);
  70  
  71  if (isset($mp_general['subscription_mngt']))
  72  {
  73      $mp_subscriptions = get_option(MailPress::option_name_subscriptions);
  74      if (!$mp_subscriptions)
  75      {
  76          $mp_subscriptions = $mp_general;
  77          $parms = array('subcomment', 'newsletters', 'default_newsletters');
  78          foreach($parms as $parm) unset($mp_general[$parm]);
  79          foreach($mp_general as $k => $v) unset($mp_subscriptions[$k]);
  80          update_option (MailPress::option_name_general, $mp_general);
  81  
  82          $mailinglist = get_option('MailPress_mailinglist');
  83          if ($mailinglist && is_array($mailinglist)) $mp_subscriptions = array_merge($mp_subscriptions, $mailinglist);
  84          if (!isset($mp_subscriptions['default_newsletters'])) $mp_subscriptions['default_newsletters'] = array();
  85          delete_option('MailPress_mailinglist');
  86          update_option(MailPress::option_name_subscriptions, $mp_subscriptions);
  87      }
  88  }
  89  
  90  //////////////////////////////////
  91  //// Upgrade to MailPress 5.0 ////
  92  //////////////////////////////////
  93  
  94  $convert_tables = array(    $wpdb->prefix . 'MailPress_mails'    =>     $wpdb->prefix . 'mailpress_mails',
  95                      $wpdb->prefix . 'MailPress_mailmeta'=>    $wpdb->prefix . 'mailpress_mailmeta',
  96                      $wpdb->prefix . 'MailPress_users'    =>    $wpdb->prefix . 'mailpress_users',
  97                      $wpdb->prefix . 'MailPress_usermeta'=>    $wpdb->prefix . 'mailpress_usermeta',
  98                      $wpdb->prefix . 'MailPress_stats'    =>    $wpdb->prefix . 'mailpress_stats'
  99  );
 100  
 101  foreach($convert_tables as $old_table => $new_table) if (!$wpdb->get_results( "SHOW KEYS FROM $new_table" )) $wpdb->query("ALTER TABLE $old_table RENAME TO $new_table;");
 102  
 103  foreach (array('mp_mail' => $wpdb->mp_mailmeta, 'mp_user' => $wpdb->mp_usermeta) as $object => $table)
 104  {
 105      $old_index = true;
 106      $indexes   = $wpdb->get_results( "SHOW KEYS FROM $table" );
 107      if (!$indexes) continue;
 108      foreach($indexes as $index) if ("{$object}_id" == $index->Column_name) $old_index = false;
 109      if ($old_index)
 110      {
 111          $sql = "ALTER TABLE $table
 112                  DROP PRIMARY KEY,
 113                  DROP INDEX user_id,
 114                  DROP INDEX meta_key,
 115                  CHANGE COLUMN " . $object[3] . "meta_id     meta_id     BIGINT(20) NOT NULL DEFAULT NULL AUTO_INCREMENT,
 116                  CHANGE COLUMN " . substr($object, 3) . "_id {$object}_id  BIGINT(20) NOT NULL DEFAULT 0,
 117                  ADD PRIMARY KEY(meta_id),
 118                  ADD INDEX {$object}_id ({$object}_id,meta_key);";
 119  
 120          $wpdb->query($sql);
 121      }
 122  }
 123  
 124  //////////////////////////////////
 125  //// Install                  ////
 126  //////////////////////////////////
 127  
 128  $charset_collate = '';
 129  if ( $wpdb->supports_collation() ) 
 130  {
 131      if ( ! empty($wpdb->charset) ) $charset_collate  = "DEFAULT CHARACTER SET $wpdb->charset";
 132      if ( ! empty($wpdb->collate) ) $charset_collate .= " COLLATE $wpdb->collate";
 133  }
 134  
 135  $queries = array();
 136  
 137  $queries[] = 
 138  "CREATE TABLE $wpdb->mp_mails (
 139   id                bigint(20)       UNSIGNED NOT NULL AUTO_INCREMENT,
 140   status            enum('draft', 'unsent', 'sending', 'sent', 'archived', '', 'paused') NOT NULL,
 141   theme             varchar(255)     NOT NULL default '',
 142   themedir          varchar(255)     NOT NULL default '',
 143   template          varchar(255)     NOT NULL default '',
 144   fromemail         varchar(255)     NOT NULL default '',
 145   fromname          varchar(255)     NOT NULL default '',
 146   toname            varchar(255)     NOT NULL default '',
 147   charset           varchar(255)     NOT NULL default '',
 148   parent            bigint(20)       UNSIGNED NOT NULL default 0,
 149   child             bigint(20)       NOT NULL default 0,
 150   subject           varchar(255)     NOT NULL default '',
 151   created           timestamp        NOT NULL default '0000-00-00 00:00:00',
 152   created_user_id   bigint(20)       UNSIGNED NOT NULL default 0,
 153   sent              timestamp        NOT NULL default '0000-00-00 00:00:00',
 154   sent_user_id      bigint(20)       UNSIGNED NOT NULL default 0,
 155   toemail           longtext         NOT NULL,
 156   plaintext         longtext         NOT NULL,
 157   html              longtext         NOT NULL,
 158  PRIMARY KEY (id),
 159  KEY status (status)
 160  ) $charset_collate;";
 161  
 162  $queries[] = 
 163  "CREATE TABLE $wpdb->mp_mailmeta (
 164   meta_id           bigint(20)       NOT NULL auto_increment,
 165   mp_mail_id        bigint(20)       NOT NULL default '0',
 166   meta_key          varchar(255)     default NULL,
 167   meta_value        longtext,
 168   PRIMARY KEY (meta_id),
 169   KEY mp_mail_id (mp_mail_id,meta_key)
 170  ) $charset_collate;";
 171  
 172  $queries[] = 
 173  "CREATE TABLE $wpdb->mp_users (
 174   id                bigint(20)       UNSIGNED NOT NULL AUTO_INCREMENT, 
 175   email             varchar(100)     NOT NULL,
 176   name              varchar(100)     NOT NULL,
 177   status            enum('waiting', 'active', 'bounced', 'unsubscribed')    NOT NULL,
 178   confkey           varchar(100)     NOT NULL,
 179   created           timestamp        NOT NULL default '0000-00-00 00:00:00',
 180   created_IP        varchar(100)     NOT NULL default '',
 181   created_agent     text             NOT NULL,
 182   created_user_id   bigint(20)       UNSIGNED NOT NULL default 0,
 183   created_country   char(2)          NOT NULL default 'ZZ',
 184   created_US_state  char(2)          NOT NULL default 'ZZ',
 185   laststatus        timestamp        NOT NULL default '0000-00-00 00:00:00',
 186   laststatus_IP     varchar(100)     NOT NULL default '',
 187   laststatus_agent  text             NOT NULL,
 188   laststatus_user_id bigint(20)      UNSIGNED NOT NULL default 0,
 189   PRIMARY KEY (id),
 190   KEY status (status)
 191  ) $charset_collate;";
 192  
 193  $queries[] = 
 194  "CREATE TABLE $wpdb->mp_usermeta (
 195   meta_id           bigint(20)       NOT NULL auto_increment,
 196   mp_user_id        bigint(20)       NOT NULL default '0',
 197   meta_key          varchar(255)     default NULL,
 198   meta_value        longtext,
 199   PRIMARY KEY (meta_id),
 200   KEY mp_user_id (mp_user_id,meta_key)
 201  ) $charset_collate;";
 202  
 203  $queries[] = 
 204  "CREATE TABLE $wpdb->mp_stats (
 205   sdate             date             NOT NULL,
 206   stype             char(1)          NOT NULL,
 207   slib              varchar(45)      NOT NULL,
 208   scount            bigint           NOT NULL,
 209   PRIMARY KEY(stype, sdate, slib)
 210  ) $charset_collate;";
 211  
 212  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
 213  dbDelta($queries);
 214  
 215  
 216  
 217  // some clean up
 218  $wpdb->query( "DELETE FROM $wpdb->mp_mails    WHERE status = '' AND theme <> '';" );
 219  $wpdb->query( "DELETE FROM $wpdb->mp_mailmeta WHERE mp_mail_id NOT IN ( SELECT id FROM $wpdb->mp_mails );" );
 220  $wpdb->query( "DELETE FROM $wpdb->mp_usermeta WHERE mp_user_id NOT IN ( SELECT id FROM $wpdb->mp_users );" );
 221  $wpdb->query( "DELETE FROM $wpdb->mp_usermeta WHERE meta_value NOT IN ( SELECT id FROM $wpdb->mp_mails ) AND meta_key = '_MailPress_mail_sent' ;" );
 222  
 223  $wpdb->query( "UPDATE $wpdb->mp_mailmeta SET meta_key = '_MailPress_attached_file' WHERE meta_key = '_mp_attached_file';" );


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1