[ 'POST_ID' => 'Post ID', 'POST_TITLE' => 'Post title', 'POST_CATEGORY' => 'Post category', 'POST_FEATURED_IMAGE' => 'Post Featured image', 'POST_EXCERPT' => 'Post excerpt', 'POST_DATE' => 'Post date', 'POST_TIME' => 'Post time', 'POST_COMMENTS_NUMBER' => 'Number of comments' ], 'Archive' => [ 'ARCHIVE_ID' => 'Archive ID', 'ARCHIVE_TITLE' => 'Archive title' ], 'Author' => [ 'AUTHOR_ID' => 'Author ID', 'AUTHOR_FIRST_NAME' => 'Author first name', 'AUTHOR_LAST_NAME' => 'Author last name', 'AUTHOR_DISPLAY_NAME' => 'Author display name', 'AUTHOR_EMAIL' => 'Author e-mail' ] ]; public function __construct() { $this->library_info = array_filter(get_option('adv_vis_ele_library_info', [])); $this->library_needs_update = false; $this->installed_elements = get_option('adv_vis_ele_installed_elements', []); $this->library_version = get_option('adv_vis_ele_library_version', '1.0.0'); // WooCommerce dynamic settings array if (class_exists('woocommerce')) { Adv_Vis_Ele_Library::$dynamic_settings['WooCommerce'] = [ 'WOO_PRODUCT_SKU' => 'Product SKU', 'WOO_PRODUCT_IMAGE' => 'Product image', 'WOO_PRODUCT_SHORT_DESCRIPTION' => 'Product short description', 'WOO_PRODUCT_LONG_DESCRIPTION' => 'Product long description', 'WOO_PRODUCT_REGULAR_PRICE' => 'Product regular price', 'WOO_PRODUCT_SALE_PRICE' => 'Product sale price', 'WOO_CURRENCY_SYMBOL' => 'WooCommerce currency symbol', 'WOO_PRODUCT_STOCK_STATUS' => 'Product stock status', 'WOO_PRODUCT_STOCK_QUANTITY' => 'Product stock quantity', 'WOO_PRODUCT_SHIPPING_CLASS' => 'Product shipping class', 'WOO_ADD_TO_CART_TEXT' => 'WooCommerce "Add to cart" text' ]; } // Make meta field last array value Adv_Vis_Ele_Library::$dynamic_settings['Meta/ACF'] = [ 'META_FIELD' => 'Meta or ACF field' ]; } /** * Fetches the remote elements library info */ public function fetch_remote_library_info($update_local_info = true) { $data = ['request' => 'library-info', 'dev' => isset($_GET['adv-vis-ele-library-dev'])]; $response = wp_remote_post(ADV_VIS_ELE_REMOTE_URL, ['body' => $data, 'timeout' => 60]); $output = wp_remote_retrieve_body($response); if (!empty($output)) { $decoded = json_decode($output); if (!empty($decoded)) { if ($decoded->response === 'success') { if (version_compare($decoded->data->version, $this->library_version) === 1 || empty(get_option('adv_vis_ele_library_version'))) { $this->library_needs_update = true; } else { $this->library_needs_update = false; } if (Adv_Vis_Ele_Admin::is_dev()) { $this->library_needs_update = false; } $dev_library = false; if (isset($_GET['adv-vis-ele-library-action']) && sanitize_text_field($_GET['adv-vis-ele-library-action']) === 'update') { if (isset($_GET['adv-vis-ele-library-dev']) || isset($_GET['adv-vis-ele-library-reset'])) { $this->library_needs_update = true; if (isset($_GET['adv-vis-ele-library-dev'])) { $dev_library = true; } } } if ($update_local_info === false) { return $this->library_needs_update; } else { if ($this->library_needs_update) { if (!isset($decoded->data->elements_json)) { return []; } $library_difference = array_diff(array_column($decoded->data->elements_json, 'id'), array_column($this->library_info, 'id')); $this->library_info = $decoded->data->elements_json; $this->library_version = $decoded->data->version; if ($dev_library) { update_option('adv_vis_ele_library_version', 'DEV'); } else { update_option('adv_vis_ele_library_version', $decoded->data->version); } update_option('adv_vis_ele_library_info', $this->library_info); if (!empty($library_difference)) { update_option('adv_vis_ele_library_info_new', $library_difference); } } } return $this->library_info; } else { return []; } } else { return []; } } else { return []; } } /** * Get local library info */ public function get_local_library_info($limit = false, $page = false) { $library_ordering = get_user_meta(get_current_user_id(), 'adv_vis_ele_library_ordering', true); if (empty($library_ordering)) { $library_ordering = 'asc'; add_user_meta(get_current_user_id(), 'adv_vis_ele_library_ordering', $library_ordering); } array_multisort(array_column($this->library_info, 'name'), SORT_NATURAL, $this->library_info); if ($library_ordering === 'desc') { $library_info = array_reverse($this->library_info); } else { $library_info = $this->library_info; } if (is_int($limit) && is_int($page)) { return array_slice($library_info, ($page * $limit) - $limit, $limit); } return $library_info; } /** * Get library changelog (remote) */ public function fetch_library_changelog() { $data = ['request' => 'library-changelog']; $response = wp_remote_post(ADV_VIS_ELE_REMOTE_URL, ['body' => $data, 'timeout' => 60]); $output = wp_remote_retrieve_body($response); if (!empty($output)) { $decoded = json_decode($output); if (!empty($decoded)) { if ($decoded->response === 'success') { return $decoded->data; } else { return ''; } } else { return ''; } } else { return ''; } } /** * Get element info from local library */ public function get_element($element_id) { $info = $this->get_local_library_info(); $key = array_search($element_id, array_column($info, 'id')); if ($key === false) { return false; } if (is_object($info[$key])) { return $info[$key]; } return false; } /** * Get element options from local library */ public function get_element_setting($element_id, $setting_name) { $element = $this->get_element($element_id); if ($element) { $key = array_search($setting_name, array_column($element->settings, 'id')); if ($key !== false) { return $element->settings[$key]; } } return false; } /** * Install element */ public function install_element($element_id) { if (wp_doing_ajax()) { $nonce_verified = isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'ave_ajax'); if (!$nonce_verified) { wp_send_json_error(['code' => '010']); } $element_id = sanitize_text_field($_POST['element-id']); $editing_shortcode = isset($_POST['editing-shortcode']); } else { $editing_shortcode = false; } if ($element_id === false || empty($element_id)) { if (wp_doing_ajax()) { wp_send_json_error(['code' => '004']); } else { return false; } } $library = new Adv_Vis_Ele_Library(); $element = $library->get_element($element_id); if ($element->license !== 'free' && !wpave_fs()->can_use_premium_code()) { if (wp_doing_ajax()) { wp_send_json_error(['message' => __('You don\'t have a valid license to install this element.', 'wp-ave')]); } else { return false; } } $license_id = !empty(wpave_fs()->_get_license()) ? wpave_fs()->_get_license()->id : ''; $install_id = !empty(wpave_fs()->get_site()) ? wpave_fs()->get_site()->id : ''; $site_private_key = !empty(wpave_fs()->get_site()) ? wpave_fs()->get_site()->secret_key : ''; $nonce = date('Y-m-d'); $pk_hash = hash('sha512', $site_private_key . '|' . $nonce); $authentication_string = base64_encode($pk_hash . '|' . $nonce); $data = [ 'request' => 'install', 'element-id' => $element_id, 'license_id' => $license_id, 'install_id' => $install_id, 'site_private_key' => $site_private_key, 'authentication_string' => $authentication_string, 'dev' => isset($_REQUEST['adv-vis-ele-library-dev']) ]; $response = wp_remote_post(ADV_VIS_ELE_REMOTE_URL, ['body' => $data, 'headers' => '', 'timeout' => 60]); $output = wp_remote_retrieve_body($response); if (empty($output)) { if (wp_doing_ajax()) { wp_send_json_error(['code' => '005', 'message' => __('Element could not be downloaded. If you are on a development server - try enabling localhost mode on Settings page.', 'wp-ave')]); } else { return false; } } $element_install_path = ADV_VIS_ELE_ELEMENTS_DIR . DIRECTORY_SEPARATOR . $element_id; Adv_Vis_Ele_Helpers::wipe_dir($element_install_path); $zipFile = $element_install_path . '.zip'; global $wp_filesystem; if(empty($wp_filesystem)) { require_once ABSPATH . 'wp-admin/includes/file.php'; WP_Filesystem(); } $wp_filesystem->put_contents($zipFile, $output); $extracted = unzip_file($zipFile, $element_install_path); @unlink($zipFile); if (!is_wp_error($extracted)) { $index_path = $element_install_path . '/index.php'; if (!is_file($index_path)) { // create index.php file to prevent directory reading $index_file = fopen($index_path, 'w'); fwrite($index_file, 'get_installed_elements())) { $this->installed_elements[] = $element_id; } else { $this->installed_elements = [$element_id]; } update_option('adv_vis_ele_installed_elements', $this->installed_elements); if (wp_doing_ajax()) { if ($editing_shortcode === true) { $success_message = __('Element was successfully installed. Please refresh or update the page.', 'wp-ave'); } else { $success_message = __('Element was successfully installed.', 'wp-ave'); } wp_send_json_success(['message' => __($success_message, 'wp-ave')]); } else { return true; } } else { if (wp_doing_ajax()) { wp_send_json_error(['code' => '007', 'message' => __('Element could not be installed. Make sure you have the right folder permissions. Please refresh and try again.', 'wp-ave')]); } else { return false; } } return false; } /** * Delete element */ public function uninstall_element($element_id) { if (wp_doing_ajax()) { $nonce_verified = isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'ave_ajax'); if (!$nonce_verified) { wp_send_json_error(['code' => '010']); } $element_id = sanitize_text_field($_POST['element-id']); } if ($element_id === false || empty($element_id)) { if (wp_doing_ajax()) { wp_send_json_error(['code' => '004']); } else { return false; } } $element_folder = ADV_VIS_ELE_ELEMENTS_DIR . DIRECTORY_SEPARATOR . $element_id; Adv_Vis_Ele_Helpers::wipe_dir($element_folder); $installed_elements = $this->get_installed_elements(); if (($key = array_search($element_id, $installed_elements)) !== false) { unset($installed_elements[$key]); $this->installed_elements = $installed_elements; update_option('adv_vis_ele_installed_elements', $this->installed_elements); if (wp_doing_ajax()) { wp_send_json_success(['message' => __('Element was successfully deleted.', 'wp-ave')]); } else { return true; } } else { if (wp_doing_ajax()) { wp_send_json_error(['code' => '006', 'message' => __('Element could not be deleted. Please refresh and try again.', 'wp-ave')]); } else { return false; } } return false; } /** * Get installed elements */ public function get_installed_elements() { return empty($this->installed_elements) ? [] : $this->installed_elements; } /** * Check if element is installed */ public function is_element_installed($element_id) { return in_array($element_id, $this->get_installed_elements()); } /** * Get elements HTML */ public function get_element_html($element) { ob_start(); ?>
license != 'free') { ?>