我们来制作一个简单的插件
首先,我们需要了解下 Xiuno BBS 的文件结构:
conf/ 配置文件目录
lang/ 语言包
log/ 日志目录
tmp/ 临时目录
model/ 数据调用(重用度高)
route/ 业务逻辑(重用度低)
plugin/ 插件目录
upload/ 上传文件
view/ 模板、静态资源(js, css, htm, font)
xiunophp/ 公共的函数库
admin/ 后台管理
index.php 入口程序
我们重点关注:plugin, model, view, route 这几个目录。
Xiuno BBS 的插件是基于 AOP 机制,所谓的面向切面编程,也就是往代码里插入代码,合并后再执行(最后合并后的代码存放于 tmp 目录下)。
一个插件一个目录,我们来示范一下最简单的 Hello, Plugin! 一个单页的例子
打开 index.php,修改 DEBUG 为 2 (这样可以及时看到效果,上线后还原为 0)
打开 index.php,修改 DEBUG 为 2 (这样可以及时看到效果,上线后还原为 0)
新建目录和文件,假定插件名为 my_plugin:
plugin/
my_plugin/
conf.json (配置文件)
icon.png (图标宽高:54*54)
hook/
index_route_case_end.php (插入点,该插入点在 index.php)
hello.php (你的业务逻辑文件)
conf.json 文件内容:
{
"name":"我的第一个 Xiuno BBS 插件",
"brief":"我的插件介绍。",
"version":"1.0",
"bbs_version":"4.0",
"installed":0,
"enable":0,
"hooks_rank":[],
"overwrites_rank":[],
"dependencies":[]
}
index_route_case_end.php 内容:
case 'hello': include APP_PATH.'plugin/my_plugin/hello.php'; break;
hello.php 内容:
<?php
message(0, 'Hello, Plugin');
?>
网址访问:http://你的域名/?hello.htm
如果网站设置了伪静态,网址去掉"?"号