public function register($type, $name, $url, $location, $priority = 500)
{
if (empty($name) || empty($url)) {
return false;
}
$url = elgg_format_url($url);
$url = elgg_normalize_url($url);
$this->bootstrap($type);
$name = trim(strtolower($name));
// normalize bogus priorities, but allow empty, null, and false to be defaults.
if (!is_numeric($priority)) {
$priority = 500;
}
// no negative priorities right now.
$priority = max((int) $priority, 0);
$item = elgg_extract($name, $GLOBALS['_ELGG']->externals_map[$type]);
if ($item) {
// updating a registered item
// don't update loaded because it could already be set
$item->url = $url;
$item->location = $location;
// if loaded before registered, that means it hasn't been added to the list yet
if ($GLOBALS['_ELGG']->externals[$type]->contains($item)) {
$priority = $GLOBALS['_ELGG']->externals[$type]->move($item, $priority);
} else {
$priority = $GLOBALS['_ELGG']->externals[$type]->add($item, $priority);
}
} else {
$item = new \stdClass();
$item->loaded = false;
$item->url = $url;
$item->location = $location;
$priority = $GLOBALS['_ELGG']->externals[$type]->add($item, $priority);
}
$GLOBALS['_ELGG']->externals_map[$type][$name] = $item;
return $priority !== false;
}