aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-04-13 14:39:21 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-04-13 14:39:21 +0000
commit388d8405bb10b3b2107629f8cd4133bff3a7693c (patch)
treec2324505fe24c0b84300f9ca687a428ea5d99fc7
parentbffcde9dfe570af9cd1c2315e31f13d6d0ebec8e (diff)
downloadelgg-388d8405bb10b3b2107629f8cd4133bff3a7693c.tar.gz
elgg-388d8405bb10b3b2107629f8cd4133bff3a7693c.tar.bz2
Consolidated the css and js pagehandlers with elgg_cachable_view_pagehandler() and fixed for URLs with multiple dots after the last / (like /js/calendars/fullcalendar.min.123456789.js)
git-svn-id: http://code.elgg.org/elgg/trunk@8985 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/elgglib.php76
1 files changed, 53 insertions, 23 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 1aef48ef4..063e25fc4 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -1685,21 +1685,7 @@ function _elgg_shutdown_hook() {
* @elgg_pagehandler js
*/
function elgg_js_page_handler($page) {
- if (is_array($page) && sizeof($page)) {
- $js = implode('/', $page);
- $js = substr($js, 0, strpos($js, '.'));
- $return = elgg_view('js/' . $js);
-
- header('Content-type: text/javascript');
-
- // @todo should js be cached when simple cache turned off
- //header('Expires: ' . date('r', time() + 864000));
- //header("Pragma: public");
- //header("Cache-Control: public");
- //header("Content-Length: " . strlen($return));
-
- echo $return;
- }
+ return elgg_cacheable_view_page_handler($page, 'js');
}
/**
@@ -1749,18 +1735,62 @@ function elgg_css_page_handler($page) {
// default css
$page[0] = 'elgg';
}
+
+ return elgg_cacheable_view_page_handler($page, 'css');
+}
+
+/**
+ * Serves a JS or CSS view with headers for caching.
+ *
+ * /<css||js>/name/of/view.<last_cache>.<css||js>
+ *
+ * @param array $page The page array
+ * @param string $type The type: js or css
+ *
+ * @return mixed
+ */
+function elgg_cacheable_view_page_handler($page, $type) {
+
+ switch ($type) {
+ case 'js':
+ $content_type = 'text/javascript';
+ break;
+
+ case 'css':
+ $content_type = 'text/css';
+ break;
+
+ default:
+ return false;
+ break;
+ }
+
+ if ($page) {
+ // the view file names can have multiple dots
+ // eg: views/default/js/calendars/jquery.fullcalendar.min.php
+ // translates to the url /js/calendars/jquery.fullcalendar.min.<ts>.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);
- $css = substr($page[0], 0, strpos($page[0], '.'));
- $return = elgg_view("css/$css");
+ $view = implode('/', $page);
+ $return = elgg_view("$type/$view");
+
+ header("Content-type: $content_type");
- header("Content-type: text/css", true);
+ // @todo should js be cached when simple cache turned off
+ //header('Expires: ' . date('r', time() + 864000));
+ //header("Pragma: public");
+ //header("Cache-Control: public");
+ //header("Content-Length: " . strlen($return));
- // @todo should css be cached when simple cache is turned off
- //header('Expires: ' . date('r', time() + 86400000), true);
- //header("Pragma: public", true);
- //header("Cache-Control: public", true);
+ echo $return;
+ }
- echo $return;
+ return true;
}
/**