ecshop源碼分析01

ecshop2.7.3的入口文件“index.php”的詳細分析

//定義常量那伐,防止被引用文件的非法載入

define('IN_ECS', true);

//加載全站初始化配置文件

require(dirname(__FILE__) . '/includes/init.php');

//自定義常量“DEBUG_MODE”與2進行按位與運算谷醉,如果"DEBUG_MODE"的二進制不是“10”娃承,就打開緩存

if ((DEBUG_MODE & 2) != 2)

{

$smarty->caching = true;

}

//初定義變量$ua為“小寫處理后的訪問用戶的所有信息”

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);

//初定義變量$uachar為各種匹配機型

$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";

//如果‘wap’沒有出現(xiàn)在經(jīng)過小寫化處理的url中钉稍,如果$ua為空或者$ua匹配到某種機型,同時滿足上述兩種情況,即手機登錄時檬某,定位到手機目錄'mobile/'下

if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))

{

$Loaction = 'mobile/';

if (!empty($Loaction))

{

ecs_header("Location: $Loaction\n");

exit;

}

}

//Shopex系統(tǒng)地址轉換,一些功能定位

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;

}

}

//判斷是否有ajax請求,若有$smarty模版實例化對象,輸出內容呀舔,并退出當前腳本

$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']));

//smarty模板引擎檢查'index.dwt'模板是否已經(jīng)被緩存

if (!$smarty->is_cached('index.dwt', $cache_id))

{

//調用模板參數(shù)

assign_template();

//“assign_ur_here()”來自“l(fā)ib_main.php”的129行弥虐,主要用來獲取當前頁面的title和路徑的函數(shù)

$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());? ? ? // 網(wǎng)店幫助

$smarty->assign('top_goods',? ? ? get_top10());? ? ? ? ? // 銷售排行

$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()); // 增加一個動態(tài)顯示所有促銷信息的標簽欄

$smarty->assign('invoice_list',? ? index_get_invoice_query());? // 發(fā)貨查詢

$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']);? ? ? // 商店公告

/*jdy add 0816 添加首頁幻燈插件*/

$smarty->assign("flash",get_flash_xml());

$smarty->assign('flash_count',count(get_flash_xml()));

/* 首頁主廣告設置 */

$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);

}

/* links */

$links = index_get_links();

$smarty->assign('img_links',? ? ? $links['img']);

$smarty->assign('txt_links',? ? ? $links['txt']);

$smarty->assign('data_dir',? ? ? ? DATA_DIR);? ? ? // 數(shù)據(jù)目錄

/* 首頁推薦分類 */

$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);

}

/* 頁面中的動態(tài)內容 */

assign_dynamic('index');

}

//顯示模版"index.dwt"

$smarty->display('index.dwt', $cache_id);

//調用發(fā)貨單查詢,mysql數(shù)據(jù)庫操作

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']);

}

}

//函數(shù)清除文件狀態(tài)緩存

clearstatcache();

return $all;

}

//獲得最新的文章列表,mysql數(shù)據(jù)庫操作

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;

}

//獲得最新的團購活動

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);

/* 根據(jù)價格階梯霜瘪,計算最低價 */

$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;

}

//取得拍賣活動列表

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;

}

//獲得所有的友情鏈接

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;

}

//解析'/flash_data.xml',控制[首頁]頭滾動圖片效果

*通過首頁廣告設置

function get_flash_xml()

{

$flashdb = array();

if (file_exists(ROOT_PATH . DATA_DIR . '/flash_data.xml'))

{

// 兼容v2.7.0及以前版本

if (!preg_match_all('/item_url="([^"]+)"\slink="([^"]+)"\stext="([^"]*)"\ssort="([^"]*)"/', file_get_contents(ROOT_PATH . DATA_DIR . '/flash_data.xml'), $t, PREG_SET_ORDER))

{

preg_match_all('/item_url="([^"]+)"\slink="([^"]+)"\stext="([^"]*)"/', file_get_contents(ROOT_PATH . DATA_DIR . '/flash_data.xml'), $t, PREG_SET_ORDER);

}

if (!empty($t))

{

foreach ($t as $key => $val)

{

$val[4] = isset($val[4]) ? $val[4] : 0;

$flashdb[] = array('src'=>$val[1],'url'=>$val[2],'text'=>$val[3],'sort'=>$val[4]);

//print_r($flashdb);

}

}

}

return $flashdb;

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末珠插,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子颖对,更是在濱河造成了極大的恐慌捻撑,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,284評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件缤底,死亡現(xiàn)場離奇詭異顾患,居然都是意外死亡,警方通過查閱死者的電腦和手機训堆,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評論 3 395
  • 文/潘曉璐 我一進店門描验,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人坑鱼,你說我怎么就攤上這事膘流。” “怎么了鲁沥?”我有些...
    開封第一講書人閱讀 164,614評論 0 354
  • 文/不壞的土叔 我叫張陵呼股,是天一觀的道長。 經(jīng)常有香客問我画恰,道長彭谁,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,671評論 1 293
  • 正文 為了忘掉前任允扇,我火速辦了婚禮缠局,結果婚禮上,老公的妹妹穿的比我還像新娘考润。我一直安慰自己狭园,他們只是感情好,可當我...
    茶點故事閱讀 67,699評論 6 392
  • 文/花漫 我一把揭開白布糊治。 她就那樣靜靜地躺著唱矛,像睡著了一般。 火紅的嫁衣襯著肌膚如雪井辜。 梳的紋絲不亂的頭發(fā)上绎谦,一...
    開封第一講書人閱讀 51,562評論 1 305
  • 那天,我揣著相機與錄音粥脚,去河邊找鬼窃肠。 笑死,一個胖子當著我的面吹牛刷允,可吹牛的內容都是我干的铭拧。 我是一名探鬼主播赃蛛,決...
    沈念sama閱讀 40,309評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼搀菩!你這毒婦竟也來了呕臂?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,223評論 0 276
  • 序言:老撾萬榮一對情侶失蹤肪跋,失蹤者是張志新(化名)和其女友劉穎歧蒋,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體州既,經(jīng)...
    沈念sama閱讀 45,668評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡谜洽,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,859評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了吴叶。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片阐虚。...
    茶點故事閱讀 39,981評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖蚌卤,靈堂內的尸體忽然破棺而出实束,到底是詐尸還是另有隱情,我是刑警寧澤逊彭,帶...
    沈念sama閱讀 35,705評論 5 347
  • 正文 年R本政府宣布咸灿,位于F島的核電站,受9級特大地震影響侮叮,放射性物質發(fā)生泄漏避矢。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,310評論 3 330
  • 文/蒙蒙 一囊榜、第九天 我趴在偏房一處隱蔽的房頂上張望审胸。 院中可真熱鬧,春花似錦卸勺、人聲如沸歹嘹。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至材蛛,卻和暖如春圆到,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背卑吭。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評論 1 270
  • 我被黑心中介騙來泰國打工芽淡, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人豆赏。 一個月前我還...
    沈念sama閱讀 48,146評論 3 370
  • 正文 我出身青樓挣菲,卻偏偏與公主長得像富稻,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子白胀,可洞房花燭夜當晚...
    茶點故事閱讀 44,933評論 2 355

推薦閱讀更多精彩內容

  • CREATE TABLE IF NOT EXISTS ecs_order_info (order_id mediu...
    cookie口閱讀 15,688評論 0 16
  • 第1章 初涉MySQL 1.1 MySQL文件 (1)MySQL目錄結構 (2)MySQL配置向導文件(安裝后配置...
    凜0_0閱讀 787評論 1 0
  • 剛剛結束了項目期椭赋,最近對ecshop用的也算比較熟了,所以給大家分享出來或杠,如果不是一定要用ecshop大家最好還是...
    寄去遠方的盛夏閱讀 1,783評論 1 4
  • Day 4:藏村下?lián)?話說蚩尤部落被打敗后哪怔,一部分人逃入了這橫斷山脈隱居起來,再沒有跟外界有聯(lián)系向抢。他們的以人祭祀的...
    羅茲閱讀 531評論 0 0
  • 我時常刷微博认境、朋友圈,浪費許多時間瀏覽一些有趣或無聊的新聞挟鸠,感覺輕松愉悅叉信,隨后拋之腦后----所謂低收益值短半衰期...
    仙女就是橋橋閱讀 231評論 0 0