ecshop index.php,ecshop  源码分析01 (index.php)

本文详细分析了ECSHOP 2.7.2版本中的核心代码,包括define常量定义、文件引入、缓存管理、用户代理检测以及页面内容的生成流程。通过对DEBUG_MODE的判断控制缓存更新,使用SMARTY模板引擎进行页面渲染,并针对不同设备展示相应内容。此外,还展示了如何处理分类推荐商品、获取商店动态信息以及处理各种商品列表等功能。
摘要由CSDN通过智能技术生成

//ecshop 2.7.2

// define是php里定义常量用的。第一个参数是常量名,第二个是常量的值。

// 它定义这个常量的作用是防止被引用文件的非法载入。

// 根据某人的说法, 挂个鸟牌。

define('IN_ECS', true);

//dirname(__FILE__) 取到的是当前文件的绝对路径

// 引入内核文件

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

// DEBUG_MODE在init.php中定义了0,根据常量不可重复定义的原则, 估计下面的判断永远都将是真.即不需要更新缓存。

// $smarty->caching 为true时, 表示不强制更新缓存。

if ((DEBUG_MODE & 2) != 2)

{

$smarty->caching = true;

}

//strtolower大写转小写

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

}

}

//判断是否有ajax请求

$act = !empty($_GET['act']) ? $_GET['act'] : '';

if ($act == 'cat_rec')

{

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

//假如有类型传过来就设置为数值类型,否则为1

$rec_type = !empty($_REQUEST['rec_type']) ? intval($_REQUEST['rec_type']) : '1';

$cat_id = !empty($_REQUEST['cid']) ? intval($_REQUEST['cid']) : '0';

//json应用。

include_once('includes/cls_json.php');

$json = new JSON;

$result = array('error' => 0, 'content' => '', 'type' => $rec_type, 'cat_id' => $cat_id);

//获得指定分类下所有底层分类的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));

}

//-- 判断是否存在缓存,如果存在则调用缓存,反之读取相应内容

// ecshop似乎没有用户选择模式功能吧, 以下加密串多少有点令人难理解.

$cache_id = sprintf('%X', crc32($_SESSION['user_rank'] . '-' . $_CFG['lang']));

// $smarty->is_cached 方法有多低能就有多低能. 方法将返回false 或者 true.

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

{ //设置默认的smarty变量数据.

assign_template();

//取得当前页信息.比如标题,链接等.

$position = assign_ur_here();

//将它赋给smarty.

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

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

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

('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 = 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

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;

}

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ECSHOP是一款开源免费的通用电子商务平台构建软件,使用她您可以非常方便的开一个网上商店,在网上开展自己的生意。ECSHOP有如下特点: 1、强大的模版机制 做网站的,做页面是一个头疼的问题。如果每次的小改动都要去改页面模版代码再上传的话,作为商家的你,一定不厌其烦。 ECSHOP结合最流行的AdobeDreamweaver软件实现了一套模版机制,让您改动模版不再需要上传,而是在后台稍稍动动手设置一下就可以了。 2、完全开放的插件机制 支付、配送,这个是商家每天都要面对的功能,如果您现在使用的程序不够开放,那么在您想快速变更所用的支付、配送体系的时候,很可能会拖了后腿。 我们根据自己的长期运营和开发经验,总结出了一套开放、简洁的插件体系,以支持不断变化的支付、配送体系的变更。 届时,您会发现,这块事情将会解除您的忧愁,可以把精力集中在更重要的事情上。 我们同时也以插件形式支持会员整合。迁入、迁出,不再烦恼。 3、功能的AJAX化 当您发现编辑一个商品,需要敲打键盘、挪动鼠标几十下的时候,您是否想到了以后大批量修改的是一个非常恐怖的工作呢? ECSHOP使用目前流行的AJAX技术,为您实现简洁修改,奠定了基础。 同时在更多方面以减轻用户的劳动,提供工作的效率为宗旨,完整的实现了相关功能的AJAX化,由于是在底层完全支持,所以也为以后的扩展打下了基础。 4、促销功能 当您把商品一一上架、却发现没有用户来关心,同样是一个头疼的问题。 那么我们目前在提供了积分、红包、赠品等常规促销手段,更根据自身的电商经验,独家加入了更容易吸引人气的夺宝奇兵促销功能。 把您每月做广告的费用拿出来一点点,变成您所卖的商品,通过夺宝奇兵活动吸引人气、回馈用户,我相信是一个比简单的广而告之更有效的办法。 5、高效率的代码和执行性能 当你浏览自己的网站,发现速度很慢,是不是恨的要全部改成静态页面呢? 其实不然,根据我们长时间的开发经验,动态、静态页面在不同的用途下各擅胜场,但是在有很多个性化功能的前提下,动态的页面要比纯静态的页面好处多多,如果动态页面的URL静态化可以通过REWRITE方式实现,那么剩下就是一个效率问题。 我们也认为,动态页面的瓶颈99%在数据库上,我们通过以往自己的数据库架构设计以及优化经验为基础,设计了目前的ECSHOP数据库结构,并通过缓存机制,实现目前的高效访问。 在不考虑网速的情况下,与纯静态页面相比,您不会感觉到丝毫的差别。我们也会在以后的开发设计中,让目前的架构更加完善、更加高效。 6、常规功能的更完善实现 有些软件的功能虽然不错,但是因为对于用户不够友善,也会让人敬而远之,也往往把客户拒之门外,我们希望能够在常规的功能上,也能为您和您的客户提供更好的用户体验。 7、代码的开源和免费的发展策略 我们认为开源是一个趋势,同时也是一个商业模式。我们也同样认为免费是一个趋势,同时也是一个商业模式。 我们不是说我们不想收费,而是希望在用户能够在提高自身收入和价值的同时,能够让我们之间形成一个双赢的结局。 我们认为的收费应该是以周边服务收费,而不是卖产品本身,所以在这之前我们与广泛的业界同仁进行过充分的交流,对自身是否可以实现这个想法也有一定的考证。 为了您更好的使用ECSHOP,请阅读docs目录下面的相应文档,如果这些文档无法满足您的需要,您可以访问我们的网站获得支持: 1.官方网站:http://www.ecshop.com [增加]增加文章标题的显示长度的设置({$article.short_title}) [增加]管理中心起始页增加安全模式信息的内容 [增加]增加初始化的文件上传目录 [修正]更新cls_sql_executor.php,提高前缀替换、表创建等操作的精确度 [修正]修改复制目录文件的函数 [修正]修改在某些环境下创建目录失败的问题 [修正]修正退款的bug [修正]已知细微Bug的修正及部分代码的优化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值