| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711 |
- <?php
- /**
- * Product import class
- *
- * Handles product import from CSV files
- *
- * @since 1.4.0
- * @package Studiou_WC_Product_Cat_Manage
- * @subpackage Studiou_WC_Product_Cat_Manage/includes
- */
- // If this file is called directly, abort.
- if (!defined('WPINC')) {
- die;
- }
- class Studiou_WC_Product_Manage_Product_Import {
- /**
- * @var Studiou_WC_Product_Manage_Product_DB
- */
- private $db;
- /**
- * In-request cache of trimmed source URL => attachment ID, so the same URL
- * appearing multiple times within one AJAX batch costs at most one DB lookup.
- *
- * @var array<string,int>
- */
- private static $url_cache = array();
- /**
- * Constructor
- *
- * @param Studiou_WC_Product_Manage_Product_DB $db Database instance
- */
- public function __construct($db) {
- $this->db = $db;
- }
- /**
- * Parse CSV file and store data for batch processing
- *
- * @param string $file_path Path to CSV file
- * @return array Result with total count and transient key
- */
- public function parse_csv_for_batch($file_path) {
- if (!file_exists($file_path)) {
- return array('error' => __('File not found', 'studiou-wc-product-cat-manage'));
- }
- // Open CSV file
- $handle = fopen($file_path, 'r');
- if (!$handle) {
- return array('error' => __('Could not open file', 'studiou-wc-product-cat-manage'));
- }
- // Read header row
- $header = fgetcsv($handle, 0, ',', '"');
- if (!$header) {
- fclose($handle);
- return array('error' => __('Invalid CSV format', 'studiou-wc-product-cat-manage'));
- }
- // Read all data rows
- $rows = array();
- $row_number = 1;
- while (($row = fgetcsv($handle, 0, ',', '"')) !== false) {
- $row_number++;
- // Skip empty rows
- if (empty(array_filter($row))) {
- continue;
- }
- // Combine header with row data
- $data = array_combine($header, $row);
- $rows[] = array(
- 'row_number' => $row_number,
- 'data' => $data
- );
- }
- fclose($handle);
- // Store data in transient (expires in 1 hour)
- $transient_key = 'studiou_wcpcm_import_' . uniqid();
- set_transient($transient_key, $rows, 3600);
- return array(
- 'transient_key' => $transient_key,
- 'total' => count($rows)
- );
- }
- /**
- * Process batch of products
- *
- * @param string $transient_key Transient key with CSV data
- * @param int $offset Starting offset
- * @param int $batch_size Number of items to process
- * @return array Result with statistics
- */
- public function process_batch($transient_key, $offset = 0, $batch_size = 5) {
- $rows = get_transient($transient_key);
- if (!$rows) {
- return array('error' => __('Import data not found or expired', 'studiou-wc-product-cat-manage'));
- }
- $result = array(
- 'success' => 0,
- 'failed' => 0,
- 'skipped' => 0,
- 'failed_items' => array(),
- 'messages' => array(),
- 'processed' => 0,
- 'total' => count($rows)
- );
- // Get batch of rows to process
- $batch = array_slice($rows, $offset, $batch_size);
- foreach ($batch as $item) {
- $row_number = $item['row_number'];
- $data = $item['data'];
- // Process the product
- $process_result = $this->process_product_row($data, $row_number);
- if ($process_result['status'] === 'success') {
- $result['success']++;
- // Don't add success messages to log
- } elseif ($process_result['status'] === 'skipped') {
- $result['skipped']++;
- $result['messages'][] = sprintf(
- __('Row %d: SKIPPED - %s', 'studiou-wc-product-cat-manage'),
- $row_number,
- $process_result['message']
- );
- // Add to failed items for re-processing
- $result['failed_items'][] = $data;
- } else {
- $result['failed']++;
- $result['messages'][] = sprintf(
- __('Row %d: FAILED - %s', 'studiou-wc-product-cat-manage'),
- $row_number,
- $process_result['message']
- );
- // Add to failed items
- $result['failed_items'][] = $data;
- }
- }
- $result['processed'] = $offset + count($batch);
- return $result;
- }
- /**
- * Process single product row
- *
- * @param array $data Product data
- * @param int $row_number Row number for error reporting
- * @return array Result with status and message
- */
- private function process_product_row($data, $row_number) {
- // Validate required fields
- if (!isset($data['Typ']) || empty($data['Typ'])) {
- return array(
- 'status' => 'skipped',
- 'message' => __('Missing product type', 'studiou-wc-product-cat-manage')
- );
- }
- // Rule 3: Only allow "variable" or "variation" types
- $type = trim($data['Typ']);
- if (!in_array($type, array('variable', 'variation'))) {
- return array(
- 'status' => 'skipped',
- 'message' => sprintf(
- __('Invalid product type: %s (only "variable" or "variation" allowed)', 'studiou-wc-product-cat-manage'),
- $type
- )
- );
- }
- // Get product ID
- $product_id = isset($data['ID']) ? intval($data['ID']) : 0;
- $sku = isset($data['Katalogové číslo']) ? trim($data['Katalogové číslo']) : '';
- // Rule 4: SKU must be unique
- if (empty($sku)) {
- return array(
- 'status' => 'skipped',
- 'message' => __('Missing SKU (Katalogové číslo)', 'studiou-wc-product-cat-manage')
- );
- }
- if (!$this->db->is_sku_unique($sku, $product_id)) {
- return array(
- 'status' => 'skipped',
- 'message' => sprintf(
- __('SKU "%s" already exists', 'studiou-wc-product-cat-manage'),
- $sku
- )
- );
- }
- // Rule 5: Validate image URL if provided
- $image_url = isset($data['Obrázky']) ? trim($data['Obrázky']) : '';
- if (!empty($image_url) && !$this->db->validate_image_url($image_url)) {
- return array(
- 'status' => 'skipped',
- 'message' => sprintf(
- __('Invalid image URL: %s', 'studiou-wc-product-cat-manage'),
- $image_url
- )
- );
- }
- // Process based on product type
- if ($type === 'variation') {
- return $this->process_variation($data, $product_id);
- } else {
- return $this->process_variable_product($data, $product_id);
- }
- }
- /**
- * Process variable product
- *
- * @param array $data Product data
- * @param int $product_id Product ID (0 for new product)
- * @return array Result with status and message
- */
- private function process_variable_product($data, $product_id) {
- try {
- // Create or update product
- if ($product_id == 0) {
- $product = new WC_Product_Variable();
- } else {
- $product = wc_get_product($product_id);
- if (!$product || !$product->is_type('variable')) {
- return array(
- 'status' => 'error',
- 'message' => sprintf(
- __('Product ID %d is not a variable product', 'studiou-wc-product-cat-manage'),
- $product_id
- )
- );
- }
- }
- // Set basic data
- $product->set_name(isset($data['Jméno']) ? $data['Jméno'] : '');
- $product->set_sku(isset($data['Katalogové číslo']) ? $data['Katalogové číslo'] : '');
- $product->set_short_description(isset($data['Krátký popis']) ? $data['Krátký popis'] : '');
- $product->set_description(isset($data['Popis']) ? $data['Popis'] : '');
- // Set categories
- if (isset($data['Kategorie']) && !empty($data['Kategorie'])) {
- $categories = array_map('trim', explode('|', $data['Kategorie']));
- $category_ids = array();
- error_log('STUDIOU WC IMPORT: Processing categories for product: ' . $product->get_name());
- error_log('STUDIOU WC IMPORT: Categories string from CSV: ' . $data['Kategorie']);
- foreach ($categories as $category_name) {
- if (empty($category_name)) {
- continue;
- }
- $category_id = $this->find_category_by_name($category_name);
- error_log('STUDIOU WC IMPORT: Looking for category "' . $category_name . '" - Result: ' . ($category_id ? 'FOUND ID=' . $category_id : 'NOT FOUND'));
- if ($category_id) {
- $category_ids[] = $category_id;
- }
- }
- error_log('STUDIOU WC IMPORT: Total category IDs found: ' . count($category_ids) . ' - IDs: ' . implode(',', $category_ids));
- if (!empty($category_ids)) {
- $product->set_category_ids($category_ids);
- error_log('STUDIOU WC IMPORT: Categories assigned to product via set_category_ids()');
- } else {
- error_log('STUDIOU WC IMPORT: WARNING - No valid category IDs found for: ' . $data['Kategorie']);
- }
- } else {
- error_log('STUDIOU WC IMPORT: No categories in CSV for product: ' . $product->get_name());
- }
- // Handle image
- if (isset($data['Obrázky']) && !empty($data['Obrázky'])) {
- $image_id = $this->upload_image_from_url($data['Obrázky']);
- if ($image_id) {
- $product->set_image_id($image_id);
- }
- }
- // Set reviews enabled
- $reviews_enabled = isset($data['Povolit zákaznické recenze?']) && $data['Povolit zákaznické recenze?'] === '1';
- $product->set_reviews_allowed($reviews_enabled);
- // Handle product attribute
- if (isset($data['Název 1 vlastnosti']) && !empty($data['Název 1 vlastnosti'])) {
- $attribute_name = $data['Název 1 vlastnosti'];
- $attribute_values = isset($data['Hodnota(y) 1 vlastnosti']) ? $data['Hodnota(y) 1 vlastnosti'] : '';
- $is_visible = isset($data['Vlastnost 1 viditelnost']) && $data['Vlastnost 1 viditelnost'] === '1';
- $is_variation = isset($data['Vlastnost 1 varianta']) && $data['Vlastnost 1 varianta'] === '1';
- // Create attribute taxonomy if it doesn't exist
- $this->db->create_attribute_if_not_exists($attribute_name);
- $attribute = new WC_Product_Attribute();
- $attribute->set_name(wc_attribute_taxonomy_name($attribute_name));
- $attribute->set_visible($is_visible);
- $attribute->set_variation($is_variation);
- // Set attribute options (terms)
- $values = array_map('trim', explode('|', $attribute_values));
- $attribute->set_options($values);
- $product->set_attributes(array($attribute));
- }
- // Handle minimum/maximum quantity
- if (isset($data['Minimum Quantity']) && !empty($data['Minimum Quantity'])) {
- $product->update_meta_data('_minimum_quantity', intval($data['Minimum Quantity']));
- }
- if (isset($data['Maximum Quantity']) && !empty($data['Maximum Quantity'])) {
- $product->update_meta_data('_maximum_quantity', intval($data['Maximum Quantity']));
- }
- // Save product
- $saved_id = $product->save();
- $message = $product_id == 0 ?
- sprintf(__('Created variable product: %s', 'studiou-wc-product-cat-manage'), $product->get_name()) :
- sprintf(__('Updated variable product: %s', 'studiou-wc-product-cat-manage'), $product->get_name());
- return array(
- 'status' => 'success',
- 'message' => $message
- );
- } catch (Exception $e) {
- return array(
- 'status' => 'error',
- 'message' => $e->getMessage()
- );
- }
- }
- /**
- * Process product variation
- *
- * @param array $data Product data
- * @param int $variation_id Variation ID (0 for new variation)
- * @return array Result with status and message
- */
- private function process_variation($data, $variation_id) {
- try {
- // Rule 6: Must have parent reference
- if (!isset($data['Nadřazené']) || empty($data['Nadřazené'])) {
- return array(
- 'status' => 'skipped',
- 'message' => __('Missing parent product reference (Nadřazené)', 'studiou-wc-product-cat-manage')
- );
- }
- // Rule 7: Must have regular price
- if (!isset($data['Běžná cena']) || empty($data['Běžná cena'])) {
- return array(
- 'status' => 'skipped',
- 'message' => __('Missing regular price (Běžná cena)', 'studiou-wc-product-cat-manage')
- );
- }
- // Find parent product by SKU
- $parent_sku = trim($data['Nadřazené']);
- $parent_product = $this->db->get_product_by_sku($parent_sku);
- if (!$parent_product || !$parent_product->is_type('variable')) {
- return array(
- 'status' => 'skipped',
- 'message' => sprintf(
- __('Parent product with SKU "%s" not found or not variable', 'studiou-wc-product-cat-manage'),
- $parent_sku
- )
- );
- }
- // Create or update variation
- if ($variation_id == 0) {
- $variation = new WC_Product_Variation();
- $variation->set_parent_id($parent_product->get_id());
- } else {
- $variation = wc_get_product($variation_id);
- if (!$variation || !$variation->is_type('variation')) {
- return array(
- 'status' => 'error',
- 'message' => sprintf(
- __('Product ID %d is not a variation', 'studiou-wc-product-cat-manage'),
- $variation_id
- )
- );
- }
- }
- // Set basic data
- $variation->set_name(isset($data['Jméno']) ? $data['Jméno'] : '');
- $variation->set_sku(isset($data['Katalogové číslo']) ? $data['Katalogové číslo'] : '');
- $variation->set_description(isset($data['Popis']) ? $data['Popis'] : '');
- $variation->set_regular_price($data['Běžná cena']);
- // Handle image
- if (isset($data['Obrázky']) && !empty($data['Obrázky'])) {
- $image_id = $this->upload_image_from_url($data['Obrázky']);
- if ($image_id) {
- $variation->set_image_id($image_id);
- }
- }
- // Set variation attributes
- if (isset($data['Název 1 vlastnosti']) && !empty($data['Název 1 vlastnosti']) &&
- isset($data['Hodnota(y) 1 vlastnosti']) && !empty($data['Hodnota(y) 1 vlastnosti'])) {
- $attribute_name = wc_attribute_taxonomy_name($data['Název 1 vlastnosti']);
- $attribute_value = $data['Hodnota(y) 1 vlastnosti'];
- $variation->set_attributes(array(
- $attribute_name => $attribute_value
- ));
- }
- // Handle minimum/maximum quantity
- if (isset($data['Minimum Quantity']) && !empty($data['Minimum Quantity'])) {
- $variation->update_meta_data('_minimum_quantity', intval($data['Minimum Quantity']));
- }
- if (isset($data['Maximum Quantity']) && !empty($data['Maximum Quantity'])) {
- $variation->update_meta_data('_maximum_quantity', intval($data['Maximum Quantity']));
- }
- // Save variation
- $saved_id = $variation->save();
- $message = $variation_id == 0 ?
- sprintf(__('Created variation: %s', 'studiou-wc-product-cat-manage'), $variation->get_name()) :
- sprintf(__('Updated variation: %s', 'studiou-wc-product-cat-manage'), $variation->get_name());
- return array(
- 'status' => 'success',
- 'message' => $message
- );
- } catch (Exception $e) {
- return array(
- 'status' => 'error',
- 'message' => $e->getMessage()
- );
- }
- }
- /**
- * Find an attachment previously imported from this exact source URL.
- *
- * Uses get_posts (not a raw $wpdb query) so a row whose attachment post was
- * deleted but whose meta was somehow orphaned can't resolve to a missing post.
- * Orders by ID ascending so the earliest (canonical) attachment wins
- * deterministically if more than one ever carries the same source URL.
- *
- * @param string $url Trimmed source URL.
- * @return int Attachment ID, or 0 if none.
- */
- private function find_attachment_by_source_url($url) {
- $ids = get_posts(array(
- 'post_type' => 'attachment',
- 'post_status' => 'inherit',
- 'posts_per_page' => 1,
- 'orderby' => 'ID',
- 'order' => 'ASC',
- 'fields' => 'ids',
- 'no_found_rows' => true,
- 'update_post_meta_cache' => false,
- 'update_post_term_cache' => false,
- 'meta_query' => array(
- array(
- 'key' => '_studiou_wcpcm_source_url',
- 'value' => $url,
- 'compare' => '=',
- ),
- ),
- ));
- return !empty($ids) ? (int) $ids[0] : 0;
- }
- /**
- * Upload an image from a URL, deduplicating by source URL.
- *
- * A given source URL is downloaded at most once: an in-request static cache
- * absorbs repeats within a batch, and a `_studiou_wcpcm_source_url` postmeta
- * lookup reuses attachments across batches and across imports.
- *
- * @param string $url Image URL (raw value from the Obrázky column).
- * @return int|null Attachment ID, or null on empty input / download failure.
- */
- private function upload_image_from_url($url) {
- // Normalize the key. process_product_row() validates a *trimmed* URL but
- // the callers pass the raw cell, so trim here to keep the cache key, the
- // DB lookup, the download, and the stored postmeta all identical to the
- // value that was validated (and to collapse whitespace-only variants).
- $url = is_string($url) ? trim($url) : '';
- if ($url === '') {
- return null;
- }
- // Layer 2 — in-request static cache.
- if (isset(self::$url_cache[$url])) {
- if (defined('WP_DEBUG') && WP_DEBUG) {
- error_log('STUDIOU WC IMPORT: image cache HIT (request) ' . $url . ' -> ' . self::$url_cache[$url]);
- }
- return self::$url_cache[$url];
- }
- // Layer 1 — persistent postmeta lookup (across batches and re-imports).
- $existing = $this->find_attachment_by_source_url($url);
- if ($existing) {
- self::$url_cache[$url] = $existing;
- if (defined('WP_DEBUG') && WP_DEBUG) {
- error_log('STUDIOU WC IMPORT: image cache HIT (db) ' . $url . ' -> ' . $existing);
- }
- return $existing;
- }
- // Layer 0 — fresh sideload.
- require_once(ABSPATH . 'wp-admin/includes/media.php');
- require_once(ABSPATH . 'wp-admin/includes/file.php');
- require_once(ABSPATH . 'wp-admin/includes/image.php');
- // Suppress intermediate sizes for import speed. Use the stable
- // '__return_empty_array' callable (not a fresh closure) so remove_filter()
- // can actually match it, and detach it in finally so it can never leak
- // into later media operations in this request.
- add_filter('intermediate_image_sizes_advanced', '__return_empty_array');
- try {
- // download_url()'s second arg sets the request timeout (30s); no
- // http_request_timeout filter is needed.
- $tmp = download_url($url, 30);
- if (is_wp_error($tmp)) {
- error_log('STUDIOU WC IMPORT: image download failed for ' . $url . ' - ' . $tmp->get_error_message());
- return null;
- }
- // Derive a clean on-disk filename. parse_url() strips any query string
- // (img.jpg?v=2 -> img.jpg) so wp_unique_filename() doesn't fold the
- // query into the basename. Null-safe: parse_url() may return null/false
- // and basename(null) is deprecated on PHP 8.1+ (we require 8.2).
- $path = parse_url($url, PHP_URL_PATH);
- $name = (is_string($path) && $path !== '') ? basename($path) : '';
- if ($name === '') {
- $name = 'image-' . md5($url) . '.jpg';
- }
- $file_array = array(
- 'name' => $name,
- 'tmp_name' => $tmp,
- );
- $id = media_handle_sideload($file_array, 0);
- if (is_wp_error($id)) {
- @unlink($tmp);
- error_log('STUDIOU WC IMPORT: image sideload failed for ' . $url . ' - ' . $id->get_error_message());
- return null;
- }
- // Tag the attachment so future rows / batches / imports dedup on it.
- update_post_meta($id, '_studiou_wcpcm_source_url', $url);
- self::$url_cache[$url] = (int) $id;
- if (defined('WP_DEBUG') && WP_DEBUG) {
- error_log('STUDIOU WC IMPORT: image sideloaded ' . $url . ' -> ' . $id);
- }
- return (int) $id;
- } catch (Exception $e) {
- error_log('STUDIOU WC IMPORT: image upload exception for ' . $url . ' - ' . $e->getMessage());
- return null;
- } finally {
- remove_filter('intermediate_image_sizes_advanced', '__return_empty_array');
- }
- }
- /**
- * Find category by name (simple lookup, categories have unique names)
- *
- * @param string $category_name Category name
- * @return int|null Category ID or null if not found
- */
- private function find_category_by_name($category_name) {
- // Trim and normalize the category name
- $category_name = trim($category_name);
- if (empty($category_name)) {
- return null;
- }
- // Simple name lookup only (no hierarchy detection)
- // Categories have unique names throughout the system
- error_log('STUDIOU WC IMPORT: find_category_by_name() called for: "' . $category_name . '"');
- // Method 1: Exact name match
- $term = get_term_by('name', $category_name, 'product_cat');
- if ($term) {
- error_log('STUDIOU WC IMPORT: Found by exact name match - ID: ' . $term->term_id);
- return $term->term_id;
- }
- // Method 2: Try by slug
- $slug = sanitize_title($category_name);
- error_log('STUDIOU WC IMPORT: Exact name failed, trying slug: "' . $slug . '"');
- $term = get_term_by('slug', $slug, 'product_cat');
- if ($term) {
- error_log('STUDIOU WC IMPORT: Found by slug match - ID: ' . $term->term_id);
- return $term->term_id;
- }
- // Method 3: Search case-insensitively through all categories
- $all_terms = get_terms(array(
- 'taxonomy' => 'product_cat',
- 'hide_empty' => false
- ));
- error_log('STUDIOU WC IMPORT: Slug failed, searching ' . count($all_terms) . ' categories case-insensitively');
- foreach ($all_terms as $t) {
- if (strcasecmp($t->name, $category_name) === 0) {
- error_log('STUDIOU WC IMPORT: Found by case-insensitive match - ID: ' . $t->term_id . ', name: "' . $t->name . '"');
- return $t->term_id;
- }
- }
- // Not found - try to create it
- error_log('STUDIOU WC IMPORT: Category NOT FOUND: "' . $category_name . '" - Attempting to create it');
- $new_term = wp_insert_term(
- $category_name,
- 'product_cat',
- array(
- 'slug' => $slug
- )
- );
- if (is_wp_error($new_term)) {
- error_log('STUDIOU WC IMPORT: Failed to create category "' . $category_name . '": ' . $new_term->get_error_message());
- error_log('STUDIOU WC IMPORT: Total available categories: ' . count($all_terms));
- // Show first 20 categories for debugging
- $sample_cats = array_slice($all_terms, 0, 20);
- foreach ($sample_cats as $cat) {
- error_log('STUDIOU WC IMPORT: Available: "' . $cat->name . '" (ID: ' . $cat->term_id . ', slug: ' . $cat->slug . ')');
- }
- return null;
- } else {
- $term_id = $new_term['term_id'];
- error_log('STUDIOU WC IMPORT: Successfully created category "' . $category_name . '" with ID: ' . $term_id);
- return $term_id;
- }
- }
- /**
- * Generate CSV with failed items
- *
- * @param array $failed_items Array of failed product data
- * @return string CSV content
- */
- public function generate_failed_csv($failed_items) {
- if (empty($failed_items)) {
- return '';
- }
- // Define CSV header
- $header = array(
- 'ID', 'Typ', 'Katalogové číslo', 'Jméno', 'Nadřazené', 'Krátký popis', 'Popis',
- 'Název 1 vlastnosti', 'Hodnota(y) 1 vlastnosti', 'Kategorie', 'Obrázky', 'Běžná cena',
- 'Vlastnost 1 viditelnost', 'Vlastnost 1 globální', 'Vlastnost 1 varianta',
- 'Povolit zákaznické recenze?', 'Minimum Quantity', 'Maximum Quantity'
- );
- // Start CSV output
- $csv = '';
- $csv .= '"' . implode('","', $header) . '"' . "\n";
- // Add failed items
- foreach ($failed_items as $item) {
- $row = array();
- foreach ($header as $column) {
- $value = isset($item[$column]) ? $item[$column] : '';
- $row[] = '"' . str_replace('"', '""', $value) . '"';
- }
- $csv .= implode(',', $row) . "\n";
- }
- return $csv;
- }
- }
|