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