mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-27 17:00:52 +01:00
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)
|
||||
$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
|
||||
|
40
inc/events.php
Normal file
40
inc/events.php
Normal file
@ -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;
|
||||
}
|
||||
|
||||
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';
|
||||
|
||||
|
6
post.php
6
post.php
@ -595,6 +595,11 @@
|
||||
$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);
|
||||
|
||||
if(isset($post['tracked_cites'])) {
|
||||
@ -643,7 +648,6 @@
|
||||
if($config['syslog'])
|
||||
_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']);
|
||||
} else {
|
||||
if(!file_exists($config['has_installed'])) {
|
||||
|
Loading…
Reference in New Issue
Block a user