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