/**
  * Answer the organizer above the reference node that can accept the component type given.
  * 
  * @param object SiteComponent $refNode
  * @param object Type $componentType
  * @return object OrganizerSiteComponent
  * @access public
  * @since 1/15/09
  * @static
  */
 public static function getOrganizerForComponentType(SiteComponent $refNode, Type $componentType)
 {
     // For pages and sections, find the menu above our component.
     if ($componentType->getDomain() == 'segue-multipart') {
         $parentComponent = $refNode->getParentComponent();
         while ($parentComponent) {
             if ($parentComponent->getComponentClass() == 'MenuOrganizer') {
                 return $parentComponent;
             }
             $parentComponent = $parentComponent->getParentComponent();
         }
         // If we didn't find a menu above our ref node, maybe we started in a heading.
         // Search down for a menu.
         $director = SiteDispatcher::getSiteDirector();
         $rootNode = $director->getRootSiteComponent($refNode->getId());
         $result = $rootNode->acceptVisitor(new GetMenuBelowSiteVisitor());
         if ($result) {
             return $result;
         }
         // If we still haven't found a menu, then there isn't one in this site.
         // Nothing more we can do.
         throw new OperationFailedException("Cannot create a " . $componentType->getKeyword() . ". Site " . $rootNode->getSlot()->getShortname() . " - '" . $rootNode->getDisplayName() . "' does not have any menus to add this component to.");
     } else {
         $parentComponent = $refNode->getParentComponent();
         while ($parentComponent) {
             if ($parentComponent->getComponentClass() == 'FlowOrganizer' || $parentComponent->getComponentClass() == 'MenuOrganizer') {
                 return $parentComponent;
             }
         }
         // If we haven't found a flow organizer above the refNode, something is wrong.
         throw new OperationFailedException("Cannot create a " . $componentType->getKeyword() . ". A ContentOrganizer was not found above reference node " . $refNode->getId());
     }
 }
 /**
  * Visit any kind of SiteComponent and record its visibility
  * 
  * @param object SiteComponent $siteComponent
  * @return array
  * @access public
  * @since 8/31/07
  */
 private function visitSiteComponent(SiteComponent $siteComponent)
 {
     $this->_visibleComponents[$siteComponent->getId()] = $siteComponent;
     $results = array();
     $results['VisibleComponents'] = $this->_visibleComponents;
     $results['FilledTargetIds'] = $this->_filledTargetIds;
     return $results;
 }
 /**
  * Answer true if the component passed is the direct child of the site nav organizer.
  * 
  * @param object SiteComponent $siteComponent
  * @return boolean
  * @access private
  * @since 4/10/08
  */
 private function isChildOfSiteNavOrg(SiteComponent $siteComponent)
 {
     if (!isset($this->siteNavOrgId)) {
         $siteNav = $siteComponent->getDirector()->getRootSiteComponent($siteComponent->getId());
         $this->siteNavOrgId = $siteNav->getOrganizer()->getId();
     }
     if ($this->siteNavOrgId == $siteComponent->getParentComponent()->getId()) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Answer an array of RSS link info.
  * 
  * @param  object SiteComponent $siteComponent
  * @return array
  * @access private
  * @since 3/11/08
  * @static
  */
 private static function getLinks(SiteComponent $siteComponent)
 {
     $harmoni = Harmoni::instance();
     $harmoni->request->startNamespace(null);
     $links = array();
     // Content RSS
     $links[] = array('url' => SiteDispatcher::quickUrl("rss", "content", array('node' => $siteComponent->getId())), 'label' => _('Content RSS'), 'title' => _("Content RSS for") . " " . htmlentities(strip_tags($siteComponent->getDisplayName())));
     // Comments RSS
     $links[] = array('url' => SiteDispatcher::quickUrl("rss", "comments", array('node' => $siteComponent->getId())), 'label' => _('Discussion RSS'), 'title' => _("Discussion RSS for") . " " . htmlentities(strip_tags($siteComponent->getDisplayName())));
     $harmoni->request->endNamespace();
     return $links;
 }
 /**
  * get url of node that action is applied to
  * 
  * @return string
  * @access public
  * @since 1/23/09
  */
 public function getTargetUrl()
 {
     return SiteDispatcher::quickURL('view', 'html', array('node' => $this->_node->getId()));
 }
 /**
  * Answer an 'add new component' link
  * 
  * @param string $title
  * @param string $display
  * @param object SiteComponent $startingSiteComponent
  * @return string
  * @access public
  * @since 12/3/07
  */
 public function getAddLink($title, $display, SiteComponent $startingComponent)
 {
     ArgumentValidator::validate($title, NonZeroLengthStringValidatorRule::getRule());
     ArgumentValidator::validate($display, NonZeroLengthStringValidatorRule::getRule());
     $harmoni = Harmoni::instance();
     ob_start();
     print "<a href='";
     $harmoni->request->startNamespace(null);
     try {
         print SiteDispatcher::quickURL($this->addModule, $this->addAction, array('title' => $title, 'refNode' => $startingComponent->getId()));
     } catch (NullArgumentException $e) {
         print $harmoni->request->quickURL($this->addModule, $this->addAction, array('title' => $title, 'node' => $startingComponent->getId(), 'refNode' => $startingComponent->getId()));
     }
     $harmoni->request->endNamespace();
     print "'";
     print " title=\"" . str_replace('%1', strip_tags($title), _("Add '%1' as a new component.")) . "\"";
     print ">";
     print $display;
     print " ?</a>";
     return ob_get_clean();
 }
 /**
  * Answer a wrapping div that triggers showing and hiding the border and 
  * controls-bar for the item
  * 
  * @param string $borderColor
  * @param SiteComponent $siteComponent
  * @return string
  * @access public
  * @since 1/16/07
  */
 function getBarPreHTML($borderColor, SiteComponent $siteComponent, $borderWidth = '2px')
 {
     ob_start();
     print "\n<div class='site_component_wrapper'";
     if (!$this->controlsAlwaysVisible()) {
         print " onmouseover='this.borderColor = \"{$borderColor}\"; showControls(this)'";
         print " onmouseout='if (isValidMouseOut(this, event)) {hideControls(this);} '";
         print " style='position: relative; border: {$borderWidth} solid transparent;'";
     } else {
         print " style='position: relative; margin: 1px; border: {$borderWidth} solid {$borderColor};'";
     }
     print " onclick='";
     print "if (shiftAndMetaOrControl(event)) { ";
     print "toggleControls(document.get_element_by_id(\"controls_bar__" . $siteComponent->getId() . "\")); ";
     print "if (event.stopPropagation) { ";
     print "event.stopPropagation(); ";
     print "} else if (window.event) { ";
     print "window.event.cancelBubble = true; ";
     print "}";
     print "}";
     print "'";
     print ">";
     return ob_get_clean();
 }
Exemple #8
0
 /**
  * Save a role for a hierarchy node
  * 
  * @param object SiteComponent $component
  * @param object SegueRole $role
  * @return <##>
  * @access public
  * @since 11/16/07
  */
 public function saveRole(SiteComponent $component, SegueRole $role)
 {
     $roleMgr = SegueRoleManager::instance();
     $idMgr = Services::getService("Id");
     $agentId = $this->getAgentId();
     $componentId = $idMgr->getId($component->getId());
     // Ensure that Everyone or Institute are not set to admin
     $everyoneId = $idMgr->getId('edu.middlebury.agents.everyone');
     $instituteId = $idMgr->getId('edu.middlebury.institute');
     if ($agentId->isEqual($everyoneId) || $agentId->isEqual($instituteId)) {
         if ($role->getIdString() == 'admin') {
             $role = $roleMgr->getRole('editor');
         }
     }
     // 		printpre("Saving role '".$role->getIdString()."' for ".$agentId." at ".$component->getDisplayName());
     // Find the parent node.
     $parent = $component->getParentComponent();
     if ($parent) {
         $parentQualifierId = $parent->getQualifierId();
         $parentRole = $roleMgr->getAgentsRole($agentId, $parentQualifierId, true);
     }
     // Apply the role or clear it if it is less than the implicitly given role.
     try {
         if (isset($parentRole) && $role->isLessThanOrEqualTo($parentRole)) {
             $roleMgr->clearRoleAZs($agentId, $componentId);
             // 				printpre("Clearing duplicate role '".$role->getIdString()."' for ".$agentId." at ".$component->getDisplayName());
         } else {
             $role->apply($agentId, $componentId);
         }
     } catch (PermissionDeniedException $e) {
     }
     return true;
 }
Exemple #9
0
 /**
  * Answer the link to add a particular SiteComponent to the selection
  * 
  * @param object SiteComponent $siteComponent
  * @return string XHTML
  * @access public
  * @since 7/31/08
  */
 public function getAddLink(SiteComponent $siteComponent)
 {
     $this->addHeadJavascript();
     $harmoni = Harmoni::instance();
     $harmoni->request->startNamespace("selection");
     ob_start();
     print "\n\t\t<a ";
     print " id='selection_add_link-" . $siteComponent->getId() . "'";
     print " class='";
     if ($this->isSiteComponentInSet($siteComponent)) {
         print "Selection_add_link_selected";
     } else {
         print "Selection_add_link_deselected";
     }
     print "' ";
     print " style='cursor: pointer;'";
     print " href='#' ";
     print " onclick=\"Segue_Selection.instance().toggleComponent({";
     print "id: '" . $siteComponent->getId() . "', ";
     print "type: '" . $siteComponent->getComponentClass() . "', ";
     print "displayName: '" . addslashes(str_replace('"', '&quot', preg_replace('/\\s+/', ' ', strip_tags($siteComponent->getDisplayName())))) . "' ";
     print "}); return false;\"";
     print 'title="' . _("Copy to your Selection") . '" ';
     print ">" . _('Copy');
     print "</a>";
     $harmoni->request->endNamespace();
     return ob_get_clean();
 }
Exemple #10
0
 /**
  * Print Node info html
  * 
  * @param object SiteComponent $siteComponent
  * @return void
  * @access protected
  * @since 3/17/08
  */
 protected function printNodeInfo(SiteComponent $siteComponent, $inMenu = false)
 {
     $harmoni = Harmoni::instance();
     print $this->getTabs() . "\t";
     if ($siteComponent->getId() == SiteDispatcher::getCurrentNodeId()) {
         print "<div class='info current'>";
     } else {
         print "<div class='info'>";
     }
     print $this->getTabs() . "\t\t";
     print "<div class='title'>";
     $nodeUrl = SiteDispatcher::quickURL('view', 'html', array('node' => $siteComponent->getId()));
     if (!$inMenu) {
         print "<a href='" . $nodeUrl . "' ";
         print ' onclick="';
         print "if (window.opener) { ";
         print "window.opener.location = this.href; ";
         print "return false; ";
         print '}" ';
         print " title='" . _("View this node") . "'>";
     }
     print $siteComponent->getDisplayName();
     if (!$inMenu) {
         print "</a>";
     }
     print "</div>";
     $nodeDescription = HtmlString::withValue($siteComponent->getDescription());
     $nodeDescription->stripTagsAndTrim(5);
     print $this->getTabs() . "\t\t";
     print "<div class='description'>" . $nodeDescription->stripTagsAndTrim(20) . "</div>";
     print $this->getTabs() . "\t";
     print "</div>";
 }
 /**
  * get url of node that action is applied to
  * 
  * @return string
  * @access public
  * @since 1/23/09
  */
 public function getTargetUrl()
 {
     $url = SiteDispatcher::quickURL('versioning', 'compare_versions', array('node' => $this->_node->getId(), 'late_rev' => $this->_version->getVersionId()));
     return $url;
 }
Exemple #12
0
 /**
  * Copy a component.
  * 
  * @param object SiteComponent
  * @return void
  * @access protected
  * @since 8/4/08
  */
 protected function copyComponent(SiteComponent $siteComponent)
 {
     $authZ = Services::getService("AuthZ");
     $idMgr = Services::getService("Id");
     if (!$authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.modify'), $siteComponent->getQualifierId())) {
         throw new PermissionDeniedException("You are not authorized to copy this node from its original location.");
     }
     try {
         /*********************************************************
          * Export the Component
          *********************************************************/
         $exportDir = DATAPORT_TMP_DIR . "/" . $siteComponent->getId() . "-" . str_replace(':', '_', DateAndTime::now()->asString());
         mkdir($exportDir);
         // Do the export
         $visitor = new DomExportSiteVisitor($exportDir);
         $visitor->enableStatusOutput(_("Exporting from original location."));
         $siteComponent->acceptVisitor($visitor);
         $doc = $visitor->doc;
         // Validate the result
         // 			printpre(htmlentities($doc->saveXMLWithWhitespace()));
         $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-subtree.xsd");
         // 			printpre($this->listDir($exportDir));
         // 			throw new Exception('test');
         /*********************************************************
          * Import the Component
          *********************************************************/
         $importer = new DomImportSiteVisitor($doc, $exportDir, SiteDispatcher::getSiteDirector());
         if (RequestContext::value('copy_permissions') == 'true') {
             $importer->enableRoleImport();
         }
         if (RequestContext::value('copy_discussions') == 'false') {
             $importer->disableCommentImport();
         }
         $importer->enableStatusOutput(_("Importing into new location"));
         $newComponent = $importer->importSubtreeUnderOrganizer($this->getDestinationComponent());
         // Delete the decompressed Archive
         $this->deleteRecursive($exportDir);
         return $newComponent;
     } catch (Exception $e) {
         $this->deleteRecursive($exportDir);
         if (file_exists($exportDir . ".tar.gz")) {
             unlink($exportDir . ".tar.gz");
         }
         throw $e;
     }
 }
 /**
  * Answer the history control
  * 
  * @param object SiteComponent $siteComponent
  * @return string
  * @access public
  * @since 1/10/08
  */
 public function getHistory(SiteComponent $siteComponent)
 {
     ob_start();
     $authZ = Services::getService("AuthZ");
     $idManager = Services::getService("Id");
     $harmoni = Harmoni::instance();
     if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $siteComponent->getQualifierId())) {
         $harmoni = Harmoni::instance();
         $harmoni->history->markReturnURL('view_history_' . $siteComponent->getId());
         $url = SiteDispatcher::quickURL('versioning', 'view_history', array("node" => $siteComponent->getId(), 'returnModule' => $harmoni->request->getRequestedModule(), 'returnAction' => $harmoni->request->getRequestedAction()));
         print "\n\t\t\t\t\t<a href='" . $url . "'>";
         print _("history");
         print "</a>";
     }
     return ob_get_clean();
 }
 /**
  * Import data into an existing component.
  * 
  * @param object DOMElement $element
  * @param object SiteComponent $siteComponent
  * @return object SiteComponent
  * @access protected
  * @since 1/22/08
  */
 protected function importComponent(DOMElement $element, SiteComponent $siteComponent)
 {
     if ($element->hasAttribute('new_id')) {
         throw new Exception("The " . $element->nodeName . " element with id '" . $element->getAttribute('id') . "' already has a new_id set.");
     }
     $element->setAttribute('new_id', $siteComponent->getId());
     // Pass ourselves off to the component to traverse the hierarchy and set
     // data from the source document.
     $siteComponent->acceptVisitor($this);
     return $siteComponent;
 }
 /**
  * Print the history link
  * 
  * @param SiteComponent $siteComponent
  * @return void
  * @access public
  * @since 6/04/08
  */
 function printHistoryLink(SiteComponent $siteComponent)
 {
     print "\n\t\t\t\t<tr><td class='ui2_settingborder'>";
     print "\n\t\t\t\t<div class='ui2_settingtitle'>";
     print _('Edit History: ') . "\n\t\t\t\t</div>";
     print "\n\t\t\t\t</td><td class='ui2_settingborder'>";
     print "\n\t\t\t\t\t";
     print "<a href='";
     $harmoni = Harmoni::instance();
     $harmoni->history->markReturnURL('view_history_' . $siteComponent->getId());
     print SiteDispatcher::quickURL('versioning', 'view_history', array("node" => $siteComponent->getId(), 'returnModule' => $harmoni->request->getRequestedModule(), 'returnAction' => $harmoni->request->getRequestedAction()));
     print "'>";
     print _("view history");
     print " &raquo;</a>";
     print "\n\t\t\t\t</td></tr>";
 }