[+TASK] Performance optimization and refactorings after an extensive profiling session.
authorjocrau <jocrau@735d13b6-9817-0410-8766-e36946ffe9aa>
Mon, 25 Jan 2010 11:34:33 +0000 (11:34 +0000)
committerBastian Bringenberg <spam@bastian-bringenberg.de>
Thu, 4 Dec 2014 23:56:07 +0000 (00:56 +0100)
[-CONFIGURATION] Removed option 'secureFields'.
[+CONFIGURATION] Added option 'fieldsToParse' (comma separated list of fields to be parsed by contagged again in list view).
[-CONFIGURATION] The long description is not pardes via lib.parseFunc_RTE by default anymore (due to performance reasons). You have to uncomment the appropriate line in the TS setup. It's recommended to do so only on pages where the long description is displayed.

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/contagged/trunk@29292 735d13b6-9817-0410-8766-e36946ffe9aa

class.tx_contagged.php
model/class.tx_contagged_model_mapper.php
model/class.tx_contagged_model_terms.php
pi1/class.tx_contagged_pi1.php
static/constants.txt
static/setup.txt
tca.php

index 019bf88..e47b5ea 100644 (file)
@@ -80,9 +80,9 @@ class tx_contagged extends tslib_pibase {
                $this->typesArray = $this->conf['types.'];
 
                // get the model (an associated array of terms)
-               $modelClassName = t3lib_div::makeInstanceClassName('tx_contagged_model_terms');
-               $model = new $modelClassName($this);
+               $model = t3lib_div::makeInstance('tx_contagged_model_terms', $this);
                $this->termsArray = $model->findAllTerms();
+
                $sortedTerms = array();
                foreach ($this->termsArray as $termKey => $termArray) {
                        $sortedTerms[] = array('term' => $termArray['term_main'], 'key' => $termKey);
@@ -91,8 +91,6 @@ class tx_contagged extends tslib_pibase {
                                        $sortedTerms[] = array('term' => $term, 'key' => $termKey);
                                }
                        }
-                       // sort the array descending by length of the value, so the longest term will match
-                       usort($sortedTerms,array($this,'sortArrayByLengthDescending'));
                }
 
                // get a comma separated list of all tags which should be omitted
@@ -121,36 +119,19 @@ class tx_contagged extends tslib_pibase {
                return $parsedContent;
        }
        
-       function sortArrayByLengthDescending($a,$b) {
-               if (strlen($a['term'])==strlen($b['term'])) {
-                       return 0;
-               }
-               return strlen($a['term'])<strlen($b['term']) ? 1 : -1;
-       }
-
-       function getRegEx($term,$termKey) {
+       function getPositions($content,&$positionsArray,$term,$termKey) {
                $termArray = $this->termsArray[$termKey];
                $typeConfigArray = $this->typesArray[$termArray['term_type'] . '.'];
-               // stdWrap for the term to search for; usefull to realize custom tags like <person>|</person>
-               $regExTerm = $this->cObj->stdWrap($term,$typeConfigArray['termStdWrap.']);
-               $regEx = '';
-               if ( $this->checkLocalGlobal($typeConfigArray,'termIsRegEx')>0 ) {
+               // $regEx = $regEx = '/(?<=\P{L}|^)' . preg_quote($term,'/') . '(?=\P{L}|$)/' . $this->conf['modifier'];//$this->getRegEx($term,$termKey);
+               if ($typeConfigArray['termIsRegEx'] > 0) {
                        $regEx = $termArray['term_main'].$this->conf['modifier'];
                } else {
-                       if (strstr($this->conf['modifier'], 'u') !== FALSE) {
-                               $regEx = '/(?<=\P{L}|^)' . preg_quote($regExTerm,'/') . '(?=\P{L}|$)/' . $this->conf['modifier'];
-                       } else {
-                               $regEx = '/(?<=\W|^)' . preg_quote($regExTerm,'/') . '(?=\W|$)/' . $this->conf['modifier'];
-                       }
+                       // if (strstr($this->conf['modifier'], 'u') !== FALSE) {
+                               $regEx = '/(?<=\P{L}|^)' . preg_quote($term,'/') . '(?=\P{L}|$)/' . $this->conf['modifier'];
+                       // } else {
+                       //      $regEx = '/(?<=\W|^)' . preg_quote($term,'/') . '(?=\W|$)/' . $this->conf['modifier'];
+                       // }
                }
-               
-               return $regEx;
-       }
-
-       function getPositions($content,&$positionsArray,$term,$termKey) {
-               $termArray = $this->termsArray[$termKey];
-               $typeConfigArray = $this->typesArray[$termArray['term_type'] . '.'];
-               $regEx = $this->getRegEx($term,$termKey);
                preg_match_all($regEx,$content,$matchesArray,PREG_OFFSET_CAPTURE);
                $matchesArray = $matchesArray[0]; // only take the full pattern matches of the regEx
 
@@ -404,11 +385,15 @@ class tx_contagged extends tslib_pibase {
                        if ($termArray['link']) {
                                $parameter = $termArray['link'];
                        } else {
-                               $parameter = $termArray['listPages'][0];
+                               if ($typeConfigArray['listPages']) {
+                                       $parameter = array_shift(t3lib_div::trimExplode(',',$typeConfigArray['listPages'],1));
+                               } else {
+                                       $parameter = array_shift(t3lib_div::trimExplode(',',$this->conf['listPages'],1));
+                               }
                        }
                        $additionalParams = array(
-                               'termSource' => $termArray['sourceName'],
-                               'termUid' => $termArray['uid'],
+                               'source' => $termArray['sourceName'],
+                               'uid' => $termArray['uid'],
                                );
                        if ($this->checkLocalGlobal($typeConfigArray,'addBackLink')) {
                                $additionalParams['backPid'] = $GLOBALS['TSFE']->id;
index 2ed714e..050af97 100644 (file)
@@ -29,7 +29,7 @@
  * @package    TYPO3
  * @subpackage tx_contagged_model_mapper
  */
-class tx_contagged_model_mapper {
+class tx_contagged_model_mapper implements t3lib_Singleton {
        var $conf; // the TypoScript configuration array
        var $controller;
 
@@ -73,7 +73,7 @@ class tx_contagged_model_mapper {
                        $term = $row[$termReplace] ? $row[$termReplace] : $row[$termMain];
                        $mappedDataArray = array();
                        $mappedDataArray['term'] = $term;
-                       $mappedDataArray['sourceName'] = $sourceName;
+                       $mappedDataArray['sourceName'] = $dataSource;
                        foreach ( $fieldsToMapArray as $field) {
                                $value = $dataSourceConfigArray['mapping.'][$field.'.'];
                                if ( $value['value'] ) {
@@ -93,32 +93,6 @@ class tx_contagged_model_mapper {
 
                        // post processing
                        $mappedDataArray['term_alt'] = t3lib_div::trimExplode(chr(10),$row['term_alt'],1);
-                       $mappedDataArray['desc_long'] = $this->cObj->parseFunc($mappedDataArray['desc_long'], array(), '< lib.parseFunc_RTE');
-                       $mappedDataArray['storagePids'] = $this->getStoragePidsArray($typeConfigArray);
-                                               
-                       if ($typeConfigArray['listPages']) {
-                               $mappedDataArray['listPages'] = t3lib_div::trimExplode(',',$typeConfigArray['listPages'],1);
-                       } else {
-                               $mappedDataArray['listPages'] = t3lib_div::trimExplode(',',$this->conf['listPages'],1);
-                       }
-
-                       $secureFields = $typeConfigArray['termIsRegEx']>0 ? $this->conf['types.'][$row['term_type'].'.']['secureFields'] : $this->conf['secureFields'];
-                       foreach ($mappedDataArray as $field => $fieldContent) {
-                               if ($fieldContent) {
-                                       if ( is_array($fieldContent) ) {
-                                               foreach ($fieldContent as $termAltKey => $innerContent) {
-                                                       if ( t3lib_div::inList($secureFields,$field) ) {
-                                                               $mappedDataArray[$field][$termAltKey] = htmlspecialchars($innerContent);
-                                                       }
-                                               }
-                                       } else {
-                                               if ( t3lib_div::inList($secureFields,$field) ) {
-                                                       $mappedDataArray[$field] = htmlspecialchars($fieldContent);
-                                               }
-                                       }
-                               }
-                       }
-                       
                        // TODO: hook "mappingPostProcessing"
                        
                        if (!empty($dataSourceConfigArray['mapping.']['uid.']['field'])) {
@@ -131,27 +105,6 @@ class tx_contagged_model_mapper {
                return $dataArray;
        }
        
-       /**
-        * get the storage pids; cascade: type > dataSource > globalConfig
-        *
-        * @param string        $typeConfigArray 
-        * @return array        An array containing the storage PIDs of the type given by
-        * @author Jochen Rau
-        */
-       function getStoragePidsArray($typeConfigArray) {
-               $storagePidsArray = array();            
-               $dataSource = $typeConfigArray['dataSource'] ? $typeConfigArray['dataSource'] : 'default';
-               if ( $typeConfigArray['storagePids'] ) {
-                       $storagePidsArray = t3lib_div::trimExplode(',',$typeConfigArray['storagePids']);
-               } elseif ( $this->conf['dataSources.'][$dataSource.'.']['storagePids'] ) {
-                       $storagePidsArray = t3lib_div::trimExplode(',',$this->conf['dataSources.'][$dataSource.'.']['storagePids']);
-               } elseif ( $this->conf['storagePids']) {
-                       $storagePidsArray = t3lib_div::trimExplode(',',$this->conf['storagePids']);
-               }
-               
-               return $storagePidsArray;
-       }
-
 }
 
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/contagged/model/class.tx_contagged_model_mapper.php']) {
index 9fbfd9d..4614a32 100644 (file)
@@ -30,12 +30,15 @@ require_once (t3lib_extMgm::extPath('contagged') . 'model/class.tx_contagged_mod
  * @package    TYPO3
  * @subpackage tx_contagged_model_terms
  */
-class tx_contagged_model_terms {
+class tx_contagged_model_terms implements t3lib_Singleton {
        var $conf; // the TypoScript configuration array
        var $controller;
        var $tablesArray = array(); // array of all tables in the database
+       var $dataSourceArray = array();
+       var $cachedSources = array();
        var $terms = array();
-       var $configuredSources;
+       var $configuredSources = array();
+       var $listPagesCache = array();
 
        function __construct($controller) {
                $this->controller = $controller;
@@ -44,90 +47,73 @@ class tx_contagged_model_terms {
                        $this->cObj = t3lib_div::makeInstance('tslib_cObj');
                }
 
-               $mapperClassName = t3lib_div::makeInstanceClassName('tx_contagged_model_mapper');
-               $this->mapper = new $mapperClassName($this->controller);
+               $this->mapper  = t3lib_div::makeInstance('tx_contagged_model_mapper', $this->controller);
 
                // build an array of tables in the database
                $this->tablesArray = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db);
                
                if (is_array($this->conf['dataSources.'])) {
                        foreach ($this->conf['dataSources.'] as $dataSource => $sourceConfiguration) {
-                               $this->configuredSources[] = $sourceConfiguration['sourceName'];
+                               $this->configuredSources[$sourceConfiguration['sourceName']] = substr($dataSource, 0, -1);
                        }
                } else {
                        throw new RuntimeException('No configuration. Please include the static template.');
                }
                
                $typesArray = $this->conf['types.'];
-               $dataSourceArray = array();
                foreach ($typesArray as $type=>$typeConfigArray) {
-                       $storagePidsArray = $this->mapper->getStoragePidsArray($typeConfigArray);
+                       $storagePidsArray = $this->getStoragePidsArray($typeConfigArray);
                        $dataSource = $typeConfigArray['dataSource'] ? $typeConfigArray['dataSource'] : 'default';
                        foreach ($storagePidsArray as $pid) {
                                // if there is an entry for the data source: check for duplicates before adding the pid
                                // otherwise: create a new entry and add the pid
-                               if ($dataSourceArray[$dataSource]) {
-                                       if ( !in_array($pid,$dataSourceArray[$dataSource]) ) {
-                                               $dataSourceArray[$dataSource][] = $pid;
-                                       }
+                               if (is_array($this->dataSourceArray[$dataSource]) && !in_array(intval($pid),$this->dataSourceArray[$dataSource])) {
+                                       $this->dataSourceArray[$dataSource][] = intval($pid);
                                } else {
-                                       $dataSourceArray[$dataSource][] = $pid;
+                                       $this->dataSourceArray[$dataSource][] = intval($pid);
                                }
                        }
                }
                
-               // get an array of all data rows in the configured tables
-               foreach ($dataSourceArray as $dataSource => $storagePidsArray ) {
-                       $this->terms = array_merge($this->terms, $this->fetchAllTermsFromSource($dataSource,$storagePidsArray));
-               }
-
-               uasort($this->terms, array($this, 'sortByTermAscending'));
        }
 
        function findAllTerms() {
+               foreach ($this->dataSourceArray as $dataSource => $storagePidsArray ) {
+                       $this->terms = array_merge($this->terms, $this->fetchTermsFromSource($dataSource,$storagePidsArray));
+               }
                return $this->terms;
        }
        
        function findAllTermsToListOnPage($pid = NULL) {
-               $terms = array();
                if ($pid === NULL) $pid = $GLOBALS['TSFE']->id;
+               foreach ($this->dataSourceArray as $dataSource => $storagePidsArray ) {
+                       $this->terms = array_merge($this->terms, $this->fetchTermsFromSource($dataSource, $storagePidsArray, ' AND exclude=0'));
+               }
+               $terms = array();
                foreach ($this->terms as $key => $term) {
-                       if ( ($term['exclude'] == 0) && ($this->conf['types.'][$term['term_type'].'.']['dontListTerms'] == 0) && (in_array($pid, $term['listPages']) || is_array($GLOBALS['T3_VAR']['ext']['contagged']['index'][$pid][$key])) ) {
+                       $typeConfigurationArray = $this->conf['types.'][$term['term_type'] . '.'];
+                       $listPidsArray = $this->getListPidsArray($term['term_type']);
+                       if (($typeConfigurationArray['dontListTerms'] == 0) && (in_array($pid, $listPidsArray) || is_array($GLOBALS['T3_VAR']['ext']['contagged']['index'][$pid][$key])) ) {
                                $terms[$key] = $term;
                        }
                }
+               uasort($terms, array($this, 'sortByTermAscending'));
                return $terms;
        }
-               
-       function findTermByUid($sourceName, $uid) {
-               $fetchedTerms = array();
-               foreach ($this->terms as $key => $term) {
-                       if ($term['sourceName'] == $sourceName && $term['uid'] == $uid) {
-                               $fetchedTerms = array($key => $term);
-                       }
-               }
-               return $fetchedTerms;
-       }
-       
-       function sourceIsConfigured($sourceName) {
-               return in_array($sourceName, $this->configuredSources);
-       }
 
        function sortByTermAscending($termArrayA, $termArrayB) {
-               $sortFieldA = $this->getSortField($termArrayA);
-               $sortFieldB = $this->getSortField($termArrayB);
-               $termsArray = array($termArrayA[$sortFieldA], $termArrayB[$sortFieldB]);
-               // $GLOBALS['TSFE']->csConvObj->convArray($termsArray,'utf-8','iso-8859-1');
-               $termsArrayBefore = $termsArray;
-               natcasesort($termsArray);
-               $termsArrayAfterwards = $termsArray;
-               if (array_pop($termsArrayBefore) == array_pop($termsArrayAfterwards)) {
-                       $result = -1;
+               return strnatcasecmp($termArrayA['term'], $termArrayB['term']);
+       }
+       
+       function findTermByUid($dataSource, $uid) {
+               $additionalWhereClause = ' AND uid=' . intval($uid);
+               $terms = $this->fetchTermsFromSource($dataSource, $storagePidsArray, $additionalWhereClause);
+               $this->fetchRelatedTerms($terms);
+               if (is_array($terms) && count($terms) > 0) {
+                       return array_shift($terms);
                } else {
-                       $result = 1;
+                       return NULL;
                }
-
-               return $result;
        }
 
        /**
@@ -137,39 +123,34 @@ class tx_contagged_model_terms {
         * @param       [type]          $storagePids: ...
         * @return      An              array with the terms an their configuration
         */
-       function fetchAllTermsFromSource($dataSource, $storagePidsArray=NULL) {
+       function fetchTermsFromSource($dataSource, $storagePidsArray= array(), $additionalWhereClause = '') {
                $dataArray = array();
-               $storagePidsList = implode(',',$storagePidsArray);
                $dataSourceConfigArray = $this->conf['dataSources.'][$dataSource . '.'];
                $sourceName = $dataSourceConfigArray['sourceName'];
-
                // check if the table exists in the database
-               if (is_array($this->tablesArray)) {
-                       if (array_key_exists($sourceName, $this->tablesArray) ) {
-                               // Build WHERE-clause
-                               $whereClause = '1=1';
-                               $whereClause .= $storagePidsList ? ' AND pid IN (' . $storagePidsList . ')' : '';
-                               $whereClause .= $dataSourceConfigArray['hasSysLanguageUid'] ? ' AND (sys_language_uid=' . intval($GLOBALS['TSFE']->sys_language_uid) . ' OR sys_language_uid=-1)' : '';
-                               $whereClause .= $this->cObj->enableFields($sourceName);
-
-                               // execute SQL-query
-                               $result = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                       '*', // SELECT ...
-                                       $sourceName, // FROM ...
-                                       $whereClause // WHERE ..
-                                       );
-                               // map the fields
-                               $mappedResult = $this->mapper->getDataArray($result,$dataSource);
-                       }
-                       if (is_array($mappedResult)) {
-                               $this->fetchRelatedTerms($mappedResult);
-                               // $this->fetchIndex($dataArray);
-                               foreach ($mappedResult as $result) {
-                                       $dataArray[$result['sourceName'] . '_' . $result['uid']] = $result;
-                               }
+               if (array_key_exists($sourceName, $this->tablesArray) ) {                               
+                       // Build WHERE-clause
+                       $whereClause = '1=1';
+                       $whereClause .= count($storagePidsArray) > 0 ? ' AND pid IN (' . implode(',',$storagePidsArray) . ')' : '';
+                       $whereClause .= $dataSourceConfigArray['hasSysLanguageUid'] ? ' AND (sys_language_uid=' . intval($GLOBALS['TSFE']->sys_language_uid) . ' OR sys_language_uid=-1)' : '';
+                       $whereClause .= $this->cObj->enableFields($sourceName);
+                       $whereClause .= $additionalWhereClause;
+
+                       // execute SQL-query
+                       $result = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                               '*', // SELECT ...
+                               $sourceName, // FROM ...
+                               $whereClause // WHERE ..
+                               );
+                       // map the fields
+                       $mappedResult = $this->mapper->getDataArray($result,$dataSource);
+                       $this->cachedSources[] = $sourceName;
+               }
+               if (is_array($mappedResult)) {
+                       foreach ($mappedResult as $result) {
+                               $dataArray[$result['sourceName'] . '_' . $result['uid']] = $result;
                        }
                }
-               
                // TODO piVars as a data source
                return $dataArray;
        }
@@ -187,8 +168,9 @@ class tx_contagged_model_terms {
                        if (!empty($result)) {
                                $termArray['related'] = array();
                                foreach ($result as $row) {
-                                       if ($this->sourceIsConfigured($row['tablenames'])) {
-                                               $termArray['related'][] = array('sourceName' => $row['tablenames'], 'uid' => $row['uid_foreign']);
+                                       $dataSource = $this->configuredSources[$row['tablenames']];
+                                       if ($dataSource !== NULL) {
+                                               $termArray['related'][] = array('source' => $dataSource, 'uid' => $row['uid_foreign']);
                                        }
                                }
                        } else {
@@ -199,36 +181,43 @@ class tx_contagged_model_terms {
                $dataArray = $newDataArray;
        }
 
-       function fetchIndex(&$dataArray) {
-               $newDataArray = array();                
-               foreach ($dataArray as $key => $termArray) {
-                       if (!empty($result)) {
-                               $termArray['related'] = array();
-                               foreach ($result as $row) {
-                                       if ($this->sourceIsConfigured($row['tablenames'])) {
-                                               $termArray['related'][] = array('sourceName' => $row['tablenames'], 'uid' => $row['uid_foreign']);
-                                       }
-                               }
-                       } else {
-                               $termArray['related'] = NULL;
-                       }
-                       $newDataArray[] = $termArray;
+       /**
+        * get the storage pids; cascade: type > dataSource > globalConfig
+        *
+        * @param string        $typeConfigArray 
+        * @return array        An array containing the storage PIDs of the type given by
+        * @author Jochen Rau
+        */
+       function getStoragePidsArray($typeConfigArray) {
+               $storagePidsArray = array();
+               $dataSource = $typeConfigArray['dataSource'] ? $typeConfigArray['dataSource'] : 'default';
+               if (!empty($typeConfigArray['storagePids'])) {
+                       $storagePidsArray = t3lib_div::intExplode(',',$typeConfigArray['storagePids']);
+               } elseif (!empty($this->conf['dataSources.'][$dataSource.'.']['storagePids']) ) {
+                       $storagePidsArray = t3lib_div::intExplode(',',$this->conf['dataSources.'][$dataSource.'.']['storagePids']);
+               } elseif (!empty($this->conf['storagePids'])) {
+                       $storagePidsArray = t3lib_div::intExplode(',',$this->conf['storagePids']);
                }
-               $dataArray = $newDataArray;
+               return $storagePidsArray;
        }
-       
-       
-       
-       function getSortField($termArray) {
-               if ($this->conf['types.'][$termArray['term_type'].'.']['sortField']) {
-                       $sortField = $this->conf['types.'][$termArray['term_type'].'.']['sortField'];
-               } elseif ($this->conf['sortField']) {
-                       $sortField = $this->conf['sortField'];
-               } else {
-                       $sortField = 'term';
-               }
 
-               return $sortField;
+       /**
+        * get the lsit pids; cascade: type > globalConfig
+        *
+        * @param string        $typeConfigArray 
+        * @return array        An array containing the list PIDs of the type given by
+        * @author Jochen Rau
+        */
+       function getListPidsArray($termType) {
+               if (!isset($this->listPagesCache[$termType])) {         
+                       $listPidsArray = array();
+                       if (!empty($this->conf['types.'][$termArray['term_type'].'.']['listPages'])) {
+                               $this->listPagesCache[$termType] = t3lib_div::intExplode(',',$this->conf['types.'][$termArray['term_type'].'.']['listPages']);
+                       } elseif (!empty($this->conf['listPages'])) {
+                               $this->listPagesCache[$termType] = t3lib_div::intExplode(',',$this->conf['listPages']);
+                       }
+               }
+               return $this->listPagesCache[$termType];
        }
 
 }
index 37efaea..e8eed56 100644 (file)
@@ -73,8 +73,10 @@ class tx_contagged_pi1 extends tslib_pibase {
                $this->backPid = $this->piVars['backPid'] ? intval($this->piVars['backPid']) : NULL;
                $this->pointer = $this->piVars['pointer'] ? intval($this->piVars['pointer']) : NULL;
                $this->indexChar = $this->piVars['index'] ? urldecode($this->piVars['index']) : NULL; // TODO The length should be configurable
-               if (!is_null($this->piVars['termSource']) && !is_null($this->piVars['termUid'])) {
-                       $termKey = stripslashes($this->piVars['termSource']) . '_' . intval($this->piVars['termUid']);
+               if (!is_null($this->piVars['source']) && !is_null($this->piVars['uid'])) {
+                       $dataSource = stripslashes($this->piVars['source']);
+                       $uid = intval($this->piVars['uid']);
+                       $termKey = stripslashes($this->piVars['source']) . '_' . intval($this->piVars['uid']);
                }               
                $sword = $this->piVars['sword'] ? htmlspecialchars(urldecode($this->piVars['sword'])) : NULL;
 
@@ -82,12 +84,11 @@ class tx_contagged_pi1 extends tslib_pibase {
                $this->typesArray = $this->conf['types.'];
 
                // get the model (an associated array of terms)
-               $this->mapper = new tx_contagged_model_mapper($this);
-               $this->model = new tx_contagged_model_terms($this);
-               $this->termsArray = $this->model->findAllTermsToListOnPage();
+               $this->mapper = t3lib_div::makeInstance('tx_contagged_model_mapper', $this);
+               $this->model = t3lib_div::makeInstance('tx_contagged_model_terms', $this);
 
                if ( !is_null($termKey) ) {
-                       $content .= $this->renderSingleItemByKey($termKey);
+                       $content .= $this->renderSingleItemByKey($dataSource, $uid);
                } elseif ((strtolower($this->conf['layout']) == 'minilist') || (strtolower($this->cObj->data['select_key']) == 'minilist')) {
                        $content .= $this->renderMiniList();
                } elseif ( is_null($termKey) && is_null($sword) ) {
@@ -112,11 +113,12 @@ class tx_contagged_pi1 extends tslib_pibase {
                $markerArray = array();
                $wrappedSubpartArray = array();
                $subparts = $this->getSubparts('LIST');
+               $termsArray = $this->model->findAllTermsToListOnPage();
                $this->renderLinks($markerArray, $wrappedSubpartArray);
-               $this->renderIndex($markerArray);
+               $this->renderIndex($markerArray, $termsArray);
                $this->renderSearchBox($markerArray);
                $indexedTerms = array();
-               foreach ( $this->termsArray as $termKey => $termArray ) {
+               foreach ( $termsArray as $termKey => $termArray ) {
                        if ( $this->indexChar==NULL || $termArray['indexChar']==$this->indexChar ) {
                                $indexedTerms[$termKey] = $termArray;
                        }
@@ -128,7 +130,7 @@ class tx_contagged_pi1 extends tslib_pibase {
                        $terms = $indexedTerms;
                }
                foreach ( $terms as $termKey => $termArray ) {
-                       $this->renderSingleItem($termKey,$markerArray,$wrappedSubpartArray);
+                       $this->renderSingleItem($termArray,$markerArray,$wrappedSubpartArray);
                        $subpartArray['###LIST###'] .= $this->cObj->substituteMarkerArrayCached($subparts['item'],$markerArray,$subpartArray,$wrappedSubpartArray);
                }
                $content = $this->cObj->substituteMarkerArrayCached($subparts['template_list'],$markerArray,$subpartArray,$wrappedSubpartArray);
@@ -143,9 +145,9 @@ class tx_contagged_pi1 extends tslib_pibase {
         */
        function renderMiniList() {
                $subparts = $this->getSubparts('MINILIST');
-               $terms = $this->termsArray;
+               $terms = $this->model->findAllTermsToListOnPage();
                foreach ( $terms as $termKey => $termArray ) {
-                       $this->renderSingleItem($termKey,$markerArray,$wrappedSubpartArray);
+                       $this->renderSingleItem($termArray,$markerArray,$wrappedSubpartArray);
                        $subpartArray['###LIST###'] .= $this->cObj->substituteMarkerArrayCached($subparts['item'],$markerArray,$subpartArray,$wrappedSubpartArray);
                }
                $content = $this->cObj->substituteMarkerArrayCached($subparts['template_list'],$markerArray,$subpartArray,$wrappedSubpartArray);
@@ -156,10 +158,11 @@ class tx_contagged_pi1 extends tslib_pibase {
        function renderListBySword($sword) {
                $swordMatched = FALSE;
                $subparts = $this->getSubparts('LIST');
+               $termsArray = $this->model->findAllTermsToListOnPage();
                $this->renderLinks($markerArray,$wrappedSubpartArray);
-               $this->renderIndex($markerArray);
+               $this->renderIndex($markerArray, $termsArray);
                $this->renderSearchBox($markerArray);
-               foreach ( $this->termsArray as $termKey => $termArray ) {
+               foreach ( $termsArray as $termKey => $termArray ) {
                        $fieldsToSearch = t3lib_div::trimExplode(',', $this->conf['searchbox.']['fieldsToSearch'] );
                        foreach ($fieldsToSearch as $field) {                                           
                                if (is_array($termArray[$field])) {
@@ -177,7 +180,7 @@ class tx_contagged_pi1 extends tslib_pibase {
                                }
                        }
                        if ( $swordMatched ) {
-                               $this->renderSingleItem($termKey,$markerArray,$wrappedSubpartArray);
+                               $this->renderSingleItem($termArray,$markerArray,$wrappedSubpartArray);
                                $subpartArray['###LIST###'] .= $this->cObj->substituteMarkerArrayCached($subparts['item'],$markerArray,$subpartArray,$wrappedSubpartArray);
                                $swordMatched = FALSE;
                        }
@@ -191,11 +194,13 @@ class tx_contagged_pi1 extends tslib_pibase {
                return $content;
        }
 
-       function renderSingleItemByKey($termKey) {
+       function renderSingleItemByKey($dataSource, $uid) {
+               $termArray = $this->model->findTermByUid($dataSource, $uid);
                $subparts = $this->getSubparts('SINGLE');
                $this->renderLinks($markerArray,$wrappedSubpartArray);
-               $this->renderIndex($markerArray);
-               $this->renderSingleItem($termKey,$markerArray,$wrappedSubpartArray);
+               $terms =  array($termArray);
+               $this->renderIndex($markerArray, $terms);
+               $this->renderSingleItem($termArray,$markerArray,$wrappedSubpartArray);
                $subpartArray['###LIST###'] = $this->cObj->substituteMarkerArrayCached($subparts['item'],$markerArray,$subpartArray,$wrappedSubpartArray);
                $content = $this->cObj->substituteMarkerArrayCached($subparts['template_list'],$markerArray,$subpartArray,$wrappedSubpartArray);
 
@@ -241,10 +246,16 @@ class tx_contagged_pi1 extends tslib_pibase {
                $wrappedSubpartArray['###LINK_TO_LIST###'] = $this->local_cObj->typolinkWrap($typolinkConf);            
        }
 
-       function renderSingleItem ($termKey,&$markerArray,&$wrappedSubpartArray) {
-               $termArray = $this->termsArray[$termKey];
+       function renderSingleItem ($termArray,&$markerArray,&$wrappedSubpartArray) {
                $typeConfigArray = $this->conf['types.'][$termArray['term_type'] . '.'];
 
+               if (!empty($this->conf['fieldsToParse'])) {
+                       $fieldsToParse = t3lib_div::trimExplode(',', $this->conf['fieldsToParse']);
+                       foreach ($fieldsToParse as $fieldName) {
+                               $termArray[$fieldName] = $this->parser->parse($termArray[$fieldName]);
+                       }
+               }
+               
                $markerArray['###TERM_TYPE###'] = $typeConfigArray['label'];
                $markerArray['###TERM###'] = $termArray['term'];
                $editIconsConf = array(
@@ -255,7 +266,7 @@ class tx_contagged_pi1 extends tslib_pibase {
                $markerArray['###TERM_ALT###'] = $termArray['term_alt']?implode(', ',$termArray['term_alt']):$this->pi_getLL('na');
                $markerArray['###TERM_REPLACE###'] = $termArray['term_replace']?$termArray['term_replace']:$this->pi_getLL('na');
                $markerArray['###DESC_SHORT###'] = $termArray['desc_short']?$termArray['desc_short']:$this->pi_getLL('na');
-               $markerArray['###DESC_LONG###'] = $termArray['desc_long']?$this->parser->parse($termArray['desc_long']):$this->pi_getLL('na');
+               $markerArray['###DESC_LONG###'] = $termArray['desc_long']?$termArray['desc_long']:$this->pi_getLL('na');
                $markerArray['###IMAGES###'] = $this->renderImages($termArray);
                $markerArray['###RELATED###'] = $this->renderRelated($termArray);
                $markerArray['###TERM_LANG###'] = $this->pi_getLL('lang.'.$termArray['term_lang'])?$this->pi_getLL('lang.'.$termArray['term_lang']):$this->pi_getLL('na');
@@ -279,8 +290,8 @@ class tx_contagged_pi1 extends tslib_pibase {
                if (!empty($typeConfigArray['typolink.'])) {
                        $typolinkConf = t3lib_div::array_merge_recursive_overrule($typolinkConf, $typeConfigArray['typolink.']);
                }
-               $typolinkConf['additionalParams'] .= '&' . $this->prefixId . '[termSource]=' . $termArray['sourceName'] . '&' . $this->prefixId . '[termUid]=' . $termArray['uid'];
-               $typolinkConf['parameter'] = $termArray['listPages'][0];
+               $typolinkConf['additionalParams'] .= '&' . $this->prefixId . '[source]=' . $termArray['sourceName'] . '&' . $this->prefixId . '[uid]=' . $termArray['uid'];
+               $typolinkConf['parameter'] = array_shift($this->model->getListPidsArray($termArray['term_type']));
                $this->typolinkConf['parameter.']['current'] = 0;
                $typolinkConf['parameter.']['wrap'] = "|,".$GLOBALS['TSFE']->type;
                $wrappedSubpartArray['###LINK_DETAILS###'] = $this->local_cObj->typolinkWrap($typolinkConf);
@@ -290,19 +301,16 @@ class tx_contagged_pi1 extends tslib_pibase {
                $relatedCode = '';
                if (is_array($term['related'])) {
                        foreach ($term['related'] as $termReference) {
-                               $result = $this->model->findTermByUid($termReference['sourceName'], $termReference['uid']);
+                               $relatedTerm = $this->model->findTermByUid($termReference['source'], $termReference['uid']);
                                $key = key($result);
-                               if (array_key_exists($key, $this->termsArray)) {
-                                       $relatedTerm = current($result);
-                                       $typolinkConf = $this->typolinkConf;
-                                       if (!empty($typeConfigArray['typolink.'])) {
-                                               $typolinkConf = t3lib_div::array_merge_recursive_overrule($typolinkConf, $typeConfigArray['typolink.']);
-                                       }
-                                       $typolinkConf['useCacheHash'] = 1;
-                                       $typolinkConf['additionalParams'] .= '&' . $this->prefixId . '[termSource]=' . $relatedTerm['sourceName'] . '&' . $this->prefixId . '[termUid]=' . $relatedTerm['uid'];
-                                       $typolinkConf['parameter.']['wrap'] = "|,".$GLOBALS['TSFE']->type;
-                                       $relatedCode .= $this->local_cObj->stdWrap($this->local_cObj->typoLink($relatedTerm['term'], $typolinkConf), $this->conf['related.']['single.']['stdWrap.']);                                   
+                               $typolinkConf = $this->typolinkConf;
+                               if (!empty($typeConfigArray['typolink.'])) {
+                                       $typolinkConf = t3lib_div::array_merge_recursive_overrule($typolinkConf, $typeConfigArray['typolink.']);
                                }
+                               $typolinkConf['useCacheHash'] = 1;
+                               $typolinkConf['additionalParams'] .= '&' . $this->prefixId . '[source]=' . $termReference['source'] . '&' . $this->prefixId . '[uid]=' . $termReference['uid'];
+                               $typolinkConf['parameter.']['wrap'] = "|,".$GLOBALS['TSFE']->type;
+                               $relatedCode .= $this->local_cObj->stdWrap($this->local_cObj->typoLink($relatedTerm['term'], $typolinkConf), $this->conf['related.']['single.']['stdWrap.']);
                        }
                        return $this->local_cObj->stdWrap(trim($relatedCode), $this->conf['related.']['stdWrap.']);
                } else {
@@ -359,13 +367,13 @@ class tx_contagged_pi1 extends tslib_pibase {
                
        }
 
-       function renderIndex(&$markerArray) {
+       function renderIndex(&$markerArray, &$terms) {
                if ($this->conf['index.']['enable'] > 0) {
                        $subparts = array();
                        $subparts['template_index'] = $this->cObj->getSubpart($this->templateCode,'###TEMPLATE_INDEX###');
                        $subparts['item'] = $this->cObj->getSubpart($subparts['template_index'],'###ITEM###');
 
-                       $indexArray = $this->getIndexArray();
+                       $indexArray = $this->getIndexArray($terms);
 
                        // wrap index chars and add a class attribute if there is a selected index char.
                        foreach ($indexArray as $indexChar => $link) {
@@ -388,7 +396,7 @@ class tx_contagged_pi1 extends tslib_pibase {
                }
        }
 
-       function getIndexArray() {
+       function getIndexArray(&$terms) {
                $indexArray = array();
                $reverseIndexArray = array();
                // Get localized index chars.
@@ -402,26 +410,25 @@ class tx_contagged_pi1 extends tslib_pibase {
 
                // The configuered subchars like Ö will be linked as O (see documentation and file "locallang.xml").
                $typolinkConf = $this->typolinkConf;
-               foreach ($this->termsArray as $termKey => $termArray) {
-                       if ( $termArray['exclude']!=1 && $this->conf['types.'][$termArray['term_type'].'.']['dontListTerms']!=1 && in_array($GLOBALS['TSFE']->id,$termArray['listPages']) ) {
-                               $sortField = $this->model->getSortField($termArray);
+               foreach ($terms as $termKey => $termArray) {
+                       if ( $this->conf['types.'][$termArray['term_type'].'.']['dontListTerms']!=1 ) {
                                foreach ($reverseIndexArray as $subChar => $indexChar) {
-                                       if ( preg_match('/^'.preg_quote($subChar).'/' . $this->conf['modifier'],$termArray[$sortField])>0 ) {
+                                       if ( preg_match('/^'.preg_quote($subChar).'/' . $this->conf['modifier'],$termArray['term'])>0 ) {
                                                $typolinkConf['additionalParams'] = '&' . $this->prefixId . '[index]=' . $indexChar;
                                                $indexArray[$indexChar] = $this->local_cObj->typolink($indexChar, $typolinkConf);
-                                               $this->termsArray[$termKey]['indexChar'] = $indexChar;
+                                               $terms[$termKey]['indexChar'] = $indexChar;
                                        }
                                }
                                // If the term matches no given index char, crate one if desired and add it to the index
-                               if ( ($this->termsArray[$termKey]['indexChar'] == '') && ($this->conf['index.']['autoAddIndexChars'] == 1) ) {                                  
+                               if ( ($terms[$termKey]['indexChar'] == '') && ($this->conf['index.']['autoAddIndexChars'] == 1) ) {                                     
                                        // get the first char of the term (UTF8)
                                        // TODO: Make the RegEx configurable to make ZIP-Codes possible
-                                       preg_match('/^./' . $this->conf['modifier'],$termArray[$sortField],$match);
+                                       preg_match('/^./' . $this->conf['modifier'],$termArray['term'],$match);
                                        $newIndexChar = $match[0];
                                        $indexArray[$newIndexChar] = NULL;
                                        $typolinkConf['additionalParams'] .= '&' . $this->prefixId . '[index]=' . urlencode($newIndexChar);
                                        $indexArray[$newIndexChar] = $this->local_cObj->typolink($newIndexChar, $typolinkConf);
-                                       $this->termsArray[$termKey]['indexChar'] = $newIndexChar;
+                                       $terms[$termKey]['indexChar'] = $newIndexChar;
                                }
                        }
                }
index 622b569..e9e38a1 100644 (file)
@@ -51,10 +51,10 @@ contagged {
        fieldsToSearch = term_main,term_alt,term_replace,desc_short,desc_long,imagecaption
        # cat=contagged (list)//34; type=string; label=Sort Field: The front-end lists will be sorted by this field.
        sortField = term
+       # cat=contagged (list)//38; type=string; label=Fields to be parsed: Fields to be parsed by contagged again before they are outputted in the list view.
+       fieldsToParse = 
        # cat=contagged (list)//40; type=string; label=Fields to Map: Fields to be mapped.
        fieldsToMap = uid,pid,term_main,term_alt,term_type,term_lang,term_replace,desc_short,desc_long,image,imagecaption,imagealt,imagetitle,related,link,exclude
-       # cat=contagged (list)//41; type=string; label=Secured Fields
-       secureFields = 
        # cat=contagged (list)//50; type=boolean; label=Add Back Link: Add a back link to the refering page. Be aware of caching if you activate this!
        addBackLink = 0
        # cat=contagged (list)//51; type=boolean; label=Add Back Link Desc.: Add the page title to the back link.
index b7dd49b..6734843 100644 (file)
@@ -2,14 +2,14 @@
 includeLibs.tx_contagged = EXT:contagged/class.tx_contagged.php
 
 # invoke the parser
-lib.stdheader.stdWrap.postUserFunc = tx_contagged->main
+lib.stdheader.stdWrap.postUserFunc = tx_contagged->main
 tt_content {
        text.20.postUserFunc = tx_contagged->main
-       bullets.20.postUserFunc = tx_contagged->main
-       table.20.stdWrap.postUserFunc = tx_contagged->main
-       uploads.20.itemRendering.20.2.postUserFunc = tx_contagged->main
-       image.20.caption.1.postUserFunc = tx_contagged->main
-       html.postUserFunc = tx_contagged->main
+       bullets.20.postUserFunc = tx_contagged->main
+       table.20.stdWrap.postUserFunc = tx_contagged->main
+       uploads.20.itemRendering.20.2.postUserFunc = tx_contagged->main
+       image.20.caption.1.postUserFunc = tx_contagged->main
+       html.postUserFunc = tx_contagged->main
 }
 
 plugin.tx_contagged {
@@ -36,7 +36,7 @@ plugin.tx_contagged {
        modifier = {$contagged.modifier}
        sortField = {$contagged.sortField}
        fieldsToMap = {$contagged.fieldsToMap}
-       secureFields = {$contagged.secureFields}
+       fieldsToParse = {$contagged.fieldsToParse}
        addBackLink = {$contagged.addBackLink}
        addBackLinkDescription = {$contagged.addBackLinkDescription}
                        
@@ -141,6 +141,7 @@ plugin.tx_contagged {
                                term_lang.field = term_lang
                                desc_short.field = desc_short
                                desc_long.field = desc_long
+                               # desc_long.stdWrap.parseFunc < lib.parseFunc_RTE
                                image.field = image
                                imagecaption.field = imagecaption
                                imagealt.field = imagealt
diff --git a/tca.php b/tca.php
index 724e840..6fcb56c 100644 (file)
--- a/tca.php
+++ b/tca.php
@@ -132,7 +132,7 @@ $TCA["tx_contagged_terms"] = array (
                                "label" => "LLL:EXT:contagged/locallang_db.xml:tx_contagged_terms.term_lang",           
                                "config" => Array (
                                        "type" => "select",
-// TODO Make selectable languages configurable. 
+                                       // TODO Make selectable languages configurable. 
                                        "items" => Array (
                                                Array("LLL:EXT:contagged/locallang_db.xml:tx_contagged_terms.term_lang.I.0", ""),
                                                Array("LLL:EXT:contagged/locallang_db.xml:tx_contagged_terms.term_lang.I.1", "en"),
@@ -169,17 +169,6 @@ $TCA["tx_contagged_terms"] = array (
                                        "type" => "text",
                                        "cols" => "30",
                                        "rows" => "5",
-                                       "wizards" => Array(
-                                               "_PADDING" => 2,
-                                               "RTE" => array(
-                                                       "notNewRecords" => 1,
-                                                       "RTEonly" => 1,
-                                                       "type" => "script",
-                                                       "title" => "Full screen Rich Text Editing|Formatteret redigering i hele vinduet",
-                                                       "icon" => "wizard_rte2.gif",
-                                                       "script" => "wizard_rte.php",
-                                               ),
-                                       ),
                                )
                        ),
                        'related' => Array (