public static function getMediaOutput($id, $type, $className)
 {
     if ($type == 'list') {
         $component = Kwf_Component_Data_Root::getInstance()->getComponentById($id);
         if ($component) {
             $galleryComponent = $component->parent;
             $components = $galleryComponent->getChildComponents(array('generator' => 'child'));
             $paths = array();
             foreach ($components as $component) {
                 $data = $component->getComponent()->getImageData();
                 if ($data['file']) {
                     $paths[$data['file']] = $data['filename'];
                 }
             }
         }
         if (!$paths) {
             throw new Kwf_Exception_NotFound();
         }
         Kwf_Util_TempCleaner::clean();
         $tmpname = "temp/" . uniqid() . ".zip";
         $zip = new ZipArchive();
         if ($zip->open($tmpname, ZIPARCHIVE::CREATE) !== TRUE) {
             throw new Kwf_Exception('Could not open file for writing: ' . $filename);
         }
         foreach ($paths as $path => $filename) {
             $zip->addFile($path, $filename);
         }
         $zip->close();
         $file = array('file' => $tmpname, 'mimeType' => 'application/zip', 'downloadFilename' => $galleryComponent->getPage()->name . '.zip');
         Kwf_Media_Output::output($file);
         exit;
     }
 }
Exemple #2
0
 public function downloadXlsFileAction()
 {
     if (!isset($this->_permissions['xls']) || !$this->_permissions['xls']) {
         throw new Kwf_Exception("XLS is not allowed.");
     }
     if (!file_exists('temp/' . $this->_getParam('downloadkey') . '.xls')) {
         throw new Kwf_Exception('Wrong downloadkey submitted');
     }
     Kwf_Util_TempCleaner::clean();
     $file = array('contents' => file_get_contents('temp/' . $this->_getParam('downloadkey') . '.xls'), 'mimeType' => 'application/octet-stream', 'downloadFilename' => 'form_' . date('Ymd-Hi') . '.xls');
     Kwf_Media_Output::output($file);
     $this->_helper->viewRenderer->setNoRender();
 }
Exemple #3
0
 public function downloadXlsFileByKey($downloadkey)
 {
     if (!file_exists('temp/' . $downloadkey . '.xls')) {
         throw new Kwf_Exception('Wrong downloadkey submitted');
     }
     Kwf_Util_TempCleaner::clean();
     $file = array('contents' => file_get_contents('temp/' . $downloadkey . '.xls'), 'mimeType' => 'application/octet-stream', 'downloadFilename' => 'form_' . date('Ymd-Hi') . '.xls');
     Kwf_Media_Output::output($file);
     $this->_helper->viewRenderer->setNoRender();
 }
 public function downloadExportFileAction()
 {
     if (!isset($this->_permissions['xls']) || !$this->_permissions['xls']) {
         throw new Kwf_Exception("XLS is not allowed.");
     }
     if (class_exists('XMLWriter')) {
         $suffix = 'xlsx';
         $mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
     } else {
         $suffix = 'xls';
         $mimeType = 'application/msexcel';
     }
     if (!file_exists('temp/' . $this->_getParam('downloadkey') . '.' . $suffix)) {
         throw new Kwf_Exception('Wrong downloadkey submitted');
     }
     Kwf_Util_TempCleaner::clean();
     $file = array('contents' => file_get_contents('temp/' . $this->_getParam('downloadkey') . '.' . $suffix), 'mimeType' => $mimeType, 'downloadFilename' => 'export_' . date('Ymd-Hi') . '.' . $suffix);
     Kwf_Media_Output::output($file);
     $this->_helper->viewRenderer->setNoRender();
 }