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() { ?>

Updates', 'xstore'); ?>

process_form(); ?>

maskHalfOfStringFromEnd($purchase); ?> is_subscription): ?>

support_status($supported_until); ?> is_subscription): ?>

process_form(); ?>

is_license ) echo 'style="color: #ff0000;"'; ?> > Envato's license policy.

ID; if( ! empty( $this->notices ) ) { foreach ($this->notices as $key => $notice) { if ( ! get_user_meta($user_id, $this->ignore_key . $key) ) { echo '
' . $notice['message'] . '
'; } } } } 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

' ); } public function activation_notice() { $this->notices['_activation'] = array( 'message' => '

You need to activate XStore

Activate theme

' ); } 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' ) . '

Update now

', ); } 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 '

The code is missing, here you have more information where you can find it

'; return; } $response = wp_remote_get( $this->api_url . 'activate/' . $code . '?envato_id='. $this->theme_id .'&domain=' .$this->domain() ); if ( ! $response ) { echo '

There was an error with the API request call; it was unable to connect to 8theme.com.

'; return; } $response_code = wp_remote_retrieve_response_code( $response ); if( $response_code != '200' ) { if( is_wp_error( $response ) ) { echo '

' . $response->get_error_message() . '

'; } if (!$response_code){ echo '

There was an error with the API request call. This is a common problem caused by an SSL certificate. Please check it here. If your certificate does not exist or has errors, please contact your server provider.

'; return; } echo '

API request call error. Response code - ' . $response_code . '

'; return; } $data = json_decode( wp_remote_retrieve_body($response), true ); if( isset( $data['error'] ) ) { echo '

' . $data['error'] . '

'; return; } if ( ! isset($data['verified']) ){ echo '

Sorry, I cannot get the API response..

'; return; } if( ! $data['verified'] ) { echo '

Sorry, the code is incorrect. Please try again.

'; return; } $this->activate( $code, $data ); $svg_key_icon = ' '; echo '

'.$svg_key_icon.' ' . $this->maskHalfOfStringFromEnd($code) . '

' . esc_html__( 'Unregister', 'xstore' ) . '

' . esc_html__('One standard license is valid only for 1 website. Running multiple websites on a single license is a copyright violation. When moving a site from one domain to another please deactivate the theme first.', 'xstore') . '

'; sleep(2); // if ( !class_exists('ETheme_Import') ) // wp_safe_redirect(admin_url( 'admin.php?page=et-panel-welcome' )); // else // wp_safe_redirect(admin_url( 'admin.php?page=et-panel-demos' )); wp_safe_redirect(admin_url( 'admin.php?page=et-panel-demos&after_activate=true&et_clear_plugins_transient' )); } } public function maskHalfOfStringFromEnd($str) { $halfLength = floor(strlen($str) / 2); $startUnmaskedIndex = strlen($str) - $halfLength; $maskedPart = str_repeat('*', $halfLength); $unmaskedPart = substr($str, 0, $startUnmaskedIndex); return $unmaskedPart . $maskedPart; } public function domain() { $domain = get_option('siteurl'); //or home $domain = str_replace('http://', '', $domain); $domain = str_replace('https://', '', $domain); $domain = str_replace('www', '', $domain); //add the . after the www if you don't want it return urlencode($domain); } public function major_update( $type = 'msg' ) { // ! major update versions $versions = array( '4.0', '4.18', '5.0', '6.0', '7.0', '8.0', '9.0', '10.0', '11.0', '12.0', '13.0', '14.0', '15.0' ); // ! current release version $release = $this->release_version(); if ( ! in_array( $release , $versions ) ){ return; } $message = esc_html__( 'This is major theme update! Please, do the backup of your files and database before proceed to update. If you use WooCommerce plugin make sure that its latest version.', 'xstore' ); switch ( $type ) { case 'msg': $return = $message; break; case 'msg-b': $return = '

' . $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 .= '
' . sprintf(__('To learn how to renew your support, follow this %s', 'xstore'), '' . __('link', 'xstore') . ''); if ($support == 'expire-soon') { $status = 'et-notice'; $left .= $icon . '
' . $renew; }else if ($support == 'expired') { $status = 'et-warning'; $left = __('Expired', 'xstore'); $left .= $icon . '
' . $renew; } else if($support == 'lifetime'){ $status = 'et-notice'; $left = 'lifetime' . $icon; } else { $status = 'et-notice'; $left .= $icon; } if ($echo){ printf( '

%s %s

', $status, __('Support status:', 'xstore'), $left ); } else { return sprintf( '

%s %s

', $status, __('Support status:', 'xstore'), $left ); } } public function deactivate_action(){ if ( $this->api_url ) { if ($this->is_new_deactivate){ $remote_response = wp_remote_get( $this->api_url . 'xstore/deactivate/' . $this->api_key . '?is_test=1/&domain=' . $this->domain() ); // write_log($this->api_url . 'deactivate/' . $this->api_key . 'is_test=1/?domain=' . $this->domain()); $code = wp_remote_retrieve_response_code( $remote_response ); $response = wp_remote_retrieve_body( $remote_response ); if ($code == 200 && $response){ $response = json_decode($response, true); if ($response['status'] == 'deleted' || $response['status'] == 'not_found'){ $this->update_options(); wp_send_json( array('status' => 'deleted') ); } wp_send_json( array('status' => $response['status']) ); } wp_send_json( array('status' => 'active') ); } $remote_response = wp_remote_get( $this->api_url . 'xstore/deactivate/' . $this->api_key . '?domain=' . $this->domain() ); // old deactivation type // $remote_response = wp_remote_get( $this->api_url . 'deactivate/' . $this->api_key . '?domain=' . $this->domain() ); //wp_remote_retrieve_response_code( $remote_response ); //wp_remote_retrieve_body( $remote_response ); } } public function update_options(){ update_option( 'etheme_activated_data', maybe_unserialize( array( 'api_key' => 0, 'theme' => 0, 'purchase' => 0, ) ) ); update_option( 'envato_purchase_code_15780546', '' ); } public function deactivate() { check_ajax_referer('etheme_theme-actions', 'security'); if (! current_user_can( 'manage_options' )){ wp_send_json( array('status' => 'error') ); } $this->deactivate_action(); $this->update_options(); delete_transient('etheme_plugins_info'); wp_send_json( array('status' => 'deleted') ); } public function ajax_etheme_activate_theme(){ check_ajax_referer('etheme_theme-actions', 'security'); if (! current_user_can( 'manage_options' )){ wp_send_json( array('status' => 'error') ); } $code = trim( $_POST['purchase_code'] ); $this->activate_theme($code); } public function check_activation_data(){ check_ajax_referer('etheme_theme-actions', 'security'); if (! current_user_can( 'manage_options' )){ wp_send_json( array('status' => 'error') ); } $code = trim( $_POST['purchase_code'] ); $this->activate_theme($code, 'check'); } public function activate_theme($code, $type='activate'){ $_response = array( 'status' => 'error', 'msg' => 'code 10' ); if( empty( $code ) ) { $_response['msg'] = '

The code is missing, here you have more information where you can find it

'; wp_send_json( $_response ); } $url = $this->api_url . 'xstore/activate/' . $code . '?envato_id='. $this->theme_id .'&domain=' .$this->domain(); if ($type=='check'){ $url .= '&is_check=1'; } add_filter( 'http_request_args', 'et_increase_http_request_timeout', 10, 2 ); $response = wp_remote_get( $url ); remove_filter( 'http_request_args', 'et_increase_http_request_timeout', 10, 2 ); if ( ! $response ) { $_response['msg'] = '

There was an error with the API request call; it was unable to connect to 8theme.com.

'; wp_send_json( $_response ); } $response_code = wp_remote_retrieve_response_code( $response ); if( $response_code != '200' ) { if( is_wp_error( $response ) ) { $_response['msg'] = '

' . $response->get_error_message() . '

'; } if (!$response_code){ $_response['msg'] = '

There was an error with the API request call. This is a common problem caused by an SSL certificate. Please check it here. If your certificate does not exist or has errors, please contact your server provider.

'; wp_send_json( $_response ); } $_response['msg'] = '

API request call error. Response code - ' . $response_code . '

'; wp_send_json( $_response ); } $data = json_decode( wp_remote_retrieve_body($response), true ); if( isset( $data['error'] ) ) { $_response['msg'] = '

' . $data['error'] . '

'; wp_send_json( $_response ); } if ( ! isset($data['verified']) ){ $_response['msg'] = '

Sorry, I cannot get the API response..

'; wp_send_json( $_response ); } if( ! $data['verified'] ) { $_response['msg'] = '

Sorry, the code is incorrect. Please try again.

'; wp_send_json( $_response ); } if ($type=='activate'){ $this->activate( $code, $data ); } $_response = array( 'status' => 'success', 'msg' => 'code 11', 'type' => (isset($data['type']))?$data['type']:'' ); // if (isset($data['type'])){ // $_response['type'] => // } if (isset($data['notice'])){ $_response['notice'] = array( 'notice' => $data['notice'], 'type' => $data['type'], 'max_domains' => $data['max_domains'], 'actve_domains' => $data['actve_domains'] ); } wp_send_json( $_response ); } } if(!function_exists('etheme_check_theme_update')) { add_action('init', 'etheme_check_theme_update'); function etheme_check_theme_update() { new ETheme_Version_Check(); } }