Ejemplo n.º 1
0
 /**
  * Get the ids of the assets that match the search criteria
  * 
  * @param mixed $searchCriteria
  * @return array
  * @access public
  * @since 11/2/04
  */
 function searchAssets($searchCriteria)
 {
     $matchingIds = array();
     $recordMgr = Services::getService("RecordManager");
     $schemaMgr = Services::getService("SchemaManager");
     $drMgr = Services::getService("Repository");
     $schemaIDs = $schemaMgr->getAllSchemaIDs();
     $includeFieldTypes = array("string", "shortstring");
     $assetContentID = "edu.middlebury.harmoni.repository.asset_content";
     // Create the search criteria object
     $criteria = new OrSearch();
     // create one string value
     $stringValue = String::withValue($searchCriteria);
     foreach ($schemaIDs as $schemaID) {
         if ($schemaID != $assetContentID) {
             $schema = $schemaMgr->getSchemaByID($schemaID);
             $schema->load();
             $ids = $schema->getAllFieldIDs();
             foreach ($ids as $id) {
                 $fieldType = $schema->getFieldType($id);
                 if (in_array($fieldType, $includeFieldTypes)) {
                     // add to the field criteria for this schematype/label
                     $criteria->addCriteria(new FieldValueSearch($schemaID, $schema->getFieldLabelFromID($id), $stringValue, SEARCH_TYPE_CONTAINS));
                 }
             }
         }
     }
     // Get the asset Ids to limit to.
     $allAssets = $this->_dr->getAssets();
     $idStrings = array();
     while ($allAssets->hasNext()) {
         $asset = $allAssets->next();
         $id = $asset->getId();
         $idStrings[] = $id->getIdString();
     }
     // Run the search
     $matchingIds = array_unique($recordMgr->getRecordSetIDsBySearch($criteria, $idStrings));
     $idManager = Services::getService("Id");
     // Include Searches of displayname and description
     $displayNameSearch = new DisplayNameSearch($this->_dr);
     $displayNameResults = $displayNameSearch->searchAssets($searchCriteria);
     for ($i = 0; $i < count($displayNameResults); $i++) {
         $matchingIds[] = $displayNameResults[$i]->getIdString();
     }
     $descriptionSearch = new DescriptionSearch($this->_dr);
     $descriptionResults = $descriptionSearch->searchAssets($searchCriteria);
     for ($i = 0; $i < count($descriptionResults); $i++) {
         $matchingIds[] = $descriptionResults[$i]->getIdString();
     }
     // Ensure uniqueness and convert the ids to id objects.
     $matchingIds = array_unique($matchingIds);
     sort($matchingIds);
     $idManager = Services::getService("Id");
     for ($i = 0; $i < count($matchingIds); $i++) {
         $matchingIds[$i] = $idManager->getId($matchingIds[$i]);
     }
     // Return the array
     return $matchingIds;
 }
 /**
  * creates appropriate object from given ids
  * 
  * @param Id $structureId
  * @param Id $partStructureId
  * @param String $part
  * @return object mixed
  * @access public
  * @since 7/21/05
  */
 function getPartObject($structureId, $partStructureId, $part)
 {
     $structure = $this->_destinationRepository->getRecordStructure($structureId);
     $partStructure = $structure->getPartStructure($partStructureId);
     $type = $partStructure->getType();
     $typeString = $type->getKeyword();
     switch ($typeString) {
         case "shortstring":
         case "string":
             $obj = String::withValue($part);
             return $obj;
             break;
         case "integer":
             $obj = Integer::withValue($part);
             return $obj;
             break;
         case "boolean":
             $obj = Boolean::withValue($part);
             return $obj;
             break;
         case "float":
             $obj = Float::withValue($part);
             return $obj;
             break;
         case "datetime":
             $obj = DateAndTime::fromString($part);
             return $obj;
             break;
         case "type":
             $obj = HarmoniType::fromString($part);
             return $obj;
             break;
         default:
             $this->addError("Unsupported PartStructure DataType: " . HarmoniType::typeToString($type) . ".");
             $false = false;
             return $false;
     }
 }
Ejemplo n.º 3
0
 /**
  * Load feed data, convert and clean it, and return its string value.
  * 
  * @param string $url
  * @return string RSS xml
  * @access protected
  * @since 7/8/08
  */
 protected function loadFeedXml($url)
 {
     $feedData = @file_get_contents($url);
     if (!strlen($feedData)) {
         throw new OperationFailedException("Could not access feed, '" . $url . "'.");
     }
     $feed = new DOMDocument();
     // If the encoding is not UTF-8, convert the document
     if (preg_match('/^<\\?xml .*encoding=[\'"]([a-zA-Z0-9-]+)[\'"].*\\?>/m', $feedData, $matches)) {
         $encoding = $matches[1];
         if (strtoupper($encoding) != 'UTF8' && strtoupper($encoding) != 'UTF-8') {
             $feedData = mb_convert_encoding($feedData, 'UTF-8', strtoupper($encoding));
             $feedData = preg_replace('/^(<\\?xml .*encoding=[\'"])([a-zA-Z0-9-]+)([\'"].*\\?>)/m', '\\1UTF-8\\3', $feedData);
         }
     }
     // Convert any non-UTF-8 characters
     $string = String::withValue($feedData);
     $string->makeUtf8();
     $feedData = $string->asString();
     if (!@$feed->loadXML($feedData)) {
         throw new OperationFailedException("Invalid feed data: \"" . $feedData . "\" for URL: " . $url);
     }
     // Handle any format conversions
     $feed = $this->convertToRss($feed);
     // Validate Feed.
     // 		$tmpFeed = $feed;
     // 		$feed = new Harmoni_DOMDocument;
     // 		$feed->loadXML($tmpFeed->saveXML());
     // 		unset($tmpFeed);
     // 		$feed->schemaValidateWithException(dirname(__FILE__).'/rss-2_0-lax.xsd');
     // Run through the titles, authors, and descriptions and clean out any unsafe HTML
     foreach ($feed->getElementsByTagName('title') as $element) {
         $element->nodeValue = strip_tags(htmlspecialchars_decode($element->nodeValue));
     }
     foreach ($feed->getElementsByTagName('author') as $element) {
         $element->nodeValue = strip_tags(htmlspecialchars_decode($element->nodeValue));
     }
     foreach ($feed->getElementsByTagName('comments') as $element) {
         $element->nodeValue = htmlentities(strip_tags(html_entity_decode($element->nodeValue)));
     }
     foreach ($feed->getElementsByTagName('link') as $element) {
         $element->nodeValue = htmlentities(strip_tags(html_entity_decode($element->nodeValue)));
     }
     foreach ($feed->getElementsByTagName('description') as $description) {
         $html = HtmlString::fromString(htmlspecialchars_decode($description->nodeValue));
         $html->cleanXSS();
         $description->nodeValue = htmlspecialchars($html->asString());
     }
     // Move the feed into a dom document.
     $tmpFeed = $feed;
     $feed = new Harmoni_DOMDocument();
     $feed->loadXML($tmpFeed->saveXML());
     unset($tmpFeed);
     // Validate the feed again
     // 		$feed->schemaValidateWithException(dirname(__FILE__).'/rss-2_0-lax.xsd');
     // Just ensure a few basic things:
     if (!$feed->documentElement->nodeName == 'rss') {
         throw new DOMDocumentException("Feed root must be an rss element");
     }
     // Check for channels
     foreach ($feed->documentElement->childNodes as $element) {
         if ($element->nodeType == 1 && $element->nodeName != 'channel') {
             throw new DOMDocumentException("'" . $node->nodeName . "' is not expected, expecting 'channel'.");
         }
     }
     // Check dates
     foreach ($feed->getElementsByTagName('pubdate') as $element) {
         if (!preg_match('/(((Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat)|(Sun)), *)?\\d\\d? +((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec)) +\\d\\d(\\d\\d)? +\\d\\d:\\d\\d(:\\d\\d)? +(([+\\-]?\\d\\d\\d\\d)|(UT)|(GMT)|(EST)|(EDT)|(CST)|(CDT)|(MST)|(MDT)|(PST)|(PDT)|\\w)/', $element->nodeValue)) {
             throw new DOMDocumentException("'" . $element->nodeValue . "' is not a valid date.");
         }
     }
     return $feed->saveXMLWithWhitespace();
 }
Ejemplo n.º 4
0
 /**
  * Answer the XML document that describes this version.
  * 
  * @return DOMDocument
  * @access public
  * @since 1/7/08
  */
 public function getVersionXml()
 {
     if (!isset($this->versionXml)) {
         $query = new SelectQuery();
         $query->addTable('segue_plugin_version');
         $query->addWhereEqual('version_id', $this->getVersionId());
         $query->addColumn('version_xml');
         $dbc = Services::getService('DBHandler');
         $result = $dbc->query($query, IMPORTER_CONNECTION);
         $this->versionXml = new Harmoni_DOMDocument();
         $xmlString = String::withValue($result->field('version_xml'));
         $xmlString->makeUtf8();
         $this->versionXml->loadXML($xmlString->asString());
     }
     return $this->versionXml;
 }
Ejemplo n.º 5
0
 /**
  * Save our results. Tearing down and unsetting the Wizard is handled by
  * in {@link runWizard()} and does not need to be implemented here.
  * 
  * @param string $cacheName
  * @return boolean TRUE if save was successful and tear-down/cleanup of the
  *		Wizard should ensue.
  * @access public
  * @since 4/28/05
  */
 function saveWizard($cacheName)
 {
     $wizard = $this->getWizard($cacheName);
     // Make sure we have a valid Repository
     $authZ = Services::getService("AuthZ");
     $idManager = Services::getService("Id");
     $repositoryManager = Services::getService("Repository");
     $repository = $repositoryManager->getRepository($idManager->getId("edu.middlebury.concerto.exhibition_repository"));
     $slideshowAsset = $repository->getAsset($idManager->getId(RequestContext::value('slideshow_id')));
     $properties = $wizard->getAllValues();
     $status = new StatusStars(_("Saving Slideshow"));
     $status->initializeStatistics(count($properties['slidestep']['slides']) + 2);
     // First, verify that we chose a parent that we can add children to.
     if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $slideshowAsset->getId())) {
         $slideshowAssetId = $slideshowAsset->getId();
         $this->_slideshowAssetId = $slideshowAssetId;
         // Update the Name and description
         if ($properties['namedescstep']['display_name']) {
             $slideshowAsset->updateDisplayName($properties['namedescstep']['display_name']);
         }
         if ($properties['namedescstep']['description']) {
             $slideshowAsset->updateDescription($properties['namedescstep']['description']);
         }
         // Update the effective/expiration dates
         // 			if ($properties['datestep']['effective_date'])
         // 				$slideshowAsset->updateEffectiveDate(
         // 					DateAndTime::fromString(
         // 					$properties['datestep']['effective_date']));
         // 			if ($properties['datestep']['expiration_date'])
         // 				$slideshowAsset->updateExpirationDate(
         // 					DateAndTime::fromString(
         // 					$properties['datestep']['expiration_date']));
         // --- Slides ---
         $slideAssetType = new HarmoniType("Asset Types", "edu.middlebury.concerto", "Slide", "Slides are components of Slide-Shows that contain captions and may reference media Assets.");
         $slideRecordStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure");
         $targetIdPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.target_id");
         $textPositionPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.text_position");
         $displayMetadataPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.display_metadata");
         $setManager = Services::getService("Sets");
         $pSlideOrder = $setManager->getPersistentSet($slideshowAssetId);
         $slideIterator = $slideshowAsset->getAssets();
         // ---- Add/Update Slides in new order (hopefully)
         $existingSlides = array();
         while ($slideIterator->hasNext()) {
             $currentSlide = $slideIterator->next();
             $id = $currentSlide->getId();
             $existingSlides[] = $id->getIdString();
         }
         $pSlideOrder->removeAllItems();
         $status->updateStatistics();
         foreach ($properties['slidestep']['slides'] as $slideProperties) {
             // 				print get_class($slideProperties['slideId']).": ".$slideProperties['title'];
             if (!isset($slideProperties['slideId'])) {
                 // ---- Clean the inputs ----
                 if (isset($slideProperties['title'])) {
                     $title = $slideProperties['title'];
                 } else {
                     $title = '';
                 }
                 if (isset($slideProperties['caption'])) {
                     $caption = $slideProperties['caption'];
                 } else {
                     $caption = '';
                 }
                 if (isset($slideProperties['text_position'])) {
                     $textPosition = String::withValue($slideProperties['text_position']);
                 } else {
                     $textPosition = String::withValue('');
                 }
                 if (isset($slideProperties['show_target_metadata'])) {
                     $displayMetadata = Boolean::withValue($slideProperties['show_target_metadata']);
                 } else {
                     $displayMetadata = Boolean::false();
                 }
                 if (isset($slideProperties['_assetId'])) {
                     $targetId = String::withValue($slideProperties['_assetId']->getIdString());
                 } else {
                     $targetId = String::withValue('');
                 }
                 // ---- Create the asset ----
                 $slideAsset = $repository->createAsset($title, $caption, $slideAssetType);
                 $slideAssetId = $slideAsset->getId();
                 $slideshowAsset->addAsset($slideAssetId);
                 // Add it to the order field
                 $pSlideOrder->addItem($slideAssetId);
                 // ---- Set the additional info ----
                 $slideRecord = $slideAsset->createRecord($slideRecordStructId);
                 $slideRecord->createPart($textPositionPartStructId, $textPosition);
                 $slideRecord->createPart($displayMetadataPartStructId, $displayMetadata);
                 $slideRecord->createPart($targetIdPartStructId, $targetId);
             } else {
                 if (in_array($slideProperties['slideId']->getIdString(), $existingSlides)) {
                     $slideAsset = $repository->getAsset($slideProperties['slideId']);
                     $slideAsset->updateDisplayName($slideProperties['title']);
                     $slideAsset->updateDescription($slideProperties['caption']);
                     $textPositionIterator = $slideAsset->getPartsByPartStructure($textPositionPartStructId);
                     if ($textPositionIterator->hasNext()) {
                         $part = $textPositionIterator->next();
                         $part->updateValue(new String($slideProperties['text_position']));
                     }
                     $showMetadataIterator = $slideAsset->getPartsByPartStructure($displayMetadataPartStructId);
                     if ($showMetadataIterator->hasNext()) {
                         $part = $showMetadataIterator->next();
                         $part->updateValue(new Boolean($slideProperties['show_target_metadata']));
                     }
                     $pSlideOrder->addItem($slideProperties['slideId']);
                     $records = $slideAsset->getRecordsByRecordStructure($slideRecordStructId);
                     $slideRecord = $records->next();
                 }
             }
             $status->updateStatistics();
         }
         // ==== Remove slide assets no longer in slideshow ----
         foreach ($existingSlides as $older) {
             $old = $idManager->getId($older);
             if (!$pSlideOrder->isInSet($old)) {
                 $slideshowAsset->removeAsset($old, false);
                 $repository->deleteAsset($old);
             }
         }
         $status->updateStatistics();
         // Log the success or failure
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Concerto");
             $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
             $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
             $item = new AgentNodeEntryItem("Modify Node", "Slideshow Modified");
             $item->addNodeId($slideshowAssetId);
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * Answer an element with a text section
  * 
  * @param string $elementName
  * @param string $data
  * @return DOMElement
  * @access protected
  * @since 1/17/08
  */
 protected function getElementNS($namespaceURI, $elementName, $data)
 {
     $string = String::withValue($data);
     $string->makeUtf8();
     $element = $this->doc->createElementNS($namespaceURI, $elementName, $string->asString());
     // 		$element->appendChild($this->doc->createCDATASection($data));
     return $element;
 }
 /**
  * Delete a PartStucture
  * 
  * @param object Id $partStructureId
  * @return void
  * @access public
  * @since 6/8/06
  */
 function deletePartStructure(Id $partStructureId)
 {
     // Delete the Structure
     $schemaMgr = Services::getService("SchemaManager");
     $recordMgr = Services::getService("RecordManager");
     $partStructure = $this->getPartStructure($partStructureId);
     $dummyValues = array(String::withValue('4000-02-05'));
     $recordIdsWithValues = $recordMgr->getRecordSetIDsBySearch(new FieldValueSearch($this->_schema->getID(), $this->_schema->getFieldLabelFromID($partStructureId->getIdString()), new HarmoniIterator($dummyValues), SEARCH_TYPE_NOT_IN_LIST));
     if (count($recordIdsWithValues)) {
         throwError(new Error(RepositoryException::OPERATION_FAILED() . " when deleting RecordStructure: '" . $recordStructureId->getIdString() . "', Records exist for this RecordStructure.", "Repository", 1));
     }
     $sm = Services::getService("SchemaManager");
     $this->_schema->deleteField($partStructureId->getIdString());
     $sm->synchronize($this->_schema);
     $partStructure = null;
 }
Ejemplo n.º 8
0
 /**
  * Save our results. Tearing down and unsetting the Wizard is handled by
  * in {@link runWizard()} and does not need to be implemented here.
  * 
  * @param string $cacheName
  * @return boolean TRUE if save was successful and tear-down/cleanup of the
  *		Wizard should ensue.
  * @access public
  * @since 4/28/05
  */
 function saveWizard($cacheName)
 {
     $wizard = $this->getWizard($cacheName);
     // Make sure we have a valid Repository
     $authZ = Services::getService("AuthZ");
     $idManager = Services::getService("Id");
     $repositoryManager = Services::getService("Repository");
     $repository = $repositoryManager->getRepository($idManager->getId("edu.middlebury.concerto.exhibition_repository"));
     $exhibitionAsset = $repository->getAsset($idManager->getId(RequestContext::value('exhibition_id')));
     $properties = $wizard->getAllValues();
     $status = new StatusStars(_("Saving Slideshow"));
     $status->initializeStatistics(count($properties['slidestep']['slides']) + 2);
     // First, verify that we chose a parent that we can add children to.
     if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.add_children"), $exhibitionAsset->getId())) {
         $slideshowAssetType = new HarmoniType("Asset Types", "edu.middlebury.concerto", "Slideshow", "Slide-Shows are ordered collections of slides that contain captions and may reference media Assets.");
         $slideshowAsset = $repository->createAsset($properties['namedescstep']['display_name'], $properties['namedescstep']['description'], $slideshowAssetType);
         $slideshowAssetId = $slideshowAsset->getId();
         $this->_slideshowAssetId = $slideshowAssetId;
         // Update the effective/expiration dates
         // 			if ($properties['datestep']['effective_date'])
         // 				$slideshowAsset->updateEffectiveDate(
         // 					DateAndTime::fromString($properties['datestep']['effective_date']));
         // 			if ($properties['datestep']['expiration_date'])
         // 				$slideshowAsset->updateExpirationDate(
         // 					DateAndTime::fromString($properties['datestep']['expiration_date']));
         $exhibitionAsset->addAsset($slideshowAssetId);
         // --- Slides ---
         $slideAssetType = new HarmoniType("Asset Types", "edu.middlebury.concerto", "Slide", "Slides are components of Slide-Shows that contain captions and may reference media Assets.");
         $slideRecordStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure");
         $targetIdPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.target_id");
         $textPositionPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.text_position");
         $displayMetadataPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.display_metadata");
         $setManager = Services::getService("Sets");
         $slideOrder = $setManager->getPersistentSet($slideshowAssetId);
         $status->updateStatistics();
         foreach ($properties['slidestep']['slides'] as $slideProperties) {
             // ---- Clean the inputs ----
             if (isset($slideProperties['title'])) {
                 $title = $slideProperties['title'];
             } else {
                 $title = '';
             }
             if (isset($slideProperties['caption'])) {
                 $caption = $slideProperties['caption'];
             } else {
                 $caption = '';
             }
             if (isset($slideProperties['text_position'])) {
                 $textPosition = String::withValue($slideProperties['text_position']);
             } else {
                 $textPosition = String::withValue('');
             }
             if (isset($slideProperties['show_target_metadata'])) {
                 $displayMetadata = Boolean::withValue($slideProperties['show_target_metadata']);
             } else {
                 $displayMetadata = Boolean::false();
             }
             if (isset($slideProperties['_assetId'])) {
                 $targetId = String::withValue($slideProperties['_assetId']->getIdString());
             } else {
                 $targetId = String::withValue('');
             }
             // ---- Create the asset ----
             $slideAsset = $repository->createAsset($title, $caption, $slideAssetType);
             $slideAssetId = $slideAsset->getId();
             $slideshowAsset->addAsset($slideAssetId);
             $slideOrder->addItem($slideAssetId);
             // ---- Set the additional info ----
             $slideRecord = $slideAsset->createRecord($slideRecordStructId);
             $slideRecord->createPart($textPositionPartStructId, $textPosition);
             $slideRecord->createPart($displayMetadataPartStructId, $displayMetadata);
             $slideRecord->createPart($targetIdPartStructId, $targetId);
             $status->updateStatistics();
         }
         // Log the success or failure
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Concerto");
             $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
             $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
             $item = new AgentNodeEntryItem("Create Node", "Slideshow added");
             $item->addNodeId($slideshowAssetId);
             $item->addNodeId($exhibitionAsset->getId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         $status->updateStatistics();
         return TRUE;
     } else {
         return FALSE;
     }
 }