第一步,主端-添加一个扩展变量 tongBuRe ,写入内存,作为同步刷新的开关,为1开,为0关。
第二步,主端-修改文件 e/class/functions.php,在尾部附加一个新的函数
- //多端刷新函数
- function shuaxin($act,$args,$en){
- global $emoreport_r,$public_r;
- if(!$public_r['add_tongBuRe'])return '';
- $shuaxin['action']=$act;
- $shuaxin['canshu']=$args;
- $shuaxin['en']=$en;
- $shuaxin['purl']=$emoreport_r[$en]['purl'].'e/extend/shuaxin/index.php';
- $shuaxin['postpass']=$emoreport_r[$en]['postpass'];
- $data['token']=md5(json_encode($shuaxin));
- unset($shuaxin['postpass']);
- $data['data']=json_encode($shuaxin);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $shuaxin['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 $errorCode;
- }
- return $output;
- }
第三步,还是这个文件,把这么一句
- shuaxin(__FUNCTION__,func_get_args(),2);
插入到这个文件的三个地方。
(1)同步首页
- function GetIndextemp(){
(2)同步内容页
- function GetHtml($classid,$id,$add,$ecms=0,$doall=0){
(3)同步列表页
- function ListHtml($classid,$fields,$enews=0,$userlistr=""){
(4) 同步索引类信息列表
- function ListHtmlIndex($classid,$fields,$enews=0,$userlistr=""){
另外,对于文件 /e/class/hinfofun.php 查找
- function AddInfoToReHtml($classid,$dore){
在其后插入:
- shuaxin(__FUNCTION__,func_get_args(),2);
希望在刷新主端首页的时候,也同时刷新手机端的首页,我们就在这个函数中插入好了!其他同理。
- //取得首页模板
- function GetIndextemp(){
- global $empire,$dbtbpre,$public_r;
- // add
- shuaxin(__FUNCTION__,func_get_args(),2);
- //jadd 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'];
- }
最后在手机端的e/extend/shuaxin/index.php文件中,处理下这个请求:
这样简单的修改后,就可以实现帝国cms7.x的多端同步生成。
- <?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");
- require "../".LoadLang("pub/fun.php");
- require("../../class/delpath.php");
- require("../../class/copypath.php");
- require("../../data/dbcache/MemberLevel.php");
- //会员
- //require("../member/class/user.php");
- require("../../class/hinfofun.php");
- $link=db_connect();
- $empire=new mysqlquery();
- $editor=1;
- //验证用户
- $token=$_POST['token'];
- $shuaxin=json_decode($_POST['data'],true);
- //en 为多端id
- $en=$shuaxin['en'];
- $shuaxin['postpass']=$emoreport_r[$en]['postpass'];
- if($token!==md5(json_encode($shuaxin)))exit(false);
- //分类刷新
- switch($shuaxin['action']){
- case 'GetHtml':
- GetHtml($shuaxin['canshu'][0],$shuaxin['canshu'][1],'',0,1);//生成信息文件
- break;
- case 'GetIndextemp':
- $indextemp=GetIndextemp();
- NewsBq(0,$indextemp,1,0); //刷新首页
- break;
- case 'ListHtml':
- ListHtml($shuaxin['canshu'][0],$shuaxin['canshu'][1],$shuaxin['canshu'][2],$shuaxin['canshu'][3]);//刷新列表
- break;
- case 'ListHtmlIndex':
- ListHtmlIndex($shuaxin['canshu'][0],$shuaxin['canshu'][1],$shuaxin['canshu'][2],$shuaxin['canshu'][3]);//刷新索引类信息列
- case 'ReListHtml':
- ReListHtml($shuaxin['canshu'][0],$shuaxin['canshu'][1]);//刷新信息列表
- break;
- case 'AddInfoToReHtml':
- AddInfoToReHtml($shuaxin['canshu'][0],$shuaxin['canshu'][1]);
- break;
- default:
- exit('0');
- }
- exit(1);