66 'parse_emails' =>
true,
76 $params = $this->events->triggerResults(
'prepare',
'html', [],
$params);
109 $linkify = new \Misd\Linkify\Linkify();
111 return $linkify->processUrls($text, [
'attr' => [
'rel' =>
'nofollow']]);
123 $linkify = new \Misd\Linkify\Linkify();
125 return $linkify->processEmails($text, [
'attr' => [
'rel' =>
'nofollow']]);
137 $result = $this->autop->process($string);
142 $this->
getLogger()->warning(
'AutoParagraph failed to process the string: ' . $e->getMessage());
179 foreach (
$attrs as $attr => $val) {
180 if (!str_starts_with($attr,
'data-') && str_contains($attr,
'_')) {
185 $attr = strtolower($attr);
187 if (!isset($val) || $val ===
false) {
195 if (is_array($val) && empty($val)) {
200 if (is_scalar($val)) {
204 if (!is_array($val)) {
209 $filtered_val = array_filter($val,
function($e) {
210 return is_scalar($e);
219 $val = htmlspecialchars($val, ENT_QUOTES,
'UTF-8',
false);
254 if ($tag_name ===
'') {
259 $is_void =
$options[
'is_void'] ?? in_array(strtolower($tag_name), [
260 'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'keygen',
'link',
'menuitem',
261 'meta',
'param',
'source',
'track',
'wbr' 265 $double_encode = !empty(
$options[
'double_encode']);
266 $text = htmlspecialchars(
$text, ENT_QUOTES | ENT_SUBSTITUTE,
'UTF-8', $double_encode);
278 return empty(
$options[
'is_xml']) ?
"<{$tag_name}{$attrs}>" :
"<{$tag_name}{$attrs} />";
281 return "<{$tag_name}{$attrs}>$text</$tag_name>";
294 public function stripTags(
string $string,
string $allowable_tags = null): string {
296 'original_string' => $string,
297 'allowable_tags' => $allowable_tags,
300 $string = strip_tags($string, $allowable_tags);
301 return (
string) $this->events->triggerResults(
'format',
'strip_tags',
$params, $string);
331 public function decode(
string $string): string {
333 [
'>',
'<',
'&',
'"',
'''],
334 [
'&gt;',
'&lt;',
'&amp;',
'&quot;',
'&#039;'],
337 $string = html_entity_decode($string, ENT_NOQUOTES,
'UTF-8');
339 [
'&gt;',
'&lt;',
'&amp;',
'&quot;',
'&#039;'],
340 [
'>',
'<',
'&',
'"',
'''],
357 if (empty($html) || empty($css)) {
361 $inliner = CssInliner::fromHtml($html)->disableStyleBlocksParsing()->inlineCss($css);
363 return $body_only ? $inliner->renderBodyContent() : $inliner->render();
376 $pattern =
'/\s(?:href|src)=([\'"]\S+[\'"])/i';
380 preg_match_all($pattern, $text, $matches);
382 if (empty($matches) || !isset($matches[1])) {
388 $urls = array_unique($urls);
390 foreach ($urls as
$url) {
392 $real_url =
substr($url, 1, -1);
396 $replacement =
str_replace($real_url, $new_url, $url);
Exception thrown if an argument is not of the expected type.
$params
Saves global plugin settings.
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_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
trait Loggable
Enables adding a logger.
getLogger()
Returns logger.
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
elgg_normalize_url(string $url)
$attributes
Elgg AJAX loader.
if(empty($title)&&empty($body)) if(!empty($link)) $attrs