wibble towards being totally SimpleExtension based, as that's easier to programatically optimise
This commit is contained in:
parent
c1aa6f4fbb
commit
6e64857936
23 changed files with 95 additions and 58 deletions
|
@ -38,6 +38,8 @@ class AdminBuildingEvent extends Event {
|
|||
class AdminPage implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
@ -179,5 +181,4 @@ class AdminPage implements Extension {
|
|||
}
|
||||
*/
|
||||
}
|
||||
add_event_listener(new AdminPage());
|
||||
?>
|
||||
|
|
|
@ -22,6 +22,8 @@ class AuthorSetEvent extends Event {
|
|||
class Artists implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
|
||||
public function receive_event(Event $event)
|
||||
{
|
||||
global $user;
|
||||
|
@ -1221,5 +1223,4 @@ class Artists implements Extension {
|
|||
return $result;
|
||||
}
|
||||
}
|
||||
add_event_listener(new Artists());
|
||||
?>
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
class Bookmarks implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
@ -64,5 +66,4 @@ class Bookmarks implements Extension {
|
|||
$database->Execute($sql, array($user->id, $url, $title));
|
||||
}
|
||||
}
|
||||
add_event_listener(new Bookmarks());
|
||||
?>
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
*/
|
||||
|
||||
class BrowserSearch implements Extension {
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
public function receive_event(Event $event) {
|
||||
global $page;
|
||||
global $config;
|
||||
|
@ -112,5 +114,4 @@ class BrowserSearch implements Extension {
|
|||
}
|
||||
}
|
||||
}
|
||||
add_event_listener(new BrowserSearch());
|
||||
?>
|
||||
|
|
|
@ -49,6 +49,8 @@ Completely compatibility will probably involve a rewrite with a different URL
|
|||
|
||||
class DanbooruApi implements Extension
|
||||
{
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
// Receive the event
|
||||
public function receive_event(Event $event)
|
||||
{
|
||||
|
@ -425,5 +427,4 @@ class DanbooruApi implements Extension
|
|||
}
|
||||
}
|
||||
|
||||
add_event_listener(new DanbooruApi());
|
||||
?>
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
class Downtime implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 10;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
@ -42,5 +44,4 @@ class Downtime implements Extension {
|
|||
else return false;
|
||||
}
|
||||
}
|
||||
add_event_listener(new Downtime(), 10);
|
||||
?>
|
||||
|
|
|
@ -100,5 +100,4 @@ class FlashFileHandler extends DataHandlerExtension {
|
|||
return $bounds;
|
||||
}
|
||||
}
|
||||
add_event_listener(new FlashFileHandler());
|
||||
?>
|
||||
|
|
|
@ -39,5 +39,4 @@ class MP3FileHandler extends DataHandlerExtension {
|
|||
return (file_exists($file));
|
||||
}
|
||||
}
|
||||
add_event_listener(new MP3FileHandler());
|
||||
?>
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
class SVGFileHandler implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
||||
|
@ -113,6 +115,4 @@ class MiniSVGParser {
|
|||
function endElement($parser, $name) {
|
||||
}
|
||||
}
|
||||
|
||||
add_event_listener(new SVGFileHandler());
|
||||
?>
|
||||
|
|
|
@ -28,6 +28,5 @@ class Holiday extends SimpleExtension {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -37,6 +37,8 @@ class AddIPBanEvent extends Event {
|
|||
class IPBan implements Extension {
|
||||
var $theme;
|
||||
// event handler {{{
|
||||
public function get_priority() {return 10;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
@ -264,5 +266,4 @@ class IPBan implements Extension {
|
|||
}
|
||||
// }}}
|
||||
}
|
||||
add_event_listener(new IPBan(), 10);
|
||||
?>
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
class LinkImage implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
@ -48,5 +50,4 @@ class LinkImage implements Extension {
|
|||
'text_link' => $text_link);
|
||||
}
|
||||
}
|
||||
add_event_listener(new LinkImage());
|
||||
?>
|
||||
|
|
|
@ -22,6 +22,8 @@ class NumericScoreSetEvent extends Event {
|
|||
class NumericScore implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
@ -271,5 +273,4 @@ class NumericScore implements Extension {
|
|||
array($image_id, $image_id));
|
||||
}
|
||||
}
|
||||
add_event_listener(new NumericScore());
|
||||
?>
|
||||
|
|
|
@ -20,6 +20,8 @@ class RatingSetEvent extends Event {
|
|||
class Ratings implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
@ -218,5 +220,4 @@ class Ratings implements Extension {
|
|||
}
|
||||
}
|
||||
}
|
||||
add_event_listener(new Ratings());
|
||||
?>
|
||||
|
|
|
@ -32,6 +32,8 @@ class AddReportedImageEvent extends Event {
|
|||
class ReportImage implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
@ -143,8 +145,6 @@ class ReportImage implements Extension {
|
|||
return $reports;
|
||||
}
|
||||
}
|
||||
add_event_listener(new ReportImage(), 29); // Not sure what I'm in before.
|
||||
|
||||
// ===== Changelog =====
|
||||
// * Version 0.3a / 0.3a_rc - 11/06/07 - I can no longer use the same theme.php file for both SVN and RCx. Sorry.
|
||||
// * Same deal with theme.php as it is with main.php
|
||||
|
@ -154,5 +154,4 @@ add_event_listener(new ReportImage(), 29); // Not sure what I'm in before.
|
|||
// * Version 0.2b - 10/27/07 - Now supports Shimmie2 RC2!
|
||||
// * Version 0.2a - 10/24/07 - Fixed some SQL issues. I will make sure to test before commiting :)
|
||||
// * Version 0.2 - 10/24/07 - First public release.
|
||||
|
||||
?>
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
* Description: Allows the admin to set min / max image dimentions
|
||||
*/
|
||||
class ResolutionLimit implements Extension {
|
||||
public function get_priority() {return 40;} // early, to veto ImageUploadEvent
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
if($event instanceof ImageAdditionEvent) {
|
||||
global $config;
|
||||
|
@ -68,5 +70,4 @@ class ResolutionLimit implements Extension {
|
|||
}
|
||||
}
|
||||
}
|
||||
add_event_listener(new ResolutionLimit(), 40); // early, to veto UIE
|
||||
?>
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
class TagEditCloud implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
//if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
@ -133,5 +135,4 @@ class TagEditCloud implements Extension {
|
|||
}
|
||||
|
||||
}
|
||||
add_event_listener(new TagEditCloud());
|
||||
?>
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
class Tag_History implements Extension {
|
||||
var $theme;
|
||||
|
||||
// in before tags are actually set, so that "get current tags" works
|
||||
public function get_priority() {return 40;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
@ -350,5 +353,4 @@ class Tag_History implements Extension {
|
|||
}
|
||||
}
|
||||
}
|
||||
add_event_listener(new Tag_History(), 40); // in before tags are actually set, so that "get current tags" works
|
||||
?>
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
class Tagger implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
if(is_null($this->theme))
|
||||
$this->theme = get_theme_object($this);
|
||||
|
@ -38,10 +40,10 @@ class Tagger implements Extension {
|
|||
}
|
||||
}
|
||||
|
||||
add_event_listener(new Tagger());
|
||||
|
||||
// Tagger AJAX back-end
|
||||
class TaggerXML implements Extension {
|
||||
public function get_priority() {return 10;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("tagger/tags")) {
|
||||
global $page;
|
||||
|
@ -170,5 +172,5 @@ class TaggerXML implements Extension {
|
|||
|
||||
return $list;
|
||||
}
|
||||
} add_event_listener( new taggerXML(),10);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
*/
|
||||
|
||||
class WordFilter implements Extension {
|
||||
// before emoticon filter
|
||||
public function get_priority() {return 40;}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
if($event instanceof TextFormattingEvent) {
|
||||
$event->formatted = $this->filter($event->formatted);
|
||||
|
@ -45,5 +48,4 @@ class WordFilter implements Extension {
|
|||
return $map;
|
||||
}
|
||||
}
|
||||
add_event_listener(new WordFilter(), 40); // before emoticon filter
|
||||
?>
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
*/
|
||||
interface Extension {
|
||||
public function receive_event(Event $event);
|
||||
public function get_priority();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,18 +106,18 @@ abstract class SimpleExtension implements Extension {
|
|||
}
|
||||
}
|
||||
|
||||
public function get_priority() {return 50;}
|
||||
public function get_priority() {
|
||||
return 50;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Several extensions have this in common, make a common API
|
||||
*/
|
||||
abstract class FormatterExtension implements Extension {
|
||||
public function receive_event(Event $event) {
|
||||
if($event instanceof TextFormattingEvent) {
|
||||
$event->formatted = $this->format($event->formatted);
|
||||
$event->stripped = $this->strip($event->stripped);
|
||||
}
|
||||
abstract class FormatterExtension extends SimpleExtension {
|
||||
public function onTextFormatting($event) {
|
||||
$event->formatted = $this->format($event->formatted);
|
||||
$event->stripped = $this->strip($event->stripped);
|
||||
}
|
||||
|
||||
abstract public function format($text);
|
||||
|
@ -127,20 +128,14 @@ abstract class FormatterExtension implements Extension {
|
|||
* This too is a common class of extension with many methods in common,
|
||||
* so we have a base class to extend from
|
||||
*/
|
||||
abstract class DataHandlerExtension implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
||||
if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
|
||||
|
||||
abstract class DataHandlerExtension extends SimpleExtension {
|
||||
public function onDataUpload($event) {
|
||||
if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
|
||||
if(!move_upload_to_archive($event)) return;
|
||||
send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
|
||||
|
||||
/* Check if we are replacing an image */
|
||||
if (array_key_exists('replace',$event->metadata) && isset($event->metadata['replace']))
|
||||
{
|
||||
if(array_key_exists('replace', $event->metadata) && isset($event->metadata['replace'])) {
|
||||
/* hax: This seems like such a dirty way to do this.. */
|
||||
|
||||
/* Validate things */
|
||||
|
@ -168,8 +163,7 @@ abstract class DataHandlerExtension implements Extension {
|
|||
send_event($ire);
|
||||
$event->image_id = $image_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
$image = $this->create_image_from_data(warehouse_path("images", $event->hash), $event->metadata);
|
||||
if(is_null($image)) {
|
||||
throw new UploadException("Data handler failed to create image object from data");
|
||||
|
@ -192,8 +186,10 @@ abstract class DataHandlerExtension implements Extension {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) {
|
||||
public function onThumnbnailGeneration($event) {
|
||||
if($this->supported_ext($event->type)) {
|
||||
if (method_exists($this, 'create_thumb_force') && $event->force == true) {
|
||||
$this->create_thumb_force($event->hash);
|
||||
}
|
||||
|
@ -201,16 +197,18 @@ abstract class DataHandlerExtension implements Extension {
|
|||
$this->create_thumb($event->hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) {
|
||||
global $page;
|
||||
public function onDisplayingImage($event) {
|
||||
global $page;
|
||||
if($this->supported_ext($event->image->ext)) {
|
||||
$this->theme->display_image($page, $event->image);
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof SetupBuildingEvent)) {
|
||||
$sb = $this->setup();
|
||||
if($sb) $event->panel->add_block($sb);
|
||||
}
|
||||
public function onSetupBuilding($event) {
|
||||
$sb = $this->setup();
|
||||
if($sb) $event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
protected function setup() {}
|
||||
|
|
|
@ -790,12 +790,14 @@ $_event_listeners = array();
|
|||
/**
|
||||
* Register an Extension
|
||||
*/
|
||||
function add_event_listener(Extension $extension, $pos=50) {
|
||||
function add_event_listener(Extension $extension, $pos=50, $events=array()) {
|
||||
global $_event_listeners;
|
||||
while(isset($_event_listeners[$pos])) {
|
||||
$pos++;
|
||||
foreach($events as $event) {
|
||||
while(isset($_event_listeners[$event][$pos])) {
|
||||
$pos++;
|
||||
}
|
||||
$_event_listeners[$event][$pos] = $extension;
|
||||
}
|
||||
$_event_listeners[$pos] = $extension;
|
||||
}
|
||||
|
||||
/** @private */
|
||||
|
@ -806,8 +808,11 @@ $_event_count = 0;
|
|||
*/
|
||||
function send_event(Event $event) {
|
||||
global $_event_listeners, $_event_count;
|
||||
if(!isset($_event_listeners[get_class($event)])) return;
|
||||
|
||||
ctx_log_start(get_class($event));
|
||||
$my_event_listeners = $_event_listeners; // http://bugs.php.net/bug.php?id=35106
|
||||
// SHIT: http://bugs.php.net/bug.php?id=35106
|
||||
$my_event_listeners = $_event_listeners[get_class($event)];
|
||||
ksort($my_event_listeners);
|
||||
foreach($my_event_listeners as $listener) {
|
||||
ctx_log_start(get_class($listener));
|
||||
|
|
24
index.php
24
index.php
|
@ -138,11 +138,31 @@ try {
|
|||
|
||||
|
||||
// initialise the extensions
|
||||
$all_events = array();
|
||||
foreach(get_declared_classes() as $class) {
|
||||
if(is_subclass_of($class, "SimpleExtension")) {
|
||||
if(is_subclass_of($class, "Event")) {
|
||||
$all_events[] = $class;
|
||||
}
|
||||
}
|
||||
foreach(get_declared_classes() as $class) {
|
||||
$rclass = new ReflectionClass($class);
|
||||
if($rclass->isAbstract()) {
|
||||
// don't do anything
|
||||
}
|
||||
elseif(is_subclass_of($class, "SimpleExtension")) {
|
||||
$c = new $class();
|
||||
$c->i_am($c);
|
||||
add_event_listener($c, $c->get_priority());
|
||||
$my_events = array();
|
||||
foreach(get_class_methods($c) as $method) {
|
||||
if(substr($method, 0, 2) == "on") {
|
||||
$my_events[] = substr($method, 2) . "Event";
|
||||
}
|
||||
}
|
||||
add_event_listener($c, $c->get_priority(), $my_events);
|
||||
}
|
||||
elseif(is_subclass_of($class, "Extension")) {
|
||||
$c = new $class();
|
||||
add_event_listener($c, $c->get_priority(), $all_events);
|
||||
}
|
||||
}
|
||||
ctx_log_endok("Initialisation");
|
||||
|
|
Reference in a new issue