. * */ /** * get_media_files * * Takes an array of media ids and returns an array of the actual filenames * * @param array $media_ids Media IDs. */ function get_media_files($media_ids) { $media_files = array(); $total_size = 0; foreach ($media_ids as $element) { if (is_array($element)) { if (isset($element['object_type'])) { $type = $element['object_type']; $id = $element['object_id']; } else { $type = array_shift($element); $id = array_shift($element); } $media = new $type($id); } else { $media = new Song($element); } if ($media->enabled) { $media->format(); $total_size += sprintf("%.2f", ($media->size/1048576)); $dirname = ''; $parent = $media->get_parent(); if ($parent != null) { $pobj = new $parent['object_type']($parent['object_id']); $pobj->format(); $dirname = $pobj->get_fullname(); } if (!array_key_exists($dirname, $media_files)) { $media_files[$dirname] = array(); } array_push($media_files[$dirname], Core::conv_lc_file($media->file)); } } return array($media_files, $total_size); } //get_media_files /** * send_zip * * takes array of full paths to medias * zips them and sends them * * @param string $name name of the zip file to be created * @param array $media_files array of full paths to medias to zip create w/ call to get_media_files */ function send_zip($name, $media_files) { /* Require needed library */ if (!@include_once(AmpConfig::get('prefix') . '/lib/vendor/maennchen/zipstream-php/src/ZipStream.php')) { throw new Exception('Missing ZipStream dependency.'); } $arc = new ZipStream\ZipStream($name . ".zip"); $options = array( 'comment' => AmpConfig::get('file_zip_comment'), ); foreach ($media_files as $dir => $files) { foreach ($files as $file) { $arc->addFileFromPath($dir . "/" . basename($file), $file, $options); } } $arc->finish(); } // send_zip /** * check_can_zip * * Check that an object type is allowed to be zipped. * * @param string $object_type */ function check_can_zip($object_type) { $allowed = true; if (AmpConfig::get('allow_zip_types')) { $allowed = false; $allowed_types = explode(',', AmpConfig::get('allow_zip_types')); foreach ($allowed_types as $atype) { if (trim($atype) == $object_type) { $allowed = true; break; } } } return $allowed; }