From 2d451224dd4cab62b87b9c77af7ba97371d97fc4 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 22 May 2012 12:14:46 +0100 Subject: [PATCH 1/9] only one of tags/image-specific-tags needs filling --- ext/upload/main.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/upload/main.php b/ext/upload/main.php index f88db765..06723691 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -215,7 +215,9 @@ class Upload extends Extension { private function tags_for_upload_slot($id) { if(isset($_POST["tags$id"])) { - $tags = array_merge(Tag::explode($_POST['tags']), Tag::explode($_POST["tags$id"])); + # merge then explode, not explode then merge - else + # one of the merges may create a surplus "tagme" + $tags = Tag::explode($_POST['tags'] . " " . $_POST["tags$id"]); } else { $tags = Tag::explode($_POST['tags']); From cb8b4f3329084fbc31676c535bde72aaf0da4ab3 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 22 May 2012 12:26:47 +0100 Subject: [PATCH 2/9] have a single var for memory limit --- ext/et/main.php | 2 +- ext/handle_ico/main.php | 2 +- ext/handle_pixel/main.php | 1 - ext/image/main.php | 4 +++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ext/et/main.php b/ext/et/main.php index 6b087d57..65b72b97 100644 --- a/ext/et/main.php +++ b/ext/et/main.php @@ -54,7 +54,7 @@ class ET extends Extension { $info['thumb_quality'] = $config->get_int('thumb_quality'); $info['thumb_width'] = $config->get_int('thumb_width'); $info['thumb_height'] = $config->get_int('thumb_height'); - $info['thumb_mem'] = $config->get_int("thumb_max_memory"); + $info['thumb_mem'] = $config->get_int("thumb_mem_limit"); $info['stat_images'] = $database->get_one("SELECT COUNT(*) FROM images"); $info['stat_comments'] = $database->get_one("SELECT COUNT(*) FROM comments"); diff --git a/ext/handle_ico/main.php b/ext/handle_ico/main.php index 7582fc53..1d642b0f 100644 --- a/ext/handle_ico/main.php +++ b/ext/handle_ico/main.php @@ -97,7 +97,7 @@ class IcoFileHandler extends Extension { $w = $config->get_int("thumb_width"); $h = $config->get_int("thumb_height"); $q = $config->get_int("thumb_quality"); - $mem = $config->get_int("thumb_max_memory") / 1024 / 1024; // IM takes memory in MB + $mem = $config->get_int("thumb_mem_limit") / 1024 / 1024; // IM takes memory in MB if($config->get_bool("ico_convert")) { // "-limit memory $mem" broken? diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 2f1ba9ae..c6779247 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -90,7 +90,6 @@ class PixelFileHandler extends DataHandlerExtension { $w = $config->get_int("thumb_width"); $h = $config->get_int("thumb_height"); $q = $config->get_int("thumb_quality"); - $mem = $config->get_int("thumb_max_memory") / 1024 / 1024; // IM takes memory in MB // Windows is a special case if(in_array("OS", $_SERVER) && $_SERVER["OS"] == 'Windows_NT') { diff --git a/ext/image/main.php b/ext/image/main.php index 836c65e9..29f71dc5 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -267,7 +267,9 @@ class ImageIO extends Extension { $sb->add_int_option("thumb_quality"); $sb->add_label(" % quality "); - $sb->add_shorthand_int_option("thumb_mem_limit", "
Max memory use: "); + if($config->get_string("thumb_engine") == "gd") { + $sb->add_shorthand_int_option("thumb_mem_limit", "
Max memory use: "); + } $event->panel->add_block($sb); } From 2e76add61bf1f8c3746939eb330fe608e73b315b Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 22 May 2012 12:46:56 +0100 Subject: [PATCH 3/9] enhance zglob to allow really long patterns --- core/util.inc.php | 24 +++++++++++++++++++----- ext/ext_manager/main.php | 4 ++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/core/util.inc.php b/core/util.inc.php index b7b0baec..4bf59033 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -386,10 +386,24 @@ function mtimefile($file) { return "$data_href/$file?$mtime"; } +/* + * like glob, with support for matching very long patterns with braces + */ function zglob($pattern) { - $r = glob($pattern); - if($r) return $r; - else return array(); + $results = array(); + if(preg_match('/(.*)\{(.*)\}(.*)/', $pattern, $matches)) { + $braced = explode(",", $matches[2]); + foreach($braced as $b) { + $sub_pattern = $matches[1].$b.$matches[3]; + $results = array_merge($results, zglob($sub_pattern)); + } + return $results; + } + else { + $r = glob($pattern); + if($r) return $r; + else return array(); + } } @@ -1088,8 +1102,8 @@ function _get_themelet_files($_theme) { $base_themelets[] = 'themes/'.$_theme.'/layout.class.php'; $base_themelets[] = 'themes/'.$_theme.'/themelet.class.php'; - $ext_themelets = glob("ext/{".ENABLED_EXTS."}/theme.php", GLOB_BRACE); - $custom_themelets = glob('themes/'.$_theme.'/{'.ENABLED_EXTS.'}.theme.php', GLOB_BRACE); + $ext_themelets = zglob("ext/{".ENABLED_EXTS."}/theme.php"); + $custom_themelets = zglob('themes/'.$_theme.'/{'.ENABLED_EXTS.'}.theme.php'); return array_merge($base_themelets, $ext_themelets, $custom_themelets); } diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php index 696f5046..851ebdbf 100644 --- a/ext/ext_manager/main.php +++ b/ext/ext_manager/main.php @@ -141,10 +141,10 @@ class ExtManager extends Extension { private function get_extensions(/*bool*/ $all) { $extensions = array(); if($all) { - $exts = glob("ext/*/main.php", GLOB_BRACE); + $exts = zglob("ext/*/main.php"); } else { - $exts = glob("ext/{".ENABLED_EXTS."}/main.php", GLOB_BRACE); + $exts = zglob("ext/{".ENABLED_EXTS."}/main.php"); } foreach($exts as $main) { $extensions[] = new ExtensionInfo($main); From bfd4ddea17c945b038fa040c639bff4cf18f7a5d Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 23 May 2012 10:39:21 +0100 Subject: [PATCH 4/9] check for classes being loaded, not files existing --- ext/home/main.php | 4 ++-- ext/image/main.php | 2 +- ext/upload/main.php | 2 +- ext/upload/theme.php | 8 ++++---- themes/danbooru/layout.class.php | 8 ++++---- themes/danbooru/view.theme.php | 2 +- themes/lite/layout.class.php | 8 ++++---- themes/lite/view.theme.php | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ext/home/main.php b/ext/home/main.php index 548b8ea7..ca00a98d 100644 --- a/ext/home/main.php +++ b/ext/home/main.php @@ -70,8 +70,8 @@ class Home extends Extension { } else { $main_links = '[url=site://post/list]Posts[/url] [url=site://comment/list]Comments[/url] [url=site://tags]Tags[/url]'; - if(file_exists("ext/pools")) {$main_links .= ' [url=site://pools]Pools[/url]';} - if(file_exists("ext/wiki")) {$main_links .= ' [url=site://wiki]Wiki[/url]';} + if(class_exists("Pools")) {$main_links .= ' [url=site://pools]Pools[/url]';} + if(class_exists("Wiki")) {$main_links .= ' [url=site://wiki]Wiki[/url]';} $main_links .= ' [url=site://ext_doc]>>[/url]'; } $main_links = format_text($main_links); diff --git a/ext/image/main.php b/ext/image/main.php index 29f71dc5..6f72a557 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -295,7 +295,7 @@ class ImageIO extends Extension { if($handler == "merge" || isset($_GET['update'])) { $merged = array_merge($image->get_tag_array(), $existing->get_tag_array()); send_event(new TagSetEvent($existing, $merged)); - if(isset($_GET['rating']) && isset($_GET['update']) && file_exists("ext/rating")){ + if(isset($_GET['rating']) && isset($_GET['update']) && class_exists("Ratings")){ send_event(new RatingSetEvent($existing, $user, $_GET['rating'])); } if(isset($_GET['source']) && isset($_GET['update'])){ diff --git a/ext/upload/main.php b/ext/upload/main.php index 06723691..c836f03f 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -329,7 +329,7 @@ class Upload extends Extension { } // Checks if url contains rating, also checks if the rating extension is enabled. - if($config->get_string("transload_engine", "none") != "none" && file_exists("ext/rating") && !empty($_GET['rating'])) { + if($config->get_string("transload_engine", "none") != "none" && class_exists("Ratings") && !empty($_GET['rating'])) { // Rating event will validate that this is s/q/e/u $rating = strtolower($_GET['rating']); $rating = $rating[0]; diff --git a/ext/upload/theme.php b/ext/upload/theme.php index 80494214..8fe5c3fe 100644 --- a/ext/upload/theme.php +++ b/ext/upload/theme.php @@ -215,10 +215,10 @@ class UploadTheme extends Themelet { // Bookmarklet checks if shimmie supports ext. If not, won't upload to site/shows alert saying not supported. $supported_ext = "jpg jpeg gif png"; - if(file_exists("ext/handle_flash")){$supported_ext .= " swf";} - if(file_exists("ext/handle_ico")){$supported_ext .= " ico ani cur";} - if(file_exists("ext/handle_mp3")){$supported_ext .= " mp3";} - if(file_exists("ext/handle_svg")){$supported_ext .= " svg";} + if(class_exists("FlashFileHandler")){$supported_ext .= " swf";} + if(class_exists("ICOFileHandler")){$supported_ext .= " ico ani cur";} + if(class_exists("MP3FileHandler")){$supported_ext .= " mp3";} + if(class_exists("SVGFileHandler")){$supported_ext .= " svg";} $title = "Booru to " . $config->get_string('title'); // CA=0: Ask to use current or new tags | CA=1: Always use current tags | CA=2: Always use new tags $html .= '

Day/Month/Year";} + if(class_exists("NumericScore")){ $custom_sublinks .= "

  • Popular by Day/Month/Year
  • ";} $custom_sublinks .= "
  • All
  • "; - if(file_exists("ext/favorites")){ $custom_sublinks .= "
  • My Favorites
  • ";} - if(file_exists("ext/rss_images")){ $custom_sublinks .= "
  • Feed
  • ";} - if(file_exists("ext/random_image")){ $custom_sublinks .= "
  • Random Image
  • ";} + if(class_exists("Favorites")){ $custom_sublinks .= "
  • My Favorites
  • ";} + if(class_exists("RSS_Images")){ $custom_sublinks .= "
  • Feed
  • ";} + if(class_exists("RandomImage")){ $custom_sublinks .= "
  • Random Image
  • ";} if($hw){ $custom_sublinks .= "
  • Help
  • "; }else{ $custom_sublinks .= "
  • Help
  • ";} break; diff --git a/themes/danbooru/view.theme.php b/themes/danbooru/view.theme.php index c5823dbd..d7f0008b 100644 --- a/themes/danbooru/view.theme.php +++ b/themes/danbooru/view.theme.php @@ -38,7 +38,7 @@ class CustomViewImageTheme extends ViewImageTheme { $html .= "
    Source: link"; } - if(file_exists("ext/rating")) { + if(class_exists("Ratings")) { if($image->rating == null || $image->rating == "u"){ $image->rating = "u"; } diff --git a/themes/lite/layout.class.php b/themes/lite/layout.class.php index 14ea1e88..39364bc4 100644 --- a/themes/lite/layout.class.php +++ b/themes/lite/layout.class.php @@ -94,11 +94,11 @@ class Layout { # the subnav links aren't shown, but it would # be nice to be correct case "post": - if(file_exists("ext/numeric_score")){ $cs .= "Popular by Day/Month/Year ";} + if(class_exists("NumericScore")){ $cs .= "Popular by Day/Month/Year ";} $cs .= "All"; - if(file_exists("ext/favorites")){ $cs .= "My Favorites";} - if(file_exists("ext/rss_images")){ $cs .= "Feed";} - if(file_exists("ext/random_image")){ $cs .= "Random Image";} + if(class_exists("Favorites")){ $cs .= "My Favorites";} + if(class_exists("RSS_Images")){ $cs .= "Feed";} + if(class_exists("Random_Image")){ $cs .= "Random Image";} if($hw){ $cs .= "Help"; }else{ $cs .= "Help";} break; diff --git a/themes/lite/view.theme.php b/themes/lite/view.theme.php index a30c5b1d..c86ceb92 100644 --- a/themes/lite/view.theme.php +++ b/themes/lite/view.theme.php @@ -44,7 +44,7 @@ class CustomViewImageTheme extends ViewImageTheme { $html .= "
    Source: link"; } - if(file_exists("ext/rating")) { + if(class_exists("Ratings")) { if($image->rating == null || $image->rating == "u"){ $image->rating = "u"; } From 5fdb54c9ec2a38da25408a492ec6ae0f3cce404b Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 23 May 2012 11:35:30 +0100 Subject: [PATCH 5/9] missed a couple of big globs --- ext/simpletest/main.php | 2 +- index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/simpletest/main.php b/ext/simpletest/main.php index cedba90d..7f44c8e9 100644 --- a/ext/simpletest/main.php +++ b/ext/simpletest/main.php @@ -200,7 +200,7 @@ class TestFinder extends TestSuite { $dir = "{".ENABLED_EXTS."}"; if(file_exists("ext/$hint/test.php")) $dir = $hint; $this->TestSuite('All tests'); - foreach(glob("ext/$dir/test.php", GLOB_BRACE) as $file) { + foreach(zglob("ext/$dir/test.php") as $file) { $this->addFile($file); } } diff --git a/index.php b/index.php index 5778e931..5f1ac93f 100644 --- a/index.php +++ b/index.php @@ -67,7 +67,7 @@ _start_cache(); try { // load base files ctx_log_start("Opening files"); - $files = array_merge(glob("core/*.php"), glob("ext/{".ENABLED_EXTS."}/main.php", GLOB_BRACE)); + $files = array_merge(zglob("core/*.php"), zglob("ext/{".ENABLED_EXTS."}/main.php")); foreach($files as $filename) { require_once $filename; } From 4f8332f3f75ab8bf0fda0b14f2604559ac5acb1d Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 23 May 2012 11:50:04 +0100 Subject: [PATCH 6/9] use the global and well tested make_http() rather than local hostify() --- ext/link_image/main.php | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/ext/link_image/main.php b/ext/link_image/main.php index dd4e91d0..3183a41d 100644 --- a/ext/link_image/main.php +++ b/ext/link_image/main.php @@ -21,16 +21,6 @@ class LinkImage extends Extension { $config->set_default_string("ext_link-img_text-link_format", '$title - $id ($ext $size $filesize)'); } - private function hostify(/*string*/ $str) { - $str = str_replace(" ", "%20", $str); - if(strpos($str, "ttp://") > 0) { - return $str; - } - else { - return "http://" . $_SERVER["HTTP_HOST"] . $str; - } - } - private function data(Image $image) { global $config; @@ -38,9 +28,9 @@ class LinkImage extends Extension { $text_link = trim($text_link) == "" ? null : $text_link; // null blank setting so the url gets filled in on the text links. return array( - 'thumb_src' => $this->hostify($image->get_thumb_link()), - 'image_src' => $this->hostify($image->get_image_link()), - 'post_link' => $this->hostify($_SERVER["REQUEST_URI"]), + 'thumb_src' => make_http($image->get_thumb_link()), + 'image_src' => make_http($image->get_image_link()), + 'post_link' => make_http($_SERVER["REQUEST_URI"]), 'text_link' => $text_link); } } From a809e95ff1a42de556e25aa4a7d77d57437f37ae Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 28 May 2012 09:46:16 +0100 Subject: [PATCH 7/9] anonymous functions are php 5.3, shimmie aims for 5.2.6 --- ext/mass_tagger/main.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ext/mass_tagger/main.php b/ext/mass_tagger/main.php index f91c05a5..ff3d91d7 100644 --- a/ext/mass_tagger/main.php +++ b/ext/mass_tagger/main.php @@ -38,13 +38,11 @@ class MassTagger extends Extension { $ids = explode( ':', $_POST['ids'] ); $ids = array_filter ( $ids , 'is_numeric' ); - $ids = array_map( "Image::by_id", $ids ); + $images = array_map( "Image::by_id", $ids ); - $func = function( $image ) use ( $tag ) { - $tag .= " " . $image->get_tag_list(); - $image->set_tags( $tag ); - }; - array_walk( $ids, $func ); + foreach($images as $image) { + $image->set_tags($tag . " " . $image->get_tag_list()); + } $page->set_mode("redirect"); $page->set_redirect(make_link("post/list")); From 5d431b9b037bd2a30f68abb7a5556bf65884dade Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 28 May 2012 09:55:55 +0100 Subject: [PATCH 8/9] apparently 'false' is an object with length, and the length is 1. Fuck PHP. --- ext/tag_list/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index e90af658..44f65837 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -438,7 +438,7 @@ class TagList extends Extension { } } - if(count($related_tags) > 0) { + if(!empty($related_tags)) { $this->theme->display_refine_block($page, $related_tags, $wild_tags); } } From d167d25942fbab876aa441204d93199f634f2929 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 28 May 2012 10:03:17 +0100 Subject: [PATCH 9/9] don't add navblock if there is already one --- core/basethemelet.class.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index 075122fa..ef9b3a42 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -11,7 +11,16 @@ class BaseThemelet { $page->add_http_header("HTTP/1.0 $code $title"); $page->set_title($title); $page->set_heading($title); - $page->add_block(new NavBlock()); + $has_nav = false; + foreach($page->blocks as $block) { + if($block->header == "Navigation") { + $has_nav = true; + break; + } + } + if(!$has_nav) { + $page->add_block(new NavBlock()); + } $page->add_block(new Block("Error", $message)); }