/** * Executes the modules configured via Extbase * * @param string $moduleName * @return Response A PSR-7 response object * @throws \RuntimeException */ protected function dispatchModule($moduleName) { $moduleConfiguration = $this->getModuleConfiguration($moduleName); // Check permissions and exit if the user has no permission for entry $this->backendUserAuthentication->modAccess($moduleConfiguration, true); $id = isset($this->request->getQueryParams()['id']) ? $this->request->getQueryParams()['id'] : $this->request->getParsedBody()['id']; if ($id && MathUtility::canBeInterpretedAsInteger($id)) { // Check page access $permClause = $this->backendUserAuthentication->getPagePermsClause(true); $access = is_array(BackendUtility::readPageAccess((int) $id, $permClause)); if (!$access) { throw new \RuntimeException('You don\'t have access to this page', 1289917924); } } /** @var Response $response */ $response = GeneralUtility::makeInstance(Response::class); // Use Core Dispatching if (isset($moduleConfiguration['routeTarget'])) { $dispatcher = GeneralUtility::makeInstance(Dispatcher::class); $this->request = $this->request->withAttribute('target', $moduleConfiguration['routeTarget']); $response = $dispatcher->dispatch($this->request, $response); } else { // extbase module $configuration = array('extensionName' => $moduleConfiguration['extensionName'], 'pluginName' => $moduleName); if (isset($moduleConfiguration['vendorName'])) { $configuration['vendorName'] = $moduleConfiguration['vendorName']; } // Run Extbase $bootstrap = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Core\Bootstrap::class); $content = $bootstrap->run('', $configuration); $response->getBody()->write($content); } return $response; }
/** * Make value list * * @param string $fieldName * @param string $fieldValue * @param array $conf * @param string $table * @param string $splitString * @return string */ public function makeValueList($fieldName, $fieldValue, $conf, $table, $splitString) { $fieldSetup = $conf; $out = ''; if ($fieldSetup['type'] == 'files') { $d = dir(PATH_site . $fieldSetup['uploadfolder']); while (false !== ($entry = $d->read())) { if ($entry == '.' || $entry == '..') { continue; } $fileArray[] = $entry; } $d->close(); natcasesort($fileArray); foreach ($fileArray as $fileName) { if (GeneralUtility::inList($fieldValue, $fileName) || $fieldValue == $fileName) { if (!$out) { $out = htmlspecialchars($fileName); } else { $out .= $splitString . htmlspecialchars($fileName); } } } } if ($fieldSetup['type'] == 'multiple') { foreach ($fieldSetup['items'] as $key => $val) { if (substr($val[0], 0, 4) == 'LLL:') { $value = $this->languageService->sL($val[0]); } else { $value = $val[0]; } if (GeneralUtility::inList($fieldValue, $val[1]) || $fieldValue == $val[1]) { if (!$out) { $out = htmlspecialchars($value); } else { $out .= $splitString . htmlspecialchars($value); } } } } if ($fieldSetup['type'] == 'binary') { foreach ($fieldSetup['items'] as $Key => $val) { if (substr($val[0], 0, 4) == 'LLL:') { $value = $this->languageService->sL($val[0]); } else { $value = $val[0]; } if (!$out) { $out = htmlspecialchars($value); } else { $out .= $splitString . htmlspecialchars($value); } } } if ($fieldSetup['type'] == 'relation') { $dontPrefixFirstTable = 0; $useTablePrefix = 0; if ($fieldSetup['items']) { foreach ($fieldSetup['items'] as $key => $val) { if (substr($val[0], 0, 4) == 'LLL:') { $value = $this->languageService->sL($val[0]); } else { $value = $val[0]; } if (GeneralUtility::inList($fieldValue, $value) || $fieldValue == $value) { if (!$out) { $out = htmlspecialchars($value); } else { $out .= $splitString . htmlspecialchars($value); } } } } if (stristr($fieldSetup['allowed'], ',')) { $from_table_Arr = explode(',', $fieldSetup['allowed']); $useTablePrefix = 1; if (!$fieldSetup['prepend_tname']) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); $statement = $queryBuilder->select($fieldName)->from($table)->execute(); while ($row = $statement->fetch()) { if (stristr($row[$fieldName], ',')) { $checkContent = explode(',', $row[$fieldName]); foreach ($checkContent as $singleValue) { if (!stristr($singleValue, '_')) { $dontPrefixFirstTable = 1; } } } else { $singleValue = $row[$fieldName]; if ($singleValue !== '' && !stristr($singleValue, '_')) { $dontPrefixFirstTable = 1; } } } } } else { $from_table_Arr[0] = $fieldSetup['allowed']; } if ($fieldSetup['prepend_tname']) { $useTablePrefix = 1; } if ($fieldSetup['foreign_table']) { $from_table_Arr[0] = $fieldSetup['foreign_table']; } $counter = 0; $useSelectLabels = 0; $useAltSelectLabels = 0; $tablePrefix = ''; $labelFieldSelect = []; foreach ($from_table_Arr as $from_table) { if ($useTablePrefix && !$dontPrefixFirstTable && $counter != 1 || $counter == 1) { $tablePrefix = $from_table . '_'; } $counter = 1; if (is_array($GLOBALS['TCA'][$from_table])) { $labelField = $GLOBALS['TCA'][$from_table]['ctrl']['label']; $altLabelField = $GLOBALS['TCA'][$from_table]['ctrl']['label_alt']; if ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items']) { $items = $GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items']; foreach ($items as $labelArray) { if (substr($labelArray[0], 0, 4) == 'LLL:') { $labelFieldSelect[$labelArray[1]] = $this->languageService->sL($labelArray[0]); } else { $labelFieldSelect[$labelArray[1]] = $labelArray[0]; } } $useSelectLabels = 1; } if ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items']) { $items = $GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items']; foreach ($items as $altLabelArray) { if (substr($altLabelArray[0], 0, 4) == 'LLL:') { $altLabelFieldSelect[$altLabelArray[1]] = $this->languageService->sL($altLabelArray[0]); } else { $altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0]; } } $useAltSelectLabels = 1; } if (!$this->tableArray[$from_table]) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($from_table); $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); $selectFields = ['uid', $labelField]; if ($altLabelField) { $selectFields[] = $altLabelField; } $queryBuilder->select(...$selectFields)->from($from_table)->orderBy('uid'); if (!$this->backendUserAuthentication->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) { $webMounts = $this->backendUserAuthentication->returnWebmounts(); $perms_clause = $this->backendUserAuthentication->getPagePermsClause(1); $webMountPageTree = ''; $webMountPageTreePrefix = ''; foreach ($webMounts as $webMount) { if ($webMountPageTree) { $webMountPageTreePrefix = ','; } $webMountPageTree .= $webMountPageTreePrefix . $this->getTreeList($webMount, 999, $begin = 0, $perms_clause); } if ($from_table === 'pages') { $queryBuilder->where(QueryHelper::stripLogicalOperatorPrefix($perms_clause), $queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter(GeneralUtility::intExplode(',', $webMountPageTree), Connection::PARAM_INT_ARRAY))); } else { $queryBuilder->where($queryBuilder->expr()->in('pid', $queryBuilder->createNamedParameter(GeneralUtility::intExplode(',', $webMountPageTree), Connection::PARAM_INT_ARRAY))); } } $statement = $queryBuilder->execute(); $this->tableArray[$from_table] = []; while ($row = $statement->fetch()) { $this->tableArray[$from_table][] = $row; } } foreach ($this->tableArray[$from_table] as $key => $val) { $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 1 ? 'on' : $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix']; $prefixString = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 'on' ? '' : ' [' . $tablePrefix . $val['uid'] . '] '; if (GeneralUtility::inList($fieldValue, $tablePrefix . $val['uid']) || $fieldValue == $tablePrefix . $val['uid']) { if ($useSelectLabels) { if (!$out) { $out = htmlspecialchars($prefixString . $labelFieldSelect[$val[$labelField]]); } else { $out .= $splitString . htmlspecialchars($prefixString . $labelFieldSelect[$val[$labelField]]); } } elseif ($val[$labelField]) { if (!$out) { $out = htmlspecialchars($prefixString . $val[$labelField]); } else { $out .= $splitString . htmlspecialchars($prefixString . $val[$labelField]); } } elseif ($useAltSelectLabels) { if (!$out) { $out = htmlspecialchars($prefixString . $altLabelFieldSelect[$val[$altLabelField]]); } else { $out .= $splitString . htmlspecialchars($prefixString . $altLabelFieldSelect[$val[$altLabelField]]); } } else { if (!$out) { $out = htmlspecialchars($prefixString . $val[$altLabelField]); } else { $out .= $splitString . htmlspecialchars($prefixString . $val[$altLabelField]); } } } } } } } return $out; }
/** * Returns array, $CPtable, of pages under the $pid going down to $counter levels. * Selecting ONLY pages which the user has read-access to! * * @param array $CPtable Accumulation of page uid=>pid pairs in branch of $pid * @param int $pid Page ID for which to find subpages * @param int $counter Number of levels to go down. * @param int $rootID ID of root point for new copied branch: The idea seems to be that a copy is not made of the already new page! * @return array Return array. */ public function int_pageTreeInfo($CPtable, $pid, $counter, $rootID) { if ($counter) { if ((int) $this->BE_USER->workspace === 0) { $workspaceStatement = ' AND t3ver_wsid=0'; } else { $workspaceStatement = ' AND t3ver_wsid IN (0,' . (int) $this->BE_USER->workspace . ')'; } $addW = !$this->admin ? ' AND ' . $this->BE_USER->getPagePermsClause($this->pMap['show']) : ''; $pages = $this->databaseConnection->exec_SELECTgetRows('uid', 'pages', 'pid=' . (int) $pid . $this->deleteClause('pages') . $workspaceStatement . $addW, '', 'sorting DESC', '', 'uid'); // Resolve placeholders of workspace versions if (!empty($pages) && (int) $this->BE_USER->workspace !== 0) { $pages = array_reverse($this->resolveVersionedRecords('pages', 'uid', 'sorting', array_keys($pages)), true); } foreach ($pages as $page) { if ($page['uid'] != $rootID) { $CPtable[$page['uid']] = $pid; // If the uid is NOT the rootID of the copyaction and if we are supposed to walk further down if ($counter - 1) { $CPtable = $this->int_pageTreeInfo($CPtable, $page['uid'], $counter - 1, $rootID); } } } } return $CPtable; }
/** * Returns array, $CPtable, of pages under the $pid going down to $counter levels. * Selecting ONLY pages which the user has read-access to! * * @param array $CPtable Accumulation of page uid=>pid pairs in branch of $pid * @param int $pid Page ID for which to find subpages * @param int $counter Number of levels to go down. * @param int $rootID ID of root point for new copied branch: The idea seems to be that a copy is not made of the already new page! * @return array Return array. */ public function int_pageTreeInfo($CPtable, $pid, $counter, $rootID) { if ($counter) { $addW = !$this->admin ? ' AND ' . $this->BE_USER->getPagePermsClause($this->pMap['show']) : ''; $mres = $this->databaseConnection->exec_SELECTquery('uid', 'pages', 'pid=' . (int) $pid . $this->deleteClause('pages') . $addW, '', 'sorting DESC'); while ($row = $this->databaseConnection->sql_fetch_assoc($mres)) { if ($row['uid'] != $rootID) { $CPtable[$row['uid']] = $pid; // If the uid is NOT the rootID of the copyaction and if we are supposed to walk further down if ($counter - 1) { $CPtable = $this->int_pageTreeInfo($CPtable, $row['uid'], $counter - 1, $rootID); } } } $this->databaseConnection->sql_free_result($mres); } return $CPtable; }
/** * Make value list * * @param string $fieldName * @param string $fieldValue * @param array $conf * @param string $table * @param string $splitString * @return string */ public function makeValueList($fieldName, $fieldValue, $conf, $table, $splitString) { $fieldSetup = $conf; $out = ''; if ($fieldSetup['type'] == 'files') { $d = dir(PATH_site . $fieldSetup['uploadfolder']); while (false !== ($entry = $d->read())) { if ($entry == '.' || $entry == '..') { continue; } $fileArray[] = $entry; } $d->close(); natcasesort($fileArray); foreach ($fileArray as $fileName) { if (GeneralUtility::inList($fieldValue, $fileName) || $fieldValue == $fileName) { if (!$out) { $out = htmlspecialchars($fileName); } else { $out .= $splitString . htmlspecialchars($fileName); } } } } if ($fieldSetup['type'] == 'multiple') { foreach ($fieldSetup['items'] as $key => $val) { if (substr($val[0], 0, 4) == 'LLL:') { $value = $this->languageService->sL($val[0]); } else { $value = $val[0]; } if (GeneralUtility::inList($fieldValue, $val[1]) || $fieldValue == $val[1]) { if (!$out) { $out = htmlspecialchars($value); } else { $out .= $splitString . htmlspecialchars($value); } } } } if ($fieldSetup['type'] == 'binary') { foreach ($fieldSetup['items'] as $Key => $val) { if (substr($val[0], 0, 4) == 'LLL:') { $value = $this->languageService->sL($val[0]); } else { $value = $val[0]; } if (!$out) { $out = htmlspecialchars($value); } else { $out .= $splitString . htmlspecialchars($value); } } } if ($fieldSetup['type'] == 'relation') { $dontPrefixFirstTable = 0; $useTablePrefix = 0; if ($fieldSetup['items']) { foreach ($fieldSetup['items'] as $key => $val) { if (substr($val[0], 0, 4) == 'LLL:') { $value = $this->languageService->sL($val[0]); } else { $value = $val[0]; } if (GeneralUtility::inList($fieldValue, $value) || $fieldValue == $value) { if (!$out) { $out = htmlspecialchars($value); } else { $out .= $splitString . htmlspecialchars($value); } } } } if (stristr($fieldSetup['allowed'], ',')) { $from_table_Arr = explode(',', $fieldSetup['allowed']); $useTablePrefix = 1; if (!$fieldSetup['prepend_tname']) { $checkres = $this->databaseConnection->exec_SELECTquery($fieldName, $table, 'uid ' . BackendUtility::deleteClause($table)); if ($checkres) { while ($row = $this->databaseConnection->sql_fetch_assoc($checkres)) { if (stristr($row[$fieldName], ',')) { $checkContent = explode(',', $row[$fieldName]); foreach ($checkContent as $singleValue) { if (!stristr($singleValue, '_')) { $dontPrefixFirstTable = 1; } } } else { $singleValue = $row[$fieldName]; if ($singleValue !== '' && !stristr($singleValue, '_')) { $dontPrefixFirstTable = 1; } } } $this->databaseConnection->sql_free_result($checkres); } } } else { $from_table_Arr[0] = $fieldSetup['allowed']; } if ($fieldSetup['prepend_tname']) { $useTablePrefix = 1; } if ($fieldSetup['foreign_table']) { $from_table_Arr[0] = $fieldSetup['foreign_table']; } $counter = 0; $useSelectLabels = 0; $useAltSelectLabels = 0; $tablePrefix = ''; $labelFieldSelect = []; foreach ($from_table_Arr as $from_table) { if ($useTablePrefix && !$dontPrefixFirstTable && $counter != 1 || $counter == 1) { $tablePrefix = $from_table . '_'; } $counter = 1; if (is_array($GLOBALS['TCA'][$from_table])) { $labelField = $GLOBALS['TCA'][$from_table]['ctrl']['label']; $altLabelField = $GLOBALS['TCA'][$from_table]['ctrl']['label_alt']; if ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items']) { $items = $GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items']; foreach ($items as $labelArray) { if (substr($labelArray[0], 0, 4) == 'LLL:') { $labelFieldSelect[$labelArray[1]] = $this->languageService->sL($labelArray[0]); } else { $labelFieldSelect[$labelArray[1]] = $labelArray[0]; } } $useSelectLabels = 1; } if ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items']) { $items = $GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items']; foreach ($items as $altLabelArray) { if (substr($altLabelArray[0], 0, 4) == 'LLL:') { $altLabelFieldSelect[$altLabelArray[1]] = $this->languageService->sL($altLabelArray[0]); } else { $altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0]; } } $useAltSelectLabels = 1; } $altLabelFieldSelect = $altLabelField ? ',' . $altLabelField : ''; $select_fields = 'uid,' . $labelField . $altLabelFieldSelect; if (!$this->backendUserAuthentication->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) { $webMounts = $this->backendUserAuthentication->returnWebmounts(); $perms_clause = $this->backendUserAuthentication->getPagePermsClause(1); $webMountPageTree = ''; $webMountPageTreePrefix = ''; foreach ($webMounts as $key => $val) { if ($webMountPageTree) { $webMountPageTreePrefix = ','; } $webMountPageTree .= $webMountPageTreePrefix . $this->getTreeList($val, 999, $begin = 0, $perms_clause); } if ($from_table == 'pages') { $where_clause = 'uid IN (' . $webMountPageTree . ') ' . BackendUtility::deleteClause($from_table) . ' AND ' . $perms_clause; } else { $where_clause = 'pid IN (' . $webMountPageTree . ') ' . BackendUtility::deleteClause($from_table); } } else { $where_clause = 'uid' . BackendUtility::deleteClause($from_table); } $orderBy = 'uid'; $res = null; if (!$this->tableArray[$from_table]) { $res = $this->databaseConnection->exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy); $this->tableArray[$from_table] = array(); } if ($res) { while ($row = $this->databaseConnection->sql_fetch_assoc($res)) { $this->tableArray[$from_table][] = $row; } $this->databaseConnection->sql_free_result($res); } foreach ($this->tableArray[$from_table] as $key => $val) { $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 1 ? 'on' : $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix']; $prefixString = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 'on' ? '' : ' [' . $tablePrefix . $val['uid'] . '] '; if (GeneralUtility::inList($fieldValue, $tablePrefix . $val['uid']) || $fieldValue == $tablePrefix . $val['uid']) { if ($useSelectLabels) { if (!$out) { $out = htmlspecialchars($prefixString . $labelFieldSelect[$val[$labelField]]); } else { $out .= $splitString . htmlspecialchars($prefixString . $labelFieldSelect[$val[$labelField]]); } } elseif ($val[$labelField]) { if (!$out) { $out = htmlspecialchars($prefixString . $val[$labelField]); } else { $out .= $splitString . htmlspecialchars($prefixString . $val[$labelField]); } } elseif ($useAltSelectLabels) { if (!$out) { $out = htmlspecialchars($prefixString . $altLabelFieldSelect[$val[$altLabelField]]); } else { $out .= $splitString . htmlspecialchars($prefixString . $altLabelFieldSelect[$val[$altLabelField]]); } } else { if (!$out) { $out = htmlspecialchars($prefixString . $val[$altLabelField]); } else { $out .= $splitString . htmlspecialchars($prefixString . $val[$altLabelField]); } } } } } } } return $out; }
/** * Returns array, $CPtable, of pages under the $pid going down to $counter levels. * Selecting ONLY pages which the user has read-access to! * * @param array $CPtable Accumulation of page uid=>pid pairs in branch of $pid * @param int $pid Page ID for which to find subpages * @param int $counter Number of levels to go down. * @param int $rootID ID of root point for new copied branch: The idea seems to be that a copy is not made of the already new page! * @return array Return array. */ public function int_pageTreeInfo($CPtable, $pid, $counter, $rootID) { if ($counter) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); $restrictions = $queryBuilder->getRestrictions()->removeAll(); $this->addDeleteRestriction($restrictions); $queryBuilder->select('uid')->from('pages')->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)))->orderBy('sorting', 'DESC'); if (!$this->admin) { $queryBuilder->andWhere($this->BE_USER->getPagePermsClause($this->pMap['show'])); } if ((int) $this->BE_USER->workspace === 0) { $queryBuilder->andWhere($queryBuilder->expr()->eq('t3ver_wsid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))); } else { $queryBuilder->andWhere($queryBuilder->expr()->in('t3ver_wsid', $queryBuilder->createNamedParameter([0, $this->BE_USER->workspace], Connection::PARAM_INT_ARRAY))); } $result = $queryBuilder->execute(); $pages = []; while ($row = $result->fetch()) { $pages[$row['uid']] = $row; } // Resolve placeholders of workspace versions if (!empty($pages) && (int) $this->BE_USER->workspace !== 0) { $pages = array_reverse($this->resolveVersionedRecords('pages', 'uid', 'sorting', array_keys($pages)), true); } foreach ($pages as $page) { if ($page['uid'] != $rootID) { $CPtable[$page['uid']] = $pid; // If the uid is NOT the rootID of the copyaction and if we are supposed to walk further down if ($counter - 1) { $CPtable = $this->int_pageTreeInfo($CPtable, $page['uid'], $counter - 1, $rootID); } } } } return $CPtable; }