From bb84a735a29bbd1e7c9d28a37ad7a604785bf8d9 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 11 May 2009 07:04:33 -0700 Subject: [PATCH] requestcontext stuff is messy, go back to globals :( --- contrib/bookmarks/main.php | 11 ++- contrib/danbooru_api/main.php | 14 ++-- contrib/downtime/main.php | 8 +- contrib/et/main.php | 12 +-- contrib/featured/main.php | 10 +-- contrib/handle_ico/main.php | 2 +- contrib/handle_svg/main.php | 2 +- contrib/home/main.php | 3 +- contrib/image_hash_ban/main.php | 22 ++---- contrib/image_hash_ban/test.php | 4 + contrib/ipban/main.php | 21 +++-- contrib/link_image/main.php | 12 +-- contrib/news/main.php | 5 +- contrib/notes/main.php | 5 +- contrib/numeric_score/main.php | 17 ++-- contrib/piclens/main.php | 5 +- contrib/pm/main.php | 44 +++++------ contrib/random_image/main.php | 19 ++--- contrib/rating/main.php | 6 +- contrib/regen_thumb/main.php | 2 +- contrib/report_image/main.php | 34 ++++---- contrib/rss_images/main.php | 9 +-- contrib/simpletest/main.php | 11 +-- contrib/simpletest/standalone.php | 3 +- contrib/site_description/main.php | 7 +- contrib/tag_history/main.php | 9 +-- contrib/wiki/main.php | 2 +- contrib/word_filter/test.php | 4 + contrib/zoom/main.php | 4 +- core/event.class.php | 17 ++-- core/imageboard.pack.php | 124 +++++++++++++++++------------- core/page.class.php | 6 +- core/requestcontext.class.php | 11 --- core/user.class.php | 34 ++++---- core/util.inc.php | 17 ++-- ext/admin/main.php | 31 ++++---- ext/alias_editor/main.php | 40 +++++----- ext/bbcode/test.php | 4 + ext/comment/main.php | 29 +++---- ext/ext_manager/main.php | 17 ++-- ext/handle_404/main.php | 2 +- ext/handle_pixel/main.php | 3 +- ext/image/main.php | 4 +- ext/index/main.php | 32 ++++---- ext/setup/main.php | 25 +++--- ext/tag_edit/main.php | 12 +-- ext/tag_list/main.php | 16 ++-- ext/upgrade/main.php | 7 +- ext/upload/main.php | 16 ++-- ext/user/main.php | 60 +++++---------- ext/user/theme.php | 2 +- ext/view/main.php | 37 ++++----- index.php | 11 +-- themes/danbooru/layout.class.php | 5 +- themes/default/layout.class.php | 5 +- themes/futaba/layout.class.php | 5 +- themes/minimal/layout.class.php | 5 +- 57 files changed, 407 insertions(+), 477 deletions(-) delete mode 100644 core/requestcontext.class.php diff --git a/contrib/bookmarks/main.php b/contrib/bookmarks/main.php index 916fa996..9e26b85e 100644 --- a/contrib/bookmarks/main.php +++ b/contrib/bookmarks/main.php @@ -10,21 +10,20 @@ class Bookmarks 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("bookmark")) { - $user = $event->context->user; - if($event->get_arg(0) == "add") { if(isset($_POST['url'])) { - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("user")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("user")); } } else if($event->get_arg(0) == "remove") { if(isset($_POST['id'])) { - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("user")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("user")); } } } diff --git a/contrib/danbooru_api/main.php b/contrib/danbooru_api/main.php index 6cf011f0..53292cc9 100644 --- a/contrib/danbooru_api/main.php +++ b/contrib/danbooru_api/main.php @@ -208,7 +208,7 @@ class DanbooruApi implements Extension // It is also currently broken due to some confusion over file variable ($tmp_filename?) // Does it exist already? - $existing = Image::by_hash($config, $database, $hash); + $existing = Image::by_hash($hash); if(!is_null($existing)) { header("HTTP/1.0 409 Conflict"); header("X-Danbooru-Errors: duplicate"); @@ -227,7 +227,7 @@ class DanbooruApi implements Extension $nevent = new DataUploadEvent($user, $file, $metadata); send_event($nevent); // If it went ok, grab the id for the newly uploaded image and pass it in the header - $newimg = Image::by_hash($config, $database, $hash); + $newimg = Image::by_hash($hash); $newid = make_link("post/view/" . $newimg->id); // Did we POST or GET this call? if($_SERVER['REQUEST_METHOD'] == 'POST') @@ -269,21 +269,21 @@ class DanbooruApi implements Extension $md5list = explode(",",$_GET['md5']); foreach($md5list as $md5) { - $results[] = Image::by_hash($config, $database, $md5); + $results[] = Image::by_hash($md5); } } elseif(isset($_GET['id'])) { $idlist = explode(",",$_GET['id']); foreach($idlist as $id) { - $results[] = Image::by_id($config, $database, $id); + $results[] = Image::by_id($id); } } else { $limit = isset($_GET['limit']) ? int_escape($_GET['limit']) : 100; $start = isset($_GET['offset']) ? int_escape($_GET['offset']) : 0; $tags = isset($_GET['tags']) ? Tag::explode($_GET['tags']) : array(); - $results = Image::find_images($config,$database,$start,$limit,$tags); + $results = Image::find_images($start, $limit, $tags); } // Now we have the array $results filled with Image objects @@ -392,12 +392,12 @@ class DanbooruApi implements Extension $name = $_REQUEST['login']; $pass = $_REQUEST['password']; $hash = md5( strtolower($name) . $pass ); - $duser = User::by_name_and_hash($config, $database, $name, $hash); + $duser = User::by_name_and_hash($name, $hash); if(!is_null($duser)) { $user = $duser; } else { - $user = User::by_id($config, $database, $config->get_int("anon_id", 0)); + $user = User::by_id($config->get_int("anon_id", 0)); } } } diff --git a/contrib/downtime/main.php b/contrib/downtime/main.php index 985ea059..8b43fae0 100644 --- a/contrib/downtime/main.php +++ b/contrib/downtime/main.php @@ -10,6 +10,7 @@ class Downtime 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 SetupBuildingEvent) { @@ -20,16 +21,15 @@ class Downtime implements Extension { } if($event instanceof PageRequestEvent) { - if($event->context->config->get_bool("downtime")) { + if($config->get_bool("downtime")) { $this->check_downtime($event); - $this->theme->display_notification($event->page); + $this->theme->display_notification($page); } } } private function check_downtime(PageRequestEvent $event) { - $user = $event->context->user; - $config = $event->context->config; + global $user, $config; if($config->get_bool("downtime") && !$user->is_admin() && ($event instanceof PageRequestEvent) && !$this->is_safe_page($event)) { diff --git a/contrib/et/main.php b/contrib/et/main.php index 02b0a4de..4336fc84 100644 --- a/contrib/et/main.php +++ b/contrib/et/main.php @@ -16,24 +16,24 @@ class ET 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("system_info")) { - if($event->context->user->is_admin()) { - $this->theme->display_info_page($event->page, $this->get_info($event->context)); + if($user->is_admin()) { + $this->theme->display_info_page($page, $this->get_info()); } } if($event instanceof UserBlockBuildingEvent) { - if($event->context->user->is_admin()) { + if($user->is_admin()) { $event->add_link("System Info", make_link("system_info")); } } } - private function get_info($context) { - $database = $context->database; - $config = $context->config; + private function get_info() { + global $config, $database; global $_event_listeners; // yay for using secret globals \o/ $info = array(); diff --git a/contrib/featured/main.php b/contrib/featured/main.php index 6344fea7..e6839adb 100644 --- a/contrib/featured/main.php +++ b/contrib/featured/main.php @@ -29,19 +29,19 @@ class Featured implements Extension { $id = int_escape($_POST['image_id']); if($id > 0) { $config->set_int("featured_id", $id); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/view/$id")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/view/$id")); } } } if($event instanceof PostListBuildingEvent) { - global $config, $database; + global $config, $page; $fid = $config->get_int("featured_id"); if($fid > 0) { - $image = Image::by_id($config, $database, $fid); + $image = Image::by_id($fid); if(!is_null($image)) { - $this->theme->display_featured($event->page, $image); + $this->theme->display_featured($page, $image); } } } diff --git a/contrib/handle_ico/main.php b/contrib/handle_ico/main.php index 532b23b3..8746a212 100644 --- a/contrib/handle_ico/main.php +++ b/contrib/handle_ico/main.php @@ -35,7 +35,7 @@ class IcoFileHandler implements Extension { global $config; global $database; $id = int_escape($event->get_arg(0)); - $image = Image::by_id($config, $database, $id); + $image = Image::by_id($id); $hash = $image->hash; $ha = substr($hash, 0, 2); diff --git a/contrib/handle_svg/main.php b/contrib/handle_svg/main.php index d9548a0a..5ddc5cdc 100644 --- a/contrib/handle_svg/main.php +++ b/contrib/handle_svg/main.php @@ -51,7 +51,7 @@ class SVGFileHandler implements Extension { global $config; global $database; $id = int_escape($event->get_arg(0)); - $image = Image::by_id($config, $database, $id); + $image = Image::by_id($id); $hash = $image->hash; $ha = substr($hash, 0, 2); diff --git a/contrib/home/main.php b/contrib/home/main.php index ec03fee5..bfc9da91 100644 --- a/contrib/home/main.php +++ b/contrib/home/main.php @@ -18,12 +18,13 @@ class Home 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("home")) { // this is a request to display this page so output the page. - $this->output_pages($event->page); + $this->output_pages($page); } if($event instanceof SetupBuildingEvent) { diff --git a/contrib/image_hash_ban/main.php b/contrib/image_hash_ban/main.php index e96c7d0e..172026b6 100644 --- a/contrib/image_hash_ban/main.php +++ b/contrib/image_hash_ban/main.php @@ -34,18 +34,16 @@ class ImageBan 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 InitExtEvent) { - global $config; if($config->get_int("ext_imageban_version") < 1) { $this->install(); } } if($event instanceof DataUploadEvent) { - global $database; - $row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash); if($row) { log_info("image_hash_ban", "Blocked image ({$event->hash})"); @@ -54,23 +52,20 @@ class ImageBan implements Extension { } if(($event instanceof PageRequestEvent) && $event->page_matches("image_hash_ban")) { - if($event->user->is_admin()) { + if($user->is_admin()) { if($event->get_arg(0) == "add") { if(isset($_POST['hash']) && isset($_POST['reason'])) { send_event(new AddImageHashBanEvent($_POST['hash'], $_POST['reason'])); - global $page; $page->set_mode("redirect"); $page->set_redirect(make_link("admin")); } if(isset($_POST['image_id'])) { - global $config; - global $database; - $image = Image::by_id($config, $database, int_escape($_POST['image_id'])); + $image = Image::by_id(int_escape($_POST['image_id'])); if($image) { send_event(new ImageDeletionEvent($image)); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/list")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list")); } } } @@ -78,7 +73,6 @@ class ImageBan implements Extension { if(isset($_POST['hash'])) { send_event(new RemoveImageHashBanEvent($_POST['hash'])); - global $page; $page->set_mode("redirect"); $page->set_redirect(make_link("admin")); } @@ -88,13 +82,13 @@ class ImageBan implements Extension { if($event->count_args() == 2) { $page_num = int_escape($event->get_arg(1)); } - $this->theme->display_Image_hash_Bans($event->page, $page_num, $this->get_image_hash_bans($page_num)); + $this->theme->display_Image_hash_Bans($page, $page_num, $this->get_image_hash_bans($page_num)); } } } if($event instanceof UserBlockBuildingEvent) { - if($event->user->is_admin()) { + if($user->is_admin()) { $event->add_link("Image Bans", make_link("image_hash_ban/list/1")); } } @@ -108,7 +102,7 @@ class ImageBan implements Extension { } if($event instanceof ImageAdminBlockBuildingEvent) { - if($event->user->is_admin()) { + if($user->is_admin()) { $event->add_part($this->theme->get_buttons_html($event->image)); } } diff --git a/contrib/image_hash_ban/test.php b/contrib/image_hash_ban/test.php index a1b1e889..1d786f2e 100644 --- a/contrib/image_hash_ban/test.php +++ b/contrib/image_hash_ban/test.php @@ -1,4 +1,8 @@ theme)) $this->theme = get_theme_object($this); if($event instanceof InitExtEvent) { - global $config; if($config->get_int("ext_ipban_version") < 5) { $this->install(); } @@ -50,7 +50,6 @@ class IPBan implements Extension { } if(($event instanceof PageRequestEvent) && $event->page_matches("ip_ban")) { - global $user; if($user->is_admin()) { if($event->get_arg(0) == "add") { if(isset($_POST['ip']) && isset($_POST['reason']) && isset($_POST['end'])) { @@ -58,40 +57,38 @@ class IPBan implements Extension { else $end = $_POST['end']; send_event(new AddIPBanEvent($_POST['ip'], $_POST['reason'], $end)); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("ip_ban/list")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("ip_ban/list")); } } else if($event->get_arg(0) == "remove") { if(isset($_POST['id'])) { send_event(new RemoveIPBanEvent($_POST['id'])); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("ip_ban/list")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("ip_ban/list")); } } else if($event->get_arg(0) == "list") { $bans = (isset($_GET["all"])) ? $this->get_bans() : $this->get_active_bans(); - $this->theme->display_bans($event->page, $bans); + $this->theme->display_bans($page, $bans); } } else { - $this->theme->display_permission_denied($event->page); + $this->theme->display_permission_denied($page); } } if($event instanceof UserBlockBuildingEvent) { - if($event->user->is_admin()) { + if($user->is_admin()) { $event->add_link("IP Bans", make_link("ip_ban/list")); } } if($event instanceof AddIPBanEvent) { - global $user; $this->add_ip_ban($event->ip, $event->reason, $event->end, $user); } if($event instanceof RemoveIPBanEvent) { - global $database; $database->Execute("DELETE FROM bans WHERE id = ?", array($event->id)); } } @@ -173,7 +170,7 @@ class IPBan implements Extension { (strstr($row['ip'], '/') && ip_in_range($remote, $row['ip'])) || ($row['ip'] == $remote) ) { - $admin = User::by_id($config, $database, $row['banner_id']); + $admin = User::by_id($row['banner_id']); $date = date("Y-m-d", $row['end_timestamp']); print "IP {$row['ip']} has been banned until $date by {$admin->name} because of {$row['reason']}"; diff --git a/contrib/link_image/main.php b/contrib/link_image/main.php index 3137d795..21b5aef3 100644 --- a/contrib/link_image/main.php +++ b/contrib/link_image/main.php @@ -8,13 +8,14 @@ class LinkImage 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 DisplayingImageEvent)) { - global $config; - $data_href = get_base_href(); - $event->page->add_header("",0); - $this->theme->links_block($event->page,$this->data($event->image)); + if(($event instanceof DisplayingImageEvent)) { + $data_href = get_base_href(); + $page->add_header("",0); + + $this->theme->links_block($page, $this->data($event->image)); } if($event instanceof SetupBuildingEvent) { $sb = new SetupBlock("Link to Image"); @@ -22,7 +23,6 @@ class LinkImage implements Extension { $event->panel->add_block($sb); } if($event instanceof InitExtEvent) { - global $config; //just set default if empty. $config->set_default_string("ext_link-img_text-link_format", '$title - $id ($ext $size $filesize)'); diff --git a/contrib/news/main.php b/contrib/news/main.php index efa13eaa..cd1a7f40 100644 --- a/contrib/news/main.php +++ b/contrib/news/main.php @@ -12,11 +12,12 @@ 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($event->context->config->get_string("news_text")) > 0) { - $this->theme->display_news($event->page, $event->context->config->get_string("news_text")); + if(strlen($config->get_string("news_text")) > 0) { + $this->theme->display_news($page, $config->get_string("news_text")); } } diff --git a/contrib/notes/main.php b/contrib/notes/main.php index 9098699f..52049ae8 100644 --- a/contrib/notes/main.php +++ b/contrib/notes/main.php @@ -12,19 +12,18 @@ class Notes 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 InitExtEvent) { - global $config; if($config->get_int("ext_notes_version") < 1) { $this->install(); } } if($event instanceof DisplayingImageEvent) { - global $database; $notes = $database->get_all("SELECT * FROM image_notes WHERE image_id = ?", array($event->image->id)); - $this->theme->display_notes($event->page, $notes); + $this->theme->display_notes($page, $notes); } } diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index 7397e8d7..ec74856d 100644 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -23,42 +23,40 @@ class NumericScore 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 InitExtEvent) { - global $config; if($config->get_int("ext_numeric_score_version", 0) < 1) { $this->install(); } } if($event instanceof DisplayingImageEvent) { - global $user; if(!$user->is_anonymous()) { $html = $this->theme->get_voter_html($event->image); - $event->page->add_block(new Block("Image Score", $html, "left", 20)); + $page->add_block(new Block("Image Score", $html, "left", 20)); } } if(($event instanceof PageRequestEvent) && $event->page_matches("numeric_score_vote")) { - if(!$event->user->is_anonymous()) { + if(!$user->is_anonymous()) { $image_id = int_escape($_POST['image_id']); $char = $_POST['vote']; $score = 0; if($char == "up") $score = 1; else if($char == "down") $score = -1; - if($score != 0) send_event(new NumericScoreSetEvent($image_id, $event->user, $score)); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/view/$image_id")); + if($score != 0) send_event(new NumericScoreSetEvent($image_id, $user, $score)); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/view/$image_id")); } } if($event instanceof NumericScoreSetEvent) { - $this->add_vote($event->image_id, $event->user->id, $event->score); + $this->add_vote($event->image_id, $user->id, $event->score); } if($event instanceof ImageDeletionEvent) { - global $database; $database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($event->image->id)); } @@ -74,7 +72,6 @@ class NumericScore implements Extension { $event->set_querylet(new Querylet("numeric_score $cmp $score")); } if(preg_match("/^favou?rite$/", $event->term, $matches)) { - global $user; $event->set_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", array($user->id))); } } diff --git a/contrib/piclens/main.php b/contrib/piclens/main.php index 679ac7a2..aa5e90ea 100644 --- a/contrib/piclens/main.php +++ b/contrib/piclens/main.php @@ -12,8 +12,9 @@ */ class PicLens implements Extension { public function receive_event(Event $event) { + global $page; if($event instanceof PageRequestEvent) { - $event->page->add_header(""); + $page->add_header(""); } if($event instanceof PostListBuildingEvent) { $foo=' @@ -21,7 +22,7 @@ class PicLens implements Extension { PicLens'; - $event->page->add_block(new Block("PicLens", $foo, "left", 20)); + $page->add_block(new Block("PicLens", $foo, "left", 20)); } } } diff --git a/contrib/pm/main.php b/contrib/pm/main.php index 4eb3618d..2db0f368 100644 --- a/contrib/pm/main.php +++ b/contrib/pm/main.php @@ -11,8 +11,7 @@ */ class SendPMEvent extends Event { - public function __construct(RequestContext $reqest, $from_id, $from_ip, $to_id, $subject, $message) { - parent::__construct($request); + 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; @@ -25,51 +24,49 @@ class PM 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 InitExtEvent) { - if($event->context->config->get_int("pm_version") < 1) { - $this->install($event->context); + if($config->get_int("pm_version") < 1) { + $this->install(); } } /* if($event instanceof UserBlockBuildingEvent) { - if(!$event->user->is_anonymous()) { + if(!$user->is_anonymous()) { $event->add_link("Private Messages", make_link("pm")); } } */ if($event instanceof UserPageBuildingEvent) { - $user = $event->context->user; $duser = $event->display_user; if(!$user->is_anonymous() && !$duser->is_anonymous()) { if(($user->id == $duser->id) || $user->is_admin()) { - $this->theme->display_pms($event->context->page, $this->get_pms($duser)); + $this->theme->display_pms($page, $this->get_pms($duser)); } if($user->id != $duser->id) { - $this->theme->display_composer($event->context->page, $user, $duser); + $this->theme->display_composer($page, $user, $duser); } } } if(($event instanceof PageRequestEvent) && $event->page_matches("pm")) { - $database = $event->context->database; - $config = $event->context->config; - $user = $event->config->user; if(!$user->is_anonymous()) { switch($event->get_arg(0)) { case "read": $pm_id = int_escape($event->get_arg(1)); $pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id)); if(is_null($pm)) { - $this->theme->display_error($event->page, "No such PM", "There is no PM #$pm_id"); + $this->theme->display_error($page, "No such PM", "There is no PM #$pm_id"); } else if(($pm["to_id"] == $user->id) || $user->is_admin()) { - $from_user = User::by_id($config, $database, int_escape($pm["from_id"])); + $from_user = User::by_id(int_escape($pm["from_id"])); $database->get_row("UPDATE private_message SET is_read='Y' WHERE id = ?", array($pm_id)); - $this->theme->display_message($event->page, $from_user, $event->user, $pm); + $this->theme->display_message($page, $from_user, $user, $pm); } else { // permission denied @@ -79,13 +76,13 @@ class PM implements Extension { $pm_id = int_escape($event->get_arg(1)); $pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id)); if(is_null($pm)) { - $this->theme->display_error($event->page, "No such PM", "There is no PM #$pm_id"); + $this->theme->display_error($page, "No such PM", "There is no PM #$pm_id"); } else if(($pm["to_id"] == $user->id) || $user->is_admin()) { $database->execute("DELETE FROM private_message WHERE id = ?", array($pm_id)); log_info("pm", "Deleted PM #$pm_id"); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("user")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("user")); } else { // permission denied @@ -96,16 +93,16 @@ class PM implements Extension { $from_id = $user->id; $subject = $_POST["subject"]; $message = $_POST["message"]; - send_event(new SendPMEvent($event->context, $from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message)); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link($_SERVER["REFERER"])); + send_event(new SendPMEvent($from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message)); + $page->set_mode("redirect"); + $page->set_redirect(make_link($_SERVER["REFERER"])); break; } } } if($event instanceof SendPMEvent) { - $event->context->database->execute(" + $database->execute(" INSERT INTO private_message( from_id, from_ip, to_id, sent_date, subject, message) @@ -117,9 +114,8 @@ class PM implements Extension { } } - protected function install(RequestContext $context) { - $database = $context->database; - $config = $context->config; + protected function install() { + global $config, $database; // shortcut to latest if($config->get_int("pm_version") < 1) { diff --git a/contrib/random_image/main.php b/contrib/random_image/main.php index 5e78c8b0..4c87b1a7 100644 --- a/contrib/random_image/main.php +++ b/contrib/random_image/main.php @@ -23,12 +23,10 @@ class RandomImage 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("random_image")) { - global $config; - global $database; - if($event->count_args() == 1) { $action = $event->get_arg(0); $search_terms = array(); @@ -37,18 +35,18 @@ class RandomImage implements Extension { $action = $event->get_arg(0); $search_terms = explode(' ', $event->get_arg(1)); } - $image = Image::by_random($config, $database, $search_terms); + $image = Image::by_random($search_terms); if($event->get_arg(0) == "download") { if(!is_null($image)) { - $event->page->set_mode("data"); - $event->page->set_type("image/jpeg"); - $event->page->set_data(file_get_contents($image->get_image_filename())); + $page->set_mode("data"); + $page->set_type("image/jpeg"); + $page->set_data(file_get_contents($image->get_image_filename())); } } if($event->get_arg(0) == "view") { if(!is_null($image)) { - send_event(new DisplayingImageEvent($image, $event->page)); + send_event(new DisplayingImageEvent($image, $page)); } } } @@ -60,11 +58,10 @@ class RandomImage implements Extension { } if($event instanceof PostListBuildingEvent) { - global $config, $database; if($config->get_bool("show_random_block")) { - $image = Image::by_random($config, $database, $event->search_terms); + $image = Image::by_random($event->search_terms); if(!is_null($image)) { - $this->theme->display_random($event->page, $image); + $this->theme->display_random($page, $image); } } } diff --git a/contrib/rating/main.php b/contrib/rating/main.php index bab3576f..68f804af 100644 --- a/contrib/rating/main.php +++ b/contrib/rating/main.php @@ -20,15 +20,14 @@ class Ratings 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 InitExtEvent) { - global $config; if($config->get_int("ext_ratings2_version") < 2) { $this->install(); } - global $config; $config->set_default_string("ext_rating_anon_privs", 'sq'); $config->set_default_string("ext_rating_user_privs", 'sq'); } @@ -38,14 +37,12 @@ class Ratings implements Extension { } if($event instanceof ImageInfoBoxBuildingEvent) { - global $user; if($user->is_admin()) { $event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80); } } if($event instanceof ImageInfoSetEvent) { - global $user; if($user->is_admin()) { send_event(new RatingSetEvent($event->image->id, $user, $_POST['rating'])); } @@ -70,7 +67,6 @@ class Ratings implements Extension { if($event instanceof SearchTermParseEvent) { $matches = array(); if(is_null($event->term) && $this->no_rating_query($event->context)) { - global $user, $config; if($user->is_anonymous()) { $sqes = $config->get_string("ext_rating_anon_privs"); } diff --git a/contrib/regen_thumb/main.php b/contrib/regen_thumb/main.php index c94f3e4b..e3241194 100644 --- a/contrib/regen_thumb/main.php +++ b/contrib/regen_thumb/main.php @@ -23,7 +23,7 @@ class RegenThumb implements Extension { if($user->is_admin() && isset($_POST['image_id'])) { global $config; global $database; - $image = Image::by_id($config, $database, int_escape($_POST['image_id'])); + $image = Image::by_id(int_escape($_POST['image_id'])); send_event(new ThumbnailGenerationEvent($image->hash, $image->ext)); $this->theme->display_results($event->page, $image); } diff --git a/contrib/report_image/main.php b/contrib/report_image/main.php index ecb72083..e5b2c589 100755 --- a/contrib/report_image/main.php +++ b/contrib/report_image/main.php @@ -33,11 +33,10 @@ class ReportImage 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 InitExtEvent) { - global $config; - $config->set_default_bool('report_image_show_thumbs', true); if($config->get_int("ext_report_image_version") < 1) { @@ -46,33 +45,31 @@ class ReportImage implements Extension { } if(($event instanceof PageRequestEvent) && $event->page_matches("image_report")) { - global $user; if($event->get_arg(0) == "add") { if(isset($_POST['image_id']) && isset($_POST['reason'])) { $image_id = int_escape($_POST['image_id']); - send_event(new AddReportedImageEvent($image_id, $event->user->id, $_POST['reason'])); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/view/$image_id")); + send_event(new AddReportedImageEvent($image_id, $user->id, $_POST['reason'])); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/view/$image_id")); } } else if($event->get_arg(0) == "remove") { if(isset($_POST['id'])) { - if($event->user->is_admin()) { + if($user->is_admin()) { send_event(new RemoveReportedImageEvent($_POST['id'])); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("image_report/list")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("image_report/list")); } } } else if($event->get_arg(0) == "list") { - if($event->user->is_admin()) { - $this->theme->display_reported_images($event->page, $this->get_reported_images()); + if($user->is_admin()) { + $this->theme->display_reported_images($page, $this->get_reported_images()); } } } if($event instanceof AddReportedImageEvent) { - global $database; $database->Execute( "INSERT INTO image_reports(image_id, reporter_id, reason) VALUES (?, ?, ?)", @@ -80,13 +77,12 @@ class ReportImage implements Extension { } if($event instanceof RemoveReportedImageEvent) { - global $database; $database->Execute("DELETE FROM image_reports WHERE id = ?", array($event->id)); } if($event instanceof DisplayingImageEvent) { - if($event->context->config->get_bool('report_image_anon') || !$event->context->user->is_anonymous()) { - $this->theme->display_image_banner($event->page, $event->image); + if($config->get_bool('report_image_anon') || !$user->is_anonymous()) { + $this->theme->display_image_banner($page, $event->image); } } @@ -98,13 +94,12 @@ class ReportImage implements Extension { } if($event instanceof UserBlockBuildingEvent) { - if($event->user->is_admin()) { + if($user->is_admin()) { $event->add_link("Reported Images", make_link("image_report/list")); } } if($event instanceof ImageDeletionEvent) { - global $database; $database->Execute("DELETE FROM image_reports WHERE image_id = ?", array($event->image->id)); } } @@ -126,7 +121,7 @@ class ReportImage implements Extension { } public function get_reported_images() { - global $database; + global $config, $database; $all_reports = $database->get_all(" SELECT image_reports.*, users.name AS reporter_name FROM image_reports @@ -135,9 +130,8 @@ class ReportImage implements Extension { $reports = array(); foreach($all_reports as $report) { - global $database, $config; $image_id = int_escape($report['image_id']); - $image = Image::by_id($config, $database, $image_id); + $image = Image::by_id($image_id); if(is_null($image)) { send_event(new RemoveReportedImageEvent($report['id'])); continue; diff --git a/contrib/rss_images/main.php b/contrib/rss_images/main.php index 69229740..cdfb9917 100644 --- a/contrib/rss_images/main.php +++ b/contrib/rss_images/main.php @@ -9,9 +9,9 @@ class RSS_Images implements Extension { // event handling {{{ public function receive_event(Event $event) { + global $config, $database, $page, $user; + if($event instanceof PostListBuildingEvent) { - global $page; - global $config; $title = $config->get_string('title'); if(count($event->search_terms) > 0) { @@ -26,9 +26,6 @@ class RSS_Images implements Extension { } if(($event instanceof PageRequestEvent) && $event->page_matches("rss/images")) { - global $config; - global $database; - $page_number = 0; $search_terms = array(); @@ -45,7 +42,7 @@ class RSS_Images implements Extension { $page_number = int_escape($event->get_arg(1)); } - $images = Image::find_images($config, $database, ($page_number-1)*10, 10, $search_terms); + $images = Image::find_images(($page_number-1)*10, 10, $search_terms); $this->do_rss($images, $search_terms, $page_number); } } diff --git a/contrib/simpletest/main.php b/contrib/simpletest/main.php index 997cb3c0..1680b3cd 100644 --- a/contrib/simpletest/main.php +++ b/contrib/simpletest/main.php @@ -25,19 +25,20 @@ 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")) { - $event->page->set_title("Test Results"); - $event->page->set_heading("Test Results"); - $event->page->add_block(new NavBlock()); + $page->set_title("Test Results"); + $page->set_heading("Test Results"); + $page->add_block(new NavBlock()); $all = new TestFinder($event->get_arg(0)); - $all->run(new SCoreReporter($event->page)); + $all->run(new SCoreReporter($page)); } if($event instanceof UserBlockBuildingEvent) { - if($event->user->is_admin()) { + if($user->is_admin()) { $event->add_link("Run Tests", make_link("test/all")); } } diff --git a/contrib/simpletest/standalone.php b/contrib/simpletest/standalone.php index 92a90d20..4439ebee 100644 --- a/contrib/simpletest/standalone.php +++ b/contrib/simpletest/standalone.php @@ -1,8 +1,10 @@ context->config->get_string("site_description")) > 0) { - $description = $event->context->config->get_string("site_description"); - $event->context->page->add_header(""); + if(strlen($config->get_string("site_description")) > 0) { + $description = $config->get_string("site_description"); + $page->add_header(""); } } diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 20d0ef70..b450d840 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -9,11 +9,11 @@ class Tag_History 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 InitExtEvent)) { // shimmie is being installed so call install to create the table. - global $config; if($config->get_int("ext_tag_history_version") < 3) { $this->install(); } @@ -24,7 +24,6 @@ class Tag_History implements Extension { if($event->get_arg(0) == "revert") { // this is a request to revert to a previous version of the tags - global $config, $user; if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) { $this->process_revert_request($_POST['revert']); } @@ -33,16 +32,16 @@ class Tag_History implements Extension { { // must be an attempt to view a tag history $image_id = int_escape($event->get_arg(0)); - $this->theme->display_history_page($event->page, $image_id, $this->get_tag_history_from_id($image_id)); + $this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id)); } else { - $this->theme->display_global_page($event->page, $this->get_global_tag_history()); + $this->theme->display_global_page($page, $this->get_global_tag_history()); } } if(($event instanceof DisplayingImageEvent)) { // handle displaying a link on the view page - $this->theme->display_history_link($event->page, $event->image->id); + $this->theme->display_history_link($page, $event->image->id); } if(($event instanceof ImageDeletionEvent)) { diff --git a/contrib/wiki/main.php b/contrib/wiki/main.php index 8e5be4c1..ef169526 100644 --- a/contrib/wiki/main.php +++ b/contrib/wiki/main.php @@ -44,7 +44,7 @@ class WikiPage { public function get_owner() { global $config; global $database; - return User::by_id($config, $database, $this->owner_id); + return User::by_id($this->owner_id); } public function is_locked() { diff --git a/contrib/word_filter/test.php b/contrib/word_filter/test.php index f1795773..4dbed6be 100644 --- a/contrib/word_filter/test.php +++ b/contrib/word_filter/test.php @@ -1,4 +1,8 @@ assertEqual( diff --git a/contrib/zoom/main.php b/contrib/zoom/main.php index 01e01ef6..dedabad8 100644 --- a/contrib/zoom/main.php +++ b/contrib/zoom/main.php @@ -10,11 +10,11 @@ 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) { - global $config; - $this->theme->display_zoomer($event->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) { diff --git a/core/event.class.php b/core/event.class.php index 6db3c22e..0c12fc86 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -4,11 +4,7 @@ * generic parent class */ abstract class Event { - var $context; - - public function __construct(RequestContext $context) { - $this->context = $context; - } + public function __construct() {} } @@ -32,12 +28,9 @@ class PageRequestEvent extends Event { var $part_count; - public function __construct(RequestContext $context, $args) { - parent::__construct($context); + public function __construct($args) { $this->args = $args; $this->arg_count = count($args); - $this->page = $context->page; - $this->user = $context->user; } public function page_matches($name) { @@ -105,8 +98,7 @@ class LogEvent extends Event { var $message; var $time; - public function __construct($context, $section, $priority, $message) { - parent::__construct($context); + public function __construct($section, $priority, $message) { $this->section = $section; $this->priority = $priority; $this->message = $message; @@ -114,8 +106,9 @@ class LogEvent extends Event { // this should be an extension /* + global $user; $ftime = date("Y-m-d H:i:s", $this->time); - $username = $context->user->name; + $username = $user->name; $ip = $_SERVER['REMOTE_ADDR']; $fp = fopen("shimmie.log", "a"); fputs($fp, "$ftime\t$section/$priority\t$username/$ip\t$message\n"); diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index f8da54d2..a08d50d6 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -15,9 +15,6 @@ * sound file, or any other supported upload type. */ class Image { - var $config; - var $database; - var $id = null; var $height, $width; var $hash, $filesize; @@ -30,12 +27,6 @@ class Image { * Constructors and other instance creators */ public function Image($row=null) { - global $config; - global $database; - - $this->config = $config; - $this->database = $database; - if(!is_null($row)) { foreach($row as $name => $value) { // FIXME: some databases use table.name rather than name @@ -45,37 +36,43 @@ class Image { } } - public static function by_id(Config $config, Database $database, $id) { + public static function by_id($id) { assert(is_numeric($id)); + global $database; $image = null; $row = $database->get_row("SELECT * FROM images WHERE images.id=?", array($id)); return ($row ? new Image($row) : null); } - public static function by_hash(Config $config, Database $database, $hash) { + public static function by_hash($hash) { assert(is_string($hash)); + global $database; $image = null; $row = $database->db->GetRow("SELECT images.* FROM images WHERE hash=?", array($hash)); return ($row ? new Image($row) : null); } - public static function by_random(Config $config, Database $database, $tags=array()) { - $max = Image::count_images($config, $database, $tags); + public static function by_random($tags=array()) { + assert(is_array($tags)); + $max = Image::count_images($tags); $rand = mt_rand(0, $max-1); - $set = Image::find_images($config, $database, $rand, 1, $tags); + $set = Image::find_images($rand, 1, $tags); if(count($set) > 0) return $set[0]; else return null; } - public static function find_images(Config $config, Database $database, $start, $limit, $tags=array()) { - $images = array(); - + public static function find_images($start, $limit, $tags=array()) { assert(is_numeric($start)); assert(is_numeric($limit)); + assert(is_array($tags)); + global $database; + + $images = array(); + if($start < 0) $start = 0; if($limit < 1) $limit = 1; - $querylet = Image::build_search_querylet($config, $database, $tags); + $querylet = Image::build_search_querylet($tags); $querylet->append(new Querylet("ORDER BY images.id DESC LIMIT ? OFFSET ?", array($limit, $start))); $result = $database->execute($querylet->sql, $querylet->variables); @@ -89,20 +86,24 @@ class Image { /* * Image-related utility functions */ - public static function count_images(Config $config, Database $database, $tags=array()) { + public static function count_images($tags=array()) { + assert(is_array($tags)); + global $database; if(count($tags) == 0) { return $database->db->GetOne("SELECT COUNT(*) FROM images"); } else { - $querylet = Image::build_search_querylet($config, $database, $tags); + $querylet = Image::build_search_querylet($tags); $result = $database->execute($querylet->sql, $querylet->variables); return $result->RecordCount(); } } - public static function count_pages(Config $config, Database $database, $tags=array()) { + public static function count_pages($tags=array()) { + assert(is_array($tags)); + global $config, $database; $images_per_page = $config->get_int('index_width') * $config->get_int('index_height'); - return ceil(Image::count_images($config, $database, $tags) / $images_per_page); + return ceil(Image::count_images($tags) / $images_per_page); } @@ -112,6 +113,7 @@ class Image { public function get_next($tags=array(), $next=true) { assert(is_array($tags)); assert(is_bool($next)); + global $database; if($next) { $gtlt = "<"; @@ -123,13 +125,13 @@ class Image { } if(count($tags) == 0) { - $row = $this->database->db->GetRow("SELECT images.* FROM images WHERE images.id $gtlt {$this->id} ORDER BY images.id $dir LIMIT 1"); + $row = $database->db->GetRow("SELECT images.* FROM images WHERE images.id $gtlt {$this->id} ORDER BY images.id $dir LIMIT 1"); } else { $tags[] = "id$gtlt{$this->id}"; - $querylet = Image::build_search_querylet($this->config, $this->database, $tags); + $querylet = Image::build_search_querylet($tags); $querylet->append_sql(" ORDER BY images.id $dir LIMIT 1"); - $row = $this->database->db->GetRow($querylet->sql, $querylet->variables); + $row = $database->db->GetRow($querylet->sql, $querylet->variables); } return ($row ? new Image($row) : null); @@ -140,23 +142,24 @@ class Image { } public function get_owner() { - return User::by_id($this->config, $this->database, $this->owner_id); + return User::by_id($this->owner_id); } public function get_tag_array() { - $cached = $this->database->cache->get("image-{$this->id}-tags"); + global $database; + $cached = $database->cache->get("image-{$this->id}-tags"); if($cached) return $cached; if(!isset($this->tag_array)) { $this->tag_array = Array(); - $row = $this->database->Execute("SELECT tag FROM image_tags JOIN tags ON image_tags.tag_id = tags.id WHERE image_id=? ORDER BY tag", array($this->id)); + $row = $database->Execute("SELECT tag FROM image_tags JOIN tags ON image_tags.tag_id = tags.id WHERE image_id=? ORDER BY tag", array($this->id)); while(!$row->EOF) { $this->tag_array[] = $row->fields['tag']; $row->MoveNext(); } } - $this->database->cache->set("image-{$this->id}-tags", $this->tag_array); + $database->cache->set("image-{$this->id}-tags", $this->tag_array); return $this->tag_array; } @@ -165,11 +168,11 @@ class Image { } public function get_image_link() { - $c = $this->config; - if(strlen($c->get_string('image_ilink')) > 0) { + global $config; + if(strlen($config->get_string('image_ilink')) > 0) { return $this->parse_link_template($c->get_string('image_ilink')); } - else if($c->get_bool('nice_urls', false)) { + else if($config->get_bool('nice_urls', false)) { return $this->parse_link_template(make_link('_images/$hash/$id - $tags.$ext')); } else { @@ -178,15 +181,16 @@ class Image { } public function get_short_link() { - return $this->parse_link_template($this->config->get_string('image_slink')); + global $config; + return $this->parse_link_template($config->get_string('image_slink')); } public function get_thumb_link() { - $c = $this->config; - if(strlen($c->get_string('image_tlink')) > 0) { + global $config; + if(strlen($config->get_string('image_tlink')) > 0) { return $this->parse_link_template($c->get_string('image_tlink')); } - else if($c->get_bool('nice_urls', false)) { + else if($config->get_bool('nice_urls', false)) { return $this->parse_link_template(make_link('_thumbs/$hash/thumb.jpg')); } else { @@ -229,18 +233,21 @@ class Image { } public function set_source($source) { + global $database; if(empty($source)) $source = null; - $this->database->execute("UPDATE images SET source=? WHERE id=?", array($source, $this->id)); + $database->execute("UPDATE images SET source=? WHERE id=?", array($source, $this->id)); } public function delete_tags_from_image() { - $this->database->execute( + global $database; + $database->execute( "UPDATE tags SET count = count - 1 WHERE id IN ". "(SELECT tag_id FROM image_tags WHERE image_id = ?)", array($this->id)); - $this->database->execute("DELETE FROM image_tags WHERE image_id=?", array($this->id)); + $database->execute("DELETE FROM image_tags WHERE image_id=?", array($this->id)); } public function set_tags($tags) { + global $database; $tags = Tag::resolve_list($tags); assert(is_array($tags)); @@ -251,32 +258,32 @@ class Image { // insert each new tags foreach($tags as $tag) { - $id = $this->database->db->GetOne( + $id = $database->db->GetOne( "SELECT id FROM tags WHERE tag = ?", array($tag)); if(empty($id)) { // a new tag - $this->database->execute( + $database->execute( "INSERT INTO tags(tag) VALUES (?)", array($tag)); - $this->database->execute( + $database->execute( "INSERT INTO image_tags(image_id, tag_id) VALUES(?, (SELECT id FROM tags WHERE tag = ?))", array($this->id, $tag)); } else { // user of an existing tag - $this->database->execute( + $database->execute( "INSERT INTO image_tags(image_id, tag_id) VALUES(?, ?)", array($this->id, $id)); } - $this->database->execute( + $database->execute( "UPDATE tags SET count = count + 1 WHERE tag = ?", array($tag)); } log_info("core-image", "Tags for Image #{$this->id} set to: ".implode(" ", $tags)); - $this->database->cache->delete("image-{$this->id}-tags"); + $database->cache->delete("image-{$this->id}-tags"); } @@ -284,8 +291,9 @@ class Image { * Other actions */ public function delete() { - $this->delete_tags_from_image(); - $this->database->execute("DELETE FROM images WHERE id=?", array($this->id)); + global $database; + $delete_tags_from_image(); + $database->execute("DELETE FROM images WHERE id=?", array($this->id)); log_info("core-image", "Deleted Image #{$image->id} ({$image->hash})"); unlink($this->get_image_filename()); @@ -293,6 +301,8 @@ class Image { } public function parse_link_template($tmpl, $_escape="url_escape") { + global $config; + // don't bother hitting the database if it won't be used... $safe_tags = ""; if(strpos($tmpl, '$tags') !== false) { // * stabs dynamically typed languages with a rusty spoon * @@ -301,7 +311,7 @@ class Image { "", $this->get_tag_list()); } - $base_href = $this->config->get_string('base_href'); + $base_href = $config->get_string('base_href'); $fname = $this->get_filename(); $base_fname = strpos($fname, '.') ? substr($fname, 0, strrpos($fname, '.')) : $fname; @@ -313,7 +323,7 @@ class Image { $tmpl = str_replace('$size', "{$this->width}x{$this->height}", $tmpl); $tmpl = str_replace('$filesize', to_shorthand_int($this->filesize), $tmpl); $tmpl = str_replace('$filename', $_escape($base_fname), $tmpl); - $tmpl = str_replace('$title', $_escape($this->config->get_string("title")), $tmpl); + $tmpl = str_replace('$title', $_escape($config->get_string("title")), $tmpl); $plte = new ParseLinkTemplateEvent($tmpl, $this); send_event($plte); @@ -322,16 +332,20 @@ class Image { return $tmpl; } - private static function build_search_querylet(Config $config, Database $database, $terms) { + private static function build_search_querylet($terms) { + assert(is_array($terms)); + global $database; if($database->engine->name == "mysql") - return Image::build_ugly_search_querylet($config, $database, $terms); + return Image::build_ugly_search_querylet($terms); else - return Image::build_accurate_search_querylet($config, $database, $terms); + return Image::build_accurate_search_querylet($terms); } // this method is simple, fast and accurate; but mysql chokes on it // because it uses subqueries - private static function build_accurate_search_querylet(Config $config, Database $database, $terms) { + private static function build_accurate_search_querylet($terms) { + global $config, $database; + $tag_querylets = array(); $img_querylets = array(); $positive_tag_count = 0; @@ -483,7 +497,9 @@ class Image { } // this function exists because mysql is a turd. - private static function build_ugly_search_querylet(Config $config, Database $database, $terms) { + private static function build_ugly_search_querylet($terms) { + global $config, $database; + $tag_querylets = array(); $img_querylets = array(); $positive_tag_count = 0; diff --git a/core/page.class.php b/core/page.class.php index b22fff3c..a38f3f5f 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -70,7 +70,9 @@ class GenericPage { // ============================================== - public function display($context) { + public function display() { + global $page; + header("Content-type: {$this->type}"); header("X-Powered-By: SCore-".SCORE_VERSION); @@ -79,7 +81,7 @@ class GenericPage { header("Cache-control: no-cache"); usort($this->blocks, "blockcmp"); $layout = new Layout(); - $layout->display_page($context); + $layout->display_page($page); break; case "data": if(!is_null($this->filename)) { diff --git a/core/requestcontext.class.php b/core/requestcontext.class.php deleted file mode 100644 index 8d5123d7..00000000 --- a/core/requestcontext.class.php +++ /dev/null @@ -1,11 +0,0 @@ - diff --git a/core/user.class.php b/core/user.class.php index 028347e7..e8959812 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -21,10 +21,7 @@ class User { * $user = User::by_name($config, $database, "bob"); * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - public function User(Config $config, Database $database, $row) { - $this->config = $config; - $this->database = $database; - + public function User($row) { $this->id = int_escape($row['id']); $this->name = $row['name']; $this->email = $row['email']; @@ -32,32 +29,36 @@ class User { $this->admin = ($row['admin'] == 'Y'); } - public static function by_session(Config $config, Database $database, $name, $session) { + public static function by_session($name, $session) { + global $config, $database; $row = $database->get_row( "SELECT * FROM users WHERE name = ? AND md5(concat(pass, ?)) = ?", array($name, get_session_ip($config), $session) ); - return is_null($row) ? null : new User($config, $database, $row); + return is_null($row) ? null : new User($row); } - public static function by_id(Config $config, Database $database, $id) { + public static function by_id($id) { assert(is_numeric($id)); + global $database; $row = $database->get_row("SELECT * FROM users WHERE id = ?", array($id)); - return is_null($row) ? null : new User($config, $database, $row); + return is_null($row) ? null : new User($row); } - public static function by_name(Config $config, Database $database, $name) { + public static function by_name($name) { assert(is_string($name)); + global $database; $row = $database->get_row("SELECT * FROM users WHERE name = ?", array($name)); - return is_null($row) ? null : new User($config, $database, $row); + return is_null($row) ? null : new User($row); } - public static function by_name_and_hash(Config $config, Database $database, $name, $hash) { + public static function by_name_and_hash($name, $hash) { assert(is_string($name)); assert(is_string($hash)); assert(strlen($hash) == 32); + global $database; $row = $database->get_row("SELECT * FROM users WHERE name = ? AND pass = ?", array($name, $hash)); - return is_null($row) ? null : new User($config, $database, $row); + return is_null($row) ? null : new User($row); } @@ -67,7 +68,8 @@ class User { public function is_anonymous() { - return ($this->id == $this->config->get_int('anon_id')); + global $config; + return ($this->id == $config->get_int('anon_id')); } public function is_admin() { @@ -76,14 +78,16 @@ class User { public function set_admin($admin) { assert(is_bool($admin)); + global $database; $yn = $admin ? 'Y' : 'N'; - $this->database->Execute("UPDATE users SET admin=? WHERE id=?", array($yn, $this->id)); + $database->Execute("UPDATE users SET admin=? WHERE id=?", array($yn, $this->id)); log_info("core-user", "Made {$this->name} admin=$yn"); } public function set_password($password) { + global $database; $hash = md5(strtolower($this->name) . $password); - $this->database->Execute("UPDATE users SET pass=? WHERE id=?", array($hash, $this->id)); + $database->Execute("UPDATE users SET pass=? WHERE id=?", array($hash, $this->id)); log_info("core-user", "Set password for {$this->name}"); } } diff --git a/core/util.inc.php b/core/util.inc.php index 351157cd..e957cfef 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -227,8 +227,7 @@ define("LOG_DEBUG", 10); define("LOG_NOTSET", 0); function log_msg($section, $priority, $message) { - global $context; - send_event(new LogEvent($context, $section, $priority, $message)); + send_event(new LogEvent($section, $priority, $message)); } function log_info($section, $message) { @@ -456,26 +455,28 @@ function _get_query_parts() { } } -function _get_page_request($context) { +function _get_page_request() { + global $config; $args = _get_query_parts(); if(count($args) == 0 || strlen($args[0]) == 0) { - $args = split('/', $context->config->get_string('front_page')); + $args = split('/', $config->get_string('front_page')); } - return new PageRequestEvent($context, $args); + return new PageRequestEvent($args); } -function _get_user($config, $database) { +function _get_user() { + global $config, $database; $user = null; if(isset($_COOKIE["shm_user"]) && isset($_COOKIE["shm_session"])) { - $tmp_user = User::by_session($config, $database, $_COOKIE["shm_user"], $_COOKIE["shm_session"]); + $tmp_user = User::by_session($_COOKIE["shm_user"], $_COOKIE["shm_session"]); if(!is_null($tmp_user)) { $user = $tmp_user; } } if(is_null($user)) { - $user = User::by_id($config, $database, $config->get_int("anon_id", 0)); + $user = User::by_id($config->get_int("anon_id", 0)); } assert(!is_null($user)); return $user; diff --git a/ext/admin/main.php b/ext/admin/main.php index 3a5ffbb7..522b4fab 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -15,34 +15,33 @@ class AdminPage 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("admin")) { - if(!$event->user->is_admin()) { - $this->theme->display_permission_denied($event->page); + if(!$user->is_admin()) { + $this->theme->display_permission_denied($page); } else { if($event->get_arg(0) == "delete_image") { // FIXME: missing lots of else {complain} if(isset($_POST['image_id'])) { - global $config; - global $database; - $image = Image::by_id($config, $database, $_POST['image_id']); + $image = Image::by_id($_POST['image_id']); if($image) { send_event(new ImageDeletionEvent($image)); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/list")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list")); } } } else { - send_event(new AdminBuildingEvent($event->page)); + send_event(new AdminBuildingEvent($page)); } } } if(($event instanceof PageRequestEvent) && $event->page_matches("admin_utils")) { - if($event->user->is_admin()) { + if($user->is_admin()) { log_info("admin", "Util: {$_POST['action']}"); set_time_limit(0); $redirect = false; @@ -61,30 +60,30 @@ class AdminPage implements Extension { $redirect = true; break; case 'database dump': - $this->dbdump($event->page); + $this->dbdump($page); break; } if($redirect) { - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("admin")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("admin")); } } } if($event instanceof ImageAdminBlockBuildingEvent) { - if($event->user->is_admin()) { + if($user->is_admin()) { $event->add_part($this->theme->get_deleter_html($event->image->id)); } } if($event instanceof AdminBuildingEvent) { - $this->theme->display_page($event->page); - $this->theme->display_form($event->page); + $this->theme->display_page($page); + $this->theme->display_form($page); } if($event instanceof UserBlockBuildingEvent) { - if($event->user->is_admin()) { + if($user->is_admin()) { $event->add_link("Board Admin", make_link("admin")); } } diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index bb12ac97..35eb0b9c 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -16,64 +16,62 @@ class AliasEditor 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("alias")) { if($event->get_arg(0) == "add") { - if($event->user->is_admin()) { + if($user->is_admin()) { if(isset($_POST['oldtag']) && isset($_POST['newtag'])) { try { $aae = new AddAliasEvent($_POST['oldtag'], $_POST['newtag']); send_event($aae); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("alias/list")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("alias/list")); } catch(AddAliasException $ex) { - $this->theme->display_error($event->page, "Error adding alias", $ex->getMessage()); + $this->theme->display_error($page, "Error adding alias", $ex->getMessage()); } } } } else if($event->get_arg(0) == "remove") { - if($event->user->is_admin()) { + if($user->is_admin()) { if(isset($_POST['oldtag'])) { - global $database; $database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag'])); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("alias/list")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("alias/list")); } } } else if($event->get_arg(0) == "list") { - global $database; - $this->theme->display_aliases($event->page, + $this->theme->display_aliases($page, $database->db->GetAssoc("SELECT oldtag, newtag FROM aliases ORDER BY newtag"), - $event->user->is_admin()); + $user->is_admin()); } else if($event->get_arg(0) == "export") { - global $database; - $event->page->set_mode("data"); - $event->page->set_type("text/plain"); - $event->page->set_data($this->get_alias_csv($database)); + $page->set_mode("data"); + $page->set_type("text/plain"); + $page->set_data($this->get_alias_csv($database)); } else if($event->get_arg(0) == "import") { - if($event->user->is_admin()) { + if($user->is_admin()) { print_r($_FILES); if(count($_FILES) > 0) { global $database; $tmp = $_FILES['alias_file']['tmp_name']; $contents = file_get_contents($tmp); $this->add_alias_csv($database, $contents); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("alias/list")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("alias/list")); } else { - $this->theme->display_error($event->page, "No File Specified", "You have to upload a file"); + $this->theme->display_error($page, "No File Specified", "You have to upload a file"); } } else { - $this->theme->display_error($event->page, "Admins Only", "Only admins can edit the alias list"); + $this->theme->display_error($page, "Admins Only", "Only admins can edit the alias list"); } } } @@ -90,7 +88,7 @@ class AliasEditor implements Extension { } if($event instanceof UserBlockBuildingEvent) { - if($event->user->is_admin()) { + if($user->is_admin()) { $event->add_link("Alias Editor", make_link("alias/list")); } } diff --git a/ext/bbcode/test.php b/ext/bbcode/test.php index d396e0d0..e8136732 100644 --- a/ext/bbcode/test.php +++ b/ext/bbcode/test.php @@ -1,4 +1,8 @@ assertEqual( diff --git a/ext/comment/main.php b/ext/comment/main.php index 6d05e841..176bcc05 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -58,6 +58,8 @@ class CommentList implements Extension { var $theme; // event handler {{{ 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) { @@ -76,32 +78,32 @@ class CommentList implements Extension { if($event->get_arg(0) == "add") { if(isset($_POST['image_id']) && isset($_POST['comment'])) { try { - $cpe = new CommentPostingEvent($_POST['image_id'], $event->user, $_POST['comment']); + $cpe = new CommentPostingEvent($_POST['image_id'], $user, $_POST['comment']); send_event($cpe); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/view/".int_escape($_POST['image_id']))); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/view/".int_escape($_POST['image_id']))); } catch(CommentPostingException $ex) { - $this->theme->display_error($event->page, "Comment Blocked", $ex->getMessage()); + $this->theme->display_error($page, "Comment Blocked", $ex->getMessage()); } } } else if($event->get_arg(0) == "delete") { - if($event->user->is_admin()) { + if($user->is_admin()) { // FIXME: post, not args if($event->count_args() == 3) { send_event(new CommentDeletionEvent($event->get_arg(1))); - $event->page->set_mode("redirect"); + $page->set_mode("redirect"); if(!empty($_SERVER['HTTP_REFERER'])) { - $event->page->set_redirect($_SERVER['HTTP_REFERER']); + $page->set_redirect($_SERVER['HTTP_REFERER']); } else { - $event->page->set_redirect(make_link("post/view/".$event->get_arg(2))); + $page->set_redirect(make_link("post/view/".$event->get_arg(2))); } } } else { - $this->theme->display_permission_denied($event->page); + $this->theme->display_permission_denied($page); } } else if($event->get_arg(0) == "list") { @@ -110,19 +112,18 @@ class CommentList implements Extension { } if($event instanceof PostListBuildingEvent) { - global $config; $cc = $config->get_int("comment_count"); if($cc > 0) { $recent = $this->get_recent_comments($cc); if(count($recent) > 0) { - $this->theme->display_recent_comments($event->page, $recent); + $this->theme->display_recent_comments($page, $recent); } } } if($event instanceof DisplayingImageEvent) { $this->theme->display_comments( - $event->page, + $page, $this->get_comments($event->image->id), $this->can_comment(), $event->image->id); @@ -228,7 +229,7 @@ class CommentList implements Extension { $n = 10; while(!$result->EOF) { - $image = Image::by_id($config, $database, $result->fields["image_id"]); + $image = Image::by_id($result->fields["image_id"]); $comments = $this->get_comments($image->id); $this->theme->add_comment_list($page, $image, $comments, $n, $this->can_comment()); $n += 1; @@ -361,7 +362,7 @@ class CommentList implements Extension { if(!$config->get_bool('comment_anon') && $user->is_anonymous()) { throw new CommentPostingException("Anonymous posting has been disabled"); } - else if(is_null(Image::by_id($config, $database, $image_id))) { + else if(is_null(Image::by_id($image_id))) { throw new CommentPostingException("The image does not exist"); } else if(trim($comment) == "") { diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php index 46825394..db5ce469 100644 --- a/ext/ext_manager/main.php +++ b/ext/ext_manager/main.php @@ -72,38 +72,39 @@ 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")) { - if($event->user->is_admin()) { + if($user->is_admin()) { if($event->get_arg(0) == "set") { if(is_writable("ext")) { $this->set_things($_POST); - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("ext_manager")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("ext_manager")); } else { - $this->theme->display_error($event->page, "File Operation Failed", + $this->theme->display_error($page, "File Operation Failed", "The extension folder isn't writable by the web server :("); } } else { - $this->theme->display_table($event->page, $this->get_extensions()); + $this->theme->display_table($page, $this->get_extensions()); } } else { - $this->theme->display_permission_denied($event->page); + $this->theme->display_permission_denied($page); } } if(($event instanceof PageRequestEvent) && $event->page_matches("ext_doc")) { $ext = $event->get_arg(0); $info = new ExtensionInfo("contrib/$ext/main.php"); - $this->theme->display_doc($event->page, $info); + $this->theme->display_doc($page, $info); } if($event instanceof UserBlockBuildingEvent) { - if($event->user->is_admin()) { + if($user->is_admin()) { $event->add_link("Extension Manager", make_link("ext_manager")); } } diff --git a/ext/handle_404/main.php b/ext/handle_404/main.php index b6fc0c39..cffab0e6 100644 --- a/ext/handle_404/main.php +++ b/ext/handle_404/main.php @@ -3,7 +3,7 @@ class Handle404 implements Extension { public function receive_event(Event $event) { if($event instanceof PageRequestEvent) { - $page = $event->page; + global $page; // hax. if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) { $h_pagename = html_escape(implode('/', $event->args)); diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 29081a3b..e6430218 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -9,6 +9,7 @@ class PixelFileHandler implements Extension { var $theme; public function receive_event(Event $event) { + global $page; 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)) { @@ -30,7 +31,7 @@ class PixelFileHandler implements Extension { } if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) { - $this->theme->display_image($event->page, $event->image); + $this->theme->display_image($page, $event->image); } } diff --git a/ext/image/main.php b/ext/image/main.php index 83b23f1a..90d21ccb 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -168,7 +168,7 @@ class ImageIO implements Extension { /* * Check for an existing image */ - $existing = Image::by_hash($config, $database, $image->hash); + $existing = Image::by_hash($image->hash); if(!is_null($existing)) { $handler = $config->get_string("upload_collision_handler"); if($handler == "merge") { @@ -204,7 +204,7 @@ class ImageIO implements Extension { private function send_file($image_id, $type) { global $config; global $database; - $image = Image::by_id($config, $database, $image_id); + $image = Image::by_id($image_id); global $page; if(!is_null($image)) { diff --git a/ext/index/main.php b/ext/index/main.php index cc0cec0c..ace8824b 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -27,12 +27,9 @@ class SearchTermParseEvent extends Event { } class PostListBuildingEvent extends Event { - var $page = null; var $search_terms = null; - public function __construct(RequestContext $context, $search) { - parent::__construct($context); - $this->page = $context->page; + public function __construct($search) { $this->search_terms = $search; } } @@ -41,10 +38,10 @@ class Index 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 InitExtEvent) { - global $config; $config->set_default_int("index_width", 3); $config->set_default_int("index_height", 4); $config->set_default_bool("index_tips", true); @@ -54,12 +51,12 @@ class Index implements Extension { if(isset($_GET['search'])) { $search = url_escape(trim($_GET['search'])); if(empty($search)) { - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/list/1")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list/1")); } else { - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/list/$search/1")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list/$search/1")); } return; } @@ -77,25 +74,22 @@ class Index implements Extension { if($page_number == 0) $page_number = 1; // invalid -> 0 - global $config; - global $database; - - $total_pages = Image::count_pages($config, $database, $search_terms); + $total_pages = Image::count_pages($search_terms); $count = $config->get_int('index_width') * $config->get_int('index_height'); - $images = Image::find_images($config, $database, ($page_number-1)*$count, $count, $search_terms); + $images = Image::find_images(($page_number-1)*$count, $count, $search_terms); if(count($search_terms) == 0 && count($images) == 0 && $page_number == 0) { - $this->theme->display_intro($event->page); + $this->theme->display_intro($page); } else if(count($search_terms) > 0 && count($images) == 1) { - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/view/{$images[0]->id}")); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/view/{$images[0]->id}")); } else { - send_event(new PostListBuildingEvent($event->context, $search_terms)); + send_event(new PostListBuildingEvent($search_terms)); $this->theme->set_page($page_number, $total_pages, $search_terms); - $this->theme->display_page($event->page, $images); + $this->theme->display_page($page, $images); } } diff --git a/ext/setup/main.php b/ext/setup/main.php index ff5a87dd..42a10c33 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -139,10 +139,10 @@ class Setup 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 InitExtEvent) { - global $config; $config->set_default_string("title", "Shimmie"); $config->set_default_string("front_page", "post/list"); $config->set_default_string("main_page", "post/list"); @@ -151,33 +151,29 @@ class Setup implements Extension { } if(($event instanceof PageRequestEvent) && $event->page_matches("nicetest")) { - $event->page->set_mode("data"); - $event->page->set_data("ok"); + $page->set_mode("data"); + $page->set_data("ok"); } if(($event instanceof PageRequestEvent) && $event->page_matches("setup")) { - global $user; if(!$user->is_admin()) { - $this->theme->display_permission_denied($event->page); + $this->theme->display_permission_denied($page); } else { if($event->get_arg(0) == "save") { - global $config; send_event(new ConfigSaveEvent($config)); $config->save(); - global $page; $page->set_mode("redirect"); $page->set_redirect(make_link("setup")); } else if($event->get_arg(0) == "advanced") { - global $config; - $this->theme->display_advanced($event->page, $config->values); + $this->theme->display_advanced($page, $config->values); } else { $panel = new SetupPanel(); send_event(new SetupBuildingEvent($panel)); - $this->theme->display_page($event->page, $panel); + $this->theme->display_page($page, $panel); } } } @@ -234,22 +230,23 @@ class Setup implements Extension { } 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": $event->config->set_string($name, $value); break; - case "int": $event->config->set_int($name, $value); break; - case "bool": $event->config->set_bool($name, $value); break; + case "string": $config->set_string($name, $value); break; + case "int": $config->set_int($name, $value); break; + case "bool": $config->set_bool($name, $value); break; } } } } if($event instanceof UserBlockBuildingEvent) { - if($event->user->is_admin()) { + if($user->is_admin()) { $event->add_link("Board Config", make_link("setup")); } } diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index bdeeb834..77bf7e3d 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -36,16 +36,14 @@ class TagEdit 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("tag_edit")) { - global $page; if($event->get_arg(0) == "replace") { - global $user; if($user->is_admin() && isset($_POST['search']) && isset($_POST['replace'])) { $search = $_POST['search']; $replace = $_POST['replace']; - global $page; $this->mass_tag_edit($search, $replace); $page->set_mode("redirect"); $page->set_redirect(make_link("admin")); @@ -61,7 +59,7 @@ class TagEdit implements Extension { } } else { - $this->theme->display_error($event->page, "Error", "Anonymous tag editing is disabled"); + $this->theme->display_error($page, "Error", "Anonymous tag editing is disabled"); } } @@ -78,7 +76,7 @@ class TagEdit implements Extension { } if($event instanceof AdminBuildingEvent) { - $this->theme->display_mass_editor($event->page); + $this->theme->display_mass_editor($page); } // When an alias is added, oldtag becomes inaccessable @@ -87,8 +85,6 @@ class TagEdit implements Extension { } if($event instanceof ImageInfoBoxBuildingEvent) { - global $user; - global $config; if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) { $event->add_part($this->theme->get_tag_editor_html($event->image), 40); } @@ -130,7 +126,7 @@ class TagEdit implements Extension { $search_forward = $search_set; if($last_id >= 0) $search_forward[] = "id<$last_id"; - $images = Image::find_images($config, $database, 0, 100, $search_forward); + $images = Image::find_images(0, 100, $search_forward); if(count($images) == 0) break; foreach($images as $image) { diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 36685550..941c7c05 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -5,10 +5,10 @@ class TagList implements Extension { // event handling {{{ public function receive_event(Event $event) { + global $config, $database, $page, $user; if($this->theme == null) $this->theme = get_theme_object($this); if($event instanceof InitExtEvent) { - global $config; $config->set_default_int("tag_list_length", 15); $config->set_default_int("tags_min", 3); $config->set_default_string("info_link", 'http://en.wikipedia.org/wiki/$tag'); @@ -16,8 +16,6 @@ class TagList implements Extension { } if(($event instanceof PageRequestEvent) && $event->page_matches("tags")) { - global $page; - $this->theme->set_navigation($this->build_navigation()); switch($event->get_arg(0)) { default: @@ -42,25 +40,23 @@ class TagList implements Extension { } if($event instanceof PostListBuildingEvent) { - global $config; if($config->get_int('tag_list_length') > 0) { if(!empty($event->search_terms)) { - $this->add_refine_block($event->page, $event->search_terms); + $this->add_refine_block($page, $event->search_terms); } else { - $this->add_popular_block($event->page); + $this->add_popular_block($page); } } } if($event instanceof DisplayingImageEvent) { - global $config; if($config->get_int('tag_list_length') > 0) { if($config->get_string('tag_list_image_type') == 'related') { - $this->add_related_block($event->page, $event->image); + $this->add_related_block($page, $event->image); } else { - $this->add_tags_block($event->page, $event->image); + $this->add_tags_block($page, $event->image); } } } @@ -192,7 +188,7 @@ class TagList implements Extension { if($n%3==0) $html .= ""; $h_tag = html_escape($row['tag']); $link = $this->tag_link($row['tag']); - $image = Image::by_random($config, $database, array($row['tag'])); + $image = Image::by_random(array($row['tag'])); if(is_null($image)) continue; // one of the popular tags has no images $thumb = $image->get_thumb_link(); $html .= "
$h_tag
\n"; diff --git a/ext/upgrade/main.php b/ext/upgrade/main.php index ef963489..6be6e92a 100644 --- a/ext/upgrade/main.php +++ b/ext/upgrade/main.php @@ -3,13 +3,12 @@ class Upgrade implements Extension { public function receive_event(Event $event) { if($event instanceof InitExtEvent) { - $this->do_things($event->context); + $this->do_things(); } } - private function do_things($context) { - $config = $context->config; - $database = $context->database; + private function do_things() { + global $config, $database; if(!is_numeric($config->get_string("db_version"))) { $config->set_int("db_version", 2); diff --git a/ext/upload/main.php b/ext/upload/main.php index ad5c704b..9b48328c 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -30,6 +30,7 @@ class Upload implements Extension { var $theme; // event handling {{{ public function receive_event(Event $event) { + global $config, $database, $page, $user; if(is_null($this->theme)) $this->theme = get_theme_object($this); $is_full = (disk_free_space(realpath("./images/")) < 100*1024*1024); @@ -45,10 +46,10 @@ class Upload implements Extension { global $user; if($this->can_upload($user)) { if($is_full) { - $this->theme->display_full($event->page); + $this->theme->display_full($page); } else { - $this->theme->display_block($event->page); + $this->theme->display_block($page); } } } @@ -57,7 +58,6 @@ class Upload implements Extension { if(count($_FILES) + count($_POST) > 0) { $tags = Tag::explode($_POST['tags']); $source = isset($_POST['source']) ? $_POST['source'] : null; - global $user; if($this->can_upload($user)) { $ok = true; foreach($_FILES as $file) { @@ -69,10 +69,10 @@ class Upload implements Extension { } } - $this->theme->display_upload_status($event->page, $ok); + $this->theme->display_upload_status($page, $ok); } else { - $this->theme->display_permission_denied($event->page); + $this->theme->display_permission_denied($page); } } else if(!empty($_GET['url'])) { @@ -84,15 +84,15 @@ class Upload implements Extension { $tags = Tag::explode($_GET['tags']); } $ok = $this->try_transload($url, $tags, $url); - $this->theme->display_upload_status($event->page, $ok); + $this->theme->display_upload_status($page, $ok); } else { - $this->theme->display_permission_denied($event->page); + $this->theme->display_permission_denied($page); } } else { if(!$is_full) { - $this->theme->display_page($event->page); + $this->theme->display_page($page); } } } diff --git a/ext/user/main.php b/ext/user/main.php index f6c99e25..67b25dd4 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -2,12 +2,6 @@ class UserBlockBuildingEvent extends Event { var $parts = array(); - var $user = null; - - public function __construct(RequestContext $context) { - parent::__construct($context); - $this->user = $context->user; - } public function add_link($name, $link, $position=50) { while(isset($this->parts[$position])) $position++; @@ -18,8 +12,7 @@ class UserBlockBuildingEvent extends Event { class UserPageBuildingEvent extends Event { var $display_user; - public function __construct(RequestContext $context, User $display_user) { - parent::__construct($context); + public function __construct(User $display_user) { $this->display_user = $display_user; } } @@ -29,8 +22,7 @@ class UserCreationEvent extends Event { var $password; var $email; - public function __construct(RequestContext $context, $name, $pass, $email) { - parent::__construct($context); + public function __construct($name, $pass, $email) { $this->username = $name; $this->password = $pass; $this->email = $email; @@ -44,19 +36,16 @@ class UserPage implements Extension { // event handling {{{ 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) { - $event->context->config->set_default_bool("login_signup_enabled", true); - $event->context->config->set_default_int("login_memory", 365); + $config->set_default_bool("login_signup_enabled", true); + $config->set_default_int("login_memory", 365); } if(($event instanceof PageRequestEvent) && $event->page_matches("user_admin")) { - $user = $event->context->user; - $database = $event->context->database; - $config = $event->context->config; - $page = $event->context->page; - if($event->get_arg(0) == "login") { if(isset($_POST['user']) && isset($_POST['pass'])) { $this->login($page); @@ -86,7 +75,7 @@ class UserPage implements Extension { } else { try { - $uce = new UserCreationEvent($event->context, $_POST['name'], $_POST['pass1'], $_POST['email']); + $uce = new UserCreationEvent($_POST['name'], $_POST['pass1'], $_POST['email']); send_event($uce); $this->set_login_cookie($uce->username, $uce->password); $page->set_mode("redirect"); @@ -102,14 +91,9 @@ class UserPage implements Extension { } } if(($event instanceof PageRequestEvent) && $event->page_matches("user")) { - $user = $event->context->user; - $config = $event->context->config; - $database = $event->context->database; - $page = $event->context->page; - - $display_user = ($event->count_args() == 0) ? $user : User::by_name($config, $database, $event->get_arg(0)); + $display_user = ($event->count_args() == 0) ? $user : User::by_name($event->get_arg(0)); if(!is_null($display_user)) { - send_event(new UserPageBuildingEvent($event->context, $display_user)); + send_event(new UserPageBuildingEvent($display_user)); } else { $this->theme->display_error($page, "No Such User", @@ -119,31 +103,25 @@ class UserPage implements Extension { } if($event instanceof UserPageBuildingEvent) { - global $user; - global $config; - $this->theme->display_user_page($event->context->page, $event->display_user, $user); + $this->theme->display_user_page($page, $event->display_user, $user); if($user->id == $event->display_user->id) { - $ubbe = new UserBlockBuildingEvent($event->context); + $ubbe = new UserBlockBuildingEvent(); send_event($ubbe); ksort($ubbe->parts); - $this->theme->display_user_links($event->context->page, $event->context->user, $ubbe->parts); + $this->theme->display_user_links($page, $user, $ubbe->parts); } if(($user->is_admin() || $user->id == $event->display_user->id) && ($user->id != $config->get_int('anon_id'))) { - $this->theme->display_ip_list($event->context->page, $this->count_upload_ips($event->display_user), $this->count_comment_ips($event->display_user)); + $this->theme->display_ip_list($page, $this->count_upload_ips($event->display_user), $this->count_comment_ips($event->display_user)); } } // user info is shown on all pages if($event instanceof PageRequestEvent) { - $user = $event->context->user; - $database = $event->context->database; - $page = $event->context->page; - if($user->is_anonymous()) { $this->theme->display_login_block($page); } else { - $ubbe = new UserBlockBuildingEvent($event->context); + $ubbe = new UserBlockBuildingEvent(); send_event($ubbe); ksort($ubbe->parts); $this->theme->display_user_block($page, $user, $ubbe->parts); @@ -172,7 +150,7 @@ class UserPage implements Extension { if(preg_match("/^(poster|user)=(.*)$/i", $event->term, $matches)) { global $config; global $database; - $user = User::by_name($config, $database, $matches[2]); + $user = User::by_name($matches[2]); if(!is_null($user)) { $user_id = $user->id; } @@ -190,15 +168,13 @@ class UserPage implements Extension { // }}} // Things done *with* the user {{{ private function login($page) { - global $database; - global $config; global $user; $name = $_POST['user']; $pass = $_POST['pass']; $hash = md5(strtolower($name) . $pass); - $duser = User::by_name_and_hash($config, $database, $name, $hash); + $duser = User::by_name_and_hash($name, $hash); if(!is_null($duser)) { $user = $duser; $this->set_login_cookie($name, $pass); @@ -279,7 +255,7 @@ class UserPage implements Extension { $pass1 = $_POST['pass1']; $pass2 = $_POST['pass2']; - $duser = User::by_id($config, $database, $id); + $duser = User::by_id($id); if((!$user->is_admin()) && ($duser->name != $user->name)) { $page->add_block(new Block("Error", @@ -325,7 +301,7 @@ class UserPage implements Extension { else { $admin = (isset($_POST['admin']) && ($_POST['admin'] == "on")); - $duser = User::by_id($config, $database, $_POST['id']); + $duser = User::by_id($_POST['id']); $duser->set_admin($admin); $page->set_mode("redirect"); diff --git a/ext/user/theme.php b/ext/user/theme.php index 681e8c9f..0eb4f4ef 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -123,7 +123,7 @@ class UserPageTheme extends Themelet { global $config; $h_join_date = html_escape($duser->join_date); - $i_image_count = Image::count_images($config, $database, array("user_id={$duser->id}")); + $i_image_count = Image::count_images(array("user_id={$duser->id}")); $i_comment_count = Comment::count_comments_by_user($duser); #$h_image_rate = sprintf("%3.1f", ($i_image_count / $i_days_old2)); diff --git a/ext/view/main.php b/ext/view/main.php index b01e7be3..4703484c 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -11,10 +11,8 @@ class DisplayingImageEvent extends Event { var $image, $page, $context; - public function __construct(RequestContext $context, Image $image) { - parent::__construct($context); + public function __construct(Image $image) { $this->image = $image; - $this->page = $context->page; } public function get_image() { @@ -65,14 +63,13 @@ class ViewImage 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(is_a($event, 'PageRequestEvent') && ( $event->page_matches("post/prev") || $event->page_matches("post/next") )) { - global $config; - global $database; $image_id = int_escape($event->get_arg(0)); if(isset($_GET['search'])) { @@ -84,7 +81,7 @@ class ViewImage implements Extension { $query = null; } - $image = Image::by_id($config, $database, $image_id); + $image = Image::by_id($image_id); if($event->page_matches("post/next")) { $image = $image->get_next($search_terms); } @@ -93,50 +90,46 @@ class ViewImage implements Extension { } if(!is_null($image)) { - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/view/{$image->id}", $query)); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/view/{$image->id}", $query)); } else { - $this->theme->display_error($event->page, "Image not found", "No more images"); + $this->theme->display_error($page, "Image not found", "No more images"); } } if(($event instanceof PageRequestEvent) && $event->page_matches("post/view")) { $image_id = int_escape($event->get_arg(0)); - global $database; - global $config; - $image = Image::by_id($config, $database, $image_id); + $image = Image::by_id($image_id); if(!is_null($image)) { - send_event(new DisplayingImageEvent($event->context, $image)); - $iabbe = new ImageAdminBlockBuildingEvent($image, $event->user); + send_event(new DisplayingImageEvent($image)); + $iabbe = new ImageAdminBlockBuildingEvent($image, $user); send_event($iabbe); ksort($iabbe->parts); - $this->theme->display_admin_block($event->page, $iabbe->parts); + $this->theme->display_admin_block($page, $iabbe->parts); } else { - $this->theme->display_error($event->page, "Image not found", "No image in the database has the ID #$image_id"); + $this->theme->display_error($page, "Image not found", "No image in the database has the ID #$image_id"); } } if(($event instanceof PageRequestEvent) && $event->page_matches("post/set")) { - global $config, $database; $image_id = int_escape($_POST['image_id']); - send_event(new ImageInfoSetEvent(Image::by_id($config, $database, $image_id))); + send_event(new ImageInfoSetEvent(Image::by_id($image_id))); $query = $_POST['query']; - $event->page->set_mode("redirect"); - $event->page->set_redirect(make_link("post/view/$image_id", $query)); + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/view/$image_id", $query)); } if($event instanceof DisplayingImageEvent) { - global $user; $iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user); send_event($iibbe); ksort($iibbe->parts); - $this->theme->display_page($event->page, $event->get_image(), $iibbe->parts); + $this->theme->display_page($page, $event->get_image(), $iibbe->parts); } } } diff --git a/index.php b/index.php index db83fcbf..a2f88173 100644 --- a/index.php +++ b/index.php @@ -55,14 +55,9 @@ try { // start the page generation waterfall $page = new Page(); $user = _get_user($config, $database); - $context = new RequestContext(); - $context->page = $page; - $context->user = $user; - $context->database = $database; - $context->config = $config; - send_event(new InitExtEvent($context)); - send_event(_get_page_request($context)); - $context->page->display($context); + send_event(new InitExtEvent()); + send_event(_get_page_request()); + $page->display(); // for databases which support transactions diff --git a/themes/danbooru/layout.class.php b/themes/danbooru/layout.class.php index 4231da2a..4f51998d 100644 --- a/themes/danbooru/layout.class.php +++ b/themes/danbooru/layout.class.php @@ -42,9 +42,8 @@ Tips * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ class Layout { - public function display_page($context) { - $page = $context->page; - $config = $context->config; + public function display_page($page) { + global $config; $theme_name = $config->get_string('theme'); $base_href = $config->get_string('base_href'); diff --git a/themes/default/layout.class.php b/themes/default/layout.class.php index ea5369c3..34699c1d 100644 --- a/themes/default/layout.class.php +++ b/themes/default/layout.class.php @@ -1,9 +1,8 @@ page; - $config = $context->config; + function display_page($page) { + global $config; $theme_name = $config->get_string('theme', 'default'); $data_href = get_base_href(); diff --git a/themes/futaba/layout.class.php b/themes/futaba/layout.class.php index 0a6ea41c..fbb32d75 100644 --- a/themes/futaba/layout.class.php +++ b/themes/futaba/layout.class.php @@ -1,9 +1,8 @@ page; - $config = $context->config; + function display_page($page) { + global $config; $theme_name = $config->get_string('theme', 'default'); $data_href = get_base_href(); diff --git a/themes/minimal/layout.class.php b/themes/minimal/layout.class.php index 306da52f..ed37aa56 100644 --- a/themes/minimal/layout.class.php +++ b/themes/minimal/layout.class.php @@ -1,9 +1,8 @@ page; - $config = $context->config; + function display_page($page) { + global $config; $theme_name = $config->get_string('theme', 'default'); $data_href = get_base_href();