/** * Read a folder structure for a zip file * * @param ElggObject $folder the folder to read * @param string $prepend current prefix * * @return array */ function file_tools_get_zip_structure($folder, $prepend) { $entries = []; if (!empty($prepend)) { $prepend = ltrim(sanitise_filepath($prepend), '/'); } if (empty($folder)) { $parent_guid = 0; } else { $parent_guid = $folder->getGUID(); } // get subfolder of this folder $entities = new ElggBatch('elgg_get_entities_from_metadata', ['type' => 'object', 'subtype' => FILE_TOOLS_SUBTYPE, 'limit' => false, 'metadata_name_value_pairs' => ['parent_guid' => $parent_guid]]); /* @var $subfolder ElggObject */ foreach ($entities as $subfolder) { $path = $prepend . $subfolder->title; $entries[] = ['directory' => $path, 'files' => file_tools_has_files($subfolder->getGUID())]; $entries = array_merge($entries, file_tools_get_zip_structure($subfolder, $path)); } return $entries; }
/** * Read a folder structure for a zip file * * @param ElggObject $folder the folder to read * @param string $prepend current prefix * * @return array */ function file_tools_get_zip_structure($folder, $prepend) { $entries = array(); if ($prepend) { $prepend .= '/'; } if (!$folder) { $parent_guid = 0; } else { $parent_guid = $folder->getGUID(); } $options = array("type" => "object", "subtype" => FILE_TOOLS_SUBTYPE, "limit" => false, "metadata_name" => "parent_guid", "metadata_value" => $parent_guid); // voor de hoogste map de sub bestanden nog ophalen if ($entities = elgg_get_entities_from_metadata($options)) { foreach ($entities as $subfolder) { $title = $prepend . $subfolder->title; $entries[] = array('directory' => $title, 'files' => file_tools_has_files($subfolder->getGUID())); $entries = array_merge($entries, file_tools_get_zip_structure($subfolder, $title)); } } return $entries; }