Filter_Plugin_Cmd_Ajax接口分析
Filter_Plugin_Cmd_Ajax是一个接口,当我们访问http://www.zblog.dev/zb_system/cmd.php?act=ajax&src=WeChatCollect_SaveProject的时候。
cmd.php
<?php
require './function/c_system_base.php';
$zbp->Load();
$action = GetVars('act', 'GET');
if (!$zbp->CheckRights($action)) {$zbp->ShowError(6, __FILE__, __LINE__);die();}
foreach ($GLOBALS['hooks']['Filter_Plugin_Cmd_Begin'] as $fpname => &$fpsignal) {
$fpname();
}
switch ($action) {
case 'ajax':
foreach ($GLOBALS['hooks']['Filter_Plugin_Cmd_Ajax'] as $fpname => &$fpsignal) {
$fpname(GetVars('src', 'GET'));
}
}在插件中打印
var_dump($GLOBALS['hooks']['Filter_Plugin_Cmd_Ajax']);
结果:array(1) { ["插件名_Filter_Plugin_Cmd_Ajax"]=> &string(0) "" }
那么$fpname就是上面数组的键,打印
var_dump($fpname);
结果:string(36) "WeChatCollect_Filter_Plugin_Cmd_Ajax"
那么&$fpname就是上面数组的值,打印
var_dump($fpsignal);
结果:string(0) ""
那么实际上$fpname(GetVars('src', 'GET'));就是
WeChatCollect_Filter_Plugin_Cmd_Ajax(GetVars('src', 'GET'))GetVars函数功能类似于$_GET(),GetVars('src', 'GET')等于$_GET("src")
GetVars('src', 'GET')打印出来是string(25) "WeChatCollect_SaveProject"
$fpname(GetVars('src', 'GET'));就是WeChatCollect_Filter_Plugin_Cmd_Ajax("WeChatCollect_SaveProject");
WeChatCollect_Filter_Plugin_Cmd_Ajax()是自己定义的函数,非zblog函数。接收方式如下:
function WeChatCollect_Filter_Plugin_Cmd_Ajax() {
global $zbp;
$action = GetVars('src', 'GET');
$array = array();
switch ($action) {
case "WeChatCollect_SaveProject":
$id = (int) $_POST['ID'];
if (!isset($id)) {
$array['msg'] = '系统错误!';
break;
}
$links=trim(GetVars('Links', 'POST'));
if($links==''){
$array['msg'] = '链接不能为空!';
break;
}
$p = new WeChatCollect_Project();
if ($id > 0) {
$p->LoadinfoByID($id);
}
foreach ($zbp->datainfo['WeChatCollect_Project'] as $key => $value) {
if ($key == 'ID') {continue;}
if (isset($_POST[$key])) {
$p->$key = trim(GetVars($key, 'POST'));
}
}
$p->Time=time();
$p->Save(); //执行保存
$array['msg'] = '保存成功';
$array['redirect_url'] = $zbp->host . 'zb_users/plugin/WeChatCollect/ProjectList.php';//定义跳转到哪个页面
break;
}对插件的配置信息进行保存。
