2 /***************************************************************
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Document for viewing the online help texts, also known as TCA_DESCR.
29 * See Inside TYPO3 for details.
32 * Revised for TYPO3 3.7 5/2004 by Kasper Skaarhoj
33 * XHTML-trans compliant
35 * @author Kasper Skaarhoj <kasper@typo3.com>
38 * [CLASS/FUNCTION INDEX of SCRIPT]
42 * 87: class SC_view_help
43 * 110: function init()
44 * 130: function main()
45 * 158: function printContent()
47 * SECTION: Rendering main modes
48 * 181: function render_TOC()
49 * 280: function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys)
50 * 311: function render_TOC_makeTocList($tocArray)
51 * 346: function render_Table($table)
52 * 391: function render_Single($table,$field)
54 * SECTION: Rendering CSH items
55 * 433: function make_seeAlso($value,$anchorTable='')
56 * 471: function printImage($image,$descr)
57 * 493: function headerLine($str,$type=0)
58 * 514: function prepareContent($str)
59 * 529: function printItem($table,$field,$anchors=0)
60 * 565: function getTableFieldNames($table,$field)
63 * (This index is automatically created/updated by the extension "extdeveval")
68 require('template.php');
69 $LANG->includeLLFile('EXT:lang/locallang_view_help.xml');
70 require_once(PATH_t3lib
.'class.t3lib_loadmodules.php');
81 * 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.
83 * @author Kasper Skaarhoj <kasper@typo3.com>
88 var $allowedHTML = '<strong><em><b><i>';
90 // For these vars, see init()
91 var $limitAccess; // If set access to fields and tables is checked. Should be done for true database tables.
92 var $table; // The "table" key
93 var $field; // The "field" key
95 // Internal, static: GPvar:
96 var $tfID; // Table/FIeld id.
97 var $back; // Back (previous tfID)
98 var $renderALL; // If set, then in TOC mode the FULL manual will be printed as well!
100 // Internal, dynamic:
101 var $content; // Content accumulation.
106 * Initialize the class for various input etc.
114 $this->tfID
= t3lib_div
::_GP('tfID');
115 $this->back
= t3lib_div
::_GP('back');
116 $this->renderALL
= t3lib_div
::_GP('renderALL');
118 // Set internal table/field to the parts of "tfID" incoming var.
119 list($this->table
,$this->field
) = explode('.',$this->tfID
);
121 // limitAccess is checked if the $this->table really IS a table.
122 $this->limitAccess
= isset($TCA[$this->table
]) ? TRUE
: FALSE
;
126 * Main function, rendering the display
131 global $BE_USER,$LANG,$TCA_DESCR,$TCA,$TBE_TEMPLATE;
133 // Start HTML output accumulation:
134 $TBE_TEMPLATE->docType
= 'xhtml_trans';
135 $TBE_TEMPLATE->divClass
= 'typo3-view-help';
136 $this->content
.= $TBE_TEMPLATE->startPage($LANG->getLL('title'));
138 if ($this->field
=='*') { // If ALL fields is supposed to be shown:
139 $this->content
.= $this->render_Table($this->table
);
140 } elseif ($this->tfID
) { // ... otherwise show only single field:
141 $this->content
.= $this->render_Single($this->table
,$this->field
);
142 } else { // Render Table Of Contents if nothing else:
143 $this->content
.= $this->render_TOC();
146 // Print close-button:
147 # $this->content.='<br /><form action=""><input type="submit" value="'.htmlspecialchars($LANG->getLL('close')).'" onclick="self.close(); return false;" /></form><br/>';
150 $this->content
.= '<br/>';
151 $this->content
.= $TBE_TEMPLATE->endPage();
155 * Outputting the accumulated content to screen
159 function printContent() {
171 /************************************
173 * Rendering main modes
175 ************************************/
178 * Creates Table Of Contents and possibly "Full Manual" mode if selected.
180 * @return string HTML content
182 function render_TOC() {
183 global $TCA_DESCR,$TCA,$LANG,$BE_USER,$TBE_MODULES;
186 $CSHkeys = array_flip(array_keys($TCA_DESCR));
187 $TCAkeys = array_keys($TCA);
189 $outputSections = array();
193 // TYPO3 Core Features:
194 $LANG->loadSingleTableDescription('xMOD_csh_corebe');
195 $this->render_TOC_el('xMOD_csh_corebe', 'core', $outputSections, $tocArray, $CSHkeys);
198 $loadModules = t3lib_div
::makeInstance('t3lib_loadModules');
199 $loadModules->load($TBE_MODULES);
200 foreach($loadModules->modules
as $mainMod => $info) {
201 $cshKey = '_MOD_'.$mainMod;
202 if ($CSHkeys[$cshKey]) {
203 $LANG->loadSingleTableDescription($cshKey);
204 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
207 if (is_array($info['sub'])) {
208 foreach($info['sub'] as $subMod => $subInfo) {
209 $cshKey = '_MOD_'.$mainMod.'_'.$subMod;
210 if ($CSHkeys[$cshKey]) {
211 $LANG->loadSingleTableDescription($cshKey);
212 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
219 foreach($TCAkeys as $table) {
220 // Load descriptions for table $table
221 $LANG->loadSingleTableDescription($table);
222 if (is_array($TCA_DESCR[$table]['columns']) && $BE_USER->check('tables_select',$table)) {
223 $this->render_TOC_el($table, 'tables', $outputSections, $tocArray, $CSHkeys);
228 foreach($CSHkeys as $cshKey => $value) {
229 if (t3lib_div
::isFirstPartOfStr($cshKey, 'xEXT_') && !isset($TCA[$cshKey])) {
230 $LANG->loadSingleTableDescription($cshKey);
231 $this->render_TOC_el($cshKey, 'extensions', $outputSections, $tocArray, $CSHkeys);
236 foreach($CSHkeys as $cshKey => $value) {
237 if (!t3lib_div
::isFirstPartOfStr($cshKey, '_MOD_') && !isset($TCA[$cshKey])) {
238 $LANG->loadSingleTableDescription($cshKey);
239 $this->render_TOC_el($cshKey, 'other', $outputSections, $tocArray, $CSHkeys);
248 <h1>'.$LANG->getLL('manual_title',1).'</h1>
249 <p>'.t3lib_BEfunc
::TYPO3_copyRightNotice().'</p>';
253 <h1>'.$LANG->getLL('introduction',1).'</h1>
254 <p>'.$LANG->getLL('description',1).'</p>';
258 <h1>'.$LANG->getLL('TOC',1).'</h1>'.
259 $this->render_TOC_makeTocList($tocArray);
261 if (!$this->renderALL
) {
264 <p class="c-nav"><a href="view_help.php?renderALL=1">'.$LANG->getLL('full_manual',1).'</a></p>';
267 if ($this->renderALL
) {
270 <h1>'.$LANG->getLL('full_manual_chapters',1).'</h1>'.
274 <!-- NEW SECTION: -->
282 * Creates a TOC list element and renders corresponding HELP content if "renderALL" mode is set.
284 * @param string CSH key / Table name
285 * @param string TOC category keyword: "core", "modules", "tables", "other"
286 * @param array Array for accumulation of rendered HELP Content (in "renderALL" mode). Passed by reference!
287 * @param array TOC array; Here TOC index elements are created. Passed by reference!
288 * @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!
291 function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys) {
294 if ($this->renderALL
) { // Render full manual right here!
295 $outputSections[$table] = $this->render_Table($table);
297 if ($outputSections[$table]) {
298 $outputSections[$table] = '
300 <!-- New CSHkey/Table: '.$table.' -->
301 <p class="c-nav"><a name="ANCHOR_'.$table.'" href="#">'.$LANG->getLL('to_top',1).'</a></p>
302 <h2>'.$this->getTableFieldLabel($table).'</h2>
304 '.$outputSections[$table];
305 $tocArray[$tocCat][$table] = '<a href="#ANCHOR_'.$table.'">'.$this->getTableFieldLabel($table).'</a>';
307 unset($outputSections[$table]);
309 } else { // Only TOC:
310 $tocArray[$tocCat][$table] = '<p><a href="view_help.php?tfID='.rawurlencode($table.'.*').'">'.$this->getTableFieldLabel($table).'</a></p>';
314 unset($CSHkeys[$table]);
318 * Renders the TOC index as a HTML bullet list from TOC array
320 * @param array ToC Array.
321 * @return string HTML bullet list for index.
323 function render_TOC_makeTocList($tocArray) {
326 // The Various manual sections:
327 $keys = explode(',', 'core,modules,tables,extensions,other');
329 // Create TOC bullet list:
331 foreach($keys as $tocKey) {
332 if (is_array($tocArray[$tocKey])) {
334 <li>'.$LANG->getLL('TOC_'.$tocKey,1).'
337 <li>',$tocArray[$tocKey]).'</li>
357 * Render CSH for a full cshKey/table
359 * @param string CSH key / table name
360 * @return string HTML output
362 function render_Table($table) {
363 global $BE_USER,$TCA_DESCR,$TCA,$LANG;
368 t3lib_div
::loadTCA($table);
370 // Load descriptions for table $table
371 $LANG->loadSingleTableDescription($table);
373 if (is_array($TCA_DESCR[$table]['columns']) && (!$this->limitAccess ||
$BE_USER->check('tables_select',$table))) {
374 // Initialize variables:
376 $parts[0] = ''; // Reserved for header of table
378 // Traverse table columns as listed in TCA_DESCR
379 reset($TCA_DESCR[$table]['columns']);
380 while(list($field) = each($TCA_DESCR[$table]['columns'])) {
382 $fieldValue = isset($TCA[$table]) && strcmp($field,'') ?
$TCA[$table]['columns'][$field] : array();
384 if (is_array($fieldValue) && (!$this->limitAccess ||
!$fieldValue['exclude'] ||
$BE_USER->check('non_exclude_fields',$table.':'.$field))) {
386 $parts[0] = $this->printItem($table,'',1); // Header
388 $parts[] = $this->printItem($table,$field,1); // Field
393 if (!strcmp($parts,'')) unset($parts[0]);
394 $output.= implode('<br />',$parts);
398 if (!$this->renderALL
) {
399 $tocLink = '<p class="c-nav"><a href="view_help.php">'.$LANG->getLL('goToToc',1).'</a></p>';
413 * Renders CSH for a single field.
415 * @param string CSH key / table name
416 * @param string Sub key / field name
417 * @return string HTML output
419 function render_Single($table,$field) {
424 // Load descriptions for table $table
425 $LANG->loadSingleTableDescription($table);
427 // Render single item:
428 $output.= $this->printItem($table,$field);
430 // Link to Full table description and TOC:
431 $getLLKey = $this->limitAccess ?
'fullDescription' : 'fullDescription_module';
433 <p class="c-nav"><a href="view_help.php?tfID='.rawurlencode($table.'.*').'">'.$LANG->getLL($getLLKey,1).'</a></p>
434 <p class="c-nav"><a href="view_help.php">'.$LANG->getLL('goToToc',1).'</a></p>';
449 /************************************
451 * Rendering CSH items
453 ************************************/
456 * Make seeAlso links from $value
458 * @param string See-also input codes
459 * @param string If $anchorTable is set to a tablename, then references to this table will be made as anchors, not URLs.
460 * @return string See-also links HTML
462 function make_seeAlso($value,$anchorTable='') {
463 global $TCA,$BE_USER,$TCA_DESCR;
465 // Split references by comma, vert.line or linebreak
466 $items = split(',|'.chr(10),$value);
469 foreach($items as $val) {
472 $iP = explode(':',$val);
473 $iPUrl = t3lib_div
::trimExplode('|',$val);
475 if (substr($iPUrl[1],0,4)=='http') {
476 $lines[] = '<a href="'.htmlspecialchars($iPUrl[1]).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>';
477 } elseif (substr($iPUrl[1],0,5)=='FILE:') {
478 $fileName = t3lib_div
::getFileAbsFileName(substr($iPUrl[1],5),1,1);
479 if ($fileName && @is_file
($fileName)) {
480 $fileName = '../'.substr($fileName,strlen(PATH_site
));
481 $lines[] = '<a href="'.htmlspecialchars($fileName).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>';
485 t3lib_div
::loadTCA($iP[0]);
487 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:
489 // Load table descriptions:
490 #$LANG->loadSingleTableDescription($iP[0]);
491 if (isset($TCA_DESCR[$iP[0]])) {
492 // Make see-also link:
493 $href = ($this->renderALL ||
($anchorTable && $iP[0]==$anchorTable) ?
'#'.implode('.',$iP) : 'view_help.php?tfID='.rawurlencode(implode('.',$iP)).'&back='.$this->tfID
);
494 $label = $this->getTableFieldLabel($iP[0],$iP[1],' / ');
495 $lines[] = '<a href="'.htmlspecialchars($href).'">'.htmlspecialchars($label).'</a>';
501 return implode('<br />',$lines);
505 * Will return an image tag with description in italics.
507 * @param string Image file reference (list of)
508 * @param string Description string (divided for each image by line break)
509 * @return string Image HTML codes
511 function printImage($images,$descr) {
514 $imgArray = t3lib_div
::trimExplode(',', $images, 1);
515 if (count($imgArray)) {
516 $descrArray = explode(chr(10),$descr,count($imgArray));
518 foreach($imgArray as $k => $image) {
519 $descr = $descrArray[$k];
521 $absImagePath = t3lib_div
::getFileAbsFileName($image,1,1);
522 if ($absImagePath && @is_file
($absImagePath)) {
523 $imgFile = substr($absImagePath,strlen(PATH_site
));
524 $imgInfo = @getimagesize
($absImagePath);
525 if (is_array($imgInfo)) {
526 $imgFile = '../'.$imgFile;
527 $code.= '<br /><img src="'.$imgFile.'" '.$imgInfo[3].' class="c-inlineimg" alt="" /><br />
529 $code.= '<p><em>'.$GLOBALS['LANG']->hscAndCharConv($descr,0).'</em></p>
531 } else $code.= '<div style="background-color: red; border: 1px solid black; color: white;">NOT AN IMAGE: '.$imgFile.'</div>';
532 } else $code.= '<div style="background-color: red; border: 1px solid black; color: white;">IMAGE FILE NOT FOUND: '.$image.'</div>';
540 * Returns header HTML content
542 * @param string Header text
543 * @param string Header type (1, 0)
544 * @return string The HTML for the header.
546 function headerLine($str,$type=0) {
549 $str='<h3>'.htmlspecialchars($str).'</h3>
553 $str='<h4 class="uppercase">'.htmlspecialchars($str).'</h4>
562 * Returns prepared content
564 * @param string Content to format.
565 * @return string Formatted content.
567 function prepareContent($str) {
568 $str = $GLOBALS['LANG']->hscAndCharConv($str,0);
569 return '<p>'.nl2br(trim(strip_tags($str,$this->allowedHTML
))).'</p>
574 * Prints a single $table/$field information piece
575 * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
577 * @param string Table name
578 * @param string Field name
579 * @param boolean If anchors is to be shown.
580 * @return string HTML content
582 function printItem($table,$field,$anchors=0) {
583 global $TCA_DESCR, $LANG, $TCA, $BE_USER;
585 // Load full table definition in $TCA
586 t3lib_div
::loadTCA($table);
588 if ($table && (!$field ||
is_array($TCA_DESCR[$table]['columns'][$field]))) {
589 // Make seeAlso references.
590 $seeAlsoRes = $this->make_seeAlso($TCA_DESCR[$table]['columns'][$field]['seeAlso'],$anchors?
$table:'');
593 $out= '<a name="'.$table.'.'.$field.'"></a>
595 $this->headerLine($this->getTableFieldLabel($table,$field),1).
596 $this->prepareContent($TCA_DESCR[$table]['columns'][$field]['description']).
597 ($TCA_DESCR[$table]['columns'][$field]['details'] ?
$this->headerLine($LANG->getLL('details').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['details']) : '').
598 ($TCA_DESCR[$table]['columns'][$field]['syntax'] ?
$this->headerLine($LANG->getLL('syntax').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['syntax']) : '').
599 ($TCA_DESCR[$table]['columns'][$field]['image'] ?
$this->printImage($TCA_DESCR[$table]['columns'][$field]['image'],$TCA_DESCR[$table]['columns'][$field]['image_descr']) : '').
600 ($TCA_DESCR[$table]['columns'][$field]['seeAlso'] && $seeAlsoRes ?
$this->headerLine($LANG->getLL('seeAlso').':').'<p>'.$seeAlsoRes.'</p>' : '').
601 ($this->back ?
'<br /><p><a href="'.htmlspecialchars('view_help.php?tfID='.rawurlencode($this->back
)).'" class="typo3-goBack">'.htmlspecialchars($LANG->getLL('goBack')).'</a></p>' : '').
608 * Returns labels for $table and $field.
609 * If $table is "_MOD_" prefixed, the part after "_MOD_" is returned (non-tables, fx. modules)
611 * @param string Table name
612 * @param string Field name
613 * @return array Table and field labels in a numeric array
615 function getTableFieldNames($table,$field) {
616 global $TCA, $TCA_DESCR, $LANG;
618 $LANG->loadSingleTableDescription($table);
620 $tableName = is_array($TCA_DESCR[$table]['columns']['']) && $TCA_DESCR[$table]['columns']['']['alttitle'] ?
621 $TCA_DESCR[$table]['columns']['']['alttitle'] :
622 (isset($TCA[$table]) ?
$TCA[$table]['ctrl']['title'] : ereg_replace('^_MOD_','',$table));
623 $fieldName = is_array($TCA_DESCR[$table]['columns'][$field]) && $TCA_DESCR[$table]['columns'][$field]['alttitle'] ?
624 $TCA_DESCR[$table]['columns'][$field]['alttitle'] :
625 (isset($TCA[$table])&&isset($TCA[$table]['columns'][$field]) ?
$TCA[$table]['columns'][$field]['label'] : $field);
626 return array($tableName,$fieldName);
630 * Returns composite label for table/field
632 * @param string Table name
633 * @param string Field name
634 * @param string Token to merge the two strings with.
635 * @return array Table and field labels in a numeric array
636 * @see getTableFieldNames()
638 function getTableFieldLabel($table,$field='',$mergeToken=': ') {
641 // Get table / field parts:
642 list($tableName,$fieldName) = $this->getTableFieldNames($table,$field);
645 $labelStr = $LANG->sL($tableName).
646 ($field ?
$mergeToken.ereg_replace(':$','', trim($LANG->sL($fieldName))):'');
653 // Include extension?
654 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/view_help.php']) {
655 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/view_help.php']);
664 $SOBE = t3lib_div
::makeInstance('SC_view_help');
667 $SOBE->printContent();