/** * Returns the specified node * * @param string $term * @param integer $requestIndex * @return void * @ExtDirect * @todo Improve this WIP search implementation */ public function searchAction($term, $requestIndex) { $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext($this->securityContext->getParty()->getPreferences()->get('context.workspace')); $this->nodeRepository->setContext($contentContext); $searchContentGroups = array(); $searchContentTypes = array(); foreach (array('TYPO3.Phoenix.ContentTypes:Page', 'TYPO3.Phoenix.ContentTypes:ContentObject') as $contentType) { $searchContentGroups[$contentType] = $this->contentTypeManager->getContentType($contentType)->getConfiguration(); array_push($searchContentTypes, $contentType); $subContentTypes = $this->contentTypeManager->getSubContentTypes($contentType); if (count($subContentTypes) > 0) { $searchContentGroups[$contentType]['subContentTypes'] = $subContentTypes; $searchContentTypes = array_merge($searchContentTypes, array_keys($subContentTypes)); } } $staticWebBaseUri = $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'Packages/TYPO3.TYPO3/'; $groups = array(); foreach ($this->nodeSearchService->findByProperties($term, $searchContentTypes) as $result) { $contentType = $result->getContentType(); if (array_key_exists($contentType->getName(), $searchContentGroups)) { $type = $contentType->getName(); } else { foreach ($searchContentGroups as $searchContentGroup => $searchContentGroupConfiguration) { if (isset($searchContentGroupConfiguration['subContentTypes']) && array_key_exists($contentType->getName(), $searchContentGroupConfiguration['subContentTypes'])) { $type = $searchContentGroup; break; } } } if (!array_key_exists($type, $groups)) { $groups[$type] = array('type' => $contentType->getName(), 'label' => $searchContentGroups[$type]['search'], 'items' => array()); } foreach ($contentType->getProperties() as $property => $configuration) { if ($property[0] !== '_') { $labelProperty = $property; break; } } $this->uriBuilder->reset(); if ($result->getContentType()->isOfType('TYPO3.Phoenix.ContentTypes:Page')) { $pageNode = $result; } else { $pageNode = $this->findNextParentFolderNode($result); $this->uriBuilder->setSection('c' . $result->getIdentifier()); } $searchResult = array('type' => $contentType->getName(), 'label' => substr(trim(strip_tags($result->getProperty($labelProperty))), 0, 50), 'action' => $this->uriBuilder->uriFor('show', array('node' => $pageNode), 'Frontend\\Node', 'TYPO3.TYPO3'), 'path' => $result->getPath()); $contentTypeConfiguration = $contentType->getConfiguration(); if (isset($contentTypeConfiguration['darkIcon'])) { $searchResult['icon'] = $staticWebBaseUri . $contentTypeConfiguration['darkIcon']; } array_push($groups[$type]['items'], $searchResult); } $data = array('requestIndex' => $requestIndex, 'actions' => array(array('label' => 'Clear all cache', 'command' => 'clear:cache:all'), array('label' => 'Clear page cache', 'command' => 'clear:cache:pages')), 'results' => array_values($groups)); $this->view->assign('value', array('data' => $data, 'success' => TRUE)); }
/** * @param string $workspaceName * @return void * @todo Pagination * @todo Tree filtering + level limit * @todo Search field * @todo Difference mechanism */ public function indexAction($workspaceName = NULL) { if (is_null($workspaceName)) { $workspaceName = $this->securityContext->getParty()->getPreferences()->get('context.workspace'); } $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext($workspaceName); $contentContext->setInvisibleContentShown(TRUE); $contentContext->setRemovedContentShown(TRUE); $contentContext->setInaccessibleContentShown(TRUE); $this->nodeRepository->setContext($contentContext); $sites = array(); foreach ($this->workspacesService->getUnpublishedNodes($workspaceName) as $node) { if (!$node->getContentType()->isOfType('TYPO3.Phoenix.ContentTypes:Section')) { $pathParts = explode('/', $node->getPath()); if (count($pathParts) > 2) { $siteNodeName = $pathParts[2]; $folder = $this->findFolderNode($node); $folderPath = implode('/', array_slice(explode('/', $folder->getPath()), 3)); $relativePath = str_replace(sprintf('/sites/%s/%s', $siteNodeName, $folderPath), '', $node->getPath()); if (!isset($sites[$siteNodeName]['siteNode'])) { $sites[$siteNodeName]['siteNode'] = $this->siteRepository->findOneByNodeName($siteNodeName); } $sites[$siteNodeName]['folders'][$folderPath]['folderNode'] = $folder; $change = array('node' => $node); if ($node->getContentType()->isOfType('TYPO3.Phoenix.ContentTypes:AbstractNode')) { $change['configuration'] = $node->getContentType()->getConfiguration(); } $sites[$siteNodeName]['folders'][$folderPath]['changes'][$relativePath] = $change; } } } $liveWorkspace = $this->workspacesService->getWorkspace('live'); ksort($sites); foreach ($sites as $siteKey => $site) { foreach ($site['folders'] as $folderKey => $folder) { foreach ($folder['changes'] as $changeKey => $change) { $liveNode = $this->nodeRepository->findOneByIdentifier($change['node']->getIdentifier(), $liveWorkspace); $sites[$siteKey]['folders'][$folderKey]['changes'][$changeKey]['isNew'] = is_null($liveNode); $sites[$siteKey]['folders'][$folderKey]['changes'][$changeKey]['isMoved'] = $liveNode && $change['node']->getPath() !== $liveNode->getPath(); } } ksort($sites[$siteKey]['folders']); } $workspaces = array(); foreach ($this->workspacesService->getWorkspaces() as $workspace) { array_push($workspaces, array('workspaceNode' => $workspace, 'unpublishedNodesCount' => $this->workspacesService->getUnpublishedNodesCount($workspace->getName()))); } $this->view->assignMultiple(array('workspaceName' => $workspaceName, 'workspaces' => $workspaces, 'sites' => $sites)); }
/** * Export sites content * * Export all sites and their content into an XML format. * * @return void */ public function exportCommand() { $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live'); $this->nodeRepository->setContext($contentContext); $sites = $this->siteRepository->findAll(); $this->response->setContent($this->siteExportService->export($sites->toArray())); }
/** * @param \TYPO3\Form\Core\Model\FinisherContext $finisherContext * @return void * @throws \TYPO3\Setup\Exception */ public function importSite(\TYPO3\Form\Core\Model\FinisherContext $finisherContext) { $formValues = $finisherContext->getFormRuntime()->getFormState()->getFormValues(); if (isset($formValues['prune']) && intval($formValues['prune']) === 1) { $this->nodeRepository->removeAll(); $this->workspaceRepository->removeAll(); $this->domainRepository->removeAll(); $this->siteRepository->removeAll(); $this->persistenceManager->persistAll(); } if (!empty($formValues['packageKey'])) { if ($this->packageManager->isPackageAvailable($formValues['packageKey'])) { throw new \TYPO3\Setup\Exception(sprintf('The package key "%s" already exists.', $formValues['packageKey']), 1346759486); } $packageKey = $formValues['packageKey']; $siteName = $formValues['packageKey']; $this->packageManager->createPackage($packageKey, NULL, Files::getUnixStylePath(Files::concatenatePaths(array(FLOW3_PATH_PACKAGES, 'Sites')))); $this->generatorService->generateSitesXml($packageKey, $siteName); $this->generatorService->generateSitesTypoScript($packageKey, $siteName); $this->generatorService->generateSitesTemplate($packageKey, $siteName); $this->packageManager->activatePackage($packageKey); } else { $packageKey = $formValues['site']; } if ($packageKey !== '') { try { $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live'); $this->nodeRepository->setContext($contentContext); $this->siteImportService->importFromPackage($packageKey); } catch (\Exception $exception) { $finisherContext->cancel(); $this->flashMessageContainer->addMessage(new \TYPO3\FLOW3\Error\Error(sprintf('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', $packageKey, $exception->getMessage()))); } } }
/** * Search a page, needed for internal links. * * @param string $query * @return void * @ExtDirect */ public function searchPageAction($query) { $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live'); $this->nodeRepository->setContext($contentContext); $nodes = $this->nodeSearchService->findByProperties($query, array('TYPO3.Phoenix.ContentTypes:Page')); $searchResult = array(); foreach ($nodes as $uninitializedNode) { $node = $contentContext->getNode($uninitializedNode->getPath()); $searchResult[] = $this->processNodeForEditorPlugins($node); } $this->view->assign('value', array('searchResult' => $searchResult, 'success' => TRUE)); }
/** * Returns the initialized node that is referenced by $relativeContextNodePath * * @param string $relativeContextNodePath * @return \TYPO3\TYPO3CR\Domain\Model\NodeInterface * @throws \TYPO3\TYPO3\Routing\Exception\NoWorkspaceException * @throws \TYPO3\TYPO3\Routing\Exception\NoSiteException * @throws \TYPO3\TYPO3\Routing\Exception\NoSuchNodeException * @throws \TYPO3\TYPO3\Routing\Exception\NoSiteNodeException * @throws \TYPO3\TYPO3\Routing\Exception\InvalidRequestPathException */ public function getNodeByContextNodePath($relativeContextNodePath) { if ($relativeContextNodePath !== '') { preg_match(NodeInterface::MATCH_PATTERN_CONTEXTPATH, $relativeContextNodePath, $matches); if (!isset($matches['NodePath'])) { throw new Exception\InvalidRequestPathException('The request path "' . $relativeContextNodePath . '" is not valid', 1346949309); } $relativeNodePath = $matches['NodePath']; } else { $relativeNodePath = ''; } if ($this->nodeRepository->getContext() === NULL) { $workspaceName = isset($matches['WorkspaceName']) ? $matches['WorkspaceName'] : 'live'; $contentContext = new ContentContext($workspaceName); $contentContext->setInvisibleContentShown(TRUE); $this->nodeRepository->setContext($contentContext); } else { $contentContext = $this->nodeRepository->getContext(); } $workspace = $contentContext->getWorkspace(FALSE); if (!$workspace) { throw new Exception\NoWorkspaceException('No workspace found for request path "' . $relativeContextNodePath . '"', 1346949318); } $site = $contentContext->getCurrentSite(); if (!$site) { throw new Exception\NoSiteException('No site found for request path "' . $relativeContextNodePath . '"', 1346949693); } $siteNode = $contentContext->getCurrentSiteNode(); if (!$siteNode) { throw new Exception\NoSiteNodeException('No site node found for request path "' . $relativeContextNodePath . '"', 1346949728); } $currentAccessModeFromContext = $contentContext->isInaccessibleContentShown(); $contentContext->setInaccessibleContentShown(TRUE); $node = $relativeNodePath === '' ? $siteNode->getPrimaryChildNode() : $siteNode->getNode($relativeNodePath); $contentContext->setInaccessibleContentShown($currentAccessModeFromContext); if (!$node instanceof NodeInterface) { throw new Exception\NoSuchNodeException('No node found on request path "' . $relativeContextNodePath . '"', 1346949857); } return $node; }
/** * Converts the specified node path into a Node. * * The node path must be an absolute context node path and can be specified as a string or as an array item with the * key "__contextNodePath". The latter case is for updating existing nodes. * * This conversion method does not support / allow creation of new nodes because new nodes should be created through * the createNode() method of an existing reference node. * * Also note that the context's "current node" is not affected by this object converter, you will need to set it to * whatever node your "current" node is, if any. * * All elements in the source array which start with two underscores (like __contextNodePath) are specially treated * by this converter. * * All elements in the source array which start with a *single underscore (like _hidden) are *directly* set on the Node * object. * * All other elements, not being prefixed with underscore, are properties of the node. * * @param string|array $source Either a string or array containing the absolute context node path which identifies the node. For example "/sites/mysitecom/homepage/about@user-admin" * @param string $targetType not used * @param array $subProperties not used * @param \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration not used * @return mixed An object or \TYPO3\FLOW3\Error\Error if the input format is not supported or could not be converted for other reasons * @throws \Exception */ public function convertFrom($source, $targetType, array $subProperties = array(), \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration = NULL) { if (is_string($source)) { $source = array('__contextNodePath' => $source); } if (!is_array($source) || !isset($source['__contextNodePath'])) { return new Error('Could not convert ' . gettype($source) . ' to Node object, a valid absolute context node path as a string or array is expected.', 1302879936); } preg_match(NodeInterface::MATCH_PATTERN_CONTEXTPATH, $source['__contextNodePath'], $matches); if (!isset($matches['NodePath'])) { return new Error('Could not convert array to Node object because the node path was invalid.', 1285162903); } $nodePath = $matches['NodePath']; if ($this->nodeRepository->getContext() === NULL) { $workspaceName = isset($matches['WorkspaceName']) ? $matches['WorkspaceName'] : 'live'; $contentContext = new ContentContext($workspaceName); $this->nodeRepository->setContext($contentContext); } else { $contentContext = $this->nodeRepository->getContext(); $workspaceName = $contentContext->getWorkspace()->getName(); } if ($workspaceName !== 'live') { $contentContext->setInvisibleContentShown(TRUE); if ($configuration->getConfigurationValue('TYPO3\\TYPO3\\Routing\\NodeObjectConverter', self::REMOVED_CONTENT_SHOWN) === TRUE) { $contentContext->setRemovedContentShown(TRUE); } } $workspace = $contentContext->getWorkspace(FALSE); if (!$workspace) { return new Error(sprintf('Could not convert %s to Node object because the workspace "%s" as specified in the context node path does not exist.', $source['__contextNodePath'], $workspaceName), 1285162905); } $currentAccessModeFromContext = $contentContext->isInaccessibleContentShown(); $contentContext->setInaccessibleContentShown(TRUE); $node = $contentContext->getNode($nodePath); $contentContext->setInaccessibleContentShown($currentAccessModeFromContext); if (!$node) { return new Error(sprintf('Could not convert array to Node object because the node "%s" does not exist.', $nodePath), 1285162908); } $contentTypeProperties = $node->getContentType()->getProperties(); foreach ($source as $nodePropertyKey => $nodePropertyValue) { if (substr($nodePropertyKey, 0, 2) === '__') { continue; } if ($nodePropertyKey[0] === '_') { $propertyName = substr($nodePropertyKey, 1); // TODO: Hack: we need to create DateTime objects for some properties of Node if (($propertyName === 'hiddenBeforeDateTime' || $propertyName === 'hiddenAfterDateTime') && is_string($nodePropertyValue)) { if ($nodePropertyValue !== '') { $nodePropertyValue = \DateTime::createFromFormat('!Y-m-d', $nodePropertyValue); } else { $nodePropertyValue = NULL; } } \TYPO3\FLOW3\Reflection\ObjectAccess::setProperty($node, $propertyName, $nodePropertyValue); } else { if (!isset($contentTypeProperties[$nodePropertyKey])) { throw new \Exception('TODO: content type XY does not have a property YY according to the schema'); } if (isset($contentTypeProperties[$nodePropertyKey]['type'])) { $targetType = $contentTypeProperties[$nodePropertyKey]['type']; if ($this->objectManager->isRegistered($targetType)) { $nodePropertyValue = $this->propertyMapper->convert(json_decode($nodePropertyValue, TRUE), $targetType); } } $node->setProperty($nodePropertyKey, $nodePropertyValue); } } return $node; }