Unify inline warnings in rcmail_html_page

pull/5838/head
Aleksander Machniak 9 years ago
parent 51dffcda86
commit b1be7fca51

@ -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 = '<html><body></body></html>';
}
if ($this->inline_warning) {
$body_start = 0;
if ($body_pos = strpos($contents, '<body')) {
$body_start = 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);
}
}

@ -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 = '<html><body>'
. $RCMAIL->gettext('messagetoobig'). ' '
. html::a($RCMAIL->url(array_merge($_GET, array('download' => 1))), $RCMAIL->gettext('download'))
. '</body></html>';
$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')) {
$body_start = 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')) . '&nbsp;' .
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;
}

@ -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;
}

Loading…
Cancel
Save