From 8f1bca7459af7eeebb30bf116ae03c25d30836f3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 21 Jul 2009 12:18:49 -0700 Subject: Remove the fallback code. It should trigger extremely rarely and seems highly inefficient to me, so let's see if we can live without it. --- modules/gallery/controllers/file_proxy.php | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'modules/gallery/controllers/file_proxy.php') diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index c5b34033..799260b5 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -66,20 +66,6 @@ class File_Proxy_Controller extends Controller { // We didn't turn it up. This may mean that the path cache is out of date, so look it up // the hard way. // - // Find all items that match the level and name, then iterate over those to find a match. - // In most cases we'll get it in one. Note that for the level calculation, we just count the - // size of $paths. - $paths = explode("/", $path); - $count = count($paths); - foreach (ORM::factory("item") - ->where("name", $paths[$count - 1]) - ->where("level", $count + 1) - ->find_all() as $match) { - if ($match->relative_path() == $path) { - $item = $match; - break; - } - } } if (!$item->loaded) { -- cgit v1.2.3 From f83db99d39cc65b212f894c7e4ed66a52625f3c8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 21 Jul 2009 12:26:16 -0700 Subject: Properly display thumbnails for private movies by backtracking from the thumbnail to the movie and then showing it as a JPG. Fixes ticket #570. --- modules/gallery/controllers/file_proxy.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'modules/gallery/controllers/file_proxy.php') diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index 799260b5..a85f0a85 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -63,9 +63,22 @@ class File_Proxy_Controller extends Controller { // We now have the relative path to the item. Search for it in the path cache $item = ORM::factory("item")->where("relative_path_cache", $path)->find(); if (!$item->loaded) { - // We didn't turn it up. This may mean that the path cache is out of date, so look it up - // the hard way. - // + // We didn't turn it up. It's possible that the relative_path_cache is out of date here. + // There was fallback code, but bharat deleted it in 8f1bca74. If it turns out to be + // necessary, it's easily resurrected. + + // If we're looking for a .jpg then it's it's possible that we're requesting the thumbnail + // for a movie. In that case, the .flv or .mp4 file would have been converted to a .jpg. + // So try some alternate types: + if (preg_match('/.jpg$/', $path)) { + foreach (array("flv", "mp4") as $ext) { + $movie_path = preg_replace('/.jpg$/', ".$ext", $path); + $item = ORM::factory("item")->where("relative_path_cache", $movie_path)->find(); + if ($item->loaded) { + break; + } + } + } } if (!$item->loaded) { @@ -102,8 +115,13 @@ class File_Proxy_Controller extends Controller { // We don't need to save the session for this request Session::abort_save(); - // Dump out the image - header("Content-Type: $item->mime_type"); + // Dump out the image. If the item is a movie, then its thumbnail will be a JPG. + if (in_array($item->mime_type, array("video/x-flv", "video/mp4"))) { + header("Content-type: image/jpeg"); + } else { + print("Content-Type: $item->mime_type"); + } + Kohana::close_buffers(false); $fd = fopen($file, "rb"); fpassthru($fd); -- cgit v1.2.3 From 2da7f937840b79b65bacb96e8dad06f2e7d41305 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 20 Aug 2009 12:24:05 +0800 Subject: Fix the setting of the mime type header. as per http://gallery.menalto.com/node/90306 Thanks rWatcher Signed-off-by: Tim Almdal --- modules/gallery/controllers/file_proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/controllers/file_proxy.php') diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index a85f0a85..8cb90c50 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -119,7 +119,7 @@ class File_Proxy_Controller extends Controller { if (in_array($item->mime_type, array("video/x-flv", "video/mp4"))) { header("Content-type: image/jpeg"); } else { - print("Content-Type: $item->mime_type"); + header("Content-Type: $item->mime_type"); } Kohana::close_buffers(false); -- cgit v1.2.3