1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-23 23:20:57 +01:00
3 events
Fredrick Brennan edited this page 2019-04-18 20:16:52 +08:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

“Events”

Tinyboards “events” are similar to those in Javascript. Events handlers are anonymous functions that are registered to Tinyboard. When Tinyboard carries out an action such as deleting a file, generating a tripcode or checking whether an IP address is banned, you can interfere with the response or make Tinyboard do something else at the same time. You can bind an infinite amount of handlers to an event.

If youre familiar with jQuery, you can think of Tinyboards event_handler function as jQuerys bind.

If event handlers return a string or true it will interupt the action. See examples below.

Anonymous functions

Anonymous functions are only available in PHP 5.3.0+. However, you can instead use real functions as event handlers if you dont meet this requirement.

Examples

To disallow a certain filename when posting (for whatever reason):

event_handler('post', function($post) {
	if ($post->has_file && $post->filename == 'bad_filename.png')
		return 'You cannot post with that filename';
});

To force all posts to have a certain tripcode:

event_handler('post', function($post) {
	$post->trip = '!hello.world';
});

To trick Tinyboard into thinking a specific thread is locked:

event_handler('check-locked', function($id) {
	if ($id == 50)
		return true;
});

To disallow a thread from being bumped:

event_handler('bump', function($id) {
	if ($id == 50)
		return true;
});

To create a custom “poster ID” for a specific IP address:

event_handler('poster-id', function($ip, $thread) {
	if ($ip == '4.3.2.1')
		return 'Hello';
});

Events

Event Called Parameters Returned value
post Before a new post is entered in the database. object $post If not false, the post is rejected and the returned value is displayed as an error message.
post-after After a new post is entered in the database. array $post
write After a file has been written to. string $path
unlink After a file has been deleted. string $path
check-flood Before checking if a poster is flooding the board. array $post If true, the poster will be deemed malicious regardless of Tinyboards decision.
check-locked Before checking if a thread is locked. int $id If true, Tinyboard will treat the thread as being locked.
check-sage-locked Before checking if a thread is “sage-locked”. int $id If true, Tinyboard will treat the thread as being “sage-locked”.
bump Before bumping a thread. int $id If true, the thread will not be bumped.
check-robot Before checking if a post is duplicate (for R9K). string $body If true, the poster will be muted regardless of whether or not the content was original to Tinyboard.
mute-time Before fetching current mute time for a user. If > 0, Tinyboard will use the returned value as the length of the mute (in seconds).
build-thread Before building a thread. int $id If true, the thread .html file will not be (re)created.
poster-id Before generating a poster ID. string $ip, int $thread If not false, Tinyboard will use the returned value as the poster ID instead.
tripcode Before generating a tripcode. string $name The returned value will be used as the name/tripcode combination instead. Must be in the format of array(name, tripcode).

See also