2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Event:
|
|
|
|
* generic parent class
|
|
|
|
*/
|
2008-08-23 12:05:24 +00:00
|
|
|
abstract class Event {
|
|
|
|
var $context;
|
2007-07-12 08:30:51 +00:00
|
|
|
|
2008-08-23 12:05:24 +00:00
|
|
|
public function __construct(RequestContext $context) {
|
|
|
|
$this->context = $context;
|
2007-07-12 08:30:51 +00:00
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-12-06 10:21:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* InitExtEvent:
|
|
|
|
* A wake-up call for extensions
|
|
|
|
*/
|
2008-08-23 12:05:24 +00:00
|
|
|
class InitExtEvent extends Event {}
|
2007-12-06 10:21:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PageRequestEvent:
|
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;
|
2007-12-06 10:21:23 +00:00
|
|
|
|
2008-09-06 17:05:21 +00:00
|
|
|
var $part_count;
|
|
|
|
|
|
|
|
public function __construct(RequestContext $context, $args) {
|
|
|
|
parent::__construct($context);
|
2007-12-06 10:21:23 +00:00
|
|
|
$this->args = $args;
|
2008-09-06 17:05:21 +00:00
|
|
|
$this->arg_count = count($args);
|
2008-09-06 17:48:03 +00:00
|
|
|
$this->page = $context->page;
|
2008-09-07 04:57:10 +00:00
|
|
|
$this->user = $context->user;
|
2007-12-06 10:21:23 +00:00
|
|
|
}
|
|
|
|
|
2008-08-23 12:05:24 +00:00
|
|
|
public function page_matches($name) {
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2007-12-06 10:21:23 +00:00
|
|
|
public function get_arg($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
|
|
|
}
|
|
|
|
|
|
|
|
public function count_args() {
|
2008-09-06 17:48:03 +00:00
|
|
|
return $this->arg_count - $this->part_count;
|
2007-12-06 10:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TextFormattingEvent:
|
|
|
|
* $original - for reference
|
|
|
|
* $formatted - with formatting applied
|
|
|
|
* $stripped - with formatting removed
|
|
|
|
*/
|
|
|
|
class TextFormattingEvent extends Event {
|
|
|
|
var $original;
|
|
|
|
var $formatted;
|
|
|
|
var $stripped;
|
|
|
|
|
|
|
|
public function TextFormattingEvent($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
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
?>
|