# Fastadmin_cms_optimize **Repository Path**: min-character/fastadmin_cms_optimize ## Basic Information - **Project Name**: Fastadmin_cms_optimize - **Description**: 此项目仅为Fastadmin-cms系统日常使用中遇到的奇葩问题的小小优化(持续更新) - **Primary Language**: PHP - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 5 - **Created**: 2025-02-24 - **Last Updated**: 2025-02-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Fastadmin-CMS网站内容管理系统程序修改日志 ### * 注该cms插件为官方收费插件请自行在官方渠道购买安装! #### 此项目仅为系统日常使用中遇到的奇葩问题的小小优化 #### Author:xslooi #### 适配系统: * Fastadmin框架 version = V1.5.0.20240328 * title = CMS内容管理系统 version = 2.0.8 * title = 百度ueditor插件 version = 1.0.12 ### 网站后台修改登录地址: * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\public\adminlogin.php` * 系统安装默认生成的后台入口文件名称修改 * 链接:`http://localhost/adminlogin.php/index/login` ### CMS设置为首页 * 网站后台->CMS管理->站点配置->伪静态->值里边:一键移除URL中的/cms->保存 ### 栏目管理-添加自定义字段 * title 栏目标题 字符 * content 栏目内容 编辑器 ### CMS管理-后台菜单名称更换为网站管理 * SQL: ``` UPDATE `fa_auth_rule` SET `title` = '网站管理' WHERE `name` = 'cms'; ``` ### 修改默认安装网址的登录头像 ```sql UPDATE `fa_admin` SET `avatar` = '/assets/img/avatar.png' WHERE `id` = 1; UPDATE `fa_user` SET `avatar` = '/assets/img/avatar.png' WHERE `id` = 1; ``` ### 栏目名称字段修改长度为 255 ```sql ALTER TABLE `fa_cms_channel` MODIFY COLUMN `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '名称' AFTER `parent_id`; ``` ### !deprecated(导入织梦系统文章) 模型管理-新闻-添加自定义字段 * shorttitle 短标题 字符 * source 来源 字符 ### 添加常用字段如:电话、手机、微信、邮箱、地址等 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\config.php` * 添加:line: 1219; ```php [ 'name' => 'sitecopyright', 'title' => '网站版权说明', 'type' => 'string', 'content' => [], 'value' => 'Copyright © 2018-2024 版权所有', 'rule' => '', 'msg' => '', 'tip' => '网站底部常见的Copyright 20XX 版权所有等描述信息', 'ok' => '', 'extend' => '', ], [ 'name' => 'icp_license', 'title' => '网站备案号', 'type' => 'string', 'content' => [], 'value' => '豫ICP备12345678号', 'rule' => '', 'msg' => '', 'tip' => '中国大陆网站备案号https://beian.miit.gov.cn', 'ok' => '', 'extend' => '', ], [ 'name' => 'contact_tel', 'title' => '联系电话', 'type' => 'string', 'content' => [], 'value' => '0371-1234567', 'rule' => '', 'msg' => '', 'tip' => '座机、400电话或者其他联系号码', 'ok' => '', 'extend' => '', ], [ 'name' => 'contact_phone', 'title' => '联系手机', 'type' => 'string', 'content' => [], 'value' => '15612345678', 'rule' => '', 'msg' => '', 'tip' => '公司手机号或者个人手机号', 'ok' => '', 'extend' => '', ], [ 'name' => 'contact_email', 'title' => '联系邮箱', 'type' => 'string', 'content' => [], 'value' => '123@qq.com', 'rule' => '', 'msg' => '', 'tip' => '公司邮箱或者个人邮箱', 'ok' => '', 'extend' => '', ], [ 'name' => 'contact_qq', 'title' => '联系QQ', 'type' => 'string', 'content' => [], 'value' => '', 'rule' => '', 'msg' => '', 'tip' => '联系人的QQ号', 'ok' => '', 'extend' => '', ], [ 'name' => 'contact_weixin', 'title' => '联系微信', 'type' => 'string', 'content' => [], 'value' => 'webfirst', 'rule' => '', 'msg' => '', 'tip' => '联系人的微信号', 'ok' => '', 'extend' => '', ], [ 'name' => 'contact_address', 'title' => '联系地址', 'type' => 'string', 'content' => [], 'value' => '河南省郑州市', 'rule' => '', 'msg' => '', 'tip' => '一般为公司的办公地址', 'ok' => '', 'extend' => '', ], [ 'name' => 'contact_factory', 'title' => '工厂地址', 'type' => 'string', 'content' => [], 'value' => '工厂地址', 'rule' => '', 'msg' => '', 'tip' => '一般为公司的工厂地址', 'ok' => '', 'extend' => '', ], [ 'name' => 'contact_third', 'title' => '在线咨询链接', 'type' => 'string', 'content' => [], 'value' => 'tencent://message/?uin=12346578&Site=web&Menu=yes', 'rule' => '', 'msg' => '', 'tip' => '第三方独立沟通链接或客服链接', 'ok' => '', 'extend' => '', ], [ 'name' => 'custom_field1', 'title' => '自定义字段1', 'type' => 'string', 'content' => [], 'value' => '', 'rule' => '', 'msg' => '', 'tip' => '由程序员定义的字段,如:联系人姓名,为空则未启用。', 'ok' => '', 'extend' => '', ], [ 'name' => 'custom_field2', 'title' => '自定义字段2', 'type' => 'string', 'content' => [], 'value' => '', 'rule' => '', 'msg' => '', 'tip' => '由程序员定义的字段,如:顶部宣传语,为空则未启用。', 'ok' => '', 'extend' => '', ], [ 'name' => 'custom_field3', 'title' => '自定义字段3', 'type' => 'string', 'content' => [], 'value' => '', 'rule' => '', 'msg' => '', 'tip' => '由程序员定义的字段,如:某个专有链接,为空则未启用。', 'ok' => '', 'extend' => '', ], [ 'name' => 'code_in_head', 'title' => 'head标签中代码', 'type' => 'text', 'content' => [], 'value' => '', 'rule' => '', 'msg' => '', 'tip' => '一般要求放在< head/>标签之前的的第三方javascript代码', 'ok' => '', 'extend' => '', ], [ 'name' => 'code_in_body', 'title' => 'body标签中代码', 'type' => 'text', 'content' => [], 'value' => '', 'rule' => '', 'msg' => '', 'tip' => '一般要求放在< body/>标签之前的的第三方javascript代码', 'ok' => '', 'extend' => '', ], [ 'name' => 'syncphonesite', 'title' => '开启同步手机站', 'type' => 'radio', 'content' => [ 1 => '开启', 0 => '关闭', ], 'value' => '0', 'rule' => 'required', 'msg' => '', 'tip' => '需要新建【default(设定皮肤)_mobile】目录,再添加一套手机模板。否则手机打开网站将显示错误', 'ok' => '', 'extend' => '', ], ``` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\config.html` * 添加:line: 14; ', 末尾替换 `,syncphonesite,sitecopyright,icp_license,contact_tel,contact_phone,contact_email,contact_qq,contact_weixin,contact_address,contact_factory,contact_third,custom_field1,custom_field2,custom_field3,code_in_head,code_in_body',` ### 添加手机版识别 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\controller\Base.php` * 添加:line: 104; ```php /** * 检测设备是否是手机 * @return bool */ public function checkMobileDevice(){ $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : ''; $mobile_browser = 0; if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) { $mobile_browser++; } if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false)) { $mobile_browser++; } if(isset($_SERVER['HTTP_X_WAP_PROFILE'])) { $mobile_browser++; } if(isset($_SERVER['HTTP_PROFILE'])) { $mobile_browser++; } $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4)); $mobile_agents = array( 'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac', 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno', 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-', 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-', 'newt','noki','oper','palm','pana','pant','phil','play','port','prox', 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar', 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-', 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp', 'wapr','webc','winw','winw','xda','xda-' ); if(in_array($mobile_ua, $mobile_agents)) { $mobile_browser++; } if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false) { $mobile_browser++; } // Pre-final check to reset everything if the user is on Windows if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false) { $mobile_browser = 0; } // But WP7 is also Windows, with a slightly different characteristic if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false) { $mobile_browser++; } if($mobile_browser>0) { return true; } else { return false; } } ``` * 添加:line: 22-25; ```php // 同步手机站变更模板目录 if(!empty($config['syncphonesite']) && $this->checkMobileDevice()){ $config['theme'] = $config['theme'] . '_mobile'; } // 设定主题模板目录 ``` ### 栏目展示,调用默认排序修改 * 路径:line 44; line 202; `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Channel.php` * 路径:line 34; `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Builder.php` * 路径:line 55; line 231; `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Archives.php` * 路径:line 188; `E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\controller\Api.php` * 路径:line 190; line 208; line 240; line 362; line 405; line 489; `E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\model\Channel.php` * 修改:`weigh desc,id desc` 修改为 `weigh asc,id asc` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\model\Channel.php` * 修改:line 270; `desc` 修改为 `asc` * 修改:line 274; `$orderway : 'desc';` 修改为 `$orderway : 'asc';` ### 后台添加内容默认权重递增 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Archives.php` * 修改:line 190; add方法 最后一句return 删除 ```php if (false === $this->request->isPost()) { // 权重默认随着id递增 $row_reigh = $this->model->max('id') + 1; $this->view->assign('row_weigh', $row_reigh); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); if ($this->dataLimit && $this->dataLimitFieldAutoFill) { $params[$this->dataLimitField] = $this->auth->id; } $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->model->validateFailException()->validate($validate); } $result = $this->model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('No rows were inserted')); } $this->success(); ``` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\view\cms\archives\add.html` * 修改:line 200; `0` 修改为 `{$row_weigh}` ### 老数据应用权重排序的SQL(权重更新为ID) ```sql UPDATE `fa_cms_archives` SET `weigh` = id WHERE `id` > 0; ``` ### 页码默认边界修改(使手机一行可放下) * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\library\Bootstrap.php` * 修改:line 69-84; ```php $side = 2; $window = $side * 2; if ($this->lastPage < $window + 4) { $block['first'] = $this->getUrlRange(1, $this->lastPage); } elseif ($this->currentPage <= $window) { $block['first'] = $this->getUrlRange(1, $window + 1); $block['last'] = $this->getUrlRange($this->lastPage, $this->lastPage); } elseif ($this->currentPage > ($this->lastPage - $window)) { $block['first'] = $this->getUrlRange(1, 1); $block['last'] = $this->getUrlRange($this->lastPage - ($window), $this->lastPage); } else { $block['first'] = $this->getUrlRange(1, 1); $block['slider'] = $this->getUrlRange($this->currentPage - 1, $this->currentPage + 1); $block['last'] = $this->getUrlRange($this->lastPage, $this->lastPage); } ``` * 修改:line 24; « 修改为 上一页 (自定义语言,酌情修改) * 修改:line 42; » 修改为 下一页 (自定义语言,酌情修改) ### 修改上一篇下一篇链接(由权重排序) * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\model\Archives.php` * 修改:line 584; `$type = $params['type'] ?? 'prev';` 修改为: `$type = $params['type'] ?? 'next';` * 修改-添加:line 588; 588 删除 ```php $weigh = self::where(['id'=>$archives])->value('weigh'); $model = self::where('weigh', $type === 'next' ? '<' : '>', $weigh)->where('status', 'normal'); ``` * 修改:line 596; ```php $model->order($type === 'prev' ? 'id desc' : 'id asc'); //修改为: $model->order($type === 'next' ? 'weigh desc, id desc' : 'weigh asc, id asc'); ``` ### 内容管理列表权重可以直接编辑 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\public\assets\js\backend\cms\archives.js` * 修改:line 139; `{field: 'weigh', title: __('Weigh'), operate: false, sortable: true},` 修改为: ```javascript { field: 'weigh', title: __('Weigh'), formatter: function (value, row, index) { return ''; }, events: { "dblclick .text-weigh": function (e) { e.preventDefault(); e.stopPropagation(); return false; } }, sortable: true }, ``` * 添加:line 415-421; * 添加在 ```javascript Controller.index // 方法体内, 在require(['../addons/cms/js/simtree', 'cookie'], function () 之前 ``` ```javascript //权重绑定事件 $(document).on("change", ".text-weigh", function () { $(this).data("params", {weigh: $(this).val()}); Table.api.multi('', [$(this).data("id")], table, this); return false; }); ``` ### 自定义字段展示顺序按照模型添加的(权重 升序,id 升序) * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\library\Service.php` * 修改:line 238; `weigh desc,id desc` 修改为:`weigh asc,id asc` ### 栏目添加默认导航显示isnav=1 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\view\cms\channel\add.html` * 修改:line 166; value="0" 修改为 value="1" * 修改:line 168; `fa fa-toggle-on text-success fa-flip-horizontal text-gray fa-2x` 修改为 `fa fa-toggle-on text-success fa-2x` ### 修改单页、栏目页、详情页默认TDK * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\controller\Page.php` * 修改:line 53; line 54; ```php Config::set('cms.keywords', isset($page['keywords']) && $page['keywords'] ? $page['keywords'] : $config['keywords']); Config::set('cms.description', isset($page['description']) && $page['description'] ? $page['description'] : $config['description']); ``` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\controller\Channel.php` * 修改:line 178; line 179; ```php Config::set('cms.keywords', isset($channel['keywords']) && $channel['keywords'] ? $channel['keywords'] : $config['keywords']); Config::set('cms.description', isset($channel['description']) && $channel['description'] ? $channel['description'] : $config['description']); ``` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\controller\Archives.php` * 修改:line 97; line 98; ```php Config::set('cms.keywords', isset($archives['keywords']) && $archives['keywords'] ? $archives['keywords'] : $config['keywords']); Config::set('cms.description', isset($archives['description']) && $archives['description'] ? $archives['description'] : $config['description']); ``` ### 自动提取关键词和描述和缩略图 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Archives.php` * 添加:add方法体内:$result = false; Db::startTrans();之前 ```php // 自动提取关键词 if(empty($params['keywords'])){ $keywords = \addons\cms\library\Service::getContentTags($params['title']); $keywords = in_array($params['title'], $keywords) ? [] : $keywords; $keywords = array_filter(array_merge([$params['tags']], $keywords)); $params['keywords'] = implode(',', $keywords); } // 自动提取描述 if(empty($params['description']) && !empty($params['content'])){ $description = mb_substr(strip_tags(str_replace([' ', "\r", "\n", "\t"], ' ', $params['content'])), 0, 150); $params['description'] = $description; } // 自动提取缩略图 todo 目前仅提取后台自行上传和手动下载的。不提取远程图片 if(empty($params['image']) && false !== stripos($params['content'], '/uploads/')){ $matches = []; preg_match('/getD($str, $i);` 之前 * 添加:line 233-236; 在 `list($d, $i) = $this->getD($str, $i);` 之前 ```php // 遇到不认识的编码,跳过 if(false === $this->getD($str, $i)){ continue; } ``` ### 修改默认页码大小为12 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\view\cms\channel\add.html` * 修改:line 126; ```html ``` ### 关闭标题和文章名称自动转换拼音 并添加按钮手动识别 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\view\cms\common\diyname.html` * 修改:line 26; 添加 ```html {if 'channel' eq $controllerName}
{/if} ``` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\public\assets\js\backend\cms\channel.js` * 删除:line 405 - 442; ```javascript var si; $(document).on("keyup", "#c-name", function () { var value = $(this).val(); if (value != '' && !value.match(/\n/)) { clearTimeout(si); si = setTimeout(function () { Fast.api.ajax({ loading: false, url: "cms/ajax/get_title_pinyin", data: {title: value} }, function (data, ret) { $("#c-diyname").val(data.pinyin.substr(0, 100)); return false; }, function (data, ret) { return false; }); }, 200); } }); ``` * 添加:line 424 - 442; 上边删除的位置 ```javascript //获取栏目拼音 var si; $(document).on("click", "#diyname-pinyin", function () { var _cname = $("#c-name"); var value = _cname.val(); if (value != '' && !value.match(/\n/)) { clearTimeout(si); si = setTimeout(function () { Fast.api.ajax({ loading: false, url: "cms/ajax/get_title_pinyin", data: {title: value, check: 0} }, function (data, ret) { $("#c-diyname").val(data.pinyin.substr(0, 100)); return false; }, function (data, ret) { return false; }); }, 200); } }); ``` ### 搜索添加检索字段(description) * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\controller\Search.php` * 修改:line 125; ` $query->where('a.title', 'like', '%' . $item . '%'); ` 修改为: ` $query->where('a.title|a.description', 'like', '%' . $item . '%'); ` ### 添加常见的文件上传类型 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\extra\upload.php` ```php 'mimetype' => 'jpg,png,bmp,jpeg,gif,webp,zip,rar,wav,mp4,mp3,webm,pdf,doc,docx,xls,xlsx,ppt,pptx', ``` ### 百度UEditor 视频和附件上传采用系统分片上传(同时修改文件上传大小) * !!!大文件上传(超过分片大小)PHP环境版本(7.4)或其他必须安装扩展:fileinfo * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\extra\upload.php` * 修改:line 20; `'maxsize' => '10mb',` 修改为: `'maxsize' => '2048mb',` * 修改:line 28; ` 'multiple' => false,` 修改为: ` 'multiple' => true,` * 修改:line 32; ` 'chunking' => false,` 修改为: ` 'chunking' => true,` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\public\assets\js\require-upload.js` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\public\assets\js\require-backend.min.js` * 修改:搜索; ```javascript class="btn btn-danger hidden faupload" ``` * 修改:替换; 修改为: ```javascript class="btn btn-danger hidden faupload" data-chunking="true" data-maxsize="2048M" data-timeout="600000" ``` ### 百度UEditor编辑器 后台附件上传允许文件: E:\WWWROOT\OtherPHPSystem\fastadmin\public\assets\addons\ueditor\dialogs\attachment\attachment.js line:162; ```javascript acceptExtensions = (editor.getOpt('fileAllowFiles') || [".txt", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".odt", ".ott", ".fodt", ".uot", ".xml", ".dot", ".htm", ".html", ".rtf", ".docm", ".zip", ".rar", ".tar", ".7z", ".tar.gz", ".tar.bz", ".tar.xz"]).join('').replace(/\./g, ',').replace(/^[,]/, ''); ``` line:235; ```javascript if ('|png|jpg|jpeg|bmp|gif|webp|'.indexOf('|' + file.ext.toLowerCase() + '|') == -1) { ``` E:\WWWROOT\OtherPHPSystem\fastadmin\public\assets\addons\ueditor\ueditor.config.js line:40; ```javascript imageMaxSize: 20971520, // 上传大小限制20Mb,单位B ``` ### 百度UEditor编辑器 本地上传图片默认不带网址(方便更换测试域名) E:\WWWROOT\OtherPHPSystem\fastadmin\public\assets\addons\ueditor\dialogs\image\image.js line:71; ```javascript var url = Fast.api.cdnurl(item, false); ``` line:787; ```javascript url: Fast.api.cdnurl(data.url, false), ``` ### 栏目添加默认 sitemap.html 和 sitemap.xml 处理逻辑(可自行模板定制) * 系统自带的sitemap未使用-请自行查看 * 模板文件sitemap.html 和 sitemapxml.html请自行处理 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\controller\Channel.php` * 添加:line 34-40; `if (!$channel || $channel['status'] != 'normal') { 在这里... $this->error(__('No specified channel found')); } ` 分支内部 ```php if('/sitemap.html' == $this->request->url()){ return $this->fetch('/sitemap'); } if('/sitemap.xml' == $this->request->url()){ return \think\Response::create($this->fetch('/sitemapxml'), 'html', 200, ['Content-Type' => 'text/xml; charset=utf-8']); } ``` ### 自定义表单在每个表单下可以自行设定成功后跳转url * 后台虽然可以设置但一个留言表只能有一个链接 * 自己的模板表单文件中添加:value="referer" 为跳转链接,默认成功返回上一页 ```html ``` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\controller\Diyform.php` * 添加:line: 297; `unset($row['id']);` 之后 ```php // 处理用户自定义跳转链接 if(isset($row['redirecturl']) && !empty($row['redirecturl'])){ $diy_redirecturl = $row['redirecturl']; unset($row['redirecturl']); } else{ $diy_redirecturl = ''; } ``` * 添加:line: 325; `$this->success($diyform['successtips'] ? $diyform['successtips'] : '提交成功!', $redirecturl);` 之前 ```php // 提交表单可以自定义跳转链接 if(!empty($diy_redirecturl)){ if('referer' == $diy_redirecturl){ $redirecturl = null; // 默认跳转引用页 } else{ $redirecturl = $diy_redirecturl; } } ``` ### 伪静态兼容模式 ?s=/static/image/logo.png 资源文件不存在时处理 !!!注意此修改会破坏插件URL路由 * 请在仅使用电脑版和手机版 *.html 链接时修改!如:api接口和小程序会连接错误! * 此修改是解决资源文件不存在时候自动刷新验证Token,前台留言验证码刷新,怎么都不对。 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\common\behavior\Common.php` * 添加:line: 79-82; `addonBegin` 函数体内 ```php $uri_ext = $request->ext(); if($uri_ext && (!in_array($uri_ext, ['xml', Config::get('default_return_type')]))) { throw new \think\exception\HttpException(404, 'uri suffix error!'); } ``` --- --- ## !!!以下更改内容影响整个框架目录,请仔细对比修改,推荐不修改,程序放在web目录之外,提高安全性 ## 程序适配 SiteGround 空间 public_html 为站点根目录 * 变更兼容public目录为变量,使之可以放入任意二级目录中 **** * 使用说明: * 适配某些空间固定的网站根目录,需要网站根目录外可以解压文件 1. 空间根目录外正常解压程序压缩包 2. public目录中所有文件复制到任意目录中如(public_html)中 **** ## 程序适配景安空间,首页放入根目录(直接解压到空间里运行) * 1、复制 public 目录中所有文件到 public 上级目录 (不需要的文件请自行处理) #### 生成缓存路径 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin_root\public_html\adminlogin.php` * 替换: ```php // 定义当前运行的web目录 define('WEB_DIR', __DIR__ . DIRECTORY_SEPARATOR); // 定义应用目录 if (is_dir(WEB_DIR . 'application/')) { define('APP_PATH', WEB_DIR . 'application/'); } else { define('APP_PATH', WEB_DIR . '../application/'); } // 判断是否安装 if (!is_file(APP_PATH . 'admin/command/Install/install.lock')) { header("location:./install.php"); exit; } // 加载框架引导文件 if (file_exists(WEB_DIR . 'thinkphp/base.php')) { require WEB_DIR . 'thinkphp/base.php'; } else { require WEB_DIR . '../thinkphp/base.php'; } // 绑定到admin模块 \think\Route::bind('admin'); // 关闭路由 \think\App::route(false); // 设置根url \think\Url::root(''); // 执行应用 \think\App::run()->send(); ``` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin_root\public_html\index.php` * 替换: ```php // 定义当前运行的web目录 define('WEB_DIR', __DIR__ . DIRECTORY_SEPARATOR); // 定义应用目录 if (is_dir(WEB_DIR . 'application/')) { define('APP_PATH', WEB_DIR . 'application/'); } else { define('APP_PATH', WEB_DIR . '../application/'); } // 判断是否安装 if (!is_file(APP_PATH . 'admin/command/Install/install.lock')) { header("location:./install.php"); exit; } // 加载框架引导文件 if (file_exists(WEB_DIR . 'thinkphp/start.php')) { require WEB_DIR . 'thinkphp/start.php'; } else { require WEB_DIR . '../thinkphp/start.php'; } ``` * 路径: `E:\WWWROOT\OtherPHPSystem\fastadmin_root\vendor\karsonzhang\fastadmin-addons\src\addons\Service.php` * 替换:line 377; `$addonsFile = ROOT_PATH . str_replace("/", DS, "public/assets/js/addons.js");` ```php $addonsFile = ROOT_PATH . str_replace("/", DS, "assets/js/addons.js"); if(defined('WEB_DIR') && strlen(WEB_DIR) > strlen(ROOT_PATH)){ $addonsFile = ROOT_PATH . str_replace("/", DS, basename(WEB_DIR) . "/assets/js/addons.js"); } ``` * 替换:line 1056; `$assetsDir = ROOT_PATH . str_replace("/", DS, "public/assets/addons/{$name}/");` ```php $assetsDir = ROOT_PATH . str_replace("/", DS, "assets/addons/{$name}/"); if(defined('WEB_DIR') && strlen(WEB_DIR) > strlen(ROOT_PATH)){ $assetsDir = ROOT_PATH . str_replace("/", DS, basename(WEB_DIR) . "/assets/addons/{$name}/"); } ``` * 添加:line 1078; `getCheckDirs` 函数体内第一行位置 ```php if(defined('WEB_DIR') && strlen(WEB_DIR) > strlen(ROOT_PATH)){ return [ 'application', 'public', basename(WEB_DIR) ]; } ``` #### 导入上传的路径 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin_root\application\admin\library\traits\Backend.php` * 替换:line 357; `$filePath = ROOT_PATH . DS . 'public' . DS . $file;` ```php $filePath = ROOT_PATH . DS . $file; if(defined('WEB_DIR') && strlen(WEB_DIR) > strlen(ROOT_PATH)){ $filePath = ROOT_PATH . DS . basename(WEB_DIR) . DS . $file; } ``` #### 上传文件路径 * 路径: `E:\WWWROOT\OtherPHPSystem\fastadmin_root\application\common\library\Upload.php` * 替换:line 371; `$destDir = ROOT_PATH . 'public' . str_replace('/', DS, $uploadDir);` ```php $destDir = rtrim(ROOT_PATH, DS) . str_replace('/', DS, $uploadDir); if(defined('WEB_DIR') && strlen(WEB_DIR) > strlen(ROOT_PATH)){ $destDir = ROOT_PATH . basename(WEB_DIR) . str_replace('/', DS, $uploadDir); } ``` #### 删除上传的文件 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\general\Attachment.php` * 替换:line 118; `$attachmentFile = ROOT_PATH . '/public' . $params['url'];` ```php $attachmentFile = rtrim(ROOT_PATH, DS) . $params['url']; if(defined('WEB_DIR') && strlen(WEB_DIR) > strlen(ROOT_PATH)){ $attachmentFile = ROOT_PATH . basename(WEB_DIR) . $params['url']; } ``` * 根目录放入Apache的伪静态配置文件.htaccess ```apacheconf Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L] ###不能访问目录 RewriteRule ^application - [F,L,NC] RewriteRule ^extend - [F,L,NC] RewriteRule ^runtime - [F,L,NC] RewriteRule ^thinkphp - [F,L,NC] RewriteRule ^vendor - [F,L,NC] ###不能执行目录 RewriteRule ^assets/(.*).(php)$ – [F,L,NC] RewriteRule ^template/(.*).(php)$ – [F,L,NC] RewriteRule ^mobile/(.*).(php)$ – [F,L,NC] RewriteRule ^static(.*).(php)$ – [F,L,NC] RewriteRule ^statics(.*).(php)$ – [F,L,NC] RewriteRule ^skin(.*).(php)$ – [F,L,NC] RewriteRule ^skins(.*).(php)$ – [F,L,NC] RewriteRule ^upload(.*).(php)$ – [F,L,NC] RewriteRule ^uploads(.*).(php)$ – [F,L,NC] ###限制后缀文件访问 order deny,allow deny from all ``` ```nginx location ~* (runtime|application)/{ return 403; } location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } } #禁止目录下执行脚本文件 if ( $uri ~ "^/(assets|theme|mobile|style|css|image|images|js|doc|template|static|statics|skin|skins|data|m|upload|uploads|rewrite)/.*\.(php|jsp|py)$" ) { return 403; } ``` ### !!! 修改网站 public 目录未处理的文件列表 * 下列文件中有使用public目录(但CMS网站日常操作不需要)可以自行修改 * `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\command\Addon.php` * `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\command\Api.php` * `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\command\Crud.php` * `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\command\Install.php` * `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\command\Min.php` * 各个插件的.addonrc配置文件 ### 百度收录织梦文章多级目录URL兼容SEO打开处理 !!!注意此修改会破坏插件URL路由 * 请在仅使用电脑版和手机版 *.html 链接时修改!如:api接口和小程序会连接错误! * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\Cms.php` * 添加:line: 128; `public function appInit()` 函数体内第一行 ```php $request = \think\Request::instance(); $request_url = $request->url(); // 百度收录织梦文章多级目录URL,fastadmin-cms系统302跳转处理 todo 手机URL未处理 附带参数未处理如:?1590650404 if (2 < substr_count($request_url, '/') && false === strpos($request_url, 'admin')) { $response_url = '/'; $request_url_array = explode('/', $request_url); foreach($request_url_array as $item){ if(false !== stripos($item, '.html')){ $response_url .= '/' . $item; } else{ $response_url .= ucfirst($item); } } header('Location:' . $response_url); exit(); } ``` ### 区块管理添加常用名称 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\model\cms\Block.php` * 修改:line: 67; ```php return ['pcbanner' => 'PC轮播图', 'wapbanner' => 'Phone轮播图', 'indexfocus' => 'PC首页焦点图', 'downloadfocus' => 'PC下载频道页焦点图', 'newsfocus' => 'PC资讯频道页焦点图', 'productfocus' => 'PC产品频道页焦点图', 'uniappfocus' => 'UniAPP焦点图', 'wxappfocus' => '原生微信小程序焦点图']; ``` ### UEditor 图片、视频、附件上传按钮美化 * public 文件夹复制覆盖即可(内部为3个样式表文件) ### 自定义表单管理-留言-字段列表 * 修改每个字段把验证规则全部删空(方便后期直接使用) ### 发布 uniapp 为H5 * 在你的项目的根目录/public 下新建一个目录为h5 把刚刚打包好的static文件夹和index.html上传到h5目录下 * 访问路径:域名/h5/ ``` nginx: location /h5/ { try_files $uri /h5/index.html; } apache: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^h5/(.*) /h5/index.html [QSA,PT,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond $1 !^(h5) RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L] ``` ### 启用本地环境调试配置 .env 文件 !!!注意线上一定要删除此文件 * 默认仅开启调试模式 * 注意此文件数据库链接配置 ### 添加一个客户管理员组并分配一个默认的管理员adminuser * 使客户便于管理网站和降低后台操作学习成本(此处单独开个文件更新——碰上过钻牛角尖的) * 文件名:客户管理权限设计.md * 仅赋予客户正常使用的权限(最小权限原则)例如: * 网站管理-站点配置 * 网站管理-栏目管理 * 网站管理-内容管理 * 网站管理-区块管理 * 网站管理-自定义表单管理 ### 后台文章权重 子管理员 mulit 修改提示无权限 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Archives.php` * 添加:line:31; `protected $searchFields = 'id,title';` 之后 ```php protected $multiFields = 'status,weigh'; ```