快消品货源批发市场
快消品货源分销平台
 
 
当前位置: 货源批发网 » 网商学院 » 独立商城 » DT(destoon) 标签解析原理

DT(destoon) 标签解析原理

放大字体  缩小字体 发布日期:2024-09-01 07:01:47  来源:电商联盟  作者:乐发网  浏览次数:3

DT(destoon) 标签解析原理
<?php
defined('IN_DESTOON') or exit('Access Denied');


function tag($parameter, $expires = 0) {
// $DT 网站配置
// $CFG 网站配置
// $MODULE 模块配置
// $CATEGORY 当前模块分类信息
// $db 数据库操作对象
// $DCAT ★★★
// $DT_TIME 当前时间戳
global $DT, $CFG, $MODULE, $CATEGORY, $db, $DCAT, $DT_TIME;

// $CATBAK 当前模块的分类信息,作为备份使用
$CATBAK = $CATEGORY ? $CATEGORY : array();

if($expires > 0) {
// TAG(标签)自定义缓存$expires秒;
$tag_expires = $expires;
} else if($expires == -2) {
// SQL查询缓存,数据库缓存
$tag_expires = $CFG['db_expires'];
} else if($expires == -1) {
// TAG(标签)不缓存;
$tag_expires = 0;
} else {
// TAG(标签)默认配置缓存;
$tag_expires = $CFG['tag_expires'];
}

// 定义TAG(标签)缓存的变量
$tag_cache = false;

// 定义SQL查询缓存,数据库缓存的变量
$db_cache = ($expires == -2 || defined('TOHTML')) ? 'CACHE' : '';

// 定义了tag缓存 && 不是SQL查询缓存 && 参数字符串不含有&page=字符串(即列表分页不缓存数据)
if($tag_expires && $db_cache != 'CACHE' && strpos($parameter, '&page=') === false) {
$tag_cache = true;

// tag缓存的文件
$TCF = DT_CACHE.'/tag/'.md5($parameter).'.htm';

// 存在tag缓存文件 并且 缓存文件的生成时间在 TAG(标签)缓存时间的有效时间内,读取缓存文件
if(is_file($TCF) && ($DT_TIME - filemtime($TCF) < $tag_expires)) {
echo substr(file_get($TCF), 17);
return;
}
}

// ★★★
$parameter = str_replace(array('&', '%'), array('', '##'), $parameter);

// 参数1转为变量
parse_str($parameter, $par);

// 空数组,直接返回
if(!is_array($par)) return '';

$par = dstripslashes($par);

extract($par);

######################## 参数 #######################
// 表前缀 无用的代码,呵呵
isset($prefix) or $prefix = $db->pre;
// 模块id
isset($moduleid) or $moduleid = 1;
// 不存在模块,返回
if(!isset($MODULE[$moduleid])) return '';
// fields指查询的字段,默认为*,可以传递例如 fields=title,addtime
isset($fields) or $fields = '*';
// 分类id
isset($catid) or $catid = 0;
// 是否包含分类儿子
isset($child) or $child = 1;
// 地区id
isset($areaid) or $areaid = 0;
// 是否包含地区分类儿子
isset($areachild) or $areachild = 0;
// 定义缓存的目录
isset($dir) or $dir = 'tag';
// tag默认使用list模板
isset($template) or $template = 'list';
// 定义sql条件变量
isset($condition) or $condition = '1';
// 定义group条件变量
isset($group) or $group = '';
// 定义页码变量
isset($page) or $page = 1;
// 定义查询记录条数变量
isset($pagesize) or $pagesize = 10;
// ★★★
isset($update) or $update = 0;
// 定义排序变量
isset($order) or $order = '';
// 定义是否显示分页变量
isset($showpage) or $showpage = 0;
// 定义日期类型变量
isset($datetype) or $datetype = 0;
// 定义链接窗口变量
isset($target) or $target = '';
//
isset($class) or $class = '';
// 定义简介长度变量
isset($length) or $length = 0;
// 定义简介变量
isset($introduce) or $introduce = 0;
// 定义调试变量
isset($debug) or $debug = 0;
// 定义列变量(模板中表格使用)
isset($cols) && $cols or $cols = 1;
// ★★★
isset($DCAT) or $DCAT = array();
if(isset($DCAT[$moduleid])) {
$CATEGORY = $DCAT[$moduleid];
} else {
$CATEGORY = $DCAT[$moduleid] = cache_read('category-'.$moduleid.'.php');
}


if($catid && $moduleid > 4) {
if(is_numeric($catid)) {
$condition .= ($child && $CATEGORY[$catid]['child']) ? " AND catid IN (".$CATEGORY[$catid]['arrchildid'].")" : " AND catid=$catid";
} else {
if($child) {
$_catids = explode(',', $catid);
$catids = '';
foreach($_catids as $_c) {
$catids .= ','.($CATEGORY[$_c]['child'] ? $CATEGORY[$_c]['arrchildid'] : $_c);
}
$catids = substr($catids, 1);
$condition .= " AND catid IN ($catids)";
} else {
$condition .= " AND catid IN ($catid)";
}
}
}

if($areaid) {
$AREA = cache_read('area.php');
if(is_numeric($areaid)) {
$condition .= ($areachild && $AREA[$areaid]['child']) ? " AND areaid IN (".$AREA[$areaid]['arrchildid'].")" : " AND areaid=$areaid";
} else {
if($areachild) {
$_areaids = explode(',', $areaid);
$areaids = '';
foreach($_areaids as $_a) {
$areaids .= ','.($AREA[$_a]['child'] ? $AREA[$_a]['arrchildid'] : $_a);
}
$areaids = substr($areaids, 1);
$condition .= " AND areaid IN ($areaids)";
} else {
$condition .= " AND areaid IN ($areaid)";
}
}
}

// 模块的链接地址
$path = $MODULE[$moduleid]['linkurl'];
// 读取表名
$table = isset($table) ? 1 : get_table($moduleid);
// 起始记录
$offset = ($page-1)*$pagesize;
// 估摸着是在模板中使用,表格使用的
$percent = dround(100/$cols).'%';
// 定义记录数量
$num = 0;
// sql 分组条件
$group = $group ? " GROUP BY $group" : '';
// sql 排序条件
$order = $order ? " ORDER BY $order" : '';
// stripslashes
$condition = stripslashes($condition);
// ★★★
$condition = str_replace('##', '%', $condition);

// ★★★
if($showpage) {
$num = $db->count($table, $condition.$group, $tag_expires ? $tag_expires : $CFG['db_expires']);
if($catid) {
if($page < 3 && $update) update_item($catid, $num);
$pages = listpages($moduleid, $catid, $num, $page, $pagesize, $CATEGORY);
} else {
$pages = pages($num, $page, $pagesize);
}
}

// $template为null,使用SQL查询缓存,数据库缓存
if($template == 'null') $db_cache = 'CACHE';

// sql
$query = "SELECT $fields FROM {$table} WHERe {$condition}{$group}{$order} LIMIT $offset,$pagesize";

// 调试
if($debug) echo $parameter.'<br/>'.$query.'<br/>';

//
$tags = array();

// rs
$result = $db->query($query, $db_cache, $tag_expires);

// rs 2 array
while($r = $db->fetch_array($result)) {
if(isset($r['title'])) {
$r['title'] = str_replace('"', '"', trim($r['title']));
$r['alt'] = $r['title'];
if($length) $r['title'] = dsubstr($r['title'], $length);
if(isset($r['style']) && $r['style']) $r['title'] = set_style($r['title'], $r['style']);
}
if(isset($r['introduce']) && $introduce) $r['introduce'] = dsubstr($r['introduce'], $introduce);
if(isset($r['linkurl']) && $r['linkurl'] && strpos($r['linkurl'], '://') === false) $r['linkurl'] = $path.$r['linkurl'];
$tags[] = $r;
}

// 不tag缓存,返回array
if($template == 'null') {
$CATEGORY = $CATBAK;
return $tags;
}

// 生成tag缓存
if($tag_cache) {
ob_start();
include template($template, $dir);
$contents = ob_get_contents();
ob_clean();
file_put($TCF, '<!--'.($DT_TIME + $tag_expires).'-->'.$contents);
$CATEGORY = $CATBAK;
echo $contents;
// 不tag缓存,返回array
} else {
include template($template, $dir);
$CATEGORY = $CATBAK;
}
}
?>

乐发网超市批发网提供超市货源信息,超市采购进货渠道。超市进货网提供成都食品批发,日用百货批发信息、微信淘宝网店超市采购信息和超市加盟信息.打造国内超市采购商与批发市场供应厂商搭建网上批发市场平台,是全国批发市场行业中电子商务权威性网站。

本文内容整合网站:百度百科知乎淘宝平台规则

本文来源: DT(destoon) 标签解析原理

分享与收藏:  网商学院搜索  告诉好友  关闭窗口  打印本文 本文关键字:
 
更多..资源下载
独立商城图文
独立商城网商学院推荐
独立商城点击排行
 
手机版 手机扫描访问