dvadf
File manager - Edit - /home/theblueo/tv/wp-includes/pomo/lib/batch-process.tar
Back
class-cartflows-importer-divi-batch.php 0000666 00000002231 15214167443 0014244 0 ustar 00 <?php /** * Divi Batch Process * * @package CartFlows * @since 1.1.1 */ if ( ! class_exists( 'Cartflows_Importer_Divi_Batch' ) && class_exists( 'WP_Background_Process' ) ) : /** * Image Background Process * * @since 1.1.1 */ class Cartflows_Importer_Divi_Batch extends WP_Background_Process { /** * Image Process * * @var string */ protected $action = 'cartflows_divi_image_process'; /** * Task * * Override this method to perform any actions required on each * queue item. Return the modified item for further processing * in the next pass through. Or, return false to remove the * item from the queue. * * @since 1.1.1 * * @param integer $post_id Post Id. * @return mixed */ protected function task( $post_id ) { CartFlows_Importer_Divi::get_instance()->import_single_post( $post_id ); return false; } /** * Complete * * Override if applicable, but ensure that the below actions are * performed, or, call parent::complete(). * * @since 1.1.1 */ protected function complete() { parent::complete(); do_action( 'cartflows_import_complete' ); } } endif; class-cartflows-importer-elementor-batch.php 0000666 00000002430 15214167443 0015304 0 ustar 00 <?php /** * Elementor Batch Process * * @package CartFlows * @since 1.0.0 */ if ( ! class_exists( 'Cartflows_Importer_Elementor_Batch' ) && class_exists( 'WP_Background_Process' ) ) : /** * Image Background Process * * @since 1.1.1 Updated class name with Elementor specific. * * @since 1.0.0 */ class Cartflows_Importer_Elementor_Batch extends WP_Background_Process { /** * Image Process * * @var string */ protected $action = 'cartflows_elementor_image_process'; /** * Task * * Override this method to perform any actions required on each * queue item. Return the modified item for further processing * in the next pass through. Or, return false to remove the * item from the queue. * * @since 1.0.0 * * @param integer $post_id Post Id. * @return mixed */ protected function task( $post_id ) { $obj = new \Elementor\TemplateLibrary\CartFlows_Importer_Elementor(); $obj->import_single_template( $post_id ); return false; } /** * Complete * * Override if applicable, but ensure that the below actions are * performed, or, call parent::complete(). * * @since 1.0.0 */ protected function complete() { parent::complete(); do_action( 'cartflows_import_complete' ); } } endif; class-cartflows-importer-elementor.php 0000666 00000003314 15214167443 0014227 0 ustar 00 <?php /** * Elementor Importer * * @package CARTFLOWS */ namespace Elementor\TemplateLibrary; use Elementor\Core\Base\Document; use Elementor\DB; use Elementor\Core\Settings\Page\Manager as PageSettingsManager; use Elementor\Core\Settings\Manager as SettingsManager; use Elementor\Core\Settings\Page\Model; use Elementor\Editor; use Elementor\Plugin; use Elementor\Settings; use Elementor\Utils; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * 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.0.0 */ class CartFlows_Importer_Elementor extends Source_Local { /** * Import single template * * @param int $post_id post ID. */ public function import_single_template( $post_id ) { $rest_content = get_post_meta( $post_id, '_elementor_data', true ); if ( empty( $rest_content ) ) { $data = __( 'Invalid content.', 'cartflows' ); wcf()->logger->import_log( '(✕) ' . $data ); } $rest_content = add_magic_quotes( $rest_content ); $content = json_decode( $rest_content, true ); if ( ! is_array( $content ) ) { $data = __( 'Invalid content. Expected an array.', 'cartflows' ); wcf()->logger->import_log( '(✕) ' . $data ); wcf()->logger->import_log( $content ); } else { wcf()->logger->import_log( '(✓) Processing Request..' ); // Import the data. $content = $this->process_export_import_content( $content, 'on_import' ); // Update content. update_metadata( 'post', $post_id, '_elementor_data', $content ); wcf()->logger->import_log( '(✓) Process Complete' ); } } } class-cartflows-importer-divi.php 0000666 00000005033 15214167443 0013170 0 ustar 00 <?php /** * Divi Importer * * @package CartFlows * @since 1.1.1 */ if ( ! class_exists( 'CartFlows_Importer_Divi' ) ) : /** * CartFlows Import Divi * * @since 1.1.1 */ class CartFlows_Importer_Divi { /** * Instance * * @since 1.1.1 * @access private * @var object Class object. */ private static $instance; /** * Initiator * * @since 1.1.1 * @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.1.1 */ public function __construct() {} /** * Allowed tags for the batch update process * * @since x.x.x * * @param array $allowedposttags Array of default allowable HTML tags. * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', * 'strip', 'data', 'entities', or the name of a field filter such as * 'pre_user_description'. * @return array Array of allowed HTML tags and their allowed attributes. */ public function allowed_tags_and_attributes( $allowedposttags, $context ) { // Keep only for 'post' contenxt. if ( 'post' === $context ) { // <style> tag and attributes. $allowedposttags['style'] = array(); } return $allowedposttags; } /** * Update post meta. * * @param integer $post_id Post ID. * @return void */ public function import_single_post( $post_id = 0 ) { // Allow the SVG tags in batch update process. add_filter( 'wp_kses_allowed_html', array( $this, 'allowed_tags_and_attributes' ), 10, 2 ); // Download and replace images. $content = get_post_meta( $post_id, 'divi_content', true ); if ( empty( $content ) ) { wcf()->logger->import_log( '(✕) Not have "Divi" Data. Post content is empty!' ); } else { wcf()->logger->import_log( '(✓) Processing Request..' ); // Update hotlink images. $content = CartFlows_Importer::get_instance()->get_content( $content ); // Update post content. wp_update_post( array( 'ID' => $post_id, 'post_content' => $content, ) ); // Delete temporary meta key. delete_post_meta( $post_id, 'divi_content' ); wcf()->logger->import_log( '(✓) Process Complete' ); } } } /** * Initialize class object with 'get_instance()' method */ CartFlows_Importer_Divi::get_instance(); endif; class-cartflows-change-template-batch.php 0000666 00000002546 15214167443 0014521 0 ustar 00 <?php /** * Change Template Process * * @package CartFlows * @since 1.2.2 */ if ( ! class_exists( 'Cartflows_Change_Template_Batch' ) && class_exists( 'WP_Background_Process' ) ) : /** * Change Template Process * * @since 1.2.2 */ class Cartflows_Change_Template_Batch extends WP_Background_Process { /** * Template Process * * @var string */ protected $action = 'cartflows_change_template_process'; /** * Task * * Override this method to perform any actions required on each * queue item. Return the modified item for further processing * in the next pass through. Or, return false to remove the * item from the queue. * * @param mixed $post_id Queue item to iterate over. * * @return mixed */ protected function task( $post_id ) { wcf()->logger->log( '(✓) Step ID ' . $post_id ); if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { error_log( 'Processed:' . $post_id ); //phpcs:ignore } update_post_meta( $post_id, '_wp_page_template', 'cartflows-default' ); return false; } /** * Complete * * Override if applicable, but ensure that the below actions are * performed, or, call parent::complete(). */ protected function complete() { parent::complete(); if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { error_log( 'Process Complete' );//phpcs:ignore } } } endif; class-cartflows-importer-beaver-builder.php 0000666 00000011457 15214167443 0015134 0 ustar 00 <?php /** * Beaver Builder Importer * * @package CartFlows * @since 1.1.1 */ if ( ! class_exists( 'CartFlows_Importer_Beaver_Builder' ) ) : /** * CartFlows Import Beaver Builder * * @since 1.1.1 */ class CartFlows_Importer_Beaver_Builder { /** * Instance * * @since 1.1.1 * @access private * @var object Class object. */ private static $instance; /** * Initiator * * @since 1.1.1 * @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.1.1 */ public function __construct() { } /** * Update post meta. * * @param integer $post_id Post ID. * @return void */ public function import_single_post( $post_id = 0 ) { $data = get_post_meta( $post_id, '_fl_builder_data', true ); if ( ! empty( $data ) ) { $data = $this->get_import_data( $data ); // 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(); } else { wcf()->logger->import_log( '(✕) Not have "Beaver Builder" Data. Post meta _fl_builder_data is empty!' ); } } /** * Update post meta. * * @param array $data Page builder data. * @return mixed */ public function get_import_data( $data ) { if ( empty( $data ) ) { return array(); } foreach ( $data as $key => $el ) { // Import 'row' images. if ( 'row' === $el->type ) { $data[ $key ]->settings = self::import_row_images( $el->settings ); } // Import 'module' images. if ( 'module' === $el->type ) { $data[ $key ]->settings = self::import_module_images( $el->settings ); } // Import 'column' images. if ( 'column' === $el->type ) { $data[ $key ]->settings = self::import_column_images( $el->settings ); } } return $data; } /** * Import Module Images. * * @param object $settings Module settings object. * @return object */ public static function import_module_images( $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 ); } /** * 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 ); } } return $settings; } /** * Import Column Images. * * @param object $settings Column settings object. * @return object */ public static function import_column_images( $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 import_row_images( $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 = CartFlows_Import_Image::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 = CartFlows_Import_Image::get_instance()->import( $image ); $settings->photo_src = $downloaded_image['url']; $settings->photo = $downloaded_image['id']; } return $settings; } } /** * Initialize class object with 'get_instance()' method */ CartFlows_Importer_Beaver_Builder::get_instance(); endif; helpers/class-cartflows-importer-image.php 0000666 00000012733 15214167443 0014766 0 ustar 00 <?php /** * Image Importer * * => How to use? * * $image = array( * 'url' => '<image-url>', * 'id' => '<image-id>', * ); * * $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image ); * * @package CartFlows * * @since 1.1.1 */ if ( ! class_exists( 'CartFlows_Import_Image' ) ) : /** * CartFlows Importer * * @since 1.1.1 */ class CartFlows_Import_Image { /** * Instance * * @since 1.1.1 * @var object Class object. * @access private */ private static $instance; /** * Images IDs * * @var array The Array of already image IDs. * @since 1.1.1 */ private $already_imported_ids = array(); /** * Initiator * * @since 1.1.1 * @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.1.1 */ public function __construct() { if ( ! function_exists( 'WP_Filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); } /** * Process Image Download * * @since 1.1.1 * @param array $attachments Attachment array. * @return array Attachment array. */ public function process( $attachments ) { $downloaded_images = array(); foreach ( $attachments as $key => $attachment ) { $downloaded_images[] = $this->import( $attachment ); } return $downloaded_images; } /** * Get Hash Image. * * @since 1.1.1 * @param string $attachment_url Attachment URL. * @return string Hash string. */ private function get_hash_image( $attachment_url ) { return sha1( $attachment_url ); } /** * Get Saved Image. * * @since 1.1.1 * @param string $attachment Attachment Data. * @return string Hash string. */ private function get_saved_image( $attachment ) { wcf()->logger->import_log( 'importer-image.php File' ); if ( apply_filters( 'cartflows_image_importer_skip_image', false, $attachment ) ) { wcf()->logger->import_log( 'Download (✕) Replace (✕) - ' . $attachment['url'] ); return $attachment; } global $wpdb; // Already imported? Then return! if ( isset( $this->already_imported_ids[ $attachment['id'] ] ) ) { wcf()->logger->import_log( 'Download (✓) Replace (✓) - ' . $attachment['url'] ); return $this->already_imported_ids[ $attachment['id'] ]; } // 1. Is already imported in Batch Import Process? $post_id = $wpdb->get_var( $wpdb->prepare( " SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_cartflows_image_hash' AND meta_value = %s ", $this->get_hash_image( $attachment['url'] ) ) ); // 2. Is image already imported though XML? if ( empty( $post_id ) ) { // Get file name without extension. // To check it exist in attachment. $filename = basename( $attachment['url'] ); wcf()->logger->import_log( 'File Basename - ' . $filename ); $post_id = $wpdb->get_var( $wpdb->prepare( " SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_wp_attached_file' AND meta_value LIKE %s ", '%/' . $filename . '%' ) ); wcf()->logger->import_log( 'Download (✓) Replace (✓) - ' . $attachment['url'] ); } if ( $post_id ) { $new_attachment = array( 'id' => $post_id, 'url' => wp_get_attachment_url( $post_id ), ); $this->already_imported_ids[ $attachment['id'] ] = $new_attachment; return $new_attachment; } return false; } /** * Import Image * * @since 1.1.1 * @param array $attachment Attachment array. * @return array Attachment array. */ public function import( $attachment ) { $saved_image = $this->get_saved_image( $attachment ); if ( $saved_image ) { return $saved_image; } $file_content = wp_remote_retrieve_body( wp_safe_remote_get( $attachment['url'], array( 'timeout' => '60', 'sslverify' => false) ) ); // Empty file content? if ( empty( $file_content ) ) { wcf()->logger->import_log( 'Download (✕) Replace (✕) - ' . $attachment['url'] ); wcf()->logger->import_log( 'Error: Failed wp_remote_retrieve_body().' ); return $attachment; } // Extract the file name and extension from the URL. $filename = basename( $attachment['url'] ); $upload = wp_upload_bits( $filename, null, $file_content ); $post = array( 'post_title' => $filename, 'guid' => $upload['url'], ); $info = wp_check_filetype( $upload['file'] ); if ( $info ) { $post['post_mime_type'] = $info['type']; } else { // For now just return the origin attachment. return $attachment; } $post_id = wp_insert_attachment( $post, $upload['file'] ); wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) ); update_post_meta( $post_id, '_cartflows_image_hash', $this->get_hash_image( $attachment['url'] ) ); $new_attachment = array( 'id' => $post_id, 'url' => $upload['url'], ); wcf()->logger->import_log( 'Download (✓) Replace (✓) - ' . $attachment['url'] ); $this->already_imported_ids[ $attachment['id'] ] = $new_attachment; return $new_attachment; } } /** * Initialize class object with 'get_instance()' method */ CartFlows_Import_Image::get_instance(); endif; helpers/class-wp-async-request.php 0000666 00000005613 15214167443 0013271 0 ustar 00 <?php /** * WP Async Request * * @see https://github.com/A5hleyRich/wp-background-processing/ * @package WP-Background-Processing */ if ( ! class_exists( 'WP_Async_Request' ) ) { /** * Abstract WP_Async_Request class. * * @abstract */ abstract class WP_Async_Request { /** * Prefix * * (default value: 'wp') * * @var string * @access protected */ protected $prefix = 'wp'; /** * Action * * (default value: 'async_request') * * @var string * @access protected */ protected $action = 'async_request'; /** * Identifier * * @var mixed * @access protected */ protected $identifier; /** * Data * * (default value: array()) * * @var array * @access protected */ protected $data = array(); /** * Initiate new async request */ public function __construct() { $this->identifier = $this->prefix . '_' . $this->action; add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); } /** * Set data used during the request * * @param array $data Data. * * @return $this */ public function data( $data ) { $this->data = $data; return $this; } /** * Dispatch the async request * * @return array|WP_Error */ public function dispatch() { $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); $args = $this->get_post_args(); return wp_remote_post( esc_url_raw( $url ), $args ); } /** * Get query args * * @return array */ protected function get_query_args() { if ( property_exists( $this, 'query_args' ) ) { return $this->query_args; } return array( 'action' => $this->identifier, 'nonce' => wp_create_nonce( $this->identifier ), ); } /** * Get query URL * * @return string */ protected function get_query_url() { if ( property_exists( $this, 'query_url' ) ) { return $this->query_url; } return admin_url( 'admin-ajax.php' ); } /** * Get post args * * @return array */ protected function get_post_args() { if ( property_exists( $this, 'post_args' ) ) { return $this->post_args; } return array( 'timeout' => 0.01, 'blocking' => false, 'body' => $this->data, 'cookies' => $_COOKIE, 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), ); } /** * Maybe handle * * Check for correct nonce and pass to handler. */ public function maybe_handle() { // Don't lock up other requests while processing. session_write_close(); check_ajax_referer( $this->identifier, 'nonce' ); $this->handle(); wp_die(); } /** * Handle * * Override this method to perform any actions required * during the async request. */ abstract protected function handle(); } } helpers/class-wp-background-process.php 0000666 00000025270 15214167443 0014262 0 ustar 00 <?php /** * WP Background Process * * @see https://github.com/A5hleyRich/wp-background-processing/ * @package WP-Background-Processing */ if ( ! class_exists( 'WP_Background_Process' ) ) { /** * Abstract WP_Background_Process class. * * @abstract * @extends WP_Async_Request */ abstract class WP_Background_Process extends WP_Async_Request { /** * Action * * (default value: 'background_process') * * @var string * @access protected */ protected $action = 'background_process'; /** * Start time of current process. * * (default value: 0) * * @var int * @access protected */ protected $start_time = 0; /** * Cron_hook_identifier * * @var mixed * @access protected */ protected $cron_hook_identifier; /** * Cron_interval_identifier * * @var mixed * @access protected */ protected $cron_interval_identifier; /** * Initiate new background process */ public function __construct() { parent::__construct(); $this->cron_hook_identifier = $this->identifier . '_cron'; $this->cron_interval_identifier = $this->identifier . '_cron_interval'; add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) ); add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) ); } /** * Dispatch * * @return mixed dispatch event. */ public function dispatch() { // Schedule the cron healthcheck. $this->schedule_event(); // Perform remote post. return parent::dispatch(); } /** * Push to queue * * @param mixed $data Data. * * @return $this */ public function push_to_queue( $data ) { $this->data[] = $data; return $this; } /** * Save queue * * @return $this */ public function save() { $key = $this->generate_key(); if ( ! empty( $this->data ) ) { update_site_option( $key, $this->data ); } return $this; } /** * Update queue * * @param string $key Key. * @param array $data Data. * * @return $this */ public function update( $key, $data ) { if ( ! empty( $data ) ) { update_site_option( $key, $data ); } return $this; } /** * Delete queue * * @param string $key Key. * * @return $this */ public function delete( $key ) { delete_site_option( $key ); return $this; } /** * Generate key * * Generates a unique key based on microtime. Queue items are * given a unique key so that they can be merged upon save. * * @param int $length Length. * * @return string */ protected function generate_key( $length = 64 ) { $unique = md5( microtime() . rand() ); $prepend = $this->identifier . '_batch_'; return substr( $prepend . $unique, 0, $length ); } /** * Maybe process queue * * Checks whether data exists within the queue and that * the process is not already running. */ public function maybe_handle() { // Don't lock up other requests while processing. session_write_close(); if ( $this->is_process_running() ) { // Background process already running. wp_die(); } if ( $this->is_queue_empty() ) { // No data to process. wp_die(); } check_ajax_referer( $this->identifier, 'nonce' ); $this->handle(); wp_die(); } /** * Is queue empty * * @return bool */ protected function is_queue_empty() { global $wpdb; $table = $wpdb->options; $column = 'option_name'; if ( is_multisite() ) { $table = $wpdb->sitemeta; $column = 'meta_key'; } $key = $this->identifier . '_batch_%'; $count = $wpdb->get_var( $wpdb->prepare( " SELECT COUNT(*) FROM {$table} WHERE {$column} LIKE %s ", $key ) ); return ( $count > 0 ) ? false : true; } /** * Is process running * * Check whether the current process is already running * in a background process. */ protected function is_process_running() { if ( get_site_transient( $this->identifier . '_process_lock' ) ) { // Process already running. return true; } return false; } /** * Lock process * * Lock the process so that multiple instances can't run simultaneously. * Override if applicable, but the duration should be greater than that * defined in the time_exceeded() method. */ protected function lock_process() { $this->start_time = time(); // Set start time of current process. $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration ); set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration ); } /** * Unlock process * * Unlock the process so that other instances can spawn. * * @return $this */ protected function unlock_process() { delete_site_transient( $this->identifier . '_process_lock' ); return $this; } /** * Get batch * * @return stdClass Return the first batch from the queue */ protected function get_batch() { global $wpdb; $table = $wpdb->options; $column = 'option_name'; $key_column = 'option_id'; $value_column = 'option_value'; if ( is_multisite() ) { $table = $wpdb->sitemeta; $column = 'meta_key'; $key_column = 'meta_id'; $value_column = 'meta_value'; } $key = $this->identifier . '_batch_%'; $query = $wpdb->get_row( $wpdb->prepare( " SELECT * FROM {$table} WHERE {$column} LIKE %s ORDER BY {$key_column} ASC LIMIT 1 ", $key ) ); $batch = new stdClass(); $batch->key = $query->$column; $batch->data = maybe_unserialize( $query->$value_column ); return $batch; } /** * Handle * * Pass each queue item to the task handler, while remaining * within server memory and time limit constraints. */ protected function handle() { $this->lock_process(); do { $batch = $this->get_batch(); foreach ( $batch->data as $key => $value ) { $task = $this->task( $value ); if ( false !== $task ) { $batch->data[ $key ] = $task; } else { unset( $batch->data[ $key ] ); } if ( $this->time_exceeded() || $this->memory_exceeded() ) { // Batch limits reached. break; } } // Update or delete current batch. if ( ! empty( $batch->data ) ) { $this->update( $batch->key, $batch->data ); } else { $this->delete( $batch->key ); } } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() ); $this->unlock_process(); // Start next batch or complete process. if ( ! $this->is_queue_empty() ) { $this->dispatch(); } else { $this->complete(); } wp_die(); } /** * Memory exceeded * * Ensures the batch process never exceeds 90% * of the maximum WordPress memory. * * @return bool */ protected function memory_exceeded() { $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory $current_memory = memory_get_usage( true ); $return = false; if ( $current_memory >= $memory_limit ) { $return = true; } return apply_filters( $this->identifier . '_memory_exceeded', $return ); } /** * Get memory limit * * @return int */ protected function get_memory_limit() { if ( function_exists( 'ini_get' ) ) { $memory_limit = ini_get( 'memory_limit' ); } else { // Sensible default. $memory_limit = '128M'; } if ( ! $memory_limit || -1 === $memory_limit ) { // Unlimited, set to 32GB. $memory_limit = '32000M'; } return intval( $memory_limit ) * 1024 * 1024; } /** * Time exceeded. * * Ensures the batch never exceeds a sensible time limit. * A timeout limit of 30s is common on shared hosting. * * @return bool */ protected function time_exceeded() { $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds $return = false; if ( time() >= $finish ) { $return = true; } return apply_filters( $this->identifier . '_time_exceeded', $return ); } /** * Complete. * * Override if applicable, but ensure that the below actions are * performed, or, call parent::complete(). */ protected function complete() { // Unschedule the cron healthcheck. $this->clear_scheduled_event(); } /** * Schedule cron healthcheck * * @access public * @param mixed $schedules Schedules. * @return mixed */ public function schedule_cron_healthcheck( $schedules ) { $interval = apply_filters( $this->identifier . '_cron_interval', 5 ); if ( property_exists( $this, 'cron_interval' ) ) { $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval_identifier ); } // Adds every 5 minutes to the existing schedules. $schedules[ $this->identifier . '_cron_interval' ] = array( 'interval' => MINUTE_IN_SECONDS * $interval, 'display' => sprintf( __( 'Every %d Minutes', 'cartflows' ), $interval ), ); return $schedules; } /** * Handle cron healthcheck * * Restart the background process if not already running * and data exists in the queue. */ public function handle_cron_healthcheck() { if ( $this->is_process_running() ) { // Background process already running. exit; } if ( $this->is_queue_empty() ) { // No data to process. $this->clear_scheduled_event(); exit; } $this->handle(); exit; } /** * Schedule event */ protected function schedule_event() { if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier ); } } /** * Clear scheduled event */ protected function clear_scheduled_event() { $timestamp = wp_next_scheduled( $this->cron_hook_identifier ); if ( $timestamp ) { wp_unschedule_event( $timestamp, $this->cron_hook_identifier ); } } /** * Cancel Process * * Stop processing queue items, clear cronjob and delete batch. */ public function cancel_process() { if ( ! $this->is_queue_empty() ) { $batch = $this->get_batch(); $this->delete( $batch->key ); wp_clear_scheduled_hook( $this->cron_hook_identifier ); } } /** * Task * * Override this method to perform any actions required on each * queue item. Return the modified item for further processing * in the next pass through. Or, return false to remove the * item from the queue. * * @param mixed $item Queue item to iterate over. * * @return mixed */ abstract protected function task( $item ); } } class-cartflows-batch-process.php 0000666 00000016322 15214167443 0013136 0 ustar 00 <?php /** * Batch Processing * * @package CartFlows * @since 1.0.0 */ if ( ! class_exists( 'CartFlows_Batch_Process' ) ) : /** * CartFlows_Batch_Process * * @since 1.0.0 */ class CartFlows_Batch_Process { /** * Instance * * @since 1.0.0 * @var object Class object. * @access private */ private static $instance; /** * Elementor Batch Instance * * @since 1.1.1 Updated instance name with elementor specific. * * @since 1.0.0 * @var object Class object. * @access public */ public static $batch_instance_elementor; /** * Beaver Builder Batch Instance * * @since 1.1.1 * @var object Class object. * @access public */ public static $batch_instance_bb; /** * Divi Batch Instance * * @since 1.1.1 * @var object Class object. * @access public */ public static $batch_instance_divi; /** * 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() { // Not BB or Elementor then avoid importer. // if ( ! class_exists( '\Elementor\Plugin' ) && ! class_exists( 'FLBuilder' ) ) { // return; // } // Core Helpers - Image. require_once ABSPATH . 'wp-admin/includes/image.php'; // Core Helpers - Batch Processing. require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-cartflows-importer-image.php'; require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-async-request.php'; require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-background-process.php'; $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' ); // Elementor. if ( ( 'elementor' === $default_page_builder ) && class_exists( '\Elementor\Plugin' ) ) { // Add "elementor" in import [queue]. // @todo Remove required `allow_url_fopen` support. if ( ini_get( 'allow_url_fopen' ) ) { require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php'; require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor-batch.php'; self::$batch_instance_elementor = new Cartflows_Importer_Elementor_Batch(); } } // Beaver Builder. if ( ( 'beaver-builder' === $default_page_builder ) && class_exists( 'FLBuilder' ) ) { require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder.php'; require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder-batch.php'; self::$batch_instance_bb = new Cartflows_Importer_Beaver_Builder_Batch(); } // Divi. if ( ( 'divi' === $default_page_builder ) && ( class_exists( 'ET_Builder_Plugin' ) || Cartflows_Compatibility::get_instance()->is_divi_enabled() ) ) { require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi.php'; require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi-batch.php'; self::$batch_instance_divi = new Cartflows_Importer_Divi_Batch(); } // Start image importing after site import complete. add_action( 'cartflows_after_template_import', array( $this, 'start_batch_process' ) ); add_action( 'cartflows_import_complete', array( $this, 'complete_batch_import' ) ); add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) ); add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 ); } /** * Added .svg files as supported format in the uploader. * * @since 1.1.4 * * @param array $mimes Already supported mime types. */ public function custom_upload_mimes( $mimes ) { // Allow SVG files. $mimes['svg'] = 'image/svg+xml'; $mimes['svgz'] = 'image/svg+xml'; // Allow XML files. $mimes['xml'] = 'text/xml'; return $mimes; } /** * Add SVG image support * * @since 1.1.4 * * @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.4. * * @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, ); } /** * Batch Process Complete. * * @return void */ public function complete_batch_import() { wcf()->logger->import_log( '(✓) BATCH Process Complete!' ); } /** * Start Image Import * * @param integer $post_id Post Id. * * @return void */ public function start_batch_process( $post_id = '' ) { $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' ); wcf()->logger->import_log( '(✓) BATCH Started!' ); wcf()->logger->import_log( '(✓) Step ID ' . $post_id ); // Add "elementor" in import [queue]. if ( 'beaver-builder' === $default_page_builder && self::$batch_instance_bb ) { // Add to queue. self::$batch_instance_bb->push_to_queue( $post_id ); // Dispatch Queue. self::$batch_instance_bb->save()->dispatch(); wcf()->logger->import_log( '(✓) Dispatch "Beaver Builder" Request..' ); } elseif ( 'elementor' === $default_page_builder && self::$batch_instance_elementor ) { // Add to queue. self::$batch_instance_elementor->push_to_queue( $post_id ); // Dispatch Queue. self::$batch_instance_elementor->save()->dispatch(); wcf()->logger->import_log( '(✓) Dispatch "Elementor" Request..' ); } elseif ( 'divi' === $default_page_builder && self::$batch_instance_divi ) { // Add to queue. self::$batch_instance_divi->push_to_queue( $post_id ); // Dispatch Queue. self::$batch_instance_divi->save()->dispatch(); wcf()->logger->import_log( '(✓) Dispatch "Divi" Request..' ); } else { wcf()->logger->import_log( '(✕) Could not import image due to allow_url_fopen() is disabled!' ); } } } /** * Kicking this off by calling 'get_instance()' method */ CartFlows_Batch_Process::get_instance(); endif; class-cartflows-importer-beaver-builder-batch.php 0000666 00000002313 15214167443 0016202 0 ustar 00 <?php /** * Beaver Builder Batch Process * * @package CartFlows * @since 1.1.1 */ if ( ! class_exists( 'Cartflows_Importer_Beaver_Builder_Batch' ) && class_exists( 'WP_Background_Process' ) ) : /** * Image Background Process * * @since 1.1.1 */ class Cartflows_Importer_Beaver_Builder_Batch extends WP_Background_Process { /** * Image Process * * @var string */ protected $action = 'cartflows_beaver_builder_image_process'; /** * Task * * Override this method to perform any actions required on each * queue item. Return the modified item for further processing * in the next pass through. Or, return false to remove the * item from the queue. * * @since 1.1.1 * * @param integer $post_id Post Id. * @return mixed */ protected function task( $post_id ) { CartFlows_Importer_Beaver_Builder::get_instance()->import_single_post( $post_id ); return false; } /** * Complete * * Override if applicable, but ensure that the below actions are * performed, or, call parent::complete(). * * @since 1.1.1 */ protected function complete() { parent::complete(); do_action( 'cartflows_import_complete' ); } } endif;
dvadf
dvadf
| ver. 1.4 |
Github
|
.
| PHP 7.0.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings