Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/elementor/app/modules/import-export/utils.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace Elementor\App\Modules\ImportExport;
4
+
5
+
use Elementor\Core\Utils\Str;
6
+
use Elementor\Modules\LandingPages\Module as Landing_Pages_Module;
7
+
use Elementor\Modules\FloatingButtons\Module as Floating_Buttons_Module;
8
+
use Elementor\TemplateLibrary\Source_Local;
9
+
use Elementor\Utils as ElementorUtils;
10
+
11
+
class Utils {
12
+
13
+
public static function read_json_file( $path ) {
14
+
if ( ! Str::ends_with( $path, '.json' ) ) {
15
+
$path .= '.json';
16
+
}
17
+
18
+
$file_content = ElementorUtils::file_get_contents( $path, true );
19
+
20
+
return $file_content ? json_decode( $file_content, true ) : [];
21
+
}
22
+
23
+
public static function map_old_new_post_ids( array $imported_data ) {
24
+
$result = [];
25
+
26
+
$result += $imported_data['templates']['succeed'] ?? [];
27
+
28
+
if ( isset( $imported_data['content'] ) ) {
29
+
foreach ( $imported_data['content'] as $post_type ) {
30
+
$result += $post_type['succeed'] ?? [];
31
+
}
32
+
}
33
+
34
+
if ( isset( $imported_data['wp-content'] ) ) {
35
+
foreach ( $imported_data['wp-content'] as $post_type ) {
36
+
$result += $post_type['succeed'] ?? [];
37
+
}
38
+
}
39
+
40
+
return $result;
41
+
}
42
+
43
+
public static function map_old_new_term_ids( array $imported_data ) {
44
+
$result = [];
45
+
46
+
if ( ! isset( $imported_data['taxonomies'] ) ) {
47
+
return $result;
48
+
}
49
+
50
+
foreach ( $imported_data['taxonomies'] as $post_type_taxonomies ) {
51
+
foreach ( $post_type_taxonomies as $taxonomy ) {
52
+
foreach ( $taxonomy as $term ) {
53
+
$result[ $term['old_id'] ] = $term['new_id'];
54
+
}
55
+
}
56
+
}
57
+
58
+
return $result;
59
+
}
60
+
61
+
public static function get_elementor_post_types() {
62
+
$elementor_post_types = get_post_types_by_support( 'elementor' );
63
+
64
+
return array_filter( $elementor_post_types, function ( $value ) {
65
+
// Templates are handled in a separate process.
66
+
return 'elementor_library' !== $value;
67
+
} );
68
+
}
69
+
70
+
public static function get_builtin_wp_post_types() {
71
+
return [ 'post', 'page', 'nav_menu_item' ];
72
+
}
73
+
74
+
public static function get_registered_cpt_names() {
75
+
$post_types = get_post_types( [
76
+
'public' => true,
77
+
'can_export' => true,
78
+
'_builtin' => false,
79
+
] );
80
+
81
+
unset(
82
+
$post_types[ Landing_Pages_Module::CPT ],
83
+
$post_types[ Source_Local::CPT ],
84
+
$post_types[ Floating_Buttons_Module::CPT_FLOATING_BUTTONS ]
85
+
);
86
+
87
+
return array_keys( $post_types );
88
+
}
89
+
90
+
/**
91
+
* Transform a string name to title format.
92
+
*
93
+
* @param $name
94
+
*
95
+
* @return string
96
+
*/
97
+
public static function transform_name_to_title( $name ): string {
98
+
if ( empty( $name ) ) {
99
+
return '';
100
+
}
101
+
102
+
$title = str_replace( [ '-', '_' ], ' ', $name );
103
+
104
+
return ucwords( $title );
105
+
}
106
+
107
+
public static function get_import_sessions( $should_run_cleanup = false ) {
108
+
$import_sessions = get_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS, [] );
109
+
110
+
if ( $should_run_cleanup ) {
111
+
foreach ( $import_sessions as $session_id => $import_session ) {
112
+
if ( ! isset( $import_session['runners'] ) && isset( $import_session['instance_data'] ) ) {
113
+
$import_sessions[ $session_id ]['runners'] = $import_session['instance_data']['runners_import_metadata'] ?? [];
114
+
115
+
unset( $import_sessions[ $session_id ]['instance_data'] );
116
+
}
117
+
}
118
+
119
+
update_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS, $import_sessions );
120
+
}
121
+
122
+
return $import_sessions;
123
+
}
124
+
125
+
public static function update_space_between_widgets_values( $space_between_widgets ) {
126
+
$setting_exist = isset( $space_between_widgets['size'] );
127
+
$already_processed = isset( $space_between_widgets['column'] );
128
+
129
+
if ( ! $setting_exist || $already_processed ) {
130
+
return $space_between_widgets;
131
+
}
132
+
133
+
$size = strval( $space_between_widgets['size'] );
134
+
$space_between_widgets['column'] = $size;
135
+
$space_between_widgets['row'] = $size;
136
+
$space_between_widgets['isLinked'] = true;
137
+
138
+
return $space_between_widgets;
139
+
}
140
+
}
141
+