lainchan/inc/events.php

49 lines
835 B
PHP
Raw Normal View History

<?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
*/
2012-04-12 10:18:19 -04:00
if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
2012-04-11 12:49:22 -04:00
// You cannot request this file directly.
exit;
}
function event() {
global $events;
$args = func_get_args();
$event = $args[0];
$args = array_splice($args, 1);
2012-04-12 10:18:19 -04:00
if (!isset($events[$event]))
return false;
2012-04-12 10:18:19 -04:00
foreach ($events[$event] as $callback) {
if (!is_callable($callback))
error('Event handler for ' . $event . ' is not callable!');
2012-04-12 10:18:19 -04:00
if ($error = call_user_func_array($callback, $args))
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();
$events[$event][] = $callback;
}
function reset_events() {
global $events;
2012-08-27 07:50:15 -04:00
$events = array();
}