/** * Fetches short title from an iso code * * @deprecated since 6.0, will be removed two versions later - Use \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFieldValue or, better, \SJBR\StaticInfoTables\Utility\LocalizationUtility::translate instead * @param string $tableName: table name * @param string $isoCode: iso code * @param string $language: language code - if not set current default language is used * @param boolean $local: local name only - if set local title is returned * @return string short title */ public static function getTitleFromIsoCode($tableName, $isoCode, $language = '', $local = FALSE) { \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction(); $indentifiers = array(); $indentifiers['iso'] = $isoCode; return parent::getLabelFieldValue($identifiers, $tableName, $language, $local); }
/** * Gets the localized name of the entity * * @return string */ public function getNameLocalized() { $language = LocalizationUtility::getCurrentLanguage(); $labelFields = LocalizationUtility::getLabelFields($this->tableName, $language); foreach ($labelFields as $labelField) { if ($this->_hasProperty($this->columnsMapping[$labelField]['mapOnProperty'])) { $value = $this->_getProperty($this->columnsMapping[$labelField]['mapOnProperty']); if ($value) { $this->nameLocalized = $value; break; } } } return $this->nameLocalized; }
/** * Initialize action. Called before every action method */ public function initializeAction() { $this->settings['baseUrl'] = GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); $mediaElementJsFolder = $this->getFileAbsFileName($this->settings['mediaelementjsFolder']); $this->settings['mediaelementjsFolderRelative'] = $mediaElementJsFolder; if ($this->settings['addHeaderData']) { if ($this->settings['addJQueryLibrary']) { $jQueryLibrary = $mediaElementJsFolder . 'build/jquery.js'; $this->addHeaderData($jQueryLibrary, 'js'); } if ($this->settings['addMediaElementJs']) { $locale = strtolower(LocalizationUtility::getCurrentLanguage()); if ($locale) { $localeFile = $mediaElementJsFolder . sprintf('src/js/me-i18n-locale-%s.js', $locale); if (file_exists($localeFile)) { $this->addHeaderData('var mejs = mejs || {}; (function () { mejs.i18n = { locale: { language: "' . $locale . '", strings: { } } }; })();', 'script'); $this->addHeaderData($localeFile, 'js'); } } $mediaElementJsJavascript = $mediaElementJsFolder . 'build/mediaelement-and-player.min.js'; $this->addHeaderData($mediaElementJsJavascript, 'js'); $mediaElementJsCss = $mediaElementJsFolder . 'build/mediaelementplayer.min.css'; $this->addHeaderData($mediaElementJsCss); if ($this->settings['skin']) { $mediaElementSkinCss = $mediaElementJsFolder . 'build/mejs-skins.css'; $this->addHeaderData($mediaElementSkinCss); } } if ($this->settings['addMediaElementJsInitialization'] && !$this->settings['addMediaElementJsInitializationFile']) { $this->addHeaderData('(function($) { $(document).ready(function() { $(\'video,audio\').mediaelementplayer(); });})(jQuery);', 'script'); } elseif ($this->settings['addMediaElementJsInitializationFile']) { $initializationFile = $this->getFileAbsFileName($this->settings['addMediaElementJsInitializationFile']); $fluidView = $this->objectManager->get(StandaloneView::class); /* @var $fluidView \TYPO3\CMS\Fluid\View\StandaloneView */ $fluidView->assign('settings', $this->settings); $fluidView->setTemplatePathAndFilename($initializationFile); $fluidView->setPartialRootPath(dirname($initializationFile)); $this->addHeaderData($fluidView->render(), 'none'); } } }
/** * Getting all languages into an array * where the key is the ISO alpha-2 code of the language * and where the value are the name of the language in the current language * Note: we exclude sacred and constructed languages * * @return array An array of names of languages */ protected function getLanguages() { $databaseConnection = $this->getDatabaseConnection(); $nameArray = array(); if (ExtensionManagementUtility::isLoaded('static_info_tables')) { $where = '1=1'; $table = 'static_languages'; $lang = LocalizationUtility::getCurrentLanguage(); $titleFields = LocalizationUtility::getLabelFields($table, $lang); $prefixedTitleFields = array(); foreach ($titleFields as $titleField) { $prefixedTitleFields[] = $table . '.' . $titleField; } $labelFields = implode(',', $prefixedTitleFields); // Restrict to certain languages if (is_array($this->configuration['thisConfig']['buttons.']) && is_array($this->configuration['thisConfig']['buttons.']['language.']) && isset($this->configuration['thisConfig']['buttons.']['language.']['restrictToItems'])) { $languageList = implode('\',\'', GeneralUtility::trimExplode(',', $databaseConnection->fullQuoteStr(strtoupper($this->configuration['thisConfig']['buttons.']['language.']['restrictToItems']), $table))); $where .= ' AND ' . $table . '.lg_iso_2 IN (' . $languageList . ')'; } $res = $databaseConnection->exec_SELECTquery($table . '.lg_iso_2,' . $table . '.lg_country_iso_2,' . $labelFields, $table, $where . ' AND lg_constructed = 0 ' . BackendUtility::BEenableFields($table) . BackendUtility::deleteClause($table)); $prefixLabelWithCode = (bool) $this->configuration['thisConfig']['buttons.']['language.']['prefixLabelWithCode']; $postfixLabelWithCode = (bool) $this->configuration['thisConfig']['buttons.']['language.']['postfixLabelWithCode']; while ($row = $databaseConnection->sql_fetch_assoc($res)) { $code = strtolower($row['lg_iso_2']) . ($row['lg_country_iso_2'] ? '-' . strtoupper($row['lg_country_iso_2']) : ''); foreach ($titleFields as $titleField) { if ($row[$titleField]) { $nameArray[$code] = $prefixLabelWithCode ? $code . ' - ' . $row[$titleField] : ($postfixLabelWithCode ? $row[$titleField] . ' - ' . $code : $row[$titleField]); break; } } } $databaseConnection->sql_free_result($res); uasort($nameArray, 'strcoll'); } return $nameArray; }
/** * Getting all languages into an array * where the key is the ISO alpha-2 code of the language * and where the value are the name of the language in the current language * Note: we exclude sacred and constructed languages * * @return array An array of names of languages * @todo Define visibility */ public function getLanguages() { $nameArray = array(); if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) { $where = '1=1'; $table = 'static_languages'; $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getCurrentLanguage(); $titleFields = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFields($table, $lang); $prefixedTitleFields = array(); foreach ($titleFields as $titleField) { $prefixedTitleFields[] = $table . '.' . $titleField; } $labelFields = implode(',', $prefixedTitleFields); // Restrict to certain languages if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['language.']) && isset($this->thisConfig['buttons.']['language.']['restrictToItems'])) { $languageList = implode('\',\'', \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($this->thisConfig['buttons.']['language.']['restrictToItems']), $table))); $where .= ' AND ' . $table . '.lg_iso_2 IN (' . $languageList . ')'; } $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($table . '.lg_iso_2,' . $table . '.lg_country_iso_2,' . $labelFields, $table, $where . ' AND lg_constructed = 0 ' . ($this->htmlAreaRTE->is_FE() ? $GLOBALS['TSFE']->sys_page->enableFields($table) : \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($table) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table))); $prefixLabelWithCode = (bool) $this->thisConfig['buttons.']['language.']['prefixLabelWithCode']; $postfixLabelWithCode = (bool) $this->thisConfig['buttons.']['language.']['postfixLabelWithCode']; while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $code = strtolower($row['lg_iso_2']) . ($row['lg_country_iso_2'] ? '-' . strtoupper($row['lg_country_iso_2']) : ''); foreach ($titleFields as $titleField) { if ($row[$titleField]) { $nameArray[$code] = $prefixLabelWithCode ? $code . ' - ' . $row[$titleField] : ($postfixLabelWithCode ? $row[$titleField] . ' - ' . $code : $row[$titleField]); break; } } } $GLOBALS['TYPO3_DB']->sql_free_result($res); uasort($nameArray, 'strcoll'); } return $nameArray; }
/** * Getting all languages into an array * where the key is the ISO alpha-2 code of the language * and where the value are the name of the language in the current language * Note: we exclude sacred and constructed languages * * @return array An array of names of languages */ protected function getLanguages() { $nameArray = []; if (ExtensionManagementUtility::isLoaded('static_info_tables')) { $table = 'static_languages'; $lang = LocalizationUtility::getCurrentLanguage(); $titleFields = LocalizationUtility::getLabelFields($table, $lang); $labelFields = []; foreach ($titleFields as $titleField) { $labelFields[] = $table . '.' . $titleField; } $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $queryBuilder->select($table . '.lg_iso_2', $table . '.lg_country_iso_2')->addSelect(...$labelFields)->from($table)->where($queryBuilder->expr()->eq('lg_constructed', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))); // Restrict to certain languages if (is_array($this->configuration['thisConfig']['buttons.']) && is_array($this->configuration['thisConfig']['buttons.']['language.']) && isset($this->configuration['thisConfig']['buttons.']['language.']['restrictToItems'])) { $languageList = GeneralUtility::trimExplode(',', strtoupper($this->configuration['thisConfig']['buttons.']['language.']['restrictToItems'])); $queryBuilder->andWhere($queryBuilder->expr()->in($table . '.lg_iso_2', $queryBuilder->createNamedParameter($languageList, Connection::PARAM_STR_ARRAY))); } $result = $queryBuilder->execute(); $prefixLabelWithCode = (bool) $this->configuration['thisConfig']['buttons.']['language.']['prefixLabelWithCode']; $postfixLabelWithCode = (bool) $this->configuration['thisConfig']['buttons.']['language.']['postfixLabelWithCode']; while ($row = $result->fetch()) { $code = strtolower($row['lg_iso_2']) . ($row['lg_country_iso_2'] ? '-' . strtoupper($row['lg_country_iso_2']) : ''); foreach ($titleFields as $titleField) { if ($row[$titleField]) { $nameArray[$code] = $prefixLabelWithCode ? $code . ' - ' . $row[$titleField] : ($postfixLabelWithCode ? $row[$titleField] . ' - ' . $code : $row[$titleField]); break; } } } uasort($nameArray, 'strcoll'); } return $nameArray; }
/** * Translate selector items array * * @param string $itemFormElValue: value of the form element * @param string $tableName: name of static info tables * @return string value of the form element with translated labels */ protected function translateSelectedItems($itemFormElValue, $tableName) { // Get the array with selected items: $itemArray = GeneralUtility::trimExplode(',', $itemFormElValue, 1); // Perform modification of the selected items array: foreach ($itemArray as $tk => $tv) { $tvP = explode('|', $tv, 2); if ($tvP[0]) { //Get isocode if present $code = strstr($tvP[1], '%28'); $code2 = strstr(substr($code, 1), '%28'); $code = $code2 ? $code2 : $code; // Translate $tvP[1] = LocalizationUtility::translate(array('uid' => $tvP[0]), $tableName); // Re-append isocode, if present $tvP[1] = $tvP[1] . ($code ? '%20' . $code : ''); } $itemArray[$tk] = implode('|', $tvP); } return implode(',', $itemArray); }
/** * Formatting an address in the format specified * * @param string $delim A delimiter for the fields of the returned address * @param string $streetAddress A street address * @param string $city A city * @param string $zip A zip code * @param string $subdivisionCode A ISO alpha-3 country code (cn_iso_3) * @param string $countryCode A zip code A country subdivision code (zn_code) * @return string The formated address using the country address format (cn_address_format) */ function formatAddress($delim, $streetAddress, $city, $zip, $subdivisionCode = '', $countryCode = '') { if (TYPO3_MODE == 'FE') { /** @var \SJBR\StaticInfoTables\PiBaseApi $staticInfoObj */ $staticInfoObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SJBR\StaticInfoTables\PiBaseApi::class); if ($staticInfoObj->needsInit()) { $staticInfoObj->init(); } return $staticInfoObj->formatAddress($delim, $streetAddress, $city, $zip, $subdivisionCode, $countryCode); } $conf = $this->loadTypoScriptForBEModule('tx_staticinfotables_pi1'); global $TYPO3_DB; $formatedAddress = ''; $countryCode = $countryCode ? trim($countryCode) : $this->defaultCountry; $subdivisionCode = $subdivisionCode ? trim($subdivisionCode) : ($countryCode == $this->defaultCountry ? $this->defaultCountryZone : ''); // Get country name $countryName = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFieldValue($countryCode, 'static_countries', '', FALSE); if (!$countryName) { return $formatedAddress; } // Get address format $res = $TYPO3_DB->exec_SELECTquery('cn_address_format', 'static_countries', 'cn_iso_3=' . $TYPO3_DB->fullQuoteStr($countryCode, 'static_countries')); $row = $TYPO3_DB->sql_fetch_assoc($res); $TYPO3_DB->sql_free_result($res); $addressFormat = $row['cn_address_format']; // Format the address $formatedAddress = $conf['addressFormat.'][$addressFormat]; $formatedAddress = str_replace('%street', $streetAddress, $formatedAddress); $formatedAddress = str_replace('%city', $city, $formatedAddress); $formatedAddress = str_replace('%zip', $zip, $formatedAddress); $formatedAddress = str_replace('%countrySubdivisionCode', $subdivisionCode, $formatedAddress); $formatedAddress = str_replace('%countrySubdivisionName', $subdivisionCode, $formatedAddress); $formatedAddress = str_replace('%countryName', strtoupper($countryName), $formatedAddress); $formatedAddress = implode($delim, \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(';', $formatedAddress, 1)); return $formatedAddress; }
/** * Manipulate a record before using it to render the selector; may be used to replace a MM-relation etc. * * @param array $row */ protected function manipulateRecord(&$row) { // Localize the record $row[$GLOBALS['TCA'][$this->table]['ctrl']['label']] = LocalizationUtility::translate(array('uid' => $row['uid']), $this->table); }
/** * Getting all languages into an array * where the key is the ISO alpha-2 code of the language * and where the value are the name of the language in the current language * Note: we exclude sacred and constructed languages * * @param string additional WHERE clause * @return array An array of names of languages */ public function initLanguages($addWhere = '') { $where = '1=1' . ($addWhere ? ' AND ' . $addWhere : ''); $table = $this->tables['LANGUAGES']; $lang = LocalizationUtility::getCurrentLanguage(); $lang = LocalizationUtility::getIsoLanguageKey($lang); $nameArray = array(); $titleFields = LocalizationUtility::getLabelFields($table, $lang); $prefixedTitleFields = array(); foreach ($titleFields as $titleField) { $prefixedTitleFields[] = $table . '.' . $titleField; } $labelFields = implode(',', $prefixedTitleFields); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($table . '.lg_iso_2,' . $table . '.lg_country_iso_2,' . $labelFields, $table, $where . ' AND lg_sacred = 0 AND lg_constructed = 0 ' . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($table)); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $code = $row['lg_iso_2'] . ($row['lg_country_iso_2'] ? '_' . $row['lg_country_iso_2'] : ''); foreach ($titleFields as $titleField) { if ($row[$titleField]) { $nameArray[$code] = $row[$titleField]; break; } } } $GLOBALS['TYPO3_DB']->sql_free_result($res); uasort($nameArray, 'strcoll'); return $nameArray; }
/** * Returns the default country as localized string. * * @return string the default country's localized name, will be empty if there is no default country */ private function getDefaultCountry() { $defaultCountryCode = tx_oelib_ConfigurationRegistry::get('plugin.tx_staticinfotables_pi1')->getAsString('countryCode'); if ($defaultCountryCode === '') { return ''; } $this->initStaticInfo(); if (class_exists('SJBR\\StaticInfoTables\\Utility\\LocalizationUtility', TRUE)) { $currentLanguageCode = Tx_Oelib_ConfigurationRegistry::get('config')->getAsString('language'); $identifiers = array('iso' => $defaultCountryCode); $result = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFieldValue($identifiers, 'static_countries', $currentLanguageCode, TRUE); } else { $result = tx_staticinfotables_div::getTitleFromIsoCode('static_countries', $defaultCountryCode, $this->staticInfo->getCurrentLanguage(), TRUE); } return $result; }
public function getCountryzoneMarker(&$template, &$sims, &$rems) { // Initialise static info library $sims['###COUNTRYZONE###'] = ''; $sims['###COUNTRYZONE_VALUE###'] = ''; if ($this->isAllowed('countryzone')) { if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) { $staticInfo = \TYPO3\CMS\Cal\Utility\Functions::makeInstance('tx_staticinfotables_pi1'); $staticInfo->init(); $current = \SJBR\StaticInfoTables\Utility\LocalizationUtility::translate(array('uid' => $this->object->getCountryzone()), 'static_country_zones', FALSE); $sims['###COUNTRYZONE###'] = $this->applyStdWrap($current, 'countryzone_static_info_stdWrap'); $sims['###COUNTRYZONE_VALUE###'] = $this->object->getCountryZone(); } else { $sims['###COUNTRYZONE###'] = $this->applyStdWrap($this->object->getCountryZone(), 'countryzone_stdWrap'); $sims['###COUNTRYZONE_VALUE###'] = $this->object->getCountryZone(); } } }
/** * Sort entities by the localized name * * @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $entities to be sorted * @param string $orderDirection may be "asc" or "desc". Default is "asc". * @return array entities ordered by localized name */ public function localizedSort(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $entities, $orderDirection = 'asc') { $result = $entities->toArray(); $locale = \SJBR\StaticInfoTables\Utility\LocalizationUtility::setCollatingLocale(); if ($locale !== FALSE) { if ($orderDirection === 'asc') { uasort($result, array($this, 'strcollOnLocalizedName')); } else { uasort($result, array($this, 'strcollOnLocalizedNameDesc')); } } return $result; }
/** * Translate selector items array * * @param array $items: array of value/label pairs * @param string $tableName: name of static info tables * @return array array of value/translated label pairs */ protected function translateSelectorItems($items, $tableName) { $translatedItems = $items; if (isset($translatedItems) && is_array($translatedItems)) { foreach ($translatedItems as $key => $item) { if ($translatedItems[$key][1]) { //Get isocode if present $code = strstr($item[0], '('); $code2 = strstr(substr($code, 1), '('); $code = $code2 ? $code2 : $code; // Translate $translatedItems[$key][0] = LocalizationUtility::translate(array('uid' => $item[1]), $tableName); // Re-append isocode, if present $translatedItems[$key][0] = $translatedItems[$key][0] . ($code ? ' ' . $code : ''); } } $currentLocale = setlocale(LC_COLLATE, '0'); $locale = LocalizationUtility::setCollatingLocale(); if ($locale !== FALSE) { uasort($translatedItems, array($this, 'strcollOnLabels')); } setlocale(LC_COLLATE, $currentLocale); } $items = $translatedItems; return $items; }
function getCountryZoneMarker(&$template, &$sims, &$rems, &$wrapped, $view) { $this->initLocalCObject(); if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) { $staticInfo = \TYPO3\CMS\Cal\Utility\Functions::makeInstance('tx_staticinfotables_pi1'); $staticInfo->init(); $current = \SJBR\StaticInfoTables\Utility\LocalizationUtility::translate(array('uid' => $this->getCountryzone()), 'static_country_zones', FALSE); $this->local_cObj->setCurrentVal($current); $sims['###COUNTRYZONE###'] = $this->local_cObj->cObjGetSingle($this->conf['view.'][$this->conf['view'] . '.'][$this->getObjectType() . '.']['countryzoneStaticInfo'], $this->conf['view.'][$this->conf['view'] . '.'][$this->getObjectType() . '.']['countryzoneStaticInfo.']); } else { $current = $this->getCountryzone(); $this->local_cObj->setCurrentVal($current); $sims['###COUNTRYZONE###'] = $this->local_cObj->cObjGetSingle($this->conf['view.'][$this->conf['view'] . '.'][$this->getObjectType() . '.']['countryzone'], $this->conf['view.'][$this->conf['view'] . '.'][$this->getObjectType() . '.']['countryzone.']); } }