/** * Answer true if this site should be included * * @param object Asset $asset * @return boolean * @access protected * @since 4/1/08 */ protected function includeSite(Asset $asset) { $matches = false; if ($this->match($asset->getDisplayName())) { $matches = true; } else { if ($this->match($asset->getDescription())) { $matches = true; } } if (!$matches) { $slotMgr = SlotManager::instance(); try { $slot = $slotMgr->getSlotBySiteId($asset->getId()); } catch (UnknownIdException $e) { } if (isset($slot) && $this->match($slot->getShortname())) { $matches = true; } } if (!$matches) { return false; } $authZ = Services::getService("AuthZ"); $idManager = Services::getService("Id"); // Since View AZs now cascade up, we don't need to check isAuthorizedBelow() if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.view"), $asset->getId())) { return TRUE; } else { return FALSE; } }
/** * * * @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; }
/** * 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) { } }
/** * Recursively copies an asset and its children to a new parent. * * @access private */ function _copyAsset(Asset $asset, Id $newParentId) { // Create the new asset $newAsset = $this->createAsset($asset->getDisplayName(), $asset->getDescription(), $asset->getAssetType()); // Move the new asset to the proper parent if it // is not being copied to the dr root. if (!$newParentId->isEqual($this->getId())) { $newParent = $this->getAsset($newParentId); $newParent->addAsset($newAsset->getId()); } // Copy its data // @todo // Copy the children $children = $asset->getAssets(); while ($children->hasNext()) { $childAsset = $children->next(); $this->_copyAsset($childAsset, $newAsset->getId()); } // Return its Id return $newAsset->getId(); }
/** * Function for printing the asset block of the slideshow XML file * * @param object Asset $asset * @param optional object Id $recordId * @return void * @access public * @since 10/14/05 */ function printAssetXML(Asset $asset, Id $recordId = null) { $assetId = $asset->getId(); $repository = $asset->getRepository(); $repositoryId = $repository->getId(); $idManager = Services::getService("Id"); // ------------------------------------------ print "\t<slide>\n"; // Title print "\t\t<title><![CDATA["; print htmlspecialchars($asset->getDisplayName(), ENT_COMPAT, 'UTF-8'); print "]]></title>\n"; // Caption print "\t\t<caption><![CDATA["; $this->printAsset($asset); print "]]></caption>\n"; // Text-Position print "\t\t<text-position>"; print "right"; print "</text-position>\n"; $fileRecords = new MultiIteratorIterator(); $fileRecords->addIterator($asset->getRecordsByRecordStructure($idManager->getId("FILE"))); $fileRecords->addIterator($asset->getRecordsByRecordStructure($idManager->getId("REMOTE_FILE"))); /********************************************************* * Files *********************************************************/ $harmoni = Harmoni::instance(); $harmoni->request->startNamespace("polyphony-repository"); $imgProcessor = Services::getService("ImageProcessor"); while ($fileRecords->hasNext()) { $this->printFileRecord($fileRecords->next(), $repositoryId, $assetId); } $harmoni->request->endNamespace(); print "\t</slide>\n"; }