activated_data = $activated_data = get_option( 'etheme_activated_data' ); $this->current_version = $theme_data->get('Version'); $this->theme_name = strtolower($theme_data->get('Name')); $this->api_url = apply_filters('etheme_protocol_url', ETHEME_API); $this->url = apply_filters('etheme_protocol_url', ETHEME_BASE_URL . 'import/demo/xstore/change-log.php'); $this->api_key = ( ! empty( $activated_data['api_key'] ) ) ? $activated_data['api_key'] : false; $this->is_subscription = ( isset($activated_data['item']) && isset($activated_data['item']['license']) && $activated_data['item']['license'] == '8theme-subscription' ); $this->is_new_deactivate = true; add_action('admin_init', array($this, 'dismiss_notices')); add_action('admin_notices', array($this, 'show_notices'), 50 ); add_action( 'wp_ajax_et_support_refresh', array($this, 'et_support_refresh') ); add_action('wp_ajax_etheme_deactivate_theme', array($this, 'deactivate')); add_action('wp_ajax_etheme_activate_theme', array($this, 'ajax_etheme_activate_theme')); add_action('wp_ajax_etheme_check_activation_data', array($this, 'check_activation_data')); if( ! etheme_is_activated() ) { #$this->activation_notice(); return; } if( $this->is_update_available() ) { if ( $this->major_update( 'both' ) ) add_action( 'admin_head', array( $this, 'major_update_holder' ) ); //$this->update_notice(); } add_action( 'switch_theme', array( $this, 'update_dismiss' ) ); add_action( 'current_screen', array( $this, 'api_results_init' ) ); if ($update_transient) { add_filter( 'site_transient_update_themes', array( $this, 'update_transient' ), 20, 2 ); add_filter( 'pre_set_site_transient_update_themes', array( $this, 'set_update_transient' ) ); //add_filter( 'themes_api', array(&$this, 'api_results'), 10, 3); } } public function api_results_init( $current_screen ) { if ( $current_screen->base !== 'woocommerce_page_wc-status' ) { add_filter( 'themes_api', array(&$this, 'api_results'), 10, 3); } } public function activation_page() { ?>
process_form(); ?>maskHalfOfStringFromEnd($purchase); ?> is_subscription): ?>
support_status($supported_until); ?> is_subscription): ?>process_form(); ?> ID; if( ! empty( $this->notices ) ) { foreach ($this->notices as $key => $notice) { if ( ! get_user_meta($user_id, $this->ignore_key . $key) ) { echo ''; } } } } public function dismiss_notices() { global $current_user; $user_id = $current_user->ID; if ( isset( $_GET['et-hide-notice'] ) && isset( $_GET['_et_notice_nonce'] ) ) { if ( ! wp_verify_nonce( $_GET['_et_notice_nonce'], 'etheme_hide_notices_nonce' ) ) { return; } add_user_meta($user_id, $this->ignore_key . '_' . $_GET['et-hide-notice'], 'true', true); } } public function setup_notice() { $this->notices['_setup'] = array( 'message' => '
Welcome to XStore – You‘re almost ready to start selling :)
Run the Setup Wizard Skip Setup
' ); } public function activation_notice() { $this->notices['_activation'] = array( 'message' => 'You need to activate XStore
' ); } public function update_notice() { if( isset( $_GET['_wpnonce'] )) return; $this->notices['_update'] = array( 'message' => 'There is a new version of ' . ETHEME_THEME_NAME . ' Theme available.
' . $this->major_update( 'msg-b' ) . ' ', ); } private function api_get_version() { $raw_response = wp_remote_get($this->api_url . '?theme=' . ETHEME_THEME_SLUG); if (!is_wp_error($raw_response) && ($raw_response['response']['code'] == 200)) { $response = json_decode($raw_response['body'], true); if(!empty($response['version'])) $this->new_version = $response['version']; } } public function update_dismiss() { global $current_user; #$user_id = $current_user->ID; #delete_user_meta($user_id, $this->ignore_key); } public function update_transient($value, $transient) { // if(isset($_GET['theme_force_check']) && $_GET['theme_force_check'] == '1') return false; if(isset($_GET['force-check']) && $_GET['force-check'] == '1') return false; return $value; } public function set_update_transient($transient) { $xstore_branding_settings = get_option( 'xstore_white_label_branding_settings', array() ); if ( count($xstore_branding_settings) && isset($xstore_branding_settings['control_panel']) && isset($xstore_branding_settings['control_panel']['hide_updates']) && $xstore_branding_settings['control_panel']['hide_updates'] == 'on' ){ return $transient; } $this->check_for_update(); if (is_null($transient)) { $transient = new stdClass(); } if( isset( $transient ) && ! isset( $transient->response ) ) { $transient->response = array(); } if( ! empty( $this->information ) && is_object( $this->information ) ) { if( $this->is_update_available() ) { $transient->response[ $this->theme_name ] = json_decode( json_encode( $this->information ), true ); } } remove_filter( 'site_transient_update_themes', array( $this, 'update_transient' ), 20, 2 ); return $transient; } public function api_results($result, $action, $args) { $this->check_for_update(); if( isset( $args->slug ) && $args->slug == $this->theme_name && $action == 'theme_information') { if( is_object( $this->information ) && ! empty( $this->information ) ) { $result = $this->information; } } return $result; } protected function check_for_update() { $force = false; // if( isset( $_GET['theme_force_check'] ) && $_GET['theme_force_check'] == '1') $force = true; if( isset( $_GET['force-check'] ) && $_GET['force-check'] == '1') $force = true; // Get data if( empty( $this->information ) ) { $version_information = get_option( 'xstore-update-info', false ); $version_information = $version_information ? $version_information : new stdClass; $this->information = is_object( $version_information ) ? $version_information : maybe_unserialize( $version_information ); } $last_check = get_option( 'xstore-update-time' ); if( $last_check == false ){ update_option( 'xstore-update-time', time(), 'no' ); } if( time() - $last_check > 172800 || $force || $last_check == false ){ $version_information = $this->api_info(); if( $version_information ) { update_option( 'xstore-update-time', time(), 'no' ); $this->information = $version_information; $this->information->checked = time(); $this->information->url = $this->url; $this->information->package = $this->download_url(); } } // Save results update_option( 'xstore-update-info', $this->information ); } public function api_info() { $version_information = new stdClass; $response = wp_remote_get( $this->api_url . 'info/' . $this->theme_name . '?plugin=et-core' ); $response_code = wp_remote_retrieve_response_code( $response ); if( $response_code != '200' ) { return false; } $response = json_decode( wp_remote_retrieve_body( $response ) ); if( ! isset( $response ) || ! isset( $response->new_version ) || empty( $response->new_version ) ) { return $version_information; } $version_information = $response; return $version_information; } public function is_update_available() { return version_compare( $this->current_version, $this->release_version(), '<' ); } public function download_url() { $activated_data = get_option( 'etheme_activated_data' ); $purchase = ( isset( $activated_data['purchase'] ) && ! empty( $activated_data['purchase'] ) ) ? $activated_data['purchase'] : ''; $url = $this->api_url . 'files/get/' . $this->theme_name . '.zip?token=' . $this->api_key . '&code=' . $purchase; return apply_filters( 'etheme_theme_url', $url ); } public function release_version() { $this->check_for_update(); if ( isset( $this->information ) && isset( $this->information->new_version ) ) { return $this->information->new_version; } } public function activate( $purchase, $args ) { $data = array( 'api_key' => $args['token'], 'theme' => ETHEME_PREFIX, 'purchase' => $purchase, ); foreach ( $args as $key => $value ) { $data['item'][$key] = $value; } update_option( 'envato_purchase_code_15780546', $purchase ); update_option( 'etheme_activated_data', maybe_unserialize( $data ) ); update_option( 'etheme_is_activated', true ); } public function process_form() { if ( isset( $_POST['xstore-purchase-code'] ) && ! empty( $_POST['xstore-purchase-code'] ) && ! isset($_POST['form-license']) && empty( $_POST['form-license'] ) ){ $this->is_license = false; } if( isset( $_POST['xstore-purchase-code'] ) && ! empty( $_POST['xstore-purchase-code'] ) && isset($_POST['form-license']) && ! empty( $_POST['form-license'] ) ) { $code = trim( $_POST['purchase-code'] ); if( empty( $code ) ) { echo ''; return; } $response = wp_remote_get( $this->api_url . 'activate/' . $code . '?envato_id='. $this->theme_id .'&domain=' .$this->domain() ); if ( ! $response ) { echo ''; return; } $response_code = wp_remote_retrieve_response_code( $response ); if( $response_code != '200' ) { if( is_wp_error( $response ) ) { echo ''; } if (!$response_code){ echo ''; return; } echo ''; return; } $data = json_decode( wp_remote_retrieve_body($response), true ); if( isset( $data['error'] ) ) { echo ''; return; } if ( ! isset($data['verified']) ){ echo ''; return; } if( ! $data['verified'] ) { echo ''; return; } $this->activate( $code, $data ); $svg_key_icon = ''; echo ''.$svg_key_icon.' ' . $this->maskHalfOfStringFromEnd($code) . '
' . $message . '
'; break; case 'ver': $return = $release; break; case 'both': $return['msg'] = $message; $return['ver'] = $release; break; default: $return = $release; break; } return $return; } public function major_update_holder() { $major_update = $this->major_update( 'both' ); echo ''; } public function et_support_refresh(){ $activated_data = get_option( 'etheme_activated_data' ); $purchase = ( isset( $activated_data['purchase'] ) && ! empty( $activated_data['purchase'] ) ) ? $activated_data['purchase'] : ''; if (!$purchase){ wp_send_json( array( 'status' => 'error', 'msg' => __('Invalid purchase code', 'xstore') ) ); } $remote_response = wp_remote_get( $this->api_url . 'support/' . $purchase . '?envato_id='. $this->theme_id ); $response_code = wp_remote_retrieve_response_code( $remote_response ); if( $response_code != '200' ) { wp_send_json( array( 'status' => 'error', 'msg' => __('API request call error. Can not connect to 8theme.com', 'xstore') ) ); } $remote_response = json_decode( wp_remote_retrieve_body( $remote_response ) ); if (isset($remote_response->error)){ wp_send_json( array( 'status' => 'error', 'msg' => $remote_response->error ) ); } $activated_data['item']['supported_until'] = $remote_response->supported_until; update_option('etheme_activated_data', $activated_data); wp_send_json( array('status' => 'success', 'msg' => __('Successful updated', 'xstore'), 'html' => $this->support_status($remote_response->supported_until, false) ) ); } public function get_support_day_left(){ $activated_data = get_option( 'etheme_activated_data' ); $supported_until = ( isset( $activated_data['item'] ) && isset( $activated_data['item']['supported_until'] ) && ! empty( $activated_data['item']['supported_until'] ) ) ? $activated_data['item']['supported_until'] : ''; $daysleft = round(((( strtotime($supported_until) - time() )/24)/60)/60); return $daysleft; } public function get_support_status(){ if ( $this->is_subscription && isset($this->activated_data['item']) && isset($this->activated_data['item']['subscription_type']) && $this->activated_data['item']['subscription_type'] == 'lifetime'){ return 'lifetime'; } $daysleft = $this->get_support_day_left(); if ($daysleft <= 30 && $daysleft > 0) { $status = 'expire-soon'; }else if ($daysleft <= 0) { $status = 'expired'; } else { $status = 'active'; } return $status; } public function support_status($supported_until, $echo = true) { $support = $this->get_support_status(); $daysleft = $this->get_support_day_left(); $left = $daysleft . ' ' . _nx( 'day left', 'days left', $daysleft, 'Support day/days left', 'xstore' ); $icon = ''; $renew = __('You can renew your support by clicking ', 'xstore') . '' . __('here', 'xstore') . ''; $renew .= '