File manager - Edit - /home/aresglob/public_html/wp/wp-includes/images/smilies/ai-builder.tar
Back
inc/api/api-init.php 0000644 00000000604 15104046434 0010312 0 ustar 00 <?php /** * INitialize API. * * @package {{package}} * @since 0.0.1 */ namespace AiBuilder\Inc\Api; use AiBuilder\Inc\Traits\Instance; /** * Api_Base * * @since 0.0.1 */ class ApiInit { use Instance; /** * Controller object. * * @var object class. */ public $controller = null; /** * Constructor * * @since 0.0.1 */ public function __construct() { } } inc/api/api-base.php 0000644 00000001007 15104046434 0010257 0 ustar 00 <?php /** * API base. * * @package {{package}} * @since 0.0.1 */ namespace AiBuilder\Inc\Api; /** * Api_Base * * @since 0.0.1 */ abstract class Api_Base extends \WP_REST_Controller { /** * Endpoint namespace. * * @var string */ protected $namespace = 'ai-builder/v1'; /** * Constructor * * @since 0.0.1 */ public function __construct() { } /** * Get API namespace. * * @since 0.0.1 * @return string */ public function get_api_namespace() { return $this->namespace; } } inc/ajax/plugin.php 0000644 00000026144 15104046434 0010257 0 ustar 00 <?php /** * Plugin ajax actions. * * @package AiBuilder */ namespace AiBuilder\Inc\Ajax; // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) { exit; } use AiBuilder\Inc\Classes\Importer\Ai_Builder_Error_Handler; use AiBuilder\Inc\Classes\Zipwp\Ai_Builder_ZipWP_Integration; use AiBuilder\Inc\Traits\Helper; use AiBuilder\Inc\Traits\Instance; use STImporter\Importer\ST_Importer; use STImporter\Importer\ST_Importer_Helper; /** * Class Flows. */ class Plugin extends AjaxBase { use Instance; /** * Ajax Instance * * @access private * @var object Class object. * @since 1.0.42 */ private static $ajax_instance = null; /** * Initiator * * @since 1.0.42 * @return object initialized object of class. */ public static function get_instance() { if ( null === self::$ajax_instance ) { self::$ajax_instance = new self(); } return self::$ajax_instance; } /** * Register_ajax_events. * * @return void */ public function register_ajax_events() { $ajax_events = array( 'required_plugins', 'required_plugin_activate', 'filesystem_permission', 'set_start_flag', 'download_image', 'report_error', 'activate_theme', 'site_language', ); $this->init_ajax_events( $ajax_events ); } /** * Required Plugins * * @since 2.0.0 * * @param array<int, array<string, string>> $required_plugins Required Plugins. * @param array<string, mixed> $options Site Options. * @param array<string, mixed> $enabled_extensions Enabled Extensions. * @return mixed */ public function required_plugins( $required_plugins = array(), $options = array(), $enabled_extensions = array() ) { Helper::required_plugins( $required_plugins, $options, $enabled_extensions ); } /** * Required Plugin Activate * * @since 2.0.0 Added parameters $init, $options & $enabled_extensions to add the WP CLI support. * @since 1.0.0 * @param string $init Plugin init file. * @param array<string, mixed> $options Site options. * @param array<string, mixed> $enabled_extensions Enabled extensions. * @return void */ public function required_plugin_activate( $init = '', $options = array(), $enabled_extensions = array() ) { Helper::required_plugin_activate( $init, $options, $enabled_extensions ); } /** * Get the status of file system permission of "/wp-content/uploads" directory. * * @return void */ public function filesystem_permission() { Helper::filesystem_permission(); } /** * Set a flag that indicates the import process has started. * * @return void */ public function set_start_flag() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } $uuid = isset( $_POST['uuid'] ) ? sanitize_text_field( $_POST['uuid'] ) : ''; $template_type = isset( $_POST['template_type'] ) ? sanitize_text_field( $_POST['template_type'] ) : ''; if ( class_exists( 'STImporter\Importer\ST_Importer' ) ) { ST_Importer::set_import_process_start_flag( $template_type, $uuid ); wp_send_json_success(); } else { wp_send_json_error( __( 'Required function not found', 'astra-sites' ) ); } } /** * Download Images * * @since 4.1.0 * @return void */ public function download_image() { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'data' => 'You do not have permission to do this action.', 'status' => false, ) ); } $index = isset( $_POST['index'] ) ? sanitize_text_field( wp_unslash( $_POST['index'] ) ) : ''; $images = Ai_Builder_ZipWP_Integration::get_business_details( 'images' ); if ( empty( $images ) || ! is_array( $images ) ) { wp_send_json_success( array( 'data' => 'No images selected to download!', 'status' => true, ) ); } $image = $images[ $index ]; if ( empty( $image ) || ! is_array( $image ) ) { wp_send_json_success( array( 'data' => 'No image to download!', 'status' => true, ) ); } $prepare_image = array( 'id' => $image['id'], 'url' => $image['url'], 'description' => isset( $image['description'] ) ? $image['description'] : '', ); $id = class_exists( 'STImporter\Importer\ST_Importer_Helper' ) ? ST_Importer_Helper::download_image( $prepare_image ) : 0; wp_send_json_success( array( 'data' => 'Image downloaded successfully!', 'status' => true, ) ); } /** * Report Error. * * @since 3.0.0 * @return void */ public function report_error() { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'data' => 'You do not have permission to do this action.', 'status' => false, ) ); } $api_domain = class_exists( 'STImporter\Importer\ST_Importer_Helper' ) ? ST_Importer_Helper::get_api_domain() : ''; $api_url = add_query_arg( [], trailingslashit( $api_domain ) . 'wp-json/starter-templates/v2/import-error/' ); if ( ! astra_sites_is_valid_url( $api_url ) ) { wp_send_json_error( array( /* Translators: %s is URL. */ 'message' => sprintf( __( 'Invalid URL - %s', 'astra-sites' ), $api_url ), 'code' => 'Error', ) ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; $user_agent_string = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ) : ''; $error = isset( $_POST['error'] ) ? json_decode( stripslashes( $_POST['error'] ), true ) : array(); $local_storage = isset( $_POST['local_storage'] ) ? json_decode( stripslashes( $_POST['local_storage'] ), true ) : array(); $ai_import_logger = get_option( 'ai_import_logger', array() ); $ai_import_logger = array( 'time' => current_time( 'mysql' ), 'data' => array( 'user_agent' => $user_agent_string, 'id' => $id, 'error' => $error, ), ); update_option( 'ai_import_logger', $ai_import_logger ); $api_args = array( 'timeout' => 3, 'blocking' => true, 'body' => array( 'url' => esc_url( site_url() ), 'err' => stripslashes( $_POST['error'] ), 'id' => $_POST['id'], 'logfile' => $this->get_log_file_path(), 'version' => AI_BUILDER_VER, 'abspath' => ABSPATH, 'user_agent' => $user_agent_string, 'server' => array( 'php_version' => Helper::get_php_version(), 'php_post_max_size' => ini_get( 'post_max_size' ), 'php_max_execution_time' => ini_get( 'max_execution_time' ), 'max_input_time' => ini_get( 'max_input_time' ), 'php_memory_limit' => ini_get( 'memory_limit' ), 'php_max_input_vars' => ini_get( 'max_input_vars' ), // phpcs:ignore:PHPCompatibility.IniDirectives.NewIniDirectives.max_input_varsFound ), 'builder_type' => isset( $_POST['type'] ) ? sanitize_text_field( $_POST['type'] ) : '', 'page_builder' => isset( $_POST['page_builder'] ) ? sanitize_text_field( $_POST['page_builder'] ) : '', 'template_type' => isset( $_POST['template_type'] ) ? sanitize_text_field( $_POST['template_type'] ) : '', ), ); do_action( 'st_before_sending_error_report', $api_args['body'] ); $request = wp_safe_remote_post( $api_url, $api_args ); do_action( 'st_after_sending_error_report', $api_args['body'], $request ); $failed_sites = get_option( 'astra_sites_import_failed_sites', array() ); $last_import_site = get_option( 'zipwp_import_site_details', array() ); if ( ! is_array( $failed_sites ) ) { $failed_sites = array(); } $uuids = array_map( static function( $site ) { return $site['uuid']; }, $failed_sites ); if ( is_array( $last_import_site ) && ! in_array( $last_import_site['uuid'], $uuids, true ) ) { $last_import_site['template_id'] = $id; $last_import_site['local_storage'] = $local_storage; $failed_sites[] = $last_import_site; update_option( 'astra_sites_import_failed_sites', $failed_sites ); } if ( is_wp_error( $request ) ) { wp_send_json_error( $request ); } $code = (int) wp_remote_retrieve_response_code( $request ); $data = json_decode( wp_remote_retrieve_body( $request ), true ); if ( 200 === $code ) { wp_send_json_success( $data ); } wp_send_json_error( $data ); } /** * Get full path of the created log file. * * @return string File Path. * @since 3.0.25 */ public function get_log_file_path() { $log_file = get_option( 'astra_sites_recent_import_log_file', false ); if ( ! empty( $log_file ) && is_string( $log_file ) ) { return str_replace( ABSPATH, esc_url( site_url() ) . '/', $log_file ); } return ''; } /** * Activate theme * * @since 1.3.2 * @return void */ public function activate_theme() { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } Ai_Builder_Error_Handler::Instance()->start_error_handler(); switch_theme( 'astra' ); Ai_Builder_Error_Handler::Instance()->stop_error_handler(); /** * Fires after the theme activation. * * @param string $theme_slug The slug of the theme that was activated. * @since 1.2.29 */ do_action( 'astra_sites_after_theme_activation', 'astra' ); wp_send_json_success( array( 'success' => true, 'message' => __( 'Theme Activated', 'astra-sites' ), ) ); } /** * Set site language. * * @since 1.0.0 * @return void */ public function site_language() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } if ( ! wp_doing_ajax() ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } $language = isset( $_POST['language'] ) ? sanitize_text_field( $_POST['language'] ) : 'en_US'; $result = $this->set_language( $language ); if ( ! $result ) { wp_send_json_error( __( 'Failed to set the site language.', 'astra-sites' ) ); } wp_send_json_success(); } /** * Set the site language. * * @since 1.0.0 * * @param string $language The language code. * @return bool */ public function set_language( $language = 'en_US' ) { require_once ABSPATH . 'wp-admin/includes/translation-install.php'; $locale_code = 'en_US' === $language ? '' : $language; if ( '' !== $locale_code && wp_can_install_language_pack() ) { $language = wp_download_language_pack( $locale_code ); } if ( ( '' === $locale_code ) || ( '' !== $locale_code && $language ) ) { update_option( 'WPLANG', $locale_code ); load_default_textdomain( $locale_code ); return switch_to_locale( $locale_code ); } return false; } } inc/ajax/ajax-errors.php 0000644 00000002011 15104046434 0011201 0 ustar 00 <?php /** * Ai Builder Ajax Errors. * * @package Ai Builder */ namespace AiBuilder\Inc\Ajax; use AiBuilder\Inc\Traits\Instance; // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Class AjaxErrors */ class AjaxErrors { use Instance; /** * Errors * * @access private * @var array<string, string> Errors strings. * @since 1.0.0 */ private static $errors = array(); /** * Constructor * * @since 1.0.0 */ public function __construct() { self::$errors = array( 'permission' => __( 'Sorry, you are not allowed to do this operation.', 'astra-sites' ), 'nonce' => __( 'Nonce validation failed', 'astra-sites' ), 'default' => __( 'Sorry, something went wrong.', 'astra-sites' ), ); } /** * Get error message. * * @param string $type Message type. * @return string */ public function get_error_msg( $type ) { if ( ! isset( self::$errors[ $type ] ) ) { $type = 'default'; } return self::$errors[ $type ]; } } AjaxErrors::Instance(); inc/ajax/ajax-init.php 0000644 00000002564 15104046434 0010645 0 ustar 00 <?php /** * AiBuilder Ajax Initialize. * * @package AiBuilder */ namespace AiBuilder\Inc\Ajax; use AiBuilder\Inc\Traits\Instance; // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Class Admin_Init. */ class AjaxInit { use Instance; /** * Ajax Instance * * @access private * @var object Class object. * @since 1.0.42 */ private static $ajax_instance = null; /** * Constructor * * @since 1.0.0 */ public function __construct() { $this->initialize_hooks(); } /** * Initiator * * @since 1.0.42 * @return object initialized object of class. */ public static function get_instance() { if ( null === self::$ajax_instance ) { self::$ajax_instance = new self(); } return self::$ajax_instance; } /** * Init Hooks. * * @since 1.0.0 * @return void */ public function initialize_hooks() { $this->register_all_ajax_events(); } /** * Register API routes. * * @return void */ public function register_all_ajax_events() { $controllers = array( 'AiBuilder\Inc\Ajax\Importer', 'AiBuilder\Inc\Ajax\Plugin', ); foreach ( $controllers as $controller ) { if ( class_exists( $controller ) && method_exists( $controller::get_instance(), 'register_ajax_events' ) ) { $controller::get_instance()->register_ajax_events(); // @phpstan-ignore-line } } } } AjaxInit::Instance(); inc/ajax/importer.php 0000644 00000042217 15104046434 0010621 0 ustar 00 <?php /** * Import ajax actions. * * @package AiBuilder */ namespace AiBuilder\Inc\Ajax; // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) { exit; } use AiBuilder\Inc\Classes\Ai_Builder_Importer_Log; use AiBuilder\Inc\Classes\Importer\Ai_Builder_Fse_Importer; use AiBuilder\Inc\Classes\Importer\Ai_Builder_Utils; use AiBuilder\Inc\Classes\Zipwp\Ai_Builder_ZipWP_Integration; use AiBuilder\Inc\Traits\Helper; use AiBuilder\Inc\Traits\Instance; use STImporter\Importer\Batch\ST_Batch_Processing_Elementor; use STImporter\Importer\Batch\ST_Batch_Processing_Gutenberg; use STImporter\Importer\Batch\ST_Batch_Processing_Misc; use STImporter\Importer\ST_Importer; use STImporter\Importer\ST_Importer_Helper; use STImporter\Resetter\ST_Resetter; /** * Class Flows. */ class Importer extends AjaxBase { use Instance; /** * Ajax Instance * * @access private * @var object Class object. * @since 1.0.42 */ private static $ajax_instance = null; /** * Constructor */ public function __construct() { add_action( 'astra_sites_import_complete', array( $this, 'update_required_options' ) ); } /** * Initiator * * @since 1.0.42 * @return object initialized object of class. */ public static function get_instance() { if ( null === self::$ajax_instance ) { self::$ajax_instance = new self(); } return self::$ajax_instance; } /** * Update options. * * @return void */ public function update_required_options() { update_option( 'astra_sites_import_complete', 'yes', false ); update_option( 'getting_started_is_setup_wizard_showing', true ); if ( 'ai' === get_option( 'astra_sites_current_import_template_type' ) ) { update_option( 'astra_sites_batch_process_complete', 'yes' ); delete_option( 'ai_import_logger' ); delete_option( 'astra_sites_import_failed_sites' ); } else { update_option( 'astra_sites_batch_process_complete', 'no' ); } delete_option( 'astra_sites_import_started' ); } /** * Register_ajax_events. * * @return void */ public function register_ajax_events() { $ajax_events = array( // Import Part 1 Start. 'backup_settings', 'reset_customizer_data', 'reset_site_options', 'reset_widgets_data', 'reset_terms_and_forms', 'get_deleted_post_ids', 'reset_posts', 'download_selected_image', 'import_customizer_settings', 'import_spectra_settings', 'import_surecart_settings', // Import Part 1 End. // Import Part 2 Start. 'import_options', 'import_widgets', 'page_builder_batch', 'image_replacement_batch', 'import_end', 'set_site_data', 'import_success', // Import Part 2 End. ); $this->init_ajax_events( $ajax_events ); } /** * Backup our existing settings. * * @return void */ public function backup_settings() { Helper::backup_settings(); } /** * Reset posts in chunks. * * @return void * * @since 3.0.8 */ public function reset_posts() { if ( wp_doing_ajax() ) { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } if ( class_exists( 'STImporter\Resetter\ST_Resetter' ) ) { ST_Resetter::reset_posts(); } if ( wp_doing_ajax() ) { wp_send_json_success(); } } /** * Import Success. * * @return void * * @since 1.2.15 */ public function import_success() { if ( wp_doing_ajax() ) { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } do_action( 'astra_sites_import_success' ); wp_send_json_success(); } /** * Reset customizer data * * @since 1.3.0 * @return void */ public function reset_customizer_data() { Helper::reset_customizer_data(); } /** * Reset site options * * @since 1.3.0 * @return void */ public function reset_site_options() { Helper::reset_site_options(); } /** * Reset widgets data * * @since 1.3.0 * @return void */ public function reset_widgets_data() { Helper::reset_widgets_data(); } /** * Reset terms and forms. * * @return void * * @since 3.0.3 */ public function reset_terms_and_forms() { if ( wp_doing_ajax() ) { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } if ( class_exists( 'STImporter\Resetter\ST_Resetter' ) ) { ST_Resetter::reset_terms_and_forms(); } if ( wp_doing_ajax() ) { wp_send_json_success(); } } /** * Get post IDs to be deleted. * * @return void */ public function get_deleted_post_ids() { if ( wp_doing_ajax() ) { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } wp_send_json_success( astra_sites_get_reset_post_data() ); } /** * Download Images * * @since 4.1.0 * @return void */ public function download_selected_image() { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'data' => 'You do not have permission to do this action.', 'status' => false, ) ); } $index = isset( $_POST['index'] ) ? sanitize_text_field( wp_unslash( $_POST['index'] ) ) : ''; $images = Ai_Builder_ZipWP_Integration::get_business_details( 'images' ); if ( empty( $images ) || ! is_array( $images ) ) { wp_send_json_error( array( 'data' => 'Image not downloaded!', 'status' => true, ) ); } $image = $images[ $index ]; if ( empty( $image ) || ! is_array( $image ) ) { wp_send_json_error( array( 'data' => 'Image not downloaded!', 'status' => true, ) ); } $prepare_image = array( 'id' => $image['id'], 'url' => $image['url'], 'description' => $image['description'], ); Ai_Builder_Importer_Log::add( 'Downloading Image ' . $image['url'] ); if ( class_exists( 'STImporter\Importer\ST_Importer_Helper' ) ) { $id = ST_Importer_Helper::download_image( $prepare_image ); Ai_Builder_Importer_Log::add( 'Downloaded Image attachment id: ' . $id ); wp_send_json_success( array( 'data' => 'Image downloaded successfully!', 'status' => true, ) ); } wp_send_json_error( array( 'data' => 'Required function not found!', 'status' => false, ) ); } /** * Import Customizer Settings. * * @since 1.0.14 * @since 1.4.0 The `$customizer_data` was added. * * @return void */ public function import_customizer_settings() { Helper::import_customizer_settings(); } /** * Import Spectra Settings * * @since 3.1.16 * * @param string $url Spectra Settings JSON file URL. * @return void */ public function import_spectra_settings( $url = '' ) { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error( array( 'error' => __( 'Permission Denied!', 'astra-sites' ), ) ); } $settings = astra_get_site_data( 'astra-site-spectra-options' ); if ( class_exists( 'STImporter\Importer\ST_Importer' ) ) { $result = ST_Importer::import_spectra_settings( $settings ); if ( false === $result['status'] ) { if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( $result['error'] ); } elseif ( wp_doing_ajax() ) { wp_send_json_error( $result['error'] ); } } if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'Imported Spectra settings from ' . $url ); } elseif ( wp_doing_ajax() ) { wp_send_json_success( $url ); } } wp_send_json_error( __( 'There was an error importing the Spectra settings.', 'astra-sites' ) ); } /** * Import Surecart Settings * * @since 3.3.0 * @return void */ public function import_surecart_settings() { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } $id = isset( $_POST['source_id'] ) ? base64_decode( sanitize_text_field( $_POST['source_id'] ) ) : ''; //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode if ( class_exists( 'STImporter\Importer\ST_Importer' ) ) { $result = ST_Importer::import_surecart_settings( $id ); if ( ! is_wp_error( $result ) ) { wp_send_json_success( 'success' ); } } wp_send_json_error( __( 'There was an error cloning the surecart store.', 'astra-sites' ) ); } /** * Import Options. * * @since 1.0.14 * @since 1.4.0 The `$options_data` was added. * * @return void */ public function import_options() { Helper::import_options(); } /** * Import Widgets. * * @since 1.0.14 * @since 1.4.0 The `$widgets_data` was added. * * @return void */ public function import_widgets() { Helper::import_widgets(); } /** * Processing GT batch. * * @since 1.0.14 * @return void */ public function page_builder_batch() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } $required_plugins = (array) astra_get_site_data( 'required-plugins' ); $plugins_slug = array_column( $required_plugins, 'slug' ); $status = array( 'status' => false, 'msg' => __( 'Required function not found', 'astra-sites' ), ); if ( in_array( 'elementor', $plugins_slug, true ) ) { $status = class_exists( 'STImporter\Importer\Batch\ST_Batch_Processing_Elementor' ) ? ST_Batch_Processing_Elementor::get_instance()->import() : $status; } else { $status = class_exists( 'STImporter\Importer\Batch\ST_Batch_Processing_Gutenberg' ) ? ST_Batch_Processing_Gutenberg::get_instance()->import() : $status; } if ( wp_doing_ajax() ) { if ( $status['success'] ) { wp_send_json_success( $status['msg'] ); } else { wp_send_json_error( $status['msg'] ); } } } /** * Processing GT batch. * * @since 1.0.14 * @return void */ public function image_replacement_batch() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } $status = class_exists( 'STImporter\Importer\Batch\ST_Batch_Processing_Misc' ) ? ST_Batch_Processing_Misc::get_instance()->import() : array( 'status' => false, 'msg' => __( 'Required function not found', 'astra-sites' ), ); if ( wp_doing_ajax() ) { if ( $status['success'] ) { wp_send_json_success( $status['msg'] ); } else { wp_send_json_error( $status['msg'] ); } } } /** * Import End. * * @since 1.0.14 * @return void */ public function import_end() { Helper::import_end(); } /** * Set site related data. * * @since 3.0.0-beta.1 * @return void */ public function set_site_data() { if ( 'spectra-one' === get_option( 'stylesheet', 'astra' ) ) { Ai_Builder_Fse_Importer::set_fse_site_data(); return; } check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'success' => false, 'message' => __( 'You are not authorized to perform this action.', 'astra-sites' ), ) ); } $param = isset( $_POST['param'] ) ? sanitize_text_field( $_POST['param'] ) : ''; if ( empty( $param ) ) { wp_send_json_error( array( 'error' => __( 'Received empty parameters.', 'astra-sites' ), ) ); } switch ( $param ) { case 'site-title': $business_name = isset( $_POST['business-name'] ) ? sanitize_text_field( stripslashes( $_POST['business-name'] ) ) : ''; if ( ! empty( $business_name ) ) { update_option( 'blogname', $business_name ); } if ( isset( $_POST['show-site-title'] ) ) { // Get the value of the POST variable. $show_site_title = filter_var( $_POST['show-site-title'], FILTER_VALIDATE_BOOLEAN ); // Determine the array based on the value of the POST variable. $options_array = $show_site_title ? array( 'desktop' => true, 'tablet' => true, 'mobile' => true, ) : array( 'desktop' => false, 'tablet' => false, 'mobile' => false, ); // Update the option in the database. astra_update_option( 'display-site-title-responsive', $options_array ); astra_update_option( 'display-site-title', $show_site_title ); } break; case 'site-logo' === $param && function_exists( 'astra_get_option' ): $logo_id = isset( $_POST['logo'] ) ? intval( $_POST['logo'] ) : 0; $width_index = 'ast-header-responsive-logo-width'; set_theme_mod( 'custom_logo', $logo_id ); if ( ! empty( $logo_id ) ) { // Disable site title when logo is set. astra_update_option( 'display-site-title', false ); } // Set logo width. $logo_width = isset( $_POST['logo-width'] ) ? sanitize_text_field( $_POST['logo-width'] ) : ''; $option = astra_get_option( $width_index ); if ( isset( $option['desktop'] ) ) { $option['desktop'] = $logo_width; } astra_update_option( $width_index, $option ); // Check if transparent header is used in the demo. $transparent_header = astra_get_option( 'transparent-header-logo', false ); $inherit_desk_logo = astra_get_option( 'different-transparent-logo', false ); if ( '' !== $transparent_header && $inherit_desk_logo ) { astra_update_option( 'transparent-header-logo', wp_get_attachment_url( $logo_id ) ); $width_index = 'transparent-header-logo-width'; $option = astra_get_option( $width_index ); if ( isset( $option['desktop'] ) ) { $option['desktop'] = $logo_width; } astra_update_option( $width_index, $option ); } $retina_logo = astra_get_option( 'different-retina-logo', false ); if ( '' !== $retina_logo ) { astra_update_option( 'ast-header-retina-logo', wp_get_attachment_url( $logo_id ) ); } $transparent_retina_logo = astra_get_option( 'different-transparent-retina-logo', false ); if ( '' !== $transparent_retina_logo ) { astra_update_option( 'transparent-header-retina-logo', wp_get_attachment_url( $logo_id ) ); } break; case 'site-colors' === $param && function_exists( 'astra_get_option' ): $palette = isset( $_POST['palette'] ) ? (array) json_decode( stripslashes( $_POST['palette'] ) ) : array(); $colors = isset( $palette['colors'] ) ? (array) $palette['colors'] : array(); if ( ! empty( $colors ) ) { $global_palette = astra_get_option( 'global-color-palette' ); $color_palettes = get_option( 'astra-color-palettes', \Astra_Global_Palette::get_default_color_palette() ); if ( is_array( $color_palettes ) ) { foreach ( $colors as $key => $color ) { $global_palette['palette'][ $key ] = $color; $color_palettes['palettes']['palette_1'][ $key ] = $color; } } update_option( 'astra-color-palettes', $color_palettes ); astra_update_option( 'global-color-palette', $global_palette ); } break; case 'site-typography' === $param && function_exists( 'astra_get_option' ): $typography = isset( $_POST['typography'] ) ? (array) json_decode( stripslashes( $_POST['typography'] ) ) : ''; $font_size_body = isset( $typography['font-size-body'] ) ? (array) $typography['font-size-body'] : ''; if ( ! empty( $font_size_body ) && is_array( $font_size_body ) ) { astra_update_option( 'font-size-body', $font_size_body ); } if ( ! empty( $typography['body-font-family'] ) ) { astra_update_option( 'body-font-family', $typography['body-font-family'] ); } if ( ! empty( $typography['body-font-variant'] ) ) { astra_update_option( 'body-font-variant', $typography['body-font-variant'] ); } if ( ! empty( $typography['body-font-weight'] ) ) { astra_update_option( 'body-font-weight', $typography['body-font-weight'] ); } if ( ! empty( $typography['body-line-height'] ) ) { astra_update_option( 'body-line-height', $typography['body-line-height'] ); } if ( ! empty( $typography['headings-font-family'] ) ) { astra_update_option( 'headings-font-family', $typography['headings-font-family'] ); } if ( ! empty( $typography['headings-font-weight'] ) ) { astra_update_option( 'headings-font-weight', $typography['headings-font-weight'] ); } if ( ! empty( $typography['headings-line-height'] ) ) { astra_update_option( 'headings-line-height', $typography['headings-line-height'] ); } if ( ! empty( $typography['headings-font-variant'] ) ) { astra_update_option( 'headings-font-variant', $typography['headings-font-variant'] ); } break; } // Clearing Cache on hostinger, Cloudways. Ai_Builder_Utils::third_party_cache_plugins_clear_cache(); wp_send_json_success(); } } inc/ajax/ajax-base.php 0000644 00000002140 15104046434 0010602 0 ustar 00 <?php /** * AiBuilder Ajax Base. * * @package AiBuilder */ namespace AiBuilder\Inc\Ajax; // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Class Admin_Menu. */ abstract class AjaxBase { /** * Ajax action prefix. * * @var string */ private $prefix = 'astra-sites'; /** * Constructor * * @since 1.0.0 */ public function __construct() { } /** * Register ajax events. * * @param array<int, string> $ajax_events Ajax events. * * @return void */ public function init_ajax_events( $ajax_events ) { if ( ! empty( $ajax_events ) ) { foreach ( $ajax_events as $ajax_event ) { add_action( 'wp_ajax_' . $this->prefix . '-' . $ajax_event, array( $this, $ajax_event ) ); // @phpstan-ignore-line } } } /** * Get ajax error message. * * @param string $type Message type. * @return string */ public function get_error_msg( $type ) { if ( class_exists( 'AiBuilder\Inc\Ajax\AjaxErrors' ) && method_exists( AjaxErrors::Instance(), 'get_error_msg' ) ) { return AjaxErrors::Instance()->get_error_msg( $type ); } return ''; } } inc/traits/helper.php 0000644 00000067747 15104046434 0010641 0 ustar 00 <?php /** * Trait. * * @package {{package}} * @since 0.0.1 */ namespace AiBuilder\Inc\Traits; use AiBuilder\Inc\Classes\Ai_Builder_Importer_Log; use AiBuilder\Inc\Classes\Importer\Ai_Builder_Error_Handler; use STImporter\Importer\ST_Importer; use STImporter\Importer\ST_Importer_File_System; use STImporter\Resetter\ST_Resetter; /** * Trait Instance. */ class Helper { use Instance; /** * Get an option from the database. * * @param string $key The option key. * @param mixed $default The option default value if option is not available. * @param bool $network_override Whether to allow the network admin setting to be overridden on subsites. * @since 1.0.0 * @return mixed The option value. */ public static function get_admin_settings_option( $key, $default = false, $network_override = false ) { // Get the site-wide option if we're in the network admin. return $network_override && is_multisite() ? get_site_option( $key, $default ) : get_option( $key, $default ); } /** * Delete an option from the database for. * * @param string $key The option key. * @param bool $network_override Whether to allow the network admin setting to be overridden on subsites. * @since 1.0.0 * @return void */ public static function delete_admin_settings_option( $key, $network_override = false ) { // Delete the site-wide option if we're in the network admin. if ( $network_override && is_multisite() ) { delete_site_option( $key ); } else { delete_option( $key ); } } /** * Get image placeholder array. * * @since 4.0.9 * @return array<int, array<string, string>> */ public static function get_image_placeholders() { return array( array( 'auther_name' => 'Placeholder', 'auther_url' => '#', 'id' => 'placeholder-landscape', 'orientation' => 'landscape', 'optimized_url' => 'https://websitedemos.net/wp-content/uploads/2024/02/placeholder-landscape.png', 'url' => 'https://websitedemos.net/wp-content/uploads/2024/02/placeholder-landscape.png', 'engine' => 'placeholder', 'engine_url' => '#', ), array( 'auther_name' => 'Placeholder', 'auther_url' => '#', 'id' => 'placeholder-portrait', 'orientation' => 'portrait', 'optimized_url' => 'https://websitedemos.net/wp-content/uploads/2024/02/placeholder-portrait.png', 'url' => 'https://websitedemos.net/wp-content/uploads/2024/02/placeholder-portrait.png', 'engine' => 'placeholder', 'engine_url' => '#', ), ); } /** * Get Saved Token. * * @since 4.0.0 * @return string */ public static function get_token() { $token_details = get_option( 'zip_ai_settings', array( 'auth_token' => '', 'zip_token' => '', 'email' => '', ) ); return is_array( $token_details ) && isset( $token_details['zip_token'] ) ? self::decrypt( $token_details['zip_token'] ) : ''; } /** * Decrypt data using base64. * * @param string $input The input string which needs to be decrypted. * @since 4.0.0 * @return string The decrypted string. */ public static function decrypt( $input ) { // If the input is empty or not a string, then abandon ship. if ( empty( $input ) || ! is_string( $input ) ) { return ''; } // Decrypt the input and return it. $base_64 = $input . str_repeat( '=', strlen( $input ) % 4 ); return base64_decode( $base_64 ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode } /** * Get installed PHP version. * * @return string PHP version. * @since 3.0.16 */ public static function get_php_version() { if ( defined( 'PHP_MAJOR_VERSION' ) && defined( 'PHP_MINOR_VERSION' ) && defined( 'PHP_RELEASE_VERSION' ) ) { // phpcs:ignore return PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION; } return phpversion(); } /** * Check whether WooCommerce plugin is installed and active. * * @since 1.2.43 * * @return bool True if WooCommerce is active, false otherwise. */ public static function is_woocommerce_active() { return class_exists( 'WooCommerce' ) || is_plugin_active( 'woocommerce/woocommerce.php' ); } /** * Determine if a plugin requires WooCommerce to function. * * @since 1.2.43 * * @param string $plugin Plugin slug or init file. * @return bool True if plugin depends on WooCommerce. */ public static function plugin_requires_woocommerce( $plugin ) { $wc_plugins = array( 'woocommerce-payments', 'woocommerce-payments/woocommerce-payments.php', 'cartflows', 'cartflows/cartflows.php', 'woo-cart-abandonment-recovery', 'woo-cart-abandonment-recovery/woo-cart-abandonment-recovery.php', ); return in_array( $plugin, $wc_plugins, true ); } /** * Has Pro Version Support? * And * Is Pro Version Installed? * * Check Pro plugin version exist of requested plugin lite version. * * Eg. If plugin 'BB Lite Version' required to import demo. Then we check the 'BB Agency Version' is exist? * If yes then we only 'Activate' Agency Version. [We couldn't install agency version.] * Else we 'Activate' or 'Install' Lite Version. * * @since 1.0.1 * * @param string $lite_version Lite version init file. * @return mixed Return false if not installed or not supported by us * else return 'Pro' version details. */ public static function pro_plugin_exist( $lite_version = '' ) { // Lite init => Pro init. $plugins = apply_filters( 'astra_sites_pro_plugin_exist', array( 'beaver-builder-lite-version/fl-builder.php' => array( 'slug' => 'bb-plugin', 'init' => 'bb-plugin/fl-builder.php', 'name' => 'Beaver Builder Plugin', ), 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' => array( 'slug' => 'bb-ultimate-addon', 'init' => 'bb-ultimate-addon/bb-ultimate-addon.php', 'name' => 'Ultimate Addon for Beaver Builder', ), 'wpforms-lite/wpforms.php' => array( 'slug' => 'wpforms', 'init' => 'wpforms/wpforms.php', 'name' => 'WPForms', ), ), $lite_version ); if ( isset( $plugins[ $lite_version ] ) ) { // Pro plugin directory exist? if ( file_exists( WP_PLUGIN_DIR . '/' . $plugins[ $lite_version ]['init'] ) ) { return $plugins[ $lite_version ]; } } return false; } /** * Get the status of file system permission of "/wp-content/uploads" directory. * * @return void */ public static function filesystem_permission() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You do not have permission to perform this action.', 'astra-sites' ) ); } } $wp_upload_path = wp_upload_dir(); $permissions = array( 'is_readable' => false, 'is_writable' => false, ); foreach ( $permissions as $file_permission => $value ) { $permissions[ $file_permission ] = $file_permission( $wp_upload_path['basedir'] ); } $permissions['is_wp_filesystem'] = true; if ( ! WP_Filesystem() ) { $permissions['is_wp_filesystem'] = false; } if ( defined( 'WP_CLI' ) ) { if ( ! $permissions['is_readable'] || ! $permissions['is_writable'] || ! $permissions['is_wp_filesystem'] ) { \WP_CLI::error( esc_html__( 'Please contact the hosting service provider to help you update the permissions so that you can successfully import a complete template.', 'astra-sites' ) ); } } else { wp_send_json_success( array( 'permissions' => $permissions, 'directory' => $wp_upload_path['basedir'], ) ); } } /** * Required Plugins * * @since 2.0.0 * * @param array<int, array<string, string>> $required_plugins Required Plugins. * @param array<string, mixed> $options Site Options. * @param array<string, mixed> $enabled_extensions Enabled Extensions. * @return mixed */ public static function required_plugins( $required_plugins = array(), $options = array(), $enabled_extensions = array() ) { // Verify Nonce. if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error( array( 'error' => __( 'Permission Denied!', 'astra-sites' ), ) ); } } $response = array( 'active' => array(), 'inactive' => array(), 'notinstalled' => array(), ); $id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : ''; $screen = isset( $_POST['screen'] ) ? sanitize_text_field( $_POST['screen'] ) : ''; if ( 'elementor' === $screen ) { $imported_demo_data = get_option( 'astra_sites_import_elementor_data_' . $id, array() ); if ( isset( $imported_demo_data['type'] ) && 'astra-blocks' === $imported_demo_data['type'] ) { // @phpstan-ignore-line // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize $plugins = unserialize( $imported_demo_data['post-meta']['astra-blocks-required-plugins'] ); // @phpstan-ignore-line $required_plugins = false !== $plugins ? $plugins : array(); } else { $required_plugins = isset( $imported_demo_data['site-pages-required-plugins'] ) ? $imported_demo_data['site-pages-required-plugins'] : array(); // @phpstan-ignore-line } } else { $required_plugins = astra_get_site_data( 'required-plugins' ); } if ( ! empty( $_POST['feature_plugins'] ) ) { $feature_plugins = is_string( $_POST['feature_plugins'] ) ? json_decode( wp_unslash( $_POST['feature_plugins'] ), true ) : array(); if ( is_array( $feature_plugins ) && is_array( $required_plugins ) ) { // Create a set of existing plugin slugs. $existing_slugs = array_column( $required_plugins, 'slug' ); // Merge only the new feature plugins that aren't already in the required plugins. foreach ( $feature_plugins as $feature_plugin ) { if ( isset( $feature_plugin['slug'] ) && ! in_array( $feature_plugin['slug'], $existing_slugs, true ) ) { $required_plugins[] = $feature_plugin; $existing_slugs[] = $feature_plugin['slug']; // Keep the slug list updated. } } } } $data = self::get_required_plugins_data( $response, $required_plugins ); // @phpstan-ignore-line if ( wp_doing_ajax() ) { wp_send_json_success( $data ); } else { return $data; } } /** * Retrieves the required plugins data based on the response and required plugin list. * * @param array<string, array<string, mixed>> $response The response containing the plugin data. * @param array<int, array<string, string>> $required_plugins The list of required plugins. * @since 3.2.5 * @return array<string, mixed> The array of required plugins data. */ public static function get_required_plugins_data( $response, $required_plugins ) { $learndash_course_grid = 'https://www.learndash.com/add-on/course-grid/'; $learndash_woocommerce = 'https://www.learndash.com/add-on/woocommerce/'; if ( is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) ) { $learndash_addons_url = admin_url( 'admin.php?page=learndash_lms_addons' ); $learndash_course_grid = $learndash_addons_url; $learndash_woocommerce = $learndash_addons_url; } $third_party_required_plugins = array(); $third_party_plugins = array( 'sfwd-lms' => array( 'init' => 'sfwd-lms/sfwd_lms.php', 'name' => 'LearnDash LMS', 'link' => 'https://www.learndash.com/', ), 'learndash-course-grid' => array( 'init' => 'learndash-course-grid/learndash_course_grid.php', 'name' => 'LearnDash Course Grid', 'link' => $learndash_course_grid, ), 'learndash-woocommerce' => array( 'init' => 'learndash-woocommerce/learndash_woocommerce.php', 'name' => 'LearnDash WooCommerce Integration', 'link' => $learndash_woocommerce, ), ); $plugin_updates = get_plugin_updates(); $update_avilable_plugins = array(); $incompatible_plugins = array(); if ( ! empty( $required_plugins ) ) { $php_version = Helper::get_php_version(); foreach ( $required_plugins as $key => $plugin ) { $plugin = (array) $plugin; if ( 'woocommerce' === $plugin['slug'] && version_compare( $php_version, '7.0', '<' ) ) { $plugin['min_php_version'] = '7.0'; $incompatible_plugins[] = $plugin; } if ( 'presto-player' === $plugin['slug'] && version_compare( $php_version, '7.3', '<' ) ) { $plugin['min_php_version'] = '7.3'; $incompatible_plugins[] = $plugin; } /** * Has Pro Version Support? * And * Is Pro Version Installed? */ $plugin_pro = Helper::pro_plugin_exist( $plugin['init'] ); if ( is_array( $plugin_pro ) ) { if ( array_key_exists( $plugin_pro['init'], $plugin_updates ) ) { $update_avilable_plugins[] = $plugin_pro; } if ( ! is_array( $response ) ) { $response = array(); } // Pro - Active. if ( is_plugin_active( $plugin_pro['init'] ) ) { $response['active'][] = $plugin_pro; self::after_plugin_activate( $plugin['init'], array(), array(), $plugin['slug'], true ); // Pro - Inactive. } else { $response['inactive'][] = $plugin_pro; } } else { if ( array_key_exists( $plugin['init'], $plugin_updates ) ) { $update_avilable_plugins[] = $plugin; } // Lite - Installed but Inactive. if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) && is_plugin_inactive( $plugin['init'] ) ) { $link = wp_nonce_url( add_query_arg( array( 'action' => 'activate', 'plugin' => $plugin['init'], ), admin_url( 'plugins.php' ) ), 'activate-plugin_' . $plugin['init'] ); $link = str_replace( '&', '&', $link ); $plugin['action'] = $link; $response['inactive'][] = $plugin; // Lite - Not Installed. } elseif ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) ) { // Added premium plugins which need to install first. if ( array_key_exists( $plugin['slug'], $third_party_plugins ) ) { $third_party_required_plugins[] = $third_party_plugins[ $plugin['slug'] ]; } else { $link = wp_nonce_url( add_query_arg( array( 'action' => 'install-plugin', 'plugin' => $plugin['slug'], ), admin_url( 'update.php' ) ), 'install-plugin_' . $plugin['slug'] ); $link = str_replace( '&', '&', $link ); $plugin['action'] = $link; $response['notinstalled'][] = $plugin; } // Lite - Active. } else { $response['active'][] = $plugin; self::after_plugin_activate( $plugin['init'], array(), array(), $plugin['slug'], true ); } } } } // Checking the `install_plugins` and `activate_plugins` capability for the current user. // To perform plugin installation process. if ( ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) && ( ( ! current_user_can( 'install_plugins' ) && ! empty( $response['notinstalled'] ) ) || ( ! current_user_can( 'activate_plugins' ) && ! empty( $response['inactive'] ) ) ) ) { $message = __( 'Insufficient Permission. Please contact your Super Admin to allow the install required plugin permissions.', 'astra-sites' ); $required_plugins_list = array_merge( $response['notinstalled'], $response['inactive'] ); $markup = $message; $markup .= '<ul>'; foreach ( $required_plugins_list as $key => $required_plugin ) { $markup .= '<li>' . esc_html( $required_plugin['name'] ) . '</li>'; } $markup .= '</ul>'; wp_send_json_error( $markup ); } return array( 'required_plugins' => $response, 'third_party_required_plugins' => $third_party_required_plugins, 'update_avilable_plugins' => $update_avilable_plugins, 'incompatible_plugins' => $incompatible_plugins, ); } /** * After Plugin Activate * * @since 2.0.0 * * @param string $plugin_init Plugin Init File. * @param array<string, mixed> $options Site Options. * @param array<string, mixed> $enabled_extensions Enabled Extensions. * @param string $plugin_slug Plugin slug. * @param bool $was_plugin_active Flag indicating if the plugin was already active. * @return void */ public static function after_plugin_activate( $plugin_init = '', $options = array(), $enabled_extensions = array(), $plugin_slug = '', $was_plugin_active = false ) { $data = array( 'astra_site_options' => $options, 'enabled_extensions' => $enabled_extensions, 'plugin_slug' => $plugin_slug, 'was_plugin_active' => $was_plugin_active, ); do_action( 'astra_sites_after_plugin_activation', $plugin_init, $data ); } /** * Required Plugin Activate * * @since 2.0.0 Added parameters $init, $options & $enabled_extensions to add the WP CLI support. * @since 1.0.0 * @param string $init Plugin init file. * @param array<string, mixed> $options Site options. * @param array<string, mixed> $enabled_extensions Enabled extensions. * @return void */ public static function required_plugin_activate( $init = '', $options = array(), $enabled_extensions = array() ) { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! sanitize_text_field( $_POST['init'] ) ) { wp_send_json_error( array( 'success' => false, 'message' => __( 'Error: You don\'t have the required permissions to install plugins.', 'astra-sites' ), ) ); } } Ai_Builder_Error_Handler::Instance()->start_error_handler(); $plugin_init = isset( $_POST['init'] ) ? esc_attr( sanitize_text_field( $_POST['init'] ) ) : $init; $plugin_slug = isset( $_POST['slug'] ) ? esc_attr( sanitize_text_field( $_POST['slug'] ) ) : ''; // Check if plugin requires WooCommerce but WooCommerce is not active. if ( self::plugin_requires_woocommerce( $plugin_slug ) || self::plugin_requires_woocommerce( $plugin_init ) ) { if ( ! self::is_woocommerce_active() ) { $message = __( 'This plugin requires WooCommerce to be installed and activated first.', 'astra-sites' ); if ( defined( 'WP_CLI' ) ) { \WP_CLI::error( $message ); } elseif ( wp_doing_ajax() ) { // Send deprioritize response instead of error. wp_send_json_success( array( 'success' => false, 'status' => 'deprioritize', 'action' => 'defer', 'message' => $message, 'reason' => 'missing_woocommerce', 'dependency' => 'woocommerce', 'plugin_slug' => $plugin_slug, 'plugin_init' => $plugin_init, 'retry_after' => 'woocommerce_activation', ) ); } return; } } /** * Disabled redirection to plugin page after activation. * Silecing the callback for WP Live Chat plugin. */ add_filter( 'wp_redirect', '__return_false' ); $silent = 'wp-live-chat-support/wp-live-chat-support.php' === $plugin_init ? true : false; $was_plugin_active = is_plugin_active( $plugin_init ); $activate = activate_plugin( $plugin_init, '', false, $silent ); Ai_Builder_Error_Handler::Instance()->stop_error_handler(); if ( is_wp_error( $activate ) ) { if ( defined( 'WP_CLI' ) ) { \WP_CLI::error( 'Plugin Activation Error: ' . $activate->get_error_message() ); } elseif ( wp_doing_ajax() ) { wp_send_json_error( array( 'success' => false, 'message' => $activate->get_error_message(), ) ); } } $options = (array) astra_get_site_data( 'astra-site-options-data' ); $enabled_extensions = (array) astra_get_site_data( 'astra-enabled-extensions' ); self::after_plugin_activate( $plugin_init, $options, $enabled_extensions, $plugin_slug, $was_plugin_active ); if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'Plugin Activated!' ); } elseif ( wp_doing_ajax() ) { wp_send_json_success( array( 'success' => true, 'status' => 'activated', 'message' => __( 'Plugin Activated', 'astra-sites' ), ) ); } } /** * Backup our existing settings. * * @return void */ public static function backup_settings() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'User does not have permission!', 'astra-sites' ) ); } } if ( ! class_exists( 'STImporter\Resetter\ST_Resetter' ) ) { wp_send_json_error( __( 'Required class not found.', 'astra-sites' ) ); } $log_file_path = ST_Resetter::backup_settings(); if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'File generated at ' . $log_file_path ); } elseif ( wp_doing_ajax() ) { wp_send_json_success(); } } /** * Import Options. * * @since 1.0.14 * @since 1.4.0 The `$options_data` was added. * * @param array<string, mixed> $options_data Site Options. * @return void */ public static function import_options( $options_data = array() ) { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } if ( empty( $options_data ) ) { $options_data = astra_get_site_data( 'astra-site-options-data' ); } if ( ! class_exists( 'STImporter\Importer\ST_Importer' ) || ! class_exists( 'STImporter\Importer\ST_Option_Importer' ) ) { wp_send_json_error( __( 'Required class not found.', 'astra-sites' ) ); } $result = ST_Importer::import_options( $options_data ); if ( false === $result['status'] ) { if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( $result['error'] ); } elseif ( wp_doing_ajax() ) { wp_send_json_error( $result['error'] ); } } if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'Site options Imported!' ); } elseif ( wp_doing_ajax() ) { wp_send_json_success( __( 'Site options Imported!', 'astra-sites' ) ); } } /** * Import Widgets. * * @since 1.0.14 * @since 1.4.0 The `$widgets_data` was added. * * @param string $widgets_data Widgets Data. * @return void */ public static function import_widgets( $widgets_data = '' ) { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } $data = astra_get_site_data( 'astra-site-widgets-data' ); if ( ! class_exists( 'STImporter\Importer\ST_Importer' ) ) { wp_send_json_error( __( 'Required class not found.', 'astra-sites' ) ); } $result = ST_Importer::import_widgets( $widgets_data, $data ); if ( false === $result['status'] ) { if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( $result['error'] ); } elseif ( wp_doing_ajax() ) { wp_send_json_error( $result['error'] ); } } else { if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'Widget Imported!' ); } elseif ( wp_doing_ajax() ) { wp_send_json_success( 'Widget Imported!' ); } } } /** * Import End. * * @since 1.0.14 * @return void */ public static function import_end() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } if ( ! class_exists( 'STImporter\Importer\ST_Importer_File_System' ) ) { wp_send_json_error( __( 'Required class not found.', 'astra-sites' ) ); } $demo_data = ST_Importer_File_System::get_instance()->get_demo_content(); // Set permalink structure to use post name. update_option( 'permalink_structure', '/%postname%/' ); update_option( 'astra-site-permalink-update-status', 'no' ); do_action( 'astra_sites_import_complete', $demo_data ); if ( wp_doing_ajax() ) { wp_send_json_success(); } } /** * Reset customizer data * * @since 1.3.0 * @return void */ public static function reset_customizer_data() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } Ai_Builder_Importer_Log::add( 'Deleted customizer Settings ' . wp_json_encode( get_option( 'astra-settings', array() ) ) ); if ( ! class_exists( 'STImporter\Resetter\ST_Resetter' ) ) { wp_send_json_error( __( 'Required class not found.', 'astra-sites' ) ); } ST_Resetter::reset_customizer_data(); if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'Deleted Customizer Settings!' ); } elseif ( wp_doing_ajax() ) { wp_send_json_success(); } } /** * Reset site options * * @since 1.3.0 * @return void */ public static function reset_site_options() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } $options = get_option( '_astra_sites_old_site_options', array() ); Ai_Builder_Importer_Log::add( 'Deleted - Site Options ' . wp_json_encode( $options ) ); if ( ! class_exists( 'STImporter\Resetter\ST_Resetter' ) ) { wp_send_json_error( __( 'Required class not found.', 'astra-sites' ) ); } ST_Resetter::reset_site_options( $options ); if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'Deleted Site Options!' ); } elseif ( wp_doing_ajax() ) { wp_send_json_success(); } } /** * Reset widgets data * * @since 1.3.0 * @return void */ public static function reset_widgets_data() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } // Get all old widget ids. $old_widgets_data = (array) get_option( '_astra_sites_old_widgets_data', array() ); if ( ! class_exists( 'STImporter\Resetter\ST_Resetter' ) ) { wp_send_json_error( __( 'Required class not found.', 'astra-sites' ) ); } ST_Resetter::reset_widgets_data( $old_widgets_data ); if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'Deleted Widgets!' ); } elseif ( wp_doing_ajax() ) { wp_send_json_success( __( 'Deleted Widgets!', 'astra-sites' ) ); } } /** * Import Customizer Settings. * * @since 1.0.14 * @since 1.4.0 The `$customizer_data` was added. * * @param array<string, mixed> $customizer_data Customizer Data. * @return void */ public static function import_customizer_settings( $customizer_data = array() ) { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { // Verify Nonce. check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } } if ( empty( $customizer_data ) ) { $customizer_data = astra_get_site_data( 'astra-site-customizer-data' ); } if ( defined( 'WP_CLI' ) && empty( $customizer_data ) ) { \WP_CLI::line( 'Customizer data is empty!' ); } elseif ( wp_doing_ajax() && empty( $customizer_data ) ) { wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) ); } if ( ! class_exists( 'STImporter\Importer\ST_Importer' ) ) { wp_send_json_error( __( 'Required class not found.', 'astra-sites' ) ); } $result = ST_Importer::import_customizer_settings( $customizer_data ); if ( false === $result['status'] ) { wp_send_json_error( $result['error'] ); } wp_send_json_success(); } } inc/traits/instance.php 0000644 00000000734 15104046434 0011145 0 ustar 00 <?php /** * Trait. * * @package {{package}} * @since 0.0.1 */ namespace AiBuilder\Inc\Traits; /** * Trait Instance. */ trait Instance { /** * Instance object. * * @var self Class Instance. */ public static $instance = null; /** * Initiator * * @since 0.0.1 * @return self Initialized object of class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } } inc/compatibility/ai-builder-compatibility.php 0000644 00000005042 15104046434 0015565 0 ustar 00 <?php /** * AI Builder Compatibility for 3rd party plugins. * * @package AI Builder * @since 1.0.11 */ if ( ! class_exists( 'Ai_Builder_Compatibility' ) ) { /** * AI Builder Compatibility * * @since 1.0.11 */ class Ai_Builder_Compatibility { /** * Instance * * @access private * @var object Class object. * @since 1.0.11 */ private static $instance = null; /** * Constructor * * @since 1.0.11 */ public function __construct() { // Plugin - Spectra. require_once AI_BUILDER_DIR . 'inc/compatibility/uag/ai-builder-compatibility-uag.php'; // Plugin - WooCommerce. require_once AI_BUILDER_DIR . 'inc/compatibility/surecart/ai-builder-compatibility-surecart.php'; // Plugin - Elementor. require_once AI_BUILDER_DIR . 'inc/compatibility/elementor/ai-builder-compatibility-elementor.php'; // Plugin - Cartflows. require_once AI_BUILDER_DIR . 'inc/compatibility/cartflows/ai-builder-compatibility-cartflows.php'; // Plugin - Suretriggers. require_once AI_BUILDER_DIR . 'inc/compatibility/suretriggers/ai-builder-compatibility-suretriggers.php'; // Plugin - CPSW. require_once AI_BUILDER_DIR . 'inc/compatibility/checkout-plugins-stripe-woo/ai-builder-compatibility-cpsw.php'; // Plugin - SureForms. require_once AI_BUILDER_DIR . 'inc/compatibility/sureforms/ai-builder-compatibility-sureforms.php'; // Plugin - SureMail. require_once AI_BUILDER_DIR . 'inc/compatibility/suremail/ai-builder-compatibility-suremail.php'; // Plugin - Latepoint. require_once AI_BUILDER_DIR . 'inc/compatibility/latepoint/ai-builder-compatibility-latepoint.php'; // Plugin - Ultimate Addons for Elementor. require_once AI_BUILDER_DIR . 'inc/compatibility/uae/ai-builder-compatibility-uae.php'; // Plugin - Ultimate Addons for Elementor Lite. require_once AI_BUILDER_DIR . 'inc/compatibility/uae-lite/ai-builder-compatibility-uae-lite.php'; // Plugin - WooCommerce Payments. require_once AI_BUILDER_DIR . 'inc/compatibility/woocommerce-payments/ai-builder-compatibility-woocommerce-payments.php'; // Plugin - SureRank. require_once AI_BUILDER_DIR . 'inc/compatibility/surerank/ai-builder-compatibility-surerank.php'; } /** * Initiator * * @since 1.0.11 * @return object initialized object of class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } } /** * Kicking this off by calling 'instance()' method */ Ai_Builder_Compatibility::instance(); } inc/compatibility/cartflows/ai-builder-compatibility-cartflows.php 0000644 00000002724 15104046434 0021577 0 ustar 00 <?php /** * AI Builder Compatibility for 'Cartflows' * * @package AI Builder * @since 3.4.6 */ namespace AiBuilder\Inc\Compatibility\Cartflows; defined( 'ABSPATH' ) || exit; if ( ! class_exists( 'Ai_Builder_Compatibility_Cartflows' ) ) { /** * Cartflows Compatibility * * @since 3.4.6 */ class Ai_Builder_Compatibility_Cartflows { /** * Instance * * @access private * @var object Class object. * @since 3.4.6 */ private static $instance = null; /** * Constructor * * @since 3.4.6 */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'disable_cartflows_redirect' ), 2 ); } /** * Initiator * * @since 3.4.6 * @return object initialized object of class. */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Disable Cartflows redirect. * * @param string $plugin_init Plugin init file used for activation. * @param array<string, mixed> $data data. * @return void */ public function disable_cartflows_redirect( $plugin_init, $data = array() ) { if ( 'cartflows/cartflows.php' === $plugin_init ) { update_option( 'wcf_setup_skipped', true ); delete_option( 'wcf_start_onboarding' ); } } } /** * Kicking this off by calling 'get_instance()' method */ Ai_Builder_Compatibility_Cartflows::get_instance(); } inc/compatibility/checkout-plugins-stripe-woo/ai-builder-compatibility-cpsw.php 0000644 00000002720 15104046434 0024131 0 ustar 00 <?php /** * Astra Sites Compatibility for 'Checkout Plugins – Stripe for WooCommerce' * * @see https://wordpress.org/plugins/checkout-plugins-stripe-woo/ * * @package Astra Sites * @since 3.0.23 */ namespace AiBuilder\Inc\Compatibility\Cpsw; defined( 'ABSPATH' ) || exit; /** * Checkout Plugins - Stripe compatibility for Starter Templates. */ class Ai_Builder_Compatibility_Cpsw { /** * Instance * * @access private * @var object Class object. * @since 3.0.23 */ private static $instance = null; /** * Constructor. */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'checkout_plugins' ), 10, 2 ); } /** * Initiator * * @since 3.0.23 * @return object initialized object of class. */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Disable redirec after installing and activating Checkout Plugins - Stripe. * * @param string $plugin_init Plugin init file used for activation. * @param array<string, mixed> $data data. * @return void */ public function checkout_plugins( $plugin_init, $data = array() ) { if ( 'checkout-plugins-stripe-woo/checkout-plugins-stripe-woo.php' === $plugin_init ) { delete_option( 'cpsw_start_onboarding' ); } } } /** * Kicking this off by calling 'get_instance()' method */ Ai_Builder_Compatibility_Cpsw::get_instance(); inc/compatibility/uag/ai-builder-compatibility-uag.php 0000644 00000002406 15104046434 0017114 0 ustar 00 <?php /** * AI Builder Compatibility for 'UAG' * * @see https://wordpress.org/plugins/ultimate-addons-for-gutenberg/ * * @package AI Builder * @since 3.0.15 */ /** * UAG compatibility for Starter Templates. */ class Ai_Builder_Compatibility_UAG { /** * Instance * * @access private * @var object Class object. * @since 3.0.15 */ private static $instance = null; /** * Constructor. */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'uag_activation' ), 10 ); } /** * Initiator * * @since 3.0.15 * @return object initialized object of class. */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Disable redirect after installing and activating UAG. * * @since 3.0.15 * @param string $plugin_init The path to the plugin file that was just activated. * @return void */ public function uag_activation( $plugin_init ) { if ( 'ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php' === $plugin_init ) { update_option( '__uagb_do_redirect', false ); } } } /** * Kicking this off by calling 'get_instance()' method */ Ai_Builder_Compatibility_UAG::get_instance(); inc/compatibility/latepoint/ai-builder-compatibility-latepoint.php 0000644 00000002702 15104046434 0021561 0 ustar 00 <?php /** * AI Builder Compatibility for 'LatePoint' * * @see https://wordpress.org/plugins/latepoint/ * * @package AI Builder * @since 1.2.30 */ if ( ! class_exists( 'Ai_Builder_Compatibility_LatePoint' ) ) { /** * LatePoint Compatibility * * @since 1.2.30 */ class Ai_Builder_Compatibility_LatePoint { /** * Instance * * @access private * @var object Class object. * @since 1.2.30 */ private static $instance; /** * Constructor * * @since 1.2.30 */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'disable_latepoint_redirection' ) ); } /** * Initiator * * @since 1.2.30 * @return object initialized object of class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Disables LatePoint redirection during plugin activation. * * @param string $plugin_init The path to the plugin file that was just activated. * * @since 1.2.30 * @return void */ public function disable_latepoint_redirection( $plugin_init ) { if ( 'latepoint/latepoint.php' === $plugin_init ) { update_option( 'latepoint_redirect_to_wizard', false ); update_option( 'latepoint_show_version_5_modal', false ); } } } /** * Kicking this off by calling 'instance()' method */ Ai_Builder_Compatibility_LatePoint::instance(); } inc/compatibility/suretriggers/ai-builder-compatibility-suretriggers.php 0000644 00000002604 15104046434 0023036 0 ustar 00 <?php /** * Astra Sites Compatibility for 'Suretriggers' * * @see https://wordpress.org/plugins/ultimate-addons-for-beaver-builder-lite/ * * @package Astra Sites * @since 4.0.8 */ namespace AiBuilder\Inc\Compatibility\SureCart; /** * Suretriggers compatibility for Starter Templates. */ class Ai_Builder_Compatibility_Suretriggers { /** * Instance * * @access private * @var object Class object. * @since 4.0.8 */ private static $instance = null; /** * Constructor. */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'suretriggers_activation' ), 10 ); } /** * Initiator * * @since 4.0.8 * @return object initialized object of class. */ public static function get_instance() { if ( ! self::$instance instanceof Ai_Builder_Compatibility_Suretriggers ) { self::$instance = new self(); } return self::$instance; } /** * Disable redirect after installing and activating UABB. * * @since 4.0.8 * @param string $plugin_init The path to the plugin file that was just activated. * @return void */ public function suretriggers_activation( $plugin_init ) { if ( 'suretriggers/suretriggers.php' === $plugin_init ) { delete_transient( 'st-redirect-after-activation' ); } } } /** * Kicking this off by calling 'get_instance()' method */ Ai_Builder_Compatibility_Suretriggers::get_instance(); inc/compatibility/sureforms/ai-builder-compatibility-sureforms.php 0000644 00000003411 15104046434 0021633 0 ustar 00 <?php /** * AI Builder Compatibility for 'SureForms' * * @see https://wordpress.org/plugins/sureforms/ * * @package AI Builder * @since 1.2.9 */ namespace AiBuilder\Inc\Compatibility\SureCart; if ( ! class_exists( 'Ai_Builder_Compatibility_SureForms' ) ) { /** * SureCart Compatibility * * @since 1.2.9 */ class Ai_Builder_Compatibility_SureForms { /** * Instance * * @access private * @var object Class object. * @since 1.2.9 */ private static $instance = null; /** * Constructor * * @since 1.2.9 */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'activation' ), 10 ); add_filter( 'srfm_enable_redirect_activation', array( $this, 'redirect_compatibility' ), 10, 1 ); } /** * Initiator * * @since 1.2.9 * @return object initialized object of class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Stop the plugin activation redirection. * * @since 1.2.13 * * @param bool $do_redirect is redirect. * @return bool */ public function redirect_compatibility( $do_redirect ) { if ( astra_sites_has_import_started() ) { return false; } return $do_redirect; } /** * Stop the plugin activation redirection. * * @since 1.0.15 * @param string $plugin_init The path to the plugin file that was just activated. * @return void */ public function activation( $plugin_init ) { if ( 'sureforms/sureforms.php' === $plugin_init ) { update_option( '__srfm_do_redirect', false ); } } } /** * Kicking this off by calling 'instance()' method */ Ai_Builder_Compatibility_SureForms::instance(); } inc/compatibility/surecart/ai-builder-compatibility-surecart.php 0000644 00000006760 15104046434 0021253 0 ustar 00 <?php /** * AI Builder Compatibility for 'SureCart' * * @see https://wordpress.org/plugins/surecart/ * * @package AI Builder * @since 3.3.0 */ namespace AiBuilder\Inc\Compatibility\SureCart; if ( ! class_exists( 'Ai_Builder_Compatibility_SureCart' ) ) { /** * SureCart Compatibility * * @since 3.3.0 */ class Ai_Builder_Compatibility_SureCart { /** * Instance * * @access private * @var object Class object. * @since 3.3.0 */ private static $instance = null; /** * Constructor * * @since 3.3.0 */ public function __construct() { add_action( 'init', array( $this, 'disable_default_surecart_pages_creation' ), 2 ); add_action( 'astra_sites_import_complete', array( $this, 'get_all_pages' ), 10 ); add_action( 'astra_sites_after_plugin_activation', array( $this, 'activation' ), 10 ); } /** * Initiator * * @since 3.3.0 * @return object initialized object of class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Set the source to 'starter-templates' on activation. * * @since 1.0.15 * @param string $plugin_init The path to the plugin file that was just activated. * @return void */ public function activation( $plugin_init ) { if ( 'surecart/surecart.php' === $plugin_init ) { update_option( 'surecart_source', 'starter_templates', false ); } } /** * Retrieve all pages * * @since 3.3.0 * @return void */ public function get_all_pages() { if ( ! is_plugin_active( 'surecart/surecart.php' ) ) { return; } // Retrieve all pages. $pages = get_pages(); if ( is_array( $pages ) ) { foreach ( $pages as $page ) { // Get the page ID. $page_id = (string) $page->ID; $page_content = $page->post_content; $this->check_page_types_and_update_options( $page_id, $page_content ); } } } /** * Check surecart page types and update options * * @param string $page_id The page ID. * @param string $page_content The page content. * @since 3.3.0 * @return void */ public function check_page_types_and_update_options( $page_id, $page_content ) { if ( strpos( $page_content, 'wp:surecart/checkout' ) !== false ) { update_option( 'surecart_checkout_page_id', $page_id ); // Extract the sc_form id using regular expressions. preg_match( '/checkout-form[^"]+\\{\\\\"id\\\\":(\d+)\\}/i', $page_content, $matches ); $number = isset( $matches[1] ) ? $matches[1] : ''; if ( ! empty( $number ) ) { update_option( 'surecart_checkout_sc_form_id', $number ); } } elseif ( strpos( $page_content, 'wp:surecart/dashboard' ) !== false ) { update_option( 'surecart_dashboard_page_id', $page_id ); } elseif ( strpos( $page_content, 'wp:surecart/product' ) !== false ) { update_option( 'surecart_shop_page_id', $page_id ); } } /** * Restrict SureCart Pages Creation process * * Why? SureCart creates set of pages on it's activation * These pages are re created via our XML import step. * In order to avoid the duplicacy we restrict these page creation process. * * @since 3.3.0 * @return void */ public function disable_default_surecart_pages_creation() { if ( astra_sites_has_import_started() ) { add_filter( 'surecart/seed/all', '__return_false' ); } } } /** * Kicking this off by calling 'instance()' method */ Ai_Builder_Compatibility_SureCart::instance(); } inc/compatibility/uae/ai-builder-compatibility-uae.php 0000644 00000002617 15104046434 0017114 0 ustar 00 <?php /** * AI Builder Compatibility for 'UAE' * * @package AI Builder * @since 1.2.37 */ namespace AiBuilder\Inc\Compatibility\UAE; defined( 'ABSPATH' ) || exit; if ( ! class_exists( 'Ai_Builder_Compatibility_UAE' ) ) { /** * UAE Compatibility * * @since 1.2.37 */ class Ai_Builder_Compatibility_UAE { /** * Instance * * @access private * @var object Class object. * @since 1.2.37 */ private static $instance = null; /** * Constructor * * @since 1.2.37 */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'activation' ), 10, 1 ); } /** * Initiator * * @since 1.2.37 * @return object initialized object of class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Disable redirection for UAE plugin when activated via Starter templates import process. * * @since 1.2.37 * @param string $plugin_init The plugin init. * @return void */ public function activation( $plugin_init ) { if ( 'ultimate-elementor/ultimate-elementor.php' === $plugin_init && astra_sites_has_import_started() ) { delete_option( 'uaepro_start_onboarding' ); } } } /** * Kicking this off by calling 'instance()' method */ Ai_Builder_Compatibility_UAE::instance(); } inc/compatibility/elementor/ai-builder-compatibility-elementor.php 0000644 00000012321 15104046434 0021545 0 ustar 00 <?php /** * AI Builder Compatibility for 'Elementor' * * @package AI Builder * @since 1.2.47 */ namespace AI_Builder\Inc\Compatibility\Elementor; defined( 'ABSPATH' ) || exit; if ( ! class_exists( '\Elementor\Plugin' ) ) { return; } if ( ! class_exists( 'AI_Builder_Compatibility_Elementor' ) ) { /** * Elementor Compatibility * * @since 1.2.47 */ class AI_Builder_Compatibility_Elementor { /** * Instance * * @access private * @var object Class object. * @since 1.2.47 */ private static $instance; /** * Constructor * * @since 1.2.47 * @return void */ public function __construct() { /** * Add Slashes * * @todo Elementor already have below code which works on defining the constant `WP_LOAD_IMPORTERS`. * After defining the constant `WP_LOAD_IMPORTERS` in WP CLI it was not works. * Try to remove below duplicate code in future. */ if ( ! wp_doing_ajax() || ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.0.0', '>=' ) ) ) { remove_filter( 'wp_import_post_meta', array( 'Elementor\Compatibility', 'on_wp_import_post_meta' ) ); remove_filter( 'wxr_importer.pre_process.post_meta', array( 'Elementor\Compatibility', 'on_wxr_importer_pre_process_post_meta' ) ); add_filter( 'wp_import_post_meta', array( $this, 'on_wp_import_post_meta' ) ); add_filter( 'wxr_importer.pre_process.post_meta', array( $this, 'on_wxr_importer_pre_process_post_meta' ) ); } add_action( 'astra_sites_before_delete_imported_posts', array( $this, 'force_delete_kit' ), 10, 2 ); add_action( 'astra_sites_before_sse_import', array( $this, 'disable_attachment_metadata' ) ); add_action( 'init', array( $this, 'init' ) ); add_action( 'astra_sites_after_plugin_activation', array( $this, 'disable_elementor_redirect' ) ); } /** * Initiator * * @since 1.2.47 * @return object initialized object of class. */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Disable Elementor redirect. * * @since 1.2.47 * @return void. */ public function disable_elementor_redirect() { $elementor_redirect = get_transient( 'elementor_activation_redirect' ); if ( ! empty( $elementor_redirect ) && '' !== $elementor_redirect ) { delete_transient( 'elementor_activation_redirect' ); } } /** * Remove the transient update check for plugins callback from Elementor. * This reduces the extra code execution for Elementor. * * @since 1.2.47 * @return void */ public function init() { // @phpstan-ignore-next-line if ( astra_sites_has_import_started() && null !== \Elementor\Plugin::$instance->admin ) { remove_filter( 'pre_set_site_transient_update_plugins', array( \Elementor\Plugin::$instance->admin->get_component( 'canary-deployment' ), 'check_version' ) ); // @phpstan-ignore-line } } /** * Disable the attachment metadata * * @since 1.2.47 * @return void */ public function disable_attachment_metadata() { remove_filter( 'wp_update_attachment_metadata', array( \Elementor\Plugin::$instance->uploads_manager->get_file_type_handlers( 'svg' ), // @phpstan-ignore-line 'set_svg_meta_data', ), 10 ); } /** * Force Delete Elementor Kit * * Delete the previously imported Elementor kit. * * @param int $post_id Post name. * @param string $post_type Post type. * * @since 1.2.47 * @return void */ public function force_delete_kit( $post_id = 0, $post_type = '' ) { if ( ! $post_id ) { return; } if ( 'elementor_library' === $post_type ) { $_GET['force_delete_kit'] = true; } } /** * Process post meta before WP importer. * * Normalize Elementor post meta on import, We need the `wp_slash` in order * to avoid the unslashing during the `add_post_meta`. * * Fired by `wp_import_post_meta` filter. * * @param array<int, array{key: string, value: mixed}> $post_meta Post meta. * * @since 1.2.47 * @access public * * @return array<int, array{key: string, value: mixed}> Updated post meta. */ public function on_wp_import_post_meta( $post_meta ) { foreach ( $post_meta as &$meta ) { if ( '_elementor_data' === $meta['key'] ) { $meta['value'] = wp_slash( $meta['value'] ); break; } } return $post_meta; } /** * Process post meta before WXR importer. * * Normalize Elementor post meta on import with the new WP_importer, We need * the `wp_slash` in order to avoid the unslashing during the `add_post_meta`. * * Fired by `wxr_importer.pre_process.post_meta` filter. * * @since 1.2.47 * @access public * * @param array{key: string, value: mixed} $post_meta Post meta. * * @return array{key: string, value: mixed} Updated post meta. */ public function on_wxr_importer_pre_process_post_meta( $post_meta ) { if ( '_elementor_data' === $post_meta['key'] ) { $post_meta['value'] = wp_slash( $post_meta['value'] ); } return $post_meta; } } /** * Kicking this off by calling 'get_instance()' method */ AI_Builder_Compatibility_Elementor::get_instance(); } inc/compatibility/woocommerce-payments/ai-builder-compatibility-woocommerce-payments.php 0000644 00000034134 15104046434 0026121 0 ustar 00 <?php /** * AI Builder Compatibility for 'WooCommerce Payments' * * @see https://wordpress.org/plugins/woocommerce-payments/ * * @package AI Builder * @since 1.2.37 */ if ( ! class_exists( 'Ai_Builder_Compatibility_WooCommerce_Payments' ) ) { /** * WooCommerce Payments Compatibility * * @since 1.2.37 */ class Ai_Builder_Compatibility_WooCommerce_Payments { /** * Instance * * @access private * @var self Class object. * @since 1.2.37 */ private static $instance; /** * Constructor * * @since 1.2.37 */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'woo_payments_activate' ), 10, 2 ); // Bail early if the WooCommerce Payments plugin is not active. if ( ! is_plugin_active( 'woocommerce-payments/woocommerce-payments.php' ) ) { return; } add_action( 'admin_notices', array( $this, 'woo_payments_admin_notice' ), 9 ); add_action( 'wp_ajax_dismiss_woopayments_notice', array( $this, 'dismiss_woopayments_notice' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_init', array( $this, 'maybe_append_woopayments_ref' ) ); add_filter( 'cpsw_notices_add_args', array( $this, 'hide_cpsw_stripe_connect_notice' ), 10, 1 ); } /** * Initiator * * @since 1.2.37 * @return self Initialized object of the class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Retrieves the WooCommerce Payments reference ID. * * @since 1.2.37 * @return string The WooCommerce Payments reference ID. */ public static function get_woopayments_ref_id() { return 'bsf-2025'; } /** * Check if WooPayments is configured and connected to Stripe. * * @since 1.2.38 * @return bool True if WooPayments is active and connected to Stripe, false otherwise. */ public static function is_woo_payments_configured() { // Check if WCPay account is connected to Stripe. // @phpstan-ignore-next-line - Dynamic class check. if ( class_exists( 'WC_Payments' ) && method_exists( 'WC_Payments', 'get_account_service' ) ) { $account_service = WC_Payments::get_account_service(); if ( is_object( $account_service ) && method_exists( $account_service, 'is_stripe_connected' ) ) { return $account_service->is_stripe_connected(); } } return false; } /** * Returns an array of allowed screen IDs for displaying notices or performing trigger actions. * * @since 1.2.38 * @return array<string> An array of allowed screen IDs. */ public static function allowed_screen_ids() { return array( 'dashboard', // WordPress Dashboard. 'plugins', // Plugins Page. 'plugins-network', // Network Plugins Page. 'edit-product', // Products Page. 'edit-shop_coupon', // Coupons Page. 'woocommerce_page_wc-orders', // WooCommerce - Orders Page. 'woocommerce_page_wc-reports', // WooCommerce - Reports Page. 'woocommerce_page_wc-status', // WooCommerce - Status Page. 'woocommerce_page_wc-settings', // WooCommerce - Settings Page. 'woocommerce_page_woo-cart-abandonment-recovery', // Cart Abandonment Recovery Page. ); } /** * Enqueue scripts and localize data. * * @since 1.2.37 * @return void */ public function enqueue_scripts() { $can_show_notice = $this->can_show_payment_notice(); // Check if we're on WooPayments connect page. // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only GET used safely here. $is_woo_payments_page = isset( $_GET['page'], $_GET['path'] ) && 'wc-admin' === sanitize_text_field( $_GET['page'] ) && '/payments/connect' === sanitize_text_field( rawurldecode( $_GET['path'] ) ); if ( ! $can_show_notice && ! $is_woo_payments_page ) { return; } wp_register_script( 'ai-builder-woopayments', AI_BUILDER_URL . 'inc/assets/js/woopayments.js', array( 'jquery' ), AI_BUILDER_VER, true ); wp_localize_script( 'ai-builder-woopayments', 'aiBuilderWooPayments', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'ajaxNonce' => wp_create_nonce( 'woopayments_nonce' ), 'dismissingText' => __( 'To complete your store setup and start selling, you must connect WooPayments now. Without it, your customers won\'t be able to pay.', 'astra-sites' ), 'dismissedCount' => class_exists( 'Astra_Sites_Page' ) ? Astra_Sites_Page::get_instance()->get_setting( 'woopayments_banner_dismissed_count', 0 ) : 0, ) ); wp_enqueue_script( 'ai-builder-woopayments' ); } /** * Hide CPSW Stripe Connect Notice. * * @since 1.2.37 * @param array<string, mixed> $args Notice arguments. * @return array<string, mixed>|null Modified notice arguments or null to hide. */ public function hide_cpsw_stripe_connect_notice( array $args ) { if ( 'connect_stripe_notice' === $args['id'] && $this->can_show_payment_notice( false ) ) { return null; // Hide the notice. } return $args; } /** * Dismiss WooCommerce Payments notice. * * @since 1.2.37 * @return void */ public function dismiss_woopayments_notice() { // Verify nonce. if ( ! isset( $_POST['_security'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_security'] ) ), 'woopayments_nonce' ) ) { wp_send_json_error( 'Invalid nonce' ); } // Get notice ID. $notice_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : ''; if ( empty( $notice_id ) ) { wp_send_json_error( 'Notice ID is required' ); } $show_after = 72 * 60 * 60; // 72 hours in seconds. // Set a transient that expires in 72 hours (259200 seconds) - to dismiss the notice. set_transient( 'astra_sites_woopayments_notice_dismissed', true, $show_after ); if ( class_exists( 'Astra_Sites_Page' ) ) { // Update the setting to track dismissed count. $dismissed_count = Astra_Sites_Page::get_instance()->get_setting( 'woopayments_banner_dismissed_count', 0 ); Astra_Sites_Page::get_instance()->update_settings( array( 'woopayments_banner_dismissed_count' => $dismissed_count + 1, ) ); } wp_send_json_success( 'Notice dismissed successfully' ); } /** * Determines if the payment notice should be shown. * * This method checks various conditions to decide if the payment notice should be displayed. * It verifies the user's capability, WooPayments configuration, notice dismissal status, Astra Sites import completion, * and the current screen to determine if the notice should be shown. * * @since 1.2.37 * @param bool $enable_screen_check Flag to enable or disable the screen check. * * @return bool Returns true if the notice should be shown, false otherwise. */ public function can_show_payment_notice( $enable_screen_check = true ) { // If the user does not have the required capability, return false. if ( ! current_user_can( 'manage_options' ) ) { return false; } // Check if the banner was dismissed and the transient is still valid. if ( get_transient( 'astra_sites_woopayments_notice_dismissed' ) ) { return false; } // If the Astra Sites import is not complete, return false. if ( 'yes' !== get_option( 'astra_sites_import_complete', 'no' ) ) { return false; } // If WooPayments is already configured, no need to show the notice. if ( self::is_woo_payments_configured() ) { return false; } // Skip screen check if disabled. if ( ! $enable_screen_check ) { return true; } // Screen check. $screen = get_current_screen(); return $screen && in_array( $screen->id, self::allowed_screen_ids(), true ); } /** * Get Stripe Connect URL. * * @since 1.2.37 * @return string */ public function get_stripe_connect_url() { return admin_url( add_query_arg( array( 'page' => 'wc-admin', 'path' => '/payments/connect', 'woopayments-ref' => self::get_woopayments_ref_id(), ), 'admin.php' ) ); } /** * Disable redirect after installing and activating WooCommerce Payments. * * @param string $plugin_init Plugin init file used for activation. * @param array<string, mixed> $data Data. * * @since 1.2.37 * @return void */ public function woo_payments_activate( $plugin_init, $data = array() ) { if ( 'woocommerce-payments/woocommerce-payments.php' === $plugin_init ) { // Prevent showing the banner if plugin was already active. if ( isset( $data['was_plugin_active'] ) && $data['was_plugin_active'] ) { return; } delete_option( 'wcpay_should_redirect_to_onboarding' ); } } /** * This method is responsible for displaying an admin notice to the user, prompting them to connect their WooCommerce Payments account. * It checks if the conditions are met to show the notice, and if so, it outputs the notice content. * * @since 1.2.37 * @return void */ public function woo_payments_admin_notice() { // Bail early if the notice can not be shown. if ( ! $this->can_show_payment_notice() ) { return; } // Connect SVG image path. $image_path = esc_url( AI_BUILDER_URL . 'inc/assets/images/payments-connect.png' ); $output = sprintf( ' <div class="woop-notice-content"> <div class="woop-notice-heading"> %2$s </div> <div class="woop-notice-description"> %3$s </div> <div class="woop-notice-action-container"> <a href="%4$s" class="woop-notice-btn" data-source="banner"> %5$s </a> </div> </div> <div class="woop-notice-image" style="display: flex;"> <img src="%1$s" class="notice-image" alt="Connect to Stripe" itemprop="logo"> </div> ', $image_path, esc_html__( 'You’re One Step Away from Accepting Payments with WooPayments — Fast, Easy & Free!', 'astra-sites' ), sprintf( /* translators: %s: WooPayments for WooCommerce text with strong tag */ __( 'Your store is ready to sell! Connect %s now to securely accept credit cards, Apple Pay, and more — with zero setup fees and instant integration.', 'astra-sites' ), '<strong>' . __( 'WooPayments', 'astra-sites' ) . '</strong>' ), esc_url( $this->get_stripe_connect_url() ), esc_html__( 'Start Accepting Payments', 'astra-sites' ) ); ?> <style> #connect_woop_notice.notice-info.mega-notice.woop-dismissible-notice { position: relative; display: flex; border: 1px solid #e6daf9; gap: 10%; align-items: center; padding: 34px !important; background: linear-gradient(90deg, #fff 23.33%, #F2EAFF80 47.42%); box-shadow: 0 2px 8px -2px #00000014; } #connect_woop_notice .woop-notice-content { font-size: 16px; font-weight: 400; line-height: 26px; text-align: left; margin-left: 0; display: flex; flex-direction: column; gap: 15px; width: 65%; } #connect_woop_notice .woop-notice-heading { font-size: 20px; font-weight: 600; line-height: 32px; text-align: left; margin: 0; } #connect_woop_notice .woop-notice-action-container { display: flex; align-items: center; column-gap: 20px; margin-top: 10px; } #connect_woop_notice .woop-notice-action-container a { background: #873EFF; box-shadow: 0 1px 2px 0 #0000000d; color: #fff !important; border-color: #873EFF; padding: 14px 16px 14px 16px; border-radius: 6px; font-size: 16px; font-weight: 500; line-height: 16px; text-align: center; text-decoration: none; transition: 0.2s ease; } #connect_woop_notice .woop-notice-action-container a:hover { background-color: #5f2db1; } #connect_woop_notice .woop-notice-image{ width: 35%; display: flex; justify-content: center; align-items: center; } #connect_woop_notice .woop-notice-image img { width: 56%; } </style> <div id="connect_woop_notice" class="notice-info mega-notice woop-dismissible-notice woop-notice woop-custom-notice notice"> <button type="button" class="notice-dismiss"></button> <?php echo wp_kses_post( $output ); ?> </div> <?php } /** * This method checks if the WooCommerce Payments reference option is not set and if the current page is the WooCommerce Payments connect page. * If both conditions are true, it appends the WooCommerce Payments reference ID to the URL query string. * This is done to ensure that the reference ID is included in the connection process for WooCommerce Payments. * * @since 1.2.37 * @return void */ public function maybe_append_woopayments_ref() { // Bail early if the WooCommerce Payments plugin was not activated through the Starter Templates import process and was already activated on the site. if ( ! class_exists( 'Astra_Sites_Page' ) || ! Astra_Sites_Page::get_instance()->get_setting( 'woopayments_ref' ) ) { return; } // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only GET used safely here. if ( is_admin() && isset( $_GET['page'], $_GET['path'] ) && 'wc-admin' === sanitize_text_field( $_GET['page'] ) && '/payments/connect' === sanitize_text_field( rawurldecode( $_GET['path'] ) ) && ! isset( $_GET['woopayments-ref'] ) ) { // phpcs:enable WordPress.Security.NonceVerification.Recommended -- Read-only GET used safely here. $ref_value = self::get_woopayments_ref_id(); // Preserve all existing query vars. // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Query string is being modified safely. $query_args = $_GET; $query_args['woopayments-ref'] = $ref_value; // Build the URL with updated args. $new_url = admin_url( 'admin.php' ) . '?' . http_build_query( $query_args ); // Perform safe redirect and exit. wp_safe_redirect( esc_url_raw( $new_url ) ); exit; } } } /** * Kicking this off by calling 'instance()' method */ Ai_Builder_Compatibility_WooCommerce_Payments::instance(); } inc/compatibility/suremail/ai-builder-compatibility-suremail.php 0000644 00000002524 15104046434 0021227 0 ustar 00 <?php /** * AI Builder Compatibility for 'SureMail' * * @see https://wordpress.org/plugins/sureMail/ * * @package AI Builder * @since 1.2.26 */ namespace AiBuilder\Inc\Compatibility\SureCart; if ( ! class_exists( 'Ai_Builder_Compatibility_SureMail' ) ) { /** * SureMail Compatibility * * @since 1.2.26 */ class Ai_Builder_Compatibility_SureMail { /** * Instance * * @access private * @var object Class object. * @since 1.2.26 */ private static $instance = null; /** * Constructor * * @since 1.2.26 */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'activation' ), 10 ); } /** * Initiator * * @since 1.2.26 * @return object initialized object of class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Stop the plugin activation redirection. * * @since 1.2.26 * @param string $plugin_init Plugin init file. * @return void */ public function activation( $plugin_init ) { if ( 'suremails/suremails.php' === $plugin_init ) { update_option( 'suremails_do_redirect', false ); } } } /** * Kicking this off by calling 'instance()' method */ Ai_Builder_Compatibility_SureMail::instance(); } inc/compatibility/uae-lite/ai-builder-compatibility-uae-lite.php 0000644 00000002671 15104046434 0021002 0 ustar 00 <?php /** * AI Builder Compatibility for 'UAE Lite' * * @package AI Builder * @since 1.2.37 */ namespace AiBuilder\Inc\Compatibility\UAE_Lite; defined( 'ABSPATH' ) || exit; if ( ! class_exists( 'Ai_Builder_Compatibility_UAE_Lite' ) ) { /** * UAE Lite Compatibility * * @since 1.2.37 */ class Ai_Builder_Compatibility_UAE_Lite { /** * Instance * * @access private * @var object Class object. * @since 1.2.37 */ private static $instance = null; /** * Constructor * * @since 1.2.37 */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'activation' ), 10, 1 ); } /** * Initiator * * @since 1.2.37 * @return object initialized object of class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Disable redirection for UAE Lite plugin when activated via Starter templates import process. * * @since 1.2.37 * @param string $plugin_init The plugin init. * @return void */ public function activation( $plugin_init ) { if ( 'header-footer-elementor/header-footer-elementor.php' === $plugin_init && astra_sites_has_import_started() ) { delete_option( 'hfe_start_onboarding' ); } } } /** * Kicking this off by calling 'instance()' method */ Ai_Builder_Compatibility_UAE_Lite::instance(); } inc/compatibility/surerank/ai-builder-compatibility-surerank.php 0000644 00000002502 15104046434 0021245 0 ustar 00 <?php /** * AI Builder Compatibility for 'SureRank'. * * @package AI Builder * @since 1.2.44 */ if ( ! class_exists( 'Ai_Builder_Compatibility_SureRank' ) ) { /** * SureRank Compatibility. * * @since 1.2.44 */ class Ai_Builder_Compatibility_SureRank { /** * Instance * * @access private * @var object Class object. * @since 1.2.44 */ private static $instance; /** * Constructor * * @since 1.2.44 */ public function __construct() { add_action( 'astra_sites_after_plugin_activation', array( $this, 'disable_surerank_redirection' ) ); } /** * Initiator * * @since 1.2.44 * @return object initialized object of class. */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Disables SureRank redirection during plugin activation. * * @param string $plugin_init The path to the plugin file that was just activated. * * @since 1.2.44 * @return void */ public function disable_surerank_redirection( $plugin_init ) { if ( 'surerank/surerank.php' === $plugin_init ) { delete_option( 'surerank_redirect_on_activation' ); } } } /** * Kicking this off by calling 'instance()' method */ Ai_Builder_Compatibility_SureRank::instance(); } inc/classes/functions.php 0000644 00000012116 15104046434 0011475 0 ustar 00 <?php /** * Functions * * @since 1.0.0 * @package Astra Sites */ use STImporter\Importer\ST_Importer_File_System; use STImporter\Importer\ST_Importer_Helper; if ( ! function_exists( 'astra_sites_error_log' ) ) { /** * Error Log * * A wrapper function for the error_log() function. * * @since 2.0.0 * * @param mixed $message Error message. * @return void */ function astra_sites_error_log( $message = '' ) { if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { if ( is_array( $message ) ) { $message = wp_json_encode( $message ); } if ( apply_filters( 'astra_sites_debug_logs', false ) && is_string( $message ) ) { error_log( $message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is for the debug logs while importing. This is conditional and will not be logged in the debug.log file for normal users. } } } } if ( ! function_exists( 'astra_sites_get_suggestion_link' ) ) { /** * Get suggestion link. * * @since 2.6.1 * * @return string. */ function astra_sites_get_suggestion_link() { $white_label_link = 'https://wpastra.com/sites-suggestions/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=suggestions'; return apply_filters( 'astra_sites_suggestion_link', $white_label_link ); } } if ( ! function_exists( 'astra_sites_is_valid_image' ) ) { /** * Check for the valid image * * @param string $link The Image link. * * @since 2.6.2 * @return int|false */ function astra_sites_is_valid_image( $link = '' ) { return preg_match( '/^((https?:\/\/)|(www\.))([a-z0-9-].?)+(:[0-9]+)?\/[\w\-\@]+\.(jpg|png|gif|jpeg|svg)\/?$/i', $link ); } } if ( ! function_exists( 'astra_get_site_data' ) ) { /** * Returns the value of the index for the Site Data * * @param string $index The index value of the data. * * @since 2.6.14 * @return mixed */ function astra_get_site_data( $index = '' ) { $demo_data = array(); if ( class_exists( 'STImporter\Importer\ST_Importer_File_System' ) ) { $demo_data = ST_Importer_File_System::get_instance()->get_demo_content(); } if ( ! empty( $demo_data ) && isset( $demo_data[ $index ] ) ) { return $demo_data[ $index ]; } return ''; } } /** * Get all the posts to be reset. * * @since 3.0.3 * @return array<int, string> */ function astra_sites_get_reset_post_data() { global $wpdb; return $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_post'" ); } /** * Get API params * * @since 2.7.3 * @return array<string, mixed> */ function astra_sites_get_api_params() { return apply_filters( 'astra_sites_api_params', array( 'purchase_key' => '', 'site_url' => get_site_url(), 'per-page' => 15, 'template_status' => '', 'version' => ASTRA_SITES_VER, ) ); } /** * Check if Import for Astra Site is in progress * * @since 3.0.21 * @return bool */ function astra_sites_has_import_started() { $has_import_started = get_option( 'astra_sites_import_started' ); if ( 'yes' === $has_import_started ) { return true; } return false; } /** * Remove the post excerpt * * @param int $post_id The post ID. * @return void * @since 3.1.0 */ function astra_sites_empty_post_excerpt( $post_id = 0 ) { if ( ! $post_id ) { return; } wp_update_post( array( 'ID' => $post_id, 'post_excerpt' => '', ) ); } /** * Get the WP Forms URL. * * @since 3.2.4 * @param int $id The template ID. * @return string */ function astra_sites_get_wp_forms_url( $id ) { $demo_data = get_option( 'astra_sites_import_elementor_data_' . $id, array() ); if ( empty( $demo_data ) ) { return ''; } if ( is_array( $demo_data ) && isset( $demo_data['type'] ) ) { $type = $demo_data['type']; if ( 'site-pages' === $type && isset( $demo_data['astra-site-wpforms-path'] ) ) { return $demo_data['astra-site-wpforms-path']; } if ( 'astra-blocks' === $type && isset( $demo_data['post-meta'] ) ) { return $demo_data['post-meta']['astra-site-wpforms-path']; } } return ''; } /** * Check is valid URL * * @param string $url The site URL. * * @since 2.7.1 * @return bool */ function astra_sites_is_valid_url( $url = '' ) { if ( empty( $url ) ) { return false; } $parse_url = wp_parse_url( $url ); if ( empty( $parse_url ) || ! is_array( $parse_url ) ) { return false; } $valid_hosts = apply_filters( 'astra_sites_valid_url', array( 'lh3.googleusercontent.com', 'pixabay.com', ) ); $ai_site_url = get_option( 'ast_ai_import_current_url', '' ); if ( is_string( $ai_site_url ) && '' !== $ai_site_url ) { $url = wp_parse_url( $ai_site_url ); $valid_hosts[] = $url ? $url['host'] : ''; } $api_domain_parse_url = ''; if ( class_exists( 'STImporter\Importer\ST_Importer_Helper' ) ) { $api_domain_parse_url = wp_parse_url( ST_Importer_Helper::get_api_domain() ); } $valid_hosts[] = is_array( $api_domain_parse_url ) && isset( $api_domain_parse_url['host'] ) ? $api_domain_parse_url['host'] : ''; // Validate host. if ( in_array( $parse_url['host'], $valid_hosts, true ) ) { return true; } return false; } inc/classes/zipwp/class-ai-builder-zipwp-integration.php 0000644 00000015141 15104046434 0017447 0 ustar 00 <?php /** * Ai Builder * * @since 1.0.0 * @package Ai Builder */ namespace AiBuilder\Inc\Classes\Zipwp; use AiBuilder\Inc\Traits\Instance; /** * ZipWP Integration */ class Ai_Builder_ZipWP_Integration { use Instance; /** * Constructor * * @since 4.0.0 */ public function __construct() { add_action( 'admin_init', array( $this, 'save_auth_token' ) ); } /** * Save auth token * * @since 4.0.0 * @return void */ public function save_auth_token() { global $pagenow; if ( ! is_admin() || ! isset( $_GET['page'] ) ) { return; } // Check if we are on the starter templates page. if ( 'themes.php' !== $pagenow || 'ai-builder' !== $_GET['page'] ) { return; } if ( ! isset( $_GET['security'] ) ) { return; } $security = sanitize_text_field( $_GET['security'] ); // Verify the nonce. if ( ! wp_verify_nonce( $security, 'zipwp-auth-nonce' ) ) { return; } if ( isset( $_GET['token'] ) && isset( $_GET['email'] ) && isset( $_GET['credit_token'] ) ) { $spec_ai_settings = $this->get_setting(); if ( ! is_array( $spec_ai_settings ) ) { $spec_ai_settings = array(); } // Update the auth token if needed. if ( isset( $_GET['credit_token'] ) && is_string( $_GET['credit_token'] ) ) { $spec_ai_settings['auth_token'] = $this->encrypt( sanitize_text_field( $_GET['credit_token'] ) ); } // Update the Zip token if needed. if ( isset( $_GET['token'] ) && is_string( $_GET['token'] ) ) { $spec_ai_settings['zip_token'] = $this->encrypt( sanitize_text_field( $_GET['token'] ) ); } // Update the email if needed. if ( isset( $_GET['email'] ) && is_string( $_GET['email'] ) ) { $spec_ai_settings['email'] = sanitize_email( $_GET['email'] ); } update_option( 'zip_ai_settings', $spec_ai_settings ); } //phpcs:enable WordPress.Security.NonceVerification.Recommended } /** * Get Saved settings. * * @since 4.0.0 * @return array<string, string>|mixed */ public static function get_setting() { return get_option( 'zip_ai_settings', array( 'auth_token' => '', 'zip_token' => '', 'email' => '', ) ); } /** * Encrypt data using base64. * * @param string $input The input string which needs to be encrypted. * @since 4.0.0 * @return string The encrypted string. */ public static function encrypt( $input ) { // If the input is empty or not a string, then abandon ship. if ( empty( $input ) || ! is_string( $input ) ) { return ''; } // Encrypt the input and return it. $base_64 = base64_encode( $input ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode return rtrim( $base_64, '=' ); } /** * Get Business details. * * @since 4.0.0 * @param string $key options name. * @return array<string, mixed>|array<int, string>|string|array<string>|array<string,string> */ public static function get_business_details( $key = '' ) { $details = get_option( 'zipwp_user_business_details', array( 'business_name' => '', 'business_address' => '', 'business_phone' => '', 'business_email' => '', 'business_category' => '', 'business_category_name' => '', 'business_description' => '', 'templates' => array(), 'language' => '', 'images' => array(), 'image_keyword' => array(), 'social_profiles' => array(), ) ); if ( ! is_array( $details ) ) { $details = array(); } $details = array( 'business_name' => ! empty( $details['business_name'] ) ? $details['business_name'] : '', 'business_address' => ! empty( $details['business_address'] ) ? $details['business_address'] : '', 'business_phone' => ! empty( $details['business_phone'] ) ? $details['business_phone'] : '', 'business_email' => ! empty( $details['business_email'] ) ? $details['business_email'] : '', 'business_category' => ! empty( $details['business_category'] ) ? $details['business_category'] : '', 'business_category_name' => ! empty( $details['business_category_name'] ) ? $details['business_category_name'] : '', 'business_description' => ! empty( $details['business_description'] ) ? $details['business_description'] : '', 'templates' => ! empty( $details['templates'] ) ? $details['templates'] : array(), 'language' => ! empty( $details['language'] ) ? $details['language'] : '', 'images' => ! empty( $details['images'] ) ? $details['images'] : array(), 'social_profiles' => ! empty( $details['social_profiles'] ) ? $details['social_profiles'] : array(), 'image_keyword' => ! empty( $details['image_keyword'] ) ? $details['image_keyword'] : array(), ); if ( ! empty( $key ) ) { return isset( $details[ $key ] ) ? $details[ $key ] : array(); } return $details; } /** * Get Saved Token. * * @since 4.0.0 * @return string */ public static function get_token() { $token_details = get_option( 'zip_ai_settings', array( 'auth_token' => '', 'zip_token' => '', 'email' => '', ) ); return is_array( $token_details ) && isset( $token_details['zip_token'] ) ? self::decrypt( $token_details['zip_token'] ) : ''; } /** * Get Saved Auth Token. * * @since 4.1.0 * @return string */ public static function get_auth_token() { $token_details = get_option( 'zip_ai_settings', array( 'auth_token' => '', 'zip_token' => '', 'email' => '', ) ); return is_array( $token_details ) && isset( $token_details['auth_token'] ) ? self::decrypt( $token_details['auth_token'] ) : ''; } /** * Get Saved ZipWP user email. * * @since 4.0.0 * @return string */ public static function get_zip_user_email() { $token_details = get_option( 'zip_ai_settings', array( 'auth_token' => '', 'zip_token' => '', 'email' => '', ) ); return is_array( $token_details ) && isset( $token_details['email'] ) ? $token_details['email'] : ''; } /** * Decrypt data using base64. * * @param string $input The input string which needs to be decrypted. * @since 4.0.0 * @return string The decrypted string. */ public static function decrypt( $input ) { // If the input is empty or not a string, then abandon ship. if ( empty( $input ) || ! is_string( $input ) ) { return ''; } // Decrypt the input and return it. $base_64 = $input . str_repeat( '=', strlen( $input ) % 4 ); return base64_decode( $base_64 ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode } } Ai_Builder_ZipWP_Integration::Instance(); inc/classes/zipwp/class-ai-builder-zipwp-api.php 0000644 00000155522 15104046434 0015705 0 ustar 00 <?php /** * Ai Builder * * @since 1.0.0 * @package Ai Builder */ namespace AiBuilder\Inc\Classes\Zipwp; use AiBuilder\Inc\Classes\Ai_Builder_Importer_Log; use AiBuilder\Inc\Traits\Helper; use AiBuilder\Inc\Traits\Instance; use STImporter\Importer\ST_Importer_File_System; use STImporter\Importer\WXR_Importer\ST_WXR_Importer; /** * Class ZipWP API * * @since 1.0.0 */ class Ai_Builder_ZipWP_Api { use Instance; /** * Constructor * * @since 4.0.0 */ public function __construct() { add_action( 'rest_api_init', array( $this, 'register_route' ) ); } /** * Get api domain * * @since 4.0.0 * @param bool $v1 Check for V1. * @return string */ public function get_api_domain( $v1 = true ) { if ( $v1 ) { return defined( 'ZIPWP_API_V1' ) ? ZIPWP_API_V1 : 'https://api.zipwp.com/api/v1/'; } return defined( 'ZIPWP_API' ) ? ZIPWP_API : 'https://api.zipwp.com/api/'; } /** * Get api namespace * * @since 4.0.0 * @return string */ public function get_api_namespace() { return 'zipwp/v1'; } /** * Get API headers * * @since 4.0.0 * @return array<string, string> */ public function get_api_headers() { return array( 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . Ai_Builder_ZipWP_Integration::get_token(), ); } /** * Check whether a given request has permission to read notes. * * @param object $request WP_REST_Request Full details about the request. * @return object|bool */ public function get_item_permissions_check( $request ) { if ( ! current_user_can( 'manage_options' ) ) { return new \WP_Error( 'gt_rest_cannot_access', __( 'Sorry, you are not allowed to do that.', 'astra-sites' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } /** * Set the dismiss time for the plan promotion. * * @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure. */ public function set_plan_promo_dismiss_time() { $dismiss_time = time(); update_option( 'ai_builder_promo_dismiss_time', $dismiss_time ); return new \WP_REST_Response( array( 'success' => true ), 200 ); } /** * Get the dismiss time for the plan promotion. * * @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure. */ public function get_plan_promo_dismiss_time() { $dismisstime = get_option( 'ai_builder_promo_dismiss_time', 0 ); return new \WP_REST_Response( array( 'success' => true, 'dismiss_time' => $dismisstime, ), 200 ); } /** * Register route * * @since 4.0.0 * @return void */ public function register_route() { $namespace = $this->get_api_namespace(); register_rest_route( $namespace, '/description/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'get_description' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'business_name' => array( 'type' => 'string', 'required' => true, 'sanitize_callback' => 'sanitize_text_field', ), 'business_description' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), 'category' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => false, ), ), ), ) ); register_rest_route( $namespace, '/images/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'get_images' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'keywords' => array( 'type' => 'string', 'required' => true, ), 'per_page' => array( 'type' => 'string', 'required' => false, ), 'page' => array( 'type' => 'string', 'required' => false, ), 'orientation' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => false, ), 'engine' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), ), ), ) ); register_rest_route( $namespace, '/keywords/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'get_keywords' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'business_name' => array( 'type' => 'string', 'required' => true, 'sanitize_callback' => 'sanitize_text_field', ), 'business_description' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), 'category' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => false, ), ), ), ) ); register_rest_route( $namespace, '/template-keywords/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'get_template_keywords' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'business_name' => array( 'type' => 'string', 'required' => true, 'sanitize_callback' => 'sanitize_text_field', ), 'business_description' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), 'business_category' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => false, ), ), ), ) ); register_rest_route( $namespace, '/categories/', array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_categories' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), ) ); register_rest_route( $namespace, '/site-features/', array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_site_features' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), ) ); register_rest_route( $namespace, '/site-languages/', array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_site_languages' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), ) ); register_rest_route( $namespace, '/get-credits/', array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_user_credits' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), ) ); register_rest_route( $namespace, '/import-status/', array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_import_status' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), ) ); register_rest_route( $namespace, '/migration-status/', array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_migration_status' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), ) ); register_rest_route( $namespace, '/templates/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'get_templates' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'business_name' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), 'keyword' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => false, ), 'page_builder' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => false, ), ), ), ) ); register_rest_route( $namespace, '/all-templates/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'get_all_templates' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'business_name' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), 'per_page' => array( 'type' => 'integer', 'required' => false, ), 'page' => array( 'type' => 'integer', 'required' => true, ), 'page_builder' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => false, ), ), ), ) ); register_rest_route( $namespace, '/user-details/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'save_user_details' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'business_description' => array( 'type' => 'string', 'required' => true, 'sanitize_callback' => 'sanitize_text_field', ), 'business_name' => array( 'type' => 'string', 'required' => true, 'sanitize_callback' => 'sanitize_text_field', ), 'business_addeess' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), 'business_phone' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), 'business_email' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), 'social_profiles' => array( 'type' => 'array', 'required' => false, ), 'business_category' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => true, ), 'site_language' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => true, ), 'keywords' => array( 'type' => 'array', 'required' => true, ), 'images' => array( 'type' => 'array', 'required' => true, ), ), ), ) ); register_rest_route( $namespace, '/site/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'create_site' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'template' => array( 'type' => 'string', 'required' => true, 'sanitize_callback' => 'sanitize_text_field', ), ), ), ) ); register_rest_route( $namespace, '/wxr/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'prepare_xml' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'template' => array( 'type' => 'string', 'required' => true, 'sanitize_callback' => 'sanitize_text_field', ), 'business_name' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), 'business_description' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), 'language' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), ), ), ) ); register_rest_route( $namespace, '/ai-site/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'get_demo' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'template' => array( 'type' => 'string', 'required' => true, 'sanitize_callback' => 'sanitize_text_field', ), 'business_name' => array( 'type' => 'string', 'required' => false, 'sanitize_callback' => 'sanitize_text_field', ), ), ), ) ); register_rest_route( $namespace, '/zip-plan/', array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'get_zip_plan_details' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array(), ) ); register_rest_route( $namespace, '/search-category/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'search_business_category' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'keyword' => array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => true, ), ), ), ) ); register_rest_route( $namespace, '/import-error-log/', array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_error_log' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), ) ); register_rest_route( $namespace, '/set-step-data/', array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'set_step_data' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'business_details' => array( 'type' => 'string', 'required' => true, ), ), ), ) ); register_rest_route( $namespace, '/set-plan-promo-dismiss-time/', array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'set_plan_promo_dismiss_time' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), ) ); register_rest_route( $namespace, '/get-plan-promo-dismiss-time/', array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_plan_promo_dismiss_time' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), ) ); } /** * Update onboarding data. * * @param \WP_REST_Request $request Full details about the request. * @return mixed * * @since 1.2.3 */ public function set_step_data( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $business_details = isset( $request['business_details'] ) ? json_decode( $request['business_details'], true ) : array(); $old_business_details = get_option( 'zipwp_user_business_details', array() ); if ( ! is_array( $old_business_details ) ) { $old_business_details = array(); } if ( is_array( $business_details ) && ! empty( $business_details ) ) { $business_details = array_merge( $old_business_details, array_intersect_key( $business_details, $old_business_details ) ); } update_option( 'zipwp_user_business_details', $business_details ); delete_option( 'ast_sites_downloaded_images' ); wp_send_json_success( array( 'status' => true, ) ); } /** * Get the error log details * * @param \WP_REST_Request $request Full details about the request. * @return mixed * * @since 1.0.36 */ public function get_error_log( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } wp_send_json_success( array( 'data' => get_option( 'ai_import_logger', array() ), 'status' => true, ) ); } /** * Get the zip plan details * * @return \WP_REST_Response * * @since 4.0.0 */ public function get_zip_plan_details() { $zip_plan = $this->get_zip_plans(); $response = new \WP_REST_Response( array( 'success' => $zip_plan['status'], 'data' => $zip_plan['data'], ) ); $response->set_status( 200 ); return $response; } /** * Get ZIP Plans. * * @return array<string, mixed> */ public function get_zip_plans() { $api_endpoint = $this->get_api_domain( false ) . '/plan/current-plan'; $request_args = array( 'headers' => $this->get_api_headers(), 'timeout' => 100, 'sslverify' => false, ); $response = wp_safe_remote_get( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. return array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( $response_data ) { return array( 'data' => $response_data, 'status' => true, ); } return array( 'data' => $response_data, 'status' => false, ); } return array( 'data' => 'Failed', 'status' => false, ); } /** * Create site. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function create_site( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain( false ) . '/starter-templates/site/'; $post_data = array( 'template' => isset( $request['template'] ) ? sanitize_text_field( $request['template'] ) : '', 'business_email' => isset( $request['business_email'] ) ? $request['business_email'] : '', 'email' => $this->get_zip_user_email(), 'business_desc' => isset( $request['business_description'] ) ? $request['business_description'] : '', 'business_name' => isset( $request['business_name'] ) ? $request['business_name'] : '', 'title' => isset( $request['business_name'] ) ? $request['business_name'] : '', 'business_phone' => isset( $request['business_phone'] ) ? $request['business_phone'] : '', 'business_address' => isset( $request['business_address'] ) ? $request['business_address'] : '', 'business_category' => isset( $request['business_category'] ) ? $request['business_category'] : '', 'business_category_name' => isset( $request['business_category'] ) ? $request['business_category'] : '', 'image_keyword' => isset( $request['image_keyword'] ) ? $request['image_keyword'] : '', 'social_profiles' => isset( $request['social_profiles'] ) ? $request['social_profiles'] : [], 'images' => isset( $request['images'] ) ? $request['images'] : '', 'language' => isset( $request['language'] ) ? $request['language'] : 'en', 'site_type' => 'ai', 'site_source' => apply_filters( 'ai_builder_site_source', 'starter-templates' ), 'site_features' => isset( $request['site_features'] ) ? $request['site_features'] : [], 'site_features_data' => isset( $request['site_features_data'] ) ? $request['site_features_data'] : [], ); if ( empty( $post_data['images'] ) ) { $post_data['images'] = Helper::get_image_placeholders(); } $body = wp_json_encode( $post_data ); $request_args = array( 'body' => is_string( $body ) ? $body : '', 'headers' => $this->get_api_headers(), 'timeout' => 1000, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); $response_data = json_decode( $response_body, true ); if ( 201 === $response_code || 200 === $response_code ) { $site_data = is_array( $response_data ) ? $response_data['site'] : array(); if ( is_array( $site_data ) ) { $site_data['step_data'] = $post_data; } update_option( 'zipwp_import_site_details', $site_data ); wp_send_json_success( array( 'http_status_code' => $response_code, 'data' => $response_data, ) ); } else { wp_send_json_error( array( 'http_status_code' => $response_code, 'data' => $response_data, ) ); } } /** * Prepare site XML. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function prepare_xml( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain( false ) . '/starter-templates/wxr/'; $post_data = array( 'template' => isset( $request['template'] ) ? sanitize_text_field( $request['template'] ) : '', 'business_name' => isset( $request['business_name'] ) ? $request['business_name'] : '', ); $body = wp_json_encode( $post_data ); $request_args = array( 'body' => is_string( $body ) ? $body : '', 'headers' => $this->get_api_headers(), 'timeout' => 1000, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 201 === $response_code || 200 === $response_code ) { if ( $response_body ) { // Get the WordPress upload directory. $upload_dir = wp_upload_dir(); // Define the file path where the attachment will be saved. $file_path = $upload_dir['path'] . '/wxr.xml'; // Save the XML content to a file. file_put_contents( $file_path, $response_body ); //phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents require_once ABSPATH . 'wp-admin/includes/image.php'; // Prepare the attachment data. $attachment = array( 'post_title' => 'Response XML', 'post_mime_type' => 'application/xml', 'post_content' => '', 'post_status' => 'inherit', ); Ai_builder_Importer_Log::add( (string) wp_json_encode( $attachment ) ); Ai_builder_Importer_Log::add( (string) wp_json_encode( $file_path ) ); // Insert the attachment into the media library. $attachment_id = wp_insert_attachment( $attachment, $file_path ); Ai_builder_Importer_Log::add( (string) wp_json_encode( $attachment_id ) ); if ( empty( $attachment_id ) ) { wp_send_json_error( __( 'There was an error downloading the XML file.', 'astra-sites' ) ); } else { update_option( 'astra_sites_imported_wxr_id', $attachment_id, false ); $attachment_metadata = wp_generate_attachment_metadata( $attachment_id, $file_path ); wp_update_attachment_metadata( $attachment_id, $attachment_metadata ); if ( class_exists( 'STImporter\Importer\WXR_Importer\ST_WXR_Importer' ) ) { $data = ST_WXR_Importer::get_xml_data( $file_path, $attachment_id ); $data['xml'] = $file_path; wp_send_json_success( $data ); } else { wp_send_json_error( __( 'Required class not found.', 'astra-sites' ) ); } } } else { wp_send_json_error( array( 'data' => 'Failed ' . $response_body, 'status' => false, ) ); } } else { wp_send_json_error( array( 'data' => 'Failed - ' . $response_body, 'status' => false, ) ); } } /** * Get AI demo site. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_demo( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain( false ) . '/starter-templates/export/' . sanitize_text_field( $request['uuid'] ); $post_data = array( 'template' => isset( $request['template'] ) ? sanitize_text_field( $request['template'] ) : '', 'business_name' => isset( $request['business_name'] ) ? $request['business_name'] : '', ); $body = wp_json_encode( $post_data ); $request_args = array( 'body' => is_string( $body ) ? $body : '', 'headers' => $this->get_api_headers(), 'timeout' => 1000, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 201 === $response_code || 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( is_array( $response_data ) ) { $exported_data = $response_data['data']; if ( ! is_array( $exported_data ) ) { $exported_data = array(); } $exported_data['astra-site-url'] = $exported_data['host']; if ( class_exists( 'STImporter\Importer\ST_Importer_File_System' ) ) { ST_Importer_File_System::get_instance()->update_demo_data( $exported_data ); } update_option( 'astra_sites_current_import_template_type', 'ai' ); update_option( 'astra_sites_batch_process_complete', 'no' ); $host_url = $exported_data['host'] ?? ''; update_option( 'ast_ai_import_current_url', $host_url ); wp_cache_flush(); wp_send_json_success( array( 'data' => $exported_data, 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => 'Failed ' . $response_body, 'status' => false, ) ); } } else { wp_send_json_error( array( 'data' => 'Failed - ' . $response_body, 'status' => false, ) ); } } /** * Save user details. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function save_user_details( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $email = $this->get_zip_user_email(); $api_endpoint = $this->get_api_domain() . '/sites/generate-cache/'; $business_details = array( 'business_description' => isset( $request['business_description'] ) ? sanitize_text_field( $request['business_description'] ) : '', 'business_name' => isset( $request['business_name'] ) ? sanitize_text_field( $request['business_name'] ) : '', 'business_email' => isset( $request['business_email'] ) ? sanitize_text_field( $request['business_email'] ) : '', 'business_address' => isset( $request['business_address'] ) ? sanitize_text_field( $request['business_address'] ) : '', 'business_phone' => isset( $request['business_phone'] ) ? sanitize_text_field( $request['business_phone'] ) : '', 'business_category' => isset( $request['business_category'] ) ? sanitize_text_field( $request['business_category'] ) : '', 'business_category_name' => isset( $request['business_category'] ) ? sanitize_text_field( $request['business_category'] ) : '', 'image_keyword' => isset( $request['keywords'] ) ? $request['keywords'] : [], 'images' => isset( $request['images'] ) ? $request['images'] : [], 'social_profiles' => isset( $request['social_profiles'] ) ? $request['social_profiles'] : [], 'language' => isset( $request['site_language'] ) ? sanitize_text_field( $request['site_language'] ) : 'en', 'templates' => get_option( 'zipwp_selection_templates', array() ), ); update_option( 'zipwp_user_business_details', $business_details ); if ( empty( $business_details['images'] ) ) { $business_details['images'] = Helper::get_image_placeholders(); } $post_data = array_merge( $business_details, [ 'email' => $email ] ); $post_data['templates'] = []; $body = wp_json_encode( $post_data ); $request_args = array( 'body' => is_string( $body ) ? $body : '', 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); wp_send_json_success( array( 'data' => $response_data, 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => 'Failed - ' . $response_body, 'status' => false, ) ); } } /** * Get AI based description. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_description( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain() . '/sites/suggest-description/'; $post_data = array( 'business_name' => isset( $request['business_name'] ) ? sanitize_text_field( $request['business_name'] ) : '', 'business_desc' => isset( $request['business_description'] ) ? sanitize_text_field( $request['business_description'] ) : '', 'business_category' => isset( $request['category'] ) ? sanitize_text_field( $request['category'] ) : '', 'language' => isset( $request['language'] ) ? sanitize_text_field( $request['language'] ) : 'en', ); $body = wp_json_encode( $post_data ); $request_args = array( 'body' => is_string( $body ) ? $body : '', 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( is_array( $response_data ) && $response_data['description'] ) { wp_send_json_success( array( 'data' => $response_data['description'], 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => 'Failed ' . $response_data, 'status' => false, ) ); } } else { wp_send_json_error( array( 'data' => 'Failed', 'status' => false, ) ); } } /** * Get Images. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_images( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain() . '/sites/images/'; $post_data = array( 'keywords' => isset( $request['keywords'] ) ? [ $request['keywords'] ] : [], 'per_page' => isset( $request['per_page'] ) ? $request['per_page'] : 20, 'page' => isset( $request['page'] ) ? $request['page'] : 1, 'orientation' => isset( $request['orientation'] ) ? sanitize_text_field( $request['orientation'] ) : '', 'engine' => isset( $request['engine'] ) ? sanitize_text_field( $request['engine'] ) : '', ); $body = wp_json_encode( $post_data ); $request_args = array( 'body' => is_string( $body ) ? $body : '', 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); wp_send_json_success( array( 'data' => is_array( $response_data ) ? $response_data['images'] : '', 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => 'Failed', 'status' => false, ) ); } } /** * Get Keywords for image search. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_keywords( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain() . '/sites/images/keywords/'; $post_data = array( 'business_desc' => isset( $request['business_description'] ) ? sanitize_text_field( $request['business_description'] ) : '', ); $body = wp_json_encode( $post_data ); $request_args = array( 'body' => is_string( $body ) ? $body : '', 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( is_array( $response_data ) ) { wp_send_json_success( array( 'data' => $response_data['keywords'], 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => 'Failed ' . $response_data, 'status' => false, ) ); } } else { wp_send_json_error( array( 'data' => 'Failed', 'status' => false, ) ); } } /** * Get Template Keywords for image search. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_template_keywords( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain() . '/sites/templates/keywords'; $post_data = array( 'business_desc' => isset( $request['business_description'] ) ? sanitize_text_field( $request['business_description'] ) : '', 'business_cat' => isset( $request['business_category'] ) ? sanitize_text_field( $request['business_category'] ) : '', 'business_category_name' => isset( $request['business_category'] ) ? sanitize_text_field( $request['business_category'] ) : '', 'business_name' => isset( $request['business_name'] ) ? sanitize_text_field( $request['business_name'] ) : '', 'language' => 'en', ); $body = wp_json_encode( $post_data ); $request_args = array( 'body' => is_string( $body ) ? $body : '', 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( is_array( $response_data ) ) { wp_send_json_success( array( 'data' => $response_data['keywords'], 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => 'Failed ' . $response_data, 'status' => false, ) ); } } else { wp_send_json_error( array( 'data' => 'Failed', 'status' => false, ) ); } } /** * Get Keywords for image search. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_templates( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $keyword = isset( $request['keyword'] ) ? sanitize_text_field( $request['keyword'] ) : 'multipurpose'; $api_endpoint = $this->get_api_domain() . '/sites/templates/search?query=' . $keyword; $post_data = array( 'business_name' => isset( $request['business_name'] ) ? sanitize_text_field( $request['business_name'] ) : '', 'page_builder' => isset( $request['page_builder'] ) ? sanitize_text_field( $request['page_builder'] ) : 'spectra', 'email' => $this->get_zip_user_email(), ); $body = wp_json_encode( $post_data ); $request_args = array( 'body' => is_string( $body ) ? $body : '', 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( $response_data ) { update_option( 'zipwp_selection_templates', $response_data ); wp_send_json_success( array( 'data' => $response_data, 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => $response_data, 'status' => false, ) ); } } else { wp_send_json_error( array( 'data' => 'Failed', 'status' => false, ) ); } } /** * Get templates by page. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_all_templates( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $per_page = isset( $request['per_page'] ) ? intval( $request['per_page'] ) : 9; $page = isset( $request['page'] ) ? intval( $request['page'] ) : 1; $api_endpoint = $this->get_api_domain() . '/sites/templates/all'; $post_data = array( 'business_name' => isset( $request['business_name'] ) ? sanitize_text_field( $request['business_name'] ) : '', 'page_builder' => isset( $request['page_builder'] ) ? sanitize_text_field( $request['page_builder'] ) : 'spectra', 'email' => $this->get_zip_user_email(), 'per_page' => $per_page, 'page' => $page, ); $body = wp_json_encode( $post_data ); $request_args = array( 'body' => is_string( $body ) ? $body : '', 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( $response_data ) { update_option( 'zipwp_selection_templates', $response_data ); wp_send_json_success( array( 'data' => $response_data, 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => $response_data, 'status' => false, ) ); } } else { wp_send_json_error( array( 'data' => 'Failed', 'status' => false, ) ); } } /** * Get Categories. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_categories( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain() . '/all-parent-categories/'; $request_args = array( 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_get( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( is_array( $response_data ) ) { wp_send_json_success( array( 'data' => $response_data['categories'], 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => 'Failed ' . $response_data, 'status' => false, ) ); } } elseif ( 401 === $response_code ) { $response_data = json_decode( $response_body, true ); wp_send_json_error( array( 'data' => is_array( $response_data ) ? $response_data['message'] : '', 'status' => false, ) ); } else { wp_send_json_error( array( 'data' => 'Failed', 'status' => false, ) ); } } /** * Get ZipWP Features list. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_site_features( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain() . '/sites/features/'; $request_args = array( 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_get( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( is_array( $response_data ) ) { wp_send_json_success( array( 'data' => $response_data['data'], 'status' => true, ) ); } wp_send_json_error( array( 'data' => 'Failed ' . $response_data, 'status' => false, ) ); } wp_send_json_error( array( 'data' => 'Failed ' . $response_body, 'status' => false, ) ); } /** * Get ZipWP Languages list. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_site_languages( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain() . '/sites/languages/'; $request_args = array( 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_get( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( is_array( $response_data ) ) { wp_send_json_success( array( 'data' => $response_data['data'], 'status' => true, ) ); } wp_send_json_error( array( 'data' => 'Failed ' . $response_data, 'status' => false, ) ); } wp_send_json_error( array( 'data' => 'Failed ' . $response_body, 'status' => false, ) ); } /** * Get User Credits. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_user_credits( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $api_endpoint = $this->get_api_domain() . '/scs-usage/'; $request_args = array( 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_post( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( is_array( $response_data ) ) { $credit_details = array(); $credit_details['used'] = ! empty( $response_data['total_used_credits'] ) ? $response_data['total_used_credits'] : 0; $credit_details['total'] = $response_data['total_credits']; $credit_details['percentage'] = intval( $credit_details['used'] / $credit_details['total'] * 100 ); $credit_details['free_user'] = $response_data['free_user']; wp_send_json_success( array( 'data' => $credit_details, 'status' => true, ) ); } wp_send_json_error( array( 'data' => 'Failed ' . $response_data, 'status' => false, ) ); } wp_send_json_error( array( 'data' => 'Failed ' . $response_body, 'status' => false, ) ); } /** * Get Import Status. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_import_status( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $site = get_option( 'zipwp_import_site_details', array() ); $uuid = is_array( $site ) ? $site['uuid'] : ''; $api_endpoint = $this->get_api_domain( false ) . '/sites/import-status/' . $uuid . '/'; $request_args = array( 'headers' => $this->get_api_headers(), 'timeout' => 100, ); $response = wp_safe_remote_get( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); if ( $response_data ) { wp_send_json_success( array( 'data' => $response_data, 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => $response_data, 'status' => false, ) ); } } else { wp_send_json_error( array( 'data' => $response_code, 'status' => false, ) ); } } /** * Get Migration Status. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function get_migration_status( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } wp_send_json_success( array( 'data' => get_option( 'astra_sites_batch_process_complete', 'no' ), 'status' => true, ) ); } /** * Search business category. * * @param \WP_REST_Request $request Full details about the request. * @return mixed */ public function search_business_category( $request ) { $nonce = (string) $request->get_header( 'X-WP-Nonce' ); // Verify the nonce. if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( array( 'data' => __( 'Nonce verification failed.', 'astra-sites' ), 'status' => false, ) ); } $keyword = $request['keyword']; $api_endpoint = $this->get_api_domain() . '/sites/business/search?q=' . $keyword; $headers = $this->get_api_headers(); $locale = get_locale(); if ( 'en_US' !== $locale ) { // Getting translation codes. $iso_locale = $locale; if ( strpos( $iso_locale, '_' ) !== false ) { $iso_locale = strstr( $locale, '_', true ); } $headers['X-Zip-Locale'] = $iso_locale ? $iso_locale : 'en'; } $request_args = array( 'headers' => $headers, 'timeout' => 100, ); $response = wp_safe_remote_get( $api_endpoint, $request_args ); if ( is_wp_error( $response ) ) { // There was an error in the request. wp_send_json_error( array( 'data' => 'Failed ' . $response->get_error_message(), 'status' => false, ) ); } $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); if ( 200 === $response_code ) { $response_data = json_decode( $response_body, true ); wp_send_json_success( array( 'data' => is_array( $response_data ) ? $response_data['results'] : '', 'status' => true, ) ); } else { wp_send_json_error( array( 'data' => 'Failed - ' . $response_body, 'status' => false, ) ); } } /** * Get Saved ZipWP user email. * * @since 4.0.0 * @return string */ public static function get_zip_user_email() { $token_details = get_option( 'zip_ai_settings', array( 'auth_token' => '', 'zip_token' => '', 'email' => '', ) ); return is_array( $token_details ) && isset( $token_details['email'] ) ? $token_details['email'] : ''; } } Ai_Builder_ZipWP_Api::Instance(); inc/classes/importer/class-ai-builder-error-handler.php 0000644 00000006427 15104046434 0017220 0 ustar 00 <?php /** * Astra Sites * * @since 3.0.23 * @package Astra Sites */ namespace AiBuilder\Inc\Classes\Importer; use AiBuilder\Inc\Classes\Ai_Builder_Importer_Log; use AiBuilder\Inc\Traits\Instance; use Exception; use Throwable; define( 'ST_ERROR_FATALS', E_ERROR | E_PARSE | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR ); /** * Ai_Builder_Error_Handler */ class Ai_Builder_Error_Handler { use Instance; /** * Constructor */ public function __construct() { require_once AI_BUILDER_DIR . 'inc/classes/ai-builder-importer-log.php'; if ( true === astra_sites_has_import_started() ) { $this->start_error_handler(); } add_action( 'shutdown', array( $this, 'stop_handler' ) ); } /** * Stop the shutdown handlers. * * @return void */ public function stop_handler() { if ( true === astra_sites_has_import_started() ) { $this->stop_error_handler(); } } /** * Start the error handling. * * @return void */ public function start_error_handler() { if ( ! interface_exists( 'Throwable' ) ) { // Fatal error handler for PHP < 7. register_shutdown_function( array( $this, 'shutdown_handler' ) ); } // Fatal error handler for PHP >= 7, and uncaught exception handler for all PHP versions. set_exception_handler( array( $this, 'exception_handler' ) ); } /** * Stop and restore the error handlers. * * @return void */ public function stop_error_handler() { // Restore the error handlers. restore_error_handler(); restore_exception_handler(); } /** * Uncaught exception handler. * * In PHP >= 7 this will receive a Throwable object. * In PHP < 7 it will receive an Exception object. * * @throws Exception Exception that is catched. * @param Throwable|Exception $e The error or exception. * * @return void */ public function exception_handler( $e ) { if ( is_a( $e, 'Exception' ) ) { $error = 'Uncaught Exception'; } else { $error = 'Uncaught Error'; } Ai_Builder_Importer_Log::add( 'There was an error on website: ' . $error ); Ai_Builder_Importer_Log::add( $e ); if ( wp_doing_ajax() ) { wp_send_json_error( array( 'message' => __( 'There was an error on your website.', 'astra-sites' ), 'stack' => array( 'error-message' => sprintf( '%s: %s', $error, $e->getMessage() ), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTrace(), ), ) ); } throw $e; } /** * Displays fatal error output for sites running PHP < 7. * * @return void */ public function shutdown_handler() { $e = error_get_last(); if ( empty( $e ) || ! ( $e['type'] & ST_ERROR_FATALS ) ) { return; } if ( $e['type'] & E_RECOVERABLE_ERROR ) { $error = 'Catchable fatal error'; } else { $error = 'Fatal error'; } Ai_Builder_Importer_Log::add( 'There was an error on website: ' . $error ); Ai_Builder_Importer_Log::add( $e['message'] ); if ( wp_doing_ajax() ) { wp_send_json_error( array( 'message' => __( 'There was an error your website.', 'astra-sites' ), 'stack' => array( 'error-message' => $error, 'error' => $e, ), ) ); } } } /** * Kicking this off by calling 'get_instance()' method */ Ai_Builder_Error_Handler::Instance(); inc/classes/importer/class-ai-builder-options-import.php 0000644 00000000541 15104046434 0017446 0 ustar 00 <?php /** * Customizer Site options importer class. * * @since 1.0.0 * @package Astra Addon */ namespace AiBuilder\Inc\Classes\Importer; use AiBuilder\Inc\Traits\Instance; /** * Customizer Site options importer class. * * @since 1.0.0 */ class Ai_Builder_Site_Options_Import { use Instance; } Ai_Builder_Site_Options_Import::Instance(); inc/classes/importer/class-ai-builder-importer.php 0000644 00000010232 15104046434 0016302 0 ustar 00 <?php /** * Ai Builder Importer * * @since 1.0.0 * @package Ai Builder */ namespace AiBuilder\Inc\Classes\Importer; use AiBuilder\Inc\Traits\Instance; use STImporter\Importer\ST_Importer_File_System; /** * Ai_Builder */ class Ai_Builder_Importer { use Instance; /** * API Domain name * * @var (String) URL */ public $api_domain; /** * API URL which is used to get the response from. * * @since 1.0.0 * @var (String) URL */ public $api_url; /** * Search API URL which is used to get the response from. * * @since 2.0.0 * @var (String) URL */ public $search_analytics_url; /** * Import Analytics API URL * * @since 3.1.4 * @var (String) URL */ public $import_analytics_url; /** * Constructor. * * @since 1.0.0 */ private function __construct() { $this->set_api_url(); $this->includes(); add_action( 'astra_sites_batch_process_complete', array( $this, 'clear_related_cache' ) ); add_action( 'astra_sites_batch_process_complete', array( $this, 'delete_related_transient' ) ); add_action( 'init', array( $this, 'permalink_update_after_import' ) ); } /** * Clear Cache. * * @return void * * @since 1.0.9 */ public function clear_related_cache() { // Clear 'Astra Addon' cache. if ( class_exists( 'Astra_Minify' ) && is_callable( 'Astra_Minify::refresh_assets' ) ) { \Astra_Minify::refresh_assets(); } Ai_Builder_Utils::third_party_cache_plugins_clear_cache(); $this->update_latest_checksums(); // Flush permalinks. flush_rewrite_rules(); //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.flush_rewrite_rules_flush_rewrite_rules -- This function is called only after import is completed } /** * Update Latest Checksums * * Store latest checksum after batch complete. * * @since 2.0.0 * @return void */ public function update_latest_checksums() { $latest_checksums = get_site_option( 'astra-sites-last-export-checksums-latest', '' ); update_site_option( 'astra-sites-last-export-checksums', $latest_checksums ); } /** * Delete related transients * * @return void * * @since 3.1.3 */ public function delete_related_transient() { delete_option( 'astra_sites_batch_process_started' ); if ( class_exists( 'STImporter\Importer\ST_Importer_File_System' ) ) { ST_Importer_File_System::get_instance()->delete_demo_content(); } delete_option( 'ast_ai_import_current_url' ); delete_option( 'astra_sites_ai_import_started' ); } /** * Include files. * * @return void * * @since 1.0.0 */ public function includes() { require_once AI_BUILDER_DIR . 'inc/classes/importer/class-ai-builder-error-handler.php'; require_once AI_BUILDER_DIR . 'inc/classes/importer/class-ai-builder-importer-utils.php'; require_once AI_BUILDER_DIR . 'inc/classes/importer/class-ai-builder-options-import.php'; require_once AI_BUILDER_DIR . 'inc/classes/importer/class-ai-builder-fse-importer.php'; } /** * Get the API URL. * * @return string * * @since 1.0.0 */ public static function get_api_domain() { return defined( 'STARTER_TEMPLATES_REMOTE_URL' ) ? STARTER_TEMPLATES_REMOTE_URL : apply_filters( 'astra_sites_api_domain', 'https://websitedemos.net/' ); } /** * Setter for $api_url * * @return void * * @since 1.0.0 */ public function set_api_url() { $this->api_domain = trailingslashit( self::get_api_domain() ); $this->api_url = apply_filters( 'astra_sites_api_url', $this->api_domain . 'wp-json/wp/v2/' ); $this->search_analytics_url = apply_filters( 'astra_sites_search_api_url', $this->api_domain . 'wp-json/analytics/v2/search/' ); $this->import_analytics_url = apply_filters( 'astra_sites_import_analytics_api_url', $this->api_domain . 'wp-json/analytics/v2/import/' ); } /** * Flush Rewrite rules * * @since 1.0.36 * @return void */ public function permalink_update_after_import() { if ( 'no' === get_option( 'astra-site-permalink-update-status', '' ) ) { // Flush the rewrite rules to apply the changes. flush_rewrite_rules(); delete_option( 'astra-site-permalink-update-status' ); } } } /** * Kicking this off by calling 'get_instance()' method */ Ai_Builder_Importer::Instance(); inc/classes/importer/class-ai-builder-fse-importer.php 0000644 00000021615 15104046434 0017064 0 ustar 00 <?php /** * FSE importer class. * * @since 1.0.0 * @package Astra Addon */ namespace AiBuilder\Inc\Classes\Importer; use AiBuilder\Inc\Traits\Instance; /** * Customizer Site options importer class. * * @since 1.0.0 */ class Ai_Builder_Fse_Importer { use Instance; /** * FSE logo attributes * * @since 3.3.0 * @var array<string, int|string> fse_logo_attributes */ public static $fse_logo_attributes = []; /** * Set FSE site related data. * * @since 3.3.0 * @return void */ public static function set_fse_site_data() { check_ajax_referer( 'astra-sites-set-ai-site-data', 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'success' => false, 'message' => __( 'You are not authorized to perform this action.', 'astra-sites' ), ) ); } $param = isset( $_POST['param'] ) ? sanitize_text_field( $_POST['param'] ) : ''; if ( empty( $param ) ) { wp_send_json_error( array( 'error' => __( 'Received empty parameters.', 'astra-sites' ), ) ); } switch ( $param ) { case 'site-logo' === $param: $logo = isset( $_POST['logo'] ) ? absint( $_POST['logo'] ) : 0; $logo_width = isset( $_POST['logo-width'] ) ? sanitize_text_field( $_POST['logo-width'] ) : ''; if ( ! empty( $logo ) || ! empty( $logo_width ) ) { self::$fse_logo_attributes = array( 'logo_width' => $logo_width, 'logo' => $logo, ); self::update_fse_site_logo( 'header' ); self::update_fse_site_logo( 'footer' ); } break; case 'site-colors' === $param: $palette = isset( $_POST['palette'] ) ? (array) json_decode( stripslashes( $_POST['palette'] ) ) : array(); $colors_passed = isset( $palette['colors'] ) ? (array) $palette['colors'] : array(); if ( ! empty( $colors_passed ) ) { $colors_array = Swt\get_theme_custom_styles(); // @phpstan-ignore-line $colors_content = $colors_array['post_content']; if ( $colors_content && isset( $colors_content['settings']['color']['palette']['theme'] ) ) { $theme_colors = $colors_content['settings']['color']['palette']['theme']; $set_colors = array(); foreach ( $theme_colors as $key => $single ) { $single['color'] = $colors_passed[ $key ]; $set_colors[] = $single; } $colors_content['settings']['color']['palette']['theme'] = $set_colors; } $update_colors = array( 'ID' => (int) $colors_array['ID'], 'post_content' => (string) wp_json_encode( $colors_content ), ); // Update the post into the database. wp_update_post( $update_colors ); } break; case 'site-typography' === $param: $typography_passed = isset( $_POST['typography'] ) ? (array) json_decode( stripslashes( $_POST['typography'] ) ) : array(); $typography_passed['body-font-family-slug'] = isset( $typography_passed['body-font-family-slug'] ) ? $typography_passed['body-font-family-slug'] : 'inter'; $typography_passed['headings-font-family-slug'] = isset( $typography_passed['headings-font-family-slug'] ) ? $typography_passed['headings-font-family-slug'] : 'inter'; if ( class_exists( 'UAGB_FSE_Fonts_Compatibility' ) && is_callable( 'UAGB_FSE_Fonts_Compatibility::get_instance' ) ) { $fse_fonts_comp_instance = new \UAGB_FSE_Fonts_Compatibility(); $fse_fonts_comp_instance->get_font_family_for_starter_template( array( ucfirst( $typography_passed['body-font-family'] ), ucfirst( $typography_passed['headings-font-family'] ) ) ); } $typography_array = Swt\get_theme_custom_styles(); // @phpstan-ignore-line $typography_content = $typography_array['post_content']; if ( $typography_content && isset( $typography_content['styles']['typography'] ) ) { $typography_content['styles']['typography']['fontFamily'] = 'var:preset|font-family|' . $typography_passed['body-font-family-slug']; } if ( $typography_content && isset( $typography_content['styles']['elements']['link']['typography'] ) ) { $typography_content['styles']['elements']['link']['typography']['fontFamily'] = 'var:preset|font-family|' . $typography_passed['body-font-family-slug']; } if ( $typography_content && isset( $typography_content['styles']['elements']['heading']['typography'] ) ) { $typography_content['styles']['elements']['heading']['typography']['fontFamily'] = 'var:preset|font-family|' . $typography_passed['headings-font-family-slug']; } if ( $typography_content && isset( $typography_content['styles']['elements']['button']['typography'] ) ) { $typography_content['styles']['elements']['button']['typography']['fontFamily'] = 'var:preset|font-family|' . $typography_passed['body-font-family-slug']; } if ( $typography_content && isset( $typography_content['styles']['elements']['h1']['typography'] ) ) { $typography_content['styles']['elements']['h1']['typography']['fontFamily'] = 'var:preset|font-family|' . $typography_passed['headings-font-family-slug']; } if ( $typography_content && isset( $typography_content['styles']['elements']['h2']['typography'] ) ) { $typography_content['styles']['elements']['h2']['typography']['fontFamily'] = 'var:preset|font-family|' . $typography_passed['headings-font-family-slug']; } if ( $typography_content && isset( $typography_content['styles']['elements']['h3']['typography'] ) ) { $typography_content['styles']['elements']['h3']['typography']['fontFamily'] = 'var:preset|font-family|' . $typography_passed['headings-font-family-slug']; } if ( $typography_content && isset( $typography_content['styles']['elements']['h4']['typography'] ) ) { $typography_content['styles']['elements']['h4']['typography']['fontFamily'] = 'var:preset|font-family|' . $typography_passed['headings-font-family-slug']; } if ( $typography_content && isset( $typography_content['styles']['elements']['h5']['typography'] ) ) { $typography_content['styles']['elements']['h5']['typography']['fontFamily'] = 'var:preset|font-family|' . $typography_passed['headings-font-family-slug']; } if ( $typography_content && isset( $typography_content['styles']['elements']['h6']['typography'] ) ) { $typography_content['styles']['elements']['h6']['typography']['fontFamily'] = 'var:preset|font-family|' . $typography_passed['headings-font-family-slug']; } $update_typography = array( 'ID' => intval( $typography_array['ID'] ), 'post_content' => (string) wp_json_encode( $typography_content ), ); // Update the post into the database. wp_update_post( $update_typography ); break; } wp_send_json_success(); } /** * Set FSE site related data. * * @since 3.3.0 * @param string $post_name post name. * @return void */ public static function update_fse_site_logo( $post_name ) { $args = array( 'orderby' => 'post_type', 'post_status' => 'publish', 'post_type' => array( 'wp_template_part' ), 'name' => $post_name, ); $fse_posts = get_posts( $args ); $post_content = ''; if ( isset( $fse_posts[0] ) && ! empty( $fse_posts[0]->post_content ) ) { $post_content = stripslashes( $fse_posts[0]->post_content ); } // Define the regex pattern to match the logo code with 'site-logo-img' class. $regex_pattern = '/<img\s[^>]*src=([\'\"]??)([^\' >]*?)\\1[^>]*>/i'; $regex_src = '/src=[\'"]([^\'"]+)[\'"]/i'; $regex_width = '/width=[\'"]([^\'"]+)[\'"]/i'; // Search for the logo code using regex. preg_match( $regex_pattern, $post_content, $matches ); // Check if a match is found. if ( ! empty( $matches ) ) { $logo_code = $matches[0]; // The matched logo code. if ( strpos( $logo_code, 'width=' ) === false ) { // Width attribute is not present, so add it. $width_add = 'width="' . self::$fse_logo_attributes['logo_width'] . '" />'; $logo_code = str_replace( '/>', $width_add, $logo_code ); } // Extract the src attribute using regex. preg_match( $regex_src, $logo_code, $matches_src ); if ( ! empty( $matches_src ) ) { $src_attribute = $matches_src[1]; // The value of the src attribute. $attachment = wp_prepare_attachment_for_js( absint( self::$fse_logo_attributes['logo'] ) ); if ( ! is_array( $attachment ) ) { return; } $post_content = str_replace( $src_attribute, $attachment['url'], $post_content ); } // Extract the width attribute using regex. preg_match( $regex_width, $logo_code, $matches_width ); if ( ! empty( $matches_width ) ) { $width_attribute = $matches_width[1]; // The value of the width attribute. $post_content = str_replace( $width_attribute, strval( self::$fse_logo_attributes['logo_width'] ), $post_content ); } $update_post = array( 'ID' => $fse_posts[0]->ID, 'post_content' => $post_content, ); // Update the post into the database. wp_update_post( $update_post ); } } } Ai_Builder_Fse_Importer::Instance(); inc/classes/importer/class-ai-builder-importer-utils.php 0000644 00000002261 15104046434 0017443 0 ustar 00 <?php /** * Astra Sites Utlis * * @since 1.0.0 * @package Astra Sites */ namespace AiBuilder\Inc\Classes\Importer; use AiBuilder\Inc\Traits\Instance; /** * Ai_Builder_Utils */ class Ai_Builder_Utils { use Instance; /** * Third party cache plugin clear cache. * * @since 4.0.0 * @return void */ public static function third_party_cache_plugins_clear_cache() { // Clear LiteSpeed cache. if ( class_exists( '\LiteSpeed\Purge' ) ) { \LiteSpeed\Purge::purge_all(); } // Clear cloudways cache. self::clear_cloudways_cache(); } /** * This function helps to purge all cache in clodways envirnoment. * In presence of Breeze plugin (https://wordpress.org/plugins/breeze/) * * @since 4.0.0 * @return void */ public static function clear_cloudways_cache() { if ( ! class_exists( 'Breeze_Configuration' ) || ! class_exists( 'Breeze_CloudFlare_Helper' ) || ! class_exists( 'Breeze_Admin' ) ) { return; } // clear varnish cache. $admin = new \Breeze_Admin(); $admin->breeze_clear_varnish(); // clear static cache. \Breeze_Configuration::breeze_clean_cache(); \Breeze_CloudFlare_Helper::reset_all_cache(); } } Ai_Builder_Utils::Instance(); inc/classes/ai-builder-importer-log.php 0000644 00000033131 15104046434 0014120 0 ustar 00 <?php /** * Astra Sites Importer Log * * @since 1.1.0 * @package Astra Sites */ namespace AiBuilder\Inc\Classes; use AiBuilder\Inc\Traits\Instance; /** * Astra Sites Importer */ class Ai_Builder_Importer_Log { use Instance; /** * Log File * * @since 1.1.0 * @var string log_file */ private static $log_file = null; /** * Constructor. * * @since 1.1.0 */ private function __construct() { // Check file read/write permissions. if ( current_user_can( 'edit_posts' ) ) { add_action( 'admin_init', array( $this, 'has_file_read_write' ) ); } } /** * Check file read/write permissions and process. * * @since 1.1.0 * @return void */ public function has_file_read_write() { $upload_dir = self::log_dir(); $file_created = false; if ( method_exists( self::get_filesystem(), 'put_contents' ) ) { $file_created = self::get_filesystem()->put_contents( $upload_dir['path'] . 'index.html', '' ); } if ( ! $file_created ) { add_action( 'admin_notices', array( $this, 'file_permission_notice' ) ); return; } // Set log file. self::set_log_file(); // Initial AJAX Import Hooks. add_action( 'astra_sites_import_start', array( $this, 'start' ), 10, 2 ); } /** * File Permission Notice * * @since 2.0.0 * @return void */ public function file_permission_notice() { $upload_dir = self::log_dir(); $plugin_name = ASTRA_SITES_NAME; /* translators: %1$s refers to the plugin name */ $notice = sprintf( __( 'Required File Permissions to import the templates from %s are missing.', 'astra-sites' ), $plugin_name ); ?> <div class="notice notice-error ai-builder-must-notices ai-builder-file-permission-issue"> <p><?php echo esc_html( $notice ); ?></p> <?php if ( defined( 'FS_METHOD' ) ) { ?> <p><?php esc_html_e( 'This is usually due to inconsistent file permissions.', 'astra-sites' ); ?></p> <p><code><?php echo esc_html( $upload_dir['path'] ); ?></code></p> <?php } else { ?> <p><?php esc_html_e( 'You can easily update permissions by adding the following code into the wp-config.php file.', 'astra-sites' ); ?></p> <p><code>define( 'FS_METHOD', 'direct' );</code></p> <?php } ?> </div> <?php } /** * Add log file URL in UI response. * * @since 1.1.0 * * @return array<string, mixed> */ public static function add_log_file_url() { $upload_dir = self::log_dir(); $upload_path = trailingslashit( $upload_dir['url'] ); $file_abs_url = get_option( 'ai_builder_recent_import_log_file', self::$log_file ); $file_url = $upload_path . basename( (string) $file_abs_url ); // @phpstan-ignore-line return array( 'abs_url' => $file_abs_url, 'url' => $file_url, ); } /** * Current Time for log. * * @since 1.1.0 * @return string Current time with time zone. */ public static function current_time() { return gmdate( 'H:i:s' ) . ' ' . date_default_timezone_get(); } /** * Import Start * * @since 1.1.0 * @param array<string, string> $data Import Data. * @param string $demo_api_uri Import site API URL. * @return void */ public function start( $data = array(), $demo_api_uri = '' ) { self::add( 'Started Import Process' ); self::add( '# System Details: ' ); self::add( "Debug Mode \t\t: " . self::get_debug_mode() ); self::add( "Operating System \t: " . self::get_os() ); self::add( "Software \t\t: " . self::get_software() ); self::add( "MySQL version \t\t: " . self::get_mysql_version() ); self::add( "XML Reader \t\t: " . self::get_xmlreader_status() ); self::add( "PHP Version \t\t: " . self::get_php_version() ); self::add( "PHP Max Input Vars \t: " . self::get_php_max_input_vars() ); self::add( "PHP Max Post Size \t: " . self::get_php_max_post_size() ); self::add( "PHP Extension GD \t: " . self::get_php_extension_gd() ); self::add( "PHP Max Execution Time \t: " . self::get_max_execution_time() ); self::add( "Max Upload Size \t: " . size_format( wp_max_upload_size() ) ); self::add( "Memory Limit \t\t: " . self::get_memory_limit() ); self::add( "Timezone \t\t: " . self::get_timezone() ); self::add( PHP_EOL . '-----' . PHP_EOL ); self::add( 'Importing Started! - ' . self::current_time() ); self::add( '---' . PHP_EOL ); self::add( 'WHY IMPORT PROCESS CAN FAIL? READ THIS - ' ); self::add( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' . PHP_EOL ); self::add( '---' . PHP_EOL ); } /** * Get Log File * * @since 1.1.0 * @return string log file URL. */ public static function get_log_file() { return self::$log_file; } /** * Log file directory * * @since 1.1.0 * @param string $dir_name Directory Name. * @return array<string, string> Uploads directory array. */ public static function log_dir( $dir_name = 'ai-builder' ) { $upload_dir = wp_upload_dir(); // Build the paths. $dir_info = array( 'path' => $upload_dir['basedir'] . '/' . $dir_name . '/', 'url' => $upload_dir['baseurl'] . '/' . $dir_name . '/', ); // Create the upload dir if it doesn't exist. if ( ! file_exists( $dir_info['path'] ) ) { // Create the directory. wp_mkdir_p( $dir_info['path'] ); if ( method_exists( self::get_filesystem(), 'put_contents' ) ) { // Add an index file for security. self::get_filesystem()->put_contents( $dir_info['path'] . 'index.html', '' ); // Add an .htaccess for security. self::get_filesystem()->put_contents( $dir_info['path'] . '.htaccess', 'deny from all' ); } } return $dir_info; } /** * Get an instance of WP_Filesystem_Direct. * * @since 2.0.0 * @return object A WP_Filesystem_Direct instance. */ public static function get_filesystem() { global $wp_filesystem; require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem(); return $wp_filesystem; } /** * Set log file * * @return void * * @since 1.1.0 */ public static function set_log_file() { $upload_dir = self::log_dir(); $upload_path = trailingslashit( $upload_dir['path'] ); // File format e.g. 'import-31-Oct-2017-06-39-12-hashcode.log'. self::$log_file = $upload_path . 'import-' . gmdate( 'd-M-Y-h-i-s' ) . '-' . wp_hash( 'starter-templates-log' ) . '.log'; if ( ! get_option( 'ai_builder_recent_import_log_file', false ) ) { update_option( 'ai_builder_recent_import_log_file', self::$log_file, false ); } } /** * Write content to a file. * * @since 1.1.0 * @param string $content content to be saved to the file. * * @return void */ public static function add( $content ) { if ( get_option( 'ai_builder_recent_import_log_file', false ) ) { $log_file = get_option( 'ai_builder_recent_import_log_file', self::$log_file ); } else { $log_file = self::$log_file; } if ( apply_filters( 'astra_sites_debug_logs', false ) ) { error_log( $content ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is for the debug logs while importing. This is conditional and will not be logged in the debug.log file for normal users. } $existing_data = ''; if ( file_exists( (string) $log_file ) && method_exists( self::get_filesystem(), 'get_contents' ) ) { // @phpstan-ignore-line $existing_data = self::get_filesystem()->get_contents( $log_file ); } // Style separator. $separator = PHP_EOL; if ( method_exists( self::get_filesystem(), 'put_contents' ) ) { self::get_filesystem()->put_contents( $log_file, $existing_data . $separator . $content, FS_CHMOD_FILE ); } } /** * Debug Mode * * @since 1.1.0 * @return string Enabled for Debug mode ON and Disabled for Debug mode Off. */ public static function get_debug_mode() { if ( WP_DEBUG ) { return __( 'Enabled', 'astra-sites' ); } return __( 'Disabled', 'astra-sites' ); } /** * Memory Limit * * @since 1.1.0 * @return string Memory limit. */ public static function get_memory_limit() { $required_memory = '64M'; $memory_limit_in_bytes_current = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT ); $memory_limit_in_bytes_required = wp_convert_hr_to_bytes( $required_memory ); if ( $memory_limit_in_bytes_current < $memory_limit_in_bytes_required ) { return sprintf( /* translators: %1$s Memory Limit, %2$s Recommended memory limit. */ _x( 'Current memory limit %1$s. We recommend setting memory to at least %2$s.', 'Recommended Memory Limit', 'astra-sites' ), WP_MEMORY_LIMIT, $required_memory ); } return WP_MEMORY_LIMIT; } /** * Timezone * * @since 1.1.0 * @see https://codex.wordpress.org/Option_Reference/ * * @return string Current timezone. */ public static function get_timezone() { $timezone = get_option( 'timezone_string' ); if ( ! $timezone ) { $timezone = get_option( 'gmt_offset' ); } return (string) $timezone; // @phpstan-ignore-line } /** * Operating System * * @since 1.1.0 * @return string Current Operating System. */ public static function get_os() { return PHP_OS; } /** * Server Software * * @since 1.1.0 * @return string Current Server Software. */ public static function get_software() { return isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( $_SERVER['SERVER_SOFTWARE'] ) : ''; } /** * MySql Version * * @since 1.1.0 * @return string Current MySql Version. */ public static function get_mysql_version() { global $wpdb; return $wpdb->db_version(); } /** * XML Reader * * @since 1.2.8 * @return string Current XML Reader status. */ public static function get_xmlreader_status() { if ( class_exists( 'XMLReader' ) ) { return __( 'Yes', 'astra-sites' ); } return __( 'No', 'astra-sites' ); } /** * PHP Version * * @since 1.1.0 * @return string Current PHP Version. */ public static function get_php_version() { if ( version_compare( PHP_VERSION, '5.4', '<' ) ) { return _x( 'We recommend to use php 5.4 or higher', 'PHP Version', 'astra-sites' ); } return PHP_VERSION; } /** * PHP Max Input Vars * * @since 1.1.0 * @return string|false Current PHP Max Input Vars */ public static function get_php_max_input_vars() { return ini_get( 'max_input_vars' ); // phpcs:disable PHPCompatibility.IniDirectives.NewIniDirectives.max_input_varsFound } /** * PHP Max Post Size * * @since 1.1.0 * @return string|false Current PHP Max Post Size */ public static function get_php_max_post_size() { return ini_get( 'post_max_size' ); } /** * PHP Max Execution Time * * @since 1.1.0 * @return string Current Max Execution Time */ public static function get_max_execution_time() { return ini_get( 'max_execution_time' ); } /** * PHP GD Extension * * @since 1.1.0 * @return string Current PHP GD Extension */ public static function get_php_extension_gd() { if ( extension_loaded( 'gd' ) ) { return __( 'Yes', 'astra-sites' ); } return __( 'No', 'astra-sites' ); } /** * Display Data * * @since 2.0.0 * @return void */ public function display_data() { $crons = _get_cron_array(); $events = array(); if ( empty( $crons ) ) { esc_html_e( 'You currently have no scheduled cron events.', 'astra-sites' ); } foreach ( $crons as $time => $cron ) { $keys = array_keys( $cron ); $key = $keys[0]; $events[ $key ] = $time; } $expired = get_site_transient( 'ai-builder-import-check' ); if ( $expired ) { global $wpdb; $transient = 'ai-builder-import-check'; $transient_timeout = $wpdb->get_col( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name LIKE %s", '%_transient_timeout_' . $transient . '%' ) ); // WPCS: cache ok. // WPCS: db call ok. $older_date = $transient_timeout[0]; $transient_status = 'Transient: Not Expired! Recheck in ' . human_time_diff( time(), $older_date ); } else { $transient_status = 'Transient: Starting.. Process for each 5 minutes.'; } $temp = get_site_option( 'ai-builder-batch-status-string', '' ); $temp .= isset( $events['wp_astra_site_importer_cron'] ) ? '<br/>Batch: Recheck batch in ' . human_time_diff( time(), $events['wp_astra_site_importer_cron'] ) : '<br/>Batch: Not Started! Until the Transient expire.'; $upload_dir = self::log_dir(); $list_files = list_files( $upload_dir['path'] ); $backup_files = array(); $log_files = array(); if ( is_array( $list_files ) ) { foreach ( $list_files as $key => $file ) { if ( strpos( $file, '.json' ) ) { $backup_files[] = $file; } if ( strpos( $file, '.txt' ) ) { $log_files[] = $file; } } } ?> <table> <tr> <td> <h2>Log Files</h2> <ul> <?php foreach ( $log_files as $key => $file ) { $file_name = basename( $file ); $file = str_replace( $upload_dir['path'], $upload_dir['url'], $file ); ?> <li> <a target="_blank" href="<?php echo esc_url( $file ); ?>"><?php echo esc_html( $file_name ); ?></a> </li> <?php } ?> </ul> </td> <td> <h2>Backup Files</h2> <ul> <?php foreach ( $backup_files as $key => $file ) { $file_name = basename( $file ); $file = str_replace( $upload_dir['path'], $upload_dir['url'], $file ); ?> <li> <a target="_blank" href="<?php echo esc_url( $file ); ?>"><?php echo esc_html( $file_name ); ?></a> </li> <?php } ?> </ul> </td> <td> <div class="batch-log"> <p><?php echo wp_kses_post( $temp ); ?></p> <p><?php echo wp_kses_post( $transient_status ); ?></p> </div> </td> </tr> </table> <?php } } /** * Kicking this off by calling 'get_instance()' method */ Ai_Builder_Importer_Log::Instance(); inc/classes/ai-builder-loader.php 0000644 00000001601 15104046434 0012743 0 ustar 00 <?php /** * Ai Builder * * @since 1.0.0 * @package Ai Builder */ namespace AiBuilder\Inc\Classes; use AiBuilder\Inc\Traits\Instance; /** * Ai_Builder */ class Ai_Builder_Loader { use Instance; /** * Constructor. * * @since 1.0.0 */ private function __construct() { $this->includes_files(); } /** * Load all the required files in the importer. * * @since 1.0.0 * * @return void */ private function includes_files() { require_once AI_BUILDER_DIR . 'inc/classes/ai-builder-importer-log.php'; require_once AI_BUILDER_DIR . 'inc/classes/zipwp/class-ai-builder-zipwp-integration.php'; require_once AI_BUILDER_DIR . 'inc/classes/zipwp/class-ai-builder-zipwp-api.php'; require_once AI_BUILDER_DIR . 'inc/classes/importer/class-ai-builder-importer.php'; } } /** * Kicking this off by calling 'get_instance()' method */ Ai_Builder_Loader::Instance(); inc/assets/images/placeholder.png 0000644 00000145370 15104046434 0013067 0 ustar 00 �PNG IHDR � e�8� tEXtSoftware Adobe ImageReadyq�e<