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

97 lines 2.4 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 $contents = $this->manifest['extra-content'] ?? [];
39
40 $extra_content = $this->loop( $contents, function($type, $content, $extra_content ) {
41 switch ( $type ) {
42 case 'form':
43 $import = $this->import_form( $content );
44 $extra_content['form'] = $import;
45 break;
46 case 'data':
47 break;
48 }
49 return $extra_content;
50 });
51
52 return [ 'extra-content' => $extra_content ];
53 }
54
55 private function import_form( $contents ): array {
56 if( ! is_array( $contents ) || empty( $contents ) ) {
57 return [];
58 }
59
60 $result = [];
61
62 $root_path = $this->dir_path . 'content' . DIRECTORY_SEPARATOR;
63
64 foreach( $contents as $json_id => $plugin_list ) {
65 if( empty( $plugin_list ) ) {
66 continue;
67 }
68
69 foreach ( $plugin_list as $plugin_name => $form_list ) {
70 if( empty( $form_list ) ) {
71 continue;
72 }
73
74 foreach ( $form_list as $form ) {
75 try {
76 $form_id = isset( $form['identifier'] ) ? $form['settings'][$form['identifier']] : $form['settings']['form_list'];
77 if(isset(self::$imported_form[ $plugin_name ][ $form_id ])){
78 $result[$json_id][ $plugin_name ][ $form['id'] ] = self::$imported_form[ $plugin_name ][ $form_id ];
79 continue;
80 }
81
82 $file_path = $root_path . wp_unslash( $form['file_path'] );
83 $import = new Form( $plugin_name, $file_path, $form );
84 $data = $import->run();
85
86 self::$imported_form[ $plugin_name ][ $form_id ] = (string) $data;
87 $result[$json_id][ $plugin_name ][ $form['id'] ] = (string) $data;
88 } catch ( Exception $e ) {
89 continue;
90 }
91 }
92 }
93 }
94
95 return $result;
96 }
97 }