### Initiate Module Install Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/app/admin/view/module/index.html Event handler for the install button, triggering the module installation process with specified name and version. ```javascript $(document).on("click", ".btn-install", function () { var that = this; var name = $(that).parents(".operate").data("name"); var version = $(that).data("version"); install(name, version, false); }); ``` -------------------------------- ### Install Module Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/app/admin/view/module/index.html Handles the installation of a module. It triggers a layer confirmation for potential data conflicts and proceeds with installation if confirmed. ```javascript var install = function (name, version, force) { var area = [ $(window).width() > 650 ? "650px" : "95%", $(window).height() > 710 ? "710px" : "95%", ]; badou.api.ajax({ url: "module/install", data: { name: name, version: version, force: force ? 1 : 0 }, }, function (data, ret) { layer.closeAll(); bdTable.api.events.toolbar.refresh(); toast.success({ message: ret.msg, }); return false; }, function (data, ret) { if (ret && ret.code === -3) { //模块目录发现影响全局的文件 layer.open({ content: laytpl(conflicttpl, { tagStyle: "modern", }).render(ret.data), shade: 0.8, area: area, title: __("Warning"), btn: [__("Continue install"), __("Cancel")], end: function () { }, yes: function () { install(name, version, true); }, }); } else if (ret && ret.code == 401) { $(".btn-userinfo").trigger("click", name, version); return false; } else { layer.alert(ret.msg, { title: __("Warning"), icon: 0 }); } return false; }); }; ``` -------------------------------- ### Install Grunt CLI and Dependencies Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/modules/nkeditor/public/modules/nkeditor/README.md Install the Grunt CLI globally and then install project dependencies in the NKeditor root directory. ```bash npm install -g grunt-cli npm install ``` -------------------------------- ### Install Qiniu SDK with Composer Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/modules/nkeditor/public/modules/nkeditor/README.md If using Qiniu cloud upload, install the SDK in the php/qiniu directory using Composer. ```bash composer install ``` -------------------------------- ### Install SortableJS with NPM Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/public/assets/libs/sortablejs/README.md Install SortableJS using npm for use in your project. ```bash npm install sortablejs --save ``` -------------------------------- ### User Registration Request Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example of a POST request for user registration. Requires username, password, and a verification code. Email, mobile are optional. ```json { "username": "newuser", "password": "password123", "email": "user@example.com", "mobile": "13800138000", "code": "123456" } ``` -------------------------------- ### Install SortableJS with Bower Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/public/assets/libs/sortablejs/README.md Install SortableJS using Bower for use in your project. ```bash bower install --save sortablejs ``` -------------------------------- ### User Login Request Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example of a POST request to the user login endpoint. Requires account and password. Content-Type should be application/json. ```json { "account": "admin", "password": "password123" } ``` -------------------------------- ### taglib/Bd.php - Nav Tag Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/CMS模块开发文档.md Example of using the 'nav' tag in ThinkPHP templates to generate navigation links. ```php {bd:nav parent="0" id="nav"}{/bd:nav} ``` -------------------------------- ### Get Content Detail Response Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example JSON response for the content detail endpoint, including the full content and metadata. ```json { "code": 1, "msg": "", "data": { "id": 1, "scode": 1, "mcode": 1, "title": "文章标题", "description": "文章描述", "content": "完整内容", "thumb": "http://...", "author": "作者", "source": "来源", "date": "2024-06-28", "hits": 100, "likes": 10, "tags": "标签1,标签2", "status": "normal" } } ``` -------------------------------- ### Switch Token Storage Driver Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/api-reference/Token.md Demonstrates how to switch the token storage driver, for example, to use Redis instead of the default MySQL. Allows performing token operations on the selected driver. ```php // 使用 Redis 驱动替代 MySQL $tokenManager = new Token(); $redisDriver = $tokenManager->getDriver('redis'); // 在驱动上执行操作 $redisDriver->set($token, 'user', 123); ``` -------------------------------- ### Token Authentication Methods Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Demonstrates the various ways to provide a Token for API authentication. This can be done via the Authorization header, a cookie, or a GET parameter. ```text 请求头: Authorization: Bearer 或 Cookie: token= 或 GET 参数: ?token= ``` -------------------------------- ### User Logout Request Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example of a POST request to log out a user. Requires Token authentication. ```text POST /api/user/logout Authorization: Bearer ``` -------------------------------- ### taglib/Bd.php - List Tag Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/CMS模块开发文档.md Example of using the 'list' tag in ThinkPHP templates to fetch content lists, with pagination enabled. ```php {bd:list num="10" page="true"}{/bd:list} ``` -------------------------------- ### Implement User Login Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/README.md Use FrontendAuth::instance() to get an authentication instance and call login() with username and password. Retrieve user info upon successful login. ```php // 参考文档:FrontendAuth.md,ENDPOINTS.md $auth = FrontendAuth::instance(); if ($auth->login('username', 'password')) { // 登录成功 $userinfo = $auth->getUserinfo(); } ``` -------------------------------- ### User Login Success Response Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example of a successful response after user login. Includes user details. ```json { "code": 1, "msg": "登录成功", "data": { "userinfo": { "id": 1, "username": "admin", "nickname": "管理员", "email": "admin@example.com", "mobile": "13800138000", "avatar": "http://...", "status": "normal", "money": 0, "score": 0 } } } ``` -------------------------------- ### Register Custom Token Driver in Configuration Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/api-reference/Token.md Example of how to register a custom token driver in the application's configuration file. ```php 'token' => [ 'default' => 'custom', 'stores' => [ 'custom' => [ 'type' => 'app\custom\token\driver\CustomDriver' ] ] ] ``` -------------------------------- ### taglib/Bd.php - Qrcode Tag Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/CMS模块开发文档.md Example of using the 'qrcode' tag in ThinkPHP templates to generate a QR code from a given string, typically a URL. ```php {bd:qrcode string="$content.url" /} ``` -------------------------------- ### Mobile Verification Code Login Request Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example of a POST request for logging in using a mobile number and verification code. Content-Type should be application/json. ```json { "mobile": "13800138000", "captcha": "123456" } ``` -------------------------------- ### taglib/Bd.php - Content Tag Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/CMS模块开发文档.md Example of using the 'content' tag in ThinkPHP templates to retrieve details of a specific content item by its ID. ```php {bd:content id="$id"}{/bd:content} ``` -------------------------------- ### Change Password Request Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example of a POST request to change a user's password. Requires current and new passwords. Content-Type should be application/json. ```json { "oldpassword": "oldpass123", "newpassword": "newpass123" } ``` -------------------------------- ### Plugin Entry File Structure Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/插件开发指南.md The main entry file for a plugin defines its lifecycle methods. It includes namespaces, use statements for necessary classes like Menu and Log, and implementations for AppInit, install, uninstall, enable, and disable. ```php getData()); // }); // 示例:在列表页面头部增加一个按钮 // function toolbarFilter($content) // { // if (request()->controller() == 'cms.ContentSort') { // $pattern = '/()(.*?)(<\/script>)/is'; // $url = 'cms.content/copy'; // $replacement = '$1$2 // // // 新增加一个按钮 // $3'; // $content = preg_replace($pattern, $replacement, $content); // } // return $content; // } // View::filter(function ($content) {return toolbarFilter($content);}); return []; } /** * 插件安装时调用 * 创建菜单、执行数据库安装、文件拷贝等操作 * @return bool */ public function install() { try { // 示例: 执行SQL文件 // \think\facade\Db::execute(file_get_contents(__DIR__ . '/install.sql')); // 定义插件的菜单结构 // Menu::create 方法接受一个菜单数组,其中可以包含 sublist 来定义子菜单。 // 菜单的 name 字段通常用作权限标识,建议使用插件的唯一标识符作为前缀。 // 确保菜单数组中的字段(如 pid、name、title、url、type、status、weigh、ismenu 等) // 与 AdminRule 表的字段定义以及 Menu 类内部处理逻辑一致。 // 特别是 status 字段,Menu.php 中使用的是 'normal' 和 'hidden' 而非 1 和 0。 $menuList = [ [ 'name' => 'your_plugin_name', 'title' => '您的插件', 'icon' => 'fa fa-plug', 'url' => 'your_plugin_name/index/index', 'type' => 1, 'status' => 'normal', 'weigh' => 0, 'ismenu' => 1, 'sublist' => [ [ 'name' => 'your_plugin_name/sub/index', 'title' => '子功能列表', 'icon' => 'fa fa-list', 'url' => 'your_plugin_name/sub/index', 'type' => 1, 'status' => 'normal', 'weigh' => 0, 'ismenu' => 1, ], // ... 更多子菜单或权限规则 ] ] ]; // 调用 Menu::create 方法创建菜单 Menu::create($menuList); return true; // 安装成功返回true,失败返回false } catch (\Exception $e) { Log::error('插件安装失败: ' . $e->getMessage()); return false; } } /** * 插件卸载时调用 * 删除菜单、执行数据库清理、文件删除等操作 * @return bool */ public function uninstall() { try { // 示例: 执行SQL文件 // \think\facade\Db::execute(file_get_contents(__DIR__ . '/uninstall.sql')); // 调用 Menu::delete 方法删除插件相关的所有菜单和权限规则 // 传入插件的顶级菜单 name,这样可以批量操作该插件下的所有菜单。 Menu::delete('your_plugin_name'); return true; // 卸载成功返回true,失败返回false } catch (\Exception $e) { Log::error('插件卸载失败: ' . $e->getMessage()); return false; } } /** * 插件启用时调用 * 开启菜单 * @return bool */ public function enable() { try { // 调用 Menu::enable 方法启用插件相关的所有菜单和权限规则 // 传入插件的顶级菜单 name,这样可以批量操作该插件下的所有菜单。 Menu::enable('your_plugin_name'); return true; } catch (\Exception $e) { Log::error('插件启用失败: ' . $e->getMessage()); return false; } } /** * 插件禁用时调用 * 关闭菜单 * @return bool */ public function disable() { try { // 调用 Menu::disable 方法禁用插件相关的所有菜单和权限规则 // 传入插件的顶级菜单 name,这样可以批量操作该插件下的所有菜单。 Menu::disable('your_plugin_name'); return true; } catch (\Exception $e) { Log::error('插件禁用失败: ' . $e->getMessage()); return false; } } } ``` -------------------------------- ### Controller with Data-Level Permissions Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/api-reference/BackendTrait.md This example demonstrates how to enable data-level permissions using the Backend trait. It configures the trait to limit data access based on the 'admin_id' field, automatically filling it on creation and filtering records during queries. ```php class Article extends BaseController { use Backend; protected $model = Article::class; protected $dataLimit = true; protected $dataLimitField = 'admin_id'; protected $dataLimitFieldAutoFill = true; // 新增时自动填充 admin_id 为当前用户 // 查询时自动过滤该用户的下级管理员创建的记录 } ``` -------------------------------- ### Get Category List Response Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example JSON response for retrieving a list of categories, which may include nested children. ```json { "code": 1, "msg": "", "data": [ { "id": 1, "mcode": 1, "name": "news", "title": "新闻中心", "description": "公司新闻", "pid": 0, "status": "normal", "children": [...] } ] } ``` -------------------------------- ### Get Content List Response Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example JSON response for the content list endpoint, showing the structure of returned data including pagination totals. ```json { "code": 1, "msg": "", "data": [ { "id": 1, "scode": 1, "title": "文章标题", "description": "文章描述", "thumb": "http://...", "author": "作者", "date": "2024-06-28", "hits": 100, "likes": 10, "status": "normal", "istop": 0, "isrecommend": 1 } ], "total": 50 } ``` -------------------------------- ### 监听用户登录成功事件 Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/插件开发指南.md 在插件的 `AppInit()` 方法中注册一个事件监听器,用于在用户成功登录后执行自定义逻辑。此示例演示了如何监听 'user_login_success' 事件,并在事件触发时记录一条日志信息。 ```php // 在插件的 AppInit() 方法中注册监听 \think\facade\Event::listen('user_login_success', function($user_id){ // 插件的业务逻辑,例如记录登录日志 \think\facade\Log::info('用户 ' . $user_id . ' 登录成功,由插件处理。'); }); ``` -------------------------------- ### Enable Cloud Storage (OSS) Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/CONFIGURATION.md Configure the upload module to use Alibaba Cloud Object Storage Service (OSS). ```php // config/upload.php 'oss' => [ 'enabled' => true, 'bucket' => 'mybucket', 'endpoint' => 'oss-cn-beijing.aliyuncs.com', 'access_key' => 'your-access-key', 'secret_key' => 'your-secret-key', 'use_https' => true, 'storage_path' => 'badoucms/', ] ``` -------------------------------- ### System Information Parameters Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/CONFIGURATION.md Configuration for system version, API server address, and module initialization key. ```php 'version' => 'v2.2.5' // 系统版本号 'api_url' => 'https://sq.badoucms.com/' // API 服务器地址 'module_init_key' => 'bW9kdWxlSW5pdA==' // 模块初始化密钥 ``` -------------------------------- ### taglib/Bd.php - Position Tag Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/CMS模块开发文档.md Example of using the 'position' tag in ThinkPHP templates to generate breadcrumb navigation. ```php {bd:position /} ``` -------------------------------- ### Compile and Build NKeditor Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/modules/nkeditor/public/modules/nkeditor/README.md Compile the project using Grunt. To create a distributable package, run 'grunt zip'. ```bash grunt grunt zip ``` -------------------------------- ### taglib/Bd.php - Sort Tag Example Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/CMS模块开发文档.md Example of using the 'sort' tag in ThinkPHP templates to retrieve a list of subcategories. ```php {bd:sort scode="$sort.scode" id="subsort"}{/bd:sort} ``` -------------------------------- ### Module/Plugin Configuration for Upgrades Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/CONFIGURATION.md Settings to control file backup during upgrades and to specify directories or files to be ignored during the upgrade process. ```php 'backup_global_files' => true // 启用/禁用时是否备份全局文件 'upgrade_ignore_dirs' => ['/template/cms/default/'] // 升级时忽略的目录 'upgrade_ignore_files' => ['bd_functions.php'] // 升级时忽略的文件 ``` -------------------------------- ### common.php - Create File Function Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/CMS模块开发文档.md Creates a file at the specified path with optional content and overwrite option. ```php create_file($path, $content = null, $over = false); ``` -------------------------------- ### Object Storage Configuration (Optional) Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/CONFIGURATION.md Configure optional object storage services like OSS or Qiniu for cloud-based file uploads. Set 'enabled' to true to activate. ```php 'oss' => [ 'enabled' => false, 'bucket' => '', 'endpoint' => '', 'access_key' => '', 'secret_key' => '', 'use_https' => true, 'storage_path' => '', ], 'qiniu' => [ 'enabled' => false, 'bucket' => '', 'domain' => '', 'access_key' => '', 'secret_key' => '', ] ``` -------------------------------- ### Cherrypick and Mount Core Plugins Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/public/assets/libs/sortablejs/README.md Cherrypick plugins like AutoScroll from the core modular build and mount them with SortableJS. ```javascript // Cherrypick default plugins import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js'; Sortable.mount(new AutoScroll()); ``` -------------------------------- ### Production Environment Base Settings Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/CONFIGURATION.md Configure security, database, and application settings for a production environment. ```php // config/badouadmin.php 'admin_failure_retry' => 5, 'admin_failure_lock_time' => 3600, // 1 小时 'login_unique' => true, 'loginip_check' => true, 'cors_request_domain' => 'example.com,www.example.com', // 具体指定域名 // config/database.php 'hostname' => 'db.example.com', 'database' => 'badoucms_prod', 'username' => 'dbuser', 'password' => 'strongpassword', 'charset' => 'utf8mb4', // config/app.php 'app_debug' => false, // 关闭调试模式 ``` -------------------------------- ### Create New Admin User Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/TYPES_AND_MODELS.md Create a new administrator account using the `create` static method on the Admin model. Ensure the password is properly hashed. ```php $admin = Admin::create([ 'username' => 'newadmin', 'password' => password_hash('password', PASSWORD_DEFAULT), 'nickname' => '新管理员', 'status' => 'normal' ]); ``` -------------------------------- ### Catch TokenExpirationException Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/api-reference/Token.md Example of how to catch and handle a TokenExpirationException when retrieving a token. ```php use app\common\library\token\TokenExpirationException; try { $token->get($tokenString); } catch (TokenExpirationException $e) { // Handle expired token echo '令牌已过期,错误消息: ' . $e->getMessage(); } ``` -------------------------------- ### Display Program Version Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/app/admin/view/dashboard/index.html Displays the application version using the config helper. ```html {:config('badouadmin.version')} ``` -------------------------------- ### User Logout Success Response Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example of a successful response after a user logs out. ```json { "code": 1, "msg": "退出登录成功" } ``` -------------------------------- ### Get Label List Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Retrieves a list of labels. Supports pagination and searching. ```APIDOC ## GET /api/cms/label ### Description Retrieves a list of labels. Supports pagination and searching. ### Method GET ### Endpoint /api/cms/label ### Parameters #### Query Parameters - **limit** (int) - Optional - Number of items per page - **search** (string) - Optional - Search keyword ``` -------------------------------- ### Initialize and Configure Baidu Map Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/modules/nkeditor/public/modules/nkeditor/plugins/baidumap/index.html Sets up the Baidu Map container size and initializes the map with specified center, zoom, and adds controls. Handles potential errors if the BMap library is not loaded. ```javascript function getParam(name) { return location.href.match(new RegExp('[?&]' + name + '=(\[?&]+)', 'i')) ? decodeURIComponent(RegExp.$1) : ''; } var centerParam = getParam('center'); var zoomParam = getParam('zoom'); var widthParam = getParam('width'); var heightParam = getParam('height'); var markersParam = getParam('markers'); var markerStylesParam = getParam('markerStyles'); //创建和初始化地图函数: function initMap() { // [FF]切换模式后报错 if (!window.BMap) { return; } var dituContent = document.getElementById('dituContent'); dituContent.style.width = widthParam + 'px'; dituContent.style.height = heightParam + 'px'; createMap(); //创建地图 setMapEvent(); //设置地图事件 addMapControl(); //向地图添加控件 // 创建标注 var markersArr = markersParam.split(','); var point = new BMap.Point(markersArr[0], markersArr[1]); var marker = new BMap.Marker(point); map.addOverlay(marker); //将标注添加到地图中 } ``` -------------------------------- ### Get Category List Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Retrieves a list of categories. Supports filtering by model ID. ```APIDOC ## GET /api/cms/sort ### Description Retrieves a list of categories. Supports filtering by model ID. ### Method GET ### Endpoint /api/cms/sort ### Parameters #### Query Parameters - **mcode** (int) - Optional - Model ID ### Response #### Success Response (200) - **code** (int) - Response code - **msg** (string) - Response message - **data** (array) - Array of category objects - **id** (int) - Category ID - **mcode** (int) - Model ID - **name** (string) - Category name - **title** (string) - Category title - **description** (string) - Category description - **pid** (int) - Parent category ID - **status** (string) - Category status - **children** (array) - Nested children categories ``` -------------------------------- ### Get Content Detail Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Retrieves the full details of a specific content item by its ID. ```APIDOC ## GET /api/cms/content/:id ### Description Retrieves the full details of a specific content item by its ID. ### Method GET ### Endpoint /api/cms/content/:id ### Parameters #### Path Parameters - **id** (int) - Required - Content ID ### Response #### Success Response (200) - **code** (int) - Response code - **msg** (string) - Response message - **data** (object) - Content details - **id** (int) - Content ID - **scode** (int) - Category ID - **mcode** (int) - Model ID - **title** (string) - Content title - **description** (string) - Content description - **content** (string) - Full content - **thumb** (string) - Thumbnail URL - **author** (string) - Author name - **source** (string) - Content source - **date** (string) - Publication date - **hits** (int) - View count - **likes** (int) - Like count - **tags** (string) - Tags associated with the content - **status** (string) - Content status ### Request Example ```bash GET /api/cms/content/1 ``` ``` -------------------------------- ### 定义插件前台路由 Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/插件开发指南.md 在 `app/index/route/your_plugin_name.php` 文件中定义插件的路由规则。注意避免与 CMS 核心路由冲突。此示例定义了一个名为 'your_plugin_name' 的路由组,包含一个 'index' 路由和一个带参数的 'hello' 路由,并设置了可选的路由后缀。 ```php ext('html'); // 可选:设置路由后缀 ``` -------------------------------- ### 控制器继承 BadouAdmin 基类 Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/插件开发指南.md 所有后台控制器必须继承自 `app\common\controller\Backend` 基类,以获得系统提供的通用功能和权限控制。 ```php enable(); } catch (ModuleException $e) { echo '模块操作失败:' . $e->getMessage(); } ``` -------------------------------- ### User Login Error Response Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Example of an error response during user login, indicating incorrect credentials. ```json { "code": 0, "msg": "用户名不正确" } ``` -------------------------------- ### common.php - Get User IP Function Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/CMS模块开发文档.md A utility function to retrieve the user's IP address. ```php get_user_ip(); ``` -------------------------------- ### Get User Info Endpoint Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Retrieves user information for the authenticated user. Requires Token authentication. ```json { "code": 1, "msg": "", "data": { "welcome": "欢迎,张三" } } ``` -------------------------------- ### Querying User by Username, Email, or Mobile Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/api-reference/FrontendAuth.md Demonstrates how to retrieve a User model instance using predefined static methods based on username, email, or mobile number. Ensure the User model is correctly imported. ```php use app\common\model\User; // 通过 User 模型的魔术方法查询 $user = User::getByUsername('admin'); $user = User::getByEmail('admin@example.com'); $user = User::getByMobile('13800138000'); ``` -------------------------------- ### Get Content Detail Request Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Retrieve the full details of a specific content item by providing its ID in the URL. ```bash GET /api/cms/content/1 ``` -------------------------------- ### Cache Configuration Settings Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/CONFIGURATION.md Configure the default cache driver and file cache path. ```php 'default' => 'file', // 默认驱动 'stores' => [ 'file' => [ 'type' => 'File', 'path' => runtime_path() . 'cache', ] ] ``` -------------------------------- ### Initialize Layui Modules and ECharts Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/app/admin/view/dashboard/index.html Initializes Layui modules (layer, carousel, element, table) and ECharts for the dashboard. Sets up click handlers for data-url attributes and configures the ECharts line chart for user registration data. ```javascript layui.use(["layer", "carousel", "element", "table"], function () { var $ = layui.jquery, layer = layui.layer, element = layui.element, table = layui.table, carousel = layui.carousel; var echartsRecords = echarts.init(document.getElementById("echarts-records"), "walden"); $("body").on("click", "[data-url]", function () { var url = $(this).attr("data-url"); url = /^(http|https):\/\//.test(url) ? url : Config.app_url + "/" + url; parent.layui.tab.addTabOnlyByElem("content", { id: $(this).attr("data-id"), title: $(this).attr("data-title"), url: url, close: true, }); }); let color = ["#0090FF", "#36CE9E", "#FFC005", "#FF515A", "#8B5CFF", "#00CA69"]; option = { color: color, legend: { right: 10, top: 10, }, tooltip: { trigger: "axis", }, grid: { top: 80, bottom: "6%", left: "3%", right: "3%", containLabel: true, }, xAxis: { type: "category", boundaryGap: false, data: Config.column, }, yAxis: {}, series: [ { name: "注册会员数量", type: "line", smooth: true, symbolSize: 8, zlevel: 3, data: Config.userdata, }, ], }; echartsRecords.setOption(option); window.onresize = function () { echartsRecords.resize(); }; }); ``` -------------------------------- ### User Center - Get User Info Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Retrieves the current user's information. This endpoint requires authentication. ```APIDOC ## GET /api/user/index ### Description Retrieves the current user's information. ### Method GET ### Endpoint /api/user/index ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **data** (object) - Contains user specific data, e.g., {"welcome": "欢迎,张三"} #### Response Example ```json { "code": 1, "msg": "", "data": { "welcome": "欢迎,张三" } } ``` ``` -------------------------------- ### Database Connection Configuration Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/CONFIGURATION.md Configure default database driver and connection details. Ensure 'utf8mb4' charset for production environments. ```php 'default' => 'mysql', 'connections' => [ 'mysql' => [ 'type' => 'mysql', 'hostname' => '127.0.0.1', 'database' => 'badoucms', 'username' => 'root', 'password' => '', 'hostport' => '3306', 'charset' => 'utf8mb4', 'prefix' => '', 'strict' => false, 'engine' => 'InnoDB', 'execute_timeout' => null, ] ] ``` ```php 'charset' => 'utf8mb4' ``` -------------------------------- ### common.php - Get Mapping Array Function Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/CMS模块开发文档.md Creates a mapping array from a data array, using specified keys and values. ```php get_mapping($array, $vValue, $vKey = null); ``` -------------------------------- ### Initiate Module Uninstall Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/app/admin/view/module/index.html Handles the click event for the uninstall button. It checks if the module is disabled and then prompts for confirmation, including an option to drop tables. ```javascript $(document).on("click", ".btn-uninstall", function () { var that = this; var name = $(that).parents(".operate").data("name"); var title = $(that).parents(".operate").data("title"); var state = $(this).data("state"); if (state == 1) { layer.alert(__("Please disable the add before trying to uninstall"), { icon: 7, }); return false; } laytpl.extendVars({ __: __, }); var uninstalltpl = document.getElementById("uninstalltpl").innerHTML; layer.confirm( laytpl(uninstalltpl).render({ title: title, name: name }), { focusBtn: false, title: __("Warning") }, function (index, layero) { uninstall( name, false, $("input[name='droptables']", layero).prop("checked"), ); } ); }); ``` -------------------------------- ### Get Custom Form Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Retrieves the details of a specific custom form, including its fields, by its ID. This endpoint does not require authentication. ```APIDOC ## GET /api/cms/form/:id ### Description Retrieves the details of a specific custom form, including its fields, by its ID. This endpoint does not require authentication. ### Method GET ### Endpoint /api/cms/form/:id ### Parameters #### Path Parameters - **id** (int) - Required - The unique identifier of the form. ### Response #### Success Response (200) - **code** (int) - Indicates success (1 for success). - **msg** (string) - Empty string on success. - **data** (object) - Contains the form details. - **id** (int) - The unique identifier of the form. - **name** (string) - The internal name of the form. - **title** (string) - The display title of the form. - **description** (string) - A description for the form. - **fields** (array) - An array of form field objects. - **id** (int) - The unique identifier of the field. - **name** (string) - The name of the field (used for submission). - **title** (string) - The display title of the field. - **type** (string) - The input type of the field (e.g., 'text', 'email'). - **required** (boolean) - Indicates if the field is mandatory. #### Response Example { "code": 1, "msg": "", "data": { "id": 1, "name": "contact_form", "title": "联系我们", "description": "请填写您的信息", "fields": [ { "id": 1, "name": "name", "title": "姓名", "type": "text", "required": true }, { "id": 2, "name": "email", "title": "邮箱", "type": "email", "required": true } ] } } ``` -------------------------------- ### common.php - Create Directory Function Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/docs/CMS模块开发文档.md Creates a directory at the specified path. ```php create_dir($path); ``` -------------------------------- ### Get Custom Form API Response Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md This JSON response details a custom form, including its fields, types, and requirements. ```json { "code": 1, "msg": "", "data": { "id": 1, "name": "contact_form", "title": "联系我们", "description": "请填写您的信息", "fields": [ { "id": 1, "name": "name", "title": "姓名", "type": "text", "required": true }, { "id": 2, "name": "email", "title": "邮箱", "type": "email", "required": true } ] } } ``` -------------------------------- ### Initiate Module Upgrade Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/app/admin/view/module/index.html Event handler for the upgrade button, triggering the module upgrade process with the module's name and version. ```javascript $(document).on("click", ".btn-upgrade", function () { var that = this; var name = $(that).parents(".operate").data("name"); var version = $(that).data("version"); upgrade(name, version); }); ``` -------------------------------- ### Get Content List Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Retrieves a paginated list of content items. Supports filtering by category, model, sorting, and searching. ```APIDOC ## GET /api/cms/content ### Description Retrieves a paginated list of content items. Supports filtering by category, model, sorting, and searching. ### Method GET ### Endpoint /api/cms/content ### Parameters #### Query Parameters - **scode** (int) - Optional - Category ID - **mcode** (int) - Optional - Model ID - **limit** (int) - Optional - Number of items per page (default 10) - **page** (int) - Optional - Page number - **sort** (string) - Optional - Field to sort by - **order** (string) - Optional - Sort order (asc/desc) - **search** (string) - Optional - Search keyword ### Response #### Success Response (200) - **code** (int) - Response code - **msg** (string) - Response message - **data** (array) - Array of content items - **id** (int) - Content ID - **scode** (int) - Category ID - **title** (string) - Content title - **description** (string) - Content description - **thumb** (string) - Thumbnail URL - **author** (string) - Author name - **date** (string) - Publication date - **hits** (int) - View count - **likes** (int) - Like count - **status** (string) - Content status - **istop** (int) - Whether it is top - **isrecommend** (int) - Whether it is recommended - **total** (int) - Total number of content items ### Request Example ```bash GET /api/cms/content?scode=1&limit=10&page=1&sort=date&order=desc ``` ``` -------------------------------- ### Get Content List Request Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Use this endpoint to retrieve a list of content items. You can filter and sort the results using query parameters. ```bash GET /api/cms/content?scode=1&limit=10&page=1&sort=date&order=desc ``` -------------------------------- ### Cherrypick and Mount Plugins Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/public/assets/libs/sortablejs/README.md Cherrypick specific plugins like MultiDrag and Swap, then mount them with SortableJS. ```javascript // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(), new Swap()); ``` -------------------------------- ### Get Comments List API Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/ENDPOINTS.md Retrieves a list of comments for a given content ID. Supports pagination with 'limit' and 'page' parameters. No authentication is required. ```json { "code": 1, "msg": "", "data": [ { "id": 1, "content": "很好的文章", "user_id": 1, "user_name": "张三", "user_avatar": "http://...", "create_time": "2024-06-28 10:00:00", "likes": 5, "replies": [...] } ], "total": 10 } ``` -------------------------------- ### Initialize Layui and Bind Form Events Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/app/admin/view/auth/rule/add.html Initializes the Layui framework and binds form events to dynamically update UI elements based on user selections for menu and type. ```javascript layui.use(['badou'],function () { var bdForm = layui.bdForm; var form = layui.form; function toggleMenuConfig() { var name = $("input[name='row[name]']"); var ismenu = $("input[name='row[ismenu]']:checked").val() == 1; var type = $("input[name='row[type]']:checked").val(); name.prop("placeholder", ismenu ? name.data("placeholder-menu") : name.data("placeholder-node")); $("div[data-type='menu']").toggleClass("layui-hide", !ismenu); $("div[data-quick-menu]").toggleClass("layui-hide", !(ismenu && type === "1")); } form.on('radio(ismenu)', toggleMenuConfig); form.on('radio(type)', toggleMenuConfig); toggleMenuConfig(); bdForm.api.bindevent($("form.layui-form")); }) ``` -------------------------------- ### checkExecutable() Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/_autodocs/api-reference/Upload.md Checks if a file is an executable script to prevent malicious code uploads. It prohibits files starting with '.' and specific PHP or HTML file extensions. ```APIDOC ## checkExecutable() ### Description Detects if a file is an executable script to prevent the upload of malicious code. ### Rules: 1. Files starting with '.' are prohibited. 2. PHP-related files (php, phar, phtml, php3-php8) are prohibited. 3. HTML files (html, htm) are prohibited. ### Exception: - `UploadException` is thrown if the file type is restricted. - Exception message: `'Uploaded file format is limited'` ### Example: ```php // The following files will be rejected: // .htaccess // shell.php // index.phtml // script.html ``` ``` -------------------------------- ### Initialize Form and Table Bindings Source: https://github.com/lxc939134342/badoucms/blob/2.0-dev/app/admin/view/general/profile/index.html Binds event listeners to forms and initializes the user log table. ```javascript bdForm.api.bindevent($("form.layui-form")); //初始化表格 bdTable.api.init({ table: table, // layui 表格对象,支持普通table与树结构table extend: { index_url: "auth.adminlog/selectpage", //获取表格数据 del_url: "auth.adminlog/del", //删除数据 table: "adminlog", //数据表名称 }, }); ```