0
点赞
收藏
分享

微信扫一扫

ecshop index.php源代码分析

云朵里的佛光 2022-08-22 阅读 143

<?php 

// 根据某人的说法, 挂个鸟牌.
define('IN_ECS', true);
// 引入内核文件
require(dirname(__FILE__) . '/includes/init.php');

// DEBUG_MODE在init.php中定义了0,根据常量不可重复定义的原则, 估计下面的判断永远都将是真.即不需要更新缓存.
// $smarty->caching 为true时, 表示不强制更新缓存.
if ((DEBUG_MODE & 2) != 2){
$smarty->caching = true;
}

/*------------------------------------------------------ */
//-- 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: $Loactionn");

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']); // 当前位置


作者:沐雪

文章均系作者原创或翻译,如有错误不妥之处,欢迎各位批评指正。本文版权归作者所有,如需转载恳请注明。
​​​ 为之网-热爱软件编程 http://www.weizhi.cc/​​


举报

相关推荐

0 条评论