8 use Elgg\Traits\Loggable;
10 use Pelago\Emogrifier\CssInliner;
11 use Pelago\Emogrifier\HtmlProcessor\CssToAttributeConverter;
38 public const MENTION_REGEX =
'/<a[^>]*?>.*?<\/a>|<.*?>|(^|\s|\!|\.|\?|>|\G)+(@([^\s<&]+))/iu';
70 'parse_emails' => true,
71 'parse_mentions' => true,
81 $params = $this->events->triggerResults(
'prepare',
'html', [],
$params);
118 $linkify = new \Misd\Linkify\Linkify();
120 return $linkify->processUrls(
$text, [
'attr' => [
'rel' =>
'nofollow']]);
132 $linkify = new \Misd\Linkify\Linkify();
134 return $linkify->processEmails(
$text, [
'attr' => [
'rel' =>
'nofollow']]);
146 $callback = function (array $matches) {
180 return $preceding_char . $replacement . $period;
183 return preg_replace_callback(self::MENTION_REGEX, $callback,
$text) ??
$text;
195 $result = $this->autop->process($string);
200 $this->getLogger()->warning(
'AutoParagraph failed to process the string: ' . $e->getMessage());
237 foreach (
$attrs as $attr => $val) {
238 if (!str_starts_with($attr,
'data-') && str_contains($attr,
'_')) {
243 $attr = strtolower($attr);
245 if (!isset($val) || $val ===
false) {
253 if (is_array($val) && empty($val)) {
258 if (is_scalar($val)) {
262 if (!is_array($val)) {
267 $filtered_val = array_filter($val,
function($e) {
268 return is_scalar($e);
271 if (count($val) != count($filtered_val)) {
275 $val = implode(
' ', $val);
277 $val = htmlspecialchars($val, ENT_QUOTES,
'UTF-8',
false);
318 'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'keygen',
'link',
'menuitem',
319 'meta',
'param',
'source',
'track',
'wbr'
323 $double_encode = !empty(
$options[
'double_encode']);
324 $text = htmlspecialchars(
$text, ENT_QUOTES | ENT_SUBSTITUTE,
'UTF-8', $double_encode);
336 return empty(
$options[
'is_xml']) ?
"<{$tag_name}{$attrs}>" :
"<{$tag_name}{$attrs} />";
339 return "<{$tag_name}{$attrs}>$text</$tag_name>";
352 public function stripTags(
string $string, ?
string $allowable_tags =
null): string {
354 'original_string' => $string,
355 'allowable_tags' => $allowable_tags,
358 $string = strip_tags($string, $allowable_tags);
359 return (
string) $this->events->triggerResults(
'format',
'strip_tags',
$params, $string);
389 public function decode(
string $string): string {
390 $string = str_replace(
391 [
'>',
'<',
'&',
'"',
'''],
392 [
'&gt;',
'&lt;',
'&amp;',
'&quot;',
'&#039;'],
395 $string = html_entity_decode($string, ENT_NOQUOTES,
'UTF-8');
397 [
'&gt;',
'&lt;',
'&amp;',
'&quot;',
'&#039;'],
398 [
'>',
'<',
'&',
'"',
'''],
419 $html_with_inlined_css = CssInliner::fromHtml(
$html)->disableStyleBlocksParsing()->inlineCss(
$css)->render();
420 $inlined_attribute_converter = CssToAttributeConverter::fromHtml($html_with_inlined_css)->convertCssToVisualAttributes();
422 return $body_only ? $inlined_attribute_converter->renderBodyContent() : $inlined_attribute_converter->render();
435 $pattern =
'/\s(?:href|src)=([\'"]\S+[\'"])/i';
439 preg_match_all($pattern,
$text, $matches);
441 if (empty($matches) || !isset($matches[1])) {
447 $urls = array_unique($urls);
449 foreach ($urls as
$url) {
451 $real_url = substr(
$url, 1, -1);
455 $replacement = str_replace($real_url, $new_url,
$url);
$params
Saves global plugin settings.
$attributes
Elgg AJAX loader.
Could not register a new user for whatever reason.
Exception thrown if an argument is not of the expected type.
Exception thrown if an error which can only be found on runtime occurs.
Create wrapper P and BR elements in HTML depending on newlines.
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
_elgg_services()
Get the global service provider.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_get_user_by_username(string $username, bool $try_email=false)
Get a user by username.
elgg_view_url(string $href, ?string $text=null, array $options=[])
Helper function for outputting urls.
if(empty($title) &&empty($body)) if(!empty($link)) $attrs
elgg_normalize_url(string $url)
$html
A wrapper to render a section of the page shell.
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.