Пример #1
0
 /**
  * Check Authorizations
  * 
  * @return boolean
  * @access public
  * @since 12/04/07
  */
 function isAuthorizedToExecute()
 {
     // Check for authorization
     $authZManager = Services::getService("AuthZ");
     $idManager = Services::getService("IdManager");
     if ($authZManager->isUserAuthorized($idManager->getId("edu.middlebury.authorization.add_children"), $idManager->getId("edu.middlebury.authorization.root"))) {
         return true;
     }
     $harmoni = Harmoni::instance();
     $harmoni->request->startNamespace("slots");
     $name = strtolower(RequestContext::value("name"));
     $harmoni->request->passthrough("name");
     $harmoni->request->endNamespace();
     $slotMgr = SlotManager::instance();
     $slot = $slotMgr->getSlotByShortname($name);
     $authN = Services::getService("AuthN");
     if ($slot->isUserOwner() && $slot->getType() == Slot::personal && $slot->getShortName() != PersonalSlot::getPersonalShortname($authN->getFirstUserId())) {
         return true;
     }
     return false;
 }
 /**
  * Create a new personal slot if our form was submitted.
  * 
  * @return void
  * @access private
  * @since 4/1/08
  */
 private function createNewSlotIfRequested()
 {
     $authN = Services::getService("AuthN");
     $harmoni = Harmoni::instance();
     // Creation of new personal slots.
     $harmoni->request->startNamespace('personal_slot');
     if (RequestContext::value('slot_postfix') && PersonalSlot::hasPersonal()) {
         try {
             $newSlotname = PersonalSlot::getPersonalShortname($authN->getFirstUserId()) . "-" . RequestContext::value('slot_postfix');
             // Replace delimiting marks with an underscore
             $newSlotname = preg_replace('/[\\s\\/=+.,()]+/i', '_', $newSlotname);
             // Remove anything left over (other than letters/numbers/-/_)
             $newSlotname = preg_replace('/[^a-z0-9_-]/i', '', $newSlotname);
             $slot = new PersonalSlot(strtolower($newSlotname));
             $slot->addOwner($authN->getFirstUserId());
         } catch (OperationFailedException $e) {
             $harmoni->request->endNamespace();
             if ($e->getCode() == Slot::OWNER_EXISTS) {
                 throw new OperationFailedException("Placeholder '" . strtolower($newSlotname) . "' already exists.");
             } else {
                 throw $e;
             }
         }
         // Log this change.
         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 Placeholder", "New placeholder created:  '" . $slot->getShortname() . "'.");
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
     }
     $harmoni->request->endNamespace();
 }
Пример #3
0
 /**
  * Execute
  * 
  * @return mixed
  * @access public
  * @since 2/4/08
  */
 public function buildContent()
 {
     try {
         $status = new StatusStars(_("Preparing Site Import"));
         $status->initializeStatistics(4);
         $destPath = DATAPORT_TMP_DIR . "/Segue1Conversion-" . $this->getDestSlotName();
         mkdir($destPath);
         $destFilePath = $destPath . '/media';
         mkdir($destFilePath);
         $status->updateStatistics();
         // Download and convert the site
         $doc = $this->convertFrom1To2($destFilePath, 'media');
         // 			printpre(htmlentities($doc->saveXMLWithWhitespace()));
         // 			throw new Exception('test');
         $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd");
         $status->updateStatistics();
         // Debug output
         // 			$outputDoc2 = new Harmoni_DOMDocument;
         // 			$outputDoc2->loadXML($doc->saveXMLWithWhitespace());
         // 			printpre(htmlentities($outputDoc2->saveXML()));
         // 			throw new Exception('test');
         // Add the user as the owner
         $authN = Services::getService("AuthN");
         $slotMgr = SlotManager::instance();
         $slot = $slotMgr->getSlotByShortname($this->getDestSlotName());
         $slot->addOwner($authN->getFirstUserId());
         // Make the slot personal if it matches the personal naming scheme.
         $userName = PersonalSlot::getPersonalShortname($authN->getFirstUserId());
         if ($slot->getType() != Slot::personal && preg_match('/^' . $userName . '(-.+)?$/', $this->getDestSlotName())) {
             $slot = $slotMgr->convertSlotToType($slot, Slot::personal);
         }
         $status->updateStatistics();
         // Import the converted site
         $director = SiteDispatcher::getSiteDirector();
         $importer = new Segue1MappingImportSiteVisitor($doc, $destPath, $director);
         $status->updateStatistics();
         $importer->enableStatusOutput();
         $importer->makeUserSiteAdministrator();
         $importer->enableRoleImport();
         $importer->setOrigenSlotname($this->getSourceSlotName());
         $importer->setDestinationSlotname($this->getDestSlotName());
         $site = $importer->importAtSlot($this->getDestSlotName());
         // Set the media quota if it is bigger than our default
         $quota = $importer->getMediaQuota();
         if ($quota > $slot->getMediaQuota()->value()) {
             $slot->setMediaQuota(ByteSize::withValue($quota));
         }
         // Delete the output directory
         try {
             if (file_exists($destPath)) {
                 $this->deleteRecursive($destPath);
             }
         } catch (Exception $deleteException) {
             print "\n<div>\n\t";
             print $deleteException->getMessage();
             print "\n</div>";
         }
         /*********************************************************
          * 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, '" . $this->getDestSlotName() . "', from Segue 1 placeholder, '" . $this->getSourceSlotName() . "'.");
             $item->addNodeId($site->getQualifierId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         $harmoni = Harmoni::instance();
         RequestContext::sendTo($harmoni->request->quickURL('dataport', 'choose_site'));
     } catch (Exception $importException) {
         // Delete the output directory
         try {
             if (file_exists($destPath)) {
                 $this->deleteRecursive($destPath);
             }
         } catch (Exception $deleteException) {
             print "\n<div>\n\t";
             print $deleteException->getMessage();
             print "\n</div>";
         }
         /*********************************************************
          * 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, '" . $this->getDestSlotName() . "', from Segue 1 placeholder, '" . $this->getSourceSlotName() . "'.");
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         throw $importException;
     }
 }
Пример #4
0
 /**
  * Print out a slot
  * 
  * @param object Slot $slot
  * @return void
  * @access protected
  * @since 8/22/07
  */
 public function printSlot(Slot $slot)
 {
     // Print an existing site.
     if ($slot->getSiteId()) {
         try {
             return $this->printSiteShort($slot->getSiteAsset(), $this, 0, $slot);
         } catch (UnknownIdException $e) {
         }
     }
     // If no site is created
     ob_start();
     if ($slot->isAlias()) {
         // Print out the content
         print "\n\t<div class='portal_list_slotname'>";
         print $slot->getShortname();
         $targets = array();
         $target = $slot->getAliasTarget();
         while ($target) {
             $targets[] = $target->getShortname();
             if ($target->isAlias()) {
                 $target = $target->getAliasTarget();
             } else {
                 $target = null;
             }
         }
         print "\n<br/>";
         print str_replace('%1', implode(' &raquo; ', $targets), _("(an alias of %1)"));
         print "\n\t</div>";
     }
     $harmoni = Harmoni::instance();
     print $slot->getShortname();
     print " - ";
     if ($slot->isUserOwner() && !$slot->isAlias()) {
         print " <a href='" . $harmoni->request->quickURL($this->getUiModule(), 'add', array('slot' => $slot->getShortname())) . "' class='create_site_link'>" . _("create site") . "</a>";
         print " | <a href='#' onclick='AliasPanel.run(\"" . $slot->getShortname() . "\", this); return false;' class='create_site_link'>" . _("make alias") . "</a>";
         $authN = Services::getService("AuthN");
         try {
             $personalShortname = PersonalSlot::getPersonalShortname($authN->getFirstUserId());
         } catch (OperationFailedException $e) {
             $personalShortname = null;
         }
         if ($slot->getType() == Slot::personal && $slot->getShortName() != $personalShortname) {
             $harmoni = Harmoni::instance();
             $harmoni->request->startNamespace("slots");
             print " | <a href='";
             print $harmoni->request->quickURL('slots', 'delete', array('name' => $slot->getShortName(), 'returnModule' => $harmoni->request->getRequestedModule(), 'returnAction' => $harmoni->request->getRequestedAction()));
             print "'";
             print " onclick=\"return confirm('" . _("Are you sure that you want to delete this placeholder?") . "');\" ";
             print ">" . _("delete placeholder") . "</a>";
             $harmoni->request->endNamespace();
         }
         print " | " . Segue_Selection::instance()->getSiteMoveCopyLink($slot);
     } else {
         print " <span class='site_not_created_message'>" . _("No Site Created") . "</span>";
     }
     if ($slot->isUserOwner() && $slot->isAlias()) {
         print "\n\t<div class='portal_list_controls'>\n\t\t";
         print "<a href='" . $harmoni->request->quickURL('slots', 'remove_alias', array('slot' => $slot->getShortname())) . "' onclick=\"if (!confirm('" . str_replace("%1", $slot->getShortname(), str_replace("%2", $slot->getAliasTarget()->getShortname(), _("Are you sure that you want \\'%1\\' to no longer be an alias of \\'%2\\'?"))) . "')) { return false; }\">" . _("remove alias") . "</a>";
         print "\n\t</div>";
     }
     ob_start();
     $this->printMigrationStatus($slot);
     $export = ob_get_clean();
     if ($export) {
         print "\n<div class='export_controls'>" . $export . "</div>";
     }
     return new Block(ob_get_clean(), STANDARD_BLOCK);
 }
Пример #5
0
 /**
  * Answer the slot object
  *
  * @return object Slot
  * @access protected
  * @since 1/14/08
  */
 protected function getSlot()
 {
     $slotMgr = SlotManager::instance();
     if (RequestContext::value('slot')) {
         $slot = $slotMgr->getSlotByShortname(RequestContext::value('slot'));
     } else {
         $authN = Services::getService("AuthN");
         $shortname = PersonalSlot::getPersonalShortname($authN->getFirstUserId());
         $slot = new PersonalSlot($shortname . "-" . $siteId);
         $slot->addOwner($authN->getFirstUserId());
     }
     return $slot;
 }