Elgg  Version 6.1
/root/Elgg/engine/lib/output.php

Converts shorthand URLs to absolute URLs, unless the given URL is absolute, protocol-relative, or starts with a protocol/fragment/queryelgg_normalize_url(''); // 'http://my.site.com/' elgg_normalize_url('dashboard'); // 'http://my.site.com/dashboard' elgg_normalize_url('http://google.com/'); // no change elgg_normalize_url('//google.com/'); // no change

Parameters
string$urlThe URL to normalize
Returns
string The absolute URL
<?php
function elgg_format_html(string $html, array $options = []): string {
return _elgg_services()->html_formatter->formatBlock($html, $options);
}
function elgg_parse_urls(string $text): string {
return _elgg_services()->html_formatter->parseUrls($text);
}
function elgg_parse_emails(string $text): string {
return _elgg_services()->html_formatter->parseEmails($text);
}
function elgg_parse_mentions(string $text): string {
return _elgg_services()->html_formatter->parseMentions($text);
}
function elgg_autop(string $string): string {
return _elgg_services()->html_formatter->addParagaraphs($string);
}
function elgg_get_excerpt(string $text, int $num_chars = 250): string {
$view = 'output/excerpt';
$vars = [
'text' => $text,
'num_chars' => $num_chars,
];
$viewtype = elgg_view_exists($view) ? '' : 'default';
}
function elgg_format_bytes(int $size, int $precision = 2): string {
if ($size < 0) {
return (string) $size;
}
if ($size === 0) {
return '0 B';
}
if ($precision < 0) {
$precision = 2;
}
$base = log($size) / log(1024);
$suffixes = ['B', 'kB', 'MB', 'GB', 'TB'];
return round(pow(1024, $base - floor($base)), $precision) . ' ' . $suffixes[floor($base)];
}
function elgg_format_element(string $tag_name, array $attributes = [], string $text = '', array $options = []): string {
return _elgg_services()->html_formatter->formatElement($tag_name, $attributes, $text, $options);
}
function elgg_normalize_url(string $url): string {
return _elgg_services()->urls->normalizeUrl($url);
}
function elgg_normalize_site_url(string $unsafe_url): ?string {
$unsafe_url = _elgg_services()->urls->normalizeUrl($unsafe_url);
if (elgg_strpos($unsafe_url, elgg_get_site_url()) === 0) {
return $unsafe_url;
}
return null;
}
function elgg_get_friendly_title(string $title): string {
// return a URL friendly title to short circuit normal title formatting
$params = ['title' => $title];
$result = elgg_trigger_event_results('format', 'friendly:title', $params, null);
if (is_string($result)) {
return $result;
}
// titles are often stored HTML encoded
$title = html_entity_decode($title ?? '', ENT_QUOTES, 'UTF-8');
// limit length to prevent issues with too long URLS (Request-URI Too Large) #13228
// limit the length before urlize() to prevent multibyte chars from being cut of in the middle #14577
return \Elgg\Translit::urlize($title);
}
function elgg_get_friendly_time(int $time, int $current_time = null): string {
if (!isset($current_time)) {
$current_time = time();
}
// return a time string to short circuit normal time formatting
$params = ['time' => $time, 'current_time' => $current_time];
$result = elgg_trigger_event_results('format', 'friendly:time', $params, null);
if (is_string($result)) {
return $result;
}
$diff = abs($current_time - $time);
$minute = 60;
$hour = $minute * 60;
$day = $hour * 24;
if ($diff < $minute) {
return elgg_echo('friendlytime:justnow');
}
if ($diff < $hour) {
$granularity = ':minutes';
$diff = round($diff / $minute);
} else if ($diff < $day) {
$granularity = ':hours';
$diff = round($diff / $hour);
} else {
$granularity = ':days';
$diff = round($diff / $day);
}
if ($diff == 0) {
$diff = 1;
}
$future = ($current_time - $time < 0) ? ':future' : '';
$singular = ($diff == 1) ? ':singular' : '';
return elgg_echo("friendlytime{$future}{$granularity}{$singular}", [$diff]);
}
function elgg_get_friendly_upload_error(int $error_code): string {
switch ($error_code) {
case UPLOAD_ERR_OK:
return '';
case UPLOAD_ERR_INI_SIZE:
$key = 'ini_size';
break;
case UPLOAD_ERR_FORM_SIZE:
$key = 'form_size';
break;
case UPLOAD_ERR_PARTIAL:
$key = 'partial';
break;
case UPLOAD_ERR_NO_FILE:
$key = 'no_file';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$key = 'no_tmp_dir';
break;
case UPLOAD_ERR_CANT_WRITE:
$key = 'cant_write';
break;
case UPLOAD_ERR_EXTENSION:
$key = 'extension';
break;
default:
$key = 'unknown';
break;
}
return elgg_echo("upload:error:{$key}");
}
function elgg_strip_tags(string $string, string $allowable_tags = null): string {
return _elgg_services()->html_formatter->stripTags($string, $allowable_tags);
}
function elgg_html_decode(string $string): string {
return _elgg_services()->html_formatter->decode($string);
}
function _elgg_get_display_query(string $string): string {
if (empty($string)) {
return $string;
}
$string = htmlentities($string, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8', false);
}