sac_root_in = $sac_rootin; $this->sac_dir_in = $sac_dirin; $this->sac_root_out = $sac_rootout; $this->sac_file_out = $sac_fileout; $this->sac_creators = array(); $this->sac_subjects = array(); $this->sac_files = array(); $this->sac_mimetypes = array(); $this->sac_provenances = array(); $this->sac_rights = array(); $this->sac_filecount = 0; } function setType($sac_thetype) { $this->sac_type = $sac_thetype; } function setTitle($sac_thetitle) { $this->sac_title = $this->clean($sac_thetitle); } function setAbstract($sac_thetitle) { $this->sac_abstract = $this->clean($sac_thetitle); } function addCreator($sac_creator) { array_push($this->sac_creators, $this->clean($sac_creator)); } function addSubject($sac_subject) { array_push($this->sac_subjects, $this->clean($sac_subject)); } function addProvenance($sac_provenance) { array_push($this->sac_provenances, $this->clean($sac_provenance)); } function addRights($sac_right) { array_push($this->sac_rights, $this->clean($sac_right)); } function setIdentifier($sac_theidentifier) { $this->sac_identifier = $sac_theidentifier; } function setStatusStatement($sac_thestatus) { $this->sac_statusstatement = $sac_thestatus; } function setCopyrightHolder($sac_thecopyrightholder) { $this->sac_copyrightholder = $this->clean($sac_thecopyrightholder); } function setCustodian($sac_thecustodian) { $this->sac_custodian = $this->clean($sac_thecustodian); } function setCitation($sac_thecitation) { $this->sac_citation = $this->clean($sac_thecitation); } function setLanguage($sac_thelanguage) { $this->sac_language = $this->clean($sac_thelanguage); } function setDateAvailable($sac_thedta) { $this->sac_dateavailable = $sac_thedta; } function setPublisher($sac_thepublisher) { $this->sac_publisher = $sac_thepublisher; } function addFile($sac_thefile, $sac_themimetype) { array_push($this->sac_files, $sac_thefile); array_push($this->sac_mimetypes, $sac_themimetype); $this->sac_filecount++; } function addMetadata($sac_theelement, $sac_thevalue) { switch ($sac_theelement) { case "abstract": $this->setAbstract($sac_thevalue); break; case "available": $this->setDateAvailable($sac_thevalue); break; case "bibliographicCitation": $this->setCitation($sac_thevalue); break; case "creator": $this->addCreator($sac_thevalue); break; case "identifier": $this->setIdentifier($sac_thevalue); break; case "publisher": $this->setPublisher($sac_thevalue); break; case "title": $this->setTitle($sac_thevalue); break; } } function create() { // Write the metadata (mets) file $fh = @fopen($this->sac_root_in . '/' . $this->sac_dir_in . '/' . $this->sac_metadata_filename, 'w'); if (!$fh) { throw new Exception("Error writing metadata file (" . $this->sac_root_in . '/' . $this->sac_dir_in . '/' . $this->sac_metadata_filename . ")"); } $this->writeHeader($fh); $this->writeDmdSec($fh); $this->writeFileGrp($fh); $this->writeStructMap($fh); $this->writeFooter($fh); fclose($fh); // Create the zipped package (force an overwrite if it already exists) $zip = new ZipArchive(); $zip->open($this->sac_root_out . '/' . $this->sac_file_out, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); $zip->addFile($this->sac_root_in . '/' . $this->sac_dir_in . '/mets.xml', 'mets.xml'); for ($i = 0; $i < $this->sac_filecount; $i++) { $zip->addFile($this->sac_root_in . '/' . $this->sac_dir_in . '/' . $this->sac_files[$i], $this->sac_files[$i]); } $zip->close(); } function writeheader($fh) { fwrite($fh, "\n"); fwrite($fh, "\n"); fwrite($fh, "\t\n"); fwrite($fh, "\t\t\n"); if (isset($this->sac_custodian)) { fwrite($fh, "\t\t\t$this->sac_custodian\n"); } else { fwrite($fh, "\t\t\tUnknown\n"); } fwrite($fh, "\t\t\n"); fwrite($fh, "\t\n"); } function writeDmdSec($fh) { fwrite($fh, "\n"); fwrite($fh, "\n"); fwrite($fh, "\n"); fwrite($fh, "\n"); fwrite($fh, "\n"); if (isset($this->sac_type)) { $this->statementVesURIValueURI($fh, "http://purl.org/dc/elements/1.1/type", "http://purl.org/eprint/terms/Type", $this->sac_type); } if (isset($this->sac_title)) { $this->statement($fh, "http://purl.org/dc/elements/1.1/title", $this->valueString($this->sac_title)); } if (isset($this->sac_abstract)) { $this->statement($fh, "http://purl.org/dc/terms/abstract", $this->valueString($this->sac_abstract)); } foreach ($this->sac_creators as $sac_creator) { $this->statement($fh, "http://purl.org/dc/elements/1.1/creator", $this->valueString($sac_creator)); } foreach ($this->sac_subjects as $sac_subject) { $this->statement($fh, "http://purl.org/dc/elements/1.1/subject", $this->valueString($sac_subject)); } foreach ($this->sac_provenances as $sac_provenance) { $this->statement($fh, "http://purl.org/dc/terms/provenance", $this->valueString($sac_provenance)); } foreach ($this->sac_rights as $sac_right) { $this->statement($fh, "http://purl.org/dc/terms/rights", $this->valueString($sac_right)); } if (isset($this->sac_identifier)) { $this->statement($fh, "http://purl.org/dc/elements/1.1/identifier", $this->valueString($this->sac_identifier)); } if (isset($this->sac_publisher)) { $this->statement($fh, "http://purl.org/dc/elements/1.1/publisher", $this->valueString($this->sac_publisher)); } fwrite($fh, "\n"); fwrite($fh, "\n"); fwrite($fh, "\n"); $this->statementValueURI($fh, "http://purl.org/dc/elements/1.1/type", "http://purl.org/eprint/entityType/Expression"); if (isset($this->sac_language)) { $this->statementVesURI($fh, "http://purl.org/dc/elements/1.1/language", "http://purl.org/dc/terms/RFC3066", $this->valueString($this->sac_language)); } $this->statementVesURIValueURI($fh, "http://purl.org/dc/elements/1.1/type", "http://purl.org/eprint/terms/Type", "http://purl.org/eprint/entityType/Expression"); if (isset($this->sac_dateavailable)) { $this->statement($fh, "http://purl.org/dc/terms/available", $this->valueStringSesURI("http://purl.org/dc/terms/W3CDTF", $this->sac_dateavailable)); } if (isset($this->sac_statusstatement)) { $this->statementVesURIValueURI($fh, "http://purl.org/eprint/terms/Status", "http://purl.org/eprint/terms/Status", $this->sac_statusstatement); } if (isset($this->sac_copyrightholder)) { $this->statement($fh, "http://purl.org/eprint/terms/copyrightHolder", $this->valueString($this->sac_copyrightholder)); } if (isset($this->sac_citation)) { $this->statement($fh, "http://purl.org/eprint/terms/bibliographicCitation", $this->valueString($this->sac_citation)); } fwrite($fh, "\n"); fwrite($fh, "\n"); fwrite($fh, "\n"); fwrite($fh, "\n"); fwrite($fh, "\n"); } function writeFileGrp($fh) { fwrite($fh, "\t\n"); fwrite($fh, "\t\t\n"); for ($i = 0; $i < $this->sac_filecount; $i++) { fwrite($fh, "\t\t\tsac_mimetypes[$i] . "\">\n"); fwrite($fh, "\t\t\t\tclean($this->sac_files[$i]) . "\" />\n"); fwrite($fh, "\t\t\t\n"); } fwrite($fh, "\t\t\n"); fwrite($fh, "\t\n"); } function writeStructMap($fh) { fwrite($fh, "\t\n"); fwrite($fh, "\t\t\n"); fwrite($fh, "\t\t\t\n"); for ($i = 0; $i < $this->sac_filecount; $i++) { fwrite($fh, "\t\t\t\t\n"); } fwrite($fh, "\t\t\t\n"); fwrite($fh, "\t\t\n"); fwrite($fh, "\t\n"); } function writeFooter($fh) { fwrite($fh, "\n"); } function valueString($value) { return "" . $value . "\n"; } function valueStringSesURI($sesURI, $value) { return "" . $value . "\n"; } function statement($fh, $propertyURI, $value) { fwrite($fh, "\n" . $value . "\n"); } function statementValueURI($fh, $propertyURI, $value) { fwrite($fh, "\n"); } function statementVesURI($fh, $propertyURI, $vesURI, $value) { fwrite($fh, "\n" . $value . "\n"); } function statementVesURIValueURI($fh, $propertyURI, $vesURI, $value) { fwrite($fh, "\n"); } function clean($data) { return str_replace(''', ''', htmlspecialchars($data, ENT_QUOTES)); } } ?>