Changeset View
Changeset View
Standalone View
Standalone View
plugins/libkolab/lib/kolab_attachments_handler.php
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public static function ui() | ||||
$rcmail->output->add_handler('plugin.filedroparea', array($self, 'files_drop_area')); | $rcmail->output->add_handler('plugin.filedroparea', array($self, 'files_drop_area')); | ||||
} | } | ||||
/** | /** | ||||
* Generate HTML element for attachments list | * Generate HTML element for attachments list | ||||
*/ | */ | ||||
public function files_list($attrib = array()) | public function files_list($attrib = array()) | ||||
{ | { | ||||
if (!$attrib['id']) { | if (empty($attrib['id'])) { | ||||
$attrib['id'] = 'kolabattachmentlist'; | $attrib['id'] = 'kolabattachmentlist'; | ||||
} | } | ||||
// define list of file types which can be displayed inline | // define list of file types which can be displayed inline | ||||
// same as in program/steps/mail/show.inc | // same as in program/steps/mail/show.inc | ||||
$this->rc->output->set_env('mimetypes', (array)$this->rc->config->get('client_mimetypes')); | $this->rc->output->set_env('mimetypes', (array)$this->rc->config->get('client_mimetypes')); | ||||
$this->rc->output->add_gui_object('attachmentlist', $attrib['id']); | $this->rc->output->add_gui_object('attachmentlist', $attrib['id']); | ||||
return html::tag('ul', $attrib, '', html::$common_attrib); | return html::tag('ul', $attrib, '', html::$common_attrib); | ||||
} | } | ||||
/** | /** | ||||
* Generate the form for event attachments upload | * Generate the form for event attachments upload | ||||
*/ | */ | ||||
public function files_form($attrib = array()) | public function files_form($attrib = array()) | ||||
{ | { | ||||
// add ID if not given | // add ID if not given | ||||
if (!$attrib['id']) { | if (empty($attrib['id'])) { | ||||
$attrib['id'] = 'kolabuploadform'; | $attrib['id'] = 'kolabuploadform'; | ||||
} | } | ||||
return $this->rc->upload_form($attrib, 'uploadform', 'upload-file', array('multiple' => true)); | return $this->rc->upload_form($attrib, 'uploadform', 'upload-file', array('multiple' => true)); | ||||
} | } | ||||
/** | /** | ||||
* Register UI object for HTML5 drag & drop file upload | * Register UI object for HTML5 drag & drop file upload | ||||
*/ | */ | ||||
public function files_drop_area($attrib = array()) | public function files_drop_area($attrib = array()) | ||||
{ | { | ||||
// add ID if not given | // add ID if not given | ||||
if (!$attrib['id']) { | if (empty($attrib['id'])) { | ||||
$attrib['id'] = 'kolabfiledroparea'; | $attrib['id'] = 'kolabfiledroparea'; | ||||
} | } | ||||
$this->rc->output->add_gui_object('filedrop', $attrib['id']); | $this->rc->output->add_gui_object('filedrop', $attrib['id']); | ||||
$this->rc->output->set_env('filedrop', array('action' => 'upload', 'fieldname' => '_attachments')); | $this->rc->output->set_env('filedrop', array('action' => 'upload', 'fieldname' => '_attachments')); | ||||
} | } | ||||
/** | /** | ||||
Show All 20 Lines | public function attachment_upload($session_key, $id_prefix = '') | ||||
// Upload progress update | // Upload progress update | ||||
if (!empty($_GET['_progress'])) { | if (!empty($_GET['_progress'])) { | ||||
$this->rc->upload_progress(); | $this->rc->upload_progress(); | ||||
} | } | ||||
$recid = $id_prefix . rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC); | $recid = $id_prefix . rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC); | ||||
$uploadid = rcube_utils::get_input_value('_uploadid', rcube_utils::INPUT_GPC); | $uploadid = rcube_utils::get_input_value('_uploadid', rcube_utils::INPUT_GPC); | ||||
if (!is_array($_SESSION[$session_key]) || $_SESSION[$session_key]['id'] != $recid) { | if (empty($_SESSION[$session_key]) || $_SESSION[$session_key]['id'] != $recid) { | ||||
$_SESSION[$session_key] = array(); | $_SESSION[$session_key] = array(); | ||||
$_SESSION[$session_key]['id'] = $recid; | $_SESSION[$session_key]['id'] = $recid; | ||||
$_SESSION[$session_key]['attachments'] = array(); | $_SESSION[$session_key]['attachments'] = array(); | ||||
} | } | ||||
// clear all stored output properties (like scripts and env vars) | // clear all stored output properties (like scripts and env vars) | ||||
$this->rc->output->reset(); | $this->rc->output->reset(); | ||||
Show All 17 Lines | public function attachment_upload($session_key, $id_prefix = '') | ||||
if (!$err && $attachment['status'] && !$attachment['abort']) { | if (!$err && $attachment['status'] && !$attachment['abort']) { | ||||
$id = $attachment['id']; | $id = $attachment['id']; | ||||
// store new attachment in session | // store new attachment in session | ||||
unset($attachment['status'], $attachment['abort']); | unset($attachment['status'], $attachment['abort']); | ||||
$this->rc->session->append($session_key . '.attachments', $id, $attachment); | $this->rc->session->append($session_key . '.attachments', $id, $attachment); | ||||
if (($icon = $_SESSION[$session_key . '_deleteicon']) && is_file($icon)) { | if (!empty($_SESSION[$session_key . '_deleteicon']) | ||||
&& ($icon = $_SESSION[$session_key . '_deleteicon']) | |||||
&& is_file($icon) | |||||
) { | |||||
$button = html::img(array( | $button = html::img(array( | ||||
'src' => $icon, | 'src' => $icon, | ||||
'alt' => $this->rc->gettext('delete') | 'alt' => $this->rc->gettext('delete') | ||||
)); | )); | ||||
} | } | ||||
else if ($_SESSION[$session_key . '_textbuttons']) { | else if (!empty($_SESSION[$session_key . '_textbuttons'])) { | ||||
$button = rcube::Q($this->rc->gettext('delete')); | $button = rcube::Q($this->rc->gettext('delete')); | ||||
} | } | ||||
else { | else { | ||||
$button = ''; | $button = ''; | ||||
} | } | ||||
$link_content = sprintf('<span class="attachment-name">%s</span><span class="attachment-size">(%s)</span>', | $link_content = sprintf('<span class="attachment-name">%s</span><span class="attachment-size">(%s)</span>', | ||||
rcube::Q($attachment['name']), $this->rc->show_bytes($attachment['size'])); | rcube::Q($attachment['name']), $this->rc->show_bytes($attachment['size'])); | ||||
$delete_link = html::a(array( | $delete_link = html::a(array( | ||||
'href' => "#delete", | 'href' => "#delete", | ||||
'class' => 'delete', | 'class' => 'delete', | ||||
'onclick' => sprintf("return %s.remove_from_attachment_list('rcmfile%s')", rcmail_output::JS_OBJECT_NAME, $id), | 'onclick' => sprintf("return %s.remove_from_attachment_list('rcmfile%s')", rcmail_output::JS_OBJECT_NAME, $id), | ||||
'title' => $this->rc->gettext('delete'), | 'title' => $this->rc->gettext('delete'), | ||||
'aria-label' => $this->rc->gettext('delete') . ' ' . $attachment['name'], | 'aria-label' => $this->rc->gettext('delete') . ' ' . $attachment['name'], | ||||
), $button); | ), $button); | ||||
$content_link = html::a(array( | $content_link = html::a(array( | ||||
'href' => "#load", | 'href' => "#load", | ||||
'class' => 'filename', | 'class' => 'filename', | ||||
'onclick' => 'return false', // sprintf("return %s.command('load-attachment','rcmfile%s', this, event)", rcmail_output::JS_OBJECT_NAME, $id), | 'onclick' => 'return false', // sprintf("return %s.command('load-attachment','rcmfile%s', this, event)", rcmail_output::JS_OBJECT_NAME, $id), | ||||
), $link_content); | ), $link_content); | ||||
$content .= $_SESSION[$session_key . '_icon_pos'] == 'left' ? $delete_link.$content_link : $content_link.$delete_link; | $left = !empty($_SESSION[$session_key . '_icon_pos']) && $_SESSION[$session_key . '_icon_pos'] == 'left'; | ||||
$content = $left ? $delete_link.$content_link : $content_link.$delete_link; | |||||
$this->rc->output->command('add2attachment_list', "rcmfile$id", array( | $this->rc->output->command('add2attachment_list', "rcmfile$id", array( | ||||
'html' => $content, | 'html' => $content, | ||||
'name' => $attachment['name'], | 'name' => $attachment['name'], | ||||
'mimetype' => $attachment['mimetype'], | 'mimetype' => $attachment['mimetype'], | ||||
'classname' => 'no-menu ' . rcube_utils::file2class($attachment['mimetype'], $attachment['name']), | 'classname' => 'no-menu ' . rcube_utils::file2class($attachment['mimetype'], $attachment['name']), | ||||
'complete' => true | 'complete' => true | ||||
), $uploadid); | ), $uploadid); | ||||
} | } | ||||
else { // upload failed | else { // upload failed | ||||
if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { | if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { | ||||
$msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array( | $msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array( | ||||
'size' => $this->rc->show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); | 'size' => $this->rc->show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); | ||||
} | } | ||||
else if ($attachment['error']) { | else if (!empty($attachment['error'])) { | ||||
$msg = $attachment['error']; | $msg = $attachment['error']; | ||||
} | } | ||||
else { | else { | ||||
$msg = $this->rc->gettext('fileuploaderror'); | $msg = $this->rc->gettext('fileuploaderror'); | ||||
} | } | ||||
$this->rc->output->command('display_message', $msg, 'error'); | $this->rc->output->command('display_message', $msg, 'error'); | ||||
$this->rc->output->command('remove_from_attachment_list', $uploadid); | $this->rc->output->command('remove_from_attachment_list', $uploadid); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
else if ($_SERVER['REQUEST_METHOD'] == 'POST') { | else if ($_SERVER['REQUEST_METHOD'] == 'POST') { | ||||
// if filesize exceeds post_max_size then $_FILES array is empty, | // if filesize exceeds post_max_size then $_FILES array is empty, | ||||
// show filesizeerror instead of fileuploaderror | // show filesizeerror instead of fileuploaderror | ||||
if ($maxsize = ini_get('post_max_size')) | if ($maxsize = ini_get('post_max_size')) { | ||||
$msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array( | $msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array( | ||||
'size' => $this->rc->show_bytes(parse_bytes($maxsize))))); | 'size' => $this->rc->show_bytes(parse_bytes($maxsize))))); | ||||
else | } | ||||
else { | |||||
$msg = $this->rc->gettext('fileuploaderror'); | $msg = $this->rc->gettext('fileuploaderror'); | ||||
} | |||||
$this->rc->output->command('display_message', $msg, 'error'); | $this->rc->output->command('display_message', $msg, 'error'); | ||||
$this->rc->output->command('remove_from_attachment_list', $uploadid); | $this->rc->output->command('remove_from_attachment_list', $uploadid); | ||||
} | } | ||||
$this->rc->output->send('iframe'); | $this->rc->output->send('iframe'); | ||||
} | } | ||||
/** | /** | ||||
* Deliver an event/task attachment to the client | * Deliver an event/task attachment to the client | ||||
* (similar as in Roundcube core program/steps/mail/get.inc) | * (similar as in Roundcube core program/steps/mail/get.inc) | ||||
*/ | */ | ||||
public function attachment_get($attachment) | public function attachment_get($attachment) | ||||
{ | { | ||||
ob_end_clean(); | ob_end_clean(); | ||||
if ($attachment && $attachment['body']) { | if ($attachment && !empty($attachment['body'])) { | ||||
// allow post-processing of the attachment body | // allow post-processing of the attachment body | ||||
$part = new rcube_message_part; | $part = new rcube_message_part; | ||||
$part->filename = $attachment['name']; | $part->filename = $attachment['name']; | ||||
$part->size = $attachment['size']; | $part->size = $attachment['size']; | ||||
$part->mimetype = $attachment['mimetype']; | $part->mimetype = $attachment['mimetype']; | ||||
$plugin = $this->rc->plugins->exec_hook('message_part_get', array( | $plugin = $this->rc->plugins->exec_hook('message_part_get', array( | ||||
'body' => $attachment['body'], | 'body' => $attachment['body'], | ||||
▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines |