function gracenote_obfuscateText($text) { require_once 'utf8ToUnicode.php'; // Copy-protection: encode the contents of each line. Will not encode anything inside of "<" and ">" characters (because that would break any HTML). $LINE_BREAK = "<br />"; // this is the format in which it comes out of the parser. $LT_UNICODE = 60; $GT_UNICODE = 62; $lines = explode($LINE_BREAK, $text); $lyrics = ""; $isInsideTag = false; foreach ($lines as $oneLine) { $charsFromLyrics = utf8ToUnicode($oneLine); foreach ($charsFromLyrics as $unicodeValue) { if ($isInsideTag) { $unicodeAsArray = array($unicodeValue); // assigned so it can be passed by reference. $lyrics .= unicodeToUtf8($unicodeAsArray); if ($GT_UNICODE == $unicodeValue) { $isInsideTag = false; } } else { if ($LT_UNICODE == $unicodeValue) { $lyrics .= "<"; $isInsideTag = true; } else { $lyrics .= "&#{$unicodeValue};"; } } } $lyrics .= $LINE_BREAK; } # Prevent over-encoding of special HTML-encoded characters. # TODO: Is it safe to just make sure all /&([0-9a-zA-Z]{2,4});/ are put back to normal text? $lyrics = str_replace("&nbsp;", " ", $lyrics); $lyrics = str_replace("&#160;", " ", $lyrics); // fb#42619 $lyrics = str_replace("&amp;", "&", $lyrics); // rt#35365 $lyrics = str_replace("&gt;", ">", $lyrics); // fb#16034 $lyrics = str_replace("&lt;", "<", $lyrics); return substr($lyrics, 0, strlen($lyrics) - strlen($LINE_BREAK)); }
public function indexOp() { $lang = Language::getLangContent(); // 生成商店二维码 require_once BASE_RESOURCE_PATH . DS . 'phpqrcode' . DS . 'index.php'; $PhpQRCode = new PhpQRCode(); $PhpQRCode->set('pngTempDir', BASE_UPLOAD_PATH . DS . ATTACH_STORE . DS . $_SESSION['store_id'] . DS); if (!$_POST) { /** * 获取商品分类 */ $gc = Model('goods_class'); $gc_list = $gc->getGoodsClassList(array('gc_parent_id' => '0')); Tpl::output('gc_list', $gc_list); $model_store_class = Model('my_goods_class'); $store_goods_class = $model_store_class->getClassTree(array('store_id' => $_SESSION['store_id'], 'stc_state' => '1')); Tpl::output('store_goods_class', $store_goods_class); if ($_GET['step'] != '') { Tpl::output('step', $_GET['step']); } else { Tpl::output('step', '1'); } } else { $file = $_FILES['csv']; if (empty($file['name'])) { showMessage($lang['store_goods_import_choose_file'], '', 'html', 'error'); } if (!is_uploaded_file($file['tmp_name'])) { showMessage($lang['store_goods_import_unknown_file'], '', 'html', 'error'); } /** * 文件类型判定 */ $file_name_array = explode('.', $file['name']); if ($file_name_array[count($file_name_array) - 1] != 'csv') { showMessage($lang['store_goods_import_wrong_type'] . $file_name_array[count($file_name_array) - 1], '', 'html', 'error'); } /** * 文件大小判定 */ if ($file['size'] > intval(ini_get('upload_max_filesize')) * 1024 * 1024) { showMessage($lang['store_goods_import_size_limit'], '', 'html', 'error'); } /** * 商品分类判定 */ if (empty($_POST['gc_id'])) { showMessage($lang['store_goods_import_wrong_class'], '', 'html', 'error'); } $gc = Model('goods_class'); $gc_row = $gc->getGoodsClassLineForTag($_POST['gc_id']); if (!is_array($gc_row) or count($gc_row) == 0) { showMessage($lang['store_goods_import_wrong_class1'], '', 'html', 'error'); } $gc_sub_list = $gc->getGoodsClassList(array('gc_parent_id' => intval($_POST['gc_id']))); if (is_array($gc_sub_list) and count($gc_sub_list) > 0) { showMessage($lang['store_goods_import_wrong_class2'], '', 'html', 'error'); } /** * 店铺商品分类判定 */ $sgcate_ids = array(); $stc = Model('store_goods_class'); if (is_array($_POST['sgcate_id']) and count($_POST['sgcate_id']) > 0) { foreach ($_POST['sgcate_id'] as $sgcate_id) { if (!in_array($sgcate_id, $sgcate_ids)) { $stc_row = $stc->getOneById($sgcate_id); if (is_array($stc_row) and count($stc_row) > 0) { $sgcate_ids[] = $sgcate_id; } } } } /** * 上传文件的字符编码转换 */ $csv_string = unicodeToUtf8(file_get_contents($file['tmp_name'])); /* 兼容淘宝助理5 start */ $csv_array = explode("\tsyncStatus", $csv_string, 2); if (count($csv_array) == 2) { $csv_string = $csv_array[1]; } /* 兼容淘宝助理5 end */ /** * 将文件转换为二维数组形式的商品数据 */ $records = $this->parse_taobao_csv($csv_string); if ($records === false) { showMessage($lang['store_goods_import_wrong_column'], '', 'html', 'error'); } /** * 转码 */ if (strtoupper(CHARSET) == 'GBK') { $records = Language::getGBK($records); } $model_goodsclass = Model('goods_class'); $model_store_goods = Model('goods'); $model_type = Model('type'); // 商品数量 $goods_num = $model_store_goods->getGoodsCommonCount(array('store_id' => $_SESSION['store_id'])); /** * 商品数,空间使用,使用期限判断 */ $model_store = Model('store'); $store_info = $model_store->getStoreInfo(array('store_id' => $_SESSION['store_id'])); $model_store_grade = Model('store_grade'); $store_grade = $model_store_grade->getOneGrade($store_info['grade_id']); /*商品数判断*/ $remain_num = -1; if (intval($store_grade['sg_goods_limit']) != 0) { if ($goods_num >= $store_grade['sg_goods_limit']) { showMessage($lang['store_goods_index_goods_limit'] . $store_grade['sg_goods_limit'] . $lang['store_goods_index_goods_limit1'], 'index.php?act=store_goods&op=goods_list', 'html', 'error'); } $remain_num = $store_grade['sg_goods_limit'] - $goods_num; } /*使用期限判断*/ if (intval($store_info['store_end_time']) != 0) { if (time() >= $store_info['store_end_time']) { showMessage($lang['store_goods_index_time_limit'], 'index.php?act=store_goods&op=goods_list', 'html', 'error'); } } /** * 循环添加数据 */ $str = ''; if (is_array($records) and count($records) > 0) { foreach ($records as $k => $record) { if ($remain_num > 0 and $k >= $remain_num) { showMessage($lang['store_goods_index_goods_limit'] . $store_grade['sg_goods_limit'] . $lang['store_goods_index_goods_limit1'] . $lang['store_goods_import_end'] . (count($records) - $remain_num) . $lang['store_goods_import_products_no_import'], 'index.php?act=store_goods&op=taobao_import&step=4', 'html', 'error'); } if (is_array($record['goods_image'])) { $str .= implode(',', $record['goods_image']); $str .= "\r\n"; } else { $str .= $record['goods_image'] . "\r\n"; } file_put_contents('image.txt', $str, FILE_APPEND); $pic_array = $this->get_goods_image($record['goods_image']); if (empty($record['goods_name'])) { continue; } $param = array(); $param['goods_name'] = $record['goods_name']; $param['gc_id'] = intval($_POST['gc_id']); //$param['gc_name'] = $gc_row['gc_tag_name']; $param['store_id'] = $_SESSION['store_id']; $param['type_id'] = '0'; $param['goods_image'] = $pic_array['goods_image'][0]; $param['goods_marketprice'] = $record['goods_store_price']; $param['goods_price'] = $record['goods_store_price']; //$param['goods_show'] = '1'; $param['goods_commend'] = $record['goods_commend']; $param['goods_addtime'] = time(); $param['goods_body'] = $record['goods_body']; $param['goods_state'] = '0'; $param['goods_verify'] = '1'; $param['areaid_1'] = intval($_POST['province_id']); $param['areaid_2'] = intval($_POST['city_id']); $param['goods_stcids'] = ',' . implode(',', array_unique($_POST['sgcate_id'])) . ','; $param['goods_serial'] = $record['goods_serial']; $goods_id = $model_store_goods->addGoodsCommon($param); //添加库存 $param = array(); $param['goods_commonid'] = $goods_id; $param['goods_name'] = $record['goods_name']; $param['gc_id'] = intval($_POST['gc_id']); $param['store_id'] = $_SESSION['store_id']; $param['goods_image'] = $pic_array['goods_image'][0]; $param['goods_marketprice'] = $record['goods_store_price']; $param['goods_price'] = $record['goods_store_price']; //$param['goods_show'] = '1'; $param['goods_commend'] = $record['goods_commend']; $param['goods_addtime'] = time(); $param['goods_state'] = '0'; $param['goods_verify'] = '1'; $param['areaid_1'] = intval($_POST['province_id']); $param['areaid_2'] = intval($_POST['city_id']); $param['goods_stcids'] = $_POST['sgcate_id']; $param['goods_storage'] = $record['spec_goods_storage']; $param['goods_serial'] = $record['goods_serial']; $goods_id1 = $model_store_goods->addGoods($param); //规格导入 // 更新常用分类信息 $goods_class = $model_goodsclass->getGoodsClassLineForTag($_POST['gc_id']); $type_id = $goods_class['type_id']; //添加规格表 (防止BUG暂时不做了) if ($type_id > 0) { //$spec_id = $model_type->addGoodsType($goods_id1, $goods_id, array('cate_id' => $_POST['gc_id'], 'type_id' => $type_id, 'attr' => $_POST['attr'])); } $goods_id_str .= "," . $goods_id; if ($goods_id) { /** * 添加商品的店铺分类表 */ /** * 商品多图的添加 */ if (!empty($pic_array['goods_image']) && is_array($pic_array['goods_image'])) { $insert_array = array(); foreach ($pic_array['goods_image'] as $pic) { if ($pic == '') { continue; } $param = array(); $param['goods_image'] = $pic; $param['store_id'] = $_SESSION['store_id']; $param['goods_commonid'] = $goods_id; $insert_array[] = $param; } //$rs = Model('upload'); //$rs = $rs->add($param); $rs = $model_store_goods->addGoodsImagesAll($insert_array); } } } if ($goods_id_str != "") { Tpl::output('goods_id_str', substr($goods_id_str, 1, strlen($goods_id_str))); } } Tpl::output('step', '4'); } /** * 相册分类 */ $model_album = Model('album'); $param = array(); $param['album_aclass.store_id'] = $_SESSION['store_id']; $aclass_info = $model_album->getClassList($param); Tpl::output('aclass_info', $aclass_info); Tpl::output('PHPSESSID', session_id()); Tpl::output('menu_sign', 'taobao_import'); Tpl::showpage('store_goods_import'); }
/** * 淘宝助理导入 * */ public function taobao_importOp() { $lang = Language::getLangContent(); if (!$_POST) { /** * 获取商品分类 */ $gc = Model('goods_class'); $gc_list = $gc->getClassList(array('gc_parent_id' => '0', 'gc_show' => 1)); Tpl::output('gc_list', $gc_list); /** * 获取店铺商品分类 */ $model_store_class = Model('my_goods_class'); $store_goods_class = $model_store_class->getClassTree(array('store_id' => $_SESSION['store_id'], 'stc_state' => '1')); Tpl::output('store_goods_class', $store_goods_class); if ($_GET['step'] != '') { Tpl::output('step', $_GET['step']); } else { Tpl::output('step', '1'); } } else { $file = $_FILES['csv']; /** * 上传文件存在判断 */ if (empty($file['name'])) { showMessage($lang['store_goods_import_choose_file'], '', 'html', 'error'); } /** * 文件来源判定 */ if (!is_uploaded_file($file['tmp_name'])) { showMessage($lang['store_goods_import_unknown_file'], '', 'html', 'error'); } /** * 文件类型判定 */ $file_name_array = explode('.', $file['name']); if ($file_name_array[count($file_name_array) - 1] != 'csv') { showMessage($lang['store_goods_import_wrong_type'] . $file_name_array[count($file_name_array) - 1], '', 'html', 'error'); } /** * 文件大小判定 */ if ($file['size'] > intval(ini_get('upload_max_filesize')) * 1024 * 1024) { showMessage($lang['store_goods_import_size_limit'], '', 'html', 'error'); } /** * 商品分类判定 */ if (empty($_POST['gc_id'])) { showMessage($lang['store_goods_import_wrong_class'], '', 'html', 'error'); } $gc = Model('goods_class'); $gc_row = $gc->getGoodsClassLineForTag($_POST['gc_id']); if (!is_array($gc_row) or count($gc_row) == 0) { showMessage($lang['store_goods_import_wrong_class1'], '', 'html', 'error'); } $gc_sub_list = $gc->getClassList(array('gc_parent_id' => intval($_POST['gc_id']), 'gc_show' => 1)); if (is_array($gc_sub_list) and count($gc_sub_list) > 0) { showMessage($lang['store_goods_import_wrong_class2'], '', 'html', 'error'); } /** * 店铺商品分类判定 */ $stc_ids = array(); $stc = Model('store_goods_class'); if (is_array($_POST['stc_id']) and count($_POST['stc_id']) > 0) { foreach ($_POST['stc_id'] as $stc_id) { if (!in_array($stc_id, $stc_ids)) { $stc_row = $stc->getOneById($stc_id); if (is_array($stc_row) and count($stc_row) > 0) { $stc_ids[] = $stc_id; } } } } /** * 上传文件的字符编码转换 */ $csv_string = unicodeToUtf8(file_get_contents($file['tmp_name'])); /* 兼容淘宝助理5 start */ $csv_array = explode("\tsyncStatus", $csv_string, 2); if (count($csv_array) == 2) { $csv_string = $csv_array[1]; } /* 兼容淘宝助理5 end */ /** * 将文件转换为二维数组形式的商品数据 */ $records = $this->parse_taobao_csv($csv_string); if ($records === false) { showMessage($lang['store_goods_import_wrong_column'], '', 'html', 'error'); } /** * 转码 */ if (strtoupper(CHARSET) == 'GBK') { $records = Language::getGBK($records); } $model_store_goods = Model('goods'); $goods_num = $model_store_goods->countGoods(array('store_id' => $_SESSION['store_id'])); /** * 商品数,空间使用,使用期限判断 */ $model_store = Model('store'); $store_info = $model_store->shopStore(array('store_id' => $_SESSION['store_id'])); $model_store_grade = Model('store_grade'); $store_grade = $model_store_grade->getOneGrade($store_info['grade_id']); /*商品数判断*/ $remain_num = -1; if (intval($store_grade['sg_goods_limit']) != 0) { if ($goods_num >= $store_grade['sg_goods_limit']) { showMessage($lang['store_goods_index_goods_limit'] . $store_grade['sg_goods_limit'] . $lang['store_goods_index_goods_limit1'], 'index.php?act=store_goods&op=goods_list', 'html', 'error'); } $remain_num = $store_grade['sg_goods_limit'] - $goods_num; } /*使用期限判断*/ if (intval($store_info['store_end_time']) != 0) { if (time() >= $store_info['store_end_time']) { showMessage($lang['store_goods_index_time_limit'], 'index.php?act=store_goods&op=goods_list', 'html', 'error'); } } /** * 循环添加数据 */ if (is_array($records) and count($records) > 0) { foreach ($records as $k => $record) { if ($remain_num > 0 and $k >= $remain_num) { showMessage($lang['store_goods_index_goods_limit'] . $store_grade['sg_goods_limit'] . $lang['store_goods_index_goods_limit1'] . $lang['store_goods_import_end'] . (count($records) - $remain_num) . $lang['store_goods_import_products_no_import'], 'index.php?act=store_goods&op=taobao_import&step=2', 'html', 'error'); } $pic_array = $this->get_goods_image($record['goods_image']); if (empty($record['goods_name'])) { continue; } $param = array(); $param['goods_name'] = $record['goods_name']; $param['gc_id'] = intval($_POST['gc_id']); $param['gc_name'] = $gc_row['gc_tag_name']; $param['store_id'] = $_SESSION['store_id']; $param['goods_image'] = $pic_array['goods_image'][0]; $param['goods_store_price'] = $record['goods_store_price']; $param['goods_show'] = '1'; $param['goods_commend'] = $record['goods_commend']; $param['goods_add_time'] = time(); $param['goods_body'] = $record['goods_body']; $param['py_price'] = $record['py_price']; $param['es_price'] = $record['es_price']; $param['kd_price'] = $record['kd_price']; $param['goods_form'] = '1'; $param['goods_starttime'] = time(); $param['goods_endtime'] = time() + C('product_indate') * 86400; $param['goods_transfee_charge'] = $record['goods_transfee_charge']; $param['city_id'] = intval($_POST['city_id']); $param['province_id'] = intval($_POST['province_id']); $goods_id = $model_store_goods->saveGoods($param); $goods_id_str .= "," . $goods_id; if ($goods_id) { /** * 添加商品的店铺分类表 */ if (!empty($stc_ids)) { $model_store_goods->saveStoreClassGoods($stc_ids, $goods_id); } /** * 添加规格表 */ if (true) { $spec_array = array(); $spec_array[0]['price'] = $record['goods_store_price']; $spec_array[0]['stock'] = $record['spec_goods_storage']; $spec_id = $model_store_goods->saveSpecGoods($spec_array, $goods_id); /** * 修改商品 */ $model_store_goods->updateGoods(array('spec_id' => $spec_id), $goods_id); } /** * 商品多图的添加 */ if (!empty($pic_array['goods_image']) && is_array($pic_array['goods_image'])) { $model_upload = Model('upload'); foreach ($pic_array['goods_image'] as $pic) { if ($pic == '') { continue; } $param = array(); $param['file_name'] = $pic; $param['file_thumb'] = $pic; $param['store_id'] = $_SESSION['store_id']; $param['upload_type'] = '2'; $param['upload_time'] = time(); $param['item_id'] = $goods_id; $model_upload->add($param); } } } else { // 导入商品中的错误处理 } } if ($goods_id_str != "") { Tpl::output('goods_id_str', substr($goods_id_str, 1, strlen($goods_id_str))); } } Tpl::output('step', '2'); } /** * 相册分类 */ $model_album = Model('album'); $param = array(); $param['album_aclass.store_id'] = $_SESSION['store_id']; $aclass_info = $model_album->getClassList($param); Tpl::output('aclass_info', $aclass_info); Tpl::output('PHPSESSID', session_id()); self::profile_menu('import_taobao', 'import_taobao'); Tpl::output('menu_sign', 'taobao_import'); Tpl::showpage('store_goods_import'); }