/**
  * Constructor
  *
  * Creates the DomDocument object, and adds XML elements common to all
  * OAI-PMH responses.  Dispatches control to appropriate verb, if any.
  * @access public
  * @param array $query HTTP POST/GET query key-value pair array.
  * @uses dispatchRequest()
  */
 public function __construct($query)
 {
     $url = new Pas_OaiPmhRepository_ServerUrl();
     $this->_serverUrl = $url->get();
     $this->_error = false;
     $this->query = $query;
     $this->document = new DomDocument('1.0', 'UTF-8');
     //formatOutput makes DOM output "pretty" XML.  Good for debugging, but
     //adds some overhead, especially on large outputs.
     $this->document->formatOutput = true;
     $this->document->xmlStandalone = true;
     $root = $this->document->createElementNS(self::OAI_PMH_NAMESPACE_URI, 'OAI-PMH');
     $this->document->appendChild($root);
     $root->setAttributeNS(self::XML_SCHEMA_NAMESPACE_URI, 'xsi:schemaLocation', self::OAI_PMH_NAMESPACE_URI . ' ' . self::OAI_PMH_SCHEMA_URI);
     $responseDate = $this->document->createElement('responseDate', self::unixToUtc(time()));
     $root->appendChild($responseDate);
     $this->metadataFormats = $this->getFormats();
     $this->dispatchRequest();
 }
示例#2
0
 /** Add meta data to the xml response as LIDO XML
  * @access public
  * @return void
  */
 public function appendMetadata()
 {
     // Create the base element
     $metadataElement = $this->document->createElement('metadata');
     $this->parentElement->appendChild($metadataElement);
     //Create the lido element
     $lidoElement = $this->document->createElementNS(self::METADATA_NAMESPACE, 'lido:lido');
     //Append to the base element
     $metadataElement->appendChild($lidoElement);
     //Set the base attributes
     $lidoElement->setAttribute('xmlns:xsi', parent::XML_SCHEMA_NAMESPACE_URI);
     $lidoElement->setAttribute('xsi:schemaLocation', self::METADATA_NAMESPACE . ' ' . self::METADATA_SCHEMA);
     //Create the dublin core metadata from an array of objects
     if (!array_key_exists('0', $this->item)) {
         if (array_key_exists('objecttype', $this->item) && $this->item['objecttype'] === 'HOARD') {
             $uri = self::HOARD_URI;
         } else {
             $uri = self::RECORD_URI;
         }
         //The base LIDO array
         $lido = array();
         if (array_key_exists('broadperiod', $this->item)) {
             $lido['title'] = $this->item['broadperiod'] . ' ' . $this->item['objecttype'];
         } else {
             $lido['title'] = $this->item['objecttype'];
             $this->item['broadperiod'] = 'UNKNOWN';
         }
         if (array_key_exists('creator', $this->item)) {
             $lido['creator'] = $this->item['creator'];
         }
         $lido['subject'] = self::SUBJECT . ' - ' . $this->item['broadperiod'];
         if (array_key_exists('description', $this->item)) {
             $description = strip_tags(str_replace(array("\n", "\r", '    '), array('', '', ' '), $this->item['description']));
         } else {
             $description = 'No description available';
         }
         $lido['old_findID'] = $this->item['old_findID'];
         $lido['description'] = strtr($description, array('\\x0B' => ''));
         $lido['publisher'] = self::RIGHTS_HOLDER;
         $lido['contributor'] = $this->institution($this->item['institution']);
         $lido['date'] = $this->item['created'];
         $lido['type'] = $this->item['objecttype'];
         $lido['format'] = self::FORMAT;
         $lido['source'] = self::SOURCE;
         $lido['language'] = self::LANGUAGE;
         $lido['identifier'] = $this->item['old_findID'];
         $lido['coverage'] = $this->item['broadperiod'];
         $lido['rights'] = self::LICENSE;
         $lido['uri'] = $this->_serverUrl . $uri . $this->item['id'];
         //The array of dates
         $dates = array();
         if (array_key_exists('fromdate', $this->item)) {
             $dates['fromdate'] = $this->item['fromdate'];
         }
         if (array_key_exists('todate', $this->item)) {
             $dates['todate'] = $this->item['todate'];
         }
         $discovery = array();
         if (array_key_exists('datefound1', $this->item)) {
             $discovery['datefound1'] = $this->item['datefound1'];
         }
         if (array_key_exists('datefound2', $this->item)) {
             $discovery['datefound2'] = $this->item['datefound2'];
         }
         $measurements = array();
         if (array_key_exists('width', $this->item)) {
             $measurements['width'] = $this->item['width'];
         }
         if (array_key_exists('height', $this->item)) {
             $measurements['height'] = $this->item['height'];
         }
         if (array_key_exists('diameter', $this->item)) {
             $measurements['diameter'] = $this->item['diameter'];
         }
         if (array_key_exists('thickness', $this->item)) {
             $measurements['thickness'] = $this->item['thickness'];
         }
         //Create the spatial array
         $spatial = array();
         if (array_key_exists('county', $this->item)) {
             $spatial['county'] = $this->item['county'];
         }
         if (array_key_exists('district', $this->item)) {
             $spatial['district'] = $this->item['district'];
         }
         //Check for availability of NGR and therefore latlon conversions
         if (array_key_exists('knownas', $this->item) && array_key_exists('fourFigure', $this->item)) {
             $lat = $this->item['fourFigureLat'];
             $lon = $this->item['fourFigureLon'];
             $spatial['coords'] = $lat . ',' . $lon;
         }
         $people = array();
         if (array_key_exists('identifer', $this->item)) {
             $people['identifer'] = $this->item['identifer'];
         }
         if (array_key_exists('recorder', $this->item)) {
             $people['recorder'] = $this->item['recorder'];
         }
         if (array_key_exists('secondaryIdentifer', $this->item)) {
             $people['secondary identifer'] = $this->item['secondaryIdentifer'];
         }
         if (array_key_exists('materialTerm', $this->item)) {
             $material = $this->item['materialTerm'];
         } else {
             $material = 'Unknown';
         }
         //Basic terms for DC
         $dcterms = array('created' => date('Y-m-d', strtotime($this->item['created'])), 'medium' => $material, 'isPartOf' => self::SOURCE, 'provenance' => self::PROVENANCE);
         //ESE terms
         $ese = array();
         $ese['provider'] = self::RIGHTS_HOLDER;
         $ese['type'] = 'TEXT';
         //The temporal array
         $temporal = array();
         if (array_key_exists('fromdate', $this->item)) {
             $temporal['year1'] = $this->item['fromdate'];
         }
         if (array_key_exists('todate', $this->item)) {
             $temporal['year2'] = $this->item['todate'];
         }
         //The formats for the images
         $formats = array();
         if (array_key_exists('thumbnail', $this->item) && array_key_exists('imagedir', $this->item)) {
             $formats['image_thumb'] = 'http://finds.org.uk' . '/' . $this->item['imagedir'] . $this->item['filename'];
             $formats['image_master'] = 'http://finds.org.uk' . '/' . $this->item['imagedir'] . $this->item['filename'];
         }
         //Create the record ID element
         $recID = $this->document->createElement('lido:lidoRecID', $lido['uri']);
         //Append the element to the LIDO element
         $lidoElement->appendChild($recID);
         $recID->setAttribute('lido:source', 'The Portable Antiquities Scheme');
         $recID->setAttribute('lido:type', 'URI');
         //Published at
         $published = $this->document->createElement('lido:objectPublishedID', $lido['uri']);
         //Append the published element to the element
         $lidoElement->appendChild($published);
         $published->setAttribute('lido:type', 'URI');
         // The category wrapper
         $categoryElement = $this->document->createElement('lido:category');
         //Append the category element to the LIDO element
         $lidoElement->appendChild($categoryElement);
         $this->appendNewElement($categoryElement, 'lido:conceptID', self::CIDOC_CRM_CONCEPT)->setAttribute('lido:type', 'URI');
         $this->appendNewElement($categoryElement, 'lido:term', self::CIDOC_TERM)->setAttribute('xml:lang', self::LANG);
         //Descriptive element
         $descriptiveElement = $this->document->createElement('lido:descriptiveMetadata');
         //Append the descriptive element to the LIDO element
         $lidoElement->appendChild($descriptiveElement);
         $descriptiveElement->setAttribute('xml:lang', self::LANG);
         //Create the class wrapper
         $classWrap = $this->document->createElement('lido:objectClassificationWrap');
         //Append the class wrapper to the descriptive element
         $descriptiveElement->appendChild($classWrap);
         //Create the work type wrapper
         $workTypeWrap = $this->document->createElement('lido:objectWorkTypeWrap');
         //Append the worktype to the class wrapper
         $classWrap->appendChild($workTypeWrap);
         $typeWrap = $this->document->createElement('lido:objectWorkType');
         $workTypeWrap->appendChild($typeWrap);
         $searchTerm = $this->document->createElement('lido:term', $this->item['objecttype']);
         $typeWrap->appendChild($searchTerm);
         $searchTerm->setAttribute('lido:addedSearchTerm', 'no');
         if (array_key_exists('thumbnail', $this->item)) {
             $classification = $this->document->createElement('lido:classificationWrap');
             $classWrap->appendChild($classification);
             $class = $this->document->createElement('lido:classification');
             $classification->appendChild($class);
             $class->setAttribute('lido:type', 'europeana:type');
             $this->appendNewElement($class, 'lido:term', 'IMAGE');
         }
         // The identifcation wrapper
         $identificationElement = $this->document->createElement('lido:objectIdentificationWrap');
         $descriptiveElement->appendChild($identificationElement);
         //The title wrap
         $titleWrap = $this->document->createElement('lido:titleWrap');
         $identificationElement->appendChild($titleWrap);
         $titleset = $this->document->createElement('lido:titleSet');
         $titleWrap->appendChild($titleset);
         $this->appendNewElement($titleset, 'lido:appellationValue', $lido['title']);
         //The repository wrapper
         $repoWrap = $this->document->createElement('lido:repositoryWrap');
         $identificationElement->appendChild($repoWrap);
         $repoSet = $this->document->createElement('lido:repositorySet');
         $repoWrap->appendChild($repoSet);
         $repoName = $this->document->createElement('lido:repositoryName');
         $repoSet->appendChild($repoName);
         $legalRepoName = $this->document->createElement('lido:legalBodyName');
         $repoName->appendChild($legalRepoName);
         $this->appendNewElement($legalRepoName, 'lido:appellationValue', 'The British Museum and the Portable Antiquities Scheme');
         //Object description wrap
         $objDescWrap = $this->document->createElement('lido:objectDescriptionWrap');
         $identificationElement->appendChild($objDescWrap);
         $objDescSet = $this->document->createElement('lido:objectDescriptionSet');
         $objDescWrap->appendChild($objDescSet);
         $this->appendNewElement($objDescSet, 'lido:descriptiveNoteValue', $lido['description']);
         if (!empty($measurements)) {
             $objMeasureWrap = $this->document->createElement('lido:objectMeasurementsWrap');
             $identificationElement->appendChild($objMeasureWrap);
             $objMeasureSet = $this->document->createElement('lido:objectMeasurementsSet');
             $objMeasureWrap->appendChild($objMeasureSet);
             $objMeas = $this->document->createElement('lido:objectMeasurements');
             $objMeasureSet->appendChild($objMeas);
             foreach ($measurements as $k => $v) {
                 $set = $this->document->createElement('lido:measurementsSet');
                 $objMeas->appendChild($set);
                 $this->appendNewElement($set, 'lido:measurementType', $k);
                 $this->appendNewElement($set, 'lido:measurementUnit', 'mm');
                 $this->appendNewElement($set, 'lido:measurementValue', $v);
             }
             if (array_key_exists('weight', $this->item)) {
                 $set = $this->document->createElement('lido:measurementsSet');
                 $objMeas->appendChild($set);
                 $this->appendNewElement($set, 'lido:measurementType', 'weight');
                 $this->appendNewElement($set, 'lido:measurementUnit', 'g');
                 $this->appendNewElement($set, 'lido:measurementValue', $this->item['weight']);
             }
         }
         //The event wrapper
         $eventElement = $this->document->createElement('lido:eventWrap');
         $descriptiveElement->appendChild($eventElement);
         $eventSet = $this->document->createElement('lido:eventSet');
         $eventElement->appendChild($eventSet);
         //The creator of the record
         $eventDating = $this->document->createElement('lido:event');
         $eventSet->appendChild($eventDating);
         $eventTypeCreation = $this->document->createElement('lido:eventType');
         $this->appendNewElement($eventTypeCreation, 'lido:term', 'Production');
         $eventDating->appendChild($eventTypeCreation);
         $eventDate = $this->document->createElement('lido:eventDate');
         $eventDating->appendChild($eventDate);
         $date = $this->document->createElement('lido:date');
         $eventDate->appendChild($date);
         if (array_key_exists('fromdate', $this->item)) {
             $eventDateTime = $this->document->createElement('lido:earliestDate', $this->item['fromdate']);
             $date->appendChild($eventDateTime);
         }
         if (array_key_exists('todate', $this->item)) {
             $eventDateTime = $this->document->createElement('lido:latestDate', $this->item['todate']);
             $date->appendChild($eventDateTime);
         }
         if (!empty($discovery)) {
             $eventSetFinding = $this->document->createElement('lido:eventSet');
             $eventElement->appendChild($eventSetFinding);
             $eventDating = $this->document->createElement('lido:event');
             $eventSetFinding->appendChild($eventDating);
             $eventTypeCreation = $this->document->createElement('lido:eventType');
             $this->appendNewElement($eventTypeCreation, 'lido:term', 'Finding');
             $eventDating->appendChild($eventTypeCreation);
             if (array_key_exists('county', $this->item)) {
                 $placeType = $this->document->createElement('lido:eventPlace');
                 $eventDating->appendChild($placeType);
                 $place = array();
                 $place[] = 'United Kingdom';
                 $place[] = $this->item['county'];
                 if (array_key_exists('district', $this->item)) {
                     $place[] = $this->item['district'];
                 }
                 if (array_key_exists('parish', $this->item)) {
                     if (!array_key_exists('knownas', $this->item)) {
                         $place[] = $this->item['parish'];
                     }
                 }
                 $placeDisplay = $this->document->createElement('lido:displayPlace', implode($place, ', '));
                 $placeType->appendChild($placeDisplay);
             }
         }
         //The admin wrapper
         $adminElement = $this->document->createElement('lido:administrativeMetadata');
         $lidoElement->appendChild($adminElement);
         $adminElement->setAttribute('xml:lang', self::LANG);
         $rightsWrapElement = $this->document->createElement('lido:rightsWorkWrap');
         $adminElement->appendChild($rightsWrapElement);
         $rightsWorkSet = $this->document->createElement('lido:rightsWorkSet');
         $rightsWrapElement->appendChild($rightsWorkSet);
         $this->appendNewElement($rightsWorkSet, 'lido:creditLine', self::RIGHTS_HOLDER);
         $recordWrap = $this->document->createElement('lido:recordWrap');
         $adminElement->appendChild($recordWrap);
         $recordID = $this->document->createElement('lido:recordID', $this->item['old_findID']);
         $recordID->setAttribute('lido:source', 'PAS');
         $recordID->setAttribute('lido:type', 'local');
         $recordWrap->appendChild($recordID);
         $recordType = $this->document->createElement('lido:recordType');
         $recordWrap->appendChild($recordType);
         $this->appendNewElement($recordType, 'lido:term', 'item');
         $recordSource = $this->document->createElement('lido:recordSource');
         $recordWrap->appendChild($recordSource);
         $legalBody = $this->document->createElement('lido:legalBodyName');
         $recordSource->appendChild($legalBody);
         $this->appendNewElement($legalBody, 'lido:appellationValue', 'The British Museum and The Portable Antiquities Scheme');
         $this->appendNewElement($recordSource, 'lido:legalBodyWeblink', 'http://finds.org.uk');
         $recordInfoSet = $this->document->createElement('lido:recordInfoSet');
         $recordWrap->appendChild($recordInfoSet);
         $url = new Pas_OaiPmhRepository_ServerUrl();
         $types = array('html');
         foreach ($types as $type) {
             $link = $url->get() . $uri . $this->item['id'];
             $this->appendNewElement($recordInfoSet, 'lido:recordInfoLink', $link)->setAttribute('lido:formatResource', $type);
         }
         if (array_key_exists('thumbnail', $this->item)) {
             //Create the resource wrap set and append to admin element
             $resourceWrapSet = $this->document->createElement('lido:resourceWrap');
             $adminElement->appendChild($resourceWrapSet);
             //Create resource set and append to resource wrap set
             $resourceSet = $this->document->createElement('lido:resourceSet');
             $resourceWrapSet->appendChild($resourceSet);
             foreach ($formats as $k => $v) {
                 if (file_exists('./' . $this->item['imagedir'] . $this->item['filename'])) {
                     list($width, $height) = getimagesize('./' . $this->item['imagedir'] . $this->item['filename']);
                     $representation = $this->document->createElement('lido:resourceRepresentation');
                     $resourceSet->appendChild($representation);
                     $representation->setAttribute('lido:type', $k);
                     $this->appendNewElement($representation, 'lido:linkResource', $v)->setAttribute('lido:formatResource', 'jpg');
                     if (file_exists('./' . $this->item['imagedir'] . $this->item['filename'])) {
                         list($width, $height) = getimagesize('./' . $this->item['imagedir'] . $this->item['filename']);
                         //Add height measurement set
                         $measurementSetHeight = $this->document->createElement('lido:resourceMeasurementsSet');
                         $representation->appendChild($measurementSetHeight);
                         //Add image height
                         $this->appendNewElement($measurementSetHeight, 'lido:measurementType', 'height');
                         $this->appendNewElement($measurementSetHeight, 'lido:measurementUnit', 'pixel');
                         $this->appendNewElement($measurementSetHeight, 'lido:measurementValue', $height);
                         //Add Width Measurement Set
                         $measurementSetWidth = $this->document->createElement('lido:resourceMeasurementsSet');
                         $representation->appendChild($measurementSetWidth);
                         //Add image width
                         $this->appendNewElement($measurementSetWidth, 'lido:measurementType', 'width');
                         $this->appendNewElement($measurementSetWidth, 'lido:measurementUnit', 'pixel');
                         $this->appendNewElement($measurementSetWidth, 'lido:measurementValue', $width);
                     }
                 }
             }
             $this->appendNewElement($resourceSet, 'lido:resourceDescription', 'Original Image');
             $resourceSource = $this->document->createElement('lido:resourceSource');
             $resourceSet->appendChild($resourceSource);
             $resourceSource->setAttribute('lido:type', 'Holder of image');
             $this->appendNewElement($resourceSource, 'lido:legalBodyID', 'http://britishmuseum.org')->setAttribute('lido:type', 'URI');
             $legalBodyName = $this->document->createElement('lido:legalBodyName');
             $resourceSource->appendChild($legalBodyName);
             $this->appendNewElement($legalBodyName, 'lido:appellationValue', 'The British Museum: Department of Britain, Europe and Prehistory');
             $rightsResource = $this->document->createElement('lido:rightsResource');
             $resourceSet->appendChild($rightsResource);
             $resourceRightsType = $this->document->createElement('lido:rightsType');
             $rightsResource->appendChild($resourceRightsType);
             $this->appendNewElement($resourceRightsType, 'lido:conceptID', self::LICENSE_URI)->setAttribute('lido:type', 'URI');
         }
     }
 }
示例#3
0
 /**
  * Metadata_Abstract constructor
  *
  * Sets base class properties.
  * @access public
  * @param Item item Item object whose metadata will be output.
  * @param DOMElement element Parent element for XML output.
  * @return void
  */
 public function __construct($item, $element)
 {
     $this->item = $item;
     $this->parentElement = $element;
     if (isset($element)) {
         $this->document = $element->ownerDocument;
     }
     $server = new Pas_OaiPmhRepository_ServerUrl();
     $this->_serverUrl = $server->get();
 }