PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / trunk
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel vtrunk
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / helpers / pmxe_functions.php
wp-all-export / helpers Last commit date
backward.php 4 weeks ago get_taxonomies_by_object_type.php 4 weeks ago pmxe_filter.php 4 weeks ago pmxe_functions.php 4 weeks ago pmxe_prepare_price.php 4 weeks ago pmxe_render_xml_attributes.php 4 weeks ago pmxe_render_xml_element.php 4 weeks ago pmxe_render_xml_text.php 4 weeks ago str_getcsv.php 4 weeks ago wp_all_export_check_children_assign.php 4 weeks ago wp_all_export_clear_xss.php 4 weeks ago wp_all_export_comments_clauses.php 4 weeks ago wp_all_export_generate_export_file.php 4 weeks ago wp_all_export_get_cpt_name.php 4 weeks ago wp_all_export_get_export_format.php 4 weeks ago wp_all_export_is_compatible.php 4 weeks ago wp_all_export_parse_field_name.php 4 weeks ago wp_all_export_posts_join.php 4 weeks ago wp_all_export_posts_where.php 4 weeks ago wp_all_export_pre_user_query.php 4 weeks ago wp_all_export_prepare_template_csv.php 4 weeks ago wp_all_export_prepare_template_xml.php 4 weeks ago wp_all_export_rand_char.php 4 weeks ago wp_all_export_remove_colons.php 4 weeks ago wp_all_export_remove_source.php 4 weeks ago wp_all_export_reverse_rules_html.php 4 weeks ago wp_all_export_rmdir.php 4 weeks ago wp_all_export_secure_file.php 4 weeks ago wp_all_export_terms_clauses.php 4 weeks ago wp_all_export_url_title.php 4 weeks ago wp_all_export_write_article.php 4 weeks ago wp_redirect_or_javascript.php 4 weeks ago
pmxe_functions.php
255 lines
1 <?php
2
3 // phpcs:ignoreFile WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound,WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound,WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- legitimate plugin prefixes (pmxe/PMXE/wpae/Wpae/wp_all_export/wpallexport/XmlExport/CdataStrategy/VariableProductTitle/Soflyy/GF_Export); Plugin Check does not honor phpcs.xml prefix declaration
4 defined( 'ABSPATH' ) || exit;
5
6
7 if ( ! function_exists('wp_all_export_isValidMd5')){
8 function wp_all_export_isValidMd5($md5 ='')
9 {
10 return preg_match('/^[a-f0-9]{32}$/', $md5);
11 }
12 }
13
14 if ( ! function_exists('wp_all_export_get_relative_path') ){
15 function wp_all_export_get_relative_path($path){
16
17 $uploads = wp_upload_dir();
18
19 return str_replace($uploads['basedir'], '', $path);
20
21 }
22 }
23
24 if ( ! function_exists('wp_all_export_get_absolute_path') ){
25 function wp_all_export_get_absolute_path($path){
26 $uploads = wp_upload_dir();
27
28 // If the path isn't http(s) and doesn't start with the basedir, add the basedir.
29 return ( strncmp($path, $uploads['basedir'], strlen($uploads['basedir'])) !== 0 and ! preg_match( '%^https?://%i', $path ) ) ? $uploads['basedir'] . $path : $path;
30
31 }
32 }
33
34 if ( ! function_exists('wp_all_export_rrmdir') ){
35 function wp_all_export_rrmdir($dir) {
36 if (is_dir($dir)) {
37 $objects = scandir($dir);
38 foreach ($objects as $object) {
39 if ($object != "." && $object != "..") {
40 if (filetype($dir . "/" . $object) == "dir") wp_all_export_rrmdir($dir . "/" . $object); else wp_delete_file($dir . "/" . $object);
41 }
42 }
43 reset($objects);
44 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- export plugin reads/writes its own files in uploads dir, WP_Filesystem not viable for streamed CSV/XML output
45 rmdir($dir);
46 }
47 }
48 }
49
50 if ( ! function_exists('pmxe_getExtension')){
51 function pmxe_getExtension($str)
52 {
53 $i = strrpos($str,".");
54 if (!$i) return "";
55 $l = strlen($str) - $i;
56 $ext = substr($str,$i+1,$l);
57 return (strlen($ext) <= 4) ? $ext : "";
58 }
59 }
60
61 if ( ! function_exists('wp_all_export_get_existing_meta_by_cpt'))
62 {
63 function wp_all_export_get_existing_meta_by_cpt( $post_type = false )
64 {
65 if (empty($post_type)) return array();
66
67 $post_type = ($post_type == 'product' and class_exists('WooCommerce')) ? array('product') : array($post_type);
68
69 global $wpdb;
70 $table_prefix = $wpdb->prefix;
71
72 $post_type = array_map(function($item) use ($wpdb) {
73 return $wpdb->prepare('%s', $item);
74 }, $post_type);
75
76 $post_type_in = implode(',', $post_type);
77
78 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,PluginCheck.Security.DirectDB.UnescapedDBParameter -- $table_prefix from $wpdb->prefix; $post_type_in built above by mapping each value through $wpdb->prepare('%s', ...)
79 $meta_keys = $wpdb->get_results("SELECT DISTINCT {$table_prefix}postmeta.meta_key FROM {$table_prefix}postmeta, {$table_prefix}posts WHERE {$table_prefix}postmeta.post_id = {$table_prefix}posts.ID AND {$table_prefix}posts.post_type IN ({$post_type_in}) AND {$table_prefix}postmeta.meta_key NOT LIKE '_edit%' AND {$table_prefix}postmeta.meta_key NOT LIKE '_oembed_%' LIMIT 1000");
80
81 $_existing_meta_keys = array();
82 if ( ! empty($meta_keys)){
83 $exclude_keys = array('_first_variation_attributes', '_is_first_variation_created');
84 foreach ($meta_keys as $meta_key) {
85 if ( strpos($meta_key->meta_key, "_tmp") === false && strpos($meta_key->meta_key, "_v_") === false && ! in_array($meta_key->meta_key, $exclude_keys))
86 $_existing_meta_keys[] = $meta_key->meta_key;
87 }
88 }
89 return $_existing_meta_keys;
90 }
91 }
92
93 if ( ! function_exists('wp_all_export_get_existing_taxonomies_by_cpt'))
94 {
95 function wp_all_export_get_existing_taxonomies_by_cpt( $post_type = false )
96 {
97 if (empty($post_type)) return array();
98
99 $post_taxonomies = array_diff_key(get_taxonomies_by_object_type(array($post_type), 'object'), array_flip(array('post_format')));
100 $_existing_taxonomies = array();
101 if ( ! empty($post_taxonomies)){
102 foreach ($post_taxonomies as $tx) {
103 if (strpos($tx->name, "pa_") !== 0)
104 $_existing_taxonomies[] = array(
105 'name' => empty($tx->label) ? $tx->name : $tx->label,
106 'label' => $tx->name,
107 'type' => 'cats'
108 );
109 }
110 }
111 return $_existing_taxonomies;
112 }
113 }
114
115 if ( ! function_exists('wp_all_export_get_taxonomies')) {
116 function wp_all_export_get_taxonomies() {
117 // get all taxonomies
118 $taxonomies = get_taxonomies(FALSE, 'objects');
119 $ignore = array('nav_menu', 'link_category');
120 $r = array();
121 // populate $r
122 foreach ($taxonomies as $taxonomy) {
123 if (in_array($taxonomy->name, $ignore)) {
124 continue;
125 }
126 if ( ! empty($taxonomy->labels->name) && strpos($taxonomy->labels->name, "_") === false){
127 $r[$taxonomy->name] = $taxonomy->labels->name;
128 }
129 else{
130 $r[$taxonomy->name] = empty($taxonomy->labels->singular_name) ? $taxonomy->name : $taxonomy->labels->singular_name;
131 }
132 }
133 asort($r, SORT_FLAG_CASE | SORT_STRING);
134 // return
135 return $r;
136
137 }
138 }
139
140 if ( ! function_exists('wp_all_export_cmp_custom_types')){
141 function wp_all_export_cmp_custom_types($a, $b)
142 {
143 return strcmp($a->labels->name, $b->labels->name);
144 }
145 }
146
147 if ( ! function_exists('prepare_date_field_value')){
148 function prepare_date_field_value($fieldOptions, $timestamp, $defaultFormat = false){
149
150 if ( ! empty($fieldOptions))
151 {
152 switch ($fieldOptions)
153 {
154 case 'unix':
155 $post_date = $timestamp;
156 break;
157 default:
158 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- exported date string must reflect WordPress site timezone, matching how dates were displayed pre-export
159 $post_date = date($fieldOptions, $timestamp);
160 break;
161 }
162 }
163 else
164 {
165
166 if ( in_array(XmlExportEngine::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ){
167 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- exported date string must reflect WordPress site timezone, matching how dates were displayed pre-export
168 $post_date = date("Y-m-d H:i:s", $timestamp);
169 } else {
170 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- exported date string must reflect WordPress site timezone, matching how dates were displayed pre-export
171 $post_date = date("Y-m-d", $timestamp);
172 }
173 }
174 return $post_date;
175 }
176 }
177
178
179 if ( ! function_exists( 'wpae_wp_enqueue_code_editor' ) ) {
180 function wpae_wp_enqueue_code_editor( $args ) {
181
182 // We need syntax highlighting to work in the plugin regardless of user setting.
183 // Function matches https://developer.wordpress.org/reference/functions/wp_enqueue_code_editor/ otherwise.
184 /*if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) {
185 return false;
186 }*/
187
188 $settings = wp_get_code_editor_settings( $args );
189
190 if ( empty( $settings ) || empty( $settings['codemirror'] ) ) {
191 return false;
192 }
193
194 wp_enqueue_script( 'code-editor' );
195 wp_enqueue_style( 'code-editor' );
196
197 if ( isset( $settings['codemirror']['mode'] ) ) {
198 $mode = $settings['codemirror']['mode'];
199 if ( is_string( $mode ) ) {
200 $mode = array(
201 'name' => $mode,
202 );
203 }
204
205 if ( ! empty( $settings['codemirror']['lint'] ) ) {
206 switch ( $mode['name'] ) {
207 case 'css':
208 case 'text/css':
209 case 'text/x-scss':
210 case 'text/x-less':
211 wp_enqueue_script( 'csslint' );
212 break;
213 case 'htmlmixed':
214 case 'text/html':
215 case 'php':
216 case 'application/x-httpd-php':
217 case 'text/x-php':
218 wp_enqueue_script( 'htmlhint' );
219 wp_enqueue_script( 'csslint' );
220 wp_enqueue_script( 'jshint' );
221 if ( ! current_user_can( 'unfiltered_html' ) ) {
222 wp_enqueue_script( 'htmlhint-kses' );
223 }
224 break;
225 case 'javascript':
226 case 'application/ecmascript':
227 case 'application/json':
228 case 'application/javascript':
229 case 'application/ld+json':
230 case 'text/typescript':
231 case 'application/typescript':
232 wp_enqueue_script( 'jshint' );
233 wp_enqueue_script( 'jsonlint' );
234 break;
235 }
236 }
237 }
238
239 wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) );
240
241 /**
242 * Fires when scripts and styles are enqueued for the code editor.
243 *
244 * @param array $settings Settings for the enqueued code editor.
245 *
246 * @since 4.9.0
247 *
248 */
249 do_action( 'wp_enqueue_code_editor', $settings );
250
251 return $settings;
252 }
253 }
254
255