/** * Make 1st level clickmenu: * * @param string $table Table name * @param int $uid UID for the current record. * @return string HTML content */ public function printDBClickMenu($table, $uid) { $uid = (int) $uid; // Get record: $this->rec = BackendUtility::getRecordWSOL($table, $uid); $menuItems = array(); $root = 0; $DBmount = false; // Rootlevel if ($table === 'pages' && $uid === 0) { $root = 1; } // DB mount if ($table === 'pages' && in_array($uid, $this->backendUser->returnWebmounts())) { $DBmount = true; } // Used to hide cut,copy icons for l10n-records $l10nOverlay = false; // Should only be performed for overlay-records within the same table if (BackendUtility::isTableLocalizable($table) && !isset($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'])) { $l10nOverlay = (int) $this->rec[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0; } // If record found (or root), go ahead and fill the $menuItems array which will contain data for the elements to render. if (is_array($this->rec) || $root) { // Get permissions $lCP = $this->backendUser->calcPerms(BackendUtility::getRecord('pages', $table === 'pages' ? (int) $this->rec['uid'] : (int) $this->rec['pid'])); // View if (!in_array('view', $this->disabledItems, true)) { if ($table === 'pages') { $menuItems['view'] = $this->DB_view($uid); } if ($table === 'tt_content') { $ws_rec = BackendUtility::getRecordWSOL($table, (int) $this->rec['uid']); $menuItems['view'] = $this->DB_view((int) $ws_rec['pid']); } } // Edit: if (!$root && ($this->backendUser->isPSet($lCP, $table, 'edit') || $this->backendUser->isPSet($lCP, $table, 'editcontent'))) { if (!in_array('edit', $this->disabledItems, true)) { $menuItems['edit'] = $this->DB_edit($table, $uid); } $this->editOK = true; } // New: if (!in_array('new', $this->disabledItems, true) && $this->backendUser->isPSet($lCP, $table, 'new')) { $menuItems['new'] = $this->DB_new($table, $uid); } // Info: if (!in_array('info', $this->disabledItems, true) && !$root) { $menuItems['info'] = $this->DB_info($table, $uid); } $menuItems['spacer1'] = 'spacer'; // Copy: if (!in_array('copy', $this->disabledItems, true) && !$root && !$DBmount && !$l10nOverlay) { $menuItems['copy'] = $this->DB_copycut($table, $uid, 'copy'); } // Cut: if (!in_array('cut', $this->disabledItems, true) && !$root && !$DBmount && !$l10nOverlay) { $menuItems['cut'] = $this->DB_copycut($table, $uid, 'cut'); } // Paste: $elFromAllTables = count($this->clipObj->elFromTable('')); if (!in_array('paste', $this->disabledItems, true) && $elFromAllTables) { $selItem = $this->clipObj->getSelectedRecord(); $elInfo = array(GeneralUtility::fixed_lgd_cs($selItem['_RECORD_TITLE'], $this->backendUser->uc['titleLen']), $root ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] : GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $this->rec), $this->backendUser->uc['titleLen']), $this->clipObj->currentMode()); if ($table === 'pages' && $lCP & Permission::PAGE_NEW) { if ($elFromAllTables) { $menuItems['pasteinto'] = $this->DB_paste('', $uid, 'into', $elInfo); } } $elFromTable = count($this->clipObj->elFromTable($table)); if (!$root && !$DBmount && $elFromTable && $GLOBALS['TCA'][$table]['ctrl']['sortby']) { $menuItems['pasteafter'] = $this->DB_paste($table, -$uid, 'after', $elInfo); } } // Delete: $elInfo = array(GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $this->rec), $this->backendUser->uc['titleLen'])); if (!in_array('delete', $this->disabledItems, true) && !$root && !$DBmount && $this->backendUser->isPSet($lCP, $table, 'delete')) { $menuItems['spacer2'] = 'spacer'; $menuItems['delete'] = $this->DB_delete($table, $uid, $elInfo); } if (!in_array('history', $this->disabledItems, true)) { $menuItems['history'] = $this->DB_history($table, $uid); } $localItems = array(); if (!$this->cmLevel && !in_array('moreoptions', $this->disabledItems, true)) { // Creating menu items here: if ($this->editOK) { $localItems['spacer3'] = 'spacer'; $localItems['moreoptions'] = $this->linkItem($this->label('more'), '', 'TYPO3.ClickMenu.fetch(' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript() . '&cmLevel=1&subname=moreoptions') . ');return false;', false, true); $menuItemHideUnhideAllowed = false; $hiddenField = ''; // Check if column for disabled is defined if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'])) { $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']; if ($hiddenField !== '' && !empty($GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude']) && $this->backendUser->check('non_exclude_fields', $table . ':' . $hiddenField)) { $menuItemHideUnhideAllowed = true; } } if ($menuItemHideUnhideAllowed && !in_array('hide', $this->disabledItems, true)) { $localItems['hide'] = $this->DB_hideUnhide($table, $this->rec, $hiddenField); } $anyEnableColumnsFieldAllowed = false; // Check if columns are defined if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) { $columnsToCheck = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']; if ($table === 'pages' && !empty($columnsToCheck)) { $columnsToCheck[] = 'extendToSubpages'; } foreach ($columnsToCheck as $currentColumn) { if (!empty($GLOBALS['TCA'][$table]['columns'][$currentColumn]['exclude']) && $this->backendUser->check('non_exclude_fields', $table . ':' . $currentColumn)) { $anyEnableColumnsFieldAllowed = true; } } } if ($anyEnableColumnsFieldAllowed && !in_array('edit_access', $this->disabledItems, true)) { $localItems['edit_access'] = $this->DB_editAccess($table, $uid); } if ($table === 'pages' && $this->editPageIconSet && !in_array('edit_pageproperties', $this->disabledItems, true)) { $localItems['edit_pageproperties'] = $this->DB_editPageProperties($uid); } } // Find delete element among the input menu items and insert the local items just before that: $c = 0; $deleteFound = false; foreach ($menuItems as $key => $value) { $c++; if ($key === 'delete') { $deleteFound = true; break; } } if ($deleteFound) { // .. subtract two... (delete item + its spacer element...) $c -= 2; // and insert the items just before the delete element. array_splice($menuItems, $c, 0, $localItems); } else { $menuItems = array_merge($menuItems, $localItems); } } } // Adding external elements to the menuItems array $menuItems = $this->processingByExtClassArray($menuItems, $table, $uid); // Processing by external functions? $menuItems = $this->externalProcessingOfDBMenuItems($menuItems); if (!is_array($this->rec)) { $this->rec = array(); } // Return the printed elements: return $this->printItems($menuItems); }
/** * 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; }
/** * 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; }