易优EyouCMS手机端url路径改为/mobile/方案(非自带m.xxx.com二级域名方案)

易优EyouCMS手机端url路径改为www.xxx.com/mobile/的方案

二次开发步骤

开发背景和剧情摘要

· Eyou是一款很他娘不错的内容管理系统,基于PHP的TP5框架开发,有着小而轻的特色,非常适合做为企业网站以及轻量级平台的网站内容管理系统,相比织梦、帝国、V9这些老前辈,在界面、安全、操作度方便都有着很不错的提升,用了这么多的CMS,最终把橄榄枝抛给易优了。
·然鹅,毕竟是年轻团队产品,还有很多功能没有开发,也有一堆的小毛病,让你有时候相当的束缚手脚,就比如今天要说的手机端URL的问题
·目前易优的手机端URL,要么是响应式的,要么就是后台给了一个m.xxx.com的二级域名格式,难道他们就不知道还有很多企业站或者优化站是www.xxx.com/mobile的子目录格式吗?也曾经在易优的官网论坛反馈过,也在群建议过,不过官方好像不怎么鸟,等了好久,也没有见相关功能更新,也等不了,决定二开,请教了一位老司机同事花了挺久时间解决,方案分享!
·本教程开发背景:EyouCMS-V1.4.7-UTF8-SP2,WNMP环境,PHP7.3.4,MySQL5.8

步骤1:路由url更改

1.1 :\application\route.php文件
1.1.1 :大概第49行
$tpldirList = ["template/{$web_tpl_theme}pc","template/{$web_tpl_theme}mobile"];
改为
$tpldirList = ['template/pc','template/mobile'];
1.1.2 :大概第60行
if (1 == $response_type && empty($globalTpCache['web_mobile_domain']) && isMobile()) {
    $separate_mobile = 1;
}
这段代码注释掉
1.2 :\application\admin\template\system\web.htm文件
1.2.1 :大概第197行
<dl class="row">
                <dt class="tit" style="width: auto">
                    <label><b>自定义变量</b></label>
                    &nbsp;&nbsp;<a href="javascript:void(0);" onclick="customvar_index(this);">[管理]</a>
                </dt>
</dl>

改为

<dl class="row">
          <dt class="tit">
              <label for="web_mobile_cat">手机端静态目录</label>
          </dt>
          <dd class="opt ui-keyword">
              <input id="web_mobile_cat" name="web_mobile_cat" value="{$config.web_mobile_cat|default=''}" class="input-txt" type="text" />
              <p class="notic"></p>
          </dd>
          {eq name="$web_cmsmode" value="2"}
          <dd class="variable">
              <div><p>web_mobile_cat</p></div>
              <div class="r"><a href="javascript:void(0);" onclick="showtext('web_mobile_cat');" class="ui-btn3 blue web_mobile_cat" data-clipboard-text="{literal}{eyou:global name='web_mobile_cat' /}{/literal}">复制标签</a></div>
          </dd>
          {/eq}
       </dl>
<dl class="row">
           <dt class="tit" style="width: auto">
               <label><b>自定义变量</b></label>
               &nbsp;&nbsp;<a href="javascript:void(0);" onclick="customvar_index(this);">[管理]</a>
           </dt>
</dl>

步骤2: 处理生成首页

2.1:\application\home\controller\Buildhtml.php文件,静态页生成器的改动
2.1.1 : 大概第185行

也就是在$msg .= '<span>index.html生成成功</span><br>';}catch(\Exception $e)之间添加代码:

if ($mobile=$this->issetMobile()) {
                // 还要生成到手机端目录
                $mobile_savepath = './'.$mobile.substr($savepath,1);
                $this->filePutContents($mobile_savepath, $tpl, 'mobile', 0, '/', 0, 1, $result);
}
2.1.2 :大概第107行:
$templateConfig['view_path'] = "./template/".TPL_THEME."pc/";
改为
$templateConfig['view_path'] = "./template/{$model}/";
2.1.3 : 大概第141行:
$content = $this->pc_to_mobile_js($content, $result); // 生成静态模式下,自动加上PC端跳转移动端的JS代码
改为
if ($model=='pc'){
    $content = $this->pc_to_mobile_js($content, $result); // 生成静态模式下,自动加上PC端跳转移动端的JS代码
}
2.1.4 : 大概第333行

也就是'view_' . $result['nid'];下面添加代码:

// 手机端若有单独的模板
$tpl_mobile = !empty($result['tempview_mobile']) ? str_replace('.'.$this->view_suffix, '',$result['tempview_mobile']):$tpl;
2.1.5 :大概第345行

也就是在$this->filePutContents('./' . $savepath, $tpl, 'pc', 0, '/', 0, 1, $result);下面添加代码

if ($mobile=$this->issetMobile()) {
                // 还要生成到手机端目录
                $mobile_savepath = './'.$mobile.'/'.$savepath;
                $this->filePutContents($mobile_savepath, $tpl_mobile, 'mobile', 0, '/', 0, 1, $result);
            }
2.1.6 :大概第505行

也就是在$tpl = !empty($row['templist']) ? str_replace('.' . $this->view_suffix, '', $row['templist']) : 'lists_' . $row['nid'];下面添加代码:

// 手机端若有单独的模板
$tpl_mobile = !empty($row['templist_mobile']) ? str_replace('.'.$this->view_suffix, '',$row['templist_mobile']) : $tpl;
2.1.7 :大概第513行
$savepath = '.' . $seo_html_arcdir . '/' . $dirpath[1] . "/lists_" . $eyou['field']['typeid'] . ".html";
改为
$savepath='/'.$dirpath[1]."/lists_".$eyou['field']['typeid'].".html";
2.1.8 :大概第515行
$savepath = '.' . $seo_html_arcdir . '/' . $dirpath_end . "/lists_" . $eyou['field']['typeid'] . ".html";
改为
$savepath='/'.$dirpath_end."/lists_".$eyou['field']['typeid'].".html";
2.1.9 :大概第519行

也就是在try { $this->filePutContents($savepath, $tpl, 'pc', 0, '/', 0, 1, $row);前面插入代码:

$savepath  = '.'.$seo_html_arcdir.$savepath;
2.1.10 :大概第526行

也就是在@copy($savepath, '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/index.html'); @unlink($savepath); }} catch (\Exception $e) {之间添加代码

if ($mobile=$this->issetMobile()) {
                    // 还要生成到手机端目录
                    substr($savepath,0,1)=='.'?$savepath=substr($savepath,1):'';
                    $mobile_savepath = '.'.$seo_html_arcdir.'/'.$mobile.$savepath;
                    $this->filePutContents($mobile_savepath, $tpl_mobile, 'mobile', 0, '/', 0, 1, $row);
                    if ($seo_html_listname == 3) {
                        @copy($mobile_savepath,'.'.$seo_html_arcdir.'/'.$mobile.'/'.$dirpath_end.'/index.html');
                        @unlink($mobile_savepath);
                    } else if ($seo_html_listname == 2 || count($dirpath) < 3){
                        @copy($mobile_savepath,'.'.$seo_html_arcdir.'/'.$mobile.$eyou['field']['dirpath'].'/index.html');
                        @unlink($mobile_savepath);
                    }
                }
2.1.11 :大概第552行
$msg     .= $this->createMultipageChannel($i, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl);
改为
$msg .= $this->createMultipageChannel($i,$tid,$row,$has_children_Row,$seo_html_listname,$seo_html_arcdir,$tpl,$tpl_mobile);
2.1.12 :大概第557行
$msg .= $this->createMultipageChannel($i, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl);
改为
$msg .= $this->createMultipageChannel($i,$tid,$row,$has_children_Row,$seo_html_listname,$seo_html_arcdir,$tpl,$tpl_mobile);
2.1.13 :针对创建有文档列表模型的静态栏目页面这段功能代码的更改:
private function createMultipageChannel($i, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl)
    {
        $msg = "";
        $this->request->get(['page' => $i]);
        $row        = $this->lists_logic($row, $has_children_Row);  // 模型对应逻辑
        $eyou       = array(
            'field' => $row,
        );
        $this->eyou = array_merge($this->eyou, $eyou);
        $this->assign('eyou', $this->eyou);
        $dirpath     = explode('/', $eyou['field']['dirpath']);
        $dirpath_end = end($dirpath);
        if ($seo_html_listname == 1) {  //存放顶级目录
            $dir      = '.' . $seo_html_arcdir . '/' . $dirpath[1];
            $savepath = '.' . $seo_html_arcdir . '/' . $dirpath[1] . "/lists_" . $eyou['field']['typeid'];
        } else if ($seo_html_listname == 3) { //存放子级目录
            $dir      = '.' . $seo_html_arcdir . '/' . $dirpath_end;
            $savepath = '.' . $seo_html_arcdir . '/' . $dirpath_end . "/lists_" . $eyou['field']['typeid'];
        } else {
            $dir      = '.' . $seo_html_arcdir . $eyou['field']['dirpath'];
            $savepath = '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/' . 'lists_' . $eyou['field']['typeid'];
        }
        if ($i > 1) {
            $savepath .= '_' . $i . '.html';;
        } else {
            $savepath .= '.html';
        }
        $top = 1;
        if ($i > 1 && $seo_html_listname == 1 && count($dirpath) > 2) {
            $top = 2;
        } else if ($i > 1 && $seo_html_listname == 3) {
            $top = 1;
        }
        try {
            $this->filePutContents($savepath, $tpl, 'pc', $i, $dir, $tid, $top, $row);
            if ($i == 1 && $seo_html_listname == 3) {
                @copy($savepath, '.' . $seo_html_arcdir . '/' . $dirpath_end . '/index.html');
                @unlink($savepath);
            } else if ($i == 1 && ($seo_html_listname == 2 || count($dirpath) < 3)) {
                @copy($savepath, '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/index.html');
                @unlink($savepath);
            }
        } catch (\Exception $e) {
            $msg .= '<span>' . $savepath . '生成失败!' . $e->getMessage() . '</span><br>';
        }

        return $msg;
    }

改为

private function createMultipageChannel($i,$tid,$row,$has_children_Row,$seo_html_listname,$seo_html_arcdir,$tpl,$tpl_mobile){
        $msg = "";
        $this->request->get(['page'=>$i]);
        $row = $this->lists_logic($row, $has_children_Row);  // 模型对应逻辑
        $eyou = array(
            'field' => $row,
        );
        $this->eyou = array_merge($this->eyou, $eyou);
        $this->assign('eyou', $this->eyou);
        $dirpath = explode('/',$eyou['field']['dirpath']);
        $dirpath_end = end($dirpath);
        if($seo_html_listname == 1){  //存放顶级目录
            $dir = '.'.$seo_html_arcdir.'/'.$dirpath[1];
            $savepath  = '.'.$seo_html_arcdir.'/'.$dirpath[1]."/lists_".$eyou['field']['typeid'];
        } else if ($seo_html_listname == 3) { //存放子级目录
            $dir = '.'.$seo_html_arcdir.'/'.$dirpath_end;
            $savepath  = '.'.$seo_html_arcdir.'/'.$dirpath_end."/lists_".$eyou['field']['typeid'];
        }else{
            $dir = '.'.$seo_html_arcdir.$eyou['field']['dirpath'];
            $savepath  = '.'.$seo_html_arcdir.$eyou['field']['dirpath'].'/'.'lists_'.$eyou['field']['typeid'];
        }
        if ($i > 1){
            $savepath .= '_'.$i.'.html';;
        }else{
            $savepath .= '.html';
        }
        $top = 1;
        if ($i > 1 && $seo_html_listname == 1 && count($dirpath) >2) {
            $top = 2;
        } else if ($i > 1 && $seo_html_listname == 3) {
            $top = 1;
        }
        try{
            $this->filePutContents($savepath, $tpl, 'pc', $i, $dir, $tid, $top, $row);
            if ($i==1 && $seo_html_listname == 3) {
                @copy($savepath,'.'.$seo_html_arcdir.'/'.$dirpath_end.'/index.html');
                @unlink($savepath);
            } else if ($i==1 && ($seo_html_listname == 2 || count($dirpath) < 3)){
                @copy($savepath,'.'.$seo_html_arcdir.$eyou['field']['dirpath'].'/index.html');
                @unlink($savepath);
            }
            
                if ($mobile=$this->issetMobile()) {
                    // 还要生成到手机端目录
                    $mobile_savepath = './'.$mobile.substr($savepath,1);
                    $mobile_dir = './'.$mobile.substr($dir,1);
                    $this->filePutContents($mobile_savepath, $tpl_mobile, 'mobile', $i, $mobile_dir, $tid, $top, $row);
                    if ($i==1 && $seo_html_listname == 3) {
                        @copy($mobile_savepath,'.'.$seo_html_arcdir.'/'.$mobile.'/'.$dirpath_end.'/index.html');
                        @unlink($mobile_savepath);
                    } else if ($i==1 && ($seo_html_listname == 2 || count($dirpath) < 3)){
                        @copy($mobile_savepath,'.'.$seo_html_arcdir.'/'.$mobile.$eyou['field']['dirpath'].'/index.html');
                        @unlink($mobile_savepath);
                    }
                }

        }catch(\Exception $e){
            $msg .= '<span>'.$savepath.'生成失败!'.$e->getMessage().'</span><br>';
        }
        return $msg;
    }
2.1.14 :针对拓展页面相关信息这段功能代码的更改
private function lists_logic($result = [], $has_children_Row = [])
    {
        if (empty($result)) {
            return [];
        }

        $tid = $result['typeid'];

        switch ($result['current_channel']) {
            case '6': // 单页模型
                {
                    $arctype_info = model('Arctype')->parentAndTopInfo($tid, $result);
                    if ($arctype_info) {
                        // 读取当前栏目的内容,否则读取每一级第一个子栏目的内容,直到有内容或者最后一级栏目为止。
                        $archivesModel = new \app\home\model\Archives();
                        $result_new = $archivesModel->readContentFirst($tid);
                        // 阅读权限 或 外部链接跳转
                        if ($result_new['arcrank'] == -1 || $result_new['is_part'] == 1) {
                            return false;
                        }
                        /*自定义字段的数据格式处理*/
                        $result_new = $this->fieldLogic->getChannelFieldList($result_new, $result_new['current_channel']);
                        /*--end*/

                        $result = array_merge($arctype_info, $result_new);

                        $result['templist'] = !empty($arctype_info['templist']) ? $arctype_info['templist'] : 'lists_' . $arctype_info['nid'];
                        $result['dirpath']  = $arctype_info['dirpath'];
                        $result['typeid']   = $arctype_info['typeid'];
                    }
                    break;
                }

            default:
                {
                    $result = model('Arctype')->parentAndTopInfo($tid, $result);
                    break;
                }
        }

        if (!empty($result)) {
            /*自定义字段的数据格式处理*/
            $result = $this->fieldLogic->getTableFieldList($result, config('global.arctype_channel_id'));
            /*--end*/
        }

        /*是否有子栏目,用于标记【全部】选中状态*/
        $result['has_children'] = !empty($has_children_Row[$tid]) ? 1 : 0;
        /*--end*/

        // seo
        $result['seo_title'] = set_typeseotitle($result['typename'], $result['seo_title']);

        /*获取当前页面URL*/
        $result['pageurl'] = $result['typeurl'];
        /*--end*/

        /*给没有type前缀的字段新增一个带前缀的字段,并赋予相同的值*/
        foreach ($result as $key => $val) {
            if (!preg_match('/^type/i', $key)) {
                $key_new = 'type' . $key;
                !array_key_exists($key_new, $result) && $result[$key_new] = $val;
            }
        }
        /*--end*/

        return $result;
    }

改为

private function lists_logic($result = [], $has_children_Row = [])
    {
        if (empty($result)) {
            return [];
        }

        $tid = $result['typeid'];

        switch ($result['current_channel']) {
            case '6': // 单页模型
            {
                $arctype_info = model('Arctype')->parentAndTopInfo($tid, $result);
                if ($arctype_info) {
                    // 读取当前栏目的内容,否则读取每一级第一个子栏目的内容,直到有内容或者最后一级栏目为止。
                    $result_new = $this->readContentFirst($tid);
                    // 阅读权限 或 外部链接跳转
                    if ($result_new['arcrank'] == -1 || $result_new['is_part'] == 1) {
                        return false;
                    }
                    /*自定义字段的数据格式处理*/
                    $result_new = $this->fieldLogic->getChannelFieldList($result_new, $result_new['current_channel']);
                    /*--end*/

                    $result = array_merge($arctype_info, $result_new);

                    $result['templist'] = !empty($arctype_info['templist']) ? $arctype_info['templist'] : 'lists_'. $arctype_info['nid'];
                    // 手机端若有单独的模板
                    $result['templist_mobile'] = !empty($arctype_info['templist_mobile']) ? $arctype_info['templist_mobile'] : 'lists_'. $arctype_info['nid'];
                    $result['dirpath'] = $arctype_info['dirpath'];
                    $result['typeid'] = $arctype_info['typeid'];
                }
                break;
            }

            default:
            {
                $result = model('Arctype')->parentAndTopInfo($tid, $result);
                break;
            }
        }

        if (!empty($result)) {
            /*自定义字段的数据格式处理*/
            $result = $this->fieldLogic->getTableFieldList($result, config('global.arctype_channel_id'));
            /*--end*/
        }

        /*是否有子栏目,用于标记【全部】选中状态*/
        $result['has_children'] = !empty($has_children_Row[$tid]) ? 1 : 0;
        /*--end*/

        // seo
        $result['seo_title'] = set_typeseotitle($result['typename'], $result['seo_title']);

        /*获取当前页面URL*/
        $result['pageurl'] = $result['typeurl'];
        /*--end*/

        /*给没有type前缀的字段新增一个带前缀的字段,并赋予相同的值*/
        foreach ($result as $key => $val) {
            if (!preg_match('/^type/i',$key)) {
                $key_new = 'type'.$key;
                !array_key_exists($key_new, $result) && $result[$key_new] = $val;
            }
        }
        /*--end*/
        return $result;
    }
2.1.15 :针对生成静态模式下且PC和移动端模板分离,就自动给PC端加上跳转移动端的JS代码这段功能代码的更改
private function pc_to_mobile_js($html = '', $result = [])
    {
        if (file_exists('./template/'.TPL_THEME.'mobile')) { // 分离式模板

            /*是否开启手机站域名,并且配置*/
            if (!empty($this->eyou['global']['web_mobile_domain_open']) && !empty($this->eyou['global']['web_mobile_domain'])) {
                $domain = $this->eyou['global']['web_mobile_domain'] . '.' . $this->request->rootDomain();
            }
            /*end*/

            $aid = input('param.aid/d');
            $tid = input('param.tid/d');
            if (!empty($aid)) { // 内容页
                $url = url('home/View/index', ['aid' => $aid], true, true, 1, 1, 0);
            } else if (!empty($tid)) { // 列表页
                $url = url('home/Lists/index', ['tid' => $tid], true, true, 1, 1, 0);
            } else { // 首页
                $url = $this->request->domain() . ROOT_DIR . '/index.php';
            }

            $jsStr = <<<EOF
    <meta http-equiv="mobile-agent" content="format=xhtml;url={$url}">
    <script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/applewebkit.*mobile/i.test(navigator.userAgent.toLowerCase()) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.userAgent.toLowerCase()))){try{if(/android|windows phone|webos|iphone|ipod|blackberry/i.test(navigator.userAgent.toLowerCase())){window.location.href="{$url}";}else if(/ipad/i.test(navigator.userAgent.toLowerCase())){}else{}}catch(e){}}}</script>
EOF;
            $html  = str_ireplace('</head>', $jsStr . "\n</head>", $html);
        } else { // 响应式模板
            // 开启手机站域名,且配置
            if (!empty($this->eyou['global']['web_mobile_domain_open']) && !empty($this->eyou['global']['web_mobile_domain'])) {
                if (empty($result['pageurl'])) {
                    $url = $this->request->subDomain($this->eyou['global']['web_mobile_domain']) . ROOT_DIR . '/index.php';
                } else {
                    $url = !preg_match('/^(http(s?):)?\/\/(.*)$/i', $result['pageurl']) ? $this->request->domain() . $result['pageurl'] : $result['pageurl'];
                    $url = preg_replace('/^(.*)(\/\/)([^\/]*)(\.?)(' . $this->request->rootDomain() . ')(.*)$/i', '${1}${2}' . $this->eyou['global']['web_mobile_domain'] . '.${5}${6}', $url);
                }

                $mobileDomain = $this->eyou['global']['web_mobile_domain'] . '.' . $this->request->rootDomain();
                $jsStr        = <<<EOF
    <meta http-equiv="mobile-agent" content="format=xhtml;url={$url}">
    <script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/applewebkit.*mobile/i.test(navigator.userAgent.toLowerCase()) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.userAgent.toLowerCase()))){try{if(/android|windows phone|webos|iphone|ipod|blackberry/i.test(navigator.userAgent.toLowerCase())){if(window.location.toString().indexOf('{$mobileDomain}') == -1){window.location.href="{$url}";}}else if(/ipad/i.test(navigator.userAgent.toLowerCase())){}else{}}catch(e){}}}</script>
EOF;
                $html         = str_ireplace('</head>', $jsStr . "\n</head>", $html);
            }
        }

        return $html;
    }

改为

private function pc_to_mobile_js($html = '', $result = [])
    {
        if (file_exists('./template/mobile')&&!empty($mobile=$this->eyou['global']['web_mobile_cat'])) {
        // 分离式模板
                $dmobile='/'.$mobile.'/';
                if (empty($result['pageurl'])) {
                    $url = $this->request->domain().ROOT_DIR . '/'.$mobile;
                } else {
                    $url = !preg_match('/^(http(s?):)?\/\/(.*)$/i', $result['pageurl']) ? $this->request->domain().$result['pageurl'] : $result['pageurl'];
                    $url = preg_replace('/^(.*)(\/\/)([^\/]*)(\.?)('.$this->request->rootDomain().')(.*)$/i', '${1}${2}${3}${4}${5}/'.$mobile.'${6}', $url);
                }
                $jsStr = <<<EOF
    <meta http-equiv="mobile-agent" content="format=xhtml;url={$url}">
    <script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/applewebkit.*mobile/i.test(navigator.userAgent.toLowerCase()) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.userAgent.toLowerCase()))){try{if(/android|windows phone|webos|iphone|ipod|blackberry/i.test(navigator.userAgent.toLowerCase())){if(window.location.toString().indexOf('{$dmobile}') == -1){window.location.href="{$url}";}}else if(/ipad/i.test(navigator.userAgent.toLowerCase())){}else{}}catch(e){}}}</script>
EOF;
                $html = str_ireplace('</head>', $jsStr."\n</head>", $html);
        }
                return $html;
    }
2.1.16 在某位添加一个方法,注意,是在最后一个大括号}之前加的
/*
* 是否有手机端
*/
    public function issetMobile()
    {
        return $this->eyou['global']['web_mobile_cat'];
    }
2.1.17 大概第102行,更改写入静态页面里的一段代码
    private function filePutContents($savepath, $tpl, $model = 'pc', $pages = 0, $dir = '/', $tid = 0, $top = 1, $result = [])
    {
        ob_start();
        static $templateConfig = null;
        null === $templateConfig && $templateConfig = \think\Config::get('template');
        /*$templateConfig['view_path'] = "./template/".TPL_THEME."pc/";*/
        $templateConfig['view_path'] = "./template/{$model}/";
        $template                    = "./template/".TPL_THEME."{$model}/{$tpl}.{$templateConfig['view_suffix']}";
        $content                     = $this->fetch($template, [], [], $templateConfig);

改为

    private function filePutContents($savepath, $tpl, $model='pc', $pages=0, $dir='/', $tid=0, $top=1, $result = [])
    {
        ob_start();
        static $templateConfig = null;
        null === $templateConfig && $templateConfig = \think\Config::get('template');
        $templateConfig['view_path'] = "./template/{$model}/";
        $template = "./template/{$model}/{$tpl}.{$templateConfig['view_suffix']}";
        $content = $this->fetch($template, [], [], $templateConfig);
2.1.17 大概第521行

更改生成栏目页面里的一段代码

private function createChannel($row, $globalConfig, $has_children_Row, $aid = 0)
    {
        $msg               = "";
        $seo_html_listname = $this->eyou['global']['seo_html_listname'];
        $seo_html_arcdir   = $this->eyou['global']['seo_html_arcdir'];
        $tid               = $row['typeid'];
        $this->request->post(['tid' => $tid]);

        $row        = $this->lists_logic($row, $has_children_Row);  // 模型对应逻辑
        $eyou       = array(
            'field' => $row,
        );
        $this->eyou = array_merge($this->eyou, $eyou);
        $this->assign('eyou', $this->eyou);

        $tpl = !empty($row['templist']) ? str_replace('.' . $this->view_suffix, '', $row['templist']) : 'lists_' . $row['nid'];
		// 手机端若有单独的模板
		$tpl_mobile = !empty($row['templist_mobile']) ? str_replace('.'.$this->view_suffix, '',$row['templist_mobile']) : $tpl;

        if (in_array($row['current_channel'], [6, 8])) {   //留言模型或单页模型,不存在多页
            $this->request->get(['page' => '']);
            $dirpath     = explode('/', $eyou['field']['dirpath']);
            $dirpath_end = end($dirpath);
            if ($seo_html_listname == 1) {  //存放顶级目录
                $savepath='/'.$dirpath[1]."/lists_".$eyou['field']['typeid'].".html";
            } else if ($seo_html_listname == 3) { // //存放子级目录
                $savepath='/'.$dirpath_end."/lists_".$eyou['field']['typeid'].".html";
            } else {
                $savepath = '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/' . 'lists_' . $eyou['field']['typeid'] . ".html";
            }
			$savepath  = '.'.$seo_html_arcdir.$savepath;
            try {
                $this->filePutContents($savepath, $tpl, 'pc', 0, '/', 0, 1, $row);
                if ($seo_html_listname == 3) {
                    @copy($savepath, '.' . $seo_html_arcdir . '/' . $dirpath_end . '/index.html');
                    @unlink($savepath);
                } else if ($seo_html_listname == 2 || count($dirpath) < 3) {
                    @copy($savepath, '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/index.html');
                    @unlink($savepath);
                }

				if ($mobile=$this->issetMobile()) {
                    // 还要生成到手机端目录
                    substr($savepath,0,1)=='.'?$savepath=substr($savepath,1):'';
                    $mobile_savepath = '.'.$seo_html_arcdir.'/'.$mobile.$savepath;
                    $this->filePutContents($mobile_savepath, $tpl_mobile, 'mobile', 0, '/', 0, 1, $row);
                    if ($seo_html_listname == 3) {
                        @copy($mobile_savepath,'.'.$seo_html_arcdir.'/'.$mobile.'/'.$dirpath_end.'/index.html');
                        @unlink($mobile_savepath);
                    } else if ($seo_html_listname == 2 || count($dirpath) < 3){
                        @copy($mobile_savepath,'.'.$seo_html_arcdir.'/'.$mobile.$eyou['field']['dirpath'].'/index.html');
                        @unlink($mobile_savepath);
                    }
                }


            } catch (\Exception $e) {
                $msg .= '<span>' . $savepath . '生成失败!' . $e->getMessage() . '</span><br>';
            }
        } else if (!empty($aid)) {     //只更新aid所在的栏目页码
            $orderby = getOrderBy($row['orderby'], $row['orderway']);
            $limit   = getLocationPages($tid, $aid, $orderby);
            $i       = !empty($limit) ? ceil($limit / $row['pagesize']) : 1;
            $msg .= $this->createMultipageChannel($i,$tid,$row,$has_children_Row,$seo_html_listname,$seo_html_arcdir,$tpl,$tpl_mobile);

        } else {    //多条信息的栏目
            $totalpage = $row['pagetotal'];
            for ($i = 1; $i <= $totalpage; $i++) {
                $msg .= $this->createMultipageChannel($i, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl);
            }
        }

        return $msg;
    }

改为

    private function createChannel($row,$globalConfig,$has_children_Row,$aid = 0){
        $msg = "";
        $seo_html_listname = $this->eyou['global']['seo_html_listname'];
        $seo_html_arcdir = $this->eyou['global']['seo_html_arcdir'];
        $tid = $row['typeid'];
        $this->request->post(['tid'=>$tid]);

        $row = $this->lists_logic($row, $has_children_Row);  // 模型对应逻辑
        $eyou = array(
            'field' => $row,
        );
        $this->eyou = array_merge($this->eyou, $eyou);
        $this->assign('eyou', $this->eyou);

        $tpl = !empty($row['templist']) ? str_replace('.'.$this->view_suffix, '',$row['templist']) : 'lists_'. $row['nid'];
        // 手机端若有单独的模板
        $tpl_mobile = !empty($row['templist_mobile']) ? str_replace('.'.$this->view_suffix, '',$row['templist_mobile']) : $tpl;

        if(in_array($row['current_channel'], [6,8])){   //留言模型或单页模型,不存在多页
            $this->request->get(['page'=>'']);
            $dirpath = explode('/',$eyou['field']['dirpath']);
            $dirpath_end = end($dirpath);
            if($seo_html_listname == 1){  //存放顶级目录
                $savepath='/'.$dirpath[1]."/lists_".$eyou['field']['typeid'].".html";
            } else if ($seo_html_listname == 3) { // //存放子级目录
                $savepath='/'.$dirpath_end."/lists_".$eyou['field']['typeid'].".html";
            }else{
                $savepath=$eyou['field']['dirpath'].'/'.'lists_'.$eyou['field']['typeid'].".html";
            }
            $savepath  = '.'.$seo_html_arcdir.$savepath;


            try{
                $this->filePutContents($savepath, $tpl, 'pc', 0, '/', 0, 1, $row);
                if ($seo_html_listname == 3) {
                    @copy($savepath,'.'.$seo_html_arcdir.'/'.$dirpath_end.'/index.html');
                    @unlink($savepath);
                } else if ($seo_html_listname == 2 || count($dirpath) < 3){
                    @copy($savepath,'.'.$seo_html_arcdir.$eyou['field']['dirpath'].'/index.html');
                    @unlink($savepath);
                }

                if ($mobile=$this->issetMobile()) {
                    // 还要生成到手机端目录
                    substr($savepath,0,1)=='.'?$savepath=substr($savepath,1):'';
                    $mobile_savepath = '.'.$seo_html_arcdir.'/'.$mobile.$savepath;
                    $this->filePutContents($mobile_savepath, $tpl_mobile, 'mobile', 0, '/', 0, 1, $row);
                    if ($seo_html_listname == 3) {
                        @copy($mobile_savepath,'.'.$seo_html_arcdir.'/'.$mobile.'/'.$dirpath_end.'/index.html');
                        @unlink($mobile_savepath);
                    } else if ($seo_html_listname == 2 || count($dirpath) < 3){
                        @copy($mobile_savepath,'.'.$seo_html_arcdir.'/'.$mobile.$eyou['field']['dirpath'].'/index.html');
                        @unlink($mobile_savepath);
                    }
                }

            }catch(\Exception $e){
                $msg .= '<span>'.$savepath.'生成失败!'.$e->getMessage().'</span><br>';
            }
        }else if(!empty($aid)){     //只更新aid所在的栏目页码
            $orderby = getOrderBy($row['orderby'],$row['orderway']);
            $limit = getLocationPages($tid,$aid,$orderby);
            $i = !empty($limit) ? ceil($limit/$row['pagesize']):1;
            $msg .= $this->createMultipageChannel($i,$tid,$row,$has_children_Row,$seo_html_listname,$seo_html_arcdir,$tpl,$tpl_mobile);

        }else{    //多条信息的栏目
            $totalpage = $row['pagetotal'];
            for ($i=1; $i <= $totalpage; $i++){
                $msg .= $this->createMultipageChannel($i,$tid,$row,$has_children_Row,$seo_html_listname,$seo_html_arcdir,$tpl,$tpl_mobile);
            }
        }

        return $msg;
    }
2.1.18 大概第484行

添加一段功能代码

    /**
     * 读取指定栏目ID下有内容的栏目信息,只读取每一级的第一个栏目
     * @param intval $typeid 栏目ID
     * @return array
     */
    private function readContentFirst($typeid)
    {
        $result = false;
        while (true)
        {
            $result = model('Single')->getInfoByTypeid($typeid);
            if (empty($result['content']) && 'lists_single.htm' == strtolower($result['templist'])) {
                $map = array(
                    'parent_id' => $result['typeid'],
                    'current_channel' => 6,
                    'is_hidden' => 0,
                    'status'    => 1,
                );
                $row = M('arctype')->where($map)->field('*')->order('sort_order asc')->find(); // 查找下一级的单页模型栏目
                if (empty($row)) { // 不存在并返回当前栏目信息
                    break;
                } elseif (6 == $row['current_channel']) { // 存在且是单页模型,则进行继续往下查找,直到有内容为止
                    $typeid = $row['id'];
                }
            } else {
                break;
            }
        }
        return $result;
    }

步骤3:数据库添加参数

3.1 数据库里,执行命令:
INSERT INTO `ey_config` (`id`, `name`, `value`, `inc_type`, `desc`, `lang`, `is_del`, `update_time`) VALUES
(287, 'web_mobile_cat', 'mobile', 'web', '', 'cn', 0, 1588557087),
(288, 'web_mobile_cat', '', 'web', '', 'en', 0, 1588495631);

用于增加web_mobile_cat这个自定义变量

3.2 表格ey_arctype添加字段

在数据库中的ey_arctype这个表里加两个字段:templist_mobiletempview_mobile,属性均为varchar,长度200就够了
然后在ey_channelfield这个表里,将templist_mobiletempview_mobile这两个字段的ifeditable属性都改为0(这样做的作用是后期在网站后台编辑中,这两个字段不会显示出来让你来编辑)

步骤4:后台界面模板更改

4.1:\application\admin\template\arctype\add.htm文件
4.1.1 :大概第168行
<dl class="row" id="dl_templist">
                <dt class="tit">
                    <label for="templist"><em>*</em>列表模板</label>
                </dt>
                <dd class="opt">
                    <select name="templist" id="templist">
                    </select>
                    <span class="err"></span>
                    <p class="notic">列表模板命名规则:<br/>lists_<font class="font_nid">模型标识</font>.htm<br/>lists_<font class="font_nid">模型标识</font>_自定义.htm</p>
                    &nbsp;<a href="javascript:void(0);" onclick="newtpl('lists');" class="ncap-btn ncap-btn-green">新建模板</a>
                </dd>
            </dl>
            <dl class="row" id="dl_tempview">
                <dt class="tit">
                    <label for="tempview"><em>*</em>文档模板</label>
                </dt>
                <dd class="opt">
                    <select name="tempview" id="tempview">
                    </select>
                    <span class="err"></span>
                    <p class="notic">文档模板命名规则:<br/>view_<font class="font_nid">模型标识</font>.htm<br/>view_<font class="font_nid">模型标识</font>_自定义.htm</p>
                    &nbsp;<a href="javascript:void(0);" onclick="newtpl('view');" class="ncap-btn ncap-btn-green">新建模板</a>
                </dd>
            </dl>

改为

<dl class="row" id="dl_templist">
                <dt class="tit">
                    <label for="templist"><em>*</em>列表模板</label>
                </dt>
                <dd class="opt">
                    <select name="templist" id="templist">
                    </select>
                    <select name="templist_mobile" id="templist_mobile">
                    </select>
                    <span class="err"></span>
                    <p class="notic">列表模板命名规则:<br/>lists_<font class="font_nid">模型标识</font>.htm<br/>lists_<font class="font_nid">模型标识</font>_自定义.htm</p>
                    &nbsp;<a href="javascript:void(0);" onclick="newtpl('lists');" class="ncap-btn ncap-btn-green">新建模板</a>
                </dd>
            </dl>
            <dl class="row" id="dl_tempview">
                <dt class="tit">
                    <label for="tempview"><em>*</em>文档模板</label>
                </dt>
                <dd class="opt">
                    <select name="tempview" id="tempview">
                    </select>
                    <select name="tempview_mobile" id="tempview_mobile">
                    </select>
                    <span class="err"></span>
                    <p class="notic">文档模板命名规则:<br/>view_<font class="font_nid">模型标识</font>.htm<br/>view_<font class="font_nid">模型标识</font>_自定义.htm</p>
                    &nbsp;<a href="javascript:void(0);" onclick="newtpl('view');" class="ncap-btn ncap-btn-green">新建模板</a>
                </dd>
            </dl>
4.1.2 :更改根据模型ID获取模板文件名里面的一段功能代码
function ajax_get_template() {
        var obj = $('#current_channel');
        var channel = parseInt($(obj).find('option:selected').val());
        var js_allow_channel_arr = {$js_allow_channel_arr};
        $('#notic_current_channel').html('');

        // 重新定义模板变量,专用于新建模板功能
        $.ajax({
            url: "{:url('Arctype/ajax_getTemplateList')}",
            type: 'GET',
            dataType: 'JSON',
            data: {_ajax:1},
            success: function(res){
                if (res.code == 1) {
                    templateList = res.data.templateList;
                }
            }
        });
        // end

        if (templateList[channel] == undefined || templateList[channel] == '') {
            showErrorMsg('模板文件不存在!');
            return false;
        } else if (templateList[channel]['msg'] != '') {
            $('#notic_current_channel').html(templateList[channel]['msg']);
        }

        $('#templist').html(templateList[channel]['lists']);
        if ($.inArray(channel, js_allow_channel_arr) == -1) {
            if (channel == 6) {
                $('#dl_templist').find('label[for=templist]').html('<em>*</em>单页模板');
            } else if (channel == 8) {
                $('#dl_templist').find('label[for=templist]').html('<em>*</em>留言模板');
            }
            $('#dl_tempview').hide();
        } else {
            $('#dl_templist').find('label[for=templist]').html('<em>*</em>列表模板');
            $('#dl_tempview').show();
        }
        $('#tempview').html(templateList[channel]['view']);

        $('.font_nid').html(templateList[channel]['nid']);

        return false;
    }

改为

 function ajax_get_template() {
        // 重新定义模板变量,专用于新建模板功能
        $.ajax({
            url: "{:url('Arctype/ajax_getTemplateList', ['_ajax'=>1])}",
            type: 'GET',
            dataType: 'JSON',
            data: {
                'templist':"{$field.templist|default=''}",
                'templist_mobile':"{$field.templist_mobile|default=''}",
                'tempview':"{$field.tempview|default=''}",
                'tempview_mobile':"{$field.tempview_mobile|default=''}",
            },
            success: function(res){
                if (res.code == 1) {
                    templateList = res.data.templateList;
                    templateList_mobile = res.data.templateList_mobile;
                }
                change_template();
            }
        });
    }

    /*根据模型ID获取模板文件名*/
    function change_template() {
        var obj = $('#current_channel');
        var channel = parseInt($(obj).val());
        var js_allow_channel_arr = {$js_allow_channel_arr};
        $('#notic_current_channel').html('');

        if (templateList[channel] == undefined || templateList[channel] == '') {
            showErrorMsg('模板文件不存在!');
            return false;
        } else if (templateList[channel]['msg'] != '') {
            $('#notic_current_channel').html(templateList[channel]['msg']);
        }

        $('#templist').html(templateList[channel]['lists']);
         if (templateList_mobile[channel]['lists'] != undefined && templateList_mobile[channel]['lists'] != '') {
            $('#templist_mobile').html(templateList_mobile[channel]['lists']);
        }

        if ($.inArray(channel, js_allow_channel_arr) == -1) {
            if (channel == 6) {
                $('#dl_templist').find('label[for=templist]').html('<em>*</em>单页模板');
            } else if (channel == 8) {
                $('#dl_templist').find('label[for=templist]').html('<em>*</em>留言模板');
            }
            $('#dl_tempview').hide();
        } else {
            $('#dl_templist').find('label[for=templist]').html('<em>*</em>列表模板');
            $('#dl_tempview').show();
        }
        $('#tempview').html(templateList[channel]['view']);

        if (templateList_mobile[channel]['view'] != undefined && templateList_mobile[channel]['view'] != '') {
            $('#tempview_mobile').html(templateList_mobile[channel]['view']);
        }

        $('.font_nid').html(templateList[channel]['nid']);

        return false;
    }
4.2:\application\admin\template\arctype\ajax_newtpl.htm文件

大概第103行

if ('lists' == res.data.type) {
   var id = 'templist';
   } else {
   var id = 'tempview';
                    }
改为
if ('lists' == res.data.type) {
   var id = $('#tpldir').val()=='mobile'?'templist_mobile':'templist';
   } else {
   var id = $('#tpldir').val()=='mobile'?'tempview_mobile':'tempview';;
}
4.3:\application\admin\template\arctype\edit.htm文件
4.3.1 : 大概第207行
<dl class="row" id="dl_templist">
                <dt class="tit">
                    <label for="templist"><em>*</em>列表模板</label>
                </dt>
                <dd class="opt">
                    <select name="templist" id="templist">
                    </select>
                    <span class="err"></span>
                    <p class="notic">模板命名规则:<br/>lists_<font class="font_nid">模型标识</font>.htm<br/>lists_<font class="font_nid">模型标识</font>_自定义.htm</p>
                    &nbsp;<a href="javascript:void(0);" onclick="newtpl('lists');" class="ncap-btn ncap-btn-green">新建模板</a>
                </dd>
            </dl>
            <dl class="row" id="dl_tempview">
                <dt class="tit">
                    <label for="tempview"><em>*</em>文档模板</label>
                </dt>
                <dd class="opt">
                    <select name="tempview" id="tempview">
                    </select>
                    <span class="err"></span>
                    <p class="notic">模板命名规则:<br/>view_<font class="font_nid">模型标识</font>.htm<br/>view_<font class="font_nid">模型标识</font>_自定义.htm</p>
                    &nbsp;<a href="javascript:void(0);" onclick="newtpl('view');" class="ncap-btn ncap-btn-green">新建模板</a>
                </dd>
            </dl>

改为

<dl class="row" id="dl_templist">
                <dt class="tit">
                    <label for="templist"><em>*</em>列表模板</label>
                </dt>
                <dd class="opt">
                    <select name="templist" id="templist">
                    </select>
                    <select name="templist_mobile" id="templist_mobile">
                    </select>
                    <span class="err"></span>
                    <p class="notic">模板命名规则:<br/>lists_<font class="font_nid">模型标识</font>.htm<br/>lists_<font class="font_nid">模型标识</font>_自定义.htm</p>
                    &nbsp;<a href="javascript:void(0);" onclick="newtpl('lists');" class="ncap-btn ncap-btn-green">新建模板</a>
                </dd>
            </dl>
            <dl class="row" id="dl_tempview">
                <dt class="tit">
                    <label for="tempview"><em>*</em>文档模板</label>
                </dt>
                <dd class="opt">
                    <select name="tempview" id="tempview">
                    </select>
                    <select name="tempview_mobile" id="tempview_mobile">
                    </select>
                    <span class="err"></span>
                    <p class="notic">模板命名规则:<br/>view_<font class="font_nid">模型标识</font>.htm<br/>view_<font class="font_nid">模型标识</font>_自定义.htm</p>
                    &nbsp;<a href="javascript:void(0);" onclick="newtpl('view');" class="ncap-btn ncap-btn-green">新建模板</a>
                </dd>
            </dl>
4.3.2 :大概第288行
var templateList = {$templateList|json_encode};
改为
var templateList,templateList_mobile;
  • 4.3.3 :大概第315行
/*根据模型ID获取模板文件名*/
    function ajax_get_template() {
        var obj = $('#current_channel');
        var channel = parseInt($(obj).val());
        var js_allow_channel_arr = {$js_allow_channel_arr};
        $('#notic_current_channel').html('');

        // 重新定义模板变量,专用于新建模板功能
        $.ajax({
            url: "{:url('Arctype/ajax_getTemplateList', ['_ajax'=>1])}",
            type: 'GET',
            dataType: 'JSON',
            data: {},
            success: function(res){
                if (res.code == 1) {
                    templateList = res.data.templateList;
                }
            }
        });
        // end

        if (templateList[channel] == undefined || templateList[channel] == '') {
            showErrorMsg('模板文件不存在!');
            return false;
        } else if (templateList[channel]['msg'] != '') {
            $('#notic_current_channel').html(templateList[channel]['msg']);
        }

        $('#templist').html(templateList[channel]['lists']);
        if ($.inArray(channel, js_allow_channel_arr) == -1) {
            if (channel == 6) {
                $('#dl_templist').find('label[for=templist]').html('<em>*</em>单页模板');
            } else if (channel == 8) {
                $('#dl_templist').find('label[for=templist]').html('<em>*</em>留言模板');
            }
            $('#dl_tempview').hide();
        } else {
            $('#dl_templist').find('label[for=templist]').html('<em>*</em>列表模板');
            $('#dl_tempview').show();
        }
        $('#tempview').html(templateList[channel]['view']);

        $('.font_nid').html(templateList[channel]['nid']);
        
        return false;
    }
    /*--end*/

改为

function ajax_get_template() {
        // 重新定义模板变量,专用于新建模板功能
        $.ajax({
            url: "{:url('Arctype/ajax_getTemplateList', ['_ajax'=>1])}",
            type: 'GET',
            dataType: 'JSON',
            data: {
                'opt':'edit',
                'templist':"{$field.templist|default=''}",
                'templist_mobile':"{$field.templist_mobile|default=''}",
                'tempview':"{$field.tempview|default=''}",
                'tempview_mobile':"{$field.tempview_mobile|default=''}",
            },
            success: function(res){
                if (res.code == 1) {
                    templateList = res.data.templateList;
                    templateList_mobile = res.data.templateList_mobile;
                }
                change_template();
            }
        });
    }

    /*根据模型ID获取模板文件名*/
    function change_template() {
        var obj = $('#current_channel');
        var channel = parseInt($(obj).val());
        var js_allow_channel_arr = {$js_allow_channel_arr};
        $('#notic_current_channel').html('');

        if (templateList[channel] == undefined || templateList[channel] == '') {
            showErrorMsg('模板文件不存在!');
            return false;
        } else if (templateList[channel]['msg'] != '') {
            $('#notic_current_channel').html(templateList[channel]['msg']);
        }

        $('#templist').html(templateList[channel]['lists']);
         if (templateList_mobile[channel]['lists'] != undefined && templateList_mobile[channel]['lists'] != '') {
            $('#templist_mobile').html(templateList_mobile[channel]['lists']);
        }

        if ($.inArray(channel, js_allow_channel_arr) == -1) {
            if (channel == 6) {
                $('#dl_templist').find('label[for=templist]').html('<em>*</em>单页模板');
            } else if (channel == 8) {
                $('#dl_templist').find('label[for=templist]').html('<em>*</em>留言模板');
            }
            $('#dl_tempview').hide();
        } else {
            $('#dl_templist').find('label[for=templist]').html('<em>*</em>列表模板');
            $('#dl_tempview').show();
        }
        $('#tempview').html(templateList[channel]['view']);

        if (templateList_mobile[channel]['view'] != undefined && templateList_mobile[channel]['view'] != '') {
            $('#tempview_mobile').html(templateList_mobile[channel]['view']);
        }
        $('.font_nid').html(templateList[channel]['nid']);
        return false;
    }
    /*--end*/

步骤5:后台界面模板对应控制器更改

5.1:\application\admin\controller\Arctype.php文件
5.1.1 :大概第244行,public function add()里面的
        /*模板列表*/
        $templateList = $this->ajax_getTemplateList('add');
        $this->assign('templateList', $templateList);
        /*--end*/

        /*自定义字段*/

改为

         /*模板列表*/
        $templateList = $this->ajax_getTemplateList('add');
        $this->assign('templateList', $templateList);

        /*手机端模板列表*/
        $templateList_mobile = $this->ajax_getTemplateList('add','','','template/mobile');
        $this->assign('templateList_mobile', $templateList_mobile);
        /*--end*/

        /*自定义字段*/
5.1.2 :大概第348行
                        /*父级模板继承*/
                        if (!empty($post['inherit_status']) && $post['inherit_status'] == 1) {
                            $subSaveData_tmp['templist'] = $post['templist'];
                            $subSaveData_tmp['tempview'] = $post['tempview'];
                        }
                        /*end*/

改为

                        /*父级模板继承*/
                        if (!empty($post['inherit_status']) && $post['inherit_status'] == 1) {
                            $subSaveData_tmp['templist'] = $post['templist'];
                            $subSaveData_tmp['tempview'] = $post['tempview'];
                            // 增加手机端模板
                            $subSaveData_tmp['templist_mobile'] = $post['templist_mobile'];
                            $subSaveData_tmp['tempview_mobile'] = $post['tempview_mobile'];
                        }
                        /*end*/
5.1.3 :大概第465行,public function edit()里面的
        /*模板列表*/
        $templateList = $this->ajax_getTemplateList('edit', $info['templist'], $info['tempview']);
        $this->assign('templateList', $templateList);
        /*--end*/

删除或者注释掉

5.1.4 :大概第348行
                        /*父级模板继承*/
                        if (!empty($post['inherit_status']) && $post['inherit_status'] == 1) {
                            $subSaveData_tmp['templist'] = $post['templist'];
                            $subSaveData_tmp['tempview'] = $post['tempview'];
                            // 增加手机端模板
                            $subSaveData_tmp['templist_mobile'] = $post['templist_mobile'];
                            $subSaveData_tmp['tempview_mobile'] = $post['tempview_mobile'];
                        }
                        /*end*/
                        $subSaveData[] = $subSaveData_tmp;

改为

                        /*父级模板继承*/
                        if (!empty($post['inherit_status']) && $post['inherit_status'] == 1) {
                            $subSaveData_tmp['templist'] = $post['templist'];
                            $subSaveData_tmp['tempview'] = $post['tempview'];
                            // 增加手机端模板
                            $subSaveData_tmp['templist_mobile'] = $post['templist_mobile'];
                            $subSaveData_tmp['tempview_mobile'] = $post['tempview_mobile'];
                        }
                        /*end*/
                        $subSaveData[] = $subSaveData_tmp;
5.1.5 :大概第712行
    public function ajax_getTemplateList($opt = 'add', $templist = '', $tempview = '')
    {   
        $planPath = 'template/'.TPL_THEME.'pc';
        $dirRes   = opendir($planPath);
        $view_suffix = config('template.view_suffix');

        /*模板PC目录文件列表*/
        $templateArr = array();
        while($filename = readdir($dirRes))
        {
            if (in_array($filename, array('.','..'))) {
                continue;
            }
            array_push($templateArr, $filename);
        }
        !empty($templateArr) && asort($templateArr);
        /*--end*/

        /*多语言全部标识*/
        $markArr = Db::name('language_mark')->column('mark');
        /*--end*/

        $templateList = array();
        $channelList = model('Channeltype')->getAll();
        foreach ($channelList as $k1 => $v1) {
            $l = 1;
            $v = 1;
            $lists = ''; // 销毁列表模板
            $view = ''; // 销毁文档模板
            $templateList[$v1['id']] = array();
            foreach ($templateArr as $k2 => $v2) {
                $v2 = iconv('GB2312', 'UTF-8', $v2);

                if ('add' == $opt) {
                    $selected = 0; // 默认选中状态
                } else {
                    $selected = 1; // 默认选中状态
                }

                preg_match('/^(lists|view)_'.$v1['nid'].'(_(.*))?(_'.$this->admin_lang.')?\.'.$view_suffix.'/i', $v2, $matches1);
                $langtpl = preg_replace('/\.'.$view_suffix.'$/i', "_{$this->admin_lang}.{$view_suffix}", $v2);
                if (file_exists(realpath($planPath.DS.$langtpl))) {
                    continue;
                } else if (preg_match('/^(.*)_([a-zA-z]{2,2})\.'.$view_suffix.'$/i',$v2,$matches2)) {
                    if (in_array($matches2[2], $markArr) && $matches2[2] != $this->admin_lang) {
                        continue;
                    }
                }

                if (!empty($matches1)) {
                    $selectefile = '';
                    if ('lists' == $matches1[1]) {
                        $lists .= '<option value="'.$v2.'" ';
                        $lists .= ($templist == $v2 || $selected == $l) ? " selected='true' " : '';
                        $lists .= '>'.$v2.'</option>';
                        $l++;
                    } else if ('view' == $matches1[1]) {
                        $view .= '<option value="'.$v2.'" ';
                        $view .= ($tempview == $v2 || $selected == $v) ? " selected='true' " : '';
                        $view .= '>'.$v2.'</option>';
                        $v++;
                    }
                }
            }
            $nofileArr = [];
            if ('add' == $opt) {
                if (empty($lists)) {
                    $lists = '<option value="">无</option>';
                    $nofileArr[] = "lists_{$v1['nid']}.{$view_suffix}";
                }
                
                if (empty($view)) {
                    $view = '<option value="">无</option>';
                    if (!in_array($v1['nid'], ['single','guestbook'])) {
                        $nofileArr[] = "view_{$v1['nid']}.{$view_suffix}";
                    }
                }
            } else {
                if (empty($lists)) {
                    $nofileArr[] = "lists_{$v1['nid']}.{$view_suffix}";
                }
                $lists = '<option value="">请选择模板…</option>'.$lists;

                if (empty($view)) {
                    if (!in_array($v1['nid'], ['single','guestbook'])) {
                        $nofileArr[] = "view_{$v1['nid']}.{$view_suffix}";
                    }
                }
                $view = '<option value="">请选择模板…</option>'.$view;
            }

            $msg = '';
            if (!empty($nofileArr)) {
                $msg = '<font color="red">该模型缺少模板文件:'.implode(' 和 ', $nofileArr).'</font>';
            }

            $templateList[$v1['id']] = array(
                'lists' => $lists,
                'view' => $view,
                'msg'    => $msg,
                'nid'    => $v1['nid'],
            );
        }

        if (IS_AJAX) {
            $this->success('请求成功', null, ['templateList'=>$templateList]);
        } else {
            return $templateList;
        }
    }

改为

// 获取模板
    public function ajax_getTemplateList($opt = 'add', $templist = '', $tempview = '', $way = 'template/pc')
    {
        if (IS_AJAX) {
            $teml=$this->find_TemplateList($opt,input('templist'),input('tempview'),'template/pc');
            $teml_mobile=$this->find_TemplateList($opt,input('templist_mobile'),input('tempview_mobile'),'template/mobile');
            $this->success('请求成功', null, ['templateList'=>$teml,'templateList_mobile'=>$teml_mobile]);
        } else {
            $teml=$this->find_TemplateList($opt,$templist,$tempview,$way);
            return $templateList;
        }
    }
    // 有模板
    public function find_TemplateList($opt = 'add', $templist = '', $tempview = '',$path='template/pc')
    {
        $planPath = $path;
        $dirRes   = opendir($planPath);
        $view_suffix = config('template.view_suffix');

        /*模板PC目录文件列表*/
        $templateArr = array();
        while($filename = readdir($dirRes))
        {
            if (in_array($filename, array('.','..'))) {
                continue;
            }
            array_push($templateArr, $filename);
        }
        !empty($templateArr) && asort($templateArr);
        /*--end*/

        /*多语言全部标识*/
        $markArr = Db::name('language_mark')->column('mark');
        /*--end*/

        $templateList = array();
        $channelList = model('Channeltype')->getAll();
        foreach ($channelList as $k1 => $v1) {
            $l = 1;
            $v = 1;
            $lists = ''; // 销毁列表模板
            $view = ''; // 销毁文档模板
            $templateList[$v1['id']] = array();
            foreach ($templateArr as $k2 => $v2) {
                $v2 = iconv('GB2312', 'UTF-8', $v2);

                if ('add' == $opt||($path=='template/pc' && empty($templist))) {
                    $selected = 1; // 默认选中状态
                } else {
                    $selected = 0; // 默认选中状态
                }

                preg_match('/^(lists|view)_'.$v1['nid'].'(_(.*))?(_'.$this->admin_lang.')?\.'.$view_suffix.'/i', $v2, $matches1);
                $langtpl = preg_replace('/\.'.$view_suffix.'$/i', "_{$this->admin_lang}.{$view_suffix}", $v2);
                if (file_exists(realpath($planPath.DS.$langtpl))) {
                    continue;
                } else if (preg_match('/^(.*)_([a-zA-z]{2,2})\.'.$view_suffix.'$/i',$v2,$matches2)) {
                    if (in_array($matches2[2], $markArr) && $matches2[2] != $this->admin_lang) {
                        continue;
                    }
                }
                if (!empty($matches1)) {
                    $selectefile = '';
                     // print_r('模板是:'.$templist.'---'.$v2.'---'.$selected.'---'.$l.'结束okk');
                    if ('lists' == $matches1[1]) {
                        $lists .= '<option value="'.$v2.'" ';
                        $lists .= ($templist == $v2 || $selected == $l) ? " selected='true' " : '';
                        $lists .= '>'.$v2.'</option>';
                        $l++;
                    } else if ('view' == $matches1[1]) {
                        $view .= '<option value="'.$v2.'" ';
                        $view .= ($tempview == $v2 || $selected == $v) ? " selected='true' " : '';
                        $view .= '>'.$v2.'</option>';
                        $v++;
                    }
                }
            }
            $nofileArr = [];
            if ('add' == $opt) {
                if (empty($lists)) {
                    $lists = '<option value="">无</option>';
                    $nofileArr[] = "lists_{$v1['nid']}.{$view_suffix}";
                }

                if (empty($view)) {
                    $view = '<option value="">无</option>';
                    if (!in_array($v1['nid'], ['single','guestbook'])) {
                        $nofileArr[] = "view_{$v1['nid']}.{$view_suffix}";
                    }
                }
            } else {
                if (empty($lists)) {
                    $nofileArr[] = "lists_{$v1['nid']}.{$view_suffix}";
                }
                $lists = '<option value="">请选择模板…</option>'.$lists;
                if (empty($view)) {
                    if (!in_array($v1['nid'], ['single','guestbook'])) {
                        $nofileArr[] = "view_{$v1['nid']}.{$view_suffix}";
                    }
                }
                $view = '<option value="">请选择模板…</option>'.$view;
            }

            $msg = '';
            if (!empty($nofileArr)) {
                $msg = '<font color="red">该模型缺少模板文件:'.implode(' 和 ', $nofileArr).'</font>';
            }
            $templateList[$v1['id']] = array(
                'lists' => $lists,
                'view' => $view,
                'msg'    => $msg,
                'nid'    => $v1['nid'],
            );
        }
        return $templateList;
    }
5.1.6 :文档中的两段相同代码
                'templist'  => !empty($post['templist']) ? $post['templist'] : '',
                'tempview'  => !empty($post['tempview']) ? $post['tempview'] : '',
                'is_hidden'  => $post['is_hidden'],

均改为

                'templist'  => !empty($post['templist']) ? $post['templist'] : '',
                'tempview'  => !empty($post['tempview']) ? $post['tempview'] : '',
                // 手机端栏目
                'templist_mobile'  => !empty($post['templist_mobile']) ? $post['templist_mobile'] : '',
                'tempview_mobile'  => !empty($post['tempview_mobile']) ? $post['tempview_mobile'] : '',
                'is_hidden'  => $post['is_hidden'],
5.2:\application\admin\controller\Channeltype.php文件

注释掉下面这段代码,大概第470行

else {
                    // 判断是否存在手机端目录,同时生成一份
                    $tplplan = "template/".TPL_THEME."mobile";
                    $planPath = realpath($tplplan);
                    if (file_exists($planPath)) {
                        $dst_m = str_replace('template/'.TPL_THEME.'pc/', 'template/'.TPL_THEME.'mobile/', $dst);
                        @file_put_contents($dst_m, $fileContent);
                    }
                }

更新补充

6.1:\application\helper.php文件(大概第409行)

使用一端时间发现,移动端的生成静态页有问题,补充了更新代码

if (isMobile()) { // 手机端访问非静态页面
                if (is_array($param)) {
                    $vars = array(
                        'aid'   => $param['aid'],
                    );
                    $vars = http_build_query($vars);
                } else {
                    $vars = $param;
                }
                static $home_lang = null;
                null == $home_lang && $home_lang = get_home_lang(); // 前台语言 by 小虎哥
                static $main_lang = null;
                null == $main_lang && $main_lang = get_main_lang(); // 前台主体语言 by 小虎哥
                if ($home_lang != $main_lang) {
                    $vars .= "&lang=".get_home_lang();
                }
                $eyouUrl = url('home/View/index', $vars, true, false, 1);
            }
            else
            { // PC端访问是静态页面
                if (!empty($param['htmlfilename'])){
                    $aid = $param['htmlfilename'];
                }else{
                    $aid = $param['aid'];
                }
                $url = $param['dirpath']."/{$aid}.html";
                static $seo_html_pagename = null;
                null === $seo_html_pagename && $seo_html_pagename = tpCache('seo.seo_html_pagename');
                static $seo_html_arcdir = null;
                null === $seo_html_arcdir && $seo_html_arcdir = tpCache('seo.seo_html_arcdir');
                if($seo_html_pagename == 1){//存放顶级目录
                    $dirpath = explode('/',$param['dirpath']);
                    $url = $seo_html_arcdir.'/'.$dirpath[1].'/'.$aid.'.html';
                } else if ($seo_html_pagename == 3) {
                    $dirpath = explode('/',$param['dirpath']);
                    $url = $seo_html_arcdir.'/'.end($dirpath).'/'.$aid.'.html';
                }else{
                    $url = $seo_html_arcdir.$param['dirpath'].'/'.$aid.'.html';
                }
                
                $eyouUrl = ROOT_DIR.$url;
                if (false !== $domain) {
                    static $re_domain = null;
                    null === $re_domain && $re_domain = request()->domain();
                    if (true === $domain) {
                        $eyouUrl = $re_domain.$eyouUrl;
                    } else {
                        $eyouUrl = rtrim($domain, '/').$eyouUrl;
                    }
                }
            }

这段代码注释掉,换成以下代码

if (!empty($param['htmlfilename'])){
                    $aid = $param['htmlfilename'];
                }else{
                    $aid = $param['aid'];
                }
                $url = $param['dirpath']."/{$aid}.html";
                static $seo_html_pagename = null;
                null === $seo_html_pagename && $seo_html_pagename = tpCache('seo.seo_html_pagename');
                static $seo_html_arcdir = null;
                null === $seo_html_arcdir && $seo_html_arcdir = tpCache('seo.seo_html_arcdir');

                if($seo_html_pagename == 1){//存放顶级目录
                    $dirpath = explode('/',$param['dirpath']);
                    $air= '/'.$dirpath[1].'/'.$aid.'.html';
                } else if ($seo_html_pagename == 3) {
                    $dirpath = explode('/',$param['dirpath']);
                    $air= '/'.end($dirpath).'/'.$aid.'.html';
                }else{
                    $air= $param['dirpath'].'/'.$aid.'.html';
                }
                // 手机端若有单独的模板
                if ($_SERVER['HTTP_VIA']=='wap' && !empty(tpCache('web.web_mobile_cat'))) {
                    $url = $seo_html_arcdir.'/'.tpCache('web.web_mobile_cat').$air;
                }else{
                    $url = $seo_html_arcdir.$air;
                }
                $eyouUrl = ROOT_DIR.$url;
                if (false !== $domain) {
                    static $re_domain = null;
                    null === $re_domain && $re_domain = request()->domain();
                    if (true === $domain) {
                        $eyouUrl = $re_domain.$eyouUrl;
                    } else {
                        $eyouUrl = rtrim($domain, '/').$eyouUrl;
                    }
                }

完结,开发结束!

本次二开是针对eyou的这个版本来开发的,不保证后期的更气会产生什么后果,当然,哪天易优团队开眼了,应该也会去开发这个功能,届时就不用本文的教程了,祝君发财…

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值