From 3f3844b3402bb4a632adb89bf9cd3bb00b8a5ac0 Mon Sep 17 00:00:00 2001 From: synox Date: Tue, 12 Mar 2019 09:27:45 +0700 Subject: [PATCH] seperate layout from content to enable using two seperate web pages. --- src/controller.php | 4 +- src/frontend.template.php | 366 ---------------------------------- src/templates/base_layout.php | 128 ++++++++++++ src/templates/inbox.php | 271 +++++++++++++++++++++++++ 4 files changed, 401 insertions(+), 368 deletions(-) delete mode 100644 src/frontend.template.php create mode 100644 src/templates/base_layout.php create mode 100644 src/templates/inbox.php diff --git a/src/controller.php b/src/controller.php index 377258b..aedbcd9 100644 --- a/src/controller.php +++ b/src/controller.php @@ -27,8 +27,8 @@ class DisplayEmailsController { } public static function render($emails, $config, $user) { - // variables that have to be defined here for frontend template: $emails, $config - require "frontend.template.php"; + // variables that have to be defined here for frontend template: $emails, $config, $user + require "templates/inbox.php"; } } diff --git a/src/frontend.template.php b/src/frontend.template.php deleted file mode 100644 index 6a2f970..0000000 --- a/src/frontend.template.php +++ /dev/null @@ -1,366 +0,0 @@ -set('HTML.Nofollow', true); -$purifier_config->set('HTML.ForbiddenElements', array("img")); -$purifier = new HTMLPurifier($purifier_config); - -\Moment\Moment::setLocale($config['locale']); - -$mailIds = array_map(function ($mail) { - return $mail->id; -}, $emails); -$mailIdsJoinedString = filter_var(join('|', $mailIds), FILTER_SANITIZE_SPECIAL_CHARS); - -// define bigger renderings here to keep the php sections within the html short. -function niceDate($date) { - $m = new \Moment\Moment($date, date_default_timezone_get()); - return $m->calendar(); -} - -function printMessageBody($email, $purifier) { - global $config; - - // To avoid showing empty mails, first purify the html and plaintext - // before checking if they are empty. - $safeHtml = $purifier->purify($email->textHtml); - - $safeText = htmlspecialchars($email->textPlain); - $safeText = nl2br($safeText); - $safeText = \AutoLinkExtension::auto_link_text($safeText); - - $hasHtml = strlen(trim($safeHtml)) > 0; - $hasText = strlen(trim($safeText)) > 0; - - if ($config['prefer_plaintext']) { - if ($hasText) { - echo $safeText; - } else { - echo $safeHtml; - } - } else { - if ($hasHtml) { - echo $safeHtml; - } else { - echo $safeText; - } - } -} - -?> - - - - - - - - - - - - <?php - echo $emails ? "(" . count($emails) . ") " : ""; - echo $user->address ?> - - - - - - - - - -
- - -
 
-
- -
-
-

- Your disposable mailbox is ready. -

-
- -
- address ?>  -
- - -
- -
-
- - -
-
-
-

- - - Open random mailbox - -

- - - or create your own address: -
-
- - -
-
- -
-
-
@
-
- - - - -
-
-
- -
-
- -
-
-
-
-
- -
-
- -
- - id, FILTER_VALIDATE_INT); ?> - - - - - - - - -
-

The mailbox is empty. Checking for new emails automatically.

-
-
-
-
-
-
-
-
- -
-
-
- - - - - - - - - - - - - - diff --git a/src/templates/base_layout.php b/src/templates/base_layout.php new file mode 100644 index 0000000..9b16315 --- /dev/null +++ b/src/templates/base_layout.php @@ -0,0 +1,128 @@ + + + + + + + + + + + + + <?php $titleRenderer() ?> + + + + + + + + + + +
+
+ +
+
+ +
+
+ +
+
+ + + + + + + + + + + + + diff --git a/src/templates/inbox.php b/src/templates/inbox.php new file mode 100644 index 0000000..d159e0c --- /dev/null +++ b/src/templates/inbox.php @@ -0,0 +1,271 @@ +set('HTML.Nofollow', true); +$purifier_config->set('HTML.ForbiddenElements', array("img")); +global $purifier; +$purifier = new HTMLPurifier($purifier_config); + +\Moment\Moment::setLocale($config['locale']); + +// Helper methods + +function niceDate($date) { + $m = new \Moment\Moment($date, date_default_timezone_get()); + return $m->calendar(); +} + +function printMessageBody($email) { + global $config, $purifier; + + // To avoid showing empty mails, first purify the html and plaintext + // before checking if they are empty. + $safeHtml = $purifier->purify($email->textHtml); + + $safeText = htmlspecialchars($email->textPlain); + $safeText = nl2br($safeText); + $safeText = \AutoLinkExtension::auto_link_text($safeText); + + $hasHtml = strlen(trim($safeHtml)) > 0; + $hasText = strlen(trim($safeText)) > 0; + + if ($config['prefer_plaintext']) { + if ($hasText) { + echo $safeText; + } else { + echo $safeHtml; + } + } else { + if ($hasHtml) { + echo $safeHtml; + } else { + echo $safeText; + } + } +} + +// Template sections: + +$titleRenderer = function () use ($emails, $user) { + echo $emails ? "(" . count($emails) . ") " : ""; + echo $user->address; +}; + + + +$preHeaderRenderer= function () use ($emails, $user) { + $mailIds = array_map(function ($mail) { + return $mail->id; + }, $emails); + $mailIdsJoinedString = filter_var(join('|', $mailIds), FILTER_SANITIZE_SPECIAL_CHARS); + + ?> + +
+ + +
 
+
+ + + +
+
+
+

+ + + Open random mailbox + +

+ + + or create your own address: +
+
+ + +
+
+ +
+
+
@
+
+ + + + +
+
+
+ +
+
+ +
+
+
+ + + +
+ + +
+

The mailbox is empty. Checking for new emails automatically.

+
+
+
+
+
+
+
+
+ +
+id, FILTER_VALIDATE_INT); ?> + + + + +
+ +
+