New feature: "events". Will eventually replace/extend "themes".
This commit is contained in:
parent
ab1db9dd8a
commit
9d58186360
|
@ -954,6 +954,23 @@
|
||||||
// Edit the current configuration (via web interface)
|
// Edit the current configuration (via web interface)
|
||||||
$config['mod']['edit_config'] = ADMIN;
|
$config['mod']['edit_config'] = ADMIN;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ====================
|
||||||
|
* 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
|
* Other/uncategorized
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require 'inc/events.php';
|
||||||
require 'contrib/gettext/gettext.inc';
|
require 'contrib/gettext/gettext.inc';
|
||||||
|
|
||||||
register_shutdown_function('fatal_error_handler');
|
register_shutdown_function('fatal_error_handler');
|
||||||
|
@ -14,6 +15,13 @@
|
||||||
function loadConfig() {
|
function loadConfig() {
|
||||||
global $board, $config, $__ip, $debug, $__version;
|
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']))
|
if(!isset($_SERVER['REMOTE_ADDR']))
|
||||||
$_SERVER['REMOTE_ADDR'] = '0.0.0.0';
|
$_SERVER['REMOTE_ADDR'] = '0.0.0.0';
|
||||||
|
|
||||||
|
|
6
post.php
6
post.php
|
@ -595,6 +595,11 @@
|
||||||
$post['thumb'] = substr_replace($post['thumb'], '', 0, mb_strlen($board['dir'] . $config['dir']['thumb']));
|
$post['thumb'] = substr_replace($post['thumb'], '', 0, mb_strlen($board['dir'] . $config['dir']['thumb']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($error = event('post', $post)) {
|
||||||
|
undoImage($post);
|
||||||
|
error($error);
|
||||||
|
}
|
||||||
|
|
||||||
$id = post($post, $OP);
|
$id = post($post, $OP);
|
||||||
|
|
||||||
if(isset($post['tracked_cites'])) {
|
if(isset($post['tracked_cites'])) {
|
||||||
|
@ -643,7 +648,6 @@
|
||||||
if($config['syslog'])
|
if($config['syslog'])
|
||||||
_syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $OP?$id:$post['thread']) . (!$OP ? '#' . $id : ''));
|
_syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $OP?$id:$post['thread']) . (!$OP ? '#' . $id : ''));
|
||||||
|
|
||||||
rebuildThemes('post');
|
|
||||||
header('Location: ' . $redirect, true, $config['redirect_http']);
|
header('Location: ' . $redirect, true, $config['redirect_http']);
|
||||||
} else {
|
} else {
|
||||||
if(!file_exists($config['has_installed'])) {
|
if(!file_exists($config['has_installed'])) {
|
||||||
|
|
Loading…
Reference in New Issue