From b1be7fca515cda1de2d13aaaf4b640779248b73c Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 3 Apr 2017 16:23:28 +0200 Subject: [PATCH] Unify inline warnings in rcmail_html_page --- program/include/rcmail_html_page.php | 37 ++++++++++++++++- program/steps/mail/get.inc | 59 ++++++++++++---------------- skins/larry/embed.css | 12 +++--- 3 files changed, 69 insertions(+), 39 deletions(-) diff --git a/program/include/rcmail_html_page.php b/program/include/rcmail_html_page.php index 9a7047d3e..462228fc8 100644 --- a/program/include/rcmail_html_page.php +++ b/program/include/rcmail_html_page.php @@ -27,12 +27,14 @@ */ class rcmail_html_page extends rcmail_output_html { + protected $inline_warning; + public function write($contents = '') { self::reset(true); // load embed.css from skin folder (if exists) - if ($embed_css = $this->get_skin_file('/embed.css')) { + if ($embed_css = $this->get_skin_file($this->config->get('embed_css_location', '/embed.css'))) { $this->include_css($embed_css); } else { // set default styles for warning blocks inside the attachment part frame @@ -43,6 +45,39 @@ class rcmail_html_page extends rcmail_output_html )); } + if (empty($contents)) { + $contents = ''; + } + + if ($this->inline_warning) { + $body_start = 0; + if ($body_pos = strpos($contents, '', $body_pos) + 1; + } + + $contents = substr_replace($contents, $this->inline_warning, $body_start, 0); + } + parent::write($contents); } + + /** + * Add inline warning with optional button + * + * @param string $text Warning content + * @param string $button_label Button label + * @param string $button_url Button URL + */ + public function register_inline_warning($text, $button_label = null, $button_url = null) + { + $text = rcube::Q($text); + + if ($button_label) { + $onclick = "location.href = '$button_url'"; + $button = html::tag('button', array('onclick' => $onclick), rcube::Q($button_label)); + $text .= html::p(array('class' => 'rcmail-inline-buttons'), $button); + } + + $this->inline_warning = html::div(array('class' => 'rcmail-inline-message rcmail-inline-warning'), $text); + } } diff --git a/program/steps/mail/get.inc b/program/steps/mail/get.inc index 62c9e4372..e8a3a38ce 100644 --- a/program/steps/mail/get.inc +++ b/program/steps/mail/get.inc @@ -182,24 +182,23 @@ if (empty($_GET['_thumb']) && $attachment->is_valid()) { header("Content-Length: " . strlen($content)); echo $content; } - else { // html warning with a button to load the file anyway + // html warning with a button to load the file anyway + else { $OUTPUT = new rcmail_html_page(); - $OUTPUT->write(html::tag('html', null, html::tag('body', 'embed', - html::div(array('class' => 'rcmail-inline-message rcmail-inline-warning'), + $OUTPUT->register_inline_warning( $RCMAIL->gettext(array( - 'name' => 'attachmentvalidationerror', - 'vars' => array( - 'expected' => $mimetype . ($file_extension ? " (.$file_extension)" : ''), - 'detected' => $real_mimetype . ($extensions[0] ? " (.$extensions[0])" : ''), + 'name' => 'attachmentvalidationerror', + 'vars' => array( + 'expected' => $mimetype . ($file_extension ? " (.$file_extension)" : ''), + 'detected' => $real_mimetype . ($extensions[0] ? " (.$extensions[0])" : ''), + ) ) - )) - . html::p(array('class' => 'rcmail-inline-buttons'), - html::tag('button', array( - 'onclick' => "location.href='" . $RCMAIL->url(array_merge($_GET, array('_nocheck' => 1))) . "'" - ), - $RCMAIL->gettext('showanyway')) - ) - )))); + ), + $RCMAIL->gettext('showanyway'), + $RCMAIL->url(array_merge($_GET, array('_nocheck' => 1))) + ); + + $OUTPUT->write(); } exit; @@ -232,13 +231,16 @@ if (empty($_GET['_thumb']) && $attachment->is_valid()) { // deliver part content if ($mimetype == 'text/html' && empty($_GET['_download'])) { + $OUTPUT = new rcmail_html_page(); + // Check if we have enough memory to handle the message in it // #1487424: we need up to 10x more memory than the body if (!rcube_utils::mem_check($attachment->size * 10)) { - $out = '' - . $RCMAIL->gettext('messagetoobig'). ' ' - . html::a($RCMAIL->url(array_merge($_GET, array('download' => 1))), $RCMAIL->gettext('download')) - . ''; + $OUTPUT->register_inline_warning( + $RCMAIL->gettext('messagetoobig'), + $RCMAIL->gettext('download'), + $RCMAIL->url(array_merge($_GET, array('_download' => 1))) + ); } else { // render HTML body @@ -246,23 +248,14 @@ if (empty($_GET['_thumb']) && $attachment->is_valid()) { // insert remote objects warning into HTML body if ($REMOTE_OBJECTS) { - $body_start = 0; - if ($body_pos = strpos($out, '', $body_pos) + 1; - } - - $out = substr($out, 0, $body_start) - . html::div(array('class' => 'rcmail-inline-message rcmail-inline-warning'), - rcube::Q($RCMAIL->gettext('blockedimages')) . ' ' . - html::tag('button', - array('onclick' => "location.href='" . $RCMAIL->url(array_merge($_GET, array('_safe' => 1))) . "'"), - rcube::Q($RCMAIL->gettext('showimages'))) - ) - . substr($out, $body_start); + $OUTPUT->register_inline_warning( + $RCMAIL->gettext('blockedimages'), + $RCMAIL->gettext('showimages'), + $RCMAIL->url(array_merge($_GET, array('_safe' => 1))) + ); } } - $OUTPUT = new rcmail_html_page(); $OUTPUT->write($out); exit; } diff --git a/skins/larry/embed.css b/skins/larry/embed.css index 2c8ba39dc..53d02a94a 100644 --- a/skins/larry/embed.css +++ b/skins/larry/embed.css @@ -20,15 +20,17 @@ margin-bottom: 0.8em; } -.rcmail-inline-message > button { - margin-left: 1em; - vertical-align: baseline; -} - .rcmail-inline-message em { font-size: 90%; } .rcmail-inline-buttons { margin-bottom: 0; + display: inline; +} + +.rcmail-inline-buttons > button { + margin-left: 1em; + vertical-align: baseline; + line-height: 12px; }