Add some more functions for adding specific elements to mails

This commit is contained in:
Joshua Ramon Enslin 2020-10-22 14:02:01 +02:00 committed by Stefan Rohde-Enslin
parent ae2d83172d
commit 85c4ddeb78
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -16,6 +16,8 @@ final class MDMailFormat {
const CSS_H2 = "margin: .3em 0 .5em 0; padding: 0 0 0 0; font-size: 1.1em; font-weight: bold;";
const CSS_P = "margin: 0 0 0 0; padding: .4em 0 .6em 0; font-style: normal;";
const CSS_FOOTER = "margin-top: .5em; padding-top: .5em; border-top: .1em solid #D6D6D6;";
const CSS_UL = "margin: 1em 0; padding: 0 0 0 1em; list-style: square;";
const CSS_OL = "margin: 1em 0; padding: 0 0 0 1em;";
const CSS_A_NORMAL = "text-decoration: none;";
const CSS_A_FOOTER = "text-decoration: none; font-size: .95em;";
const CSS_A_FOOTER_HOVER = "color: " . self::ACCENT_COLOR_SEC . " !important;";
@ -42,6 +44,8 @@ final class MDMailFormat {
*/
public function appendHeadline(string $input):void {
$input = trim($input);
$this->_msg_html .= "<h1 style='" . self::CSS_H1 . "'>" . nl2br($input) . "</h1>";
$this->_msg_plain .= "{$input}
===================
@ -58,6 +62,8 @@ final class MDMailFormat {
*/
public function appendHeadlineSec(string $input):void {
$input = trim($input);
$this->_msg_html .= "<h2 style='" . self::CSS_H2 . "'>" . nl2br($input) . "</h2>";
$this->_msg_plain .= "{$input}
-------------------
@ -74,6 +80,8 @@ final class MDMailFormat {
*/
public function appendParagraph(string $input):void {
$input = trim($input);
$this->_msg_html .= "<p style='" . self::CSS_P . "'>" . nl2br($input) . "</p>";
$this->_msg_plain .= "
{$input}
@ -91,6 +99,8 @@ final class MDMailFormat {
*/
public function appendButton(string $href, string $input):void {
$input = trim($input);
$this->_msg_html .= "<a style='" . self::CSS_A_BUTTONLIKE . "' class='buttonLike' href='" . $href . "'>" . nl2br($input) . "</a>";
$this->_msg_plain .= "
{$input}: {$href}
@ -108,6 +118,8 @@ final class MDMailFormat {
*/
public function appendLink(string $href, string $input):void {
$input = trim($input);
$this->_msg_html .= "<a style='" . self::CSS_A_NORMAL . "' href='" . $href . "'>" . nl2br($input) . "</a>";
$this->_msg_plain .= "{$input}: {$href}";
@ -119,7 +131,7 @@ final class MDMailFormat {
* @return void
*/
public function startUl():void {
$this->_msg_html .= "<ul>";
$this->_msg_html .= "<ul style='" . self::CSS_UL . "'>";
$this->_msg_plain .= PHP_EOL;
}
@ -141,7 +153,7 @@ final class MDMailFormat {
* @return void
*/
public function startOl():void {
$this->_msg_html .= "<ol>";
$this->_msg_html .= "<ol style='" . self::CSS_OL . "'>";
$this->_msg_plain .= PHP_EOL;
}
@ -157,6 +169,22 @@ final class MDMailFormat {
}
/**
* Function for appending a list item in an unordered list.
*
* @param string $input Input text.
*
* @return void
*/
public function appendLiUl(string $input):void {
$input = trim($input);
$this->_msg_html .= "<li>{$input}</li>";
$this->_msg_plain .= PHP_EOL . "- {$input}";
}
/**
* Function for starting a list item in an unordered list.
*
@ -191,6 +219,31 @@ final class MDMailFormat {
}
/**
* Function for horizontal rule.
*
* @return void
*/
public function appendHr():void {
$this->_msg_html .= "<hr />";
$this->_msg_plain .= PHP_EOL . "----------" . PHP_EOL;
}
/**
* Function for appending simple text.
*
* @param string $input Input text.
*
* @return void
*/
public function appendInlineText(string $input):void {
$input = trim($input);
$this->_msg_html .= $input . " ";
$this->_msg_plain .= $input . " ";
}
// Getters
/**
@ -212,6 +265,8 @@ final class MDMailFormat {
a.buttonLike { ' . self::CSS_A_BUTTONLIKE . ' }
a.buttonLike:hover { ' . self::CSS_A_BUTTONLIKE_HOVER . ' }
p { ' . self::CSS_P . ' }
ul { ' . self::CSS_UL . ' }
ol { ' . self::CSS_OL . ' }
#footer { ' . self::CSS_FOOTER . ' }
#footer a { ' . self::CSS_A_FOOTER . ' }
#footer a:hover { ' . self::CSS_A_FOOTER_HOVER . ' }