first commit

This commit is contained in:
2024-11-04 20:48:19 +01:00
commit 2fa33a3be9
7968 changed files with 2313063 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<?php
/**
* Fires once an attachment has been added.
*
* @since 2.0.0
*
* @param int $post_ID Attachment ID.
*/
function pmxi_add_attachment($post_ID){
// add image filename to pmxi_images table
if (wp_attachment_is_image($post_ID)){
$imageRecord = new PMXI_Image_Record();
$imageRecord->getBy(array(
'attachment_id' => $post_ID
));
if ($imageRecord->isEmpty()){
$image_name = basename(wp_get_attachment_url( $post_ID ));
$imageRecord->set(array(
'attachment_id' => $post_ID,
'image_url' => '',
'image_filename' => $image_name
))->insert();
}
}
}

View File

@@ -0,0 +1,40 @@
<?php
function pmxi_admin_head(){
?>
<style type="text/css">
#toplevel_page_pmxi-admin-home ul li:last-child{
display: none;
}
</style>
<?php
$input = new PMXI_Input();
$get_params = $input->get(array(
'id' => false,
'action' => false
));
if ($get_params['id']){
?>
<script type="text/javascript">
var import_id = '<?php echo intval($get_params["id"]); ?>';
</script>
<?php
}
$wp_all_import_ajax_nonce = '';
if ( get_current_user_id() and current_user_can( PMXI_Plugin::$capabilities )) {
$wp_all_import_ajax_nonce = wp_create_nonce( "wp_all_import_secure" );
}
?>
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url( "admin-ajax.php" ); ?>';
var import_action = '<?php echo esc_js($get_params["action"]); ?>';
var wp_all_import_security = '<?php echo wp_unslash($wp_all_import_ajax_nonce); ?>';
</script>
<?php
}

View File

@@ -0,0 +1,10 @@
<?php
function pmxi_admin_init(){
wp_enqueue_script('wp-all-import-script', WP_ALL_IMPORT_ROOT_URL . '/static/js/wp-all-import.js', array('jquery'), PMXI_VERSION);
@ini_set('mysql.connect_timeout', 300);
@ini_set('default_socket_timeout', 300);
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Register plugin specific admin menu
*/
function pmxi_admin_menu() {
global $menu, $submenu;
$icon_base64 = "PHN2ZyBjbGFzcz0iaW1nLWZsdWlkIiB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MjEuNTAzMyAzNi41MjYzTDIzLjIzNDkgMzYuNDMxNkMyMC42NDc5IDM0Ljg2MzIgMTguOTQ3NiAzMi45NTc5IDE3Ljk5ODMgMzAuNTA1M0MxNy4wNDkgMzIuOTU3OSAxNS4zNDg3IDM0Ljg2MzIgMTIuNzYxNyAzNi40MzE2TDE0LjUwMzcgMzYuNTI2M0MxNC45MDAxIDM2LjU0NzQgMTUuMjEzMSAzNi44OTQ3IDE1LjE5MjIgMzcuMzA1M0MxNS4xNzE0IDM3LjY5NDcgMTQuODQ4IDM4IDE0LjQ2MiAzOEgxNC40MjAzTDEwLjE5NTUgMzcuNzY4NEM5Ljk2NjAzIDM3Ljc1NzkgOS43Njc4MyAzNy42NDIxIDkuNjMyMjIgMzcuNDUyNkM5LjQ5NjYxIDM3LjI2MzIgOS40NjUzMSAzNy4wMzE2IDkuNTM4MzQgMzYuODEwNUwxMC44MjE0IDMyLjg4NDJDMTAuOTQ2NiAzMi41MDUzIDExLjM1MzQgMzIuMjk0NyAxMS43Mzk0IDMyLjQyMTFDMTIuMTE0OSAzMi41NDc0IDEyLjMyMzYgMzIuOTU3OSAxMi4xOTg0IDMzLjM0NzRMMTEuNjAzOCAzNS4xNTc5QzE1Ljk1MzcgMzIuNjMxNiAxNi44NTA4IDI5LjUwNTMgMTcuMTQyOSAyNi43NTc5QzE3LjE5NTEgMjYuMzI2MyAxNy41NDk3IDI2IDE3Ljk3NzQgMjZDMTguNDA1MSAyNiAxOC43NzAyIDI2LjMyNjMgMTguODEyIDI2Ljc1NzlDMTkuMTA0IDI5LjUxNTggMjAuMDAxMiAzMi42NDIxIDI0LjM3MiAzNS4xNzg5TDIzLjc3NzQgMzMuMzU3OUMyMy42NDE4IDMyLjk3ODkgMjMuODUwNCAzMi41NTc5IDI0LjIzNjQgMzIuNDMxNloiLz48L3N2Zz4=";
if (current_user_can( PMXI_Plugin::$capabilities )) { // admin management options
$wpai_menu = array(
array('pmxi-admin-import', __('New Import', 'pmxi_plugin')),
array('pmxi-admin-manage' , __('Manage Imports', 'pmxi_plugin')),
array('pmxi-admin-settings', __('Settings', 'pmxi_plugin')),
array('pmxi-admin-help', __('Support', 'pmxi_plugin')),
array('pmxi-admin-history', __('History', 'pmxi_plugin')),
);
$wpai_menu = apply_filters('pmxi_admin_menu', $wpai_menu);
add_menu_page(__('WP All Import', 'wp_all_import_plugin'), __('All Import', 'wp_all_import_plugin'), PMXI_Plugin::$capabilities, 'pmxi-admin-home', array(PMXI_Plugin::getInstance(), 'adminDispatcher'), 'data:image/svg+xml;base64,' . $icon_base64, 112);
// workaround to rename 1st option to `Home`
$submenu['pmxi-admin-home'] = array();
foreach ($wpai_menu as $key => $value) {
add_submenu_page('pmxi-admin-home', $value[1], $value[1], PMXI_Plugin::$capabilities, $value[0], array(PMXI_Plugin::getInstance(), 'adminDispatcher'));
}
}
}

View File

@@ -0,0 +1,140 @@
<?php
function pmxi_admin_notices() {
// compare woocommerce add-on version
if ( class_exists( 'PMWI_Plugin' ) and ( defined('PMWI_VERSION') and version_compare(PMWI_VERSION, '2.1.4') < 0 and PMWI_EDITION == 'paid' or defined('PMWI_FREE_VERSION') and version_compare(PMWI_FREE_VERSION, '1.2.2') < 0 and PMWI_EDITION == 'free') ) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: Please update your WP All Import WooCommerce add-on to the latest version', 'wp_all_import_plugin'),
PMWI_Plugin::getInstance()->getName()
) ?>
</p></div>
<?php
if (defined('PMWI_EDITION') and PMWI_EDITION == 'paid')
{
deactivate_plugins( PMWI_ROOT_DIR . '/wpai-woocommerce-add-on.php');
}
else
{
if (defined('PMWI_FREE_ROOT_DIR')){
deactivate_plugins( PMWI_FREE_ROOT_DIR . '/plugin.php');
}
else{
deactivate_plugins( PMWI_ROOT_DIR . '/plugin.php');
}
}
}
// compare ACF add-on
if ( class_exists( 'PMAI_Plugin' ) and defined('PMAI_VERSION') and version_compare(PMAI_VERSION, '3.0.0-beta1') < 0 and PMAI_EDITION == 'paid' ) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: Please update your WP All Import ACF add-on to the latest version', 'wp_all_import_plugin'),
PMAI_Plugin::getInstance()->getName()
) ?>
</p></div>
<?php
if (defined('PMAI_EDITION') and PMAI_EDITION == 'paid')
{
deactivate_plugins( PMAI_ROOT_DIR . '/wpai-acf-add-on.php');
}
}
// compare Linkcloak add-on
if ( class_exists( 'PMLCA_Plugin' ) and defined('PMLCA_VERSION') and version_compare(PMLCA_VERSION, '1.0.0-beta1') < 0 and PMLCA_EDITION == 'paid' ) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: Please update your WP All Import Linkcloak add-on to the latest version', 'wp_all_import_plugin'),
PMLCA_Plugin::getInstance()->getName()
) ?>
</p></div>
<?php
if (defined('PMLCA_EDITION') and PMLCA_EDITION == 'paid')
{
deactivate_plugins( PMLCA_ROOT_DIR . '/wpai-linkcloak-add-on.php');
}
}
// compare User add-on
if ( class_exists( 'PMUI_Plugin' ) and defined('PMUI_VERSION') and version_compare(PMUI_VERSION, '1.0.0-beta1') < 0 and PMUI_EDITION == 'paid' ) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: Please update your WP All Import User add-on to the latest version', 'wp_all_import_plugin'),
PMUI_Plugin::getInstance()->getName()
) ?>
</p></div>
<?php
if (defined('PMUI_EDITION') and PMUI_EDITION == 'paid')
{
deactivate_plugins( PMUI_ROOT_DIR . '/wpai-user-add-on.php');
}
}
// compare WPML add-on
if ( class_exists( 'PMLI_Plugin' ) and defined('PMLI_VERSION') and version_compare(PMLI_VERSION, '1.0.0-beta1') < 0 and PMLI_EDITION == 'paid' ) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: Please update your WP All Import WPML add-on to the latest version', 'wp_all_import_plugin'),
PMLI_Plugin::getInstance()->getName()
) ?>
</p></div>
<?php
if (defined('PMLI_EDITION') and PMLI_EDITION == 'paid')
{
deactivate_plugins( PMLI_ROOT_DIR . '/plugin.php');
}
}
$input = new PMXI_Input();
$messages = $input->get('pmxi_nt', array());
if ($messages) {
is_array($messages) or $messages = array($messages);
foreach ($messages as $type => $m) {
in_array((string)$type, array('updated', 'error')) or $type = 'updated';
?>
<div class="<?php echo esc_attr($type); ?>"><p><?php echo wp_kses_post($m); ?></p></div>
<?php
}
}
$warnings = $input->get('warnings', array());
if ($warnings) {
is_array($warnings) or $warnings = explode(',', $warnings);
foreach ($warnings as $code) {
switch ($code) {
case 1:
$m = __('<strong>Warning:</strong> your title is blank.', 'wp_all_import_plugin');
break;
case 2:
$m = __('<strong>Warning:</strong> your content is blank.', 'wp_all_import_plugin');
break;
case 3:
$m = __('<strong>Warning:</strong> You must <a href="https://www.wpallimport.com/checkout/?edd_action=add_to_cart&download_id=2707176&edd_options%5Bprice_id%5D=1&utm_source=import-plugin-free&utm_medium=upgrade-notice&utm_campaign=images" target="_blank">upgrade to the Pro edition of WP All Import</a> to import images. The settings you configured in the images section will be ignored.', 'wp_all_import_plugin');
break;
case 4:
$m = __('<strong>Warning:</strong> You must <a href="https://www.wpallimport.com/checkout/?edd_action=add_to_cart&download_id=2707176&edd_options%5Bprice_id%5D=1&utm_source=import-plugin-free&utm_medium=upgrade-notice&utm_campaign=custom-fields" target="_blank">upgrade to the Pro edition of WP All Import</a> to import data to Custom Fields. The settings you configured in the Custom Fields section will be ignored.', 'wp_all_import_plugin');
break;
default:
$m = false;
break;
}
if ($m):
?>
<div class="error"><p><?php echo wp_kses_post($m); ?></p></div>
<?php
endif;
}
}
wp_all_import_addon_notifications();
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Fires once an existing attachment has been updated.
*
* @since 4.4.0
*
* @param int $post_ID Post ID.
* @param WP_Post $post_after Post object following the update.
* @param WP_Post $post_before Post object before the update.
*/
function pmxi_attachment_updated($post_ID, $post_after, $post_before){
// update image filename in pmxi_images table
if (wp_attachment_is_image($post_ID)){
$imageRecord = new PMXI_Image_Record();
$imageRecord->getBy(array(
'attachment_id' => $post_ID
));
if (!$imageRecord->isEmpty()){
$image_name = basename(wp_get_attachment_url( $post_ID ));
// Do not update filename for scaled images.
if (strpos($image_name, '-scaled.') === FALSE) {
$imageRecord->set(array(
'image_filename' => $image_name
))->update();
}
}
}
}

View File

@@ -0,0 +1,14 @@
<?php
function pmxi_delete_post($post_id) {
if (!empty($post_id) && is_numeric($post_id)){
$post = new PMXI_Post_Record();
$is_post = ! $post->getBy( 'post_id', $post_id )->isEmpty();
if ( $is_post ) {
$post->delete();
} else {
$image = new PMXI_Image_Record();
$image->getBy( 'attachment_id', $post_id )->isEmpty() or $image->delete();
}
}
}

View File

@@ -0,0 +1,94 @@
<?php
function pmxi_pmxi_after_xml_import( $import_id, $import )
{
if ($import->options['custom_type'] == 'taxonomies') {
$parent_terms = get_option('wp_all_import_taxonomies_hierarchy_' . $import_id);
if (!empty($parent_terms)){
foreach ($parent_terms as $term_id => $pterm){
$parent_term = get_term_by('slug', $pterm, $import->options['taxonomy_type']) or $parent_term = get_term_by('name', $pterm, $import->options['taxonomy_type']) or ctype_digit($pterm) and $parent_term = get_term_by('id', $pterm, $import->options['taxonomy_type']);
if (!empty($parent_term) && !is_wp_error($parent_term)){
wp_update_term($term_id, $import->options['taxonomy_type'], array(
'parent' => $parent_term->term_id,
));
}
}
}
delete_option('wp_all_import_taxonomies_hierarchy_' . $import_id);
}
if (in_array($import->options['custom_type'], ['comments', 'woo_reviews'])) {
$parent_comments = get_option('wp_all_import_comments_hierarchy_' . $import_id);
if (!empty($parent_comments)){
foreach ($parent_comments as $comment_id => $pcomment){
$parent_comment = get_comment($pcomment);
if (!empty($parent_comment) && !is_wp_error($parent_comment)){
wp_update_comment(array(
'comment_ID' => $comment_id,
'comment_parent' => $parent_comment->comment_ID,
));
}
}
}
delete_option('wp_all_import_taxonomies_hierarchy_' . $import_id);
}
if ( ! in_array($import->options['custom_type'], array('taxonomies', 'import_users', 'shop_customer', 'comments', 'woo_reviews')) ) {
$custom_type = get_post_type_object( $import->options['custom_type'] );
if ( ! empty($custom_type) && $custom_type->hierarchical ){
$parent_posts = get_option('wp_all_import_posts_hierarchy_' . $import_id);
if (!empty($parent_posts)){
foreach ($parent_posts as $pid => $identity){
$parent_post = wp_all_import_get_parent_post($identity, $import->options['custom_type'], $import->options['type']);
if (!empty($parent_post) && !is_wp_error($parent_post)){
wp_update_post(array(
'ID' => $pid,
'post_parent' => $parent_post
));
}
}
}
delete_option('wp_all_import_posts_hierarchy_' . $import_id);
}
$recount_terms_after_import = TRUE;
$recount_terms_after_import = apply_filters('wp_all_import_recount_terms_after_import', $recount_terms_after_import, $import_id);
if ($recount_terms_after_import) {
// Update term count after import process is complete.
$taxonomies = get_object_taxonomies( $import->options['custom_type'] );
if (!empty($taxonomies)) {
foreach ( (array) $taxonomies as $taxonomy ) {
$term_ids = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'fields' => 'tt_ids',
)
);
if ( ! empty( $term_ids ) ) {
wp_update_term_count_now( $term_ids, $taxonomy );
}
}
}
// Update post count only once after import process is completed.
wp_all_import_update_post_count();
}
}
// Re-count post comments.
if ( in_array($import->options['custom_type'], array('comments', 'woo_reviews')) ) {
$recount_comments_after_import = TRUE;
$recount_comments_after_import = apply_filters('wp_all_import_recount_comments_after_import', $recount_comments_after_import, $import_id);
if ($recount_comments_after_import) {
$comment_posts = get_option('wp_all_import_comment_posts_' . $import_id);
if (!empty($comment_posts)) {
foreach ($comment_posts as $comment_post) {
wp_update_comment_count_now($comment_post);
}
}
}
}
// Add removed action during import.
add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 );
add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 );
add_action( 'post_updated', 'wp_save_post_revision', 10, 1 );
}

View File

@@ -0,0 +1,20 @@
<?php
function pmxi_pmxi_before_xml_import( $import_id ) {
delete_option('wp_all_import_taxonomies_hierarchy_' . $import_id);
// Remove some costly unnecessary actions during import.
remove_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10 );
remove_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10 );
remove_action( 'post_updated', 'wp_save_post_revision', 10 );
// Invalidate hashes if functions file has been changed.
$functions_hash = wp_all_import_generate_functions_hash();
if ($functions_hash) {
$current_hash = get_option('_wp_all_import_functions_hash_' . $import_id, false);
if ($functions_hash !== $current_hash) {
global $wpdb;
$wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'pmxi_hash WHERE import_id = ' . $import_id );
update_option('_wp_all_import_functions_hash_' . $import_id, $functions_hash, false);
}
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* @param $post_type
* @param $post
*/
function pmxi_pmxi_extend_options_custom_fields($post_type, $post) {
if ( class_exists('ACF') && ! is_plugin_active('wpai-acf-add-on/wpai-acf-add-on.php') ) {
global $acf;
$savedGroups = array();
if ( !is_null($acf) && isset($acf->settings['version']) && version_compare($acf->settings['version'], '5.0.0') >= 0 ) {
$savedGroups = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'acf-field-group',
'order' => 'ASC',
'orderby' => 'title'
));
$groups = [];
if (function_exists('acf_local')) {
$groups = acf_local()->groups;
}
if (empty($groups) && function_exists('acf_get_local_field_groups')) {
$groups = acf_get_local_field_groups();
}
} else {
$groups = apply_filters('acf/get_field_groups', array());
}
if (!empty($savedGroups)) {
foreach ($savedGroups as $key => $group) {
if ( version_compare($acf->settings['version'], '5.0.0') >= 0 ) {
$groupData = acf_get_field_group($group);
// Prepare validation rules.
if (!empty($groupData['location'])) {
foreach ($groupData['location'] as $i => $locations) {
foreach ($locations as $j => $location) {
if ($location['param'] !== 'post_type') {
unset($groupData['location'][$i][$j]);
}
}
}
}
// Only render visible field groups.
if (in_array($post_type, array('taxonomies', 'import_users')) || acf_get_field_group_visibility($groupData, array('post_type' => $post_type)) || empty($groupData['location'][0])) {
if (!isset($groups[$group->post_name])) {
$groups[] = array(
'ID' => $group->ID,
'title' => $group->post_title,
'slug' => $group->post_excerpt
);
} else {
$groups[$group->post_name]['ID'] = $group->ID;
}
}
} else {
if (!isset($groups[$group->post_name])) {
$groups[] = array(
'ID' => $group->ID,
'title' => $group->post_title,
'slug' => $group->post_excerpt
);
} else {
$groups[$group->post_name]['ID'] = $group->ID;
}
}
}
}
if (!empty($groups)) {
foreach ($groups as $key => $group) {
if (empty($group['ID']) && !empty($group['id'])) {
$groups[$key]['ID'] = $group['id'];
} elseif (empty($group['ID']) && !empty($group['key'])) {
$groups[$key]['ID'] = $group['key'];
}
}
}
require_once WP_ALL_IMPORT_ROOT_DIR . '/views/admin/promotion/acf.php';
}
}

View File

@@ -0,0 +1,117 @@
<?php
function pmxi_wp_ajax_auto_detect_cf(){
if ( ! check_ajax_referer( 'wp_all_import_secure', 'security', false )){
exit( json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin'))) );
}
if ( ! current_user_can( PMXI_Plugin::$capabilities ) ){
exit( json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin'))) );
}
$input = new PMXI_Input();
$post_type = $input->post('post_type', 'post');
global $wpdb;
$table_prefix = $wpdb->prefix;
$ignoreFields = array(
'_edit_lock', '_edit_last', '_wp_trash_meta_status', '_wp_trash_meta_time', '_visibility', '_stock_status', '_downloadable', '_virtual', '_regular_price', '_sale_price', '_purchase_note', '_featured', '_weight', '_length',
'_width', '_height', '_sku', '_sale_price_dates_from', '_sale_price_dates_to', '_price', '_sold_individually', '_manage_stock', '_stock', '_upsell_ids', '_crosssell_ids','_downloadable_files', '_download_limit', '_download_expiry', '_download_type', '_product_url', '_button_text', '_backorders', '_tax_status', '_tax_class', '_product_image_gallery', '_default_attributes','total_sales', '_product_attributes', '_product_version', '_thumbnail_id', '_is_first_variation_created', '_regular_price_tmp', '_sale_price_tmp', '_price_tmp', '_stock_tmp',
'_order_total', '_order_version', '_order_tax', '_order_shipping_tax', '_order_shipping', '_cart_discount_tax', '_cart_discount', '_order_currency', '_order_key', '_prices_include_tax'
);
$fields = array();
switch ($post_type) {
case 'shop_customer':
$user_fields = array('first_name', 'last_name', 'nickname', 'description', PMXI_Plugin::getInstance()->getWPPrefix() . 'capabilities');
$billing_fields = array('billing_first_name','billing_last_name','billing_company','billing_address_1','billing_address_2','billing_city','billing_postcode','billing_country','billing_state','billing_phone','billing_email');
$shipping_fields = array('shipping_first_name','shipping_last_name','shipping_company','shipping_address_1','shipping_address_2','shipping_city','shipping_postcode','shipping_country','shipping_state');
$ignoreFields = array_merge($ignoreFields, $user_fields, $billing_fields, $shipping_fields);
$fields = $input->post('fields', array());
break;
case 'import_users':
case 'taxonomies':
$fields = $input->post('fields', array());
break;
default:
$results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT meta_key FROM ". $table_prefix ."posts, ". $table_prefix ."postmeta WHERE post_type = %s AND ". $table_prefix ."posts.ID = ". $table_prefix ."postmeta.post_id", $post_type), ARRAY_A);
if (!empty($results) && !is_wp_error($results)){
foreach ($results as $key => $value) {
$fields[] = $value['meta_key'];
}
}
break;
}
$result = array();
if ($fields) {
is_array($fields) or $fields = array($fields);
foreach ($fields as $field) {
switch ($post_type){
case 'import_users':
case 'shop_customer':
$values = $wpdb->get_results("
SELECT DISTINCT usermeta.meta_value
FROM ".$wpdb->usermeta." as usermeta
WHERE usermeta.meta_key='".$field."'
", ARRAY_A);
break;
case 'taxonomies':
$values = $wpdb->get_results("
SELECT DISTINCT termmeta.meta_value
FROM ".$wpdb->termmeta." as termmeta
WHERE termmeta.meta_key='".$field."'
", ARRAY_A);
break;
default:
$values = $wpdb->get_results("
SELECT DISTINCT postmeta.meta_value
FROM ".$wpdb->postmeta." as postmeta
WHERE postmeta.meta_key='".$field."'
", ARRAY_A);
break;
}
if ( ! empty($values) ){
foreach ($values as $key => $value) {
if ( ! empty($value['meta_value'])
and !empty($field)
and ! in_array($field, $ignoreFields)
and strpos($field, '_max_') !== 0
and strpos($field, '_min_') !== 0 and ! preg_match('%_[0-9]{1,}_%', $field)
and ($post_type != 'shop_order' or strpos($field, '_billing') !== 0 and strpos($field, '_shipping') !== 0)) {
$result[] = array(
'key' => $field,
'val' => $value['meta_value'],
'is_serialized' => is_serialized($value['meta_value'])
);
break;
}
}
}
}
}
if (empty($result)){
switch ($post_type){
case 'taxonomies':
$custom_type = new stdClass();
$custom_type->labels = new stdClass();
$custom_type->labels->singular_name = __('Taxonomy Term', 'wp_all_import_plugin');
break;
default:
$custom_type = get_post_type_object( $post_type );
break;
}
$msg = sprintf(__('No Custom Fields are present in your database for %s', 'wp_all_import_plugin'), esc_attr($custom_type->labels->name));
}
elseif (count($result) === 1)
$msg = sprintf(__('%s field was automatically detected.', 'wp_all_import_plugin'), count($result));
else{
$msg = sprintf(__('%s fields were automatically detected.', 'wp_all_import_plugin'), count($result));
}
exit( json_encode(array('result' => $result, 'msg' => $msg)) );
}

View File

@@ -0,0 +1,67 @@
<?php
function pmxi_wp_ajax_auto_detect_sf(){
if ( ! check_ajax_referer( 'wp_all_import_secure', 'security', false )){
exit( json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin'))) );
}
if ( ! current_user_can( PMXI_Plugin::$capabilities ) ){
exit( json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin'))) );
}
$input = new PMXI_Input();
$fieldName = $input->post('name', '');
$post_type = $input->post('post_type', 'post');
global $wpdb;
$result = array();
if ($fieldName) {
switch ($post_type){
case 'import_users':
case 'shop_customer':
$values = $wpdb->get_results("
SELECT DISTINCT usermeta.meta_value
FROM ".$wpdb->usermeta." as usermeta
WHERE usermeta.meta_key='".$fieldName."'
", ARRAY_A);
break;
case 'taxonomies':
$values = $wpdb->get_results("
SELECT DISTINCT termmeta.meta_value
FROM ".$wpdb->termmeta." as termmeta
WHERE termmeta.meta_key='".$fieldName."'
", ARRAY_A);
break;
default:
$values = $wpdb->get_results("
SELECT DISTINCT postmeta.meta_value
FROM ".$wpdb->postmeta." as postmeta
WHERE postmeta.meta_key='".$fieldName."'
", ARRAY_A);
break;
}
if ( ! empty($values) ){
foreach ($values as $key => $value) {
if ( ! empty($value['meta_value']) and is_serialized($value['meta_value'])){
$v = unserialize($value['meta_value']);
if ( ! empty($v) and is_array($v) ){
foreach ($v as $skey => $svalue) {
$result[] = array(
'key' => $skey,
'val' => maybe_serialize($svalue),
);
}
break;
}
}
}
}
}
exit( json_encode(array('result' => $result)) );
}

View File

@@ -0,0 +1,91 @@
<?php
function pmxi_wp_ajax_delete_import(){
if ( ! check_ajax_referer( 'wp_all_import_secure', 'security', false )){
exit( json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))) );
}
if ( ! current_user_can( PMXI_Plugin::$capabilities ) ){
exit( json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))) );
}
$input = new PMXI_Input();
$post = $input->post(array(
'data' => '',
'iteration' => 1
));
$params = array();
parse_str($post['data'], $params);
$response = array(
'result' => false,
'msg' => ''
);
$get_import_id = $params['import_ids'][0];
$import = new PMXI_Import_Record();
$import->getById($get_import_id);
if ( ! $import->isEmpty() )
{
if (!empty($import['options']['custom_type'])){
switch ($import['options']['custom_type']){
case 'import_users':
$custom_type = new stdClass();
$custom_type->label = __('Users', 'wp_all_import_plugin');
break;
case 'shop_customer':
$custom_type = new stdClass();
$custom_type->label = __('Customers', 'wp_all_import_plugin');
break;
default:
$custom_type = get_post_type_object( $import['options']['custom_type'] );
break;
}
$cpt_name = ( ! empty($custom_type)) ? strtolower($custom_type->label) : '';
} else {
$cpt_name = '';
}
}
if ( $params['is_delete_import'] and ! $params['is_delete_posts'] ) {
$response['redirect'] = esc_url_raw(add_query_arg('pmxi_nt', urlencode(__('Import deleted', 'wp_all_import_plugin')), $params['base_url']));
} elseif( ! $params['is_delete_import'] and $params['is_delete_posts']) {
$response['redirect'] = esc_url_raw(add_query_arg('pmxi_nt', urlencode(sprintf(__('All associated %s deleted.', 'wp_all_import_plugin'), $cpt_name)), $params['base_url']));
} elseif( $params['is_delete_import'] and $params['is_delete_posts']) {
$response['redirect'] = esc_url_raw(add_query_arg('pmxi_nt', urlencode(sprintf(__('Import and all associated %s deleted.', 'wp_all_import_plugin'), $cpt_name)), $params['base_url']));
} else {
$response['redirect'] = esc_url_raw(add_query_arg('pmxi_nt', urlencode(__('Nothing to delete.', 'wp_all_import_plugin')), $params['base_url']));
exit( json_encode( $response ));
}
if ( ! empty($params['import_ids'])) {
foreach ($params['import_ids'] as $key => $id) {
$import = new PMXI_Import_Record();
$import->getById($id);
if ( ! $import->isEmpty() ) {
if ((int) $post['iteration'] === 1) {
$import->set(array(
'deleted' => 0
))->update();
}
$is_all_records_deleted = $import->deletePostsAjax( ! $params['is_delete_posts'], $params['is_delete_images'], $params['is_delete_attachments'] );
$response['result'] = (empty($params['import_ids'][$key + 1])) ? $is_all_records_deleted : false;
$response['msg'] = sprintf(__('Import #%d - %d records deleted', 'wp_all_import_plugin'), intval($import->id), intval($import->deleted));
if ( $is_all_records_deleted === true )
{
$import->delete( ! $params['is_delete_posts'], $params['is_delete_images'], $params['is_delete_attachments'], $params['is_delete_import'] );
}
}
}
}
exit( json_encode( $response ));
}

View File

@@ -0,0 +1,16 @@
<?php
function pmxi_wp_ajax_dismiss_notifications(){
if ( ! check_ajax_referer( 'wp_all_import_secure', 'security', false )){
exit( json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))) );
}
if ( ! current_user_can( PMXI_Plugin::$capabilities ) ){
exit( json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))) );
}
if (isset($_POST['addon']) ) {
update_option(sanitize_key($_POST['addon']) . '_notice_ignore', 'true', false);
}
exit( json_encode( array('result' => true)));
}

View File

@@ -0,0 +1,28 @@
<?php
function pmxi_wp_ajax_import_failed(){
if ( ! check_ajax_referer( 'wp_all_import_secure', 'security', false )){
exit( json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))) );
}
if ( ! current_user_can( PMXI_Plugin::$capabilities ) ){
exit( json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))) );
}
$result = false;
if (!empty($_POST['id'])) {
$import = new PMXI_Import_record();
$import->getbyId(intval($_POST['id']));
if ( ! $import->isEmpty()) {
$import->set(array(
'executing' => 0,
'last_activity' => date('Y-m-d H:i:s'),
'failed' => 1,
'failed_on' => date('Y-m-d H:i:s')
))->save();
$result = true;
do_action('pmxi_import_failed', intval($_POST['id']));
}
}
exit( json_encode( array('result' => $result)));
}

View File

@@ -0,0 +1,165 @@
<?php
function pmxi_wp_ajax_test_images(){
if ( ! check_ajax_referer( 'wp_all_import_secure', 'security', false )){
exit( json_encode(array('result' => array(), 'failed_msgs' => array(__('Security check', 'wp_all_import_plugin')))));
}
if ( ! current_user_can( PMXI_Plugin::$capabilities ) ){
exit( json_encode(array('result' => array(), 'failed_msgs' => array(__('Security check', 'wp_all_import_plugin')))));
}
$input = new PMXI_Input();
$post = $input->post(array(
'download' => 'yes',
'imgs' => array()
));
$result = array();
$wp_uploads = wp_upload_dir();
$imgs_basedir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY . DIRECTORY_SEPARATOR;
$targetDir = $wp_uploads['path'];
$success_images = 0;
$success_msg = '';
$failed_msgs = array();
if ( ! @is_writable($targetDir) )
{
$failed_msgs[] = sprintf(__('Uploads folder `%s` is not writable.', 'wp_all_import_plugin'), $targetDir);
}
else
{
switch ($post['download'])
{
// Use images currently uploaded in wp-content/uploads/wpallimport/files/
case 'no':
if ( ! empty($post['imgs']) )
{
foreach ($post['imgs'] as $img)
{
if ( preg_match('%^(http|https|ftp|ftps)%i', $img)){
$failed_msgs[] = sprintf(__('Use image name instead of URL `%s`.', 'wp_all_import_plugin'), esc_url($img));
continue;
}
if ( @file_exists($imgs_basedir . $img) ){
if (@is_readable($imgs_basedir . $img)){
$success_images++;
} else{
$failed_msgs[] = sprintf(__('File `%s` isn\'t readable', 'wp_all_import_plugin'), preg_replace('%.*/wp-content%', '/wp-content', esc_attr($imgs_basedir . $img)));
}
}
else{
$failed_msgs[] = sprintf(__('File `%s` doesn\'t exist', 'wp_all_import_plugin'), preg_replace('%.*/wp-content%', '/wp-content', esc_attr($imgs_basedir . $img)));
}
}
}
if ((int)$success_images === 1)
{
$success_msg = sprintf(__('%d image was successfully retrieved from `%s`', 'wp_all_import_plugin'), intval($success_images), preg_replace('%.*/wp-content%', '/wp-content', esc_attr($wp_uploads['basedir']) . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY));
}
elseif ((int)$success_images > 1)
{
$success_msg = sprintf(__('%d images were successfully retrieved from `%s`', 'wp_all_import_plugin'), intval($success_images), preg_replace('%.*/wp-content%', '/wp-content', esc_attr($wp_uploads['basedir']) . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY));
}
break;
// Use images currently in Media Library
case 'gallery':
if ( ! empty($post['imgs']) )
{
global $wpdb;
foreach ($post['imgs'] as $img)
{
$bn = wp_all_import_sanitize_filename(wp_all_import_basename($img));
$img_ext = pmxi_getExtensionFromStr($img);
$default_extension = pmxi_getExtension($bn);
$image_name = apply_filters("wp_all_import_image_filename", urldecode(sanitize_file_name((($img_ext) ? str_replace("." . $default_extension, "", $bn) : $bn))) . (("" != $img_ext) ? '.' . $img_ext : ''));
$attch = wp_all_import_get_image_from_gallery($image_name, $targetDir);
if ( ! empty($attch) )
{
$success_images++;
}
else
{
$failed_msgs[] = sprintf(__('Image `%s` not found in media library.', 'wp_all_import_plugin'), esc_attr($image_name));
}
}
}
if ((int)$success_images === 1)
{
$success_msg = sprintf(__('%d image was successfully found in media gallery', 'wp_all_import_plugin'), intval($success_images));
}
elseif ((int)$success_images > 1)
{
$success_msg = sprintf(__('%d images were successfully found in media gallery', 'wp_all_import_plugin'), intval($success_images));
}
break;
// Download images hosted elsewhere
default:
$start = time();
if ( ! empty($post['imgs']) )
{
foreach ($post['imgs'] as $img)
{
if ( ! preg_match('%^(http|https|ftp|ftps)%i', $img)){
$failed_msgs[] = sprintf(__('URL `%s` is not valid.', 'wp_all_import_plugin'), esc_url($img));
continue;
}
$image_name = wp_unique_filename($targetDir, 'test');
$image_filepath = $targetDir . '/' . $image_name;
$url = trim($img);
$request = get_file_curl($url, $image_filepath);
$get_ctx = stream_context_create(array('http' => array('timeout' => 5)));
if ( (is_wp_error($request) or $request === false) and ! @file_put_contents($image_filepath, @file_get_contents($img, false, $get_ctx))) {
$failed_msgs[] = (is_wp_error($request)) ? $request->get_error_message() : sprintf(__('File `%s` cannot be saved locally', 'wp_all_import_plugin'), esc_url($img));
} elseif( ! ($image_info = apply_filters('pmxi_getimagesize', @getimagesize($image_filepath), $image_filepath)) or ! in_array($image_info[2], wp_all_import_supported_image_types())) {
$failed_msgs[] = sprintf(__('File `%s` is not a valid image.', 'wp_all_import_plugin'), esc_url($img));
} else {
$success_images++;
}
@unlink($image_filepath);
}
}
$time = time() - $start;
if ((int)$success_images === 1)
{
$success_msg = sprintf(__('%d image was successfully downloaded in %s seconds', 'wp_all_import_plugin'), intval($success_images), number_format($time, 2));
}
elseif ((int)$success_images > 1)
{
$success_msg = sprintf(__('%d images were successfully downloaded in %s seconds', 'wp_all_import_plugin'), intval($success_images), number_format($time, 2));
}
break;
}
}
exit(json_encode(array(
'success_images' => $success_images,
'success_msg' => $success_msg,
'failed_msgs' => $failed_msgs
))); die;
}

View File

@@ -0,0 +1,26 @@
<?php
function pmxi_wpmu_new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta)
{
// create/update required database tables
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
require PMXI_Plugin::ROOT_DIR . '/schema.php';
global $wpdb;
if (function_exists('is_multisite') && is_multisite()) {
// check if it is a network activation - if so, run the activation function for each blog id
$old_blog = $wpdb->blogid;
switch_to_blog($blog_id);
require PMXI_Plugin::ROOT_DIR . '/schema.php';
dbDelta($plugin_queries);
// sync data between plugin tables and wordpress (mostly for the case when plugin is reactivated)
$post = new PMXI_Post_Record();
$wpdb->query('DELETE FROM ' . $post->getTable() . ' WHERE post_id NOT IN (SELECT ID FROM ' . $wpdb->posts . ')');
switch_to_blog($old_blog);
return;
}
}