diff --git a/core/util.inc.php b/core/util.inc.php index 34aa782a..a2f8af64 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -317,6 +317,19 @@ function array_contains($array, $target) { return false; } +// from http://uk.php.net/network +function ip_in_range($IP, $CIDR) { + list ($net, $mask) = split ("/", $CIDR); + + $ip_net = ip2long ($net); + $ip_mask = ~((1 << (32 - $mask)) - 1); + + $ip_ip = ip2long ($IP); + + $ip_ip_net = $ip_ip & $ip_mask; + + return ($ip_ip_net == $ip_net); +} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Event API * diff --git a/ext/ipban/main.php b/ext/ipban/main.php index d486a8a6..2c03be6a 100644 --- a/ext/ipban/main.php +++ b/ext/ipban/main.php @@ -31,7 +31,7 @@ class IPBan extends Extension { if(is_a($event, 'InitExtEvent')) { global $config; - if($config->get_int("ext_ipban_version") < 2) { + if($config->get_int("ext_ipban_version") < 5) { $this->install(); } @@ -94,9 +94,13 @@ class IPBan extends Extension { global $config; global $database; + $remote = $_SERVER['REMOTE_ADDR']; $bans = $this->get_active_bans(); foreach($bans as $row) { - if($row['ip'] == $_SERVER['REMOTE_ADDR']) { + if( + (strstr($row['ip'], '/') && ip_in_range($remote, $row['ip'])) || + ($row['ip'] == $remote) + ) { $admin = $database->get_user_by_id($row['banner_id']); print "IP {$row['ip']} has been banned by {$admin->name} because of {$row['reason']}"; diff --git a/ext/ipban/schema.xml b/ext/ipban/schema.xml index 7b68487a..10a8e68e 100644 --- a/ext/ipban/schema.xml +++ b/ext/ipban/schema.xml @@ -4,7 +4,7 @@ - + @@ -14,6 +14,6 @@ DELETE FROM config WHERE name='ext_ipban_version' - INSERT INTO config(name, value) VALUES('ext_ipban_version', 3) + INSERT INTO config(name, value) VALUES('ext_ipban_version', 5) diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 8ab59e79..42523953 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -12,6 +12,7 @@ class TagList extends Extension { $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'); + $config->set_default_string("tag_list_image_type", 'related'); } if(is_a($event, 'PageRequestEvent') && ($event->page_name == "tags")) { @@ -51,7 +52,12 @@ class TagList extends Extension { if(is_a($event, 'DisplayingImageEvent')) { global $config; if($config->get_int('tag_list_length') > 0) { - $this->add_related_block($event->page, $event->image); + if($config->get_string('tag_list_image_type') == 'related') { + $this->add_related_block($event->page, $event->image); + } + else { + $this->add_tags_block($event->page, $event->image); + } } } @@ -63,6 +69,10 @@ class TagList extends Extension { $sb = new SetupBlock("Popular / Related Tag List"); $sb->add_int_option("tag_list_length", "Show top "); $sb->add_label(" tags"); $sb->add_text_option("info_link", "
Tag info link: "); + $sb->add_choice_option("tag_list_image_type", array( + "Image's tags only" => "tags", + "Show related" => "related" + ), "
Image tag list: "); $sb->add_bool_option("tag_list_numbers", "
Show tag counts: "); $event->panel->add_block($sb); } @@ -194,6 +204,26 @@ class TagList extends Extension { } } + private function add_tags_block($page, $image) { + global $database; + global $config; + + $query = " + SELECT tags.tag, tags.count + FROM tags, image_tags + WHERE tags.id = image_tags.tag_id + AND image_tags.image_id = ? + ORDER BY count DESC + LIMIT ? + "; + $args = array($image->id, $config->get_int('tag_list_length')); + + $tags = $database->get_all($query, $args); + if(count($tags) > 0) { + $this->theme->display_related_block($page, $tags); + } + } + private function add_popular_block($page) { global $database; global $config;