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