中药方大全小图标
您当前的位置:首页 > 其他 > 网站日记

jiuhecai谈帝国cms 生成首页函数是怎样的?如何二开?

提示: 阅读权限:公开  来源:jiuhecai  作者:jiuhecai

帝国cms7.2中,jiuhecai做了查找发现,生成首页的函数很多啊。大概有五个地方出现呵呵。

第一个地方,后台编辑用的

//函数hreindex位于文件/e/class/hinfofun.php中
//增加信息生成首页
function hReIndex()
	$indextemp=GetIndextemp();
	NewsBq($classid,$indextemp,1,0);
}

还有呢:前台投稿也需要生成首页啊

//函数QReIndex位于文件/e/class/qinfofun.php#中。
//投稿生成首页
function QReIndex()
	$indextemp=GetIndextemp();
	NewsBq($classid,$indextemp,1,0);
}

当当当当,正宫娘娘来了,后台刷新首页的:

//函数ReIndex位于文件/e/class/jhcchtmlfun.php中。
//刷新首页
function ReIndex()
	$indextemp=GetIndextemp();//取得模板
	NewsBq($classid,$indextemp,1,0);
	insert_dolog("");//操作日志
	printerror("ReIndexSuccess","history.go(-1)");
}

这算最牛逼的,因为有仪仗队啊,写了操作日记,返回了操作结果。

第四个地方,setnews.php中

//函数setenews位于文件/e/admin/SetEnews1.php中。
//参数设置
function SetEnews($add,$userid,$username)
	global $empire,$dbtbpre;
	...
	DelFiletext(ECMS_PATH.'index.php');
			$indextemp=GetIndextemp();
			NewsBq(0,$indextemp,1,0);
			...

第五个地方,定时刷新里肯定少不了啊:

//函数DoTimeRepage位于文件/e/admin/DoTimeRepage.php中。
//定时刷新任务
function DoTimeRepage($time)
	global $empire,$dbtbpre;
	if(empty($time))
	{$time=120;}
	...
	else//生成首页
		{
			$indextemp=GetIndextemp();
			NewsBq($classid,$indextemp,1,0);

	    }...

 

可见,生成首页分两步,第一步获取模板,用getindextemp函数

//函数GetIndextemp位于文件/e/class/functions.php中。
//取得首页模板
function GetIndextemp()
	global $empire,$dbtbpre,$public_r;
	if($public_r['indexpageid'])
	{
		$r=$empire->fetch1("select temptext from {$dbtbpre}enewsindexpage where tempid='".$public_r['indexpageid']."'");
		return $r['temptext'];
	}
	$r=$empire->fetch1("select indextemp from ".GetTemptb("enewspubtemp")." limit 1");
	return $r['indextemp'];
}

第二步,用NewsBq函数,第一个参数为0,第二个参数为模板字符串,第三个参数确保为1,第四个为0

 

现在,jiuhecai要装逼了,希望在刷新主端首页的时候,也同时刷新手机端的首页,我们就在这个函数中插入好了

//取得首页模板
function GetIndextemp(){
	global $empire,$dbtbpre,$public_r;
	//jiuhecai add
	jhcShuaXin(__FUNCTION__,func_get_args(),2);
	//jiuhecai add end
	if($public_r['indexpageid'])
	{
		$r=$empire->fetch1("select temptext from {$dbtbpre}enewsindexpage where tempid='".$public_r['indexpageid']."'");
		return $r['temptext'];
	}
	$r=$empire->fetch1("select indextemp from ".GetTemptb("enewspubtemp")." limit 1");
	return $r['indextemp'];
}

jhcShuaXin是我写的自定义函数,放到了eclassfunctions.php的最后

//多端刷新函数 by jiuhecai
function jhcShuaXin($act,$args,$en){
    global $emoreport_r,$public_r;
    if(!$public_r['add_tongBuRe'])return '';
    $jhcr[action]=$act;
    $jhcr[canshu]=$args;
    $jhcr[en]=$en;
    $jhcr[purl]=$emoreport_r[$en][purl].'e/extend/jhcshua/index.php';
    $jhcr[postpass]=$emoreport_r[$en][postpass];
    $data[token]=md5(json_encode($jhcr));
    unset($jhcr[postpass]);
    $data[data]=json_encode($jhcr);
    $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $jhcr['purl']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch,CURLOPT_TIMEOUT,60); //定义超时60秒钟 
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        $output = curl_exec($ch);
        $errorCode = curl_errno($ch);
    curl_close($ch);
    if(0 !== $errorCode) {
        //return false;
        return $errorCode;
    }
    return $output;
}

在手机端的e/extend/jhcshua/index.php文件中,处理下这个请求:

<?php
define('EmpireCMSAdmin','1');
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../class/functions.php");
require("../../data/dbcache/class.php");
require("../../class/t_functions.php");
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
//验证用户
$token=$_POST[token];
$jhcr=json_decode($_POST[data],true);
$en=$jhcr[en];
$jhcr[postpass]=$emoreport_r[$en][postpass];
if($token!==md5(json_encode($jhcr)))exit(false);
// print_r($jhcr);

switch($jhcr[action]){
    case 'GetHtml':
        GetHtml($jhcr[canshu][0],$jhcr[canshu][1],'',0,1);//生成信息文件
        exit("ok");
        break;
    case 'GetIndextemp':  
        $indextemp=GetIndextemp();
	    NewsBq(0,$indextemp,1,0); //刷新首页
        exit("ok");
        break;
}
echo "shibai";
exit;

 

这样,就轻松完成了,多端首页的同步刷新。

 

同理,在主端的functions.php中的gethtml里插入同样的一条语句,就实现了信息的同步刷新。函数里的2,表示手机端的id

//生成内容文件
function GetHtml($classid,$id,$add,$ecms=0,$doall=0){
	global $public_r,$class_r,$class_zr,$fun_r,$empire,$dbtbpre,$emod_r,$class_tr,$level_r,$etable_r;
	//jiuhecai add
	jhcShuaXin(__FUNCTION__,func_get_args(),2);
	//jiuhecai add end
	$mid=$class_r[$classid]['modid'];
	...

再接再厉,列表页的刷新,查到用到的函数是ListHtml,她也在functions.php中。

二话不说,也是插入一条语句:jhcShuaXin(__FUNCTION__,func_get_args(),2);结果就成了:

//生成信息列表
function ListHtml($classid,$fields,$enews=0,$userlistr=""){
	global $empire,$dbtbpre,$emod_r,$public_r,$class_r,$class_zr,$fun_r,$class_tr,$level_r,$etable_r;
	jhcShuaXin(__FUNCTION__,func_get_args(),2);//add by jiuhecai
	...

对应的,手机端的e/extend/jhcshua/index.php文件中要接应下,函数名是ListHtml,修改后是这样的:

<?php
define('EmpireCMSAdmin','1');
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../class/functions.php");
require("../../data/dbcache/class.php");
require("../../class/t_functions.php");
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
//验证用户
$token=$_POST[token];
$jhcr=json_decode($_POST[data],true);
$en=$jhcr[en];
$jhcr[postpass]=$emoreport_r[$en][postpass];
if($token!==md5(json_encode($jhcr)))exit(false);
//分类刷新
switch($jhcr[action]){
    case 'GetHtml':
        GetHtml($jhcr[canshu][0],$jhcr[canshu][1],'',0,1);//生成信息文件
        break;
    case 'GetIndextemp':  
        $indextemp=GetIndextemp();
	    NewsBq(0,$indextemp,1,0); //刷新首页
        break;
    case 'ListHtml':
        ListHtml($jhcr[canshu][0],$jhcr[canshu][1],$jhcr[canshu][2],$jhcr[canshu][3]);//刷新列表
        break;
    default:
        exit('0');
}
exit(1);

临汾早晨也是这么闷热,真实秋后一伏,热老牛。帝国cms7.2的手机端列表页的同步更新搞定了。可以外出散步了。

 

 

tags: 帝国cms 生成 帝国
返回顶部
推荐资讯
视频:田纪钧讲关节不痛的秘密、膝关节拉筋法
视频:田纪钧讲关节不
白露到了,你还好吗?
白露到了,你还好吗?
尿疗与断食
尿疗与断食
给风疹反复发作女孩的药方(组图)
给风疹反复发作女孩的
相关文章
栏目更新
栏目热门
  1. 帝国cms全站搜索的分页格式如何修改-流程
  2. libreoffice7的命令大全
  3. 帝国cms插件之标题生成标题图片
  4. 帝国cms插件安装模板
  5. useragent两千条,爬虫专用
  6. 帝国cms插件如何兼容gbk和utf8
  7. 帝国cms插件之迅搜
  8. 帝国cms用户上传文件名的命名规则及修改方
  9. 帝国cms7.2函数大全
  10. 帝国cms代码片段备忘录