Elgg  Version 6.2
/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);
}
log($level, $message, array $context=[])
Log a message.
Definition: Loggable.php:58
$vars
Definition: theme.php:5
if(!empty($avatar) &&! $avatar->isValid()) elseif(empty($avatar)) if(! $owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
Definition: upload.php:39
$params
Saves global plugin settings.
Definition: save.php:13
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
$attributes
Elgg AJAX loader.
Definition: ajax_loader.php:10
if(! $annotation instanceof ElggAnnotation) $time
Definition: time.php:20
if(!elgg_is_empty($icon_alt) &&!str_starts_with($icon_alt, '<')) switch( $type)
Definition: button.php:64
$text
Definition: button.php:33
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition: deactivate.php:39
if($alt_image) $tag_name
Definition: image_block.php:45
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
$title
Definition: generic.php:50
$viewtype
Definition: default.php:11
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_trigger_event_results(string $event, string $type, array $params=[], $returnvalue=null)
Triggers an event where it is expected that the mixed return value could be manipulated by event call...
Definition: events.php:117
elgg_view_exists(string $view, string $viewtype='', bool $recurse=true)
Returns whether the specified view exists.
Definition: views.php:131
_elgg_view_under_viewtype(string $view, array $vars, string $viewtype)
Render a view while the global viewtype is temporarily changed.
Definition: views.php:1401
elgg_substr()
Wrapper function for mb_substr().
Definition: mb_wrapper.php:195
elgg_strpos()
Wrapper function for mb_strpos().
Definition: mb_wrapper.php:71
$num_chars
Definition: excerpt.php:16
elgg_format_html(string $html, array $options=[])
Output functions Processing text for output such as pulling out URLs and extracting excerpts.
Definition: output.php:20
elgg_parse_urls(string $text)
Takes a string and turns any URLs into formatted links.
Definition: output.php:32
elgg_get_friendly_time(int $time, ?int $current_time=null)
Formats a UNIX timestamp in a friendly way (eg "less than a minute ago")
Definition: output.php:221
elgg_parse_mentions(string $text)
Takes a string and turns any @ mentions into formatted links.
Definition: output.php:56
elgg_normalize_site_url(string $unsafe_url)
From untrusted input, get a site URL safe for forwarding.
Definition: output.php:175
elgg_normalize_url(string $url)
Definition: output.php:163
elgg_format_bytes(int $size, int $precision=2)
Format bytes to a human readable format.
Definition: output.php:103
elgg_format_element(string $tag_name, array $attributes=[], string $text='', array $options=[])
Format an HTML element.
Definition: output.php:145
elgg_get_friendly_title(string $title)
When given a title, returns a version suitable for inclusion in a URL.
Definition: output.php:192
elgg_parse_emails(string $text)
Takes a string and turns any email addresses into formatted links.
Definition: output.php:44
elgg_get_friendly_upload_error(int $error_code)
Returns a human-readable message for PHP's upload error codes.
Definition: output.php:272
elgg_html_decode(string $string)
Decode HTML markup into a raw text string.
Definition: output.php:354
elgg_get_excerpt(string $text, int $num_chars=250)
Returns an excerpt.
Definition: output.php:83
elgg_autop(string $string)
Create paragraphs from text with line spacing.
Definition: output.php:67
elgg_strip_tags(string $string, ?string $allowable_tags=null)
Strip tags and offer plugins the chance.
Definition: output.php:323
$html
A wrapper to render a section of the page shell.
Definition: section.php:9
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
Definition: robots.php:10
$size
Definition: thumb.php:23