[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  
   3  /* MailPress install */
   4  
   5  global $wpdb, $wp_version;
   6  
   7  $m = array();
   8  
   9  if ( version_compare( $wp_version, $min_ver_wp , '<' ) )    $m[] = sprintf( __( 'Your %1$s version is \'%2$s\', at least version \'%3$s\' required.', 'MailPress' ), __( 'WordPress' ), $wp_version , $min_ver_wp );
  10  if ( !extension_loaded( 'simplexml' ) )                $m[] = sprintf( __( 'Default php extension \'%1$s\' not loaded.', 'MailPress'), 'simplexml'  );
  11  if ( !extension_loaded( 'intl' ) )                    $m[] = sprintf( __( 'Default php extension \'%1$s\' not loaded.', 'MailPress'), 'intl' );
  12  if ( !function_exists( 'proc_open' ) )                $m[] =          __( '"proc_open" php function is not available, ask your webhost technical support.', 'MailPress');
  13  
  14   
  15  //////////////////////////////////
  16  ////            7.0           ////     Since MailPress 7.0 content of tmp and mp-content/advanced is moved/copied to uploads mailpress directory
  17  //////////////////////////////////
  18  
  19  if ( !is_dir( MP_UPL_ABSPATH ) && !mkdir( MP_UPL_ABSPATH ) )         $m[] = sprintf( __( 'The directory \'%1$s\' cannot be created.', 'MailPress' ), MP_UPL_ABSPATH );
  20  if (  is_dir( MP_UPL_ABSPATH ) && !is_writable( MP_UPL_ABSPATH ) )     $m[] = sprintf( __( 'The directory \'%1$s\' is not writable.', 'MailPress' ), MP_UPL_ABSPATH );
  21  
  22  $mp_tmp_renames = array ( 'log' => 'MP_Log_' . $wpdb->blogid . '_*.txt', 'ip' => '*.spc', 'oembed' => '*.png', );
  23  
  24  foreach( $mp_tmp_renames as $dir => $pattern )
  25  {
  26      $dir = MP_UPL_ABSPATH . $dir;
  27      if ( !is_dir( $dir ) && !mkdir( $dir ) )                     $m[] = sprintf( __( 'The directory \'%1$s\' cannot be created.', 'MailPress' ), $dir );
  28      if ( is_dir( $dir )  && !is_writable( $dir ) )                $m[] = sprintf( __( 'The directory \'%1$s\' is not writable.', 'MailPress' ), $dir );
  29  }
  30  
  31  //
  32  
  33  if ( !empty( $m ) )
  34  {
  35      $plugin = filter_input( INPUT_GET, 'plugin' );
  36      $err  = sprintf( __( '<b>Sorry, but you can\'t run this plugin : %1$s. </b>', 'MailPress' ), $plugin );
  37      $err .= '<ol><li>' . implode( '</li><li>', $m ) . '</li></ol>';
  38  
  39      if ( isset( $plugin ) ) deactivate_plugins( $plugin );    
  40      trigger_error( $err, E_USER_ERROR );
  41      return false;
  42  }
  43  
  44  
  45  //////////////////////////////////
  46  ////            7.0           ////     Since MailPress 7.0 content of tmp and mp-content/advanced is moved/copied to uploads mailpress directory
  47  //////////////////////////////////
  48  //// TMP ////
  49  
  50  if ( is_dir( MP_ABSPATH . 'tmp' ) )
  51  {
  52  
  53  // log / ip / oembed 
  54  
  55      foreach( $mp_tmp_renames as $dir => $pattern )
  56      {
  57          $files = glob( MP_ABSPATH . 'tmp/' . $pattern );
  58          if ( $files )
  59          {
  60              $log = ( ( 'log' == $dir ) && ( $wpdb->blogid != get_current_blog_id() ) );
  61              foreach( $files as $file )
  62              {
  63                  $dfile = ( $log ) ?  str_replace( 'MP_Log_' . $wpdb->blogid . '_', 'MP_Log_' . get_current_blog_id() . '_', basename( $file ) ) : basename( $file );
  64                  rename( $file, MP_UPL_ABSPATH . $dir . '/' . $dfile );
  65              }
  66              if( !file_exists( MP_UPL_ABSPATH . $dir . '/index.php' )) copy( MP_CONTENT_DIR . 'index.php', MP_UPL_ABSPATH . $dir . '/index.php' );
  67          }
  68      }
  69  
  70  // spool ... nothing done here ! expecting all spooled mails are sent and directories are empty.
  71  
  72      $spool_path = 'spool/' . get_current_blog_id() . '/';
  73  
  74      if ( !is_dir( MP_UPL_ABSPATH . $spool_path ) )
  75      {
  76          $batch_spool_send = get_option( 'MailPress_batch_spool_send' );
  77          if ( $batch_spool_send )
  78          {
  79              if ( isset( $batch_spool_send['path'] ) && is_dir( $batch_spool_send['path'] ) )
  80              {
  81                  //rename( $batch_spool_send['path'], MP_UPL_ABSPATH . $spool_path );
  82                  unset( $batch_spool_send['path'] );
  83                  update_option( 'MailPress_batch_spool_send', $batch_spool_send );
  84              }
  85          }
  86      }
  87  }
  88  
  89  //// end of TMP ////
  90  
  91  //// ADVANCED ////
  92  
  93  $advanced_path = 'advanced/' . get_current_blog_id() . '/';
  94  
  95  if ( !is_dir( MP_UPL_ABSPATH . $advanced_path ) )
  96  {
  97      if ( is_dir( MP_CONTENT_DIR . 'advanced' ) )
  98      {
  99          // mirroring the files for this blog
 100          $source = untrailingslashit( MP_CONTENT_DIR . 'advanced' );
 101          $dest   = untrailingslashit( MP_UPL_ABSPATH . $advanced_path );
 102          mkdir( $dest, 0777, true );
 103          foreach( $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST ) as $item )
 104          {
 105              if ($item->isDir())     mkdir( $dest . '/' . $iterator->getSubPathName(), 0777, true );
 106              else                 copy( $item, $dest . '/' . $iterator->getSubPathName() );
 107          }
 108      }
 109  }
 110  
 111  //// end of ADVANCED ////
 112  
 113  //////////////////////////////////
 114  //// Install                  ////
 115  //////////////////////////////////
 116  
 117  // theme init
 118  if ( !get_option( 'MailPress_current_theme' ) )
 119  {
 120      add_option ( 'MailPress_template',    'twentyten' );
 121      add_option ( 'MailPress_stylesheet',    'twentyten' );
 122      add_option ( 'MailPress_current_theme',    'MailPress Twenty Ten' );
 123  }
 124  
 125  $charset_collate = $wpdb->get_charset_collate();
 126  
 127  $mp_tables = "CREATE TABLE $wpdb->mp_mails (
 128  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
 129  status enum('draft','unsent','sending','sent','archived','','paused') NOT NULL,
 130  theme varchar(255) NOT NULL default '',
 131  themedir varchar(255) NOT NULL default '',
 132  template varchar(255) NOT NULL default '',
 133  fromemail varchar(255) NOT NULL default '',
 134  fromname varchar(255) NOT NULL default '',
 135  toname varchar(255) NOT NULL default '',
 136  charset varchar(255) NOT NULL default '',
 137  parent bigint(20) UNSIGNED NOT NULL default 0,
 138  child bigint(20) NOT NULL default 0,
 139  subject varchar(255) NOT NULL default '',
 140  created timestamp NOT NULL default '0000-00-00 00:00:00',
 141  created_user_id bigint(20) UNSIGNED NOT NULL default 0,
 142  sent timestamp NOT NULL default '0000-00-00 00:00:00',
 143  sent_user_id bigint(20) UNSIGNED NOT NULL default 0,
 144  toemail longtext NOT NULL,
 145  plaintext longtext NOT NULL,
 146  html longtext NOT NULL,
 147  PRIMARY KEY (id),
 148  KEY status (status)
 149  ) $charset_collate;
 150  CREATE TABLE $wpdb->mp_mailmeta (
 151  meta_id bigint(20) unsigned NOT NULL auto_increment,
 152  mp_mail_id bigint(20) unsigned NOT NULL default '0',
 153  meta_key varchar(255) NOT NULL default '',
 154  meta_value longtext,
 155  PRIMARY KEY (meta_id),
 156  KEY mp_mail_id (mp_mail_id,meta_key),
 157  KEY meta_key (meta_key)
 158  ) $charset_collate;
 159  CREATE TABLE $wpdb->mp_users (
 160  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
 161  email varchar(100) NOT NULL,
 162  name varchar(100) NOT NULL,
 163  status enum('waiting','active','bounced','unsubscribed') NOT NULL,
 164  confkey varchar(100) NOT NULL,
 165  created timestamp NOT NULL default '0000-00-00 00:00:00',
 166  created_IP varchar(100) NOT NULL default '',
 167  created_agent text NOT NULL,
 168  created_user_id bigint(20) UNSIGNED NOT NULL default 0,
 169  created_country char(2) NOT NULL default 'ZZ',
 170  created_US_state char(2) NOT NULL default 'ZZ',
 171  laststatus timestamp NOT NULL default '0000-00-00 00:00:00',
 172  laststatus_IP varchar(100) NOT NULL default '',
 173  laststatus_agent text NOT NULL,
 174  laststatus_user_id bigint(20) UNSIGNED NOT NULL default 0,
 175  PRIMARY KEY (id),
 176  KEY status (status)
 177  ) $charset_collate;
 178  CREATE TABLE $wpdb->mp_usermeta (
 179  meta_id bigint(20) unsigned NOT NULL auto_increment,
 180  mp_user_id bigint(20) unsigned NOT NULL default '0',
 181  meta_key varchar(255) NOT NULL default '',
 182  meta_value longtext,
 183  PRIMARY KEY (meta_id),
 184  KEY mp_user_id (mp_user_id,meta_key),
 185  KEY meta_key (meta_key)
 186  ) $charset_collate;
 187  CREATE TABLE $wpdb->mp_stats (
 188  sdate date NOT NULL,
 189  stype char(1) NOT NULL,
 190  slib varchar(45) NOT NULL,
 191  scount bigint NOT NULL,
 192  PRIMARY KEY (stype,sdate,slib)
 193  ) $charset_collate;\n";
 194  
 195  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
 196  dbDelta( $mp_tables );
 197  
 198  // some clean up
 199  $wpdb->query( "DELETE FROM $wpdb->mp_mails    WHERE status = '' AND theme <> '';" );
 200  $wpdb->query( "DELETE FROM $wpdb->mp_mailmeta WHERE mp_mail_id NOT IN ( SELECT id FROM $wpdb->mp_mails );" );
 201  $wpdb->query( "DELETE FROM $wpdb->mp_usermeta WHERE mp_user_id NOT IN ( SELECT id FROM $wpdb->mp_users );" );
 202  $wpdb->query( "DELETE FROM $wpdb->mp_usermeta WHERE meta_value NOT IN ( SELECT id FROM $wpdb->mp_mails ) AND meta_key = '_MailPress_mail_sent' ;" );
 203  $wpdb->query( "DELETE FROM $wpdb->mp_stats    WHERE scount = 0 ;" );
 204  
 205  $wpdb->query( "UPDATE $wpdb->mp_mailmeta SET meta_key = '_MailPress_attached_file' WHERE meta_key = '_mp_attached_file';" );


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1