예제 #1
0
 /**
  * Download all media attached to specified object (not necessarily open for editing)
  * Includes all representation media attached to the specified object + any media attached to oter
  * objects in the same object hierarchy as the specified object. Used by the book viewer interfacce to 
  * initiate a download.
  */
 public function DownloadMedia()
 {
     if (!caObjectsDisplayDownloadLink($this->request)) {
         $this->postError(1100, _t('Cannot download media'), 'DetailController->DownloadMedia');
         return;
     }
     $pn_object_id = $this->request->getParameter('object_id', pInteger);
     $t_object = new ca_objects($pn_object_id);
     if (!($vn_object_id = $t_object->getPrimaryKey())) {
         return;
     }
     $ps_version = $this->request->getParameter('version', pString);
     if (!$ps_version) {
         $ps_version = 'original';
     }
     $this->view->setVar('version', $ps_version);
     $va_ancestor_ids = $t_object->getHierarchyAncestors(null, array('idsOnly' => true, 'includeSelf' => true));
     if ($vn_parent_id = array_pop($va_ancestor_ids)) {
         $t_object->load($vn_parent_id);
         array_unshift($va_ancestor_ids, $vn_parent_id);
     }
     $va_child_ids = $t_object->getHierarchyChildren(null, array('idsOnly' => true));
     foreach ($va_ancestor_ids as $vn_id) {
         array_unshift($va_child_ids, $vn_id);
     }
     $vn_c = 1;
     $va_file_names = array();
     $va_file_paths = array();
     foreach ($va_child_ids as $vn_object_id) {
         $t_object = new ca_objects($vn_object_id);
         if (!$t_object->getPrimaryKey()) {
             continue;
         }
         $va_reps = $t_object->getRepresentations(array($ps_version));
         $vs_idno = $t_object->get('idno');
         foreach ($va_reps as $vn_representation_id => $va_rep) {
             $va_rep_info = $va_rep['info'][$ps_version];
             $vs_idno_proc = preg_replace('![^A-Za-z0-9_\\-]+!', '_', $vs_idno);
             switch ($this->request->user->getPreference('downloaded_file_naming')) {
                 case 'idno':
                     $vs_file_name = $vs_idno_proc . '_' . $vn_c . '.' . $va_rep_info['EXTENSION'];
                     break;
                 case 'idno_and_version':
                     $vs_file_name = $vs_idno_proc . '_' . $ps_version . '_' . $vn_c . '.' . $va_rep_info['EXTENSION'];
                     break;
                 case 'idno_and_rep_id_and_version':
                     $vs_file_name = $vs_idno_proc . '_representation_' . $vn_representation_id . '_' . $ps_version . '.' . $va_rep_info['EXTENSION'];
                     break;
                 case 'original_name':
                 default:
                     if ($va_rep['info']['original_filename']) {
                         $va_tmp = explode('.', $va_rep['info']['original_filename']);
                         if (sizeof($va_tmp) > 1) {
                             if (strlen($vs_ext = array_pop($va_tmp)) < 3) {
                                 $va_tmp[] = $vs_ext;
                             }
                         }
                         $vs_file_name = join('_', $va_tmp);
                     } else {
                         $vs_file_name = $vs_idno_proc . '_representation_' . $vn_representation_id . '_' . $ps_version;
                     }
                     if (isset($va_file_names[$vs_file_name . '.' . $va_rep_info['EXTENSION']])) {
                         $vs_file_name .= "_{$vn_c}";
                     }
                     $vs_file_name .= '.' . $va_rep_info['EXTENSION'];
                     break;
             }
             $va_file_names[$vs_file_name] = true;
             $this->view->setVar('version_download_name', $vs_file_name);
             //
             // Perform metadata embedding
             $t_rep = new ca_object_representations($va_rep['representation_id']);
             if (!($vs_path = caEmbedMetadataIntoRepresentation($t_object, $t_rep, $ps_version))) {
                 $vs_path = $t_rep->getMediaPath('media', $ps_version);
             }
             $va_file_paths[$vs_path] = $vs_file_name;
             $vn_c++;
         }
     }
     if (sizeof($va_file_paths) > 1) {
         if (!($vn_limit = ini_get('max_execution_time'))) {
             $vn_limit = 30;
         }
         set_time_limit($vn_limit * 2);
         $o_zip = new ZipFile();
         foreach ($va_file_paths as $vs_path => $vs_name) {
             $o_zip->addFile($vs_path, $vs_name, null, array('compression' => 0));
             // don't try to compress
         }
         $this->view->setVar('archive_path', $vs_path = $o_zip->output(ZIPFILE_FILEPATH));
         $this->view->setVar('archive_name', preg_replace('![^A-Za-z0-9\\.\\-]+!', '_', $t_object->get('idno')) . '.zip');
         $this->response->sendHeaders();
         $vn_rc = $this->render('Details/object_download_media_binary.php');
         $this->response->sendContent();
         if ($vs_path) {
             unlink($vs_path);
         }
     } else {
         foreach ($va_file_paths as $vs_path => $vs_name) {
             $this->view->setVar('archive_path', $vs_path);
             $this->view->setVar('archive_name', $vs_name);
         }
         $this->response->sendHeaders();
         $vn_rc = $this->render('Details/object_download_media_binary.php');
         $this->response->sendContent();
     }
     return $vn_rc;
 }
예제 #2
0
//
// CSS
//
if (isset($_POST['ft']['cssreset'])) {
    $zipfile->addFile("./css/reset.css", './resources/css/reset.css');
}
if (isset($_POST['ft']['csspaination'])) {
    $css_file .= "\n" . file_get_contents('./resources/css/pagination.css');
}
$zipfile->addFile("./static/css/index.html", tmpco($index_file));
$zipfile->addFile("./static/images/index.html", tmpco($index_file));
$zipfile->addFile("./static/js/index.html", tmpco($index_file));
$zipfile->addFile("./static/fonts/index.html", tmpco($index_file));
//
// Images
//
if (isset($_POST['ft']['spacer'])) {
    $zipfile->addFile("./images/spacer.gif", './resources/images/spacer.gif');
}
//
// create css file
//
$zipfile->addFile("./css/stylesheet.css", tmpco($css_file));
//
// create info.php file
//
$info_codes .= "\n" . '#static folder path, public url' . "\n" . '$_info[\'STATIC_URL\'] = \'http://localhost/sdeploy/static\';';
$zipfile->addFile("./includes/info.php", tmpco($info_codes));
//at end !
echo $zipfile->output('framework.zip');
예제 #3
0
 /**
  * Download all media attached to specified object (not necessarily open for editing)
  * Includes all representation media attached to the specified object + any media attached to oter
  * objects in the same object hierarchy as the specified object. Used by the book viewer interfacce to 
  * initiate a download.
  */
 public function DownloadMedia($pa_options = null)
 {
     list($vn_subject_id, $t_subject) = $this->_initView();
     $pn_representation_id = $this->request->getParameter('representation_id', pInteger);
     $pn_value_id = $this->request->getParameter('value_id', pInteger);
     if ($pn_value_id) {
         //print_R($_REQUEST); die;
         return $this->DownloadAttributeMedia();
     }
     $ps_version = $this->request->getParameter('version', pString);
     if (!$vn_subject_id) {
         return;
     }
     $o_view = new View($this->request, $this->request->getViewsDirectoryPath() . '/bundles/');
     if (!$ps_version) {
         $ps_version = 'original';
     }
     $o_view->setVar('version', $ps_version);
     $va_ancestor_ids = $t_subject->isHierarchical() ? $t_subject->getHierarchyAncestors(null, array('idsOnly' => true, 'includeSelf' => true)) : array($vn_subject_id);
     if ($vn_parent_id = array_pop($va_ancestor_ids)) {
         $t_subject->load($vn_parent_id);
         array_unshift($va_ancestor_ids, $vn_parent_id);
     }
     $va_child_ids = $t_subject->isHierarchical() ? $t_subject->getHierarchyChildren(null, array('idsOnly' => true)) : array($vn_subject_id);
     foreach ($va_ancestor_ids as $vn_id) {
         array_unshift($va_child_ids, $vn_id);
     }
     $vn_c = 1;
     $va_file_names = array();
     $va_file_paths = array();
     foreach ($va_child_ids as $vn_child_id) {
         if (!$t_subject->load($vn_child_id)) {
             continue;
         }
         if ($t_subject->tableName() == 'ca_object_representations') {
             $va_reps = array($vn_child_id => array('representation_id' => $vn_child_id, 'info' => array($ps_version => $t_subject->getMediaInfo('media', $ps_version))));
         } else {
             $va_reps = $t_subject->getRepresentations(array($ps_version));
         }
         $vs_idno = $t_subject->get('idno');
         foreach ($va_reps as $vn_representation_id => $va_rep) {
             if ($pn_representation_id && $pn_representation_id != $vn_representation_id) {
                 continue;
             }
             $va_rep_info = $va_rep['info'][$ps_version];
             $vs_idno_proc = preg_replace('![^A-Za-z0-9_\\-]+!', '_', $vs_idno);
             switch ($this->request->user->getPreference('downloaded_file_naming')) {
                 case 'idno':
                     $vs_file_name = $vs_idno_proc . '_' . $vn_c . '.' . $va_rep_info['EXTENSION'];
                     break;
                 case 'idno_and_version':
                     $vs_file_name = $vs_idno_proc . '_' . $ps_version . '_' . $vn_c . '.' . $va_rep_info['EXTENSION'];
                     break;
                 case 'idno_and_rep_id_and_version':
                     $vs_file_name = $vs_idno_proc . '_representation_' . $vn_representation_id . '_' . $ps_version . '.' . $va_rep_info['EXTENSION'];
                     break;
                 case 'original_name':
                 default:
                     if ($va_rep['info']['original_filename']) {
                         $va_tmp = explode('.', $va_rep['info']['original_filename']);
                         if (sizeof($va_tmp) > 1) {
                             if (strlen($vs_ext = array_pop($va_tmp)) < 3) {
                                 $va_tmp[] = $vs_ext;
                             }
                         }
                         $vs_file_name = join('_', $va_tmp);
                     } else {
                         $vs_file_name = $vs_idno_proc . '_representation_' . $vn_representation_id . '_' . $ps_version;
                     }
                     if (isset($va_file_names[$vs_file_name . '.' . $va_rep_info['EXTENSION']])) {
                         $vs_file_name .= "_{$vn_c}";
                     }
                     $vs_file_name .= '.' . $va_rep_info['EXTENSION'];
                     break;
             }
             $va_file_names[$vs_file_name] = true;
             $o_view->setVar('version_download_name', $vs_file_name);
             //
             // Perform metadata embedding
             $t_rep = new ca_object_representations($va_rep['representation_id']);
             if (!($vs_path = caEmbedMetadataIntoRepresentation($t_subject, $t_rep, $ps_version))) {
                 $vs_path = $t_rep->getMediaPath('media', $ps_version);
             }
             $va_file_paths[$vs_path] = $vs_file_name;
             $vn_c++;
         }
     }
     if (sizeof($va_file_paths) > 1) {
         if (!($vn_limit = ini_get('max_execution_time'))) {
             $vn_limit = 30;
         }
         set_time_limit($vn_limit * 2);
         $o_zip = new ZipFile();
         foreach ($va_file_paths as $vs_path => $vs_name) {
             $o_zip->addFile($vs_path, $vs_name, null, array('compression' => 0));
             // don't try to compress
         }
         $o_view->setVar('archive_path', $vs_path = $o_zip->output(ZIPFILE_FILEPATH));
         $o_view->setVar('archive_name', preg_replace('![^A-Za-z0-9\\.\\-]+!', '_', $t_subject->get('idno')) . '.zip');
         $this->response->addContent($o_view->render('download_media_binary.php'));
         if ($vs_path) {
             unlink($vs_path);
         }
     } else {
         foreach ($va_file_paths as $vs_path => $vs_name) {
             $o_view->setVar('archive_path', $vs_path);
             $o_view->setVar('archive_name', $vs_name);
         }
         $this->response->addContent($o_view->render('download_media_binary.php'));
     }
 }
예제 #4
0
function caZipDirectory($ps_directory, $ps_name, $ps_output_file)
{
    $va_files_to_zip = caGetDirectoryContentsAsList($ps_directory);
    $o_zip = new ZipFile();
    foreach ($va_files_to_zip as $vs_file) {
        $vs_name = str_replace($ps_directory, $ps_name, $vs_file);
        $o_zip->addFile($vs_file, $vs_name);
    }
    $vs_new_file = $o_zip->output(ZIPFILE_FILEPATH);
    copy($vs_new_file, $ps_output_file);
    unlink($vs_new_file);
    return true;
}
 /**
  * 
  * 
  */
 public function DownloadRepresentations()
 {
     if ($t_subject = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true)) {
         $pa_ids = null;
         if ($vs_ids = trim($this->request->getParameter($t_subject->tableName(), pString))) {
             if ($vs_ids != 'all') {
                 $pa_ids = explode(';', $vs_ids);
                 foreach ($pa_ids as $vn_i => $vs_id) {
                     if (!trim($vs_id) || !(int) $vs_id) {
                         unset($pa_ids[$vn_i]);
                     }
                 }
             }
         }
         if (!is_array($pa_ids) || !sizeof($pa_ids)) {
             $pa_ids = $this->opo_result_context->getResultList();
         }
         $vn_file_count = 0;
         if (is_array($pa_ids) && sizeof($pa_ids)) {
             $ps_version = $this->request->getParameter('version', pString);
             if ($qr_res = $t_subject->makeSearchResult($t_subject->tableName(), $pa_ids, array('filterNonPrimaryRepresentations' => false))) {
                 //$vs_tmp_name = caGetTempFileName('DownloadRepresentations', 'zip');
                 //$o_phar = new PharData($vs_tmp_name, null, null, Phar::ZIP);
                 $o_phar = new ZipFile();
                 //if (!($vn_limit = ini_get('max_execution_time'))) { $vn_limit = 30; }
                 //set_time_limit($vn_limit * 2);
                 set_time_limit(7200);
                 while ($qr_res->nextHit()) {
                     if (!is_array($va_version_list = $qr_res->getMediaVersions('ca_object_representations.media')) || !in_array($ps_version, $va_version_list)) {
                         $vs_version = 'original';
                     } else {
                         $vs_version = $ps_version;
                     }
                     $va_paths = $qr_res->getMediaPaths('ca_object_representations.media', $vs_version);
                     $va_infos = $qr_res->getMediaInfos('ca_object_representations.media');
                     $va_representation_ids = $qr_res->get('ca_object_representations.representation_id', array('returnAsArray' => true));
                     foreach ($va_paths as $vn_i => $vs_path) {
                         $vs_ext = array_pop(explode(".", $vs_path));
                         $vs_idno_proc = preg_replace('![^A-Za-z0-9_\\-]+!', '_', $qr_res->get($t_subject->tableName() . '.idno'));
                         $vs_original_name = $va_infos[$vn_i]['ORIGINAL_FILENAME'];
                         $vn_index = sizeof($va_paths) > 1 ? "_" . ($vn_i + 1) : '';
                         $vn_representation_id = $va_representation_ids[$vn_i];
                         // make sure we don't download representations the user isn't allowed to read
                         if (!caCanRead($this->request->user->getPrimaryKey(), 'ca_object_representations', $vn_representation_id)) {
                             continue;
                         }
                         switch ($this->request->user->getPreference('downloaded_file_naming')) {
                             case 'idno':
                                 $vs_filename = "{$vs_idno_proc}{$vn_index}.{$vs_ext}";
                                 break;
                             case 'idno_and_version':
                                 $vs_filename = "{$vs_idno_proc}_{$vs_version}{$vn_index}.{$vs_ext}";
                                 break;
                             case 'idno_and_rep_id_and_version':
                                 $vs_filename = "{$vs_idno_proc}_representation_{$vn_representation_id}_{$vs_version}{$vn_index}.{$vs_ext}";
                                 break;
                             case 'original_name':
                             default:
                                 if ($vs_original_name) {
                                     $va_tmp = explode('.', $vs_original_name);
                                     if (sizeof($va_tmp) > 1) {
                                         if (strlen($vs_ext = array_pop($va_tmp)) < 3) {
                                             $va_tmp[] = $vs_ext;
                                         }
                                     }
                                     $vs_filename = join('_', $va_tmp) . "{$vn_index}.{$vs_ext}";
                                 } else {
                                     $vs_filename = "{$vs_idno_proc}_representation_{$vn_representation_id}_{$vs_version}{$vn_index}.{$vs_ext}";
                                 }
                                 break;
                         }
                         //if ($vs_path_with_embedding = caEmbedMetadataIntoRepresentation(new ca_objects($qr_res->get('ca_objects.object_id')), new ca_object_representations($vn_representation_id), $vs_version)) {
                         //	$vs_path = $vs_path_with_embedding;
                         //}
                         if (!file_exists($vs_path)) {
                             continue;
                         }
                         $o_phar->addFile($vs_path, $vs_filename, 0, array('compression' => 0));
                         $vn_file_count++;
                     }
                 }
                 $vs_tmp_name = $o_phar->output(ZIPFILE_FILEPATH);
                 $this->view->setVar('tmp_file', $vs_tmp_name);
                 $this->view->setVar('download_name', 'media_for_' . mb_substr(preg_replace('![^A-Za-z0-9]+!u', '_', $this->getCriteriaForDisplay()), 0, 20) . '.zip');
                 set_time_limit($vn_limit);
             }
         }
         if ($vn_file_count > 0) {
             $this->render('Results/object_representation_download_binary.php');
         } else {
             $this->response->setHTTPResponseCode(204, _t('No files to download'));
         }
         return;
     }
     // post error
     $this->postError(3100, _t("Could not generate ZIP file for download"), "BaseEditorController->DownloadRepresentation()");
 }