pmxe_functions.php
5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
if ( ! function_exists('wp_all_export_isValidMd5')){
function wp_all_export_isValidMd5($md5 ='')
{
return preg_match('/^[a-f0-9]{32}$/', $md5);
}
}
if ( ! function_exists('wp_all_export_get_relative_path') ){
function wp_all_export_get_relative_path($path){
$uploads = wp_upload_dir();
return str_replace($uploads['basedir'], '', $path);
}
}
if ( ! function_exists('wp_all_export_get_absolute_path') ){
function wp_all_export_get_absolute_path($path){
$uploads = wp_upload_dir();
return ( strpos($path, $uploads['basedir']) === false and ! preg_match('%^https?://%i', $path)) ? $uploads['basedir'] . $path : $path;
}
}
if ( ! function_exists('wp_all_export_rrmdir') ){
function wp_all_export_rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir . "/" . $object) == "dir") wp_all_export_rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object);
}
}
reset($objects);
rmdir($dir);
}
}
}
if ( ! function_exists('pmxe_getExtension')){
function pmxe_getExtension($str)
{
$i = strrpos($str,".");
if (!$i) return "";
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return (strlen($ext) <= 4) ? $ext : "";
}
}
if ( ! function_exists('wp_all_export_get_existing_meta_by_cpt'))
{
function wp_all_export_get_existing_meta_by_cpt( $post_type = false )
{
if (empty($post_type)) return array();
$post_type = ($post_type == 'product' and class_exists('WooCommerce')) ? array('product') : array($post_type);
global $wpdb;
$table_prefix = $wpdb->prefix;
$post_type = array_map(function($item) use ($wpdb) {
return $wpdb->prepare('%s', $item);
}, $post_type);
$post_type_in = implode(',', $post_type);
$meta_keys = $wpdb->get_results($wpdb->prepare("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"));
$_existing_meta_keys = array();
if ( ! empty($meta_keys)){
$exclude_keys = array('_first_variation_attributes', '_is_first_variation_created');
foreach ($meta_keys as $meta_key) {
if ( strpos($meta_key->meta_key, "_tmp") === false && strpos($meta_key->meta_key, "_v_") === false && ! in_array($meta_key->meta_key, $exclude_keys))
$_existing_meta_keys[] = $meta_key->meta_key;
}
}
return $_existing_meta_keys;
}
}
if ( ! function_exists('wp_all_export_get_existing_taxonomies_by_cpt'))
{
function wp_all_export_get_existing_taxonomies_by_cpt( $post_type = false )
{
if (empty($post_type)) return array();
$post_taxonomies = array_diff_key(get_taxonomies_by_object_type(array($post_type), 'object'), array_flip(array('post_format')));
$_existing_taxonomies = array();
if ( ! empty($post_taxonomies)){
foreach ($post_taxonomies as $tx) {
if (strpos($tx->name, "pa_") !== 0)
$_existing_taxonomies[] = array(
'name' => empty($tx->label) ? $tx->name : $tx->label,
'label' => $tx->name,
'type' => 'cats'
);
}
}
return $_existing_taxonomies;
}
}
if ( ! function_exists('wp_all_export_get_taxonomies')) {
function wp_all_export_get_taxonomies() {
// get all taxonomies
$taxonomies = get_taxonomies(FALSE, 'objects');
$ignore = array('nav_menu', 'link_category');
$r = array();
// populate $r
foreach ($taxonomies as $taxonomy) {
if (in_array($taxonomy->name, $ignore)) {
continue;
}
if ( ! empty($taxonomy->labels->name) && strpos($taxonomy->labels->name, "_") === false){
$r[$taxonomy->name] = $taxonomy->labels->name;
}
else{
$r[$taxonomy->name] = empty($taxonomy->labels->singular_name) ? $taxonomy->name : $taxonomy->labels->singular_name;
}
}
asort($r, SORT_FLAG_CASE | SORT_STRING);
// return
return $r;
}
}
if ( ! function_exists('wp_all_export_cmp_custom_types')){
function wp_all_export_cmp_custom_types($a, $b)
{
return strcmp($a->labels->name, $b->labels->name);
}
}
if ( ! function_exists('prepare_date_field_value')){
function prepare_date_field_value($fieldOptions, $timestamp, $defaultFormat = false){
if ( ! empty($fieldOptions))
{
switch ($fieldOptions)
{
case 'unix':
$post_date = $timestamp;
break;
default:
$post_date = date($fieldOptions, $timestamp);
break;
}
}
else
{
if ( in_array(XmlExportEngine::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ){
$post_date = date("Y-m-d H:i:s", $timestamp);
} else {
$post_date = date("Y-m-d", $timestamp);
}
}
return $post_date;
}
}