Files
firstgarden-web-gnu/lib/hook.lib.php
kkigomi 6e684e80f2 add_replace()에서 $args 값을 1로 변경
replace hook은 값을 반환해야하므로 항상 최소 1개의 인자를 받아야하지만 기본 값이 0이어서 매번 이를 변경해줘야하는 문제
2023-07-08 06:58:03 +09:00

134 lines
2.7 KiB
PHP

<?php
if (!defined('_GNUBOARD_')) exit;
define('G5_HOOK_DEFAULT_PRIORITY', 8);
if (!function_exists('get_called_class')) {
function get_called_class() {
$bt = debug_backtrace();
$lines = file($bt[1]['file']);
preg_match(
'/([a-zA-Z0-9\_]+)::'.$bt[1]['function'].'/',
$lines[$bt[1]['line']-1],
$matches
);
return $matches[1];
}
}
include_once(dirname(__FILE__) .'/Hook/hook.class.php');
include_once(dirname(__FILE__) .'/Hook/hook.extends.class.php');
function get_hook_class(){
if( class_exists('GML_Hook') ){
return GML_Hook::getInstance();
}
return null;
}
function add_event($tag, $func, $priority=G5_HOOK_DEFAULT_PRIORITY, $args=0){
if( $hook = get_hook_class() ){
$hook->addAction($tag, $func, $priority, $args);
}
}
function run_event($tag, $arg = ''){
if( $hook = get_hook_class() ){
$args = array();
if (
is_array($arg)
&&
isset($arg[0])
&&
is_object($arg[0])
&&
1 == count($arg)
) {
$args[] =& $arg[0];
} else {
$args[] = $arg;
}
$numArgs = func_num_args();
for ($a = 2; $a < $numArgs; $a++) {
$args[] = func_get_arg($a);
}
$hook->doAction($tag, $args, false);
}
}
function add_replace($tag, $func, $priority=G5_HOOK_DEFAULT_PRIORITY, $args=1){
if( $hook = get_hook_class() ){
return $hook->addFilter($tag, $func, $priority, $args);
}
return null;
}
function run_replace($tag, $arg = ''){
if( $hook = get_hook_class() ){
$args = array();
if (
is_array($arg)
&&
isset($arg[0])
&&
is_object($arg[0])
&&
1 == count($arg)
) {
$args[] =& $arg[0];
} else {
$args[] = $arg;
}
$numArgs = func_num_args();
for ($a = 2; $a < $numArgs; $a++) {
$args[] = func_get_arg($a);
}
return $hook->apply_filters($tag, $args, false);
}
return null;
}
function delete_event($tag, $func, $priority=G5_HOOK_DEFAULT_PRIORITY){
if( $hook = get_hook_class() ){
return $hook->remove_action($tag, $func, $priority);
}
return null;
}
function delete_replace($tag, $func, $priority=G5_HOOK_DEFAULT_PRIORITY){
if( $hook = get_hook_class() ){
return $hook->remove_filter($tag, $func, $priority);
}
return null;
}
function get_hook_datas($type='', $is_callback=''){
if( $hook = get_hook_class() ){
return $hook->get_properties($type, $is_callback);
}
return null;
}