コード例 #1
0
        /* Ping Google to update sitemaps
           http://www.google.com/support/webmasters/bin/answer.py?answer=183669
           */
        cw_flush('Sending update request: ' . 'www.google.com' . '/webmasters/tools/ping' . '?sitemap=' . urlencode($http_location . '/' . $_filename));
        cw_flush("\n");
        if (!defined('IS_CRON')) {
            echo '<br />';
        }
        cw_load('http');
        list($header, $body) = cw_http_get_request('www.google.com', '/webmasters/tools/ping', 'sitemap=' . urlencode($http_location . '/' . $_filename));
        $msg = "\nGoogle response:\n" . $body;
        if (!defined('IS_CRON')) {
            $msg = '<br /><br />' . $msg;
        }
        echo $msg;
        cw_add_top_message($msg);
    }
    $success_msg = "Sitemap XML <a href='{$http_location}/{$_filename}'>file</a> updated";
    cw_call('cw_system_messages_add', array('sitemap_xml', $success_msg, SYSTEM_MESSAGE_COMMON, SYSTEM_MESSAGE_INFO));
} else {
    $msg = cw_get_langvar_by_name('msg_err_file_permission_denied', null, false, true);
    echo $msg;
    echo "<br />File: {$_filename}<br />";
    cw_add_top_message($msg, 'E');
    $warn_msg = "Sitemap XML. <acronym title='{$_filename}'>" . cw_get_langvar_by_name('msg_err_file_permission_denied') . '</acronym>';
    cw_call('cw_system_messages_add', array('sitemap_xml', $warn_msg, SYSTEM_MESSAGE_COMMON, SYSTEM_MESSAGE_WARNING));
    cw_call('cw_system_messages_show', array('sitemap_xml'));
}
if (!defined('IS_CRON')) {
    cw_flush("\n <a href='index.php?target=sitemap_xml'>Continue</a>");
}
コード例 #2
0
 function dumpTableContent($table, $schema, $fd)
 {
     global $sql_backup_rows;
     if ($fd === false) {
         print "{$schema}\n\n";
     } else {
         fwrite($fd, "{$schema}\n\n");
         echo cw_get_langvar_by_name("lbl_dumping_table_n", array("table" => $table), false, true) . "<br />\n";
     }
     $rows_cnt = 0;
     $current_row = 0;
     $count = cw_query_first_cell("SELECT count(*) FROM " . $table);
     if ($count < 1) {
         return;
     }
     for ($pos = 0; $count > 0; $count -= $sql_backup_rows, $pos += $sql_backup_rows) {
         $local_query = "SELECT * FROM {$table} LIMIT {$pos},{$sql_backup_rows}";
         $result = db_query($local_query);
         if ($result != FALSE) {
             $fields_cnt = mysql_num_fields($result);
             $rows_cnt = mysql_num_rows($result);
             // Checks whether the field is an integer or not
             for ($j = 0; $j < $fields_cnt; $j++) {
                 $field_set[$j] = mysql_field_name($result, $j);
                 $type = mysql_field_type($result, $j);
                 $field_num[$j] = ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' || $type == 'bigint' || $type == 'timestamp') && (!defined("OVERRIDE_NUM_FIELD") || !constant("OVERRIDE_NUM_FIELD"));
             }
             // Sets the scheme
             $schema_insert = "INSERT INTO {$table} VALUES (";
             $search = array("", "\n", "\r", "");
             //\x08\\x09, not required
             $replace = array('0', '\\n', '\\r', '\\Z');
             $current_row = 0;
             while ($row = mysql_fetch_row($result)) {
                 $current_row++;
                 for ($j = 0; $j < $fields_cnt; $j++) {
                     if (!isset($row[$j])) {
                         $values[] = 'NULL';
                     } else {
                         if ($row[$j] == '0' || $row[$j] != '') {
                             // a number
                             if ($field_num[$j]) {
                                 $values[] = $row[$j];
                             } else {
                                 $values[] = "'" . str_replace($search, $replace, addslashes($row[$j])) . "'";
                             }
                         } else {
                             $values[] = "''";
                         }
                     }
                     // end if
                 }
                 // end for
                 // Extended inserts case
                 $insert_line = $schema_insert . implode(', ', $values) . ')';
                 unset($values);
                 // Send the line
                 if ($fd === false) {
                     print $insert_line . ";\n";
                     flush();
                 } else {
                     fwrite($fd, $insert_line . ";\n");
                     fflush($fd);
                 }
                 // loic1: send a fake header to bypass browser timeout if data
                 //        are bufferized
             }
             // end while
         }
         // end if ($result != FALSE)
         db_free_result($result);
         if ($fd !== false) {
             cw_flush(". ");
         }
     }
     // for
     if ($fd === false) {
         print "\n";
     } else {
         fwrite($fd, "\n");
         echo "<br />";
     }
 }
コード例 #3
0
function cw_product_build_flat($params, $return)
{
    extract($params);
    global $tables, $addons;
    $where = "";
    if ($product_id) {
        if (!is_array($product_id)) {
            $product_id = array($product_id);
        }
        $where = "product_id in ('" . implode("', '", $product_id) . "')";
        db_query("delete from {$tables['products_flat']} where {$where}");
    } else {
        db_query("delete from {$tables['products_flat']}");
    }
    $fields = $from_tbls = $query_joins = $where = $groupbys = $having = $orderbys = array();
    $from_tbls[] = 'products';
    $fields[] = "{$tables['products']}.product_id";
    $where[] = $tables['products'] . '.' . $where;
    # kornev, get the query from the addons
    if ($return) {
        foreach ($return as $saname => $sadata) {
            if (isset(${$saname}) && is_array(${$saname}) && empty(${$saname})) {
                ${$saname} = $sadata;
            }
        }
    }
    # kornev, there are nothing to do if the fields are empty (by default)
    if (count($fields) == 1) {
        return;
    }
    $groupbys[] = "{$tables['products']}.product_id";
    # kornev, generate it;
    $search_query = cw_db_generate_query($fields, $from_tbls, $query_joins, $where, $groupbys, $having, $orderbys);
    if ($tick > 0) {
        cw_display_service_header('lbl_rebuild_products_flat');
    }
    $sd = db_query($search_query);
    $updated = 0;
    if ($sd) {
        while ($row = db_fetch_array($sd)) {
            cw_array2insert('products_flat', cw_addslashes($row), true);
            $updated++;
            if ($tick > 0 && $updated % $tick == 0) {
                cw_flush('.');
            }
            if ($tick > 0 && $updated / $tick % 100 == 0) {
                cw_flush('<br/>');
            }
        }
    }
    db_free_result($sd);
    return $updated;
}
コード例 #4
0
function cw_display_service_footer()
{
    global $smarty;
    if (defined("SERVICE_HEADER")) {
        cw_display("main/service_footer.tpl", $smarty);
        cw_flush();
    }
}
コード例 #5
0
     $p_id = -1;
     $_c_id = $c_id;
     while ($p_id != 0 && $safety_cnt < 15) {
         $c_data = cw_query_first("SELECT parent_id, category_id, category  FROM tmp_cw_categories WHERE category_id = '{$c_id}'");
         $p_id = $c_data['parent_id'];
         $c_id = $c_data['category_id'];
         $cat_name = $c_data['category'];
         $cat_names[] = $cat_name;
         $c_id = $p_id;
         $safety_cnt++;
     }
     $cat_names = array_reverse($cat_names);
     $cat_path = implode("/", $cat_names);
     cw_csvxc_logged_query("UPDATE tmp_cw_categories SET category_path='" . addslashes($cat_path) . "' WHERE category_id='{$_c_id}'", ". ");
 }
 cw_flush("<br>");
 $cat_fields_arr = cw_csvxc_get_table_fields('cw_categories');
 $cat_l_join_flds_arr = cw_csvxc_get_fields_combination('cw_categories', $cat_fields_arr, 'tmp_load_CATEGORIES');
 $cat_fields_arr[] = 'tmp_cw_categories.`category_path`';
 $cat_l_join_flds_arr[] = 'tmp_load_CATEGORIES.`CATEGORY`';
 $cat_fields_arr[] = 'tmp_cw_categories.`ref_tlc_id`';
 $cat_l_join_flds_arr[] = 'tmp_load_CATEGORIES.`id_categories`';
 cw_csvxc_logged_query("REPLACE INTO tmp_cw_categories (" . implode(", ", $cat_fields_arr) . ") SELECT " . implode(", ", $cat_l_join_flds_arr) . " FROM tmp_load_CATEGORIES LEFT JOIN cw_categories ON tmp_load_CATEGORIES.CATEGORYID=cw_categories.category_id WHERE tmp_load_CATEGORIES.ref_category_id != 0 AND tmp_load_CATEGORIES.CATEGORY != ''");
 //routines for new categories insert
 list($ins_into_fields, $select_fields) = cw_csvxc_get_columns4insert('cw_categories', 'tmp_load_CATEGORIES', 'tmp_cw_categories');
 $ins_into_fields[] = 'tmp_cw_categories.`category_path`';
 $select_fields[] = 'tmp_load_CATEGORIES.`CATEGORY`';
 $ins_into_fields[] = 'tmp_cw_categories.`ref_tlc_id`';
 $select_fields[] = 'tmp_load_CATEGORIES.`id_categories`';
 cw_csvxc_logged_query("INSERT INTO tmp_cw_categories (" . implode(", ", $ins_into_fields) . ") SELECT " . implode(", ", $select_fields) . " FROM tmp_load_CATEGORIES WHERE ref_category_id=0");
 //add lvl field to tmp_cw_categories
コード例 #6
0
<?php

# kornev, TOFIX
if (!isset($tables['cached_images'])) {
    $tables['cached_images'] = 'cw_xcm_cached_images';
}
$cache_files = cw_query("SELECT * FROM {$tables['cached_images']}");
if (empty($cache_files) || !is_array($cache_files)) {
    cw_header_location("index.php?target=settings&js_tab=Smarty_plugins");
}
cw_display_service_header();
cw_flush('Removing cached images: ...');
$cnt = 0;
if (count($cache_files)) {
    foreach ($cache_files as $file) {
        @unlink($file['image_path']);
        $cnt++;
        if ($cnt > 5) {
            cw_flush('.');
        }
    }
}
db_query("TRUNCATE TABLE {$tables['cached_images']}");
cw_flush('<br />cached images are deleted.');
cw_header_location("index.php?target=settings&js_tab=Smarty_plugins");
exit;
コード例 #7
0
     $where[] = "ca.country in ('" . implode("', '", $countries) . "')";
 }
 if ($config['news']['news_emails_per_pass'] > 0) {
     $news_send_data =& cw_session_register('news_send_data');
     if ($action == 'send') {
         $count_query = cw_db_generate_query(array('count(*)'), $from_tbls, $query_joins, $where, $groupbys, $having, array());
         $subscribers_count = cw_query_first_cell($count_query);
         if (!$subscribers_count) {
             return;
         }
         $news_send_data[$messageid] = array('count' => $subscribers_count, 'lastpos' => 0);
         echo cw_get_langvar_by_name("lbl_news_sending_messages", array("count" => $news_send_data[$messageid]['count']), false, true);
     } else {
         echo cw_get_langvar_by_name("lbl_news_continue_sending_messages", array("last" => $news_send_data[$messageid]['lastpos'], "count" => $news_send_data[$messageid]['count']), false, true);
     }
     cw_flush();
     $limit = sprintf(" LIMIT %d,%d", $news_send_data[$messageid]['lastpos'], $config['news']['news_emails_per_pass']);
 }
 $user_search_query = cw_db_generate_query($fields, $from_tbls, $query_joins, $where, $groupbys, $having, $orderbys);
 $tmp = cw_query($user_search_query . $limit);
 if (is_array($tmp)) {
     foreach ($tmp as $v) {
         if (!empty($v['email'])) {
             $recipients[] = $v['email'];
         }
     }
 }
 $message = cw_query_first("SELECT * FROM {$tables['newsletter']} WHERE news_id='{$messageid}'");
 if (empty($news_send_data[$messageid]['lastpos'])) {
     # kornev, simple subscribers on the first step
     $tmp = cw_query("SELECT email FROM {$tables['newslist_subscription']} WHERE list_id='{$list_id}' ORDER BY email");
コード例 #8
0
function cw_recalc_subcat_count($category_id = 0, $tick = 0)
{
    global $tables, $config;
    if ($tick > 0) {
        cw_display_service_header('lbl_recalc_subcat_count') . '<br/>';
    } elseif ($tick > 0 && $start % $tick == 0) {
        cw_flush('.');
    }
    if (!$category_id) {
        $where = '';
    } elseif (is_array($category_id)) {
        if (is_array(current($category_id))) {
            foreach ($categoryid as $k => $v) {
                $categoryid[$k] = $v['category_id'];
            }
        }
        $where = "where category_id in ('" . implode("', '", $category_id) . "')";
    } else {
        $where = "where parent_id='{$category_id}' or category_id='{$category_id}'";
    }
    $subcategories = cw_query_column("select category_id from {$tables['categories']} {$where}");
    db_query("delete from {$tables['categories_subcount']} where category_id in ('" . implode("', '", $subcategories) . "')");
    $subcategories_list = implode("','", $subcategories);
    // Calculates memberships subcategories/products' counts as '0-membership' count plus only unique subcategories/products
    // for that membership (vs 0-mbrs) excluding all common with '0-membership' scats/prods
    // Status 1 -- only enabled scats/prods
    // Status 0 -- All scats/prods
    $counts = "select cm.category_id, cm.membership_id,\n\t\tcount(DISTINCT if(ifnull(cms.membership_id,-1)=-1,NULL,sc.category_id)) as subcategory_count,\n\t\tcount(DISTINCT if(ifnull(cms.membership_id,-1)=-1,NULL,if(ifnull(sc.status,0)=0,NULL,sc.category_id))) as subcategory_count_avail,\n\t\tcount(DISTINCT if(ifnull(pm.membership_id,-1)=-1,NULL,p.product_id)) as product_count,\n\t\tcount(DISTINCT if(ifnull(pm.membership_id,-1)=-1,NULL,if(ifnull(pr.status,0)=0,NULL,p.product_id))) as product_count_avail\n\t\tfrom {$tables['categories_memberships']} cm\n\t\tleft join {$tables['categories']} sc on cm.category_id = sc.parent_id\n\t\tleft join {$tables['categories_memberships']} cms on sc.category_id=cms.category_id and cms.membership_id in (0,cm.membership_id)\n\t\tleft Join  {$tables['products_categories']} p on p.category_id=cm.category_id\n\t\tleft Join  {$tables['products']} pr on p.product_id=pr.product_id\n\t\tleft Join  {$tables['products_memberships']} pm on pm.product_id=p.product_id and pm.membership_id in (0,cm.membership_id)\n\t\twhere cm.category_id in ('{$subcategories_list}')\n\t\tand cm.membership_id is not null and cm.category_id is not null\n\t\tgroup by cm.category_id, cm.membership_id";
    $counts = cw_query_hash($counts, array('category_id', 'membership_id'), false);
    $i = 0;
    if (!empty($counts)) {
        foreach ($counts as $category_id => $data) {
            foreach ($data as $membership_id => $cnts) {
                extract($cnts);
                $status = 0;
                $arr = compact('category_id', 'membership_id', 'status', 'subcategory_count', 'product_count');
                cw_array2insert('categories_subcount', $arr, true);
                $status = 1;
                $subcategory_count = $subcategory_count_avail;
                $product_count = $product_count_avail;
                $arr = compact('category_id', 'membership_id', 'status', 'subcategory_count', 'product_count');
                cw_array2insert('categories_subcount', $arr, true);
                if ($tick > 0 && $i % $tick == 0) {
                    cw_flush(". ");
                }
                $i++;
            }
        }
    }
    # kornev, used only in the shop - so only the shop amount is calculated
    # general products count
    cw_load('product');
    $count_products = cw_query_first("select group_concat(distinct membership_id) as ind from {$tables['products_memberships']}");
    $count_products = array_fill_keys(explode(',', $count_products['ind']), 0);
    db_query("delete from {$tables['categories_subcount']} where category_id = 0");
    if (is_array($count_products)) {
        foreach ($count_products as $k => $v) {
            $product_count = intval(cw_func_call('cw_product_search', array('data' => array('count' => 1), 'user_info' => array('membership_id' => $k), 'current_area' => 'C')));
            cw_array2insert('categories_subcount', array('category_id' => 0, 'membership_id' => $k, 'status' => 2, 'product_count' => $product_count), true);
        }
    }
}
コード例 #9
0
function cw_rebuild_variants($product_id, $force_rebuild = false, $tick = 1)
{
    global $tables;
    if (!$force_rebuild) {
        # Check variant's matrix
        $options_count = cw_query_first_cell("SELECT COUNT(*) FROM {$tables['product_options']}, {$tables['product_options_values']} WHERE {$tables['product_options']}.product_option_id = {$tables['product_options_values']}.product_option_id AND {$tables['product_options']}.product_id = '{$product_id}' AND {$tables['product_options']}.type = '' AND {$tables['product_options']}.avail = 1 AND {$tables['product_options_values']}.avail = 1");
        $variants_count = count(cw_query_column("SELECT COUNT(*) FROM {$tables['product_variant_items']}, {$tables['product_variants']} WHERE {$tables['product_variants']}.product_id = '{$product_id}' AND {$tables['product_variants']}.variant_id = {$tables['product_variant_items']}.variant_id GROUP BY {$tables['product_variant_items']}.option_id"));
        if ($options_count == $variants_count && $options_count > 0) {
            return true;
        }
    }
    if ($tick > 0) {
        cw_display_service_header("lbl_rebuild_variants");
    }
    $ids = cw_query_column("SELECT variant_id FROM {$tables['product_variants']} WHERE product_id = '{$product_id}'");
    if (!empty($ids)) {
        # Save old data
        $vars = cw_query_hash("SELECT pv.*, pwa.avail  FROM {$tables['product_variants']} as pv LEFT JOIN {$tables['products_warehouses_amount']} as pwa ON pv.variant_id = pwa.variant_id WHERE pv.product_id = '{$product_id}'", "variant_id", false);
        $prices = db_query("select pp.* from {$tables['products_prices']} as pp where pp.product_id = '{$product_id}' AND variant_id != 0");
        if ($prices) {
            while ($v = db_fetch_array($prices)) {
                if (!isset($vars[$v['variant_id']])) {
                    continue;
                }
                $key = $v['quantity'] . "|" . $v['membership_id'];
                if (!isset($vars[$v['variant_id']]['prices'])) {
                    $vars[$v['variant_id']]['prices'] = array();
                }
                if (!isset($vars[$v['variant_id']]['prices'][$key]) || $vars[$v['variant_id']]['prices'][$key]['price'] > $v['price']) {
                    $vars[$v['variant_id']]['prices'][$key] = $v;
                }
            }
            db_free_result($prices);
        }
        unset($prices);
        $items = cw_query_hash("SELECT {$tables['product_variant_items']}.*, {$tables['product_options_values']}.product_option_id FROM {$tables['product_variant_items']}, {$tables['product_options_values']}, {$tables['product_variants']} WHERE {$tables['product_variant_items']}.option_id = {$tables['product_options_values']}.option_id AND {$tables['product_variant_items']}.variant_id = {$tables['product_variants']}.variant_id AND {$tables['product_variants']}.product_id = '{$product_id}'", array('product_option_id', "option_id"), true, true);
        # Delete old variants
        /*
                $tmp = cw_query_first("SELECT MIN(avail) as avail, MIN(weight) as weight FROM $tables[product_variants] WHERE product_id = '$product_id'");
                db_query("UPDATE $tables[products] SET avail = '$tmp[avail]', weight = '$tmp[weight]' WHERE product_id = '$product_id'");
                unset($tmp);
        */
        db_query("DELETE FROM {$tables['products_prices']} WHERE product_id = '{$product_id}' AND variant_id != 0");
        db_query("DELETE FROM {$tables['product_variant_items']} WHERE variant_id IN ('" . implode("','", $ids) . "')");
        db_query("DELETE FROM {$tables['products_warehouses_amount']} WHERE product_id = '{$product_id}' AND variant_id != 0");
    }
    unset($ids);
    db_query("DELETE FROM {$tables['product_variants']} WHERE product_id = '{$product_id}'");
    # Get modifier-classes
    $classes = cw_query($sql = "SELECT product_option_id FROM {$tables['product_options']} WHERE product_id = '{$product_id}' AND type = '' AND avail = 1 ORDER BY orderby");
    if (empty($classes)) {
        return false;
    }
    foreach ($classes as $k => $v) {
        $classes[$k]['cnt'] = 0;
        $classes[$k]['options'] = cw_query_column("SELECT option_id FROM {$tables['product_options_values']} WHERE product_option_id = '{$v['product_option_id']}' AND avail = 1 ORDER BY orderby, option_id ASC ");
        if (!@count($classes[$k]['options']) || !is_array($classes[$k]['options'])) {
            unset($classes[$k]);
        }
    }
    if (empty($classes)) {
        return false;
    }
    $classes = array_values($classes);
    $classes[0]['cnt'] = -1;
    # Build variant's matrix
    $variants = array();
    # Write variants to DB
    $product = cw_query_first("SELECT {$tables['products']}.eancode, {$tables['products']}.productcode, {$tables['products']}.weight,  {$tables['products']}.cost, {$tables['products_prices']}.price FROM {$tables['products']}, {$tables['products_prices']}  WHERE  {$tables['products_prices']}.variant_id = 0 AND {$tables['products_prices']}.quantity = '1' AND {$tables['products_prices']}.membership_id = 0 AND {$tables['products']}.product_id = '{$product_id}' GROUP BY {$tables['products']}.product_id");
    $cnt_row = $cnt = $cnd_ean = 0;
    do {
        $is_end = false;
        $options = array();
        $old_variants = array();
        foreach ($classes as $k => $c) {
            $option_id = 0;
            if (!$is_end) {
                if ($c['cnt'] >= count($c['options']) - 1) {
                    $c['cnt'] = 0;
                } else {
                    $c['cnt']++;
                    $is_end = true;
                }
                $classes[$k] = $c;
            }
            $option_id = $c['options'][$c['cnt']];
            if (empty($option_id)) {
                continue;
            }
            $options[] = $option_id;
            if (isset($items[$c['product_option_id']][$option_id])) {
                if (empty($old_variants)) {
                    $old_variants = $items[$c['product_option_id']][$option_id];
                } else {
                    $old_variants = array_intersect($old_variants, $items[$c['product_option_id']][$option_id]);
                }
            }
        }
        if (!$is_end || empty($options)) {
            break;
        }
        $_product = $product;
        # Restore old data
        $old_variant_id = false;
        if (is_array($old_variants) && !empty($old_variants)) {
            $old_variant_id = array_shift($old_variants);
            if (isset($vars[$old_variant_id])) {
                $_product = cw_array_merge($_product, $vars[$old_variant_id]);
            }
        }
        unset($old_variants);
        # Get unique SKU
        $sku = $_product['productcode'];
        while (cw_query_first_cell("SELECT COUNT(*) FROM {$tables['product_variants']} WHERE productcode = '{$sku}'") > 0) {
            $sku = $_product['productcode'] . ++$cnt;
        }
        $eancode = $_product['eancode'];
        while (cw_query_first_cell("SELECT COUNT(*) FROM {$tables['product_variants']} WHERE eancode = '{$eancode}'") > 0) {
            $eancode = $_product['eancode'] . ++$cnd_ean;
        }
        $data = array("product_id" => $product_id, "weight" => $_product['weight'], "cost" => $_product['cost'], "productcode" => $sku, 'eancode' => $eancode);
        # Check variant_id
        if (!empty($old_variant_id) && cw_query_first_cell("SELECT COUNT(*) FROM {$tables['product_variants']} WHERE variant_id = '{$old_variant_id}'") == 0) {
            $data['variant_id'] = $old_variant_id;
        }
        # Insert variant info
        $variant_id = cw_array2insert('product_variants', $data);
        if (empty($variant_id)) {
            continue;
        }
        if ($_product['avail'] == NULL) {
            $_product['avail'] = 0;
        }
        if (cw_query_first_cell("SELECT COUNT(*) FROM {$tables['products_warehouses_amount']} WHERE variant_id = '{$variant_id}'") == 0) {
            cw_array2insert('products_warehouses_amount', array('product_id' => $product_id, 'avail' => $_product['avail'], 'avail_ordered' => 0, 'avail_sold' => 0, 'avail_reserved' => '0', 'variant_id' => $variant_id, 'warehouse_customer_id' => '0'), false);
        }
        # Write products_prices
        if (empty($_product['prices'])) {
            cw_price_lists_replace_price($product_id, $_product['price'], $variant_id, true, true);
        } else {
            foreach ($_product['prices'] as $p) {
                cw_price_lists_replace_price($product_id, $p['price'], $variant_id, true, $p['is_manual']);
            }
        }
        # Restore image
        if (!empty($old_variant_id) && $variant_id != $old_variant_id) {
            cw_image_delete($variant_id, "W");
            db_query("UPDATE {$tables['products_images_var']} SET id = '{$variant_id}' WHERE id = '{$old_variant_id}'");
        }
        # Write matrix
        foreach ($options as $i) {
            db_query("INSERT INTO {$tables['product_variant_items']} (variant_id, option_id) VALUES ('{$variant_id}','{$i}')");
        }
        if ($tick > 0 && $cnt_row++ % $tick == 0) {
            cw_flush(". ");
        }
    } while ($is_end);
    # Clean old variants images
    $images = cw_query_column("SELECT {$tables['products_images_var']}.id FROM {$tables['product_variants']} LEFT JOIN {$tables['products_images_var']} ON {$tables['product_variants']}.variant_id = {$tables['products_images_var']}.id WHERE {$tables['products_images_var']}.id IS NULL");
    if (!empty($images)) {
        cw_image_delete($images, "W");
    }
    return true;
}
コード例 #10
0
<?php

$success = false;
if (!isset($domain_id)) {
    cw_flush('No domains specified');
    $top_message = array('content' => 'No domains specified', 'type' => 'W');
    return false;
}
cw_load('product', 'xml', 'category', 'image', 'attributes');
// Google Product Search fields accordint to the spec
// http://www.google.com/support/merchants/bin/answer.py?answer=188494
$xml_fields = array('g:id', 'title', 'description', 'g:google_product_category', 'g:product_type', 'link', 'g:image_link', 'g:additional_image_link', 'g:condition', 'g:availability', 'g:price', 'g:brand', 'g:gtin', 'g:mpn', 'g:item_group_id', 'g:color', 'g:material', 'g:pattern', 'g:size', 'g:gender', 'g:age_group', 'g:shipping_weight', 'g:expiration_date');
if ($addons['multi_domains']) {
    $domain = cw_func_call('cw_md_domain_get', array('domain_id' => $domain_id));
}
$default_thumb = cw_get_default_image('products_images_thumb');
$default_det = cw_get_default_image('products_images_det');
// Get all attributes of this addon
$gb_attr = array();
global $google_base_attributes_map;
$gb_attributes_full = cw_call('cw_get_attributes_by_addon', array('google_base'));
foreach ($gb_attributes_full as $gbv) {
    $gb_attr[$gbv['field']] = $gbv['attribute_id'];
    if (!empty($google_base_attributes_map[$gbv['field']])) {
        $mapped_attr = cw_func_call('cw_attributes_get_attributes_by_field', array('field' => $google_base_attributes_map[$gbv['field']]));
        if (!empty($mapped_attr['P'])) {
            $gb_attr[$gbv['field']] = $mapped_attr['P'];
        }
    }
}
unset($gb_attributes_full, $gbv, $mapped_attr);
コード例 #11
0
function cw_csvxc_transfer_import_images($src_table, $src_field, $key_field, $alt_field = '')
{
    global $src_images_path, $dst_images_path, $csvxc_images_translate_path, $cw_images_subdir;
    if (empty($csvxc_images_translate_path[$src_table . "_" . $src_field])) {
        return;
    }
    if (!empty($alt_field)) {
        $alt_field_qry = ", `{$alt_field}`";
    }
    $imgs_list = cw_query($qry = "SELECT `{$src_field}`, `{$key_field}`{$alt_field_qry} FROM `{$src_table}` WHERE `{$src_field}`!='' AND `{$key_field}`!=0");
    cw_log_add("flexible_import", $qry);
    $img_cw_type = $csvxc_images_translate_path[$src_table . "_" . $src_field]['dir'];
    cw_flush("<b>Importing new images {$img_cw_type}</b> found " . count($imgs_list) . " to copy <br>");
    cw_log_add("flexible_import", "<b>Importing new images {$img_cw_type}</b> found " . count($imgs_list) . " to copy <br>");
    $flush_step = intval(count($imgs_list) / 100);
    $flush_cnt = 0;
    if (empty($imgs_list)) {
        return;
    }
    if (!isset($csvxc_images_translate_path[$src_table . "_" . $src_field]['table'])) {
        $csvxc_images_translate_path[$src_table . "_" . $src_field]['table'] = 'cw_' . $img_cw_type;
    }
    cw_flush("Taking images from {$src_images_path} <br>");
    cw_log_add("flexible_import", "Taking images from {$src_images_path}");
    $img_exts = array(1 => 'gif', 2 => 'jpg', 3 => 'png');
    foreach ($imgs_list as $img_data) {
        if (strpos($img_data[$src_field], "http:") !== false) {
            $image_type = 2;
            foreach ($img_exts as $im_type => $im_ext) {
                if (strpos($img_data[$src_field], ".{$im_ext}") !== false) {
                    $image_type = $im_type;
                    break;
                }
            }
            $path_parts = parse_str($img_data[$src_field]);
            $image_ins_array = array('id' => $img_data[$key_field], 'image_path' => $img_data[$src_field], 'image_type' => $image_type, 'image_x' => 0, 'image_y' => 0, 'image_size' => 0, 'filename' => ltrim($path_parts['path'], '/'), 'date' => time(), 'alt' => isset($img_data[$alt_field]) ? $img_data[$alt_field] : '', 'avail' => 1, 'orderby' => 0, 'md5' => '');
            cw_flush("Inserted web file " . $img_data[$src_field] . " <br>");
            cw_log_add("flexible_import", "Inserted web file " . $img_data[$src_field]);
            cw_array2insert($csvxc_images_translate_path[$src_table . "_" . $src_field]['table'], $image_ins_array, 'true');
            $flush_cnt++;
            if ($flush_cnt >= $flush_step) {
                //cw_flush("+ ");
                $flush_cnt = 0;
            }
            continue;
            /*
                        cw_flush("Loading web file $img_data[$src_field]<br>");
                        //continue;
              
                        $web_file_content = file_get_contents($img_data[$src_field]);
                        if ($web_file_content) {
                            $temp_image_name = $src_images_path.'/'.md5($img_data[$src_field]);
                            @unlink($temp_image_name); 
                            if (file_put_contents($temp_image_name, $web_file_content)) {
                                $size_info = getimagesize($temp_image_name);
                                if (isset($img_exts[$size_info[2]])) {
                                    $new_temp_image_name = $temp_image_name.".".$img_exts[$size_info[2]];
                                    rename($temp_image_name, $new_temp_image_name);
                                    if (file_exists($new_temp_image_name)) {
                                        $img_data[$src_field] = md5($img_data[$src_field]).".".$img_exts[$size_info[2]]; 
                                    } 
                                }
                            }
                        }  
            */
        }
        $src_path = $src_images_path . '/' . ltrim($img_data[$src_field], '/');
        if (!file_exists($src_path)) {
            cw_flush("Cant find file {$src_path} <br>");
            cw_log_add("flexible_import", "Cant find file {$src_path}");
            //cw_flush("- ");
            continue;
        }
        $flush_cnt++;
        if ($flush_cnt >= $flush_step) {
            //cw_flush("+ ");
            $flush_cnt = 0;
        }
        $subdir_fname = $img_cw_type;
        $dest_filename = end(explode('/', $img_data[$src_field]));
        $dest_path = $dst_images_path . '/' . $subdir_fname . '/' . $dest_filename;
        $fname_c = 1;
        while (file_exists($dest_path) && $fname_c < 10 && strpos($src_path, "no_image.jpg") === false) {
            $path_parts = pathinfo($dest_path);
            $dest_filename = $path_parts['filename'] . '_' . $fname_c . '.' . $path_parts['extension'];
            $dest_path = $dst_images_path . '/' . $subdir_fname . '/' . $dest_filename;
            $fname_c++;
        }
        if (copy($src_path, $dest_path)) {
            list($image_x, $image_y, $image_type) = getimagesize($dest_path);
            $path_parts = pathinfo($dest_path);
            $image_ins_array = array('id' => $img_data[$key_field], 'image_path' => addslashes('.' . $cw_images_subdir . '/' . $subdir_fname . '/' . $dest_filename), 'image_type' => $image_type, 'image_x' => $image_x, 'image_y' => $image_y, 'image_size' => filesize($dest_path), 'filename' => addslashes($path_parts['basename']), 'date' => time(), 'alt' => isset($img_data[$alt_field]) ? $img_data[$alt_field] : '', 'avail' => 1, 'orderby' => 0, 'md5' => md5_file($dest_path));
            cw_flush("Inserted file {$dest_path} copied from {$src_path} <br>");
            cw_log_add("flexible_import", "Inserted file {$dest_path} copied from {$src_path}");
            cw_array2insert($csvxc_images_translate_path[$src_table . "_" . $src_field]['table'], $image_ins_array, 'true');
        } else {
            cw_flush("Cant copy image {$src_path} to {$dest_path}");
            cw_log_add("flexible_import", "Cant copy image {$src_path} to {$dest_path}");
        }
    }
    cw_flush("<b>Done</b><br>");
}