PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.1.4
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.1.4
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / Core / Importer / Runners / ExtraContent.php

ExtraContent.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.1.4, at includes/Core/Importer/Runners/ExtraContent.php

102 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Core\Importer\Runners;
4
5 use Exception;
6 use Templately\Core\Importer\Form;
7 use Templately\Core\Importer\Runners\BaseRunner;
8
9 class ExtraContent extends BaseRunner {
10
11 protected static $imported_form = [];
12
13 public function get_name(): string {
14 return 'extra-content';
15 }
16
17 public function get_label(): string {
18 return __( 'Extra Contents', 'templately' );
19 }
20
21 public function should_log(): bool {
22 return true;
23 }
24
25 public function get_action(): string {
26 return 'eventLog';
27 }
28
29 public function log_message(): string {
30 return __( 'Importing Forms and Others Extra Contents', 'templately' );
31 }
32
33 public function should_run( $data, $imported_data = [] ): bool {
34 return ! empty( $this->manifest['extra-content'] ) && !empty($data['import_demo_content']);
35 }
36
37 public function import( $data, $imported_data ): array {
38 $extra_content = [];
39 $contents = $this->manifest['extra-content'];
40
41 if( ! empty( $contents ) ) {
42 foreach( $contents as $type => $content ) {
43 switch ( $type ) {
44 case 'form':
45 $import = $this->import_form( $content );
46 $extra_content['form'] = $import;
47 break;
48 case 'data':
49 break;
50 }
51 }
52
53 // $imported_data = array_merge( $imported_data, [ 'extra-content' => $this->extra_content ] );
54 }
55
56
57 return [ 'extra-content' => $extra_content ];
58 }
59
60 private function import_form( $contents ): array {
61 if( ! is_array( $contents ) || empty( $contents ) ) {
62 return [];
63 }
64
65 $result = [];
66
67 $root_path = $this->dir_path . 'content' . DIRECTORY_SEPARATOR;
68
69 foreach( $contents as $json_id => $plugin_list ) {
70 if( empty( $plugin_list ) ) {
71 continue;
72 }
73
74 foreach ( $plugin_list as $plugin_name => $form_list ) {
75 if( empty( $form_list ) ) {
76 continue;
77 }
78
79 foreach ( $form_list as $form ) {
80 try {
81 $form_id = isset( $form['identifier'] ) ? $form['settings'][$form['identifier']] : $form['settings']['form_list'];
82 if(isset(self::$imported_form[ $plugin_name ][ $form_id ])){
83 $result[$json_id][ $plugin_name ][ $form['id'] ] = self::$imported_form[ $plugin_name ][ $form_id ];
84 continue;
85 }
86
87 $file_path = $root_path . wp_unslash( $form['file_path'] );
88 $import = new Form( $plugin_name, $file_path, $form );
89 $data = $import->run();
90
91 self::$imported_form[ $plugin_name ][ $form_id ] = (string) $data;
92 $result[$json_id][ $plugin_name ][ $form['id'] ] = (string) $data;
93 } catch ( Exception $e ) {
94 continue;
95 }
96 }
97 }
98 }
99
100 return $result;
101 }
102 }