/** * Answer true if the current user is authorized to export this node. * * @param SiteComponent $siteComponent * @return boolean * @access protected */ protected function isAuthorizedToExportComments(SiteComponent $siteComponent) { $authZ = Services::getService("AuthZ"); $idMgr = Services::getService("Id"); return $authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.view_comments'), $siteComponent->getQualifierId()); }
/** * 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; } } }
/** * Answer the HTML for the controls top-bar * * @param <##> * @return <##> * @access public * @since 4/7/06 */ function getControlsHTML(SiteComponent $siteComponent, $title, $controlsHTML, $borderColor, $backgroundColor, $dividerColor, $leftIndentLevel = 0, $borderWidth = '0px', $selectionLinkHtml = null) { $halfLineWidth = 1; $lineWidth = $halfLineWidth * 2 . 'px'; $halfLineWidth = $halfLineWidth . 'px'; $opacityStyles = "filter:alpha(opacity=70); " . "-moz-opacity: .70; " . "opacity: .70; "; ob_start(); print "\n<div class='controls_bar' " . "id='controls_bar__" . $siteComponent->getId() . "' " . "style='" . "color: #000; " . "min-width: 150px; " . "border-top: {$borderWidth} solid {$borderColor}; " . "border-left: {$borderWidth} solid {$borderColor}; " . "border-right: {$borderWidth} solid {$borderColor}; " . ($leftIndentLevel ? "margin-left: 10px; " : ""); if (!$this->controlsAlwaysVisible()) { print "visibility: hidden; "; } // print "position: absolute; "; // print "z-index: 10; "; print "left: 0px; "; print "'"; // print " onmouseover='showControlsLink(this)'" // ." onmouseout='hideControlsLink(this)'"; // Any clicks on the page will hide all options panels. // Prevent clicks within the panel from hiding it. print " onclick='"; print "if (event.stopPropagation) { "; print "event.stopPropagation(); "; print "} else if (window.event) { "; print "window.event.cancelBubble = true; "; print "}"; print "'"; print ">"; print "\n<table border='0' cellpadding='0' cellspacing='0'" . " style='width: 100%; padding: 0px; margin: 0px; " . "background-color: {$backgroundColor}; " . $opacityStyles . "'" . ">"; print "\n\t<tr>"; print "\n\t\t<td class='controls_bar_title'>"; print "\n\t\t" . $title; print "\n\t\t</td>"; print "\n\t\t<td style='text-align: right;'>"; print AuthZPrinter::getAZIcon($siteComponent->getQualifierId()); if (!is_null($selectionLinkHtml)) { print "\n\t\t\t\t<span class='selection_link'" . " style='" . "cursor: pointer; white-space: nowrap;'" . ">"; print $selectionLinkHtml; print " |</span>"; } print "\n\t\t\t\t<span class='controls_link'" . " style='" . "cursor: pointer; white-space: nowrap;'" . " onclick='toggleControls(this.parentNode.parentNode.parentNode.parentNode.parentNode);'" . ">"; print "\n\t\t\t" . _("Options"); print "\n\t\t\t</span>"; print "\n\t\t</td>"; print "\n\t</tr>"; print "\n</table>"; $opacityStyles = "filter:alpha(opacity=95); " . "-moz-opacity: .95; " . "opacity: .95; "; print "\n\t\t\t<div class='controls' style='display: none; border-top: 1px solid {$dividerColor}; background-color: {$backgroundColor}; " . $opacityStyles . " position: absolute; left: 0px; z-index: 10; text-align: left;' "; print ">"; print $controlsHTML; print "\n\t\t\t\t</div>"; print "\n</div>"; // if (!$float) { // print "\n<div style='display: block;' class='controls_spacer'> </div>"; // } return ob_get_clean(); }
/** * 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(); }
/** * Print block style options * * @param SiteComponent $siteComponent * @return void * @access public * @since 6/04/08 */ function printBlockStyleOptions(SiteComponent $siteComponent) { print "\n\t\t\t\t<tr><td class='ui2_settingborder'>"; print "\n\t\t\t\t<div class='ui2_settingtitle'>"; print _('Block Style: ') . "\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; } $methods = array('Block_Standard' => _('Standard Block'), 'Block_Sidebar' => _('Sidebar Block'), 'Block_Alert' => _('Alert Block'), 'Header' => _('Header'), 'Footer' => _('Footer')); print "\n\t\t\t\t\t<select class='ui2_field'"; print $canEdit ? "" : " disabled='disabled'"; print " name='" . RequestContext::name('displayType') . "'>"; foreach ($methods as $method => $display) { print "\n\t\t\t\t\t\t<option value='" . $method . "'"; if ($siteComponent->getDisplayType() === $method) { print " selected='selected'"; } print ">"; print $display; print "</option>"; } print "\n\t\t\t\t\t</select><br/> "; print "\n\t\t\t\t</td></tr>"; }