File manager - Edit - /home/aresglob/public_html/wp/wp-includes/images/smilies/importers.zip
Back
PK =3j[tt�� � class-astra-sites-helper.phpnu �[��� <?php /** * Astra Site Helper * * @since 1.0.0 * @package Astra Sites */ if ( ! class_exists( 'Astra_Sites_Helper' ) ) : /** * Astra_Sites_Helper * * @since 1.0.0 */ class Astra_Sites_Helper { /** * Instance * * @access private * @var object Instance * @since 1.0.0 */ private static $instance; /** * Initiator * * @since 1.0.0 * @return object initialized object of class. */ public static function get_instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Constructor * * @since 1.0.0 */ public function __construct() { add_filter( 'wie_import_data', array( $this, 'custom_menu_widget' ) ); add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 ); } /** * Add svg image support * * @since 1.1.5 * * @param array $response Attachment response. * @param object $attachment Attachment object. * @param array $meta Attachment meta data. */ public function add_svg_image_support( $response, $attachment, $meta ) { if ( ! function_exists( 'simplexml_load_file' ) ) { return $response; } if ( ! empty( $response['sizes'] ) ) { return $response; } if ( 'image/svg+xml' !== $response['mime'] ) { return $response; } $svg_path = get_attached_file( $attachment->ID ); $dimensions = self::get_svg_dimensions( $svg_path ); $response['sizes'] = array( 'full' => array( 'url' => $response['url'], 'width' => $dimensions->width, 'height' => $dimensions->height, 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait', ), ); return $response; } /** * Get SVG Dimensions * * @since 1.1.5 * * @param string $svg SVG file path. * @return array Return SVG file height & width for valid SVG file. */ public static function get_svg_dimensions( $svg ) { $svg = simplexml_load_file( $svg ); if ( false === $svg ) { $width = '0'; $height = '0'; } else { $attributes = $svg->attributes(); $width = (string) $attributes->width; $height = (string) $attributes->height; } return (object) array( 'width' => $width, 'height' => $height, ); } /** * Custom Menu Widget * * In widget export we set the nav menu slug instead of ID. * So, In import process we check get menu id by slug and set * it in import widget process. * * @since 1.0.7 * * @param object $all_sidebars Widget data. * @return object Set custom menu id by slug. */ public function custom_menu_widget( $all_sidebars ) { // Get current menu ID & Slugs. $menu_locations = array(); $nav_menus = (object) wp_get_nav_menus(); if ( isset( $nav_menus ) ) { foreach ( $nav_menus as $menu_key => $menu ) { if ( is_object( $menu ) ) { $menu_locations[ $menu->term_id ] = $menu->slug; } } } // Import widget data. $all_sidebars = (object) $all_sidebars; foreach ( $all_sidebars as $widgets_key => $widgets ) { foreach ( $widgets as $widget_key => $widget ) { // Found slug in current menu list. if ( isset( $widget->nav_menu ) ) { $menu_id = array_search( $widget->nav_menu, $menu_locations, true ); if ( ! empty( $menu_id ) ) { $all_sidebars->$widgets_key->$widget_key->nav_menu = $menu_id; } } } } return $all_sidebars; } /** * Downloads an image from the specified URL. * * Taken from the core media_sideload_image() function and * modified to return an array of data instead of html. * * @since 1.0.10 * * @param string $file The image file path. * @return array An array of image data. */ public static function sideload_image( $file ) { $data = new stdClass(); if ( ! function_exists( 'media_handle_sideload' ) ) { require_once ABSPATH . 'wp-admin/includes/media.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; } if ( ! empty( $file ) ) { // Set variables for storage, fix file filename for query strings. preg_match( '/[^\?]+\.(jpe?g|jpe|svg|gif|png)\b/i', $file, $matches ); $file_array = array(); $file_array['name'] = basename( $matches[0] ); // Download file to temp location. $file_array['tmp_name'] = download_url( $file ); // If error storing temporarily, return the error. if ( is_wp_error( $file_array['tmp_name'] ) ) { return $file_array['tmp_name']; } // Do the validation and storage stuff. $id = media_handle_sideload( $file_array, 0 ); // If error storing permanently, unlink. if ( is_wp_error( $id ) ) { unlink( $file_array['tmp_name'] ); //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink -- Deleting the file from temp location. return $id; } // Build the object to return. $meta = wp_get_attachment_metadata( $id ); $data->attachment_id = $id; $data->url = wp_get_attachment_url( $id ); $data->thumbnail_url = wp_get_attachment_thumb_url( $id ); $data->height = isset( $meta['height'] ) ? $meta['height'] : ''; $data->width = isset( $meta['width'] ) ? $meta['width'] : ''; } return $data; } /** * Extract image URLs and other URLs from a given HTML content. * * @since 2.6.10 * * @param string $content HTML content string. * @return array Array of URLS. */ public static function extract_segregated_urls( $content ) { // Extract all links. preg_match_all( '#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $content, $match ); $extracts = array( 'image' => array(), 'other' => array(), ); $all_links = array_unique( $match[0] ); // Not have any link. if ( empty( $all_links ) ) { return array(); } $image_links = array(); $other_links = array(); // Extract normal and image links. foreach ( $all_links as $key => $link ) { if ( preg_match( '/^((https?:\/\/)|(www\.))([a-z0-9-].?)+(:[0-9]+)?\/[\w\-]+\.(jpg|png|gif|jpeg)\/?$/i', $link ) ) { // Get all image links. // Avoid *-150x, *-300x and *-1024x images. if ( false === strpos( $link, '-150x' ) && false === strpos( $link, '-300x' ) && false === strpos( $link, '-1024x' ) ) { $image_links[] = $link; } } else { // Collect other links. $other_links[] = $link; } } $extracts['image'] = $image_links; $extracts['other'] = $other_links; return $extracts; } /** * Get the client IP address. * * @since 2.6.4 */ public static function get_client_ip() { $ipaddress = ''; if ( getenv( 'HTTP_CLIENT_IP' ) ) { $ipaddress = getenv( 'HTTP_CLIENT_IP' ); } elseif ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) { $ipaddress = getenv( 'HTTP_X_FORWARDED_FOR' ); } elseif ( getenv( 'HTTP_X_FORWARDED' ) ) { $ipaddress = getenv( 'HTTP_X_FORWARDED' ); } elseif ( getenv( 'HTTP_FORWARDED_FOR' ) ) { $ipaddress = getenv( 'HTTP_FORWARDED_FOR' ); } elseif ( getenv( 'HTTP_FORWARDED' ) ) { $ipaddress = getenv( 'HTTP_FORWARDED' ); } elseif ( getenv( 'REMOTE_ADDR' ) ) { $ipaddress = getenv( 'REMOTE_ADDR' ); } else { $ipaddress = 'UNKNOWN'; } return $ipaddress; } } /** * Kicking this off by calling 'get_instance()' method */ Astra_Sites_Helper::get_instance(); endif; PK =3j[x{K� � ? batch-processing/class-astra-sites-batch-processing-cleanup.phpnu �[��� <?php /** * Cleanup batch import tasks. * * @package Astra Sites * @since 4.0.11 */ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Cleanup' ) ) : /** * Astra_Sites_Batch_Processing_Cleanup * * @since 4.0.11 */ class Astra_Sites_Batch_Processing_Cleanup { /** * Constructor * * @since 4.0.11 */ public function __construct() {} /** * Import * * @since 4.0.11 * @return void */ public function import() { if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Processing "Cleanup" Batch Import' ); } update_option( 'st_attachments', array(), 'no' ); delete_option( 'st_attachments_offset' ); } } endif; PK =3j[�� B batch-processing/class-astra-sites-batch-processing-customizer.phpnu �[��� <?php /** * Customizer batch import tasks. * * @package Astra Sites * @since 3.0.22 */ use STImporter\Importer\Helpers\ST_Image_Importer; /** * Astra_Sites_Batch_Processing_Customizer * * @since 3.0.22 */ class Astra_Sites_Batch_Processing_Customizer { /** * Instance * * @since 3.0.22 * @access private * @var object Class object. */ private static $instance; /** * Initiator * * @since 3.0.22 * @return object initialized object of class. */ public static function get_instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Constructor * * @since 3.0.22 */ public function __construct() {} /** * Import * * @since 3.0.22 * @return void */ public function import() { if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Processing "Customizer" Batch Import' ); } Astra_Sites_Importer_Log::add( '---- Processing batch process for Customizer start ----' ); self::images_download(); Astra_Sites_Importer_Log::add( '---- Processing batch process for Customizer done ----' ); } /** * Downloads images from customizer. */ public static function images_download() { $options = get_option( 'astra-settings', array() ); array_walk_recursive( $options, function ( &$value ) { if ( ! is_array( $value ) && astra_sites_is_valid_image( $value ) ) { $downloaded_image = ST_Image_Importer::get_instance()->import( array( 'url' => $value, 'id' => 0, ) ); $value = $downloaded_image['url']; } } ); // Updated settings. update_option( 'astra-settings', $options ); } } /** * Kicking this off by calling 'get_instance()' method */ Astra_Sites_Batch_Processing_Customizer::get_instance(); PK =3j[u���7 �7 @ batch-processing/class-astra-sites-batch-processing-importer.phpnu �[��� <?php /** * Batch Processing * * @package Astra Sites * @since 2.0.0 */ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Importer' ) ) : /** * Astra_Sites_Batch_Processing_Importer * * @since 1.0.14 */ class Astra_Sites_Batch_Processing_Importer { /** * Instance * * @since 1.0.14 * @access private * @var object Class object. */ private static $instance; /** * Initiator * * @since 1.0.14 * @return object initialized object of class. */ public static function get_instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Constructor * * @since 1.0.14 */ public function __construct() { } /** * Import All Categories and Tags * * @since 2.6.22 * @return void */ public function import_all_categories_and_tags() { astra_sites_error_log( 'Requesting Site Categories' ); update_site_option( 'astra-sites-batch-status-string', 'Requesting Site Categories' ); $api_args = array( 'timeout' => 30, ); $request = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-content/uploads/all-site-categories.json', $api_args ); if ( ! is_wp_error( $request ) && 200 === (int) wp_remote_retrieve_response_code( $request ) ) { $cats = json_decode( wp_remote_retrieve_body( $request ), true ); if ( isset( $cats['code'] ) ) { $message = isset( $cats['message'] ) ? $cats['message'] : ''; if ( ! empty( $message ) ) { astra_sites_error_log( 'HTTP Request Error: ' . $message ); } else { astra_sites_error_log( 'HTTP Request Error!' ); } } else { Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-all-site-categories-and-tags.json', $cats ); do_action( 'astra_sites_sync_all_site_categories_and_tags', $cats ); } } astra_sites_error_log( 'Site Categories Imported Successfully!' ); update_site_option( 'astra-sites-batch-status-string', 'Site Categories Imported Successfully!' ); } /** * Import All Categories and Tags * * @since 2.6.22 * @return void */ public function import_all_categories() { astra_sites_error_log( 'Requesting Site Categories' ); update_site_option( 'astra-sites-batch-status-string', 'Requesting Site Categories' ); $api_args = array( 'timeout' => 30, ); $request = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/astra-sites-site-category/?hide_empty=true&_fields=id,name,slug&per_page=100', $api_args ); if ( ! is_wp_error( $request ) && 200 === (int) wp_remote_retrieve_response_code( $request ) ) { $cats = json_decode( wp_remote_retrieve_body( $request ), true ); if ( isset( $cats['code'] ) ) { $message = isset( $cats['message'] ) ? $cats['message'] : ''; if ( ! empty( $message ) ) { astra_sites_error_log( 'HTTP Request Error: ' . $message ); } else { astra_sites_error_log( 'HTTP Request Error!' ); } } else { Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-all-site-categories.json', $cats ); do_action( 'astra_sites_sync_all_site_categories', $cats ); } } astra_sites_error_log( 'Site Categories Imported Successfully!' ); update_site_option( 'astra-sites-batch-status-string', 'Site Categories Imported Successfully!' ); } /** * Import Categories * * @since 2.0.0 * @return void */ public function import_site_categories() { astra_sites_error_log( 'Requesting Site Categories' ); update_site_option( 'astra-sites-batch-status-string', 'Requesting Site Categories' ); $api_args = array( 'timeout' => 30, ); $categories_request = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/astra-sites-site-category/?hide_empty=true&_fields=id,name,slug&per_page=100', $api_args ); if ( ! is_wp_error( $categories_request ) && 200 === (int) wp_remote_retrieve_response_code( $categories_request ) ) { $categories = json_decode( wp_remote_retrieve_body( $categories_request ), true ); if ( isset( $categories['code'] ) ) { $message = isset( $categories['message'] ) ? $categories['message'] : ''; if ( ! empty( $message ) ) { astra_sites_error_log( 'HTTP Request Error: ' . $message ); } else { astra_sites_error_log( 'HTTP Request Error!' ); } } else { Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-categories.json', $categories ); do_action( 'astra_sites_sync_categories', $categories ); } } astra_sites_error_log( 'Site Categories Imported Successfully!' ); update_site_option( 'astra-sites-batch-status-string', 'Site Categories Imported Successfully!' ); } /** * Import Block Categories * * @since 2.0.0 * @return void */ public function import_block_categories() { astra_sites_error_log( 'Requesting Block Categories' ); update_site_option( 'astra-sites-batch-status-string', 'Requesting Block Categories' ); $api_args = array( 'timeout' => 30, ); $tags_request = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/blocks-category/?_fields=id,name,slug&per_page=100&hide_empty=1', $api_args ); if ( ! is_wp_error( $tags_request ) && 200 === (int) wp_remote_retrieve_response_code( $tags_request ) ) { $tags = json_decode( wp_remote_retrieve_body( $tags_request ), true ); if ( isset( $tags['code'] ) ) { $message = isset( $tags['message'] ) ? $tags['message'] : ''; if ( ! empty( $message ) ) { astra_sites_error_log( 'HTTP Request Error: ' . $message ); } else { astra_sites_error_log( 'HTTP Request Error!' ); } } else { $categories = array(); foreach ( $tags as $key => $value ) { $categories[ $value['id'] ] = $value; } Astra_Sites_File_System::get_instance()->update_json_file( 'astra-blocks-categories.json', $categories ); do_action( 'astra_sites_sync_blocks_categories', $categories ); } } astra_sites_error_log( 'Block Categories Imported Successfully!' ); update_site_option( 'astra-sites-batch-status-string', 'Categories Imported Successfully!' ); } /** * Import Page Builders * * @since 2.0.0 * @return void */ public function set_license_page_builder() { astra_sites_error_log( 'Requesting License Page Builders' ); $url = add_query_arg( array( '_fields' => 'id,name,slug', 'site_url' => get_site_url(), 'purchase_key' => Astra_Sites::get_instance()->get_license_key(), 'only_allow_page_builders' => 'true', ), trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/astra-site-page-builder/' ); $api_args = array( 'timeout' => 30, ); $page_builder_request = wp_safe_remote_get( $url, $api_args ); if ( ! is_wp_error( $page_builder_request ) && 200 === (int) wp_remote_retrieve_response_code( $page_builder_request ) ) { $page_builders = json_decode( wp_remote_retrieve_body( $page_builder_request ), true ); if ( isset( $page_builders['code'] ) ) { $message = isset( $page_builders['message'] ) ? $page_builders['message'] : ''; if ( ! empty( $message ) ) { astra_sites_error_log( 'HTTP Request Error: ' . $message ); } else { astra_sites_error_log( 'HTTP Request Error!' ); } } else { // Set mini agency page builder. $page_builder_slugs = wp_list_pluck( $page_builders, 'slug' ); if ( in_array( 'elementor', $page_builder_slugs ) && ! in_array( 'beaver-builder', $page_builder_slugs ) ) { update_option( 'astra-sites-license-page-builder', 'elementor', 'no' ); astra_sites_error_log( 'Set "Elementor" as License Page Builder' ); } elseif ( in_array( 'beaver-builder', $page_builder_slugs ) && ! in_array( 'elementor', $page_builder_slugs ) ) { update_option( 'astra-sites-license-page-builder', 'beaver-builder', 'no' ); astra_sites_error_log( 'Set "Beaver Builder" as License Page Builder' ); } else { update_option( 'astra-sites-license-page-builder', '', 'no' ); astra_sites_error_log( 'Not Set Any License Page Builder' ); } } } } /** * Import Page Builders * * @since 2.0.0 * @return void */ public function import_page_builders() { astra_sites_error_log( 'Requesting Page Builders' ); update_site_option( 'astra-sites-batch-status-string', 'Requesting Page Builders' ); $purchase_key = Astra_Sites::get_instance()->get_license_key(); $site_url = get_site_url(); $api_args = array( 'timeout' => 30, ); $page_builder_request = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/astra-site-page-builder/?_fields=id,name,slug&site_url=' . $site_url . '&purchase_key=' . $purchase_key, $api_args ); if ( ! is_wp_error( $page_builder_request ) && 200 === (int) wp_remote_retrieve_response_code( $page_builder_request ) ) { $page_builders = json_decode( wp_remote_retrieve_body( $page_builder_request ), true ); if ( isset( $page_builders['code'] ) ) { $message = isset( $page_builders['message'] ) ? $page_builders['message'] : ''; if ( ! empty( $message ) ) { astra_sites_error_log( 'HTTP Request Error: ' . $message ); } else { astra_sites_error_log( 'HTTP Request Error!' ); } } else { Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-page-builders.json', $page_builders ); do_action( 'astra_sites_sync_page_builders', $page_builders ); } } astra_sites_error_log( 'Page Builders Imported Successfully!' ); update_site_option( 'astra-sites-batch-status-string', 'Page Builders Imported Successfully!' ); } /** * Import Blocks * * @since 2.0.0 * @param integer $page Page number. * @return void */ public function import_blocks( $page = 1 ) { astra_sites_error_log( 'BLOCK: -------- ACTUAL IMPORT --------' ); $api_args = array( 'timeout' => 30, ); $all_blocks = array(); astra_sites_error_log( 'BLOCK: Requesting ' . $page ); update_site_option( 'astra-blocks-batch-status-string', 'Requesting for blocks page - ' . $page ); $query_args = apply_filters( 'astra_sites_blocks_query_args', array( 'page_builder' => 'elementor', 'per_page' => 100, 'page' => $page, 'wireframe' => 'yes', ) ); $api_url = add_query_arg( $query_args, trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/astra-blocks/v1/blocks/' ); $response = wp_safe_remote_get( $api_url, $api_args ); if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) { $astra_blocks = json_decode( wp_remote_retrieve_body( $response ), true ); if ( isset( $astra_blocks['code'] ) ) { $message = isset( $astra_blocks['message'] ) ? $astra_blocks['message'] : ''; if ( ! empty( $message ) ) { astra_sites_error_log( 'HTTP Request Error: ' . $message ); } else { astra_sites_error_log( 'HTTP Request Error!' ); } } else { astra_sites_error_log( 'BLOCK: Storing data for page ' . $page . ' in option astra-blocks-' . $page ); update_site_option( 'astra-blocks-batch-status-string', 'Storing data for page ' . $page . ' in option astra-blocks-' . $page ); Astra_Sites_File_System::get_instance()->update_json_file( 'astra-blocks-' . $page . '.json', $astra_blocks ); do_action( 'astra_sites_sync_blocks', $page, $astra_blocks ); } } else { astra_sites_error_log( 'BLOCK: API Error: ' . $response->get_error_message() ); } astra_sites_error_log( 'BLOCK: Complete storing data for blocks ' . $page ); update_site_option( 'astra-blocks-batch-status-string', 'Complete storing data for page ' . $page ); } /** * Import * * @since 1.0.14 * @since 2.0.0 Added page no. * * @param integer $page Page number. * @return array */ public function import_sites( $page = 1 ) { $api_args = array( 'timeout' => 30, ); $sites_and_pages = array(); astra_sites_error_log( 'Requesting ' . $page ); update_site_option( 'astra-sites-batch-status-string', 'Requesting ' . $page ); $query_args = apply_filters( 'astra_sites_import_sites_query_args', array( 'per_page' => 15, 'page' => $page, ) ); $api_url = add_query_arg( $query_args, trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/astra-sites/v1/sites-and-pages/' ); $response = wp_safe_remote_get( $api_url, $api_args ); if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) { $sites_and_pages = json_decode( wp_remote_retrieve_body( $response ), true ); if ( isset( $sites_and_pages['code'] ) ) { $message = isset( $sites_and_pages['message'] ) ? $sites_and_pages['message'] : ''; if ( ! empty( $message ) ) { astra_sites_error_log( 'HTTP Request Error: ' . $message ); } else { astra_sites_error_log( 'HTTP Request Error!' ); } } else { astra_sites_error_log( 'Storing data for page ' . $page . ' in option astra-sites-and-pages-page-' . $page ); update_site_option( 'astra-sites-batch-status-string', 'Storing data for page ' . $page . ' in option astra-sites-and-pages-page-' . $page ); Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-and-pages-page-' . $page . '.json', $sites_and_pages ); do_action( 'astra_sites_sync_sites_and_pages', $page, $sites_and_pages ); } } else { astra_sites_error_log( 'API Error: ' . $response->get_error_message() ); } astra_sites_error_log( 'Complete storing data for page ' . $page ); update_site_option( 'astra-sites-batch-status-string', 'Complete storing data for page ' . $page ); return $sites_and_pages; } } /** * Kicking this off by calling 'get_instance()' method */ Astra_Sites_Batch_Processing_Importer::get_instance(); endif; PK =3j[uf�� � ? batch-processing/class-astra-sites-batch-processing-widgets.phpnu �[��� <?php /** * Batch Processing * * @package Astra Sites * @since 1.0.14 */ use STImporter\Importer\Helpers\ST_Image_Importer; if ( ! class_exists( 'Astra_Sites_Batch_Processing_Widgets' ) ) : /** * Astra_Sites_Batch_Processing_Widgets * * @since 1.0.14 */ class Astra_Sites_Batch_Processing_Widgets { /** * WP Forms. * * @since 2.6.22 * @var object Class object. */ public $wpforms_ids_mapping; /** * Instance * * @since 1.0.14 * @access private * @var object Class object. */ private static $instance; /** * Initiator * * @since 1.0.14 * @return object initialized object of class. */ public static function get_instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Constructor * * @since 1.0.14 */ public function __construct() { } /** * Import * * @since 1.0.14 * @return void */ public function import() { if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Importing Widgets Data' ); } // Catch mapping data. $this->wpforms_ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() ); // Process image widget data. $this->widget_media_image(); // Process text widget data. $this->widget_text(); // Process WP Forms widget data. $this->widget_wpform(); } /** * Widget WP Forms * * @since 3.1.3 * @return void */ public function widget_wpform() { $data = get_option( 'widget_wpforms-widget', null ); if ( empty( $data ) ) { return; } Astra_Sites_Importer_Log::add( '---- Processing Contact Form Mapping from WP Forms Widgets -----' ); foreach ( $data as $key => $value ) { if ( isset( $value['form_id'] ) && ! empty( $value['form_id'] ) ) { $content = $value['form_id']; // Empty mapping? Then return. if ( ! empty( $this->wpforms_ids_mapping ) ) { // Replace ID's. foreach ( $this->wpforms_ids_mapping as $old_id => $new_id ) { if ( $old_id === $content ) { $content = $new_id; } } } $data[ $key ]['form_id'] = $content; if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Updating Contact Form Mapping from WP Forms Widgets' ); } } } update_option( 'widget_wpforms-widget', $data ); } /** * Widget Text * * @since 2.6.22 * @return void */ public function widget_text() { $data = get_option( 'widget_text', null ); if ( empty( $data ) ) { return; } Astra_Sites_Importer_Log::add( '---- Processing Contact Form Mapping from Text Widgets -----' ); foreach ( $data as $key => $value ) { if ( isset( $value['text'] ) && ! empty( $value['text'] ) ) { $content = $value['text']; // Empty mapping? Then return. if ( ! empty( $this->wpforms_ids_mapping ) ) { // Replace ID's. foreach ( $this->wpforms_ids_mapping as $old_id => $new_id ) { $content = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $content ); $content = str_replace( '{"formId":"' . $old_id . '"}', '{"formId":"' . $new_id . '"}', $content ); } } $data[ $key ]['text'] = $content; if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Updating Contact Form Mapping from Text Widgets' ); } } } update_option( 'widget_text', $data ); } /** * Widget Media Image * * @since 1.0.14 * @return void */ public function widget_media_image() { $data = get_option( 'widget_media_image', null ); if ( empty( $data ) ) { return; } Astra_Sites_Importer_Log::add( '---- Processing Images from Widgets -----' ); foreach ( $data as $key => $value ) { if ( isset( $value['url'] ) && isset( $value['attachment_id'] ) ) { $image = array( 'url' => $value['url'], 'id' => $value['attachment_id'], ); $downloaded_image = ST_Image_Importer::get_instance()->import( $image ); $data[ $key ]['url'] = $downloaded_image['url']; $data[ $key ]['attachment_id'] = $downloaded_image['id']; if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Importing Widgets Image: ' . $value['url'] . ' | New Image ' . $downloaded_image['url'] ); } } } update_option( 'widget_media_image', $data ); } } /** * Kicking this off by calling 'get_instance()' method */ Astra_Sites_Batch_Processing_Widgets::get_instance(); endif; PK =3j[��e� � F batch-processing/class-astra-sites-batch-processing-beaver-builder.phpnu �[��� <?php /** * Batch Processing * * @package Astra Sites * @since 1.0.14 */ use STImporter\Importer\Helpers\ST_Image_Importer; if ( ! class_exists( 'Astra_Sites_Batch_Processing_Beaver_Builder' ) ) : /** * Astra_Sites_Batch_Processing_Beaver_Builder * * @since 1.0.14 */ class Astra_Sites_Batch_Processing_Beaver_Builder { /** * Instance * * @since 1.0.14 * @access private * @var object Class object. */ private static $instance; /** * Initiator * * @since 1.0.14 * @return object initialized object of class. */ public static function get_instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Constructor * * @since 1.0.14 */ public function __construct() { } /** * Import * * @since 1.0.14 * @return void */ public function import() { if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Processing "Beaver Builder" Batch Import' ); } Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for Beaver Builder ----' ); if ( ! is_callable( 'FLBuilderModel::get_post_types' ) ) { return; } $post_types = FLBuilderModel::get_post_types( 'post-types' ); if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'For post types: ' . implode( ', ', $post_types ) ); } if ( empty( $post_types ) && ! is_array( $post_types ) ) { return; } $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types ); if ( empty( $post_ids ) && ! is_array( $post_ids ) ) { return; } foreach ( $post_ids as $post_id ) { $this->import_single_post( $post_id ); } } /** * Update post meta. * * @param integer $post_id Post ID. * @return void */ public function import_single_post( $post_id = 0 ) { $is_bb_post = get_post_meta( $post_id, '_fl_builder_enabled', true ); if ( ! $is_bb_post ) { return; } // Is page imported with Starter Sites? // If not then skip batch process. $imported_from_demo_site = get_post_meta( $post_id, '_astra_sites_enable_for_batch', true ); if ( ! $imported_from_demo_site ) { return; } if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Beaver Builder - Processing page: ' . $post_id ); } Astra_Sites_Importer_Log::add( '---- Processing WordPress Page - for Beaver Builder ---- "' . $post_id . '"' ); if ( ! empty( $post_id ) ) { // Get page builder data. $data = get_post_meta( $post_id, '_fl_builder_data', true ); if ( ! empty( $data ) ) { foreach ( $data as $key => $el ) { // Update 'row' images. if ( 'row' === $el->type ) { $data[ $key ]->settings = self::update_row( $el->settings ); } // Update 'module' images. if ( 'module' === $el->type ) { $data[ $key ]->settings = self::update_module( $el->settings ); } // Update 'column' images. if ( 'column' === $el->type ) { $data[ $key ]->settings = self::update_column( $el->settings ); } } // Update page builder data. update_post_meta( $post_id, '_fl_builder_data', $data ); update_post_meta( $post_id, '_fl_builder_draft', $data ); // Clear all cache. FLBuilderModel::delete_asset_cache_for_all_posts(); } // Clean the post excerpt. astra_sites_empty_post_excerpt( $post_id ); } } /** * Import Module Images. * * @param object $settings Module settings object. * @return object */ public static function update_module( $settings ) { // 1) Set photos. $settings = self::import_photo( $settings ); /** * 2) Set `$settings->data` for Only type 'image-icon' * * @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon. */ if ( isset( $settings->data ) && isset( $settings->photo ) && ! empty( $settings->photo ) && 'image-icon' === $settings->type ) { $settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo ); } if ( 'uabb-wp-forms-styler' === $settings->type ) { astra_sites_error_log( '--------WP Form Styler ID replacement start-------' ); $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() ); if ( $ids_mapping ) { // Update WP form IDs. foreach ( $ids_mapping as $old_id => $new_id ) { if ( isset( $settings->wp_form_id ) && $old_id === $settings->wp_form_id ) { astra_sites_error_log( '--------WP Form Styler ID ' . $old_id . ' replaced to ' . $new_id . '-------' ); $settings->wp_form_id = $new_id; } } } astra_sites_error_log( '--------WP Form Styler ID replacement done-------' ); } // 3) Set `list item` module images. if ( isset( $settings->add_list_item ) ) { foreach ( $settings->add_list_item as $key => $value ) { $settings->add_list_item[ $key ] = self::import_photo( $value ); } } // 4) Set `list item` module images. if ( isset( $settings->text ) ) { $settings->text = self::get_wpforms_mapping( $settings->text ); } elseif ( isset( $settings->html ) ) { $settings->html = self::get_wpforms_mapping( $settings->html ); } return $settings; } /** * Replace WP Forms shortcode. * * @since 2.0.0 * @param string $content Content. * @return string Content. */ private static function get_wpforms_mapping( $content = '' ) { $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() ); astra_sites_error_log( wp_json_encode( $ids_mapping ) ); if ( $ids_mapping ) { // Update WP form IDs. foreach ( $ids_mapping as $old_id => $new_id ) { $content = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $content ); } } return $content; } /** * Import Column Images. * * @param object $settings Column settings object. * @return object */ public static function update_column( $settings ) { // 1) Set BG Images. $settings = self::import_bg_image( $settings ); return $settings; } /** * Import Row Images. * * @param object $settings Row settings object. * @return object */ public static function update_row( $settings ) { // 1) Set BG Images. $settings = self::import_bg_image( $settings ); return $settings; } /** * Helper: Import BG Images. * * @param object $settings Row settings object. * @return object */ public static function import_bg_image( $settings ) { if ( ( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) ) ) { $image = array( 'url' => $settings->bg_image_src, 'id' => $settings->bg_image, ); $downloaded_image = ST_Image_Importer::get_instance()->import( $image ); $settings->bg_image_src = $downloaded_image['url']; $settings->bg_image = $downloaded_image['id']; } return $settings; } /** * Helper: Import Photo. * * @param object $settings Row settings object. * @return object */ public static function import_photo( $settings ) { if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) { $image = array( 'url' => $settings->photo_src, 'id' => $settings->photo, ); $downloaded_image = ST_Image_Importer::get_instance()->import( $image ); $settings->photo_src = $downloaded_image['url']; $settings->photo = $downloaded_image['id']; } return $settings; } } /** * Kicking this off by calling 'get_instance()' method */ Astra_Sites_Batch_Processing_Beaver_Builder::get_instance(); endif; PK =3j[���~r r 7 batch-processing/class-astra-sites-batch-processing.phpnu �[��� <?php /** * Batch Processing * * @package Astra Sites * @since 1.0.14 */ if ( ! class_exists( 'Astra_Sites_Batch_Processing' ) ) : /** * Astra_Sites_Batch_Processing * * @since 1.0.14 */ class Astra_Sites_Batch_Processing { /** * Instance * * @since 1.0.14 * @var object Class object. * @access private */ private static $instance; /** * Process All * * @since 1.0.14 * @var object Class object. * @access public */ public static $process_all; /** * Force Sync * * @since 4.2.4 * @var bool is force sync. * @access public */ public static $is_force_sync = false; /** * Last Export Checksums * * @since 2.0.0 * @var object Class object. * @access public */ public $last_export_checksums; /** * Sites Importer * * @since 2.0.0 * @var object Class object. * @access public */ public static $process_site_importer; /** * Process Single Page * * @since 2.0.0 * @var object Class object. * @access public */ public static $process_single; /** * Initiator * * @since 1.0.14 * @return object initialized object of class. */ public static function get_instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Constructor * * @since 1.0.14 */ public function __construct() { $this->includes(); $this->check_is_force_sync(); // Start image importing after site import complete. add_filter( 'astra_sites_image_importer_skip_image', array( $this, 'skip_image' ), 10, 2 ); add_action( 'astra_sites_import_complete', array( $this, 'start_process' ) ); add_action( 'astra_sites_process_single', array( $this, 'start_process_single' ) ); if ( current_user_can( 'manage_options' ) ) { add_action( 'admin_init', array( $this, 'start_importer' ) ); } add_action( 'wp_ajax_astra-sites-update-library', array( $this, 'update_library' ) ); add_action( 'wp_ajax_astra-sites-update-library-complete', array( $this, 'update_library_complete' ) ); add_action( 'wp_ajax_astra-sites-import-all-categories-and-tags', array( $this, 'import_all_categories_and_tags' ) ); add_action( 'wp_ajax_astra-sites-import-all-categories', array( $this, 'import_all_categories' ) ); add_action( 'wp_ajax_astra-sites-import-block-categories', array( $this, 'import_block_categories' ) ); add_action( 'wp_ajax_astra-sites-import-page-builders', array( $this, 'import_page_builders' ) ); add_action( 'wp_ajax_astra-sites-import-blocks', array( $this, 'import_blocks' ) ); add_action( 'wp_ajax_astra-sites-get-sites-request-count', array( $this, 'sites_requests_count' ) ); add_action( 'wp_ajax_astra-sites-get-blocks-request-count', array( $this, 'blocks_requests_count' ) ); add_action( 'wp_ajax_astra-sites-import-sites', array( $this, 'import_sites' ) ); add_action( 'wp_ajax_astra-sites-get-all-categories', array( $this, 'get_all_categories' ) ); add_action( 'wp_ajax_astra-sites-get-all-categories-and-tags', array( $this, 'get_all_categories_and_tags' ) ); add_action( 'astra_sites_site_import_batch_complete', array( $this, 'sync_batch_complete' ) ); } /** * Start Image Import * * @since 1.0.14 * * @return void */ public function start_process() { set_transient( 'astra_sites_batch_process_started', 'yes', HOUR_IN_SECONDS ); /** WordPress Plugin Administration API */ require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once ABSPATH . 'wp-admin/includes/update.php'; $this->includes(); $wxr_id = get_site_option( 'astra_sites_imported_wxr_id', 0 ); if ( $wxr_id ) { wp_delete_attachment( $wxr_id, true ); Astra_Sites_Importer_Log::add( 'Deleted Temporary WXR file ' . $wxr_id ); delete_option( 'astra_sites_imported_wxr_id' ); Astra_Sites_Importer_Log::add( 'Option `astra_sites_imported_wxr_id` Deleted.' ); } $classes = array(); Astra_Sites_Importer_Log::add( 'Batch Process Started..' ); Astra_Sites_Importer_Log::add( Astra_Sites_White_Label::get_instance()->get_white_label_name( ASTRA_SITES_NAME ) . ' - Importing Images for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' ); // Add "widget" in import [queue]. $classes[] = Astra_Sites_Batch_Processing_Widgets::get_instance(); // Add "brizy" in import [queue]. if ( is_plugin_active( 'brizy/brizy.php' ) ) { $classes[] = Astra_Sites_Batch_Processing_Brizy::get_instance(); } // Add "bb-plugin" in import [queue]. // Add "beaver-builder-lite-version" in import [queue]. if ( is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) || is_plugin_active( 'bb-plugin/fl-builder.php' ) ) { $classes[] = Astra_Sites_Batch_Processing_Beaver_Builder::get_instance(); } // Add "elementor" in import [queue]. // @todo Remove required `allow_url_fopen` support. if ( ini_get( 'allow_url_fopen' ) && is_plugin_active( 'elementor/elementor.php' ) ) { $import = new \Elementor\TemplateLibrary\Astra_Sites_Batch_Processing_Elementor(); $classes[] = $import; } // Add "astra-addon" in import [queue]. if ( is_plugin_active( 'astra-addon/astra-addon.php' ) ) { $classes[] = Astra_Sites_Compatibility_Astra_Pro::get_instance(); } // Add "customizer" in import [queue]. $classes[] = Astra_Sites_Batch_Processing_Customizer::get_instance(); if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Batch Process Started..' ); // Process all classes. foreach ( $classes as $key => $class ) { if ( method_exists( $class, 'import' ) ) { $class->import(); } } WP_CLI::line( 'Batch Process Complete!' ); } else { // Add all classes to batch queue. foreach ( $classes as $key => $class ) { self::$process_all->push_to_queue( $class ); } // Dispatch Queue. self::$process_all->save()->dispatch(); } } /** * Check if sync is forced. * * @return void */ public function check_is_force_sync() { if ( isset( $_GET['st-force-sync'] ) && 'true' === $_GET['st-force-sync'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended self::$is_force_sync = true; } } /** * Update the latest checksum after all the import batch processes are done. */ public function sync_batch_complete() { Astra_Sites_Importer::get_instance()->update_latest_checksums(); } /** * Include Files * * @since 2.5.0 */ public function includes() { // Core Helpers - Image. // @todo This file is required for Elementor. // Once we implement our logic for updating elementor data then we'll delete this file. require_once ABSPATH . 'wp-admin/includes/image.php'; // Prepare Widgets. require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-widgets.php'; // Prepare Page Builders. require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php'; require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php'; require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php'; // Prepare Cleanup. require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-cleanup.php'; // // Prepare Customizer. require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-customizer.php'; // // Process Importer. require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-importer.php'; self::$process_all = new WP_Background_Process_Astra(); self::$process_single = new WP_Background_Process_Astra_Single(); self::$process_site_importer = new WP_Background_Process_Astra_Site_Importer(); } /** * Import All Categories * * @since 2.6.22 * @return void */ public function import_all_categories() { 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' ); } Astra_Sites_Batch_Processing_Importer::get_instance()->import_all_categories(); wp_send_json_success(); } /** * Import All Categories and Tags * * @since 2.6.22 * @return void */ public function import_all_categories_and_tags() { 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' ); } Astra_Sites_Batch_Processing_Importer::get_instance()->import_all_categories_and_tags(); wp_send_json_success(); } /** * Import Block Categories * * @since 2.0.0 * @return void */ public function import_block_categories() { 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' ); } Astra_Sites_Batch_Processing_Importer::get_instance()->import_block_categories(); wp_send_json_success(); } /** * Import Page Builders * * @since 2.0.0 * @return void */ public function import_page_builders() { 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' ); } Astra_Sites_Batch_Processing_Importer::get_instance()->import_page_builders(); wp_send_json_success(); } /** * Import Blocks * * @since 2.0.0 * @return void */ public function import_blocks() { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error(); } $page_no = isset( $_POST['page_no'] ) ? absint( $_POST['page_no'] ) : ''; if ( $page_no ) { $sites_and_pages = Astra_Sites_Batch_Processing_Importer::get_instance()->import_blocks( $page_no ); wp_send_json_success(); } wp_send_json_error(); } /** * Import Sites * * @since 2.0.0 * @return void */ public function import_sites() { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error(); } $page_no = isset( $_POST['page_no'] ) ? absint( $_POST['page_no'] ) : ''; if ( $page_no ) { $sites_and_pages = Astra_Sites_Batch_Processing_Importer::get_instance()->import_sites( $page_no ); wp_send_json_success( $sites_and_pages ); } wp_send_json_error(); } /** * Sites Requests Count * * @since 2.0.0 * @return void */ public function sites_requests_count() { 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' ); } // Get count. $total_requests = $this->get_total_requests(); if ( $total_requests ) { wp_send_json_success( $total_requests ); } wp_send_json_error(); } /** * Blocks Requests Count * * @since 2.1.0 * @return void */ public function blocks_requests_count() { 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' ); } // Get count. $total_requests = $this->get_total_blocks_requests(); if ( $total_requests ) { wp_send_json_success( $total_requests ); } wp_send_json_error(); } /** * Update Library Complete * * @since 2.0.0 * @return void */ public function update_library_complete() { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error(); } Astra_Sites_Importer::get_instance()->update_latest_checksums(); do_action( 'starter_templates_save_sites_count_as_per_page_builder' ); update_site_option( 'astra-sites-batch-is-complete', 'no' ); update_site_option( 'astra-sites-manual-sync-complete', 'yes' ); wp_send_json_success(); } /** * Get Last Exported Checksum Status * * @since 2.0.0 * @return string Checksums Status. */ public function get_last_export_checksums() { $old_last_export_checksums = get_site_option( 'astra-sites-last-export-checksums', '' ); $new_last_export_checksums = $this->set_last_export_checksums(); $checksums_status = 'no'; if ( empty( $old_last_export_checksums ) ) { $checksums_status = 'yes'; } if ( $new_last_export_checksums !== $old_last_export_checksums ) { $checksums_status = 'yes'; } return apply_filters( 'astra_sites_checksums_status', $checksums_status ); } /** * Set Last Exported Checksum * * @since 2.0.0 * @return string Checksums Status. */ public function set_last_export_checksums() { if ( ! empty( $this->last_export_checksums ) ) { return $this->last_export_checksums; } $api_args = array( 'timeout' => 60, ); $response = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/astra-sites/v1/get-last-export-checksums', $api_args ); if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) { $result = json_decode( wp_remote_retrieve_body( $response ), true ); // Set last export checksums. if ( ! empty( $result['last_export_checksums'] ) ) { update_site_option( 'astra-sites-last-export-checksums-latest', $result['last_export_checksums'] ); $this->last_export_checksums = $result['last_export_checksums']; } } return $this->last_export_checksums; } /** * Update Library * * @since 2.0.0 * @return void */ public function update_library() { check_ajax_referer( 'astra-sites', '_ajax_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error(); } if ( 'no' === $this->get_last_export_checksums() ) { wp_send_json_success( 'updated' ); } wp_send_json_success(); } /** * Start Importer * * @since 2.0.0 * @return void */ public function start_importer() { $process_sync = apply_filters( 'astra_sites_initial_sync', true ); if ( ! $process_sync && ! self::$is_force_sync ) { return; } $is_fresh_site = get_site_option( 'astra-sites-fresh-site', '' ); if ( self::$is_force_sync || ( empty( $is_fresh_site ) && '' === $is_fresh_site ) ) { $this->process_import(); update_site_option( 'astra-sites-fresh-site', 'no' ); } } /** * Process Batch * * @since 2.0.0 * @return mixed */ public function process_batch() { $process_sync = apply_filters( 'astra_sites_process_sync_batch', true ); if ( ! $process_sync && ! self::$is_force_sync ) { return; } if ( 'no' === $this->get_last_export_checksums() && ! self::$is_force_sync ) { $this->log( 'Library is up to date!' ); if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Library is up to date!' ); } return; } $is_cron_disabled = false; $status = Astra_Sites_Page::get_instance()->test_cron(); if ( is_wp_error( $status ) ) { astra_sites_error_log( 'Error! Batch Not Start due to disabled cron events!' ); update_site_option( 'astra-sites-batch-status-string', 'Error! Batch Not Start due to disabled cron events!' ); if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Error! Batch Not Start due to disabled cron events!' ); } else { $is_cron_disabled = true; } } $this->log( 'Sync Library Started!' ); // Added the categories and tags. $this->log( 'Added All Categories and tags in queue.' ); if ( defined( 'WP_CLI' ) || $is_cron_disabled ) { Astra_Sites_Batch_Processing_Importer::get_instance()->import_all_categories_and_tags(); } else { self::$process_site_importer->push_to_queue( array( 'instance' => Astra_Sites_Batch_Processing_Importer::get_instance(), 'method' => 'import_all_categories_and_tags', ) ); } // Added the categories. $this->log( 'Added All Site Categories in queue.' ); if ( defined( 'WP_CLI' ) || $is_cron_disabled ) { Astra_Sites_Batch_Processing_Importer::get_instance()->import_all_categories(); } else { self::$process_site_importer->push_to_queue( array( 'instance' => Astra_Sites_Batch_Processing_Importer::get_instance(), 'method' => 'import_all_categories', ) ); } // Added the page_builders. $this->log( 'Added page builders in queue.' ); if ( defined( 'WP_CLI' ) || $is_cron_disabled ) { Astra_Sites_Batch_Processing_Importer::get_instance()->import_page_builders(); } else { self::$process_site_importer->push_to_queue( array( 'instance' => Astra_Sites_Batch_Processing_Importer::get_instance(), 'method' => 'import_page_builders', ) ); } // Get count. $total_requests = $this->get_total_blocks_requests(); if ( $total_requests ) { $this->log( 'BLOCK: Total Blocks Requests ' . $total_requests ); for ( $page = 1; $page <= $total_requests; $page++ ) { $this->log( 'BLOCK: Added page ' . $page . ' in queue.' ); if ( defined( 'WP_CLI' ) || $is_cron_disabled ) { Astra_Sites_Batch_Processing_Importer::get_instance()->import_blocks( $page ); } else { self::$process_site_importer->push_to_queue( array( 'page' => $page, 'instance' => Astra_Sites_Batch_Processing_Importer::get_instance(), 'method' => 'import_blocks', ) ); } } } // Added the categories. $this->log( 'Added Block Categories in queue.' ); if ( defined( 'WP_CLI' ) || $is_cron_disabled ) { Astra_Sites_Batch_Processing_Importer::get_instance()->import_block_categories(); } else { self::$process_site_importer->push_to_queue( array( 'instance' => Astra_Sites_Batch_Processing_Importer::get_instance(), 'method' => 'import_block_categories', ) ); } // Get count. $total_requests = $this->get_total_requests(); if ( $total_requests ) { $this->log( 'Total Requests ' . $total_requests ); for ( $page = 1; $page <= $total_requests; $page++ ) { $this->log( 'Added page ' . $page . ' in queue.' ); if ( defined( 'WP_CLI' ) || $is_cron_disabled ) { Astra_Sites_Batch_Processing_Importer::get_instance()->import_sites( $page ); } else { self::$process_site_importer->push_to_queue( array( 'page' => $page, 'instance' => Astra_Sites_Batch_Processing_Importer::get_instance(), 'method' => 'import_sites', ) ); } } } if ( defined( 'WP_CLI' ) || $is_cron_disabled ) { $this->log( 'Sync Process Complete.' ); $this->sync_batch_complete(); delete_site_option( 'astra-sites-batch-status' ); update_site_option( 'astra-sites-batch-is-complete', 'yes' ); } else { // Dispatch Queue. $this->log( 'Dispatch the Queue!' ); self::$process_site_importer->save()->dispatch(); } } /** * Log * * @since 2.0.0 * * @param string $message Log message. * @return void. */ public function log( $message = '' ) { if ( defined( 'WP_CLI' ) ) { WP_CLI::line( $message ); } else { astra_sites_error_log( $message ); update_site_option( 'astra-sites-batch-status-string', $message ); } } /** * Process Import * * @since 2.0.0 * * @return mixed Null if process is already started. */ public function process_import() { $process_sync = apply_filters( 'astra_sites_process_auto_sync_library', true ); if ( ! $process_sync && ! self::$is_force_sync ) { return; } // Batch is already started? Then return. $status = get_site_option( 'astra-sites-batch-status' ); if ( 'in-process' === $status ) { return; } // Check batch expiry. $expired = get_site_transient( 'astra-sites-import-check' ); if ( false !== $expired && ! self::$is_force_sync ) { return; } // For 1 week. set_site_transient( 'astra-sites-import-check', 'true', apply_filters( 'astra_sites_sync_check_time', WEEK_IN_SECONDS ) ); update_site_option( 'astra-sites-batch-status', 'in-process' ); // Process batch. $this->process_batch(); } /** * Get Total Requests * * @return integer */ public function get_total_requests() { astra_sites_error_log( 'Getting Total Pages' ); update_site_option( 'astra-sites-batch-status-string', 'Getting Total Pages' ); $api_args = array( 'timeout' => 60, ); $response = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/astra-sites/v1/get-total-pages/?per_page=15', $api_args ); if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) { $total_requests = json_decode( wp_remote_retrieve_body( $response ), true ); if ( isset( $total_requests['pages'] ) ) { $this->log( 'Updated requests ' . $total_requests['pages'] ); Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-requests.json', $total_requests['pages'] ); do_action( 'astra_sites_sync_get_total_pages', $total_requests['pages'] ); return $total_requests['pages']; } } astra_sites_error_log( 'Request Failed! Still Calling..' ); update_site_option( 'astra-sites-batch-status-string', 'Request Failed! Still Calling..' ); } /** * Get Blocks Total Requests * * @return integer */ public function get_total_blocks_requests() { astra_sites_error_log( 'BLOCK: Getting Total Blocks' ); update_site_option( 'astra-sites-batch-status-string', 'Getting Total Blocks' ); $api_args = array( 'timeout' => 60, ); $query_args = array( 'page_builder' => 'elementor', 'wireframe' => 'yes', ); $api_url = add_query_arg( $query_args, trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/astra-blocks/v1/get-blocks-count/' ); $response = wp_safe_remote_get( $api_url, $api_args ); if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) { $total_requests = json_decode( wp_remote_retrieve_body( $response ), true ); if ( isset( $total_requests['pages'] ) ) { astra_sites_error_log( 'BLOCK: Updated requests ' . $total_requests['pages'] ); update_site_option( 'astra-blocks-batch-status-string', 'Updated requests ' . $total_requests['pages'] ); Astra_Sites_File_System::get_instance()->update_json_file( 'astra-blocks-requests.json', $total_requests['pages'] ); do_action( 'astra_sites_sync_blocks_requests', $total_requests['pages'] ); return $total_requests['pages']; } } astra_sites_error_log( 'BLOCK: Request Failed! Still Calling..' ); update_site_option( 'astra-blocks-batch-status-string', 'Request Failed! Still Calling..' ); } /** * Start Single Page Import * * @param int $page_id Page ID . * @since 2.0.0 * @return void */ public function start_process_single( $page_id ) { astra_sites_error_log( '=================== ' . Astra_Sites_White_Label::get_instance()->get_white_label_name( ASTRA_SITES_NAME ) . ' - Single Page - Importing Images for Blog name \'' . get_the_title( $page_id ) . '\' (' . $page_id . ') ===================' ); $default_page_builder = Astra_Sites_Page::get_instance()->get_setting( 'page_builder' ); // Add "brizy" in import [queue]. if ( 'brizy' === $default_page_builder && is_plugin_active( 'brizy/brizy.php' ) ) { // Add "gutenberg" in import [queue]. self::$process_single->push_to_queue( array( 'page_id' => $page_id, 'instance' => Astra_Sites_Batch_Processing_Brizy::get_instance(), ) ); } // Add "bb-plugin" in import [queue]. if ( 'beaver-builder' === $default_page_builder && ( is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) || is_plugin_active( 'bb-plugin/fl-builder.php' ) ) ) { // Add "gutenberg" in import [queue]. self::$process_single->push_to_queue( array( 'page_id' => $page_id, 'instance' => Astra_Sites_Batch_Processing_Beaver_Builder::get_instance(), ) ); } // Add "elementor" in import [queue]. if ( 'elementor' === $default_page_builder ) { // @todo Remove required `allow_url_fopen` support. if ( ini_get( 'allow_url_fopen' ) ) { if ( is_plugin_active( 'elementor/elementor.php' ) ) { // !important, Clear the cache after images import. \Elementor\Plugin::$instance->posts_css_manager->clear_cache(); $import = new \Elementor\TemplateLibrary\Astra_Sites_Batch_Processing_Elementor(); self::$process_single->push_to_queue( array( 'page_id' => $page_id, 'instance' => $import, ) ); } } else { astra_sites_error_log( 'Couldn\'t not import image due to allow_url_fopen() is disabled!' ); } } // Dispatch Queue. self::$process_single->save()->dispatch(); } /** * Skip Image from Batch Processing. * * @since 1.0.14 * * @param boolean $can_process Batch process image status. * @param array $attachment Batch process image input. * @return boolean */ public function skip_image( $can_process, $attachment ) { if ( isset( $attachment['url'] ) && ! empty( $attachment['url'] ) ) { // If image URL contain current site URL? then return true to skip that image from import. if ( strpos( $attachment['url'], site_url() ) !== false ) { return true; } $ai_site_url = get_option( 'ast_ai_import_current_url', '' ); $ai_host_url = ''; if ( ! empty( $ai_site_url ) ) { $url = wp_parse_url( $ai_site_url ); $ai_host_url = ! empty( $url['host'] ) ? $url['host'] : ''; } if ( strpos( $attachment['url'], 'brainstormforce.com' ) !== false || strpos( $attachment['url'], 'wpastra.com' ) !== false || strpos( $attachment['url'], 'sharkz.in' ) !== false || strpos( $attachment['url'], 'websitedemos.net' ) !== false || ( ! empty( $ai_host_url ) && strpos( $attachment['url'], $ai_host_url ) !== false ) ) { return false; } } return true; } /** * Get all post id's * * @since 1.0.14 * * @param array $post_types Post types. * @return array */ public static function get_pages( $post_types = array() ) { if ( $post_types ) { $args = array( 'post_type' => $post_types, // Query performance optimization. 'fields' => 'ids', 'no_found_rows' => true, 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array( //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query array( 'key' => '_astra_sites_imported_post', 'value' => '1', 'compare' => '=', ), ), ); $query = new WP_Query( $args ); // Have posts? if ( $query->have_posts() ) : return $query->posts; endif; } return null; } /** * Get Supporting Post Types.. * * @since 1.3.7 * @param integer $feature Feature. * @return array */ public static function get_post_types_supporting( $feature ) { global $_wp_post_type_features; $post_types = array_keys( wp_filter_object_list( $_wp_post_type_features, array( $feature => true ) ) ); return $post_types; } /** * Get all categories. * * @return void */ public function get_all_categories() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } $all_categories = Astra_Sites_File_System::get_instance()->get_json_file_content( 'astra-sites-all-site-categories.json' ); wp_send_json_success( $all_categories ); } wp_send_json_error( __( 'You are not allowed to perform this action.', 'astra-sites' ) ); } /** * Get all categories and tags. * * @return void */ public function get_all_categories_and_tags() { if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) { if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) ); } $all_categories_and_tags = Astra_Sites_File_System::get_instance()->get_json_file_content( 'astra-sites-all-site-categories-and-tags.json' ); wp_send_json_success( $all_categories_and_tags ); } wp_send_json_error( __( 'You are not allowed to perform this action.', 'astra-sites' ) ); } } /** * Kicking this off by calling 'get_instance()' method */ Astra_Sites_Batch_Processing::get_instance(); endif; PK =3j[��a5d d = batch-processing/class-astra-sites-batch-processing-brizy.phpnu �[��� <?php /** * Batch Processing * * @package Astra Sites * @since 1.2.14 */ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Brizy' ) ) : /** * Astra Sites Batch Processing Brizy * * @since 1.2.14 */ class Astra_Sites_Batch_Processing_Brizy { /** * Instance * * @since 1.2.14 * @access private * @var object Class object. */ private static $instance; /** * Initiator * * @since 1.2.14 * @return object initialized object of class. */ public static function get_instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Constructor * * @since 1.2.14 */ public function __construct() {} /** * Import * * @since 1.2.14 * @return void */ public function import() { if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Processing "Brizy" Batch Import' ); } Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for "Brizy" ----' ); if ( ! is_callable( 'Brizy_Editor_Storage_Common::instance' ) ) { return; } $post_types = Brizy_Editor_Storage_Common::instance()->get( 'post-types' ); if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'For post types: ' . implode( ', ', $post_types ) ); } if ( empty( $post_types ) && ! is_array( $post_types ) ) { return; } $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types ); if ( empty( $post_ids ) && ! is_array( $post_ids ) ) { return; } foreach ( $post_ids as $post_id ) { $this->import_single_post( $post_id ); } } /** * Update post meta. * * @param integer $post_id Post ID. * @return void */ public function import_single_post( $post_id = 0 ) { $is_brizy_post = get_post_meta( $post_id, 'brizy_post_uid', true ); if ( ! $is_brizy_post ) { return; } // Is page imported with Starter Sites? // If not then skip batch process. $imported_from_demo_site = get_post_meta( $post_id, '_astra_sites_enable_for_batch', true ); if ( ! $imported_from_demo_site ) { return; } if ( defined( 'WP_CLI' ) ) { WP_CLI::line( 'Brizy - Processing page: ' . $post_id ); } astra_sites_error_log( '---- Processing WordPress Page - for "Brizy" ---- "' . $post_id . '"' ); $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() ); $json_value = null; $post = Brizy_Editor_Post::get( (int) $post_id ); $editor_data = $post->get_editor_data(); // Empty mapping? Then return. if ( ! empty( $ids_mapping ) ) { // Update WPForm IDs. astra_sites_error_log( '---- Processing WP Forms Mapping ----' ); astra_sites_error_log( $ids_mapping ); foreach ( $ids_mapping as $old_id => $new_id ) { $editor_data = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $editor_data ); } } $post->set_editor_data( $editor_data ); $post->set_needs_compile( $post->get_needs_compile() ); $post->set_editor_version( BRIZY_EDITOR_VERSION ); $post->set_compiler_version( BRIZY_EDITOR_VERSION ); $post->set_plugin_version( BRIZY_VERSION ); $post->saveStorage(); $post->savePost(); // Clean the post excerpt. astra_sites_empty_post_excerpt( $post_id ); } } /** * Kicking this off by calling 'get_instance()' method */ Astra_Sites_Batch_Processing_Brizy::get_instance(); endif; PK =3j[^?8 8 A batch-processing/class-astra-sites-batch-processing-elementor.phpnu �[��� <?php /** * Elementor Importer * * @package Astra Sites */ namespace Elementor\TemplateLibrary; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } // If plugin - 'Elementor' not exist then return. if ( ! class_exists( '\Elementor\Plugin' ) ) { return; } use Elementor\Core\Base\Document; use Elementor\Core\Editor\Editor; use Elementor\DB; use Elementor\Core\Settings\Manager as SettingsManager; use Elementor\Core\Settings\Page\Model; use Elementor\Modules\Library\Documents\Library_Document; use Elementor\Plugin; use Elementor\Utils; /** * Elementor template library local source. * * Elementor template library local source handler class is responsible for * handling local Elementor templates saved by the user locally on his site. * * @since 1.2.13 Added compatibility for Elemetnor v2.5.0 * @since 1.0.0 */ class Astra_Sites_Batch_Processing_Elementor extends Source_Local { /** * Import * * @since 1.0.14 * @return void */ public function import() { if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'Processing "Elementor" Batch Import' ); } \Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for Elementor ----' ); $post_types = \Astra_Sites_Batch_Processing::get_post_types_supporting( 'elementor' ); if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'For post types: ' . implode( ', ', $post_types ) ); } if ( empty( $post_types ) && ! is_array( $post_types ) ) { return; } // 🎯 Image Duplication fix: Use simple query and filter in PHP. $post_ids = \Astra_Sites_Batch_Processing::get_pages( $post_types ); if ( empty( $post_ids ) && ! is_array( $post_ids ) ) { return; } // 🎯 PERFORMANCE FIX: Filter out already processed pages in PHP (faster than complex meta_query). $unprocessed_posts = $this->filter_unprocessed_posts( $post_ids ); if ( empty( $unprocessed_posts ) ) { \Astra_Sites_Importer_Log::add( 'No Elementor pages found that need processing.' ); return; } \Astra_Sites_Importer_Log::add( 'Found ' . count( $unprocessed_posts ) . ' Elementor pages to process.' ); foreach ( $unprocessed_posts as $post_id ) { $this->import_single_post( $post_id ); } } /** * Update post meta. * * @since 1.0.14 * @param integer $post_id Post ID. * @return void */ public function import_single_post( $post_id = 0 ) { $is_elementor_post = get_post_meta( $post_id, '_elementor_version', true ); if ( ! $is_elementor_post ) { return; } // Is page imported with Starter Sites? // If not then skip batch process. $imported_from_demo_site = get_post_meta( $post_id, '_astra_sites_enable_for_batch', true ); if ( ! $imported_from_demo_site ) { return; } // 🎯 FIX: Check if this page has already been processed by Elementor batch processing. $already_processed = get_post_meta( $post_id, '_astra_sites_hotlink_imported', true ); if ( $already_processed ) { if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'Elementor - Skipping already processed page: ' . $post_id ); } \Astra_Sites_Importer_Log::add( '---- Skipping Already Processed Elementor Page ---- "' . $post_id . '"' ); return; } if ( defined( 'WP_CLI' ) ) { \WP_CLI::line( 'Elementor - Processing page: ' . $post_id ); } \Astra_Sites_Importer_Log::add( '---- Processing WordPress Page - for Elementor ---- "' . $post_id . '"' ); if ( ! empty( $post_id ) ) { $data = get_post_meta( $post_id, '_elementor_data', true ); \Astra_Sites_Importer_Log::add( wp_json_encode( $data ) ); if ( ! empty( $data ) ) { // Update WP form IDs. $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() ); \Astra_Sites_Importer_Log::add( wp_json_encode( $ids_mapping ) ); if ( $ids_mapping ) { foreach ( $ids_mapping as $old_id => $new_id ) { $data = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $data ); $data = str_replace( '"select_form":"' . $old_id, '"select_form":"' . $new_id, $data ); $data = str_replace( '"form_id":"' . $old_id, '"form_id":"' . $new_id, $data ); } } if ( ! is_array( $data ) ) { $data = json_decode( $data, true ); } \Astra_Sites_Importer_Log::add( wp_json_encode( $data ) ); $document = Plugin::$instance->documents->get( $post_id ); if ( $document ) { $data = $document->get_elements_raw_data( $data, true ); } // Import the data. $data = $this->process_export_import_content( $data, 'on_import' ); // Replace the site urls. $demo_data = \Astra_Sites_File_System::get_instance()->get_demo_content(); \Astra_Sites_Importer_Log::add( wp_json_encode( $demo_data ) ); if ( isset( $demo_data['astra-site-url'] ) ) { $data = wp_json_encode( $data ); if ( ! empty( $data ) ) { $site_url = get_site_url(); $site_url = str_replace( '/', '\/', $site_url ); $demo_site_url = 'https:' . $demo_data['astra-site-url']; $demo_site_url = str_replace( '/', '\/', $demo_site_url ); $data = str_replace( $demo_site_url, $site_url, $data ); $data = wp_slash( $data ); // slash is added for smooth unslashing on updating metadata. } } // Update processed meta. update_metadata( 'post', $post_id, '_elementor_data', $data ); update_metadata( 'post', $post_id, '_astra_sites_hotlink_imported', true ); // 🎯 FIX: Add timestamp to track when processing was completed. update_metadata( 'post', $post_id, '_astra_sites_elementor_processed_time', time() ); // !important, Clear the cache after images import. Plugin::$instance->files_manager->clear_cache(); } // Clean the post excerpt. $clean_post_excerpt = apply_filters( 'astra_sites_pre_process_post_empty_excerpt', true ); if ( $clean_post_excerpt ) { astra_sites_empty_post_excerpt( $post_id ); } } } /** * Filter posts to get only those that need Elementor processing * * @since 4.4.27 * @param array $post_ids Array of post IDs to filter. * @return array Filtered array of post IDs that need processing. */ private function filter_unprocessed_posts( $post_ids ) { if ( empty( $post_ids ) || ! is_array( $post_ids ) ) { return array(); } $unprocessed_posts = array(); foreach ( $post_ids as $post_id ) { // Check if it's an Elementor page. $is_elementor_post = get_post_meta( $post_id, '_elementor_version', true ); if ( ! $is_elementor_post ) { continue; } // Check if it's enabled for batch processing. $enabled_for_batch = get_post_meta( $post_id, '_astra_sites_enable_for_batch', true ); if ( ! $enabled_for_batch ) { continue; } // 🎯 FIX: Skip if already processed. $already_processed = get_post_meta( $post_id, '_astra_sites_hotlink_imported', true ); if ( $already_processed ) { continue; } $unprocessed_posts[] = $post_id; } return $unprocessed_posts; } } PK =3j[��I�e e ! class-astra-customizer-import.phpnu �[��� <?php /** * Customizer Data importer class. * * @since 1.0.0 * @package Astra Addon */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Customizer Data importer class. * * @since 1.0.0 */ class Astra_Customizer_Import { /** * Instance of Astra_Customizer_Import * * @since 1.0.0 * @var Astra_Customizer_Import */ private static $instance = null; /** * Instantiate Astra_Customizer_Import * * @since 1.0.0 * @return (Object) Astra_Customizer_Import */ public static function instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Import customizer options. * * @since 1.0.0 * * @param (Array) $options customizer options from the demo. */ public function import( $options ) { // Update Astra Theme customizer settings. if ( isset( $options['astra-settings'] ) ) { update_option( 'astra-settings', $options['astra-settings'] ); } // Add Custom CSS. if ( isset( $options['custom-css'] ) ) { wp_update_custom_css_post( $options['custom-css'] ); } } } PK =3j['�]?�) �) class-astra-widget-importer.phpnu �[��� <?php /** * Widget Importer Exporter * https://github.com/churchthemes/widget-importer-exporter * * Released under the GNU General Public License v2.0 * https://github.com/churchthemes/widget-importer-exporter/blob/master/license.txt * * Widget Data exporter class. * * @since 2.0.0 * @package Astra Sites */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Widget Data exporter class. */ class Astra_Widget_Importer { /** * Instance of Astra_Widget_Importer * * @var Astra_Widget_Importer */ private static $instance = null; /** * Instance * * @return object */ public static function instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Available widgets * * Gather site's widgets into array with ID base, name, etc. * Used by export and import functions. * * @since 0.4 * @global array $wp_registered_widget_updates * @return array Widget information */ public function wie_available_widgets() { global $wp_registered_widget_controls; $widget_controls = $wp_registered_widget_controls; $available_widgets = array(); foreach ( $widget_controls as $widget ) { if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[ $widget['id_base'] ] ) ) { // no dupes. $available_widgets[ $widget['id_base'] ]['id_base'] = $widget['id_base']; $available_widgets[ $widget['id_base'] ]['name'] = $widget['name']; } } return apply_filters( 'wie_available_widgets', $available_widgets ); } /** * Import widget JSON data * * @since 0.4 * @global array $wp_registered_sidebars * * @param object $data JSON widget data from .wie file. * * @return array Results array */ public function import_widgets_data( $data ) { global $wp_registered_sidebars; // Have valid data? // If no data or could not decode. if ( empty( $data ) || ! is_object( $data ) ) { wp_die( esc_html__( 'Import data could not be read. Please try a different file.', 'astra-sites' ), '', array( 'back_link' => true, ) ); } // Hook before import. do_action( 'wie_before_import' ); $data = apply_filters( 'wie_import_data', $data ); // Get all available widgets site supports. $available_widgets = $this->wie_available_widgets(); // Get all existing widget instances. $widget_instances = array(); foreach ( $available_widgets as $widget_data ) { $widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] ); } // Begin results. $results = array(); // Loop import data's sidebars. foreach ( $data as $sidebar_id => $widgets ) { // Skip inactive widgets. // (should not be in export file). if ( 'wp_inactive_widgets' === $sidebar_id ) { continue; } // Check if sidebar is available on this site. // Otherwise add widgets to inactive, and say so. if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) { $sidebar_available = true; $use_sidebar_id = $sidebar_id; $sidebar_message_type = 'success'; $sidebar_message = ''; } else { $sidebar_available = false; $use_sidebar_id = 'wp_inactive_widgets'; // add to inactive if sidebar does not exist in theme. $sidebar_message_type = 'error'; $sidebar_message = esc_html__( 'Widget area does not exist in theme (using Inactive)', 'astra-sites' ); } // Result for sidebar. $results[ $sidebar_id ]['name'] = ! empty( $wp_registered_sidebars[ $sidebar_id ]['name'] ) ? $wp_registered_sidebars[ $sidebar_id ]['name'] : $sidebar_id; // sidebar name if theme supports it; otherwise ID. $results[ $sidebar_id ]['message_type'] = $sidebar_message_type; $results[ $sidebar_id ]['message'] = $sidebar_message; $results[ $sidebar_id ]['widgets'] = array(); // Loop widgets. foreach ( $widgets as $widget_instance_id => $widget ) { $fail = false; // Get id_base (remove -# from end) and instance ID number. $id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id ); $instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id ); // Does site support this widget? if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) { $fail = true; $widget_message_type = 'error'; $widget_message = esc_html__( 'Site does not support widget', 'astra-sites' ); // explain why widget not imported. } // Filter to modify settings object before conversion to array and import. // Leave this filter here for backwards compatibility with manipulating objects (before conversion to array below). // Ideally the newer wie_widget_settings_array below will be used instead of this. $widget = apply_filters( 'wie_widget_settings', $widget ); // object. // Convert multidimensional objects to multidimensional arrays // Some plugins like Jetpack Widget Visibility store settings as multidimensional arrays // Without this, they are imported as objects and cause fatal error on Widgets page // If this creates problems for plugins that do actually intend settings in objects then may need to consider other approach: https://wordpress.org/support/topic/problem-with-array-of-arrays // It is probably much more likely that arrays are used than objects, however. $widget = json_decode( wp_json_encode( $widget ), true ); // Filter to modify settings array // This is preferred over the older wie_widget_settings filter above. // Do before identical check because changes may make it identical to end result (such as URL replacements). $widget = apply_filters( 'wie_widget_settings_array', $widget ); // Does widget with identical settings already exist in same sidebar? if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) { // Get existing widgets in this sidebar. $sidebars_widgets = get_option( 'sidebars_widgets' ); $sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array(); // check Inactive if that's where will go. // Loop widgets with ID base. $single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array(); foreach ( $single_widget_instances as $check_id => $check_widget ) { // Is widget in same sidebar and has identical settings? if ( in_array( "$id_base-$check_id", $sidebar_widgets, true ) && (array) $widget === $check_widget ) { $fail = true; $widget_message_type = 'warning'; $widget_message = esc_html__( 'Widget already exists', 'astra-sites' ); // explain why widget not imported. break; } } } // No failure. if ( ! $fail ) { // Add widget instance. $single_widget_instances = get_option( 'widget_' . $id_base ); // all instances for that widget ID base, get fresh every time. $single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array( '_multiwidget' => 1, ); // start fresh if have to. $single_widget_instances[] = $widget; // add it. // Get the key it was given. end( $single_widget_instances ); $new_instance_id_number = key( $single_widget_instances ); // If key is 0, make it 1. // When 0, an issue can occur where adding a widget causes data from other widget to load, and the widget doesn't stick (reload wipes it). if ( '0' === strval( $new_instance_id_number ) ) { $new_instance_id_number = 1; $single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0]; unset( $single_widget_instances[0] ); } // Move _multiwidget to end of array for uniformity. if ( isset( $single_widget_instances['_multiwidget'] ) ) { $multiwidget = $single_widget_instances['_multiwidget']; unset( $single_widget_instances['_multiwidget'] ); $single_widget_instances['_multiwidget'] = $multiwidget; } // Update option with new widget. $result = update_option( 'widget_' . $id_base, $single_widget_instances ); // Assign widget instance to sidebar. $sidebars_widgets = get_option( 'sidebars_widgets' ); // which sidebars have which widgets, get fresh every time. // Avoid rarely fatal error when the option is an empty string. // https://github.com/churchthemes/widget-importer-exporter/pull/11. if ( ! $sidebars_widgets ) { $sidebars_widgets = array(); } $new_instance_id = $id_base . '-' . $new_instance_id_number; // use ID number from new widget instance. $sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id; // add new instance to sidebar. update_option( 'sidebars_widgets', $sidebars_widgets ); // save the amended data. // After widget import action. $after_widget_import = array( 'sidebar' => $use_sidebar_id, 'sidebar_old' => $sidebar_id, 'widget' => $widget, 'widget_type' => $id_base, 'widget_id' => $new_instance_id, 'widget_id_old' => $widget_instance_id, 'widget_id_num' => $new_instance_id_number, 'widget_id_num_old' => $instance_id_number, ); do_action( 'wie_after_widget_import', $after_widget_import ); // Success message. if ( $sidebar_available ) { $widget_message_type = 'success'; $widget_message = esc_html__( 'Imported', 'astra-sites' ); } else { $widget_message_type = 'warning'; $widget_message = esc_html__( 'Imported to Inactive', 'astra-sites' ); } } // Result for widget instance. $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['name'] = isset( $available_widgets[ $id_base ]['name'] ) ? $available_widgets[ $id_base ]['name'] : $id_base; // widget name or ID if name not available (not supported by site). $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : esc_html__( 'No Title', 'astra-sites' ); // show "No Title" if widget instance is untitled. $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message_type'] = $widget_message_type; $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message'] = $widget_message; } } // Hook after import. do_action( 'wie_after_import' ); // Return results. return apply_filters( 'wie_import_results', $results ); } } PK =3j[Kb��&