Follow-up to #17670: Add typo3/template.php getDynTabMenuJScode() again and remove...
[Packages/TYPO3.CMS.git] / typo3 / view_help.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
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.
13 *
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.
18 *
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Document for viewing the online help texts, also known as TCA_DESCR.
29 * See Inside TYPO3 for details.
30 *
31 * $Id$
32 * Revised for TYPO3 3.7 5/2004 by Kasper Skårhøj
33 * XHTML-trans compliant
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 91: class local_t3lib_parsehtml extends t3lib_parsehtml
43 * 102: function processContent($value,$dir,$conf)
44 *
45 *
46 * 122: class SC_view_help
47 * 146: function init()
48 * 167: function main()
49 * 198: function printContent()
50 *
51 * SECTION: Rendering main modes
52 * 221: function render_TOC()
53 * 338: function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys)
54 * 370: function render_TOC_makeTocList($tocArray)
55 * 409: function render_Table($table)
56 * 469: function render_Single($table,$field)
57 *
58 * SECTION: Rendering CSH items
59 * 515: function make_seeAlso($value,$anchorTable='')
60 * 564: function printImage($images,$descr)
61 * 599: function headerLine($str,$type=0)
62 * 620: function prepareContent($str)
63 * 635: function printItem($table,$field,$anchors=0)
64 * 668: function getTableFieldNames($table,$field)
65 * 691: function getTableFieldLabel($table,$field='',$mergeToken=': ')
66 *
67 * SECTION: Glossary related
68 * 726: function createGlossaryIndex()
69 * 785: function substituteGlossaryWords($code)
70 * 801: function substituteGlossaryWords_htmlcleaner_callback($code)
71 *
72 * TOTAL FUNCTIONS: 19
73 * (This index is automatically created/updated by the extension "extdeveval")
74 *
75 */
76
77 require('init.php');
78 require('template.php');
79 $LANG->includeLLFile('EXT:lang/locallang_view_help.xml');
80
81
82 /**
83 * Extension of the parse_html class.
84 *
85 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
86 * @package TYPO3
87 * @subpackage core
88 */
89 class local_t3lib_parsehtml extends t3lib_parsehtml {
90
91 /**
92 * Processing content between tags for HTML_cleaner
93 *
94 * @param string The value
95 * @param integer Direction, either -1 or +1. 0 (zero) means no change to input value.
96 * @param mixed Not used, ignore.
97 * @return string The processed value.
98 * @access private
99 */
100 function processContent($value,$dir,$conf) {
101 $value = $this->pObj->substituteGlossaryWords_htmlcleaner_callback($value);
102
103 return $value;
104 }
105 }
106
107
108
109
110
111
112
113 /**
114 * 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.
115 *
116 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
117 * @package TYPO3
118 * @subpackage core
119 */
120 class SC_view_help {
121 var $allowedHTML = '<strong><em><b><i>';
122
123 // For these vars, see init()
124 var $limitAccess; // If set access to fields and tables is checked. Should be done for true database tables.
125 var $table; // The "table" key
126 var $field; // The "field" key
127 /**
128 * Key used to point to the right CSH resource
129 * In simple cases, is equal to $table
130 *
131 * @var string
132 */
133 protected $mainKey;
134
135 // Internal, static: GPvar:
136 var $tfID; // Table/FIeld id.
137 var $ffID; // Flexform file/field information
138 var $back; // Back (previous tfID)
139 var $renderALL; // If set, then in TOC mode the FULL manual will be printed as well!
140
141 // Internal, dynamic:
142 var $content; // Content accumulation.
143 var $glossaryWords; // Glossary words
144
145
146
147 /**
148 * Initialize the class for various input etc.
149 *
150 * @return void
151 */
152 function init() {
153 global $LANG, $TCA;
154
155 // Setting GPvars:
156 $this->tfID = t3lib_div::_GP('tfID');
157 // Sanitizes the tfID using whitelisting.
158 if (!preg_match('/^[a-zA-Z0-9_\-\.\*]*$/', $this->tfID)) {
159 $this->tfID = '';
160 }
161 if (!$this->tfID) {
162 if (($this->ffID = t3lib_div::_GP('ffID'))) {
163 $this->ffID = unserialize(base64_decode($this->ffID));
164 }
165 }
166 $this->back = t3lib_div::_GP('back');
167 $this->renderALL = t3lib_div::_GP('renderALL');
168
169 // Set internal table/field to the parts of "tfID" incoming var.
170 $identifierParts = explode('.', $this->tfID);
171 // The table is the first item
172 $this->table = array_shift($identifierParts);
173 $this->mainKey = $this->table;
174 // The field is the second one
175 $this->field = array_shift($identifierParts);
176 // There may be extra parts for FlexForms
177 if (count($identifierParts) > 0) {
178 // There's at least one extra part
179 $extraIdentifierInformation = array();
180 $extraIdentifierInformation[] = array_shift($identifierParts);
181 // Load the TCA details of the table
182 t3lib_div::loadTCA($this->table);
183 // If the ds_pointerField contains a comma, it means the choice of FlexForm DS
184 // is determined by 2 parameters. In this case we have an extra identifier part
185 if (strpos($TCA[$this->table]['columns'][$this->field]['config']['ds_pointerField'], ',') !== FALSE) {
186 $extraIdentifierInformation[] = array_shift($identifierParts);
187 }
188 // The remaining parts make up the FlexForm field name itself
189 // (reassembled with dots)
190 $flexFormField = implode('.', $identifierParts);
191 // Assemble a different main key and switch field to use FlexForm field name
192 $this->mainKey .= '.' . $this->field;
193 foreach ($extraIdentifierInformation as $extraKey) {
194 $this->mainKey .= '.' . $extraKey;
195 }
196 $this->field = $flexFormField;
197 }
198
199 // limitAccess is checked if the $this->table really IS a table (and if the user is NOT a translator who should see all!)
200 $showAllToUser = t3lib_BEfunc::isModuleSetInTBE_MODULES('txllxmltranslateM1') && $GLOBALS['BE_USER']->check('modules','txllxmltranslateM1');
201 $this->limitAccess = isset($TCA[$this->table]) ? !$showAllToUser : FALSE;
202 }
203
204 /**
205 * Main function, rendering the display
206 *
207 * @return void
208 */
209 function main() {
210 global $BE_USER,$LANG,$TCA_DESCR,$TCA,$TBE_TEMPLATE;
211
212 // Start HTML output accumulation:
213 $TBE_TEMPLATE->divClass = 'typo3-view-help';
214 $this->content .= $TBE_TEMPLATE->startPage($LANG->getLL('title'));
215
216 if ($this->field == '*') {
217 // If ALL fields is supposed to be shown:
218 $this->createGlossaryIndex();
219 $this->content .= $this->render_Table($this->mainKey);
220
221 } elseif ($this->tfID) {
222 // ... otherwise show only single field:
223 $this->createGlossaryIndex();
224 $this->content .= $this->render_Single($this->mainKey, $this->field);
225
226 } elseif (is_array($this->ffID)) {
227 $this->content .= $this->render_SingleFlex();
228
229 } else {
230 // Render Table Of Contents if nothing else:
231 $this->content.= $this->render_TOC();
232 }
233
234 // Print close-button:
235 # $this->content.='<br /><form action=""><input type="submit" value="'.htmlspecialchars($LANG->getLL('close')).'" onclick="self.close(); return false;" /></form><br/>';
236
237 // End page:
238 $this->content.= '<br/>';
239 $this->content.= $TBE_TEMPLATE->endPage();
240 }
241
242 /**
243 * Outputting the accumulated content to screen
244 *
245 * @return void
246 */
247 function printContent() {
248 echo $this->content;
249 }
250
251
252
253
254
255
256
257
258
259 /************************************
260 *
261 * Rendering main modes
262 *
263 ************************************/
264
265 /**
266 * Creates Table Of Contents and possibly "Full Manual" mode if selected.
267 *
268 * @return string HTML content
269 */
270 function render_TOC() {
271 global $TCA_DESCR,$TCA,$LANG,$BE_USER,$TBE_MODULES;
272
273 // Initialize:
274 $CSHkeys = array_flip(array_keys($TCA_DESCR));
275 $TCAkeys = array_keys($TCA);
276
277 $outputSections = array();
278 $tocArray = array();
279
280
281 // TYPO3 Core Features:
282 $LANG->loadSingleTableDescription('xMOD_csh_corebe');
283 $this->render_TOC_el('xMOD_csh_corebe', 'core', $outputSections, $tocArray, $CSHkeys);
284
285 // Backend Modules:
286 $loadModules = t3lib_div::makeInstance('t3lib_loadModules');
287 $loadModules->load($TBE_MODULES);
288 foreach($loadModules->modules as $mainMod => $info) {
289 $cshKey = '_MOD_'.$mainMod;
290 if ($CSHkeys[$cshKey]) {
291 $LANG->loadSingleTableDescription($cshKey);
292 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
293 }
294
295 if (is_array($info['sub'])) {
296 foreach($info['sub'] as $subMod => $subInfo) {
297 $cshKey = '_MOD_'.$mainMod.'_'.$subMod;
298 if ($CSHkeys[$cshKey]) {
299 $LANG->loadSingleTableDescription($cshKey);
300 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
301 }
302 }
303 }
304 }
305
306 // Database Tables:
307 foreach($TCAkeys as $table) {
308 // Load descriptions for table $table
309 $LANG->loadSingleTableDescription($table);
310 if (is_array($TCA_DESCR[$table]['columns']) && $BE_USER->check('tables_select',$table)) {
311 $this->render_TOC_el($table, 'tables', $outputSections, $tocArray, $CSHkeys);
312 }
313 }
314
315 // Extensions
316 foreach($CSHkeys as $cshKey => $value) {
317 if (t3lib_div::isFirstPartOfStr($cshKey, 'xEXT_') && !isset($TCA[$cshKey])) {
318 $LANG->loadSingleTableDescription($cshKey);
319 $this->render_TOC_el($cshKey, 'extensions', $outputSections, $tocArray, $CSHkeys);
320 }
321 }
322
323 // Glossary
324 foreach($CSHkeys as $cshKey => $value) {
325 if (t3lib_div::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($TCA[$cshKey])) {
326 $LANG->loadSingleTableDescription($cshKey);
327 $this->render_TOC_el($cshKey, 'glossary', $outputSections, $tocArray, $CSHkeys);
328 }
329 }
330
331 // Other:
332 foreach($CSHkeys as $cshKey => $value) {
333 if (!t3lib_div::isFirstPartOfStr($cshKey, '_MOD_') && !isset($TCA[$cshKey])) {
334 $LANG->loadSingleTableDescription($cshKey);
335 $this->render_TOC_el($cshKey, 'other', $outputSections, $tocArray, $CSHkeys);
336 }
337 }
338
339
340 // COMPILE output:
341 $output = '';
342 $output.= '
343
344 <h1>'.$LANG->getLL('manual_title',1).'</h1>';
345
346 $output.= '
347
348 <h2>'.$LANG->getLL('introduction',1).'</h2>
349 <p>'.$LANG->getLL('description',1).'</p>';
350
351 $output.= '
352
353 <h2>'.$LANG->getLL('TOC',1).'</h2>'.
354 $this->render_TOC_makeTocList($tocArray);
355
356 if (!$this->renderALL) {
357 $output.= '
358 <br/>
359 <p class="c-nav"><a href="view_help.php?renderALL=1">'.$LANG->getLL('full_manual',1).'</a></p>';
360 }
361
362 if ($this->renderALL) {
363 $output.= '
364
365 <h2>'.$LANG->getLL('full_manual_chapters',1).'</h2>'.
366 implode('
367
368
369 <!-- NEW SECTION: -->
370 ',$outputSections);
371 }
372
373 $output .= '<hr /><p class="manual-title">'.t3lib_BEfunc::TYPO3_copyRightNotice().'</p>';
374
375 return $output;
376 }
377
378 /**
379 * Creates a TOC list element and renders corresponding HELP content if "renderALL" mode is set.
380 *
381 * @param string CSH key / Table name
382 * @param string TOC category keyword: "core", "modules", "tables", "other"
383 * @param array Array for accumulation of rendered HELP Content (in "renderALL" mode). Passed by reference!
384 * @param array TOC array; Here TOC index elements are created. Passed by reference!
385 * @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!
386 * @return void
387 */
388 function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys) {
389 global $LANG;
390
391 if ($this->renderALL) { // Render full manual right here!
392 $outputSections[$table] = $this->render_Table($table);
393
394 if ($outputSections[$table]) {
395 $outputSections[$table] = '
396
397 <!-- New CSHkey/Table: '.$table.' -->
398 <p class="c-nav"><a name="ANCHOR_'.$table.'" href="#">'.$LANG->getLL('to_top',1).'</a></p>
399 <h2>'.$this->getTableFieldLabel($table).'</h2>
400
401 '.$outputSections[$table];
402 $tocArray[$tocCat][$table] = '<a href="#ANCHOR_'.$table.'">'.$this->getTableFieldLabel($table).'</a>';
403 } else {
404 unset($outputSections[$table]);
405 }
406 } else { // Only TOC:
407 $tocArray[$tocCat][$table] = '<p><a href="view_help.php?tfID='.rawurlencode($table.'.*').'">'.$this->getTableFieldLabel($table).'</a></p>';
408 }
409
410 // Unset CSH key:
411 unset($CSHkeys[$table]);
412 }
413
414 /**
415 * Renders the TOC index as a HTML bullet list from TOC array
416 *
417 * @param array ToC Array.
418 * @return string HTML bullet list for index.
419 */
420 function render_TOC_makeTocList($tocArray) {
421 global $LANG;
422
423 // The Various manual sections:
424 $keys = explode(',', 'core,modules,tables,extensions,glossary,other');
425
426 // Create TOC bullet list:
427 $output = '';
428 foreach($keys as $tocKey) {
429 if (is_array($tocArray[$tocKey])) {
430 $output.='
431 <li>'.$LANG->getLL('TOC_'.$tocKey,1).'
432 <ul>
433 <li>'.implode('</li>
434 <li>',$tocArray[$tocKey]).'</li>
435 </ul>
436 </li>';
437 }
438 }
439
440 // Compile TOC:
441 $output = '
442
443 <!-- TOC: -->
444 <div class="c-toc">
445 <ul>
446 '.$output.'
447 </ul>
448 </div>';
449
450 return $output;
451 }
452
453 /**
454 * Render CSH for a full cshKey/table
455 *
456 * @param string $key Full CSH key (may be different from table name)
457 * @param string $table CSH key / table name
458 * @return string HTML output
459 */
460 function render_Table($key, $table) {
461 global $BE_USER,$TCA_DESCR,$TCA,$LANG;
462
463 $output = '';
464
465 // Load table TCA
466 t3lib_div::loadTCA($key);
467
468 // Load descriptions for table $table
469 $LANG->loadSingleTableDescription($key);
470
471 if (is_array($TCA_DESCR[$key]['columns']) && (!$this->limitAccess || $BE_USER->check('tables_select', $table))) {
472 // Initialize variables:
473 $parts = array();
474 $parts[0] = ''; // Reserved for header of table
475
476 // Traverse table columns as listed in TCA_DESCR
477 foreach ($TCA_DESCR[$key]['columns'] as $field => $_) {
478
479 $fieldValue = isset($TCA[$key]) && strcmp($field, '') ? $TCA[$key]['columns'][$field] : array();
480
481 if (is_array($fieldValue) && (!$this->limitAccess || !$fieldValue['exclude'] || $BE_USER->check('non_exclude_fields', $table . ':' . $field))) {
482 if (!$field) {
483 $parts[0] = $this->printItem($key, '', 1); // Header
484 } else {
485 $parts[] = $this->printItem($key, $field, 1); // Field
486 }
487 }
488 }
489
490 if (!$parts[0]) {
491 unset($parts[0]);
492 }
493 $output .= implode('<br />', $parts);
494 }
495
496 // Substitute glossary words:
497 $output = $this->substituteGlossaryWords($output);
498
499 // TOC link:
500 if (!$this->renderALL) {
501 $tocLink = '<p class="c-nav"><a href="view_help.php">' . $LANG->getLL('goToToc', 1) . '</a></p>';
502
503 $output =
504 $tocLink.'
505 <br/>'.
506 $output.'
507 <br />'.
508 $tocLink;
509 }
510
511 return $output;
512 }
513
514 /**
515 * Renders CSH for a single field.
516 *
517 * @param string $key CSH key / table name
518 * @param string $field Sub key / field name
519 * @return string HTML output
520 */
521 function render_Single($key, $field) {
522 global $LANG, $TCA;
523
524 $output = '';
525
526 // Load the description field
527 $LANG->loadSingleTableDescription($key);
528
529 // Render single item
530 $output.= $this->printItem($key, $field);
531
532 // Substitute glossary words:
533 $output = $this->substituteGlossaryWords($output);
534
535 // Link to Full table description and TOC:
536 $getLLKey = $this->limitAccess ? 'fullDescription' : 'fullDescription_module';
537 $output.= '<br />
538 <p class="c-nav"><a href="view_help.php?tfID=' . rawurlencode($key . '.*') . '">' . $LANG->getLL($getLLKey, 1) . '</a></p>
539 <p class="c-nav"><a href="view_help.php">' . $LANG->getLL('goToToc', 1) . '</a></p>';
540
541 return $output;
542 }
543
544
545 /**
546 * Renders CSH for a single field.
547 *
548 * @param string CSH key / table name
549 * @param string Sub key / field name
550 * @return string HTML output
551 * @deprecated since TYPO3 4.5, this function will be removed in TYPO3 4.7. Use render_Single() instead.
552 */
553 function render_SingleFlex() {
554 t3lib_div::logDeprecatedFunction();
555 $output = '';
556
557 // Render
558 $output.= $this->printItemFlex();
559
560 // Substitute glossary words:
561 return $this->substituteGlossaryWords($output);
562 }
563
564
565 /************************************
566 *
567 * Rendering CSH items
568 *
569 ************************************/
570
571 /**
572 * Make seeAlso links from $value
573 *
574 * @param string See-also input codes
575 * @param string If $anchorTable is set to a tablename, then references to this table will be made as anchors, not URLs.
576 * @return string See-also links HTML
577 */
578 function make_seeAlso($value,$anchorTable='') {
579 global $TCA,$BE_USER,$TCA_DESCR;
580
581 // Split references by comma or linebreak
582 $items = preg_split('/[,' . LF . ']/', $value);
583 $lines = array();
584
585 foreach($items as $val) {
586 $val = trim($val);
587 if ($val) {
588 $iP = explode(':',$val);
589 $iPUrl = t3lib_div::trimExplode('|',$val);
590 // URL reference:
591 if (substr($iPUrl[1],0,4)=='http') {
592 $lines[] = '<a href="'.htmlspecialchars($iPUrl[1]).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>';
593 } elseif (substr($iPUrl[1],0,5)=='FILE:') {
594 $fileName = t3lib_div::getFileAbsFileName(substr($iPUrl[1],5),1,1);
595 if ($fileName && @is_file($fileName)) {
596 $fileName = '../'.substr($fileName,strlen(PATH_site));
597 $lines[] = '<a href="'.htmlspecialchars($fileName).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>';
598 }
599 } else {
600 // "table" reference
601 t3lib_div::loadTCA($iP[0]);
602
603 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:
604
605 // Load table descriptions:
606 #$LANG->loadSingleTableDescription($iP[0]);
607 if (isset($TCA_DESCR[$iP[0]])) {
608 // Make see-also link:
609 $href = ($this->renderALL || ($anchorTable && $iP[0]==$anchorTable) ? '#'.implode('.',$iP) : 'view_help.php?tfID='.rawurlencode(implode('.',$iP)).'&back='.$this->tfID);
610 $label = $this->getTableFieldLabel($iP[0],$iP[1],' / ');
611 $lines[] = '<a href="'.htmlspecialchars($href).'">'.htmlspecialchars($label).'</a>';
612 }
613 }
614 }
615 }
616 }
617 return implode('<br />',$lines);
618 }
619
620 /**
621 * Will return an image tag with description in italics.
622 *
623 * @param string Image file reference (list of)
624 * @param string Description string (divided for each image by line break)
625 * @return string Image HTML codes
626 */
627 function printImage($images,$descr) {
628 $code = '';
629 // Splitting:
630 $imgArray = t3lib_div::trimExplode(',', $images, 1);
631 if (count($imgArray)) {
632 $descrArray = explode(LF,$descr,count($imgArray));
633
634 foreach($imgArray as $k => $image) {
635 $descr = $descrArray[$k];
636
637 $absImagePath = t3lib_div::getFileAbsFileName($image,1,1);
638 if ($absImagePath && @is_file($absImagePath)) {
639 $imgFile = substr($absImagePath,strlen(PATH_site));
640 $imgInfo = @getimagesize($absImagePath);
641 if (is_array($imgInfo)) {
642 $imgFile = '../'.$imgFile;
643 $code.= '<br /><img src="'.$imgFile.'" '.$imgInfo[3].' class="c-inlineimg" alt="" /><br />
644 ';
645 $code.= '<p><em>'.$GLOBALS['LANG']->hscAndCharConv($descr,1).'</em></p>
646 ';
647 } else $code.= '<div style="background-color: red; border: 1px solid black; color: white;">NOT AN IMAGE: '.$imgFile.'</div>';
648 } else $code.= '<div style="background-color: red; border: 1px solid black; color: white;">IMAGE FILE NOT FOUND: '.$image.'</div>';
649 }
650 }
651
652 return $code;
653 }
654
655 /**
656 * Returns header HTML content
657 *
658 * @param string Header text
659 * @param string Header type (1, 0)
660 * @return string The HTML for the header.
661 */
662 function headerLine($str,$type=0) {
663 switch($type) {
664 case 1:
665 $str = '<h2 class="t3-row-header">' . htmlspecialchars($str) . '</h2>
666 ';
667 break;
668 case 0:
669 $str = '<h3 class="divider">' . htmlspecialchars($str) . '</h3>
670 ';
671 break;
672 }
673
674 return $str;
675 }
676
677 /**
678 * Returns prepared content
679 *
680 * @param string Content to format.
681 * @return string Formatted content.
682 */
683 function prepareContent($str) {
684 $str = $GLOBALS['LANG']->hscAndCharConv($str,0);
685 return '<p>'.nl2br(trim(strip_tags($str,$this->allowedHTML))).'</p>
686 ';
687 }
688
689 /**
690 * Prints a single $table/$field information piece
691 * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
692 *
693 * @param string $key CSH key / table name
694 * @param string $field Sub key / field name
695 * @param boolean $anchors If anchors is to be shown.
696 * @return string HTML content
697 */
698 function printItem($key, $field, $anchors = FALSE) {
699 global $TCA_DESCR, $LANG, $TCA, $BE_USER;
700 $out = '';
701
702 // Load full table definition in $TCA
703 t3lib_div::loadTCA($key);
704
705 if ($key && (!$field || is_array($TCA_DESCR[$key]['columns'][$field]))) {
706 // Make seeAlso references.
707 $seeAlsoRes = $this->make_seeAlso($TCA_DESCR[$key]['columns'][$field]['seeAlso'], $anchors ? $key : '');
708
709 // Making item:
710 $out = '<a name="' . $key . '.' . $field . '"></a>' .
711 $this->headerLine($this->getTableFieldLabel($key, $field), 1) .
712 $this->prepareContent($TCA_DESCR[$key]['columns'][$field]['description']) .
713 ($TCA_DESCR[$key]['columns'][$field]['details'] ? $this->headerLine($LANG->getLL('details').':').$this->prepareContent($TCA_DESCR[$key]['columns'][$field]['details']) : '') .
714 ($TCA_DESCR[$key]['columns'][$field]['syntax'] ? $this->headerLine($LANG->getLL('syntax').':').$this->prepareContent($TCA_DESCR[$key]['columns'][$field]['syntax']) : '') .
715 ($TCA_DESCR[$key]['columns'][$field]['image'] ? $this->printImage($TCA_DESCR[$key]['columns'][$field]['image'],$TCA_DESCR[$key]['columns'][$field]['image_descr']) : '') .
716 ($TCA_DESCR[$key]['columns'][$field]['seeAlso'] && $seeAlsoRes ? $this->headerLine($LANG->getLL('seeAlso').':').'<p>'.$seeAlsoRes.'</p>' : '') .
717 ($this->back ? '<br /><p><a href="' . htmlspecialchars('view_help.php?tfID=' . rawurlencode($this->back)) . '" class="typo3-goBack">' . htmlspecialchars($LANG->getLL('goBack')) . '</a></p>' : '') .
718 '<br />';
719 }
720 return $out;
721 }
722
723 /**
724 * Prints a single $table/$field information piece
725 * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
726 *
727 * @param string Table name
728 * @param string Field name
729 * @param boolean If anchors is to be shown.
730 * @return string HTML content
731 * @deprecated since TYPO3 4.5, this function will be removed in TYPO3 4.7. Use printItem() instead.
732 */
733 function printItemFlex() {
734 t3lib_div::logDeprecatedFunction();
735 // Get all texts
736 foreach (explode(',', 'description,details,syntax,image,image_descr,seeAlso') as $var) {
737 // Double $ below is not a error!
738 $$var = $GLOBALS['LANG']->sL($this->ffID['cshFile'] . ':' . $this->ffID['field'] . '.' . $var);
739 }
740 // Make seeAlso references.
741 $seeAlsoRes = $this->make_seeAlso($seeAlso);
742
743 // Making item:
744 $out= $this->headerLine($this->ffID['title'], 1) .
745 $this->prepareContent($description) .
746 ($details ? $this->headerLine($GLOBALS['LANG']->getLL('details').':') . $this->prepareContent($details) : '') .
747 ($syntax ? $this->headerLine($GLOBALS['LANG']->getLL('syntax').':') . $this->prepareContent($syntax) : '') .
748 ($image ? $this->printImage($image, $image_descr) : '') .
749 ($seeAlso && $seeAlsoRes ? $this->headerLine($GLOBALS['LANG']->getLL('seeAlso').':').'<p>'.$seeAlsoRes.'</p>' : '') .
750 '<br />';
751 return $out;
752 }
753
754 /**
755 * Returns labels for a given field in a given structure
756 *
757 * @param string $key CSH key / table name
758 * @param string $field Sub key / field name
759 * @return array Table and field labels in a numeric array
760 */
761 function getTableFieldNames($key, $field) {
762 global $TCA, $TCA_DESCR, $LANG;
763
764 $LANG->loadSingleTableDescription($key);
765
766 // Define the label for the key
767 $keyName = $key;
768 if (is_array($TCA_DESCR[$key]['columns']['']) && isset($TCA_DESCR[$key]['columns']['']['alttitle'])) {
769 // If there's an alternative title, use it
770 $keyName = $TCA_DESCR[$key]['columns']['']['alttitle'];
771 } elseif (isset($TCA[$key])) {
772 // Otherwise, if it's a table, use its title
773 $keyName = $TCA[$key]['ctrl']['title'];
774 } else {
775 // If no title was found, make sure to remove any "_MOD_"
776 $keyName = preg_replace('/^_MOD_/', '', $key);
777 }
778 // Define the label for the field
779 $fieldName = $field;
780 if (is_array($TCA_DESCR[$key]['columns'][$field]) && isset($TCA_DESCR[$key]['columns'][$field]['alttitle'])) {
781 // If there's an alternative title, use it
782 $fieldName = $TCA_DESCR[$key]['columns'][$field]['alttitle'];
783 } elseif (isset($TCA[$key])&&isset($TCA[$key]['columns'][$field])) {
784 // Otherwise, if it's a table, use its title
785 $fieldName = $TCA[$key]['columns'][$field]['label'];
786 }
787 return array($keyName, $fieldName);
788 }
789
790 /**
791 * Returns composite label for table/field
792 *
793 * @param string $key CSH key / table name
794 * @param string $field Sub key / field name
795 * @param string $mergeToken Token to merge the two strings with
796 * @return string Labels joined with merge token
797 * @see getTableFieldNames()
798 */
799 function getTableFieldLabel($key, $field = '', $mergeToken = ': ') {
800 global $LANG;
801 $tableName = '';
802 $fieldName = '';
803
804 // Get table / field parts:
805 list($tableName, $fieldName) = $this->getTableFieldNames($key, $field);
806
807 // Create label:
808 $labelString = $LANG->sL($tableName) .
809 ($field ? $mergeToken . rtrim(trim($LANG->sL($fieldName)), ':') : '');
810
811 return $labelString;
812 }
813
814
815
816
817
818
819
820
821
822
823
824 /******************************
825 *
826 * Glossary related
827 *
828 ******************************/
829
830 /**
831 * Creates glossary index in $this->glossaryWords
832 * Glossary is cached in cache_hash cache and so will be updated only when cache is cleared.
833 *
834 * @return void
835 */
836 function createGlossaryIndex() {
837 global $TCA_DESCR,$TCA,$LANG;
838
839 // Create hash string and try to retrieve glossary array:
840 $hash = md5('typo3/view_help.php:glossary');
841 list($this->glossaryWords,$this->substWords) = unserialize(t3lib_BEfunc::getHash($hash));
842
843 // Generate glossary words if not found:
844 if (!is_array($this->glossaryWords)) {
845
846 // Initialize:
847 $this->glossaryWords = array();
848 $this->substWords = array();
849 $CSHkeys = array_flip(array_keys($TCA_DESCR));
850
851 // Glossary
852 foreach($CSHkeys as $cshKey => $value) {
853 if (t3lib_div::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($TCA[$cshKey])) {
854 $LANG->loadSingleTableDescription($cshKey);
855
856 if (is_array($TCA_DESCR[$cshKey]['columns'])) {
857
858 // Traverse table columns as listed in TCA_DESCR
859 foreach ($TCA_DESCR[$cshKey]['columns'] as $field => $data) {
860 if ($field) {
861 $this->glossaryWords[$cshKey.'.'.$field] = array(
862 'title' => trim($data['alttitle'] ? $data['alttitle'] : $cshKey),
863 'description' => str_replace('%22','%23%23%23', rawurlencode($data['description'])),
864 );
865 }
866 }
867 }
868 }
869 }
870
871 // First, create unique list of words:
872 foreach($this->glossaryWords as $key => $value) {
873 $word = strtolower($value['title']); // Making word lowercase in order to filter out same words in different cases.
874
875 if ($word!=='') {
876 $this->substWords[$word] = $value;
877 $this->substWords[$word]['key'] = $key;
878 }
879 }
880
881 krsort($this->substWords);
882
883 t3lib_BEfunc::storeHash($hash,serialize(array($this->glossaryWords,$this->substWords)),'Glossary');
884 }
885 }
886
887 /**
888 * Processing of all non-HTML content in the output
889 * Will be done by a call-back to ->substituteGlossaryWords_htmlcleaner_callback()
890 *
891 * @param string Input HTML code
892 * @return string Output HTML code
893 */
894 function substituteGlossaryWords($code) {
895 $htmlParser = t3lib_div::makeInstance('local_t3lib_parsehtml');
896 $htmlParser->pObj = $this;
897 $code = $htmlParser->HTMLcleaner($code, array(), 1);
898
899 return $code;
900 }
901
902 /**
903 * Substituting glossary words in the CSH
904 * (This is a call-back function from "class local_t3lib_parsehtml extends t3lib_parsehtml", see top of this script)
905 *
906 * @param string Input HTML string
907 * @return string HTML with substituted words in.
908 * @coauthor alex widschwendter, media.res kommunikationsloesungen
909 */
910 function substituteGlossaryWords_htmlcleaner_callback($code) {
911 if (is_array($this->substWords) && count($this->substWords) && strlen(trim($code))) {
912
913 // Substitute words:
914 foreach($this->substWords as $wordKey => $wordSet) {
915 // quoteMeta used so special chars (which should not occur though) in words will not break the regex. Seemed to work (- kasper)
916 $parts = preg_split('/( |[\(])('.quoteMeta($wordSet['title']).')([\.\!\)\?\:\,]+| )/i', ' '.$code.' ', 2, PREG_SPLIT_DELIM_CAPTURE);
917 if (count($parts) == 5) {
918 $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))).'">'.
919 htmlspecialchars($parts[2]).
920 '</a>';
921 $code = substr(implode('',$parts),1,-1);
922
923 // Disable entry so it doesn't get used next time:
924 unset($this->substWords[$wordKey]);
925 }
926 }
927 $code = str_replace('###', '&quot;',rawurldecode($code));
928 }
929
930 return $code;
931 }
932
933 }
934
935
936
937 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/view_help.php'])) {
938 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/view_help.php']);
939 }
940
941
942
943 // Make instance:
944 $SOBE = t3lib_div::makeInstance('SC_view_help');
945 $SOBE->init();
946 $SOBE->main();
947 $SOBE->printContent();
948
949 ?>