port page_matches from score to trunk

git-svn-id: file:///home/shish/svn/shimmie2/trunk@1028 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2008-09-06 17:48:03 +00:00
parent 7030727a6d
commit 96a37605e4
33 changed files with 40 additions and 53 deletions

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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());
}

View file

@ -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'])) {

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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'])) {

View file

@ -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") {

View file

@ -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'];

View file

@ -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) {

View file

@ -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;

View file

@ -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'])) {

View file

@ -17,7 +17,7 @@ class RSS_Comments implements Extension {
$page->add_header("<link rel=\"alternate\" type=\"application/rss+xml\" ".
"title=\"$title - Comments\" href=\"".make_link("rss/comments")."\" />");
}
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);

View file

@ -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) {

View file

@ -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,

View file

@ -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")
{

View file

@ -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";
}

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -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;

View file

@ -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'])) {

View file

@ -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);

View file

@ -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")) {

View file

@ -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");
}
}

View file

@ -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)) {

View file

@ -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");

View file

@ -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;

View file

@ -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());

View file

@ -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;

View file

@ -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;

View file

@ -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));