From c76d079a45fde60cf8618161138e45237cfbefb3 Mon Sep 17 00:00:00 2001 From: smusman98 Date: Mon, 18 Jul 2022 15:37:35 +0500 Subject: [PATCH] 2.1.4-rc.1 --- Postman/Extensions/Admin/PostmanAdmin.php | 31 - Postman/Extensions/Admin/PostmanAdminView.php | 92 --- .../License/EDD_SL_Plugin_Updater.php | 585 ------------------ .../License/PostmanLicenseHandler.php | 482 --------------- .../License/PostmanLicenseManager.php | 90 --- postman-smtp.php | 4 +- readme.txt | 8 +- 7 files changed, 6 insertions(+), 1286 deletions(-) delete mode 100644 Postman/Extensions/Admin/PostmanAdmin.php delete mode 100644 Postman/Extensions/Admin/PostmanAdminView.php delete mode 100644 Postman/Extensions/License/EDD_SL_Plugin_Updater.php delete mode 100644 Postman/Extensions/License/PostmanLicenseHandler.php delete mode 100644 Postman/Extensions/License/PostmanLicenseManager.php diff --git a/Postman/Extensions/Admin/PostmanAdmin.php b/Postman/Extensions/Admin/PostmanAdmin.php deleted file mode 100644 index 3b61a0a6..00000000 --- a/Postman/Extensions/Admin/PostmanAdmin.php +++ /dev/null @@ -1,31 +0,0 @@ -get_extensions(); - - if ( count( $extensions ) > 0 ) { - add_action('admin_menu', [ $this, 'add_menu' ], 20 ); - } - - } - - public function add_menu() { - add_submenu_page( - PostmanViewController::POSTMAN_MENU_SLUG, - __('Extensions', 'post-smtp'), - __('Extensions', 'post-smtp'), - 'manage_options', - 'post-smtp-extensions', - [ $this, 'render_menu' ] - ); - } - - public function render_menu() { - include_once 'PostmanAdminView.php'; - } -} diff --git a/Postman/Extensions/Admin/PostmanAdminView.php b/Postman/Extensions/Admin/PostmanAdminView.php deleted file mode 100644 index 428ee174..00000000 --- a/Postman/Extensions/Admin/PostmanAdminView.php +++ /dev/null @@ -1,92 +0,0 @@ - - - - -
-

Post SMTP Installed Extensions

-
-
- get_extensions(); - - foreach ( $extensions as $slug => $extension) : - $short_name = $extension['license_manager']->get_slug( $extension['plugin_data']['Name'] ); - $nonce = $short_name . '_license_key-nonce'; - - $license_data = get_option( $short_name . '_license_active' ); - $license_key = get_option( $short_name . '_license_key' ); - - $license_valid = is_object( $license_data ) && $license_data->license === 'valid'; - $license_field_class = $license_valid ? 'readonly' : ''; - $license_field_value = $license_valid ? base64_encode($license_key) : ''; - - wp_nonce_field( $nonce, $nonce ); - ?> - -
-
- -
- -
-
- - type="password" - name="post_smtp_extension[]" - class="regular-text" - value="" - placeholder="Serial Key"> -
- -
- - - - - license === 'expired' ) : ?> - Renew License - - - -
-
- -
- - - -
-
-
diff --git a/Postman/Extensions/License/EDD_SL_Plugin_Updater.php b/Postman/Extensions/License/EDD_SL_Plugin_Updater.php deleted file mode 100644 index 06738347..00000000 --- a/Postman/Extensions/License/EDD_SL_Plugin_Updater.php +++ /dev/null @@ -1,585 +0,0 @@ -api_url = trailingslashit( $_api_url ); - $this->api_data = $_api_data; - $this->name = plugin_basename( $_plugin_file ); - $this->slug = basename( $_plugin_file, '.php' ); - $this->version = $_api_data['version']; - $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false; - $this->beta = ! empty( $this->api_data['beta'] ) ? true : false; - $this->cache_key = 'edd_sl_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ); - - $edd_plugin_data[ $this->slug ] = $this->api_data; - - /** - * Fires after the $edd_plugin_data is setup. - * - * @since x.x.x - * - * @param array $edd_plugin_data Array of EDD SL plugin data. - */ - do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data ); - - // Set up hooks. - $this->init(); - - } - - /** - * Set up WordPress filters to hook into WP's update process. - * - * @uses add_filter() - * - * @return void - */ - public function init() { - - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); - remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 ); - add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); - add_action( 'admin_init', array( $this, 'show_changelog' ) ); - - } - - /** - * Check for Updates at the defined API endpoint and modify the update array. - * - * This function dives into the update API just when WordPress creates its update array, - * then adds a custom API call and injects the custom plugin data retrieved from the API. - * It is reassembled from parts of the native WordPress plugin update code. - * See wp-includes/update.php line 121 for the original wp_update_plugins() function. - * - * @uses api_request() - * - * @param array $_transient_data Update array build by WordPress. - * @return array Modified update array with custom plugin data. - */ - public function check_update( $_transient_data ) { - - global $pagenow; - - if ( ! is_object( $_transient_data ) ) { - $_transient_data = new stdClass; - } - - if ( 'plugins.php' == $pagenow && is_multisite() ) { - return $_transient_data; - } - - if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) { - return $_transient_data; - } - - $version_info = $this->get_cached_version_info(); - - if ( false === $version_info ) { - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) ); - - $this->set_version_info_cache( $version_info ); - - } - - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { - - if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { - - $_transient_data->response[ $this->name ] = $version_info; - - // Make sure the plugin property is set to the plugin's name/location. See issue 1463 on Software Licensing's GitHub repo. - $_transient_data->response[ $this->name ]->plugin = $this->name; - - } - - $_transient_data->last_checked = time(); - $_transient_data->checked[ $this->name ] = $this->version; - - } - - return $_transient_data; - } - - /** - * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! - * - * @param string $file - * @param array $plugin - */ - public function show_update_notification( $file, $plugin ) { - - if ( is_network_admin() ) { - return; - } - - if( ! current_user_can( 'update_plugins' ) ) { - return; - } - - if( ! is_multisite() ) { - return; - } - - if ( $this->name != $file ) { - return; - } - - // Remove our filter on the site transient - remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); - - $update_cache = get_site_transient( 'update_plugins' ); - - $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass(); - - if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { - - $version_info = $this->get_cached_version_info(); - - if ( false === $version_info ) { - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) ); - - // Since we disabled our filter for the transient, we aren't running our object conversion on banners, sections, or icons. Do this now: - if ( isset( $version_info->banners ) && ! is_array( $version_info->banners ) ) { - $version_info->banners = $this->convert_object_to_array( $version_info->banners ); - } - - if ( isset( $version_info->sections ) && ! is_array( $version_info->sections ) ) { - $version_info->sections = $this->convert_object_to_array( $version_info->sections ); - } - - if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) { - $version_info->icons = $this->convert_object_to_array( $version_info->icons ); - } - - if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) { - $version_info->icons = $this->convert_object_to_array( $version_info->icons ); - } - - if ( isset( $version_info->contributors ) && ! is_array( $version_info->contributors ) ) { - $version_info->contributors = $this->convert_object_to_array( $version_info->contributors ); - } - - $this->set_version_info_cache( $version_info ); - } - - if ( ! is_object( $version_info ) ) { - return; - } - - if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { - - $update_cache->response[ $this->name ] = $version_info; - - } - - $update_cache->last_checked = time(); - $update_cache->checked[ $this->name ] = $this->version; - - set_site_transient( 'update_plugins', $update_cache ); - - } else { - - $version_info = $update_cache->response[ $this->name ]; - - } - - // Restore our filter - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); - - if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { - - // build a plugin list row, with update notification - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); - # - echo ''; - echo ''; - echo '
'; - - $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); - - if ( empty( $version_info->download_link ) ) { - printf( - __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'easy-digital-downloads' ), - esc_html( $version_info->name ), - '', - esc_html( $version_info->new_version ), - '' - ); - } else { - printf( - __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'easy-digital-downloads' ), - esc_html( $version_info->name ), - '', - esc_html( $version_info->new_version ), - '', - '', - '' - ); - } - - do_action( "in_plugin_update_message-{$file}", $plugin, $version_info ); - - echo '
'; - } - } - - /** - * Updates information on the "View version x.x details" page with custom data. - * - * @uses api_request() - * - * @param mixed $_data - * @param string $_action - * @param object $_args - * @return object $_data - */ - public function plugins_api_filter( $_data, $_action = '', $_args = null ) { - - if ( $_action != 'plugin_information' ) { - - return $_data; - - } - - if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { - - return $_data; - - } - - $to_send = array( - 'slug' => $this->slug, - 'is_ssl' => is_ssl(), - 'fields' => array( - 'banners' => array(), - 'reviews' => false, - 'icons' => array(), - ) - ); - - $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ); - - // Get the transient where we store the api request for this plugin for 24 hours - $edd_api_request_transient = $this->get_cached_version_info( $cache_key ); - - //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now. - if ( empty( $edd_api_request_transient ) ) { - - $api_response = $this->api_request( 'plugin_information', $to_send ); - - // Expires in 3 hours - $this->set_version_info_cache( $api_response, $cache_key ); - - if ( false !== $api_response ) { - $_data = $api_response; - } - - } else { - $_data = $edd_api_request_transient; - } - - // Convert sections into an associative array, since we're getting an object, but Core expects an array. - if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) { - $_data->sections = $this->convert_object_to_array( $_data->sections ); - } - - // Convert banners into an associative array, since we're getting an object, but Core expects an array. - if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) { - $_data->banners = $this->convert_object_to_array( $_data->banners ); - } - - // Convert icons into an associative array, since we're getting an object, but Core expects an array. - if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) { - $_data->icons = $this->convert_object_to_array( $_data->icons ); - } - - // Convert contributors into an associative array, since we're getting an object, but Core expects an array. - if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) { - $_data->contributors = $this->convert_object_to_array( $_data->contributors ); - } - - if( ! isset( $_data->plugin ) ) { - $_data->plugin = $this->name; - } - - return $_data; - } - - /** - * Convert some objects to arrays when injecting data into the update API - * - * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON - * decoding, they are objects. This method allows us to pass in the object and return an associative array. - * - * @since 3.6.5 - * - * @param stdClass $data - * - * @return array - */ - private function convert_object_to_array( $data ) { - $new_data = array(); - foreach ( $data as $key => $value ) { - $new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value; - } - - return $new_data; - } - - /** - * Disable SSL verification in order to prevent download update failures - * - * @param array $args - * @param string $url - * @return object $array - */ - public function http_request_args( $args, $url ) { - - $verify_ssl = $this->verify_ssl(); - if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { - $args['sslverify'] = $verify_ssl; - } - return $args; - - } - - /** - * Calls the API and, if successfull, returns the object delivered by the API. - * - * @uses get_bloginfo() - * @uses wp_remote_post() - * @uses is_wp_error() - * - * @param string $_action The requested action. - * @param array $_data Parameters for the API action. - * @return false|object - */ - private function api_request( $_action, $_data ) { - - global $wp_version, $edd_plugin_url_available; - - $verify_ssl = $this->verify_ssl(); - - // Do a quick status check on this domain if we haven't already checked it. - $store_hash = md5( $this->api_url ); - if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) { - $test_url_parts = parse_url( $this->api_url ); - - $scheme = ! empty( $test_url_parts['scheme'] ) ? $test_url_parts['scheme'] : 'http'; - $host = ! empty( $test_url_parts['host'] ) ? $test_url_parts['host'] : ''; - $port = ! empty( $test_url_parts['port'] ) ? ':' . $test_url_parts['port'] : ''; - - if ( empty( $host ) ) { - $edd_plugin_url_available[ $store_hash ] = false; - } else { - $test_url = $scheme . '://' . $host . $port; - $response = wp_remote_get( $test_url, array( 'timeout' => $this->health_check_timeout, 'sslverify' => $verify_ssl ) ); - $edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true; - } - } - - if ( false === $edd_plugin_url_available[ $store_hash ] ) { - return; - } - - $data = array_merge( $this->api_data, $_data ); - - if ( $data['slug'] != $this->slug ) { - return; - } - - if( $this->api_url == trailingslashit ( home_url() ) ) { - return false; // Don't allow a plugin to ping itself - } - - $api_params = array( - 'edd_action' => 'get_version', - 'license' => ! empty( $data['license'] ) ? $data['license'] : '', - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, - 'version' => isset( $data['version'] ) ? $data['version'] : false, - 'slug' => $data['slug'], - 'author' => $data['author'], - 'url' => home_url(), - 'beta' => ! empty( $data['beta'] ), - ); - - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) ); - - if ( ! is_wp_error( $request ) ) { - $request = json_decode( wp_remote_retrieve_body( $request ) ); - } - - if ( $request && isset( $request->sections ) ) { - $request->sections = maybe_unserialize( $request->sections ); - } else { - $request = false; - } - - if ( $request && isset( $request->banners ) ) { - $request->banners = maybe_unserialize( $request->banners ); - } - - if ( $request && isset( $request->icons ) ) { - $request->icons = maybe_unserialize( $request->icons ); - } - - if( ! empty( $request->sections ) ) { - foreach( $request->sections as $key => $section ) { - $request->$key = (array) $section; - } - } - - return $request; - } - - public function show_changelog() { - - global $edd_plugin_data; - - if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { - return; - } - - if( empty( $_REQUEST['plugin'] ) ) { - return; - } - - if( empty( $_REQUEST['slug'] ) ) { - return; - } - - if( ! current_user_can( 'update_plugins' ) ) { - wp_die( __( 'You do not have permission to install plugin updates', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) ); - } - - $data = $edd_plugin_data[ $_REQUEST['slug'] ]; - $beta = ! empty( $data['beta'] ) ? true : false; - $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' ); - $version_info = $this->get_cached_version_info( $cache_key ); - - if( false === $version_info ) { - - $api_params = array( - 'edd_action' => 'get_version', - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, - 'slug' => $_REQUEST['slug'], - 'author' => $data['author'], - 'url' => home_url(), - 'beta' => ! empty( $data['beta'] ) - ); - - $verify_ssl = $this->verify_ssl(); - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) ); - - if ( ! is_wp_error( $request ) ) { - $version_info = json_decode( wp_remote_retrieve_body( $request ) ); - } - - - if ( ! empty( $version_info ) && isset( $version_info->sections ) ) { - $version_info->sections = maybe_unserialize( $version_info->sections ); - } else { - $version_info = false; - } - - if( ! empty( $version_info ) ) { - foreach( $version_info->sections as $key => $section ) { - $version_info->$key = (array) $section; - } - } - - $this->set_version_info_cache( $version_info, $cache_key ); - - } - - if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) { - echo '
' . $version_info->sections['changelog'] . '
'; - } - - exit; - } - - public function get_cached_version_info( $cache_key = '' ) { - - if( empty( $cache_key ) ) { - $cache_key = $this->cache_key; - } - - $cache = get_option( $cache_key ); - - if( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) { - return false; // Cache is expired - } - - // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point. - $cache['value'] = json_decode( $cache['value'] ); - if ( ! empty( $cache['value']->icons ) ) { - $cache['value']->icons = (array) $cache['value']->icons; - } - - return $cache['value']; - - } - - public function set_version_info_cache( $value = '', $cache_key = '' ) { - - if( empty( $cache_key ) ) { - $cache_key = $this->cache_key; - } - - $data = array( - 'timeout' => strtotime( '+3 hours', time() ), - 'value' => json_encode( $value ) - ); - - update_option( $cache_key, $data, 'no' ); - - } - - /** - * Returns if the SSL of the store should be verified. - * - * @since 1.6.13 - * @return bool - */ - private function verify_ssl() { - return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this ); - } - -} diff --git a/Postman/Extensions/License/PostmanLicenseHandler.php b/Postman/Extensions/License/PostmanLicenseHandler.php deleted file mode 100644 index f8f32a21..00000000 --- a/Postman/Extensions/License/PostmanLicenseHandler.php +++ /dev/null @@ -1,482 +0,0 @@ -file = $_file; - $this->item_name = $_item_name; - - if ( is_numeric( $_item_id ) ) { - $this->item_id = absint( $_item_id ); - } - - $this->item_shortname = $this->get_slug(); - $this->version = $_version; - $this->license = trim( get_option( $this->item_shortname . '_license_key', '' ) ); - $this->license_data = get_option( $this->item_shortname . '_license_active', '' ); - $this->author = $_author; - $this->api_url = is_null( $_api_url ) ? $this->api_url : $_api_url; - - /** - * Allows for backwards compatibility with old license options, - * i.e. if the plugins had license key fields previously, the license - * handler will automatically pick these up and use those in lieu of the - * user having to reactive their license. - */ - if ( ! empty( $_optname ) ) { - $opt = get_option( $_optname, false ); - - if( isset( $opt ) && empty( $this->license ) ) { - $this->license = trim( $opt ); - } - } - - // Setup hooks - $this->includes(); - $this->hooks(); - - } - - /** - * Include the updater class - * - * @access private - * @return void - */ - private function includes() { - if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { - require_once 'EDD_SL_Plugin_Updater.php'; - } - } - - /** - * Setup hooks - * - * @access private - * @return void - */ - public function hooks() { - - // Activate license key on settings save - add_action( 'admin_init', array( $this, 'activate_license' ) ); - - // Deactivate license key - add_action( 'admin_init', array( $this, 'deactivate_license' ) ); - - add_action( 'init', array( $this, 'cron' ), 20 ); - - add_action( 'admin_init', array( $this, 'validate_license' ) ); - - // Updater - add_action( 'admin_init', array( $this, 'auto_updater' ), 0 ); - - // Display notices to admins - add_action( 'admin_notices', array( $this, 'notices' ) ); - - //add_action( 'in_plugin_update_message-' . plugin_basename( $this->file ), array( $this, 'plugin_row_license_missing' ), 10, 2 ); - } - - /** - * Auto updater - * - * @access private - * @return void - */ - public function auto_updater() { - - $args = array( - 'version' => $this->version, - 'license' => $this->license, - 'author' => $this->author, - 'beta' => function_exists( 'edd_extension_has_beta_support' ) && edd_extension_has_beta_support( $this->item_shortname ), - ); - - if( ! empty( $this->item_id ) ) { - $args['item_id'] = $this->item_id; - } else { - $args['item_name'] = $this->item_name; - } - - // Setup the updater - $edd_updater = new EDD_SL_Plugin_Updater( - $this->api_url, - $this->file, - $args - ); - } - - public function cron() { - if ( ! wp_next_scheduled( $this->item_shortname . '_scheduled_events' ) ) { - wp_schedule_event( current_time( 'timestamp', true ), 'daily', $this->item_shortname . '_scheduled_events' ); - } - } - - public function get_slug() { - return preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->item_name ) ) ); - } - - /** - * Display help text at the top of the Licenses tag - * - * @since 2.5 - * @param string $active_tab - * @return void - */ - public function license_help_text( $active_tab = '' ) { - - static $has_ran; - - if( 'licenses' !== $active_tab ) { - return; - } - - if( ! empty( $has_ran ) ) { - return; - } - - echo '

' . sprintf( - __( 'Enter your extension license keys here to receive updates for purchased extensions. If your license key has expired, please renew your license.', 'easy-digital-downloads' ), - 'http://docs.easydigitaldownloads.com/article/1000-license-renewal' - ) . '

'; - - $has_ran = true; - - } - - - /** - * Activate the license key - * - * @return void - */ - public function activate_license() { - - if ( ! isset( $_POST['post_smtp_extension'][ $this->item_shortname . '_activate'] ) ) { - return; - } - - if ( ! isset( $_REQUEST[ $this->item_shortname . '_license_key-nonce'] ) || ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce'], $this->item_shortname . '_license_key-nonce' ) ) { - - return; - - } - - if ( ! current_user_can( 'manage_options' ) ) { - return; - } - - if ( empty( $_POST['post_smtp_extension'][ $this->item_shortname . '_license_key'] ) ) { - - delete_option( $this->item_shortname . '_license_active' ); - delete_option( $this->item_shortname . '_license_key' ); - - return; - - } - - foreach ( $_POST as $key => $value ) { - if( false !== strpos( $key, 'license_key_deactivate' ) ) { - // Don't activate a key when deactivating a different key - return; - } - } - - $details = get_option( $this->item_shortname . '_license_active' ); - - if ( is_object( $details ) && 'valid' === $details->license ) { - return; - } - - $license = sanitize_text_field( $_POST['post_smtp_extension'][ $this->item_shortname . '_license_key'] ); - - if( empty( $license ) ) { - return; - } - - // Data to send to the API - $api_params = array( - 'edd_action' => 'activate_license', - 'license' => $license, - 'item_name' => urlencode( $this->item_name ), - 'url' => home_url() - ); - - if ( ! empty( $this->item_id ) ) { - $api_params['item_id'] = $this->item_id; - } - - // Call the API - $response = wp_remote_post( - $this->api_url, - array( - 'timeout' => 15, - 'sslverify' => false, - 'body' => $api_params - ) - ); - - // Make sure there are no errors - if ( is_wp_error( $response ) ) { - return; - } - - // Tell WordPress to look for updates - set_site_transient( 'update_plugins', null ); - - // Decode license data - $this->license_data = json_decode( wp_remote_retrieve_body( $response ) ); - - update_option( $this->item_shortname . '_license_active', $this->license_data ); - update_option( $this->item_shortname . '_license_key', $license ); - - if ( $this->license_data->success && $this->license_data->license == 'valid' ) { - $slug = plugin_basename($this->file); - PostmanLicenseManager::get_instance()->add_extension($slug); - } - } - - - /** - * Deactivate the license key - * - * @return void - */ - public function deactivate_license() { - - if ( ! isset( $_POST['post_smtp_extension'][ $this->item_shortname . '_deactivate'] ) ) { - return; - } - - if ( ! isset( $_POST['post_smtp_extension'][ $this->item_shortname . '_license_key'] ) ) - return; - - if( ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce'], $this->item_shortname . '_license_key-nonce' ) ) { - - wp_die( __( 'Nonce verification failed', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) ); - - } - - if( ! current_user_can( 'manage_options' ) ) { - return; - } - - $license_key = sanitize_text_field( base64_decode( $_POST['post_smtp_extension'][ $this->item_shortname . '_license_key'] ) ); - - // Run on deactivate button press - // Data to send to the API - $api_params = array( - 'edd_action' => 'deactivate_license', - 'license' => $license_key, - 'item_name' => urlencode( $this->item_name ), - 'url' => home_url() - ); - - if ( ! empty( $this->item_id ) ) { - $api_params['item_id'] = $this->item_id; - } - - // Call the API - $response = wp_remote_post( - $this->api_url, - array( - 'timeout' => 15, - 'sslverify' => false, - 'body' => $api_params - ) - ); - - // Make sure there are no errors - if ( is_wp_error( $response ) ) { - return; - } - - // Decode the license data - $this->license_data = json_decode( wp_remote_retrieve_body( $response ) ); - - delete_option( $this->item_shortname . '_license_active' ); - delete_option( $this->item_shortname . '_license_key' ); - - $slug = plugin_basename($this->file); - PostmanLicenseManager::get_instance()->remove_extension($slug); - - } - - public function validate_license() { - if ( false === ( $cron_data = get_transient( $this->item_shortname . '_cron' ) ) ) { - $this->license_check(); - - set_transient( $this->item_shortname . '_cron', true, rand( 12, 48 ) * HOUR_IN_SECONDS ); - } - - $license_data = $this->license_data; - - if ( $license_data && isset( $license_data->expires ) ) { - if ( $license_data->expires == 'lifetime' ) { - $expires = '2500/12/12'; - } else { - $expires = $license_data->expires; - } - } else { - return; - } - - $datetime1 = new DateTime(); - - if ( is_numeric( $expires ) ) { - $datetime2 = new DateTime(); - $datetime2->setTimestamp( $expires ); - } else { - $datetime2 = new DateTime( $expires ); - } - - foreach ( self::DAYS_TO_ALERT as $day_to_alert ) { - - $interval = $datetime1->diff($datetime2); - if( $interval->days == $day_to_alert ){ - add_action( 'admin_notices', function () use ( $day_to_alert, $license_data ) { - //echo $this->item_name . ' is about to expire in ' . $day_to_alert . ' days: ' . $license_data->expires; - }); - - return; - } - - if ( $interval->days == 0 ) { - add_action( 'admin_notices', function () use ( $license_data ) { - //echo $this->item_name . ' license expire today at: ' . $license_data->expires; - }); - - return; - } - } - - if ( $license_data->activations_left == 0 ) { - add_action( 'admin_notices', function () use ( $license_data ) { - //echo $this->item_name . ' has no activations'; - }); - - return; - } - } - - - /** - * Check if license key is valid once per week - * - * @since 2.5 - * @return void - */ - public function license_check() { - - // data to send in our API request - $api_params = array( - 'edd_action'=> 'check_license', - 'license' => $this->license, - 'item_name' => urlencode( $this->item_name ), - 'url' => home_url() - ); - - // Call the API - $response = wp_remote_post( - $this->api_url, - array( - 'timeout' => 15, - 'sslverify' => false, - 'body' => $api_params - ) - ); - - // make sure the response came back okay - if ( is_wp_error( $response ) ) { - return false; - } - - if ( wp_remote_retrieve_response_code( $response ) !== 200 ) { - return false; - } - - $this->license_data = json_decode( wp_remote_retrieve_body( $response ) ); - - update_option( $this->item_shortname . '_license_active', $this->license_data ); - - } - - private function get_license_data() { - return get_option( $this->item_shortname . '_license_active' ); - } - - - /** - * Admin notices for errors - * - * @return void - */ - public function notices() { - - $showed_invalid_message = null; - - if( empty( $this->license ) ) { - return; - } - - if( ! current_user_can( 'manage_options' ) ) { - return; - } - - $messages = array(); - - $license = get_option( $this->item_shortname . '_license_active' ); - - if( is_object( $license ) && 'valid' !== $license->license && empty( $showed_invalid_message ) ) { - - if( isset( $_GET['page'] ) && 'post-smtp-extensions' === $_GET['page'] ) { - - $messages[] = sprintf( - __( '%s has invalid or expired license key for Post SMTP.'), - '' . $this->item_name . '' - ); - - $showed_invalid_message = true; - - } - - } - - if( ! empty( $messages ) ) { - - foreach( $messages as $message ) { - - echo '
'; - echo '

' . $message . '

'; - echo '
'; - - } - - } - - } - - public function is_licensed() { - return is_object($this->license_data) && 'valid' === $this->license_data->license; - } -} - -endif; // end class_exists check diff --git a/Postman/Extensions/License/PostmanLicenseManager.php b/Postman/Extensions/License/PostmanLicenseManager.php deleted file mode 100644 index 17cfecf7..00000000 --- a/Postman/Extensions/License/PostmanLicenseManager.php +++ /dev/null @@ -1,90 +0,0 @@ -includes(); - $this->rand_cache_interval = rand( 1, 24 ); - } - - public function includes() { - include_once 'PostmanLicenseHandler.php'; - - include_once ABSPATH . '/wp-admin/includes/plugin.php'; - - } - - /** - * Init - */ - public function init() { - - $plugins = get_plugins(); - foreach ( $plugins as $plugin_dir_and_filename => $plugin_data ) { - - if ( ! is_plugin_active( $plugin_dir_and_filename ) ) { - continue; - } - - if ( false !== strpos( $plugin_dir_and_filename, 'post-smtp-extension' ) ) { - $slug = $plugin_dir_and_filename; - $class = $plugin_data['Class']; - $plugin_path = WP_CONTENT_DIR . '/plugins/' . $plugin_dir_and_filename; - - $this->extensions[$slug]['plugin_data'] = $plugin_data; - $this->extensions[$slug]['plugin_dir_and_filename'] = $plugin_dir_and_filename; - $this->extensions[$slug]['license_manager'] = new PostmanLicenseHandler( - $plugin_path, $plugin_data['Name'], - $plugin_data['Version'], $plugin_data['Author'], null, self::ENDPOINT - ); - if ( $this->extensions[$slug]['license_manager']->is_licensed() ) { - $this->extensions[$slug]['instance'] = new $class; - } - } - } - - if ( ! empty( $this->extensions ) ) { - new PostmanAdmin(); - } - } - - public function add_extension($slug) { - $plugin_path = WP_CONTENT_DIR . '/plugins/' . $this->extensions[$slug]['plugin_dir_and_filename']; - $class = $this->extensions[$slug]['plugin_data']['Class']; - - include_once $plugin_path; - $this->extensions[$slug]['instance'] = new $class; - } - - public function remove_extension($slug) { - $this->extensions[$slug]['instance'] = null; - unset($this->extensions[$slug]['instance']); - } - - public function get_extensions() { - return $this->extensions; - } -} diff --git a/postman-smtp.php b/postman-smtp.php index ff86ded6..6dc3f21c 100644 --- a/postman-smtp.php +++ b/postman-smtp.php @@ -6,7 +6,7 @@ * Plugin Name: Post SMTP * Plugin URI: https://wordpress.org/plugins/post-smtp/ * Description: Email not reliable? Post SMTP is the first and only WordPress SMTP plugin to implement OAuth 2.0 for Gmail, Hotmail and Yahoo Mail. Setup is a breeze with the Configuration Wizard and integrated Port Tester. Enjoy worry-free delivery even if your password changes! - * Version: 2.1.4-rc.1 + * Version: 2.1.4-beta.1 * Author: Post SMTP * Text Domain: post-smtp * Author URI: https://postmansmtp.com @@ -74,7 +74,7 @@ function ps_fs() { define( 'POST_SMTP_BASE', __FILE__ ); define( 'POST_SMTP_PATH', __DIR__ ); define( 'POST_SMTP_URL', plugins_url('', POST_SMTP_BASE ) ); -define( 'POST_SMTP_VER', '2.1.4' ); +define( 'POST_SMTP_VER', '2.1.3' ); define( 'POST_SMTP_ASSETS', plugin_dir_url( __FILE__ ) . 'assets/' ); $postman_smtp_exist = in_array( 'postman-smtp/postman-smtp.php', (array) get_option( 'active_plugins', array() ) ); diff --git a/readme.txt b/readme.txt index c5f0a3df..6b7577e0 100644 --- a/readme.txt +++ b/readme.txt @@ -212,7 +212,7 @@ You've [forgotten to choose an email address in the consent screen](https://word == SMTP Error Messages == -= Communication Error [334] – make sure the Envelope From Email is the same account used to create the Client ID. = += Communication Error [334] – make sure the Envelope From Email is the same account used to create the Client ID. = * This is almost always caused by being logged in to Google/Microsoft/Yahoo with a different user than the one Post is configured to send mail with. Logout and try again with the correct user * Login to [Webmail](http://www.gmail.com) and see if there is an "Unusual Activity" warning waiting for your attention @@ -287,7 +287,7 @@ To avoid being flagged as spam, you need to prove your email isn't forged. On a Removed unused code * **FIX** -“Less secure App” Banner appearing in non-appropriate cases +“Less secure App” Banner appearing in non-appropriate cases = 2.1.1.1 - 2022-06-15 = @@ -317,7 +317,7 @@ Add notice about Google Less Secure App. = 2.0.25 - 2022-04-06 = * **Bug Fixes** * WP 5.9 Compatibility Ballon UI issue. -* Uncaught Error: Class ‘PostmanAdminController’ not found. +* Uncaught Error: Class ‘PostmanAdminController’ not found. * Ajax error appearing due to Google API depreciated function. * **Improvements** @@ -338,7 +338,7 @@ Add notice about Google Less Secure App. = 2.0.21 - 2021-02-11 * Fixed: Security issue - nonce validation. -* Fixed: Class ‘PostmanViewController’ not found +* Fixed: Class ‘PostmanViewController’ not found * New: New wp-config.php constant to disable the email logger = `POST_SMTP_CORE_MAIL_LOG`. = 2.0.20 - 2021-01-19