/** * Answer the displayName * * @return string * @access public * @since 3/31/06 */ function getDisplayName() { $child = $this->_element->firstChild; while ($child) { if ($child->nodeName == 'displayName') { return HtmlString::getSafeHtml($child->getText()); } $child = $child->nextSibling; } return _('Default Name'); }
/** * Update the dublin core record with info from the form. * * @param object Asset $asset * @param object Record $record * @return void * @access public * @since 1/30/07 */ function updateDublinCoreRecord($asset, $record) { $idManager = Services::getService("Id"); $value = String::fromString(HtmlString::getSafeHtml($asset->getDisplayName())); $id = $idManager->getId("dc.title"); $this->updateSingleValuedPart($record, $id, $value); $value = String::fromString(HtmlString::getSafeHtml($asset->getDescription())); $id = $idManager->getId("dc.description"); $this->updateSingleValuedPart($record, $id, $value); $value = String::fromString(HtmlString::getSafeHtml(RequestContext::value('creator'))); $id = $idManager->getId("dc.creator"); $this->updateSingleValuedPart($record, $id, $value); $value = String::fromString(HtmlString::getSafeHtml(RequestContext::value('source'))); $id = $idManager->getId("dc.source"); $this->updateSingleValuedPart($record, $id, $value); $value = String::fromString(HtmlString::getSafeHtml(RequestContext::value('publisher'))); $id = $idManager->getId("dc.publisher"); $this->updateSingleValuedPart($record, $id, $value); $value = DateAndTime::fromString(RequestContext::value('date')); $id = $idManager->getId("dc.date"); $this->updateSingleValuedPart($record, $id, $value); }
/** * Add HTML text to the bactrace, usefull for storing source URLs, etc * * @param string $additionalText * @return void * @access public * @since 8/1/06 */ function addTextToBactrace($additionalText) { $this->_additionalBactraceText .= HtmlString::getSafeHtml($additionalText); }
/** * Update the subject * * @param string $subject * @return void * @access public * @since 7/11/07 */ function updateSubject($subject) { // Check Authorizations $authZ = Services::getService('AuthZ'); if (!$this->canModify()) { throw new PermissionDeniedException("You are not authorized to change this comment."); } if ($subject) { $this->_asset->updateDisplayName(HtmlString::getSafeHtml($subject)); } else { $this->_asset->updateDisplayName(_("(untitled)")); } CommentManager::logMessage('Comment Subject Updated', CommentManager::getCommentParentAsset($this), array($this->getId())); }
/** * Answer the persisted 'title' value of this plugin. * * @return string * @access public * @since 1/13/06 */ public final function getTitle() { return HtmlString::getSafeHtml($this->_asset->getDisplayName()); }
/** * Process the changes and build the output * * @return void * @access public * @since 1/26/07 */ public function buildContent() { try { ob_start(); $idManager = Services::getService("Id"); $fileAsset = $this->getFileAsset(); // Update the files $oldFilename = null; $newFilename = null; foreach (array_keys($_FILES) as $fieldName) { if (preg_match('/^file___(.+)$/', $fieldName, $matches)) { $fileRecord = $fileAsset->getRecord($idManager->getId($matches[1])); $filenameParts = $fileRecord->getPartsByPartStructure($idManager->getId("FILE_NAME")); $oldFilename = $filenameParts->next()->getValue(); $newFilename = $_FILES[$fieldName]['name']; $this->updateFileRecord($fileAsset, $fileRecord, $fieldName); } else { if ($fieldName == 'media_file') { $oldFilename = null; $newFilename = $_FILES[$fieldName]['name']; $this->addFileRecord($fileAsset); } } } // Update the displayname // // If the displayname in the form is the old filename, update it to the // new filename if (RequestContext::value('displayName') && RequestContext::value('displayName') == $oldFilename && $newFilename) { $fileAsset->updateDisplayName($newFilename); } else { if (RequestContext::value('displayName') && RequestContext::value('displayName') != $fileAsset->getDisplayName()) { $fileAsset->updateDisplayName(HtmlString::getSafeHtml(RequestContext::value('displayName'))); } } // Update the description if needed. if (!RequestContext::value('description')) { $fileAsset->updateDescription(''); } else { if (RequestContext::value('description') != $fileAsset->getDescription()) { $fileAsset->updateDescription(HtmlString::getSafeHtml(RequestContext::value('description'))); } } // Update the other metadata. $dublinCoreRecords = $fileAsset->getRecordsByRecordStructure($idManager->getId('dc')); if ($dublinCoreRecords->hasNext()) { $this->updateDublinCoreRecord($fileAsset, $dublinCoreRecords->next()); } else { $this->addDublinCoreRecord($fileAsset); } // 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."); $message = "File updated with id '" . $fileAsset->getId()->getIdString() . "'"; if (isset($newFilename)) { $message .= " and new filename '" . $newFilename . "'"; } $item = new AgentNodeEntryItem("Media Library", $message); $item->addNodeId($fileAsset->getId()); $item->addNodeId($this->getContentAsset()->getId()); $contentAsset = $this->getContentAsset(); $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); } // printpre($_FILES); if ($error = ob_get_clean()) { $this->error($error); } $this->start(); // print "\n<![CDATA["; // print_r($_REQUEST); // print_r($_FILES); // print "\n]]>"; print $this->getAssetXml($fileAsset); print $this->getQuota(); $this->end(); } catch (Exception $e) { $this->error($e->getMessage(), get_class($e)); } }
/** * * * @param <##> * @return <##> * @access public * @since 1/18/06 */ public function printSiteShort(Asset $asset, $action, $num, Slot $otherSlot = null) { $harmoni = Harmoni::instance(); $assetId = $asset->getId(); $authZ = Services::getService('AuthZ'); $idMgr = Services::getService('Id'); if (!$authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.view'), $assetId) && !$otherSlot->isUserOwner()) { return new UnstyledBlock('', BLANK); } $container = new Container(new YLayout(), BLOCK, STANDARD_BLOCK); $fillContainerSC = new StyleCollection("*.fillcontainer", "fillcontainer", "Fill Container", "Elements with this style will fill their container."); $fillContainerSC->addSP(new MinHeightSP("88%")); // $fillContainerSC->addSP(new WidthSP("100%")); // $fillContainerSC->addSP(new BorderSP("3px", "solid", "#F00")); $container->addStyle($fillContainerSC); $centered = new StyleCollection("*.centered", "centered", "Centered", "Centered Text"); $centered->addSP(new TextAlignSP("center")); // Use the alias instead of the Id if it is available. $viewUrl = SiteDispatcher::getSitesUrlForSiteId($assetId->getIdString()); $slotManager = SlotManager::instance(); try { $sitesTrueSlot = $slotManager->getSlotBySiteId($assetId); } catch (Exception $e) { } // Print out the content ob_start(); print "\n\t<div class='portal_list_slotname'>"; if (isset($sitesTrueSlot)) { if (is_null($otherSlot) || $sitesTrueSlot->getShortname() == $otherSlot->getShortname()) { print $sitesTrueSlot->getShortname(); } else { print $otherSlot->getShortname(); $targets = array(); $target = $otherSlot->getAliasTarget(); while ($target) { $targets[] = $target->getShortname(); if ($target->isAlias()) { $target = $target->getAliasTarget(); } else { $target = null; } } print "\n<br/>"; print str_replace('%1', implode(' » ', $targets), _("(an alias of %1)")); // Add Alias info. // if ($otherSlot->isAlias()) { // ob_start(); // // print _("This slot is an alias of ").$slot->getAliasTarget()->getShortname(); // // $container->add(new UnstyledBlock(ob_get_clean()), "100%", null, LEFT, TOP); // } } } else { print _("ID#") . ": " . $assetId->getIdString(); } print "\n\t</div>"; print "\n\t<div class='portal_list_site_title'>"; if ($authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.view'), $assetId)) { print "\n\t\t<a href='" . $viewUrl . "'>"; print "\n\t\t\t<strong>" . HtmlString::getSafeHtml($asset->getDisplayName()) . "</strong>"; print "\n\t\t</a>"; print "\n\t\t<br/>"; print "\n\t\t<a href='" . $viewUrl . "' style='font-size: smaller;'>"; print "\n\t\t\t" . $viewUrl; print "\n\t\t</a>"; } print "\n\t</div>"; print "\n\t<div class='portal_list_controls'>\n\t\t"; $controls = array(); if ($authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.view'), $assetId)) { $controls[] = "<a href='" . $viewUrl . "'>" . _("view") . "</a>"; } // Hide all edit links if not authenticated to prevent web spiders from traversing them if ($this->isAuthenticated) { // While it is more correct to check modify permission permission, doing // so forces us to check AZs on the entire site until finding a node with // authorization or running out of nodes to check. Since edit-mode actions // devolve into view-mode if no authorization is had by the user, just // show the links all the time to cut page loads from 4-6 seconds to // less than 1 second. if ($authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.view'), $assetId)) { $controls[] = "<a href='" . SiteDispatcher::quickURL($action->getUiModule(), 'editview', array('node' => $assetId->getIdString())) . "'>" . _("edit") . "</a>"; } // if ($action->getUiModule() == 'ui2') { // $controls[] = "<a href='".SiteDispatcher::quickURL($action->getUiModule(), 'arrangeview', array('node' => $assetId->getIdString()))."'>"._("arrange")."</a>"; // } // add link to tracking if ($authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.view'), $assetId)) { $trackUrl = $harmoni->request->quickURL("participation", "actions", array('node' => $assetId->getIdString())); ob_start(); print " <a target='_blank' href='" . $trackUrl . "'"; print ' onclick="'; print "var url = '" . $trackUrl . "'; "; print "window.open(url, 'site_map', 'width=600,height=600,resizable=yes,scrollbars=yes'); "; print "return false;"; print '"'; print ">" . _("track") . "</a>"; $controls[] = ob_get_clean(); } if (!is_null($otherSlot) && $otherSlot->isAlias() && $otherSlot->isUserOwner()) { $controls[] = "<a href='" . $harmoni->request->quickURL('slots', 'remove_alias', array('slot' => $otherSlot->getShortname())) . "' onclick=\"if (!confirm('" . str_replace("%1", $otherSlot->getShortname(), str_replace("%2", $otherSlot->getAliasTarget()->getShortname(), _("Are you sure that you want \\'%1\\' to no longer be an alias of \\'%2\\'?"))) . "')) { return false; }\">" . _("remove alias") . "</a>"; } else { if ($authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.delete'), $assetId)) { $controls[] = "<a href='" . $harmoni->request->quickURL($action->getUiModule(), 'deleteComponent', array('node' => $assetId->getIdString())) . "' onclick=\"if (!confirm('" . _("Are you sure that you want to permenantly delete this site?") . "')) { return false; }\">" . _("delete") . "</a>"; } } // Add a control to select this site for copying. This should probably // have its own authorization, but we'll use add_children/modify for now. if ($authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.modify'), $assetId)) { if (isset($sitesTrueSlot) && (is_null($otherSlot) || $sitesTrueSlot->getShortname() == $otherSlot->getShortname())) { $controls[] = Segue_Selection::instance()->getAddLink(SiteDispatcher::getSiteDirector()->getSiteComponentFromAsset($asset)); } } } print implode("\n\t\t | ", $controls); print "\n\t</div>"; if ($authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.view'), $assetId)) { $description = HtmlString::withValue($asset->getDescription()); $description->trim(25); print "\n\t<div class='portal_list_site_description'>" . $description->asString() . "</div>"; } print "\n\t<div style='clear: both;'></div>"; print $this->getExportControls($assetId, $otherSlot, $sitesTrueSlot); $component = new UnstyledBlock(ob_get_clean()); $container->add($component, "100%", null, LEFT, TOP); return $container; }
/** * Load the DC values for this asset * * @return void * @access private * @since 4/27/07 */ function _loadDC() { if (!isset($this->_dcValues)) { $this->_dcValues = array('dc.title' => array(), 'dc.creator' => array(), 'dc.contributor' => array(), 'dc.description' => array(), 'dc.subject' => array(), 'dc.format' => array(), 'dc.publisher' => array(), 'dc.source' => array(), 'dc.rights' => array()); $idManager = Services::getService("Id"); $dcRecords = $this->_asset->getRecordsByRecordStructure($idManager->getId("dc")); if ($dcRecords->hasNext()) { $record = $dcRecords->next(); foreach (array_keys($this->_dcValues) as $partIdString) { $parts = $record->getPartsByPartStructure($idManager->getId($partIdString)); while ($parts->hasNext()) { $part = $parts->next(); $value = $part->getValue(); $this->_dcValues[$partIdString][] = HtmlString::getSafeHtml($value->asString()); } } // Add on date objects $this->_dcValues['dc.date'] = array(); $partIdString = 'dc.date'; $parts = $record->getPartsByPartStructure($idManager->getId($partIdString)); while ($parts->hasNext()) { $part = $parts->next(); $this->_dcValues[$partIdString][] = $part->getValue(); } } else { $this->_dcValues['dc.date'] = array(); } } }
/** * Log an error or exception with the Logging OSID implemenation * * @param string $type The type of error or exception that occurred * @param string $message A message. * @param array $backtrace * @param optional string $logName The name of the log to write to. * @param optional string $category A category for the error or exception. * @return void * @access public * @since 10/10/07 * @static */ public static function logMessage($type, $message, array $backtrace, $logName = 'Harmoni', $category = null) { /********************************************************* * Log the error in the default system log if the log_errors * directive is on. *********************************************************/ if (ini_get('log_errors') === true || ini_get('log_errors') === 'On' || ini_get('log_errors') === '1') { error_log("PHP " . $type . ": " . strip_tags($message)); } /********************************************************* * Log the error using the Logging OSID if available. *********************************************************/ // If we have an error in the error handler or the logging system, // don't infinitely loop trying to log the error of the error.... $testBacktrace = debug_backtrace(); for ($i = 1; $i < count($testBacktrace); $i++) { if (isset($testBacktrace[$i]['function']) && strtolower($testBacktrace[$i]['function']) == 'logMessage') { return; } } if (class_exists('Services') && Services::serviceRunning("Logging")) { $logName = preg_replace('/[^a-z0-9_\\s-.]/i', '', $logName); try { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting($logName); $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", strip_tags($type), "Events involving critical system errors."); $item = new AgentNodeEntryItem(strip_tags($category), HtmlString::getSafeHtml($message)); $item->setBacktrace($backtrace); if (isset($_SERVER['REQUEST_URI'])) { $item->addTextToBactrace("\n<div><strong>REQUEST_URI: </strong>" . $_SERVER['REQUEST_URI'] . "</div>"); } if (isset($_SERVER['HTTP_REFERER'])) { $item->addTextToBactrace("\n<div><strong>HTTP_REFERER: </strong>" . htmlspecialchars($_SERVER['HTTP_REFERER']) . "</div>"); } if (isset($_SERVER['HTTP_USER_AGENT'])) { $item->addTextToBactrace("\n<div><strong>HTTP_USER_AGENT: </strong><pre>" . htmlspecialchars(print_r($_SERVER['HTTP_USER_AGENT'], true)) . "</pre></div>"); } // Log IP addresses of unauthenticated users for help in tracing // anonymous intrusion attempts. Currently not logging IP addresses // of logged-in users for privacy, even though visitor accounts // mean that logged-in users may be just as dangerous as anonymous ones. if (Services::serviceRunning("AuthN")) { $authN = Services::getService("AuthN"); if (!$authN->isUserAuthenticatedWithAnyType()) { if (isset($_SERVER['REMOTE_ADDR'])) { $item->addTextToBactrace("\n<div><strong>REMOTE_ADDR: </strong><pre>" . htmlspecialchars($_SERVER['REMOTE_ADDR']) . "</pre></div>"); } if (isset($_SERVER['REMOTE_HOST'])) { $item->addTextToBactrace("\n<div><strong>REMOTE_HOST: </strong><pre>" . htmlspecialchars($_SERVER['REMOTE_HOST']) . "</pre></div>"); } } } $item->addTextToBactrace("\n<div><strong>GET: </strong><pre>" . htmlspecialchars(print_r(self::stripPrivate($_GET), true)) . "</pre></div>"); $item->addTextToBactrace("\n<div><strong>POST: </strong><pre>" . htmlspecialchars(print_r(self::stripPrivate($_POST), true)) . "</pre></div>"); $log->appendLogWithTypes($item, $formatType, $priorityType); } catch (Exception $e) { // Just continue if we can't log the exception. } } }
/** * Print out a custom error page for an exception with the HTTP status code * specified * * @param object Exception $e * @param int $code * @return void * @access private * @since 2/21/08 */ private function printException(Exception $e, $code) { // Debugging mode for development, rethrow the exception if (defined('DISPLAY_ERROR_BACKTRACE') && DISPLAY_ERROR_BACKTRACE) { throw $e; } else { $message = HtmlString::getSafeHtml($e->getMessage()); $codeString = self::getCodeString($code); $errorString = _('Error'); if ($this->shouldLogException($e, $code)) { $logMessage = _('This error has been logged.'); } else { $logMessage = ''; } print <<<END <html>\t \t<head> \t\t<title>{$code} {$codeString}</title> \t\t<style> \t\t\tbody { \t\t\t\tbackground-color: #FFF8C6; \t\t\t\tfont-family: Verdana, sans-serif; \t\t\t} \t\t\t \t\t\t.header { \t\t\t\theight: 65px; \t\t\t\tborder-bottom: 1px dotted #333; \t\t\t} \t\t\t.concerto_name { \t\t\t\tfont-family: Tahoma, sans-serif; \t\t\t\tfont-variant: small-caps; \t\t\t\tfont-weight: bold; \t\t\t\tfont-size: 60px; \t\t\t\tcolor: #333333; \t\t\t\t \t\t\t\tfloat: left; \t\t\t} \t\t\t \t\t\t.error { \t\t\t\tfont-size: 20px; \t\t\t\tfont-weight: bold; \t\t\t\tfloat: left; \t\t\t\tmargin-top: 40px; \t\t\t\tmargin-left: 20px; \t\t\t} \t\t\t \t\t\tblockquote { \t\t\t\tmargin-bottom: 50px; \t\t\t\tclear: both; \t\t\t} \t\t</style> \t</head> \t<body> \t\t<div class='header'> \t\t\t<div class='concerto_name'>Concerto</div> \t\t\t<div class='error'>{$errorString}</div> \t\t</div> \t\t<blockquote> \t\t\t<h1>{$codeString}</h1> \t\t\t<p>{$message}</p> \t\t</blockquote> \t\t<p>{$logMessage}</p> \t</body> </html> END; } }
/** * Add a Dublin Core Record to a media Asset. * * @param object Asset $asset * @param object DOMElement $element * @return void * @access protected * @since 1/24/08 */ protected function addDublinCoreRecord(Asset $asset, DOMElement $element) { $idManager = Services::getService("Id"); $record = $asset->createRecord($idManager->getId("dc")); $element->setAttribute('new_id', $record->getId()->getIdString()); try { $value = String::fromString(HtmlString::getSafeHtml($asset->getDisplayName())); $id = $idManager->getId("dc.title"); $this->updateSingleValuedPart($record, $id, $value); } catch (MissingNodeException $e) { } try { $value = String::fromString(HtmlString::getSafeHtml($asset->getDescription())); $id = $idManager->getId("dc.description"); $this->updateSingleValuedPart($record, $id, $value); } catch (MissingNodeException $e) { } try { $valueElement = $this->getSingleElement('./creator', $element); if ($valueElement) { $value = String::fromString(HtmlString::getSafeHtml($this->getStringValue($valueElement))); $id = $idManager->getId("dc.creator"); $this->updateSingleValuedPart($record, $id, $value); } } catch (MissingNodeException $e) { } try { $valueElement = $this->getSingleElement('./source', $element); if ($valueElement) { $value = String::fromString(HtmlString::getSafeHtml($this->getStringValue($valueElement))); $id = $idManager->getId("dc.source"); $this->updateSingleValuedPart($record, $id, $value); } } catch (MissingNodeException $e) { } try { $valueElement = $this->getSingleElement('./publisher', $element); if ($valueElement) { $value = String::fromString(HtmlString::getSafeHtml($this->getStringValue($valueElement))); $id = $idManager->getId("dc.publisher"); $this->updateSingleValuedPart($record, $id, $value); } } catch (MissingNodeException $e) { } try { $valueElement = $this->getSingleElement('./date', $element); if ($valueElement) { $value = DateAndTime::fromString($this->getStringValue($valueElement)); $id = $idManager->getId("dc.date"); $this->updateSingleValuedPart($record, $id, $value); } } catch (MissingNodeException $e) { } }
/** * Print info about a Slot * * @param object Slot $slot * @return void * @access private * @since 3/13/08 */ private function printSlotInfo(Slot $slot) { $harmoni = Harmoni::instance(); if ($slot->siteExists()) { $asset = $slot->getSiteAsset(); try { $authZ = Services::getService('AuthZ'); $idMgr = Services::getService('Id'); if (!$authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.view'), $slot->getSiteId())) { print "\n<div class='site_info'>"; print "\n\t<div class='site_description'>"; print _("A site has been created for this placeholder, but you do not have authorization to view it."); print "</div>"; print "\n</div>"; return; } } catch (UnknownIdException $e) { } $viewUrl = SiteDispatcher::quickURL('view', 'html', array('site' => $slot->getShortname())); print "\n<div class='site_info'>"; print "\n\t<div class='site_title'>"; print "\n\t\t<a href='" . $viewUrl . "' target='_blank'>"; print "\n\t\t\t<strong>" . HtmlString::getSafeHtml($asset->getDisplayName()) . "</strong>"; print "\n\t\t</a>"; print "\n\t</div>"; $description = HtmlString::withValue($asset->getDescription()); $description->trim(25); print "\n\t<div class='site_description'>" . $description->asString() . "</div>"; print "\n</div>"; } print "\n\t<div class='slotname'>"; print $slot->getShortname(); print "\n\t</div>"; }
/** * Update the description * * @param string $description * @return void * @access public * @since 3/31/06 */ function updateDescription($description) { $this->_asset->updateDescription(HtmlString::getSafeHtml($description)); }
/** * Get the name of this Agent. * * @return string * * @throws object AgentException An exception with one of the * following messages defined in org.osid.agent.AgentException may * be thrown: {@link * org.osid.agent.AgentException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.agent.AgentException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.agent.AgentException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED} * * @access public */ function getDisplayName() { return HtmlString::getSafeHtml($this->_node->getDisplayName()); }