assets
3 weeks ago
init.php
3 weeks ago
layout-import-api.php
2 years ago
layout-list-api.php
3 weeks ago
library-source.php
2 years ago
library-source.php
98 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite\Modules\Layout_Manager; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; |
| 5 | |
| 6 | |
| 7 | use Elementor\TemplateLibrary\Source_Base; |
| 8 | |
| 9 | class Library_Source extends Source_Base { |
| 10 | |
| 11 | public function get_id() { |
| 12 | return 'elementskit-layout-manager'; |
| 13 | } |
| 14 | |
| 15 | public function get_title() { |
| 16 | return __( 'ElementsKit Layout Manager', 'elementskit-lite' ); |
| 17 | } |
| 18 | |
| 19 | public function register_data() {} |
| 20 | |
| 21 | public function save_item( $template_data ) { |
| 22 | return new \WP_Error( 'invalid_request', 'Cannot save template to a elementskit layout manager' ); |
| 23 | } |
| 24 | |
| 25 | public function update_item( $new_data ) { |
| 26 | return new \WP_Error( 'invalid_request', 'Cannot update template to a elementskit layout manager' ); |
| 27 | } |
| 28 | |
| 29 | public function delete_template( $template_id ) { |
| 30 | return new \WP_Error( 'invalid_request', 'Cannot delete template from a elementskit layout manager' ); |
| 31 | } |
| 32 | |
| 33 | public function export_template( $template_id ) { |
| 34 | return new \WP_Error( 'invalid_request', 'Cannot export template from a elementskit layout manager' ); |
| 35 | } |
| 36 | |
| 37 | public function get_items( $args = array() ) { |
| 38 | return array(); |
| 39 | } |
| 40 | |
| 41 | public function get_item( $template_id ) { |
| 42 | $templates = $this->get_items(); |
| 43 | |
| 44 | return $templates[ $template_id ]; |
| 45 | } |
| 46 | |
| 47 | public function request_template_data( $template_id ) { |
| 48 | if ( empty( $template_id ) ) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | $body = array( |
| 53 | 'home_url' => trailingslashit( home_url() ), |
| 54 | 'plugin_version' => \ElementsKit_Lite::version(), |
| 55 | ); |
| 56 | |
| 57 | $query = array_merge( |
| 58 | array( |
| 59 | 'action' => 'get_layout_data', |
| 60 | 'layout_id' => $template_id, |
| 61 | ), |
| 62 | \ElementsKit_Lite::license_data() |
| 63 | ); |
| 64 | |
| 65 | $request_url = \ElementsKit_Lite::api_url() . 'layout-manager-api/' . '?' . http_build_query( $query ); |
| 66 | $response = wp_remote_get( |
| 67 | $request_url, |
| 68 | array( |
| 69 | 'timeout' => 30, |
| 70 | ) |
| 71 | ); |
| 72 | |
| 73 | return wp_remote_retrieve_body( $response ); |
| 74 | } |
| 75 | |
| 76 | public function get_data( array $args, $context = 'display' ) { |
| 77 | $data = $this->request_template_data( $args['template_id'] ); |
| 78 | |
| 79 | $data = json_decode( $data, true ); |
| 80 | |
| 81 | if ( empty( $data ) || empty( $data['content'] ) ) { |
| 82 | throw new \Exception( esc_html__( 'Template does not have any content', 'elementskit-lite' ) ); |
| 83 | } |
| 84 | |
| 85 | $data['content'] = $this->replace_elements_ids( $data['content'] ); |
| 86 | $data['content'] = $this->process_export_import_content( $data['content'], 'on_import' ); |
| 87 | |
| 88 | $post_id = $args['editor_post_id']; |
| 89 | $document = \Elementor\Plugin::instance()->documents->get( $post_id ); |
| 90 | |
| 91 | if ( $document ) { |
| 92 | $data['content'] = $document->get_elements_raw_data( $data['content'], true ); |
| 93 | } |
| 94 | |
| 95 | return $data; |
| 96 | } |
| 97 | } |
| 98 |