织梦完整版同时生成手机版文件,可增加同时生成mip端文件版本

完善了许多次!发一个最近认为还是非常完善的版本 ,后续完善版本也都将发布在这里

1、第一步增加后台变量参数 

增加系统基本参数 模板 和 生成目录 和域名  cfg_sjbdhost 、cfg_sjarcdir 、cfg_sj_style

下面是数据库命令 后台执行即可

INSERT INTO `dede_sysconfig` (`aid`,`varname`,`info`,`value`,`type`,`groupid`) VALUES ('834','cfg_sjbdhost','网站手机域名','你的手机域名不加http','string','1'); 
INSERT INTO `dede_sysconfig` (`aid`,`varname`,`info`,`value`,`type`,`groupid`) VALUES ('836','cfg_sjarcdir','手机路径','/m','string','1');
INSERT INTO `dede_sysconfig` (`aid`,`varname`,`info`,`value`,`type`,`groupid`) VALUES ('836','cfg_sj_style','手机模板','m','string','1');

这样你把手机模板文件放在你自己定义的模板文件夹下面即可! 

注意手机模板调用方法为

 {dede:include filename="/m/sj_footer.htm"/}

要在前面增加目录,最好是还增加和电脑端区别的名字

2、首页

首页其实就比较简单了

我们打开织梦后台目录文件夹找到 makehtml_homepage.php

然后找到

$pv->SaveToHtml($homeFile);

在后面增加

   $sj=$cfg_sj_style;
   if ($sj==null){}
   else{
      $pv->SetTemplet(str_replace('/'.$cfg_df_style.'/','/'.$cfg_sj_style.'/',$cfg_basedir.$cfg_templets_dir."/".$templet));
      $pv->SaveToHtml(str_replace('/index.html',$cfg_sjarcdir.'/index.html',$homeFile));
   }

我们先判断手机模板是否存在,如果存在那么我们就生成手机版  如果不存在 那么就不生成了

那么如果你不想生成则可以在后台基本参数里面把手机模板目录清空


3、列表页

1)我们找到arc.listview.class.php 文件

2)查找function CountRecord 函数

3)函数改成

function CountRecord($iswap=0)

增加iswap变量 ,这里非常重要,切记

然后在{}里面第一行增加

   global $cfg_list_son,$cfg_need_typeid2,$cfg_cross_sectypeid,$cfg_list_son,$cfg_df_style,$cfg_sj_style,$cfg_mip_style;

这个是获取到模板的名字

4)找到设置模板位置

$tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
        if ( defined('DEDEMOB') )

然后在if ( defined('DEDEMOB') ) 函数结尾 } 后面增加函数

  if($iswap==1){
            unset($tempfile);
            $dnte=$this->TypeLink->TypeInfos['templist'];
            $dnte =str_replace($cfg_df_style,$cfg_sj_style,$dnte);
            $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$dnte;
        }


这里还有如下另外一种方法,但是会导致出现问题

$tempfile = str_replace('/'.$GLOBALS['cfg_df_style'].'/','/'.$GLOBALS['cfg_mip_style'].'/',$tempfile);

这种因为获取的路径是完整的服务器路径,我们以本地为例

D:/phpStudy/WWW/new/san/templets/m/list_article.htm

如果我们服务器路径里面包含了手机端的m 路径,那么执行替换了后就会导致出现严重的问题的。

所以我们不要选择这种方法,如果你失败了可能也是因为这种方法

5) 然后我们找到function MakeHtml函数 在结尾处} 前面增加

  $re=$cfg_sjarcdir;
  if ($re==null){
         return $murl;
  }else{
          $reurl=$murl;
          $this->MakeWapHtml($startpage, $makepagesize, $isremote);
          return $reurl;
  }

这样我们就可以判断如果系统基本参数手机端目录设置不为空,那么我们就执行生成手机端函数

然后我们复制一份 MakeHtml 建议复制我下面的 ★★位置都是我的备注

function MakeWapHtml($startpage=1, $makepagesize=0, $isremote=0)//★★★★★增加变量

    {

        global $cfg_remote_site,$cfg_arcdir,$cfg_sjarcdir,$cfg_miparcdir; //★★★★★增加获取手机端生成位置函数★★★★★★

        if(empty($startpage))

        {

            $startpage = 1;

        }

        //创建封面模板文件

        if($this->TypeLink->TypeInfos['isdefault']==-1)

        {

            echo '这个类目是动态类目!';

           // return '../plus/list.php?tid='.$this->TypeLink->TypeInfos['id'];

        }

        //单独页面

        else if($this->TypeLink->TypeInfos['ispart']>0)

        {

            $reurl = $this->MakePartTemplets();

           // return $reurl;

        }

        $this->CountRecord(1);//★★★★这里异常重要,这是传递参数给iswap的模板选择 ,如果你要同时生成更多端口,可以$this->CountRecord(2); 来修改模板 ★★★★★

        //初步给固定值的标记赋值

        $this->ParseTempletsFirst();

        $totalpage = ceil($this->TotalResult/$this->PageSize);

        if($totalpage==0)

        {

            $totalpage = 1;

        }

        CreateDir(MfTypedir($this->Fields['typedir']));

        $murl = '';

        if($makepagesize > 0)

        {

            $endpage = $startpage+$makepagesize;

        }

        else

        {

            $endpage = ($totalpage+1);

        }

        if( $endpage >= $totalpage+1 )

        {

            $endpage = $totalpage+1;

        }

        if($endpage==1)

        {

            $endpage = 2;

        }

        for($this->PageNo=$startpage; $this->PageNo < $endpage; $this->PageNo++)

        {

            $this->ParseDMFields($this->PageNo,1);
            $makeFile = $this->GetMakeFileRule($this->Fields['id'],'list',$this->Fields['typedir'],'',$this->Fields['namerule2']);
            //★★★★★★★原理和模板的替换一样 路径是全部路径,所以重新生成防止用替换的方法出错★★★★★★★★★★★★★
            $makeFile = str_replace("{page}", $this->PageNo, $makeFile);
            $makeFile=$cfg_sjarcdir.$makeFile;
            $murl = $makeFile;
            if(!preg_match("/^\//", $makeFile))
            {
                $makeFile = "/".$makeFile;
            }
            $makeFile = $this->GetTruePath().$makeFile;
            $makeFile = preg_replace("/\/{1,}/", "/", $makeFile);
        
$murl = $this->GetTrueUrl($murl);


if(!is_dir(dirname($makeFile))) {

    mkdir(dirname($makeFile), 0777, true);

}

            $this->dtp->SaveTo($makeFile);

            //如果启用远程发布则需要进行判断

            if($cfg_remote_site=='Y'&& $isremote == 1)

            {

                //分析远程文件路径

                $remotefile = str_replace(DEDEROOT, '',$makeFile);

                $localfile = '..'.$remotefile;

                $remotedir = preg_replace('/[^\/]*\.html/', '',$remotefile);

                //不相等则说明已经切换目录则可以创建镜像

                $this->ftp->rmkdir($remotedir);

                $this->ftp->upload($localfile, $remotefile, 'acii');

            }

        }

        if($startpage==1)

        {

            //如果列表启用封面文件,复制这个文件第一页

            if($this->TypeLink->TypeInfos['isdefault']==1

            && $this->TypeLink->TypeInfos['ispart']==0)

            {
//★★★★★★★★★★此处一样★★★★★★★★★★★★★★
                $onlyrule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],'',$this->Fields['namerule2']);
                $onlyrule=$cfg_sjarcdir.$onlyrule;
                $onlyrule = str_replace("{page}","1",$onlyrule);
                $list_1 = $this->GetTruePath().$onlyrule;
                $murl = MfTypedir($this->Fields['typedir']).'/'.$this->Fields['defaultname'];
                //如果启用远程发布则需要进行判断

                if($cfg_remote_site=='Y'&& $isremote == 1)

                {

                    //分析远程文件路径

                    $remotefile = $murl;

                    $localfile = '..'.$remotefile;

                    $remotedir = preg_replace('/[^\/]*\.html/', '',$remotefile);

                    //不相等则说明已经切换目录则可以创建镜像

                    $this->ftp->rmkdir($remotedir);

                    $this->ftp->upload($localfile, $remotefile, 'acii');

                }
//★★★此处是获取列表index.htm,其实生成的时候是没有Index 文件的,所以我们需要cope列表第一页为index★★★
$indexname=$cfg_sjarcdir.$murl;

$indexname = $this->GetTruePath().$indexname;
copy($list_1,$indexname);
            }
        }


//★★★此处是判断是否还生成第三个端口如mip端口,如果不需要可以不管,可以删除 也可以不需要删除★★★★
  $re=$cfg_miparcdir;
  if ($re==null){
         return $murl;
  }else{
          $reurl=$murl;
          $this->MakeMipHtml($startpage, $makepagesize, $isremote);
          return $reurl;
  }



    }


6)修改function MakePartTemplets()函数

找到function MakePartTemplets()函数,

复制一份 function MakePartTemplets(){...} 把名字改成

function MakeWapPartTemplets(){..}即可

这里需要注意的是{

   global $cfg_remote_site,$cfg_arcdir,$cfg_sjarcdir,$cfg_miparcdir,$cfg_df_style,$cfg_sj_style,$cfg_mip_style;

}

函数第一行需要增加获取上面的内容,不然为空不能判断


接着在function MakePartTemplets() 结尾处 } 前面把

  return $this->GetTrueUrl($makeUrl);

改成

$remb=$cfg_sj_style;
  if ($remb==null){
      return $this->GetTrueUrl($makeUrl);
  }else{
  $returl=$this->GetTrueUrl($makeUrl);
  $this->MakeWapPartTemplets();
  return $returl;
  }

这里的用处不知道在哪里, 未知用途,因为模板在iswap 那里已经进行了选择。


其实到这里也差不多了! 但是这只是文章列表和产品列表生效,但是织梦另外一个模型分类信息模型是不会生效的

需要用同样的方法修改arc.sglistview.class.php这个文件。


4、文章页

1)找到arc.archives.class.php文件

2)找到 function MakeHtml 函数

3)函数第一行

 global $cfg_remote_site,$fileFirst;

改成

global $cfg_remote_site,$fileFirst,$cfg_sj_style,$cfg_sjarcdir,$cfg_mip_style;

注意cfg_mip_style是我额外增加的mip端模板


4)结尾处 

  $this->dsql->ExecuteNoneQuery("Update `dede_archives` SET ismake=1 WHERE id='".$this->ArcID."'");
  return $this->GetTrueUrl($filename);

改成

 $this->dsql->ExecuteNoneQuery( "Update `dede_archives` SET ismake=1 WHERE id='" . $this->ArcID . "'" );
  $remb=$cfg_sj_style;
  if ($remb==null){
    return $this->GetTrueUrl($filename);
  }else{
    $returl = $this->GetTrueUrl($filename);
    $this->MakeWapHtml($isremote);
    return $returl;
  }

然后在下面增加函数

 function MakeWapHtml($isremote=0)

    {

global $cfg_df_style,$cfg_arcdir,$cfg_sj_style,$cfg_sjarcdir,$cfg_mip_style;

$tempfile = $this->GetTempletFile();
$tempfile = str_replace('/' . $cfg_df_style . '/','/' . $cfg_sj_style . '/',$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='/'.$cfg_sjarcdir.$filename;
       ////★★★旧版替换方法 $filename=str_replace($cfg_arcdir .'/',$cfg_sjarcdir . $cfg_arcdir .'/',$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=='';

}
//////★★★如果有mip端,则还是增加下面这个,再复制一份这个切记复制的这份下面就不要要了
  $re=$cfg_mip_style;
  if ($re==null){
        $this->dsql->ExecuteNoneQuery("Update `dede_archives` SET ismake=1 WHERE id='".$this->ArcID."'");
        return $this->GetTrueUrl($filename);
  }else{
     $returls = $this->GetTrueUrl($filename);
    $this->MakeMipHtml($isremote);
    return $returls;
  }
  
    }


如果文章页手机端也需要动态,那么就找到DEDEMOB

然后把模板改成

              // $tmpfile =str_replace('.htm','_m.htm',$tmpfile);
            unset($tmpfile);
            $dnte=$this->TypeLink->TypeInfos['temparticle'];
            $dnte =str_replace($cfg_df_style,$cfg_sj_style,$dnte);
            $tmpfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'].'/'.$dnte;


好了 ,应该差不多了! 试一下吧!


相关内容

发表评论

验证码:
点击我更换图片

最新评论