/** * Print out a slot * * @param object $slot * @return object Component * @access public * @since 12/4/07 */ public function getSlotComponent(Slot $slot) { $harmoni = Harmoni::instance(); ob_start(); print "\n\t<tr>"; print "\n\t\t<td>"; if ($slot->siteExists()) { print "\n\t\t\t<a href='"; print $harmoni->request->quickURL('ui1', 'view', array('site' => $slot->getShortname())); print "' target='_blank'>" . $slot->getShortname() . "</a>"; } else { print $slot->getShortname(); } print "</td>"; print "\n\t\t<td>" . $slot->getType() . "</td>"; print "\n\t\t<td>" . $slot->getLocationCategory() . "</td>"; // Media Quota print "\n\t\t<td>"; if ($slot->usesDefaultMediaQuota()) { $quota = SlotAbstract::getDefaultMediaQuota()->asString(); print "<a href='#' title='{$quota}' onclick='alert(\"{$quota}\"); return false;'>"; print _("Default"); print "</a>"; } else { print $slot->getMediaQuota()->asString(); } print "</td>"; print "\n\t\t<td style='text-align: center'>" . ($slot->siteExists() ? "yes" : '') . "</td>"; print "\n\t\t<td>"; $owners = $slot->getOwners(); $ownerStrings = array(); $agentMgr = Services::getService('Agent'); foreach ($owners as $ownerId) { $ownerStrings[] = $agentMgr->getAgent($ownerId)->getDisplayName(); } print implode("; ", $ownerStrings); print "</td>"; $harmoni->request->passthrough('starting_number'); $harmoni->request->startNamespace("slots"); print "\n\t\t<td style='white-space: nowrap;'>"; print "\n\t\t\t<a href='"; print $harmoni->request->quickURL('slots', 'edit', array('name' => $slot->getShortname())); print "'>" . _("edit") . "</a>"; if (!$slot->siteExists()) { $harmoni->request->startNamespace(null); print "\n\t\t\t| <a href='"; print $harmoni->request->quickURL('dataport', 'import', array('site' => $slot->getShortname())); print "'>" . _("import") . "</a>"; $harmoni->request->endNamespace(); print "\n\t\t\t| <a href='"; print $harmoni->request->quickURL('slots', 'delete', array('name' => $slot->getShortname())); print "' onclick=\""; print "return confirm('" . _('Are you sure you want to delete this placeholder?') . "');"; print "\">" . _("delete") . "</a>"; } else { $harmoni->request->startNamespace(null); print "\n\t\t\t| <a href='"; print $harmoni->request->quickURL('dataport', 'export', array('node' => $slot->getSiteId()->getIdString())); print "'>" . _("export") . "</a>"; $harmoni->request->endNamespace(); } print "\n\t\t</td>"; $harmoni->request->endNamespace(); $harmoni->request->forget('starting_number'); print "\n\t</tr>"; return ob_get_clean(); }
/** * Convert a slot to another type. The object passed on will no longer be valid. * * @param object Slot $slot * @param string $type * @return object Slot * @access public * @since 1/4/08 */ public function convertSlotToType(Slot $slot, $type) { if (!isset($this->slotTypes[$type])) { throw new Exception("Unknown SlotType, '{$type}'. Should be one of (" . implode(", ", array_keys($this->slotTypes)) . ")."); } $shortname = $slot->getShortname(); $dbc = Services::getService("DatabaseManager"); try { // Add a row to the slot table $query = new InsertQuery(); $query->setTable('segue_slot'); $query->addValue('shortname', $shortname); if ($slot->getSiteId()) { $query->addValue('site_id', $slot->getSiteId()->getIdString()); } if ($slot->isAlias()) { $query->addValue('alias_target', $slot->getAliasTarget()->getShortname()); } $query->addValue('type', $type); $query->addValue('location_category', $slot->getLocationCategory()); if (!$slot->usesDefaultMediaQuota()) { $query->addValue('media_quota', $slot->getMediaQuota()); } $dbc->query($query, IMPORTER_CONNECTION); } catch (DuplicateKeyDatabaseException $e) { // Update row to the slot table $query = new UpdateQuery(); $query->setTable('segue_slot'); $query->addWhereEqual('shortname', $shortname); $query->addValue('type', $type); $dbc->query($query, IMPORTER_CONNECTION); } // Clear our cache unset($this->slots[$shortname]); $slot = $this->getSlotByShortname($shortname); return $slot; }
/** * Make this slot an alias of another slot. * * @param object Slot $targetSlot * @return void * @access public * @since 10/8/08 */ public function makeAlias(Slot $targetSlot) { if (!is_null($this->siteId)) { throw new OperationFailedException("Cannot make a slot with an existing site an Alias."); } if ($this->isAlias()) { throw new OperationFailedException("This slot is already an Alias."); } // Check for cycles in aliases. $target = $targetSlot; while ($target) { if ($this->getShortname() == $target->getShortname()) { throw new OperationFailedException("Cannot create loops of aliases."); } if ($target->isAlias()) { $target = $target->getAliasTarget(); } else { $target = null; } } $this->aliasTarget = $targetSlot->getShortname(); $this->recordInDB(); $query = new UpdateQuery(); $query->setTable('segue_slot'); $query->addWhereEqual('shortname', $this->getShortname()); $query->addValue('alias_target', $targetSlot->getShortname()); $dbc = Services::getService('DBHandler'); try { $dbc->query($query, IMPORTER_CONNECTION); } catch (QueryDatabaseException $e) { $this->aliasTarget = null; throw new OperationFailedException("Unknown target placeholder, '" . $targetSlot->getShortname() . "'."); } }
/** * Answer an HTML block of export controls. * * @param Id $assetId * @param optional Slot $slot * @return string */ public function getExportControls(Id $assetId, Slot $slot = null, Slot $sitesTrueSlot = null) { if (!defined('DATAPORT_ENABLE_EXPORT_REDIRECT') || !DATAPORT_ENABLE_EXPORT_REDIRECT) { return ''; } $authZ = Services::getService('AuthZ'); $idMgr = Services::getService('Id'); ob_start(); if (!empty($slot)) { $this->printMigrationStatus($slot); } // Export controls if ($authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.modify'), $assetId)) { print "\n\t<div class='portal_list_controls portal_list_export_controls'>\n\t\t"; $controls = array(); if (isset($sitesTrueSlot)) { $params = array('site' => $sitesTrueSlot->getShortname()); } else { $params = array('node' => $assetId->getIdString()); } if ($this->isExportEnabled('html')) { $control = "<a href='" . SiteDispatcher::quickURL('dataport', 'export_html', $params) . "' onclick='new ArchiveStatus(this, \"" . SiteDispatcher::quickURL('dataport', 'check_html_export', $params) . "\");'>" . _("export HTML archive") . "</a>"; if (!empty($GLOBALS['dataport_export_types']['html']['help'])) { $control .= " (<a href='" . $GLOBALS['dataport_export_types']['html']['help'] . "' target='_blank'>help</a>)"; } $controls[] = $control; } if ($this->isExportEnabled('wordpress')) { $control = "<a href='" . SiteDispatcher::quickURL('dataport', 'wordpress', $params) . "'>" . _("export for wordpress") . "</a>"; if (!empty($GLOBALS['dataport_export_types']['wordpress']['help'])) { $control .= " (<a href='" . $GLOBALS['dataport_export_types']['wordpress']['help'] . "' target='_blank'>help</a>)"; } $controls[] = $control; } if ($this->isExportEnabled('files')) { $control = "<a href='" . SiteDispatcher::quickURL('dataport', 'files', $params) . "'>" . _("export files") . "</a>"; if (!empty($GLOBALS['dataport_export_types']['files']['help'])) { $control .= " (<a href='" . $GLOBALS['dataport_export_types']['files']['help'] . "' target='_blank'>help</a>)"; } $controls[] = $control; } print implode("\n\t\t | ", $controls); print "\n\t</div>"; } $export = ob_get_clean(); if ($export) { return "\n<div class='export_controls'>" . $export . "</div>"; } else { return ''; } }
/** * Answer a link to move/copy a site to a new slot. * * @param object Slot $slot * @return string * @access public * @since 10/10/08 */ public function getSiteMoveCopyLink(Slot $slot) { $this->addHeadJavascript(); $harmoni = Harmoni::instance(); $harmoni->request->startNamespace("selection"); ob_start(); print "<a "; print " style='cursor: pointer;'"; print " class='Selection_MoveCopy_Link' "; print " onclick=\"MoveCopyPanel.run('" . $slot->getShortname() . "', 'Slot', [], this); return false;\""; print " title=\"" . _("Paste from your Selection") . "\""; print ">" . _('Paste'); print "</a>"; $harmoni->request->endNamespace(); return ob_get_clean(); }
/** * 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>"; }
/** * Add a slot to a users array for an agent. * * @param Agent $agent * @param Slot $slot * @return int */ protected function addSlotForAgent(Agent $agent, Slot $slot) { $agentIdString = $agent->getId()->getIdString(); $email = $this->getAgentEmail($agent); // Don't include people without email addresses if (empty($email)) { return 0; } $this->slots[$slot->getShortname()]['users'][$email] = array('name' => $agent->getDisplayName(), 'email' => $email); ksort($this->slots[$slot->getShortname()]['users']); return 1; }
/** * Create the new site with this template at the slot specified. * * @param object Slot $slot * @param optional string $displayName * @param optional string $description * @return object SiteNavBlockSiteComponent * @access public * @since 6/11/08 */ public function createSite(Slot $slot, $displayName = 'Untitled', $description = '') { $director = SiteDispatcher::getSiteDirector(); $doc = new Harmoni_DOMDocument(); $doc->load($this->_path . "/site.xml"); // Validate the document contents $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd"); $mediaDir = $this->_path . "/media"; if (!file_exists($mediaDir)) { $mediaDir = null; } // @todo Strip out any history. $importer = new StripHistoryImportSiteVisitor($doc, $mediaDir, $director); $importer->disableCommentImport(); $site = $importer->importAtSlot($slot->getShortname()); try { // Replace #SITE_NAME# and #SITE_DESCRIPTION# placeholders $site->acceptVisitor(new Segue_Templates_ReplacePlaceholderVisitor($displayName, $description)); } catch (Exception $e) { $director->deleteSiteComponent($site); $slot->deleteSiteId(); throw $e; } return $site; }