function emodal_get_license($key = null) { $license = emodal_get_option(EMCORE_SLUG . '-license'); if (!$license) { $license = array('valid' => false, 'key' => '', 'status' => array('code' => null, 'message' => null, 'expires' => null, 'domains' => null)); emodal_update_option(EMCORE_SLUG . '-license', $license); } return $license && $key ? emresolve($license, $key) : $license; }
public function action_edit() { if ($this->check_post_nonce() && isset($_POST['publish'])) { /* $EModal_License = new EModal_License; $EModal_License->check_license(empost('license.key')); if(!empty(empost('access_key'))) { $new = empost('access_key'); $old = emodal_get_option( EMCORE_SLUG. '_access_key' ); if($new != '') { if($old === null || $old == '') { $new = SHA1($new); } elseif($old && $old != $new && $old != SHA1($new)) { $new = SHA1($new); } emodal_update_option(EMCORE_SLUG. '_access_key', $new); } else { emodal_delete_option(EMCORE_SLUG. '_access_key'); } } */ $new_values = apply_filters('emodal_settings_pre_save', emodal_get_option('emodal_settings')); emodal_update_option('emodal_settings', $new_values); do_action('emodal_settings_save', $new_values); EModal_Admin_Notice::add(__('Settings Updated.', EMCORE_SLUG), 'updated'); //EModal_Admin::check_updates(); $this->redirect_to_edit(); } $view = new EModal_View_Admin_Settings_Form(); $view->set('title', __('Easy Modal Settings', EMCORE_SLUG)); $view->set('tabs', apply_filters('emodal_admin_settings_form_tabs', array())); self::$instance->view = $view; }
public function check_license($new_license = false, $force_check = false) { $license = emodal_get_license(); if ($new_license == '') { emodal_delete_option(EMCORE_SLUG . '-license'); delete_site_transient(EMCORE_SLUG . '-license-check'); delete_transient(EMCORE_SLUG . '-addon-list'); return; } if ($new_license && $new_license != $license['key'] && SHA1($new_license) != $license['key']) { $license = array('valid' => false, 'key' => $new_license != '' ? SHA1($new_license) : '', 'status' => array('code' => NULL, 'message' => NULL, 'expires' => NULL, 'domains' => NULL)); if ($new_license != '') { $force_check = true; } emodal_update_option(EMCORE_SLUG . '-license', $license); } if ($force_check || $license['valid'] && !get_site_transient(EMCORE_SLUG . '-license-check')) { $status = $this->api_request('license_check'); if (is_array($status) && in_array($status['code'], $this->unactivated_status_codes)) { $status = $this->api_request('activate_domain'); //$this->api_request('license_check'); } if (is_array($status) && in_array($status['code'], $this->valid_status_codes)) { $license['valid'] = true; } else { if ($status instanceof WP_Error) { $status = array('code' => 00, 'message' => $status->error); } } $license['status'] = $status; emodal_update_option(EMCORE_SLUG . '-license', $license); set_site_transient(EMCORE_SLUG . '-license-check', true, 365 * (60 * 60 * 24) / 12); delete_transient(EMCORE_SLUG . '-addon-list'); } return $license; }
public function reset_emodal_db() { if (isset($_POST['remove_old_emodal_data'])) { // run a quick security check if (!check_admin_referer(EMCORE_NONCE, EMCORE_NONCE)) { return; } // get out if we didn't click the Activate button global $wpdb; $wpdb->query("DELETE FROM {$wpdb->options} WHERE `option_name` LIKE 'EasyModal%';"); do_action('remove_old_emodal_data'); } if (isset($_POST['reset_emodal_db'])) { // run a quick security check if (!check_admin_referer(EMCORE_NONCE, EMCORE_NONCE)) { return; } // get out if we didn't click the Activate button global $wpdb; $wpdb->query("DROP TABLE IF EXISTS `{$wpdb->em_modal_metas}`;"); $wpdb->query("DROP TABLE IF EXISTS `{$wpdb->em_modals}`;"); $wpdb->query("DROP TABLE IF EXISTS `{$wpdb->em_theme_metas}`;"); $wpdb->query("DROP TABLE IF EXISTS `{$wpdb->em_themes}`;"); emodal_delete_option(EMCORE_SLUG . '_db_version'); do_action('emodal_db_update', false); /* $wpdb->query( "DELETE FROM $wpdb->em_modal_metas" ); $wpdb->query( "DELETE FROM $wpdb->em_modals" ); $wpdb->query( "DELETE FROM $wpdb->em_theme_metas" ); $wpdb->query( "DELETE FROM $wpdb->em_themes" ); */ do_action('emodal_reset_db'); } if (isset($_POST['migrate_emodal_db'])) { // run a quick security check if (!check_admin_referer(EMCORE_NONCE, EMCORE_NONCE)) { return; } // get out if we didn't click the Activate button if (emodal_get_option('EasyModal_Version')) { global $wpdb; $wpdb->query("DELETE FROM {$wpdb->em_modal_metas}"); $wpdb->query("DELETE FROM {$wpdb->em_modals}"); $wpdb->query("DELETE FROM {$wpdb->em_theme_metas}"); $wpdb->query("DELETE FROM {$wpdb->em_themes}"); new EModal_Migrate_Pre_V2(); do_action('emodal_migrate_db'); } } if (isset($_POST['uninstall_emodal_db'])) { // run a quick security check if (!check_admin_referer(EMCORE_NONCE, EMCORE_NONCE)) { return; } // get out if we didn't click the Activate button global $wpdb; $wpdb->query("DROP TABLE IF EXISTS `{$wpdb->em_modal_metas}`;"); $wpdb->query("DROP TABLE IF EXISTS `{$wpdb->em_modals}`;"); $wpdb->query("DROP TABLE IF EXISTS `{$wpdb->em_theme_metas}`;"); $wpdb->query("DROP TABLE IF EXISTS `{$wpdb->em_themes}`;"); $wpdb->query("DELETE FROM {$wpdb->options} WHERE `option_name` LIKE 'easy-modal%';"); do_action('emodal_uninstall'); emodal_update_option(EMCORE_SLUG . '_uninstalled', true); } }
public function __construct() { if (emodal_get_option('EasyModal_Version')) { $themes = self::get_themes(); $theme_check = array(); foreach ($themes as $theme) { $new_theme = new EModal_Model_Theme(); $new_theme->set_fields(array('id' => intval($theme['id']), 'name' => $theme['name'], 'is_system' => intval($theme['id']) == 1 ? 1 : 0, 'meta' => array('overlay' => array('background' => array('color' => $theme['overlayColor'], 'opacity' => $theme['overlayOpacity'])), 'container' => array('padding' => $theme['containerPadding'], 'background' => array('color' => $theme['containerBgColor']), 'border' => array('style' => $theme['containerBorderStyle'], 'color' => $theme['containerBorderColor'], 'width' => $theme['containerBorderWidth'], 'radius' => $theme['containerBorderRadius'])), 'title' => array('font' => array('color' => $theme['contentTitleFontColor'], 'size' => $theme['contentTitleFontSize'], 'family' => $theme['contentTitleFontFamily'])), 'content' => array('font' => array('color' => $theme['contentFontColor'])), 'close' => array('padding' => ($theme['closeSize'] - $theme['closeFontSize']) / 2, 'text' => $theme['closeText'], 'location' => $theme['closePosition'], 'background' => array('color' => $theme['closeBgColor']), 'border' => array('radius' => $theme['closeBorderRadius']), 'font' => array('color' => $theme['closeFontColor'], 'size' => $theme['closeFontSize']))))); $new_theme->save(); $theme_check[] = $new_theme->id; } $modals = self::get_modals(); foreach ($modals as $modal) { $new_modal = new EModal_Model_Modal(); $new_modal->set_fields(array('id' => is_int(intval($modal['id'])) ? intval($modal['id']) : NULL, 'theme_id' => in_array(intval($modal['theme']), $theme_check) ? intval($modal['theme']) : 1, 'name' => $modal['name'], 'title' => $modal['title'], 'content' => $modal['content'], 'is_sitewide' => $modal['sitewide'] ? 1 : 0, 'content' => $modal['content'], 'is_system' => in_array($modal['id'], array('Login', 'Register', 'Forgot')) ? 1 : 0, 'meta' => array('display' => array('size' => $modal['size'] == '' ? 'normal' : $modal['size'], 'custom_width' => $modal['userWidth'], 'custom_width_unit' => $modal['userWidthUnit'], 'custom_height' => $modal['userHeight'], 'custom_height_unit' => $modal['userHeightUnit'], 'animation' => array('type' => $modal['animation'], 'speed' => $modal['duration'], 'origin' => $modal['direction'])), 'close' => array('overlay_click' => $modal['overlayClose'] ? 1 : 0, 'esc_press' => $modal['overlayEscClose'] ? 1 : 0, 'disabled' => !empty($modal['closeDisabled']) && $modal['closeDisabled'] ? 1 : 0)))); $new_modal->save(); if ($modal['id'] == 'Login') { $login_modal = $new_modal->id; } elseif ($modal['id'] == 'Register') { $register_modal = $new_modal->id; } elseif ($modal['id'] == 'Forgot') { $forgot_modal = $new_modal->id; } } $license = self::get_license(); if (!empty($license)) { $EModal_License = new EModal_License(); $EModal_License->check_license($license, true); EModal_Admin::check_updates(); } $settings = self::get_settings(); if (array_key_exists('autoOpen_id', $settings)) { $autoopen = array('modal_id' => intval($settings['autoOpen_id']), 'type' => 'page-load', 'pageload' => array('delay' => intval($settings['autoOpen_delay'])), 'cookie' => array('time' => is_float($settings['autoOpen_timer']) || is_int($settings['autoOpen_timer']) ? $settings['autoOpen_timer'] . ' days' : $settings['autoOpen_timer'])); emodal_update_option('easy-modal-pro_autoopen', $autoopen); $autoexit = array('modal_id' => intval($settings['autoExit_id']), 'cookie' => array('time' => is_float($settings['autoExit_timer']) || is_int($settings['autoExit_timer']) ? $settings['autoExit_timer'] . ' days' : $settings['autoExit_timer'])); emodal_update_option('easy-modal-pro-exit-modals_autoexit', $autoexit); } if ($settings['login_modal_enabled']) { if (empty($login_modal)) { $new_login_modal = new EModal_Model_Modal(); $new_login_modal->set_fields(array('name' => 'Login Modal', 'meta' => array('size' => 'small'))); $new_login_modal->save(); $login_modal = $new_login_modal->id; } if (empty($register_modal)) { $new_registration_modal = new EModal_Model_Modal(); $new_registration_modal->set_fields(array('name' => 'Registration Modal', 'meta' => array('size' => 'small'))); $new_registration_modal->save(); $register_modal = $new_registration_modal->id; } if (empty($forgot_modal)) { $new_forgot_modal = new EModal_Model_Modal(); $new_forgot_modal->set_fields(array('name' => 'Forgot Password Modal', 'meta' => array('size' => 'small'))); $new_forgot_modal->save(); $forgot_modal = $new_forgot_modal->id; } $loginmodal = array('enabled' => $settings['login_modal_enabled'] ? 1 : 0, 'force_login' => $settings['force_user_login'] ? 1 : 0, 'login' => array('modal_id' => $login_modal), 'registration' => array('modal_id' => $register_modal, 'enable_password' => $settings['registration_modal']['enable_password'] ? 1 : 0, 'autologin' => $settings['registration_modal']['autologin'] ? 1 : 0), 'forgot' => array('modal_id' => $forgot_modal)); emodal_update_option('easy-modal-pro-login-modals_loginmodal', $loginmodal); } } global $wpdb; $wpdb->query("UPDATE {$wpdb->postmeta} SET meta_key = 'easy-modal_post_modals' WHERE meta_key = 'easy_modal_post_modals'"); $post_meta = $wpdb->get_results("SELECT * FROM {$wpdb->postmeta} WHERE meta_key LIKE 'easy_modal_post_%' ORDER BY post_id ASC"); $new_post_meta = array(); $delete_post_meta = array(); foreach ($post_meta as $meta) { if (empty($new_post_meta[$meta->post_id])) { $new_post_meta[$meta->post_id] = array('autoopen' => array('modal_id' => NULL, 'type' => 'page-load', 'pageload' => array('delay' => NULL), 'cookie' => array('time' => NULL, 'path' => ''), 'scroll' => array('distance' => NULL)), 'autoexit' => array('modal_id' => NULL, 'cookie' => array('time' => NULL, 'path' => '')), 'loginmodal' => array('force_login' => 0)); } switch ($meta->meta_key) { case "easy_modal_post_autoExit_id": $new_post_meta[$meta->post_id]['autoexit']['modal_id'] = intval($meta->meta_value); break; case "easy_modal_post_autoExit_timer": $new_post_meta[$meta->post_id]['autoexit']['cookie']['time'] = is_float($meta->meta_value) || is_int($meta->meta_value) ? $meta->meta_value . ' days' : $meta->meta_value; break; case "easy_modal_post_autoOpen_id": $new_post_meta[$meta->post_id]['autoopen']['modal_id'] = intval($meta->meta_value); break; case "easy_modal_post_autoOpen_timer": $new_post_meta[$meta->post_id]['autoopen']['cookie']['time'] = is_float($meta->meta_value) || is_int($meta->meta_value) ? $meta->meta_value . ' days' : $meta->meta_value; break; case "easy_modal_post_autoOpen_delay": $new_post_meta[$meta->post_id]['autoopen']['pageload']['delay'] = intval($meta->meta_value); break; case "easy_modal_post_force_user_login": $new_post_meta[$meta->post_id]['autoopen']['modal_id'] = $meta->meta_value == 'true' ? 1 : 0; break; } if ($meta->meta_key != 'easy-modal_post_modals') { $delete_post_meta[] = $meta->meta_id; } } foreach ($new_post_meta as $post_id => $meta) { update_post_meta($post_id, 'easy-modal-pro_autoopen', $meta['autoopen']); update_post_meta($post_id, 'easy-modal-pro-exit-modals_autoexit', $meta['autoexit']); update_post_meta($post_id, 'easy-modal-pro-login-modals_loginmodal', $meta['loginmodal']); } emodal_update_option(EMCORE_SLUG . '_migration_approval', true); }
public function install($multisite_blog) { global $wpdb, $blog_id, $emodal_db_update_global; $emodal_db_update_global = false; $current_version = emodal_get_option(EMCORE_SLUG . '_db_version'); if ($current_version != EMCORE_DB_VERSION || $emodal_db_update_global) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } $sql = "CREATE TABLE {$wpdb->prefix}em_themes (\r\n\t\t\t\tid mediumint(9) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t\tname varchar(150) NOT NULL DEFAULT '',\r\n\t\t\t\tcreated datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\t\t\tmodified datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\t\t\tis_system tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\tis_trash tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\tPRIMARY KEY (id)\r\n\t\t\t){$charset_collate};"; dbDelta($sql); $sql = "CREATE TABLE {$wpdb->prefix}em_theme_metas (\r\n\t\t\t\tid mediumint(9) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t\ttheme_id mediumint(9) unsigned NOT NULL,\r\n\t\t\t\toverlay longtext,\r\n\t\t\t\tcontainer longtext,\r\n\t\t\t\tclose longtext,\r\n\t\t\t\ttitle longtext,\r\n\t\t\t\tcontent longtext,\r\n\t\t\t\tPRIMARY KEY (id)\r\n\t\t\t){$charset_collate};"; dbDelta($sql); $sql = "CREATE TABLE {$wpdb->prefix}em_modals (\r\n\t\t\t\tid mediumint(9) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t\ttheme_id mediumint(9) unsigned NOT NULL DEFAULT '1',\r\n\t\t\t\tname varchar(150) NOT NULL DEFAULT '',\r\n\t\t\t\ttitle varchar(255) DEFAULT NULL,\r\n\t\t\t\tcontent longtext,\r\n\t\t\t\tcreated datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\t\t\tmodified datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\t\t\tis_sitewide tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\tis_system tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\tis_trash tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\tPRIMARY KEY (id)\r\n\t\t\t){$charset_collate};"; dbDelta($sql); $sql = "CREATE TABLE {$wpdb->prefix}em_modal_metas (\r\n\t\t\t\tid mediumint(9) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t\tmodal_id mediumint(9) unsigned NOT NULL,\r\n\t\t\t\tdisplay longtext,\r\n\t\t\t\tclose longtext,\r\n\t\t\t\tPRIMARY KEY (id)\r\n\t\t\t){$charset_collate};"; dbDelta($sql); if (!$current_version && !emodal_get_option('EasyModal_Version')) { $this->install_data(); } emodal_update_option(EMCORE_SLUG . '_db_version', EMCORE_DB_VERSION); $emodal_db_update_global = true; } if (emodal_get_option('EasyModal_Version') && !emodal_get_option(EMCORE_SLUG . '_migration_approval')) { new EModal_Migrate_Pre_V2(); } }