From 96a37605e47f568902ee22a4d50843b0932307f0 Mon Sep 17 00:00:00 2001 From: shish Date: Sat, 6 Sep 2008 17:48:03 +0000 Subject: [PATCH] port page_matches from score to trunk git-svn-id: file:///home/shish/svn/shimmie2/trunk@1028 7f39781d-f577-437e-ae19-be835c7a54ca --- contrib/bulk_add/main.php | 2 +- contrib/downtime/main.php | 2 +- contrib/et/main.php | 2 +- contrib/event_log/main.php | 2 +- contrib/featured/main.php | 2 +- contrib/handle_ico/main.php | 2 +- contrib/handle_svg/main.php | 2 +- contrib/home/main.php | 2 +- contrib/image_hash_ban/main.php | 2 +- contrib/ipban/main.php | 2 +- contrib/numeric_score/main.php | 2 +- contrib/random_image/main.php | 2 +- contrib/regen_thumb/main.php | 2 +- contrib/report_image/main.php | 2 +- contrib/rss_comments/main.php | 2 +- contrib/rss_images/main.php | 2 +- contrib/svn_update/main.php | 2 +- contrib/tag_history/main.php | 2 +- contrib/wiki/main.php | 2 +- core/event.class.php | 3 ++- core/util.inc.php | 15 ++------------- ext/admin/main.php | 4 ++-- ext/alias_editor/main.php | 2 +- ext/comment/main.php | 2 +- ext/ext_manager/main.php | 2 +- ext/image/main.php | 4 ++-- ext/index/main.php | 5 +---- ext/setup/main.php | 2 +- ext/tag_edit/main.php | 2 +- ext/tag_list/main.php | 2 +- ext/upload/main.php | 2 +- ext/user/main.php | 4 ++-- ext/view/main.php | 6 +++--- 33 files changed, 40 insertions(+), 53 deletions(-) diff --git a/contrib/bulk_add/main.php b/contrib/bulk_add/main.php index d9996bf3..d1bc925d 100644 --- a/contrib/bulk_add/main.php +++ b/contrib/bulk_add/main.php @@ -12,7 +12,7 @@ class BulkAdd implements Extension { public function receive_event(Event $event) { if(is_null($this->theme)) $this->theme = get_theme_object($this); - if(($event instanceof PageRequestEvent) && ($event->page_name == "bulk_add")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("bulk_add")) { if($event->user->is_admin() && isset($_POST['dir'])) { set_time_limit(0); diff --git a/contrib/downtime/main.php b/contrib/downtime/main.php index fbf9f55f..5cdfa5ab 100644 --- a/contrib/downtime/main.php +++ b/contrib/downtime/main.php @@ -40,7 +40,7 @@ class Downtime implements Extension { } private function is_safe_page($event) { - if($event->page_name == "user_admin" && $event->get_arg(0) == "login") return true; + if($event->page_matches("user_admin/login")) return true; else return false; } } diff --git a/contrib/et/main.php b/contrib/et/main.php index 4e1ea20a..64653548 100644 --- a/contrib/et/main.php +++ b/contrib/et/main.php @@ -12,7 +12,7 @@ class ET implements Extension { public function receive_event(Event $event) { if(is_null($this->theme)) $this->theme = get_theme_object($this); - if(($event instanceof PageRequestEvent) && ($event->page_name == "system_info")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("system_info")) { if($event->user->is_admin()) { $this->theme->display_info_page($event->page, $this->get_info()); } diff --git a/contrib/event_log/main.php b/contrib/event_log/main.php index da26aecc..7b82221a 100644 --- a/contrib/event_log/main.php +++ b/contrib/event_log/main.php @@ -16,7 +16,7 @@ class EventLog implements Extension { $this->setup(); } - if(($event instanceof PageRequestEvent) && $event->page_name == "event_log") { + if(($event instanceof PageRequestEvent) && $event->page_matches("event_log")) { global $database; if($event->user->is_admin()) { if(isset($_POST['action'])) { diff --git a/contrib/featured/main.php b/contrib/featured/main.php index fb1670c7..28e1e1ee 100644 --- a/contrib/featured/main.php +++ b/contrib/featured/main.php @@ -17,7 +17,7 @@ class Featured implements Extension { $config->set_default_int('featured_id', 0); } - if(($event instanceof PageRequestEvent) && ($event->page_name == "set_feature")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("set_feature")) { global $user; if($user->is_admin() && isset($_POST['image_id'])) { global $config; diff --git a/contrib/handle_ico/main.php b/contrib/handle_ico/main.php index 20df8315..344c3737 100644 --- a/contrib/handle_ico/main.php +++ b/contrib/handle_ico/main.php @@ -38,7 +38,7 @@ class IcoFileHandler implements Extension { $this->theme->display_image($event->page, $event->image); } - if(($event instanceof PageRequestEvent) && ($event->page_name == "get_ico")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("get_ico")) { global $database; $id = int_escape($event->get_arg(0)); $image = $database->get_image($id); diff --git a/contrib/handle_svg/main.php b/contrib/handle_svg/main.php index 7ba44a43..3941b5a4 100644 --- a/contrib/handle_svg/main.php +++ b/contrib/handle_svg/main.php @@ -48,7 +48,7 @@ class SVGFileHandler implements Extension { $this->theme->display_image($event->page, $event->image); } - if(($event instanceof PageRequestEvent) && ($event->page_name == "get_svg")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("get_svg")) { global $database; $id = int_escape($event->get_arg(0)); $image = $database->get_image($id); diff --git a/contrib/home/main.php b/contrib/home/main.php index ff803f18..6d6ca8bf 100644 --- a/contrib/home/main.php +++ b/contrib/home/main.php @@ -14,7 +14,7 @@ class Home implements Extension { public function receive_event(Event $event) { if(is_null($this->theme)) $this->theme = get_theme_object($this); - if(($event instanceof PageRequestEvent) && ($event->page_name == "home")) + 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); diff --git a/contrib/image_hash_ban/main.php b/contrib/image_hash_ban/main.php index 854ecbff..baeaeb0e 100644 --- a/contrib/image_hash_ban/main.php +++ b/contrib/image_hash_ban/main.php @@ -52,7 +52,7 @@ class ImageBan implements Extension { } } - if(($event instanceof PageRequestEvent) && ($event->page_name == "image_hash_ban")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("image_hash_ban")) { if($event->user->is_admin()) { if($event->get_arg(0) == "add") { if(isset($_POST['hash']) && isset($_POST['reason'])) { diff --git a/contrib/ipban/main.php b/contrib/ipban/main.php index 58b103f4..375dfe0e 100644 --- a/contrib/ipban/main.php +++ b/contrib/ipban/main.php @@ -45,7 +45,7 @@ class IPBan implements Extension { $this->check_ip_ban(); } - if(($event instanceof PageRequestEvent) && ($event->page_name == "ip_ban")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("ip_ban")) { global $user; if($user->is_admin()) { if($event->get_arg(0) == "add") { diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index 291246d4..ea3baa15 100644 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -37,7 +37,7 @@ class NumericScore implements Extension { } } - if(($event instanceof PageRequestEvent) && ($event->page_name == "numeric_score_vote")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("numeric_score_vote")) { if(!$event->user->is_anonymous()) { $image_id = int_escape($_POST['image_id']); $char = $_POST['vote']; diff --git a/contrib/random_image/main.php b/contrib/random_image/main.php index a4237fc9..962fec35 100644 --- a/contrib/random_image/main.php +++ b/contrib/random_image/main.php @@ -9,7 +9,7 @@ class RandomImage implements Extension { public function receive_event(Event $event) { - if(($event instanceof PageRequestEvent) && ($event->page_name == "random_image")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("random_image")) { global $database; if($event->count_args() == 1) { diff --git a/contrib/regen_thumb/main.php b/contrib/regen_thumb/main.php index 5529d1f8..ff968ddd 100644 --- a/contrib/regen_thumb/main.php +++ b/contrib/regen_thumb/main.php @@ -12,7 +12,7 @@ class RegenThumb implements Extension { public function receive_event(Event $event) { if(is_null($this->theme)) $this->theme = get_theme_object($this); - if(($event instanceof PageRequestEvent) && ($event->page_name == "regen_thumb")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("regen_thumb")) { global $user; if($user->is_admin() && isset($_POST['image_id'])) { global $database; diff --git a/contrib/report_image/main.php b/contrib/report_image/main.php index 5064cef6..8956a0d3 100755 --- a/contrib/report_image/main.php +++ b/contrib/report_image/main.php @@ -45,7 +45,7 @@ class ReportImage implements Extension { } } - if(($event instanceof PageRequestEvent) && ($event->page_name == "image_report")) { + 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'])) { diff --git a/contrib/rss_comments/main.php b/contrib/rss_comments/main.php index 8a061577..b29f5fb6 100644 --- a/contrib/rss_comments/main.php +++ b/contrib/rss_comments/main.php @@ -17,7 +17,7 @@ class RSS_Comments implements Extension { $page->add_header(""); } - if(($event instanceof PageRequestEvent) && ($event->page_name == "rss")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("rss")) { if($event->get_arg(0) == 'comments') { global $database; $this->do_rss($database); diff --git a/contrib/rss_images/main.php b/contrib/rss_images/main.php index a3b2dcf1..ff681157 100644 --- a/contrib/rss_images/main.php +++ b/contrib/rss_images/main.php @@ -25,7 +25,7 @@ class RSS_Images implements Extension { } } - if(($event instanceof PageRequestEvent) && ($event->page_name == "rss")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("rss")) { if($event->get_arg(0) == 'images') { global $database; if($event->count_args() >= 2) { diff --git a/contrib/svn_update/main.php b/contrib/svn_update/main.php index 5a8ba9e1..27156f3e 100644 --- a/contrib/svn_update/main.php +++ b/contrib/svn_update/main.php @@ -12,7 +12,7 @@ class SVNUpdate implements Extension { public function receive_event(Event $event) { if(is_null($this->theme)) $this->theme = get_theme_object($this); - if(($event instanceof PageRequestEvent) && ($event->page_name == "update")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("update")) { if($event->user->is_admin()) { if($event->get_arg(0) == "view_changes") { $this->theme->display_update_todo($event->page, diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 83b6a294..a654f355 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -19,7 +19,7 @@ class Tag_History implements Extension { } } - if(($event instanceof PageRequestEvent) && ($event->page_name == "tag_history")) + if(($event instanceof PageRequestEvent) && $event->page_matches("tag_history")) { if($event->get_arg(0) == "revert") { diff --git a/contrib/wiki/main.php b/contrib/wiki/main.php index 89ddade2..8f3d099a 100644 --- a/contrib/wiki/main.php +++ b/contrib/wiki/main.php @@ -62,7 +62,7 @@ class Wiki implements Extension { $this->setup(); } - if(($event instanceof PageRequestEvent) && ($event->page_name == "wiki")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("wiki")) { if(is_null($event->get_arg(0)) || strlen(trim($event->get_arg(0))) == 0) { $title = "Index"; } diff --git a/core/event.class.php b/core/event.class.php index 75071d14..cadfe1a1 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -133,6 +133,7 @@ class PageRequestEvent extends Event { parent::__construct($context); $this->args = $args; $this->arg_count = count($args); + $this->page = $context->page; } public function page_matches($name) { @@ -163,7 +164,7 @@ class PageRequestEvent extends Event { } public function count_args() { - return $this->arg_count; + return $this->arg_count - $this->part_count; } } diff --git a/core/util.inc.php b/core/util.inc.php index a41136d6..510921bb 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -535,24 +535,13 @@ function _get_query_parts() { } function _get_page_request($context) { - global $config; $args = _get_query_parts(); if(count($args) == 0 || strlen($args[0]) == 0) { - $parts = split('/', $config->get_string('front_page')); - $page_name = array_shift($parts); - $args = $parts; - } - else if(count($args) == 1) { - $page_name = $args[0]; - $args = array(); - } - else { - $page_name = $args[0]; - $args = array_slice($args, 1); + $args = split('/', $context->config->get_string('front_page')); } - return new PageRequestEvent($context, $page_name, $args); + return new PageRequestEvent($context, $args); } function _get_user($config, $database) { diff --git a/ext/admin/main.php b/ext/admin/main.php index a57a58ab..28908ae9 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -17,7 +17,7 @@ class AdminPage implements Extension { public function receive_event(Event $event) { if(is_null($this->theme)) $this->theme = get_theme_object($this); - if(($event instanceof PageRequestEvent) && ($event->page_name == "admin")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("admin")) { if(!$event->user->is_admin()) { $this->theme->display_error($event->page, "Permission Denied", "This page is for admins only"); } @@ -41,7 +41,7 @@ class AdminPage implements Extension { } } - if(($event instanceof PageRequestEvent) && ($event->page_name == "admin_utils")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("admin_utils")) { if($event->user->is_admin()) { set_time_limit(0); $redirect = false; diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 4383facc..e7db9aff 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -16,7 +16,7 @@ class AliasEditor implements Extension { public function receive_event(Event $event) { if(is_null($this->theme)) $this->theme = get_theme_object($this); - if(($event instanceof PageRequestEvent) && ($event->page_name == "alias")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("alias")) { if($event->get_arg(0) == "add") { if($event->user->is_admin()) { if(isset($_POST['oldtag']) && isset($_POST['newtag'])) { diff --git a/ext/comment/main.php b/ext/comment/main.php index 9d5aee3d..f9511ea2 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -66,7 +66,7 @@ class CommentList implements Extension { } } - if(($event instanceof PageRequestEvent) && ($event->page_name == "comment")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("comment")) { if($event->get_arg(0) == "add") { $cpe = new CommentPostingEvent($_POST['image_id'], $event->user, $_POST['comment']); send_event($cpe); diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php index e6e99547..2983b35e 100644 --- a/ext/ext_manager/main.php +++ b/ext/ext_manager/main.php @@ -59,7 +59,7 @@ class ExtManager implements Extension { public function receive_event(Event $event) { if(is_null($this->theme)) $this->theme = get_theme_object($this); - if(($event instanceof PageRequestEvent) && ($event->page_name == "ext_manager")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("ext_manager")) { if($event->user->is_admin()) { if($event->get_arg(0) == "set") { if(is_writable("ext")) { diff --git a/ext/image/main.php b/ext/image/main.php index 9746b9f2..cca1bdde 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -25,10 +25,10 @@ class ImageIO implements Extension { if(!is_null($num) && preg_match("/(\d+)/", $num, $matches)) { $num = $matches[1]; - if($event->page_name == "image") { + if($event->page_matches("image")) { $this->send_file($num, "image"); } - else if($event->page_name == "thumb") { + else if($event->page_matches("thumb")) { $this->send_file($num, "thumb"); } } diff --git a/ext/index/main.php b/ext/index/main.php index a5244050..2d24628c 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -23,10 +23,7 @@ class Index implements Extension { $config->set_default_bool("index_tips", true); } - if(($event instanceof PageRequestEvent) && (($event->page_name == "index") || - ($event->page_name == "post" && $event->get_arg(0) == "list"))) { - if($event->page_name == "post") array_shift($event->args); - + if(($event instanceof PageRequestEvent) && $event->page_matches("post/list")) { if(isset($_GET['search'])) { $search = url_escape(trim($_GET['search'])); if(empty($search)) { diff --git a/ext/setup/main.php b/ext/setup/main.php index cb76e93d..105a66fd 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -137,7 +137,7 @@ class Setup implements Extension { $config->set_default_string("theme", "default"); } - if(($event instanceof PageRequestEvent) && ($event->page_name == "setup")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("setup")) { global $user; if(!$user->is_admin()) { $this->theme->display_error($event->page, "Permission Denied", "This page is for admins only"); diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index 6813e39b..0c74993d 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -6,7 +6,7 @@ class TagEdit implements Extension { public function receive_event(Event $event) { if(is_null($this->theme)) $this->theme = get_theme_object($this); - if(($event instanceof PageRequestEvent) && ($event->page_name == "tag_edit")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("tag_edit")) { global $page; if($event->get_arg(0) == "replace") { global $user; diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index ab858fd2..4f7b3cd4 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -15,7 +15,7 @@ class TagList implements Extension { $config->set_default_string("tag_list_image_type", 'related'); } - if(($event instanceof PageRequestEvent) && ($event->page_name == "tags")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("tags")) { global $page; $this->theme->set_navigation($this->build_navigation()); diff --git a/ext/upload/main.php b/ext/upload/main.php index 6e72eb49..55f3752a 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -27,7 +27,7 @@ class Upload implements Extension { } } - if(($event instanceof PageRequestEvent) && ($event->page_name == "upload")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("upload")) { if(count($_FILES) + count($_POST) > 0) { $tags = tag_explode($_POST['tags']); $source = isset($_POST['source']) ? $_POST['source'] : null; diff --git a/ext/user/main.php b/ext/user/main.php index 3cdb27c3..9b2028a8 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -49,7 +49,7 @@ class UserPage implements Extension { $config->set_default_int("login_memory", 365); } - if(($event instanceof PageRequestEvent) && ($event->page_name == "user_admin")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("user_admin")) { global $user; global $database; global $config; @@ -97,7 +97,7 @@ class UserPage implements Extension { $this->set_more_wrapper($event->page); } } - if(($event instanceof PageRequestEvent) && ($event->page_name == "user")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("user")) { global $user; global $config; global $database; diff --git a/ext/view/main.php b/ext/view/main.php index ec65f369..679b42d0 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -45,8 +45,8 @@ class ViewImage implements Extension { public function receive_event(Event $event) { if(is_null($this->theme)) $this->theme = get_theme_object($this); - if(($event instanceof PageRequestEvent) && ($event->page_name == "post") && ($event->get_arg(0) == "view")) { - $image_id = int_escape($event->get_arg(1)); + if(($event instanceof PageRequestEvent) && $event->page_matches("post/view")) { + $image_id = int_escape($event->get_arg(0)); global $database; $image = $database->get_image($image_id); @@ -63,7 +63,7 @@ class ViewImage implements Extension { } } - if(($event instanceof PageRequestEvent) && ($event->page_name == "post") && ($event->get_arg(0) == "set")) { + if(($event instanceof PageRequestEvent) && $event->page_matches("post/set")) { $image_id = int_escape($_POST['image_id']); send_event(new ImageInfoSetEvent($image_id));