Example #1
0
        }
        if (!empty($store->store_xml_feed) && stristr($store->store_xml_feed, 'http') !== false) {
            $import_data = compare_store_parse_and_import($store->store_xml_feed, $store_id, $store->store_parser);
            if (is_wp_error($import_data)) {
                echo '<p><strong>' . __('Sorry, there has been an error.', 'compare') . '</strong><br/>';
                echo esc_html($import_data->get_error_message()) . '</p>';
                return false;
            }
        } else {
            $message = __('Store ', 'compare') . '<strong>' . $store->store_name . '</strong>' . __(' has no feed associated with it.', 'compare');
            compare_display_import_info($message);
        }
    } else {
        /*store has expired delete its feeds*/
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}feed_list WHERE store_id = %d", $store_id));
        /* mark store as not paid and set available for update */
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}stores SET store_status = '0', store_update = %s WHERE store_id = %d", $hash, $store_id));
        /* inform user that store has expired, feeds deleted and add some links where he can prolongate this */
        $link = add_query_arg(array('hash' => $hash), compare_get_permalink_by_tpl('page-tpl_register_store'));
        $message = __('Your store has been expired and feed associated with your store have been deleted.', 'compare') . "<br/><br/>";
        $message .= __('In order to activate your store again visit link bellow and select your new package.', 'compare') . "<br/><br/>";
        $message .= '<a href="' . esc_attr($link) . '" target="_blank">' . $link . '</a>';
        compare_inform_store($message, $store->store_contact_email, __('Store Has Expired - Feeds Removed', 'compare'));
        compare_display_import_info(__('Store has expired, owner has been informed.', 'compare'));
    }
} else {
    $message = __('Store ', 'compare') . '<strong>' . $store->store_name . '</strong>' . __(' is disabled since it is not paid for.', 'compare');
    compare_display_import_info($message);
}
compare_display_import_info('<br/>***** ' . __('STORE FEED IMPORT PROCESS COMPLETED', 'compare') . ' *****<br/>');
Example #2
0
function compare_store_parse_and_import($link, $store_id, $store_custom_parser)
{
    $internal_errors = libxml_use_internal_errors(true);
    if (stristr($link, '.csv') !== false) {
        $feed_content = compare_csv_to_xml($link);
    } else {
        WP_Filesystem();
        global $wp_filesystem;
        $feed_content = $wp_filesystem->get_contents($link);
    }
    $dom = new DOMDocument();
    $old_value = null;
    if (function_exists('libxml_disable_entity_loader')) {
        $old_value = libxml_disable_entity_loader(true);
    }
    $success = $dom->loadXML($feed_content);
    if (!is_null($old_value)) {
        libxml_disable_entity_loader($old_value);
    }
    if (!$success || isset($dom->doctype)) {
        return new WP_Error('SimpleXML_parse_error', __('There was an error when reading this WXR file', 'compare'), libxml_get_errors());
    }
    $xml = simplexml_import_dom($dom);
    unset($dom);
    // halt if loading produces an error
    if (!$xml) {
        return new WP_Error('SimpleXML_parse_error', __('There was an error when reading this WXR file', 'compare'), libxml_get_errors());
    }
    set_time_limit(0);
    if (empty($store_custom_parser)) {
        foreach ($xml->xpath('/products/product') as $product) {
            compare_display_import_info('------------------------------------------------------------------------');
            compare_display_import_info(__('Importing feed for product: <strong>', 'compare') . $product->name . '</strong>');
            /* main post attributes */
            $name = !empty($product->name) ? (string) $product->name : '';
            $description = !empty($product->description) ? (string) $product->description : '';
            $categories = !empty($product->categories) ? (string) $product->categories : '';
            $tags = !empty($product->tags) ? (string) $product->tags : '';
            $brand = !empty($product->brand) ? (string) $product->brand : '';
            /* featured image */
            $image = !empty($product->image) ? (string) $product->image : '';
            /* meta values */
            $pid = !empty($product->pid) ? (string) $product->pid : '';
            $short_desc = !empty($product->short_desc) ? (string) $product->short_desc : '';
            /* feed values */
            $url = !empty($product->url) ? (string) $product->url : '';
            $price = !empty($product->price) ? (string) $product->price : '';
            $shipping = !empty($product->shipping) ? (string) $product->shipping : '';
            $shipping_comment = !empty($product->shipping_comment) ? (string) $product->shipping_comment : '';
            compare_core_import($name, $description, $categories, $tags, $brand, $image, $pid, $short_desc, $url, $price, $shipping, $shipping_comment, $store_id);
        }
    } else {
        $parser_product_root = get_post_meta($store_custom_parser, 'parser_product_root', true);
        $parser_product_name = get_post_meta($store_custom_parser, 'parser_product_name', true);
        $parser_product_cats = get_post_meta($store_custom_parser, 'parser_product_cats', true);
        $parser_cats_separator = get_post_meta($store_custom_parser, 'parser_cats_separator', true);
        $parser_product_tags = get_post_meta($store_custom_parser, 'parser_product_tags', true);
        $parser_tags_separator = get_post_meta($store_custom_parser, 'parser_tags_separator', true);
        $parser_product_brand = get_post_meta($store_custom_parser, 'parser_product_brand', true);
        $parser_product_price = get_post_meta($store_custom_parser, 'parser_product_price', true);
        $parser_product_url = get_post_meta($store_custom_parser, 'parser_product_url', true);
        $parser_product_id = get_post_meta($store_custom_parser, 'parser_product_id', true);
        $parser_desc = get_post_meta($store_custom_parser, 'parser_desc', true);
        $parser_short_desc = get_post_meta($store_custom_parser, 'parser_short_desc', true);
        $parser_shipping = get_post_meta($store_custom_parser, 'parser_shipping', true);
        $parser_shipping_comment = get_post_meta($store_custom_parser, 'parser_shipping_comment', true);
        $parser_product_image = get_post_meta($store_custom_parser, 'parser_product_image', true);
        foreach ($xml->xpath('/' . $parser_product_root) as $product) {
            compare_display_import_info('------------------------------------------------------------------------');
            compare_display_import_info(__('Importing feed for product: <strong>', 'compare') . $product->name . '</strong>');
            /* main post attributes */
            $name = $product->name;
            $description = $product->xpath('./' . $parser_desc);
            $description = !empty($description) ? (string) $description[0] : '';
            $categories = $product->xpath('./' . $parser_product_cats);
            $categories = !empty($categories) ? (string) $categories[0] : '';
            $name = $product->xpath('./' . $parser_product_name);
            $name = !empty($name) ? (string) $name[0] : '';
            $tags = $product->xpath('./' . $parser_product_tags);
            $tags = !empty($tags) ? (string) $tags[0] : '';
            $brand = $product->xpath('./' . $parser_product_brand);
            $brand = !empty($brand) ? (string) $brand[0] : '';
            /* featured image */
            $image = $product->xpath('./' . $parser_product_image);
            $image = !empty($image) ? (string) $image[0] : '';
            /* meta values */
            $pid = $product->xpath('./' . $parser_product_id);
            $pid = !empty($pid) ? (string) $pid[0] : '';
            $short_desc = $product->xpath('./' . $parser_short_desc);
            $short_desc = !empty($short_desc) ? (string) $short_desc[0] : '';
            /* feed values */
            $url = $product->xpath('./' . $parser_product_url);
            $url = !empty($url) ? (string) $url[0] : '';
            $price = $product->xpath('./' . $parser_product_price);
            $price = !empty($price) ? (string) $price[0] : '';
            $shipping = $product->xpath('./' . $parser_shipping);
            $shipping = !empty($shipping) ? (string) $shipping[0] : '';
            $shipping_comment = $product->xpath('./' . $parser_shipping_comment);
            $shipping_comment = !empty($shipping_comment) ? (string) $shipping_comment[0] : '';
            compare_core_import($name, $description, $categories, $tags, $brand, $image, $pid, $short_desc, $url, $price, $shipping, $shipping_comment, $store_id, $parser_cats_separator, $parser_tags_separator);
        }
    }
}