";
}
public function config_menu()
{
include_once TENWEB_VIEWS_DIR . "/configs.php";
}
public function set_products($reset = false)
{
$in_progress_key = TENWEB_PREFIX . '_setting_products_in_progress';
$setting_products_in_progress = get_site_transient($in_progress_key);
if ($setting_products_in_progress) {
// Do NOT allow other set products while one of them is in progress
return;
} else {
set_site_transient($in_progress_key, 1, TW_IN_PROGRESS_LOCK);
}
$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 . '_client_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 . '_client_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'];
delete_site_transient($in_progress_key);
}
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_migration_logs()
{
if (check_ajax_referer('wp_rest', 'tenweb_nonce', false)) {
Helper::flush_migration_log();
}
}
public function clear_cache()
{
if (check_ajax_referer('wp_rest', 'tenweb_nonce', false)) {
Helper::clear_cache();
}
}
public function save_configs()
{
if (check_ajax_referer('wp_rest', 'tenweb_nonce', false)) {
Helper::save_configs($_POST);
}
}
public function delete_banned_ip()
{
if (check_ajax_referer('wp_rest', 'tenweb_nonce', false)) {
if (isset($_POST['ips'])) {
Helper::delete_banned_ip($_POST['ips']);
}
}
}
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';
require_once TENWEB_INCLUDES_DIR . '/class-cache.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);
$domain_id = get_site_option(TENWEB_PREFIX . '_domain_id');
$url = TENWEB_DASHBOARD . '/websites?website_connected=' . $domain_id;
if (!empty($_GET['sign_up_from_free_plugin'])) {
$url .= '&from_free_plugin=1';
}
die('');
} else {
$errors = $this->class_login->get_errors();
$err_msg = (!empty($errors)) ? $errors['message'] : 'Something went wrong.';
update_site_option(TENWEB_PREFIX . '_connect_error', $err_msg);
}
}
if (is_multisite()) {
die('');
}
die('');
}
/**
* @param array $args [sign_up_from_free_plugin, client_email, name]
*
* @return mixed
*/
public function get_registration_link($args = [])
{
$return_url = get_admin_url() . 'admin.php';
if (is_multisite()) {
$return_url = network_admin_url() . 'admin.php';
}
$return_url_args = array('page' => 'tenweb_menu');
$register_url_args = array(
'site_url' => urlencode(get_site_url()),
'utm_source' => '10webplugin',
'utm_medium' => 'freeplugin',
'nonce' => wp_create_nonce('10web_register_url')
);
if (!empty($args)) {
$register_url_args = $register_url_args + $args;
$return_url_args = $return_url_args + $args;
}
$register_url_args['return_url'] = urlencode(add_query_arg($return_url_args, $return_url));
$plugin_from = get_site_option("tenweb_manager_installed");
if ($plugin_from !== false) {
$plugin_from = json_decode($plugin_from, true);
if (is_array($plugin_from) && reset($plugin_from) !== false) {
$register_url_args['plugin_id'] = reset($plugin_from);
if (isset($plugin_from["type"])) {
$register_url_args['utm_source'] = $plugin_from["type"];
}
}
}
// $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_migration_logs', array($this, 'clear_migration_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'));
add_action('wp_ajax_' . TENWEB_PREFIX . '_save_configs', array($this, 'save_configs'));
add_action('wp_ajax_' . TENWEB_PREFIX . '_delete_banned_ip', array($this, 'delete_banned_ip'));
}
public function multisite_notice()
{
?>
"Ten web manager does not support multisite yet."
You have logged in with 10web admin account using one time access
token.
tenweb_screen) {
return;
}
$site_info = Helper::get_site_info();
if ($site_info['other_data']['file_system']['config'] == false) {
$text = '10web manager plugin does not have filesystem permissions to intall, update and delete products. Please configure your file system connection from
config.php file. ';
$text .= 'More';
Helper::add_notices($text);
}
if (get_site_option(TENWEB_PREFIX . '_is_available') !== '1') {
$text = '10Web Manager plugin does not have file system permissions to install, update and delete products. You can download your purchased plugins here. In order to fix the permission issue, please contact our customer care team.';
Helper::add_notices($text);
}
$notices = Helper::get_notices();
foreach ($notices as $notice) {
echo $notice;
}
}
public function connection_notices()
{
$connect_error = get_site_option(TENWEB_PREFIX . '_connect_error');
$screen = get_current_screen();
echo '