summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-03-19 02:41:06 +1100
committerMichael Save <savetheinternet@tinyboard.org>2012-03-19 02:41:06 +1100
commit9d5818636008f99e425465c42a808a36489f4052 (patch)
treee2c35a312c7e9a894c8c00aa2e3d54e60f686770 /inc
parentab1db9dd8a8480c7c5cd69c11abe281ddc6d97ca (diff)
New feature: "events". Will eventually replace/extend "themes".
Diffstat (limited to 'inc')
-rw-r--r--inc/config.php17
-rw-r--r--inc/events.php40
-rw-r--r--inc/functions.php8
3 files changed, 65 insertions, 0 deletions
diff --git a/inc/config.php b/inc/config.php
index ae0a36c5..afc4ceaa 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -956,6 +956,23 @@
/*
* ====================
+ * Events (PHP 5.3.0+)
+ * ====================
+ */
+
+ // event_handler('post', function($post) {
+ // // do something
+ // });
+
+ // event_handler('post', function($post) {
+ // // do something else
+ //
+ // // return an error (reject post)
+ // return 'Sorry, you cannot post that!';
+ // });
+
+/*
+ * ====================
* Other/uncategorized
* ====================
*/
diff --git a/inc/events.php b/inc/events.php
new file mode 100644
index 00000000..a5b9129d
--- /dev/null
+++ b/inc/events.php
@@ -0,0 +1,40 @@
+<?php
+
+function event() {
+ global $events;
+
+ $args = func_get_args();
+
+ $event = $args[0];
+ $args = array_splice($args, 1);
+
+ rebuildThemes($event);
+
+ if(!isset($events[$event]))
+ return false;
+
+ foreach($events[$event] as $callback) {
+ if(!is_callable($callback))
+ error('Event handler for ' . $event . ' is not callable!');
+ if($error = call_user_func_array($callback, $args))
+ return $error;
+ }
+
+ return false;
+}
+
+function event_handler($event, $callback) {
+ global $events;
+
+ if(!isset($events[$event]))
+ $events[$event] = Array();
+
+ $events[$event][] = $callback;
+}
+
+function reset_events() {
+ global $events;
+
+ $events = Array();
+}
+
diff --git a/inc/functions.php b/inc/functions.php
index 25ff89b5..d62c3a20 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -5,6 +5,7 @@
exit;
}
+ require 'inc/events.php';
require 'contrib/gettext/gettext.inc';
register_shutdown_function('fatal_error_handler');
@@ -14,6 +15,13 @@
function loadConfig() {
global $board, $config, $__ip, $debug, $__version;
+ reset_events();
+
+ if(!defined('PHP_VERSION_ID')) {
+ $version = explode('.', PHP_VERSION);
+ define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
+ }
+
if(!isset($_SERVER['REMOTE_ADDR']))
$_SERVER['REMOTE_ADDR'] = '0.0.0.0';