[TASK] Add tool-function to strip PATH_site-part of paths
[Packages/TYPO3.CMS.git] / typo3 / sysext / cshmanual / Classes / Controller / HelpModuleController.php
1 <?php
2 namespace TYPO3\CMS\Cshmanual\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31
32 /**
33 * 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.
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37 class HelpModuleController {
38
39 /**
40 * @todo Define visibility
41 */
42 public $allowedHTML = '<strong><em><b><i>';
43
44 /**
45 * For these vars, see init()
46 * If set access to fields and tables is checked. Should be done for TRUE database tables.
47 *
48 * @todo Define visibility
49 */
50 public $limitAccess;
51
52 /**
53 * The "table" key
54 *
55 * @todo Define visibility
56 */
57 public $table;
58
59 /**
60 * The "field" key
61 *
62 * @todo Define visibility
63 */
64 public $field;
65
66 /**
67 * Key used to point to the right CSH resource
68 * In simple cases, is equal to $table
69 *
70 * @var string
71 */
72 protected $mainKey;
73
74 /**
75 * Internal, static: GPvar
76 * Table/Field id
77 *
78 * @todo Define visibility
79 */
80 public $tfID;
81
82 /**
83 * Back (previous tfID)
84 *
85 * @todo Define visibility
86 */
87 public $back;
88
89 /**
90 * If set, then in TOC mode the FULL manual will be printed as well!
91 *
92 * @todo Define visibility
93 */
94 public $renderALL;
95
96 /**
97 * Content accumulation
98 *
99 * @todo Define visibility
100 */
101 public $content;
102
103 /**
104 * Glossary words
105 *
106 * @todo Define visibility
107 */
108 public $glossaryWords;
109
110 /**
111 * Initialize the class for various input etc.
112 *
113 * @return void
114 * @todo Define visibility
115 */
116 public function init() {
117 // Setting GPvars:
118 $this->tfID = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tfID');
119 // Sanitizes the tfID using whitelisting.
120 if (!preg_match('/^[a-zA-Z0-9_\\-\\.\\*]*$/', $this->tfID)) {
121 $this->tfID = '';
122 }
123 $this->back = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('back');
124 $this->renderALL = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('renderALL');
125 // Set internal table/field to the parts of "tfID" incoming var.
126 $identifierParts = explode('.', $this->tfID);
127 // The table is the first item
128 $this->table = array_shift($identifierParts);
129 $this->mainKey = $this->table;
130 // The field is the second one
131 $this->field = array_shift($identifierParts);
132 // There may be extra parts for FlexForms
133 if (count($identifierParts) > 0) {
134 // There's at least one extra part
135 $extraIdentifierInformation = array();
136 $extraIdentifierInformation[] = array_shift($identifierParts);
137 // If the ds_pointerField contains a comma, it means the choice of FlexForm DS
138 // is determined by 2 parameters. In this case we have an extra identifier part
139 if (strpos($GLOBALS['TCA'][$this->table]['columns'][$this->field]['config']['ds_pointerField'], ',') !== FALSE) {
140 $extraIdentifierInformation[] = array_shift($identifierParts);
141 }
142 // The remaining parts make up the FlexForm field name itself
143 // (reassembled with dots)
144 $flexFormField = implode('.', $identifierParts);
145 // Assemble a different main key and switch field to use FlexForm field name
146 $this->mainKey .= '.' . $this->field;
147 foreach ($extraIdentifierInformation as $extraKey) {
148 $this->mainKey .= '.' . $extraKey;
149 }
150 $this->field = $flexFormField;
151 }
152 // limitAccess is checked if the $this->table really IS a table (and if the user is NOT a translator who should see all!)
153 $showAllToUser = BackendUtility::isModuleSetInTBE_MODULES('txllxmltranslateM1') && $GLOBALS['BE_USER']->check('modules', 'txllxmltranslateM1');
154 $this->limitAccess = isset($GLOBALS['TCA'][$this->table]) ? !$showAllToUser : FALSE;
155 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_view_help.xlf', 1);
156 }
157
158 /**
159 * Main function, rendering the display
160 *
161 * @return void
162 * @todo Define visibility
163 */
164 public function main() {
165 // Start HTML output accumulation:
166 $GLOBALS['TBE_TEMPLATE']->divClass = 'typo3-view-help';
167 $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage($GLOBALS['LANG']->getLL('title'));
168 if ($this->field == '*') {
169 // If ALL fields is supposed to be shown:
170 $this->createGlossaryIndex();
171 $this->content .= $this->render_Table($this->mainKey);
172 } elseif ($this->tfID) {
173 // ... otherwise show only single field:
174 $this->createGlossaryIndex();
175 $this->content .= $this->render_Single($this->mainKey, $this->field);
176 } else {
177 // Render Table Of Contents if nothing else:
178 $this->content .= $this->render_TOC();
179 }
180 // End page:
181 $this->content .= '<br/>';
182 $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage();
183 }
184
185 /**
186 * Outputting the accumulated content to screen
187 *
188 * @return void
189 * @todo Define visibility
190 */
191 public function printContent() {
192 echo $this->content;
193 }
194
195 /************************************
196 * Rendering main modes
197 ************************************/
198
199 /**
200 * Creates Table Of Contents and possibly "Full Manual" mode if selected.
201 *
202 * @return string HTML content
203 * @todo Define visibility
204 */
205 public function render_TOC() {
206 // Initialize:
207 $CSHkeys = array_flip(array_keys($GLOBALS['TCA_DESCR']));
208 $TCAkeys = array_keys($GLOBALS['TCA']);
209 $outputSections = array();
210 $tocArray = array();
211 // TYPO3 Core Features:
212 $GLOBALS['LANG']->loadSingleTableDescription('xMOD_csh_corebe');
213 $this->render_TOC_el('xMOD_csh_corebe', 'core', $outputSections, $tocArray, $CSHkeys);
214 // Backend Modules:
215 $loadModules = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleLoader');
216 $loadModules->load($GLOBALS['TBE_MODULES']);
217 foreach ($loadModules->modules as $mainMod => $info) {
218 $cshKey = '_MOD_' . $mainMod;
219 if ($CSHkeys[$cshKey]) {
220 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
221 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
222 }
223 if (is_array($info['sub'])) {
224 foreach ($info['sub'] as $subMod => $subInfo) {
225 $cshKey = '_MOD_' . $mainMod . '_' . $subMod;
226 if ($CSHkeys[$cshKey]) {
227 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
228 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
229 }
230 }
231 }
232 }
233 // Database Tables:
234 foreach ($TCAkeys as $table) {
235 // Load descriptions for table $table
236 $GLOBALS['LANG']->loadSingleTableDescription($table);
237 if (is_array($GLOBALS['TCA_DESCR'][$table]['columns']) && $GLOBALS['BE_USER']->check('tables_select', $table)) {
238 $this->render_TOC_el($table, 'tables', $outputSections, $tocArray, $CSHkeys);
239 }
240 }
241 // Extensions
242 foreach ($CSHkeys as $cshKey => $value) {
243 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, 'xEXT_') && !isset($GLOBALS['TCA'][$cshKey])) {
244 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
245 $this->render_TOC_el($cshKey, 'extensions', $outputSections, $tocArray, $CSHkeys);
246 }
247 }
248 // Glossary
249 foreach ($CSHkeys as $cshKey => $value) {
250 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($GLOBALS['TCA'][$cshKey])) {
251 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
252 $this->render_TOC_el($cshKey, 'glossary', $outputSections, $tocArray, $CSHkeys);
253 }
254 }
255 // Other:
256 foreach ($CSHkeys as $cshKey => $value) {
257 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, '_MOD_') && !isset($GLOBALS['TCA'][$cshKey])) {
258 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
259 $this->render_TOC_el($cshKey, 'other', $outputSections, $tocArray, $CSHkeys);
260 }
261 }
262
263 // COMPILE output:
264 $output = '';
265 $output .= '<h1>' . $GLOBALS['LANG']->getLL('manual_title', TRUE) . '</h1>';
266 $output .= '<p class="lead">' . $GLOBALS['LANG']->getLL('description', TRUE) . '</p>';
267
268 $output .= '<h2>' . $GLOBALS['LANG']->getLL('TOC', TRUE) . '</h2>' . $this->render_TOC_makeTocList($tocArray);
269 if (!$this->renderALL) {
270 $output .= '
271 <br/>
272 <p class="c-nav"><a href="mod.php?M=help_cshmanual&renderALL=1">' . $GLOBALS['LANG']->getLL('full_manual', TRUE) . '</a></p>';
273 }
274 if ($this->renderALL) {
275 $output .= '
276
277 <h2>' . $GLOBALS['LANG']->getLL('full_manual_chapters', TRUE) . '</h2>' . implode('
278
279
280 <!-- NEW SECTION: -->
281 ', $outputSections);
282 }
283 $output .= '<hr /><p class="manual-title">' . BackendUtility::TYPO3_copyRightNotice() . '</p>';
284 return $output;
285 }
286
287 /**
288 * Creates a TOC list element and renders corresponding HELP content if "renderALL" mode is set.
289 *
290 * @param string $table CSH key / Table name
291 * @param string $tocCat TOC category keyword: "core", "modules", "tables", "other
292 * @param array $outputSections Array for accumulation of rendered HELP Content (in "renderALL" mode). Passed by reference!
293 * @param array $tocArray TOC array; Here TOC index elements are created. Passed by reference!
294 * @param array $CSHkeys 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!
295 * @return void
296 * @todo Define visibility
297 */
298 public function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys) {
299 // Render full manual right here!
300 if ($this->renderALL) {
301 $outputSections[$table] = $this->render_Table($table);
302 if ($outputSections[$table]) {
303 $outputSections[$table] = '
304
305 <!-- New CSHkey/Table: ' . $table . ' -->
306 <p class="c-nav"><a name="ANCHOR_' . $table . '" href="#">' . $GLOBALS['LANG']->getLL('to_top', TRUE) . '</a></p>
307 <h2>' . $this->getTableFieldLabel($table) . '</h2>
308
309 ' . $outputSections[$table];
310 $tocArray[$tocCat][$table] = '<a href="#ANCHOR_' . $table . '">' . $this->getTableFieldLabel($table) . '</a>';
311 } else {
312 unset($outputSections[$table]);
313 }
314 } else {
315 // Only TOC:
316 $tocArray[$tocCat][$table] = '<p><a href="mod.php?M=help_cshmanual&tfID=' . rawurlencode(($table . '.*')) . '">' . $this->getTableFieldLabel($table) . '</a></p>';
317 }
318 // Unset CSH key:
319 unset($CSHkeys[$table]);
320 }
321
322 /**
323 * Renders the TOC index as a HTML bullet list from TOC array
324 *
325 * @param array $tocArray ToC Array.
326 * @return string HTML bullet list for index.
327 * @todo Define visibility
328 */
329 public function render_TOC_makeTocList($tocArray) {
330 // The Various manual sections:
331 $keys = explode(',', 'core,modules,tables,extensions,glossary,other');
332 // Create TOC bullet list:
333 $output = '';
334 foreach ($keys as $tocKey) {
335 if (is_array($tocArray[$tocKey])) {
336 $output .= '
337 <li>' . $GLOBALS['LANG']->getLL(('TOC_' . $tocKey), TRUE) . '
338 <ul>
339 <li>' . implode('</li>
340 <li>', $tocArray[$tocKey]) . '</li>
341 </ul>
342 </li>';
343 }
344 }
345 // Compile TOC:
346 $output = '
347
348 <!-- TOC: -->
349 <div class="c-toc">
350 <ul>
351 ' . $output . '
352 </ul>
353 </div>';
354 return $output;
355 }
356
357 /**
358 * Render CSH for a full cshKey/table
359 *
360 * @param string $key Full CSH key (may be different from table name)
361 * @param string $table CSH key / table name
362 * @return string HTML output
363 * @todo Define visibility
364 */
365 public function render_Table($key, $table = NULL) {
366 $output = '';
367 // Take default key if not explicitly specified
368 if ($table === NULL) {
369 $table = $key;
370 }
371 // Load descriptions for table $table
372 $GLOBALS['LANG']->loadSingleTableDescription($key);
373 if (is_array($GLOBALS['TCA_DESCR'][$key]['columns']) && (!$this->limitAccess || $GLOBALS['BE_USER']->check('tables_select', $table))) {
374 // Initialize variables:
375 $parts = array();
376 // Reserved for header of table
377 $parts[0] = '';
378 // Traverse table columns as listed in TCA_DESCR
379 foreach ($GLOBALS['TCA_DESCR'][$key]['columns'] as $field => $_) {
380 $fieldValue = isset($GLOBALS['TCA'][$key]) && strcmp($field, '') ? $GLOBALS['TCA'][$key]['columns'][$field] : array();
381 if (is_array($fieldValue) && (!$this->limitAccess || !$fieldValue['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $field))) {
382 if (!$field) {
383 // Header
384 $parts[0] = $this->printItem($key, '', 1);
385 } else {
386 // Field
387 $parts[] = $this->printItem($key, $field, 1);
388 }
389 }
390 }
391 if (!$parts[0]) {
392 unset($parts[0]);
393 }
394 $output .= implode('<br />', $parts);
395 }
396 // Substitute glossary words:
397 $output = $this->substituteGlossaryWords($output);
398 // TOC link:
399 if (!$this->renderALL) {
400 $tocLink = '<p class="c-nav"><a href="mod.php?M=help_cshmanual">' . $GLOBALS['LANG']->getLL('goToToc', TRUE) . '</a></p>';
401 $output = $tocLink . '
402 <br/>' . $output . '
403 <br />' . $tocLink;
404 }
405 return $output;
406 }
407
408 /**
409 * Renders CSH for a single field.
410 *
411 * @param string $key CSH key / table name
412 * @param string $field Sub key / field name
413 * @return string HTML output
414 * @todo Define visibility
415 */
416 public function render_Single($key, $field) {
417 $output = '';
418 // Load the description field
419 $GLOBALS['LANG']->loadSingleTableDescription($key);
420 // Render single item
421 $output .= $this->printItem($key, $field);
422 // Substitute glossary words:
423 $output = $this->substituteGlossaryWords($output);
424 // Link to Full table description and TOC:
425 $getLLKey = $this->limitAccess ? 'fullDescription' : 'fullDescription_module';
426 $output .= '<br />
427 <p class="c-nav"><a href="mod.php?M=help_cshmanual&tfID=' . rawurlencode(($key . '.*')) . '">' . $GLOBALS['LANG']->getLL($getLLKey, TRUE) . '</a></p>
428 <p class="c-nav"><a href="mod.php?M=help_cshmanual">' . $GLOBALS['LANG']->getLL('goToToc', TRUE) . '</a></p>';
429 return $output;
430 }
431
432 /************************************
433 * Rendering CSH items
434 ************************************/
435
436 /**
437 * Make seeAlso links from $value
438 *
439 * @param string $value See-also input codes
440 * @param string $anchorTable If $anchorTable is set to a tablename, then references to this table will be made as anchors, not URLs.
441 * @return string See-also links HTML
442 * @todo Define visibility
443 */
444 public function make_seeAlso($value, $anchorTable = '') {
445 // Split references by comma or linebreak
446 $items = preg_split('/[,' . LF . ']/', $value);
447 $lines = array();
448 foreach ($items as $val) {
449 $val = trim($val);
450 if ($val) {
451 $iP = explode(':', $val);
452 $iPUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('|', $val);
453 // URL reference:
454 if (substr($iPUrl[1], 0, 4) == 'http') {
455 $lines[] = '<a href="' . htmlspecialchars($iPUrl[1]) . '" target="_blank"><em>' . htmlspecialchars($iPUrl[0]) . '</em></a>';
456 } elseif (substr($iPUrl[1], 0, 5) == 'FILE:') {
457 $fileName = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(substr($iPUrl[1], 5), 1, 1);
458 if ($fileName && @is_file($fileName)) {
459 $fileName = '../' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($fileName);
460 $lines[] = '<a href="' . htmlspecialchars($fileName) . '" target="_blank"><em>' . htmlspecialchars($iPUrl[0]) . '</em></a>';
461 }
462 } else {
463 // "table" reference
464 if (!isset($GLOBALS['TCA'][$iP[0]]) || (!$iP[1] || is_array($GLOBALS['TCA'][$iP[0]]['columns'][$iP[1]])) && (!$this->limitAccess || $GLOBALS['BE_USER']->check('tables_select', $iP[0]) && (!$iP[1] || !$GLOBALS['TCA'][$iP[0]]['columns'][$iP[1]]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $iP[0] . ':' . $iP[1])))) {
465 // Checking read access:
466 if (isset($GLOBALS['TCA_DESCR'][$iP[0]])) {
467 // Make see-also link:
468 $href = $this->renderALL || $anchorTable && $iP[0] == $anchorTable ? '#' . implode('.', $iP) : 'mod.php?M=help_cshmanual&tfID=' . rawurlencode(implode('.', $iP)) . '&back=' . $this->tfID;
469 $label = $this->getTableFieldLabel($iP[0], $iP[1], ' / ');
470 $lines[] = '<a href="' . htmlspecialchars($href) . '">' . htmlspecialchars($label) . '</a>';
471 }
472 }
473 }
474 }
475 }
476 return implode('<br />', $lines);
477 }
478
479 /**
480 * Will return an image tag with description in italics.
481 *
482 * @param string $images Image file reference (list of)
483 * @param string $descr Description string (divided for each image by line break)
484 * @return string Image HTML codes
485 * @todo Define visibility
486 */
487 public function printImage($images, $descr) {
488 $code = '';
489 // Splitting:
490 $imgArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $images, TRUE);
491 if (count($imgArray)) {
492 $descrArray = explode(LF, $descr, count($imgArray));
493 foreach ($imgArray as $k => $image) {
494 $descr = $descrArray[$k];
495 $absImagePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($image, 1, 1);
496 if ($absImagePath && @is_file($absImagePath)) {
497 $imgFile = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($absImagePath);
498 $imgInfo = @getimagesize($absImagePath);
499 if (is_array($imgInfo)) {
500 $imgFile = '../' . $imgFile;
501 $code .= '<br /><img src="' . $imgFile . '" ' . $imgInfo[3] . ' class="c-inlineimg" alt="" /><br />
502 ';
503 $code .= '<p><em>' . htmlspecialchars($descr) . '</em></p>
504 ';
505 } else {
506 $code .= '<div style="background-color: red; border: 1px solid black; color: white;">NOT AN IMAGE: ' . $imgFile . '</div>';
507 }
508 } else {
509 $code .= '<div style="background-color: red; border: 1px solid black; color: white;">IMAGE FILE NOT FOUND: ' . $image . '</div>';
510 }
511 }
512 }
513 return $code;
514 }
515
516 /**
517 * Returns header HTML content
518 *
519 * @param string $str Header text
520 * @param integer $type Header type (1, 0)
521 * @return string The HTML for the header.
522 * @todo Define visibility
523 */
524 public function headerLine($str, $type = 0) {
525 switch ($type) {
526 case 1:
527 $str = '<h2 class="t3-row-header">' . htmlspecialchars($str) . '</h2>
528 ';
529 break;
530 case 0:
531 $str = '<h3 class="divider">' . htmlspecialchars($str) . '</h3>
532 ';
533 break;
534 }
535 return $str;
536 }
537
538 /**
539 * Returns prepared content
540 *
541 * @param string $str Content to format.
542 * @return string Formatted content.
543 * @todo Define visibility
544 */
545 public function prepareContent($str) {
546 return '<p>' . nl2br(trim(strip_tags($str, $this->allowedHTML))) . '</p>
547 ';
548 }
549
550 /**
551 * Prints a single $table/$field information piece
552 * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
553 *
554 * @param string $key CSH key / table name
555 * @param string $field Sub key / field name
556 * @param boolean $anchors If anchors is to be shown.
557 * @return string HTML content
558 * @todo Define visibility
559 */
560 public function printItem($key, $field, $anchors = FALSE) {
561 $out = '';
562 if ($key && (!$field || is_array($GLOBALS['TCA_DESCR'][$key]['columns'][$field]))) {
563 // Make seeAlso references.
564 $seeAlsoRes = $this->make_seeAlso($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['seeAlso'], $anchors ? $key : '');
565 // Making item:
566 $out = '<a name="' . $key . '.' . $field . '"></a>' . $this->headerLine($this->getTableFieldLabel($key, $field), 1) . $this->prepareContent($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['description']) . ($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['details'] ? $this->headerLine(($GLOBALS['LANG']->getLL('details') . ':')) . $this->prepareContent($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['details']) : '') . ($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['syntax'] ? $this->headerLine(($GLOBALS['LANG']->getLL('syntax') . ':')) . $this->prepareContent($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['syntax']) : '') . ($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['image'] ? $this->printImage($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['image'], $GLOBALS['TCA_DESCR'][$key]['columns'][$field]['image_descr']) : '') . ($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['seeAlso'] && $seeAlsoRes ? $this->headerLine(($GLOBALS['LANG']->getLL('seeAlso') . ':')) . '<p>' . $seeAlsoRes . '</p>' : '') . ($this->back ? '<br /><p><a href="' . htmlspecialchars(('mod.php?M=help_cshmanual&tfID=' . rawurlencode($this->back))) . '" class="typo3-goBack">' . htmlspecialchars($GLOBALS['LANG']->getLL('goBack')) . '</a></p>' : '') . '<br />';
567 }
568 return $out;
569 }
570
571 /**
572 * Returns labels for a given field in a given structure
573 *
574 * @param string $key CSH key / table name
575 * @param string $field Sub key / field name
576 * @return array Table and field labels in a numeric array
577 * @todo Define visibility
578 */
579 public function getTableFieldNames($key, $field) {
580 $GLOBALS['LANG']->loadSingleTableDescription($key);
581 // Define the label for the key
582 $keyName = $key;
583 if (is_array($GLOBALS['TCA_DESCR'][$key]['columns']['']) && isset($GLOBALS['TCA_DESCR'][$key]['columns']['']['alttitle'])) {
584 // If there's an alternative title, use it
585 $keyName = $GLOBALS['TCA_DESCR'][$key]['columns']['']['alttitle'];
586 } elseif (isset($GLOBALS['TCA'][$key])) {
587 // Otherwise, if it's a table, use its title
588 $keyName = $GLOBALS['TCA'][$key]['ctrl']['title'];
589 } else {
590 // If no title was found, make sure to remove any "_MOD_"
591 $keyName = preg_replace('/^_MOD_/', '', $key);
592 }
593 // Define the label for the field
594 $fieldName = $field;
595 if (is_array($GLOBALS['TCA_DESCR'][$key]['columns'][$field]) && isset($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['alttitle'])) {
596 // If there's an alternative title, use it
597 $fieldName = $GLOBALS['TCA_DESCR'][$key]['columns'][$field]['alttitle'];
598 } elseif (isset($GLOBALS['TCA'][$key]) && isset($GLOBALS['TCA'][$key]['columns'][$field])) {
599 // Otherwise, if it's a table, use its title
600 $fieldName = $GLOBALS['TCA'][$key]['columns'][$field]['label'];
601 }
602 return array($keyName, $fieldName);
603 }
604
605 /**
606 * Returns composite label for table/field
607 *
608 * @param string $key CSH key / table name
609 * @param string $field Sub key / field name
610 * @param string $mergeToken Token to merge the two strings with
611 * @return string Labels joined with merge token
612 * @see getTableFieldNames()
613 * @todo Define visibility
614 */
615 public function getTableFieldLabel($key, $field = '', $mergeToken = ': ') {
616 $tableName = '';
617 $fieldName = '';
618 // Get table / field parts:
619 list($tableName, $fieldName) = $this->getTableFieldNames($key, $field);
620 // Create label:
621 $labelString = $GLOBALS['LANG']->sL($tableName) . ($field ? $mergeToken . rtrim(trim($GLOBALS['LANG']->sL($fieldName)), ':') : '');
622 return $labelString;
623 }
624
625 /******************************
626 * Glossary related
627 ******************************/
628
629 /**
630 * Creates glossary index in $this->glossaryWords
631 * Glossary is cached in cache_hash cache and so will be updated only when cache is cleared.
632 *
633 * @return void
634 * @todo Define visibility
635 */
636 public function createGlossaryIndex() {
637 // Create hash string and try to retrieve glossary array:
638 $hash = md5('typo3/mod.php?M=help_cshmanual:glossary');
639 $cachedData = BackendUtility::getHash($hash);
640 // Generate glossary words if not found:
641 if (is_array($cachedData)) {
642 list($this->glossaryWords, $this->substWords) = $cachedData;
643 } else {
644 // Initialize:
645 $this->glossaryWords = array();
646 $this->substWords = array();
647 $CSHkeys = array_flip(array_keys($GLOBALS['TCA_DESCR']));
648 // Glossary
649 foreach ($CSHkeys as $cshKey => $value) {
650 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($GLOBALS['TCA'][$cshKey])) {
651 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
652 if (is_array($GLOBALS['TCA_DESCR'][$cshKey]['columns'])) {
653 // Traverse table columns as listed in TCA_DESCR
654 foreach ($GLOBALS['TCA_DESCR'][$cshKey]['columns'] as $field => $data) {
655 if ($field) {
656 $this->glossaryWords[$cshKey . '.' . $field] = array(
657 'title' => trim($data['alttitle'] ? $data['alttitle'] : $cshKey),
658 'description' => str_replace('%22', '%23%23%23', rawurlencode($data['description']))
659 );
660 }
661 }
662 }
663 }
664 }
665 // First, create unique list of words:
666 foreach ($this->glossaryWords as $key => $value) {
667 // Making word lowercase in order to filter out same words in different cases.
668 $word = strtolower($value['title']);
669 if ($word !== '') {
670 $this->substWords[$word] = $value;
671 $this->substWords[$word]['key'] = $key;
672 }
673 }
674 krsort($this->substWords);
675 BackendUtility::storeHash($hash, array($this->glossaryWords, $this->substWords), 'Glossary');
676 }
677 }
678
679 /**
680 * Processing of all non-HTML content in the output
681 * Will be done by a call-back to ->substituteGlossaryWords_htmlcleaner_callback()
682 *
683 * @param string $code Input HTML code
684 * @return string Output HTML code
685 * @todo Define visibility
686 */
687 public function substituteGlossaryWords($code) {
688 $htmlParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Html\HtmlParser');
689 $htmlParser->pObj = $this;
690 $code = $htmlParser->HTMLcleaner($code, array(), 1);
691 return $code;
692 }
693
694 /**
695 * Substituting glossary words in the CSH
696 * This is a call-back function from "class local_t3lib_parsehtml
697 * extends \TYPO3\CMS\Core\Html\HtmlParser", see top of this script
698 *
699 * @param string $code Input HTML string
700 * @return string HTML with substituted words in.
701 * @todo Define visibility
702 */
703 public function substituteGlossaryWords_htmlcleaner_callback($code) {
704 if (is_array($this->substWords) && count($this->substWords) && strlen(trim($code))) {
705 // Substitute words:
706 foreach ($this->substWords as $wordKey => $wordSet) {
707 // quoteMeta used so special chars (which should not occur though) in words will not break the regex. Seemed to work (- kasper)
708 $parts = preg_split('/( |[\\(])(' . quoteMeta($wordSet['title']) . ')([\\.\\!\\)\\?\\:\\,]+| )/i', ' ' . $code . ' ', 2, PREG_SPLIT_DELIM_CAPTURE);
709 if (count($parts) == 5) {
710 $parts[2] = '<a class="glossary-term" href="' . htmlspecialchars(('mod.php?M=help_cshmanual&tfID=' . rawurlencode($wordSet['key']) . '&back=' . $this->tfID)) . '" title="' . rawurlencode(htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(rawurldecode($wordSet['description']), 80))) . '">' . htmlspecialchars($parts[2]) . '</a>';
711 $code = substr(implode('', $parts), 1, -1);
712 // Disable entry so it doesn't get used next time:
713 unset($this->substWords[$wordKey]);
714 }
715 }
716 $code = str_replace('###', '&quot;', rawurldecode($code));
717 }
718 return $code;
719 }
720
721 }