Allow odfviewer to hook into calendar attachments in order to display open office documents inline

This commit is contained in:
Thomas Bruederli 2012-04-25 21:15:07 +02:00
parent 1b09ae2801
commit 1067ef9827
2 changed files with 31 additions and 17 deletions

View file

@ -1552,19 +1552,29 @@ class calendar extends rcube_plugin
}
if ($attachment) {
$mimetype = strtolower($attachment['mimetype']);
// allow post-processing of the attachment body
$part = new rcube_message_part;
$part->filename = $attachment['name'];
$part->size = $attachment['size'];
$part->mimetype = $attachment['mimetype'];
$plugin = $this->rc->plugins->exec_hook('message_part_get', array(
'body' => $this->driver->get_attachment_body($id, $event),
'mimetype' => strtolower($attachment['mimetype']),
'download' => !empty($_GET['_download']),
'part' => $part,
));
if ($plugin['abort'])
exit;
$mimetype = $plugin['mimetype'];
list($ctype_primary, $ctype_secondary) = explode('/', $mimetype);
$body = $this->driver->get_attachment_body($id, $event);
// TODO: allow post-processing of the attachment body
//$plugin = $RCMAIL->plugins->exec_hook('message_part_get',
// array('uid' => $MESSAGE->uid, 'id' => $part->mime_id, 'mimetype' => $mimetype, 'part' => $part, 'download' => !empty($_GET['_download'])));
$browser = $this->rc->output->browser;
// send download headers
if ($_GET['_download']) {
if ($plugin['download']) {
header("Content-Type: application/octet-stream");
if ($browser->ie)
header("Content-Type: application/force-download");
@ -1582,7 +1592,7 @@ class calendar extends rcube_plugin
if ($mimetype == 'text/html' && empty($_GET['_download'])) {
$OUTPUT = new rcube_html_page();
// @TODO: use washtml on $body
$OUTPUT->write($body);
$OUTPUT->write($plugin['body']);
}
else {
// don't kill the connection if download takes more than 30 sec.
@ -1601,7 +1611,7 @@ class calendar extends rcube_plugin
$disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
header("Content-Disposition: $disposition; filename=\"$filename\"");
echo $body;
echo $plugin['body'];
}
exit;

View file

@ -26,7 +26,7 @@
*/
class odfviewer extends rcube_plugin
{
public $task = 'mail|logout';
public $task = 'mail|calendar|logout';
private $tempdir = 'plugins/odfviewer/files/';
private $tempbase = 'plugins/odfviewer/files/';
@ -56,10 +56,9 @@ class odfviewer extends rcube_plugin
$ua = new rcube_browser;
if ($ua->ie && $ua->ver < 9)
return;
// extend list of mimetypes that should open in preview
$rcmail = rcmail::get_instance();
if ($rcmail->action == 'preview' || $rcmail->action == 'show') {
if ($rcmail->action == 'preview' || $rcmail->action == 'show' || $rcmail->task == 'calendar') {
$mimetypes = $rcmail->config->get('client_mimetypes', 'text/plain,text/html,text/xml,image/jpeg,image/gif,image/png,application/x-javascript,application/pdf,application/x-shockwave-flash');
if (!is_array($mimetypes))
$mimetypes = explode(',', $mimetypes);
@ -83,10 +82,15 @@ class odfviewer extends rcube_plugin
// FIXME: copy file to disk because only apache can send the file correctly
$tempfn = $this->tempdir . $fn;
if (!file_exists($tempfn)) {
$fp = fopen($tempfn, 'w');
$imap = rcmail::get_instance()->get_storage();
$imap->get_message_part($args['uid'], $args['id'], $args['part'], false, $fp);
fclose($fp);
if ($args['body']) {
file_put_contents($tempfn, $args['body']);
}
else {
$fp = fopen($tempfn, 'w');
$imap = rcmail::get_instance()->get_storage();
$imap->get_message_part($args['uid'], $args['id'], $args['part'], false, $fp);
fclose($fp);
}
// remember tempfiles in session to clean up on logout
$_SESSION['odfviewer']['tempfiles'][] = $fn;