aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/elgglib.php14
-rw-r--r--engine/tests/api/helpers.php20
2 files changed, 22 insertions, 12 deletions
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();
}
diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php
index b8cf96900..b7057220b 100644
--- a/engine/tests/api/helpers.php
+++ b/engine/tests/api/helpers.php
@@ -104,9 +104,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
global $CONFIG;
// specify name
- $result = elgg_register_js('key', '//test1.com', 'footer');
+ $result = elgg_register_js('key', 'http://test1.com', 'footer');
$this->assertTrue($result);
- $this->assertIdentical('//test1.com', $CONFIG->externals['js']['footer']['key']);
+ $this->assertIdentical('http://test1.com', $CONFIG->externals['js']['footer']['key']->url);
// send a bad url
$result = elgg_register_js();
@@ -120,9 +120,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
global $CONFIG;
// specify name
- $result = elgg_register_css('key', '//test1.com');
+ $result = elgg_register_css('key', 'http://test1.com');
$this->assertTrue($result);
- $this->assertIdentical('//test1.com', $CONFIG->externals['css']['head']['key']);
+ $this->assertIdentical('http://test1.com', $CONFIG->externals['css']['head']['key']->url);
}
/**
@@ -131,7 +131,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
public function testElggUnregisterJS() {
global $CONFIG;
- $urls = array('id1' => '//url1.com', 'id2' => '//url2.com', 'id3' => '//url3.com');
+ $base = trim(elgg_get_site_url(), "/");
+
+ $urls = array('id1' => "$base/urla", 'id2' => "$base/urlb", 'id3' => "$base/urlc");
foreach ($urls as $id => $url) {
elgg_register_js($id, $url);
}
@@ -142,11 +144,11 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$result = elgg_unregister_js('id1');
$this->assertFalse($result);
- $result = elgg_unregister_js('', '//url2.com');
+ $result = elgg_unregister_js('', 'does_not_exist');
$this->assertFalse($result);
$result = elgg_unregister_js('id2');
- $this->assertIdentical($urls['id3'], $CONFIG->externals['js']['head']['id3']);
+ $this->assertIdentical($urls['id3'], $CONFIG->externals['js']['head']['id3']->url);
}
/**
@@ -157,9 +159,9 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest {
$base = trim(elgg_get_site_url(), "/");
- $urls = array('id1' => "$base/id1", 'id2' => "$base/id2", 'id3' => "$base/id3");
+ $urls = array('id1' => "$base/urla", 'id2' => "$base/urlb", 'id3' => "$base/urlc");
foreach ($urls as $id => $url) {
- elgg_register_js($url, $id);
+ elgg_register_js($id, $url);
}
$js_urls = elgg_get_js('head');