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;
|
2008-12-08 20:40:01 +00:00
|
|
|
var $vetoed = false;
|
|
|
|
var $veto_reason;
|
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
|
|
|
}
|
2008-12-08 20:40:01 +00:00
|
|
|
|
|
|
|
public function veto($reason="") {
|
|
|
|
$this->vetoed = true;
|
|
|
|
$this->veto_reason = $reason;
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-12-06 10:21:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ConfigSaveEvent:
|
|
|
|
* Sent when the setup screen's 'set' button has been
|
|
|
|
* activated; new config options are in $_POST
|
|
|
|
*/
|
|
|
|
class ConfigSaveEvent extends Event {
|
|
|
|
var $config;
|
|
|
|
|
|
|
|
public function ConfigSaveEvent($config) {
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DataUploadEvent:
|
|
|
|
* $user -- the user uploading the data
|
|
|
|
* $tmpname -- the temporary file used for upload
|
|
|
|
* $metadata -- info about the file, should contain at least "filename", "extension", "tags" and "source"
|
|
|
|
*
|
|
|
|
* Some data is being uploaded. Should be caught by a file handler.
|
|
|
|
*/
|
|
|
|
class DataUploadEvent extends Event {
|
|
|
|
var $user, $tmpname, $metadata, $hash, $type;
|
|
|
|
|
|
|
|
public function DataUploadEvent($user, $tmpname, $metadata) {
|
|
|
|
$this->user = $user;
|
|
|
|
$this->tmpname = $tmpname;
|
|
|
|
|
|
|
|
$this->metadata = $metadata;
|
|
|
|
$this->metadata['hash'] = md5_file($tmpname);
|
|
|
|
$this->metadata['size'] = filesize($tmpname);
|
|
|
|
|
|
|
|
// useful for most file handlers, so pull directly into fields
|
|
|
|
$this->hash = $this->metadata['hash'];
|
|
|
|
$this->type = strtolower($metadata['extension']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DisplayingImageEvent:
|
|
|
|
* $image -- the image being displayed
|
|
|
|
* $page -- the page to display on
|
|
|
|
*
|
|
|
|
* Sent when an image is ready to display. Extensions who
|
|
|
|
* wish to appear on the "view" page should listen for this,
|
|
|
|
* which only appears when an image actually exists.
|
|
|
|
*/
|
|
|
|
class DisplayingImageEvent extends Event {
|
|
|
|
var $image, $page;
|
|
|
|
|
|
|
|
public function DisplayingImageEvent($image, $page) {
|
|
|
|
$this->image = $image;
|
|
|
|
$this->page = $page;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_image() {
|
|
|
|
return $this->image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ImageAdditionEvent:
|
|
|
|
* $user -- the user adding the image
|
|
|
|
* $image -- the image being added
|
|
|
|
*
|
|
|
|
* An image is being added to the database
|
|
|
|
*/
|
|
|
|
class ImageAdditionEvent extends Event {
|
|
|
|
var $user, $image;
|
|
|
|
|
|
|
|
public function ImageAdditionEvent($user, $image) {
|
|
|
|
$this->image = $image;
|
|
|
|
$this->user = $user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ImageDeletionEvent:
|
|
|
|
* $image -- the image being deleted
|
|
|
|
*
|
|
|
|
* An image is being deleted. Used by things like tags
|
|
|
|
* and comments handlers to clean out related rows in
|
|
|
|
* their tables
|
|
|
|
*/
|
|
|
|
class ImageDeletionEvent extends Event {
|
|
|
|
var $image;
|
|
|
|
|
|
|
|
public function ImageDeletionEvent($image) {
|
|
|
|
$this->image = $image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*
|
2008-09-06 17:05:21 +00:00
|
|
|
* TODO: up to date docs
|
2007-12-06 10:21:23 +00:00
|
|
|
*
|
|
|
|
* Used for initial page generation triggers
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ParseLinkTemplateEvent:
|
|
|
|
* $link -- the formatted link
|
|
|
|
* $original -- the formatting string, for reference
|
|
|
|
* $image -- the image who's link is being parsed
|
|
|
|
*/
|
|
|
|
class ParseLinkTemplateEvent extends Event {
|
|
|
|
var $link, $original;
|
|
|
|
var $image;
|
|
|
|
|
|
|
|
public function ParseLinkTemplateEvent($link, $image) {
|
|
|
|
$this->link = $link;
|
|
|
|
$this->original = $link;
|
|
|
|
$this->image = $image;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function replace($needle, $replace) {
|
|
|
|
$this->link = str_replace($needle, $replace, $this->link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SourceSetEvent:
|
|
|
|
* $image_id
|
|
|
|
* $source
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class SourceSetEvent extends Event {
|
|
|
|
var $image_id;
|
|
|
|
var $source;
|
|
|
|
|
|
|
|
public function SourceSetEvent($image_id, $source) {
|
|
|
|
$this->image_id = $image_id;
|
|
|
|
$this->source = $source;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TagSetEvent:
|
|
|
|
* $image_id
|
|
|
|
* $tags
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class TagSetEvent extends Event {
|
|
|
|
var $image_id;
|
|
|
|
var $tags;
|
|
|
|
|
|
|
|
public function TagSetEvent($image_id, $tags) {
|
|
|
|
$this->image_id = $image_id;
|
2007-12-08 05:33:15 +00:00
|
|
|
$this->tags = tag_explode($tags);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ThumbnailGenerationEvent:
|
|
|
|
* Request a thumb be made for an image
|
|
|
|
*/
|
|
|
|
class ThumbnailGenerationEvent extends Event {
|
|
|
|
var $hash;
|
|
|
|
var $type;
|
|
|
|
|
|
|
|
public function ThumbnailGenerationEvent($hash, $type) {
|
|
|
|
$this->hash = $hash;
|
|
|
|
$this->type = $type;
|
|
|
|
}
|
|
|
|
}
|
2008-02-06 17:24:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SearchTermParseEvent:
|
|
|
|
* Signal that a search term needs parsing
|
|
|
|
*/
|
|
|
|
class SearchTermParseEvent extends Event {
|
|
|
|
var $term = null;
|
2008-10-17 19:57:18 +00:00
|
|
|
var $context = null;
|
2008-10-17 20:18:38 +00:00
|
|
|
var $querylets = array();
|
2008-02-06 17:24:08 +00:00
|
|
|
|
2008-10-17 19:57:18 +00:00
|
|
|
public function SearchTermParseEvent($term, $context) {
|
2008-02-06 17:24:08 +00:00
|
|
|
$this->term = $term;
|
2008-10-17 19:57:18 +00:00
|
|
|
$this->context = $context;
|
2008-02-06 17:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function is_querylet_set() {
|
2008-10-17 20:18:38 +00:00
|
|
|
return (count($this->querylets) > 0);
|
2008-02-06 17:24:08 +00:00
|
|
|
}
|
|
|
|
|
2008-10-17 20:18:38 +00:00
|
|
|
public function get_querylets() {
|
|
|
|
return $this->querylets;
|
2008-02-06 17:24:08 +00:00
|
|
|
}
|
|
|
|
|
2008-10-17 20:18:38 +00:00
|
|
|
public function add_querylet($q) {
|
|
|
|
$this->querylets[] = $q;
|
2008-02-06 17:24:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
?>
|