From d87b6ffe7312888d109428e6a939f33394549677 Mon Sep 17 00:00:00 2001 From: brettp Date: Wed, 13 Apr 2011 19:30:44 +0000 Subject: Fixes #3331. Changed cache schema to allow for JS/CSS views with slashes and dots. git-svn-id: http://code.elgg.org/elgg/trunk@8986 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/handlers/cache_handler.php | 15 +++++++++------ engine/lib/cache.php | 2 +- engine/lib/elgglib.php | 10 ++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/engine/handlers/cache_handler.php b/engine/handlers/cache_handler.php index 05c35171b..7d6f42dc3 100644 --- a/engine/handlers/cache_handler.php +++ b/engine/handlers/cache_handler.php @@ -3,7 +3,7 @@ * Cache handler. * * External access to cached CSS and JavaScript views. The cached file URLS - * should be of the form: cache//// where + * should be of the form: cache///.. where * type is either css or js, view is the name of the cached view, and * unique_id is an identifier that is updated every time the cache is flushed. * The simplest way to maintain a unique identifier is to use the lastcache @@ -50,13 +50,16 @@ if (!$request || !$simplecache_enabled) { echo 'Cache error: bad request'; exit; } -$request = explode('/', $request); +// testing showed regex to be marginally faster than array / string functions over 100000 reps +// it won't make a difference in real life and regex is easier to read. +// //.. +$regex = '|([^/]+)/([^/]+)/(.+)\.([^\.]+)\.([^.]+)$|'; +preg_match($regex, $request, $matches); -//cache//// -$type = $request[0]; -$view = $request[1]; -$viewtype = $request[2]; +$type = $matches[1]; +$viewtype = $matches[2]; +$view = $matches[3]; switch ($type) { case 'css': diff --git a/engine/lib/cache.php b/engine/lib/cache.php index d4888f9d9..8529ae7fa 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -166,7 +166,7 @@ function elgg_get_simplecache_url($type, $view) { if (elgg_is_simplecache_enabled()) { $viewtype = elgg_get_viewtype(); - $url = elgg_get_site_url() . "cache/$type/$view/$viewtype/$view.$lastcache.$type"; + $url = elgg_get_site_url() . "cache/$type/$viewtype/$view.$lastcache.$type"; } else { $url = elgg_get_site_url() . "$type/$view.$lastcache.$type"; } diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 063e25fc4..a800aca7a 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1771,12 +1771,10 @@ function elgg_cacheable_view_page_handler($page, $type) { // translates to the url /js/calendars/jquery.fullcalendar.min..js // and the view js/calendars/jquery.fullcalendar.min // we ignore the last two dots for the ts and the ext. - $last_part = array_pop($page); - $last_part_bits = explode('.', $last_part); - $last_part_bits = array_slice($last_part_bits, 0, -2); - $page[] = implode('.', $last_part_bits); - - $view = implode('/', $page); + $page = implode('/', $page); + $regex = '|(.+)\.([^\.]+)\.([^.]+)$|'; + preg_match($regex, $page, $matches); + $view = $matches[1]; $return = elgg_view("$type/$view"); header("Content-type: $content_type"); -- cgit v1.2.3