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

您所在的位置:网站首页 易语言手机端 易优EyouCMS手机端url路径改为/mobile/方案(非自带m.xxx.com二级域名方案)

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

2024-01-04 02:12| 来源: 网络整理| 查看: 265

易优EyouCMS手机端url路径改为www.xxx.com/mobile/的方案 二次开发步骤**开发背景和剧情摘要**: 步骤1:路由url更改1.1 :\application\route.php文件1.1.1 :大概第49行1.1.2 :大概第60行 1.2 :\application\admin\template\system\web.htm文件1.2.1 :大概第197行 步骤2: 处理生成首页2.1:\application\home\controller\Buildhtml.php文件,静态页生成器的改动2.1.1 : 大概第185行2.1.2 :大概第107行:2.1.3 : 大概第141行:2.1.4 : 大概第333行2.1.5 :大概第345行2.1.6 :大概第505行2.1.7 :大概第513行2.1.8 :大概第515行2.1.9 :大概第519行2.1.10 :大概第526行2.1.11 :大概第552行2.1.12 :大概第557行2.1.13 :针对`创建有文档列表模型的静态栏目页面`这段功能代码的更改:2.1.14 :针对`拓展页面相关信息`这段功能代码的更改2.1.15 :针对`生成静态模式下且PC和移动端模板分离,就自动给PC端加上跳转移动端的JS代码`这段功能代码的更改2.1.16 在某位添加一个方法,注意,是在最后一个大括号`}`之前加的2.1.17 大概第102行,更改`写入静态页面`里的一段代码2.1.17 大概第521行2.1.18 大概第484行 步骤3:数据库添加参数3.1 数据库里,执行命令:3.2 表格ey_arctype添加字段 步骤4:后台界面模板更改4.1:\application\admin\template\arctype\add.htm文件4.1.1 :大概第168行4.1.2 :更改`根据模型ID获取模板文件名`里面的一段功能代码 4.2:\application\admin\template\arctype\ajax_newtpl.htm文件4.3:\application\admin\template\arctype\edit.htm文件4.3.1 : 大概第207行4.3.2 :大概第288行 步骤5:后台界面模板对应控制器更改5.1:\application\admin\controller\Arctype.php文件5.1.1 :大概第244行,public function add()里面的5.1.2 :大概第348行5.1.3 :大概第465行,public function edit()里面的5.1.4 :大概第348行5.1.5 :大概第712行5.1.6 :文档中的两段相同代码 5.2:\application\admin\controller\Channeltype.php文件 更新补充6.1:\application\helper.php文件(大概第409行) 完结,开发结束!

二次开发步骤 开发背景和剧情摘要:

· 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行 自定义变量 ;;[管理]

改为

手机端静态目录 {eq name="$web_cmsmode" value="2"} web_mobile_cat 复制标签 {/eq} 自定义变量 ;;[管理] 步骤2: 处理生成首页 2.1:\application\home\controller\Buildhtml.php文件,静态页生成器的改动 2.1.1 : 大概第185行

也就是在$msg .= 'index.html生成成功';和}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) $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) $msg .= '' . $savepath . '生成失败!' . $e->getMessage() . ''; } 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) // 还要生成到手机端目录 $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) $msg .= ''.$savepath.'生成失败!'.$e->getMessage().''; } 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 =


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3