Elgg  Version master
Functions
output.php File Reference

Go to the source code of this file.

Functions

 elgg_format_html (string $html, array $options=[])
 Output functions Processing text for output such as pulling out URLs and extracting excerpts. More...
 
 elgg_parse_urls (string $text)
 Takes a string and turns any URLs into formatted links. More...
 
 elgg_parse_emails (string $text)
 Takes a string and turns any email addresses into formatted links. More...
 
 elgg_parse_mentions (string $text)
 Takes a string and turns any @ mentions into formatted links. More...
 
 elgg_autop (string $string)
 Create paragraphs from text with line spacing. More...
 
 elgg_get_excerpt (string $text, int $num_chars=250)
 Returns an excerpt. More...
 
 elgg_format_bytes (int $size, int $precision=2)
 Format bytes to a human readable format. More...
 
 elgg_format_element (string $tag_name, array $attributes=[], string $text= '', array $options=[])
 Format an HTML element. More...
 
 elgg_normalize_url (string $url)
 
 elgg_normalize_site_url (string $unsafe_url)
 From untrusted input, get a site URL safe for forwarding. More...
 
 elgg_get_friendly_title (string $title)
 When given a title, returns a version suitable for inclusion in a URL. More...
 
 elgg_get_friendly_time (int $time, int $current_time=null)
 Formats a UNIX timestamp in a friendly way (eg "less than a minute ago") More...
 
 elgg_get_friendly_upload_error (int $error_code)
 Returns a human-readable message for PHP's upload error codes. More...
 
 elgg_strip_tags (string $string, string $allowable_tags=null)
 Strip tags and offer plugins the chance. More...
 
 elgg_html_decode (string $string)
 Decode HTML markup into a raw text string. More...
 
 _elgg_get_display_query (string $string)
 Prepares query string for output to prevent CSRF attacks. More...
 

Function Documentation

_elgg_get_display_query ( string  $string)

Prepares query string for output to prevent CSRF attacks.

Parameters
string$stringstring to prepare
Returns
string
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 366 of file output.php.

elgg_autop ( string  $string)

Create paragraphs from text with line spacing.

Parameters
string$stringThe string
Returns
string
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 67 of file output.php.

elgg_format_bytes ( int  $size,
int  $precision = 2 
)

Format bytes to a human readable format.

Parameters
int$sizeFile size in bytes to format
int$precisionPrecision to round formatting bytes to
Returns
string
Since
1.9.0
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 103 of file output.php.

elgg_format_element ( string  $tag_name,
array  $attributes = [],
string  $text = '',
array  $options = [] 
)

Format an HTML element.

Parameters
string$tag_nameThe element tagName. e.g. "div". This will not be validated.
array$attributesThe element attributes.
string$textThe contents of the element. Assumed to be HTML unless encode_text is true.
array$optionsOptions array with keys:
  • encode_text => (bool, default false) If true, $text will be HTML-escaped. Already-escaped entities will not be double-escaped.
  • double_encode => (bool, default false) If true, the $text HTML escaping will be allowed to double encode HTML entities: '×' will become '×'
  • is_void => (bool) If given, this determines whether the function will return just the open tag. Otherwise this will be determined by the tag name according to this list: http://www.w3.org/html/wg/drafts/html/master/single-page.html#void-elements
  • is_xml => (bool, default false) If true, void elements will be formatted like "<tag />"
Returns
string
Exceptions
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 145 of file output.php.

elgg_format_html ( string  $html,
array  $options = [] 
)

Output functions Processing text for output such as pulling out URLs and extracting excerpts.

Prepare HTML output

Parameters
string$htmlHTML string
array$optionsFormatting options

bool $parse_urls Replace URLs with anchor tags bool $parse_emails Replace email addresses with anchor tags bool $sanitize Sanitize HTML tags bool $autop Add paragraphs instead of new lines

Returns
string
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 20 of file output.php.

elgg_get_excerpt ( string  $text,
int  $num_chars = 250 
)

Returns an excerpt.

Will return up to n chars stopping at the nearest space. If no spaces are found (like in Japanese) will crop off at the n char mark. Adds ... if any text was chopped.

Parameters
string$textThe full text to excerpt
int$num_charsReturn a string up to $num_chars long
Returns
string
Since
1.7.2
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 83 of file output.php.

elgg_get_friendly_time ( int  $time,
int  $current_time = null 
)

Formats a UNIX timestamp in a friendly way (eg "less than a minute ago")

See also
elgg_view_friendly_time()
Parameters
int$timeA UNIX epoch timestamp
int$current_timeCurrent UNIX epoch timestamp (optional)
Returns
string The friendly time string
Since
1.7.2
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 221 of file output.php.

elgg_get_friendly_title ( string  $title)

When given a title, returns a version suitable for inclusion in a URL.

Parameters
string$titleThe title
Returns
string The optimized title
Since
1.7.2
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 192 of file output.php.

elgg_get_friendly_upload_error ( int  $error_code)

Returns a human-readable message for PHP's upload error codes.

Parameters
int$error_codeThe code as stored in $_FILES['name']['error']
Returns
string
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 272 of file output.php.

elgg_html_decode ( string  $string)

Decode HTML markup into a raw text string.

This applies html_entity_decode() to a string while re-entitising HTML special char entities to prevent them from being decoded back to their unsafe original forms.

This relies on html_entity_decode() not translating entities when doing so leaves behind another entity, e.g. &gt; if decoded would create > which is another entity itself. This seems to escape the usual behaviour where any two paired entities creating a HTML tag are usually decoded, i.e. a lone > is not decoded, but <foo> would be decoded to <foo> since it creates a full tag.

Note: html_entity_decode() is poorly explained in the manual - which is really bad given its potential for misuse on user input already escaped elsewhere. Stackoverflow is littered with advice to use this function in the precise way that would lead to user input being capable of injecting arbitrary HTML.

Parameters
string$stringEncoded HTML
Returns
string
Author
Pádraic Brady
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 354 of file output.php.

elgg_normalize_site_url ( string  $unsafe_url)

From untrusted input, get a site URL safe for forwarding.

Parameters
string$unsafe_urlURL from untrusted input
Returns
null|string Normalized URL or null if given URL was not a path.
Since
1.12.18
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 175 of file output.php.

elgg_normalize_url ( string  $url)
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 163 of file output.php.

elgg_parse_emails ( string  $text)

Takes a string and turns any email addresses into formatted links.

Parameters
string$textThe input string
Returns
string The output string with formatted links
Since
2.3
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 44 of file output.php.

elgg_parse_mentions ( string  $text)

Takes a string and turns any @ mentions into formatted links.

Parameters
string$textThe input string
Returns
string The output string with formatted links
Since
5.0
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 56 of file output.php.

elgg_parse_urls ( string  $text)

Takes a string and turns any URLs into formatted links.

Parameters
string$textThe input string
Returns
string The output string with formatted links
Since
4.3
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 32 of file output.php.

elgg_strip_tags ( string  $string,
string  $allowable_tags = null 
)

Strip tags and offer plugins the chance.

Plugins register for output:strip_tags event. Original string included in $params['original_string']

Parameters
string$stringFormatted string
string$allowable_tagsOptional parameter to specify tags which should not be stripped
Returns
string String run through strip_tags() and any events.
Examples:
/root/Elgg/engine/lib/output.php.

Definition at line 323 of file output.php.