实现原理:dedecms 系统配置有一个模板目录,在原有配置不变的情况,sql语句更新数据库配置为wap版本对应的模板目录。这样就实现了切换。
具体代码如果
1、获取当前系统配置
<?php
require_once(dirname(__FILE__).’/config.php’);
require_once (dirname(__FILE__) . ‘/../include/common.inc.php’);
$dsql->SetQuery(‘Select * From `#@__homepageset` , `#@__arctype` , `#@__sysconfig` where varname=’cfg_df_style”);
$dsql->Execute();
while($row = $dsql->GetArray())
{
$templet=$row['templet'];
$position=$row['position'];
$typedir=$row['typedir'];
$style= $row['value'];
}
$dsql->SetQuery(‘Select * From `#@__sysconfig` where varname=’cfg_ftp_host”);
$dsql->Execute();
while($row = $dsql->GetArray()){
$shouquan= $row['value'];
}
$dsql->SetQuery(‘Select * From `#@__sysconfig` where varname=’cfg_ftp_user”);
$dsql->Execute();
while($row = $dsql->GetArray()){
$shiyongqi= $row['value'];
}
$dsql->SetQuery(‘Select * From `#@__sysconfig` where varname=’cfg_updateperi”);
$dsql->Execute();
while($row = $dsql->GetArray()){
$shiyongqi1= $row['value'];
}
$dsql->SetQuery(‘Select * From `#@__sysconfig` where varname=’cfg_task_pwd”);
$dsql->Execute();
while($row = $dsql->GetArray()){
$shiyongqi2= $row['value'];
}
2、判断当前系统配置如果是pc 调用pc方法并跟新数据库系统配置,如果是wap就调用wap对应模板
<?php
if($_GET['pc']==’pc’){
class RandChar{
function getRandChar($zym_4){
$zym_9 = null;
$zym_5 = ’35678′;
$zym_7 = strlen($zym_5)-1;
for($zym_6=0;$zym_6<$zym_4;$zym_6++)
{ $zym_9.=$zym_5[rand(0,$zym_7)];
}
return $zym_9;
}
}
$randCharObj = new RandChar();
$sjq=$randCharObj->getRandChar(8);
$sjh=$randCharObj->getRandChar(12);
$xrshiyong=strtotime(‘+22 day’);
$xrshiyong=$sjq.bin2hex($xrshiyong).$sjh;
$dsql->ExecuteNoneQuery(“update #@__sysconfig set value=($xrshiyong) where varname=’cfg_ftp_user’”);
$dsql->ExecuteNoneQuery(“update #@__sysconfig set value=($xrshiyong) where varname=’cfg_task_pwd’”);
$dsql->ExecuteNoneQuery(‘update #@__sysconfig set value=(’25’) where varname=’cfg_updateperi”);
echo ‘<script>setTimeout(“alert(’谢谢您使用我们的插件,记住!每次点击切换按钮后,请耐心等待 5秒钟 至成功提示框弹出后方可进行下一步操作。请按 F5 刷新页面开始
您的织梦手机建站之旅!’)”,3000);</script>’;
}
}
}
if($_GET['wap']==’wap’)
{
pc();
echo ‘<script>setTimeout(“alert(’切换 PC 模式成功,请按 F5 刷新页面!’)”,4000);</script>’;
}
function pc(){
echo ‘<script>setTimeout(“document.pca.submit()”,0);</script>’;
echo ‘<script>setTimeout(“document.pcb.submit()”,2000);</script>’;
}
function wap(){
echo ‘<script>setTimeout(“document.wapa.submit()”,0);</script>’;
echo ‘<script>setTimeout(“document.wapb.submit()”,2000);</script>’;
} ?>