Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
core\formatting Class Reference

Public Member Functions

 format_string (?string $string, bool $striplinks=true, ?context $context=null, bool $filter=true, bool $escape=true,)
 Given a simple string, this function returns the string processed by enabled string filters if $CFG->filterall is enabled.
 
 format_text (?string $text, string $format=FORMAT_MOODLE, ?context $context=null, bool $trusted=false, ?bool $clean=null, bool $filter=true, bool $para=true, bool $newlines=true, bool $overflowdiv=false, bool $blanktarget=false, bool $allowid=false,)
 Given text in a variety of format codings, this function returns the text as safe HTML.
 
 get_filterall ()
 Get the current filterall value.
 
 get_forceclean ()
 Get the current forceclean value.
 
 get_striptags ()
 Get the current striptags value.
 
 set_filterall (bool $filterall)
 Set the value of the filterall setting.
 
 set_forceclean (bool $forceclean)
 Set the value of the forceclean setting.
 
 set_striptags (bool $striptags)
 Set the value of the striptags setting.
 

Protected Member Functions

 should_filter_string ()
 During initial install, or upgrade from a really old version of Moodle, we should not filter strings at all.
 

Protected Attributes

bool bool $filterall
 Whether to apply filters.
 
bool bool $forceclean
 Whether to apply forceclean.
 
array $formatstringcache = []
 A string cache for format_string.
 
bool bool $striptags
 Whether to apply striptags.
 

Member Function Documentation

◆ format_string()

core\formatting::format_string ( ?string $string,
bool $striplinks = true,
?context $context = null,
bool $filter = true,
bool $escape = true )

Given a simple string, this function returns the string processed by enabled string filters if $CFG->filterall is enabled.

This function should be used to print short strings (non html) that need filter processing e.g. activity titles, post subjects, glossary concepts.

Parameters
null | string$stringThe string to be filtered. Should be plain text, expect possibly for multilang tags.
boolean$striplinksTo strip any link in the result text.
null | context$contextThe context used for formatting
bool$filterWhether to apply filters
bool$escapeWhether to escape ampersands
Return values
string

◆ format_text()

core\formatting::format_text ( ?string $text,
string $format = FORMAT_MOODLE,
?context $context = null,
bool $trusted = false,
?bool $clean = null,
bool $filter = true,
bool $para = true,
bool $newlines = true,
bool $overflowdiv = false,
bool $blanktarget = false,
bool $allowid = false )

Given text in a variety of format codings, this function returns the text as safe HTML.

This function should mainly be used for long strings like posts, answers, glossary items etc. For short strings format_string().

Parameters
null | string$textThe text to be formatted. This is raw text originally from user input.
string$formatIdentifier of the text format to be used [FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_MARKDOWN]
null | context$contextThe context used for filtering
bool$trustedIf true the string won't be cleaned. Note: FORMAT_MARKDOWN does not support trusted text.
null | bool$cleanIf true the string will be cleaned. Note: This parameter is overridden if the text is trusted
bool$filterIf true the string will be run through applicable filters as well.
bool$paraIf true then the returned string will be wrapped in div tags.
bool$newlinesIf true then lines newline breaks will be converted to HTML newline breaks.
bool$overflowdivIf set to true the formatted text will be encased in a div
bool$blanktargetIf true all tags will have target="_blank" added unless target is explicitly specified.
bool$allowidIf true then id attributes will not be removed, even when using htmlpurifier.
Return values
string

◆ get_filterall()

core\formatting::get_filterall ( )

Get the current filterall value.

Reverts to CFG->filterall if not set.

Return values
bool

◆ get_forceclean()

core\formatting::get_forceclean ( )

Get the current forceclean value.

Return values
bool

◆ get_striptags()

core\formatting::get_striptags ( )

Get the current striptags value.

Reverts to CFG->formatstringstriptags if not set.

Return values
bool

◆ set_filterall()

core\formatting::set_filterall ( bool $filterall)

Set the value of the filterall setting.

Parameters
bool$filterall
Return values
formatting

◆ set_forceclean()

core\formatting::set_forceclean ( bool $forceclean)

Set the value of the forceclean setting.

Parameters
bool$forceclean
Return values
self

◆ set_striptags()

core\formatting::set_striptags ( bool $striptags)

Set the value of the striptags setting.

Parameters
bool$striptags
Return values
formatting

◆ should_filter_string()

core\formatting::should_filter_string ( )
protected

During initial install, or upgrade from a really old version of Moodle, we should not filter strings at all.

Return values
bool

The documentation for this class was generated from the following file: