From 9b2c527e6cea1ce81293324f1783bc78225ada0f Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 12 Mar 2011 21:02:30 +0000 Subject: Refs #3091 registering js and css support priority though does not maintain registration order if items have equal priority git-svn-id: http://code.elgg.org/elgg/trunk@8669 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'engine/lib/elgglib.php') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 7b21f7dfc..93be114f2 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -208,7 +208,7 @@ function elgg_register_css($name, $url, $priority = 500) { * @return bool * @since 1.8.0 */ -function elgg_register_external_file($type, $name, $url, $location, $priority) { +function elgg_register_external_file($type, $name, $url, $location, $priority = 500) { global $CONFIG; if (empty($name) || empty($url)) { @@ -230,7 +230,12 @@ function elgg_register_external_file($type, $name, $url, $location, $priority) { } $name = trim(strtolower($name)); - $CONFIG->externals[$type][$location][$name] = elgg_normalize_url($url); + + $item = new stdClass(); + $item->url = elgg_normalize_url($url); + $item->priority = max((int)$priority, 0); + + $CONFIG->externals[$type][$location][$name] = $item; return true; } @@ -327,7 +332,10 @@ function elgg_get_external_file($type, $location) { isset($CONFIG->externals[$type]) && isset($CONFIG->externals[$type][$location])) { - return array_values($CONFIG->externals[$type][$location]); + $items = array_values($CONFIG->externals[$type][$location]); + usort($items, create_function('$a,$b','return $a->priority >= $b->priority;')); + array_walk($items, create_function('&$v,$k', '$v = $v->url;')); + return $items; } return array(); } -- cgit v1.2.3