Resolves #45809: Refactor code and introduce namespacing
authorstan <stan@735d13b6-9817-0410-8766-e36946ffe9aa>
Mon, 25 Feb 2013 01:54:01 +0000 (01:54 +0000)
committerstan <stan@735d13b6-9817-0410-8766-e36946ffe9aa>
Mon, 25 Feb 2013 01:54:01 +0000 (01:54 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/static_info_tables/trunk@71492 735d13b6-9817-0410-8766-e36946ffe9aa

18 files changed:
ChangeLog
Classes/Hook/Backend/Form/ElementRenderingHelper.php [new file with mode: 0644]
Classes/Hook/Backend/Form/class.tx_staticinfotables_renderElement.php [deleted file]
Classes/Hook/Core/DataHandling/ProcessDataMap.php [new file with mode: 0644]
Classes/Hook/Core/DataHandling/class.tx_staticinfotables_processdatamap.php [deleted file]
Classes/PiBaseApi.php [new file with mode: 0644]
Classes/Utility/EntityLabelUtility.php [new file with mode: 0644]
Classes/Utility/LocalizationUtility.php [new file with mode: 0644]
Classes/Utility/TcaUtility.php [new file with mode: 0644]
class.tx_staticinfotables_div.php [deleted file]
class.tx_staticinfotables_syslanguage.php
doc/manual.sxw
ext_autoload.php
ext_emconf.php
ext_localconf.php
ext_tables.php
pi1/class.tx_staticinfotables_pi1.php
tca.php

index 7de16df..7b0123e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-02-24  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Resolves #45809: Refactor code and introduce namespacing
+
 2013-02-22  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Resolves #45738: Connect static_country_zones to static_countries
diff --git a/Classes/Hook/Backend/Form/ElementRenderingHelper.php b/Classes/Hook/Backend/Form/ElementRenderingHelper.php
new file mode 100644 (file)
index 0000000..6ccabcf
--- /dev/null
@@ -0,0 +1,167 @@
+<?php
+namespace SJBR\StaticInfoTables\Hook\Backend\Form;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  All rights reserved
+*
+*  This script is part of the Typo3 project. The Typo3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+/**
+ * Custom rendering of some backend forms elements
+ *
+ */
+class ElementRenderingHelper {
+
+       /*
+        * Add ISO codes to the label of entities
+        */
+       public function addIsoCodeToLabel ($PA, $fObj) {
+               $PA['title'] = $PA['row'][$GLOBALS['TCA'][$PA['table']]['ctrl']['label']];
+               if (TYPO3_MODE == 'BE') {
+                       switch ($PA['table']) {
+                               case 'static_territories':
+                               case 'cc_static_territories':
+                                       $isoCode = $PA['row']['tr_iso_nr'];
+                                       if (!$isoCode) {
+                                               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                                       'uid,tr_iso_nr',
+                                                       $PA['table'],
+                                                       'uid = ' . intval($PA['row']['uid']) . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($PA['table'])
+                                               );
+                                               $isoCode = $rows[0]['tr_iso_nr'];
+                                       }
+                                       if ($isoCode) {
+                                               $PA['title'] = $PA['title'] . ' (' . $isoCode . ')';
+                                       }
+                                       break;
+                               case 'static_countries':
+                               case 'cc_static_countries':
+                                       $isoCode = $PA['row']['cn_iso_2'];
+                                       if (!$isoCode) {
+                                               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                                       'uid,cn_iso_2',
+                                                       $PA['table'],
+                                                       'uid = ' . intval($PA['row']['uid']) . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($PA['table'])
+                                               );
+                                               $isoCode = $rows[0]['cn_iso_2'];
+                                       }
+                                       if ($isoCode) {
+                                               $PA['title'] = $PA['title'] . ' (' . $isoCode . ')';
+                                       }
+                                       break;
+                               case 'static_languages':
+                               case 'cc_static_languages':
+                                       $isoCodes = array($PA['row']['lg_iso_2']);
+                                       if ($PA['row']['lg_country_iso_2']) {
+                                               $isoCodes[] = $PA['row']['lg_country_iso_2'];
+                                       }
+                                       $isoCode = implode('_', $isoCodes);
+                                       if (!$isoCode || !$PA['row']['lg_country_iso_2']) {
+                                               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                                       'uid,lg_iso_2,lg_country_iso_2',
+                                                       $PA['table'],
+                                                       'uid = ' . intval($PA['row']['uid']) . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($PA['table'])
+                                               );
+                                               $isoCodes = array($rows[0]['lg_iso_2']);
+                                               if ($rows[0]['lg_country_iso_2']) {
+                                                       $isoCodes[] = $rows[0]['lg_country_iso_2'];
+                                               }
+                                               $isoCode = implode('_', $isoCodes);     
+                                       }
+                                       if ($isoCode) {
+                                               $PA['title'] = $PA['title'] . ' (' . $isoCode . ')';
+                                       }
+                                       break;
+                               case 'static_currencies':
+                               case 'cc_static_currencies':
+                                       $isoCode = $PA['row']['cu_iso_3'];
+                                       if (!$isoCode) {
+                                               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                                       'uid,cu_iso_3',
+                                                       $PA['table'],
+                                                       'uid = ' . intval($PA['row']['uid']) . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($PA['table'])
+                                               );
+                                               $isoCode = $rows[0]['cu_iso_3'];
+                                       }
+                                       if ($isoCode) {
+                                               $PA['title'] = $PA['title'] . ' (' . $isoCode . ')';
+                                       }
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+       }
+
+       /*
+        * Translate and sort the territories selector using the current locale
+        */
+       public function translateTerritoriesSelector ($PA, $fObj) {
+               switch ($PA['table']) {
+                       case 'static_territories':
+                       case 'cc_static_territories':
+                               // Avoid circular relation
+                               $row = $PA['row'];
+                               foreach ($PA['items'] as $index => $item) {
+                                       if ($item[1] == $row['uid']) {
+                                               unset($PA['items'][$index]);
+                                       }
+                               }
+                               break;
+               }
+               foreach ($PA['items'] as $index => $item) {
+                       if ($PA['items'][$index][1]) {
+                               $PA['items'][$index][0] = \SJBR\StaticInfoTables\Utility\LocalizationUtility::translate(array('uid' => $item[1]), 'static_territories');
+                       }
+               }
+               asort($PA['items']);
+       }
+
+       /*
+        * Translate and sort the currencies selector using the current locale
+        */
+       public function translateCurrenciesSelector ($PA, $fObj) {
+               foreach ($PA['items'] as $index => $item) {
+                       if ($PA['items'][$index][1]) {
+                               $PA['items'][$index][0] = \SJBR\StaticInfoTables\Utility\LocalizationUtility::translate(array('uid' => $item[1]), 'static_currencies');
+                       }
+               }
+               asort($PA['items']);
+       }
+
+       /*
+        * Translate and sort the languages selector using the current locale
+        */
+       public function translateLanguagesSelector ($PA, $fObj) {
+               foreach ($PA['items'] as $index => $item) {
+                       if ($PA['items'][$index][1]) {
+                               //Get isocode if present
+                               $code = strstr($item[0], '(');
+                               $code2 = strstr(substr($code, 1), '(');
+                               $code = $code2 ? $code2 : $code;
+                               // Translate
+                               $PA['items'][$index][0] = \SJBR\StaticInfoTables\Utility\LocalizationUtility::translate(array('uid' => $item[1]), 'static_languages');
+                               // Re-append isocode, if present
+                               $PA['items'][$index][0] = $PA['items'][$index][0] . ($code ? ' ' . $code : '');
+                       }
+               }
+               asort($PA['items']);
+       }
+}
+?>
diff --git a/Classes/Hook/Backend/Form/class.tx_staticinfotables_renderElement.php b/Classes/Hook/Backend/Form/class.tx_staticinfotables_renderElement.php
deleted file mode 100644 (file)
index ff35530..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-<?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
-*  All rights reserved
-*
-*  This script is part of the Typo3 project. The Typo3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
-/**
- * Custom rendering of some backend forms elements
- *
- */
-class tx_staticinfotables_renderElement {
-
-       /*
-        * Add ISO codes to the label of entities
-        */
-       public function addIsoCodeToLabel ($PA, $fObj) {
-               $PA['title'] = $PA['row'][$GLOBALS['TCA'][$PA['table']]['ctrl']['label']];
-               if (TYPO3_MODE == 'BE') {
-                       switch ($PA['table']) {
-                               case 'static_territories':
-                               case 'cc_static_territories':
-                                       $isoCode = $PA['row']['tr_iso_nr']; 
-                                       if (!$isoCode) {
-                                               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                                       'uid,tr_iso_nr',
-                                                       $PA['table'],
-                                                       'uid = ' . intval($PA['row']['uid']) . t3lib_befunc::deleteClause($PA['table'])
-                                               );
-                                               $isoCode = $rows[0]['tr_iso_nr'];
-                                       }
-                                       if ($isoCode) {
-                                               $PA['title'] = tx_staticinfotables_div::getTitleFromIsoCode($PA['table'], $isoCode) . ' (' . $isoCode . ')';
-                                       }
-                                       break;
-                               case 'static_countries':
-                               case 'cc_static_countries':
-                                       $isoCode = $PA['row']['cn_iso_2']; 
-                                       if (!$isoCode) {
-                                               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                                       'uid,cn_iso_2',
-                                                       $PA['table'],
-                                                       'uid = ' . intval($PA['row']['uid']) . t3lib_befunc::deleteClause($PA['table'])
-                                               );
-                                               $isoCode = $rows[0]['cn_iso_2'];
-                                       }
-                                       if ($isoCode) {
-                                               $PA['title'] = tx_staticinfotables_div::getTitleFromIsoCode($PA['table'], $isoCode) . ' (' . $isoCode . ')';
-                                       }
-                                       break;
-                               case 'static_currencies':
-                               case 'cc_static_currencies':
-                                       $isoCode = $PA['row']['cu_iso_3'];
-                                       if (!$isoCode) {
-                                               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                                       'uid,cu_iso_3',
-                                                       $PA['table'],
-                                                       'uid = ' . intval($PA['row']['uid']) . t3lib_befunc::deleteClause($PA['table'])
-                                               );
-                                               $isoCode = $rows[0]['cu_iso_3'];
-                                       }
-                                       if ($isoCode) {
-                                               $PA['title'] = tx_staticinfotables_div::getTitleFromIsoCode($PA['table'], $isoCode) . ' (' . $isoCode . ')';
-                                       }
-                                       break;
-                               default:
-                                       break;
-                       }
-               }
-       }
-
-       /*
-        * Sort the territories selector using the current locale
-        */
-       public function sortTerritoriesSelector ($PA, $fObj) {
-               switch ($PA['table']) {
-                       case 'static_territories':
-                       case 'cc_static_territories':
-                               // Avoid circular relation
-                               $row = $PA['row'];
-                               foreach ($PA['items'] as $index => $item) {
-                                       if ($item[1] == $row['uid']) {
-                                               unset($PA['items'][$index]);
-                                       }
-                               }
-                       case 'static_countries':
-                       case 'cc_static_countries':
-                               asort($PA['items']);
-                               break;
-               }
-       }
-
-       /*
-        * Sort the currencies selector using the current locale
-        */
-       public function sortCurrenciesSelector ($PA, $fObj) {
-               switch ($PA['table']) {
-                       case 'static_currencies':
-                       case 'cc_static_currencies':
-                               asort($PA['items']);
-                               break;
-               }
-       }
-}
-?>
diff --git a/Classes/Hook/Core/DataHandling/ProcessDataMap.php b/Classes/Hook/Core/DataHandling/ProcessDataMap.php
new file mode 100644 (file)
index 0000000..0f7dbdf
--- /dev/null
@@ -0,0 +1,127 @@
+<?php
+namespace SJBR\StaticInfoTables\Hook\Core\DataHandling;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  All rights reserved
+*
+*  This script is part of the Typo3 project. The Typo3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+/**
+ * Hook on Core/DataHandling/DataHandler to manage redundancy of ISO codes in static info tables
+ */
+class ProcessDataMap {
+
+       /**
+        * Post-process redundant ISO codes fields
+        *
+        * @param       object          $fobj TCEmain object reference
+        * @return      void
+        */
+       public function processDatamap_postProcessFieldArray ($status, $table, $id, &$incomingFieldArray, &$fObj) {
+               switch ($table) {
+                       case 'static_territories':
+                       case 'cc_static_territories':
+                               //Post-process containing territory ISO numeric code
+                               $tablePrefix = ($table == 'cc_static_territories' ? 'cc_': '');
+                               if ($incomingFieldArray['tr_parent_territory_uid']) {
+                                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                               'uid,tr_iso_nr',
+                                               $tablePrefix . 'static_territories',
+                                               'uid = ' . intval($incomingFieldArray['tr_parent_territory_uid']) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($tablePrefix . 'static_territories')
+                                       );
+                                       $incomingFieldArray['tr_parent_iso_nr'] = $rows[0]['tr_iso_nr'];
+                               } else if (isset($incomingFieldArray['tr_parent_territory_uid'])) {
+                                       $incomingFieldArray['tr_parent_iso_nr'] = 0;
+                               }
+                               break;
+                       case 'static_countries':
+                       case 'cc_static_countries':
+                               $tablePrefix = ($table == 'cc_static_countries' ? 'cc_': '');
+                               //Post-process containing territory ISO numeric code
+                               if ($incomingFieldArray['cn_parent_territory_uid']) {
+                                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                               'uid,tr_iso_nr',
+                                               $tablePrefix . 'static_territories',
+                                               'uid = ' . intval($incomingFieldArray['cn_parent_territory_uid']) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($tablePrefix . 'static_territories')
+                                       );
+                                       $incomingFieldArray['cn_parent_tr_iso_nr'] = $rows[0]['tr_iso_nr'];
+                               } else if (isset($incomingFieldArray['cn_parent_territory_uid'])) {
+                                       $incomingFieldArray['cn_parent_tr_iso_nr'] = 0;
+                               }
+                               //Post-process currency ISO numeric and A3 codes
+                               if ($incomingFieldArray['cn_currency_uid']) {
+                                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                               'uid,cu_iso_nr,cu_iso_3',
+                                               $tablePrefix . 'static_currencies',
+                                               'uid = ' . intval($incomingFieldArray['cn_currency_uid']) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($tablePrefix . 'static_currencies')
+                                       );
+                                       $incomingFieldArray['cn_currency_iso_nr'] = $rows[0]['cu_iso_nr'];
+                                       $incomingFieldArray['cn_currency_iso_3'] = $rows[0]['cu_iso_3'];
+                               } else if (isset($incomingFieldArray['cn_currency_uid'])) {
+                                       $incomingFieldArray['cn_currency_iso_nr'] = 0;
+                                       $incomingFieldArray['cn_currency_iso_3'] = '';
+                               }
+                               break;                  
+               }
+       }
+       /**
+        * Post-process redundant ISO codes fields of IRRE child
+        *
+        * @param       object          $fobj TCEmain object reference
+        * @return      void
+        */
+       public function processDatamap_afterDatabaseOperations ($status, $table, $id, &$fieldArray, &$fObj) {
+               switch ($table) {
+                       case 'static_countries':
+                       case 'cc_static_countries':
+                               //Post-process country ISO numeric, A2 and A3 codes on country zones
+                               $tablePrefix = ($table == 'cc_static_countries' ? 'cc_': '');
+                               // Get the country record uid
+                               if ($status == 'new') {
+                                       $id = $fObj->substNEWwithIDs[$id];
+                               }
+                               // Get the country zones
+                               $countryZones = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                       '*',
+                                       $tablePrefix . 'static_country_zones',
+                                       'zn_country_uid = ' . intval($id) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($tablePrefix . 'static_country_zones')
+                               );
+                               if (is_array($countryZones) && count($countryZones)) {
+                                       $countries = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                               'uid,cn_iso_nr,cn_iso_2,cn_iso_3',
+                                               $table,
+                                               'uid = ' . intval($id) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table)
+                                       );
+                                       foreach ($countryZones as $countryZone) {
+                                               $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
+                                                       $tablePrefix . 'static_country_zones',
+                                                       'uid = ' . intval($countryZone['uid']),
+                                                       array (
+                                                               'zn_country_iso_nr' => intval($countries[0]['cn_iso_nr']),
+                                                               'zn_country_iso_2' => $countries[0]['cn_iso_2'],
+                                                               'zn_country_iso_3' => $countries[0]['cn_iso_3']
+                                                       )
+                                               );
+                                       }
+                               }
+                               break;                          
+               }
+       }
+}
+?>
diff --git a/Classes/Hook/Core/DataHandling/class.tx_staticinfotables_processdatamap.php b/Classes/Hook/Core/DataHandling/class.tx_staticinfotables_processdatamap.php
deleted file mode 100644 (file)
index d170963..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-<?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
-*  All rights reserved
-*
-*  This script is part of the Typo3 project. The Typo3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
-/**
- * Hook on Core/DataHandling/DataHandler to manage redundancy of ISO codes in static info tables
- */
-class tx_staticinfotables_processDataMap {
-
-       /**
-        * Post-process redundant ISO codes fields
-        *
-        * @param       object          $fobj TCEmain object reference
-        * @return      void
-        */
-       public function processDatamap_postProcessFieldArray ($status, $table, $id, &$incomingFieldArray, &$fObj) {
-               switch ($table) {
-                       case 'static_territories':
-                       case 'cc_static_territories':
-                               //Post-process containing territory ISO numeric code
-                               $tablePrefix = ($table == 'cc_static_territories' ? 'cc_': '');
-                               if ($incomingFieldArray['tr_parent_territory_uid']) {
-                                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                               'uid,tr_iso_nr',
-                                               $tablePrefix . 'static_territories',
-                                               'uid = ' . intval($incomingFieldArray['tr_parent_territory_uid']) . t3lib_befunc::deleteClause($tablePrefix . 'static_territories')
-                                       );
-                                       $incomingFieldArray['tr_parent_iso_nr'] = $rows[0]['tr_iso_nr'];
-                               } else if (isset($incomingFieldArray['tr_parent_territory_uid'])) {
-                                       $incomingFieldArray['tr_parent_iso_nr'] = NULL;
-                               }
-                               break;
-                       case 'static_countries':
-                       case 'cc_static_countries':
-                               $tablePrefix = ($table == 'cc_static_countries' ? 'cc_': '');
-                               //Post-process containing territory ISO numeric code
-                               if ($incomingFieldArray['cn_parent_territory_uid']) {
-                                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                               'uid,tr_iso_nr',
-                                               $tablePrefix . 'static_territories',
-                                               'uid = ' . intval($incomingFieldArray['cn_parent_territory_uid']) . t3lib_befunc::deleteClause($tablePrefix . 'static_territories')
-                                       );
-                                       $incomingFieldArray['cn_parent_tr_iso_nr'] = $rows[0]['tr_iso_nr'];
-                               } else if (isset($incomingFieldArray['cn_parent_territory_uid'])) {
-                                       $incomingFieldArray['cn_parent_tr_iso_nr'] = NULL;
-                               }
-                               //Post-process currency ISO numeric and A3 codes
-                               if ($incomingFieldArray['cn_currency_uid']) {
-                                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                               'uid,cu_iso_nr,cu_iso_3',
-                                               $tablePrefix . 'static_currencies',
-                                               'uid = ' . intval($incomingFieldArray['cn_currency_uid']) . t3lib_befunc::deleteClause($tablePrefix . 'static_currencies')
-                                       );
-                                       $incomingFieldArray['cn_currency_iso_nr'] = $rows[0]['cu_iso_nr'];
-                                       $incomingFieldArray['cn_currency_iso_3'] = $rows[0]['cu_iso_3'];
-                               } else if (isset($incomingFieldArray['cn_currency_uid'])) {
-                                       $incomingFieldArray['cn_currency_iso_nr'] = NULL;
-                                       $incomingFieldArray['cn_currency_iso_3'] = NULL;
-                               }
-                               break;                  
-               }
-       }
-       /**
-        * Post-process redundant ISO codes fields of IRRE child
-        *
-        * @param       object          $fobj TCEmain object reference
-        * @return      void
-        */
-       public function processDatamap_afterDatabaseOperations ($status, $table, $id, &$fieldArray, &$fObj) {
-               switch ($table) {
-                       case 'static_countries':
-                       case 'cc_static_countries':
-                               //Post-process country ISO numeric, A2 and A3 codes on country zones
-                               $tablePrefix = ($table == 'cc_static_countries' ? 'cc_': '');
-                               // Get the country record uid
-                               if ($status == 'new') {
-                                       $id = $fObj->substNEWwithIDs[$id];
-                               }
-                               // Get the country zones
-                               $countryZones = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                       '*',
-                                       $tablePrefix . 'static_country_zones',
-                                       'zn_country_uid = ' . intval($id) . t3lib_befunc::deleteClause($tablePrefix . 'static_country_zones')
-                               );
-                               if (is_array($countryZones) && count($countryZones)) {
-                                       $countries = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                               'uid,cn_iso_nr,cn_iso_2,cn_iso_3',
-                                               $table,
-                                               'uid = ' . intval($id) . t3lib_befunc::deleteClause($table)
-                                       );
-                                       foreach ($countryZones as $countryZone) {
-                                               $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
-                                                       $tablePrefix . 'static_country_zones',
-                                                       'uid = ' . intval($countryZone['uid']),
-                                                       array (
-                                                               'zn_country_iso_nr' => intval($countries[0]['cn_iso_nr']),
-                                                               'zn_country_iso_2' => $countries[0]['cn_iso_2'],
-                                                               'zn_country_iso_3' => $countries[0]['cn_iso_3']
-                                                       )
-                                               );
-                                       }
-                               }
-                               break;                          
-               }
-       }
-}
-?>
diff --git a/Classes/PiBaseApi.php b/Classes/PiBaseApi.php
new file mode 100644 (file)
index 0000000..878f349
--- /dev/null
@@ -0,0 +1,606 @@
+<?php
+namespace SJBR\StaticInfoTables;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2004-2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  All rights reserved
+*
+*  This script is part of the Typo3 project. The Typo3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+/**
+ *
+ * Class for handling static info tables: countries, and subdivisions, currencies, languages and taxes
+ *
+ */
+class PiBaseApi extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
+
+       var $cObj;              // The backReference to the mother cObj object set at call time
+       var $prefixId = 'tx_staticinfotables_pi1';              // Same as class name
+       var $scriptRelPath = 'pi1/class.tx_staticinfotables_pi1.php';   // Path to this script relative to the extension dir.
+       var $extKey = 'static_info_tables';              // The extension key.
+       var $conf = array();
+       var $currency;          // default currency
+       var $currencyInfo = array();
+       var $defaultCountry;
+       var $defaultCountryZone;
+       var $defaultLanguage;
+       var $types = array('TERRITORIES', 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES', 'LANGUAGES');
+       var $tables = array(
+               'TERRITORIES'   => 'static_territories',
+               'COUNTRIES'     => 'static_countries',
+               'SUBDIVISIONS'  => 'static_country_zones',
+               'CURRENCIES'    => 'static_currencies',
+               'LANGUAGES'     => 'static_languages'
+       );
+       var $bHasBeenInitialised = FALSE;
+
+
+       /**
+        * Returns info if the tx_staticinfotables_pi1 object has already been initialised.
+        * You need to initialise this object only once.
+        *
+        * @return      boolean         Always returns true
+        */
+       public function needsInit () {
+               return !$this->bHasBeenInitialised;
+       }
+
+
+       /**
+        * Initializing the class: sets the language based on the TS configuration language property
+        *
+        * @param       array           $conf ... overwriting setup of extension
+        * @return      boolean         Always returns true
+        */
+       public function init ($conf=array()) {
+
+               $this->conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->prefixId.'.'];
+
+                       //Get the default currency and make sure it does exist in table static_currencies
+               $this->currency = $conf['currencyCode'];
+               if (!$this->currency) {
+                       $this->currency = (trim($this->conf['currencyCode'])) ? trim($this->conf['currencyCode']) : 'EUR';
+               }
+                       //If nothing is set, we use the Euro because TYPO3 is spread more in this area
+               if (!$this->getStaticInfoName('CURRENCIES', $this->currency)) {
+                       $this->currency = 'EUR';
+               }
+               $this->currencyInfo = $this->loadCurrencyInfo($this->currency);
+               $this->defaultCountry = $conf['countryCode'];
+
+               if (!$this->defaultCountry) {
+                       $this->defaultCountry = trim($this->conf['countryCode']);
+               }
+               if (!$this->getStaticInfoName('COUNTRIES', $this->defaultCountry)) {
+                       $this->defaultCountry = 'DEU';
+               }
+
+               $this->defaultCountryZone = $conf['countryZoneCode'];
+               if (!$this->defaultCountryZone) {
+                       $this->defaultCountryZone = trim($this->conf['countryZoneCode']);
+               }
+               if (!$this->getStaticInfoName('SUBDIVISIONS', $this->defaultCountryZone, $this->defaultCountry)) {
+                       if ($this->defaultCountry == 'DEU') {
+                               $this->defaultCountryZone = 'NW';
+                       } else {
+                               $this->defaultCountryZone = '';
+                       }
+               }
+
+               $this->defaultLanguage = $conf['languageCode'];
+               if (!$this->defaultLanguage) {
+                       $this->defaultLanguage = trim($this->conf['languageCode']);
+               }
+               if (!$this->getStaticInfoName('LANGUAGES', $this->defaultLanguage)) {
+                       $this->defaultLanguage = 'EN';
+               }
+               $this->bHasBeenInitialised = TRUE;
+               return TRUE;
+       }
+
+       /**
+        * Getting the name of a country, country subdivision, currency, language, tax
+        *
+        * @param       string          Defines the type of entry of the requested name: 'TERRIRORIES', 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES', 'LANGUAGES'
+        * @param       string          The ISO alpha-3 code of a territory, country or currency, or the ISO alpha-2 code of a language or the code of a country subdivision, can be a comma ',' separated string, then all the single items are looked up and returned
+        * @param       string          The value of the country code (cn_iso_3) for which a name of type 'SUBDIVISIONS' is requested (meaningful only in this case)
+        * @param       string          Not used
+        * @param       boolean         local name only - if set local title is returned
+        * @return      string          The name of the object in the current language
+        */
+       public function getStaticInfoName ($type = 'COUNTRIES', $code, $country = '', $countrySubdivision = '', $local = FALSE) {
+               $names = FALSE;
+               if (in_array($type, $this->types) && trim($code)) {
+                       $codeArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', ($code));
+                       $tableName = $this->tables[$type];
+                       if (!$tableName) {
+                               return FALSE;
+                       }
+                       $nameArray = array();
+                       foreach ($codeArray as $item) {
+                               $isoCodeArray = array();
+                               $isoCodeArray[] = $item;
+                               switch ($type) {
+                                       case 'SUBDIVISIONS':
+                                               $isoCodeArray[] = trim($country) ? trim($country) : $this->defaultCountry;
+                                               break;
+                                       case 'LANGUAGES':
+                                               $isoCodeArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode( '_', $code, 1);
+                                               break;
+                               }
+                               $nameArray[] = \SJBR\StaticInfoTables\Utility\LocalizationUtility::translate(array('iso' => $isoCodeArray), $tableName, $local);
+                       }
+                       $names = implode(',', $nameArray);
+               }
+               return $names;
+       }
+
+       /**
+        * Buils a HTML drop-down selector of countries, country subdivisions, currencies or languages
+        *
+        * @param       string          Defines the type of entries to be presented in the drop-down selector: 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES' or 'LANGUAGES'
+        * @param       string          A value for the name attribute of the <select> tag
+        * @param       string          A value for the class attribute of the <select> tag
+        * @param       array           The values of the code of the entries to be pre-selected in the drop-down selector: value of cn_iso_3, zn_code, cu_iso_3 or lg_iso_2
+        * @param       string          The value of the country code (cn_iso_3) for which a drop-down selector of type 'SUBDIVISIONS' is requested (meaningful only in this case)
+        * @param       boolean/string          If set to 1, an onchange attribute will be added to the <select> tag for immediate submit of the changed value; if set to other than 1, overrides the onchange script
+        * @param       string          A value for the id attribute of the <select> tag
+        * @param       string          A value for the title attribute of the <select> tag
+        * @param       string          A where clause for the records
+        * @param       string          language to be used
+        * @param       boolean         $local: If set, we are looking for the "local" title field
+        * @param       array           additional array to be merged as key => value pair
+        * @param       int             max elements that can be selected. Default: 1
+        * @param       array           out: resulting selected array with the ISO alpha-3 code of the countries
+        * @return      string          A set of HTML <select> and <option> tags
+        */
+       public function buildStaticInfoSelector ($type='COUNTRIES', $name='', $class='', $selectedArray=array(), $country='', $submit=0, $id='', $title='', $addWhere='', $lang='', $local=FALSE, $mergeArray=array(), $size=1, &$outSelectedArray=array()) {
+
+               if ($size > 1) {
+                       $multiple = ' multiple="multiple"';
+                       $name .= '[]';
+               } else {
+                       $multiple="";
+               }
+               if (isset($selectedArray) && !is_array($selectedArray)) {
+                       $selectedArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode (',', $selectedArray);
+               }
+
+               $charset = $GLOBALS['TSFE']->renderCharset;
+               $country = trim($country);
+               $nameAttribute = (trim($name)) ? 'name="'.htmlspecialchars(trim($name), ENT_COMPAT, $charset).'" ' : '';
+               $classAttribute = (trim($class)) ? 'class="'.htmlspecialchars(trim($class), ENT_COMPAT, $charset).'" ' : '';
+               $idAttribute = (trim($id)) ? 'id="'.htmlspecialchars(trim($id), ENT_COMPAT, $charset).'" ' : '';
+               $titleAttribute = (trim($title)) ? 'title="'.htmlspecialchars(trim($title), ENT_COMPAT, $charset).'" ' : '';
+               $onchangeAttribute = '';
+               if ($submit) {
+                       if ($submit == 1) {
+                               $onchangeAttribute = $this->conf['onChangeAttribute'];
+                       } else {
+                               $onchangeAttribute = $submit;
+                       }
+                       $onchangeAttribute = str_replace('"', '\'', $onchangeAttribute);
+                       $onchangeAttribute = $this->quoteJSvalue($onchangeAttribute);
+                       $onchangeAttribute = 'onchange='.$onchangeAttribute;
+               }
+               $selector = '<select size="'.$size.'" '.$idAttribute.$nameAttribute.$titleAttribute.$classAttribute.$onchangeAttribute.$multiple.'>'.chr(10);
+
+               switch ($type) {
+                       case 'COUNTRIES':
+                               $nameArray = $this->initCountries('ALL', $lang, $local, $addWhere);
+                               $defaultSelectedArray = array($this->defaultCountry);
+                               break;
+                       case 'SUBDIVISIONS':
+                               $param = (trim($country) ? trim($country) : $this->defaultCountry);
+                               $nameArray = $this->initCountrySubdivisions($param, $addWhere);
+                               if ($param == $this->defaultCountry) {
+                                       $defaultSelectedArray = array($this->defaultCountryZone);
+                               }
+                               break;
+                       case 'CURRENCIES':
+                               $nameArray = $this->initCurrencies($addWhere);
+                               $defaultSelectedArray = array($this->currency);
+                               break;
+                       case 'LANGUAGES':
+                               $nameArray = $this->initLanguages($addWhere);
+                               $defaultSelectedArray = array($this->defaultLanguage);
+                               break;
+               }
+
+               if (!$defaultSelectedArray) {
+                       reset($nameArray);
+                       $defaultSelectedArray = array(key($nameArray));
+               }
+               $bEmptySelected = (empty($selectedArray) || ((count($selectedArray) == 1) && empty($selectedArray[0])));
+               $selectedArray = ((!$bEmptySelected || count($mergeArray)) ? $selectedArray : $defaultSelectedArray);
+
+               if (count($mergeArray)) {
+                       $nameArray = array_merge($nameArray, $mergeArray);
+                       uasort($nameArray, 'strcoll');
+               }
+
+               if (count($nameArray) > 0) {
+                       $selector .= $this->optionsConstructor($nameArray, $selectedArray, $outSelectedArray);
+                       $selector .= '</select>'.chr(10);
+               } else {
+                       $selector = '';
+               }
+               return $selector;
+       }
+
+       /**
+        * Getting all countries into an array
+        *      where the key is the ISO alpha-3 code of the country
+        *      and where the value is the name of the country in the current language
+        *
+        * @param       string          It defines a selection: 'ALL', 'UN', 'EU'
+        * @param       string          language to be used
+        * @param       boolean         If set, we are looking for the "local" title field
+        * @param       string          additional WHERE clause
+        * @return      array           An array of names of countries
+        */
+       public function initCountries ($param='UN', $lang='', $local=FALSE, $addWhere='') {
+
+               $table = $this->tables['COUNTRIES'];
+               if (!$lang) {
+                       $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getCurrentLanguage();
+                       $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getIsoLanguageKey($lang);
+               }
+               $nameArray = array();
+               $titleFields = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFields($table, $lang, $local);
+               $prefixedTitleFields = array();
+               $prefixedTitleFields[] = $table.'.cn_iso_3';
+               foreach ($titleFields as $titleField) {
+                       $prefixedTitleFields[] = $table.'.'.$titleField;
+               }
+
+               array_unique($prefixedTitleFields);
+               $labelFields = implode(',', $prefixedTitleFields);
+               if ($param == 'UN') {
+                       $where = 'cn_uno_member=1';
+               } elseif ($param == 'EU') {
+                       $where = 'cn_eu_member=1';
+               } elseif ($param == 'ALL')      {
+                       $where = '1=1';
+               } else {
+                       $where = '1=1';
+               }
+
+               $where .= ($addWhere ? ' AND '.$addWhere : '');
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                       $labelFields,
+                       $table,
+                       $where.$GLOBALS['TSFE']->sys_page->enableFields($table)
+               );
+
+               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
+
+                       foreach ($titleFields as $titleField) {
+                               if ($row[$titleField]) {
+                                       $nameArray[$row['cn_iso_3']] = $GLOBALS['TSFE']->csConv($row[$titleField], 'utf-8');
+                                       break;
+                               }
+                       }
+               }
+               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+
+               if ($this->conf['countriesAllowed'] != '')      {
+                       $countriesAllowedArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['countriesAllowed']);
+                       $newNameArray = array();
+                       foreach ($countriesAllowedArray as $iso3)       {
+                               if (isset($nameArray[$iso3]))   {
+                                       $newNameArray[$iso3] = $nameArray[$iso3];
+                               }
+                       }
+                       $nameArray = $newNameArray;
+               } else {
+                       uasort($nameArray, 'strcoll');
+               }
+               return $nameArray;
+       }
+
+
+       /**
+        * Getting all country subdivisions of a given country into an array
+        *      where the key is the code of the subdivision
+        *      and where the value is the name of the country subdivision in the current language
+        * You can leave the ISO code empty and use the additional WHERE clause instead of it.
+        *
+        * @param       string          The ISO alpha-3 code of a country
+        * @param       string          additional WHERE clause
+        * @return      array           An array of names of country subdivisions
+        */
+       public function initCountrySubdivisions ($param, $addWhere='') {
+
+               $table = $this->tables['SUBDIVISIONS'];
+               if (strlen($param) == 3) {
+                       $country = $param;
+                       $where = 'zn_country_iso_3='.$GLOBALS['TYPO3_DB']->fullQuoteStr($country,$table);
+               } else {
+                       $where = '1=1';
+               }
+               $where .= ($addWhere ? ' AND '.$addWhere : '');
+               $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getCurrentLanguage();
+               $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getIsoLanguageKey($lang);
+               $nameArray = array();
+               $titleFields = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFields($table, $lang);
+               $prefixedTitleFields = array();
+               foreach ($titleFields as $titleField) {
+                       $prefixedTitleFields[] = $table.'.'.$titleField;
+               }
+               $labelFields = implode(',', $prefixedTitleFields);
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                       $table.'.zn_code,'.$labelFields,
+                       $table,
+                       $where.
+                               $GLOBALS['TSFE']->sys_page->enableFields($table)
+                       );
+               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                       foreach ($titleFields as $titleField) {
+                               if ($row[$titleField]) {
+                                       $nameArray[$row['zn_code']] = $GLOBALS['TSFE']->csConv($row[$titleField], 'utf-8');
+                                       break;
+                               }
+                       }
+               }
+               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+               uasort($nameArray, 'strcoll');
+               return $nameArray;
+       }
+
+       /**
+        * Getting all currencies into an array
+        *      where the key is the ISO alpha-3 code of the currency
+        *      and where the value are the name of the currency in the current language
+        *
+        * @param       string          additional WHERE clause
+        * @return      array           An array of names of currencies
+        */
+       public function initCurrencies ($addWhere='') {
+
+               $where = '1=1'.($addWhere ? ' AND '.$addWhere : '');
+               $table = $this->tables['CURRENCIES'];
+               $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getCurrentLanguage();
+               $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getIsoLanguageKey($lang);
+               $nameArray = array();
+               $titleFields = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFields($table, $lang);
+               $prefixedTitleFields = array();
+               foreach ($titleFields as $titleField) {
+                       $prefixedTitleFields[] = $table.'.'.$titleField;
+               }
+               $labelFields = implode(',', $prefixedTitleFields);
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                       $table.'.cu_iso_3,'.$labelFields,
+                       $table,
+                       $where.$GLOBALS['TSFE']->sys_page->enableFields($table)
+                       );
+               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                       foreach ($titleFields as $titleField) {
+                               if ($row[$titleField]) {
+                                       $nameArray[$row['cu_iso_3']] = $GLOBALS['TSFE']->csConv($row[$titleField], 'utf-8');
+                                       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
+        *
+        * @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 = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getCurrentLanguage();
+               $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getIsoLanguageKey($lang);
+               $nameArray = array();
+               $titleFields = \SJBR\StaticInfoTables\Utility\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 ' .
+                               $GLOBALS['TSFE']->sys_page->enableFields($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] = $GLOBALS['TSFE']->csConv($row[$titleField], 'utf-8');
+                                       break;
+                               }
+                       }
+               }
+               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+               uasort($nameArray, 'strcoll');
+               return $nameArray;
+       }
+
+       /**
+        * Builds a list of <option> tags
+        *
+        * @param       array           An array where the values will be the texts of an <option> tags and keys will be the values of the tags
+        * @param       string          A pre-selected value: if the value appears as a key, the <option> tag will bear a 'selected' attribute
+        * @param       array           out: resulting selected array with the ISO alpha-3 code of the countries
+        * @return      string          A string of HTML <option> tags
+        */
+       public function optionsConstructor ($nameArray, $selectedArray=array(), &$outSelectedArray=array()) {
+
+               $options = '';
+               foreach ($nameArray as $value => $name) {
+
+                       $options  .= '<option value="'.$value.'"';
+                       if (in_array($value, $selectedArray))   {
+                               $options  .= ' selected="selected"';
+                               $outSelectedArray[] = $value;
+                       }
+                       $options  .= '>'.$name.'</option>'.chr(10);
+               }
+               if (!isset($outSelectedArray) || count($outSelectedArray) == 0) {
+                       reset ($nameArray);
+                       $outSelectedArray = array(key($nameArray));
+               }
+               return $options;
+       }
+
+       /**
+        * Loading currency display parameters from Static Info Tables
+        *
+        * @param       string          An ISO alpha-3 currency code
+        * @return      array           An array of information regarding the currrency
+        */
+       public function loadCurrencyInfo ($currencyCode) {
+
+               // Fetching the currency record
+               $this->currencyInfo['cu_iso_3'] = trim($currencyCode);
+               $this->currencyInfo['cu_iso_3'] = ($this->currencyInfo['cu_iso_3']) ? $this->currencyInfo['cu_iso_3'] : $this->currency;
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                       '*',
+                       'static_currencies',
+                       'cu_iso_3='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->currencyInfo['cu_iso_3'],'static_currencies')
+               );
+               // If not found we fetch the default currency!
+               if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+                       $this->currencyInfo['cu_iso_3'] = $this->currency;
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                               '*',
+                               'static_currencies',
+                               'cu_iso_3='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->currencyInfo['cu_iso_3'],'static_currencies')
+                       );
+               }
+               $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+
+               $this->currencyInfo['cu_name'] = $this->getStaticInfoName('CURRENCIES', $this->currencyInfo['cu_iso_3']);
+               $this->currencyInfo['cu_symbol_left'] = $row['cu_symbol_left'];
+               $this->currencyInfo['cu_symbol_right'] = $row['cu_symbol_right'];
+               $this->currencyInfo['cu_decimal_digits'] = $row['cu_decimal_digits'];
+               $this->currencyInfo['cu_decimal_point'] = $row['cu_decimal_point'];
+               $this->currencyInfo['cu_thousands_point'] = $row['cu_thousands_point'];
+
+               return $this->currencyInfo;
+       }
+
+       /**
+        * Formatting an amount in the currency loaded by loadCurrencyInfo($currencyCode)
+        *
+        *       '' - the currency code is not displayed
+        *       'RIGHT' - the code is displayed at the right of the amount
+        *       'LEFT' - the code is displayed at the left of the amount
+        *
+        * @param       float           An amount to be displayed in the loaded currency
+        * @param       string          A flag specifying if the the currency code should be displayed:
+        * @return      string          The formated amounted
+        */
+       public function formatAmount ($amount, $displayCurrencyCode='') {
+               $formatedAmount = '';
+               if ( $displayCurrencyCode == 'LEFT') {
+                       $formatedAmount .= $this->currencyInfo['cu_iso_3'].chr(32);
+               }
+               $formatedAmount .= $this->currencyInfo['cu_symbol_left'];
+               $formatedAmount .= number_format($amount, intval($this->currencyInfo['cu_decimal_digits']), $this->currencyInfo['cu_decimal_point'], (($this->currencyInfo['cu_thousands_point'])?$this->currencyInfo['cu_thousands_point']:chr(32)));
+               $formatedAmount .= (($this->currencyInfo['cu_symbol_right'])?chr(32):'').$this->currencyInfo['cu_symbol_right'];
+               if ($displayCurrencyCode == 'RIGHT') {
+                       $formatedAmount .= chr(32).$this->currencyInfo['cu_iso_3'];
+               }
+               return $formatedAmount;
+       }
+
+       /**
+        * Formatting an address in the format specified
+        *
+        * @param       string          A delimiter for the fields of the returned address
+        * @param       string          A street address
+        * @param       string          A city
+        * @param       string          A country subdivision code (zn_code)
+        * @param       string          A ISO alpha-3 country code (cn_iso_3)
+        * @param       string          A zip code
+        * @return      string          The formated address using the country address format (cn_address_format)
+        */
+       public function formatAddress ($delim, $streetAddress, $city, $zip, $subdivisionCode='', $countryCode='') {
+
+               $formatedAddress = '';
+               $countryCode = ($countryCode ? trim($countryCode) : $this->defaultCountry);
+               $subdivisionCode = ($subdivisionCode ? trim($subdivisionCode) : ($countryCode == $this->defaultCountry ? $this->defaultCountryZone : ''));
+
+                       // Get country name
+               $countryName = $this->getStaticInfoName('COUNTRIES', $countryCode);
+               if (!$countryName) {
+                       return $formatedAddress;
+               }
+
+                       // Get address format
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                       'cn_address_format',
+                       'static_countries',
+                       'cn_iso_3='.$GLOBALS['TYPO3_DB']->fullQuoteStr($countryCode,'static_countries')
+               );
+               $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+               $addressFormat = $row['cn_address_format'];
+
+                       // Get country subdivision name
+               $countrySubdivisionName = $this->getStaticInfoName('SUBDIVISIONS', $subdivisionCode, $countryCode);
+
+                       // Format the address
+               $formatedAddress = $this->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', $countrySubdivisionName, $formatedAddress);
+               $formatedAddress = str_replace('%countryName', strtoupper($countryName), $formatedAddress);
+               $formatedAddress = implode($delim, \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(';', $formatedAddress, 1));
+
+               return $formatedAddress;
+       }
+
+       /**
+        * Quotes a string for usage as JS parameter. Depends wheter the value is used in script tags (it must not get `htmlspecialchar'ed in this case because this is done in this function)
+        *
+        * @param       string          The string to encode.
+        * @param       boolean         If the values are used inside of <script> tags.
+        * @return      string          The encoded value already quoted
+        */
+       protected function quoteJSvalue ($value, $inScriptTags=FALSE) {
+               $value = addcslashes($value, '"'.chr(10).chr(13));
+               if (!$inScriptTags) {
+                       $value = htmlspecialchars($value, ENT_COMPAT, $GLOBALS['TSFE']->renderCharset);
+               }
+               return '"'.$value.'"';
+       }
+}
+class_alias('SJBR\StaticInfoTables\PiBaseApi', 'tx_staticinfotables_pi1');
+?>
\ No newline at end of file
diff --git a/Classes/Utility/EntityLabelUtility.php b/Classes/Utility/EntityLabelUtility.php
new file mode 100644 (file)
index 0000000..40be16e
--- /dev/null
@@ -0,0 +1,230 @@
+<?php
+namespace SJBR\StaticInfoTables\Utility;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2004-2010 René Fritz (r.fritz@colorcube.de)
+*  (c) 2013 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  All rights reserved
+*
+*  This script is part of the Typo3 project. The Typo3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+/**
+ * Functions to get appropriate labels for entities
+ */
+class EntityLabelUtility {
+
+       /**
+        * Replaces any dynamic markers in a SQL statement.
+        *
+        * @param       string          The SQL statement with dynamic markers.
+        * @param       string          Name of the table.
+        * @param       array           row from table.
+        * @return      string          SQL query with dynamic markers subsituted.
+        */
+       protected function replaceMarkersInSQL ($sql, $table, $row) {
+
+               $TSconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getTCEFORM_TSconfig($table, $row);
+
+               /* Replace references to specific fields with value of that field */
+               if (strstr($sql,'###REC_FIELD_'))       {
+                       $sql_parts = explode('###REC_FIELD_',$sql);
+                       while(list($kk,$vv)=each($sql_parts))   {
+                               if ($kk)        {
+                                       $sql_subpart = explode('###',$vv,2);
+                                       $sql_parts[$kk]=$TSconfig['_THIS_ROW'][$sql_subpart[0]].$sql_subpart[1];
+                               }
+                       }
+                       $sql = implode('',$sql_parts);
+               }
+
+               /* Replace markers with TSConfig values */
+               $sql = str_replace('###THIS_UID###',intval($TSconfig['_THIS_UID']),$sql);
+               $sql = str_replace('###THIS_CID###',intval($TSconfig['_THIS_CID']),$sql);
+               $sql = str_replace('###SITEROOT###',intval($TSconfig['_SITEROOT']),$sql);
+               $sql = str_replace('###PAGE_TSCONFIG_ID###',intval($TSconfig[$field]['PAGE_TSCONFIG_ID']),$sql);
+               $sql = str_replace('###PAGE_TSCONFIG_IDLIST###',$GLOBALS['TYPO3_DB']->cleanIntList($TSconfig[$field]['PAGE_TSCONFIG_IDLIST']),$sql);
+               $sql = str_replace('###PAGE_TSCONFIG_STR###',$GLOBALS['TYPO3_DB']->quoteStr($TSconfig[$field]['PAGE_TSCONFIG_STR'], $table),$sql);
+
+               return $sql;
+       }
+
+
+       /**
+        * Function to use in own TCA definitions
+        * Adds additional select items
+        *
+        *                      items           reference to the array of items (label,value,icon)
+        *                      config          The config array for the field.
+        *                      TSconfig        The "itemsProcFunc." from fieldTSconfig of the field.
+        *                      table           Table name
+        *                      row             Record row
+        *                      field           Field name
+        *
+        * @param       array           itemsProcFunc data array:
+        * @return      void            The $items array may have been modified
+        */
+       public function selectItemsTCA ($params) {
+               global $TCA;
+
+               $where = '';
+               $config = &$params['config'];
+               $table = $config['itemsProcFunc_config']['table'];
+               $tcaWhere = $config['itemsProcFunc_config']['where'];
+               if ($tcaWhere)  {
+                       $where = self::replaceMarkersInSQL($tcaWhere, $params['table'], $params['row']);
+               }
+
+               if ($table) {
+                       $indexField = $config['itemsProcFunc_config']['indexField'];
+                       $indexField = $indexField ? $indexField : 'uid';
+
+                       $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getCurrentLanguage();
+                       $lang = strtolower(\SJBR\StaticInfoTables\Utility\LocalizationUtility::getIsoLanguageKey($lang));
+                       $titleFields = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFields($table, $lang);
+                       $prefixedTitleFields = array();
+                       foreach ($titleFields as $titleField) {
+                               $prefixedTitleFields[] = $table.'.'.$titleField;
+                       }
+                       $fields = $table.'.'.$indexField.','.implode(',', $prefixedTitleFields);
+
+                       if ($config['itemsProcFunc_config']['prependHotlist']) {
+
+                               $limit = $config['itemsProcFunc_config']['hotlistLimit'];
+                               $limit = $limit ? $limit : '8';
+                               $app = $config['itemsProcFunc_config']['hotlistApp'];
+                               $app = $app ? $app : TYPO3_MODE;
+
+                               $res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
+                                               $fields,
+                                               $table,
+                                               'tx_staticinfotables_hotlist',
+                                               '',     // $foreign_table
+                                               'AND tx_staticinfotables_hotlist.tablenames='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'tx_staticinfotables_hotlist').' AND tx_staticinfotables_hotlist.application='.$GLOBALS['TYPO3_DB']->fullQuoteStr($app,'tx_staticinfotables_hotlist'),
+                                               '',
+                                               'tx_staticinfotables_hotlist.sorting DESC',     // $orderBy
+                                               $limit
+                                       );
+
+                               $cnt = 0;
+                               $rows = array();
+                               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
+
+                                       foreach ($titleFields as $titleField) {
+                                               if ($row[$titleField]) {
+                                                       $rows[$row[$indexField]] = $row[$titleField];
+                                                       break;
+                                               }
+                                       }
+                                       $cnt++;
+                               }
+                               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+
+                               if (!isset($config['itemsProcFunc_config']['hotlistSort']) || $config['itemsProcFunc_config']['hotlistSort']) {
+                                       asort ($rows);
+                               }
+
+                               foreach ($rows as $index => $title)     {
+                                       $params['items'][] = array($title, $index, '');
+                                       $cnt++;
+                               }
+                               if($cnt && !$config['itemsProcFunc_config']['hotlistOnly']) {
+                                       $params['items'][] = array('--------------', '', '');
+                               }
+                       }
+
+                               // Set ORDER BY:
+                       $orderBy = $titleFields[0];
+
+                       if(!$config['itemsProcFunc_config']['hotlistOnly']) {
+                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, '1=1'.$where . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($table), '', $orderBy);
+                               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                                       foreach ($titleFields as $titleField) {
+                                               if ($row[$titleField]) {
+                                                       $params['items'][] = array($row[$titleField], $row[$indexField], '');
+                                                       break;
+                                               }
+                                       }
+                               }
+                               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+                       }
+               }
+       }
+
+
+       /**
+        * Updates the hotlist table.
+        * This means that a hotlist entry will be created or the counter of an existing entry will be increased
+        *
+        * @param       string          table name: static_countries, ...
+        * @param       string          value of the following index field
+        * @param       string          the field which holds the value and is an index field: uid (default) or one of the iso code fields which are also unique
+        * @param       string          This indicates a counter group. Default is TYPO3_MOD (BE or FE). If you want a unique hotlist for your application you can provide here a name (e.g. extension key)
+        * @return      void
+        */
+       public function updateHotlist ($table, $indexValue, $indexField='', $app='') {
+
+               if ($table && $indexValue) {
+                       $indexField = $indexField ? $indexField : 'uid';
+                       $app = $app ? $app : TYPO3_MODE;
+
+                       if ($indexField=='uid') {
+                               $uid = $indexValue;
+
+                       } else {
+                                       // fetch original record
+                               $fields = array();
+                               $fields[$indexField] = $indexField;
+                               $fields['uid'] = 'uid';
+
+                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',',$fields), $table, $indexField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($indexValue,$table) . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($table));
+                               if ($res !== FALSE)     {
+                                       if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                                               $uid = $row['uid'];
+                                       }
+                                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+                               }
+                       }
+
+                       if ($uid) {
+                                       // update record from hotlist table
+                               $newRow = array('sorting' => 'sorting+1');
+                               // the dumb update function does not allow to use sorting+1 - that's why this trick is necessary
+
+                               $GLOBALS['TYPO3_DB']->sql_query(str_replace('"sorting+1"', 'sorting+1', $GLOBALS['TYPO3_DB']->UPDATEquery(
+                                               'tx_staticinfotables_hotlist',
+                                               'uid_local='.$uid.
+                                                       ' AND application='.$GLOBALS['TYPO3_DB']->fullQuoteStr($app,'tx_staticinfotables_hotlist').
+                                                       ' AND tablenames='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'tx_staticinfotables_hotlist').
+                                                       \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields('tx_staticinfotables_hotlist'),
+                                               $newRow)));
+
+                               if (!$GLOBALS['TYPO3_DB']->sql_affected_rows()) {
+                                               // insert new hotlist entry
+                                       $row = array(
+                                               'uid_local' => $uid,
+                                               'tablenames' => $table,
+                                               'application' => $app,
+                                               'sorting' => 1,
+                                       );
+                                       $res = $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_staticinfotables_hotlist', $row);
+                               }
+                       }
+               }
+       }
+}
+?>
\ No newline at end of file
diff --git a/Classes/Utility/LocalizationUtility.php b/Classes/Utility/LocalizationUtility.php
new file mode 100644 (file)
index 0000000..1802c1d
--- /dev/null
@@ -0,0 +1,282 @@
+<?php
+namespace SJBR\StaticInfoTables\Utility;
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2009 Sebastian Kurfürst <sebastian@typo3.org>
+ *  (c) 2013 Stanislas Rolland <typo3@sjbr.ca>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * Localization helper which should be used to fetch localized labels for static info entities.
+ *
+ */
+class LocalizationUtility {
+
+       /**
+        * Key of the language to use
+        *
+        * @var string
+        */
+       protected static $languageKey = 'default';
+
+       /**
+        * Pointer to alternative fall-back language to use
+        *
+        * @var array
+        */
+       protected static $alternativeLanguageKeys = array();
+
+       /**
+        * Returns the localized label for a static info entity
+        *
+        * @param array $identifiers An array with key 1- 'uid' containing a uid and/or 2- 'iso' containing one or two iso codes (i.e. country zone code and country code, or language code and country code)
+        * @param string $tableName The name of the table
+        * @param boolean local name only - if set local labels are returned
+        * @return string The value from the label field of the table
+        */
+       public static function translate ($identifiers, $tableName, $local = FALSE) {
+
+               $value = '';
+               self::setLanguageKeys();
+               \SJBR\StaticInfoTables\Utility\TcaUtility::loadTca($tableName);
+
+               $isoLanguage = self::getIsoLanguageKey(self::$languageKey);
+               $value = self::getLabelFieldValue($identifiers, $tableName, $isoLanguage, $local);
+               if ($value) {
+                       $value = self::convertCharset($value, 'utf-8');
+               } else if (count(self::$alternativeLanguageKeys)) {
+                       // To do: modify configuration to deal with alternative language keys
+                       $languages = array_reverse(self::$alternativeLanguageKeys);
+                       foreach ($languages as $language) {
+                               $isoLanguage = self::getIsoLanguageKey($language);
+                               $value = self::getLabelFieldValue($identifiers, $tableName, $isoLanguage);
+                               if ($value) {
+                                       $value = self::convertCharset($value, 'utf-8');
+                                       break;
+                               }
+                       }
+               }
+               return $value;
+       }
+
+       /**
+        * Get the localized value for the label field
+        *
+        * @param array $identifiers An array with key 1- 'uid' containing a uid and/or 2- 'iso' containing one or two iso codes (i.e. country zone code and country code, or language code and country code)
+        * @param string $tableName The name of the table
+        * @param string language ISO code
+        * @param boolean local name only - if set local labels are returned
+        * @return string the value for the label field
+        */
+       protected static function getLabelFieldValue ($identifiers, $tableName, $language, $local = FALSE) {
+               $value = '';
+               $labelFields = self::getLabelFields($tableName, $language, $local);
+               if (count($labelFields)) {
+                       // Build the list of fields
+                       $prefixedLabelFields = array();
+                       foreach ($labelFields as $labelField) {
+                               $prefixedLabelFields[] = $tableName . '.' . $labelField;
+                       }
+                       $fields = $tableName . '.uid,' . implode(',', $prefixedLabelFields);
+                       //Build the where clause
+                       $whereClause = '';
+                       if ($identifiers['uid']) {
+                               $whereClause .= $tableName . '.uid = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($identifiers['uid'], $tableName);
+                       } else if (!empty($identifiers['iso'])) {
+                               $isoCode = is_array($identifiers['iso']) ? $identifiers['iso'] : array($identifiers['iso']);
+                               foreach ($isoCode as $index => $code) {
+                                       if ($code) {
+                                               $field = self::getIsoCodeField($tableName, $code, $index);
+                                               if ($field) {
+                                                       $whereClause .= ($whereClause ? ' AND ' : '') . $tableName . '.' . $field . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($code, $tableName);
+                                               }
+                                       }
+                               }
+                       }
+                       // Get the entity
+                       if ($whereClause) {
+                               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                       $fields,
+                                       $tableName,
+                                       $whereClause . \SJBR\StaticInfoTables\Utility\TcaUtility::getEnableFields($tableName)
+                               );
+                               if (is_array($rows) && count($rows)) {
+                                       foreach ($labelFields as $labelField) {
+                                               if ($rows[0][$labelField]) {
+                                                       $value = $rows[0][$labelField];
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+               }
+               return $value;
+       }
+
+       /**
+        * Returns the label fields for a given language
+        *
+        * @param string table name
+        * @param string ISO language code to be used
+        * @param boolean If set, we are looking for the "local" title field
+        * @return array field names
+        */
+       public static function getLabelFields ($tableName, $lang, $local = FALSE) {
+               $labelFields = array();
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['tables'][$tableName]['label_fields'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['tables'][$tableName]['label_fields'] as $field) {
+                               if ($local) {
+                                       $labelField = str_replace ('##', 'local', $field);
+                               } else {
+                                       $labelField = str_replace ('##', strtolower($lang), $field);
+                               }
+                               if (is_array($GLOBALS['TCA'][$tableName]['columns'][$labelField])) {
+                                       $labelFields[] = $labelField;
+                               }
+                       }
+               }
+               return $labelFields;
+       }
+
+       /**
+        * Returns a iso code field for the passed table name, iso code and index
+        *
+        * @param string table name
+        * @param string iso code
+        * @param integer index in the table's isocode_field configuration array
+        * @return string field name
+        */
+       protected static function getIsoCodeField ($table, $isoCode, $index = 0) {
+               $isoCodeField = '';
+               $isoCodeFieldTemplate = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['tables'][$table]['isocode_field'][$index];
+               if ($isoCode && $table && $isoCodeFieldTemplate) {
+                       $field = str_replace ('##', self::isoCodeType($isoCode), $isoCodeFieldTemplate);
+                       if (is_array($GLOBALS['TCA'][$table]['columns'][$field])) {
+                               $isoCodeField = $field;
+                       }
+               }
+               return $isoCodeField;
+       }
+
+       /**
+        * Returns the type of an iso code: nr, 2, 3
+        *
+        * @param       string          iso code
+        * @return      string          iso code type
+        */
+       protected static function isoCodeType ($isoCode) {
+               $type = '';
+               $isoCodeAsInteger = \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($isoCode);
+               if ($isoCodeAsInteger) {
+                       $type = 'nr';
+               } else if (strlen($isoCode) == 2) {
+                       $type = '2';
+               } else if (strlen($isoCode) == 3) {
+                       $type = '3';
+               }
+               return $type;
+       }
+
+       /**
+        * Get the ISO language key corresponding to a TYPO3 language key
+        *
+        * @param string $key The TYPO3 language key
+        * @return string the ISO language key
+        */
+       public static function getIsoLanguageKey($key) {
+               if ($key === 'default') {
+                       $lang = 'EN';
+               } else {
+                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                               'lg_iso_2,lg_country_iso_2',
+                               'static_languages',
+                               'lg_typo3 = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($key, 'static_languages')
+                       );
+                       if (is_array($rows) && count($rows)) {
+                               $lang = $rows[0]['lg_iso_2'] . ($rows[0]['lg_country_iso_2'] ? '_' . $rows[0]['lg_country_iso_2'] : '');
+                       }
+       
+                       $lang = $lang ? $lang : strtoupper($key);
+               }
+               return $lang;
+       }
+
+       /**
+        * Get the current TYPO3 language
+        *
+        * @return string the TYP3 language key
+        */
+       public static function getCurrentLanguage() {
+               if (self::$languageKey === 'default') {
+                       self::setLanguageKeys();
+               }
+               return self::$languageKey;
+       }
+
+       /**
+        * Sets the currently active language/language_alt keys.
+        * Default values are "default" for language key and "" for language_alt key.
+        *
+        * @return void
+        * @author Christopher Hlubek <hlubek@networkteam.com>
+        * @author Bastian Waidelich <bastian@typo3.org>
+        */
+       protected static function setLanguageKeys() {
+               self::$languageKey = 'default';
+               self::$alternativeLanguageKeys = array();
+               if (TYPO3_MODE === 'FE') {
+                       if (isset($GLOBALS['TSFE']->config['config']['language'])) {
+                               self::$languageKey = $GLOBALS['TSFE']->config['config']['language'];
+                               if (isset($GLOBALS['TSFE']->config['config']['language_alt'])) {
+                                       self::$alternativeLanguageKeys[] = $GLOBALS['TSFE']->config['config']['language_alt'];
+                               } else {
+                                       /** @var $locales \TYPO3\CMS\Core\Localization\Locales */
+                                       $locales = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\Locales');
+                                       if (in_array(self::$languageKey, $locales->getLocales())) {
+                                               foreach ($locales->getLocaleDependencies(self::$languageKey) as $language) {
+                                                       self::$alternativeLanguageKeys[] = $language;
+                                               }
+                                       }
+                               }
+                       }
+               } else {
+                       self::$languageKey = $GLOBALS['LANG']->lang;
+                       if (strlen($GLOBALS['BE_USER']->uc['lang']) > 0) {
+                               self::$languageKey = $GLOBALS['BE_USER']->uc['lang'];
+                       }
+               }
+       }
+
+       /**
+        * Converts a string from the specified character set to the current.
+        * The current charset is defined by the TYPO3 mode.
+        *
+        * @param string $value string to be converted
+        * @return string converted string
+        */
+       protected static function convertCharset($value) {
+               if (TYPO3_MODE === 'FE') {
+                       return $GLOBALS['TSFE']->csConv($value, 'utf-8');
+               } else {
+                       return $value;
+               }
+       }
+}
+?>
\ No newline at end of file
diff --git a/Classes/Utility/TcaUtility.php b/Classes/Utility/TcaUtility.php
new file mode 100644 (file)
index 0000000..f751313
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+namespace SJBR\StaticInfoTables\Utility;
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2013 StanislasRolland <typo3@sjbr.ca>
+*  All rights reserved
+*
+*  This script is part of the Typo3 project. The Typo3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+/**
+ * TCA-related functions
+ */
+class TcaUtility {
+
+       /**
+        * Load the configuration of a table and additional configuration by language packs
+        *
+        * @param string $tableName: the name of the table
+        * @return      void
+        */
+       static public function loadTca ($tableName) {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA($tableName);
+               // Get all extending TCA's
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['extendingTCA'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['extendingTCA'] as $extensionKey) {
+                               if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extensionKey)) {
+                                       include(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey) . 'ext_tables.php');
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Get the enable fields clause based on the table configuration
+        *
+        * @param string $tableName: the name of the table
+        * @return string enable fileds clause
+        */
+       static public function getEnableFields ($tableName) {
+               if (TYPO3_MODE === 'FE') {
+                       $enableFields = $GLOBALS['TSFE']->sys_page->enableFields($tableName);
+               } else {
+                       $enableFields = \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($tableName);
+               }
+       }
+}
+?>
\ No newline at end of file
diff --git a/class.tx_staticinfotables_div.php b/class.tx_staticinfotables_div.php
deleted file mode 100644 (file)
index 2849999..0000000
+++ /dev/null
@@ -1,643 +0,0 @@
-<?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2004-2010 René Fritz (r.fritz@colorcube.de)
-*  All rights reserved
-*
-*  This script is part of the Typo3 project. The Typo3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
-/**
- * Misc functions to access the static info tables
- *
- * $Id$
- *
- * @author     René Fritz <r.fritz@colorcube.de>
- * @package TYPO3
- */
-/**
- * [CLASS/FUNCTION INDEX of SCRIPT]
- *
- *
- *
- *   57: class tx_staticinfotables_div
- *   69:     function getTCAlabelField ($table, $loadTCA=TRUE, $lang='', $local=FALSE)
- *  119:     function isoCodeType ($isoCode)
- *  143:     function getIsoCodeField ($table, $isoCode, $bLoadTCA=TRUE, $index=0)
- *  169:     function getTCAsortField ($table, $loadTCA=TRUE)
- *  181:     function getCurrentLanguage ()
- *  215:     function getCurrentSystemLanguage ($where='')
- *  249:     function getCollateLocale ()
- *  282:     function getTitleFromIsoCode ($table, $isoCode, $lang='', $local=FALSE)
- *  341:     function replaceMarkersInSQL ($sql, $table, $row)
- *  383:     function selectItemsTCA ($params)
- *  480:     function updateHotlist ($table, $indexValue, $indexField='', $app='')
- *  542:     function &fetchCountries ($country, $iso2='', $iso3='', $isonr='')
- *  587:     function quoteJSvalue ($value, $inScriptTags=FALSE)
- *  609:     function loadTcaAdditions ($ext_keys)
- *
- * TOTAL FUNCTIONS: 14
- * (This index is automatically created/updated by the extension "extdeveval")
- *
- */
-class tx_staticinfotables_div {
-
-       private static $cache = array();
-
-       /**
-        * Returns a label field for the current language
-        *
-        * @param       string          table name
-        * @param       boolean         If set (default) the TCA definition of the table should be loaded with t3lib_div::loadTCA(). It will be needed to set it to false if you call this function from inside of tca.php
-        * @param       string          language to be used
-        * @param       boolean         If set, we are looking for the "local" title field
-        * @return      string          field name
-        */
-       function getTCAlabelField ($table, $loadTCA=TRUE, $lang='', $local=FALSE) {
-               global $TCA, $LANG, $TSFE;
-
-               if (is_object($LANG)) {
-                       $csConvObj = $LANG->csConvObj;
-               } elseif (is_object($TSFE)) {
-                       $csConvObj = $TSFE->csConvObj;
-               }
-
-               if (!is_object($csConvObj))       {
-                       include_once(PATH_t3lib.'class.t3lib_cs.php');
-                       // The object may not exist yet, so we need to create it now.
-                       $csConvObj = &t3lib_div::makeInstance('t3lib_cs');
-               }
-
-               $labelFields = array();
-               if($table && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'][$table]['label_fields'])) {
-                       if ($loadTCA)   {
-                               t3lib_div::loadTCA($table);
-
-                                       // get all extending TCAs
-                               if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['extendingTCA']))        {
-                                       tx_staticinfotables_div::loadTcaAdditions($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['extendingTCA']);
-                               }
-                       }
-
-                       $lang = $lang ? $lang : tx_staticinfotables_div::getCurrentLanguage();
-                       $lang = isset($csConvObj->isoArray[$lang]) ? $csConvObj->isoArray[$lang] : $lang;
-
-                       foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'][$table]['label_fields'] as $field) {
-                               if ($local) {
-                                       $labelField = str_replace ('##', 'local', $field);
-                               } else {
-                                       $labelField = str_replace ('##', $csConvObj->conv_case('utf-8',$lang,'toLower'), $field);
-                               }
-                               if (is_array($TCA[$table]['columns'][$labelField])) {
-                                       $labelFields[] = $labelField;
-                               }
-                       }
-               }
-               return $labelFields;
-       }
-
-
-       /**
-        * Returns the type of an iso code: nr, 2, 3
-        *
-        * @param       string          iso code
-        * @return      string          iso code type
-        */
-       function isoCodeType ($isoCode) {
-               $type = '';
-                       // t3lib_utility_Math was introduced in TYPO3 4.6
-               $isoCodeAsInteger = class_exists('t3lib_utility_Math')
-                       ? t3lib_utility_Math::canBeInterpretedAsInteger($isoCode)
-                       : t3lib_div::testInt($isoCode);
-               if ($isoCodeAsInteger) {
-                       $type = 'nr';
-               } elseif (strlen($isoCode) == 2) {
-                       $type = '2';
-               } elseif (strlen($isoCode) == 3) {
-                       $type = '3';
-               }
-               return $type;
-       }
-
-
-       /**
-        * Returns a iso code field for the passed table and iso code
-        *
-        *                                 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables']
-        *
-        * @param       string          table name
-        * @param       string          iso code
-        * @param       boolean         If set (default) the TCA definition of the table should be loaded with t3lib_div::loadTCA(). It will be needed to set it to FALSE if you call this function from inside of tca.php
-        * @param       integer         index in the table's isocode_field array in the global variable
-        * @return      string          field name
-        */
-       function getIsoCodeField ($table, $isoCode, $bLoadTCA=TRUE, $index=0) {
-               global $TCA;
-               $rc = FALSE;
-
-               if ($isoCode && $table && (($isoCodeField = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'][$table]['isocode_field'][$index]) != '')) {
-                       if ($bLoadTCA) {
-                               t3lib_div::loadTCA($table);
-                       }
-                       $type = tx_staticinfotables_div::isoCodeType($isoCode);
-                       $isoCodeField = str_replace ('##', $type, $isoCodeField);
-
-                       if (is_array($TCA[$table]['columns'][$isoCodeField])) {
-                               $rc = $isoCodeField;
-                       }
-               }
-               return $rc;
-       }
-
-
-       /**
-        * Returns a sort field for the current language
-        *
-        * @param       string          table name
-        * @param       boolean         If set (default) the TCA definition of the table should be loaded
-        * @return      string          field name
-        */
-       function getTCAsortField ($table, $loadTCA=TRUE) {
-               $labelFields = tx_staticinfotables_div::getTCAlabelField($table, $loadTCA);
-
-               return $labelFields[0];
-       }
-
-
-       /**
-        * Returns the current language as iso-2-alpha code
-        *
-        * @return      string          'DE', 'EN', 'DK', ...
-        */
-       function getCurrentLanguage () {
-
-               if (is_object($GLOBALS['TSFE'])) {
-                       $langCodeT3 = $GLOBALS['TSFE']->lang;
-                       $csConvObj = $GLOBALS['TSFE']->csConvObj;
-               } elseif (is_object($GLOBALS['LANG'])) {
-                       $langCodeT3 = $GLOBALS['LANG']->lang;
-                       $csConvObj = $GLOBALS['LANG']->csConvObj;
-               } else {
-                       return 'EN';
-               }
-               if ($langCodeT3 === 'default') {
-                       return 'EN';
-               }
-                       // Return cached value if any
-               if (isset(self::$cache['getCurrentLanguage'][$langCodeT3])) {   
-                       return self::$cache['getCurrentLanguage'][$langCodeT3];
-               }
-
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                       'lg_iso_2,lg_country_iso_2',
-                       'static_languages',
-                       'lg_typo3=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($langCodeT3, 'static_languages')
-               );
-               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
-                       $lang = $row['lg_iso_2'] . ($row['lg_country_iso_2'] ? '_' . $row['lg_country_iso_2'] : '');
-               }
-               $GLOBALS['TYPO3_DB']->sql_free_result($res);
-
-               $lang = $lang ? $lang : $csConvObj->conv_case('utf-8', $langCodeT3, 'toUpper');
-
-                       // Initialize cache array
-               if (!is_array(self::$cache['getCurrentLanguage'])) {
-                       self::$cache['getCurrentLanguage'] = array();
-               }
-                       // Cache retrieved value
-               self::$cache['getCurrentLanguage'][$langCodeT3] = $lang;
-
-               return $lang;
-       }
-
-
-       /**
-        * Returns the row of the current system language
-        *
-        * @param       [type]          $where: ...
-        * @return      array           row in the sys_language table
-        */
-       function getCurrentSystemLanguage ($where='') {
-               global $LANG, $TSFE, $TYPO3_DB;
-
-               $rc = array();
-
-               if (is_object($LANG)) {
-                       $langCodeT3 = $LANG->lang;
-               } elseif (is_object($TSFE)) {
-                       $langCodeT3 = $TSFE->lang;
-               } else {
-                       return $rc;
-               }
-
-               $res = $TYPO3_DB->exec_SELECTquery(
-                       'sys_language.uid',
-                       'sys_language LEFT JOIN static_languages ON sys_language.static_lang_isocode=static_languages.uid',
-                       'static_languages.lg_typo3='.$TYPO3_DB->fullQuoteStr($langCodeT3,'static_languages').
-                               $where
-                       );
-               while($row = $TYPO3_DB->sql_fetch_assoc($res)) {
-                       $rc[$row['uid']] = $row;
-               }
-
-               $TYPO3_DB->sql_free_result($res);
-               return $rc;
-       }
-
-
-       /*
-        *
-        * Returns the locale to used when sorting labels
-        *
-        * @return      string  locale
-        */
-       function getCollateLocale () {
-               global $LANG, $TSFE, $TYPO3_DB;
-
-               if (is_object($LANG)) {
-                       $langCodeT3 = $LANG->lang;
-               } elseif (is_object($TSFE)) {
-                       $langCodeT3 = $TSFE->lang;
-               } else {
-                       return 'C';
-               }
-
-               $res = $TYPO3_DB->exec_SELECTquery(
-                       'lg_collate_locale',
-                       'static_languages',
-                       'lg_typo3='.$TYPO3_DB->fullQuoteStr($langCodeT3,'static_languages')
-                       );
-               while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
-                       $locale = $row['lg_collate_locale'];
-               }
-               $TYPO3_DB->sql_free_result($res);
-               return $locale ? $locale : 'C';
-       }
-
-
-       /**
-        * Fetches short title from an iso code
-        *
-        * @param       string          table name
-        * @param       string          iso code
-        * @param       string          language code - if not set current default language is used
-        * @param       boolean         local name only - if set local title is returned
-        * @return      string          short title
-        */
-       function getTitleFromIsoCode ($table, $isoCode, $lang='', $local=FALSE) {
-               global $TSFE, $TYPO3_DB;
-
-               $title = '';
-               $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang, $local);
-               if (count ($titleFields))       {
-                       $prefixedTitleFields = array();
-                       foreach ($titleFields as $titleField) {
-                               $prefixedTitleFields[] = $table.'.'.$titleField;
-                       }
-                       $fields = implode(',', $prefixedTitleFields);
-                       $whereClause = '1=1';
-                       if (!is_array($isoCode)) {
-                               $isoCode = array($isoCode);
-                       }
-                       $index = 0;
-                       foreach ($isoCode as $index => $code) {
-                               if ($code != '')        {
-                                       $tmpField = tx_staticinfotables_div::getIsoCodeField($table, $code, TRUE, $index);
-                                       $tmpValue = $TYPO3_DB->fullQuoteStr($code,$table);
-                                       if ($tmpField && $tmpValue)     {
-                                               $whereClause .= ' AND ' . $table . '.' . $tmpField . ' = ' . $tmpValue;
-                                       }
-                               }
-                       }
-                       if (is_object($TSFE)) {
-                               $enableFields = $TSFE->sys_page->enableFields($table);
-                       } else {
-                               $enableFields = t3lib_BEfunc::deleteClause($table);
-                       }
-
-                       $res = $TYPO3_DB->exec_SELECTquery(
-                               $fields,
-                               $table,
-                               $whereClause.$enableFields
-                       );
-                       if ($row = $TYPO3_DB->sql_fetch_assoc($res))    {
-                               foreach ($titleFields as $titleField) {
-                                       if ($row[$titleField]) {
-                                               $title = $row[$titleField];
-                                               break;
-                                       }
-                               }
-                       }
-                       $TYPO3_DB->sql_free_result($res);
-               }
-
-               return $title;
-       }
-
-
-       /**
-        * Replaces any dynamic markers in a SQL statement.
-        *
-        * @param       string          The SQL statement with dynamic markers.
-        * @param       string          Name of the table.
-        * @param       array           row from table.
-        * @return      string          SQL query with dynamic markers subsituted.
-        */
-       function replaceMarkersInSQL ($sql, $table, $row)       {
-
-               $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($table, $row);
-
-               /* Replace references to specific fields with value of that field */
-               if (strstr($sql,'###REC_FIELD_'))       {
-                       $sql_parts = explode('###REC_FIELD_',$sql);
-                       while(list($kk,$vv)=each($sql_parts))   {
-                               if ($kk)        {
-                                       $sql_subpart = explode('###',$vv,2);
-                                       $sql_parts[$kk]=$TSconfig['_THIS_ROW'][$sql_subpart[0]].$sql_subpart[1];
-                               }
-                       }
-                       $sql = implode('',$sql_parts);
-               }
-
-               /* Replace markers with TSConfig values */
-               $sql = str_replace('###THIS_UID###',intval($TSconfig['_THIS_UID']),$sql);
-               $sql = str_replace('###THIS_CID###',intval($TSconfig['_THIS_CID']),$sql);
-               $sql = str_replace('###SITEROOT###',intval($TSconfig['_SITEROOT']),$sql);
-               $sql = str_replace('###PAGE_TSCONFIG_ID###',intval($TSconfig[$field]['PAGE_TSCONFIG_ID']),$sql);
-               $sql = str_replace('###PAGE_TSCONFIG_IDLIST###',$GLOBALS['TYPO3_DB']->cleanIntList($TSconfig[$field]['PAGE_TSCONFIG_IDLIST']),$sql);
-               $sql = str_replace('###PAGE_TSCONFIG_STR###',$GLOBALS['TYPO3_DB']->quoteStr($TSconfig[$field]['PAGE_TSCONFIG_STR'], $table),$sql);
-
-               return $sql;
-       }
-
-
-       /**
-        * Function to use in own TCA definitions
-        * Adds additional select items
-        *
-        *                      items           reference to the array of items (label,value,icon)
-        *                      config          The config array for the field.
-        *                      TSconfig        The "itemsProcFunc." from fieldTSconfig of the field.
-        *                      table           Table name
-        *                      row             Record row
-        *                      field           Field name
-        *
-        * @param       array           itemsProcFunc data array:
-        * @return      void            The $items array may have been modified
-        */
-       function selectItemsTCA ($params) {
-               global $TCA;
-
-               $where = '';
-               $config = &$params['config'];
-               $table = $config['itemsProcFunc_config']['table'];
-               $tcaWhere = $config['itemsProcFunc_config']['where'];
-               if ($tcaWhere)  {
-                       $where = tx_staticinfotables_div::replaceMarkersInSQL($tcaWhere, $params['table'], $params['row']);
-               }
-
-               if ($table) {
-                       $indexField = $config['itemsProcFunc_config']['indexField'];
-                       $indexField = $indexField ? $indexField : 'uid';
-
-                       $lang = strtolower(tx_staticinfotables_div::getCurrentLanguage());
-                       $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
-                       $prefixedTitleFields = array();
-                       foreach ($titleFields as $titleField) {
-                               $prefixedTitleFields[] = $table.'.'.$titleField;
-                       }
-                       $fields = $table.'.'.$indexField.','.implode(',', $prefixedTitleFields);
-
-                       if ($config['itemsProcFunc_config']['prependHotlist']) {
-
-                               $limit = $config['itemsProcFunc_config']['hotlistLimit'];
-                               $limit = $limit ? $limit : '8';
-                               $app = $config['itemsProcFunc_config']['hotlistApp'];
-                               $app = $app ? $app : TYPO3_MODE;
-
-                               $res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
-                                               $fields,
-                                               $table,
-                                               'tx_staticinfotables_hotlist',
-                                               '',     // $foreign_table
-                                               'AND tx_staticinfotables_hotlist.tablenames='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'tx_staticinfotables_hotlist').' AND tx_staticinfotables_hotlist.application='.$GLOBALS['TYPO3_DB']->fullQuoteStr($app,'tx_staticinfotables_hotlist'),
-                                               '',
-                                               'tx_staticinfotables_hotlist.sorting DESC',     // $orderBy
-                                               $limit
-                                       );
-
-                               $cnt = 0;
-                               $rows = array();
-                               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
-
-                                       foreach ($titleFields as $titleField) {
-                                               if ($row[$titleField]) {
-                                                       $rows[$row[$indexField]] = $row[$titleField];
-                                                       break;
-                                               }
-                                       }
-                                       $cnt++;
-                               }
-                               $GLOBALS['TYPO3_DB']->sql_free_result($res);
-
-                               if (!isset($config['itemsProcFunc_config']['hotlistSort']) || $config['itemsProcFunc_config']['hotlistSort']) {
-                                       asort ($rows);
-                               }
-
-                               foreach ($rows as $index => $title)     {
-                                       $params['items'][] = array($title, $index, '');
-                                       $cnt++;
-                               }
-                               if($cnt && !$config['itemsProcFunc_config']['hotlistOnly']) {
-                                       $params['items'][] = array('--------------', '', '');
-                               }
-                       }
-
-                               // Set ORDER BY:
-                       $orderBy = $titleFields[0];
-
-                       if(!$config['itemsProcFunc_config']['hotlistOnly']) {
-                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, '1=1'.$where.t3lib_BEfunc::deleteClause($table), '', $orderBy);
-                               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
-                                       foreach ($titleFields as $titleField) {
-                                               if ($row[$titleField]) {
-                                                       $params['items'][] = array($row[$titleField], $row[$indexField], '');
-                                                       break;
-                                               }
-                                       }
-                               }
-                               $GLOBALS['TYPO3_DB']->sql_free_result($res);
-                       }
-               }
-       }
-
-
-       /**
-        * Updates the hotlist table.
-        * This means that a hotlist entry will be created or the counter of an existing entry will be increased
-        *
-        * @param       string          table name: static_countries, ...
-        * @param       string          value of the following index field
-        * @param       string          the field which holds the value and is an index field: uid (default) or one of the iso code fields which are also unique
-        * @param       string          This indicates a counter group. Default is TYPO3_MOD (BE or FE). If you want a unique hotlist for your application you can provide here a name (e.g. extension key)
-        * @return      void
-        */
-       function updateHotlist ($table, $indexValue, $indexField='', $app='') {
-
-               if ($table && $indexValue) {
-                       $indexField = $indexField ? $indexField : 'uid';
-                       $app = $app ? $app : TYPO3_MODE;
-
-                       if ($indexField=='uid') {
-                               $uid = $indexValue;
-
-                       } else {
-                                       // fetch original record
-                               $fields = array();
-                               $fields[$indexField] = $indexField;
-                               $fields['uid'] = 'uid';
-
-                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',',$fields), $table, $indexField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($indexValue,$table).t3lib_BEfunc::deleteClause($table));
-                               if ($res !== FALSE)     {
-                                       if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
-                                               $uid = $row['uid'];
-                                       }
-                                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
-                               }
-                       }
-
-                       if ($uid) {
-                                       // update record from hotlist table
-                               $newRow = array('sorting' => 'sorting+1');
-                               // the dumb update function does not allow to use sorting+1 - that's why this trick is necessary
-
-                               $GLOBALS['TYPO3_DB']->sql_query(str_replace('"sorting+1"', 'sorting+1', $GLOBALS['TYPO3_DB']->UPDATEquery(
-                                               'tx_staticinfotables_hotlist',
-                                               'uid_local='.$uid.
-                                                       ' AND application='.$GLOBALS['TYPO3_DB']->fullQuoteStr($app,'tx_staticinfotables_hotlist').
-                                                       ' AND tablenames='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'tx_staticinfotables_hotlist').
-                                                       t3lib_BEfunc::deleteClause('tx_staticinfotables_hotlist'),
-                                               $newRow)));
-
-                               if (!$GLOBALS['TYPO3_DB']->sql_affected_rows()) {
-                                               // insert new hotlist entry
-                                       $row = array(
-                                               'uid_local' => $uid,
-                                               'tablenames' => $table,
-                                               'application' => $app,
-                                               'sorting' => 1,
-                                       );
-                                       $res = $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_staticinfotables_hotlist', $row);
-                               }
-                       }
-               }
-       }
-
-
-       /**
-        * Get a list of countries by specific parameters or parts of names of countries
-        * in different languages. Parameters might be left empty.
-        *
-        * @param       string          a name of the country or a part of it in any language
-        * @param       string          ISO alpha-2 code of the country
-        * @param       string          ISO alpha-3 code of the country
-        * @param       array           Database row.
-        * @return      array           Array of rows of country records
-        */
-       function &fetchCountries ($country, $iso2='', $iso3='', $isonr='')      {
-               global $TYPO3_DB;
-
-               $rcArray = array();
-               $where = '';
-
-               $table = 'static_countries';
-               if ($country != '')     {
-                       $value = $TYPO3_DB->fullQuoteStr(trim('%'.$country.'%'),$table);
-                       $where = 'cn_official_name_local LIKE '.$value.' OR cn_official_name_en LIKE '.$value.' OR cn_short_local LIKE '.$value;
-               }
-
-               if ($isonr != '')       {
-                       $where = 'cn_iso_nr='.$TYPO3_DB->fullQuoteStr(trim($isonr),$table);
-               }
-
-               if ($iso2 != '')        {
-                       $where = 'cn_iso_2='.$TYPO3_DB->fullQuoteStr(trim($iso2),$table);
-               }
-
-               if ($iso3 !='') {
-                       $where = 'cn_iso_3='.$TYPO3_DB->fullQuoteStr(trim($iso3),$table);
-               }
-
-               if ($where != '')       {
-                       $res = $TYPO3_DB->exec_SELECTquery('*', $table, $where);
-
-                       if ($res)       {
-                               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
-                                       $rcArray[] = $row;
-                               }
-                       }
-                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
-               }
-               return $rcArray;
-       }
-
-
-       /**
-        * Quotes a string for usage as JS parameter. Depends wheter the value is used in script tags (it must not get `htmlspecialchar'ed in this case because this is done in this function)
-        *
-        * @param       string          The string to encode.
-        * @param       boolean         If the values are used inside of <script> tags.
-        * @return      string          The encoded value already quoted
-        */
-       function quoteJSvalue ($value, $inScriptTags=FALSE) {
-               $value = addcslashes($value, '"'.chr(10).chr(13));
-               if (!$inScriptTags) {
-                       $value = htmlspecialchars($value, ENT_COMPAT, $GLOBALS['TSFE']->renderCharset);
-               }
-               return '"'.$value.'"';
-       }
-
-
-       /**
-        * loadTcaAdditions($ext_keys)
-        *
-        * It has been copied here in order not to depend on the div extension only for this function.
-        *
-        * @param       array           extension keys which have TCA additions to load
-        * @return      void
-        * @see div extension
-        */
-       function loadTcaAdditions ($ext_keys){
-               global $_EXTKEY, $TCA;
-
-               //Merge all ext_keys
-               if (is_array($ext_keys)) {
-                       foreach ($ext_keys as $_EXTKEY) {
-                               if (t3lib_extMgm::isLoaded($_EXTKEY))   {
-                                       //Include the ext_table
-                                       include(t3lib_extMgm::extPath($_EXTKEY).'ext_tables.php');
-                               }
-                       }
-               }
-       }
-}
-
-
-if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/static_info_tables/class.tx_staticinfotables_div.php'])    {
-       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/static_info_tables/class.tx_staticinfotables_div.php']);
-}
-?>
\ No newline at end of file
index 02fde83..d023567 100644 (file)
 class tx_staticinfotables_syslanguage {
 
        function processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, &$pObj) {
-               if($table == 'sys_language' AND $fieldArray['static_lang_isocode']) {
-                               // the hotlist will be updated only if the field changed, because only then it's in the $fieldArray
-                       tx_staticinfotables_div::updateHotlist ('static_languages', $fieldArray['static_lang_isocode'], 'uid');
+               if($table == 'sys_language' && $fieldArray['static_lang_isocode']) {
+                       // the hotlist will be updated only if the field changed, because only then it's in the $fieldArray
+                       \SJBR\StaticInfoTables\Utility\EntityLabelUtility::updateHotlist('static_languages', $fieldArray['static_lang_isocode'], 'uid');
                }
        }
 }
 
-
-if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/static_info_tables/class.tx_staticinfotables_syslanguage.php'])    {
-       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/static_info_tables/class.tx_staticinfotables_syslanguage.php']);
-}
 ?>
\ No newline at end of file
index 71e854f..aba57aa 100644 (file)
Binary files a/doc/manual.sxw and b/doc/manual.sxw differ
index c334025..c686865 100644 (file)
@@ -2,15 +2,18 @@
 /*
  * Register necessary class names with autoloader
  *
- * $Id: ext_autoload.php $
  */
 $extensionPath = t3lib_extMgm::extPath('static_info_tables');
+$extensionClassesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('static_info_tables') . 'Classes/';
 return array(
-       'tx_staticinfotables_renderElement' => $extensionPath . 'Classes/Hook/Backend/Form/class.tx_staticinfotables_renderElement.php',
-       'tx_staticinfotables_processdatamap' => $extensionPath . 'Classes/Hook/Core/DataHandling/class.tx_staticinfotables_processdatamap.php',
-       'tx_staticinfotables_div' => $extensionPath . 'class.tx_staticinfotables_div.php',
+       'SJBR\StaticInfoTables\PiBaseApi' => $extensionClassesPath . 'PiBaseApi.php',
+       'SJBR\StaticInfoTables\Hook\Backend\Form\ElementRenderingHelper' => $extensionClassesPath . 'Hook/Backend/Form/ElementRenderingHelper.php',
+       'SJBR\StaticInfoTables\Hook\Core\DataHandling\ProcessDataMap' => $extensionClassesPath . 'Hook/Core/DataHandling/ProcessDataMap.php',
+       'SJBR\StaticInfoTables\Utility\EntityLabelUtility' => $extensionClassesPath . 'Utility/EntityLabelUtility.php',
+       'SJBR\StaticInfoTables\Utility\LocalizationUtility' => $extensionClassesPath . 'Utility/LocalizationUtility.php',
+       'SJBR\StaticInfoTables\Utility\TcaUtility' => $extensionClassesPath . 'Utility/TcaUtility.php',
        'tx_staticinfotables_syslanguage' => $extensionPath . 'class.tx_staticinfotables_syslanguage.php',
-       'tx_staticinfotables_pi1' => $extensionPath . 'pi1/class.tx_staticinfotables_pi1.php',
 );
 unset($extensionPath);
+unset($extensionClassesPath);
 ?>
\ No newline at end of file
index 73deded..60ab853 100644 (file)
@@ -34,8 +34,8 @@ $EM_CONF[$_EXTKEY] = array(
        'CGLcompliance_note' => '',\r
        'constraints' => array(\r
                'depends' => array(\r
-                       'typo3' => '4.7-0.0.0',\r
-                       'php' => '5.3.0-0.0.0',\r
+                       'typo3' => '6.0.2-0.0.0',\r
+                       'php' => '5.3.7-0.0.0',\r
                ),\r
                'conflicts' => array(\r
                        'sr_static_info' => '',\r
index 324920f..66e6932 100644 (file)
@@ -1,16 +1,18 @@
 <?php
-if (!defined ('TYPO3_MODE'))   die ('Access denied.');
+if (!defined ('TYPO3_MODE')) {
+       die ('Access denied.');
+}
 
 if (!defined ('STATIC_INFO_TABLES_EXTkey')) {
-       define('STATIC_INFO_TABLES_EXTkey',$_EXTKEY);
+       define('STATIC_INFO_TABLES_EXTkey', $_EXTKEY);
 }
 
 if (!defined ('PATH_BE_staticinfotables')) {
-       define('PATH_BE_staticinfotables', t3lib_extMgm::extPath(STATIC_INFO_TABLES_EXTkey));
+       define('PATH_BE_staticinfotables', \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY));
 }
 
 if (!defined ('PATH_BE_staticinfotables_rel')) {
-       define('PATH_BE_staticinfotables_rel', t3lib_extMgm::extRelPath(STATIC_INFO_TABLES_EXTkey));
+       define('PATH_BE_staticinfotables_rel', \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY));
 }
 
 // Unserializing the configuration so we can use it here
@@ -60,9 +62,9 @@ $labelTable = array(
        ),
 );
 
-if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables']) && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'])) {
-       $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'] = array_merge ($labelTable, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables']);
+if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY]['tables']) && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY]['tables'])) {
+       $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY]['tables'] = array_merge ($labelTable, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY]['tables']);
 } else {
-       $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'] = $labelTable;
+       $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY]['tables'] = $labelTable;
 }
 ?>
\ No newline at end of file
index f2f209b..6b357e8 100644 (file)
@@ -1,15 +1,17 @@
 <?php
-if (!defined ('TYPO3_MODE'))   die ('Access denied.');
+if (!defined ('TYPO3_MODE')) {
+       die ('Access denied.');
+}
 
-t3lib_extMgm::addStaticFile('static_info_tables', 'Configuration/TypoScript/', 'Static Info tables');
+// Configure extension static template
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('static_info_tables', 'Configuration/TypoScript/', 'Static Info Tables');
 
 $GLOBALS['TCA']['static_territories'] = array(
        'ctrl' => array(
                'label' => 'tr_name_en',
                'label_alt' => 'tr_iso_nr',
                'label_alt_force' => 1,
-               'label_userFunc' => 'EXT:static_info_tables/Classes/Hook/Backend/Form/class.tx_staticinfotables_renderElement.php:tx_staticinfotables_renderElement->addIsoCodeToLabel',
-               // This should always be true, as it prevents the static data from being altered
+               'label_userFunc' => 'SJBR\StaticInfoTables\Hook\Backend\Form\ElementRenderingHelper->addIsoCodeToLabel',
                'readOnly' => 1,
                'adminOnly' => 1,
                'rootLevel' => 1,
@@ -31,16 +33,15 @@ $GLOBALS['TCA']['static_countries'] = array(
                'label' => 'cn_short_en',
                'label_alt' => 'cn_iso_2',
                'label_alt_force' => 1,
-               'label_userFunc' => 'EXT:static_info_tables/Classes/Hook/Backend/Form/class.tx_staticinfotables_renderElement.php:tx_staticinfotables_renderElement->addIsoCodeToLabel',
-               // This should always be true, as it prevents the static data from being altered
+               'label_userFunc' => 'SJBR\StaticInfoTables\Hook\Backend\Form\ElementRenderingHelper->addIsoCodeToLabel',
                'readOnly' => 1,
                'adminOnly' => 1,
                'rootLevel' => 1,
                'is_static' => 1,
                'default_sortby' => 'ORDER BY cn_short_en',
                'delete' => 'deleted',
-               'title' => 'LLL:EXT:'.STATIC_INFO_TABLES_EXTkey.'/Resources/Private/Language/locallang_db.xlf:static_countries.title',
-               'dynamicConfigFile' => PATH_BE_staticinfotables.'tca.php',
+               'title' => 'LLL:EXT:static_info_tables/Resources/Private/Language/locallang_db.xlf:static_countries.title',
+               'dynamicConfigFile' => PATH_BE_staticinfotables . 'tca.php',
                'iconfile' => PATH_BE_staticinfotables_rel . 'Resources/Public/Images/Icons/icon_static_countries.gif',
        ),
        'interface' => array(
@@ -59,8 +60,8 @@ $GLOBALS['TCA']['static_country_zones'] = array(
                'is_static' => 1,
                'default_sortby' => 'ORDER BY zn_name_local',
                'delete' => 'deleted',
-               'title' => 'LLL:EXT:'.STATIC_INFO_TABLES_EXTkey.'/Resources/Private/Language/locallang_db.xlf:static_country_zones.title',
-               'dynamicConfigFile' => PATH_BE_staticinfotables.'tca.php',
+               'title' => 'LLL:EXT:static_info_tables/Resources/Private/Language/locallang_db.xlf:static_country_zones.title',
+               'dynamicConfigFile' => PATH_BE_staticinfotables . 'tca.php',
                'iconfile' => PATH_BE_staticinfotables_rel . 'Resources/Public/Images/Icons/icon_static_countries.gif',
        ),
        'interface' => array(
@@ -72,15 +73,17 @@ $GLOBALS['TCA']['static_country_zones'] = array(
 $GLOBALS['TCA']['static_languages'] = array(
        'ctrl' => array(
                'label' => 'lg_name_en',
-               'label_alt' => 'lg_name_en,lg_iso_2',
+               'label_alt' => 'lg_iso_2',
+               'label_alt_force' => 1,
+               'label_userFunc' => 'SJBR\StaticInfoTables\Hook\Backend\Form\ElementRenderingHelper->addIsoCodeToLabel',
                'readOnly' => 1,
                'adminOnly' => 1,
                'rootLevel' => 1,
                'is_static' => 1,
                'default_sortby' => 'ORDER BY lg_name_en',
                'delete' => 'deleted',
-               'title' => 'LLL:EXT:'.STATIC_INFO_TABLES_EXTkey.'/Resources/Private/Language/locallang_db.xlf:static_languages.title',
-               'dynamicConfigFile' => PATH_BE_staticinfotables.'tca.php',
+               'title' => 'LLL:EXT:static_info_tables/Resources/Private/Language/locallang_db.xlf:static_languages.title',
+               'dynamicConfigFile' => PATH_BE_staticinfotables . 'tca.php',
                'iconfile' => PATH_BE_staticinfotables_rel . 'Resources/Public/Images/Icons/icon_static_languages.gif',
        ),
        'interface' => array(
@@ -94,15 +97,15 @@ $GLOBALS['TCA']['static_currencies'] = array(
                'label' => 'cu_name_en',
                'label_alt' => 'cu_iso_3',
                'label_alt_force' => 1,
-               'label_userFunc' => 'EXT:static_info_tables/Classes/Hook/Backend/Form/class.tx_staticinfotables_renderElement.php:tx_staticinfotables_renderElement->addIsoCodeToLabel',
+               'label_userFunc' => 'SJBR\StaticInfoTables\Hook\Backend\Form\ElementRenderingHelper->addIsoCodeToLabel',
                'readOnly' => 1,
                'adminOnly' => 1,
                'rootLevel' => 1,
                'is_static' => 1,
                'default_sortby' => 'ORDER BY cu_name_en',
                'delete' => 'deleted',
-               'title' => 'LLL:EXT:'.STATIC_INFO_TABLES_EXTkey.'/Resources/Private/Language/locallang_db.xlf:static_currencies.title',
-               'dynamicConfigFile' => PATH_BE_staticinfotables.'tca.php',
+               'title' => 'LLL:EXT:static_info_tables/Resources/Private/Language/locallang_db.xlf:static_currencies.title',
+               'dynamicConfigFile' => PATH_BE_staticinfotables . 'tca.php',
                'iconfile' => PATH_BE_staticinfotables_rel . 'Resources/Public/Images/Icons/icon_static_currencies.gif',
        ),
        'interface' => array(
@@ -117,11 +120,8 @@ $GLOBALS['TCA']['static_currencies']['ctrl']['readOnly'] = 0;
 $GLOBALS['TCA']['static_territories']['ctrl']['readOnly'] = 0;
 
 
-// ******************************************************************
-// sys_language
-// ******************************************************************
-
-t3lib_div::loadTCA('sys_language');
+// Configure static language field of sys_language table
+\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_language');
 $GLOBALS['TCA']['sys_language']['columns']['static_lang_isocode']['config'] = array(
        'type' => 'select',
        'items' => array(
@@ -129,7 +129,7 @@ $GLOBALS['TCA']['sys_language']['columns']['static_lang_isocode']['config'] = ar
        ),
        #'foreign_table' => 'static_languages',
        #'foreign_table_where' => 'AND static_languages.pid=0 ORDER BY static_languages.lg_name_en',
-       'itemsProcFunc' => 'tx_staticinfotables_div->selectItemsTCA',
+       'itemsProcFunc' => 'SJBR\StaticInfoTables\Utility\EntityLabelUtility->selectItemsTCA',
        'itemsProcFunc_config' => array(
                'table' => 'static_languages',
                'indexField' => 'uid',
@@ -142,12 +142,15 @@ $GLOBALS['TCA']['sys_language']['columns']['static_lang_isocode']['config'] = ar
                //'hotlistOnly' => 0,
                //'hotlistApp' => TYPO3_MODE,
        ),
+       /*'foreign_table' => 'static_languages',
+       'foreign_table_where' => 'AND static_languages.pid=0 ORDER BY static_languages.lg_name_en',
+       'itemsProcFunc' => 'SJBR\StaticInfoTables\Hook\Backend\Form\ElementRenderingHelper->translateLanguagesSelector',*/
        'size' => 1,
        'minitems' => 0,
-       'maxitems' => 1,
+       'maxitems' => 1
 );
 // Add data handling hooks
-$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:static_info_tables/Classes/Hook/Core/DataHandling/class.tx_staticinfotables_processdatamap.php:&tx_staticinfotables_processdatamap';
-$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:static_info_tables/class.tx_staticinfotables_syslanguage.php:&tx_staticinfotables_syslanguage';
+$GLOBSALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = '&SJBR\StaticInfoTables\Hook\Core\DataHandling\ProcessDataMap';
+$GLOBSALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:static_info_tables/class.tx_staticinfotables_syslanguage.php:&tx_staticinfotables_syslanguage';
 
 ?>
\ No newline at end of file
index ffe726a..65b4681 100644 (file)
@@ -1,679 +1,3 @@
 <?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2004-2010 Stanislas Rolland <stanislas.rolland(arobas)sjbr.ca>
-*  All rights reserved
-*
-*  This script is part of the Typo3 project. The Typo3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*  A copy is found in the textfile GPL.txt and important notices to the license
-*  from the author is found in LICENSE.txt distributed with these scripts.
-*
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
-/**
- *
- * Class for handling static info tables: countries, and subdivisions, currencies, languages and taxes
- *
- * $Id$
- *
- * @author     Stanislas Rolland <stanislas.rolland(arobas)sjbr.ca>
- */
-
-/**
- * [CLASS/FUNCTION INDEX of SCRIPT]
- *
- *
- *
- *   66: class tx_staticinfotables_pi1 extends tslib_pibase
- *   97:     function needsInit ()
- *  108:     function init ($conf=array())
- *  166:     function getStaticInfoName ($type='COUNTRIES', $code, $country='', $countrySubdivision='', $local=FALSE)
- *  238:     function buildStaticInfoSelector ($type='COUNTRIES', $name='', $class='', $selectedArray=array(), $country='', $submit=0, $id='', $title='', $addWhere='', $lang='', $local=FALSE, $mergeArray=array(), $size=1, &$outSelectedArray=array())
- *  324:     function initCountries ($param='UN', $lang='', $local=FALSE, $addWhere='')
- *  382:     function initCountrySubdivisions ($param, $addWhere='')
- *  429:     function initCurrencies ($addWhere='')
- *  470:     function initLanguages ($addWhere='')
- *  512:     function optionsConstructor ($nameArray, $selectedArray=array(), &$outSelectedArray=array())
- *  539:     function loadCurrencyInfo ($currencyCode)
- *  585:     function formatAmount ($amount, $displayCurrencyCode='')
- *  614:     function formatAddress ($delim, $streetAddress, $city, $zip, $subdivisionCode='', $countryCode='')
- *  659:     function getCurrentLanguage ()
- *
- * TOTAL FUNCTIONS: 13
- * (This index is automatically created/updated by the extension "extdeveval")
- *
- */
-
-class tx_staticinfotables_pi1 extends tslib_pibase {
-
-       var $cObj;              // The backReference to the mother cObj object set at call time
-       var $prefixId = 'tx_staticinfotables_pi1';              // Same as class name
-       var $scriptRelPath = 'pi1/class.tx_staticinfotables_pi1.php';   // Path to this script relative to the extension dir.
-       var $extKey = 'static_info_tables';              // The extension key.
-       var $conf = array();
-       var $currency;          // default currency
-       var $currencyInfo = array();
-       var $defaultCountry;
-       var $defaultCountryZone;
-       var $defaultLanguage;
-       var $types = array('TERRITORIES', 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES', 'LANGUAGES', 'TAXES', 'SUBTAXES');
-       var $tables = array(
-               'TERRITORIES'   => 'static_territories',
-               'COUNTRIES'     => 'static_countries',
-               'SUBDIVISIONS'  => 'static_country_zones',
-               'CURRENCIES'    => 'static_currencies',
-               'LANGUAGES'     => 'static_languages',
-               'TAXES'         => 'static_taxes',
-               'SUBTAXES'      => 'static_taxes'
-       );
-       var $bHasBeenInitialised = FALSE;
-
-
-       /**
-        * Returns info if the tx_staticinfotables_pi1 object has already been initialised.
-        * You need to initialise this object only once.
-        *
-        * @return      boolean         Always returns true
-        */
-       function needsInit ()   {
-               return !$this->bHasBeenInitialised;
-       }
-
-
-       /**
-        * Initializing the class: sets the language based on the TS configuration language property
-        *
-        * @param       array           $conf ... overwriting setup of extension
-        * @return      boolean         Always returns true
-        */
-       function init ($conf=array())   {
-
-               $this->conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->prefixId.'.'];
-
-                       //Get the default currency and make sure it does exist in table static_currencies
-               $this->currency = $conf['currencyCode'];
-               if (!$this->currency)   {
-                       $this->currency = (trim($this->conf['currencyCode'])) ? trim($this->conf['currencyCode']) : 'EUR';
-               }
-                       //If nothing is set, we use the Euro because TYPO3 is spread more in this area
-               if (!$this->getStaticInfoName('CURRENCIES', $this->currency)) {
-                       $this->currency = 'EUR';
-               }
-               $this->currencyInfo = $this->loadCurrencyInfo($this->currency);
-               $this->defaultCountry = $conf['countryCode'];
-
-               if (!$this->defaultCountry)     {
-                       $this->defaultCountry = trim($this->conf['countryCode']);
-               }
-               if (!$this->getStaticInfoName('COUNTRIES', $this->defaultCountry)) {
-                       $this->defaultCountry = 'DEU';
-               }
-
-               $this->defaultCountryZone = $conf['countryZoneCode'];
-               if (!$this->defaultCountryZone) {
-                       $this->defaultCountryZone = trim($this->conf['countryZoneCode']);
-               }
-               if (!$this->getStaticInfoName('SUBDIVISIONS', $this->defaultCountryZone, $this->defaultCountry))        {
-                       if ($this->defaultCountry == 'DEU') {
-                               $this->defaultCountryZone = 'NW';
-                       } else {
-                               $this->defaultCountryZone = '';
-                       }
-               }
-
-               $this->defaultLanguage = $conf['languageCode'];
-               if (!$this->defaultLanguage)    {
-                       $this->defaultLanguage = trim($this->conf['languageCode']);
-               }
-               if (!$this->getStaticInfoName('LANGUAGES', $this->defaultLanguage)) {
-                       $this->defaultLanguage = 'EN';
-               }
-               $this->bHasBeenInitialised = TRUE;
-               return TRUE;
-       }
-
-
-       /**
-        * Getting the name of a country, country subdivision, currency, language, tax
-        *
-        * @param       string          Defines the type of entry of the requested name: 'TERRIRORIES', 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES', 'LANGUAGES', 'TAXES', 'SUBTAXES'
-        * @param       string          The ISO alpha-3 code of a territory, country or currency, or the ISO alpha-2 code of a language or the code of a country subdivision, can be a comma ',' separated string, then all the single items are looked up and returned
-        * @param       string          The value of the country code (cn_iso_3) for which a name of type 'SUBDIVISIONS', 'TAXES' or 'SUBTAXES' is requested (meaningful only in these cases)
-        * @param       string          The value of the country subdivision code for which a name of type 'SUBTAXES' is requested (meaningful only in this case)
-        * @param       boolean         local name only - if set local title is returned
-        * @return      string          The name of the object in the current language
-        */
-       function getStaticInfoName ($type='COUNTRIES', $code, $country='', $countrySubdivision='', $local=FALSE) {
-               global $TYPO3_DB;
-
-               if (in_array($type, $this->types) && trim($code)) {
-                       $codeArray = t3lib_div::trimExplode(',',($code));
-                       $table = $this->tables[$type];
-                       if (!$table)    {
-                               return FALSE;
-                       }
-                       $lang = $this->getCurrentLanguage();
-                       if (!t3lib_extMgm::isLoaded(STATIC_INFO_TABLES_EXTkey.'_'.strtolower($lang)))   {
-                               $lang = '';
-                       }
-                       $nameArray = array();
-                       foreach ($codeArray as $tmpisoCode)     {
-                               $isoCodeArray = array();
-                               $isoCodeArray[] = $tmpisoCode;
-
-                               switch($type)   {
-                                       case 'TERRITORIES':
-                                       case 'COUNTRIES':
-                                       case 'CURRENCIES':
-                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $local);
-                                               break;
-                                       case 'SUBDIVISIONS':
-                                       case 'TAXES':
-                                               $isoCodeArray[] = trim($country) ? trim($country) : $this->defaultCountry;
-                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $local);
-                                               break;
-                                       case 'SUBTAXES':
-                                               $isoCodeArray[] = trim($country) ? trim($country) : $this->defaultCountry;
-                                               $isoCodeArray[] = trim($countrySubdivision) ? trim($countrySubdivision) : $this->defaultCountryZone;
-                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $local);
-                                               break;
-                                       case 'LANGUAGES':
-                                               $isoCodeArray = t3lib_div::trimExplode( '_', $code, 1);
-                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $local);
-                                               break;
-                               }
-                               if (!$name && $lang != 'EN')    {
-                                       // use the default English name if there is not text in another language
-                                       $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, '', $local);
-                               }
-                               $nameArray[] = $GLOBALS['TSFE']->csConv($name, 'utf-8');
-                       }
-                       $rc = implode(',',$nameArray);
-               } else {
-                       $rc = FALSE;
-               }
-               return $rc;
-       }
-
-
-       /**
-        * Buils a HTML drop-down selector of countries, country subdivisions, currencies or languages
-        *
-        * @param       string          Defines the type of entries to be presented in the drop-down selector: 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES' or 'LANGUAGES'
-        * @param       string          A value for the name attribute of the <select> tag
-        * @param       string          A value for the class attribute of the <select> tag
-        * @param       array           The values of the code of the entries to be pre-selected in the drop-down selector: value of cn_iso_3, zn_code, cu_iso_3 or lg_iso_2
-        * @param       string          The value of the country code (cn_iso_3) for which a drop-down selector of type 'SUBDIVISIONS' is requested (meaningful only in this case)
-        * @param       boolean/string          If set to 1, an onchange attribute will be added to the <select> tag for immediate submit of the changed value; if set to other than 1, overrides the onchange script
-        * @param       string          A value for the id attribute of the <select> tag
-        * @param       string          A value for the title attribute of the <select> tag
-        * @param       string          A where clause for the records
-        * @param       string          language to be used
-        * @param       boolean         $local: If set, we are looking for the "local" title field
-        * @param       array           additional array to be merged as key => value pair
-        * @param       int             max elements that can be selected. Default: 1
-        * @param       array           out: resulting selected array with the ISO alpha-3 code of the countries
-        * @return      string          A set of HTML <select> and <option> tags
-        */
-       function buildStaticInfoSelector ($type='COUNTRIES', $name='', $class='', $selectedArray=array(), $country='', $submit=0, $id='', $title='', $addWhere='', $lang='', $local=FALSE, $mergeArray=array(), $size=1, &$outSelectedArray=array())    {
-
-               if ($size > 1) {
-                       $multiple = ' multiple="multiple"';
-                       $name .= '[]';
-               } else {
-                       $multiple="";
-               }
-               if (isset($selectedArray) && !is_array($selectedArray)) {
-                       $selectedArray = t3lib_div::trimExplode (',',$selectedArray);
-               }
-
-               $charset = $GLOBALS['TSFE']->renderCharset;
-               $country = trim($country);
-               $nameAttribute = (trim($name)) ? 'name="'.htmlspecialchars(trim($name), ENT_COMPAT, $charset).'" ' : '';
-               $classAttribute = (trim($class)) ? 'class="'.htmlspecialchars(trim($class), ENT_COMPAT, $charset).'" ' : '';
-               $idAttribute = (trim($id)) ? 'id="'.htmlspecialchars(trim($id), ENT_COMPAT, $charset).'" ' : '';
-               $titleAttribute = (trim($title)) ? 'title="'.htmlspecialchars(trim($title), ENT_COMPAT, $charset).'" ' : '';
-               $onchangeAttribute = '';
-               if ($submit) {
-                       if ($submit == 1) {
-                               $onchangeAttribute = $this->conf['onChangeAttribute'];
-                       } else {
-                               $onchangeAttribute = $submit;
-                       }
-                       $onchangeAttribute = str_replace('"', '\'', $onchangeAttribute);
-                       $onchangeAttribute = tx_staticinfotables_div::quoteJSvalue($onchangeAttribute);
-                       $onchangeAttribute = 'onchange='.$onchangeAttribute;
-               }
-               $selector = '<select size="'.$size.'" '.$idAttribute.$nameAttribute.$titleAttribute.$classAttribute.$onchangeAttribute.$multiple.'>'.chr(10);
-
-               switch($type)   {
-                       case 'COUNTRIES':
-                               $nameArray = $this->initCountries('ALL',$lang,$local,$addWhere);
-                               $defaultSelectedArray = array($this->defaultCountry);
-                               break;
-                       case 'SUBDIVISIONS':
-                               $param = (trim($country) ? trim($country) : $this->defaultCountry);
-                               $nameArray = $this->initCountrySubdivisions($param,$addWhere);
-                               if($param == $this->defaultCountry) {
-                                       $defaultSelectedArray = array($this->defaultCountryZone);
-                               }
-                               break;
-                       case 'CURRENCIES':
-                               $nameArray = $this->initCurrencies($addWhere);
-                               $defaultSelectedArray = array($this->currency);
-                               break;
-                       case 'LANGUAGES':
-                               $nameArray = $this->initLanguages($addWhere);
-                               $defaultSelectedArray = array($this->defaultLanguage);
-                               break;
-               }
-
-               if (!$defaultSelectedArray)     {
-                       reset($nameArray);
-                       $defaultSelectedArray = array(key($nameArray));
-               }
-               $bEmptySelected = (empty($selectedArray) || ((count($selectedArray) == 1) && empty($selectedArray[0])));
-               $selectedArray = ((!$bEmptySelected || count($mergeArray)) ? $selectedArray : $defaultSelectedArray);
-
-               if (count($mergeArray)) {
-                       $nameArray = array_merge($nameArray, $mergeArray);
-                       uasort($nameArray, 'strcoll');
-               }
-
-               if(count($nameArray) > 0)       {
-                       $selector .= $this->optionsConstructor($nameArray, $selectedArray, $outSelectedArray);
-                       $selector .= '</select>'.chr(10);
-               } else {
-                       $selector = '';
-               }
-               return $selector;
-       }
-
-
-       /**
-        * Getting all countries into an array
-        *      where the key is the ISO alpha-3 code of the country
-        *      and where the value is the name of the country in the current language
-        *
-        * @param       string          It defines a selection: 'ALL', 'UN', 'EU'
-        * @param       string          language to be used
-        * @param       boolean         If set, we are looking for the "local" title field
-        * @param       string          additional WHERE clause
-        * @return      array           An array of names of countries
-        */
-       function initCountries ($param='UN', $lang='', $local=FALSE, $addWhere='') {
-               global $TYPO3_DB;
-
-               $table = $this->tables['COUNTRIES'];
-               if (!$lang)     {
-                       $lang = $this->getCurrentLanguage();
-               }
-               $nameArray = array();
-               $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang, $local);
-               $prefixedTitleFields = array();
-               $prefixedTitleFields[] = $table.'.cn_iso_3';
-               foreach ($titleFields as $titleField) {
-                       $prefixedTitleFields[] = $table.'.'.$titleField;
-               }
-
-               array_unique($prefixedTitleFields);
-               $labelFields = implode(',', $prefixedTitleFields);
-               if ($param == 'UN') {
-                       $where = 'cn_uno_member=1';
-               } elseif ($param == 'EU') {
-                       $where = 'cn_eu_member=1';
-               } elseif ($param == 'ALL')      {
-                       $where = '1=1';
-               } else {
-                       $where = '1=1';
-               }
-
-               $where .= ($addWhere ? ' AND '.$addWhere : '');
-               $res = $TYPO3_DB->exec_SELECTquery(
-                       $labelFields,
-                       $table,
-                       $where.$GLOBALS['TSFE']->sys_page->enableFields($table)
-               );
-
-               while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
-
-                       foreach ($titleFields as $titleField) {
-                               if ($row[$titleField]) {
-                                       $nameArray[$row['cn_iso_3']] = $GLOBALS['TSFE']->csConv($row[$titleField], 'utf-8');
-                                       break;
-                               }
-                       }
-               }
-               $TYPO3_DB->sql_free_result($res);
-
-               if ($this->conf['countriesAllowed'] != '')      {
-                       $countriesAllowedArray = t3lib_div::trimExplode(',', $this->conf['countriesAllowed']);
-                       $newNameArray = array();
-                       foreach ($countriesAllowedArray as $iso3)       {
-                               if (isset($nameArray[$iso3]))   {
-                                       $newNameArray[$iso3] = $nameArray[$iso3];
-                               }
-                       }
-                       $nameArray = $newNameArray;
-               } else {
-                       uasort($nameArray, 'strcoll');
-               }
-               return $nameArray;
-       }
-
-
-       /**
-        * Getting all country subdivisions of a given country into an array
-        *      where the key is the code of the subdivision
-        *      and where the value is the name of the country subdivision in the current language
-        * You can leave the ISO code empty and use the additional WHERE clause instead of it.
-        *
-        * @param       string          The ISO alpha-3 code of a country
-        * @param       string          additional WHERE clause
-        * @return      array           An array of names of country subdivisions
-        */
-       function initCountrySubdivisions ($param, $addWhere='') {
-               global $TYPO3_DB;
-
-               $table = $this->tables['SUBDIVISIONS'];
-               if (strlen($param) == 3)        {
-                       $country = $param;
-                       $where = 'zn_country_iso_3='.$TYPO3_DB->fullQuoteStr($country,$table);
-               } else {
-                       $where = '1=1';
-               }
-               $where .= ($addWhere ? ' AND '.$addWhere : '');
-               $lang = $this->getCurrentLanguage();
-               $nameArray = array();
-               $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
-               $prefixedTitleFields = array();
-               foreach ($titleFields as $titleField) {
-                       $prefixedTitleFields[] = $table.'.'.$titleField;
-               }
-               $labelFields = implode(',', $prefixedTitleFields);
-               $res = $TYPO3_DB->exec_SELECTquery(
-                       $table.'.zn_code,'.$labelFields,
-                       $table,
-                       $where.
-                               $GLOBALS['TSFE']->sys_page->enableFields($table)
-                       );
-               while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
-                       foreach ($titleFields as $titleField) {
-                               if ($row[$titleField]) {
-                                       $nameArray[$row['zn_code']] = $GLOBALS['TSFE']->csConv($row[$titleField], 'utf-8');
-                                       break;
-                               }
-                       }
-               }
-               $TYPO3_DB->sql_free_result($res);
-               uasort($nameArray, 'strcoll');
-               return $nameArray;
-       }
-
-
-       /**
-        * Getting all currencies into an array
-        *      where the key is the ISO alpha-3 code of the currency
-        *      and where the value are the name of the currency in the current language
-        *
-        * @param       string          additional WHERE clause
-        * @return      array           An array of names of currencies
-        */
-       function initCurrencies ($addWhere='') {
-               global $TYPO3_DB;
-
-               $where = '1=1'.($addWhere ? ' AND '.$addWhere : '');
-               $table = $this->tables['CURRENCIES'];
-               $lang = $this->getCurrentLanguage();
-               $nameArray = array();
-               $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
-               $prefixedTitleFields = array();
-               foreach ($titleFields as $titleField) {
-                       $prefixedTitleFields[] = $table.'.'.$titleField;
-               }
-               $labelFields = implode(',', $prefixedTitleFields);
-               $res = $TYPO3_DB->exec_SELECTquery(
-                       $table.'.cu_iso_3,'.$labelFields,
-                       $table,
-                       $where.$GLOBALS['TSFE']->sys_page->enableFields($table)
-                       );
-               while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
-                       foreach ($titleFields as $titleField) {
-                               if ($row[$titleField]) {
-                                       $nameArray[$row['cu_iso_3']] = $GLOBALS['TSFE']->csConv($row[$titleField], 'utf-8');
-                                       break;
-                               }
-                       }
-               }
-               $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
-        *
-        * @param       string          additional WHERE clause
-        * @return      array           An array of names of languages
-        */
-       function initLanguages ($addWhere='') {
-               global $TYPO3_DB;
-
-               $where = '1=1'.($addWhere ? ' AND '.$addWhere : '');
-               $table = $this->tables['LANGUAGES'];
-               $lang = $this->getCurrentLanguage();
-               $nameArray = array();
-               $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
-               $prefixedTitleFields = array();
-               foreach ($titleFields as $titleField) {
-                       $prefixedTitleFields[] = $table.'.'.$titleField;
-               }
-               $labelFields = implode(',', $prefixedTitleFields);
-               $res = $TYPO3_DB->exec_SELECTquery(
-                       $table.'.lg_iso_2,'.$table.'.lg_country_iso_2,'.$labelFields,
-                       $table,
-                       $where.' AND lg_sacred = 0 AND lg_constructed = 0 '.
-                               $GLOBALS['TSFE']->sys_page->enableFields($table)
-                       );
-               while ($row = $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] = $GLOBALS['TSFE']->csConv($row[$titleField], 'utf-8');
-                                       break;
-                               }
-                       }
-               }
-               $TYPO3_DB->sql_free_result($res);
-               uasort($nameArray, 'strcoll');
-               return $nameArray;
-       }
-
-
-       /**
-        * Builds a list of <option> tags
-        *
-        * @param       array           An array where the values will be the texts of an <option> tags and keys will be the values of the tags
-        * @param       string          A pre-selected value: if the value appears as a key, the <option> tag will bear a 'selected' attribute
-        * @param       array           out: resulting selected array with the ISO alpha-3 code of the countries
-        * @return      string          A string of HTML <option> tags
-        */
-       function optionsConstructor ($nameArray, $selectedArray=array(), &$outSelectedArray=array()) {
-
-               $options = '';
-
-               foreach($nameArray as $value => $name)  {
-
-                       $options  .= '<option value="'.$value.'"';
-                       if (in_array($value, $selectedArray))   {
-                               $options  .= ' selected="selected"';
-                               $outSelectedArray[] = $value;
-                       }
-                       $options  .= '>'.$name.'</option>'.chr(10);
-               }
-               if (!isset($outSelectedArray) || count($outSelectedArray) == 0) {
-                       reset ($nameArray);
-                       $outSelectedArray = array(key($nameArray));
-               }
-               return $options;
-       }
-
-
-       /**
-        * Loading currency display parameters from Static Info Tables
-        *
-        * @param       string          An ISO alpha-3 currency code
-        * @return      array           An array of information regarding the currrency
-        */
-       function loadCurrencyInfo ($currencyCode)       {
-               global $TYPO3_DB;
-
-                       // Fetching the currency record
-               $this->currencyInfo['cu_iso_3'] = trim($currencyCode);
-               $this->currencyInfo['cu_iso_3'] = ($this->currencyInfo['cu_iso_3']) ? $this->currencyInfo['cu_iso_3'] : $this->currency;
-               $res = $TYPO3_DB->exec_SELECTquery(
-                       '*',
-                       'static_currencies',
-                       'cu_iso_3='.$TYPO3_DB->fullQuoteStr($this->currencyInfo['cu_iso_3'],'static_currencies')
-               );
-                       // If not found we fetch the default currency!
-               if (!$TYPO3_DB->sql_num_rows($res)) {
-                       $TYPO3_DB->sql_free_result($res);
-                       $this->currencyInfo['cu_iso_3'] = $this->currency;
-                       $res = $TYPO3_DB->exec_SELECTquery(
-                               '*',
-                               'static_currencies',
-                               'cu_iso_3='.$TYPO3_DB->fullQuoteStr($this->currencyInfo['cu_iso_3'],'static_currencies')
-                       );
-               }
-               $row = $TYPO3_DB->sql_fetch_assoc($res);
-               $TYPO3_DB->sql_free_result($res);
-
-               $this->currencyInfo['cu_name'] = $this->getStaticInfoName('CURRENCIES', $this->currencyInfo['cu_iso_3']);
-               $this->currencyInfo['cu_symbol_left'] = $row['cu_symbol_left'];
-               $this->currencyInfo['cu_symbol_right'] = $row['cu_symbol_right'];
-               $this->currencyInfo['cu_decimal_digits'] = $row['cu_decimal_digits'];
-               $this->currencyInfo['cu_decimal_point'] = $row['cu_decimal_point'];
-               $this->currencyInfo['cu_thousands_point'] = $row['cu_thousands_point'];
-
-               return $this->currencyInfo;
-       }
-
-
-       /**
-        * Formatting an amount in the currency loaded by loadCurrencyInfo($currencyCode)
-        *
-        *       '' - the currency code is not displayed
-        *       'RIGHT' - the code is displayed at the right of the amount
-        *       'LEFT' - the code is displayed at the left of the amount
-        *
-        * @param       float           An amount to be displayed in the loaded currency
-        * @param       string          A flag specifying if the the currency code should be displayed:
-        * @return      string          The formated amounted
-        */
-       function formatAmount ($amount, $displayCurrencyCode='')        {
-
-               $formatedAmount = '';
-
-               if( $displayCurrencyCode == 'LEFT' )    {
-                       $formatedAmount .= $this->currencyInfo['cu_iso_3'].chr(32);
-               }
-               $formatedAmount .= $this->currencyInfo['cu_symbol_left'];
-               $formatedAmount .= number_format($amount, intval($this->currencyInfo['cu_decimal_digits']), $this->currencyInfo['cu_decimal_point'], (($this->currencyInfo['cu_thousands_point'])?$this->currencyInfo['cu_thousands_point']:chr(32)));
-               $formatedAmount .= (($this->currencyInfo['cu_symbol_right'])?chr(32):'').$this->currencyInfo['cu_symbol_right'];
-               if( $displayCurrencyCode == 'RIGHT' )   {
-                       $formatedAmount .= chr(32).$this->currencyInfo['cu_iso_3'];
-               }
-
-               return $formatedAmount;
-       }
-
-
-       /**
-        * Formatting an address in the format specified
-        *
-        * @param       string          A delimiter for the fields of the returned address
-        * @param       string          A street address
-        * @param       string          A city
-        * @param       string          A country subdivision code (zn_code)
-        * @param       string          A ISO alpha-3 country code (cn_iso_3)
-        * @param       string          A zip code
-        * @return      string          The formated address using the country address format (cn_address_format)
-        */
-       function formatAddress ($delim, $streetAddress, $city, $zip, $subdivisionCode='', $countryCode='')      {
-               global $TYPO3_DB;
-
-               $formatedAddress = '';
-               $countryCode = ($countryCode ? trim($countryCode) : $this->defaultCountry);
-               $subdivisionCode = ($subdivisionCode ? trim($subdivisionCode) : ($countryCode == $this->defaultCountry ? $this->defaultCountryZone : ''));
-
-                       // Get country name
-               $countryName = $this->getStaticInfoName('COUNTRIES', $countryCode);
-               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'];
-
-                       // Get country subdivision name
-               $countrySubdivisionName = $this->getStaticInfoName('SUBDIVISIONS', $subdivisionCode, $countryCode);
-
-                       // Format the address
-               $formatedAddress = $this->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', $countrySubdivisionName, $formatedAddress);
-               $formatedAddress = str_replace('%countryName', strtoupper($countryName), $formatedAddress);
-               $formatedAddress = implode($delim, t3lib_div::trimExplode(';', $formatedAddress, 1));
-
-               return $formatedAddress;
-       }
-
-
-       /**
-        * Returns the current language as iso-2-alpha code
-        *
-        * @return      string          'DE', 'EN', 'DK', ...
-        */
-       function getCurrentLanguage () {
-               global $TYPO3_DB;
-
-               $rc = tx_staticinfotables_div::getCurrentLanguage();
-               return $rc;
-       }
-}
-
-
-if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/static_info_tables/pi1/class.tx_staticinfotables_pi1.php'])        {
-       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/static_info_tables/pi1/class.tx_staticinfotables_pi1.php']);
-}
-
-?>
\ No newline at end of file
+require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('static_info_tables') . 'Classes/PiBaseApi.php';
+?>>
\ No newline at end of file
diff --git a/tca.php b/tca.php
index 683a7b8..3ed6b7e 100644 (file)
--- a/tca.php
+++ b/tca.php
@@ -30,9 +30,9 @@ $GLOBALS['TCA']['static_territories'] = array(
                                ),
                                'foreign_table' => 'static_territories',
                                'foreign_table_where' => 'ORDER BY static_territories.tr_name_en',
-                               'itemsProcFunc' => 'EXT:static_info_tables/Classes/Hook/Backend/Form/class.tx_staticinfotables_renderElement.php:&tx_staticinfotables_renderElement->sortTerritoriesSelector',
+                               'itemsProcFunc' => 'SJBR\StaticInfoTables\Hook\Backend\Form\ElementRenderingHelper->translateTerritoriesSelector',
                                'size' => 1,
-                               'minitems' => 1,
+                               'minitems' => 0,
                                'maxitems' => 1,
                        )
                ),
@@ -52,11 +52,28 @@ $GLOBALS['TCA']['static_territories'] = array(
                                'default' => '',
                                '_is_string' => '1'
                        )
-               )
+               ),
+'fk_billing_country' => array (
+  'exclude' => 1,
+  'label' => 'Voici',
+  'config' => array (
+    'type' => 'group',
+    'internal_type' => 'db',
+    'allowed' => 'static_countries',
+    'size' => 1,
+    'minitems' => 1,
+    'maxitems' => 1,
+    'wizards' => array(
+      'suggest' => array(
+        'type' => 'suggest',
+      ),
+    ),
+  )
+),
        ),
        'types' => array(
                '1' => array(
-                       'showitem' => 'tr_iso_nr,tr_name_en,--palette--;;1;;'
+                       'showitem' => 'tr_iso_nr,tr_name_en,fk_billing_country,--palette--;;1;;'
                )
        ),
        'palettes' => array(
@@ -115,9 +132,9 @@ $GLOBALS['TCA']['static_countries'] = array(
                                ),
                                'foreign_table' => 'static_territories',
                                'foreign_table_where' => 'ORDER BY static_territories.tr_name_en',
-                               'itemsProcFunc' => 'EXT:static_info_tables/Classes/Hook/Backend/Form/class.tx_staticinfotables_renderElement.php:&tx_staticinfotables_renderElement->sortTerritoriesSelector',
+                               'itemsProcFunc' => 'SJBR\StaticInfoTables\Hook\Backend\Form\ElementRenderingHelper->translateTerritoriesSelector',
                                'size' => 1,
-                               'minitems' => 1,
+                               'minitems' => 0,
                                'maxitems' => 1,
                        )
                ),
@@ -183,9 +200,9 @@ $GLOBALS['TCA']['static_countries'] = array(
                                ),
                                'foreign_table' => 'static_currencies',
                                'foreign_table_where' => 'ORDER BY static_currencies.cu_name_en',
-                               'itemsProcFunc' => 'EXT:static_info_tables/Classes/Hook/Backend/Form/class.tx_staticinfotables_renderElement.php:&tx_staticinfotables_renderElement->sortCurrenciesSelector',
+                               'itemsProcFunc' => 'SJBR\StaticInfoTables\Hook\Backend\Form\ElementRenderingHelper->translateCurrenciesSelector',
                                'size' => 1,
-                               'minitems' => 1,
+                               'minitems' => 0,
                                'maxitems' => 1,
                        )
                ),