2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
|
|
|
* Generic parent class for all events.
|
|
|
|
*
|
|
|
|
* An event is anything that can be passed around via send_event($blah)
|
2007-04-16 11:58:25 +00:00
|
|
|
*/
|
2008-08-23 12:05:24 +00:00
|
|
|
abstract class Event {
|
2009-05-11 14:04:33 +00:00
|
|
|
public function __construct() {}
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-12-06 10:21:23 +00:00
|
|
|
|
|
|
|
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
2009-07-21 03:18:40 +00:00
|
|
|
* A wake-up call for extensions. Upon recieving an InitExtEvent an extension
|
|
|
|
* should check that it's database tables are there and install them if not,
|
|
|
|
* and set any defaults with Config::set_default_int() and such.
|
2007-12-06 10:21:23 +00:00
|
|
|
*/
|
2008-08-23 12:05:24 +00:00
|
|
|
class InitExtEvent extends Event {}
|
2007-12-06 10:21:23 +00:00
|
|
|
|
|
|
|
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
|
|
|
* A signal that a page has been requested.
|
|
|
|
*
|
2009-01-03 21:00:09 +00:00
|
|
|
* User requests /view/42 -> an event is generated with $args = array("view",
|
|
|
|
* "42"); when an event handler asks $event->page_matches("view"), it returns
|
|
|
|
* true and ignores the matched part, such that $event->count_args() = 1 and
|
|
|
|
* $event->get_arg(0) = "42"
|
2007-12-06 10:21:23 +00:00
|
|
|
*/
|
|
|
|
class PageRequestEvent extends Event {
|
2008-09-06 17:05:21 +00:00
|
|
|
var $args;
|
|
|
|
var $arg_count;
|
|
|
|
var $part_count;
|
|
|
|
|
2009-05-11 14:04:33 +00:00
|
|
|
public function __construct($args) {
|
2007-12-06 10:21:23 +00:00
|
|
|
$this->args = $args;
|
2008-09-06 17:05:21 +00:00
|
|
|
$this->arg_count = count($args);
|
2007-12-06 10:21:23 +00:00
|
|
|
}
|
|
|
|
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
|
|
|
* Test if the requested path matches a given pattern.
|
|
|
|
*
|
|
|
|
* If it matches, store the remaining path elements in $args
|
2012-02-08 01:13:58 +00:00
|
|
|
*
|
|
|
|
* @retval bool
|
2009-07-19 07:38:13 +00:00
|
|
|
*/
|
2012-02-02 13:58:48 +00:00
|
|
|
public function page_matches(/*string*/ $name) {
|
2008-08-23 12:05:24 +00:00
|
|
|
$parts = explode("/", $name);
|
2008-09-06 17:05:21 +00:00
|
|
|
$this->part_count = count($parts);
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2008-09-06 17:05:21 +00:00
|
|
|
if($this->part_count > $this->arg_count) {
|
2008-08-23 12:05:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-06 17:05:21 +00:00
|
|
|
for($i=0; $i<$this->part_count; $i++) {
|
2008-08-23 12:05:24 +00:00
|
|
|
if($parts[$i] != $this->args[$i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-08 01:13:58 +00:00
|
|
|
/**
|
|
|
|
* Get the n th argument of the page request (if it exists.)
|
|
|
|
* @param $n integer
|
|
|
|
* @retval The argmuent (string) or NULL
|
|
|
|
*/
|
2012-02-02 13:58:48 +00:00
|
|
|
public function get_arg(/*int*/ $n) {
|
2008-09-06 17:05:21 +00:00
|
|
|
$offset = $this->part_count + $n;
|
|
|
|
if($offset >= 0 && $offset < $this->arg_count) {
|
|
|
|
return $this->args[$offset];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return null;
|
|
|
|
}
|
2007-12-06 10:21:23 +00:00
|
|
|
}
|
|
|
|
|
2012-02-08 01:13:58 +00:00
|
|
|
/**
|
|
|
|
* Returns the number of arguments the page request has.
|
|
|
|
* @retval int
|
|
|
|
*/
|
2007-12-06 10:21:23 +00:00
|
|
|
public function count_args() {
|
2012-01-11 20:57:00 +00:00
|
|
|
return (int)($this->arg_count - $this->part_count);
|
2007-12-06 10:21:23 +00:00
|
|
|
}
|
2010-04-26 01:35:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Many things use these functions
|
|
|
|
*/
|
|
|
|
public function get_search_terms() {
|
|
|
|
$search_terms = array();
|
2012-01-11 20:57:00 +00:00
|
|
|
if($this->count_args() === 2) {
|
2010-04-26 05:07:34 +00:00
|
|
|
$search_terms = explode(' ', $this->get_arg(0));
|
2010-04-26 01:35:53 +00:00
|
|
|
}
|
|
|
|
return $search_terms;
|
|
|
|
}
|
|
|
|
public function get_page_number() {
|
|
|
|
$page_number = 1;
|
2012-01-11 20:57:00 +00:00
|
|
|
if($this->count_args() === 1) {
|
2010-04-26 02:39:02 +00:00
|
|
|
$page_number = int_escape($this->get_arg(0));
|
2010-04-26 01:35:53 +00:00
|
|
|
}
|
2012-01-11 20:57:00 +00:00
|
|
|
else if($this->count_args() === 2) {
|
2010-04-26 02:39:02 +00:00
|
|
|
$page_number = int_escape($this->get_arg(1));
|
2010-04-26 01:35:53 +00:00
|
|
|
}
|
2012-01-11 20:57:00 +00:00
|
|
|
if($page_number === 0) $page_number = 1; // invalid -> 0
|
2010-04-26 01:35:53 +00:00
|
|
|
return $page_number;
|
|
|
|
}
|
|
|
|
public function get_page_size() {
|
|
|
|
global $config;
|
2012-04-01 16:47:39 +00:00
|
|
|
return $config->get_int('index_images');
|
2010-04-26 01:35:53 +00:00
|
|
|
}
|
2007-12-06 10:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
|
|
|
* A signal that some text needs formatting, the event carries
|
|
|
|
* both the text and the result
|
2007-12-06 10:21:23 +00:00
|
|
|
*/
|
|
|
|
class TextFormattingEvent extends Event {
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
|
|
|
* For reference
|
|
|
|
*/
|
2007-12-06 10:21:23 +00:00
|
|
|
var $original;
|
2009-07-19 07:38:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* with formatting applied
|
|
|
|
*/
|
2007-12-06 10:21:23 +00:00
|
|
|
var $formatted;
|
2009-07-19 07:38:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* with formatting removed
|
|
|
|
*/
|
2007-12-06 10:21:23 +00:00
|
|
|
var $stripped;
|
|
|
|
|
2012-02-02 13:58:48 +00:00
|
|
|
public function __construct(/*string*/ $text) {
|
2008-01-12 07:44:08 +00:00
|
|
|
$h_text = html_escape(trim($text));
|
|
|
|
$this->original = $h_text;
|
|
|
|
$this->formatted = $h_text;
|
|
|
|
$this->stripped = $h_text;
|
2007-12-06 10:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-08 10:52:29 +00:00
|
|
|
|
|
|
|
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
|
|
|
* A signal that something needs logging
|
2009-05-08 10:52:29 +00:00
|
|
|
*/
|
|
|
|
class LogEvent extends Event {
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
|
|
|
* a category, normally the extension name
|
|
|
|
*
|
2009-07-21 06:36:12 +00:00
|
|
|
* @retval string
|
2009-07-19 07:38:13 +00:00
|
|
|
*/
|
2009-05-08 10:52:29 +00:00
|
|
|
var $section;
|
2009-07-19 07:38:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* See python...
|
|
|
|
*
|
2009-07-21 06:36:12 +00:00
|
|
|
* @retval int
|
2009-07-19 07:38:13 +00:00
|
|
|
*/
|
2009-05-08 10:52:29 +00:00
|
|
|
var $priority = 0;
|
2009-07-19 07:38:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free text to be logged
|
|
|
|
*
|
2009-07-21 06:36:12 +00:00
|
|
|
* @retval text
|
2009-07-19 07:38:13 +00:00
|
|
|
*/
|
2009-05-08 10:52:29 +00:00
|
|
|
var $message;
|
2009-07-19 07:38:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The time that the event was created
|
|
|
|
*
|
2009-07-21 06:36:12 +00:00
|
|
|
* @retval int
|
2009-07-19 07:38:13 +00:00
|
|
|
*/
|
2009-05-08 10:52:29 +00:00
|
|
|
var $time;
|
|
|
|
|
2009-05-11 14:04:33 +00:00
|
|
|
public function __construct($section, $priority, $message) {
|
2009-05-08 10:52:29 +00:00
|
|
|
$this->section = $section;
|
|
|
|
$this->priority = $priority;
|
|
|
|
$this->message = $message;
|
|
|
|
$this->time = time();
|
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
?>
|