当前位置: 代码迷 >> 综合 >> ecshop2.7.3的入口文件“index.php”的详细分析
  详细解决方案

ecshop2.7.3的入口文件“index.php”的详细分析

热度:91   发布时间:2024-02-02 05:44:12.0

//定义常量,防止被引用文件的非法载入

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为“小写处理后的访问用户的所有信息”

u a = s t r t o l o w e r ( ua = strtolower( _SERVER[‘HTTP_USER_AGENT’]);

//初定义变量$uachar为各种匹配机型

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

//如果‘wap’没有出现在经过小写化处理的url中,如果 u a ua为空或者 ua匹配到某种机型,同时满足上述两种情况,即手机登录时,定位到手机目录’mobile/'下

if(( u a = = p r e g m a t c h ( ua == '' || preg_match( uachar, KaTeX parse error: Expected 'EOF', got '&' at position 5: ua))&?& !strpos(strto…_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;

}

}

//判断是否有ajax请求,若有$smarty模版实例化对象,输出内容,并退出当前脚本

a c t = ! e m p t y ( act = !empty( _GET[‘act’]) ? $_GET[‘act’] : ‘’;

if ($act == ‘cat_rec’)

{

$rec_array = array(1 => ‘best’, 2 => ‘new’, 3 => ‘hot’);

r e c t y p e = ! e m p t y ( rec_type = !empty( _REQUEST[‘rec_type’]) ? intval($_REQUEST[‘rec_type’]) : ‘1’;

c a t i d = ! e m p t y ( 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);

c h i l d r e n = g e t c h i l d r e n ( children = get_children( cat_id);

s m a r t y ? > a s s i g n ( smarty->assign( rec_array[ r e c t y p e ] . g o o d s , g e t c a t e g o r y r e c o m m e n d g o o d s ( rec_type] . '_goods', get_category_recommend_goods( rec_array[$rec_type], $children)); // 推荐商品

$smarty->assign(‘cat_rec_sign’, 1);

$result[‘content’] = $smarty->fetch(‘library/recommend_’ . r e c a r r a y [ rec_array[ rec_type] . ‘.lbi’);

die( j s o n ? > e n c o d e ( json->encode( result));

}

//格式化并缓存编号

c a c h e i d = s p r i n t f ( cache_id = sprintf('%X', crc32( _SESSION[‘user_rank’] . ‘-’ . $_CFG[‘lang’]));

//smarty模板引擎检查’index.dwt’模板是否已经被缓存

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

{

//调用模板参数

assign_template();

//“assign_ur_here()”来自“lib_main.php”的129行,主要用来获取当前页面的title和路径的函数

$position = assign_ur_here();

//下面是通过缓存获取内容实例化

$smarty->assign(‘page_title’, $position[‘title’]); // 页面标题

$smarty->assign(‘ur_here’, $position[‘ur_here’]); // 当前位置

/* meta information */

s m a r t y ? > a s s i g n ( k e y w o r d s , h t m l s p e c i a l c h a r s ( smarty->assign('keywords', htmlspecialchars( _CFG[‘shop_keywords’]));

s m a r t y ? > a s s i g n ( d e s c r i p t i o n , h t m l s p e c i a l c h a r s ( smarty->assign('description', htmlspecialchars( _CFG[‘shop_desc’]));

$smarty->assign(‘flash_theme’, $_CFG[‘flash_theme’]); // Flash轮播图片模板

s m a r t y ? > a s s i g n ( f e e d u r l , ( 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(‘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’]); // 商店公告

/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 = d b ? > g e t R o w ( 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); // 数据目录

/* 首页推荐分类 */

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

{

c a t r e c [ 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’);

}

//显示模版"index.dwt"

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

//调用发货单查询,mysql数据库操作

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 = G L O B A L S [ d b ] ? > g e t A l l ( 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’];

a l l [ all[ key][‘invoice_no’] = s h i p p i n g ? > q u e r y ( ( s t r i n g ) shipping->query((string) row[‘invoice_no’]);

}

}

//函数清除文件状态缓存

clearstatcache();

return $all;

}

//获得最新的文章列表,mysql数据库操作

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 = G L O B A L S [ d b ] ? > g e t A l l ( GLOBALS['db']->getAll( sql);

$arr = array();

foreach ($res AS $idx => $row)

{

a r r [ arr[ idx][‘id’] = $row[‘article_id’];

a r r [ arr[ idx][‘title’] = $row[‘title’];

a r r [ arr[ idx][‘short_title’] = $GLOBALS[’_CFG’][‘article_title_length’] > 0 ?

sub_str($row[‘title’], $GLOBALS[’_CFG’][‘article_title_length’]) : $row[‘title’];

a r r [ arr[ idx][‘cat_name’] = $row[‘cat_name’];

a r r [ arr[ idx][‘add_time’] = local_date($GLOBALS[’_CFG’][‘date_format’], $row[‘add_time’]);

a r r [ arr[ idx][‘url’] = $row[‘open_type’] != 1 ?

build_uri(‘article’, array(‘aid’ => $row[‘article_id’]), r o w [ t i t l e ] ) : t r i m ( row['title']) : trim( row[‘file_url’]);

a r r [ 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 = G L O B A L S [ d b ] ? > q u e r y ( GLOBALS['db']->query( sql);

while ($row = G L O B A L S [ d b ] ? > f e t c h R o w ( GLOBALS['db']->fetchRow( res))

{

/* 如果缩略图为空,使用默认图片 */

r o w [ g o o d s i m g ] = g e t i m a g e p a t h ( row['goods_img'] = get_image_path( row[‘goods_id’], $row[‘goods_img’]);

r o w [ t h u m b ] = g e t i m a g e p a t h ( row['thumb'] = get_image_path( row[‘goods_id’], $row[‘goods_thumb’], true);

/* 根据价格阶梯,计算最低价 */

e x t i n f o = u n s e r i a l i z e ( ext_info = unserialize( row[‘ext_info’]);

$price_ladder = $ext_info[‘price_ladder’];

if (!is_array( p r i c e l a d d e r ) e m p t y ( price_ladder) || empty( price_ladder))

{

$row[‘last_price’] = price_format(0);

}

else

{

foreach ($price_ladder AS $amount_price)

{

p r i c e l a d d e r [ price_ladder[ amount_price[‘amount’]] = $amount_price[‘price’];

}

}

ksort($price_ladder);

r o w [ l a s t p r i c e ] = p r i c e f o r m a t ( e n d ( 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’];

r o w [ s h o r t s t y l e n a m e ] = a d d s t y l e ( 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 = G L O B A L S [ d b ] ? > q u e r y ( GLOBALS['db']->query( sql);

$list = array();

while ($row = G L O B A L S [ d b ] ? > f e t c h R o w ( GLOBALS['db']->fetchRow( res))

{

e x t i n f o = u n s e r i a l i z e ( ext_info = unserialize( row[‘ext_info’]);

a r r = a r r a y m e r g e ( arr = array_merge( row, $ext_info);

a r r [ f o r m a t e d s t a r t p r i c e ] = p r i c e f o r m a t ( arr['formated_start_price'] = price_format( arr[‘start_price’]);

a r r [ f o r m a t e d e n d p r i c e ] = p r i c e f o r m a t ( arr['formated_end_price'] = price_format( arr[‘end_price’]);

a r r [ t h u m b ] = g e t i m a g e p a t h ( 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’];

a r r [ s h o r t s t y l e n a m e ] = a d d s t y l e ( 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 = G L O B A L S [ d b ] ? > g e t A l l ( 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)

{

v a l [ 4 ] = i s s e t ( val[4] = isset( val[4]) ? $val[4] : 0;

f l a s h d b [ ] = a r r a y ( s r c = > flashdb[] = array('src'=> val[1],‘url’=> v a l [ 2 ] , t e x t = > val[2],'text'=> val[3],‘sort’=>$val[4]);

//print_r($flashdb);

}

}

}

return $flashdb;

}

  相关解决方案