* Minor change to spamProtectEmailAddresses ASCII
[Packages/TYPO3.CMS.git] / typo3 / view_help.php
index db1f85f..3a67109 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  *
  *
  *
- *   88: class SC_view_help
- *  111:     function init()
- *  131:     function main()
- *  160:     function printContent()
+ *   82: class local_t3lib_parsehtml extends t3lib_parsehtml
+ *   93:     function processContent($value,$dir,$conf)
+ *
+ *
+ *  114: class SC_view_help
+ *  138:     function init()
+ *  159:     function main()
+ *  190:     function printContent()
  *
  *              SECTION: Rendering main modes
- *  183:     function render_TOC()
- *  292:     function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys)
- *  324:     function render_TOC_makeTocList($tocArray)
- *  363:     function render_Table($table)
- *  420:     function render_Single($table,$field)
+ *  213:     function render_TOC()
+ *  330:     function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys)
+ *  362:     function render_TOC_makeTocList($tocArray)
+ *  401:     function render_Table($table)
+ *  461:     function render_Single($table,$field)
  *
  *              SECTION: Rendering CSH items
- *  463:     function make_seeAlso($value,$anchorTable='')
- *  512:     function printImage($images,$descr)
- *  547:     function headerLine($str,$type=0)
- *  568:     function prepareContent($str)
- *  583:     function printItem($table,$field,$anchors=0)
- *  616:     function getTableFieldNames($table,$field)
- *  639:     function getTableFieldLabel($table,$field='',$mergeToken=': ')
+ *  507:     function make_seeAlso($value,$anchorTable='')
+ *  556:     function printImage($images,$descr)
+ *  591:     function headerLine($str,$type=0)
+ *  612:     function prepareContent($str)
+ *  627:     function printItem($table,$field,$anchors=0)
+ *  660:     function getTableFieldNames($table,$field)
+ *  683:     function getTableFieldLabel($table,$field='',$mergeToken=': ')
+ *  702:     function createGlossaryIndex()
+ *  738:     function substituteGlossaryWords($code)
+ *  776:     function substituteGlossaryWords_nonHTML($code)
  *
- * TOTAL FUNCTIONS: 15
+ * TOTAL FUNCTIONS: 19
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
@@ -69,8 +76,34 @@ require('init.php');
 require('template.php');
 $LANG->includeLLFile('EXT:lang/locallang_view_help.xml');
 require_once(PATH_t3lib.'class.t3lib_loadmodules.php');
+require_once(PATH_t3lib.'class.t3lib_parsehtml.php');
+
+
+/**
+ * Extension of the parse_html class.
+ *
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @package TYPO3
+ * @subpackage core
+ */
+class local_t3lib_parsehtml extends t3lib_parsehtml {
+
+       /**
+        * Processing content between tags for HTML_cleaner
+        *
+        * @param       string          The value
+        * @param       integer         Direction, either -1 or +1. 0 (zero) means no change to input value.
+        * @param       mixed           Not used, ignore.
+        * @return      string          The processed value.
+        * @access private
+        */
+       function processContent($value,$dir,$conf)      {
+               $value = $this->pObj->substituteGlossaryWords($value);
 
+               return $value;
+       }
 
+}
 
 
 
@@ -100,6 +133,7 @@ class SC_view_help {
 
                // Internal, dynamic:
        var $content;   // Content accumulation.
+       var $glossaryWords;             // Glossary words
 
 
 
@@ -119,8 +153,9 @@ class SC_view_help {
                        // Set internal table/field to the parts of "tfID" incoming var.
                list($this->table,$this->field) = explode('.',$this->tfID);
 
-                       // limitAccess is checked if the $this->table really IS a table.
-               $this->limitAccess = isset($TCA[$this->table]) ? TRUE : FALSE;
+                       // limitAccess is checked if the $this->table really IS a table (and if the user is NOT a translator who should see all!)
+               $showAllToUser = t3lib_BEfunc::isModuleSetInTBE_MODULES('txllxmltranslateM1') && $GLOBALS['BE_USER']->check('modules','txllxmltranslateM1');
+               $this->limitAccess = isset($TCA[$this->table]) ? !$showAllToUser : FALSE;
        }
 
        /**
@@ -137,8 +172,10 @@ class SC_view_help {
                $this->content.= $TBE_TEMPLATE->startPage($LANG->getLL('title'));
 
                if ($this->field=='*')  { // If ALL fields is supposed to be shown:
+                       $this->createGlossaryIndex();
                        $this->content.= $this->render_Table($this->table);
                } elseif ($this->tfID) { // ... otherwise show only single field:
+                       $this->createGlossaryIndex();
                        $this->content.= $this->render_Single($this->table,$this->field);
                } else {        // Render Table Of Contents if nothing else:
                        $this->content.= $this->render_TOC();
@@ -233,6 +270,14 @@ class SC_view_help {
                        }
                }
 
+                       // Glossary
+               foreach($CSHkeys as $cshKey => $value)  {
+                       if (t3lib_div::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($TCA[$cshKey]))        {
+                               $LANG->loadSingleTableDescription($cshKey);
+                               $this->render_TOC_el($cshKey, 'glossary', $outputSections, $tocArray, $CSHkeys);
+                       }
+               }
+
                        // Other:
                foreach($CSHkeys as $cshKey => $value)  {
                        if (!t3lib_div::isFirstPartOfStr($cshKey, '_MOD_') && !isset($TCA[$cshKey]))    {
@@ -325,7 +370,7 @@ class SC_view_help {
                global $LANG;
 
                        // The Various manual sections:
-               $keys = explode(',', 'core,modules,tables,extensions,other');
+               $keys = explode(',', 'core,modules,tables,extensions,glossary,other');
 
                        // Create TOC bullet list:
                $output = '';
@@ -395,6 +440,9 @@ class SC_view_help {
                        $output.= implode('<br />',$parts);
                }
 
+                       // Substitute glossary words:
+               $output = $this->substituteGlossaryWords_nonHTML($output);
+
                        // TOC link:
                if (!$this->renderALL)  {
                        $tocLink = '<p class="c-nav"><a href="view_help.php">'.$LANG->getLL('goToToc',1).'</a></p>';
@@ -428,6 +476,9 @@ class SC_view_help {
                        // Render single item:
                $output.= $this->printItem($table,$field);
 
+                       // Substitute glossary words:
+               $output = $this->substituteGlossaryWords_nonHTML($output);
+
                        // Link to Full table description and TOC:
                $getLLKey = $this->limitAccess ? 'fullDescription' : 'fullDescription_module';
                $output.= '<br />
@@ -527,7 +578,7 @@ class SC_view_help {
                                                $imgFile = '../'.$imgFile;
                                                $code.= '<br /><img src="'.$imgFile.'" '.$imgInfo[3].' class="c-inlineimg" alt="" /><br />
                                                ';
-                                               $code.= '<p><em>'.$GLOBALS['LANG']->hscAndCharConv($descr,0).'</em></p>
+                                               $code.= '<p><em>'.$GLOBALS['LANG']->hscAndCharConv($descr,1).'</em></p>
                                                ';
                                        } else $code.= '<div style="background-color: red; border: 1px solid black; color: white;">NOT AN IMAGE: '.$imgFile.'</div>';
                                } else $code.= '<div style="background-color: red; border: 1px solid black; color: white;">IMAGE FILE NOT FOUND: '.$image.'</div>';
@@ -648,6 +699,94 @@ class SC_view_help {
 
                return $labelStr;
        }
+
+       /**
+        * Creates glossary index in $this->glossaryWords
+        *
+        * @return      void
+        * @todo: Implement some caching of this array - needed when the glossary grows to a large size!
+        */
+       function createGlossaryIndex()  {
+               global $TCA_DESCR,$TCA,$LANG;
+return;
+                       // Initialize:
+               $CSHkeys = array_flip(array_keys($TCA_DESCR));
+
+                       // Glossary
+               foreach($CSHkeys as $cshKey => $value)  {
+                       if (t3lib_div::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($TCA[$cshKey]))        {
+                               $LANG->loadSingleTableDescription($cshKey);
+
+                               if (is_array($TCA_DESCR[$cshKey]['columns']))   {
+
+                                               // Traverse table columns as listed in TCA_DESCR
+                                       reset($TCA_DESCR[$cshKey]['columns']);
+                                       while(list($field,$data) = each($TCA_DESCR[$cshKey]['columns']))        {
+                                               if ($field)     {
+                                                       $this->glossaryWords[$cshKey.'.'.$field] = array(
+                                                               'title' => trim($data['alttitle'] ? $data['alttitle'] : $cshKey),
+                                                               'description' => $data['description'],
+                                                       );
+                                               }
+                                       }
+                               }
+                       }
+               }
+#debug($this->glossaryWords);
+       }
+
+       /**
+        * Substituting glossary words in the CSH
+        *
+        * @param       string          Input HTML string
+        * @return      string          HTML with substituted words in.
+        * @todo        It is certain that the substitution of words could be improved. This is just a basic implementation. Suggestions are welcome!
+        */
+       function substituteGlossaryWords($code) {
+               if (is_array($this->glossaryWords) && strlen(trim($code)))      {
+#debug(array($code),1);
+                               // First, create unique list of words:
+                       $substWords = array();
+                       foreach($this->glossaryWords as $key => $value) {
+                               $word = strtolower($value['title']);    // Making word lowercase in order to filter out same words in different cases.
+
+                               if ($word!=='') {
+                                       $substWords[$word] = $value;
+                                       $substWords[$word]['key'] = $key;
+                               }
+                       }
+
+                               // Substitute words:
+                       foreach($substWords as $wordSet)        {
+                               $parts = preg_split("/([^[:alnum:]]+)(".$wordSet['title'].")([^[:alnum:]]+)/", ' '.$code.' ', 2, PREG_SPLIT_DELIM_CAPTURE);
+                               if (count($parts) == 5) {
+                                       $parts[2] = '<a style="background-color: yellow; " href="'.htmlspecialchars('view_help.php?tfID='.rawurlencode($wordSet['key']).'&back='.$this->tfID).'" title="'.htmlspecialchars($wordSet['description']).'">'.$parts[2].'</a>';
+#debug($parts,$word);
+#debug($wordSet['title']);
+                                       $code = substr(implode('',$parts),1,-1);
+
+                                               // Disable entry so it doesn't get used next time:
+                                       unset($this->glossaryWords[$wordSet['key']]);
+                               }
+                       }
+               }
+
+               return $code;
+       }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $code: ...
+        * @return      [type]          ...
+        */
+       function substituteGlossaryWords_nonHTML($code) {
+               $htmlParser = t3lib_div::makeInstance('local_t3lib_parsehtml');
+               $htmlParser->pObj = &$this;
+               $code = $htmlParser->HTMLcleaner($code, array(), 1);
+
+               return $code;
+       }
 }