发布时间:2016/9/27 9:43:33
dede织梦系统
html编辑器
首先创建手机版的文章模板,这里自己创建,跟其他模板一样,不过保存路径/templets/wap/article_article.htm,详情看前面文章介绍。
首先找到include目录下的arc.archives.class.php,修改文件前最好备份一下,找到函数function MakeHtml($isremote=0),大概在380行左右。函数最后一行代码修改一如下:
$returl=$this->GetTrueUrl($filename);
$this->MakeWapHtml($isremote);
return $returl;
上面增加了$this->MakeWapHtml($isremote);这个就是我们增加的手机版生成静态页函数。具体代码如下:
function MakeWapHtml($isremote=0)
{
$tempfile = $this->GetTempletFile();
$tempfile = str_replace('default','wap',$tempfile);
if(!file_exists($tempfile) !is_file($tempfile))
{
}else{
global $cfg_remote_site,$fileFirst;
if($this->IsError)
{
return '';
}
$this->Fields["displaytype"] = "st";
//预编译$th
$this->dtp->LoadTemplate($tempfile);
$this->TempSource = $this->dtp->SourceString;
$this->ParAddTable();
$this->ParseTempletsFirst();
$this->Fields['senddate'] = empty($this->Fields['senddate'])? '' : $this->Fields['senddate'];
$this->Fields['title'] = empty($this->Fields['title'])? '' : $this->Fields['title'];
$this->Fields['arcrank'] = empty($this->Fields['arcrank'])? 0 : $this->Fields['arcrank'];
$this->Fields['ismake'] = empty($this->Fields['ismake'])? 0 : $this->Fields['ismake'];
$this->Fields['money'] = empty($this->Fields['money'])? 0 : $this->Fields['money'];
$this->Fields['filename'] = empty($this->Fields['filename'])? '' : $this->Fields['filename'];
//分析要创建的文件名称
$filename = GetFileNewName(
$this->ArcID,$this->Fields['typeid'],$this->Fields['senddate'],
$this->Fields['title'],$this->Fields['ismake'],$this->Fields['arcrank'],
$this->TypeLink->TypeInfos['namerule'],$this->TypeLink->TypeInfos['typedir'],$this->Fields['money'],$this->Fields['filename']
);
$filename='/wap'.$filename;
$filename=str_replace('/wap/html/','/wap/',$filename);
$filenames = explode(".", $filename);
$this->ShortName = $filenames[count($filenames)-1];
if($this->ShortName=='') $this->ShortName = 'html';
$fileFirst = preg_replace("/\.".$this->ShortName."$/i", "", $filename);
$this->Fields['namehand'] = basename($fileFirst);
$filenames = explode("/", $filename);
$this->NameFirst = preg_replace("/\.".$this->ShortName."$/i", "", $filenames[count($filenames)-1]);
if($this->NameFirst=='')
{
$this->NameFirst = $this->arcID;
}
//获得当前文档的全名
$filenameFull = GetFileUrl(
$this->ArcID,$this->Fields['typeid'],$this->Fields["senddate"],
$this->Fields["title"],$this->Fields["ismake"],
$this->Fields["arcrank"],$this->TypeLink->TypeInfos['namerule'],$this->TypeLink->TypeInfos['typedir'],$this->Fields["money"],$this->Fields['filename'],
$this->TypeLink->TypeInfos['moresite'],$this->TypeLink->TypeInfos['siteurl'],$this->TypeLink->TypeInfos['sitepath']
);
$this->Fields['arcurl'] = $this->Fields['fullname'] = $filenameFull;
//对于已设置不生成HTML的文章直接返回网址
if($this->Fields['ismake']==-1 $this->Fields['arcrank']!=0 $this->Fields['money']>0
($this->Fields['typeid']==0 && $this->Fields['channel'] != -1) )
{
return $this->GetTrueUrl($filename);
}
//循环生成HTML文件
else
{
for($i=1;$i<=$this->TotalPage;$i++)
{
if($this->TotalPage > 1) {
$this->Fields['tmptitle'] = (empty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']);
if($i>1) $this->Fields['title'] = $this->Fields['tmptitle']."($i)";
}
if($i>1)
{
$TRUEfilename = $this->GetTruePath().$fileFirst."_".$i.".".$this->ShortName;
}
else
{
$TRUEfilename = $this->GetTruePath().$filename;
}
$this->ParseDMFields($i,1);
if(!is_dir(dirname($TRUEfilename))) {
mkdir(dirname($TRUEfilename), 0777, true);
}
$this->dtp->SaveTo($TRUEfilename);
//如果启用远程发布则需要进行判断
if($cfg_remote_site=='Y' && $isremote == 1)
{
//分析远程文件路径
$remotefile = str_replace(DEDEROOT, '', $TRUEfilename);
$localfile = '..'.$remotefile;
//创建远程文件夹
$remotedir = preg_replace("#[^\/]*\.html#", '', $remotefile);
$this->ftp->rmkdir($remotedir);
$this->ftp->upload($localfile, $remotefile, 'ascii');
}
}
}
$this->TempSource=='';
}
}
其中注意代码$tempfile = str_replace('default','wap',$tempfile);这是把pc模板目录替换成手机模板目录,根据自己的目录替换,默认是default。
还有代码
$filename='/wap'.$filename; $filename=str_replace('/wap/html/','/wap/',$filename);
我这里pc端生成静态页面的目录是html,dede织梦系统默认是a目录,根据自己的目录设置,
下面我们就在后台添加一篇文章,看看你的原来静态页面目录和wap目录下是不是同时生成了一个页面。
如果要使手机版打开pc端的静态页自动跳转到手机版的静态页面,只需在pc内容页模板里加上跳转代码。这个前面的一篇关于动态手机版的文章有介绍。
注意自己系统相应的目录与我的目录的区别
注意备份文件,因为目前只是自己测试是没问题