remove regular Extension, have SimpleExtension take its place, optimise the event system based on SimpleExtension methods

This commit is contained in:
Shish 2012-02-08 12:07:01 +00:00
parent 2b85e2d2fd
commit 0698b780f9
69 changed files with 79 additions and 116 deletions

View file

@ -35,7 +35,7 @@ class AdminBuildingEvent extends Event {
} }
} }
class AdminPage extends SimpleExtension { class AdminPage extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page, $user; global $page, $user;

View file

@ -9,7 +9,7 @@
require_once "lib/S3.php"; require_once "lib/S3.php";
class UploadS3 extends SimpleExtension { class UploadS3 extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_string("amazon_s3_access", ""); $config->set_default_string("amazon_s3_access", "");

View file

@ -19,7 +19,7 @@ class AuthorSetEvent extends Event {
} }
} }
class Artists extends SimpleExtension { class Artists extends Extension {
public function onImageInfoSet(ImageInfoSetEvent $event) { public function onImageInfoSet(ImageInfoSetEvent $event) {
global $user; global $user;
if (isset($_POST["tag_edit__author"])) { if (isset($_POST["tag_edit__author"])) {

View file

@ -19,7 +19,7 @@
* from Essex" * from Essex"
*/ */
class BanWords extends SimpleExtension { class BanWords extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_string('banned_words', " $config->set_default_string('banned_words', "

View file

@ -27,7 +27,7 @@
* </pre> * </pre>
*/ */
class Blocks extends SimpleExtension { class Blocks extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $config, $page; global $config, $page;
$all = $config->get_string("blocks_text"); $all = $config->get_string("blocks_text");

View file

@ -8,7 +8,7 @@
* *
* Development TODO at http://github.com/zshall/shimmie2/issues * Development TODO at http://github.com/zshall/shimmie2/issues
*/ */
class Blotter extends SimpleExtension { class Blotter extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
/** /**
* I love re-using this installer don't I... * I love re-using this installer don't I...

View file

@ -6,7 +6,7 @@
* Description: Allow users to bookmark searches * Description: Allow users to bookmark searches
*/ */
class Bookmarks extends SimpleExtension { class Bookmarks extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
$this->install(); $this->install();
} }

View file

@ -13,7 +13,7 @@
* engine" notification they have * engine" notification they have
*/ */
class BrowserSearch extends SimpleExtension { class BrowserSearch extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_string("search_suggestions_results_order", 'a'); $config->set_default_string("search_suggestions_results_order", 'a');

View file

@ -14,7 +14,7 @@
* <p><b>Note:</b> requires the "admin" extension to be enabled * <p><b>Note:</b> requires the "admin" extension to be enabled
*/ */
class BulkAdd extends SimpleExtension { class BulkAdd extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page, $user; global $page, $user;
if($event->page_matches("bulk_add")) { if($event->page_matches("bulk_add")) {

View file

@ -47,7 +47,7 @@ Completely compatibility will probably involve a rewrite with a different URL
*/ */
class DanbooruApi extends SimpleExtension { class DanbooruApi extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
if($event->page_matches("api") && ($event->get_arg(0) == 'danbooru')) { if($event->page_matches("api") && ($event->get_arg(0) == 'danbooru')) {
$this->api_danbooru($event); $this->api_danbooru($event);

View file

@ -11,7 +11,7 @@
* message specified in the box. * message specified in the box.
*/ */
class Downtime extends SimpleExtension { class Downtime extends Extension {
public function get_priority() {return 10;} public function get_priority() {return 10;}
public function onSetupBuilding($event) { public function onSetupBuilding($event) {

View file

@ -24,7 +24,7 @@ class Emoticons extends FormatterExtension {
} }
} }
class EmoticonList extends SimpleExtension { class EmoticonList extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
if($event->page_matches("emote/list")) { if($event->page_matches("emote/list")) {
$this->theme->display_emotes(glob("ext/emoticons/default/*")); $this->theme->display_emotes(glob("ext/emoticons/default/*"));

View file

@ -12,7 +12,7 @@
* versions of PHP I should test with, etc. * versions of PHP I should test with, etc.
*/ */
class ET extends SimpleExtension { class ET extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $user; global $user;
if($event->page_matches("system_info")) { if($event->page_matches("system_info")) {

View file

@ -26,7 +26,7 @@ class FavoriteSetEvent extends Event {
} }
} }
class Favorites extends SimpleExtension { class Favorites extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
if($config->get_int("ext_favorites_version", 0) < 1) { if($config->get_int("ext_favorites_version", 0) < 1) {

View file

@ -18,7 +18,7 @@
* every couple of hours. * every couple of hours.
*/ */
class Featured extends SimpleExtension { class Featured extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_int('featured_id', 0); $config->set_default_int('featured_id', 0);

View file

@ -8,7 +8,7 @@
* Documentation: * Documentation:
*/ */
class Forum extends SimpleExtension { class Forum extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config, $database; global $config, $database;

View file

@ -10,7 +10,7 @@
* <br>7-zip: <code>7zr x -o"%d" "%f"</code> * <br>7-zip: <code>7zr x -o"%d" "%f"</code>
*/ */
class ArchiveFileHandler extends SimpleExtension { class ArchiveFileHandler extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_string('archive_extract_command', 'unzip -d "%d" "%f"'); $config->set_default_string('archive_extract_command', 'unzip -d "%d" "%f"');

View file

@ -5,7 +5,7 @@
* Description: Handle windows icons * Description: Handle windows icons
*/ */
class IcoFileHandler extends SimpleExtension { class IcoFileHandler extends Extension {
public function onDataUpload(DataUploadEvent $event) { public function onDataUpload(DataUploadEvent $event) {
if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
$hash = $event->hash; $hash = $event->hash;

View file

@ -5,7 +5,7 @@
* Description: Handle SVG files * Description: Handle SVG files
*/ */
class SVGFileHandler extends SimpleExtension { class SVGFileHandler extends Extension {
public function onDataUpload(DataUploadEvent $event) { public function onDataUpload(DataUploadEvent $event) {
if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
$hash = $event->hash; $hash = $event->hash;

View file

@ -6,7 +6,7 @@
* License: GPLv2 * License: GPLv2
* Description: Use an additional stylesheet on certain holidays. * Description: Use an additional stylesheet on certain holidays.
*/ */
class Holiday extends SimpleExtension { class Holiday extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_bool("holiday_aprilfools", false); $config->set_default_bool("holiday_aprilfools", false);

View file

@ -15,7 +15,7 @@
* alongside the default choices. * alongside the default choices.
*/ */
class Home extends SimpleExtension { class Home extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_string("home_links", '[$base/post/list|Posts] $config->set_default_string("home_links", '[$base/post/list|Posts]

View file

@ -29,7 +29,7 @@ class AddImageHashBanEvent extends Event {
} }
} }
// }}} // }}}
class ImageBan extends SimpleExtension { class ImageBan extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config, $database; global $config, $database;
if($config->get_int("ext_imageban_version") < 1) { if($config->get_int("ext_imageban_version") < 1) {

View file

@ -34,7 +34,7 @@ class AddIPBanEvent extends Event {
} }
// }}} // }}}
class IPBan extends SimpleExtension { class IPBan extends Extension {
public function get_priority() {return 10;} public function get_priority() {return 10;}
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {

View file

@ -4,7 +4,7 @@
* Author: Artanis <artanis.00@gmail.com> * Author: Artanis <artanis.00@gmail.com>
* Description: Show various forms of link to each image, for copy & paste * Description: Show various forms of link to each image, for copy & paste
*/ */
class LinkImage extends SimpleExtension { class LinkImage extends Extension {
public function onDisplayingImage(DisplayingImageEvent $event) { public function onDisplayingImage(DisplayingImageEvent $event) {
global $page; global $page;
$this->theme->links_block($page, $this->data($event->image)); $this->theme->links_block($page, $this->data($event->image));

View file

@ -6,7 +6,7 @@
* Visibility: admin * Visibility: admin
*/ */
class LogDatabase extends SimpleExtension { class LogDatabase extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $database; global $database;
global $config; global $config;

View file

@ -14,7 +14,7 @@
* As of now only compatible with the lite theme. * As of now only compatible with the lite theme.
*/ */
class MassTagger extends SimpleExtension { class MassTagger extends Extension {
public function onPostListBuilding(PostListBuildingEvent $event) { public function onPostListBuilding(PostListBuildingEvent $event) {
global $config, $page, $user; global $config, $page, $user;

View file

@ -8,7 +8,7 @@
* Any HTML is allowed * Any HTML is allowed
*/ */
class News extends SimpleExtension { class News extends Extension {
public function onPostListBuilding(PostListBuildingEvent $event) { public function onPostListBuilding(PostListBuildingEvent $event) {
global $config, $page; global $config, $page;
if(strlen($config->get_string("news_text")) > 0) { if(strlen($config->get_string("news_text")) > 0) {

View file

@ -7,7 +7,7 @@
* Documentation: * Documentation:
*/ */
class Notes extends SimpleExtension { class Notes extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config, $database; global $config, $database;

View file

@ -19,7 +19,7 @@ class NumericScoreSetEvent extends Event {
} }
} }
class NumericScore extends SimpleExtension { class NumericScore extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
if($config->get_int("ext_numeric_score_version", 0) < 1) { if($config->get_int("ext_numeric_score_version", 0) < 1) {

View file

@ -5,7 +5,7 @@
* Description: ChibiPaint-based Oekaki uploader * Description: ChibiPaint-based Oekaki uploader
*/ */
class Oekaki extends SimpleExtension { class Oekaki extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $user, $page; global $user, $page;

View file

@ -42,7 +42,7 @@ class PM {
} }
} }
class PrivMsg extends SimpleExtension { class PrivMsg extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config, $database; global $config, $database;

View file

@ -10,7 +10,7 @@
class PoolCreationException extends SCoreException { class PoolCreationException extends SCoreException {
} }
class Pools extends SimpleExtension { class Pools extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config, $database; global $config, $database;

View file

@ -7,7 +7,7 @@
* Further modified by Shish to remove the 7MB local QR generator * Further modified by Shish to remove the 7MB local QR generator
* and replace it with a link to google chart APIs * and replace it with a link to google chart APIs
*/ */
class QRImage extends SimpleExtension { class QRImage extends Extension {
public function onDisplayingImage(DisplayingImageEvent $event) { public function onDisplayingImage(DisplayingImageEvent $event) {
$this->theme->links_block(make_http(make_link('image/'.$event->image->id.'.jpg'))); $this->theme->links_block(make_http(make_link('image/'.$event->image->id.'.jpg')));
} }

View file

@ -19,7 +19,7 @@
* <code>/random_image/download/size=1024x768+cute</code> * <code>/random_image/download/size=1024x768+cute</code>
*/ */
class RandomImage extends SimpleExtension { class RandomImage extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if($event->page_matches("random_image")) { if($event->page_matches("random_image")) {

View file

@ -17,7 +17,7 @@ class RatingSetEvent extends Event {
} }
} }
class Ratings extends SimpleExtension { class Ratings extends Extension {
public function onAdminBuilding(AdminBuildingEvent $event) { public function onAdminBuilding(AdminBuildingEvent $event) {
$this->theme->display_bulk_rater(); $this->theme->display_bulk_rater();
} }

View file

@ -12,7 +12,7 @@
* since been increased. * since been increased.
*/ */
class RegenThumb extends SimpleExtension { class RegenThumb extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;

View file

@ -29,7 +29,7 @@ class AddReportedImageEvent extends Event {
} }
} }
class ReportImage extends SimpleExtension { class ReportImage extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_bool('report_image_show_thumbs', true); $config->set_default_bool('report_image_show_thumbs', true);

View file

@ -5,7 +5,7 @@
* License: GPLv2 * License: GPLv2
* Description: Allows the admin to set min / max image dimentions * Description: Allows the admin to set min / max image dimentions
*/ */
class ResolutionLimit extends SimpleExtension { class ResolutionLimit extends Extension {
public function get_priority() {return 40;} // early, to veto ImageUploadEvent public function get_priority() {return 40;} // early, to veto ImageUploadEvent
public function onImageAddition(ImageAdditionEvent $event) { public function onImageAddition(ImageAdditionEvent $event) {

View file

@ -26,7 +26,7 @@ class ImageResizeException extends SCoreException {
/** /**
* This class handles image resize requests. * This class handles image resize requests.
*/ */
class ResizeImage extends SimpleExtension { class ResizeImage extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;

View file

@ -6,7 +6,7 @@
* Description: Self explanatory * Description: Self explanatory
*/ */
class RSS_Comments extends SimpleExtension { class RSS_Comments extends Extension {
public function onPostListBuilding(PostListBuildingEvent $event) { public function onPostListBuilding(PostListBuildingEvent $event) {
global $config, $page; global $config, $page;
$title = $config->get_string('title'); $title = $config->get_string('title');

View file

@ -6,7 +6,7 @@
* Description: Self explanatory * Description: Self explanatory
*/ */
class RSS_Images extends SimpleExtension { class RSS_Images extends Extension {
public function onPostListBuilding(PostListBuildingEvent $event) { public function onPostListBuilding(PostListBuildingEvent $event) {
global $config, $page; global $config, $page;
$title = $config->get_string('title'); $title = $config->get_string('title');

View file

@ -26,7 +26,7 @@ class _SafeImage {
} }
} }
class ShimmieApi extends SimpleExtension { class ShimmieApi extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $database, $page; global $database, $page;

View file

@ -205,7 +205,7 @@ class TestFinder extends TestSuite {
} }
} }
class SimpleSCoreTest extends SimpleExtension { class SimpleSCoreTest extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page; global $page;
if($event->page_matches("test")) { if($event->page_matches("test")) {

View file

@ -9,7 +9,7 @@
* This extension sets the "description" meta tag in the header * This extension sets the "description" meta tag in the header
* of pages so that search engines can pick it up * of pages so that search engines can pick it up
*/ */
class SiteDescription extends SimpleExtension { class SiteDescription extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $config, $page; global $config, $page;
if(strlen($config->get_string("site_description")) > 0) { if(strlen($config->get_string("site_description")) > 0) {

View file

@ -7,7 +7,7 @@
* Documentation: * Documentation:
*/ */
class XMLSitemap extends SimpleExtension { class XMLSitemap extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
if($event->page_matches("sitemap.xml")) { if($event->page_matches("sitemap.xml")) {
$images = Image::find_images(0, 50, array()); $images = Image::find_images(0, 50, array());

View file

@ -12,7 +12,7 @@
* colorize used tags in cloud || always show used tags in front of cloud * colorize used tags in cloud || always show used tags in front of cloud
* theme junk * theme junk
*/ */
class TagEditCloud extends SimpleExtension { class TagEditCloud extends Extension {
public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) { public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) {
global $config; global $config;

View file

@ -5,7 +5,7 @@
* Description: Keep a record of tag changes, and allows you to revert changes. * Description: Keep a record of tag changes, and allows you to revert changes.
*/ */
class Tag_History extends SimpleExtension { class Tag_History extends Extension {
// in before tags are actually set, so that "get current tags" works // in before tags are actually set, so that "get current tags" works
public function get_priority() {return 40;} public function get_priority() {return 40;}

View file

@ -6,7 +6,7 @@
* Do not remove this notice. * Do not remove this notice.
*/ */
class Tagger extends SimpleExtension { class Tagger extends Extension {
public function onDisplayingImage(DisplayingImageEvent $event) { public function onDisplayingImage(DisplayingImageEvent $event) {
global $page, $config, $user; global $page, $config, $user;
@ -32,7 +32,7 @@ class Tagger extends SimpleExtension {
} }
// Tagger AJAX back-end // Tagger AJAX back-end
class TaggerXML extends SimpleExtension { class TaggerXML extends Extension {
public function get_priority() {return 10;} public function get_priority() {return 10;}
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {

View file

@ -8,7 +8,7 @@
* Formatting is done with HTML * Formatting is done with HTML
*/ */
class Tips extends SimpleExtension { class Tips extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config, $database; global $config, $database;

View file

@ -6,7 +6,7 @@
* Description: Show a twitter feed with the Sea of Clouds script * Description: Show a twitter feed with the Sea of Clouds script
*/ */
class TwitterSoc extends SimpleExtension { class TwitterSoc extends Extension {
public function onPostListBuilding(PostListBuildingEvent $event) { public function onPostListBuilding(PostListBuildingEvent $event) {
global $config, $page; global $config, $page;
if(strlen($config->get_string("twitter_soc_username")) > 0) { if(strlen($config->get_string("twitter_soc_username")) > 0) {

View file

@ -6,7 +6,7 @@
* License: GPLv2 * License: GPLv2
* Description: Shimmie updater! * Description: Shimmie updater!
*/ */
class Update extends SimpleExtension { class Update extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_string("update_url", "http://nodeload.github.com/shish/shimmie2/zipball/master"); //best to avoid using https $config->set_default_string("update_url", "http://nodeload.github.com/shish/shimmie2/zipball/master"); //best to avoid using https

View file

@ -53,7 +53,7 @@ class WikiPage {
} }
} }
class Wiki extends SimpleExtension { class Wiki extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $database; global $database;
global $config; global $config;

View file

@ -6,7 +6,7 @@
* Description: Simple search and replace * Description: Simple search and replace
*/ */
class WordFilter extends SimpleExtension { class WordFilter extends Extension {
// before emoticon filter // before emoticon filter
public function get_priority() {return 40;} public function get_priority() {return 40;}

View file

@ -13,20 +13,14 @@
* $formatted_text = $tfe->formatted; * $formatted_text = $tfe->formatted;
* \endcode * \endcode
* *
* An extension is something which is capable of reacting to events. They * An extension is something which is capable of reacting to events.
* register themselves using the add_event_listener() function, after which
* events will be sent to the object's recieve_event() function.
*
* SimpleExtension subclasses are slightly different -- they are registered
* automatically, and events are sent to a named method, eg PageRequestEvent
* will be sent to onPageRequest()
* *
* *
* \page hello The Hello World Extension * \page hello The Hello World Extension
* *
* \code * \code
* // ext/hello/main.php * // ext/hello/main.php
* public class Hello extends SimpleExtension { * public class Hello extends Extension {
* public void onPageRequest(PageRequestEvent $event) { * public void onPageRequest(PageRequestEvent $event) {
* global $page, $user; * global $page, $user;
* $this->theme->display_hello($page, $user); * $this->theme->display_hello($page, $user);
@ -62,33 +56,17 @@
* *
*/ */
/**
* A generic extension class, for subclassing
*/
interface Extension {
public function receive_event(Event $event);
public function get_priority();
}
/** /**
* send_event(BlahEvent()) -> onBlah($event) * send_event(BlahEvent()) -> onBlah($event)
* *
* Also loads the theme object into $this->theme if available * Also loads the theme object into $this->theme if available
* *
* index.php will load all SimpleExtension subclasses, * The original concept came from Artanis's Extension extension
* so no need for register_extension(new Foo())
*
* Automatic registration is done with priority returned by get_priority()
*
* Hopefully this removes as much copy & paste code from the extension
* files as possible~
*
* The original concept came from Artanis's SimpleExtension extension
* --> http://github.com/Artanis/simple-extension/tree/master * --> http://github.com/Artanis/simple-extension/tree/master
* Then re-implemented by Shish after he broke the forum and couldn't * Then re-implemented by Shish after he broke the forum and couldn't
* find the thread where the original was posted >_< * find the thread where the original was posted >_<
*/ */
abstract class SimpleExtension implements Extension { abstract class Extension {
var $theme; var $theme;
var $_child; var $_child;
@ -100,15 +78,6 @@ abstract class SimpleExtension implements Extension {
if(is_null($this->theme)) $this->theme = get_theme_object($child, false); if(is_null($this->theme)) $this->theme = get_theme_object($child, false);
} }
public function receive_event(Event $event) {
$name = get_class($event);
// this is rather clever..
$name = "on".str_replace("Event", "", $name);
if(method_exists($this->_child, $name)) {
$this->_child->$name($event);
}
}
public function get_priority() { public function get_priority() {
return 50; return 50;
} }
@ -117,7 +86,7 @@ abstract class SimpleExtension implements Extension {
/** /**
* Several extensions have this in common, make a common API * Several extensions have this in common, make a common API
*/ */
abstract class FormatterExtension extends SimpleExtension { abstract class FormatterExtension extends Extension {
public function onTextFormatting(TextFormattingEvent $event) { public function onTextFormatting(TextFormattingEvent $event) {
$event->formatted = $this->format($event->formatted); $event->formatted = $this->format($event->formatted);
$event->stripped = $this->strip($event->stripped); $event->stripped = $this->strip($event->stripped);
@ -131,7 +100,7 @@ abstract class FormatterExtension extends SimpleExtension {
* 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 extends SimpleExtension { abstract class DataHandlerExtension extends Extension {
public function onDataUpload(DataUploadEvent $event) { public function onDataUpload(DataUploadEvent $event) {
if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
if(!move_upload_to_archive($event)) return; if(!move_upload_to_archive($event)) return;

View file

@ -824,6 +824,7 @@ $_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; if(!isset($_event_listeners[get_class($event)])) return;
$method_name = "on".str_replace("Event", "", get_class($event));
ctx_log_start(get_class($event)); ctx_log_start(get_class($event));
// SHIT: http://bugs.php.net/bug.php?id=35106 // SHIT: http://bugs.php.net/bug.php?id=35106
@ -831,7 +832,7 @@ function send_event(Event $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));
$listener->receive_event($event); $listener->$method_name($event);
ctx_log_endok(); ctx_log_endok();
} }
$_event_count++; $_event_count++;
@ -1001,7 +1002,7 @@ function _load_extensions() {
if($rclass->isAbstract()) { if($rclass->isAbstract()) {
// don't do anything // don't do anything
} }
elseif(is_subclass_of($class, "SimpleExtension")) { elseif(is_subclass_of($class, "Extension")) {
$c = new $class(); $c = new $class();
$c->i_am($c); $c->i_am($c);
$my_events = array(); $my_events = array();
@ -1012,10 +1013,6 @@ function _load_extensions() {
} }
add_event_listener($c, $c->get_priority(), $my_events); 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);
}
} }
if(COMPILE_ELS) { if(COMPILE_ELS) {
@ -1024,13 +1021,10 @@ function _load_extensions() {
foreach(get_declared_classes() as $class) { foreach(get_declared_classes() as $class) {
$rclass = new ReflectionClass($class); $rclass = new ReflectionClass($class);
if($rclass->isAbstract()) {} if($rclass->isAbstract()) {}
elseif(is_subclass_of($class, "SimpleExtension")) { elseif(is_subclass_of($class, "Extension")) {
$p .= "\$$class = new $class(); "; $p .= "\$$class = new $class(); ";
$p .= "\${$class}->i_am(\$$class);\n"; $p .= "\${$class}->i_am(\$$class);\n";
} }
elseif(is_subclass_of($class, "Extension")) {
$p .= "\$$class = new $class();\n";
}
} }
$p .= "\$_event_listeners = array(\n"; $p .= "\$_event_listeners = array(\n";

View file

@ -22,7 +22,7 @@ class AddAliasEvent extends Event {
class AddAliasException extends SCoreException {} class AddAliasException extends SCoreException {}
class AliasEditor extends SimpleExtension { class AliasEditor extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;

View file

@ -60,7 +60,7 @@ class Comment {
} }
} }
class CommentList extends SimpleExtension { class CommentList extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config, $database; global $config, $database;
$config->set_default_bool('comment_anon', true); $config->set_default_bool('comment_anon', true);

View file

@ -87,7 +87,7 @@ class ExtensionInfo {
} }
} }
class ExtManager extends SimpleExtension { class ExtManager extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page, $user; global $page, $user;
if($event->page_matches("ext_manager")) { if($event->page_matches("ext_manager")) {

View file

@ -8,7 +8,7 @@
* Description: Shows an error message when the user views a page with no content * Description: Shows an error message when the user views a page with no content
*/ */
class Handle404 extends SimpleExtension { class Handle404 extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page; global $page;
// hax. // hax.

View file

@ -129,7 +129,7 @@ class ParseLinkTemplateEvent extends Event {
/** /**
* A class to handle adding / getting / removing image files from the disk. * A class to handle adding / getting / removing image files from the disk.
*/ */
class ImageIO extends SimpleExtension { class ImageIO extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_int('thumb_width', 192); $config->set_default_int('thumb_width', 192);

View file

@ -128,7 +128,7 @@ class PostListBuildingEvent extends Event {
} }
} }
class Index extends SimpleExtension { class Index extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_int("index_width", 3); $config->set_default_int("index_width", 3);

View file

@ -7,7 +7,7 @@
* Description: Provides an interface for sending and receiving mail. * Description: Provides an interface for sending and receiving mail.
*/ */
class Mail extends SimpleExtension { class Mail extends Extension {
public function onSetupBuilding(SetupBuildingEvent $event) { public function onSetupBuilding(SetupBuildingEvent $event) {
$sb = new SetupBlock("Mailing Options"); $sb = new SetupBlock("Mailing Options");
$sb->add_text_option("mail_sub", "<br>Subject prefix: "); $sb->add_text_option("mail_sub", "<br>Subject prefix: ");
@ -26,7 +26,7 @@ class Mail extends SimpleExtension {
$config->set_default_string("mail_fot", "<a href='".make_http(make_link())."'>".$config->get_string("site_title")."</a>"); $config->set_default_string("mail_fot", "<a href='".make_http(make_link())."'>".$config->get_string("site_title")."</a>");
} }
} }
class MailTest extends SimpleExtension { class MailTest extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
if($event->page_matches("mail/test")) { if($event->page_matches("mail/test")) {
global $page; global $page;

View file

@ -161,7 +161,7 @@ class SetupBlock extends Block {
} }
// }}} // }}}
class Setup extends SimpleExtension { class Setup extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_string("title", "Shimmie"); $config->set_default_string("title", "Shimmie");

View file

@ -55,7 +55,7 @@ class LockSetEvent extends Event {
} }
} }
class TagEdit extends SimpleExtension { class TagEdit extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $user, $page; global $user, $page;
if($event->page_matches("tag_edit")) { if($event->page_matches("tag_edit")) {

View file

@ -5,7 +5,7 @@
* Description: Show the tags in various ways * Description: Show the tags in various ways
*/ */
class TagList extends SimpleExtension { class TagList extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_int("tag_list_length", 15); $config->set_default_int("tag_list_length", 15);

View file

@ -6,7 +6,7 @@
* Visibility: admin * Visibility: admin
*/ */
class Upgrade extends SimpleExtension { class Upgrade extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config, $database; global $config, $database;

View file

@ -41,7 +41,7 @@ class UploadException extends SCoreException {}
* All files that are uploaded to the site are handled through this class. * All files that are uploaded to the site are handled through this class.
* This also includes transloaded files as well. * This also includes transloaded files as well.
*/ */
class Upload extends SimpleExtension { class Upload extends Extension {
// early, so it can stop the DataUploadEvent before any data handlers see it // early, so it can stop the DataUploadEvent before any data handlers see it
public function get_priority() {return 40;} public function get_priority() {return 40;}

View file

@ -42,7 +42,7 @@ class UserCreationEvent extends Event {
class UserCreationException extends SCoreException {} class UserCreationException extends SCoreException {}
class UserPage extends SimpleExtension { class UserPage extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; global $config;
$config->set_default_bool("login_signup_enabled", true); $config->set_default_bool("login_signup_enabled", true);

View file

@ -66,7 +66,7 @@ class ImageAdminBlockBuildingEvent extends Event {
} }
} }
class ViewImage extends SimpleExtension { class ViewImage extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page, $user; global $page, $user;