parent
85ea427242
commit
fe791c2000
|
@ -1 +1,5 @@
|
||||||
# Validator for the standard csv format for imports to museum-digital
|
# Validator for the standard csv format for imports to museum-digital
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
- [JSZip](https://github.com/Stuk/jszip), dual-licensed under MIT & GPLv3
|
||||||
|
|
|
@ -33,26 +33,51 @@ const AUTOLOAD_DIRS = [
|
||||||
|
|
||||||
const AUTOLOAD_CLASS_MAP = [
|
const AUTOLOAD_CLASS_MAP = [
|
||||||
'CsvxmlAvailableFields' => __DIR__ . '/../classes/CsvxmlAvailableFields.php',
|
'CsvxmlAvailableFields' => __DIR__ . '/../classes/CsvxmlAvailableFields.php',
|
||||||
|
'FieldEntry' => __DIR__ . '/../classes/FieldEntry.php',
|
||||||
'MDTlLoader' => __DIR__ . '/../classes/MDTlLoader/src/MDTlLoader.php',
|
'MDTlLoader' => __DIR__ . '/../classes/MDTlLoader/src/MDTlLoader.php',
|
||||||
'MDFormatter' => __DIR__ . '/../classes/MD_STD/src/MDFormatter.php',
|
'MDFormatter' => __DIR__ . '/../classes/MD_STD/src/MDFormatter.php',
|
||||||
'MD_JAIL' => __DIR__ . '/../classes/MD_STD/src/MD_JAIL.php',
|
'MD_JAIL' => __DIR__ . '/../classes/MD_STD/src/MD_JAIL.php',
|
||||||
'MD_STD' => __DIR__ . '/../classes/MD_STD/src/MD_STD.php',
|
'MD_STD' => __DIR__ . '/../classes/MD_STD/src/MD_STD.php',
|
||||||
'MD_STD_CACHE' => __DIR__ . '/../classes/MD_STD/src/MD_STD_CACHE.php',
|
'MD_STD_CACHE' => __DIR__ . '/../classes/MD_STD/src/MD_STD_CACHE.php',
|
||||||
|
'MD_STD_DEBUG' => __DIR__ . '/../classes/MD_STD/src/MD_STD_DEBUG.php',
|
||||||
'MD_STD_IN' => __DIR__ . '/../classes/MD_STD/src/MD_STD_IN.php',
|
'MD_STD_IN' => __DIR__ . '/../classes/MD_STD/src/MD_STD_IN.php',
|
||||||
'MD_STD_SEC' => __DIR__ . '/../classes/MD_STD/src/MD_STD_SEC.php',
|
'MD_STD_SEC' => __DIR__ . '/../classes/MD_STD/src/MD_STD_SEC.php',
|
||||||
|
'MD_STD_SORT' => __DIR__ . '/../classes/MD_STD/src/MD_STD_SORT.php',
|
||||||
|
'MDActorVariantTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDActorVariantTypesSet.php',
|
||||||
|
'MDAppointmentAttendanceModeSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDAppointmentAttendanceModeSet.php',
|
||||||
|
'MDAppointmentContributorsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDAppointmentContributorsSet.php',
|
||||||
'MDAppointmentRecordingSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDAppointmentRecordingSet.php',
|
'MDAppointmentRecordingSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDAppointmentRecordingSet.php',
|
||||||
|
'MDAppointmentStatusSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDAppointmentStatusSet.php',
|
||||||
|
'MDBlockedMailserverSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDBlockedMailserverSet.php',
|
||||||
|
'MDCloserLocationTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDCloserLocationTypesSet.php',
|
||||||
|
'MDColorsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDColorsSet.php',
|
||||||
'MDConservationReportTypeSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDConservationReportTypeSet.php',
|
'MDConservationReportTypeSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDConservationReportTypeSet.php',
|
||||||
|
'MDConservationStatusSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDConservationStatusSet.php',
|
||||||
'MDCurrenciesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDCurrenciesSet.php',
|
'MDCurrenciesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDCurrenciesSet.php',
|
||||||
|
'MDDataHistorySubjectsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDDataHistorySubjectsSet.php',
|
||||||
'MDEntryTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDEntryTypesSet.php',
|
'MDEntryTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDEntryTypesSet.php',
|
||||||
'MDEventsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDEventsSet.php',
|
'MDEventsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDEventsSet.php',
|
||||||
|
'MDExhibitionContributorsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDExhibitionContributorsSet.php',
|
||||||
|
'MDExternalHostingSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDExternalHostingSet.php',
|
||||||
'MDLanguagesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDLanguagesSet.php',
|
'MDLanguagesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDLanguagesSet.php',
|
||||||
'MDLicensesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDLicensesSet.php',
|
'MDLicensesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDLicensesSet.php',
|
||||||
|
'MDLoanTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDLoanTypesSet.php',
|
||||||
'MDMarkingTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDMarkingTypesSet.php',
|
'MDMarkingTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDMarkingTypesSet.php',
|
||||||
|
'MDNodaRepositoriesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDNodaRepositoriesSet.php',
|
||||||
'MDObjectPositionsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDObjectPositionsSet.php',
|
'MDObjectPositionsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDObjectPositionsSet.php',
|
||||||
'MDObjectPublicationBackgrounds' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDObjectPublicationBackgrounds.php',
|
'MDObjectPublicationBackgrounds' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDObjectPublicationBackgrounds.php',
|
||||||
|
'MDObjectStatusSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDObjectStatusSet.php',
|
||||||
|
'MDObjectSyndicationSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDObjectSyndicationSet.php',
|
||||||
|
'MDPhoneTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDPhoneTypesSet.php',
|
||||||
'MDPlacetypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDPlacetypesSet.php',
|
'MDPlacetypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDPlacetypesSet.php',
|
||||||
'MDPodcastContributorsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDPodcastContributorsSet.php',
|
'MDPodcastContributorsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDPodcastContributorsSet.php',
|
||||||
|
'MDProcessTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDProcessTypesSet.php',
|
||||||
|
'MDRecordingTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDRecordingTypesSet.php',
|
||||||
|
'MDRequirementsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDRequirementsSet.php',
|
||||||
|
'MDResearchStatusSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDResearchStatusSet.php',
|
||||||
'MDSourceTypeSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDSourceTypeSet.php',
|
'MDSourceTypeSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDSourceTypeSet.php',
|
||||||
|
'MDSpaceAccessStatusSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDSpaceAccessStatusSet.php',
|
||||||
|
'MDSpaceTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDSpaceTypesSet.php',
|
||||||
'MDTitleTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDTitleTypesSet.php',
|
'MDTitleTypesSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDTitleTypesSet.php',
|
||||||
'MDUnitsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDUnitsSet.php',
|
'MDUnitsSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDUnitsSet.php',
|
||||||
'MDValueSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDValueSet.php',
|
'MDValueSet' => __DIR__ . '/../classes/MDAllowedValueSets/src/MDValueSet.php',
|
||||||
|
@ -66,8 +91,10 @@ const AUTOLOAD_CLASS_MAP = [
|
||||||
'MDFileDoesNotExist' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDFileDoesNotExist.php',
|
'MDFileDoesNotExist' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDFileDoesNotExist.php',
|
||||||
'MDFileIsNotReadable' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDFileIsNotReadable.php',
|
'MDFileIsNotReadable' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDFileIsNotReadable.php',
|
||||||
'MDInaccessiblePropertyException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDInaccessiblePropertyException.php',
|
'MDInaccessiblePropertyException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDInaccessiblePropertyException.php',
|
||||||
|
'MDInputTooLongException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDInputTooLongException.php',
|
||||||
'MDInvalidColorCode' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDInvalidColorCode.php',
|
'MDInvalidColorCode' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDInvalidColorCode.php',
|
||||||
'MDInvalidEmail' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDInvalidEmail.php',
|
'MDInvalidEmail' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDInvalidEmail.php',
|
||||||
|
'MDInvalidEmptyInputException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDInvalidEmptyInputException.php',
|
||||||
'MDInvalidUrl' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDInvalidUrl.php',
|
'MDInvalidUrl' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDInvalidUrl.php',
|
||||||
'MDOutputBufferNotStarted' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDOutputBufferNotStarted.php',
|
'MDOutputBufferNotStarted' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDOutputBufferNotStarted.php',
|
||||||
'MDRequiredConfigNotSet' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDRequiredConfigNotSet.php',
|
'MDRequiredConfigNotSet' => __DIR__ . '/../classes/MDErrorReporter/exceptions/generic/MDRequiredConfigNotSet.php',
|
||||||
|
@ -81,6 +108,7 @@ const AUTOLOAD_CLASS_MAP = [
|
||||||
'MDpageParameterMissingException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/page/MDpageParameterMissingException.php',
|
'MDpageParameterMissingException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/page/MDpageParameterMissingException.php',
|
||||||
'MDpageParameterNotNumericException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/page/MDpageParameterNotNumericException.php',
|
'MDpageParameterNotNumericException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/page/MDpageParameterNotNumericException.php',
|
||||||
'MDDuplicateLinkException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/updates/MDDuplicateLinkException.php',
|
'MDDuplicateLinkException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/updates/MDDuplicateLinkException.php',
|
||||||
|
'MDFileIsNotWritable' => __DIR__ . '/../classes/MDErrorReporter/exceptions/updates/MDFileIsNotWritable.php',
|
||||||
'MDFileUploadNotAcceptedException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/updates/MDFileUploadNotAcceptedException.php',
|
'MDFileUploadNotAcceptedException' => __DIR__ . '/../classes/MDErrorReporter/exceptions/updates/MDFileUploadNotAcceptedException.php',
|
||||||
'MDInvalidCurrency' => __DIR__ . '/../classes/MDErrorReporter/exceptions/updates/MDInvalidCurrency.php',
|
'MDInvalidCurrency' => __DIR__ . '/../classes/MDErrorReporter/exceptions/updates/MDInvalidCurrency.php',
|
||||||
'MDInvalidInputDate' => __DIR__ . '/../classes/MDErrorReporter/exceptions/updates/MDInvalidInputDate.php',
|
'MDInvalidInputDate' => __DIR__ . '/../classes/MDErrorReporter/exceptions/updates/MDInvalidInputDate.php',
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
<?PHP
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function for sanitizing contents for prospective XML contents.
|
|
||||||
*
|
|
||||||
* @param string $transform Input string.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function transform(string $transform):string {
|
|
||||||
$transform = str_replace(chr(14), "", $transform);
|
|
||||||
$transform = str_replace('"', '"', $transform);
|
|
||||||
$transform = str_replace('&', '&', $transform);
|
|
||||||
$transform = str_replace('"', '"', $transform);
|
|
||||||
$transform = str_replace('</br>', ' ', $transform);
|
|
||||||
$transform = str_replace('<br />', ' ', $transform);
|
|
||||||
$transform = str_replace('’', '\'', $transform);
|
|
||||||
$transform = str_replace(chr(11), ' ', $transform);
|
|
||||||
|
|
||||||
$transform = str_replace('<', '<', $transform);
|
|
||||||
$transform = str_replace('>', '>', $transform);
|
|
||||||
$transform = str_replace('´', ''', $transform);
|
|
||||||
$transform = str_replace('&sbquo', '\'', $transform);
|
|
||||||
$transform = str_replace('&lsquo', '\'', $transform);
|
|
||||||
$transform = str_replace(chr(96), '\'', $transform);
|
|
||||||
$transform = str_replace(chr(130), '\'', $transform);
|
|
||||||
$transform = str_replace(chr(145), '\'', $transform);
|
|
||||||
$transform = str_replace(chr(146), '\'', $transform);
|
|
||||||
return $transform;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function for sanitizing contents for prospective XML contents.
|
|
||||||
*
|
|
||||||
* @param string $tagify Input string.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function tagify(string $tagify):string {
|
|
||||||
$tagify = str_replace(' ', '_', $tagify);
|
|
||||||
$tagify = str_replace('/', '_', $tagify);
|
|
||||||
$tagify = str_replace(',', '_', $tagify);
|
|
||||||
$tagify = str_replace('__', '_', $tagify);
|
|
||||||
$tagify = str_replace('Ä', 'ae', $tagify);
|
|
||||||
$tagify = str_replace('ä', 'ae', $tagify);
|
|
||||||
$tagify = str_replace('Ö', 'oe', $tagify);
|
|
||||||
$tagify = str_replace('ö', 'oe', $tagify);
|
|
||||||
$tagify = str_replace('Ü', 'ue', $tagify);
|
|
||||||
$tagify = str_replace('ü', 'ue', $tagify);
|
|
||||||
$tagify = str_replace('ß', 'ss', $tagify);
|
|
||||||
$tagify = str_replace(chr(41), '', $tagify);
|
|
||||||
$tagify = str_replace(chr(40), '', $tagify);
|
|
||||||
return $tagify;
|
|
||||||
|
|
||||||
}
|
|
440
inc/zip.php
440
inc/zip.php
|
@ -1,440 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Class to create and manage a Zip file.
|
|
||||||
*
|
|
||||||
* Inspired by CreateZipFile by Rochak Chauhan www.rochakchauhan.com (http://www.phpclasses.org/browse/package/2322.html)
|
|
||||||
* and
|
|
||||||
* http://www.pkware.com/documents/casestudies/APPNOTE.TXT Zip file specification.
|
|
||||||
*
|
|
||||||
* @author A. Grandt
|
|
||||||
* @see Distributed under "General Public License"
|
|
||||||
* @version 1.1
|
|
||||||
*/
|
|
||||||
class Zip {
|
|
||||||
private $zipMemoryThreshold = 1048576; // Autocreate tempfile if the zip data exceeds 1048576 bytes (1 MB)
|
|
||||||
private $endOfCentralDirectory = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record
|
|
||||||
private $localFileHeader = "\x50\x4b\x03\x04"; // Local file header signature
|
|
||||||
private $centralFileHeader = "\x50\x4b\x01\x02"; // Central file header signature
|
|
||||||
|
|
||||||
private $zipData = null;
|
|
||||||
private $zipFile = null;
|
|
||||||
private $zipComment = null;
|
|
||||||
private $cdRec = array(); // central directory
|
|
||||||
private $offset = 0;
|
|
||||||
private $isFinalized = false;
|
|
||||||
|
|
||||||
private $streamChunkSize = 65536;
|
|
||||||
private $streamFilePath = null;
|
|
||||||
private $streamTimeStamp = null;
|
|
||||||
private $streamComment = null;
|
|
||||||
private $streamFile = null;
|
|
||||||
private $streamData = null;
|
|
||||||
private $streamFileLength = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param $useZipFile boolean. Write temp zip data to tempFile? Default false
|
|
||||||
*/
|
|
||||||
function __construct($useZipFile = false) {
|
|
||||||
if ($useZipFile) {
|
|
||||||
$this->zipFile = tmpfile();
|
|
||||||
} else {
|
|
||||||
$this->zipData = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function __destruct() {
|
|
||||||
if (!is_null($this->zipFile)) {
|
|
||||||
fclose($this->zipFile);
|
|
||||||
}
|
|
||||||
$this->zipData= null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Zip archive comment.
|
|
||||||
*
|
|
||||||
* @param string $newComment New comment. null to clear.
|
|
||||||
*/
|
|
||||||
public function setComment($newComment = null) {
|
|
||||||
$this->zipComment = $newComment;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set zip file to write zip data to.
|
|
||||||
* This will cause all present and future data written to this class to be written to this file.
|
|
||||||
* This can be used at any time, even after the Zip Archive have been finalized. Any previous file will be closed.
|
|
||||||
* Warning: If the given file already exists, it will be overwritten.
|
|
||||||
*
|
|
||||||
* @param string $fileName
|
|
||||||
*/
|
|
||||||
public function setZipFile($fileName) {
|
|
||||||
if (file_exists($fileName)) {
|
|
||||||
unlink ($fileName);
|
|
||||||
}
|
|
||||||
$fd=fopen($fileName, "x+b");
|
|
||||||
if (!is_null($this->zipFile)) {
|
|
||||||
rewind($this->zipFile);
|
|
||||||
while(!feof($this->zipFile)) {
|
|
||||||
fwrite($fd, fread($this->zipFile, $this->streamChunkSize));
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose($this->zipFile);
|
|
||||||
} else {
|
|
||||||
fwrite($fd, $this->zipData);
|
|
||||||
$this->zipData = null;
|
|
||||||
}
|
|
||||||
$this->zipFile = $fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an empty directory entry to the zip archive.
|
|
||||||
* Basically this is only used if an empty directory is added.
|
|
||||||
*
|
|
||||||
* @param string $directoryPath Directory Path and name to be added to the archive.
|
|
||||||
* @param int $timestamp (Optional) Timestamp for the added directory, if omitted or set to 0, the current time will be used.
|
|
||||||
* @param string $fileComment (Optional) Comment to be added to the archive for this directory. To use fileComment, timestamp must be given.
|
|
||||||
*/
|
|
||||||
public function addDirectory($directoryPath, $timestamp = 0, $fileComment = null) {
|
|
||||||
if ($this->isFinalized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->buildZipEntry($directoryPath, $fileComment, "\x00\x00", "\x00\x00", $timestamp, "\x00\x00\x00\x00", 0, 0, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a file to the archive at the specified location and file name.
|
|
||||||
*
|
|
||||||
* @param string $data File data.
|
|
||||||
* @param string $filePath Filepath and name to be used in the archive.
|
|
||||||
* @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
|
|
||||||
* @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
|
|
||||||
*/
|
|
||||||
public function addFile($data, $filePath, $timestamp = 0, $fileComment = null) {
|
|
||||||
if ($this->isFinalized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$gzType = "\x08\x00"; // Compression type 8 = deflate
|
|
||||||
$gpFlags = "\x02\x00"; // General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression.
|
|
||||||
$dataLength = strlen($data);
|
|
||||||
$fileCRC32 = pack("V", crc32($data));
|
|
||||||
|
|
||||||
$gzData = gzcompress($data);
|
|
||||||
$gzData = substr( substr($gzData, 0, strlen($gzData) - 4), 2); // gzcompress adds a 2 byte header and 4 byte CRC we can't use.
|
|
||||||
// The 2 byte header does contain useful data, though in this case the 2 parameters we'd be interrested in will always be 8 for compression type, and 2 for General purpose flag.
|
|
||||||
$gzLength = strlen($gzData);
|
|
||||||
|
|
||||||
if ($gzLength >= $dataLength) {
|
|
||||||
$gzLength = $dataLength;
|
|
||||||
$gzData = $data;
|
|
||||||
$gzType = "\x00\x00"; // Compression type 0 = stored
|
|
||||||
$gpFlags = "\x00\x00"; // Compression type 0 = stored
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($this->zipFile) && ($this->offset + $gzLength) > $this->zipMemoryThreshold) {
|
|
||||||
$this->zipFile = tmpfile();
|
|
||||||
fwrite($this->zipFile, $this->zipData);
|
|
||||||
$this->zipData = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, 32);
|
|
||||||
if (is_null($this->zipFile)) {
|
|
||||||
$this->zipData .= $gzData;
|
|
||||||
} else {
|
|
||||||
fwrite($this->zipFile, $gzData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a file to the archive at the specified location and file name.
|
|
||||||
*
|
|
||||||
* @param string $dataFile File name/path.
|
|
||||||
* @param string $filePath Filepath and name to be used in the archive.
|
|
||||||
* @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
|
|
||||||
* @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
|
|
||||||
*/
|
|
||||||
public function addLargeFile($dataFile, $filePath, $timestamp = 0, $fileComment = null) {
|
|
||||||
if ($this->isFinalized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->openStream($filePath, $timestamp, $fileComment);
|
|
||||||
|
|
||||||
$fh = fopen($dataFile, "rb");
|
|
||||||
while(!feof($fh)) {
|
|
||||||
$this->addStreamData(fread($fh, $this->streamChunkSize));
|
|
||||||
}
|
|
||||||
fclose($fh);
|
|
||||||
|
|
||||||
$this->closeStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a stream to be used for large entries.
|
|
||||||
*
|
|
||||||
* @param string $filePath Filepath and name to be used in the archive.
|
|
||||||
* @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
|
|
||||||
* @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
|
|
||||||
*/
|
|
||||||
public function openStream($filePath, $timestamp = 0, $fileComment = null) {
|
|
||||||
if ($this->isFinalized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($this->zipFile)) {
|
|
||||||
$this->zipFile = tmpfile();
|
|
||||||
fwrite($this->zipFile, $this->zipData);
|
|
||||||
$this->zipData = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen($this->streamFilePath) > 0) {
|
|
||||||
closeStream();
|
|
||||||
}
|
|
||||||
$this->streamFile = tempnam(sys_get_temp_dir(), 'Zip');
|
|
||||||
$this->streamData = gzopen($this->streamFile, "w9");
|
|
||||||
$this->streamFilePath = $filePath;
|
|
||||||
$this->streamTimestamp = $timestamp;
|
|
||||||
$this->streamFileComment = $fileComment;
|
|
||||||
$this->streamFileLength = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addStreamData($data) {
|
|
||||||
$length = gzwrite($this->streamData, $data, strlen($data));
|
|
||||||
if ($length != strlen($data)) {
|
|
||||||
print "<p>Length mismatch</p>\n";
|
|
||||||
}
|
|
||||||
$this->streamFileLength += $length;
|
|
||||||
return $length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close the current stream.
|
|
||||||
*/
|
|
||||||
public function closeStream() {
|
|
||||||
if ($this->isFinalized || strlen($this->streamFilePath) == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fflush($this->streamData);
|
|
||||||
gzclose($this->streamData);
|
|
||||||
|
|
||||||
$gzType = "\x08\x00"; // Compression type 8 = deflate
|
|
||||||
$gpFlags = "\x02\x00"; // General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression.
|
|
||||||
|
|
||||||
$file_handle = fopen($this->streamFile, "rb");
|
|
||||||
$stats = fstat($file_handle);
|
|
||||||
$eof = $stats['size'];
|
|
||||||
|
|
||||||
fseek($file_handle, $eof-8);
|
|
||||||
$fileCRC32 = fread($file_handle, 4);
|
|
||||||
$dataLength = $this->streamFileLength;//$gzl[1];
|
|
||||||
|
|
||||||
$gzLength = $eof-10;
|
|
||||||
$eof -= 9;
|
|
||||||
|
|
||||||
fseek($file_handle, 10);
|
|
||||||
|
|
||||||
$this->buildZipEntry($this->streamFilePath, $this->streamFileComment, $gpFlags, $gzType, $this->streamTimestamp, $fileCRC32, $gzLength, $dataLength, 32);
|
|
||||||
while(!feof($file_handle)) {
|
|
||||||
fwrite($this->zipFile, fread($file_handle, $this->streamChunkSize));
|
|
||||||
}
|
|
||||||
|
|
||||||
unlink($this->streamFile);
|
|
||||||
$this->streamFile = null;
|
|
||||||
$this->streamData = null;
|
|
||||||
$this->streamFilePath = null;
|
|
||||||
$this->streamTimestamp = null;
|
|
||||||
$this->streamFileComment = null;
|
|
||||||
$this->streamFileLength = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close the archive.
|
|
||||||
* A closed archive can no longer have new files added to it.
|
|
||||||
*/
|
|
||||||
public function finalize() {
|
|
||||||
if(!$this->isFinalized) {
|
|
||||||
if (strlen($this->streamFilePath) > 0) {
|
|
||||||
$this->closeStream();
|
|
||||||
}
|
|
||||||
$cd = implode("", $this->cdRec);
|
|
||||||
|
|
||||||
$cdRec = $cd . $this->endOfCentralDirectory
|
|
||||||
. pack("v", sizeof($this->cdRec))
|
|
||||||
. pack("v", sizeof($this->cdRec))
|
|
||||||
. pack("V", strlen($cd))
|
|
||||||
. pack("V", $this->offset);
|
|
||||||
if (!is_null($this->zipComment)) {
|
|
||||||
$cdRec .= pack("v", strlen($this->zipComment)) . $this->zipComment;
|
|
||||||
} else {
|
|
||||||
$cdRec .= "\x00\x00";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($this->zipFile)) {
|
|
||||||
$this->zipData .= $cdRec;
|
|
||||||
} else {
|
|
||||||
fwrite($this->zipFile, $cdRec);
|
|
||||||
fflush($this->zipFile);
|
|
||||||
}
|
|
||||||
$this->isFinalized = true;
|
|
||||||
$cd = null;
|
|
||||||
$this->cdRec = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the handle ressource for the archive zip file.
|
|
||||||
* If the zip haven't been finalized yet, this will cause it to become finalized
|
|
||||||
*
|
|
||||||
* @return zip file handle
|
|
||||||
*/
|
|
||||||
public function getZipFile() {
|
|
||||||
if(!$this->isFinalized) {
|
|
||||||
$this->finalize();
|
|
||||||
}
|
|
||||||
if (is_null($this->zipFile)) {
|
|
||||||
$this->zipFile = tmpfile();
|
|
||||||
fwrite($this->zipFile, $this->zipData);
|
|
||||||
$this->zipData = null;
|
|
||||||
}
|
|
||||||
rewind($this->zipFile);
|
|
||||||
return $this->zipFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the zip file contents
|
|
||||||
* If the zip haven't been finalized yet, this will cause it to become finalized
|
|
||||||
*
|
|
||||||
* @return zip data
|
|
||||||
*/
|
|
||||||
public function getZipData() {
|
|
||||||
if(!$this->isFinalized) {
|
|
||||||
$this->finalize();
|
|
||||||
}
|
|
||||||
if (is_null($this->zipFile)) {
|
|
||||||
return $this->zipData;
|
|
||||||
} else {
|
|
||||||
rewind($this->zipFile);
|
|
||||||
$filestat = fstat($this->zipFile);
|
|
||||||
return fread($this->zipFile, $filestat['size']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send the archive as a zip download
|
|
||||||
*
|
|
||||||
* @param String $fileName The name of the Zip archive, ie. "archive.zip".
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function sendZip($fileName) {
|
|
||||||
if(!$this->isFinalized) {
|
|
||||||
$this->finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!headers_sent($headerFile, $headerLine) or die("<p><strong>Error:</strong> Unable to send file $fileName. HTML Headers have already been sent from <strong>$headerFile</strong> in line <strong>$headerLine</strong></p>")) {
|
|
||||||
if (ob_get_contents() === false or die("\n<p><strong>Error:</strong> Unable to send file <strong>$fileName.epub</strong>. Output buffer contains the following text (typically warnings or errors):<br>" . ob_get_contents() . "</p>")) {
|
|
||||||
if (ini_get('zlib.output_compression')) {
|
|
||||||
ini_set('zlib.output_compression', 'Off');
|
|
||||||
}
|
|
||||||
|
|
||||||
header('Pragma: public');
|
|
||||||
header("Last-Modified: " . gmdate("D, d M Y H:i:s T"));
|
|
||||||
header("Expires: 0");
|
|
||||||
header("Accept-Ranges: bytes");
|
|
||||||
header("Connection: close");
|
|
||||||
header("Content-Type: application/zip");
|
|
||||||
header('Content-Disposition: attachment; filename="' . $fileName . '";' );
|
|
||||||
header("Content-Transfer-Encoding: binary");
|
|
||||||
header("Content-Length: ". $this->getArchiveSize());
|
|
||||||
|
|
||||||
if (is_null($this->zipFile)) {
|
|
||||||
echo $this->zipData;
|
|
||||||
} else {
|
|
||||||
rewind($this->zipFile);
|
|
||||||
|
|
||||||
while(!feof($this->zipFile)) {
|
|
||||||
echo fread($this->zipFile, $this->streamChunkSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getArchiveSize() {
|
|
||||||
if (is_null($this->zipFile)) {
|
|
||||||
return strlen($this->zipData);
|
|
||||||
}
|
|
||||||
$filestat = fstat($this->zipFile);
|
|
||||||
return $filestat['size'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate the 2 byte dostime used in the zip entries.
|
|
||||||
*
|
|
||||||
* @param int $timestamp
|
|
||||||
* @return 2-byte encoded DOS Date
|
|
||||||
*/
|
|
||||||
private function getDosTime($timestamp = 0) {
|
|
||||||
$timestamp = (int)$timestamp;
|
|
||||||
$date = ($timestamp == 0 ? getdate() : getDate($timestamp));
|
|
||||||
if ($date["year"] >= 1980) {
|
|
||||||
return pack("V", (($date["mday"] + ($date["mon"] << 5) + (($date["year"]-1980) << 9)) << 16) |
|
|
||||||
(($date["seconds"] >> 1) + ($date["minutes"] << 5) + ($date["hours"] << 11)));
|
|
||||||
}
|
|
||||||
return "\x00\x00\x00\x00";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build the Zip file structures
|
|
||||||
*
|
|
||||||
* @param unknown_type $filePath
|
|
||||||
* @param unknown_type $fileComment
|
|
||||||
* @param unknown_type $gpFlags
|
|
||||||
* @param unknown_type $gzType
|
|
||||||
* @param unknown_type $timestamp
|
|
||||||
* @param unknown_type $fileCRC32
|
|
||||||
* @param unknown_type $gzLength
|
|
||||||
* @param unknown_type $dataLength
|
|
||||||
* @param integer $extFileAttr 16 for directories, 32 for files.
|
|
||||||
*/
|
|
||||||
private function buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, $extFileAttr) {
|
|
||||||
$filePath = str_replace("\\", "/", $filePath);
|
|
||||||
$fileCommentLength = (is_null($fileComment) ? 0 : strlen($fileComment));
|
|
||||||
$dosTime = $this->getDosTime($timestamp);
|
|
||||||
|
|
||||||
$zipEntry = $this->localFileHeader;
|
|
||||||
$zipEntry .= "\x14\x00"; // Version needed to extract
|
|
||||||
$zipEntry .= $gpFlags . $gzType . $dosTime. $fileCRC32;
|
|
||||||
$zipEntry .= pack("VV", $gzLength, $dataLength);
|
|
||||||
$zipEntry .= pack("v", strlen($filePath) ); // File name length
|
|
||||||
$zipEntry .= "\x00\x00"; // Extra field length
|
|
||||||
$zipEntry .= $filePath; // FileName . Extra field
|
|
||||||
|
|
||||||
if (is_null($this->zipFile)) {
|
|
||||||
$this->zipData .= $zipEntry;
|
|
||||||
} else {
|
|
||||||
fwrite($this->zipFile, $zipEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
$cdEntry = $this->centralFileHeader;
|
|
||||||
$cdEntry .= "\x00\x00"; // Made By Version
|
|
||||||
$cdEntry .= "\x14\x00"; // Version Needed to extract
|
|
||||||
$cdEntry .= $gpFlags . $gzType . $dosTime. $fileCRC32;
|
|
||||||
$cdEntry .= pack("VV", $gzLength, $dataLength);
|
|
||||||
$cdEntry .= pack("v", strlen($filePath)); // Filename length
|
|
||||||
$cdEntry .= "\x00\x00"; // Extra field length
|
|
||||||
$cdEntry .= pack("v", $fileCommentLength); // File comment length
|
|
||||||
$cdEntry .= "\x00\x00"; // Disk number start
|
|
||||||
$cdEntry .= "\x00\x00"; // internal file attributes
|
|
||||||
$cdEntry .= pack("V", $extFileAttr ); // External file attributes
|
|
||||||
$cdEntry .= pack("V", $this->offset ); // Relative offset of local header
|
|
||||||
$cdEntry .= $filePath; // FileName . Extra field
|
|
||||||
if (!is_null($fileComment)) {
|
|
||||||
$cdEntry .= $fileComment; // Comment
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->cdRec[] = $cdEntry;
|
|
||||||
$this->offset += strlen($zipEntry) + $gzLength;
|
|
||||||
}
|
|
||||||
}
|
|
21
security.php
21
security.php
|
@ -1,21 +0,0 @@
|
||||||
<?PHP
|
|
||||||
/**
|
|
||||||
* Generates a CSV template based on the field list provided for CSVXML.
|
|
||||||
*
|
|
||||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
|
||||||
*/
|
|
||||||
declare(strict_types = 1);
|
|
||||||
require_once __DIR__ . "/../functions/functions.php";
|
|
||||||
|
|
||||||
header("Content-type: text/plain");
|
|
||||||
echo MD_JAIL::check_server_setup([
|
|
||||||
"shell_access_whitelist" => [],
|
|
||||||
"sys_function_whitelist" => ["getenv"],
|
|
||||||
"file_function_whitelist" => [],
|
|
||||||
"file_uploads" => true,
|
|
||||||
"allow_url_fopen" => false,
|
|
||||||
"max_input_vars" => 100, // Default: 1000
|
|
||||||
"max_input_nesting_level" => 10, // Default: 1000
|
|
||||||
"post_max_size" => "4M",
|
|
||||||
"curl" => false,
|
|
||||||
]);
|
|
Loading…
Reference in New Issue
Block a user