PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.1.8
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.1.8
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.8, at includes/Core/Importer/Runners/ExtraContent.php

123 lines 3.0 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 $progress = $this->origin->get_progress();
41
42 if(empty($progress)){
43 $this->log( 0 );
44 $progress = ["__started__"];
45 $this->origin->update_progress( $progress);
46 }
47
48 if( ! empty( $contents ) ) {
49 foreach( $contents as $type => $content ) {
50 // If the template has been processed, skip it
51 if (in_array($type, $progress)) {
52 continue;
53 }
54
55 switch ( $type ) {
56 case 'form':
57 $import = $this->import_form( $content );
58 $extra_content['form'] = $import;
59 break;
60 case 'data':
61 break;
62 }
63
64 $progress[] = $type;
65 $this->origin->update_progress($progress, [ 'extra-content' => $extra_content ]);
66
67 if( end( $contents ) !== $content){
68 $this->sse_message( [
69 'type' => 'continue',
70 'action' => 'continue',
71 'results' => __METHOD__ . '::' . __LINE__,
72 ] );
73 exit;
74 }
75 }
76 }
77
78 return [ 'extra-content' => $extra_content ];
79 }
80
81 private function import_form( $contents ): array {
82 if( ! is_array( $contents ) || empty( $contents ) ) {
83 return [];
84 }
85
86 $result = [];
87
88 $root_path = $this->dir_path . 'content' . DIRECTORY_SEPARATOR;
89
90 foreach( $contents as $json_id => $plugin_list ) {
91 if( empty( $plugin_list ) ) {
92 continue;
93 }
94
95 foreach ( $plugin_list as $plugin_name => $form_list ) {
96 if( empty( $form_list ) ) {
97 continue;
98 }
99
100 foreach ( $form_list as $form ) {
101 try {
102 $form_id = isset( $form['identifier'] ) ? $form['settings'][$form['identifier']] : $form['settings']['form_list'];
103 if(isset(self::$imported_form[ $plugin_name ][ $form_id ])){
104 $result[$json_id][ $plugin_name ][ $form['id'] ] = self::$imported_form[ $plugin_name ][ $form_id ];
105 continue;
106 }
107
108 $file_path = $root_path . wp_unslash( $form['file_path'] );
109 $import = new Form( $plugin_name, $file_path, $form );
110 $data = $import->run();
111
112 self::$imported_form[ $plugin_name ][ $form_id ] = (string) $data;
113 $result[$json_id][ $plugin_name ][ $form['id'] ] = (string) $data;
114 } catch ( Exception $e ) {
115 continue;
116 }
117 }
118 }
119 }
120
121 return $result;
122 }
123 }