summaryrefslogtreecommitdiff
path: root/program/steps/mail/attachments.inc
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-05-27 20:08:36 +0200
committerAleksander Machniak <alec@alec.pl>2014-05-27 20:08:36 +0200
commitb21f8bd3ef368563f2debf4e0debfb319ce763ea (patch)
treec4f6723f3c7dc321d9b3c75c3bb939b918601176 /program/steps/mail/attachments.inc
parentf41912e4cb4281358de8c22c72d47b05d2b8ec8f (diff)
Implemented image selector dialog for TinyMCE, css fixes in classic skin for TinyMCE4
Diffstat (limited to 'program/steps/mail/attachments.inc')
-rw-r--r--program/steps/mail/attachments.inc43
1 files changed, 42 insertions, 1 deletions
diff --git a/program/steps/mail/attachments.inc b/program/steps/mail/attachments.inc
index 85bc36cac..c8b7f9517 100644
--- a/program/steps/mail/attachments.inc
+++ b/program/steps/mail/attachments.inc
@@ -60,7 +60,7 @@ if ($RCMAIL->action=='remove-attachment') {
exit;
}
-if ($RCMAIL->action=='display-attachment') {
+if ($RCMAIL->action == 'display-attachment') {
$id = 'undefined';
if (preg_match('/^rcmfile(\w+)$/', $_GET['_file'], $regs)) {
@@ -76,6 +76,47 @@ if ($RCMAIL->action=='display-attachment') {
$attachment['size'] = $attachment['data'] ? strlen($attachment['data']) : @filesize($attachment['path']);
}
+ // generate image thumbnail for file browser in HTML editor
+ if (!empty($_GET['_thumbnail'])) {
+ $temp_dir = $RCMAIL->config->get('temp_dir');
+ $thumbnail_size = 80;
+ list(,$ext) = explode('/', $attachment['mimetype']);
+ $mimetype = $attachment['mimetype'];
+ $file_ident = $attachment['id'] . ':' . $attachment['mimetype'] . ':' . $attachment['size'];
+ $cache_basename = $temp_dir . '/' . md5($file_ident . ':' . $RCMAIL->user->ID . ':' . $thumbnail_size);
+ $cache_file = $cache_basename . '.' . $ext;
+
+ // render thumbnail image if not done yet
+ if (!is_file($cache_file)) {
+ if (!$attachment['path']) {
+ $orig_name = $filename = $cache_basename . '.orig.' . $ext;
+ file_put_contents($orig_name, $attachment['data']);
+ }
+ else {
+ $filename = $attachment['path'];
+ }
+
+ $image = new rcube_image($filename);
+ if ($imgtype = $image->resize($thumbnail_size, $cache_file, true)) {
+ $mimetype = 'image/' . $imgtype;
+
+ if ($orig_name) {
+ unlink($orig_name);
+ }
+ }
+ }
+
+ if (is_file($cache_file)) {
+ // cache for 1h
+ $RCMAIL->output->future_expire_header(3600);
+ header('Content-Type: ' . $mimetype);
+ header('Content-Length: ' . filesize($cache_file));
+
+ readfile($cache_file);
+ exit;
+ }
+ }
+
header('Content-Type: ' . $attachment['mimetype']);
header('Content-Length: ' . $attachment['size']);