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