/** * 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()); } }
/** * 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; } }
/** * Search for SiteComponents with the title passed going up the hierarchy, then down * into siblings. * * @param object SiteComponent $startingComponent * @return mixed string or null * @access private * @since 12/3/07 */ private function searchUp(SiteComponent $startingComponent) { $parent = $startingComponent->getParentComponent(); if ($parent) { $result = $this->searchDown($parent); if (!is_null($result)) { return $result; } else { return $this->searchUp($parent); } } return null; }
/** * Answer the NavBlock above the node passed * * @param SiteComponent $siteComponent * @return NavBlockSiteComponent * @access protected * @since 8/27/08 */ protected function getParentNavBlock(SiteComponent $siteComponent) { $parent = $siteComponent->getParentComponent(); if (!$parent) { throw new OperationFailedException("No Parent Component."); } switch ($parent->getComponentClass()) { case 'NavBlock': case 'SiteNavBlock': return $parent; default: return $this->getParentNavBlock($parent); } }
/** * Add a qualifierId * * @param object SiteComponent $siteComponent * @return void * @access private * @since 11/14/07 */ private function addQualifierForSiteComponent(SiteComponent $siteComponent, $isRoot = false) { $qualifierId = $siteComponent->getQualifierId(); $authZ = Services::getService('AuthZ'); $idMgr = Services::getService('Id'); // Skip if we've added it already if (in_array($qualifierId->getIdString(), $this->qualifierIdsAdded)) { return; } $this->qualifierIdsAdded[] = $qualifierId->getIdString(); // Skip any printing of the node if the current user has no authorization // to view the node or any descendents. if (!$authZ->isUserAuthorized($idMgr->getId("edu.middlebury.authorization.view"), $qualifierId) && !$authZ->isUserAuthorizedBelow($idMgr->getId("edu.middlebury.authorization.view_authorizations"), $qualifierId)) { return; } $roleMgr = SegueRoleManager::instance(); $valuesHidden = false; try { $role = $roleMgr->getAgentsRole($this->agentId, $qualifierId); } catch (PermissionDeniedException $e) { $role = $roleMgr->getAgentsRole($this->agentId, $qualifierId, true); $valuesHidden = true; } // Create the property with the current role $title = strip_tags($siteComponent->getDisplayName()); if (!strlen($title)) { $title = _("Untitled"); } if ($isRoot) { $this->property->addField($qualifierId->getIdString(), $title, $role->getIdString(), ">="); } else { $parentQualifierId = $siteComponent->getParentComponent()->getQualifierId(); $this->property->addChildField($parentQualifierId->getIdString(), $qualifierId->getIdString(), $title, $role->getIdString(), ">="); } // Make the values hidden if the current user has no authorization // to view the authorizations of the node. if ($valuesHidden) { $this->property->makeValuesHidden($qualifierId->getIdString()); } // Disable options that are precluded by implicit authorizations // coming from group membership. $groupRole = $roleMgr->getGroupImplictRole($this->agentId, $qualifierId, true); try { $groupIds = $groupRole->getAgentsCausing(); $names = array(); $agentMgr = Services::getService("Agent"); foreach ($groupIds as $id) { $group = $agentMgr->getAgentOrGroup($id); if ($group->getDisplayName()) { $names[] = "'" . $group->getDisplayName() . "'"; } else { $names[] = "'" . $id->getIdString() . "'"; } } $groupNames = ' (' . implode(", ", $names) . ")"; } catch (Exception $e) { $groupNames = ''; } foreach ($roleMgr->getRoles() as $role) { if ($role->isLessThan($groupRole)) { $message = _("You cannot remove the '%1' role because '%2' is a member a group%3 that has been given the '%1' role."); $message = str_replace("%1", $groupRole->getDisplayName(), $message); $message = str_replace("%2", $this->agent->getDisplayName(), $message); $message = str_replace("%3", $groupNames, $message); $this->property->makeDisabled($qualifierId->getIdString(), $role->getIdString(), $message); } } // Disable options that are precluded by implicit authorizations // coming from above the site in the AuthZ hierarchy. foreach ($roleMgr->getRoles() as $role) { if ($role->isLessThan($this->siteImplicitRole)) { $this->property->makeDisabled($qualifierId->getIdString(), $role->getIdString(), $this->siteImplicitRoleMessage); } } // Disable options where modify_authorization is not allowed. $authN = Services::getService('AuthN'); $adminRole = $roleMgr->getRole('admin'); if (!$authZ->isUserAuthorized($idMgr->getId("edu.middlebury.authorization.modify_authorizations"), $qualifierId)) { foreach ($roleMgr->getRoles() as $role) { $this->property->makeDisabled($qualifierId->getIdString(), $role->getIdString(), _("You are not authorized to change authorization here.")); } } else { if ($authN->getFirstUserId()->isEqual($this->agentId)) { foreach ($roleMgr->getRoles() as $role) { if ($role->isLessThan($adminRole)) { $this->property->makeDisabled($qualifierId->getIdString(), $role->getIdString(), _("You cannot remove your own Administrator access.")); } } } } // Disable the Administrator role for everyone and institute. $nonAdminAgents = array(); $nonAdminAgents[] = $idMgr->getId('edu.middlebury.agents.everyone'); $nonAdminAgents[] = $idMgr->getId('edu.middlebury.agents.anonymous'); $nonAdminAgents[] = $idMgr->getId('edu.middlebury.agents.users'); $nonAdminAgents[] = $idMgr->getId('edu.middlebury.institute'); foreach ($nonAdminAgents as $agentId) { if ($agentId->isEqual($this->agentId)) { $message = _("You cannot give the '%1' role to '%2' for security reasons."); $message = str_replace("%1", $adminRole->getDisplayName(), $message); $message = str_replace("%2", $this->agent->getDisplayName(), $message); $this->property->makeDisabled($qualifierId->getIdString(), 'admin', $message); break; } } }
/** * 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; }
/** * Print sort order controls for flow organizers. * * @param SiteComponent $siteComponent * @return void * @access public * @since 4/17/06 */ function printSortMethod($siteComponent, $step) { $property = $step->addComponent("sort_method", new WSelectList()); $methods = array('default' => _('use default'), 'custom' => _('Override - Custom'), 'title_asc' => _('Override - Alphabetic by Title - Ascending'), 'title_desc' => _('Override - Alphabetic by Title - Descending'), 'create_date_asc' => _("Override - Chronologically by Create Date - Ascending"), 'create_date_desc' => _("Override - Chronologically by Create Date - Descending"), 'mod_date_asc' => _("Override - Chronologically by Modification Date - Ascending"), 'mod_date_desc' => _("Override - Chronologically by Modification Date - Descending")); foreach ($methods as $method => $display) { $property->addOption($method, $display); } if ($siteComponent) { $property->setValue($siteComponent->sortMethodSetting()); $parent = $siteComponent->getParentComponent(); } else { $parent = null; } print "\n<p><strong>" . _("Content Sort Method:") . "</strong> "; print "\n[[sort_method]]"; if ($parent) { print "\n<br/>" . str_replace('%1', $parent->sortMethod(), _("Current default setting: %1")); } print "\n<br/><span style='font-size: smaller;'>"; print _("This setting will change how 'content containers' sort their content. The 'custom' setting allows manual arrangement."); print "</span>"; print "\n</p>"; }
/** * Print the reorder form * * @param object SiteComponent $siteComponent * @return void * @access public * @since 9/20/07 */ public function printReorderForm(SiteComponent $siteComponent) { $authZ = Services::getService("AuthZ"); $idManager = Services::getService("Id"); $harmoni = Harmoni::instance(); $parent = $siteComponent->getParentComponent(); if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $parent->getQualifierId())) { $url = $harmoni->request->quickURL($this->module, 'reorder', array('returnNode' => SiteDispatcher::getCurrentNodeId(), 'returnAction' => $this->action)); $harmoni->request->startNamespace('reorder'); $organizer = $siteComponent->getParentComponent(); $myCell = $organizer->getCellForSubcomponent($siteComponent); print "\n\t\t\t\t\t<form class='ui1_controls reorder_form_" . $parent->getId() . "' action='" . $url . "' method='post' style='display: none'>"; print "\n\t<input type='hidden' name='" . RequestContext::name('node') . "' value='" . $siteComponent->getId() . "' />"; print "\n\t<select name='" . RequestContext::name('position') . "' onchange='this.form.submit();'>"; for ($i = 0; $i < $organizer->getTotalNumberOfCells(); $i++) { print "\n\t\t<option value='{$i}'"; if ($myCell == $i) { print " selected='selected'"; } print ">" . ($i + 1) . "</option>"; } print "\n\t</select>"; print "\n\t<input type='button' onclick=\""; print "hideReorder('" . $parent->getId() . "'); "; print "\" value='" . _("Cancel") . "'/>"; print "\n\t\t\t\t\t</form>"; $harmoni->request->endNamespace(); } }
/** * Move a component. * * @param object SiteComponent * @return void * @access protected * @since 8/4/08 */ protected function moveComponent(SiteComponent $siteComponent) { // Check that we are allow to remove the source component $authZ = Services::getService("AuthZ"); $idManager = Services::getService("Id"); if (!$authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.remove_children"), $siteComponent->getParentComponent()->getQualifierId())) { throw new PermissionDeniedException("You are not authorized to remove this node from its original location."); } $oldParent = $siteComponent->getParentComponent(); $oldParent->detatchSubcomponent($siteComponent); $this->getDestinationComponent()->addSubcomponent($siteComponent); return $siteComponent; }
/** * Print the discussion controls * * @param SiteComponent $siteComponent * @return void * @access public * @since 7/16/07 */ function printCommentSettings($siteComponent, $isSite = false) { print "\n\t\t\t\t<tr><td class='ui2_settingborder'>"; print "\n\t\t\t\t<div class='ui2_settingtitle'>"; print _('Discussion: ') . "\n\t\t\t\t</div>"; print "\n\t\t\t\t</td><td class='ui2_settingborder'>"; $authZ = Services::getService("AuthZ"); $idManager = Services::getService("Id"); if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $siteComponent->getQualifierId())) { $canEdit = true; } else { $canEdit = false; } print "\n\t\t\t\t\t<select class='ui2_field'"; print $canEdit ? "" : " disabled='disabled'"; print " name='" . RequestContext::name('commentsEnabled') . "'>"; $parent = $siteComponent->getParentComponent(); // if not site setting (i.e. root node of site), the include default option if (!$isSite) { print "\n\t\t\t\t\t\t<option value='default'"; if ($siteComponent->commentsEnabled() === 'default') { print " selected='selected'>"; } else { print ">"; } print _("default"); if ($parent) { print " (" . _("current") . ": "; if ($parent->commentsEnabled() === true) { print _("yes"); } else { print _("no"); } print ")"; } print "</option>"; } // other setting select option print "\n\t\t\t\t\t\t<option value='true'"; if ($siteComponent->commentsEnabled() === true) { print " selected='selected'"; } print ">"; print _("yes"); print "</option>"; print "\n\t\t\t\t\t\t<option value='false'"; if ($siteComponent->commentsEnabled() === false) { print " selected='selected'"; } print ">"; print _("no"); print "</option>"; print "\n\t\t\t\t\t</select> "; // print out default settings // $parent = $siteComponent->getParentComponent(); // if ($parent) { // print "\n<span class='ui2_text'>("._("default").": "; // print (($parent->showComments() === true)?_("yes"):_("no")); // print ")</span>"; // } print "\n\t\t\t\t</td></tr>"; }
/** * Answer the root of the site * * @param SiteComponent $siteComponent * @return SiteNavBlockSiteComponent * @access public * @since 9/24/07 */ public function getSiteNavBlock(SiteComponent $siteComponent) { $parent = $siteComponent->getParentComponent(); if (is_null($parent)) { return $siteComponent; } else { return $this->getSiteNavBlock($parent); } }