1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190:
<?php
class Inbound_Mailer_Activation {
public function __construct() {
if ( strstr(php_sapi_name() , 'fcgi') ) {
add_action('mod_rewrite_rules', array(__CLASS__, 'add_rewrite_rules'));
}
self::run_activation();
}
public static function run_activation() {
self::store_version_data();
self::run_updates();
delete_option('inbound_activate_mailer');
}
public static function run_updates() {
$updaters = get_class_methods('Inbound_Mailer_Activation_Update_Routines');
$completed = ( get_option( 'inbound_email_completed_upgrade_routines' ) ) ? get_option( 'inbound_email_completed_upgrade_routines' ) : array();
$remaining = array_diff( $updaters , $completed );
foreach ( $remaining as $updater ) {
Inbound_Mailer_Activation_Update_Routines::$updater();
$completed[] = $updater;
}
update_option( 'inbound_email_completed_upgrade_routines' , $completed );
}
public static function run_upgrade_routine_checks() {
if (isset($_GET['plugin_action']) && $_GET['plugin_action'] == 'upgrade_routines' && $_GET['plugin'] =='inbound-email' ) {
self::run_updates();
wp_redirect(admin_url('edit.php?post_type=inbound-email'));
exit;
}
$updaters = get_class_methods('Inbound_Mailer_Activation_Update_Routines');
$updaters = (is_array($updaters)) ? $updaters : array();
$completed = ( get_option( 'inbound_email_completed_upgrade_routines' ) ) ? get_option( 'inbound_email_completed_upgrade_routines' ) : array();
$remaining = array_diff( $updaters , $completed );
if (count($remaining)>0) {
add_action( 'admin_notices', array( __CLASS__ , 'display_upgrade_routine_notice' ) );
}
}
public static function display_upgrade_routine_notice() {
?>
<div class="error">
<p><?php _e( 'Inbound Email Component plugin requires a database upgrade:', 'inbound-pro' ); ?> <a href='?plugin=inbound-email&plugin_action=upgrade_routines'><?php _e('Upgrade Database Now' , 'inbound-pro' ); ?></a></p>
</div>
<?php
}
public static function store_version_data() {
$old = get_transient('inbound_email_current_version');
set_transient( 'inbound_email_previous_version' , $old );
set_transient( 'inbound_email_current_version' , INBOUND_EMAIL_CURRENT_VERSION );
}
public static function add_rewrite_rules( $rules ) {
if (stristr($rules, '[E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]')) {
return $rules;
}
$rules_array = preg_split('/$\R?^/m', $rules);
if (count($rules_array) < 3) {
$rules_array = explode("\n", $rules);
$rules_array = array_filter($rules_array);
}
$i = 0;
foreach ($rules_array as $key => $val) {
if (!trim($val)) {
continue;
}
if (stristr($val, "RewriteEngine On")) {
$new_val = "RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]";
$rules_array[$i] = $new_val;
$i++;
$rules_array[$i] = $val;
$i++;
} else {
$rules_array[$i] = $val;
$i++;
}
}
$rules = implode("\n", $rules_array);
return $rules;
}
public static function create_email_queue_table() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$table_name = $wpdb->prefix . "inbound_email_queue";
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`email_id` bigint(9) NOT NULL,
`variation_id` mediumint(9) NOT NULL,
`lead_id` bigint(9) NOT NULL,
`post_id` bigint(9) NOT NULL,
`list_ids` text NOT NULL,
`job_id` bigint(9) NOT NULL,
`rule_id` bigint(9) NOT NULL,
`token` tinytext NOT NULL,
`type` tinytext NOT NULL,
`tokens` mediumtext NOT NULL,
`status` tinytext NOT NULL,
`datetime` DATETIME NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta( $sql );
}
}
if (get_option('inbound_activate_mailer' , false) ) {
new Inbound_Mailer_Activation();
}
add_action( 'admin_init' , array( 'Inbound_Mailer_Activation' , 'run_upgrade_routine_checks' ) );