/** * Answer an XML document for the options for this theme * * @return object Harmoni_DOMDocument * @access public * @since 5/15/08 */ public function getOptionsDocument() { $options = new Harmoni_DOMDocument(); if (file_exists($this->optionsPath)) { $options->preserveWhiteSpace = false; $options->load($this->optionsPath); $options->schemaValidateWithException(dirname(__FILE__) . '/theme_options.xsd'); } return $options; }
/** * 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 1/28/08 */ public function saveWizard($cacheName) { $wizard = $this->getWizard($cacheName); if (!$wizard->validate()) { return false; } $values = $wizard->getAllValues(); // printpre($values); // return false; try { if (!defined('DATAPORT_TMP_DIR')) { throw new Exception("DATAPORT_TMP_DIR must be defined in the Segue configuration."); } $archivePath = $values['mode']['backup_file']['tmp_name']; $archiveName = basename($archivePath); $decompressDir = DATAPORT_TMP_DIR . '/' . $archiveName . '_source'; if (!$values['mode']['backup_file']['size']) { throw new Exception("File upload error - archive was not successfully uploaded and has no size."); } $this->decompressArchive($archivePath, $decompressDir); // Do the import $director = SiteDispatcher::getSiteDirector(); $doc = new Harmoni_DOMDocument(); $doc->load($decompressDir . "/site.xml"); // Validate the document contents $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd"); $mediaDir = $decompressDir; switch ($values['mode']['trust']) { case 'all': $class = 'DomImportSiteVisitor'; break; case 'time_only': $class = 'UntrustedAgentDomImportSiteVisitor'; break; default: $class = 'UntrustedAgentAndTimeDomImportSiteVisitor'; } $importer = new $class($doc, $mediaDir, $director); if ($values['mode']['roles'] == '1') { $importer->enableRoleImport(); } if ($values['mode']['comments'] == '0') { $importer->disableCommentImport(); } if (isset($values['owners'])) { $idMgr = Services::getService('Id'); foreach ($values['owners']['admins'] as $adminIdString) { $importer->addSiteAdministrator($idMgr->getId($adminIdString)); } } $importer->enableStatusOutput(); $site = $importer->importAtSlot($values['mode']['slotname']); // Delete the uploaded file unlink($archivePath); // Delete the decompressed Archive $this->deleteRecursive($decompressDir); } catch (Exception $importException) { // Delete the uploaded file try { if (file_exists($archivePath)) { unlink($archivePath); } } catch (Exception $deleteException) { print "\n<div>\n\t"; print $deleteException->getMessage(); print "\n</div>"; } // Delete the decompressed Archive try { if (file_exists($decompressDir)) { $this->deleteRecursive($decompressDir); } } catch (Exception $deleteException) { print "\n<div>\n\t"; print $deleteException->getMessage(); print "\n</div>"; } print "\n<div>\n\t"; print $importException->getMessage(); // print HarmoniErrorHandler::printDebugBacktrace($importException->getTrace()); print "\n</div>"; $wizard->backupFile->setValue(array('name' => null, 'size' => null, 'type' => null)); /********************************************************* * Log the failure *********************************************************/ if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Segue"); $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", "Error", "Recoverable errors."); $item = new AgentNodeEntryItem("Create Site", "Failure in importing site for placeholder, '" . $values['mode']['slotname'] . "'. " . $importException->getMessage()); $item->setBacktrace($importException->getTrace()); $item->addTextToBactrace("Archive Upload: " . printpre($values['mode']['backup_file'], true)); $log->appendLogWithTypes($item, $formatType, $priorityType); } return false; } /********************************************************* * Log the success *********************************************************/ if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Segue"); $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 Site", "Site imported for placeholder, '" . $values['mode']['slotname'] . "'."); $item->addNodeId($site->getQualifierId()); $log->appendLogWithTypes($item, $formatType, $priorityType); } return true; }
/** * Answer a DOM XML Document for the given topic * * @param string $topic * @return object DOMDocument * @access public * @since 12/9/05 */ function getTopicXmlDocument($topic) { $document = new Harmoni_DOMDocument(); $tocPart = $this->_tableOfContents->getTableOfContentsPart($topic); if (!$tocPart || !$tocPart->file || !file_exists($tocPart->file)) { ob_start(); print "<html>\n"; print "\t<head>\n"; print "\t\t<title>"; print dgettext("polyphony", "Topic Not Found"); print "</title>\n"; print "\t</head>\n"; print "\t<body>\n"; print "\t\t<h1>"; print dgettext("polyphony", "Topic Not Found"); print "</h1>\n"; print "\t\t<p>"; print dgettext("polyphony", "The topic that you requested was not found."); print "</p>\n"; print "\t</body>\n"; print "</html>\n"; $document->loadXML(ob_get_clean()); } else { $document->load($tocPart->file); } return $document; }
/** * Convert a Segue1 export into a Segue2 export * * @param string $destFilePath The path that Segue2 export file will be placed in. * @param string $relativeOutputFilePath The output file path relative to * encode into the xml output. * @return object DOMDocument The Segue2 export document * @access protected * @since 3/14/08 */ protected function convertFrom1To2($destFilePath, $relativeOutputFilePath) { try { $sourcePath = $this->downloadSegue1Export(); $sourceFilePath = $sourcePath . "/media"; $sourceDocPath = $sourcePath . "/site.xml"; $sourceDoc = new Harmoni_DOMDocument(); $sourceDoc->load($sourceDocPath); $converter = new Segue1To2Director($destFilePath, $relativeOutputFilePath); $outputDoc = $converter->convert($sourceDoc, $sourceFilePath); // Delete the source directory $this->cleanUpSourcePath($sourcePath); } catch (DOMException $e) { $size = ByteSize::withValue(filesize($sourceDocPath)); $this->cleanUpSourcePath($sourcePath); if ($e->getCode() === DOMSTRING_SIZE_ERR) { throw new DOMException("The export of '" . $this->getSourceSlotName() . "' is too large to load (" . $size->asString() . ") or contains an element that is too large to load.", DOMSTRING_SIZE_ERR); } throw $e; } catch (Exception $e) { if (isset($sourcePath)) { $this->cleanUpSourcePath($sourcePath); } throw $e; } return $outputDoc; }
/** * Create the new site with this template at the slot specified. * * @param object Slot $slot * @param optional string $displayName * @param optional string $description * @return object SiteNavBlockSiteComponent * @access public * @since 6/11/08 */ public function createSite(Slot $slot, $displayName = 'Untitled', $description = '') { $director = SiteDispatcher::getSiteDirector(); $doc = new Harmoni_DOMDocument(); $doc->load($this->_path . "/site.xml"); // Validate the document contents $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd"); $mediaDir = $this->_path . "/media"; if (!file_exists($mediaDir)) { $mediaDir = null; } // @todo Strip out any history. $importer = new StripHistoryImportSiteVisitor($doc, $mediaDir, $director); $importer->disableCommentImport(); $site = $importer->importAtSlot($slot->getShortname()); try { // Replace #SITE_NAME# and #SITE_DESCRIPTION# placeholders $site->acceptVisitor(new Segue_Templates_ReplacePlaceholderVisitor($displayName, $description)); } catch (Exception $e) { $director->deleteSiteComponent($site); $slot->deleteSiteId(); throw $e; } return $site; }