Merge branch 'master' of github.com:shish/shimmie2

This commit is contained in:
Shish 2012-01-27 18:21:09 +00:00
commit ff9e4192ce
24 changed files with 96 additions and 58 deletions

View file

@ -38,6 +38,8 @@ class AdminBuildingEvent extends Event {
class AdminPage implements Extension { class AdminPage implements Extension {
var $theme; var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
@ -179,5 +181,4 @@ class AdminPage implements Extension {
} }
*/ */
} }
add_event_listener(new AdminPage());
?> ?>

View file

@ -22,6 +22,8 @@ class AuthorSetEvent extends Event {
class Artists implements Extension { class Artists implements Extension {
var $theme; var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event) public function receive_event(Event $event)
{ {
global $user; global $user;
@ -1221,5 +1223,4 @@ class Artists implements Extension {
return $result; return $result;
} }
} }
add_event_listener(new Artists());
?> ?>

View file

@ -9,6 +9,8 @@
class Bookmarks implements Extension { class Bookmarks implements Extension {
var $theme; var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this); 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)); $database->Execute($sql, array($user->id, $url, $title));
} }
} }
add_event_listener(new Bookmarks());
?> ?>

View file

@ -14,6 +14,8 @@
*/ */
class BrowserSearch implements Extension { class BrowserSearch implements Extension {
public function get_priority() {return 50;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $page; global $page;
global $config; global $config;
@ -112,5 +114,4 @@ class BrowserSearch implements Extension {
} }
} }
} }
add_event_listener(new BrowserSearch());
?> ?>

View file

@ -49,6 +49,8 @@ Completely compatibility will probably involve a rewrite with a different URL
class DanbooruApi implements Extension class DanbooruApi implements Extension
{ {
public function get_priority() {return 50;}
// Receive the event // Receive the event
public function receive_event(Event $event) public function receive_event(Event $event)
{ {
@ -425,5 +427,4 @@ class DanbooruApi implements Extension
} }
} }
add_event_listener(new DanbooruApi());
?> ?>

View file

@ -14,6 +14,8 @@
class Downtime implements Extension { class Downtime implements Extension {
var $theme; var $theme;
public function get_priority() {return 10;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
@ -42,5 +44,4 @@ class Downtime implements Extension {
else return false; else return false;
} }
} }
add_event_listener(new Downtime(), 10);
?> ?>

View file

@ -100,5 +100,4 @@ class FlashFileHandler extends DataHandlerExtension {
return $bounds; return $bounds;
} }
} }
add_event_listener(new FlashFileHandler());
?> ?>

View file

@ -39,5 +39,4 @@ class MP3FileHandler extends DataHandlerExtension {
return (file_exists($file)); return (file_exists($file));
} }
} }
add_event_listener(new MP3FileHandler());
?> ?>

View file

@ -8,6 +8,8 @@
class SVGFileHandler implements Extension { class SVGFileHandler implements Extension {
var $theme; var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
@ -113,6 +115,4 @@ class MiniSVGParser {
function endElement($parser, $name) { function endElement($parser, $name) {
} }
} }
add_event_listener(new SVGFileHandler());
?> ?>

View file

@ -28,6 +28,5 @@ class Holiday extends SimpleExtension {
} }
} }
} }
} }
?> ?>

View file

@ -37,6 +37,8 @@ class AddIPBanEvent extends Event {
class IPBan implements Extension { class IPBan implements Extension {
var $theme; var $theme;
// event handler {{{ // event handler {{{
public function get_priority() {return 10;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this); 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);
?> ?>

View file

@ -7,6 +7,8 @@
class LinkImage implements Extension { class LinkImage implements Extension {
var $theme; var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
@ -48,5 +50,4 @@ class LinkImage implements Extension {
'text_link' => $text_link); 'text_link' => $text_link);
} }
} }
add_event_listener(new LinkImage());
?> ?>

View file

@ -22,6 +22,8 @@ class NumericScoreSetEvent extends Event {
class NumericScore implements Extension { class NumericScore implements Extension {
var $theme; var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
@ -271,5 +273,4 @@ class NumericScore implements Extension {
array($image_id, $image_id)); array($image_id, $image_id));
} }
} }
add_event_listener(new NumericScore());
?> ?>

View file

@ -83,6 +83,7 @@ class Oekaki extends SimpleExtension {
// FIXME: "edit this image" button on existing images? // FIXME: "edit this image" button on existing images?
function onPostListBuilding($event) { function onPostListBuilding($event) {
global $user, $page;
if($this->can_upload($user)) { if($this->can_upload($user)) {
$this->theme->display_block($page); $this->theme->display_block($page);
} }

View file

@ -20,6 +20,8 @@ class RatingSetEvent extends Event {
class Ratings implements Extension { class Ratings implements Extension {
var $theme; var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
@ -218,5 +220,4 @@ class Ratings implements Extension {
} }
} }
} }
add_event_listener(new Ratings());
?> ?>

View file

@ -32,6 +32,8 @@ class AddReportedImageEvent extends Event {
class ReportImage implements Extension { class ReportImage implements Extension {
var $theme; var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
@ -143,8 +145,6 @@ class ReportImage implements Extension {
return $reports; return $reports;
} }
} }
add_event_listener(new ReportImage(), 29); // Not sure what I'm in before.
// ===== Changelog ===== // ===== 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. // * 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 // * 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.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.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. // * Version 0.2 - 10/24/07 - First public release.
?> ?>

View file

@ -6,6 +6,8 @@
* Description: Allows the admin to set min / max image dimentions * Description: Allows the admin to set min / max image dimentions
*/ */
class ResolutionLimit implements Extension { class ResolutionLimit implements Extension {
public function get_priority() {return 40;} // early, to veto ImageUploadEvent
public function receive_event(Event $event) { public function receive_event(Event $event) {
if($event instanceof ImageAdditionEvent) { if($event instanceof ImageAdditionEvent) {
global $config; global $config;
@ -68,5 +70,4 @@ class ResolutionLimit implements Extension {
} }
} }
} }
add_event_listener(new ResolutionLimit(), 40); // early, to veto UIE
?> ?>

View file

@ -15,6 +15,8 @@
class TagEditCloud implements Extension { class TagEditCloud implements Extension {
var $theme; var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
//if(is_null($this->theme)) $this->theme = get_theme_object($this); //if(is_null($this->theme)) $this->theme = get_theme_object($this);
@ -133,5 +135,4 @@ class TagEditCloud implements Extension {
} }
} }
add_event_listener(new TagEditCloud());
?> ?>

View file

@ -8,6 +8,9 @@
class Tag_History implements Extension { class Tag_History implements Extension {
var $theme; 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) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
@ -352,5 +355,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
?> ?>

View file

@ -9,6 +9,8 @@
class Tagger implements Extension { class Tagger implements Extension {
var $theme; var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
if(is_null($this->theme)) if(is_null($this->theme))
$this->theme = get_theme_object($this); $this->theme = get_theme_object($this);
@ -38,10 +40,10 @@ class Tagger implements Extension {
} }
} }
add_event_listener(new Tagger());
// Tagger AJAX back-end // Tagger AJAX back-end
class TaggerXML implements Extension { class TaggerXML implements Extension {
public function get_priority() {return 10;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
if(($event instanceof PageRequestEvent) && $event->page_matches("tagger/tags")) { if(($event instanceof PageRequestEvent) && $event->page_matches("tagger/tags")) {
global $page; global $page;
@ -170,5 +172,5 @@ class TaggerXML implements Extension {
return $list; return $list;
} }
} add_event_listener( new taggerXML(),10); }
?> ?>

View file

@ -7,6 +7,9 @@
*/ */
class WordFilter implements Extension { class WordFilter implements Extension {
// before emoticon filter
public function get_priority() {return 40;}
public function receive_event(Event $event) { public function receive_event(Event $event) {
if($event instanceof TextFormattingEvent) { if($event instanceof TextFormattingEvent) {
$event->formatted = $this->filter($event->formatted); $event->formatted = $this->filter($event->formatted);
@ -45,5 +48,4 @@ class WordFilter implements Extension {
return $map; return $map;
} }
} }
add_event_listener(new WordFilter(), 40); // before emoticon filter
?> ?>

View file

@ -67,6 +67,7 @@
*/ */
interface Extension { interface Extension {
public function receive_event(Event $event); public function receive_event(Event $event);
public function get_priority();
} }
/** /**
@ -105,19 +106,19 @@ 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 * Several extensions have this in common, make a common API
*/ */
abstract class FormatterExtension implements Extension { abstract class FormatterExtension extends SimpleExtension {
public function receive_event(Event $event) { public function onTextFormatting($event) {
if($event instanceof TextFormattingEvent) {
$event->formatted = $this->format($event->formatted); $event->formatted = $this->format($event->formatted);
$event->stripped = $this->strip($event->stripped); $event->stripped = $this->strip($event->stripped);
} }
}
abstract public function format($text); abstract public function format($text);
abstract public function strip($text); abstract public function strip($text);
@ -127,20 +128,14 @@ abstract class FormatterExtension implements Extension {
* This too is a common class of extension with many methods in common, * This too is a common class of extension with many methods in common,
* so we have a base class to extend from * so we have a base class to extend from
*/ */
abstract class DataHandlerExtension implements Extension { abstract class DataHandlerExtension extends SimpleExtension {
var $theme; public function onDataUpload($event) {
if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
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)) {
if(!move_upload_to_archive($event)) return; if(!move_upload_to_archive($event)) return;
send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
/* Check if we are replacing an image */ /* 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.. */ /* hax: This seems like such a dirty way to do this.. */
/* Validate things */ /* Validate things */
@ -168,8 +163,7 @@ abstract class DataHandlerExtension implements Extension {
send_event($ire); send_event($ire);
$event->image_id = $image_id; $event->image_id = $image_id;
} }
else else {
{
$image = $this->create_image_from_data(warehouse_path("images", $event->hash), $event->metadata); $image = $this->create_image_from_data(warehouse_path("images", $event->hash), $event->metadata);
if(is_null($image)) { if(is_null($image)) {
throw new UploadException("Data handler failed to create image object from data"); 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) { if (method_exists($this, 'create_thumb_force') && $event->force == true) {
$this->create_thumb_force($event->hash); $this->create_thumb_force($event->hash);
} }
@ -201,17 +197,19 @@ abstract class DataHandlerExtension implements Extension {
$this->create_thumb($event->hash); $this->create_thumb($event->hash);
} }
} }
}
if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) { public function onDisplayingImage($event) {
global $page; global $page;
if($this->supported_ext($event->image->ext)) {
$this->theme->display_image($page, $event->image); $this->theme->display_image($page, $event->image);
} }
}
if(($event instanceof SetupBuildingEvent)) { public function onSetupBuilding($event) {
$sb = $this->setup(); $sb = $this->setup();
if($sb) $event->panel->add_block($sb); if($sb) $event->panel->add_block($sb);
} }
}
protected function setup() {} protected function setup() {}
abstract protected function supported_ext($ext); abstract protected function supported_ext($ext);

View file

@ -790,12 +790,14 @@ $_event_listeners = array();
/** /**
* Register an Extension * Register an Extension
*/ */
function add_event_listener(Extension $extension, $pos=50) { function add_event_listener(Extension $extension, $pos=50, $events=array()) {
global $_event_listeners; global $_event_listeners;
while(isset($_event_listeners[$pos])) { foreach($events as $event) {
while(isset($_event_listeners[$event][$pos])) {
$pos++; $pos++;
} }
$_event_listeners[$pos] = $extension; $_event_listeners[$event][$pos] = $extension;
}
} }
/** @private */ /** @private */
@ -806,8 +808,11 @@ $_event_count = 0;
*/ */
function send_event(Event $event) { function send_event(Event $event) {
global $_event_listeners, $_event_count; global $_event_listeners, $_event_count;
if(!isset($_event_listeners[get_class($event)])) return;
ctx_log_start(get_class($event)); 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); ksort($my_event_listeners);
foreach($my_event_listeners as $listener) { foreach($my_event_listeners as $listener) {
ctx_log_start(get_class($listener)); ctx_log_start(get_class($listener));

View file

@ -138,11 +138,31 @@ try {
// initialise the extensions // initialise the extensions
$all_events = array();
foreach(get_declared_classes() as $class) { 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 = new $class();
$c->i_am($c); $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"); ctx_log_endok("Initialisation");