锘??php /** * ECSHOP 棣栭〉鏂囦欢 * ============================================================================ * * 鐗堟潈鎵€鏈?2005-2012 涓婃捣鍟嗘淳缃戠粶绉戞妧鏈夐檺鍏徃锛屽苟淇濈暀鎵€鏈夋潈鍒┿€? * 缃戠珯鍦板潃: http://www.ecshop.com锛? * ---------------------------------------------------------------------------- * 杩欎笉鏄竴涓嚜鐢辫蒋浠讹紒鎮ㄥ彧鑳藉湪涓嶇敤浜庡晢涓氱洰鐨勭殑鍓嶆彁涓嬪绋嬪簭浠g爜杩涜淇敼鍜? * 浣跨敤锛涗笉鍏佽瀵圭▼搴忎唬鐮佷互浠讳綍褰㈠紡浠讳綍鐩殑鐨勫啀鍙戝竷銆? * ============================================================================ * $Author: liubo $ * $Id: index.php 17217 2011-01-19 06:29:08Z liubo $ */ define('IN_ECS', true); require(dirname(__FILE__) . '/includes/init.php'); if ((DEBUG_MODE & 2) != 2) { $smarty->caching = true; } $ua = strtolower($_SERVER['HTTP_USER_AGENT']); $uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i"; if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap')) { $Loaction = 'mobile/'; if (!empty($Loaction)) { ecs_header("Location: $Loaction\n"); exit; } } /*------------------------------------------------------ */ //-- Shopex绯荤粺鍦板潃杞崲 /*------------------------------------------------------ */ if (!empty($_GET['gOo'])) { if (!empty($_GET['gcat'])) { /* 鍟嗗搧鍒嗙被銆?/ $Loaction = 'category.php?id=' . $_GET['gcat']; } elseif (!empty($_GET['acat'])) { /* 鏂囩珷鍒嗙被銆?/ $Loaction = 'article_cat.php?id=' . $_GET['acat']; } elseif (!empty($_GET['goodsid'])) { /* 鍟嗗搧璇︽儏銆?/ $Loaction = 'goods.php?id=' . $_GET['goodsid']; } elseif (!empty($_GET['articleid'])) { /* 鏂囩珷璇︽儏銆?/ $Loaction = 'article.php?id=' . $_GET['articleid']; } if (!empty($Loaction)) { ecs_header("Location: $Loaction\n"); exit; } } //鍒ゆ柇鏄惁鏈塧jax璇锋眰 $act = !empty($_GET['act']) ? $_GET['act'] : ''; if ($act == 'cat_rec') { $rec_array = array(1 => 'best', 2 => 'new', 3 => 'hot'); $rec_type = !empty($_REQUEST['rec_type']) ? intval($_REQUEST['rec_type']) : '1'; $cat_id = !empty($_REQUEST['cid']) ? intval($_REQUEST['cid']) : '0'; include_once('includes/cls_json.php'); $json = new JSON; $result = array('error' => 0, 'content' => '', 'type' => $rec_type, 'cat_id' => $cat_id); $children = get_children($cat_id); $smarty->assign($rec_array[$rec_type] . '_goods', get_category_recommend_goods($rec_array[$rec_type], $children)); // 鎺ㄨ崘鍟嗗搧 $smarty->assign('cat_rec_sign', 1); $result['content'] = $smarty->fetch('library/recommend_' . $rec_array[$rec_type] . '.lbi'); die($json->encode($result)); } /*------------------------------------------------------ */ //-- 鍒ゆ柇鏄惁瀛樺湪缂撳瓨锛屽鏋滃瓨鍦ㄥ垯璋冪敤缂撳瓨锛屽弽涔嬭鍙栫浉搴斿唴瀹? /*------------------------------------------------------ */ /* 缂撳瓨缂栧彿 */ $cache_id = sprintf('%X', crc32($_SESSION['user_rank'] . '-' . $_CFG['lang'])); if (!$smarty->is_cached('index.dwt', $cache_id)) { assign_template(); $position = assign_ur_here(); $smarty->assign('page_title', $position['title']); // 椤甸潰鏍囬 $smarty->assign('ur_here', $position['ur_here']); // 褰撳墠浣嶇疆 /* meta information */ $smarty->assign('keywords', htmlspecialchars($_CFG['shop_keywords'])); $smarty->assign('description', htmlspecialchars($_CFG['shop_desc'])); $smarty->assign('flash_theme', $_CFG['flash_theme']); // Flash杞挱鍥剧墖妯℃澘 $smarty->assign('feed_url', ($_CFG['rewrite'] == 1) ? 'feed.xml' : 'feed.php'); // RSS URL $smarty->assign('categories', get_categories_tree()); // 鍒嗙被鏍? $smarty->assign('helps', get_shop_help()); // 缃戝簵甯姪 $smarty->assign('top_goods', get_top10()); // 閿€鍞帓琛? $smarty->assign('top_goods', get_top10()); // 閿€鍞帓琛? $smarty->assign('get_top10_index', get_top10_index()); // 閿€鍞帓琛? $smarty->assign('best_goods', get_recommend_goods('best')); // 鎺ㄨ崘鍟嗗搧 $smarty->assign('new_goods', get_recommend_goods('new')); // 鏈€鏂板晢鍝? $smarty->assign('hot_goods', get_recommend_goods('hot')); // 鐑偣鏂囩珷 $smarty->assign('promotion_goods', get_promote_goods()); // 鐗逛环鍟嗗搧 $smarty->assign('brand_list', get_brands()); $smarty->assign('promotion_info', get_promotion_info()); // 澧炲姞涓€涓姩鎬佹樉绀烘墍鏈変績閿€淇℃伅鐨勬爣绛炬爮 $smarty->assign('invoice_list', index_get_invoice_query()); // 鍙戣揣鏌ヨ $smarty->assign('new_articles', index_get_new_articles()); // 鏈€鏂版枃绔? $smarty->assign('group_buy_goods', index_get_group_buy()); // 鍥㈣喘鍟嗗搧 $smarty->assign('auction_list', index_get_auction()); // 鎷嶅崠娲诲姩 $smarty->assign('shop_notice', $_CFG['shop_notice']); // 鍟嗗簵鍏憡 $smarty->assign('script_name', 'index'); $smarty->assign('index_comments', get_comments($num)); /* 棣栭〉涓诲箍鍛婅缃?*/ $smarty->assign('index_ad', $_CFG['index_ad']); if ($_CFG['index_ad'] == 'cus') { $sql = 'SELECT ad_type, content, url FROM ' . $ecs->table("ad_custom") . ' WHERE ad_status = 1'; $ad = $db->getRow($sql, true); $smarty->assign('ad', $ad); } /*鍛ㄦ鏀?start*/ $xml_array=simplexml_load_file(ROOT_PATH . DATA_DIR .'/flash_data.xml'); //灏哫ML涓殑鏁版嵁,璇诲彇鍒版暟缁勫璞′腑 $index_ad_w = array(); $index_ad_s = array(); foreach($xml_array as $key => $val) { if($val['width_screen'] == 0) { $index_ad_w[] = array('src'=>$val['item_url'],'url'=>$val['link'],'text'=>$val['text'],'sort'=>$val['sort'],'width_screen'=>$val['width_screen']); } else { $index_ad_s[] = array('src'=>$val['item_url'],'url'=>$val['link'],'text'=>$val['text'],'sort'=>$val['sort'],'width_screen'=>$val['width_screen']); } } $smarty->assign('index_ad_w', $index_ad_w); $smarty->assign('index_ad_w_count', count($index_ad_w)); $smarty->assign('index_ad_s', $index_ad_s); $smarty->assign('index_ad_s_count', count($index_ad_s)); /*鍛ㄦ鏀?end*/ /* links */ $links = index_get_links(); $smarty->assign('img_links', $links['img']); $smarty->assign('txt_links', $links['txt']); $smarty->assign('data_dir', DATA_DIR); // 鏁版嵁鐩綍 /* 棣栭〉鎺ㄨ崘鍒嗙被 */ $cat_recommend_res = $db->getAll("SELECT c.cat_id, c.cat_name, cr.recommend_type FROM " . $ecs->table("cat_recommend") . " AS cr INNER JOIN " . $ecs->table("category") . " AS c ON cr.cat_id=c.cat_id"); if (!empty($cat_recommend_res)) { $cat_rec_array = array(); foreach($cat_recommend_res as $cat_recommend_data) { $cat_rec[$cat_recommend_data['recommend_type']][] = array('cat_id' => $cat_recommend_data['cat_id'], 'cat_name' => $cat_recommend_data['cat_name']); } $smarty->assign('cat_rec', $cat_rec); } /* 椤甸潰涓殑鍔ㄦ€佸唴瀹?*/ assign_dynamic('index'); } $smarty->display('index.dwt', $cache_id); /*------------------------------------------------------ */ //-- PRIVATE FUNCTIONS /*------------------------------------------------------ */ /** * 璋冪敤鍙戣揣鍗曟煡璇? * * @access private * @return array */ function index_get_invoice_query() { $sql = 'SELECT o.order_sn, o.invoice_no, s.shipping_code FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o' . ' LEFT JOIN ' . $GLOBALS['ecs']->table('shipping') . ' AS s ON s.shipping_id = o.shipping_id' . " WHERE invoice_no > '' AND shipping_status = " . SS_SHIPPED . ' ORDER BY shipping_time DESC LIMIT 10'; $all = $GLOBALS['db']->getAll($sql); foreach ($all AS $key => $row) { $plugin = ROOT_PATH . 'includes/modules/shipping/' . $row['shipping_code'] . '.php'; if (file_exists($plugin)) { include_once($plugin); $shipping = new $row['shipping_code']; $all[$key]['invoice_no'] = $shipping->query((string)$row['invoice_no']); } } clearstatcache(); return $all; } /** * 鑾峰緱鏈€鏂扮殑鏂囩珷鍒楄〃銆? * * @access private * @return array */ function index_get_new_articles() { $sql = 'SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type, ac.cat_id, ac.cat_name ' . ' FROM ' . $GLOBALS['ecs']->table('article') . ' AS a, ' . $GLOBALS['ecs']->table('article_cat') . ' AS ac' . ' WHERE a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1' . ' ORDER BY a.article_type DESC, a.add_time DESC LIMIT ' . $GLOBALS['_CFG']['article_number']; $res = $GLOBALS['db']->getAll($sql); $arr = array(); foreach ($res AS $idx => $row) { $arr[$idx]['id'] = $row['article_id']; $arr[$idx]['title'] = $row['title']; $arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title']; $arr[$idx]['cat_name'] = $row['cat_name']; $arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); $arr[$idx]['url'] = $row['open_type'] != 1 ? build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']); $arr[$idx]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id']), $row['cat_name']); } return $arr; } /** * 鑾峰緱鏈€鏂扮殑鍥㈣喘娲诲姩 * * @access private * @return array */ function index_get_group_buy() { $time = gmtime(); $limit = get_library_number('group_buy', 'index'); $group_buy_list = array(); if ($limit > 0) { $sql = 'SELECT gb.act_id AS group_buy_id, gb.goods_id, gb.ext_info, gb.goods_name, g.goods_thumb, g.goods_img ' . 'FROM ' . $GLOBALS['ecs']->table('goods_activity') . ' AS gb, ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "WHERE gb.act_type = '" . GAT_GROUP_BUY . "' " . "AND g.goods_id = gb.goods_id " . "AND gb.start_time <= '" . $time . "' " . "AND gb.end_time >= '" . $time . "' " . "AND g.is_delete = 0 " . "ORDER BY gb.act_id DESC " . "LIMIT $limit" ; $res = $GLOBALS['db']->query($sql); while ($row = $GLOBALS['db']->fetchRow($res)) { /* 濡傛灉缂╃暐鍥句负绌猴紝浣跨敤榛樿鍥剧墖 */ $row['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $row['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); /* 鏍规嵁浠锋牸闃舵锛岃绠楁渶浣庝环 */ $ext_info = unserialize($row['ext_info']); $price_ladder = $ext_info['price_ladder']; if (!is_array($price_ladder) || empty($price_ladder)) { $row['last_price'] = price_format(0); } else { foreach ($price_ladder AS $amount_price) { $price_ladder[$amount_price['amount']] = $amount_price['price']; } } ksort($price_ladder); $row['last_price'] = price_format(end($price_ladder)); $row['url'] = build_uri('group_buy', array('gbid' => $row['group_buy_id'])); $row['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $row['short_style_name'] = add_style($row['short_name'],''); $group_buy_list[] = $row; } } return $group_buy_list; } /** * 鍙栧緱鎷嶅崠娲诲姩鍒楄〃 * @return array */ function index_get_auction() { $now = gmtime(); $limit = get_library_number('auction', 'index'); $sql = "SELECT a.act_id, a.goods_id, a.goods_name, a.ext_info, g.goods_thumb ". "FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS a," . $GLOBALS['ecs']->table('goods') . " AS g" . " WHERE a.goods_id = g.goods_id" . " AND a.act_type = '" . GAT_AUCTION . "'" . " AND a.is_finished = 0" . " AND a.start_time <= '$now'" . " AND a.end_time >= '$now'" . " AND g.is_delete = 0" . " ORDER BY a.start_time DESC" . " LIMIT $limit"; $res = $GLOBALS['db']->query($sql); $list = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $ext_info = unserialize($row['ext_info']); $arr = array_merge($row, $ext_info); $arr['formated_start_price'] = price_format($arr['start_price']); $arr['formated_end_price'] = price_format($arr['end_price']); $arr['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $arr['url'] = build_uri('auction', array('auid' => $arr['act_id'])); $arr['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($arr['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $arr['goods_name']; $arr['short_style_name'] = add_style($arr['short_name'],''); $list[] = $arr; } return $list; } /** * 鑾峰緱鎵€鏈夌殑鍙嬫儏閾炬帴 * * @access private * @return array */ function index_get_links() { $sql = 'SELECT link_logo, link_name, link_url FROM ' . $GLOBALS['ecs']->table('friend_link') . ' ORDER BY show_order'; $res = $GLOBALS['db']->getAll($sql); $links['img'] = $links['txt'] = array(); foreach ($res AS $row) { if (!empty($row['link_logo'])) { $links['img'][] = array('name' => $row['link_name'], 'url' => $row['link_url'], 'logo' => $row['link_logo']); } else { $links['txt'][] = array('name' => $row['link_name'], 'url' => $row['link_url']); } } return $links; } function get_comments($num) { $sql = 'SELECT a.*,b.goods_id,b.goods_thumb,b.goods_name FROM '. $GLOBALS['ecs']->table('comment') . ' AS a,'. $GLOBALS['ecs']->table('goods') .'AS b WHERE a.status = 1 AND a.parent_id = 0 and a.comment_type=0 and a.id_value=b.goods_id '. ' ORDER BY a.add_time DESC'; if ($num > 0) { $sql .= ' LIMIT ' . $num; } $res = $GLOBALS['db']->getAll($sql); $comments = array(); foreach ($res AS $idx => $row) { $comments[$idx]['add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']); $comments[$idx]['content'] = $row['content']; $comments[$idx]['id_value'] = $row['id_value']; $comments[$idx]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $comments[$idx]['goods_name'] = $row['goods_name']; $comments[$idx]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']); } return $comments; } ?>