* Minor change to spamProtectEmailAddresses ASCII
[Packages/TYPO3.CMS.git] / typo3 / view_help.php
index 0403672..3a67109 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@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
  * Revised for TYPO3 3.7 5/2004 by Kasper Skaarhoj
  * XHTML-trans compliant
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  *
- *   87: class SC_view_help
- *  110:     function init()
- *  130:     function main()
- *  158:     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
- *  181:     function render_TOC()
- *  280:     function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys)
- *  311:     function render_TOC_makeTocList($tocArray)
- *  346:     function render_Table($table)
- *  391:     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
- *  433:     function make_seeAlso($value,$anchorTable='')
- *  471:     function printImage($image,$descr)
- *  493:     function headerLine($str,$type=0)
- *  514:     function prepareContent($str)
- *  529:     function printItem($table,$field,$anchors=0)
- *  565:     function getTableFieldNames($table,$field)
+ *  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: 14
+ * TOTAL FUNCTIONS: 19
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
@@ -68,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;
+       }
+
+}
 
 
 
@@ -80,7 +114,7 @@ require_once(PATH_t3lib.'class.t3lib_loadmodules.php');
 /**
  * Script Class for rendering the Context Sensitive Help documents, either the single display in the small pop-up window or the full-table view in the larger window.
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  */
@@ -99,6 +133,7 @@ class SC_view_help {
 
                // Internal, dynamic:
        var $content;   // Content accumulation.
+       var $glossaryWords;             // Glossary words
 
 
 
@@ -118,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;
        }
 
        /**
@@ -136,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();
@@ -232,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]))    {
@@ -324,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 = '';
@@ -394,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>';
@@ -427,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 />
@@ -460,7 +512,8 @@ class SC_view_help {
         * @return      string          See-also links HTML
         */
        function make_seeAlso($value,$anchorTable='')   {
-               global $TCA,$BE_USER;
+               global $TCA,$BE_USER,$TCA_DESCR;
+
                        // Split references by comma, vert.line or linebreak
                $items = split(',|'.chr(10),$value);
                $lines = array();
@@ -485,10 +538,14 @@ class SC_view_help {
 
                                        if (!isset($TCA[$iP[0]]) || ((!$iP[1] || is_array($TCA[$iP[0]]['columns'][$iP[1]])) && (!$this->limitAccess || ($BE_USER->check('tables_select',$iP[0]) && (!$iP[1] || !$TCA[$iP[0]]['columns'][$iP[1]]['exclude'] || $BE_USER->check('non_exclude_fields',$iP[0].':'.$iP[1]))))))      {       // Checking read access:
 
-                                                       // Make see-also link:
-                                               $href = ($this->renderALL || ($anchorTable && $iP[0]==$anchorTable) ? '#'.implode('.',$iP) : 'view_help.php?tfID='.rawurlencode(implode('.',$iP)).'&back='.$this->tfID);
-                                               $label = $this->getTableFieldLabel($iP[0],$iP[1],' / ');
-                                               $lines[] = '<a href="'.htmlspecialchars($href).'">'.htmlspecialchars($label).'</a>';
+                                                       // Load table descriptions:
+                                               #$LANG->loadSingleTableDescription($iP[0]);
+                                               if (isset($TCA_DESCR[$iP[0]]))  {
+                                                               // Make see-also link:
+                                                       $href = ($this->renderALL || ($anchorTable && $iP[0]==$anchorTable) ? '#'.implode('.',$iP) : 'view_help.php?tfID='.rawurlencode(implode('.',$iP)).'&back='.$this->tfID);
+                                                       $label = $this->getTableFieldLabel($iP[0],$iP[1],' / ');
+                                                       $lines[] = '<a href="'.htmlspecialchars($href).'">'.htmlspecialchars($label).'</a>';
+                                               }
                                        }
                                }
                        }
@@ -521,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>';
@@ -642,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;
+       }
 }