2012-03-18 11:41:06 -04:00
|
|
|
<?php
|
|
|
|
|
2012-04-11 12:49:22 -04:00
|
|
|
/*
|
2013-01-20 05:23:46 -05:00
|
|
|
* Copyright (c) 2010-2013 Tinyboard Development Group
|
2012-04-11 12:49:22 -04:00
|
|
|
*/
|
|
|
|
|
2013-09-06 06:12:04 -04:00
|
|
|
defined('TINYBOARD') or exit;
|
2012-04-11 12:49:22 -04:00
|
|
|
|
2012-03-18 11:41:06 -04:00
|
|
|
function event() {
|
|
|
|
global $events;
|
|
|
|
|
|
|
|
$args = func_get_args();
|
|
|
|
|
|
|
|
$event = $args[0];
|
2012-03-24 00:31:35 -04:00
|
|
|
|
2012-03-18 11:41:06 -04:00
|
|
|
$args = array_splice($args, 1);
|
|
|
|
|
2012-04-12 10:18:19 -04:00
|
|
|
if (!isset($events[$event]))
|
2012-03-18 11:41:06 -04:00
|
|
|
return false;
|
|
|
|
|
2012-04-12 10:18:19 -04:00
|
|
|
foreach ($events[$event] as $callback) {
|
|
|
|
if (!is_callable($callback))
|
2012-03-18 11:41:06 -04:00
|
|
|
error('Event handler for ' . $event . ' is not callable!');
|
2012-04-12 10:18:19 -04:00
|
|
|
if ($error = call_user_func_array($callback, $args))
|
2012-03-18 11:41:06 -04:00
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function event_handler($event, $callback) {
|
|
|
|
global $events;
|
|
|
|
|
2012-04-12 10:18:19 -04:00
|
|
|
if (!isset($events[$event]))
|
2012-08-27 07:50:15 -04:00
|
|
|
$events[$event] = array();
|
2012-03-18 11:41:06 -04:00
|
|
|
|
|
|
|
$events[$event][] = $callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset_events() {
|
|
|
|
global $events;
|
|
|
|
|
2012-08-27 07:50:15 -04:00
|
|
|
$events = array();
|
2012-03-18 11:41:06 -04:00
|
|
|
}
|
|
|
|
|