Translations of this page: en bg cs de fi fr hu it ja pl ru tr zh

This is an old revision of the document!


API for events registration (pun_admin_events)

PunBB 1.3 official extension

  • Status: under development
  • Current version: 0.8

General idea

Adds event logging and a GUI for browsing logs.

Specification

Functionality

The extension allows to use API for registration of events.

Interface

  • Link “Events” in the “Management” tab in administration menu.
  • “Events page”:
    • On this page all registered events are shown.
    • Event filters:
      • By date from
      • By date to
      • By event's type
      • By IP
      • By username
      • By comment
      • Sort by
      • Sort direction
    • Fields of the event table:
      • IP
      • Event type
      • Event's comment
      • Event date
      • Username of the one who triggers the event

Database

  • New table pun_admin_events
Field Type Default Description
ip VARCHAR(15) 0.0.0.0 IP-address of user, who cause the event
type VARCHAR(64) Type of the event.
comment VARCHAR(255) Some comment about event.
user_id INT(10) NULL User id who cause the event.
user_name VARCHAR(255) NULL Username of user who cause the event.
date INT(10) UNSIGNED Date of the event.

API documentation

Functions

pun_admin_event

Registers an event.

void pun_admin_event(string $type, [string $comment = '', [bool $search_user = true]])

  • string $type: Type of registered events. (Example: “Topic”)
  • string $comment: Comments of registered events. (Example: “Topic under ID 100 has been deleted.”)
  • bool $search_user: If set to true, the function tries to determine the user, who caused the event.

Examples

Example 1

The first example shows how to register posts and topics deletion at your forum. Add this piece of code after line 92 of ”<FORUM_ROOT>/delete.php”.

<?php
include FORUM_ROOT.'extensions/pun_admin_events/pun_admin_events.php';
pun_admin_event('Topic', 'Topic under ID '.$cur_post['tid'].' has been deleted.', true);
?>

Add this after line 102 of ”<FORUM_ROOT>/delete.php”.

<?php
include FORUM_ROOT.'extensions/pun_admin_events/pun_admin_events.php';
pun_admin_event('Post', 'Post under ID '.$cur_post['tid'].' has been deleted.', true);
?>
Example 2

You can use this extension not only for registration of forum events, but also for other purposes. This example shows how to register file downloading using a php script:

<?php
define('FORUM_ROOT', './');
include FORUM_ROOT.'extensions/pun_admin_events/pun_admin_events.php';
 
function download($file, $content_type = 'text/html')
{
	if (is_readable($file))
	{
		$fp = fopen($file, 'rb');
 
		header('Content-Type: '.$content_type);
		header('Content-Length: '.filesize($file));
 
		fpassthru($fp);
 
		pun_admin_event('download', 'The file "'.$file.'" has been downloaded.');
	}
	else
		pun_admin_event('download_error', 'Error upon downloading file "'.$file.'"');
}
 
$downloads = array('documentation');
if (isset($_GET['id']) && is_scalar($_GET['id']) && in_array($_GET['id'], $downloads))
{
	download($_GET['id']);
	die();
}
 
?>

Screenshots


Personal Tools