| 1 |
<?php |
| 2 |
|
| 3 |
namespace MasterAddons\Inc\Admin\Templates\Includes\Sources; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
abstract class Base { |
| 10 |
|
| 11 |
|
| 12 |
abstract public function get_slug(); |
| 13 |
|
| 14 |
|
| 15 |
abstract public function get_version(); |
| 16 |
|
| 17 |
|
| 18 |
abstract public function get_items(); |
| 19 |
|
| 20 |
|
| 21 |
abstract public function get_categories(); |
| 22 |
|
| 23 |
|
| 24 |
abstract public function get_keywords(); |
| 25 |
|
| 26 |
|
| 27 |
abstract public function get_item( $template_id ); |
| 28 |
|
| 29 |
|
| 30 |
abstract public function transient_lifetime(); |
| 31 |
|
| 32 |
|
| 33 |
public function templates_key() { |
| 34 |
return 'master_addons_templates_' . $this->get_slug() . '_' . $this->get_version(); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
public function categories_key() { |
| 39 |
return 'master_addons_categories_' . $this->get_slug() . '_' . $this->get_version(); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
public function keywords_key() { |
| 44 |
return 'master_addons_keywords_' . $this->get_slug() . '_' . $this->get_version(); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
public function set_templates_cache( $value ) { |
| 49 |
set_transient( $this->templates_key(), $value, $this->transient_lifetime() ); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
public function get_templates_cache() { |
| 54 |
|
| 55 |
if ( $this->is_debug_active() ) { |
| 56 |
return false; |
| 57 |
} |
| 58 |
|
| 59 |
return get_transient( $this->templates_key() ); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
public function delete_templates_cache() { |
| 64 |
delete_transient( $this->templates_key() ); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
public function set_categories_cache( $value ) { |
| 69 |
set_transient( $this->categories_key(), $value, $this->transient_lifetime() ); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
public function get_categories_cache() { |
| 74 |
|
| 75 |
if ( $this->is_debug_active() ) { |
| 76 |
return false; |
| 77 |
} |
| 78 |
|
| 79 |
return get_transient( $this->categories_key() ); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
public function delete_categories_cache() { |
| 84 |
delete_transient( $this->categories_key() ); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
public function set_keywords_cache( $value ) { |
| 89 |
set_transient( $this->keywords_key(), $value, $this->transient_lifetime() ); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
public function get_keywords_cache() { |
| 94 |
|
| 95 |
if ( $this->is_debug_active() ) { |
| 96 |
return false; |
| 97 |
} |
| 98 |
|
| 99 |
return get_transient( $this->keywords_key() ); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
public function delete_keywords_cache() { |
| 104 |
delete_transient( $this->keywords_key() ); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
public function is_debug_active() { |
| 109 |
|
| 110 |
if ( defined( 'MA_EL_API_DEBUG' ) && true === MA_EL_API_DEBUG ) { |
| 111 |
return true; |
| 112 |
} else { |
| 113 |
return false; |
| 114 |
} |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
public function id_prefix() { |
| 120 |
return 'ma_el_'; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
protected function replace_elements_ids( $content ) { |
| 125 |
return \Elementor\Plugin::$instance->db->iterate_data( $content, function( $element ) { |
| 126 |
$element['id'] = \Elementor\Utils::generate_random_string(); |
| 127 |
return $element; |
| 128 |
} ); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
protected function process_export_import_content( $content, $method ) { |
| 133 |
return \Elementor\Plugin::$instance->db->iterate_data( |
| 134 |
$content, function( $element_data ) use ( $method ) { |
| 135 |
$element = \Elementor\Plugin::$instance->elements_manager->create_element_instance( $element_data ); |
| 136 |
|
| 137 |
// If the widget/element isn't exist, like a plugin that creates a widget but deactivated |
| 138 |
if ( ! $element ) { |
| 139 |
return null; |
| 140 |
} |
| 141 |
|
| 142 |
return $this->process_element_export_import_content( $element, $method ); |
| 143 |
} |
| 144 |
); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
protected function process_element_export_import_content( $element, $method ) { |
| 149 |
|
| 150 |
$element_data = $element->get_data(); |
| 151 |
|
| 152 |
if ( method_exists( $element, $method ) ) { |
| 153 |
// TODO: Use the internal element data without parameters. |
| 154 |
$element_data = $element->{$method}( $element_data ); |
| 155 |
} |
| 156 |
|
| 157 |
foreach ( $element->get_controls() as $control ) { |
| 158 |
$control_class = \Elementor\Plugin::$instance->controls_manager->get_control( $control['type'] ); |
| 159 |
|
| 160 |
// If the control isn't exist, like a plugin that creates the control but deactivated. |
| 161 |
if ( ! $control_class ) { |
| 162 |
return $element_data; |
| 163 |
} |
| 164 |
|
| 165 |
if ( method_exists( $control_class, $method ) ) { |
| 166 |
$element_data['settings'][ $control['name'] ] = $control_class->{$method}( $element->get_settings( $control['name'] ), $control ); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
return $element_data; |
| 171 |
} |
| 172 |
} |
| 173 |
|