# Fastadmin_cms_optimize **Repository Path**: hellowangming/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**: 2024-01-09 - **Last Updated**: 2024-01-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Fastadmin-CMS网站内容管理系统程序修改日志 ### * 注该cms插件为官方收费插件请自行在官方渠道购买安装! #### 此项目仅为系统日常使用中遇到的奇葩问题的小小优化 #### Author:xslooi #### 适配系统: * Fastadmin框架 version = V1.4.0.20230711 * title = CMS内容管理系统 version = 1.5.23 * title = 百度ueditor插件 version = 1.0.9 ### 网站后台修改登录地址: * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\public\adminlogin88.php` * 系统安装默认生成的后台入口文件名称修改 * 链接:`http://localhost/adminlogin88.php/index/login` ### CMS设置为首页 * 网站后台->CMS管理->站点配置->伪静态->值里边去掉 `/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; ``` ### 栏目名称字段修改长度为 200 ```sql ALTER TABLE `fa_cms_channel` MODIFY COLUMN `name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '名称' AFTER `parent_id`; ``` ### 模型管理-新闻-添加自定义字段 * shorttitle 短标题 字符 * source 来源 字符 ### 添加常用字段如:电话、手机、微信、邮箱、地址等 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\config.php` * 添加:line: 1067; ```php [ 'name' => 'sitecopyright', 'title' => '网站版权说明', 'type' => 'string', 'content' => [], 'value' => 'Copyright © 2018-2022 版权所有', 'rule' => '', 'msg' => '', 'tip' => '网站底部常见的Copyright 20XX 版权所有等描述信息', 'ok' => '', 'extend' => '', ], [ 'name' => 'icp_license', 'title' => '网站备案号', 'type' => 'string', 'content' => [], 'value' => '豫ICP备12345678号', 'rule' => '', 'msg' => '', 'tip' => '中国大陆网站备案号http://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: 13; `'config'=>'system_user_id,sitename,sitelogo,title,keywords,description,indexpagesize,theme,qrcode,wxapp,donateimage,userpage,openedsite,searchtype,autopinyin,baidupush,usersidenav,loadmode,pagemode,indexloadmode,indexpagemode,cachelifetime,urlsuffix,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: 73; ```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 41; line 194; `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Channel.php` * 路径:line 34; `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Builder.php` * 路径:line 52; line 272; `E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Archives.php` * 路径:line 176; `E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\controller\Api.php` * 路径:line 190; line 208; line 239; line 361; line 407; line 491; `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 269; `desc` 修改为 `asc` * 修改:line 273; `$orderway : 'desc';` 修改为 `$orderway : 'asc';` ### 后台添加内容默认权重递增 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Archives.php` * 添加:add方法 ```php /** * 添加 * * @return string * @throws \think\Exception */ public function add() { 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 203; `0` 修改为 `{$row_weigh}` ### 页码默认边界修改(使手机一行可放下) * 路径:`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 578; `prev` 修改为: `next` * 修改-添加:line 582; ```php $weigh = self::where(['id'=>$archives])->value('weigh'); $model = self::where('weigh', $type === 'next' ? '<' : '>', $weigh)->where('status', 'normal'); ``` * 修改:line 591; ```php $model->order($type === 'prev' ? 'id desc' : 'id asc'); //修改为: $model->order($type === 'next' ? 'weigh desc, id desc' : 'weigh asc, id asc'); ``` ### 栏目添加默认导航显示isnav=1 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\view\cms\channel\add.html` * 修改:line 169; value="0" 修改为 value="1" * 修改:line 171; `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 19; `$config = get_addon_config('cms');` * 修改:line 43; line 44; ```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 173; line 174; ```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 89; line 90; ```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('/'; }, events: { "dblclick .text-weigh": function (e) { e.preventDefault(); e.stopPropagation(); return false; } }, sortable: true }, ``` * 添加:line 415-421; * 添加在 ```javascript Controller.index // 方法体内, 在$(document).on('click', '.btn-move', 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 229; `weigh desc,id desc` 修改为:`weigh asc,id asc` ### 文章标题-遇到不认识的编码 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\library\VicWord.php` * 修改:line 91; ```php // exit('我不认识的编码'); return false; // todo 遇到不认识的编码返回false ``` * 添加:line 176-179; 在 `list($d, $i) = $this->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 129; ```html ``` ### 关闭标题和文章名称自动转换拼音 并添加按钮手动识别 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\view\cms\channel\add.html` * 修改:line 89 - 91; ```html
``` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\view\cms\channel\edit.html` * 修改:line 90 - 92; ```html
``` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\public\assets\js\backend\cms\channel.js` * 删除:line 405 - 424; ```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 405 - 424; 上边删除的位置 ```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 108; ` $query->where('a.title', 'like', '%' . $item . '%'); ` 修改为: ` $query->where('a.title|a.description', 'like', '%' . $item . '%'); ` ### 百度UEditor 视频和附件上传采用系统分片上传(同时修改文件上传大小) * 路径:`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` * 修改:搜索; ```javascript class="btn btn-danger hidden faupload" ``` * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\public\assets\js\require-backend.min.js` * 修改:替换; 修改为: ```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(/^[,]/, ''); ``` ### 添加一个客户管理员组并分配一个默认的管理员adminuser * 使客户便于管理网站和降低后台操作学习成本 * 仅赋予客户正常使用的权限(最小权限原则)例如: * 网站管理-站点配置 * 网站管理-栏目管理 * 网站管理-内容管理 ### 后台文章权重 子管理员 mulit 修改提示无权限 * 路径:`E:\WWWROOT\OtherPHPSystem\fastadmin\application\admin\controller\cms\Archives.php` * 添加:line:32; `protected $searchFields = 'id,title';` 之后 ```php protected $multiFields = 'status,weigh'; ``` ### 修改cms - config.html 非总管理员菜单显示 * 路径: `E:\WWWROOT\OtherPHPSystem\fastadmin\addons\cms\config.html` * 修改:line: 28; ```html