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