PATH:
home
/
letacommog
/
entrepro
/
wp-content
/
plugins
/
wpai-ceo-addon
<?php /* Plugin Name: WP All Import - Rehub Content Egg Add-On Description: Import Content Egg data (modules Offer, Coupon) to the Posts. Version: 1.7 Author: WPsoul.com Author URI: https://wpsoul.com/ Requires at least: 4.8 Tested up to: 4.9.8 Text Domain: wpaiceaddon Domain Path: /languages/ */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly. } /* * Import class WPAI */ include "rapid-addon.php"; /* * Post Offer Object */ $wpai_ce_offer = new RapidAddon(__("Content Egg Offer", "wpaiceaddon"), 'wpai_ce_offer'); $wpai_ce_offer->add_field('ce_orig_url', __("Offer URL (required)", "wpaiceaddon"), 'text', null, __("Leave it empty if you want delete offers after updating the posts.", "wpaiceaddon")); $wpai_ce_offer->add_field('ce_title', __("Title (required)", "wpaiceaddon"), 'text', null, __("Leave it empty if you want delete offers after updating the posts.", "wpaiceaddon")); $wpai_ce_offer->add_field('ce_description', __("Description", "wpaiceaddon"), 'textarea'); $wpai_ce_offer->add_field('ce_img', __("Image URL", "wpaiceaddon"), 'text'); $wpai_ce_offer->add_field('ce_deeplink', __("Deeplink", "wpaiceaddon"), 'text'); $wpai_ce_offer->add_field('ce_domain', __("Merchant Domain", "wpaiceaddon"), 'text', null, __("Will be used for parsing logo", "wpaiceaddon")); $wpai_ce_offer->add_field('ce_merchant', __("Merchant Name", "wpaiceaddon"), 'text', null, __("Will be used as name of shop", "wpaiceaddon")); $wpai_ce_offer->add_field('ce_price', __("Price", "wpaiceaddon"), 'text'); $wpai_ce_offer->add_field('ce_priceOld', __("Old price", "wpaiceaddon"), 'text'); $wpai_ce_offer->add_field('ce_currencyCode', __("Offer currency", "wpaiceaddon"), 'text', null, __("Currency in ISO 4217. This is only for schema markup. Example: USD or EUR", "wpaiceaddon")); $wpai_ce_offer->add_field('ce_rating', __("Offer rating", "wpaiceaddon"), 'text', null, __("Set number from 1 to 5", "wpaiceaddon")); $wpai_ce_offer->add_field('ce_unique_id', __("Unique Offer ID", "wpaiceaddon"), 'text', null, __("This code forms a link for the redirect of the Affiliate URL. Otherwise, will be generated automatically.", "wpaiceaddon")); $wpai_ce_offer->add_field('ce_unique_pid', __("Unique Post ID", "wpaiceaddon"), 'text', null, __("This code will be used for identification of the Post which has a few offers.", "wpaiceaddon")); $wpai_ce_offer->set_import_function('wpai_ce_offer_import'); $wpai_ce_offer->admin_notice(__("The WPAI CE Offer Add-On requires WP All Import and Content Egg plugins.", "wpaiceaddon"), array("plugins" => array("content-egg/content-egg.php"))); $wpai_ce_offer->run(array("post_types" => array("post", "product"))); /* * Post Coupon Object */ $wpai_ce_coupon = new RapidAddon(__("Content Egg Coupon", "wpaiceaddon"), 'wpai_ce_coupon'); $wpai_ce_coupon->add_field('cec_title', __("Title (required)", "wpaiceaddon"), 'text', null, __("Leave it empty if you want delete coupons after updating the posts.", "wpaiceaddon")); $wpai_ce_coupon->add_field('cec_url', __("Affiliate URL (required)", "wpaiceaddon"), 'text', null, __("Leave it empty if you want delete coupons after updating the posts.", "wpaiceaddon")); $wpai_ce_coupon->add_field('cec_code', __("Coupon code", "wpaiceaddon"), 'text'); $wpai_ce_coupon->add_field('cec_startdate', __("Start date (YYYY/MM/DD)", "wpaiceaddon"), 'text'); $wpai_ce_coupon->add_field('cec_enddate', __("End date (YYYY/MM/DD)", "wpaiceaddon"), 'text'); $wpai_ce_coupon->add_field('cec_date_format', __("Convert date from British format:", "wpaiceaddon"), 'radio', array('0' => __("No", "wpairehubaddon"), '1' => __("From dd/mm/yyyy", "wpairehubaddon"), '2' => __("From dd/mm/yy", "wpairehubaddon"))); $wpai_ce_coupon->add_field('cec_mdomain', __("Merchant domain", "wpaiceaddon"), 'text', null, __("Will be used for parsing logo", "wpaiceaddon")); $wpai_ce_coupon->add_field('cec_mlogo', __("Image URL", "wpairehubaddon"), 'text', null, __( "Put in a full URL path to the Image", "wpaiceaddon")); $wpai_ce_coupon->add_field('cec_description', __("Description", "wpaiceaddon"), 'textarea'); $wpai_ce_coupon->set_import_function('wpai_ce_coupon_import'); $wpai_ce_coupon->run(array("post_types" => array("post", "product"))); /* * Post Offer callback function */ function wpai_ce_offer_import($post_id, $data, $import_options, $article) { global $wpai_ce_offer; if ($wpai_ce_offer->can_update_meta('_cegg_data_Offer', $import_options)) { $new_data = array(); $wpai_ce_offer->log(sprintf(__('<b>%s:</b>', 'wpaiceaddon'), $wpai_ce_offer->name)); if (empty($data['ce_title']) || !filter_var($data['ce_orig_url'], FILTER_VALIDATE_URL) || !filter_var($data['ce_img'], FILTER_VALIDATE_URL)) { $loger_text = sprintf(__('- The post "%s" has empty or wrong required fields (title, urls). The offer was deleted or not added', 'wpaiceaddon'), get_the_title($post_id)); } else { $new_data['title'] = trim(sanitize_text_field($data['ce_title'])); $new_data['orig_url'] = $data['ce_orig_url']; $new_data['img'] = $data['ce_img']; $new_data['description'] = !empty($data['ce_description']) ? trim(wp_kses_post($data['ce_description'])) : ''; $new_data['price'] = !empty($data['ce_price']) ? trim(sanitize_text_field($data['ce_price'])) : ''; $new_data['priceOld'] = !empty($data['ce_priceOld']) ? trim(sanitize_text_field($data['ce_priceOld'])) : ''; $new_data['currencyCode'] = !empty($data['ce_currencyCode']) ? trim(sanitize_text_field($data['ce_currencyCode'])) : ''; $new_data['unique_id'] = !empty($data['ce_unique_id']) ? trim(sanitize_text_field($data['ce_unique_id'])) : substr(md5($data['ce_orig_url']), 0, 9); $new_data['unique_pid'] = !empty($data['ce_unique_pid']) ? trim(sanitize_text_field($data['ce_unique_pid'])) : ''; $new_data['extra']['deeplink'] = !empty($data['ce_deeplink']) ? trim(strip_tags($data['ce_deeplink'])) : ''; $new_data['domain'] = !empty($data['ce_domain']) ? \ContentEgg\application\helpers\TextHelper::getHostName($data['ce_domain']) : ''; $new_data['merchant'] = !empty($data['ce_merchant']) ? sanitize_text_field($data['ce_merchant']) : ''; $new_data['rating'] = '0'; if(!empty($data['ce_rating'])) $new_data['rating'] = ($data['ce_rating'] > 4) ? 5 : $data['ce_rating']; if(!empty($new_data['unique_pid'])) add_post_meta($post_id, '_ce_unique_pid', $new_data['unique_pid']); $loger_text = sprintf(__('- The offer "%s" was added to the post "%s".', 'wpaiceaddon'), $new_data['title'], get_the_title($post_id)); } \ContentEgg\application\components\ContentManager::saveData(array($new_data), 'Offer', $post_id); $wpai_ce_offer->log($loger_text); } } /* * Post Coupon callback function */ function wpai_ce_coupon_import($post_id, $data, $import_options) { global $wpai_ce_coupon; if ($wpai_ce_coupon->can_update_meta('_cegg_data_Coupon', $import_options)) { $new_data = array(); $wpai_ce_coupon->log(sprintf(__('<b>%s:</b>', 'wpaiceaddon'), $wpai_ce_coupon->name)); if (empty($data['cec_title']) || !filter_var($data['cec_url'], FILTER_VALIDATE_URL) || ($data['cec_mlogo'] && !filter_var($data['cec_mlogo'], FILTER_VALIDATE_URL))) { $loger_text = sprintf(__('- The post "%s" has empty or wrong required cupon fields (title, urls). The coupon was deleted or not added', 'wpaiceaddon'), get_the_title($post_id)); } else { $new_data['title'] = trim(sanitize_text_field($data['cec_title'])); $new_data['url'] = $data['cec_url']; $new_data['img'] = $data['cec_mlogo']; $new_data['code'] = !empty($data['cec_code']) ? trim(sanitize_text_field($data['cec_code'])) : ''; $new_data['startDate']= !empty($data['cec_startdate']) ? ce_change_date_format($data['cec_startdate'], $data['cec_date_format']) : ''; $new_data['endDate'] = !empty($data['cec_enddate']) ? ce_change_date_format($data['cec_enddate'], $data['cec_date_format']) : ''; $new_data['domain'] = !empty($data['cec_mdomain']) ? \ContentEgg\application\helpers\TextHelper::getHostName($data['cec_mdomain']) : ''; $new_data['description'] = !empty($data['cec_description']) ? trim(wp_kses_post($data['cec_description'])) : ''; $loger_text = sprintf(__('- The coupon "%s" was added to the post "%s".', 'wpaiceaddon'), $new_data['title'], get_the_title($post_id)); } \ContentEgg\application\components\ContentManager::saveData(array($new_data), 'Coupon', $post_id); $wpai_ce_coupon->log($loger_text); } } /* * Convert format date from import data to Y/m/d */ if (!function_exists('ce_change_date_format')) { function ce_change_date_format($date, $gbf) { if (trim($date) == false) return ''; preg_match('/\d{2}\/\d{2}\/(\d{4}|\d{2})/', $date, $matches); if ($gbf == 1) { $new_date = date_create_from_format('d/m/Y', $matches[0]); if(!$new_date) return ''; } elseif($gbf == 2) { $new_date = date_create_from_format('d/m/y', $matches[0]); if(!$new_date) return ''; } else { $new_date = date_create($date); if (!$new_date) return ''; } return date_format($new_date, 'Y/m/d'); } } /* * Update CE Offers */ function ce_append_previous_data( $post_id, $xml, $is_update ) { global $wpai_ce_offer; $current_data = get_post_meta($post_id, '_cegg_data_Offer', true); $previous_data = get_transient( 'ceo_wpai_data_'. $post_id ); $new_data = !empty($previous_data) ? $previous_data : array(); $cached_timeout = apply_filters( 'ceoi_cached_timeout', 30*DAY_IN_SECONDS ); // value is days in seconds if($is_update) { if(!empty($current_data)) { $stock_out = apply_filters( 'ceoi_stock_out', __return_false() ); foreach($current_data as $item => $value){ if(isset($new_data[$item])) { if(empty($value['price'])){ if($stock_out){ $new_data[$item]['price'] = ''; $new_data[$item]['priceOld'] = ''; $new_data[$item]['stock_status'] = '-1'; }else{ unset($new_data[$item]); } }else{ $new_data[$item]['orig_url'] = $value['orig_url']; $new_data[$item]['price'] = $value['price']; $new_data[$item]['priceOld'] = $value['priceOld']; } }else{ $new_data[$item] = $value; } } } update_post_meta($post_id, '_cegg_data_Offer', $new_data); if(empty($new_data)){ delete_transient('ceo_wpai_data_'. $post_id); }else{ set_transient('ceo_wpai_data_'. $post_id, $new_data, $cached_timeout); } $wpai_ce_offer->log(sprintf(__('- The offers were <b>UPDATED</b> in the post "%s".', 'wpaiceaddon'), get_the_title($post_id))); }else{ set_transient('ceo_wpai_data_'. $post_id, $current_data, $cached_timeout); } } add_action( 'pmxi_saved_post', 'ce_append_previous_data', 10, 3 ); /* * Remove transient after putting Post to trash. */ function ce_remove_previous_data($post_id){ delete_transient('ceo_wpai_data_'. $post_id); } add_action( 'wp_trash_post', 'ce_remove_previous_data' );
[+]
..
[-] ceo-wpai-addon.php
[edit]
[-] rapid-addon.php
[edit]
[+]
languages