/** * Execute * * @return void * @access public * @since 7/31/08 */ public function execute() { try { if (!RequestContext::value('id')) { throw new InvalidArgumentException("Id is expected."); } $selection = Segue_Selection::instance(); $director = SiteDispatcher::getSiteDirector(); $component = $director->getSiteComponentById(RequestContext::value('id')); if ($selection->isSiteComponentInSet($component)) { $selection->removeSiteComponent($component); } $this->start(); $selection->reset(); while ($selection->hasNext()) { $siteComponent = $selection->nextSiteComponent(); print "\n\t<siteComponent type='" . $siteComponent->getComponentClass() . "' "; if (method_exists($siteComponent, 'isSection')) { if ($siteComponent->isSection()) { print "navType='Section' "; } else { print "navType='Page' "; } } print "id='" . $siteComponent->getId() . "' "; print "displayName=\"" . str_replace('"', '"', preg_replace('/\\s+/', ' ', strip_tags($siteComponent->getDisplayName()))) . "\" "; print "/>"; } $this->end(); } catch (Exception $e) { HarmoniErrorHandler::logException($e); $this->error($e->getMessage(), get_class($e)); } }
/** * Execute * * @return void * @access public * @since 09/23/08 */ public function execute() { try { $this->start(); $userData = UserData::instance(); $userData->setPreference(RequestContext::value('key'), RequestContext::value('val')); print "\n\t<preference key=\"" . RequestContext::value('key') . '">'; print $userData->getPreference(RequestContext::value('key')); print '</preference>'; $this->end(); } catch (Exception $e) { HarmoniErrorHandler::logException($e); $this->error($e->getMessage(), get_class($e)); } }
/** * Answer an array of the Agent ids that are the students for the course. * * @return array * @access public * @since 8/20/07 */ public function getStudents() { $students = array(); $members = $this->getGroup()->getMembers(false); while ($members->hasNext()) { $agentId = $members->next()->getId(); try { if ($this->isStudent($agentId)) { $students[] = $agentId; } } catch (OperationFailedException $e) { HarmoniErrorHandler::logException($e); } } return $students; }
/** * Execute this action * * @return void * @access public * @since 1/14/09 */ public final function execute() { $this->start(); try { $this->buildXml(); } catch (PermissionDeniedException $e) { $this->error($e->getMessage()); } catch (Exception $e) { HarmoniErrorHandler::logException($e); $this->error(get_class($e) . ": " . $e->getMessage()); } $this->end(); }
/** * Execute the plugin and return its markup. * * @param optional boolean $showControls * @param optional boolean $extended If true, return the extended version. Default: false. * @return string * @access public * @since 1/13/06 */ public function executeAndGetMarkup($showControls = false, $extended = false) { $obLevel = ob_get_level(); try { $this->setShowControls($showControls); $harmoni = Harmoni::instance(); $harmoni->request->startNamespace(get_class($this) . ':' . $this->getId()); if (isset($this->localModule) && $this->localModule && isset($this->localAction) && $this->localAction) { $this->_baseUrl = SiteDispatcher::mkURL($this->localModule, $this->localAction); } else { $this->_baseUrl = SiteDispatcher::mkURL(); } $this->update($this->_getRequestData()); if ($extended) { $markup = $this->getExtendedMarkup(); } else { $markup = $this->getMarkup(); } // update the description if needed $this->setShowControls(false); $desc = $this->generateDescription(); $this->setShowControls($showControls); if ($desc != $this->_asset->getDescription()) { $this->_asset->updateDescription($desc); } // Data records are now depricated. // $this->_storeData(); $harmoni->request->endNamespace(); } catch (Exception $e) { while (ob_get_level() > $obLevel) { ob_end_clean(); } HarmoniErrorHandler::logException($e); $markup = _("An Error has occured in the plugin with the following message: "); $markup .= $e->getMessage(); } return $markup; }
/** * Build the content for this action * * @return void * @access public * @since 4/26/05 */ function outputContent() { $defaultTextDomain = textdomain("polyphony"); $harmoni = Harmoni::instance(); $idManager = Services::getService("Id"); $harmoni->request->startNamespace("polyphony-repository"); // Get the requested record. try { $asset = $this->getAsset(); if (RequestContext::value("record_id")) { $recordId = $idManager->getId(RequestContext::value("record_id")); $record = $asset->getRecord($recordId); } else { $record = RepositoryInputOutputModuleManager::getFirstImageOrFileRecordForAsset($asset); } } catch (UnknownIdException $e) { HarmoniErrorHandler::logException($e); $this->getUnknownIdMessage(); } // Make sure that the structure is the right one. $structure = $record->getRecordStructure(); $fileId = $idManager->getId('FILE'); $remoteFileId = $idManager->getId('REMOTE_FILE'); if (!$fileId->isEqual($structure->getId()) && !$remoteFileId->isEqual($structure->getId())) { try { throw new Exception("The requested record is not of the FILE structure, and therefore cannot be displayed."); } catch (Exception $e) { HarmoniErrorHandler::logException($e); $this->getUnknownIdMessage(); } } else { // Get the parts for the record. $partIterator = $record->getParts(); $parts = array(); while ($partIterator->hasNext()) { $part = $partIterator->next(); $partStructure = $part->getPartStructure(); $partStructureId = $partStructure->getId(); $parts[$partStructureId->getIdString()] = $part; } // If we have a thumbnail, print that. if ($parts['THUMBNAIL_MIME_TYPE']->getValue()) { header("Content-Type: " . $parts['THUMBNAIL_MIME_TYPE']->getValue()); $mime = Services::getService("MIME"); $extension = $mime->getExtensionForMIMEType($parts['THUMBNAIL_MIME_TYPE']->getValue()); $filename = $parts['FILE_NAME']->getValue(); if (!$filename) { $filename = _("Untitled"); } header('Content-Disposition: filename="' . $filename . "." . $extension . '"'); print $parts['THUMBNAIL_DATA']->getValue(); } else { header("Content-Type: image/png"); $mimeType = $parts['MIME_TYPE']->getValue(); if (!$mimeType || $mimeType == 'application/octet-stream') { $mime = Services::getService("MIME"); $mimeType = $mime->getMIMETypeForFileName($parts['FILE_NAME']->getValue()); } // These are mappings to file names in the KDE icon set. $subTypeImages = array("text/plain" => "txt.png", "text/css" => "css.png", "text/html" => "html.png", "text/x-lyx" => "mime_lyx.png", "text/xml" => "xml.png", "audio/midi" => "midi.png", "video/quicktime" => "quicktime.png", "application/vnd.rn-realmedia" => "real.png", "application/x-pn-realaudio" => "real.png", "application/x-pn-realaudio" => "real.png", "application/msword" => "wordprocessing.png", "application/vnd.ms-word" => "wordprocessing.png", "application/vnd.ms-excel" => "spreadsheet.png", "application/msword" => "wordprocessing.png", "application/vnd.ms-powerpoint" => "kpresenter_kpr.png", "application/mspowerpoint" => "kpresenter_kpr.png", "application/pdf" => "pdf.png", "application/x-tar" => "tar.png", "application/x-gtar" => "gtar.png", "application/x-ustar" => "tar.png", "application/x-gzip" => "tar.png", "application/x-bzip" => "tar.png", "application/x-bzip2" => "tar.png", "application/x-bcpio" => "tar.png", "application/x-cpio" => "tar.png", "application/x-shar" => "tar.png", "application/mac-binhex40" => "tar.png", "application/x-stuffit" => "tar.png", "application/zip" => "tar.png"); $typeImages = array("text" => "txt.png", "application" => "binary.png", "audio" => "sound.png", "video" => "video.png", "image" => "image.png"); if (isset($subTypeImages[$mimeType])) { $imageName = $subTypeImages[$mimeType]; } else { $typeParts = explode("/", $mimeType); $imageName = $typeImages[$typeParts[0]]; } header('Content-Disposition: filename="' . $imageName . '"'); print file_get_contents(POLYPHONY_DIR . "/icons/filetypes/" . $imageName); } } $harmoni->request->endNamespace(); textdomain($defaultTextDomain); exit; }
/** * Tells the wizard component to update itself - this may include getting * form post data or validation - whatever this particular component wants to * do every pageload. * @param string $fieldName The field name to use when outputting form data or * similar parameters/information. * @access public * @return boolean - TRUE if everything is OK */ function update($fieldName) { $val = RequestContext::value($fieldName); if (is_array($val)) { $uploadFile = $val['tmp_name']; if (is_uploaded_file($uploadFile)) { if ($val['error'] == 0) { // no error! // Check that our file is one of our allowed types if (isset($this->_accept) && is_array($this->_accept) && count($this->_accept) && !in_array($val['type'], $this->_accept)) { $this->_errString = dgettext("polyphony", "File '%1' of type '%2' is not allowed. Allowed types: %3"); $this->_errString = str_replace('%1', $val['name'], $this->_errString); $this->_errString = str_replace('%2', $val['type'], $this->_errString); $this->_errString = str_replace('%3', implode(', ', $this->_accept), $this->_errString); return false; } // Get the temporary directory to use. if (defined('POLYPHONY_TMP_DIR')) { $tmpDir = POLYPHONY_TMP_DIR; } else { $tmpDir = dirname($uploadFile); } // get a new temp filename so PHP doesn't delete the uploaded file $newFile = tempnam($tmpDir, "WU"); if (file_exists($newFile)) { @unlink($newFile); } if (move_uploaded_file($uploadFile, $newFile)) { // if we already have an uploaded file, delete it if ($this->_changed) { @unlink($this->_hdfile); } $this->_changed = true; $this->_hdfile = $newFile; $this->_filename = $val['name']; $this->_mimetype = $val['type']; $this->_size = $val['size']; return true; } else { HarmoniErrorHandler::logException(new OperationFailedException("Could not move file from '" . $uploadFile . "' to '" . $newFile . "'")); } } else { // generate an error string for display $errString = ''; switch ($val['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $errString = dgettext("polyphony", "File exceeded maximum allowed size."); break; case UPLOAD_ERR_PARTIAL: $errString = dgettext("polyphony", "An upload error occured. (partial upload)"); break; case UPLOAD_ERR_NO_FILE: $errString = dgettext("polyphony", "An upload error occured. (no file)"); break; case UPLOAD_ERR_NO_TMP_DIR: $errString = dgettext("polyphony", "An upload error occured. (no temp directory)"); break; } $this->_errString = $errString; } } } return false; }
/** * Given an internal definition of the slot, load any extra owners * that might be in an external data source. * * @return void * @access public * @since 8/14/07 */ public function mergeWithExternal() { if (!$this->mergedWithExternal) { $courseMgr = SegueCourseManager::instance(); $idMgr = Services::getService("Id"); try { $course = $courseMgr->getCourse($idMgr->getId($this->getShortname())); $this->mergedWithExternal = true; foreach ($course->getInstructors() as $instructor) { if (!$this->isOwner($instructor) && !$this->isRemovedOwner($instructor)) { $this->populateOwnerId($instructor); } } } catch (Exception $e) { // If we can't find any external definition for the course, // skip rather than dying. HarmoniErrorHandler::logException($e); } } }
/** * Build the content for this action * * @return void * @access public * @since 4/26/05 */ function outputContent() { $defaultTextDomain = textdomain("polyphony"); $harmoni = Harmoni::instance(); $idManager = Services::getService("Id"); $harmoni->request->startNamespace("polyphony-repository"); $size = RequestContext::value("size"); $websafe = RequestContext::value("websafe"); // See if we are passed a size if (is_numeric($size)) { $size = intval($size); } else { $size = FALSE; } if ($websafe) { $websafe = TRUE; } else { $websafe = FALSE; } if (RequestContext::value('attachment')) { $attachment = true; } else { $attachment = false; } // Get the requested record. try { $asset = $this->getAsset(); try { $recordId = $idManager->getId(RequestContext::value("record_id")); $record = $asset->getRecord($recordId); } catch (InvalidArgumentException $e) { // If no record id is specified, use the first file record available $record = RepositoryInputOutputModuleManager::getFirstImageOrFileRecordForAsset($asset); if (!$record) { throw $e; } } catch (UnknownIdException $e) { // If no record id is specified, use the first file record available $record = RepositoryInputOutputModuleManager::getFirstImageOrFileRecordForAsset($asset); if (!$record) { throw $e; } } } catch (UnknownIdException $e) { HarmoniErrorHandler::logException($e); $this->getUnknownIdMessage(); } // Make sure that the structure is the right one. $structure = $record->getRecordStructure(); $remoteFileId = $idManager->getId('REMOTE_FILE'); $fileId = $idManager->getId('FILE'); if ($remoteFileId->isEqual($structure->getId())) { $urlParts = $record->getPartsByPartStructure($idManager->getId("FILE_URL")); $urlPart = $urlParts->next(); header("Location: " . $urlPart->getValue()); } else { if (!$fileId->isEqual($structure->getId())) { try { throw new Exception("The requested record is not of the FILE structure, and therefore cannot be displayed."); } catch (Exception $e) { HarmoniErrorHandler::logException($e); $this->getUnknownIdMessage(); } } else { // Get the parts for the record. $partIterator = $record->getParts(); $parts = array(); while ($partIterator->hasNext()) { $part = $partIterator->next(); $partStructure = $part->getPartStructure(); $partStructureId = $partStructure->getId(); $parts[$partStructureId->getIdString()] = $part; } $imgProcessor = Services::getService("ImageProcessor"); // If we want to (and can) resize the file, do so if (($size || $websafe) && $imgProcessor->isFormatSupported($parts['MIME_TYPE']->getValue())) { $imageCache = new RepositoryImageCache($record->getId(), $size, $websafe, $parts); header("Content-Type: " . $imageCache->getCachedMimeType()); if ($attachment) { header('Content-Disposition: attachment; filename="' . $imageCache->getCachedFileName() . '"'); } else { header('Content-Disposition: filename="' . $imageCache->getCachedFileName() . '"'); } $data = $imageCache->getCachedImageData(); header('Content-Length: ' . strlen($data)); print $data; } else { header("Content-Type: " . $parts['MIME_TYPE']->getValue()); $filename = $parts['FILE_NAME']->getValue(); if (!preg_match("/[^\\w]/", $filename)) { $mime = Services::getService("MIME"); $extension = $mime->getExtensionForMIMEType($parts['MIME_TYPE']->getValue()); $filename = _("Untitled") . "." . $extension; } if ($attachment) { header('Content-Disposition: attachment; filename="' . $filename . '"'); } else { header('Content-Disposition: filename="' . $filename . '"'); } $data = $parts['FILE_DATA']->getValue(); header('Content-Length: ' . strlen($data)); print $data; } } } $harmoni->request->endNamespace(); textdomain($defaultTextDomain); exit; }
/** * Add a step to set site-wide permissions. * * @param object Wizard $wizard * @return void * @access protected * @since 8/13/08 */ protected function addRolesStep(Wizard $wizard) { $step = new WizardStep(); $step->setDisplayName(_("Roles")); $rolesProperty = $step->addComponent('roles', new RowRadioMatrix()); $roleMgr = SegueRoleManager::instance(); // Add the options foreach ($roleMgr->getRoles() as $role) { if (!$role->isEqual($roleMgr->getRole('custom'))) { $rolesProperty->addOption($role->getIdString(), $role->getDisplayName(), $role->getDescription()); } } // Add agents. $agentMgr = Services::getService("Agent"); $idMgr = Services::getService("Id"); // Super groups $agentsIds = array(); $agentsIds[] = $idMgr->getId('edu.middlebury.agents.everyone'); $agentsIds[] = $idMgr->getId('edu.middlebury.institute'); foreach ($agentsIds as $agentId) { $agent = $agentMgr->getAgentOrGroup($agentId); $rolesProperty->addField($agentId->getIdString(), $agent->getDisplayName(), 'no_access'); } $membersProperty = $step->addComponent('site_members', new MembershipButton($this->getSlot()->getShortname())); ob_start(); print _("Site-Members"); print " [[site_members]]"; print " (" . Help::link('Site-Members') . ")"; print "\n<div style='font-size: smaller; font-weight: normal; width: 300px;'>"; print _("This is a custom group of users that are associated with this site. Users and groups can manually be made site-members or users can self-register using the 'Join Site' plugin if it is enabled."); print "</div>"; $rolesProperty->addField('edu.middlebury.site-members.temp', ob_get_clean(), 'commenter'); // Other owners foreach ($this->getOwners() as $agentId) { $agent = $agentMgr->getAgentOrGroup($agentId); $rolesProperty->addField($agentId->getIdString(), $agent->getDisplayName(), 'admin'); } // Class if (method_exists($this->getSlot(), 'getCourse')) { try { $course = $this->getSlot()->getCourse(); $rolesProperty->addField($course->getGroupId()->getIdString(), $course->getDisplayName(), 'no_access'); } catch (Exception $e) { HarmoniErrorHandler::logException($e, 'Segue'); } } $rolesProperty->makeDisabled('edu.middlebury.agents.everyone', 'admin'); $rolesProperty->makeDisabled('edu.middlebury.institute', 'admin'); // Search $property = $step->addComponent("search", new AddSiteAgentSearchField()); $property->setRolesProperty($rolesProperty); // Create the step text ob_start(); print "\n<h2>" . _("Site-wide Roles") . "</h2>"; print "\n<p>" . _("Below you can set site-wide roles for users and groups over the entire site. Once the site is created you can use the <strong>Roles</strong> button (at the top of the page) to set the roles that users and groups have on various parts of the site.") . "</p>"; print "\n<p><strong>" . _("Roles are always additive:") . "</strong></p> <ul><li>" . _("The Commenter role includes the Reader role, and the Author role is a superset of the Reader and Commenter roles. Click on the role-headings for more details.") . "</li><li>" . _("Groups and individuals can later be given additional roles on particular sections or pages of the site, but site-wide roles can not reduced on particular sections or pages.") . "</li></ul>"; print "\n[[roles]]"; print "\n<p>" . _("Search for users or groups:") . "[[search]]"; print "\n<br/>" . _("<em>If you wish to give a role to a class, search for its course code, for example: </em> <code>span0101a-f08</code>"); print "</p>"; print "\n<div style='width: 400px'> </div>"; $step->setContent(ob_get_clean()); $step = $wizard->addStep("roles", $step); $wizard->makeStepRequired('roles'); }
/** * Handle an Exception * * @param object Exception $e * @parma int $code The HTTP status code to use. * @return void * @access public * @since 2/26/08 */ public function handleAnException(Exception $e, $code) { ArgumentValidator::validate($code, IntegerValidatorRule::getRule()); if (!headers_sent()) { header('HTTP/1.1 ' . $code . ' ' . self::getCodeString($code)); } $this->printException($e, $code); if ($this->shouldLogException($e, $code)) { HarmoniErrorHandler::logException($e); } }
/** * Answer an array of the administrators of this Site. * * @return array of Agent objects * @access protected * @since 2/19/09 */ protected function getAdministrators() { $admins = array(); $agentMgr = Services::getService('Agent'); $roleMgr = SegueRoleManager::instance(); $agentIdsWithRoles = $roleMgr->getAgentsWithRoleAtLeast($roleMgr->getRole('admin'), $this->getSiteNode()->getQualifierId(), true); foreach ($agentIdsWithRoles as $id) { // We ran into a case where roles weren't clearing when an agent // was deleted, log this issue and skip rather than crashing the // choose agent screen. try { $admins[] = $agentMgr->getAgentOrGroup($id); } catch (UnknownIdException $e) { HarmoniErrorHandler::logException($e, 'Segue'); } } return $admins; }
/** * Apply the current version element data to the plugin as the current version. * * @param object SeguePluginsAPI $plugin * @param object DOMElement $element * @return void * @access protected * @since 1/23/08 */ protected function applyCurrentPluginVersion(SeguePluginsAPI $plugin, DOMElement $element) { $versionElement = $this->getSingleElement('./currentVersion/child::node()', $element); $doc = new Harmoni_DOMDocument(); $doc->appendChild($doc->importNode($versionElement, true)); try { $plugin->applyVersion($doc); } catch (InvalidVersionException $e) { HarmoniErrorHandler::logException($e, 'Segue'); printpre($e->getMessage()); } }
/** * Execute the Action * * @param object Harmoni $harmoni * @return mixed * @access public * @since 4/3/06 */ function execute() { $harmoni = Harmoni::instance(); /********************************************************* * Split sites based on their location-category *********************************************************/ try { $rootSiteComponent = SiteDispatcher::getCurrentRootNode(); } catch (UnknownIdException $e) { // For non-existant node exceptions, redirect to the site root. if ($e->getCode() == 289743 && RequestContext::value('node') && RequestContext::value('site')) { $url = SiteDispatcher::quickURL($harmoni->request->getRequestedModule(), $harmoni->request->getRequestedAction(), array('site' => RequestContext::value('site'))); $errorPrinter = SegueErrorPrinter::instance(); $message = "<strong>" . _("The node you requested does not exist or has been deleted. Click %1 to go to the %2.") . "</strong>"; $message = str_replace('%1', "<a href='" . $url . "'>" . _("here") . "</a>", $message); $message = str_replace('%2', "<a href='" . $url . "'>" . _("main page of the site") . "</a>", $message); $errorPrinter->handExceptionWithRedirect($e, 404, $message); exit; } else { if (RequestContext::value('site')) { $slotMgr = SlotManager::instance(); $slot = $slotMgr->getSlotByShortname(RequestContext::value('site')); // Redirect to the new URL if this site has been migrated if ($redirectUrl = $slot->getMigratedRedirectUrl()) { header("HTTP/1.1 301 Moved Permanently"); header('Location: ' . $redirectUrl); exit; } throw $e; } else { throw $e; } } } try { $slot = $rootSiteComponent->getSlot(); // Redirect to the new URL if this site has been migrated if ($redirectUrl = $slot->getMigratedRedirectUrl()) { header("HTTP/1.1 301 Moved Permanently"); header('Location: ' . $redirectUrl); exit; } if (SiteDispatcher::getBaseUrlForSlot($slot) != MYURL) { RequestContext::sendTo(SiteDispatcher::quickUrl()); } else { /********************************************************* * Ensure that the requested node is a member of the site * listed in the URL. *********************************************************/ if (!RequestContext::value('site') || RequestContext::value('site') != $slot->getShortname()) { /********************************************************* * This is added in Segue 2.1.0 for testing that all * Segue-generated links are producing the correct URLs. * This should be removed here and in * segue/config/debug_default.conf.php * after testing is complete. *********************************************************/ if (defined('DEBUG_LOG_WRONG_SITE') && DEBUG_LOG_WRONG_SITE == true && isset($_SERVER['HTTP_REFERER']) && preg_match('#^' . str_replace('.', '\\.', MYURL) . '#', $_SERVER['HTTP_REFERER'])) { HarmoniErrorHandler::logException(new WrongSiteException("Expecting site '" . $slot->getShortname() . "', saw '" . RequestContext::value('site') . "' in the url. Links to wrong sites should not be generated by Segue. If the link on the referrer page was written by Segue (and not a user), submit a bug report. Sending to " . SiteDispatcher::quickUrl())); } RequestContext::sendTo(SiteDispatcher::quickUrl()); } } // Mark the site as viewed Segue_AccessLog::instance()->touch($slot->getShortname()); } catch (UnknownIdException $e) { // No slot for the site.... } $authZ = Services::getService("AuthZ"); $recordManager = Services::getService("RecordManager"); // // Begin Optimizations // // The code below queues up authorizations for all visible nodes, // as well as pre-fetches all of the RecordSets that have data // specific to the visible nodes. $visibleComponents = SiteDispatcher::getSiteDirector()->getVisibleComponents(SiteDispatcher::getCurrentNodeId()); $preCacheIds = array(); foreach ($visibleComponents as $component) { $id = $component->getQualifierId(); $authZ->getIsAuthorizedCache()->queueId($id); $preCacheIds[] = $id->getIdString(); } $recordManager->preCacheRecordsFromRecordSetIDs($preCacheIds); // // End Optimizations // $mainScreen = new Container(new YLayout(), BLOCK, BACKGROUND_BLOCK); $allWrapper = $this->addHeaderControls($mainScreen); $this->addSiteContent($mainScreen); $this->addFooterControls($allWrapper); if (defined('SEGUE_SITE_FOOTER')) { $allWrapper->add(new UnstyledBlock(SEGUE_SITE_FOOTER), "100%", null, CENTER, BOTTOM); } $this->mainScreen = $mainScreen; return $allWrapper; }
/** * Execute this action. * * @return void * @access public * @since 8/5/08 */ public function execute() { try { if (!$this->isAuthorizedToExecute()) { throw new PermissionDeniedException(_("Your are not authorized to delete here.")); } // Traverse the subtree $this->getSiteComponent()->acceptVisitor($this); // print out our info $this->start(); print "\n\t<siteComponent"; if ($this->sections) { print " sections='" . $this->sections . "'"; } if ($this->pages) { print " pages='" . $this->pages . "'"; } if ($this->blocks) { print " blocks='" . $this->blocks . "'"; } if ($this->posts) { print " posts='" . $this->posts . "'"; } if ($this->media) { print " media='" . $this->media . "'"; } print "/>"; $this->end(); } catch (Exception $e) { HarmoniErrorHandler::logException($e); $this->error($e->getMessage(), get_class($e)); } }
/** * Answer out an XML block representing the given asset, its Dublin Core, and * its file records * * @param object Asset $asset * @return void * @access public * @since 1/26/07 */ function getAssetXml($asset) { try { $idManager = Services::getService("Id"); $authZ = Services::getService("AuthZ"); if (!$authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.view"), $asset->getId())) { return ''; } ob_start(); $assetId = $asset->getId(); $repository = $asset->getRepository(); $repositoryId = $repository->getId(); print "\n\t<asset id=\"" . $assetId->getIdString() . "\" repositoryId=\"" . $repositoryId->getIdString() . "\">"; print "\n\t\t<displayName><![CDATA["; print HtmlString::getSafeHtml($asset->getDisplayName()); print "]]></displayName>"; print "\n\t\t<description><![CDATA["; print HtmlString::getSafeHtml($asset->getDescription()); print "]]></description>"; print "\n\t\t<modificationDate><![CDATA["; $date = $asset->getModificationDate(); print $date->asString(); print "]]></modificationDate>"; print "\n\t\t<authorization function='edu.middlebury.authorization.view' />"; if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $asset->getId())) { print "\n\t\t<authorization function='edu.middlebury.authorization.modify' />"; } if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.delete"), $asset->getId())) { print "\n\t\t<authorization function='edu.middlebury.authorization.delete' />"; } /********************************************************* * Files *********************************************************/ $fileRecords = $asset->getRecordsByRecordStructure($idManager->getId('FILE')); while ($fileRecords->hasNext()) { $fileRecord = $fileRecords->next(); $fileRecordId = $fileRecord->getId(); print "\n\t\t<file id=\"" . $fileRecordId->getIdString() . "\""; print " mimetype=\"" . $fileRecord->getPartsByPartStructure($idManager->getId("MIME_TYPE"))->next()->getValue() . "\""; print ">"; $parts = $fileRecord->getPartsByPartStructure($idManager->getId("FILE_NAME")); $part = $parts->next(); print "\n\t\t\t<name><![CDATA[" . HtmlString::getSafeHtml($part->getValue()) . "]]></name>"; $parts = $fileRecord->getPartsByPartStructure($idManager->getId("FILE_SIZE")); $part = $parts->next(); print "\n\t\t\t<size>" . $part->getValue() . "</size>"; print "\n\t\t\t<url><![CDATA["; print RepositoryInputOutputModuleManager::getFileUrlForRecord($asset, $fileRecord); print "]]></url>"; print "\n\t\t\t<thumbnailUrl><![CDATA["; print RepositoryInputOutputModuleManager::getThumbnailUrlForRecord($asset, $fileRecord); print "]]></thumbnailUrl>"; print "\n\t\t</file>"; } /********************************************************* * Dublin Core *********************************************************/ $records = $asset->getRecordsByRecordStructure($idManager->getId('dc')); if ($records->hasNext()) { $record = $records->next(); $recordId = $record->getId(); print "\n\t\t<dublinCore id=\"" . $recordId->getIdString() . "\">"; $parts = $record->getPartsByPartStructure($idManager->getId("dc.title")); if ($parts->hasNext()) { $part = $parts->next(); $valueObj = $part->getValue(); print "\n\t\t\t<title><![CDATA[" . HtmlString::getSafeHtml($valueObj->asString()) . "]]></title>"; } $parts = $record->getPartsByPartStructure($idManager->getId("dc.description")); if ($parts->hasNext()) { $part = $parts->next(); $valueObj = $part->getValue(); print "\n\t\t\t<description><![CDATA[" . HtmlString::getSafeHtml($valueObj->asString()) . "]]></description>"; } $parts = $record->getPartsByPartStructure($idManager->getId("dc.creator")); if ($parts->hasNext()) { $part = $parts->next(); $valueObj = $part->getValue(); print "\n\t\t\t<creator><![CDATA[" . HtmlString::getSafeHtml($valueObj->asString()) . "]]></creator>"; } $parts = $record->getPartsByPartStructure($idManager->getId("dc.source")); if ($parts->hasNext()) { $part = $parts->next(); $valueObj = $part->getValue(); print "\n\t\t\t<source><![CDATA[" . HtmlString::getSafeHtml($valueObj->asString()) . "]]></source>"; } $parts = $record->getPartsByPartStructure($idManager->getId("dc.publisher")); if ($parts->hasNext()) { $part = $parts->next(); $valueObj = $part->getValue(); print "\n\t\t\t<publisher><![CDATA[" . HtmlString::getSafeHtml($valueObj->asString()) . "]]></publisher>"; } $parts = $record->getPartsByPartStructure($idManager->getId("dc.date")); if ($parts->hasNext()) { $part = $parts->next(); $valueObj = $part->getValue(); $date = $valueObj->asDate(); print "\n\t\t\t<date><![CDATA["; print $date->asString(); print "]]></date>"; } print "\n\t\t</dublinCore>"; } print "\n\t\t<permsHtml><![CDATA["; print AuthZPrinter::getAZIcon($asset->getId()); print "]]></permsHtml>"; print "\n\t</asset>"; return ob_get_clean(); } catch (Exception $e) { HarmoniErrorHandler::logException($e, 'Segue'); $this->error($e->getMessage()); } }
/** * Sort an array of courses chronologically * * @param array $courses * @param optional $sortDirection SORT_ASC or SORT_DESC * @return array * @access private * @since 8/22/07 */ private function sortCourses(array $courses, $sortDirection) { if ($sortDirection != SORT_ASC && $sortDirection != SORT_DESC) { throw new Exception("Unknown sort direction, '" . $sortDirection . "', should be one of the constants SORT_ASC or SORT_DESC."); } // Load up our Sorting arrays $years = array(); $semesterOrder = array(); $ids = array(); foreach ($courses as $course) { try { $years[] = $course->getYear(); $semesterOrder[] = $course->getSemesterOrder(); } catch (Exception $e) { HarmoniErrorHandler::logException($e, "Segue"); $years[] = null; $semesterOrder[] = null; } $ids[] = $course->getId()->getIdString(); } array_multisort($years, SORT_NUMERIC, $sortDirection, $semesterOrder, SORT_NUMERIC, $sortDirection, $ids, SORT_STRING, SORT_ASC, $courses); return $courses; }
/** * Answer the media file * * @return object MediaFile * @access public * @since 4/25/07 */ function getMediaFile() { if (!isset($this->_mediaFile)) { try { if ($this->getContent()) { $this->_mediaFile = MediaFile::withIdString($this->getContent()); } else { return null; } } catch (InvalidArgumentException $e) { HarmoniErrorHandler::logException($e, 'Segue'); return null; } catch (UnknownIdException $e) { HarmoniErrorHandler::logException($e, 'Segue'); return null; } } return $this->_mediaFile; }
/** * Create the wizard * * @return object Wizard * @access public * @since 11/14/07 */ public function createWizard() { // Instantiate the wizard, then add our steps. $wizard = SingleStepWizard::withText("<div>\n" . "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n" . "<tr>\n" . "<td align='left' width='50%'>\n" . "[[_cancel]]\n" . "</td>\n" . "<td align='right' width='50%'>\n" . "</td></tr></table>" . "</div>\n" . "<hr/>\n" . "<div>\n" . "[[_steps]]" . "</div>\n"); $wizard->_returnModule = RequestContext::value('returnModule'); $wizard->_returnAction = RequestContext::value('returnAction'); $cancelButton = $wizard->getChild('_cancel'); $cancelButton->setLabel(_("Close")); $step = $wizard->addStep("agents", new WizardStep()); ob_start(); print "\n<h2>" . _("Roles") . "</h2>"; print "\n<p>"; print _("Choose a user or group to edit roles for."); print "\n</p>\n"; $agentMgr = Services::getService("Agent"); $idMgr = Services::getService("Id"); $harmoni = Harmoni::instance(); $roleMgr = SegueRoleManager::instance(); $everyoneId = $idMgr->getId("edu.middlebury.agents.everyone"); $instituteId = $idMgr->getId("edu.middlebury.institute"); $membersId = $this->getSite()->getMembersGroup()->getId(); $agents = array(); $agents[] = $agentMgr->getGroup($everyoneId); $agents[] = $agentMgr->getGroup($instituteId); $agents[] = $agentMgr->getGroup($membersId); $agentIdsWithRoles = $roleMgr->getAgentsWithRoleAtLeast($roleMgr->getRole('reader'), $this->getSiteId(), true); foreach ($agentIdsWithRoles as $id) { if (!$id->isEqual($everyoneId) && !$id->isEqual($instituteId) && !$id->isEqual($membersId)) { // We ran into a case where roles weren't clearing when an agent // was deleted, log this issue and skip rather than crashing the // choose agent screen. try { $agents[] = $agentMgr->getAgentOrGroup($id); } catch (UnknownIdException $e) { HarmoniErrorHandler::logException($e, 'Segue'); } } } if (count($agents)) { print "\n<table width='100%' class='search_results' cellspacing='0'>"; $i = 0; foreach ($agents as $agent) { print "\n\t<tr class='search_result_item'>"; print "\n\t\t<td class='color{$i}'>"; print "\n\t\t\t<a href='#' onclick=\"AgentInfoPanel.run('" . addslashes($agent->getId()->getIdString()) . "', '" . addslashes($agent->getDisplayName()) . "', this); return false;\">"; print $agent->getDisplayName(); print "</a>"; // print out site members if ($agent->getId()->isEqual($membersId)) { $harmoni->request->forget('returnAction'); $harmoni->request->forget('returnModule'); $harmoni->request->forget('agent'); $url = SiteDispatcher::quickURL('agent', 'modify_members'); $harmoni->request->passthrough('returnAction'); $harmoni->request->passthrough('returnModule'); $harmoni->request->passthrough('agent'); print "\n\t\t\t <button onclick='window.location = \"{$url}\".urlDecodeAmpersands(); return false;'>" . _("Add/Remove Members") . "</button>"; print " (" . Help::link('Site-Members') . ")"; print "\n<br/>"; print "\n<span style='font-size: smaller'>"; print _("This is a custom group of users that are associated with this site. Users and groups can manually be made site-members or users can self-register using the 'Join Site' plugin if it is enabled."); print "</span>"; $membersGroup = $this->getSite()->getMembersGroup(); $subGroups = $membersGroup->getGroups(true); print "\n<table width='100%' class='search_results' cellspacing='0'>"; while ($subGroups->hasNext()) { print "\n\t<tr class='search_result_item'>"; print "\n\t\t<td>"; print " " . $subGroups->next()->getDisplayName(); print "\n\t\t</td></tr>"; } $members = $membersGroup->getMembers(false); while ($members->hasNext()) { print "\n\t<tr class='search_result_item'>"; print "\n\t\t<td>"; print " " . $members->next()->getDisplayName(); print "\n\t\t</td></tr>"; } print "\n</table><br/>"; } print "\n\t\t</td>"; print "\n\t\t<td valign='top' class='color{$i}' style='text-align: right; white-space: nowrap;'>"; $url = SiteDispatcher::quickURL('roles', 'modify', array('node' => SiteDispatcher::getCurrentNodeId(), 'agent' => $agent->getId()->getIdString())); print "\n\t\t\t<button onclick='window.location = \"{$url}\".urlDecodeAmpersands(); return false;'>" . _("Modify Roles »") . "</button>"; print "\n\t\t</td>"; print "\n\t</tr>"; $i = intval(!$i); } print "\n</table>"; } $property = $step->addComponent("search", new WSearchField()); $property->setSearchSource(new AgentSearchSource()); print "\n<div style='margin-top: 20px; border-top: 1px solid; padding: 5px;'>"; print "\n<h3>" . _("Assign roles to other users/groups") . "</h3>"; print _("Search for other users/groups. Once found you will be able to assign roles to these other users/groups. To assign roles to students in a class, type in the course code (e.g. span0101a-f08)") . "<br/><br/>"; print _("User/group name: ") . " [[search]]"; print "</div>"; $step->setContent(ob_get_clean()); return $wizard; }
/** * Create a new file asset * * @return object Asset * @access public * @since 1/26/07 */ function createFileAsset() { $contentAsset = $this->getContentAsset(); $asset = MediaAsset::createForContentAsset($contentAsset); if (!($displayName = RequestContext::value('displayName'))) { $displayName = $_FILES['media_file']['name']; } if (!($description = RequestContext::value('description'))) { $description = ''; } // Check the quota $slot = $this->getSlot(); if ($this->getQuotaUsed() + $_FILES['media_file']['size'] > $slot->getMediaQuota()->value()) { throw new Exception("Cannot add File, {$displayName}, quota of " . $slot->getMediaQuota()->asString() . " exceeded."); } // Create the asset $asset->updateDisplayName($displayName); $asset->updateDescription($description); try { $this->addFileRecord($asset); } catch (Exception $e) { HarmoniErrorHandler::logException($e, 'Segue'); $this->nonFatalError($e->getMessage(), get_class($e)); } try { $this->addDublinCoreRecord($asset); } catch (Exception $e) { HarmoniErrorHandler::logException($e, 'Segue'); $this->nonFatalError($e->getMessage(), get_class($e)); } // Log the success or 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", "Event_Notice", "Normal events."); $item = new AgentNodeEntryItem("Media Library", "File uploaded with id '" . $asset->getId()->getIdString() . "' and filename '" . $_FILES['media_file']['name'] . "'"); $item->addNodeId($asset->getId()); $item->addNodeId($contentAsset->getId()); $idManager = Services::getService("Id"); $director = AssetSiteDirector::forAsset($contentAsset); $site = $director->getRootSiteComponent($contentAsset->getId()->getIdString()); $item->addNodeId($idManager->getId($site->getId())); $log->appendLogWithTypes($item, $formatType, $priorityType); } return $asset; }
/** * Visit a menu organizer and return the menu GUI component that corresponds * to it. * * @param object MenuOrganizerSiteComponent * @return object Component * @access public * @since 4/3/06 */ public function visitMenuOrganizer(MenuOrganizerSiteComponent $organizer) { // Choose layout direction based on number of rows if ($this->_menuNestingLevel) { $layout = new YLayout(); } else { if ($organizer->getDirection() == "Left-Right/Top-Bottom") { $layout = new XLayout(); } else { if ($organizer->getDirection() == "Right-Left/Top-Bottom") { $layout = new XLayout(); $layout->setRenderDirection("Right-Left/Top-Bottom"); } else { $layout = new YLayout(); } } } if ($this->_menuNestingLevel) { $guiContainer = new SubMenu($layout, $this->_menuNestingLevel); } else { switch ($organizer->getDisplayType()) { case 'Menu_Left': $menuIndex = MENU_LEFT; break; case 'Menu_Right': $menuIndex = MENU_RIGHT; break; case 'Menu_Top': $menuIndex = MENU_TOP; break; case 'Menu_Bottom': $menuIndex = MENU_BOTTOM; break; default: throw new OperationFailedException("Unknown Menu DisplayType, '" . $organizer->getDisplayType() . "'."); } $guiContainer = new Menu($layout, $menuIndex); } $hasChildComponents = false; $i = 0; foreach ($organizer->getSortedSubcomponents() as $child) { try { ArgumentValidator::validate($child, ExtendsValidatorRule::getRule('SiteComponent')); } catch (Exception $e) { HarmoniErrorHandler::logException($e); continue; } $childGuiComponents = $child->acceptVisitor($this, true); if ($childGuiComponents === false || is_array($childGuiComponents) && !count($childGuiComponents)) { // do nothing } else { if (is_array($childGuiComponents)) { $hasChildComponents = true; // wrap the menu item if needed $this->addFlowChildWrapper($organizer, $i, $childGuiComponents[0]); // Add each of the the menuItems/submenus foreach (array_keys($childGuiComponents) as $key) { $guiContainer->add($childGuiComponents[$key]); } } else { $hasChildComponents = true; $guiContainer->add($this->addFlowChildWrapper($organizer, $i, $childGuiComponents)); } } $i++; } // Add a placeholder if no content exists so that the screen doesn't stretch if (!$hasChildComponents) { $noticeComponent = $this->getMenuTargetPlaceholder($organizer); if (isset($this->_emptyCellContainers[$organizer->getTargetId()])) { $this->_emptyCellContainers[$organizer->getTargetId()]->insertAtPlaceholder($this->_emptyCellPlaceholders[$organizer->getTargetId()], $noticeComponent, null, null, null, TOP); unset($this->_emptyCellContainers[$organizer->getTargetId()], $this->_emptyCellPlaceholders[$organizer->getTargetId()]); } else { $this->_missingTargets[$organizer->getTargetId()] = $noticeComponent; $this->_missingTargetWidths[$organizer->getTargetId()] = null; } } return $guiContainer; }