Some minor bugfixes. New feature: auto-generation of keywords.
authorjocrau <jocrau@735d13b6-9817-0410-8766-e36946ffe9aa>
Wed, 16 May 2007 21:41:42 +0000 (21:41 +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@5485 735d13b6-9817-0410-8766-e36946ffe9aa

ChangeLog
class.tx_contagged.php
ext_emconf.php
ext_tables.php
ext_tables.sql
static/constants.txt
static/css/setup.txt
static/setup.txt
tca.php

index 1b3dc33..5a2e669 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 (add new changes on top of this file)
 
-07-04-27 Jochen Rau  <j.rau@web.de>
+2007-05-16 Jochen Rau  <j.rau@web.de>
+
+       * Changed from tt_content.text.20.parseFunc.userFunc to .postUserFunc
+       * Changed the separator of alternative terms from '|' (Pipe) to chr(10) (CR); the backend field is now multiline
+       * Added a prefix 'contagged_' to the registered values in $GLOBALS['TSFE'] to prevend name conflicts
+       * Some bugfixes in the type configuration and the css-class of dfn_inline
+       * Added option 'updateKeywords': It is now possible to auto-update page keywords based on the terms found on a page
+
+2007-04-27 Jochen Rau  <j.rau@web.de>
 
        * Initial release
index cdcaca3..dd7f0bf 100644 (file)
@@ -48,7 +48,7 @@ class tx_contagged extends tslib_pibase {
        var $pi_checkCHash = true;
        var $dataTable = 'tx_contagged_terms';
        var $conf; // the TypoScript configuration array
-
+       var $termsFoundArray = array(); // an array of main terms for each term found in the cObj
 
        /**
                * The method for parsing, tagging and linking the terms in a cObj
@@ -59,7 +59,7 @@ class tx_contagged extends tslib_pibase {
                */
        function main($content, $conf) {
                $this->conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->prefixId.'.'];
-
+               
                // exit if the page should be skipped
                if ($this->isPageToSkip()) {
                        return $content;
@@ -130,14 +130,21 @@ class tx_contagged extends tslib_pibase {
                                                        // the  term is handled as $matchedTerm, so it doesn't conflict with case (in)sensitivity of the RegEx
                                                        $matchLength = strlen($content[$intKey]) - (strlen($pieces[0]) + strlen($pieces[1]));
                                                        $matchedTerm = substr($content[$intKey], strlen($pieces[0]), $matchLength);
-                                                       $GLOBALS['TSFE']->register['matchedTerm'] = $matchedTerm;
+                                                       $GLOBALS['TSFE']->register['contagged_matchedTerm'] = $matchedTerm;
                                                        if ( trim($matchedTerm) && ($inTag === false) && ($occuranciesOfTerm < $maxOccur) ) {
+                                                               // Build an array of terms found in the content.
+                                                               // This will be used to store them as keywords of the page.
+                                                               // The term used will be the replaced term. If there is no replacement the main term will be used.
+                                                               $this->termsFoundArray[] = $termArray['term_replace']?$termArray['term_replace']:$termArray['term_main'];
+                                                               
                                                                $this->replaceMatchedTerm(&$matchedTerm,$typeConfigArray,$termArray);
                                                                $this->linkMatchedTerm(&$matchedTerm,$typeConfigArray,$termArray);
 
                                                                // call stdWrap to handle the matched term via TS
                                                                // TODO: wrapping inside AND outside the a-tag should be enabled
-                                                               $matchedTerm = $this->cObj->stdWrap($matchedTerm,$typeConfigArray['stdWrap.']);
+                                                               if ($typeConfigArray['stdWrap.']) {
+                                                                       $matchedTerm = $this->cObj->stdWrap($matchedTerm,$typeConfigArray['stdWrap.']);
+                                                               }
 
                                                                $matchedTerm = $before . $matchedTerm . $after;
 
@@ -156,21 +163,40 @@ class tx_contagged extends tslib_pibase {
                        
                        }
                }
+               
+               if ($this->conf['updateKeywords'] > 0) {
+                       $this->insertKeywords();
+               }
 
                return $content;
 
        }
 
+       function insertKeywords() {
+               // make a list of unique terms found in the content
+               $this->termsFoundArray = array_unique($this->termsFoundArray);
+               $termsFoundList = implode(',',$this->termsFoundArray);
+               // build an array passed to the UPDATE query
+               $updateArray = array($this->prefixId . '_keywords' => $termsFoundList);
+//             $updateArray = array('keywords' => $termsFoundList);
+               // execute sql-query
+               $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', // TABLE ...
+                       'uid=' . $GLOBALS['TSFE']->id, // WHERE ...
+                       $updateArray
+               );
+       }
+
        function getTypeConfigArray($termArray) {
                // shortcut to the TS configuration array of the current type of term
                $typeConfigArray = $this->conf['types.'][$termArray['term_type'] . '.'];
 
                // load several fields into the register to be handled by the TS setup
-               $GLOBALS['TSFE']->register['uid'] = $termArray['uid'];
-               $GLOBALS['TSFE']->register['desc_short'] = $termArray['desc_short'];
-               $GLOBALS['TSFE']->register['desc_long'] = $termArray['desc_long'];
-               $GLOBALS['TSFE']->register['term_replace'] = $termArray['term_replace'];
-               $GLOBALS['TSFE']->register['link'] = $termArray['link'];
+               $GLOBALS['TSFE']->register['contagged_uid'] = $termArray['uid'];
+               $GLOBALS['TSFE']->register['contagged_desc_short'] = $termArray['desc_short'];
+               $GLOBALS['TSFE']->register['contagged_desc_long'] = $termArray['desc_long'];
+               $GLOBALS['TSFE']->register['contagged_term_main'] = $termArray['term_main'];
+               $GLOBALS['TSFE']->register['contagged_term_replace'] = $termArray['term_replace'];
+               $GLOBALS['TSFE']->register['contagged_link'] = $termArray['link'];
 
                return $typeConfigArray;
 
@@ -178,11 +204,7 @@ class tx_contagged extends tslib_pibase {
 
        function linkMatchedTerm(&$matchedTerm,$typeConfigArray,$termArray) {
                // check conditions if the term should be linked to a list page
-               if ( isset($typeConfigArray['linkToListPage']) ) {
-                       $makeLink = ($typeConfigArray['linkToListPage'] > 0) ? true : false;
-               } else {
-                       $makeLink = ($this->conf['linkToListPage'] > 0) ? true : false;
-               }                                       
+               $makeLink = $this->checkLocalGlobal($typeConfigArray,'linkToListPage');
                if ( ($termArray['desc_long'] == '') || ($termArray['exclude'] > 0) ) {
                        $makeLink = false;
                }
@@ -191,6 +213,7 @@ class tx_contagged extends tslib_pibase {
                if ($makeLink) {
                        unset($typolinkConf); // TODO Is it necessary to unset the $typoLinkConf?
                        $listPage = ($typeConfigArray['listPage']?$typeConfigArray['listPage']:$this->conf['listPage']);
+                       $GLOBALS['TSFE']->register['contagged_list_page'] = $termArray['uid'];
                        $typolinkConf['parameter'] = (int) $listPage;
                        $typolinkConf['useCacheHash'] = 1;
                        $typolinkConf['additionalParams'] =
@@ -215,6 +238,15 @@ class tx_contagged extends tslib_pibase {
                }
        }
 
+       function checkLocalGlobal($typeConfigArray,$attributeName) {
+               if ( isset($typeConfigArray[$attributeName]) ) {
+                       $addAttribute = ($typeConfigArray[$attributeName] > 0) ? true : false;
+               } else {
+                       $addAttribute = ($this->conf[$attributeName] > 0) ? true : false;
+               }
+               
+               return $addAttribute;
+       }
 
        /**
                * If the language of the term is undefined, 
@@ -225,12 +257,6 @@ class tx_contagged extends tslib_pibase {
                * then the language attribute is added.
                */
        function getLangAttribute($typeConfigArray,$termArray) {
-               // check if the global or local flag to add a language attribute is set
-               if ( isset($typeConfigArray['addLangAttribute']) ) {
-                       $addLangAttribute = ($typeConfigArray['addLangAttribute'] > 0) ? true : false;
-               } else {
-                       $addLangAttribute = ($this->conf['addLangAttribute'] > 0) ? true : false;
-               }
                // get page language
                if ($GLOBALS['TSFE']->config['config']['language']) {
                        $pageLanguage = $GLOBALS['TSFE']->config['config']['language'];
@@ -238,45 +264,29 @@ class tx_contagged extends tslib_pibase {
                        $pageLanguage = substr($GLOBALS['TSFE']->config['config']['htmlTag_langKey'],0,2);
                }
                // build language attribute if the page language is different from the terms language
-               if ( $addLangAttribute && !empty($termArray['term_lang']) && ( $pageLanguage!=$termArray['term_lang'] ) ) {
+               if ( $this->checkLocalGlobal($typeConfigArray,'addLangAttribute') && !empty($termArray['term_lang']) && ( $pageLanguage!=$termArray['term_lang'] ) ) {
                        $langAttribute = ' lang="' . $termArray['term_lang'] . '"';
                        $langAttribute .= ' xml:lang="' . $termArray['term_lang'] . '"';
-               } else {
-                       $langAttribute = '';
                }
 
                return $langAttribute;
        }
 
        function getTitleAttribute($typeConfigArray,$termArray) {
-               if ( isset($typeConfigArray['addTitleAttribute']) ) {
-                       $addTitleAttribute = ($typeConfigArray['addTitleAttribute'] > 0) ? true : false;
-               } else {
-                       $addTitleAttribute = ($this->conf['addTitleAttribute'] > 0) ? true : false;
-               }                                       
-               if ($addTitleAttribute && isset($termArray['desc_short'])) {
+               if ($this->checkLocalGlobal($typeConfigArray,'addTitleAttribute') && isset($termArray['desc_short'])) {
                        $titleAttribute = ' title="' . $termArray['desc_short'] . '"';
-               } else {
-                       $titleAttribute = '';
                }
-
+               
                return $titleAttribute;
        }
 
        function getCssClassAttribute($typeConfigArray,$termArray) {
-               if ( isset($typeConfigArray['addCssClassAttribute']) ) {
-                       $addCssClassAttribute = ($typeConfigArray['addCssClassAttribute'] > 0) ? true : false;
-               } else {
-                       $addCssClassAttribute = ($this->conf['addCssClassAttribute'] > 0) ? true : false;
-               }                                       
-               if ($addCssClassAttribute) {
+               if ($this->checkLocalGlobal($typeConfigArray,'addCssClassAttribute')) {
                        if ( $typeConfigArray['cssClass'] ) {
                                $cssClassAttribute = $this->pi_classParam($typeConfigArray['cssClass']);
                        } else {
                                $cssClassAttribute = $this->pi_classParam($termArray['term_type']);
                        }
-               } else {
-                       $cssClassAttribute = '';
                }
 
                return $cssClassAttribute;
@@ -335,14 +345,16 @@ class tx_contagged extends tslib_pibase {
                $terms = array ();
                foreach ($result as $row) {
                        // build an array of alternative shortcurts (term_alt) and add the main term (term_main)
-                       $terms = t3lib_div :: trimExplode('|', htmlspecialchars($row['term_alt']), $onlyNonEmptyValues = 1);
+                       $terms = t3lib_div :: trimExplode(chr(10), htmlspecialchars($row['term_alt']), $onlyNonEmptyValues = 1);
                        $terms[] = trim(htmlspecialchars($row['term_main']));
+                       // TODO sort the array by descending length of value string; in combination with the htmlparser this will prevend nesting
                        $desc_long = $this->cObj->parseFunc($row['desc_long'],$conf='',$ref='< lib.parseFunc_RTE');
                        // $desc_long = preg_replace('/(\015\012)|(\015)|(\012)/','<br />',$row['desc_long']);
                        // $desc_long = trim(htmlspecialchars($desc_long));
                        // put it all together
                        $dataArray[] = array (
                                'uid' => $row['uid'],
+                               'term_main' => trim(htmlspecialchars($row['term_main'])),
                                'terms' => $terms,
                                'term_type' => $row['term_type'],
                                'term_lang' => $row['term_lang'],
index 3e8a07b..6db5756 100644 (file)
@@ -12,7 +12,7 @@
 
 $EM_CONF[$_EXTKEY] = array(
        'title' => 'Content parser and tagger',
-       'description' => 'This extension parses the text of a content element to tag, replace and link specific terms. It is useful to auto-generate a glossary - but not only. Because it is configurable through TS.',
+       'description' => 'The extension parses your content to tag, replace and link specific terms. It is useful to auto-generate a glossary - but not only. And it is configurable through TS.',
        'category' => 'fe',
        'author' => 'Jochen Rau',
        'author_email' => 'j.rau@web.de',
index 31ba72f..ab2d604 100644 (file)
@@ -3,7 +3,8 @@ if (!defined ('TYPO3_MODE')) die ('Access denied.');
 
 t3lib_extMgm::allowTableOnStandardPages('tx_contagged_terms');
 t3lib_extMgm::addToInsertRecords('tx_contagged_terms');
-t3lib_extMgm::addPItoST43($_EXTKEY,'class.tx_contagged.php','','includeLib',1);
+
+// t3lib_extMgm::addPItoST43($_EXTKEY,'class.tx_contagged.php','','includeLib',1);
 
 // add contagged to the "insert plugin" content element
 t3lib_extMgm::addPlugin(Array('LLL:EXT:contagged/locallang_db.php:tx_contagged_terms.plugin','contagged'));
index b284911..17b3cb6 100644 (file)
@@ -45,5 +45,6 @@ CREATE TABLE tx_contagged_terms (
 # Table structure for table 'pages'
 #
 CREATE TABLE pages (
-       tx_contagged_dont_parse tinyint(3) DEFAULT '0' NOT NULL
+       tx_contagged_dont_parse tinyint(3) DEFAULT '0' NOT NULL,
+       tx_contagged_keywords text NOT NULL,
 );
index c2740b3..45a32d3 100644 (file)
@@ -36,4 +36,6 @@ contagged {
        # cat=plugin.contagged//90; type=boolean; label=[Add css class]: Should a css class name be added to the tag? By default the class name is the name of the type of term (e.g. "dfn_inline") headed by the extension prefix.
        addCssClassAttribute = 0
 
+       # cat=plugin.contagged//95; type=boolean; label=[Update page keywords]: Should the matched terms be used as keywords for the page they are on. If there is a replaced term it will be used as keyword. If no the main term will be the keyword. The list of matched terms will be stored in a separate database field (not in the field 'keywords'), so your own keywords are preserved.
+       updateKeywords = 0
 }
\ No newline at end of file
index 7271d72..2ac1e97 100644 (file)
@@ -7,7 +7,7 @@ plugin.tx_contagged {
 
                acronym, abbr, dfn {
                        font-style: normal;
-                       border-bottom: 1px dotted #FF9900;
+                       border-bottom: 1px dotted #333333;
                        cursor: help;
                        position: relative;
                }
@@ -17,7 +17,7 @@ plugin.tx_contagged {
                }
                /* z-index makes shure the block is the top most element */
                dfn.tx-contagged-dfn_block>span {
-                       background: #FFF7CE;
+                       background: #EEEEEE;
                        display: none;
                        z-index: 9999;
                }
@@ -28,7 +28,7 @@ plugin.tx_contagged {
                        left: -11px;
                        width: 300px;
                        margin-top: -1px;
-                       border: 1px #FFCC00 solid;
+                       border: 1px #CCCCCC solid;
                        padding: 0px 10px 10px 10px;
                }
                dfn.tx-contagged-dfn_block p {
index 76c47a6..9ed663a 100644 (file)
@@ -1,5 +1,15 @@
+# incude class tx_contagged as library 
+includeLibs.tx_contagged = EXT:contagged/class.tx_contagged.php
+
 # setup the content element by calling the user function 'main' of the class tx_contagged
-tt_content.text.20.parseFunc.userFunc = tx_contagged->main
+#tt_content.text.20.parseFunc.userFunc = tx_contagged->main
+tt_content.text.20.postUserFunc = tx_contagged->main
+
+
+#temp_content < styles.content.get
+#temp_content.stdWrap.postUserFunc = tx_contagged->main
+#styles.content.get >
+#styles.content.get < temp_content
 
 plugin.tx_contagged {
        linkToListPage = {$contagged.linkToListPage}
@@ -11,6 +21,7 @@ plugin.tx_contagged {
        addTitleAttribute = {$contagged.addTitleAttribute}
        addLangAttribute = {$contagged.addLangAttribute}
        addCssClassAttribute = {$contagged.addCssClassAttribute}
+       updateKeywords = {$contagged.updateKeywords}
        types {
 
                definition {
@@ -27,12 +38,12 @@ plugin.tx_contagged {
                                10 = TEXT
                                10.value = | <span><p>
                                20 = TEXT
-                               20.data = register:matchedTerm
+                               20.data = register:contagged_matchedTerm
                                30 = TEXT
                                30.value = </p>
                                40 = TEXT
                                40.required = 1
-                               40.data = register:desc_long
+                               40.data = register:contagged_desc_long
                                50 = TEXT
                                50.value = </span>
                        }
@@ -40,7 +51,8 @@ plugin.tx_contagged {
 
                dfn_inline {
                        label = Definition (inline)
-                       linkToList = 0
+                       tag = dfn
+                       linkToListPage = 0
                        addCssClassAttribute = 1
                        stdWrap.innerWrap.cObject = COA
                        stdWrap.innerWrap.cObject {
@@ -49,7 +61,7 @@ plugin.tx_contagged {
                                20 = TEXT
                                20.required = 1
                                20.stripHtml = 1
-                               20.data = register:desc_long
+                               20.data = register:contagged_desc_long
                                30 = TEXT
                                30.value = ]&nbsp;</span>
                        }
diff --git a/tca.php b/tca.php
index 37c0aaf..7ca36c4 100644 (file)
--- a/tca.php
+++ b/tca.php
@@ -111,8 +111,9 @@ $TCA["tx_contagged_terms"] = array (
                                "exclude" => 1,
                                "label" => "LLL:EXT:contagged/locallang_db.xml:tx_contagged_terms.term_alt",
                                "config" => Array (
-                                       "type" => "input",
-                                       "size" => "30",
+                                       "type" => "text",
+                                       "cols" => "30",
+                                       "rows" => "5",
                                )
                        ),
                        "term_type" => Array (