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