diff --git a/includes/library/appsero/Client.php b/includes/library/appsero/Client.php deleted file mode 100755 index f14901f..0000000 --- a/includes/library/appsero/Client.php +++ /dev/null @@ -1,210 +0,0 @@ -hash = $hash; - $this->name = $name; - $this->file = $file; - - $this->set_basename_and_slug(); - } - - /** - * Initialize insights class - * - * @return Appsero\Insights - */ - public function insights() { - - if ( ! class_exists( __NAMESPACE__ . '\Insights') ) { - require_once __DIR__ . '/Insights.php'; - } - - return new Insights( $this ); - } - - /** - * Initialize plugin/theme updater - * - * @return Appsero\Updater - */ - public function updater() { - - if ( ! class_exists( __NAMESPACE__ . '\Updater') ) { - require_once __DIR__ . '/Updater.php'; - } - - return new Updater( $this ); - } - - /** - * Initialize license checker - * - * @return Appsero\License - */ - public function license() { - - if ( ! class_exists( __NAMESPACE__ . '\License') ) { - require_once __DIR__ . '/License.php'; - } - - return new License( $this ); - } - - /** - * API Endpoint - * - * @return string - */ - public function endpoint() { - $endpoint = apply_filters( 'appsero_endpoint', 'https://api.appsero.com' ); - - return trailingslashit( $endpoint ); - } - - /** - * Set project basename, slug and version - * - * @return void - */ - protected function set_basename_and_slug() { - - if ( strpos( $this->file, WP_CONTENT_DIR . '/themes/' ) === false ) { - - $this->basename = plugin_basename( $this->file ); - - list( $this->slug, $mainfile) = explode( '/', $this->basename ); - - require_once ABSPATH . 'wp-admin/includes/plugin.php'; - - $plugin_data = get_plugin_data( $this->file ); - - $this->project_version = $plugin_data['Version']; - $this->type = 'plugin'; - $this->textdomain = $this->slug; - - } else { - - $this->basename = str_replace( WP_CONTENT_DIR . '/themes/', '', $this->file ); - - list( $this->slug, $mainfile) = explode( '/', $this->basename ); - - $theme = wp_get_theme( $this->slug ); - - $this->project_version = $theme->version; - $this->type = 'theme'; - - } - } - - /** - * Send request to remote endpoint - * - * @param array $params - * @param string $route - * - * @return array|WP_Error Array of results including HTTP headers or WP_Error if the request failed. - */ - public function send_request( $params, $route, $blocking = false ) { - $url = $this->endpoint() . $route; - - $headers = array( - 'user-agent' => 'Appsero/' . md5( esc_url( home_url() ) ) . ';', - 'Accept' => 'application/json', - ); - - $response = wp_remote_post( $url, array( - 'method' => 'POST', - 'timeout' => 30, - 'redirection' => 5, - 'httpversion' => '1.0', - 'blocking' => $blocking, - 'headers' => $headers, - 'body' => array_merge( $params, array( 'client' => $this->version ) ), - 'cookies' => array() - ) ); - - return $response; - } - -} diff --git a/includes/library/appsero/Insights.php b/includes/library/appsero/Insights.php deleted file mode 100755 index 3b113ca..0000000 --- a/includes/library/appsero/Insights.php +++ /dev/null @@ -1,875 +0,0 @@ -client = $client; - } - } - - /** - * Don't show the notice - * - * @return \self - */ - public function hide_notice() { - $this->show_notice = false; - - return $this; - } - - /** - * Add extra data if needed - * - * @param array $data - * - * @return \self - */ - public function add_extra( $data = array() ) { - $this->extra_data = $data; - - return $this; - } - - /** - * Set custom notice text - * - * @param string $text - * - * @return \self - */ - public function notice( $text ) { - $this->notice = $text; - - return $this; - } - - /** - * Initialize insights - * - * @return void - */ - public function init() { - if ( $this->client->type == 'plugin' ) { - $this->init_plugin(); - } else if ( $this->client->type == 'theme' ) { - $this->init_theme(); - } - } - - /** - * Initialize theme hooks - * - * @return void - */ - public function init_theme() { - $this->init_common(); - - add_action( 'switch_theme', array( $this, 'deactivation_cleanup' ) ); - add_action( 'switch_theme', array( $this, 'theme_deactivated' ), 12, 3 ); - } - - /** - * Initialize plugin hooks - * - * @return void - */ - public function init_plugin() { - // plugin deactivate popup - if ( ! $this->is_local_server() ) { - add_filter( 'plugin_action_links_' . $this->client->basename, array( $this, 'plugin_action_links' ) ); - add_action( 'admin_footer', array( $this, 'deactivate_scripts' ) ); - } - - $this->init_common(); - - register_activation_hook( $this->client->file, array( $this, 'activate_plugin' ) ); - register_deactivation_hook( $this->client->file, array( $this, 'deactivation_cleanup' ) ); - } - - /** - * Initialize common hooks - * - * @return void - */ - protected function init_common() { - add_action( 'admin_init', array( $this, 'handle_optin_optout' ) ); - - // uninstall reason - add_action( 'wp_ajax_' . $this->client->slug . '_submit-uninstall-reason', array( $this, 'uninstall_reason_submission' ) ); - - // cron events - add_filter( 'cron_schedules', array( $this, 'add_weekly_schedule' ) ); - add_action( $this->client->slug . '_tracker_send_event', array( $this, 'send_tracking_data' ) ); - // add_action( 'admin_init', array( $this, 'send_tracking_data' ) ); // test - } - - /** - * Send tracking data to AppSero server - * - * @param boolean $override - * - * @return void - */ - public function send_tracking_data( $override = false ) { - // skip on AJAX Requests - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { - return; - } - - if ( ! $this->tracking_allowed() && ! $override ) { - return; - } - - // Send a maximum of once per week - $last_send = $this->get_last_send(); - - if ( $last_send && $last_send > strtotime( '-1 week' ) ) { - return; - } - - $response = $this->client->send_request( $this->get_tracking_data(), 'track' ); - - update_option( $this->client->slug . '_tracking_last_send', time() ); - } - - /** - * Get the tracking data points - * - * @return array - */ - protected function get_tracking_data() { - $all_plugins = $this->get_all_plugins(); - - $users = get_users( array( - 'role' => 'administrator', - 'orderby' => 'ID', - 'order' => 'ASC', - 'number' => 1, - 'paged' => 1, - ) ); - - $admin_user = ( is_array( $users ) && ! empty( $users ) ) ? $users[0] : false; - $first_name = $last_name = ''; - - if ( $admin_user ) { - $first_name = $admin_user->first_name ? $admin_user->first_name : $admin_user->display_name; - $last_name = $admin_user->last_name; - } - - $data = array( - 'version' => $this->client->project_version, - 'url' => esc_url( home_url() ), - 'site' => $this->get_site_name(), - 'admin_email' => get_option( 'admin_email' ), - 'first_name' => $first_name, - 'last_name' => $last_name, - 'hash' => $this->client->hash, - 'server' => $this->get_server_info(), - 'wp' => $this->get_wp_info(), - 'users' => $this->get_user_counts(), - 'active_plugins' => count( $all_plugins['active_plugins'] ), - 'inactive_plugins' => count( $all_plugins['inactive_plugins'] ), - 'ip_address' => $this->get_user_ip_address(), - 'theme' => get_stylesheet(), - 'version' => $this->client->project_version, - ); - - // Add metadata - if ( $extra = $this->get_extra_data() ) { - $data['extra'] = $extra; - } - - return apply_filters( $this->client->slug . '_tracker_data', $data ); - } - - /** - * If a child class wants to send extra data - * - * @return mixed - */ - protected function get_extra_data() { - if ( is_callable( $this->extra_data ) ) { - return call_user_func( $this->extra_data ); - } - - if ( is_array( $this->extra_data ) ) { - return $this->extra_data; - } - - return array(); - } - - /** - * Explain the user which data we collect - * - * @return string - */ - protected function data_we_collect() { - $data = array( - 'Server environment details (php, mysql, server, WordPress versions)', - 'Number of users in your site', - 'Site language', - 'Number of active and inactive plugins', - 'Site name and url', - 'Your name and email address', - ); - - return $data; - } - - /** - * Check if the user has opted into tracking - * - * @return bool - */ - public function tracking_allowed() { - $allow_tracking = get_option( $this->client->slug . '_allow_tracking', 'no' ); - - return $allow_tracking == 'yes'; - } - - /** - * Get the last time a tracking was sent - * - * @return false|string - */ - private function get_last_send() { - return get_option( $this->client->slug . '_tracking_last_send', false ); - } - - /** - * Check if the notice has been dismissed or enabled - * - * @return boolean - */ - private function notice_dismissed() { - $version = get_option( $this->client->slug . '_hide_fortressdb_version', null ); - $current_version = get_option( 'weforms_version' ); - - if ( $version && version_compare( $current_version, $version, '<=' ) ) { - return true; - } - - return false; - } - - /** - * Check if the current server is localhost - * - * @return boolean - */ - private function is_local_server() { - return false; - - $is_local = in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ) ); - - return apply_filters( 'appsero_is_local', $is_local ); - } - - /** - * Schedule the event weekly - * - * @return void - */ - private function schedule_event() { - $hook_name = $this->client->slug . '_tracker_send_event'; - - if ( ! wp_next_scheduled( $hook_name ) ) { - wp_schedule_event( time(), 'weekly', $hook_name ); - } - } - - /** - * Clear any scheduled hook - * - * @return void - */ - private function clear_schedule_event() { - wp_clear_scheduled_hook( $this->client->slug . '_tracker_send_event' ); - } - - /** - * handle the optin/optout - * - * @return void - */ - public function handle_optin_optout() { - - if ( isset( $_GET[ $this->client->slug . '_hide_fortressdb' ] ) && $_GET[ $this->client->slug . '_hide_fortressdb' ] == 'true' ) { - $current_version = get_option( 'weforms_version' ); - update_option( $this->client->slug . '_hide_fortressdb_version', $current_version ); - - wp_redirect( remove_query_arg( $this->client->slug . '_hide_fortressdb' ) ); - exit; - } - } - - /** - * Get the number of post counts - * - * @param string $post_type - * - * @return integer - */ - public function get_post_count( $post_type ) { - global $wpdb; - - return (int) $wpdb->get_var( "SELECT count(ID) FROM $wpdb->posts WHERE post_type = '$post_type' and post_status = 'publish'"); - } - - /** - * Get server related info. - * - * @return array - */ - private static function get_server_info() { - global $wpdb; - - $server_data = array(); - - if ( isset( $_SERVER['SERVER_SOFTWARE'] ) && ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) { - $server_data['software'] = $_SERVER['SERVER_SOFTWARE']; - } - - if ( function_exists( 'phpversion' ) ) { - $server_data['php_version'] = phpversion(); - } - - $server_data['mysql_version'] = $wpdb->db_version(); - - $server_data['php_max_upload_size'] = size_format( wp_max_upload_size() ); - $server_data['php_default_timezone'] = date_default_timezone_get(); - $server_data['php_soap'] = class_exists( 'SoapClient' ) ? 'Yes' : 'No'; - $server_data['php_fsockopen'] = function_exists( 'fsockopen' ) ? 'Yes' : 'No'; - $server_data['php_curl'] = function_exists( 'curl_init' ) ? 'Yes' : 'No'; - - return $server_data; - } - - /** - * Get WordPress related data. - * - * @return array - */ - private function get_wp_info() { - $wp_data = array(); - - $wp_data['memory_limit'] = WP_MEMORY_LIMIT; - $wp_data['debug_mode'] = ( defined('WP_DEBUG') && WP_DEBUG ) ? 'Yes' : 'No'; - $wp_data['locale'] = get_locale(); - $wp_data['version'] = get_bloginfo( 'version' ); - $wp_data['multisite'] = is_multisite() ? 'Yes' : 'No'; - - return $wp_data; - } - - /** - * Get the list of active and inactive plugins - * - * @return array - */ - private function get_all_plugins() { - // Ensure get_plugins function is loaded - if ( ! function_exists( 'get_plugins' ) ) { - include ABSPATH . '/wp-admin/includes/plugin.php'; - } - - $plugins = get_plugins(); - $active_plugins_keys = get_option( 'active_plugins', array() ); - $active_plugins = array(); - - foreach ( $plugins as $k => $v ) { - // Take care of formatting the data how we want it. - $formatted = array(); - $formatted['name'] = strip_tags( $v['Name'] ); - - if ( isset( $v['Version'] ) ) { - $formatted['version'] = strip_tags( $v['Version'] ); - } - - if ( isset( $v['Author'] ) ) { - $formatted['author'] = strip_tags( $v['Author'] ); - } - - if ( isset( $v['Network'] ) ) { - $formatted['network'] = strip_tags( $v['Network'] ); - } - - if ( isset( $v['PluginURI'] ) ) { - $formatted['plugin_uri'] = strip_tags( $v['PluginURI'] ); - } - - if ( in_array( $k, $active_plugins_keys ) ) { - // Remove active plugins from list so we can show active and inactive separately - unset( $plugins[$k] ); - $active_plugins[$k] = $formatted; - } else { - $plugins[$k] = $formatted; - } - } - - return array( 'active_plugins' => $active_plugins, 'inactive_plugins' => $plugins ); - } - - /** - * Get user totals based on user role. - * - * @return array - */ - public function get_user_counts() { - $user_count = array(); - $user_count_data = count_users(); - $user_count['total'] = $user_count_data['total_users']; - - // Get user count based on user role - foreach ( $user_count_data['avail_roles'] as $role => $count ) { - $user_count[ $role ] = $count; - } - - return $user_count; - } - - /** - * Add weekly cron schedule - * - * @param array $schedules - * - * @return array - */ - public function add_weekly_schedule( $schedules ) { - - $schedules['weekly'] = array( - 'interval' => DAY_IN_SECONDS * 7, - 'display' => 'Once Weekly', - ); - - return $schedules; - } - - /** - * Plugin activation hook - * - * @return void - */ - public function activate_plugin() { - $allowed = get_option( $this->client->slug . '_allow_tracking', 'no' ); - - // if it wasn't allowed before, do nothing - if ( 'yes' !== $allowed ) { - return; - } - - // re-schedule and delete the last sent time so we could force send again - $hook_name = $this->client->slug . '_tracker_send_event'; - if ( ! wp_next_scheduled( $hook_name ) ) { - wp_schedule_event( time(), 'weekly', $hook_name ); - } - - delete_option( $this->client->slug . '_tracking_last_send' ); - - $this->send_tracking_data( true ); - } - - /** - * Clear our options upon deactivation - * - * @return void - */ - public function deactivation_cleanup() { - $this->clear_schedule_event(); - - if ( 'theme' == $this->client->type ) { - delete_option( $this->client->slug . '_tracking_last_send' ); - delete_option( $this->client->slug . '_allow_tracking' ); - } - - delete_option( $this->client->slug . '_tracking_notice' ); - } - - /** - * Hook into action links and modify the deactivate link - * - * @param array $links - * - * @return array - */ - public function plugin_action_links( $links ) { - - if ( array_key_exists( 'deactivate', $links ) ) { - $links['deactivate'] = str_replace( ' 'could-not-understand', - 'text' => 'I couldn\'t understand how to make it work', - 'type' => 'textarea', - 'placeholder' => 'Would you like us to assist you?' - ), - array( - 'id' => 'found-better-plugin', - 'text' => 'I found a better plugin', - 'type' => 'text', - 'placeholder' => 'Which plugin?' - ), - array( - 'id' => 'not-have-that-feature', - 'text' => 'The plugin is great, but I need specific feature that you don\'t support', - 'type' => 'textarea', - 'placeholder' => 'Could you tell us more about that feature?' - ), - array( - 'id' => 'is-not-working', - 'text' => 'The plugin is not working', - 'type' => 'textarea', - 'placeholder' => 'Could you tell us a bit more whats not working?' - ), - array( - 'id' => 'looking-for-other', - 'text' => 'It\'s not what I was looking for', - 'type' => '', - 'placeholder' => '' - ), - array( - 'id' => 'did-not-work-as-expected', - 'text' => 'The plugin didn\'t work as expected', - 'type' => 'textarea', - 'placeholder' => 'What did you expect?' - ), - array( - 'id' => 'other', - 'text' => 'Other', - 'type' => 'textarea', - 'placeholder' => 'Could you tell us a bit more?' - ), - ); - - return $reasons; - } - - /** - * Plugin deactivation uninstall reason submission - * - * @return void - */ - public function uninstall_reason_submission() { - - if ( ! isset( $_POST['reason_id'] ) ) { - wp_send_json_error(); - } - - $current_user = wp_get_current_user(); - - $data = array( - 'hash' => $this->client->hash, - 'reason_id' => sanitize_text_field( $_POST['reason_id'] ), - 'reason_info' => isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '', - 'site' => $this->get_site_name(), - 'url' => esc_url( home_url() ), - 'admin_email' => get_option( 'admin_email' ), - 'user_email' => $current_user->user_email, - 'first_name' => $current_user->first_name, - 'last_name' => $current_user->last_name, - 'server' => $this->get_server_info(), - 'wp' => $this->get_wp_info(), - 'ip_address' => $this->get_user_ip_address(), - 'theme' => get_stylesheet(), - 'version' => $this->client->project_version, - ); - - // Add metadata - if ( $extra = $this->get_extra_data() ) { - $data['extra'] = $extra; - } - - $this->client->send_request( $data, 'deactivate' ); - - wp_send_json_success(); - } - - /** - * Handle the plugin deactivation feedback - * - * @return void - */ - public function deactivate_scripts() { - global $pagenow; - - if ( 'plugins.php' != $pagenow ) { - return; - } - - $reasons = $this->get_uninstall_reasons(); - ?> - -
-
-
-

client->textdomain, 'weforms' ); ?>

-
- -
-
    - -
  • - -
  • - -
-

We share your data with Appsero to troubleshoot problems & make product improvements. Learn more about how Appsero handles your data.

-
- - -
-
- - - - - - get_template() == $this->client->slug ) { - $current_user = wp_get_current_user(); - - $data = array( - 'hash' => $this->client->hash, - 'reason_id' => 'none', - 'reason_info' => '', - 'site' => $this->get_site_name(), - 'url' => esc_url( home_url() ), - 'admin_email' => get_option( 'admin_email' ), - 'user_email' => $current_user->user_email, - 'first_name' => $current_user->first_name, - 'last_name' => $current_user->last_name, - 'server' => $this->get_server_info(), - 'wp' => $this->get_wp_info(), - 'ip_address' => $this->get_user_ip_address(), - 'theme' => get_stylesheet(), - 'version' => $this->client->project_version, - ); - - $this->client->send_request( $data, 'deactivate' ); - } - } - - /** - * Get user IP Address - */ - private function get_user_ip_address() { - $response = wp_remote_get( 'https://icanhazip.com/' ); - - if ( is_wp_error( $response ) ) { - return ''; - } - - $ip = trim( wp_remote_retrieve_body( $response ) ); - - if ( ! filter_var( $ip, FILTER_VALIDATE_IP ) ) { - return ''; - } - - return $ip; - } - - /** - * Get site name - */ - private function get_site_name() { - $site_name = get_bloginfo( 'name' ); - - if ( empty( $site_name ) ) { - $site_name = get_bloginfo( 'description' ); - $site_name = wp_trim_words( $site_name, 3, '' ); - } - - if ( empty( $site_name ) ) { - $site_name = get_bloginfo( 'url' ); - } - - return $site_name; - } -} diff --git a/includes/library/appsero/License.php b/includes/library/appsero/License.php deleted file mode 100755 index 8604960..0000000 --- a/includes/library/appsero/License.php +++ /dev/null @@ -1,701 +0,0 @@ -client = $client; - - $this->option_key = 'appsero_' . md5( $this->client->slug ) . '_manage_license'; - - $this->schedule_hook = $this->client->slug . '_license_check_event'; - - // Run hook to check license status daily - add_action( $this->schedule_hook, array( $this, 'check_license_status' ) ); - - // Active/Deactive corn schedule - $this->run_schedule(); - } - - /** - * Check license - * - * @return boolean - */ - public function check( $license_key ) { - $route = 'public/license/' . $this->client->hash . '/check'; - - return $this->send_request( $license_key, $route ); - } - - /** - * Active a license - * - * @return boolean - */ - public function activate( $license_key ) { - $route = 'public/license/' . $this->client->hash . '/activate'; - - return $this->send_request( $license_key, $route ); - } - - /** - * Deactivate a license - * - * @return boolean - */ - public function deactivate( $license_key ) { - $route = 'public/license/' . $this->client->hash . '/deactivate'; - - return $this->send_request( $license_key, $route ); - } - - /** - * Send common request - * - * @param $license_key - * @param $route - * - * @return array - */ - protected function send_request( $license_key, $route ) { - $params = array( - 'license_key' => $license_key, - 'url' => esc_url( home_url() ), - ); - - $response = $this->client->send_request( $params, $route, true ); - - if ( is_wp_error( $response ) ) { - return array( - 'success' => false, - 'error' => $response->get_error_message() - ); - } - - $response = json_decode( wp_remote_retrieve_body( $response ), true ); - - if ( empty( $response ) || isset( $response['exception'] )) { - return array( - 'success' => false, - 'error' => 'Unknown error occurred, Please try again.' - ); - } - - if ( isset( $response['errors'] ) && isset( $response['errors']['license_key'] ) ) { - $response = array( - 'success' => false, - 'error' => $response['errors']['license_key'][0] - ); - } - - return $response; - } - - /** - * Add settings page for license - * - * @param array $args - * - * @return void - */ - public function add_settings_page( $args = array() ) { - $defaults = array( - 'type' => 'menu', // Can be: menu, options, submenu - 'page_title' => 'Manage License', - 'menu_title' => 'Manage License', - 'capability' => 'manage_options', - 'menu_slug' => $this->client->slug . '-manage-license', - 'icon_url' => '', - 'position' => null, - 'parent_slug' => '', - ); - - $this->menu_args = wp_parse_args( $args, $defaults ); - - add_action( 'admin_menu', array( $this, 'admin_menu' ), 99 ); - } - - /** - * Admin Menu hook - * - * @return void - */ - public function admin_menu() { - switch ( $this->menu_args['type'] ) { - case 'menu': - $this->add_menu_page(); - break; - - case 'submenu': - $this->add_submenu_page(); - break; - - case 'options': - $this->add_options_page(); - break; - } - } - - /** - * License menu output - */ - public function menu_output() { - - if ( isset( $_POST['submit'] ) ) { - $this->license_form_submit( $_POST ); - } - - $license = get_option( $this->option_key, null ); - $action = ( $license && isset( $license['status'] ) && 'activate' == $license['status'] ) ? 'deactive' : 'active'; - $this->licenses_style(); - ?> - -
-

License Settings

- - show_license_page_notices(); - do_action( 'before_appsero_license_section' ); - ?> - -
- show_license_page_card_header(); ?> - -
-

Active client->name; ?> by your license key to get professional support and automatic update from your WordPress dashboard.

-
- - -
-
- - - - - /> -
- -
-
- - show_active_license_info( $license ); - } - ?> -
-
- - -
- error = "Please add all information"; - return; - } - - if ( ! wp_verify_nonce( $form['_nonce'], $this->client->name ) ) { - $this->error = "You don't have permission to manage license."; - return; - } - - switch ( $form['_action'] ) { - case 'active': - $this->active_client_license( $form ); - break; - - case 'deactive': - $this->deactive_client_license( $form ); - break; - } - } - - /** - * Check license status on schedule - */ - public function check_license_status() { - $license = get_option( $this->option_key, null ); - - if ( isset( $license['key'] ) && ! empty( $license['key'] ) ) { - $response = $this->check( $license['key'] ); - - if ( isset( $response['success'] ) && $response['success'] ) { - $license['status'] = 'activate'; - $license['remaining'] = $response['remaining']; - $license['activation_limit'] = $response['activation_limit']; - $license['expiry_days'] = $response['expiry_days']; - $license['title'] = $response['title']; - $license['source_id'] = $response['source_identifier']; - $license['recurring'] = $response['recurring']; - } else { - $license['status'] = 'deactivate'; - $license['expiry_days'] = 0; - } - - update_option( $this->option_key, $license, false ); - } - } - - /** - * Check this is a valid license - */ - public function is_valid() { - if ( null !== $this->is_valid_licnese ) { - return $this->is_valid_licnese; - } - - $license = get_option( $this->option_key, null ); - if ( ! empty( $license['key'] ) && isset( $license['status'] ) && $license['status'] == 'activate' ) { - $this->is_valid_licnese = true; - } else { - $this->is_valid_licnese = false; - } - - return $this->is_valid_licnese; - } - - /** - * Check this is a valid license - */ - public function is_valid_by( $option, $value ) { - $license = get_option( $this->option_key, null ); - - if ( ! empty( $license['key'] ) && isset( $license['status'] ) && $license['status'] == 'activate' ) { - if ( isset( $license[ $option ] ) && $license[ $option ] == $value ) { - return true; - } - } - - return false; - } - - /** - * Styles for licenses page - */ - private function licenses_style() { - ?> - - -
-
-

Activation Remaining

- -

Unlimited

- -

- out of -

- -
-
-

Expires in

- 10 ? '' : 'occupied'; - echo '

' . $license['expiry_days'] . ' days

'; - } else { - echo '

Never

'; - } - ?> -
-
- error ) ) : - ?> -
-

error; ?>

-
- success ) ) : - ?> -
-

success; ?>

-
- '; - } - - /** - * Card header - */ - private function show_license_page_card_header() { - ?> -
- - - - - - Activate License -
- error = 'The license key field is required.'; - return; - } - - $license_key = sanitize_text_field( $form['license_key'] ); - $response = $this->activate( $license_key ); - - if ( ! $response['success'] ) { - $this->error = $response['error'] ? $response['error'] : 'Unknown error occurred.'; - return; - } - - $data = array( - 'key' => $license_key, - 'status' => 'activate', - 'remaining' => $response['remaining'], - 'activation_limit' => $response['activation_limit'], - 'expiry_days' => $response['expiry_days'], - 'title' => $response['title'], - 'source_id' => $response['source_identifier'], - 'recurring' => $response['recurring'], - ); - - update_option( $this->option_key, $data, false ); - - $this->success = 'License activated successfully.'; - } - - /** - * Deactive client license - */ - private function deactive_client_license( $form ) { - $license = get_option( $this->option_key, null ); - - if ( empty( $license['key'] ) ) { - $this->error = 'License key not found.'; - return; - } - - $response = $this->deactivate( $license['key'] ); - - $data = array( - 'key' => '', - 'status' => 'deactivate', - ); - - update_option( $this->option_key, $data, false ); - - if ( ! $response['success'] ) { - $this->error = $response['error'] ? $response['error'] : 'Unknown error occurred.'; - return; - } - - $this->success = 'License deactivated successfully.'; - } - - /** - * Add license menu page - */ - private function add_menu_page() { - add_menu_page( - $this->menu_args['page_title'], - $this->menu_args['menu_title'], - $this->menu_args['capability'], - $this->menu_args['menu_slug'], - array( $this, 'menu_output' ), - $this->menu_args['icon_url'], - $this->menu_args['position'] - ); - } - - /** - * Add submenu page - */ - private function add_submenu_page() { - add_submenu_page( - $this->menu_args['parent_slug'], - $this->menu_args['page_title'], - $this->menu_args['menu_title'], - $this->menu_args['capability'], - $this->menu_args['menu_slug'], - array( $this, 'menu_output' ), - $this->menu_args['position'] - ); - } - - /** - * Add submenu page - */ - private function add_options_page() { - add_options_page( - $this->menu_args['page_title'], - $this->menu_args['menu_title'], - $this->menu_args['capability'], - $this->menu_args['menu_slug'], - array( $this, 'menu_output' ), - $this->menu_args['position'] - ); - } - - /** - * Schedule daily sicense checker event - */ - public function schedule_cron_event() { - if ( ! wp_next_scheduled( $this->schedule_hook ) ) { - wp_schedule_event( time(), 'daily', $this->schedule_hook ); - - wp_schedule_single_event( time() + 20, $this->schedule_hook ); - } - } - - /** - * Clear any scheduled hook - */ - public function clear_scheduler() { - wp_clear_scheduled_hook( $this->schedule_hook ); - } - - /** - * Enable/Disable schedule - */ - private function run_schedule() { - switch ( $this->client->type ) { - case 'plugin': - register_activation_hook( $this->client->file, array( $this, 'schedule_cron_event' ) ); - register_deactivation_hook( $this->client->file, array( $this, 'clear_scheduler' ) ); - break; - - case 'theme': - add_action( 'after_switch_theme', array( $this, 'schedule_cron_event' ) ); - add_action( 'switch_theme', array( $this, 'clear_scheduler' ) ); - break; - } - } - - /** - * Form action URL - */ - private function formActionUrl() { - echo add_query_arg( - array( 'page' => $_GET['page'] ), - admin_url( basename( $_SERVER['SCRIPT_NAME'] ) ) - ); - } - - /** - * Get input license key - * @param $action - * @return $license - */ - private function get_input_license_value( $action, $license ) { - if ( 'active' == $action ) { - return isset( $license['key'] ) ? $license['key'] : ''; - } - - if ( 'deactive' == $action ) { - $key_length = strlen( $license['key'] ); - - return str_pad( - substr( $license['key'], 0, $key_length / 2 ), $key_length, '*' - ); - } - - return ''; - } - -} diff --git a/includes/library/appsero/Updater.php b/includes/library/appsero/Updater.php deleted file mode 100755 index 2c244e9..0000000 --- a/includes/library/appsero/Updater.php +++ /dev/null @@ -1,247 +0,0 @@ -client = $client; - $this->cache_key = 'appsero_' . md5( $this->client->slug ) . '_version_info'; - - // Run hooks. - if ( $this->client->type == 'plugin' ) { - $this->run_plugin_hooks(); - } elseif ( $this->client->type == 'theme' ) { - $this->run_theme_hooks(); - } - } - - /** - * Set up WordPress filter to hooks to get update. - * - * @return void - */ - public function run_plugin_hooks() { - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_plugin_update' ) ); - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); - } - - /** - * Set up WordPress filter to hooks to get update. - * - * @return void - */ - public function run_theme_hooks() { - add_filter( 'pre_set_site_transient_update_themes', array( $this, 'check_theme_update' ) ); - } - - /** - * Check for Update for this specific project - */ - public function check_plugin_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->client->basename ] ) ) { - return $transient_data; - } - - $version_info = $this->get_cached_version_info(); - - if ( false === $version_info ) { - $version_info = $this->get_project_latest_version(); - $this->set_cached_version_info( $version_info ); - } - - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { - - if ( version_compare( $this->client->project_version, $version_info->new_version, '<' ) ) { - unset( $version_info->sections ); - $transient_data->response[ $this->client->basename ] = $version_info; - } - - $transient_data->last_checked = time(); - $transient_data->checked[ $this->client->basename ] = $this->client->project_version; - } - - return $transient_data; - } - - /** - * Get version info from database - * - * @return Object or Boolean - */ - private function get_cached_version_info() { - - $value = get_transient( $this->cache_key ); - - if( ! $value && ! isset( $value->name ) ) { - return false; // Cache is expired - } - - // We need to turn the icons into an array - if ( isset( $value->icons ) ) { - $value->icons = (array) $value->icons; - } - - // We need to turn the banners into an array - if ( isset( $value->banners ) ) { - $value->banners = (array) $value->banners; - } - - if ( isset( $value->sections ) ) { - $value->sections = (array) $value->sections; - } - - return $value; - } - - /** - * Set version info to database - */ - private function set_cached_version_info( $value ) { - if ( ! $value ) { - return; - } - - set_transient( $this->cache_key, $value, 3 * HOUR_IN_SECONDS ); - } - - /** - * Get plugin info from Appsero - */ - private function get_project_latest_version() { - - $license_option_key = 'appsero_' . md5( $this->client->slug ) . '_manage_license'; - $license = get_option( $license_option_key, null ); - - $params = array( - 'version' => $this->client->project_version, - 'name' => $this->client->name, - 'slug' => $this->client->slug, - 'basename' => $this->client->basename, - 'license_key' => ! empty( $license ) && isset( $license['key'] ) ? $license['key'] : '', - ); - - $route = 'update/' . $this->client->hash . '/check'; - - $response = $this->client->send_request( $params, $route, true ); - - if ( is_wp_error( $response ) ) { - return false; - } - - $response = json_decode( wp_remote_retrieve_body( $response ) ); - - if ( ! isset( $response->slug ) ) { - return false; - } - - if ( isset( $response->icons ) ) { - $response->icons = (array) $response->icons; - } - - if ( isset( $response->banners ) ) { - $response->banners = (array) $response->banners; - } - - if ( isset( $response->sections ) ) { - $response->sections = (array) $response->sections; - } - - return $response; - } - - /** - * Updates information on the "View version x.x details" page with custom data. - * - * @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->client->slug ) ) { - return $data; - } - - $version_info = $this->get_cached_version_info(); - - if ( false === $version_info ) { - $version_info = $this->get_project_latest_version(); - $this->set_cached_version_info( $version_info ); - } - - return $version_info; - } - - /** - * Check theme upate - */ - public function check_theme_update( $transient_data ) { - global $pagenow; - - if ( ! is_object( $transient_data ) ) { - $transient_data = new \stdClass; - } - - if ( 'themes.php' == $pagenow && is_multisite() ) { - return $transient_data; - } - - if ( ! empty( $transient_data->response ) && ! empty( $transient_data->response[ $this->client->slug ] ) ) { - return $transient_data; - } - - $version_info = $this->get_cached_version_info(); - - if ( false === $version_info ) { - $version_info = $this->get_project_latest_version(); - $this->set_cached_version_info( $version_info ); - } - - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { - - if ( version_compare( $this->client->project_version, $version_info->new_version, '<' ) ) { - $transient_data->response[ $this->client->slug ] = (array) $version_info; - } - - $transient_data->last_checked = time(); - $transient_data->checked[ $this->client->slug ] = $this->client->project_version; - } - - return $transient_data; - } - -} diff --git a/weforms.php b/weforms.php index 2979aa3..9ed005f 100644 --- a/weforms.php +++ b/weforms.php @@ -99,8 +99,6 @@ public function __construct() { add_action( 'admin_init', [ $this, 'plugin_upgrades' ] ); add_action( 'plugins_loaded', [ $this, 'init_plugin' ] ); - - $this->init_appsero(); } /**