本文标题:《「教程」Z-Blog 插件运作机制简述》。
镜像链接:https://www.wdssmq.com/post/20190817262.html
[TOC]
基于 include.php 的标准用法
可以类比一列火车。。出发时会从数据库带上固定的货物,,可以在途经的站点向指定的车箱内增加东西。。或者干脆加挂车箱。再或者把车上的东西搬下来加工一下再搬回来。
所有预定的操作都需要在出发前申请。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| RegisterPlugin("demoPlugin","ActivePlugin_demoPlugin");
function ActivePlugin_demoPlugin() { Add_Filter_Plugin('Filter_Plugin_Index_Begin', 'demoPlugin_hello'); }
function demoPlugin_hello() { global $zbp; $zbp->header .= '<script>alert("hello")</script>'; }
|
预约制和买票上车制的不同是,前者到站后你要等叫号,叫到你你再上。
列车发车后,“车长”手里会有这样一份表格,而前边的 Add_Filter_Plugin() 函数就相当于填写这张表;
| 站点名 |
事项列表 |
| aaa |
eeee,ttew,aewe |
| Filter_Plugin_Index_Begin |
demoPlugin_hello,XXXX |
| nnn |
|
1 2 3 4 5
| foreach ($GLOBALS['hooks']['Filter_Plugin_Index_Begin'] as $fpname => &$fpsignal) { $fpname(); }
|
插件自己新开一条铁路
插件下新建一个 api.php 文件然后写入如下示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <?php
require '../../../zb_system/function/c_system_base.php';
$zbp->Load();
if (!$zbp->CheckPlugin('demoPlugin')) { $zbp->ShowError(48); die(); }
$articles = GetList(10); $pagebar = new Pagebar($zbp->option['ZC_INDEX_REGEX'], true, true);
$zbp->template->SetTags('articles', $articles); $zbp->template->SetTags('pagebar', $pagebar); $zbp->template->SetTemplate('index'); $zbp->template->Display();
|