BUGFIX: In some cases no term was found if the content was not UTF-8; now support...
authorjocrau <jocrau@735d13b6-9817-0410-8766-e36946ffe9aa>
Tue, 9 Sep 2008 10:05:32 +0000 (10:05 +0000)
committerBastian Bringenberg <spam@bastian-bringenberg.de>
Thu, 4 Dec 2014 23:56:05 +0000 (00:56 +0100)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/contagged/trunk@11834 735d13b6-9817-0410-8766-e36946ffe9aa

ChangeLog
class.tx_contagged.php
ext_emconf.php
pi1/class.tx_contagged_pi1.php
static/constants.txt

index 42a6380..d985658 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+v0.1.2 2008-09-09 Jochen Rau <j.rau@web.de>
+
+       * FIX In some cases no term was found; the use of the modifier "u" didn't work if the content is not UTF-8; now support for UTF-8 must be activated manually by changing the RegEx-modifier "Uis" to "Uuis"; fixes bug #1483
+
 v0.1.1 2008-09-01 Jochen Rau <j.rau@web.de>
 
        * ADD Added a RealUrl example configuration to "doc" folder
index 4d26320..f9fc3c3 100644 (file)
@@ -51,21 +51,21 @@ class tx_contagged extends tslib_pibase {
                
                // exit if the content should be skipped
                if ($this->isContentToSkip()) return $content;
-               
-               $GLOBALS['TSFE']->additionalHeaderData['tx_contagged'] = '<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath('contagged').'js/selecttext.js"></script>';
-               $GLOBALS['TSFE']->JSeventFuncCalls['onload']['tx_contagged'] = 'init_getSelectedText();';
+
+               // $GLOBALS['TSFE']->additionalHeaderData['tx_contagged'] = '<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath('contagged').'js/selecttext.js"></script>';
+               // $GLOBALS['TSFE']->JSeventFuncCalls['onload']['tx_contagged'] = 'init_getSelectedText();';
                // $GLOBALS['TSFE']->JSeventFuncCalls['onmouseup']['tx_contagged'] = 'getSelectedText();';
                // $GLOBALS['TSFE']->divSection = '<span id="tx_contagged_new" style="visibility:hidden;position:relative;top:280px;left:10px;z-index:1000;"></span>';
 
                // TODO "New" icon
-               $storagePids = t3lib_div::trimExplode(',',$this->conf['storagePids'],1);
-               $mainStoragePid = $storagePids[0];
-               $panelConf = array(
-                               'newRecordFromTable' => 'tx_contagged_terms',
-                               'newRecordInPid' => $mainStoragePid,
-                               );
-               $innerHTML = $this->cObj->editPanel('',$panelConf,'');
-               $GLOBALS['TSFE']->divSection = '<div id="tx_contagged_panel" class="" style="visibility:hidden;position:absolute;width:0px;top:0;left:0;z-index:1000;">'.$innerHTML.'</div>';
+               // $storagePids = t3lib_div::trimExplode(',',$this->conf['storagePids'],1);
+               // $mainStoragePid = $storagePids[0];
+               // $panelConf = array(
+               //              'newRecordFromTable' => 'tx_contagged_terms',
+               //              'newRecordInPid' => $mainStoragePid,
+               //              );
+               // $innerHTML = $this->cObj->editPanel('',$panelConf,'');
+               // $GLOBALS['TSFE']->divSection = '<div id="tx_contagged_panel" class="" style="visibility:hidden;position:absolute;width:0px;top:0;left:0;z-index:1000;">'.$innerHTML.'</div>';
                
 
                // get an array of all type configurations
@@ -81,13 +81,11 @@ class tx_contagged extends tslib_pibase {
 
                // TODO split recursively
                $parseObj = t3lib_div::makeInstance('t3lib_parsehtml');
-               $content = $parseObj->splitIntoBlock($tagsToOmitt,$content);
-               // debug($content);
-               foreach($content as $intKey => $HTMLvalue) {
+               $splittedContent = $parseObj->splitIntoBlock($tagsToOmitt,$content);
+               foreach((array)$splittedContent as $intKey => $HTMLvalue) {
                        if (!($intKey%2)) {
                                $positionsArray = array();
                                // iterate through all terms
-                               // debug($this->termsArray);
                                foreach ($this->termsArray as $termKey=>$termArray) {
                                        // get the maximum amount of replaced terms
                                        $maxOccur = $this->typesArray[$termArray['term_type'] . '.']['maxOccur'] ? (int)$typeConfigArray['maxOccur'] : 9999;
@@ -102,16 +100,14 @@ class tx_contagged extends tslib_pibase {
                                        // sort the array descending by length of the value, so the longest term will match
                                        usort($terms,array($this,'sortArrayByLengthDescending'));
                                        foreach ( $terms as $term ) {
-                                               $this->getPositions($content[$intKey],&$positionsArray,$typeConfigArray,$term,$termArray,$termKey,$regEx,$tagsToOmitt,$maxOccur);
+                                               $this->getPositions($splittedContent[$intKey],&$positionsArray,$typeConfigArray,$term,$termArray,$termKey,$regEx,$tagsToOmitt,$maxOccur);
                                        }
                                }
-                               // debug($content[$intKey]);
                                ksort($positionsArray);
-                               // debug($positionsArray);
-                               $content[$intKey] = $this->doReplace($content[$intKey],$positionsArray);                        
+                               $splittedContent[$intKey] = $this->doReplace($splittedContent[$intKey],$positionsArray);                        
                        }
                }
-               $content = implode('',$content);
+               $parsedContent = implode('',$splittedContent);
                
 
                // update the keywords (field "tx_contagged_keywords" in table "page")
@@ -119,7 +115,7 @@ class tx_contagged extends tslib_pibase {
                        $this->insertKeywords();
                }
 
-               return $content;
+               return $parsedContent;
 
        }
        
@@ -139,7 +135,8 @@ class tx_contagged extends tslib_pibase {
                if ( $this->checkLocalGlobal($typeConfigArray,'termIsRegEx')>0 ) {
                        $regEx = $termArray['term_main'].$this->conf['modifier'];
                } else {
-                       $regEx = '/(?<=\P{L}|^)' . preg_quote($regExTerm,'/') . '(?=\P{L}|$)/'.$this->conf['modifier'];
+                       $regEx = '/(?<=\W|^)' . preg_quote($regExTerm,'/') . '(?=\W|$)/' . $this->conf['modifier'];
+                       // $regEx = '/(?<=\W|^)' . preg_quote($regExTerm,'/') . '(?=\W|$)/Uis';
                }
                
                return $regEx;
@@ -147,9 +144,9 @@ class tx_contagged extends tslib_pibase {
 
        function getPositions($content,&$positionsArray,$typeConfigArray,$term,$termArray,$termKey,$regEx,$tagsToOmitt,$maxOccur) {
                $regEx = $this->getRegEx($term,$termKey,$typeConfigArray);
-               // debug($regEx,2);
                preg_match_all($regEx,$content,$matchesArray,PREG_OFFSET_CAPTURE);
                $matchesArray = $matchesArray[0]; // only take the full pattern matches of the regEx
+               // var_dump($matchesArray);
                for ($i=0; $i < count($matchesArray); $i++) {
                        
                        $preContent = substr($content,0,$matchesArray[$i][1]);
@@ -157,7 +154,7 @@ class tx_contagged extends tslib_pibase {
 
                        // Flag: $inTag=true if we are inside a tag < here we are >
                        $inTag = FALSE;
-                       if ( preg_match('/<[^<>]*$/u',$preContent)>0 && preg_match('/^[^<>]*>/u',$postContent)>0 ) {
+                       if ( preg_match('/<[^<>]*$/' . $this->conf['modifier'],$preContent)>0 && preg_match('/^[^<>]*>/' . $this->conf['modifier'],$postContent)>0 ) {
                                $inTag = TRUE;
                        }
                        if (!$inTag) {
@@ -165,8 +162,8 @@ class tx_contagged extends tslib_pibase {
                                $preMatch = '';
                                $postMatch = '';
                                if ($this->checkLocalGlobal($typeConfigArray,'checkPreAndPostMatches')>0) {
-                                       preg_match('/(?<=\P{L})[\p{L}\p{Pd}]*\p{Pd}$/Uuis', $preContent, $preMatch);
-                                       preg_match('/^\p{Pd}[\p{L}\p{Pd}]*(?=\P{L})/Uuis', $postContent, $postMatch);
+                                       preg_match('/(?<=\W)\w*-$/' . $this->conf['modifier'], $preContent, $preMatch);
+                                       preg_match('/^-\w*(?=\W)/' . $this->conf['modifier'], $postContent, $postMatch);
                                }
                                $matchedTerm = $preMatch[0].$matchesArray[$i][0].$postMatch[0];
                                $matchStart = $matchesArray[$i][1] - strlen($preMatch[0]);
@@ -359,7 +356,7 @@ class tx_contagged extends tslib_pibase {
                // Replace <p></p> with <br/>; Idea from Markus Timtner. Thank you!
                // TODO: strip or replace all block-tags
                if ($typeConfigArray['stripBlockTags']>0) {
-                       $this->termsArray[$termKey]['desc_long'] = preg_replace('/<p[^<>]*>(.*?)<\/p\s*>/ui','$1<br />',$this->termsArray[$termKey]['desc_long']);
+                       $this->termsArray[$termKey]['desc_long'] = preg_replace('/<p[^<>]*>(.*?)<\/p\s*>/' . $this->conf['modifier'],'$1<br />',$this->termsArray[$termKey]['desc_long']);
                }
 
                $GLOBALS['TSFE']->register['contagged_key'] = $termKey;
index 96c549f..243780b 100644 (file)
@@ -3,7 +3,7 @@
 ########################################################################
 # Extension Manager/Repository config file for ext: "contagged"
 #
-# Auto generated 01-09-2008 17:25
+# Auto generated 09-09-2008 12:05
 #
 # Manual updates:
 # Only the data in the array - anything else is removed by next write.
@@ -15,7 +15,7 @@ $EM_CONF[$_EXTKEY] = array(
        'description' => 'This extension parses your content to tag, replace and link specific terms. It is useful to auto-generate a glossary - but not only. See \'ChangeLog\' and WiKi (\'http://wiki.typo3.org/index.php/Contagged\'). Needs at least PHP 4.4.0',
        'category' => 'fe',
        'shy' => 0,
-       'version' => '0.1.0',
+       'version' => '0.1.2',
        'dependencies' => '',
        'conflicts' => '',
        'priority' => '',
@@ -40,7 +40,7 @@ $EM_CONF[$_EXTKEY] = array(
                'suggests' => array(
                ),
        ),
-       '_md5_values_when_last_written' => 'a:24:{s:9:"ChangeLog";s:4:"e057";s:10:"README.txt";s:4:"821e";s:22:"class.tx_contagged.php";s:4:"35e5";s:21:"ext_conf_template.txt";s:4:"0086";s:12:"ext_icon.gif";s:4:"50a3";s:17:"ext_localconf.php";s:4:"d45d";s:14:"ext_tables.php";s:4:"022c";s:14:"ext_tables.sql";s:4:"3600";s:27:"icon_tx_contagged_terms.gif";s:4:"50a3";s:16:"locallang_db.xml";s:4:"750b";s:7:"tca.php";s:4:"b9b2";s:14:"doc/manual.sxw";s:4:"0774";s:23:"doc/realurl_example.php";s:4:"7ef3";s:16:"js/selecttext.js";s:4:"1179";s:41:"model/class.tx_contagged_model_mapper.php";s:4:"8ead";s:40:"model/class.tx_contagged_model_terms.php";s:4:"a8ed";s:30:"pi1/class.tx_contagged_pi1.php";s:4:"2a60";s:18:"pi1/contagged.tmpl";s:4:"4d1f";s:17:"pi1/locallang.xml";s:4:"1a34";s:20:"static/constants.txt";s:4:"ec47";s:16:"static/setup.txt";s:4:"635b";s:20:"static/css/setup.txt";s:4:"fd93";s:25:"static/examples/setup.txt";s:4:"b39c";s:31:"tests/tx_contagged_testcase.php";s:4:"4a3c";}',
+       '_md5_values_when_last_written' => 'a:23:{s:9:"ChangeLog";s:4:"2429";s:10:"README.txt";s:4:"72b7";s:22:"class.tx_contagged.php";s:4:"3429";s:21:"ext_conf_template.txt";s:4:"0086";s:12:"ext_icon.gif";s:4:"50a3";s:17:"ext_localconf.php";s:4:"d45d";s:14:"ext_tables.php";s:4:"022c";s:14:"ext_tables.sql";s:4:"3600";s:27:"icon_tx_contagged_terms.gif";s:4:"50a3";s:16:"locallang_db.xml";s:4:"750b";s:7:"tca.php";s:4:"b9b2";s:14:"doc/manual.sxw";s:4:"0774";s:23:"doc/realurl_example.php";s:4:"7ef3";s:16:"js/selecttext.js";s:4:"1179";s:41:"model/class.tx_contagged_model_mapper.php";s:4:"8ead";s:40:"model/class.tx_contagged_model_terms.php";s:4:"a8ed";s:30:"pi1/class.tx_contagged_pi1.php";s:4:"6370";s:18:"pi1/contagged.tmpl";s:4:"4d1f";s:17:"pi1/locallang.xml";s:4:"1a34";s:20:"static/constants.txt";s:4:"d5ab";s:16:"static/setup.txt";s:4:"635b";s:20:"static/css/setup.txt";s:4:"fd93";s:25:"static/examples/setup.txt";s:4:"b39c";}',
        'suggests' => array(
        ),
 );
index f7cb203..3804ab4 100644 (file)
@@ -320,7 +320,7 @@ class tx_contagged_pi1 extends tslib_pibase {
                                foreach ($reverseIndexArray as $subChar => $indexChar) {
                                        // debug(preg_quote($subChar),$termArray['term']);
                                        // debug(preg_match('/^'.preg_quote($subChar).'/ui',$termArray['term']));
-                                       if ( preg_match('/^'.preg_quote($subChar).'/ui',$termArray[$sortField])>0 ) {
+                                       if ( preg_match('/^'.preg_quote($subChar).'/' . $this->conf['modifier'],$termArray[$sortField])>0 ) {
                                                $typolinkConf['additionalParams'] = '&' . $this->prefixId . '[index]=' . $indexChar;
                                                $indexArray[$indexChar] = $this->local_cObj->typolink($indexChar, $typolinkConf);
                                                $this->termsArray[$termKey]['indexChar'] = $indexChar;
@@ -330,7 +330,7 @@ class tx_contagged_pi1 extends tslib_pibase {
                                if ( $this->termsArray[$termKey]['indexChar']=='' && $this->conf['autoAddIndexChars']==1 ) {                                    
                                        // get the first char of the term (UTF8)
                                        // TODO: Make the RegEx configurable to make ZIP-Codes possible
-                                       preg_match('/^./u',$termArray[$sortField],$match);
+                                       preg_match('/^./' . $this->conf['modifier'],$termArray[$sortField],$match);
                                        $newIndexChar = $match[0];
                                        $indexArray[$newIndexChar] = NULL;
                                        $typolinkConf['additionalParams'] = '&' . $this->prefixId . '[index]=' . urlencode($newIndexChar);
index 756e51b..7ea1f24 100644 (file)
@@ -53,8 +53,8 @@ contagged {
        # cat=plugin.contagged//85; type=wrap; label=[Label Wrap 2]
        labelWrap2 = &nbsp;(|)
 
-       # cat=plugin.contagged//90; type=string; label=[RegEx modifier]: RegEx modifier of the main RegEx. Don't touch it, if you don't know what you do ;-) .
-       modifier = Uuis
+       # cat=plugin.contagged//90; type=string; label=[RegEx modifier]: RegEx modifier of the main RegEx. You have to add "u" if you have a site with UTF-8 encoding.
+       modifier = Uis
 
        # cat=plugin.contagged//91; type=string; label=[Fields to be searched]: Fields to be searched.
        fieldsToSearch = term,term_main,term_replace,desc_short,desc_long