From 5ab092946ab3863d1ecd0c2a25fb4e55f266d0eb Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 11 May 2009 14:09:24 -0700 Subject: [PATCH] make things use SimpleExtension --- contrib/bulk_add/main.php | 27 +++--- contrib/handle_archive/main.php | 30 +++---- contrib/handle_flash/main.php | 21 ++--- contrib/handle_ico/main.php | 33 +++---- contrib/home/main.php | 66 ++++++-------- contrib/news/main.php | 29 +++--- contrib/pm/main.php | 115 +++++++++++------------- contrib/rss_comments/main.php | 124 ++++++++++++------------- contrib/rss_images/main.php | 38 ++++---- contrib/simpletest/main.php | 22 ++--- contrib/zoom/main.php | 26 ++---- ext/bbcode/main.php | 14 +-- ext/ext_manager/main.php | 25 +++--- ext/image/main.php | 129 +++++++++++++------------- ext/index/main.php | 110 +++++++++++------------ ext/load_ext_data/main.php | 30 +++---- ext/setup/main.php | 154 ++++++++++++++++---------------- ext/tag_edit/main.php | 1 + ext/view/main.php | 1 + 19 files changed, 457 insertions(+), 538 deletions(-) diff --git a/contrib/bulk_add/main.php b/contrib/bulk_add/main.php index 2dc84e6f..5ea1651f 100644 --- a/contrib/bulk_add/main.php +++ b/contrib/bulk_add/main.php @@ -13,27 +13,25 @@ * tagged "holiday 2008") */ -class BulkAdd implements Extension { - var $theme; - - public function receive_event(Event $event) { - if(is_null($this->theme)) $this->theme = get_theme_object($this); - - if(($event instanceof PageRequestEvent) && $event->page_matches("bulk_add")) { - if($event->user->is_admin() && isset($_POST['dir'])) { +class BulkAdd extends SimpleExtension { + public function onPageRequest($event) { + global $page, $user; + if($event->page_matches("bulk_add")) { + if($user->is_admin() && isset($_POST['dir'])) { set_time_limit(0); $this->add_dir($_POST['dir']); - $this->theme->display_upload_results($event->page); + $this->theme->display_upload_results($page); } } - - if($event instanceof AdminBuildingEvent) { - global $page; - $this->theme->display_admin_block($page); - } } + public function onAdminBuilding($event) { + global $page; + $this->theme->display_admin_block($page); + } + + private function add_image($tmpname, $filename, $tags) { if(file_exists($tmpname)) { global $user; @@ -97,5 +95,4 @@ class BulkAdd implements Extension { } } } -add_event_listener(new BulkAdd()); ?> diff --git a/contrib/handle_archive/main.php b/contrib/handle_archive/main.php index b5baf990..72fa640b 100644 --- a/contrib/handle_archive/main.php +++ b/contrib/handle_archive/main.php @@ -10,22 +10,22 @@ *
7-zip: 7zr x -o"%d" "%f" */ -class ArchiveFileHandler implements Extension { - public function receive_event(Event $event) { - if($event instanceof InitExtEvent) { - global $config; - $config->set_default_string('archive_extract_command', 'unzip -d "%d" "%f"'); - } +class ArchiveFileHandler extends SimpleExtension { + public function onInitExt($event) { + global $config; + $config->set_default_string('archive_extract_command', 'unzip -d "%d" "%f"'); + } - if($event instanceof SetupBuildingEvent) { - $sb = new SetupBlock("Archive Handler Options"); - $sb->add_text_option("archive_tmp_dir", "Temporary folder: "); - $sb->add_text_option("archive_extract_command", "
Extraction command: "); - $sb->add_label("
%f for archive, %d for temporary directory"); - $event->panel->add_block($sb); - } + public function onSetupBuilding($event) { + $sb = new SetupBlock("Archive Handler Options"); + $sb->add_text_option("archive_tmp_dir", "Temporary folder: "); + $sb->add_text_option("archive_extract_command", "
Extraction command: "); + $sb->add_label("
%f for archive, %d for temporary directory"); + $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; $tmp = sys_get_temp_dir(); $tmpdir = "$tmp/shimmie-archive-{$event->hash}"; @@ -38,6 +38,7 @@ class ArchiveFileHandler implements Extension { } } + private function supported_ext($ext) { $exts = array("zip"); return array_contains($exts, strtolower($ext)); @@ -100,5 +101,4 @@ class ArchiveFileHandler implements Extension { // $this->theme->add_status("Adding $subdir", $list); } } -add_event_listener(new ArchiveFileHandler()); ?> diff --git a/contrib/handle_flash/main.php b/contrib/handle_flash/main.php index 408b3578..db1b9e61 100644 --- a/contrib/handle_flash/main.php +++ b/contrib/handle_flash/main.php @@ -5,13 +5,9 @@ * Description: Handle Flash files */ -class FlashFileHandler 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)) { +class FlashFileHandler extends SimpleExtension { + public function onDataUpload($event) { + if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { $hash = $event->hash; $ha = substr($hash, 0, 2); if(!move_upload_to_archive($event)) return; @@ -24,19 +20,25 @@ class FlashFileHandler implements Extension { } 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; $ha = substr($hash, 0, 2); // FIXME: scale image, as not all boards use 192x192 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); } } + private function supported_ext($ext) { $exts = array("swf"); return array_contains($exts, strtolower($ext)); @@ -127,5 +129,4 @@ class FlashFileHandler implements Extension { return true; } } -add_event_listener(new FlashFileHandler()); ?> diff --git a/contrib/handle_ico/main.php b/contrib/handle_ico/main.php index 8746a212..67bab3c0 100644 --- a/contrib/handle_ico/main.php +++ b/contrib/handle_ico/main.php @@ -5,13 +5,9 @@ * Description: Handle windows icons */ -class IcoFileHandler 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)) { +class IcoFileHandler extends SimpleExtension { + public function onDataUpload($event) { + if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { $hash = $event->hash; $ha = substr($hash, 0, 2); if(!move_upload_to_archive($event)) return; @@ -22,29 +18,35 @@ class IcoFileHandler implements Extension { } 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); } + } - if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) { + public function onDisplayingImage($event) { + if($this->supported_ext($event->image->ext)) { $this->theme->display_image($event->page, $event->image); } + } - if(($event instanceof PageRequestEvent) && $event->page_matches("get_ico")) { - global $config; - global $database; + public function onPageRequest($event) { + global $config, $database; + if($event->page_matches("get_ico")) { $id = int_escape($event->get_arg(0)); $image = Image::by_id($id); $hash = $image->hash; $ha = substr($hash, 0, 2); - $event->page->set_type("image/x-icon"); - $event->page->set_mode("data"); - $event->page->set_data(file_get_contents("images/$ha/$hash")); + $page->set_type("image/x-icon"); + $page->set_mode("data"); + $page->set_data(file_get_contents("images/$ha/$hash")); } } + private function supported_ext($ext) { $exts = array("ico", "ani", "cur"); return array_contains($exts, strtolower($ext)); @@ -106,5 +108,4 @@ class IcoFileHandler implements Extension { return true; } } -add_event_listener(new IcoFileHandler()); ?> diff --git a/contrib/home/main.php b/contrib/home/main.php index bfc9da91..9e383f95 100644 --- a/contrib/home/main.php +++ b/contrib/home/main.php @@ -14,35 +14,37 @@ * alongside the default choices. */ -class Home implements Extension { - var $theme; +class Home extends SimpleExtension { + 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) { - global $config, $database, $page, $user; - if(is_null($this->theme)) $this->theme = get_theme_object($this); + $body = $this->get_body(); - if(($event instanceof PageRequestEvent) && $event->page_matches("home")) - { - // this is a request to display this page so output the page. - $this->output_pages($page); - } - if($event instanceof SetupBuildingEvent) - { - $counters = array(); - foreach(glob("ext/home/counters/*") as $counter_dirname) { - $name = str_replace("ext/home/counters/", "", $counter_dirname); - $counters[ucfirst($name)] = $name; - } - - $sb = new SetupBlock("Home Page"); - $sb->add_label("Page Links - Example: [$"."base/index|Posts]"); - $sb->add_longtext_option("home_links", "
"); - $sb->add_choice_option("home_counter", $counters, "
Counter: "); - $sb->add_label("
Note: page accessed via /home"); - $event->panel->add_block($sb); + $this->theme->display_page($page, $sitename, $data_href, $theme_name, $body); } } + public function onSetupBuilding($event) { + $counters = array(); + foreach(glob("ext/home/counters/*") as $counter_dirname) { + $name = str_replace("ext/home/counters/", "", $counter_dirname); + $counters[ucfirst($name)] = $name; + } + + $sb = new SetupBlock("Home Page"); + $sb->add_label("Page Links - Example: [$"."base/index|Posts]"); + $sb->add_longtext_option("home_links", "
"); + $sb->add_choice_option("home_counter", $counters, "
Counter: "); + $sb->add_label("
Note: page accessed via /home"); + $event->panel->add_block($sb); + } + + private function get_body() { // returns just the contents of the body @@ -75,21 +77,5 @@ class Home implements Extension { 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()); ?> diff --git a/contrib/news/main.php b/contrib/news/main.php index cd1a7f40..16eefa73 100644 --- a/contrib/news/main.php +++ b/contrib/news/main.php @@ -8,25 +8,18 @@ * Any HTML is allowed */ -class News implements Extension { - var $theme; - - 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) { - $this->theme->display_news($page, $config->get_string("news_text")); - } - } - - if($event instanceof SetupBuildingEvent) { - $sb = new SetupBlock("News"); - $sb->add_longtext_option("news_text"); - $event->panel->add_block($sb); +class News extends SimpleExtension { + public function onPostListBuilding($event) { + global $config, $page; + if(strlen($config->get_string("news_text")) > 0) { + $this->theme->display_news($page, $config->get_string("news_text")); } } + + public function onSetupBuilding($event) { + $sb = new SetupBlock("News"); + $sb->add_longtext_option("news_text"); + $event->panel->add_block($sb); + } } -add_event_listener(new News()); ?> diff --git a/contrib/pm/main.php b/contrib/pm/main.php index 2db0f368..5a176a76 100644 --- a/contrib/pm/main.php +++ b/contrib/pm/main.php @@ -14,47 +14,58 @@ class SendPMEvent extends Event { public function __construct($from_id, $from_ip, $to_id, $subject, $message) { $this->from_id = $from_id; $this->from_ip = $from_ip; - $this->to_id = $to_id; + $this->to_id = $to_id; $this->subject = $subject; $this->message = $message; } } -class PM implements Extension { - var $theme; +class PM extends SimpleExtension { + public function onInitExt($event) { + global $config, $database; - public function receive_event(Event $event) { - global $config, $database, $page, $user; + // 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"); + } + } - if(is_null($this->theme)) $this->theme = get_theme_object($this); + /* + public function onUserBlockBuilding($event) { + global $user; + if(!$user->is_anonymous()) { + $event->add_link("Private Messages", make_link("pm")); + } + } + */ - if($event instanceof InitExtEvent) { - if($config->get_int("pm_version") < 1) { - $this->install(); + public function onUserPageBuilding($event) { + global $page, $user; + $duser = $event->display_user; + if(!$user->is_anonymous() && !$duser->is_anonymous()) { + if(($user->id == $duser->id) || $user->is_admin()) { + $this->theme->display_pms($page, $this->get_pms($duser)); + } + if($user->id != $duser->id) { + $this->theme->display_composer($page, $user, $duser); } } + } - /* - if($event instanceof UserBlockBuildingEvent) { - if(!$user->is_anonymous()) { - $event->add_link("Private Messages", make_link("pm")); - } - } - */ - - if($event instanceof UserPageBuildingEvent) { - $duser = $event->display_user; - if(!$user->is_anonymous() && !$duser->is_anonymous()) { - if(($user->id == $duser->id) || $user->is_admin()) { - $this->theme->display_pms($page, $this->get_pms($duser)); - } - if($user->id != $duser->id) { - $this->theme->display_composer($page, $user, $duser); - } - } - } - - if(($event instanceof PageRequestEvent) && $event->page_matches("pm")) { + public function onPageRequest($event) { + if($event->page_matches("pm")) { if(!$user->is_anonymous()) { switch($event->get_arg(0)) { case "read": @@ -100,42 +111,21 @@ class PM implements Extension { } } } - - if($event instanceof SendPMEvent) { - $database->execute(" - INSERT INTO private_message( - from_id, from_ip, to_id, - sent_date, subject, message) - VALUES(?, ?, ?, now(), ?, ?)", - array($event->from_id, $event->from_ip, - $event->to_id, $event->subject, $event->message) - ); - 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"); + public function onSendPM($event) { + $database->execute(" + INSERT INTO private_message( + from_id, from_ip, to_id, + sent_date, subject, message) + VALUES(?, ?, ?, now(), ?, ?)", + array($event->from_id, $event->from_ip, + $event->to_id, $event->subject, $event->message) + ); + log_info("pm", "Sent PM to User #$to_id"); } + private function get_pms(User $user) { global $database; @@ -147,5 +137,4 @@ class PM implements Extension { ", array($user->id)); } } -add_event_listener(new PM()); ?> diff --git a/contrib/rss_comments/main.php b/contrib/rss_comments/main.php index 52fbead3..bb261a3b 100644 --- a/contrib/rss_comments/main.php +++ b/contrib/rss_comments/main.php @@ -6,74 +6,63 @@ * Description: Self explanitory */ -class RSS_Comments implements Extension { -// event handling {{{ - public function receive_event(Event $event) { - if($event instanceof PostListBuildingEvent) { - global $page; - global $config; - $title = $config->get_string('title'); - - $page->add_header(""); - } - if(($event instanceof PageRequestEvent) && $event->page_matches("rss")) { - if($event->get_arg(0) == 'comments') { - global $database; - $this->do_rss($database); - } - } - } -// }}} -// output {{{ - private function do_rss($database) { - global $page; - global $config; - $page->set_mode("data"); - $page->set_type("application/rss+xml"); - - $comments = $database->get_all(" - SELECT - users.id as user_id, users.name as user_name, - comments.comment as comment, comments.id as comment_id, - comments.image_id as image_id, comments.owner_ip as poster_ip, - UNIX_TIMESTAMP(posted) AS posted_timestamp - FROM comments - LEFT JOIN users ON comments.owner_id=users.id - ORDER BY comments.id DESC - LIMIT 10 - "); - - $data = ""; - foreach($comments as $comment) { - $image_id = $comment['image_id']; - $comment_id = $comment['comment_id']; - $link = make_link("post/view/$image_id"); - $owner = html_escape($comment['user_name']); - $posted = date(DATE_RSS, $comment['posted_timestamp']); - $comment = html_escape($comment['comment']); - $content = html_escape("$owner: $comment"); - - $data .= " - - $owner comments on $image_id - $link - $comment_id - $posted - $content - - "; - } - +class RSS_Comments extends SimpleExtension { + public function onPostListBuilding($event) { + global $config, $page; $title = $config->get_string('title'); - $base_href = $config->get_string('base_href'); - $version = $config->get_string('version'); - $xml = <<add_header(""); + } + + public function onPageRequest($event) { + global $config, $database, $page; + if($event->page_matches("rss/comments")) { + $page->set_mode("data"); + $page->set_type("application/rss+xml"); + + $comments = $database->get_all(" + SELECT + users.id as user_id, users.name as user_name, + comments.comment as comment, comments.id as comment_id, + comments.image_id as image_id, comments.owner_ip as poster_ip, + UNIX_TIMESTAMP(posted) AS posted_timestamp + FROM comments + LEFT JOIN users ON comments.owner_id=users.id + ORDER BY comments.id DESC + LIMIT 10 + "); + + $data = ""; + foreach($comments as $comment) { + $image_id = $comment['image_id']; + $comment_id = $comment['comment_id']; + $link = make_link("post/view/$image_id"); + $owner = html_escape($comment['user_name']); + $posted = date(DATE_RSS, $comment['posted_timestamp']); + $comment = html_escape($comment['comment']); + $content = html_escape("$owner: $comment"); + + $data .= " + + $owner comments on $image_id + $link + $comment_id + $posted + $content + + "; + } + + $title = $config->get_string('title'); + $base_href = $config->get_string('base_href'); + $version = $config->get_string('version'); + $xml = << - - $title - The latest comments on the image board + + $title + The latest comments on the image board $base_href $version (c) 2007 Shish @@ -81,9 +70,8 @@ class RSS_Comments implements Extension { EOD; - $page->set_data($xml); + $page->set_data($xml); + } } -// }}} } -add_event_listener(new RSS_Comments()); ?> diff --git a/contrib/rss_images/main.php b/contrib/rss_images/main.php index cdfb9917..879e70a7 100644 --- a/contrib/rss_images/main.php +++ b/contrib/rss_images/main.php @@ -6,26 +6,24 @@ * Description: Self explanitory */ -class RSS_Images implements Extension { -// event handling {{{ - public function receive_event(Event $event) { - global $config, $database, $page, $user; +class RSS_Images extends SimpleExtension { + public function onPostListBuilding($event) { + global $config, $page; + $title = $config->get_string('title'); - if($event instanceof PostListBuildingEvent) { - $title = $config->get_string('title'); - - if(count($event->search_terms) > 0) { - $search = implode(' ', $event->search_terms); - $page->add_header(""); - } - else { - $page->add_header(""); - } + if(count($event->search_terms) > 0) { + $search = implode(' ', $event->search_terms); + $page->add_header(""); } + else { + $page->add_header(""); + } + } - if(($event instanceof PageRequestEvent) && $event->page_matches("rss/images")) { + public function onPageRequest($event) { + if($event->page_matches("rss/images")) { $page_number = 0; $search_terms = array(); @@ -46,8 +44,8 @@ class RSS_Images implements Extension { $this->do_rss($images, $search_terms, $page_number); } } -// }}} -// output {{{ + + private function do_rss($images, $search_terms, $page_number) { global $page; global $config; @@ -113,7 +111,5 @@ class RSS_Images implements Extension { "; $page->set_data($xml); } -// }}} } -add_event_listener(new RSS_Images()); ?> diff --git a/contrib/simpletest/main.php b/contrib/simpletest/main.php index 1680b3cd..1a5916db 100644 --- a/contrib/simpletest/main.php +++ b/contrib/simpletest/main.php @@ -21,14 +21,10 @@ class TestFinder extends TestSuite { } } -class SimpleSCoreTest implements Extension { - var $theme; - - 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 PageRequestEvent) && $event->page_matches("test")) { +class SimpleSCoreTest extends SimpleExtension { + public function onPageRequest($event) { + global $page; + if($event->page_matches("test")) { $page->set_title("Test Results"); $page->set_heading("Test Results"); $page->add_block(new NavBlock()); @@ -36,13 +32,13 @@ class SimpleSCoreTest implements Extension { $all = new TestFinder($event->get_arg(0)); $all->run(new SCoreReporter($page)); } + } - if($event instanceof UserBlockBuildingEvent) { - if($user->is_admin()) { - $event->add_link("Run Tests", make_link("test/all")); - } + public function onUserBlockBuilding($event) { + global $user; + if($user->is_admin()) { + $event->add_link("Run Tests", make_link("test/all")); } } } -add_event_listener(new SimpleSCoreTest()); ?> diff --git a/contrib/zoom/main.php b/contrib/zoom/main.php index dedabad8..c365b68c 100644 --- a/contrib/zoom/main.php +++ b/contrib/zoom/main.php @@ -6,24 +6,16 @@ * Description: Scales down too-large images using browser based scaling */ -class Zoom implements Extension { - var $theme; - - 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)); - } - - if($event instanceof SetupBuildingEvent) { - $sb = new SetupBlock("Image Zoom"); - $sb->add_bool_option("image_zoom", "Zoom by default: "); - $event->panel->add_block($sb); - } +class Zoom extends SimpleExtension { + public function onDisplayingImage($event) { + global $config, $page; + $this->theme->display_zoomer($page, $event->image, $config->get_bool("image_zoom", false)); } + public function onSetupBuilding($event) { + $sb = new SetupBlock("Image Zoom"); + $sb->add_bool_option("image_zoom", "Zoom by default: "); + $event->panel->add_block($sb); + } } -add_event_listener(new Zoom()); ?> diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php index 4030d216..ae4b9ca8 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -1,14 +1,7 @@ formatted = $this->bbcode_to_html($event->formatted); - $event->stripped = $this->bbcode_to_text($event->stripped); - } - } - - private function bbcode_to_html($text) { +class BBCode extends FormatterExtension { + public function format($text) { $text = $this->extract_code($text); $text = preg_replace("/\[b\](.*?)\[\/b\]/s", "\\1", $text); $text = preg_replace("/\[i\](.*?)\[\/i\]/s", "\\1", $text); @@ -42,7 +35,7 @@ class BBCode implements Extension { return $text; } - private function bbcode_to_text($text) { + public function strip($text) { $text = preg_replace("/\[b\](.*?)\[\/b\]/s", "\\1", $text); $text = preg_replace("/\[i\](.*?)\[\/i\]/s", "\\1", $text); $text = preg_replace("/\[u\](.*?)\[\/u\]/s", "\\1", $text); @@ -65,6 +58,7 @@ class BBCode implements Extension { return $text; } + private function filter_spoiler($text) { return str_replace( array("[spoiler]","[/spoiler]"), diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php index db5ce469..47aa618f 100644 --- a/ext/ext_manager/main.php +++ b/ext/ext_manager/main.php @@ -68,14 +68,10 @@ class ExtensionInfo { // {{{ } } // }}} -class ExtManager implements Extension { - var $theme; - - 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 PageRequestEvent) && $event->page_matches("ext_manager")) { +class ExtManager extends SimpleExtension { + public function onPageRequest($event) { + global $page, $user; + if($event->page_matches("ext_manager")) { if($user->is_admin()) { if($event->get_arg(0) == "set") { if(is_writable("ext")) { @@ -97,19 +93,21 @@ class ExtManager implements Extension { } } - if(($event instanceof PageRequestEvent) && $event->page_matches("ext_doc")) { + if($event->page_matches("ext_doc")) { $ext = $event->get_arg(0); $info = new ExtensionInfo("contrib/$ext/main.php"); $this->theme->display_doc($page, $info); } + } - if($event instanceof UserBlockBuildingEvent) { - if($user->is_admin()) { - $event->add_link("Extension Manager", make_link("ext_manager")); - } + public function onUserBlockBuilding($event) { + global $user; + if($user->is_admin()) { + $event->add_link("Extension Manager", make_link("ext_manager")); } } + private function get_extensions() { $extensions = array(); foreach(glob("contrib/*/main.php") as $main) { @@ -152,5 +150,4 @@ class ExtManager implements Extension { } } } -add_event_listener(new ExtManager()); ?> diff --git a/ext/image/main.php b/ext/image/main.php index 90d21ccb..d5b72512 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -74,77 +74,75 @@ class ParseLinkTemplateEvent extends Event { * A class to handle adding / getting / removing image * files from the disk */ -class ImageIO implements Extension { -// event handling {{{ - public function receive_event(Event $event) { - if($event instanceof InitExtEvent) { - global $config; - $config->set_default_int('thumb_width', 192); - $config->set_default_int('thumb_height', 192); - $config->set_default_int('thumb_quality', 75); - $config->set_default_int('thumb_mem_limit', parse_shorthand_int('8MB')); +class ImageIO extends SimpleExtension { + public function onInitExt($event) { + global $config; + $config->set_default_int('thumb_width', 192); + $config->set_default_int('thumb_height', 192); + $config->set_default_int('thumb_quality', 75); + $config->set_default_int('thumb_mem_limit', parse_shorthand_int('8MB')); - $config->set_default_string('image_ilink', ''); - $config->set_default_string('image_tlink', ''); - $config->set_default_string('image_tip', '$tags // $size // $filesize'); - $config->set_default_string('upload_collision_handler', 'error'); - } + $config->set_default_string('image_ilink', ''); + $config->set_default_string('image_tlink', ''); + $config->set_default_string('image_tip', '$tags // $size // $filesize'); + $config->set_default_string('upload_collision_handler', 'error'); + } - if($event instanceof PageRequestEvent) { - $num = $event->get_arg(0); - $matches = array(); - if(!is_null($num) && preg_match("/(\d+)/", $num, $matches)) { - $num = $matches[1]; + public function onPageRequest($event) { + $num = $event->get_arg(0); + $matches = array(); + if(!is_null($num) && preg_match("/(\d+)/", $num, $matches)) { + $num = $matches[1]; - if($event->page_matches("image")) { - $this->send_file($num, "image"); - } - else if($event->page_matches("thumb")) { - $this->send_file($num, "thumb"); - } + if($event->page_matches("image")) { + $this->send_file($num, "image"); + } + else if($event->page_matches("thumb")) { + $this->send_file($num, "thumb"); } } - - if($event instanceof ImageAdditionEvent) { - $error = $this->add_image($event->image); - if(!empty($error)) throw new UploadException($error); - } - - if($event instanceof ImageDeletionEvent) { - $event->image->delete(); - } - - if($event instanceof SetupBuildingEvent) { - $sb = new SetupBlock("Image Options"); - $sb->position = 30; - // advanced only - //$sb->add_text_option("image_ilink", "Image link: "); - //$sb->add_text_option("image_tlink", "
Thumbnail link: "); - $sb->add_text_option("image_tip", "Image tooltip: "); - $sb->add_choice_option("upload_collision_handler", array('Error'=>'error', 'Merge'=>'merge'), "
Upload collision handler: "); - $event->panel->add_block($sb); - - $thumbers = array(); - $thumbers['Built-in GD'] = "gd"; - $thumbers['ImageMagick'] = "convert"; - - $sb = new SetupBlock("Thumbnailing"); - $sb->add_choice_option("thumb_engine", $thumbers, "Engine: "); - - $sb->add_label("
Size "); - $sb->add_int_option("thumb_width"); - $sb->add_label(" x "); - $sb->add_int_option("thumb_height"); - $sb->add_label(" px at "); - $sb->add_int_option("thumb_quality"); - $sb->add_label(" % quality "); - - $sb->add_shorthand_int_option("thumb_mem_limit", "
Max memory use: "); - - $event->panel->add_block($sb); - } } -// }}} + + public function onImageAddition($event) { + $error = $this->add_image($event->image); + if(!empty($error)) throw new UploadException($error); + } + + public function onImageDeletion($event) { + $event->image->delete(); + } + + public function onSetupBuilding($event) { + $sb = new SetupBlock("Image Options"); + $sb->position = 30; + // advanced only + //$sb->add_text_option("image_ilink", "Image link: "); + //$sb->add_text_option("image_tlink", "
Thumbnail link: "); + $sb->add_text_option("image_tip", "Image tooltip: "); + $sb->add_choice_option("upload_collision_handler", array('Error'=>'error', 'Merge'=>'merge'), "
Upload collision handler: "); + $event->panel->add_block($sb); + + $thumbers = array(); + $thumbers['Built-in GD'] = "gd"; + $thumbers['ImageMagick'] = "convert"; + + $sb = new SetupBlock("Thumbnailing"); + $sb->add_choice_option("thumb_engine", $thumbers, "Engine: "); + + $sb->add_label("
Size "); + $sb->add_int_option("thumb_width"); + $sb->add_label(" x "); + $sb->add_int_option("thumb_height"); + $sb->add_label(" px at "); + $sb->add_int_option("thumb_quality"); + $sb->add_label(" % quality "); + + $sb->add_shorthand_int_option("thumb_mem_limit", "
Max memory use: "); + + $event->panel->add_block($sb); + } + + // add image {{{ private function add_image($image) { global $page; @@ -247,5 +245,4 @@ class ImageIO implements Extension { } // }}} } -add_event_listener(new ImageIO()); ?> diff --git a/ext/index/main.php b/ext/index/main.php index ace8824b..9125de4f 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -34,20 +34,17 @@ class PostListBuildingEvent extends Event { } } -class Index implements Extension { - var $theme; +class Index extends SimpleExtension { + public function onInitExt($event) { + global $config; + $config->set_default_int("index_width", 3); + $config->set_default_int("index_height", 4); + $config->set_default_bool("index_tips", true); + } - public function receive_event(Event $event) { + public function onPageRequest($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_height", 4); - $config->set_default_bool("index_tips", true); - } - - if(($event instanceof PageRequestEvent) && $event->page_matches("post/list")) { + if($event->page_matches("post/list")) { if(isset($_GET['search'])) { $search = url_escape(trim($_GET['search'])); if(empty($search)) { @@ -92,56 +89,55 @@ class Index implements Extension { $this->theme->display_page($page, $images); } } + } - if($event instanceof SetupBuildingEvent) { - $sb = new SetupBlock("Index Options"); - $sb->position = 20; + public function onSetupBuilding($event) { + $sb = new SetupBlock("Index Options"); + $sb->position = 20; - $sb->add_label("Index table size "); - $sb->add_int_option("index_width"); - $sb->add_label(" x "); - $sb->add_int_option("index_height"); - $sb->add_label(" images"); + $sb->add_label("Index table size "); + $sb->add_int_option("index_width"); + $sb->add_label(" x "); + $sb->add_int_option("index_height"); + $sb->add_label(" images"); - $event->panel->add_block($sb); + $event->panel->add_block($sb); + } + + public function onSearchTermParse($event) { + $matches = array(); + if(preg_match("/^size(<|>|<=|>=|=)(\d+)x(\d+)$/", $event->term, $matches)) { + $cmp = $matches[1]; + $args = array(int_escape($matches[2]), int_escape($matches[3])); + $event->add_querylet(new Querylet("width $cmp ? AND height $cmp ?", $args)); } - - if($event instanceof SearchTermParseEvent) { - $matches = array(); - if(preg_match("/^size(<|>|<=|>=|=)(\d+)x(\d+)$/", $event->term, $matches)) { - $cmp = $matches[1]; - $args = array(int_escape($matches[2]), int_escape($matches[3])); - $event->add_querylet(new Querylet("width $cmp ? AND height $cmp ?", $args)); - } - else if(preg_match("/^ratio(<|>|<=|>=|=)(\d+):(\d+)$/", $event->term, $matches)) { - $cmp = $matches[1]; - $args = array(int_escape($matches[2]), int_escape($matches[3])); - $event->add_querylet(new Querylet("width / height $cmp ? / ?", $args)); - } - else if(preg_match("/^(filesize|id)(<|>|<=|>=|=)(\d+[kmg]?b?)$/i", $event->term, $matches)) { - $col = $matches[1]; - $cmp = $matches[2]; - $val = parse_shorthand_int($matches[3]); - $event->add_querylet(new Querylet("images.$col $cmp ?", array($val))); - } - else if(preg_match("/^hash=([0-9a-fA-F]*)$/i", $event->term, $matches)) { - $hash = strtolower($matches[2]); - $event->add_querylet(new Querylet("images.hash = '$hash'")); - } - else if(preg_match("/^(filetype|ext)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) { - $ext = strtolower($matches[2]); - $event->add_querylet(new Querylet("images.ext = '$ext'")); - } - else if(preg_match("/^(filename|name)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) { - $filename = strtolower($matches[2]); - $event->add_querylet(new Querylet("images.filename LIKE '%$filename%'")); - } - else if(preg_match("/^posted=(([0-9\*]*)?(-[0-9\*]*)?(-[0-9\*]*)?)$/", $event->term, $matches)) { - $val = str_replace("*", "%", $matches[1]); - $img_search->append(new Querylet("images.posted LIKE '%$val%'")); - } + else if(preg_match("/^ratio(<|>|<=|>=|=)(\d+):(\d+)$/", $event->term, $matches)) { + $cmp = $matches[1]; + $args = array(int_escape($matches[2]), int_escape($matches[3])); + $event->add_querylet(new Querylet("width / height $cmp ? / ?", $args)); + } + else if(preg_match("/^(filesize|id)(<|>|<=|>=|=)(\d+[kmg]?b?)$/i", $event->term, $matches)) { + $col = $matches[1]; + $cmp = $matches[2]; + $val = parse_shorthand_int($matches[3]); + $event->add_querylet(new Querylet("images.$col $cmp ?", array($val))); + } + else if(preg_match("/^hash=([0-9a-fA-F]*)$/i", $event->term, $matches)) { + $hash = strtolower($matches[2]); + $event->add_querylet(new Querylet("images.hash = '$hash'")); + } + else if(preg_match("/^(filetype|ext)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) { + $ext = strtolower($matches[2]); + $event->add_querylet(new Querylet("images.ext = '$ext'")); + } + else if(preg_match("/^(filename|name)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) { + $filename = strtolower($matches[2]); + $event->add_querylet(new Querylet("images.filename LIKE '%$filename%'")); + } + else if(preg_match("/^posted=(([0-9\*]*)?(-[0-9\*]*)?(-[0-9\*]*)?)$/", $event->term, $matches)) { + $val = str_replace("*", "%", $matches[1]); + $img_search->append(new Querylet("images.posted LIKE '%$val%'")); } } } -add_event_listener(new Index()); ?> diff --git a/ext/load_ext_data/main.php b/ext/load_ext_data/main.php index 47eeeef3..82681786 100644 --- a/ext/load_ext_data/main.php +++ b/ext/load_ext_data/main.php @@ -1,26 +1,22 @@ add_header(""); - } + $css_files = glob("ext/*/style.css"); + if($css_files) { + foreach($css_files as $css_file) { + $page->add_header(""); } + } - $js_files = glob("ext/*/script.js"); - if($js_files) { - foreach($js_files as $js_file) { - $page->add_header(""); - } + $js_files = glob("ext/*/script.js"); + if($js_files) { + foreach($js_files as $js_file) { + $page->add_header(""); } } } } -add_event_listener(new LoadExtData()); ?> diff --git a/ext/setup/main.php b/ext/setup/main.php index 42a10c33..be2b7be7 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -135,27 +135,25 @@ class SetupBlock extends Block { } // }}} -class Setup implements Extension { - var $theme; +class Setup extends SimpleExtension { + public function onInitExt($event) { + global $config; + $config->set_default_string("title", "Shimmie"); + $config->set_default_string("front_page", "post/list"); + $config->set_default_string("main_page", "post/list"); + $config->set_default_string("base_href", "./index.php?q="); + $config->set_default_string("theme", "default"); + } - public function receive_event(Event $event) { - global $config, $database, $page, $user; - if(is_null($this->theme)) $this->theme = get_theme_object($this); + public function onPageRequest($event) { + global $config, $page, $user; - if($event instanceof InitExtEvent) { - $config->set_default_string("title", "Shimmie"); - $config->set_default_string("front_page", "post/list"); - $config->set_default_string("main_page", "post/list"); - $config->set_default_string("base_href", "./index.php?q="); - $config->set_default_string("theme", "default"); - } - - if(($event instanceof PageRequestEvent) && $event->page_matches("nicetest")) { + if($event->page_matches("nicetest")) { $page->set_mode("data"); $page->set_data("ok"); } - if(($event instanceof PageRequestEvent) && $event->page_matches("setup")) { + if($event->page_matches("setup")) { if(!$user->is_admin()) { $this->theme->display_permission_denied($page); } @@ -177,80 +175,80 @@ class Setup implements Extension { } } } + } - if($event instanceof SetupBuildingEvent) { - $themes = array(); - foreach(glob("themes/*") as $theme_dirname) { - $name = str_replace("themes/", "", $theme_dirname); - $themes[ucfirst($name)] = $name; + public function onSetupBuilding($event) { + $themes = array(); + foreach(glob("themes/*") as $theme_dirname) { + $name = str_replace("themes/", "", $theme_dirname); + $themes[ucfirst($name)] = $name; + } + + $full = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"]; + $test_url = str_replace("/index.php", "/nicetest", $full); + + $nicescript = ""; - $sb = new SetupBlock("General"); - $sb->position = 0; - $sb->add_text_option("title", "Site title: "); - $sb->add_text_option("front_page", "
Front page: "); - $sb->add_text_option("main_page", "
Main page: "); - $sb->add_text_option("contact_link", "
Contact URL: "); - $sb->add_choice_option("theme", $themes, "
Theme: "); - $sb->add_bool_option("nice_urls", "
Nice URLs: "); - $sb->add_label("(Javascript inactive, can't test!)$nicescript"); - $event->panel->add_block($sb); - } - - if($event instanceof ConfigSaveEvent) { - global $config; - foreach($_POST as $_name => $junk) { - if(substr($_name, 0, 6) == "_type_") { - $name = substr($_name, 6); - $type = $_POST["_type_$name"]; - $value = isset($_POST["_config_$name"]) ? $_POST["_config_$name"] : null; - switch($type) { - case "string": $config->set_string($name, $value); break; - case "int": $config->set_int($name, $value); break; - case "bool": $config->set_bool($name, $value); break; - } - } + out_span.innerHTML = '(test failed)'; } - } + "; + $sb = new SetupBlock("General"); + $sb->position = 0; + $sb->add_text_option("title", "Site title: "); + $sb->add_text_option("front_page", "
Front page: "); + $sb->add_text_option("main_page", "
Main page: "); + $sb->add_text_option("contact_link", "
Contact URL: "); + $sb->add_choice_option("theme", $themes, "
Theme: "); + $sb->add_bool_option("nice_urls", "
Nice URLs: "); + $sb->add_label("(Javascript inactive, can't test!)$nicescript"); + $event->panel->add_block($sb); + } - if($event instanceof UserBlockBuildingEvent) { - if($user->is_admin()) { - $event->add_link("Board Config", make_link("setup")); + public function onConfigSave($event) { + global $config; + foreach($_POST as $_name => $junk) { + if(substr($_name, 0, 6) == "_type_") { + $name = substr($_name, 6); + $type = $_POST["_type_$name"]; + $value = isset($_POST["_config_$name"]) ? $_POST["_config_$name"] : null; + switch($type) { + case "string": $config->set_string($name, $value); break; + case "int": $config->set_int($name, $value); break; + case "bool": $config->set_bool($name, $value); break; + } } } } + + public function onUserBlockBuilding($event) { + global $user; + if($user->is_admin()) { + $event->add_link("Board Config", make_link("setup")); + } + } } -add_event_listener(new Setup()); ?> diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index 77bf7e3d..a439dc51 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -101,6 +101,7 @@ class TagEdit implements Extension { } } + private function can_tag() { global $config, $user; return $config->get_bool("tag_edit_anon") || !$user->is_anonymous(); diff --git a/ext/view/main.php b/ext/view/main.php index 4703484c..b61c0512 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -59,6 +59,7 @@ class ImageAdminBlockBuildingEvent extends Event { $this->parts[$position] = $html; } } + class ViewImage implements Extension { var $theme;