最近由于做网站的需要,想加入浏览历史记录。在帝国里面找到了这个实现代码,没有做特别的改动,只是想把他实现出来,但是作者没有说明。这里做一下记录。
附原作者的链接:http://bbs.phome.net/ShowThread?threadid=294140&forumid=31
按下面的步骤来操作
第一步:先把内部代码放入userfun.php中,代码如下:
//---------------------------浏览历史记录函数
function user_SetCook($name,$id,$time=0,$num=10){//cookie名称 ID 时间戳 数量
global $empire,$dbtbpre;
$r=$empire->fetch1("select * from {$dbtbpre}ecms_news where id=$id");
if(!$id||!$r['id']){
printerror2('不存在的产品记录',$_SERVER['HTTP_REFERER']);
}
$prodq=$id.'|';
$projilu=getcvar($name);
if($projilu){
$prozuhe=$prodq.$projilu;//把新浏览的放在第一
$pro_arr=explode('|',$prozuhe);
$new_arr=array_merge(array_unique($pro_arr));//去除重复,重新索引下标
foreach($new_arr as $key=>$val){
if(($key
$pro.=$val.'|';
}
}
}else{
$pro=$prodq;
}
esetcookie($name,$pro,$time);
//esetcookie($name,'',0);
//print_r($_COOKIE);
}
//---------------------------浏览历史输出函数
function user_GetCook($name,$tbname,$num=10){ //名称 数据表 数量
global $empire,$dbtbpre;
if(preg_match("/^[0-9\|]+$/",getcvar($name))){
$jilu_all=substr(getcvar($name),0,-1); //1|2|3
$jilu_idin=str_replace('|',',',$jilu_all);//1,2,3
}else{
$jilu_idin=0;//避免sql错误没有返回0
}
$sql=$empire->query("select id,title,titlepic,titleurl from {$dbtbpre}ecms_{$tbname} where id in ({$jilu_idin}) order by find_in_set(id,'{$jilu_idin}') limit {$num}"); //按id in 里面的排序
while($jilu_r=$empire->fetch($sql))
{
$titleurl=sys_ReturnBqTitleLink($jilu_r);
echo '
'.$jilu_r[title].'';//此处是修改样式需要图片自己加}
}
?>
上面的代码放入e/class/userfun.php中
第二步:复制代码另存为xxx.php文件,以下是实现代码
html, body, div, ul, ol, li, dl, dt, dd, h1, h2, h3, h4, h5, h6, pre, form, p, blockquote, fieldset, input {margin: 0;padding: 0}
h1, h2, h3, h4, h5, h6, pre, code, address, caption, cite, code, em, strong, th {font-size: 1em;font-weight: normal;font-style: normal}
strong{ font-weight:bold}
address, caption, cite, code, dfn, em, i, th, var, b {
font-style: normal;
font-weight: normal;
}
ul,li, ol {list-style: none}
fieldset, img {border: none}
caption, th {text-align: left}
table { border-collapse: collapse; border-spacing: 0; }
/* LAYOUT */
.clear {clear: both}
a { color: #4a4a4a}
a:link, a:visited, a:active {text-decoration: none}
a:hover {text-decoration: underline;color:#2a609f}
div a:hover {
color: #FF5A5A;
}
body {
font: 12px/18px "Lucida Grande", "Lucida Sans Unicode", Arial, Verdana, sans-serif;
color: #4a4a4a;
}
div{
float: left;
width: 160px;
overflow: hidden;
}
div:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
div strong {
display: block;
font-size: 14px;
color: #999999;
margin: 5px 0 15px 0;
font-weight: bold;
}
div a {
margin: 0 10px 10px 0;
float: left;
display: block;
color: #666666;
border: 1px solid #dbdbdb;
background: #fbfbfb;
font-size: 12px;
font-weight: normal;
padding: 1px 6px;
-webkit-box-shadow: 1px 1px 2px #dbdbdb;
-moz-box-shadow: 1px 1px 2px #dbdbdb;
box-shadow: 1px 1px 2px #dbdbdb;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
word-wrap: normal;
word-break: keep-all;
}
浏览历史
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../class/userfun.php");
$link=db_connect();
$empire=new mysqlquery();
$id=(int)$_GET['id'];
user_SetCook('cookiepro',$id,0,10);//cookie名称可以自己定别重复 ID 时间戳 数量
user_GetCook('cookiepro','news',10);//字段是news
db_close();
$empire=null;
?>
保存为PHP文件比如xxx.php,放入e/public/ViewClick,文件夹中
第三步,把下面的代码放入内容页面。请注意,字段我是放新闻字段'news',所以内容页必须是新闻字段的内容页才行。修改字段可以放其他页面,比如商城,软件栏目等内容页面下。
function reinitIframe(){
var iframe = document.getElementById("ifm");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}catch (ex){}
}
window.setInterval("reinitIframe()", 200);
放入你要放的位置,js代码是iframe自适应代码。不放入这段代码有可能不能适应高度。
我自己做的一些教程
1\每分钟自动更新生成一次内容页
http://bbs.phome.net/ShowThread?threadid=305894&forumid=31
2\微博群发插件,支持28个微博平台,支持定时发布
http://bbs.phome.net/ShowThread?threadid=304982&forumid=31
3\帝国短网址插件
http://bbs.phome.net/ShowThread?threadid=304088&forumid=31
4\把 网 站 的 图 片 批 量 放 云 服 务 器
http://www.dwz.cn/bxuRG
5\使用谷歌DOCS定时自动更新你的网站
http://bbs.phome.net/ShowThread?threadid=306593&forumid=31
上传以下附件:
[下载 *.rar](文件大小:2.87 KB,下载次数:137)