/** * Get translation * * @param int $uid * @param int $sysLanguageUid * @return Tx_MooxNews_Domain_Model_News */ public function getTranslation($uid, $sysLanguageUid) { $translation = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordLocalization('tx_mooxnews_domain_model_news', $uid, $sysLanguageUid); if (is_array($translation[0])) { $return = $translation[0]; } return $return; }
/** * @param $pageInfo * @param $lang * @return array */ protected function getResults($pageInfo, $lang) { $results = []; if ($lang) { $tableName = 'pages_language_overlay'; $localizedPageInfo = BackendUtility::getRecordLocalization('pages', $pageInfo['uid'], $lang); if ($localizedPageInfo[0]) { $uidForeign = $localizedPageInfo[0]['uid']; } else { return []; } } else { $tableName = 'pages'; $uidForeign = $pageInfo['uid']; } $where = 'uid_foreign = ' . $uidForeign; $where .= ' AND tablenames = "' . $tableName . '"'; $res = $this->getDatabaseConnection()->exec_SELECTquery('results', 'tx_csseo_domain_model_evaluation', $where); while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) { $results = unserialize($row['results']); } return $results; }
/** * Returning uid of previous localized record, if any, for tables with a "sortby" column * Used when new localized records are created so that localized records are sorted in the same order as the default language records * * @param string $table Table name * @param int $uid Uid of default language record * @param int $pid Pid of default language record * @param int $language Language of localization * @return int uid of record after which the localized record should be inserted */ protected function getPreviousLocalizedRecordUid($table, $uid, $pid, $language) { $previousLocalizedRecordUid = $uid; if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['sortby']) { $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby']; $select = $sortRow . ',pid,uid'; // For content elements, we also need the colPos if ($table === 'tt_content') { $select .= ',colPos'; } // Get the sort value of the default language record $row = BackendUtility::getRecord($table, $uid, $select); if (is_array($row)) { // Find the previous record in default language on the same page $where = 'pid=' . (int) $pid . ' AND ' . 'sys_language_uid=0' . ' AND ' . $sortRow . '<' . (int) $row[$sortRow]; // Respect the colPos for content elements if ($table === 'tt_content') { $where .= ' AND colPos=' . (int) $row['colPos']; } $res = $this->databaseConnection->exec_SELECTquery($select, $table, $where . $this->deleteClause($table), '', $sortRow . ' DESC', '1'); // If there is an element, find its localized record in specified localization language if ($previousRow = $this->databaseConnection->sql_fetch_assoc($res)) { $previousLocalizedRecord = BackendUtility::getRecordLocalization($table, $previousRow['uid'], $language); if (is_array($previousLocalizedRecord[0])) { $previousLocalizedRecordUid = $previousLocalizedRecord[0]['uid']; } } $this->databaseConnection->sql_free_result($res); } } return $previousLocalizedRecordUid; }
/** * @param integer $uid * @param integer $languageUid * @return array|NULL */ protected function loadRecordFromDatabase($uid, $languageUid = 0) { $uid = (int) $uid; $languageUid = (int) $languageUid; if (0 === $languageUid) { $record = BackendUtility::getRecord('tt_content', $uid); } else { $record = BackendUtility::getRecordLocalization('tt_content', $uid, $languageUid); } $record = $this->workspacesAwareRecordService->getSingle('tt_content', '*', $record['uid']); return $record; }
/** * Overwrites the localization of a record * if the record does not have the localization, it is copied to the record. * * @param string $table Name of the table in which we overwrite records * @param int $uidCopied Uid of the record that is the overwriter * @param int $uidOverwrite Uid of the record that is to be overwritten * @param int $loc Uid of the syslang that is overwritten * * @return bool Success */ public function overwriteLocale($table, $uidCopied, $uidOverwrite, $loc) { $backendUser = $this->getBackendUser(); // check params if (!is_string($table) || !is_numeric($uidCopied) || !is_numeric($uidOverwrite) || !is_numeric($loc)) { if (TYPO3_DLOG) { GeneralUtility::devLog('copyLocale (belib) gets passed invalid parameters.', COMMERCE_EXTKEY, 3); } return false; } $tableConfig = SettingsFactory::getInstance()->getTcaValue($table); // check if table is defined in the TCA if ($tableConfig && $uidCopied) { // make data $recFrom = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordLocalization($table, $uidCopied, $loc); $recTo = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordLocalization($table, $uidOverwrite, $loc); // if the item is not localized, return if (false == $recFrom) { return true; } // if the overwritten record does not have // the corresponding localization, just copy it if (false == $recTo) { return self::copyLocale($table, $uidCopied, $uidOverwrite, $loc); } // overwrite l18n parent $recFrom[0]['l18n_parent'] = $uidOverwrite; // unset uid for cleanliness unset($recFrom[0]['uid']); // unset all fields that are not supposed to be copied on localized versions foreach ($tableConfig['columns'] as $fN => $fCfg) { // Otherwise, do not copy field (unless it is the // language field or pointer to the original language) if (GeneralUtility::inList('exclude,noCopy,mergeIfNotBlank', $fCfg['l10n_mode']) && $fN != $tableConfig['ctrl']['languageField'] && $fN != $tableConfig['ctrl']['transOrigPointerField']) { unset($recFrom[0][$fN]); } elseif (isset($fCfg['config']['type']) && 'flex' == $fCfg['config']['type'] && isset($recFrom[0][$fN])) { if ($recFrom[0][$fN]) { $recFrom[0][$fN] = GeneralUtility::xml2array($recFrom[0][$fN]); if (trim($recFrom[0][$fN]) == '') { unset($recFrom[0][$fN]); } } else { unset($recFrom[0][$fN]); } } } $data = array(); $data[$table][$recTo[0]['uid']] = $recFrom[0]; // init tce /** * Data handler. * * @var \TYPO3\CMS\Core\DataHandling\DataHandler $tce */ $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler'); $tce->stripslashes_values = 0; $tcaDefaultOverride = $backendUser->getTSConfigProp('TCAdefaults'); if (is_array($tcaDefaultOverride)) { $tce->setDefaultsFromUserTS($tcaDefaultOverride); } // start $tce->start($data, array()); // Write to session that we copy // this is used by the hook to the datamap class to figure out if // it should call the dynaflex so far this is the best (though not // very clean) way to solve the issue we get when saving an article $backendUser->uc['txcommerce_copyProcess'] = 1; $backendUser->writeUC(); $tce->process_datamap(); // copying done, clear session $backendUser->uc['txcommerce_copyProcess'] = 0; $backendUser->writeUC(); // for articles we have to overwrite the attributes if ('tx_commerce_articles' == $table) { self::overwriteArticleAttributes($uidCopied, $uidOverwrite, $loc); } } return true; }
/** * Returning uid of previous localized record, if any, for tables with a "sortby" column * Used when new localized records are created so that localized records are sorted in the same order as the default language records * * This is a port from DataHandler::getPreviousLocalizedRecordUid that respects tx_flux_parent and tx_flux_column! * * @param integer $uid Uid of default language record * @param integer $language Language of localization * @param TYPO3\CMS\Core\DataHandling\DataHandler $datahandler * @return integer uid of record after which the localized record should be inserted */ protected function getPreviousLocalizedRecordUid($uid, $language, DataHandler $reference) { $table = 'tt_content'; $previousLocalizedRecordUid = $uid; $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby']; $select = $sortRow . ',pid,uid,colPos,tx_flux_parent,tx_flux_column'; // Get the sort value of the default language record $row = BackendUtility::getRecord($table, $uid, $select); if (is_array($row)) { // Find the previous record in default language on the same page $where = sprintf('pid=%d AND sys_language_uid=0 AND %s < %d', (int) $row['pid'], $sortRow, (int) $row[$sortRow]); // Respect the colPos for content elements if ($table === 'tt_content') { $where .= sprintf(' AND colPos=%d AND tx_flux_column=\'%s\' AND tx_flux_parent=%d', (int) $row['colPos'], $row['tx_flux_column'], (int) $row['tx_flux_parent']); } $where .= $reference->deleteClause($table); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where, '', $sortRow . ' DESC', '1'); // If there is an element, find its localized record in specified localization language if ($previousRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $previousLocalizedRecord = BackendUtility::getRecordLocalization($table, $previousRow['uid'], $language); if (is_array($previousLocalizedRecord[0])) { $previousLocalizedRecordUid = $previousLocalizedRecord[0]['uid']; } } $GLOBALS['TYPO3_DB']->sql_free_result($res); } return $previousLocalizedRecordUid; }
/** * Get translations * * @param int $l10nParent * @param array $settings * @param array $languages * @return \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult */ public function getTranslations($l10nParent, $settings = array(), $languages = array()) { $translations = array(); foreach ($languages as $language) { if ($language['uid'] > 0) { $translation = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordLocalization('tx_mooxnews_domain_model_news', $l10nParent, $language['uid']); $language[0] = $language['title']; $language[1] = $language['uid']; $language[2] = $language['flagIcon']; if (is_array($translation[0])) { $translation[0]['language'] = $language; $translations[] = $translation[0]; } else { $translations[] = array("notranslation" => true, 'language' => $language); } } } return $translations; /* $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager'); $newsRepository = $objectManager->get('Tx_MooxNews_Domain_Repository_NewsRepository'); return $newsRepository->findTranslations($l10nParent); */ }
/** * Generation of TCEform elements of the type "select" * This will render a selector box element, or possibly a special construction with two selector boxes. * That depends on configuration. * * @param array $PA: * parameter array for the current field * @param object $fobj: * to the parent object * @return string HTML code for the field */ function displayCategoryTree($PA, $fobj) { $table = $PA['table']; $field = $PA['field']; $row = $PA['row']; $config = $PA['fieldConf']['config']; $isPluginFlexform = false; $isBeUserForm = false; $isBeGroupsForm = false; $isCategoryForm = false; $selectedCalendars = array(); $calendarMode = 0; if ($field == 'pi_flexform') { $isPluginFlexform = true; if ($PA['row']['pi_flexform']) { $cfgArr = GeneralUtility::xml2array($PA['row']['pi_flexform']); } else { $cfgArr = array(); } if (is_array($cfgArr) && is_array($cfgArr['data']['s_Cat']['lDEF']) && is_array($cfgArr['data']['s_Cat']['lDEF']['calendarSelection'])) { $selectedCalendars = GeneralUtility::intExplode(',', $cfgArr['data']['s_Cat']['lDEF']['calendarSelection']['vDEF']); } $calendarMode = $cfgArr['data']['s_Cat']['lDEF']['calendarMode']['vDEF']; } $selectedCalendars[] = 0; $selectedCalendars = array_unique($selectedCalendars); if ($table == 'tx_cal_category') { $isCategoryForm = true; } if ($table == 'be_users') { $isBeUserForm = true; } if ($table == 'be_groups') { $isBeGroupsForm = true; } if ($row['calendar_id'] == 0 && !$isCategoryForm && !$isPluginFlexform && !$isBeUserForm && !$isBeGroupsForm) { /* Get the records, with access restrictions and all that good stuff applied. */ $tempCalRes = \TYPO3\CMS\Cal\Backend\TCA\ItemsProcFunc::getSQLResource('tx_cal_calendar', '', '', '', '1'); if ($tempCalRes) { while ($calendarRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($tempCalRes)) { $row['calendar_id'] = $calendarRow['uid']; } $GLOBALS['TYPO3_DB']->sql_free_result($tempCalRes); } } $pidList = array(); if ($isPluginFlexform) { $pagesEntry = $row['pages']; $recursiveEntry = $row['recursive']; $pagesEntryArray = array_unique(explode(',', $pagesEntry)); foreach ($pagesEntryArray as $id) { preg_match('/[a-zA-Z]*_([0-9]*)|[a-zA-Z0-9]*/', $id, $idArray); $list = array(); $this->getTreeList($idArray[1], $recursiveEntry, $list); if ($list) { $pidList[] = implode(',', $list); } } $pidList = implode(',', $pidList); if ($pidList == '') { $pidList = '0'; } } $this->pObj =& $PA['pObj']; // Field configuration from TCA: $config = $PA['fieldConf']['config']; // it seems TCE has a bug and do not work correctly with '1' $config['maxitems'] = $config['maxitems'] == 2 ? 1 : $config['maxitems']; // Getting the selector box items from the system $selItems = $this->pObj->addSelectOptionsToItemArray($this->pObj->initItemArray($PA['fieldConf']), $PA['fieldConf'], $this->pObj->setTSconfig($table, $row), $field); $selItems = $this->pObj->addItems($selItems, $PA['fieldTSConfig']['addItems.']); // f ($config['itemsProcFunc']) $selItems = $this->pObj->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field); // Possibly remove some items: $removeItems = GeneralUtility::trimExplode(',', $PA['fieldTSConfig']['removeItems'], 1); foreach ($selItems as $tk => $p) { if (in_array($p[1], $removeItems)) { unset($selItems[$tk]); } else { if (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) { $selItems[$tk][0] = $this->pObj->sL($PA['fieldTSConfig']['altLabels.'][$p[1]]); } } // Removing doktypes with no access: if ($table . '.' . $field == 'pages.doktype') { if (!($GLOBALS['BE_USER']->isAdmin() || GeneralUtility::inList($GLOBALS['BE_USER']->groupData['pagetypes_select'], $p[1]))) { unset($selItems[$tk]); } } } // Creating the label for the "No Matching Value" entry. $nMV_label = isset($PA['fieldTSConfig']['noMatchingValue_label']) ? $this->pObj->sL($PA['fieldTSConfig']['noMatchingValue_label']) : '[ ' . $this->pObj->getLL('l_noMatchingValue') . ' ]'; $nMV_label = @sprintf($nMV_label, $PA['itemFormElValue']); // Prepare some values: $maxitems = intval($config['maxitems']); $minitems = intval($config['minitems']); $size = intval($config['size']); // If a SINGLE selector box... if ($maxitems <= 1 and !$config['treeView']) { } else { if ($row['sys_language_uid'] && $row['l18n_parent']) { // the current record is a translation of another record if ($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['tx_cal']) { // get tt_news extConf array $confArr = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['tx_cal']); } if ($confArr['useStoragePid']) { $TSconfig = BackendUtility::getTCEFORM_TSconfig($table, $row); $storagePid = $TSconfig['_STORAGE_PID'] ? $TSconfig['_STORAGE_PID'] : 0; $SPaddWhere = ' AND tx_cal_category.pid IN (' . $storagePid . ')'; } $errorMsg = array(); $notAllowedItems = array(); if ($GLOBALS['BE_USER']->getTSConfigVal('options.useListOfAllowedItems') && !$GLOBALS['BE_USER']->isAdmin()) { $notAllowedItems = $this->getNotAllowedItems($PA, $SPaddWhere); } // get categories of the translation original // $catres = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query ('tx_cal_category.uid,tx_cal_category.title,tt_news_cat_mm.sorting AS mmsorting', 'tt_news', 'tt_news_cat_mm', 'tt_news_cat', ' AND tt_news_cat_mm.uid_local='.$row['l18n_parent'].$SPaddWhere,'', 'mmsorting'); $catres = false; if ($table == 'tx_cal_event') { $catres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_cal_category.uid, tx_cal_category.title', 'tx_cal_category,tx_cal_event_category_mm', 'tx_cal_category.uid = tx_cal_event_category_mm.uid_foreign and tx_cal_event_category_mm.uid_local=' . $row['l18n_parent'] . $SPaddWhere); } else { $catres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_cal_category.uid, tx_cal_category.title', 'tx_cal_category', 'tx_cal_category.uid=' . $row['l18n_parent'] . $SPaddWhere); } $categories = array(); $NACats = array(); $na = false; if ($catres) { while ($catrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($catres)) { if (TYPO3_MODE == 'BE' || $GLOBALS['TSFE']->beUserLogin && $GLOBALS['BE_USER']->extAdmEnabled) { $tempRow = BackendUtility::getRecordLocalization('tx_cal_category', $catrow['uid'], $PA['row']['sys_language_uid'], ''); if (is_array($tempRow)) { $catrow = $tempRow[0]; } } if (in_array($catrow['uid'], $notAllowedItems)) { $categories[$catrow['uid']] = $NACats[] = '<p style="padding:0px;color:red;font-weight:bold;">- ' . $catrow['title'] . ' <span class="typo3-dimmed"><em>[' . $catrow['uid'] . ']</em></span></p>'; $na = true; } else { $categories[$catrow['uid']] = '<p style="padding:0px;">- ' . $catrow['title'] . ' <span class="typo3-dimmed"><em>[' . $catrow['uid'] . ']</em></span></p>'; } } $GLOBALS['TYPO3_DB']->sql_free_result($catres); } if ($na) { $this->NA_Items = '<table class="warningbox" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td><img src="gfx/icon_fatalerror.gif" class="absmiddle" alt="" height="16" width="18">SAVING DISABLED!! <br />' . ($row['l18n_parent'] && $row['sys_language_uid'] ? 'The translation original of this' : 'This') . ' record has the following categories assigned that are not defined in your BE usergroup: ' . implode($NACats, chr(10)) . '</td></tr></tbody></table>'; } $item = implode($categories, chr(10)); if ($item) { $item = 'Categories from the translation original of this record:<br />' . $item; } else { $item = 'The translation original of this record has no categories assigned.<br />'; } $item = '<div class="typo3-TCEforms-originalLanguageValue">' . $item . '</div>'; } else { // build tree selector $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '" />'; // Set max and min items: if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 4006000) { $maxitems = MathUtility::forceIntegerInRange($config['maxitems'], 0); if (!$maxitems) { $maxitems = 100000; } $minitems = MathUtility::forceIntegerInRange($config['minitems'], 0); } else { $maxitems = GeneralUtility::forceIntegerInRange($config['maxitems'], 0); if (!$maxitems) { $maxitems = 100000; } $minitems = GeneralUtility::forceIntegerInRange($config['minitems'], 0); } // Register the required number of elements: $this->pObj->requiredElements[$PA['itemFormElName']] = array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field); // ************************************************* // ********************** START ******************** // ************************************************* if ($config['treeView'] and $config['foreign_table']) { $confArr = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['cal']); $treeOrderBy = $confArr['treeOrderBy'] ? $confArr['treeOrderBy'] : 'uid'; if ($GLOBALS['BE_USER']->getTSConfigVal('options.useListOfAllowedItems') && !$GLOBALS['BE_USER']->isAdmin()) { $notAllowedItems = $this->getNotAllowedItems($PA, $SPaddWhere); } if ($table == 'be_users' || $table == 'be_groups') { $allowAllCategories = true; $allowAllCalendars = true; $be_userCategories = array(); $be_userCalendars = array(); if ($row['tx_cal_enable_accesscontroll'] && $row['tx_cal_calendar']) { $allowedCalendarIds = GeneralUtility::intExplode(',', $row['tx_cal_calendar']); $allowedCalendarIds[] = 0; $catWhere = ' AND tx_cal_category.calendar_id in (' . implode(',', $allowedCalendarIds) . ')'; $calWhere = ' AND tx_cal_calendar.uid in (' . implode(',', $allowedCalendarIds) . ')'; } } else { // get default items $defItems = array(); if (is_array($config['items']) && $table == 'tt_content' && $row['CType'] == 'list' && $row['list_type'] == 'cal_controller' && $field == 'pi_flexform') { reset($config['items']); while (list($itemName, $itemValue) = each($config['items'])) { if ($itemValue[0]) { $ITitle = $this->pObj->sL($itemValue[0]); $defItems[] = '<a href="#" onclick="setFormValueFromBrowseWin(\'data[' . $table . '][' . $row['uid'] . '][' . $field . '][data][sDEF][lDEF][categorySelection][vDEF]\',' . $itemValue[1] . ',\'' . $ITitle . '\'); return false;" style="text-decoration:none;">' . $ITitle . '</a>'; } } } $allowAllCategories = true; $allowAllCalendars = true; $be_userCategories = array(); $be_userCalendars = array(); if ($row['calendar_id'] > 0) { if ($isCategoryForm) { $catWhere = ' AND tx_cal_category.calendar_id IN (' . $row['calendar_id'] . ')'; } else { $catWhere = ' AND tx_cal_category.calendar_id IN (0,' . $row['calendar_id'] . ')'; } $calWhere = ' AND tx_cal_calendar.uid IN (0,' . $row['calendar_id'] . ')'; if ($table != 'tx_cal_event') { $notAllowedItems[] = $row['uid']; } if (!$GLOBALS['BE_USER']->user['admin']) { if ($GLOBALS['BE_USER']->user['tx_cal_enable_accesscontroll']) { $be_userCategories = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->user['tx_cal_category'], 1); $be_userCalendars = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->user['tx_cal_calendar'], 1); } if (is_array($GLOBALS['BE_USER']->userGroups)) { foreach ($GLOBALS['BE_USER']->userGroups as $gid => $group) { if ($group['tx_cal_enable_accesscontroll']) { if ($group['tx_cal_category']) { $groupCategories = GeneralUtility::trimExplode(',', $group['tx_cal_category'], 1); $be_userCategories = array_merge($be_userCategories, $groupCategories); } if ($group['tx_cal_calendar']) { $groupCalendars = GeneralUtility::trimExplode(',', $group['tx_cal_calendar'], 1); $be_userCalendars = array_merge($be_userCalendars, $groupCalendars); } } } } if ($be_userCategories[0]) { $allowAllCategories = false; } if ($be_userCalendars[0]) { $allowAllCalendars = false; } } } else { if ($isPluginFlexform && $GLOBALS['BE_USER']->user['tx_cal_enable_accesscontroll'] && !$GLOBALS['BE_USER']->user['admin']) { $allowAllCalendars = false; $allowAllCategories = false; $be_userCategories = array(0); if ($GLOBALS['BE_USER']->user['tx_cal_category']) { $be_userCategories = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->user['tx_cal_category'], 1); } $be_userCalendars = array(0); if ($GLOBALS['BE_USER']->user['tx_cal_calendar']) { $be_userCalendars = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->user['tx_cal_calendar'], 1); } if (is_array($GLOBALS['BE_USER']->userGroups)) { foreach ($GLOBALS['BE_USER']->userGroups as $gid => $group) { if ($group['tx_cal_enable_accesscontroll']) { if ($group['tx_cal_category']) { $groupCategories = GeneralUtility::trimExplode(',', $group['tx_cal_category'], 1); $be_userCategories = array_merge($be_userCategories, $groupCategories); } if ($group['tx_cal_calendar']) { $groupCalendars = GeneralUtility::trimExplode(',', $group['tx_cal_calendar'], 1); $be_userCalendars = array_merge($be_userCalendars, $groupCalendars); } } } } } else { if ($isPluginFlexform && count($selectedCalendars) > 0) { if ($calendarMode == 0) { } else { if ($calendarMode == 1) { $catWhere = ' AND tx_cal_category.calendar_id in (' . implode(',', $selectedCalendars) . ')'; $calWhere = ' AND tx_cal_calendar.uid in (' . implode(',', $selectedCalendars) . ')'; } else { // $calendarMode==2 $selectedCalendars = array_diff($selectedCalendars, array(0)); if (count($selectedCalendars) > 0) { $catWhere = ' AND tx_cal_category.calendar_id not in (' . implode(',', $selectedCalendars) . ')'; $calWhere = ' AND tx_cal_calendar.uid not in (' . implode(',', $selectedCalendars) . ')'; } } } } else { if (count($selectedCalendars) > 0) { $catWhere = ' AND tx_cal_category.calendar_id in (' . implode(',', $selectedCalendars) . ')'; $calWhere = ' AND tx_cal_calendar.uid in (' . implode(',', $selectedCalendars) . ')'; } } } } } $calWhere .= ' AND tx_cal_calendar.sys_language_uid IN (-1,0)'; $catWhere .= ' AND tx_cal_category.sys_language_uid IN (-1,0)'; if ($config['treeViewClass'] and is_object($treeViewObj =& GeneralUtility::getUserObj($config['treeViewClass'], 'user_', false))) { } else { $treeViewObj = new \TYPO3\CMS\Cal\Backend\TCA\TceFuncSelectTreeView(); } if (TYPO3_MODE == 'BE' || $GLOBALS['TSFE']->beUserLogin && $GLOBALS['BE_USER']->extAdmEnabled) { $enableFields = BackendUtility::BEenableFields('tx_cal_category') . ' AND tx_cal_category.deleted = 0'; } else { $enableFields = $this->cObj->enableFields('tx_cal_category'); } $catWhere .= $enableFields; if ($isPluginFlexform) { $catWhere .= ' AND pid IN (' . $pidList . ')'; } $catres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_cal_category.uid, tx_cal_category.title, tx_cal_category.calendar_id, tx_cal_category.parent_category', 'tx_cal_category', '1=1' . $catWhere, $treeOrderBy); $categoryById = array(); $categoryByCalendarId = array(); $categoryByParentId = array(); $allCategoryById = array(); $allCategoryByCalendarId = array(); $allCategoryByParentId = array(); if ($catres) { while ($catrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($catres)) { if (TYPO3_MODE == 'BE' || $GLOBALS['TSFE']->beUserLogin && $GLOBALS['BE_USER']->extAdmEnabled) { $tempRow = BackendUtility::getRecordLocalization('tx_cal_category', $catrow['uid'], $PA['row']['sys_language_uid'], ''); if (is_array($tempRow)) { $catrow = $tempRow[0]; } } if ($allowAllCalendars && $allowAllCategories || ($catrow['calendar_id'] == 0 || in_array($catrow['calendar_id'], $be_userCalendars)) && in_array($catrow['uid'], $be_userCategories)) { $categoryById[$catrow['uid']] = $catrow; $categoryByCalendarId[$catrow['calendar_id']][] = $catrow; $categoryByParentId[$catrow['parent_category']][] = $catrow; } $allCategoryById[$catrow['uid']] = $catrow; $allCategoryByCalendarId[$catrow['calendar_id']][] = $catrow; $allCategoryByParentId[$catrow['parent_category']][] = $catrow; } $GLOBALS['TYPO3_DB']->sql_free_result($catres); } $ids = array(); foreach ($categoryById as $catRow) { $ids = array_merge($ids, $this->checkChildIds($catRow['uid'], $allCategoryByParentId)); } $ids = array_unique($ids); foreach ($ids as $id) { $categoryById[$id] = $allCategoryById[$id]; $categoryByCalendarId[$allCategoryById[$id]['calendar_id']][] = $allCategoryById[$id]; if (in_array($allCategoryById[$id]['parent_category'], $ids) || $categoryById[$allCategoryById[$id]['parent_category']]) { $categoryByParentId[$allCategoryById[$id]['parent_category']][] = $allCategoryById[$id]; } } if (!$allowAllCalendars) { $calWhere .= ' AND uid IN (' . implode(',', $be_userCalendars) . ')'; } if (TYPO3_MODE == 'BE' || $GLOBALS['TSFE']->beUserLogin && $GLOBALS['BE_USER']->extAdmEnabled) { $enableFields = BackendUtility::BEenableFields('tx_cal_calendar') . ' AND tx_cal_calendar.deleted = 0'; } else { $enableFields = $this->cObj->enableFields('tx_cal_calendar'); } $calWhere .= $enableFields; if ($isPluginFlexform) { $calWhere .= ' AND pid IN (' . $pidList . ')'; } $calres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_cal_calendar.uid, tx_cal_calendar.title', 'tx_cal_calendar', '1=1 ' . $calWhere); $calendars = array(); if ($calres) { while ($calrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($calres)) { $calendars[$calrow['uid']] = $calrow; } $GLOBALS['TYPO3_DB']->sql_free_result($calres); } $dataArray = array(); if (count($categoryByCalendarId[0]) > 0) { $treeViewObj->MOUNTS[] = 'cal:global'; $calArray = array(); $calArray['title'] = 'Global Categories:'; $calArray['uid'] = 'cal:global'; foreach ($categoryByCalendarId[0] as $globalCat) { if ($globalCat['parent_category'] == 0 || $isPluginFlexform && !$categoryById[$globalCat['parent_category']]) { $childArray = array('title' => $globalCat['title'], 'uid' => $globalCat['uid']); $this->addChildren($globalCat['uid'], $childArray, $categoryById, $categoryByParentId, $treeViewObj->subLevelID, $notAllowedItems); $calArray[$treeViewObj->subLevelID][$globalCat['uid']] = $childArray; } } $dataArray['cal:global'] = $calArray; } unset($categoryByCalendarId[0]); foreach ($calendars as $calUid => $calendar) { $treeViewObj->MOUNTS[] = 'cal:' . $calUid; $notAllowedItems[] = 'cal:' . $calUid; $calArray = array(); $calArray['title'] = $calendar['title']; $calArray['uid'] = 'cal:' . $calendar['uid']; if ($categoryByCalendarId[$calUid]) { foreach ($categoryByCalendarId[$calUid] as $category) { if ($category['parent_category'] == 0 || $isPluginFlexform && !$categoryById[$category['parent_category']]) { $childArray = array('title' => $category['title'], 'uid' => $category['uid']); $this->addChildren($category['uid'], $childArray, $categoryById, $categoryByParentId, $treeViewObj->subLevelID, $notAllowedItems); $calArray[$treeViewObj->subLevelID][$category['uid']] = $childArray; } } } $dataArray['cal:' . $calUid] = $calArray; } // ################### // $treeViewObj->table = $config['foreign_table']; $treeViewObj->table = 'tx_cal_category'; $treeViewObj->init($SPaddWhere); $treeViewObj->backPath = $this->pObj->backPath; $treeViewObj->setDataFromArray($dataArray); // $treeViewObj->parentField = $GLOBALS['TCA'][$config['foreign_table']]['ctrl']['treeParentField']; // $treeViewObj->parentField = 'parent_category'; // if($row['calendar_id']){ // $treeViewObj->clause = ' AND calendar_id = '.$row['calendar_id']; // } $treeViewObj->expandAll = 1; $treeViewObj->expandFirst = 1; $treeViewObj->fieldArray = array('uid', 'title'); // those fields will be filled to the array $treeViewObj->tree $treeViewObj->ext_IconMode = '1'; // no context menu on icons $treeViewObj->title = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$config['foreign_table']]['ctrl']['title']); $treeViewObj->TCEforms_itemFormElName = $PA['itemFormElName']; if ($table == $config['foreign_table']) { $treeViewObj->TCEforms_nonSelectableItemsArray[] = $row['uid']; } if (is_array($notAllowedItems) && $notAllowedItems[0]) { foreach ($notAllowedItems as $k) { $treeViewObj->TCEforms_nonSelectableItemsArray[] = $k; } } // render tree html $lockBeUserToDBmounts = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']; $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts'] = 0; $treeContent = $treeViewObj->getBrowsableTree(); $treeItemC = count($treeViewObj->dataLookup); $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts'] = $lockBeUserToDBmounts; /* * if ($defItems[0]) { // add default items to the tree table. In this case the value [not categorized] $treeItemC += count($defItems); $treeContent .= '<table border="0" cellpadding="0" cellspacing="0"><tr> <td>'.$this->pObj->sL($config['itemsHeader']).' </td><td>'.implode($defItems,'<br />').'</td> </tr></table>'; } */ // find recursive categories or "storagePid" related errors and if there are some, add a message to the $errorMsg array. $errorMsg = $this->findRecursiveCategories($PA, $row, $table, $storagePid, $treeViewObj->ids); $width = 280; // default width for the field with the category tree if (intval($confArr['categoryTreeWidth'])) { // if a value is set in extConf take this one. if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 4006000) { $width = MathUtility::forceIntegerInRange($confArr['categoryTreeWidth'], 1, 600); } else { $width = GeneralUtility::forceIntegerInRange($confArr['categoryTreeWidth'], 1, 600); } } elseif ($GLOBALS['CLIENT']['BROWSER'] == 'msie') { // to suppress the unneeded horizontal scrollbar IE needs a width of at least 320px $width = 320; } if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 4006000) { $config['autoSizeMax'] = MathUtility::forceIntegerInRange($config['autoSizeMax'], 0); $height = $config['autoSizeMax'] ? MathUtility::forceIntegerInRange($treeItemC + 2, MathUtility::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size; } else { $config['autoSizeMax'] = GeneralUtility::forceIntegerInRange($config['autoSizeMax'], 0); $height = $config['autoSizeMax'] ? GeneralUtility::forceIntegerInRange($treeItemC + 2, GeneralUtility::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size; } // hardcoded: 16 is the height of the icons $height = $height * 16; $divStyle = 'position:relative; left:0px; top:0px; height:' . $height . 'px; width:' . $width . 'px;border:solid 1px;overflow:auto;background:#fff;margin-bottom:5px;'; $thumbnails = '<div name="' . $PA['itemFormElName'] . '_selTree" style="' . htmlspecialchars($divStyle) . '">'; $thumbnails .= $treeContent; $thumbnails .= '</div>'; } else { $sOnChange = 'setFormValueFromBrowseWin(\'' . $PA['itemFormElName'] . '\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); ' . implode('', $PA['fieldChangeFunc']); // Put together the select form with selected elements: $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"' : ' style="' . $this->pObj->defaultMultipleSelectorStyle . '"'; if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 4006000) { $size = $config['autoSizeMax'] ? MathUtility::forceIntegerInRange(count($itemArray) + 1, MathUtility::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size; } else { $size = $config['autoSizeMax'] ? GeneralUtility::forceIntegerInRange(count($itemArray) + 1, GeneralUtility::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size; } $thumbnails = '<select style="width:150px;" name="' . $PA['itemFormElName'] . '_sel"' . $this->pObj->insertDefStyle('select') . ($size ? ' size="' . $size . '"' : '') . ' onchange="' . htmlspecialchars($sOnChange) . '"' . $PA['onFocus'] . $selector_itemListStyle . '>'; // thumbnails = '<select name="'.$PA['itemFormElName'].'_sel"'.$this->pObj->insertDefStyle('select').($size?' size="'.$size.'"':'').' onchange="'.htmlspecialchars($sOnChange).'"'.$PA['onFocus'].$selector_itemListStyle.'>'; foreach ($selItems as $p) { $thumbnails .= '<option value="' . htmlspecialchars($p[1]) . '">' . htmlspecialchars($p[0]) . '</option>'; } $thumbnails .= '</select>'; } // Perform modification of the selected items array: $itemArray = GeneralUtility::trimExplode(',', $PA['itemFormElValue'], 1); foreach ($itemArray as $tk => $tv) { $tvP = explode('|', $tv, 2); if (in_array($tvP[0], $removeItems) && !$PA['fieldTSConfig']['disableNoMatchingValueElement']) { $tvP[1] = rawurlencode($nMV_label); } elseif (isset($PA['fieldTSConfig']['altLabels.'][$tvP[0]])) { $tvP[1] = rawurlencode($this->pObj->sL($PA['fieldTSConfig']['altLabels.'][$tvP[0]])); } else { $tvP[1] = rawurlencode($this->pObj->sL(rawurldecode($tvP[1]))); } $itemArray[$tk] = implode('|', $tvP); } $sWidth = 150; // default width for the left field of the category select if (intval($confArr['categorySelectedWidth'])) { if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 4006000) { $sWidth = MathUtility::forceIntegerInRange($confArr['categorySelectedWidth'], 1, 600); } else { $sWidth = GeneralUtility::forceIntegerInRange($confArr['categorySelectedWidth'], 1, 600); } } if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 7000000) { $params = array('size' => $size, 'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0), 'style' => ' style="width:' . $sWidth . 'px;"', 'dontShowMoveIcons' => $maxitems <= 1, 'maxitems' => $maxitems, 'info' => '', 'headers' => array('selector' => $this->pObj->getLL('l_selected') . ':<br />', 'items' => $this->pObj->getLL('l_items') . ':<br />'), 'noBrowser' => 1, 'rightbox' => $thumbnails, 'foreign_table' => 'tx_cal_category', 'treeConfig' => array('dataProvider' => 'TYPO3\\CMS\\Cal\\TreeProvider\\MixedTreeDataProvider', 'parentField' => 'calendar_id', 'appearance' => array('showHeader' => TRUE, 'allowRecursiveMode' => TRUE, 'expandAll' => TRUE, 'maxLevels' => 99))); } else { if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 4006000) { $params = array('size' => $size, 'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0), 'style' => ' style="width:' . $sWidth . 'px;"', 'dontShowMoveIcons' => $maxitems <= 1, 'maxitems' => $maxitems, 'info' => '', 'headers' => array('selector' => $this->pObj->getLL('l_selected') . ':<br />', 'items' => $this->pObj->getLL('l_items') . ':<br />'), 'noBrowser' => 1, 'thumbnails' => $thumbnails); } else { $params = array('size' => $size, 'autoSizeMax' => GeneralUtility::forceIntegerInRange($config['autoSizeMax'], 0), 'style' => ' style="width:' . $sWidth . 'px;"', 'dontShowMoveIcons' => $maxitems <= 1, 'maxitems' => $maxitems, 'info' => '', 'headers' => array('selector' => $this->pObj->getLL('l_selected') . ':<br />', 'items' => $this->pObj->getLL('l_items') . ':<br />'), 'noBrowser' => 1, 'thumbnails' => $thumbnails); } } if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 7000000) { $treeHelperElement = new TreeHelperElement($this->pObj); $item .= $treeHelperElement->getDbFileIcon($PA['itemFormElName'], '', '', $itemArray, '', $params, $PA['onFocus']); } else { $item .= $this->pObj->dbFileIcons($PA['itemFormElName'], '', '', $itemArray, '', $params, $PA['onFocus']); } // Wizards: $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />'; if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) >= 7000000) { $treeHelperElement = new TreeHelperElement($this->pObj); $item = $treeHelperElement->getRenderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf); $item .= '<style>.t3-icon-blank {width: 18px;height: 30px;}</style>'; } else { $item = $this->pObj->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf); } } } return $this->NA_Items . implode($errorMsg, chr(10)) . $item; }
/** * Returning uid of previous localized record, if any, for tables with a "sortby" column * Used when new localized records are created so that localized records are sorted in the same order as the default language records * * @param string $table Table name * @param int $uid Uid of default language record * @param int $pid Pid of default language record * @param int $language Language of localization * @return int uid of record after which the localized record should be inserted */ protected function getPreviousLocalizedRecordUid($table, $uid, $pid, $language) { $previousLocalizedRecordUid = $uid; if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['sortby']) { $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby']; $select = [$sortRow, 'pid', 'uid']; // For content elements, we also need the colPos if ($table === 'tt_content') { $select[] = 'colPos'; } // Get the sort value of the default language record $row = BackendUtility::getRecord($table, $uid, implode(',', $select)); if (is_array($row)) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $this->addDeleteRestriction($queryBuilder->getRestrictions()->removeAll()); $queryBuilder->select(...$select)->from($table)->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)), $queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)), $queryBuilder->expr()->lt($sortRow, $queryBuilder->createNamedParameter($row[$sortRow], \PDO::PARAM_INT)))->orderBy($sortRow, 'DESC')->setMaxResults(1); if ($table === 'tt_content') { $queryBuilder->andWhere($queryBuilder->expr()->eq('colPos', $queryBuilder->createNamedParameter($row['colPos'], \PDO::PARAM_INT))); } // If there is an element, find its localized record in specified localization language if ($previousRow = $queryBuilder->execute()->fetch()) { $previousLocalizedRecord = BackendUtility::getRecordLocalization($table, $previousRow['uid'], $language); if (is_array($previousLocalizedRecord[0])) { $previousLocalizedRecordUid = $previousLocalizedRecord[0]['uid']; } } } } return $previousLocalizedRecordUid; }