ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Mail\Mime\Presentation\HtmlMailBodyComposer Class Reference

Composes the HTML representation of a mail body, and the plain text alternative that goes with it. More...

+ Inheritance diagram for ILIAS\Mail\Mime\Presentation\HtmlMailBodyComposer:
+ Collaboration diagram for ILIAS\Mail\Mime\Presentation\HtmlMailBodyComposer:

Public Member Functions

 __construct (private readonly MailAssets $assets, private readonly PlainTextMailBodyComposer $plain_text, private readonly UIFactory $ui, private readonly Renderer $renderer, private readonly Refinery $refinery, private readonly DataFactory $data, private readonly string $installation_title, private readonly string $installation_url)
 
 compose (MailBodySource $source)
 
 compose (MailBodySource $source)
 

Private Member Functions

 containsHtml (string $email_body)
 

Private Attributes

const string BLOCK_ELEMENT_PATTERN = '~</?(p|br|div|ul|ol|li|code|pre|h[1-6])\b~i'
 
const string INLINE_TAGS = '<b><u><i><a>'
 

Detailed Description

Composes the HTML representation of a mail body, and the plain text alternative that goes with it.

Knows nothing about recipients, transports or where assets are stored.

Definition at line 35 of file HtmlMailBodyComposer.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Mail\Mime\Presentation\HtmlMailBodyComposer::__construct ( private readonly MailAssets  $assets,
private readonly PlainTextMailBodyComposer  $plain_text,
private readonly UIFactory  $ui,
private readonly Renderer  $renderer,
private readonly Refinery  $refinery,
private readonly DataFactory  $data,
private readonly string  $installation_title,
private readonly string  $installation_url 
)

Definition at line 40 of file HtmlMailBodyComposer.php.

49 {
50 }

Member Function Documentation

◆ compose()

ILIAS\Mail\Mime\Presentation\HtmlMailBodyComposer::compose ( MailBodySource  $source)

Implements ILIAS\Mail\Mime\Presentation\MailBodyComposer.

Definition at line 52 of file HtmlMailBodyComposer.php.

52 : ComposedMailBody
53 {
54 $html = $source->transformedToHtml();
55 $html = $this->containsHtml($html) ? $html : nl2br($html);
56 $html = $this->refinery->string()->makeClickable()->transform($html);
57
58 $images = $this->assets->inlineImages();
59 $logo = $images->logo();
60 $page = $this->ui->layout()->page()->mail(
61 $this->assets->styleSheet()->path(),
62 'cid:' . ($logo?->cid() ?? ''),
63 $this->installation_title,
64 $this->ui->legacy()->content($html),
65 $this->data->link($this->installation_url, $this->data->uri($this->installation_url))
66 );
67 $plain_text = $this->plain_text->compose(new MailBodySource($html));
68
69 return new ComposedMailBody(
70 $this->renderer->render($page),
71 $plain_text->body(),
72 $images
73 );
74 }
renderer()

References $page, ILIAS\Mail\Mime\Presentation\HtmlMailBodyComposer\containsHtml(), ILIAS\Repository\refinery(), renderer(), ILIAS\Mail\Mime\Presentation\MailBodySource\transformedToHtml(), and ILIAS\Repository\ui().

+ Here is the call graph for this function:

◆ containsHtml()

ILIAS\Mail\Mime\Presentation\HtmlMailBodyComposer::containsHtml ( string  $email_body)
private

Definition at line 76 of file HtmlMailBodyComposer.php.

76 : bool
77 {
78 if (!str_contains($email_body, '<') || !str_contains($email_body, '>')) {
79 return false;
80 }
81
82 if (preg_match(self::BLOCK_ELEMENT_PATTERN, $email_body) === 1) {
83 return true;
84 }
85
86 return strip_tags($email_body, self::INLINE_TAGS) !== $email_body;
87 }

Referenced by ILIAS\Mail\Mime\Presentation\HtmlMailBodyComposer\compose().

+ Here is the caller graph for this function:

Field Documentation

◆ BLOCK_ELEMENT_PATTERN

const string ILIAS\Mail\Mime\Presentation\HtmlMailBodyComposer::BLOCK_ELEMENT_PATTERN = '~</?(p|br|div|ul|ol|li|code|pre|h[1-6])\b~i'
private

Definition at line 37 of file HtmlMailBodyComposer.php.

◆ INLINE_TAGS

const string ILIAS\Mail\Mime\Presentation\HtmlMailBodyComposer::INLINE_TAGS = '<b><u><i><a>'
private

Definition at line 38 of file HtmlMailBodyComposer.php.


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