功能
为单个附件独立配置下载权限,支持 6 种权限类型:
public公开(默认)login登录可见credit积分购买(按enabled_credits_types与default_price配置扣费)vipVIP 专属(按vip_gids用户组列表放行)reply回复可见(用户在该附件所属主题下有回帖)group指定用户组(按permission_params.gids放行)
购买与退款:用户积分扣费购买后写入
xnx_attach_access_purchase(UNIQUE KEY (aid,uid));退款时status=0但保留记录,重新购买走ON DUPLICATE KEY UPDATE复原豁免规则:管理员(gid=1/2)与附件作者(
attach.uid)自动放行下载拦截:在
attach_download_starthook 拦截下载入口,未通过checkAccess直接message(-1)阻止多入口注入:
发帖/编辑帖时附件列表
model_post_file_list_html_end注入「权限配置」按钮主题页
thread_end.htm/ 帖子页post_ref_thread_after.htm渲染权限标识与解锁提示帖子 JS
post_js.htm/ 主题 JSthread_js.htm注入购买/查询交互
级联清理:删帖(
model_thread_delete_start/model_post_delete_start)时自动清理对应附件的权限记录后台路由
admin_attach_access提供统计/管理面板(仅 gid=1/2)前台路由
attach-access-purchase(POST 扣费购买)/attach-access-status(GET 查询访问状态)缓存:权限数据与购买状态均使用「版本号 + 数据」双层缓存(版本号 86400 秒、数据 3600 秒),写操作通过
bumpPermissionVersion/bumpPurchasedVersion失效
文件结构
plugin/xnx_attach_access/
├── conf.json
├── install.php / uninstall.php
├── model/AttachAccessService.php
├── route/
│ ├── admin_attach_access.php (后台统计/管理面板)
│ └── attach_access.php (前台 purchase / status 接口)
├── hook/
│ ├── model_inc_file.php
│ ├── model_route_table_end.php
│ ├── index_route_case_end.php
│ ├── admin_index_route_case_end.php
│ ├── attach_start.php
│ ├── attach_download_start.php (下载入口拦截)
│ ├── attach_assoc_post_end.php
│ ├── model_attach_create_end.php
│ ├── model_post_delete_start.php
│ ├── model_post_update_end.php
│ ├── model_post_file_list_html_end.php
│ ├── model_thread_delete_start.php
│ ├── post_js.htm
│ ├── post_ref_thread_after.htm
│ ├── thread_end.htm
│ ├── thread_js.htm
│ ├── lang_zh_cn_bbs.php
│ ├── lang_zh_tw_bbs.php
│ └── lang_en_us_bbs.php
├── view/htm/
│ ├── setting.htm
│ ├── attach_access_modal.htm
│ └── attach_access_post_card.htm
└── static/js/
├── post_attach_access.js
└── thread_attach_access.js
配置流程
后台启用插件(自动建
xnx_attach_access权限表 +xnx_attach_access_purchase购买表,写入 6 种类型与默认 VIP 用户组 2/4)进入「插件设置」勾选启用的权限类型、允许的积分类型、默认价格、VIP 用户组
用户在发帖/编辑帖时点击附件旁「权限配置」按钮 → 弹窗选择类型与参数(如积分价格、用户组)
测试:游客访问附件下载链接 → 提示「请先登录 / 需回复 / 需购买」;登录/回复/购买后下载放行;作者或管理员直接放行