| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor Importer |
| 4 |
* |
| 5 |
* @package CARTFLOWS |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Elementor\TemplateLibrary; |
| 9 |
|
| 10 |
use Elementor\Core\Base\Document; |
| 11 |
use Elementor\DB; |
| 12 |
use Elementor\Core\Settings\Page\Manager as PageSettingsManager; |
| 13 |
use Elementor\Core\Settings\Manager as SettingsManager; |
| 14 |
use Elementor\Core\Settings\Page\Model; |
| 15 |
use Elementor\Editor; |
| 16 |
use Elementor\Plugin; |
| 17 |
use Elementor\Settings; |
| 18 |
use Elementor\Utils; |
| 19 |
|
| 20 |
if ( ! defined( 'ABSPATH' ) ) { |
| 21 |
exit; // Exit if accessed directly. |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Elementor template library local source. |
| 26 |
* |
| 27 |
* Elementor template library local source handler class is responsible for |
| 28 |
* handling local Elementor templates saved by the user locally on his site. |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
*/ |
| 32 |
class CartFlows_Importer_Elementor extends Source_Local { |
| 33 |
|
| 34 |
/** |
| 35 |
* Import single template |
| 36 |
* |
| 37 |
* @param int $post_id post ID. |
| 38 |
*/ |
| 39 |
public function import_single_template( $post_id ) { |
| 40 |
|
| 41 |
do_action( 'cartflows_before_elementor_import_single_template' ); |
| 42 |
|
| 43 |
$rest_content = get_post_meta( $post_id, '_elementor_data', true ); |
| 44 |
|
| 45 |
if ( empty( $rest_content ) ) { |
| 46 |
wcf()->logger->import_log( __( '(✕) Empty content.', 'cartflows' ) ); |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
if ( empty( $rest_content ) ) { |
| 51 |
wcf()->logger->import_log( __( '(✕) Invalid content.', 'cartflows' ) ); |
| 52 |
} |
| 53 |
|
| 54 |
if ( is_array( $rest_content ) ) { |
| 55 |
$content = $rest_content; |
| 56 |
} else { |
| 57 |
$rest_content = add_magic_quotes( $rest_content ); |
| 58 |
$content = json_decode( $rest_content, true ); |
| 59 |
} |
| 60 |
|
| 61 |
if ( ! is_array( $content ) ) { |
| 62 |
$data = __( 'Invalid content. Expected an array.', 'cartflows' ); |
| 63 |
wcf()->logger->import_log( '(✕) ' . $data ); |
| 64 |
wcf()->logger->import_log( $content ); |
| 65 |
} else { |
| 66 |
|
| 67 |
wcf()->logger->import_log( '(✓) Processing Request..' ); |
| 68 |
|
| 69 |
// Import the data. |
| 70 |
$content = $this->process_export_import_content( $content, 'on_import' ); |
| 71 |
|
| 72 |
// Serialize the array if found. |
| 73 |
if ( is_array( $content ) ) { |
| 74 |
$content = wp_slash( wp_json_encode( $content ) ); |
| 75 |
} |
| 76 |
|
| 77 |
// Update content. |
| 78 |
update_metadata( 'post', $post_id, '_elementor_data', $content ); |
| 79 |
|
| 80 |
$this->clear_cache(); |
| 81 |
|
| 82 |
wcf()->logger->import_log( '(✓) Process Complete' ); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Clear Cache. |
| 88 |
* |
| 89 |
* @since 1.0.0 |
| 90 |
*/ |
| 91 |
public function clear_cache() { |
| 92 |
// Clear 'Elementor' file cache. |
| 93 |
if ( class_exists( '\Elementor\Plugin' ) ) { |
| 94 |
\Elementor\Plugin::$instance->files_manager->clear_cache(); |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|