deactivation_popup(); if(is_multisite() === true) { add_action('network_admin_notices', array($this, 'multisite_notice')); return; } $this->init(); $this->login_wp_user(); if(!empty($_GET['nonce']) && wp_verify_nonce($_GET['nonce'], '10web_register_url')) { add_action('in_admin_header', array($this, 'tenweb_connection')); } add_action('init', array($this, 'register_hooks')); add_action('admin_head', array($this, 'admin_head')); add_action('wp_ajax_' . TENWEB_PREFIX . '_dashboard_login', array($this, 'login_user')); add_action('tenweb_send_site_state', array($this, 'tenweb_send_site_state')); } public function admin_head(){ if($this->user_logged_in) { echo ''; } echo ''; } private function init(){ /*update version*/ if(TENWEB_VERSION != get_option(TENWEB_PREFIX . '_version')) { $error_msgs = tenweb_activate("0"); foreach($error_msgs as $error_msg) { Helper::add_notices($error_msg); } } $this->load_classes(); $this->class_login = Login::get_instance(); $this->user_logged_in = $this->class_login->check_logged_in(); if($this->user_logged_in) { User::get_instance(); } } private function login_wp_user(){ if(!empty($_GET['tenweb_wp_login_token']) && is_user_logged_in() === false) { User::get_instance()->login(); } } public function register_hooks(){ if($this->user_logged_in) { $this->set_products(); } add_action('rest_api_init', array($this, 'init_rest_api')); if(is_multisite() === true) { add_action('network_admin_menu', array($this, 'add_menu'), 24); } else { add_action('admin_menu', array($this, 'add_menu'), 24); } add_action('current_screen', array($this, 'is_tenweb_screen'));//for including login for styles add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); add_action('admin_init', array($this, 'check_debug_mode')); add_filter('http_request_args', array($this, 'add_request_timeout'), 2, 2); if(get_option(TENWEB_PREFIX . '_connect_error') !== false){ add_action('admin_notices', array($this, 'connection_notices')); } if($this->user_logged_in && is_admin()) { if(get_option(TENWEB_PREFIX . '_activated') !== false) { $this->send_availability_request(); } if(is_multisite() === true) { add_action('network_admin_notices', array($this, 'admin_notices')); } else { add_action('admin_notices', array($this, 'admin_notices')); } if(User::get_instance()->tenweb_user_logged_in()) { add_action('admin_footer', array($this, 'tenweb_user_logged_in_notice')); } add_action('current_screen', array($this, 'check_site_state')); add_action('deleted_plugin', array($this, 'check_site_state_after_action'));//todo add_action('tenweb_check_site_state_after_action', array($this, 'tenweb_check_site_state_after_action')); $this->user_info = Helper::get_tenweb_user_info(); $this->user_agreements = Helper::get_user_agreements_info(); $this->add_paid_products_update_msg(); } add_filter('site_transient_update_plugins', array($this, 'remove_plugins_from_updates'), 1); add_filter('site_transient_update_themes', array($this, 'remove_themes_from_updates'), 1); } public function check_site_state(){ $screen = get_current_screen(); $other_pages = array( "plugins", "plugins-network", "plugin-install", "themes", "themes-network", "options-general", "plugin-editor", "theme-editor", ); if($this->tenweb_screen || in_array($screen->id, $other_pages)) { Helper::check_site_state(); }else if(isset($_GET['page']) && ($_GET['page'] == 'WDD_plugins' || $_GET['page'] == 'WDD_themes' || $_GET['page'] == 'WDD_addons')){ Helper::check_site_state(); } } public function check_site_state_after_action(){ wp_cache_delete('plugins', 'plugins'); $this->set_products(); Helper::check_site_state(); } public function tenweb_check_site_state_after_action(){ wp_cache_delete('plugins', 'plugins'); wp_clean_themes_cache(false); $this->set_products(); Helper::check_site_state(); } public function admin_enqueue_scripts(){ /*enqueue scripts and styles only on our page*/ if($this->tenweb_screen == false) { return; } //$rest_route = get_rest_url() . TENWEB_REST_NAMESPACE . '/action'; $rest_route = add_query_arg(array( 'rest_route' => '/'.TENWEB_REST_NAMESPACE . '/action' ), get_home_url()."/"); wp_enqueue_script('player_api','https://www.youtube.com/player_api', array(), TENWEB_VERSION); wp_register_script(TENWEB_PREFIX . '_scripts_main', TENWEB_URL . '/assets/js/main.js', array(), TENWEB_VERSION); wp_enqueue_script(TENWEB_PREFIX . '_scripts_main'); wp_localize_script(TENWEB_PREFIX . '_scripts_main', TENWEB_PREFIX, array( 'ajaxurl' => admin_url('admin-ajax.php'), 'ajaxnonce' => wp_create_nonce('wp_rest'), 'plugin_url' => TENWEB_URL, 'action_endpoint' => $rest_route )); wp_register_style(TENWEB_PREFIX . '_styles_main', TENWEB_URL . '/assets/css/main.css', array(), TENWEB_VERSION); wp_enqueue_style(TENWEB_PREFIX . '_styles_main'); //enqueue scripts and styles } public function add_menu(){ $this->menu_ids[] = add_menu_page( __('10WEB Manager', TENWEB_LANG), __('10WEB Manager', TENWEB_LANG), 'manage_options', TENWEB_PREFIX . '_menu', array($this, 'display_products'), TENWEB_URL_IMG . '/manager-logo.png', 4 ); $this->menu_ids[] = add_submenu_page( TENWEB_PREFIX . '_menu', __('10WEB Products', TENWEB_LANG), __('10WEB Products', TENWEB_LANG), 'manage_options', TENWEB_PREFIX . '_menu', array($this, 'display_products') ); $debug_mode = get_site_option(TENWEB_PREFIX . '_debug_mode'); if($debug_mode == '1') { $this->menu_ids[] = add_submenu_page( TENWEB_PREFIX . '_menu', __('10WEB Logs', TENWEB_LANG), __('10WEB Logs', TENWEB_LANG), 'manage_options', TENWEB_PREFIX . '_error_logs', array($this, 'error_logs_menu') ); } if(is_multisite()) { foreach($this->menu_ids as $key => $menu_id) { $this->menu_ids[$key] = $menu_id . '-network'; } } } public function display_products(){ $user_name = (isset($this->user_info['name'])) ? $this->user_info['name'] : null; /*Self update notice*/ if($this->class_login->check_logged_in()) { $manager = self::get_product_by('slug', '10web-manager', 'plugin', 'installed'); if(!is_null($manager) && $manager->has_update()) { self::manager_update($manager->id); } } if($this->class_login->check_logged_in()) { include_once TENWEB_VIEWS_DIR . '/products-menu.php'; }else{ $registration_link = $this->get_registration_link(); if(isset($_GET["login"]) && $_GET["login"] == "1") { include_once TENWEB_VIEWS_DIR . '/login-menu.php'; } else { include_once TENWEB_VIEWS_DIR . '/tenweb-menu.php'; } } // $domain_id = get_site_option(TENWEB_PREFIX . '_domain_id'); // if($domain_id !== false){ // echo ''; // } } public function error_logs_menu(){ $logs = array_reverse(Helper::get_error_logs()); $time_zone = date_default_timezone_get(); include_once TENWEB_VIEWS_DIR . "/error-logs-menu.php"; } public function set_products($reset = false){ $plugins = get_site_option(TENWEB_PREFIX . '_plugins_list'); $themes = get_site_option(TENWEB_PREFIX . '_themes_list'); $addons = get_site_option(TENWEB_PREFIX . '_addons_list'); $transient = get_site_transient(TENWEB_PREFIX . '_user_products_transient'); if($transient === false || $reset === true) { $api = Api::get_instance(); $products = $api->get_products(); if(!(empty($products['plugins']) && empty($products['themes']) && empty($products['addons']))) { $plugins = $products['plugins']; $themes = $products['themes']; $addons = $products['addons']; update_site_option(TENWEB_PREFIX . '_plugins_list', $plugins); update_site_option(TENWEB_PREFIX . '_themes_list', $themes); update_site_option(TENWEB_PREFIX . '_addons_list', $addons); Helper::calc_request_block('user_products', true); $expiration = Helper::get_expiration('user_products'); $expiration = $expiration['expiration']; } else { $block_count = Helper::calc_request_block('user_products'); $expiration = Helper::get_expiration('user_products'); $expiration = $expiration['block_time'] * $block_count; } set_site_transient(TENWEB_PREFIX . '_user_products_transient', '1', $expiration); } //if first api call failed $plugins = (!is_array($plugins)) ? array() : $plugins; $themes = (!is_array($themes)) ? array() : $themes; $addons = (!is_array($addons)) ? array() : $addons; self::$products_raw_data = array('plugins' => $plugins, 'themes' => $themes, 'addons' => $addons); $products_objects = Helper::get_products_objects($plugins, $themes, $addons); self::$plugins = $products_objects['plugins']; self::$themes = $products_objects['themes']; self::$addons = $products_objects['addons']; } public function remove_plugins_from_updates($plugins){ if(isset($GLOBALS['tenweb_update_process']) && $GLOBALS['tenweb_update_process'] == true) { return $plugins; } if(empty($plugins) || !is_object($plugins) || empty($plugins->response)) { return $plugins; } if(empty(self::$plugins['installed_products'])) { return $plugins; } foreach(self::$plugins['installed_products'] as $installed_product) { $state = $installed_product->get_state(); if($state->is_paid == false) { continue; } $wp_slug = $installed_product->get_wp_slug(); if(isset($plugins->response[$wp_slug])) { unset($plugins->response[$wp_slug]); } } return $plugins; } public function remove_themes_from_updates($themes){ if(isset($GLOBALS['tenweb_update_process']) && $GLOBALS['tenweb_update_process'] == true) { return $themes; } if(empty($themes) || !is_object($themes) || empty($themes->response)) { return $themes; } if(empty(self::$themes['installed_products'])) { return $themes; } foreach(self::$themes['installed_products'] as $installed_product) { $state = $installed_product->get_state(); if($state->is_paid == false) { continue; } $wp_slug = $installed_product->slug; if(isset($themes->response[$wp_slug])) { unset($themes->response[$wp_slug]); } } return $themes; } public function get_products_raw_data(){ return self::$products_raw_data; } public function is_tenweb_screen(){ $screen = get_current_screen(); $this->tenweb_screen = (!($screen == null || !in_array($screen->id, $this->menu_ids))); } public function init_rest_api(){ require_once TENWEB_INCLUDES_DIR . '/class-rest-api.php'; RestApi::get_instance(); } public function clear_logs(){ if(check_ajax_referer('wp_rest', 'tenweb_nonce', false)) { delete_site_transient(TENWEB_PREFIX . '_error_logs'); } } public function clear_cache(){ if(check_ajax_referer('wp_rest', 'tenweb_nonce', false)) { Helper::clear_cache(); } } public function check_curl(){ if(check_ajax_referer('wp_rest', 'tenweb_nonce', false)) { $urls = array( 'https://www.google.com/', 'https://core.10web.io/', 'https://manager.10web.io/', 'https://optimizer.10web.io/', 'https://backup.10web.io/', 'https://seo.10web.io/' ); $data = array(); foreach($urls as $url) { $response = wp_remote_get($url); if(is_wp_error($response)) { $data[] = array('success' => false, 'url' => $url, 'error_msg' => $response->get_error_message()); } else { $data[] = array('success' => true, 'url' => $url, 'error_msg' => ""); } } die(json_encode($data)); } } public function login_user(){ if(!check_ajax_referer('tenweb_login_nonce', 'tenweb_nonce', false)) { $error = array( 'error' => 'nonce_error', 'message' => 'Wrong nonce.' ); die(json_encode($error)); } $data = $this->class_login->login(); if($this->class_login->check_logged_in()) { Helper::get_tenweb_user_info(true); Helper::get_user_agreements_info(true); } else { die(json_encode($this->class_login->get_errors())); } } private function load_classes(){ include_once TENWEB_INCLUDES_DIR . '/class-api.php'; include_once TENWEB_INCLUDES_DIR . '/product-state.php'; include_once TENWEB_INCLUDES_DIR . '/class-user.php'; include_once TENWEB_INCLUDES_DIR . '/class-login.php'; include_once TENWEB_INCLUDES_DIR . '/class-product.php'; include_once TENWEB_INCLUDES_DIR . '/interface-product-actions.php'; include_once TENWEB_INCLUDES_DIR . '/class-installed-plugin.php'; include_once TENWEB_INCLUDES_DIR . '/class-installed-theme.php'; include_once TENWEB_INCLUDES_DIR . '/class-migration-run.php'; } private function send_availability_request(){ delete_option(TENWEB_PREFIX . '_activated'); $api = Api::get_instance(); if($api->availability_request() === true) { delete_site_transient(TENWEB_PREFIX . '_send_states_transient'); } } public function tenweb_connection(){ include_once 'views/connect-popup.php'; $this->register_from_dashboard(); } private function register_from_dashboard(){ if(!empty($_GET['email']) && !empty($_GET['token'])) { $email = sanitize_email($_GET['email']); $token = sanitize_text_field($_GET['token']); $pwd = md5($token); if($this->class_login->login($email, $pwd, $token) == true && $this->class_login->check_logged_in()) { Helper::get_tenweb_user_info(true); Helper::get_user_agreements_info(true); die(''); } else { $errors = $this->class_login->get_errors(); $err_msg = (!empty($errors)) ? $errors['message'] : 'Something went wrong.'; update_option(TENWEB_PREFIX . '_connect_error', $err_msg); } } die(''); } private function get_registration_link(){ $register_url_args = array( 'site_url' => urlencode(get_site_url()), 'return_url' => urlencode(get_admin_url() . 'admin.php?page=tenweb_menu'), 'email' => '', 'first_name' => '', 'last_name' => '', 'utm_source' => 'freeplugin', 'utm_medium' => '10webplugin', 'nonce' => wp_create_nonce('10web_register_url') ); // $user = wp_get_current_user(); // if(isset($user->data->ID)) { // $register_url_args['email'] = $user->data->user_email; // $register_url_args['first_name'] = get_user_meta($user->data->ID, 'first_name', true); // $register_url_args['last_name'] = get_user_meta($user->data->ID, 'last_name', true); // } $url = add_query_arg($register_url_args, TENWEB_DASHBOARD . '/sign-up/'); return $url; } public function check_debug_mode(){ if(isset($_GET['tenweb_debug'])) { if($_GET['tenweb_debug'] == '1') { update_site_option(TENWEB_PREFIX . '_debug_mode', '1'); } else { delete_site_option(TENWEB_PREFIX . '_debug_mode'); } } add_action('wp_ajax_' . TENWEB_PREFIX . '_clear_logs', array($this, 'clear_logs')); add_action('wp_ajax_' . TENWEB_PREFIX . '_clear_cache', array($this, 'clear_cache')); add_action('wp_ajax_' . TENWEB_PREFIX . '_check_curl', array($this, 'check_curl')); } public function multisite_notice(){ ?>
"Ten web manager does not support multisite yet."
' . $connect_error . '
' . __("New version of 10WEB Manager is available!", TENWEB_LANG) . '
' . __("Please update now", TENWEB_LANG) . ''; $html .= '