make things use SimpleExtension

This commit is contained in:
Shish 2009-05-11 14:09:24 -07:00
parent 8dd3f8cbc0
commit 389eed5867
19 changed files with 457 additions and 538 deletions

View File

@ -13,26 +13,24 @@
* tagged "holiday 2008") * tagged "holiday 2008")
*/ */
class BulkAdd implements Extension { class BulkAdd extends SimpleExtension {
var $theme; public function onPageRequest($event) {
global $page, $user;
public function receive_event(Event $event) { if($event->page_matches("bulk_add")) {
if(is_null($this->theme)) $this->theme = get_theme_object($this); if($user->is_admin() && isset($_POST['dir'])) {
if(($event instanceof PageRequestEvent) && $event->page_matches("bulk_add")) {
if($event->user->is_admin() && isset($_POST['dir'])) {
set_time_limit(0); set_time_limit(0);
$this->add_dir($_POST['dir']); $this->add_dir($_POST['dir']);
$this->theme->display_upload_results($event->page); $this->theme->display_upload_results($page);
}
} }
} }
if($event instanceof AdminBuildingEvent) { public function onAdminBuilding($event) {
global $page; global $page;
$this->theme->display_admin_block($page); $this->theme->display_admin_block($page);
} }
}
private function add_image($tmpname, $filename, $tags) { private function add_image($tmpname, $filename, $tags) {
if(file_exists($tmpname)) { if(file_exists($tmpname)) {
@ -97,5 +95,4 @@ class BulkAdd implements Extension {
} }
} }
} }
add_event_listener(new BulkAdd());
?> ?>

View File

@ -10,14 +10,13 @@
* <br>7-zip: <code>7zr x -o"%d" "%f"</code> * <br>7-zip: <code>7zr x -o"%d" "%f"</code>
*/ */
class ArchiveFileHandler implements Extension { class ArchiveFileHandler extends SimpleExtension {
public function receive_event(Event $event) { public function onInitExt($event) {
if($event instanceof InitExtEvent) {
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"');
} }
if($event instanceof SetupBuildingEvent) { public function onSetupBuilding($event) {
$sb = new SetupBlock("Archive Handler Options"); $sb = new SetupBlock("Archive Handler Options");
$sb->add_text_option("archive_tmp_dir", "Temporary folder: "); $sb->add_text_option("archive_tmp_dir", "Temporary folder: ");
$sb->add_text_option("archive_extract_command", "<br>Extraction command: "); $sb->add_text_option("archive_extract_command", "<br>Extraction command: ");
@ -25,7 +24,8 @@ class ArchiveFileHandler implements Extension {
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type)) { public function onDataUpload($event) {
if($this->supported_ext($event->type)) {
global $config; global $config;
$tmp = sys_get_temp_dir(); $tmp = sys_get_temp_dir();
$tmpdir = "$tmp/shimmie-archive-{$event->hash}"; $tmpdir = "$tmp/shimmie-archive-{$event->hash}";
@ -38,6 +38,7 @@ class ArchiveFileHandler implements Extension {
} }
} }
private function supported_ext($ext) { private function supported_ext($ext) {
$exts = array("zip"); $exts = array("zip");
return array_contains($exts, strtolower($ext)); return array_contains($exts, strtolower($ext));
@ -100,5 +101,4 @@ class ArchiveFileHandler implements Extension {
// $this->theme->add_status("Adding $subdir", $list); // $this->theme->add_status("Adding $subdir", $list);
} }
} }
add_event_listener(new ArchiveFileHandler());
?> ?>

View File

@ -5,13 +5,9 @@
* Description: Handle Flash files * Description: Handle Flash files
*/ */
class FlashFileHandler implements Extension { class FlashFileHandler 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)) {
$hash = $event->hash; $hash = $event->hash;
$ha = substr($hash, 0, 2); $ha = substr($hash, 0, 2);
if(!move_upload_to_archive($event)) return; if(!move_upload_to_archive($event)) return;
@ -24,19 +20,25 @@ class FlashFileHandler implements Extension {
} }
send_event(new ImageAdditionEvent($event->user, $image)); send_event(new ImageAdditionEvent($event->user, $image));
} }
}
if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) { public function onThumbnailGeneration($event) {
if($this->supported_ext($event->type)) {
$hash = $event->hash; $hash = $event->hash;
$ha = substr($hash, 0, 2); $ha = substr($hash, 0, 2);
// FIXME: scale image, as not all boards use 192x192 // FIXME: scale image, as not all boards use 192x192
copy("ext/handle_flash/thumb.jpg", "thumbs/$ha/$hash"); copy("ext/handle_flash/thumb.jpg", "thumbs/$ha/$hash");
} }
}
if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) { public function onDisplayingImage($event) {
global $page;
if($this->supported_ext($event->image->ext)) {
$this->theme->display_image($event->page, $event->image); $this->theme->display_image($event->page, $event->image);
} }
} }
private function supported_ext($ext) { private function supported_ext($ext) {
$exts = array("swf"); $exts = array("swf");
return array_contains($exts, strtolower($ext)); return array_contains($exts, strtolower($ext));
@ -127,5 +129,4 @@ class FlashFileHandler implements Extension {
return true; return true;
} }
} }
add_event_listener(new FlashFileHandler());
?> ?>

View File

@ -5,13 +5,9 @@
* Description: Handle windows icons * Description: Handle windows icons
*/ */
class IcoFileHandler implements Extension { class IcoFileHandler 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)) {
$hash = $event->hash; $hash = $event->hash;
$ha = substr($hash, 0, 2); $ha = substr($hash, 0, 2);
if(!move_upload_to_archive($event)) return; if(!move_upload_to_archive($event)) return;
@ -22,29 +18,35 @@ class IcoFileHandler implements Extension {
} }
send_event(new ImageAdditionEvent($event->user, $image)); send_event(new ImageAdditionEvent($event->user, $image));
} }
}
if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) { public function onThumbnailGeneration($event) {
if($this->supported_ext($event->type)) {
$this->create_thumb($event->hash); $this->create_thumb($event->hash);
} }
if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) {
$this->theme->display_image($event->page, $event->image);
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("get_ico")) { public function onDisplayingImage($event) {
global $config; if($this->supported_ext($event->image->ext)) {
global $database; $this->theme->display_image($event->page, $event->image);
}
}
public function onPageRequest($event) {
global $config, $database;
if($event->page_matches("get_ico")) {
$id = int_escape($event->get_arg(0)); $id = int_escape($event->get_arg(0));
$image = Image::by_id($id); $image = Image::by_id($id);
$hash = $image->hash; $hash = $image->hash;
$ha = substr($hash, 0, 2); $ha = substr($hash, 0, 2);
$event->page->set_type("image/x-icon"); $page->set_type("image/x-icon");
$event->page->set_mode("data"); $page->set_mode("data");
$event->page->set_data(file_get_contents("images/$ha/$hash")); $page->set_data(file_get_contents("images/$ha/$hash"));
} }
} }
private function supported_ext($ext) { private function supported_ext($ext) {
$exts = array("ico", "ani", "cur"); $exts = array("ico", "ani", "cur");
return array_contains($exts, strtolower($ext)); return array_contains($exts, strtolower($ext));
@ -106,5 +108,4 @@ class IcoFileHandler implements Extension {
return true; return true;
} }
} }
add_event_listener(new IcoFileHandler());
?> ?>

View File

@ -14,20 +14,22 @@
* alongside the default choices. * alongside the default choices.
*/ */
class Home implements Extension { class Home extends SimpleExtension {
var $theme; public function onPageRequest($event) {
global $config, $page;
if($event->page_matches("home")) {
$base_href = $config->get_string('base_href');
$data_href = get_base_href();
$sitename = $config->get_string('title');
$theme_name = $config->get_string('theme');
public function receive_event(Event $event) { $body = $this->get_body();
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("home")) $this->theme->display_page($page, $sitename, $data_href, $theme_name, $body);
{
// this is a request to display this page so output the page.
$this->output_pages($page);
} }
if($event instanceof SetupBuildingEvent) }
{
public function onSetupBuilding($event) {
$counters = array(); $counters = array();
foreach(glob("ext/home/counters/*") as $counter_dirname) { foreach(glob("ext/home/counters/*") as $counter_dirname) {
$name = str_replace("ext/home/counters/", "", $counter_dirname); $name = str_replace("ext/home/counters/", "", $counter_dirname);
@ -41,7 +43,7 @@ class Home implements Extension {
$sb->add_label("<br>Note: page accessed via /home"); $sb->add_label("<br>Note: page accessed via /home");
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
}
private function get_body() private function get_body()
{ {
@ -75,21 +77,5 @@ class Home implements Extension {
return $this->theme->build_body($sitename, $main_links, $contact_link, $num_comma, $counter_text); return $this->theme->build_body($sitename, $main_links, $contact_link, $num_comma, $counter_text);
} }
private function output_pages($page)
{
// output a sectionalised list of all the main pages on the site.
global $config;
$base_href = $config->get_string('base_href');
$data_href = get_base_href();
$sitename = $config->get_string('title');
$theme_name = $config->get_string('theme');
$body = $this->get_body();
$this->theme->display_page($page, $sitename, $data_href, $theme_name, $body);
} }
}
add_event_listener(new Home());
?> ?>

View File

@ -8,25 +8,18 @@
* Any HTML is allowed * Any HTML is allowed
*/ */
class News implements Extension { class News extends SimpleExtension {
var $theme; public function onPostListBuilding($event) {
global $config, $page;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof PostListBuildingEvent) {
if(strlen($config->get_string("news_text")) > 0) { if(strlen($config->get_string("news_text")) > 0) {
$this->theme->display_news($page, $config->get_string("news_text")); $this->theme->display_news($page, $config->get_string("news_text"));
} }
} }
if($event instanceof SetupBuildingEvent) { public function onSetupBuilding($event) {
$sb = new SetupBlock("News"); $sb = new SetupBlock("News");
$sb->add_longtext_option("news_text"); $sb->add_longtext_option("news_text");
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
} }
}
add_event_listener(new News());
?> ?>

View File

@ -20,29 +20,39 @@ class SendPMEvent extends Event {
} }
} }
class PM implements Extension { class PM extends SimpleExtension {
var $theme; public function onInitExt($event) {
global $config, $database;
public function receive_event(Event $event) { // shortcut to latest
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
if($config->get_int("pm_version") < 1) { if($config->get_int("pm_version") < 1) {
$this->install(); $database->create_table("private_message", "
id SCORE_AIPK,
from_id INTEGER NOT NULL,
from_ip SCORE_INET NOT NULL,
to_id INTEGER NOT NULL,
sent_date DATETIME NOT NULL,
subject VARCHAR(64) NOT NULL,
message TEXT NOT NULL,
is_read SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
INDEX (to_id)
");
$config->set_int("pm_version", 1);
log_info("pm", "extension installed");
} }
} }
/* /*
if($event instanceof UserBlockBuildingEvent) { public function onUserBlockBuilding($event) {
global $user;
if(!$user->is_anonymous()) { if(!$user->is_anonymous()) {
$event->add_link("Private Messages", make_link("pm")); $event->add_link("Private Messages", make_link("pm"));
} }
} }
*/ */
if($event instanceof UserPageBuildingEvent) { public function onUserPageBuilding($event) {
global $page, $user;
$duser = $event->display_user; $duser = $event->display_user;
if(!$user->is_anonymous() && !$duser->is_anonymous()) { if(!$user->is_anonymous() && !$duser->is_anonymous()) {
if(($user->id == $duser->id) || $user->is_admin()) { if(($user->id == $duser->id) || $user->is_admin()) {
@ -54,7 +64,8 @@ class PM implements Extension {
} }
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("pm")) { public function onPageRequest($event) {
if($event->page_matches("pm")) {
if(!$user->is_anonymous()) { if(!$user->is_anonymous()) {
switch($event->get_arg(0)) { switch($event->get_arg(0)) {
case "read": case "read":
@ -100,8 +111,9 @@ class PM implements Extension {
} }
} }
} }
}
if($event instanceof SendPMEvent) { public function onSendPM($event) {
$database->execute(" $database->execute("
INSERT INTO private_message( INSERT INTO private_message(
from_id, from_ip, to_id, from_id, from_ip, to_id,
@ -112,29 +124,7 @@ class PM implements Extension {
); );
log_info("pm", "Sent PM to User #$to_id"); log_info("pm", "Sent PM to User #$to_id");
} }
}
protected function install() {
global $config, $database;
// shortcut to latest
if($config->get_int("pm_version") < 1) {
$database->create_table("private_message", "
id SCORE_AIPK,
from_id INTEGER NOT NULL,
from_ip SCORE_INET NOT NULL,
to_id INTEGER NOT NULL,
sent_date DATETIME NOT NULL,
subject VARCHAR(64) NOT NULL,
message TEXT NOT NULL,
is_read SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
INDEX (to_id)
");
$config->set_int("pm_version", 1);
}
log_info("pm", "extension installed");
}
private function get_pms(User $user) { private function get_pms(User $user) {
global $database; global $database;
@ -147,5 +137,4 @@ class PM implements Extension {
", array($user->id)); ", array($user->id));
} }
} }
add_event_listener(new PM());
?> ?>

View File

@ -6,29 +6,18 @@
* Description: Self explanitory * Description: Self explanitory
*/ */
class RSS_Comments implements Extension { class RSS_Comments extends SimpleExtension {
// event handling {{{ public function onPostListBuilding($event) {
public function receive_event(Event $event) { global $config, $page;
if($event instanceof PostListBuildingEvent) {
global $page;
global $config;
$title = $config->get_string('title'); $title = $config->get_string('title');
$page->add_header("<link rel=\"alternate\" type=\"application/rss+xml\" ". $page->add_header("<link rel=\"alternate\" type=\"application/rss+xml\" ".
"title=\"$title - Comments\" href=\"".make_link("rss/comments")."\" />"); "title=\"$title - Comments\" href=\"".make_link("rss/comments")."\" />");
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("rss")) {
if($event->get_arg(0) == 'comments') { public function onPageRequest($event) {
global $database; global $config, $database, $page;
$this->do_rss($database); if($event->page_matches("rss/comments")) {
}
}
}
// }}}
// output {{{
private function do_rss($database) {
global $page;
global $config;
$page->set_mode("data"); $page->set_mode("data");
$page->set_type("application/rss+xml"); $page->set_type("application/rss+xml");
@ -83,7 +72,6 @@ class RSS_Comments implements Extension {
EOD; EOD;
$page->set_data($xml); $page->set_data($xml);
} }
// }}}
} }
add_event_listener(new RSS_Comments()); }
?> ?>

View File

@ -6,12 +6,9 @@
* Description: Self explanitory * Description: Self explanitory
*/ */
class RSS_Images implements Extension { class RSS_Images extends SimpleExtension {
// event handling {{{ public function onPostListBuilding($event) {
public function receive_event(Event $event) { global $config, $page;
global $config, $database, $page, $user;
if($event instanceof PostListBuildingEvent) {
$title = $config->get_string('title'); $title = $config->get_string('title');
if(count($event->search_terms) > 0) { if(count($event->search_terms) > 0) {
@ -25,7 +22,8 @@ class RSS_Images implements Extension {
} }
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("rss/images")) { public function onPageRequest($event) {
if($event->page_matches("rss/images")) {
$page_number = 0; $page_number = 0;
$search_terms = array(); $search_terms = array();
@ -46,8 +44,8 @@ class RSS_Images implements Extension {
$this->do_rss($images, $search_terms, $page_number); $this->do_rss($images, $search_terms, $page_number);
} }
} }
// }}}
// output {{{
private function do_rss($images, $search_terms, $page_number) { private function do_rss($images, $search_terms, $page_number) {
global $page; global $page;
global $config; global $config;
@ -113,7 +111,5 @@ class RSS_Images implements Extension {
</rss>"; </rss>";
$page->set_data($xml); $page->set_data($xml);
} }
// }}}
} }
add_event_listener(new RSS_Images());
?> ?>

View File

@ -21,14 +21,10 @@ class TestFinder extends TestSuite {
} }
} }
class SimpleSCoreTest implements Extension { class SimpleSCoreTest extends SimpleExtension {
var $theme; public function onPageRequest($event) {
global $page;
public function receive_event(Event $event) { if($event->page_matches("test")) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("test")) {
$page->set_title("Test Results"); $page->set_title("Test Results");
$page->set_heading("Test Results"); $page->set_heading("Test Results");
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
@ -36,13 +32,13 @@ class SimpleSCoreTest implements Extension {
$all = new TestFinder($event->get_arg(0)); $all = new TestFinder($event->get_arg(0));
$all->run(new SCoreReporter($page)); $all->run(new SCoreReporter($page));
} }
}
if($event instanceof UserBlockBuildingEvent) { public function onUserBlockBuilding($event) {
global $user;
if($user->is_admin()) { if($user->is_admin()) {
$event->add_link("Run Tests", make_link("test/all")); $event->add_link("Run Tests", make_link("test/all"));
} }
} }
} }
}
add_event_listener(new SimpleSCoreTest());
?> ?>

View File

@ -6,24 +6,16 @@
* Description: Scales down too-large images using browser based scaling * Description: Scales down too-large images using browser based scaling
*/ */
class Zoom implements Extension { class Zoom extends SimpleExtension {
var $theme; public function onDisplayingImage($event) {
global $config, $page;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if($this->theme == null) $this->theme = get_theme_object($this);
if($event instanceof DisplayingImageEvent) {
$this->theme->display_zoomer($page, $event->image, $config->get_bool("image_zoom", false)); $this->theme->display_zoomer($page, $event->image, $config->get_bool("image_zoom", false));
} }
if($event instanceof SetupBuildingEvent) { public function onSetupBuilding($event) {
$sb = new SetupBlock("Image Zoom"); $sb = new SetupBlock("Image Zoom");
$sb->add_bool_option("image_zoom", "Zoom by default: "); $sb->add_bool_option("image_zoom", "Zoom by default: ");
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
} }
}
add_event_listener(new Zoom());
?> ?>

View File

@ -1,14 +1,7 @@
<?php <?php
class BBCode implements Extension { class BBCode extends FormatterExtension {
public function receive_event(Event $event) { public function format($text) {
if($event instanceof TextFormattingEvent) {
$event->formatted = $this->bbcode_to_html($event->formatted);
$event->stripped = $this->bbcode_to_text($event->stripped);
}
}
private function bbcode_to_html($text) {
$text = $this->extract_code($text); $text = $this->extract_code($text);
$text = preg_replace("/\[b\](.*?)\[\/b\]/s", "<b>\\1</b>", $text); $text = preg_replace("/\[b\](.*?)\[\/b\]/s", "<b>\\1</b>", $text);
$text = preg_replace("/\[i\](.*?)\[\/i\]/s", "<i>\\1</i>", $text); $text = preg_replace("/\[i\](.*?)\[\/i\]/s", "<i>\\1</i>", $text);
@ -42,7 +35,7 @@ class BBCode implements Extension {
return $text; return $text;
} }
private function bbcode_to_text($text) { public function strip($text) {
$text = preg_replace("/\[b\](.*?)\[\/b\]/s", "\\1", $text); $text = preg_replace("/\[b\](.*?)\[\/b\]/s", "\\1", $text);
$text = preg_replace("/\[i\](.*?)\[\/i\]/s", "\\1", $text); $text = preg_replace("/\[i\](.*?)\[\/i\]/s", "\\1", $text);
$text = preg_replace("/\[u\](.*?)\[\/u\]/s", "\\1", $text); $text = preg_replace("/\[u\](.*?)\[\/u\]/s", "\\1", $text);
@ -65,6 +58,7 @@ class BBCode implements Extension {
return $text; return $text;
} }
private function filter_spoiler($text) { private function filter_spoiler($text) {
return str_replace( return str_replace(
array("[spoiler]","[/spoiler]"), array("[spoiler]","[/spoiler]"),

View File

@ -68,14 +68,10 @@ class ExtensionInfo { // {{{
} }
} // }}} } // }}}
class ExtManager implements Extension { class ExtManager extends SimpleExtension {
var $theme; public function onPageRequest($event) {
global $page, $user;
public function receive_event(Event $event) { if($event->page_matches("ext_manager")) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("ext_manager")) {
if($user->is_admin()) { if($user->is_admin()) {
if($event->get_arg(0) == "set") { if($event->get_arg(0) == "set") {
if(is_writable("ext")) { if(is_writable("ext")) {
@ -97,18 +93,20 @@ class ExtManager implements Extension {
} }
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("ext_doc")) { if($event->page_matches("ext_doc")) {
$ext = $event->get_arg(0); $ext = $event->get_arg(0);
$info = new ExtensionInfo("contrib/$ext/main.php"); $info = new ExtensionInfo("contrib/$ext/main.php");
$this->theme->display_doc($page, $info); $this->theme->display_doc($page, $info);
} }
}
if($event instanceof UserBlockBuildingEvent) { public function onUserBlockBuilding($event) {
global $user;
if($user->is_admin()) { if($user->is_admin()) {
$event->add_link("Extension Manager", make_link("ext_manager")); $event->add_link("Extension Manager", make_link("ext_manager"));
} }
} }
}
private function get_extensions() { private function get_extensions() {
$extensions = array(); $extensions = array();
@ -152,5 +150,4 @@ class ExtManager implements Extension {
} }
} }
} }
add_event_listener(new ExtManager());
?> ?>

View File

@ -74,10 +74,8 @@ class ParseLinkTemplateEvent extends Event {
* A class to handle adding / getting / removing image * A class to handle adding / getting / removing image
* files from the disk * files from the disk
*/ */
class ImageIO implements Extension { class ImageIO extends SimpleExtension {
// event handling {{{ public function onInitExt($event) {
public function receive_event(Event $event) {
if($event instanceof InitExtEvent) {
global $config; global $config;
$config->set_default_int('thumb_width', 192); $config->set_default_int('thumb_width', 192);
$config->set_default_int('thumb_height', 192); $config->set_default_int('thumb_height', 192);
@ -90,7 +88,7 @@ class ImageIO implements Extension {
$config->set_default_string('upload_collision_handler', 'error'); $config->set_default_string('upload_collision_handler', 'error');
} }
if($event instanceof PageRequestEvent) { public function onPageRequest($event) {
$num = $event->get_arg(0); $num = $event->get_arg(0);
$matches = array(); $matches = array();
if(!is_null($num) && preg_match("/(\d+)/", $num, $matches)) { if(!is_null($num) && preg_match("/(\d+)/", $num, $matches)) {
@ -105,16 +103,16 @@ class ImageIO implements Extension {
} }
} }
if($event instanceof ImageAdditionEvent) { public function onImageAddition($event) {
$error = $this->add_image($event->image); $error = $this->add_image($event->image);
if(!empty($error)) throw new UploadException($error); if(!empty($error)) throw new UploadException($error);
} }
if($event instanceof ImageDeletionEvent) { public function onImageDeletion($event) {
$event->image->delete(); $event->image->delete();
} }
if($event instanceof SetupBuildingEvent) { public function onSetupBuilding($event) {
$sb = new SetupBlock("Image Options"); $sb = new SetupBlock("Image Options");
$sb->position = 30; $sb->position = 30;
// advanced only // advanced only
@ -143,8 +141,8 @@ class ImageIO implements Extension {
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
}
// }}}
// add image {{{ // add image {{{
private function add_image($image) { private function add_image($image) {
global $page; global $page;
@ -247,5 +245,4 @@ class ImageIO implements Extension {
} }
// }}} // }}}
} }
add_event_listener(new ImageIO());
?> ?>

View File

@ -34,20 +34,17 @@ class PostListBuildingEvent extends Event {
} }
} }
class Index implements Extension { class Index extends SimpleExtension {
var $theme; public function onInitExt($event) {
global $config;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
$config->set_default_int("index_width", 3); $config->set_default_int("index_width", 3);
$config->set_default_int("index_height", 4); $config->set_default_int("index_height", 4);
$config->set_default_bool("index_tips", true); $config->set_default_bool("index_tips", true);
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("post/list")) { public function onPageRequest($event) {
global $config, $database, $page, $user;
if($event->page_matches("post/list")) {
if(isset($_GET['search'])) { if(isset($_GET['search'])) {
$search = url_escape(trim($_GET['search'])); $search = url_escape(trim($_GET['search']));
if(empty($search)) { if(empty($search)) {
@ -92,8 +89,9 @@ class Index implements Extension {
$this->theme->display_page($page, $images); $this->theme->display_page($page, $images);
} }
} }
}
if($event instanceof SetupBuildingEvent) { public function onSetupBuilding($event) {
$sb = new SetupBlock("Index Options"); $sb = new SetupBlock("Index Options");
$sb->position = 20; $sb->position = 20;
@ -106,7 +104,7 @@ class Index implements Extension {
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
if($event instanceof SearchTermParseEvent) { public function onSearchTermParse($event) {
$matches = array(); $matches = array();
if(preg_match("/^size(<|>|<=|>=|=)(\d+)x(\d+)$/", $event->term, $matches)) { if(preg_match("/^size(<|>|<=|>=|=)(\d+)x(\d+)$/", $event->term, $matches)) {
$cmp = $matches[1]; $cmp = $matches[1];
@ -142,6 +140,4 @@ class Index implements Extension {
} }
} }
} }
}
add_event_listener(new Index());
?> ?>

View File

@ -1,9 +1,7 @@
<?php <?php
class LoadExtData implements Extension { class LoadExtData extends SimpleExtension {
public function receive_event(Event $event) { public function onPageRequest($event) {
if($event instanceof PageRequestEvent) { global $page;
global $page, $config;
$data_href = get_base_href(); $data_href = get_base_href();
$css_files = glob("ext/*/style.css"); $css_files = glob("ext/*/style.css");
@ -21,6 +19,4 @@ class LoadExtData implements Extension {
} }
} }
} }
}
add_event_listener(new LoadExtData());
?> ?>

View File

@ -135,14 +135,9 @@ class SetupBlock extends Block {
} }
// }}} // }}}
class Setup implements Extension { class Setup extends SimpleExtension {
var $theme; public function onInitExt($event) {
global $config;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
$config->set_default_string("title", "Shimmie"); $config->set_default_string("title", "Shimmie");
$config->set_default_string("front_page", "post/list"); $config->set_default_string("front_page", "post/list");
$config->set_default_string("main_page", "post/list"); $config->set_default_string("main_page", "post/list");
@ -150,12 +145,15 @@ class Setup implements Extension {
$config->set_default_string("theme", "default"); $config->set_default_string("theme", "default");
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("nicetest")) { public function onPageRequest($event) {
global $config, $page, $user;
if($event->page_matches("nicetest")) {
$page->set_mode("data"); $page->set_mode("data");
$page->set_data("ok"); $page->set_data("ok");
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("setup")) { if($event->page_matches("setup")) {
if(!$user->is_admin()) { if(!$user->is_admin()) {
$this->theme->display_permission_denied($page); $this->theme->display_permission_denied($page);
} }
@ -177,8 +175,9 @@ class Setup implements Extension {
} }
} }
} }
}
if($event instanceof SetupBuildingEvent) { public function onSetupBuilding($event) {
$themes = array(); $themes = array();
foreach(glob("themes/*") as $theme_dirname) { foreach(glob("themes/*") as $theme_dirname) {
$name = str_replace("themes/", "", $theme_dirname); $name = str_replace("themes/", "", $theme_dirname);
@ -229,7 +228,7 @@ class Setup implements Extension {
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
if($event instanceof ConfigSaveEvent) { public function onConfigSave($event) {
global $config; global $config;
foreach($_POST as $_name => $junk) { foreach($_POST as $_name => $junk) {
if(substr($_name, 0, 6) == "_type_") { if(substr($_name, 0, 6) == "_type_") {
@ -245,12 +244,11 @@ class Setup implements Extension {
} }
} }
if($event instanceof UserBlockBuildingEvent) { public function onUserBlockBuilding($event) {
global $user;
if($user->is_admin()) { if($user->is_admin()) {
$event->add_link("Board Config", make_link("setup")); $event->add_link("Board Config", make_link("setup"));
} }
} }
} }
}
add_event_listener(new Setup());
?> ?>

View File

@ -101,6 +101,7 @@ class TagEdit implements Extension {
} }
} }
private function can_tag() { private function can_tag() {
global $config, $user; global $config, $user;
return $config->get_bool("tag_edit_anon") || !$user->is_anonymous(); return $config->get_bool("tag_edit_anon") || !$user->is_anonymous();

View File

@ -59,6 +59,7 @@ class ImageAdminBlockBuildingEvent extends Event {
$this->parts[$position] = $html; $this->parts[$position] = $html;
} }
} }
class ViewImage implements Extension { class ViewImage implements Extension {
var $theme; var $theme;