TYPO3 API  SVNRelease
view_help.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * Document for viewing the online help texts, also known as TCA_DESCR.
00029  * See Inside TYPO3 for details.
00030  *
00031  * $Id: view_help.php 10311 2011-01-25 20:51:14Z francois $
00032  * Revised for TYPO3 3.7 5/2004 by Kasper Skårhøj
00033  * XHTML-trans compliant
00034  *
00035  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00036  */
00037 /**
00038  * [CLASS/FUNCTION INDEX of SCRIPT]
00039  *
00040  *
00041  *
00042  *   91: class local_t3lib_parsehtml extends t3lib_parsehtml
00043  *  102:     function processContent($value,$dir,$conf)
00044  *
00045  *
00046  *  122: class SC_view_help
00047  *  146:     function init()
00048  *  167:     function main()
00049  *  198:     function printContent()
00050  *
00051  *              SECTION: Rendering main modes
00052  *  221:     function render_TOC()
00053  *  338:     function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys)
00054  *  370:     function render_TOC_makeTocList($tocArray)
00055  *  409:     function render_Table($table)
00056  *  469:     function render_Single($table,$field)
00057  *
00058  *              SECTION: Rendering CSH items
00059  *  515:     function make_seeAlso($value,$anchorTable='')
00060  *  564:     function printImage($images,$descr)
00061  *  599:     function headerLine($str,$type=0)
00062  *  620:     function prepareContent($str)
00063  *  635:     function printItem($table,$field,$anchors=0)
00064  *  668:     function getTableFieldNames($table,$field)
00065  *  691:     function getTableFieldLabel($table,$field='',$mergeToken=': ')
00066  *
00067  *              SECTION: Glossary related
00068  *  726:     function createGlossaryIndex()
00069  *  785:     function substituteGlossaryWords($code)
00070  *  801:     function substituteGlossaryWords_htmlcleaner_callback($code)
00071  *
00072  * TOTAL FUNCTIONS: 19
00073  * (This index is automatically created/updated by the extension "extdeveval")
00074  *
00075  */
00076 
00077 require('init.php');
00078 require('template.php');
00079 $LANG->includeLLFile('EXT:lang/locallang_view_help.xml');
00080 
00081 
00082 /**
00083  * Extension of the parse_html class.
00084  *
00085  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00086  * @package TYPO3
00087  * @subpackage core
00088  */
00089 class local_t3lib_parsehtml extends t3lib_parsehtml {
00090 
00091     /**
00092      * Processing content between tags for HTML_cleaner
00093      *
00094      * @param   string      The value
00095      * @param   integer     Direction, either -1 or +1. 0 (zero) means no change to input value.
00096      * @param   mixed       Not used, ignore.
00097      * @return  string      The processed value.
00098      * @access private
00099      */
00100     function processContent($value,$dir,$conf)  {
00101         $value = $this->pObj->substituteGlossaryWords_htmlcleaner_callback($value);
00102 
00103         return $value;
00104     }
00105 }
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 /**
00114  * 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.
00115  *
00116  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00117  * @package TYPO3
00118  * @subpackage core
00119  */
00120 class SC_view_help {
00121     var $allowedHTML = '<strong><em><b><i>';
00122 
00123         // For these vars, see init()
00124     var $limitAccess;   // If set access to fields and tables is checked. Should be done for true database tables.
00125     var $table;         // The "table" key
00126     var $field;         // The "field" key
00127         /**
00128          * Key used to point to the right CSH resource
00129          * In simple cases, is equal to $table
00130          *
00131          * @var string
00132          */
00133     protected $mainKey;
00134 
00135         // Internal, static: GPvar:
00136     var $tfID;          // Table/FIeld id.
00137     var $ffID;          // Flexform file/field information
00138     var $back;          // Back (previous tfID)
00139     var $renderALL;     // If set, then in TOC mode the FULL manual will be printed as well!
00140 
00141         // Internal, dynamic:
00142     var $content;   // Content accumulation.
00143     var $glossaryWords;     // Glossary words
00144 
00145 
00146 
00147     /**
00148      * Initialize the class for various input etc.
00149      *
00150      * @return  void
00151      */
00152     function init() {
00153         global $LANG, $TCA;
00154 
00155             // Setting GPvars:
00156         $this->tfID = t3lib_div::_GP('tfID');
00157             // Sanitizes the tfID using whitelisting.
00158         if (!preg_match('/^[a-zA-Z0-9_\-\.\*]*$/', $this->tfID)) {
00159             $this->tfID = '';
00160         }
00161         if (!$this->tfID) {
00162             if (($this->ffID = t3lib_div::_GP('ffID'))) {
00163                 $this->ffID = unserialize(base64_decode($this->ffID));
00164             }
00165         }
00166         $this->back = t3lib_div::_GP('back');
00167         $this->renderALL = t3lib_div::_GP('renderALL');
00168 
00169             // Set internal table/field to the parts of "tfID" incoming var.
00170         $identifierParts = explode('.', $this->tfID);
00171             // The table is the first item
00172         $this->table = array_shift($identifierParts);
00173         $this->mainKey = $this->table;
00174             // The field is the second one
00175         $this->field = array_shift($identifierParts);
00176             // There may be extra parts for FlexForms
00177         if (count($identifierParts) > 0) {
00178                 // There's at least one extra part
00179             $extraIdentifierInformation = array();
00180             $extraIdentifierInformation[] = array_shift($identifierParts);
00181                 // Load the TCA details of the table
00182             t3lib_div::loadTCA($this->table);
00183                 // If the ds_pointerField contains a comma, it means the choice of FlexForm DS
00184                 // is determined by 2 parameters. In this case we have an extra identifier part
00185             if (strpos($TCA[$this->table]['columns'][$this->field]['config']['ds_pointerField'], ',') !== FALSE) {
00186                 $extraIdentifierInformation[] = array_shift($identifierParts);
00187             }
00188                 // The remaining parts make up the FlexForm field name itself
00189                 // (reassembled with dots)
00190             $flexFormField = implode('.', $identifierParts);
00191                 // Assemble a different main key and switch field to use FlexForm field name
00192             $this->mainKey .= '.' . $this->field;
00193             foreach ($extraIdentifierInformation as $extraKey) {
00194                 $this->mainKey .= '.' . $extraKey;
00195             }
00196             $this->field = $flexFormField;
00197         }
00198 
00199             // limitAccess is checked if the $this->table really IS a table (and if the user is NOT a translator who should see all!)
00200         $showAllToUser = t3lib_BEfunc::isModuleSetInTBE_MODULES('txllxmltranslateM1') && $GLOBALS['BE_USER']->check('modules','txllxmltranslateM1');
00201         $this->limitAccess = isset($TCA[$this->table]) ? !$showAllToUser : FALSE;
00202     }
00203 
00204     /**
00205      * Main function, rendering the display
00206      *
00207      * @return  void
00208      */
00209     function main() {
00210         global $BE_USER,$LANG,$TCA_DESCR,$TCA,$TBE_TEMPLATE;
00211 
00212             // Start HTML output accumulation:
00213         $TBE_TEMPLATE->divClass = 'typo3-view-help';
00214         $this->content .= $TBE_TEMPLATE->startPage($LANG->getLL('title'));
00215 
00216         if ($this->field == '*') {
00217                  // If ALL fields is supposed to be shown:
00218             $this->createGlossaryIndex();
00219             $this->content .= $this->render_Table($this->mainKey);
00220 
00221         } elseif ($this->tfID) {
00222                  // ... otherwise show only single field:
00223             $this->createGlossaryIndex();
00224             $this->content .= $this->render_Single($this->mainKey, $this->field);
00225 
00226         } elseif (is_array($this->ffID)) {
00227             $this->content .= $this->render_SingleFlex();
00228 
00229         } else {
00230                 // Render Table Of Contents if nothing else:
00231             $this->content.= $this->render_TOC();
00232         }
00233 
00234             // Print close-button:
00235 #       $this->content.='<br /><form action=""><input type="submit" value="'.htmlspecialchars($LANG->getLL('close')).'" onclick="self.close(); return false;" /></form><br/>';
00236 
00237             // End page:
00238         $this->content.= '<br/>';
00239         $this->content.= $TBE_TEMPLATE->endPage();
00240     }
00241 
00242     /**
00243      * Outputting the accumulated content to screen
00244      *
00245      * @return  void
00246      */
00247     function printContent() {
00248         echo $this->content;
00249     }
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258 
00259     /************************************
00260      *
00261      * Rendering main modes
00262      *
00263      ************************************/
00264 
00265     /**
00266      * Creates Table Of Contents and possibly "Full Manual" mode if selected.
00267      *
00268      * @return  string      HTML content
00269      */
00270     function render_TOC()   {
00271         global $TCA_DESCR,$TCA,$LANG,$BE_USER,$TBE_MODULES;
00272 
00273             // Initialize:
00274         $CSHkeys = array_flip(array_keys($TCA_DESCR));
00275         $TCAkeys = array_keys($TCA);
00276 
00277         $outputSections = array();
00278         $tocArray = array();
00279 
00280 
00281             // TYPO3 Core Features:
00282         $LANG->loadSingleTableDescription('xMOD_csh_corebe');
00283         $this->render_TOC_el('xMOD_csh_corebe', 'core', $outputSections, $tocArray, $CSHkeys);
00284 
00285             // Backend Modules:
00286         $loadModules = t3lib_div::makeInstance('t3lib_loadModules');
00287         $loadModules->load($TBE_MODULES);
00288         foreach($loadModules->modules as $mainMod => $info) {
00289             $cshKey = '_MOD_'.$mainMod;
00290             if ($CSHkeys[$cshKey])  {
00291                 $LANG->loadSingleTableDescription($cshKey);
00292                 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
00293             }
00294 
00295             if (is_array($info['sub'])) {
00296                 foreach($info['sub'] as $subMod => $subInfo)    {
00297                     $cshKey = '_MOD_'.$mainMod.'_'.$subMod;
00298                     if ($CSHkeys[$cshKey])  {
00299                         $LANG->loadSingleTableDescription($cshKey);
00300                         $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
00301                     }
00302                 }
00303             }
00304         }
00305 
00306             // Database Tables:
00307         foreach($TCAkeys as $table) {
00308                 // Load descriptions for table $table
00309             $LANG->loadSingleTableDescription($table);
00310             if (is_array($TCA_DESCR[$table]['columns']) && $BE_USER->check('tables_select',$table)) {
00311                 $this->render_TOC_el($table, 'tables', $outputSections, $tocArray, $CSHkeys);
00312             }
00313         }
00314 
00315             // Extensions
00316         foreach($CSHkeys as $cshKey => $value)  {
00317             if (t3lib_div::isFirstPartOfStr($cshKey, 'xEXT_') && !isset($TCA[$cshKey])) {
00318                 $LANG->loadSingleTableDescription($cshKey);
00319                 $this->render_TOC_el($cshKey, 'extensions', $outputSections, $tocArray, $CSHkeys);
00320             }
00321         }
00322 
00323             // Glossary
00324         foreach($CSHkeys as $cshKey => $value)  {
00325             if (t3lib_div::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($TCA[$cshKey]))    {
00326                 $LANG->loadSingleTableDescription($cshKey);
00327                 $this->render_TOC_el($cshKey, 'glossary', $outputSections, $tocArray, $CSHkeys);
00328             }
00329         }
00330 
00331             // Other:
00332         foreach($CSHkeys as $cshKey => $value)  {
00333             if (!t3lib_div::isFirstPartOfStr($cshKey, '_MOD_') && !isset($TCA[$cshKey]))    {
00334                 $LANG->loadSingleTableDescription($cshKey);
00335                 $this->render_TOC_el($cshKey, 'other', $outputSections, $tocArray, $CSHkeys);
00336             }
00337         }
00338 
00339 
00340             // COMPILE output:
00341         $output = '';
00342         $output.= '
00343 
00344             <h1>'.$LANG->getLL('manual_title',1).'</h1>';
00345 
00346         $output.= '
00347 
00348             <h2>'.$LANG->getLL('introduction',1).'</h2>
00349             <p>'.$LANG->getLL('description',1).'</p>';
00350 
00351         $output.= '
00352 
00353             <h2>'.$LANG->getLL('TOC',1).'</h2>'.
00354             $this->render_TOC_makeTocList($tocArray);
00355 
00356         if (!$this->renderALL)  {
00357             $output.= '
00358                 <br/>
00359                 <p class="c-nav"><a href="view_help.php?renderALL=1">'.$LANG->getLL('full_manual',1).'</a></p>';
00360         }
00361 
00362         if ($this->renderALL)   {
00363             $output.= '
00364 
00365                 <h2>'.$LANG->getLL('full_manual_chapters',1).'</h2>'.
00366                 implode('
00367 
00368 
00369                 <!-- NEW SECTION: -->
00370                 ',$outputSections);
00371         }
00372 
00373         $output .= '<hr /><p class="manual-title">'.t3lib_BEfunc::TYPO3_copyRightNotice().'</p>';
00374 
00375         return $output;
00376     }
00377 
00378     /**
00379      * Creates a TOC list element and renders corresponding HELP content if "renderALL" mode is set.
00380      *
00381      * @param   string      CSH key / Table name
00382      * @param   string      TOC category keyword: "core", "modules", "tables", "other"
00383      * @param   array       Array for accumulation of rendered HELP Content (in "renderALL" mode). Passed by reference!
00384      * @param   array       TOC array; Here TOC index elements are created. Passed by reference!
00385      * @param   array       CSH keys array. Every item rendered will be unset in this array so finally we can see what CSH keys are not processed yet. Passed by reference!
00386      * @return  void
00387      */
00388     function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys)    {
00389         global $LANG;
00390 
00391         if ($this->renderALL)   {   // Render full manual right here!
00392             $outputSections[$table] = $this->render_Table($table);
00393 
00394             if ($outputSections[$table])    {
00395                 $outputSections[$table] = '
00396 
00397         <!-- New CSHkey/Table: '.$table.' -->
00398         <p class="c-nav"><a name="ANCHOR_'.$table.'" href="#">'.$LANG->getLL('to_top',1).'</a></p>
00399         <h2>'.$this->getTableFieldLabel($table).'</h2>
00400 
00401         '.$outputSections[$table];
00402                 $tocArray[$tocCat][$table] = '<a href="#ANCHOR_'.$table.'">'.$this->getTableFieldLabel($table).'</a>';
00403             } else {
00404                 unset($outputSections[$table]);
00405             }
00406         } else {    // Only TOC:
00407             $tocArray[$tocCat][$table] = '<p><a href="view_help.php?tfID='.rawurlencode($table.'.*').'">'.$this->getTableFieldLabel($table).'</a></p>';
00408         }
00409 
00410             // Unset CSH key:
00411         unset($CSHkeys[$table]);
00412     }
00413 
00414     /**
00415      * Renders the TOC index as a HTML bullet list from TOC array
00416      *
00417      * @param   array       ToC Array.
00418      * @return  string      HTML bullet list for index.
00419      */
00420     function render_TOC_makeTocList($tocArray)  {
00421         global $LANG;
00422 
00423             // The Various manual sections:
00424         $keys = explode(',', 'core,modules,tables,extensions,glossary,other');
00425 
00426             // Create TOC bullet list:
00427         $output = '';
00428         foreach($keys as $tocKey)   {
00429             if (is_array($tocArray[$tocKey]))   {
00430                 $output.='
00431                     <li>'.$LANG->getLL('TOC_'.$tocKey,1).'
00432                         <ul>
00433                             <li>'.implode('</li>
00434                             <li>',$tocArray[$tocKey]).'</li>
00435                         </ul>
00436                     </li>';
00437             }
00438         }
00439 
00440             // Compile TOC:
00441         $output = '
00442 
00443             <!-- TOC: -->
00444             <div class="c-toc">
00445                 <ul>
00446                 '.$output.'
00447                 </ul>
00448             </div>';
00449 
00450         return $output;
00451     }
00452 
00453     /**
00454      * Render CSH for a full cshKey/table
00455      *
00456      * @param string $key Full CSH key (may be different from table name)
00457      * @param string $table CSH key / table name
00458      * @return string HTML output
00459      */
00460     function render_Table($key, $table) {
00461         global $BE_USER,$TCA_DESCR,$TCA,$LANG;
00462 
00463         $output = '';
00464 
00465             // Load table TCA
00466         t3lib_div::loadTCA($key);
00467 
00468             // Load descriptions for table $table
00469         $LANG->loadSingleTableDescription($key);
00470 
00471         if (is_array($TCA_DESCR[$key]['columns']) && (!$this->limitAccess || $BE_USER->check('tables_select', $table))) {
00472                 // Initialize variables:
00473             $parts = array();
00474             $parts[0] = ''; // Reserved for header of table
00475 
00476                 // Traverse table columns as listed in TCA_DESCR
00477             foreach ($TCA_DESCR[$key]['columns'] as $field => $_) {
00478 
00479                 $fieldValue = isset($TCA[$key]) && strcmp($field, '') ? $TCA[$key]['columns'][$field] : array();
00480 
00481                 if (is_array($fieldValue) && (!$this->limitAccess || !$fieldValue['exclude'] || $BE_USER->check('non_exclude_fields', $table . ':' . $field))) {
00482                     if (!$field)    {
00483                         $parts[0] = $this->printItem($key, '', 1);  // Header
00484                     } else {
00485                         $parts[] = $this->printItem($key, $field, 1);   // Field
00486                     }
00487                 }
00488             }
00489 
00490             if (!$parts[0]) {
00491                 unset($parts[0]);
00492             }
00493             $output .= implode('<br />', $parts);
00494         }
00495 
00496             // Substitute glossary words:
00497         $output = $this->substituteGlossaryWords($output);
00498 
00499             // TOC link:
00500         if (!$this->renderALL) {
00501             $tocLink = '<p class="c-nav"><a href="view_help.php">' . $LANG->getLL('goToToc', 1) . '</a></p>';
00502 
00503             $output =
00504                 $tocLink.'
00505                 <br/>'.
00506                 $output.'
00507                 <br />'.
00508                 $tocLink;
00509         }
00510 
00511         return $output;
00512     }
00513 
00514     /**
00515      * Renders CSH for a single field.
00516      *
00517      * @param string $key CSH key / table name
00518      * @param string $field Sub key / field name
00519      * @return string HTML output
00520      */
00521     function render_Single($key, $field) {
00522         global $LANG, $TCA;
00523 
00524         $output = '';
00525 
00526             // Load the description field
00527         $LANG->loadSingleTableDescription($key);
00528 
00529             // Render single item
00530         $output.= $this->printItem($key, $field);
00531 
00532             // Substitute glossary words:
00533         $output = $this->substituteGlossaryWords($output);
00534 
00535             // Link to Full table description and TOC:
00536         $getLLKey = $this->limitAccess ? 'fullDescription' : 'fullDescription_module';
00537         $output.= '<br />
00538             <p class="c-nav"><a href="view_help.php?tfID=' . rawurlencode($key . '.*') . '">' . $LANG->getLL($getLLKey, 1) . '</a></p>
00539             <p class="c-nav"><a href="view_help.php">' . $LANG->getLL('goToToc', 1) . '</a></p>';
00540 
00541         return $output;
00542     }
00543 
00544 
00545     /**
00546      * Renders CSH for a single field.
00547      *
00548      * @param   string      CSH key / table name
00549      * @param   string      Sub key / field name
00550      * @return  string      HTML output
00551      * @deprecated since TYPO3 4.5, this function will be removed in TYPO3 4.7. Use render_Single() instead.
00552      */
00553     function render_SingleFlex() {
00554         t3lib_div::logDeprecatedFunction();
00555         $output = '';
00556 
00557             // Render
00558         $output.= $this->printItemFlex();
00559 
00560             // Substitute glossary words:
00561         return $this->substituteGlossaryWords($output);
00562     }
00563 
00564 
00565     /************************************
00566      *
00567      * Rendering CSH items
00568      *
00569      ************************************/
00570 
00571     /**
00572      * Make seeAlso links from $value
00573      *
00574      * @param   string      See-also input codes
00575      * @param   string      If $anchorTable is set to a tablename, then references to this table will be made as anchors, not URLs.
00576      * @return  string      See-also links HTML
00577      */
00578     function make_seeAlso($value,$anchorTable='')   {
00579         global $TCA,$BE_USER,$TCA_DESCR;
00580 
00581             // Split references by comma or linebreak
00582         $items = preg_split('/[,' . LF . ']/', $value);
00583         $lines = array();
00584 
00585         foreach($items as $val) {
00586             $val = trim($val);
00587             if ($val)   {
00588                 $iP = explode(':',$val);
00589                 $iPUrl = t3lib_div::trimExplode('|',$val);
00590                     // URL reference:
00591                 if (substr($iPUrl[1],0,4)=='http')  {
00592                     $lines[] = '<a href="'.htmlspecialchars($iPUrl[1]).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>';
00593                 } elseif (substr($iPUrl[1],0,5)=='FILE:')   {
00594                     $fileName = t3lib_div::getFileAbsFileName(substr($iPUrl[1],5),1,1);
00595                     if ($fileName && @is_file($fileName))   {
00596                         $fileName = '../'.substr($fileName,strlen(PATH_site));
00597                         $lines[] = '<a href="'.htmlspecialchars($fileName).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>';
00598                     }
00599                 } else {
00600                     // "table" reference
00601                     t3lib_div::loadTCA($iP[0]);
00602 
00603                     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:
00604 
00605                             // Load table descriptions:
00606                         #$LANG->loadSingleTableDescription($iP[0]);
00607                         if (isset($TCA_DESCR[$iP[0]]))  {
00608                                 // Make see-also link:
00609                             $href = ($this->renderALL || ($anchorTable && $iP[0]==$anchorTable) ? '#'.implode('.',$iP) : 'view_help.php?tfID='.rawurlencode(implode('.',$iP)).'&back='.$this->tfID);
00610                             $label = $this->getTableFieldLabel($iP[0],$iP[1],' / ');
00611                             $lines[] = '<a href="'.htmlspecialchars($href).'">'.htmlspecialchars($label).'</a>';
00612                         }
00613                     }
00614                 }
00615             }
00616         }
00617         return implode('<br />',$lines);
00618     }
00619 
00620     /**
00621      * Will return an image tag with description in italics.
00622      *
00623      * @param   string      Image file reference (list of)
00624      * @param   string      Description string (divided for each image by line break)
00625      * @return  string      Image HTML codes
00626      */
00627     function printImage($images,$descr) {
00628         $code = '';
00629             // Splitting:
00630         $imgArray = t3lib_div::trimExplode(',', $images, 1);
00631         if (count($imgArray))   {
00632             $descrArray = explode(LF,$descr,count($imgArray));
00633 
00634             foreach($imgArray as $k => $image)  {
00635                 $descr = $descrArray[$k];
00636 
00637                 $absImagePath = t3lib_div::getFileAbsFileName($image,1,1);
00638                 if ($absImagePath && @is_file($absImagePath))   {
00639                     $imgFile = substr($absImagePath,strlen(PATH_site));
00640                     $imgInfo = @getimagesize($absImagePath);
00641                     if (is_array($imgInfo)) {
00642                         $imgFile = '../'.$imgFile;
00643                         $code.= '<br /><img src="'.$imgFile.'" '.$imgInfo[3].' class="c-inlineimg" alt="" /><br />
00644                         ';
00645                         $code.= '<p><em>'.$GLOBALS['LANG']->hscAndCharConv($descr,1).'</em></p>
00646                         ';
00647                     } else $code.= '<div style="background-color: red; border: 1px solid black; color: white;">NOT AN IMAGE: '.$imgFile.'</div>';
00648                 } else $code.= '<div style="background-color: red; border: 1px solid black; color: white;">IMAGE FILE NOT FOUND: '.$image.'</div>';
00649             }
00650         }
00651 
00652         return $code;
00653     }
00654 
00655     /**
00656      * Returns header HTML content
00657      *
00658      * @param   string      Header text
00659      * @param   string      Header type (1, 0)
00660      * @return  string      The HTML for the header.
00661      */
00662     function headerLine($str,$type=0)   {
00663         switch($type)   {
00664             case 1:
00665                 $str = '<h2 class="t3-row-header">' . htmlspecialchars($str) . '</h2>
00666                 ';
00667             break;
00668             case 0:
00669                 $str = '<h3 class="divider">' . htmlspecialchars($str) . '</h3>
00670                 ';
00671             break;
00672         }
00673 
00674         return $str;
00675     }
00676 
00677     /**
00678      * Returns prepared content
00679      *
00680      * @param   string      Content to format.
00681      * @return  string      Formatted content.
00682      */
00683     function prepareContent($str)   {
00684         $str = $GLOBALS['LANG']->hscAndCharConv($str,0);
00685         return '<p>'.nl2br(trim(strip_tags($str,$this->allowedHTML))).'</p>
00686         ';
00687     }
00688 
00689     /**
00690      * Prints a single $table/$field information piece
00691      * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
00692      *
00693      * @param string $key CSH key / table name
00694      * @param string $field Sub key / field name
00695      * @param boolean $anchors If anchors is to be shown.
00696      * @return string HTML content
00697      */
00698     function printItem($key, $field, $anchors = FALSE) {
00699         global $TCA_DESCR, $LANG, $TCA, $BE_USER;
00700         $out = '';
00701 
00702             // Load full table definition in $TCA
00703         t3lib_div::loadTCA($key);
00704 
00705         if ($key && (!$field || is_array($TCA_DESCR[$key]['columns'][$field]))) {
00706                 // Make seeAlso references.
00707             $seeAlsoRes = $this->make_seeAlso($TCA_DESCR[$key]['columns'][$field]['seeAlso'], $anchors ? $key : '');
00708 
00709                 // Making item:
00710             $out = '<a name="' . $key . '.' . $field . '"></a>' .
00711                     $this->headerLine($this->getTableFieldLabel($key, $field), 1) .
00712                     $this->prepareContent($TCA_DESCR[$key]['columns'][$field]['description']) .
00713                     ($TCA_DESCR[$key]['columns'][$field]['details'] ? $this->headerLine($LANG->getLL('details').':').$this->prepareContent($TCA_DESCR[$key]['columns'][$field]['details']) : '') .
00714                     ($TCA_DESCR[$key]['columns'][$field]['syntax'] ? $this->headerLine($LANG->getLL('syntax').':').$this->prepareContent($TCA_DESCR[$key]['columns'][$field]['syntax']) : '') .
00715                     ($TCA_DESCR[$key]['columns'][$field]['image'] ? $this->printImage($TCA_DESCR[$key]['columns'][$field]['image'],$TCA_DESCR[$key]['columns'][$field]['image_descr']) : '') .
00716                     ($TCA_DESCR[$key]['columns'][$field]['seeAlso'] && $seeAlsoRes ? $this->headerLine($LANG->getLL('seeAlso').':').'<p>'.$seeAlsoRes.'</p>' : '') .
00717                     ($this->back ? '<br /><p><a href="' . htmlspecialchars('view_help.php?tfID=' . rawurlencode($this->back)) . '" class="typo3-goBack">' . htmlspecialchars($LANG->getLL('goBack')) . '</a></p>' : '') .
00718                     '<br />';
00719         }
00720         return $out;
00721     }
00722 
00723     /**
00724      * Prints a single $table/$field information piece
00725      * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
00726      *
00727      * @param   string      Table name
00728      * @param   string      Field name
00729      * @param   boolean     If anchors is to be shown.
00730      * @return  string      HTML content
00731      * @deprecated since TYPO3 4.5, this function will be removed in TYPO3 4.7. Use printItem() instead.
00732      */
00733     function printItemFlex() {
00734         t3lib_div::logDeprecatedFunction();
00735         // Get all texts
00736         foreach (explode(',', 'description,details,syntax,image,image_descr,seeAlso') as $var) {
00737             // Double $ below is not a error!
00738             $$var = $GLOBALS['LANG']->sL($this->ffID['cshFile'] . ':' . $this->ffID['field'] . '.' . $var);
00739         }
00740         // Make seeAlso references.
00741         $seeAlsoRes = $this->make_seeAlso($seeAlso);
00742 
00743             // Making item:
00744         $out= $this->headerLine($this->ffID['title'], 1) .
00745                 $this->prepareContent($description) .
00746                 ($details ? $this->headerLine($GLOBALS['LANG']->getLL('details').':') . $this->prepareContent($details) : '') .
00747                 ($syntax ? $this->headerLine($GLOBALS['LANG']->getLL('syntax').':') . $this->prepareContent($syntax) : '') .
00748                 ($image ? $this->printImage($image, $image_descr) : '') .
00749                 ($seeAlso && $seeAlsoRes ? $this->headerLine($GLOBALS['LANG']->getLL('seeAlso').':').'<p>'.$seeAlsoRes.'</p>' : '') .
00750         '<br />';
00751         return $out;
00752     }
00753 
00754     /**
00755      * Returns labels for a given field in a given structure
00756      *
00757      * @param string $key CSH key / table name
00758      * @param string $field Sub key / field name
00759      * @return array Table and field labels in a numeric array
00760      */
00761     function getTableFieldNames($key, $field) {
00762         global $TCA, $TCA_DESCR, $LANG;
00763 
00764         $LANG->loadSingleTableDescription($key);
00765 
00766             // Define the label for the key
00767         $keyName = $key;
00768         if (is_array($TCA_DESCR[$key]['columns']['']) && isset($TCA_DESCR[$key]['columns']['']['alttitle'])) {
00769                 // If there's an alternative title, use it
00770             $keyName = $TCA_DESCR[$key]['columns']['']['alttitle'];
00771         } elseif (isset($TCA[$key])) {
00772                 // Otherwise, if it's a table, use its title
00773             $keyName = $TCA[$key]['ctrl']['title'];
00774         } else {
00775                 // If no title was found, make sure to remove any "_MOD_"
00776             $keyName = preg_replace('/^_MOD_/', '', $key);
00777         }
00778             // Define the label for the field
00779         $fieldName = $field;
00780         if (is_array($TCA_DESCR[$key]['columns'][$field]) && isset($TCA_DESCR[$key]['columns'][$field]['alttitle'])) {
00781                 // If there's an alternative title, use it
00782             $fieldName = $TCA_DESCR[$key]['columns'][$field]['alttitle'];
00783         } elseif (isset($TCA[$key])&&isset($TCA[$key]['columns'][$field])) {
00784                 // Otherwise, if it's a table, use its title
00785             $fieldName = $TCA[$key]['columns'][$field]['label'];
00786         }
00787         return array($keyName, $fieldName);
00788     }
00789 
00790     /**
00791      * Returns composite label for table/field
00792      *
00793      * @param string $key CSH key / table name
00794      * @param string $field Sub key / field name
00795      * @param string $mergeToken Token to merge the two strings with
00796      * @return string Labels joined with merge token
00797      * @see getTableFieldNames()
00798      */
00799     function getTableFieldLabel($key, $field = '', $mergeToken = ': ') {
00800         global $LANG;
00801         $tableName = '';
00802         $fieldName = '';
00803 
00804             // Get table / field parts:
00805         list($tableName, $fieldName) = $this->getTableFieldNames($key, $field);
00806 
00807             // Create label:
00808         $labelString = $LANG->sL($tableName) .
00809                     ($field ? $mergeToken . rtrim(trim($LANG->sL($fieldName)), ':') : '');
00810 
00811         return $labelString;
00812     }
00813 
00814 
00815 
00816 
00817 
00818 
00819 
00820 
00821 
00822 
00823 
00824     /******************************
00825      *
00826      * Glossary related
00827      *
00828      ******************************/
00829 
00830     /**
00831      * Creates glossary index in $this->glossaryWords
00832      * Glossary is cached in cache_hash cache and so will be updated only when cache is cleared.
00833      *
00834      * @return  void
00835      */
00836     function createGlossaryIndex()  {
00837         global $TCA_DESCR,$TCA,$LANG;
00838 
00839             // Create hash string and try to retrieve glossary array:
00840         $hash = md5('typo3/view_help.php:glossary');
00841         list($this->glossaryWords,$this->substWords) = unserialize(t3lib_BEfunc::getHash($hash));
00842 
00843             // Generate glossary words if not found:
00844         if (!is_array($this->glossaryWords)) {
00845 
00846                 // Initialize:
00847             $this->glossaryWords = array();
00848             $this->substWords = array();
00849             $CSHkeys = array_flip(array_keys($TCA_DESCR));
00850 
00851                 // Glossary
00852             foreach($CSHkeys as $cshKey => $value)  {
00853                 if (t3lib_div::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($TCA[$cshKey]))    {
00854                     $LANG->loadSingleTableDescription($cshKey);
00855 
00856                     if (is_array($TCA_DESCR[$cshKey]['columns']))   {
00857 
00858                             // Traverse table columns as listed in TCA_DESCR
00859                         foreach ($TCA_DESCR[$cshKey]['columns'] as $field => $data) {
00860                             if ($field) {
00861                                 $this->glossaryWords[$cshKey.'.'.$field] = array(
00862                                     'title' => trim($data['alttitle'] ? $data['alttitle'] : $cshKey),
00863                                     'description' =>  str_replace('%22','%23%23%23', rawurlencode($data['description'])),
00864                                 );
00865                             }
00866                         }
00867                     }
00868                 }
00869             }
00870 
00871                 // First, create unique list of words:
00872             foreach($this->glossaryWords as $key => $value) {
00873                 $word = strtolower($value['title']);    // Making word lowercase in order to filter out same words in different cases.
00874 
00875                 if ($word!=='') {
00876                     $this->substWords[$word] = $value;
00877                     $this->substWords[$word]['key'] = $key;
00878                 }
00879             }
00880 
00881             krsort($this->substWords);
00882 
00883             t3lib_BEfunc::storeHash($hash,serialize(array($this->glossaryWords,$this->substWords)),'Glossary');
00884         }
00885     }
00886 
00887     /**
00888      * Processing of all non-HTML content in the output
00889      * Will be done by a call-back to ->substituteGlossaryWords_htmlcleaner_callback()
00890      *
00891      * @param   string      Input HTML code
00892      * @return  string      Output HTML code
00893      */
00894     function substituteGlossaryWords($code) {
00895         $htmlParser = t3lib_div::makeInstance('local_t3lib_parsehtml');
00896         $htmlParser->pObj = $this;
00897         $code = $htmlParser->HTMLcleaner($code, array(), 1);
00898 
00899         return $code;
00900     }
00901 
00902     /**
00903      * Substituting glossary words in the CSH
00904      * (This is a call-back function from "class local_t3lib_parsehtml extends t3lib_parsehtml", see top of this script)
00905      *
00906      * @param   string      Input HTML string
00907      * @return  string      HTML with substituted words in.
00908      * @coauthor    alex widschwendter, media.res kommunikationsloesungen
00909      */
00910     function substituteGlossaryWords_htmlcleaner_callback($code)    {
00911         if (is_array($this->substWords) && count($this->substWords) && strlen(trim($code))) {
00912 
00913                 // Substitute words:
00914             foreach($this->substWords as $wordKey => $wordSet)  {
00915                     // quoteMeta used so special chars (which should not occur though) in words will not break the regex. Seemed to work (- kasper)
00916                 $parts = preg_split('/( |[\(])('.quoteMeta($wordSet['title']).')([\.\!\)\?\:\,]+| )/i', ' '.$code.' ', 2, PREG_SPLIT_DELIM_CAPTURE);
00917                 if (count($parts) == 5) {
00918                     $parts[2] = '<a class="glossary-term" href="'.htmlspecialchars('view_help.php?tfID='.rawurlencode($wordSet['key']).'&back='.$this->tfID).'" title="'.rawurlencode(htmlspecialchars(t3lib_div::fixed_lgd_cs(rawurldecode($wordSet['description']),80))).'">'.
00919                                 htmlspecialchars($parts[2]).
00920                                 '</a>';
00921                     $code = substr(implode('',$parts),1,-1);
00922 
00923                         // Disable entry so it doesn't get used next time:
00924                     unset($this->substWords[$wordKey]);
00925                 }
00926             }
00927             $code = str_replace('###', '&quot;',rawurldecode($code));
00928         }
00929 
00930         return $code;
00931     }
00932 
00933 }
00934 
00935 
00936 
00937 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/view_help.php'])) {
00938     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/view_help.php']);
00939 }
00940 
00941 
00942 
00943 // Make instance:
00944 $SOBE = t3lib_div::makeInstance('SC_view_help');
00945 $SOBE->init();
00946 $SOBE->main();
00947 $SOBE->printContent();
00948 
00949 ?>