diff --git a/.htaccess b/.htaccess index 8e33b6f3..30a33a42 100644 --- a/.htaccess +++ b/.htaccess @@ -53,6 +53,7 @@ AddType audio/ogg oga ogg opus AddType image/jpeg jpg jpeg AddType image/bmp bmp AddType image/svg+xml svg svgz +AddType image/x-icon ico ani cur AddType image/webp webp AddType video/mp4 f4v f4p m4v mp4 AddType video/ogg ogv diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index b619f3d5..0827b411 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -1102,6 +1102,11 @@ class Tag { $tag = preg_replace("/^(\.+[\/\\\\])+/", "", $tag); # trailing slashes? $tag = trim($tag, ", \t\n\r\0\x0B"); + if(mb_strlen($tag, 'UTF-8') > 255){ + flash_message("The tag below is longer than 255 characters, please use a shorter tag.\n$tag\n"); + continue; + } + if(!empty($tag)) { $tag_array[] = $tag; } diff --git a/core/util.inc.php b/core/util.inc.php index 94cf1eb0..1d5460f9 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -15,6 +15,16 @@ function html_escape($input) { return htmlentities($input, ENT_QUOTES, "UTF-8"); } +/** + * Unescape data that was made safe for printing into HTML + * + * @param $input + * @return string + */ +function html_unescape($input) { + return html_entity_decode($input, ENT_QUOTES, "UTF-8"); +} + /** * Make sure some data is safe to be used in integer context * diff --git a/ext/arrowkey_navigation/main.php b/ext/arrowkey_navigation/main.php index 75cc22bd..023ca87b 100644 --- a/ext/arrowkey_navigation/main.php +++ b/ext/arrowkey_navigation/main.php @@ -47,6 +47,7 @@ class ArrowkeyNavigation extends Extension { (function($){ $(document).keyup(function(e) { if($(e.target).is('input', 'textarea')){ return; } + if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) { return; } if (e.keyCode == 37) { window.location.href = '{$prev_url}'; } else if (e.keyCode == 39) { window.location.href = '{$next_url}'; } }); diff --git a/ext/comment/theme.php b/ext/comment/theme.php index 20e963f9..f017bdb3 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -259,8 +259,6 @@ class CommentListTheme extends Themelet { else { $h_userlink = ''.$h_name.''; } - $stripped_nonl = str_replace("\n", "\\n", substr($tfe->stripped, 0, 50)); - $stripped_nonl = str_replace("\r", "\\r", $stripped_nonl); $hb = ($comment->owner_class == "hellbanned" ? "hb" : ""); if($trim) { @@ -280,9 +278,14 @@ class CommentListTheme extends Themelet { } $h_reply = " - Reply"; $h_ip = $user->can("view_ip") ? "
".show_ip($comment->poster_ip, "Comment posted {$comment->posted}") : ""; - $h_del = $user->can("delete_comment") ? - ' - Del' : ''; + $h_del = ""; + if ($user->can("delete_comment")) { + $comment_preview = substr(html_unescape($tfe->stripped), 0, 50); + $j_delete_confirm_message = json_encode("Delete comment by {$comment->owner_name}:\n$comment_preview"); + $h_delete_script = html_escape("return confirm($j_delete_confirm_message);"); + $h_delete_link = make_link("comment/delete/$i_comment_id/$i_image_id"); + $h_del = " - Del"; + } $html = "
diff --git a/ext/handle_ico/main.php b/ext/handle_ico/main.php index 83cd9d56..beda9596 100644 --- a/ext/handle_ico/main.php +++ b/ext/handle_ico/main.php @@ -35,20 +35,6 @@ class IcoFileHandler extends Extension { } } - public function onPageRequest(PageRequestEvent $event) { - global $page; - if($event->page_matches("get_ico")) { - $id = int_escape($event->get_arg(0)); - $image = Image::by_id($id); - $hash = $image->hash; - $ha = substr($hash, 0, 2); - - $page->set_type("image/x-icon"); - $page->set_mode("data"); - $page->set_data(file_get_contents("images/$ha/$hash")); - } - } - /** * @param string $ext * @return bool @@ -67,13 +53,15 @@ class IcoFileHandler extends Extension { $image = new Image(); $fp = fopen($filename, "r"); - $header = unpack("snull/stype/scount", fread($fp, 6)); + $header = unpack("Snull/Stype/Scount", fread($fp, 6)); - $subheader = unpack("cwidth/cheight/ccolours/cnull/splanes/sbpp/lsize/loffset", fread($fp, 16)); + $subheader = unpack("Cwidth/Cheight/Ccolours/Cnull/Splanes/Sbpp/Lsize/loffset", fread($fp, 16)); fclose($fp); - $image->width = $subheader['width']; - $image->height = $subheader['height']; + $width = $subheader['width']; + $height = $subheader['height']; + $image->width = $width == 0 ? 256 : $width; + $image->height = $height == 0 ? 256 : $height; $image->filesize = $metadata['size']; $image->hash = $metadata['hash']; @@ -92,7 +80,7 @@ class IcoFileHandler extends Extension { private function check_contents($file) { if(!file_exists($file)) return false; $fp = fopen($file, "r"); - $header = unpack("snull/stype/scount", fread($fp, 6)); + $header = unpack("Snull/Stype/Scount", fread($fp, 6)); fclose($fp); return ($header['null'] == 0 && ($header['type'] == 0 || $header['type'] == 1)); } diff --git a/ext/handle_ico/test.php b/ext/handle_ico/test.php index b019eed0..fa130100 100644 --- a/ext/handle_ico/test.php +++ b/ext/handle_ico/test.php @@ -4,7 +4,6 @@ class IcoHandlerTest extends ShimmiePHPUnitTestCase { $this->log_in_as_user(); $image_id = $this->post_image("lib/static/favicon.ico", "shimmie favicon"); $this->get_page("post/view/$image_id"); // test for no crash - $this->get_page("get_ico/$image_id"); // test for no crash # FIXME: test that the thumb works # FIXME: test that it gets displayed properly diff --git a/ext/handle_ico/theme.php b/ext/handle_ico/theme.php index aa092709..36daa9c2 100644 --- a/ext/handle_ico/theme.php +++ b/ext/handle_ico/theme.php @@ -2,9 +2,10 @@ class IcoFileHandlerTheme extends Themelet { public function display_image(Page $page, Image $image) { - $ilink = make_link("get_ico/{$image->id}/{$image->id}.ico"); + $ilink = $image->get_image_link(); $html = " - + main image "; $page->add_block(new Block("Image", $html, "main", 10)); } diff --git a/ext/handle_pixel/script.js b/ext/handle_pixel/script.js index b85094cc..e127e42f 100644 --- a/ext/handle_pixel/script.js +++ b/ext/handle_pixel/script.js @@ -1,5 +1,7 @@ $(function() { - function zoom(zoom_type) { + function zoom(zoom_type, save_cookie) { + save_cookie = save_cookie === undefined ? true : save_cookie; + var img = $('.shm-main-image'); if(zoom_type == "full") { @@ -21,14 +23,21 @@ $(function() { $(".shm-zoomer").val(zoom_type); - Cookies.set("ui-image-zoom", zoom_type, {expires: 365}); + if (save_cookie) { + Cookies.set("ui-image-zoom", zoom_type, {expires: 365}); + } } $(".shm-zoomer").change(function(e) { zoom(this.options[this.selectedIndex].value); }); + $(window).resize(function(e) { + $(".shm-zoomer").each(function (e) { + zoom(this.options[this.selectedIndex].value, false) + }); + }); - $(".shm-main-image").click(function(e) { + $("img.shm-main-image").click(function(e) { switch(Cookies.get("ui-image-zoom")) { case "full": zoom("width"); break; default: zoom("full"); break; diff --git a/ext/handle_svg/main.php b/ext/handle_svg/main.php index 872d59d4..6db9ad1d 100644 --- a/ext/handle_svg/main.php +++ b/ext/handle_svg/main.php @@ -101,6 +101,9 @@ class MiniSVGParser { /** @var int */ public $height=0; + /** @var int */ + private $xml_depth=0; + /** @param string $file */ function __construct($file) { $xml_parser = xml_parser_create(); @@ -110,13 +113,15 @@ class MiniSVGParser { } function startElement($parser, $name, $attrs) { - if($name == "SVG") { + if($name == "SVG" && $this->xml_depth == 0) { $this->width = int_escape($attrs["WIDTH"]); $this->height = int_escape($attrs["HEIGHT"]); } + $this->xml_depth++; } function endElement($parser, $name) { + $this->xml_depth--; } } diff --git a/ext/handle_svg/theme.php b/ext/handle_svg/theme.php index 76d76aa3..8e87ee1d 100644 --- a/ext/handle_svg/theme.php +++ b/ext/handle_svg/theme.php @@ -5,8 +5,8 @@ class SVGFileHandlerTheme extends Themelet { $ilink = make_link("get_svg/{$image->id}/{$image->id}.svg"); // $ilink = $image->get_image_link(); $html = " - - + + "; $page->add_block(new Block("Image", $html, "main", 10)); diff --git a/ext/handle_video/theme.php b/ext/handle_video/theme.php index 159283b1..171582d5 100644 --- a/ext/handle_video/theme.php +++ b/ext/handle_video/theme.php @@ -42,7 +42,12 @@ class VideoFileHandlerTheme extends Themelet { $html .= $html_fallback; } else { $html .= " -