Elgg  Version 3.0
/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($html, array $options = []) {
return _elgg_services()->html_formatter->formatBlock($html, $options);
}
function parse_urls($text) {
return _elgg_services()->html_formatter->parseUrls($text);
}
return _elgg_services()->html_formatter->parseEmails($text);
}
function elgg_autop($string) {
return _elgg_services()->html_formatter->addParagaraphs($string);
}
function elgg_get_excerpt($text, $num_chars = 250) {
$view = 'output/excerpt';
$vars = [
'text' => $text,
'num_chars' => $num_chars,
];
$viewtype = elgg_view_exists($view) ? '' : 'default';
}
function elgg_format_bytes($size, $precision = 2) {
$size = (int) $size;
if ($size < 0) {
return false;
}
$precision = (int) $precision;
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_attributes(array $attrs = []) {
return _elgg_services()->html_formatter->formatAttributes($attrs);
}
function elgg_format_element($tag_name, array $attributes = [], $text = '', array $options = []) {
return _elgg_services()->html_formatter->formatElement($tag_name, $attributes, $text, $options);
}
$url = str_replace(' ', '%20', $url);
return $url;
}
if (preg_match("#^([a-z]+)\\:#", $url, $m)) {
// we don't let http/https: URLs fail filter_var(), but anything else starting with a protocol
// is OK
if ($m[1] !== 'http' && $m[1] !== 'https') {
return $url;
}
}
if (preg_match("#^(\\#|\\?|//)#", $url)) {
// starts with '//' (protocol-relative link), query, or fragment
return $url;
}
if (preg_match("#^[^/]*\\.php(\\?.*)?$#", $url)) {
// root PHP scripts: 'install.php', 'install.php?step=step'. We don't want to confuse these
// for domain names.
return elgg_get_site_url() . $url;
}
if (preg_match("#^[^/?]*\\.#", $url)) {
// URLs starting with domain: 'example.com', 'example.com/subpage'
return "http://$url";
}
// 'page/handler', 'mod/plugin/file.php'
// trim off any leading / because the site URL is stored
// with a trailing /
return elgg_get_site_url() . ltrim($url, '/');
}
function elgg_normalize_site_url($unsafe_url) {
if (!is_string($unsafe_url)) {
return false;
}
$unsafe_url = elgg_normalize_url($unsafe_url);
if (0 === strpos($unsafe_url, elgg_get_site_url())) {
return $unsafe_url;
}
return false;
}
// return a URL friendly title to short circuit normal title formatting
$params = ['title' => $title];
$result = elgg_trigger_plugin_hook('format', 'friendly:title', $params, null);
if ($result) {
return $result;
}
// titles are often stored HTML encoded
$title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
return $title;
}
function elgg_get_friendly_time($time, $current_time = null) {
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_plugin_hook('format', 'friendly:time', $params, null);
if ($result) {
return $result;
}
$diff = abs((int) $current_time - (int) $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 = ((int) $current_time - (int) $time < 0) ? ':future' : '';
$singular = ($diff == 1) ? ':singular' : '';
return elgg_echo("friendlytime{$future}{$granularity}{$singular}", [$diff]);
}
function elgg_get_friendly_upload_error($error_code) {
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, $allowable_tags = null) {
return _elgg_services()->html_formatter->stripTags($string, $allowable_tags);
}
function elgg_html_decode($string) {
return _elgg_services()->html_formatter->decode($string);
}
function _elgg_get_display_query($string) {
//encode <,>,&, quotes and characters above 127
if (function_exists('mb_convert_encoding')) {
$display_query = mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8');
} else {
// if no mbstring extension, we just strip characters
$display_query = preg_replace("/[^\x01-\x7F]/", "", $string);
}
return htmlspecialchars($display_query, ENT_QUOTES, 'UTF-8', false);
}
// based on http://php.net/manual/en/function.filter-var.php#104160
$res = filter_var($url, FILTER_VALIDATE_URL);
if ($res) {
return $res;
}
// Check if it has unicode chars.
if (strlen($url) == $l) {
return $res;
}
// Replace wide chars by “X”.
$s = '';
for ($i = 0; $i < $l; ++$i) {
$ch = elgg_substr($url, $i, 1);
$s .= (strlen($ch) > 1) ? 'X' : $ch;
}
// Re-check now.
return filter_var($s, FILTER_VALIDATE_URL) ? $url : false;
}