| | |
| | | // check requirements first |
| | | if (!class_exists('ZipArchive', false)) { |
| | | rcmail::raise_error(array( |
| | | 'code' => 520, 'type' => 'php', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | | 'code' => 520, |
| | | 'file' => __FILE__, |
| | | 'line' => __LINE__, |
| | | 'message' => "php_zip extension is required for the zipdownload plugin"), true, false); |
| | | return; |
| | | } |
| | |
| | | $this->charset = $rcmail->config->get('zipdownload_charset', RCUBE_CHARSET); |
| | | $this->add_texts('localization'); |
| | | |
| | | if ($rcmail->config->get('zipdownload_attachments', 1) > -1 && ($rcmail->action == 'show' || $rcmail->action == 'preview')) |
| | | if ($rcmail->config->get('zipdownload_attachments', 1) > -1 && ($rcmail->action == 'show' || $rcmail->action == 'preview')) { |
| | | $this->add_hook('template_object_messageattachments', array($this, 'attachment_ziplink')); |
| | | } |
| | | |
| | | $this->register_action('plugin.zipdownload.zip_attachments', array($this, 'download_attachments')); |
| | | $this->register_action('plugin.zipdownload.zip_messages', array($this, 'download_selection')); |
| | | $this->register_action('plugin.zipdownload.zip_folder', array($this, 'download_folder')); |
| | | |
| | | if ($rcmail->config->get('zipdownload_folder', false) || $rcmail->config->get('zipdownload_selection', false)) { |
| | | if (($selection = $rcmail->config->get('zipdownload_selection')) || $rcmail->config->get('zipdownload_folder')) { |
| | | $this->include_script('zipdownload.js'); |
| | | $this->api->output->set_env('zipdownload_selection', $rcmail->config->get('zipdownload_selection', false)); |
| | | $this->api->output->set_env('zipdownload_selection', $selection); |
| | | |
| | | if ($rcmail->config->get('zipdownload_folder', false) && ($rcmail->action == '' || $rcmail->action == 'show')) { |
| | | $zipdownload = $this->api->output->button(array('command' => 'plugin.zipdownload.zip_folder', 'type' => 'link', 'classact' => 'active', 'content' => $this->gettext('downloadfolder'))); |
| | |
| | | public function download_attachments() |
| | | { |
| | | $rcmail = rcmail::get_instance(); |
| | | $imap = $rcmail->storage; |
| | | $imap = $rcmail->get_storage(); |
| | | $temp_dir = $rcmail->config->get('temp_dir'); |
| | | $tmpfname = tempnam($temp_dir, 'zipdownload'); |
| | | $tempfiles = array($tmpfname); |
| | |
| | | fclose($tmpfp); |
| | | $zip->addFile($tmpfn, $disp_name); |
| | | } |
| | | |
| | | } |
| | | |
| | | $zip->close(); |
| | |
| | | $this->_deliver_zipfile($tmpfname, $filename); |
| | | |
| | | // delete temporary files from disk |
| | | foreach ($tempfiles as $tmpfn) |
| | | foreach ($tempfiles as $tmpfn) { |
| | | unlink($tmpfn); |
| | | } |
| | | |
| | | exit; |
| | | } |
| | |
| | | if (isset($_REQUEST['_uid'])) { |
| | | $uids = explode(",", rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GPC)); |
| | | |
| | | if (sizeof($uids) > 0) |
| | | if (sizeof($uids) > 0) { |
| | | $this->_download_messages($uids); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | public function download_folder() |
| | | { |
| | | $imap = rcmail::get_instance()->storage; |
| | | $imap = rcmail::get_instance()->get_storage(); |
| | | $mbox_name = $imap->get_folder(); |
| | | |
| | | // initialize searching result if search_filter is used |
| | |
| | | private function _download_messages($uids) |
| | | { |
| | | $rcmail = rcmail::get_instance(); |
| | | $imap = $rcmail->storage; |
| | | $imap = $rcmail->get_storage(); |
| | | $temp_dir = $rcmail->config->get('temp_dir'); |
| | | $tmpfname = tempnam($temp_dir, 'zipdownload'); |
| | | $tempfiles = array($tmpfname); |
| | |
| | | $this->_deliver_zipfile($tmpfname, $imap->get_folder() . '.zip'); |
| | | |
| | | // delete temporary files from disk |
| | | foreach ($tempfiles as $tmpfn) |
| | | foreach ($tempfiles as $tmpfn) { |
| | | unlink($tmpfn); |
| | | } |
| | | |
| | | exit; |
| | | } |
| | |
| | | |
| | | // send download headers |
| | | header("Content-Type: application/octet-stream"); |
| | | if ($browser->ie) |
| | | if ($browser->ie) { |
| | | header("Content-Type: application/force-download"); |
| | | } |
| | | |
| | | // don't kill the connection if download takes more than 30 sec. |
| | | @set_time_limit(0); |