4c58f6d77100cd18b5bb1e933718fc77076200a3
[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 text file 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 if ($this->field == '*') {
166 // If ALL fields is supposed to be shown:
167 $this->createGlossaryIndex();
168 $this->content .= $this->render_Table($this->mainKey);
169 } elseif ($this->tfID) {
170 // ... otherwise show only single field:
171 $this->createGlossaryIndex();
172 $this->content .= $this->render_Single($this->mainKey, $this->field);
173 } else {
174 // Render Table Of Contents if nothing else:
175 $this->content .= $this->render_TOC();
176 }
177
178 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
179 $this->doc->backPath = $GLOBALS['BACK_PATH'];
180 $this->doc->setModuleTemplate('EXT:cshmanual/Resources/Private/Templates/cshmanual.html');
181
182 $markers = array('CONTENT' => $this->content);
183
184 $this->content = $this->doc->moduleBody(array(), array(), $markers);
185 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
186 }
187
188 /**
189 * Outputting the accumulated content to screen
190 *
191 * @return void
192 * @todo Define visibility
193 */
194 public function printContent() {
195 echo $this->content;
196 }
197
198 /************************************
199 * Rendering main modes
200 ************************************/
201
202 /**
203 * Creates Table Of Contents and possibly "Full Manual" mode if selected.
204 *
205 * @return string HTML content
206 * @todo Define visibility
207 */
208 public function render_TOC() {
209 // Initialize:
210 $CSHkeys = array_flip(array_keys($GLOBALS['TCA_DESCR']));
211 $TCAkeys = array_keys($GLOBALS['TCA']);
212 $outputSections = array();
213 $tocArray = array();
214 // TYPO3 Core Features:
215 $GLOBALS['LANG']->loadSingleTableDescription('xMOD_csh_corebe');
216 $this->render_TOC_el('xMOD_csh_corebe', 'core', $outputSections, $tocArray, $CSHkeys);
217 // Backend Modules:
218 $loadModules = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleLoader');
219 $loadModules->load($GLOBALS['TBE_MODULES']);
220 foreach ($loadModules->modules as $mainMod => $info) {
221 $cshKey = '_MOD_' . $mainMod;
222 if ($CSHkeys[$cshKey]) {
223 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
224 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
225 }
226 if (is_array($info['sub'])) {
227 foreach ($info['sub'] as $subMod => $subInfo) {
228 $cshKey = '_MOD_' . $mainMod . '_' . $subMod;
229 if ($CSHkeys[$cshKey]) {
230 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
231 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
232 }
233 }
234 }
235 }
236 // Database Tables:
237 foreach ($TCAkeys as $table) {
238 // Load descriptions for table $table
239 $GLOBALS['LANG']->loadSingleTableDescription($table);
240 if (is_array($GLOBALS['TCA_DESCR'][$table]['columns']) && $GLOBALS['BE_USER']->check('tables_select', $table)) {
241 $this->render_TOC_el($table, 'tables', $outputSections, $tocArray, $CSHkeys);
242 }
243 }
244 // Extensions
245 foreach ($CSHkeys as $cshKey => $value) {
246 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, 'xEXT_') && !isset($GLOBALS['TCA'][$cshKey])) {
247 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
248 $this->render_TOC_el($cshKey, 'extensions', $outputSections, $tocArray, $CSHkeys);
249 }
250 }
251 // Glossary
252 foreach ($CSHkeys as $cshKey => $value) {
253 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($GLOBALS['TCA'][$cshKey])) {
254 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
255 $this->render_TOC_el($cshKey, 'glossary', $outputSections, $tocArray, $CSHkeys);
256 }
257 }
258 // Other:
259 foreach ($CSHkeys as $cshKey => $value) {
260 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, '_MOD_') && !isset($GLOBALS['TCA'][$cshKey])) {
261 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
262 $this->render_TOC_el($cshKey, 'other', $outputSections, $tocArray, $CSHkeys);
263 }
264 }
265
266 // COMPILE output:
267 $output = '';
268 $output .= '<h1>' . $GLOBALS['LANG']->getLL('manual_title', TRUE) . '</h1>';
269 $output .= '<p class="lead">' . $GLOBALS['LANG']->getLL('description', TRUE) . '</p>';
270
271 $output .= '<h2>' . $GLOBALS['LANG']->getLL('TOC', TRUE) . '</h2>' . $this->render_TOC_makeTocList($tocArray);
272 if (!$this->renderALL) {
273 $output .= '
274 <br/>
275 <p class="c-nav"><a href="mod.php?M=help_cshmanual&renderALL=1">' . $GLOBALS['LANG']->getLL('full_manual', TRUE) . '</a></p>';
276 }
277 if ($this->renderALL) {
278 $output .= '
279
280 <h2>' . $GLOBALS['LANG']->getLL('full_manual_chapters', TRUE) . '</h2>' . implode('
281
282
283 <!-- NEW SECTION: -->
284 ', $outputSections);
285 }
286 $output .= '<hr /><p class="manual-title">' . BackendUtility::TYPO3_copyRightNotice() . '</p>';
287 return $output;
288 }
289
290 /**
291 * Creates a TOC list element and renders corresponding HELP content if "renderALL" mode is set.
292 *
293 * @param string $table CSH key / Table name
294 * @param string $tocCat TOC category keyword: "core", "modules", "tables", "other
295 * @param array $outputSections Array for accumulation of rendered HELP Content (in "renderALL" mode). Passed by reference!
296 * @param array $tocArray TOC array; Here TOC index elements are created. Passed by reference!
297 * @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!
298 * @return void
299 * @todo Define visibility
300 */
301 public function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys) {
302 // Render full manual right here!
303 if ($this->renderALL) {
304 $outputSections[$table] = $this->render_Table($table);
305 if ($outputSections[$table]) {
306 $outputSections[$table] = '
307
308 <!-- New CSHkey/Table: ' . $table . ' -->
309 <p class="c-nav"><a name="ANCHOR_' . $table . '" href="#">' . $GLOBALS['LANG']->getLL('to_top', TRUE) . '</a></p>
310 <h2>' . $this->getTableFieldLabel($table) . '</h2>
311
312 ' . $outputSections[$table];
313 $tocArray[$tocCat][$table] = '<a href="#ANCHOR_' . $table . '">' . $this->getTableFieldLabel($table) . '</a>';
314 } else {
315 unset($outputSections[$table]);
316 }
317 } else {
318 // Only TOC:
319 $tocArray[$tocCat][$table] = '<p><a href="mod.php?M=help_cshmanual&tfID=' . rawurlencode(($table . '.*')) . '">' . $this->getTableFieldLabel($table) . '</a></p>';
320 }
321 // Unset CSH key:
322 unset($CSHkeys[$table]);
323 }
324
325 /**
326 * Renders the TOC index as a HTML bullet list from TOC array
327 *
328 * @param array $tocArray ToC Array.
329 * @return string HTML bullet list for index.
330 * @todo Define visibility
331 */
332 public function render_TOC_makeTocList($tocArray) {
333 // The Various manual sections:
334 $keys = explode(',', 'core,modules,tables,extensions,glossary,other');
335 // Create TOC bullet list:
336 $output = '';
337 foreach ($keys as $tocKey) {
338 if (is_array($tocArray[$tocKey])) {
339 $output .= '
340 <li>' . $GLOBALS['LANG']->getLL(('TOC_' . $tocKey), TRUE) . '
341 <ul>
342 <li>' . implode('</li>
343 <li>', $tocArray[$tocKey]) . '</li>
344 </ul>
345 </li>';
346 }
347 }
348 // Compile TOC:
349 $output = '
350
351 <!-- TOC: -->
352 <div class="c-toc">
353 <ul>
354 ' . $output . '
355 </ul>
356 </div>';
357 return $output;
358 }
359
360 /**
361 * Render CSH for a full cshKey/table
362 *
363 * @param string $key Full CSH key (may be different from table name)
364 * @param string $table CSH key / table name
365 * @return string HTML output
366 * @todo Define visibility
367 */
368 public function render_Table($key, $table = NULL) {
369 $output = '';
370 // Take default key if not explicitly specified
371 if ($table === NULL) {
372 $table = $key;
373 }
374 // Load descriptions for table $table
375 $GLOBALS['LANG']->loadSingleTableDescription($key);
376 if (is_array($GLOBALS['TCA_DESCR'][$key]['columns']) && (!$this->limitAccess || $GLOBALS['BE_USER']->check('tables_select', $table))) {
377 // Initialize variables:
378 $parts = array();
379 // Reserved for header of table
380 $parts[0] = '';
381 // Traverse table columns as listed in TCA_DESCR
382 foreach ($GLOBALS['TCA_DESCR'][$key]['columns'] as $field => $_) {
383 $fieldValue = isset($GLOBALS['TCA'][$key]) && (string)$field !== '' ? $GLOBALS['TCA'][$key]['columns'][$field] : array();
384 if (is_array($fieldValue) && (!$this->limitAccess || !$fieldValue['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $field))) {
385 if (!$field) {
386 // Header
387 $parts[0] = $this->printItem($key, '', 1);
388 } else {
389 // Field
390 $parts[] = $this->printItem($key, $field, 1);
391 }
392 }
393 }
394 if (!$parts[0]) {
395 unset($parts[0]);
396 }
397 $output .= implode('<br />', $parts);
398 }
399 // Substitute glossary words:
400 $output = $this->substituteGlossaryWords($output);
401 // TOC link:
402 if (!$this->renderALL) {
403 $tocLink = '<p class="c-nav"><a href="mod.php?M=help_cshmanual">' . $GLOBALS['LANG']->getLL('goToToc', TRUE) . '</a></p>';
404 $output = $tocLink . '
405 <br/>' . $output . '
406 <br />' . $tocLink;
407 }
408 return $output;
409 }
410
411 /**
412 * Renders CSH for a single field.
413 *
414 * @param string $key CSH key / table name
415 * @param string $field Sub key / field name
416 * @return string HTML output
417 * @todo Define visibility
418 */
419 public function render_Single($key, $field) {
420 $output = '';
421 // Load the description field
422 $GLOBALS['LANG']->loadSingleTableDescription($key);
423 // Render single item
424 $output .= $this->printItem($key, $field);
425 // Substitute glossary words:
426 $output = $this->substituteGlossaryWords($output);
427 // Link to Full table description and TOC:
428 $getLLKey = $this->limitAccess ? 'fullDescription' : 'fullDescription_module';
429 $output .= '<br />
430 <p class="c-nav"><a href="mod.php?M=help_cshmanual&tfID=' . rawurlencode(($key . '.*')) . '">' . $GLOBALS['LANG']->getLL($getLLKey, TRUE) . '</a></p>
431 <p class="c-nav"><a href="mod.php?M=help_cshmanual">' . $GLOBALS['LANG']->getLL('goToToc', TRUE) . '</a></p>';
432 return $output;
433 }
434
435 /************************************
436 * Rendering CSH items
437 ************************************/
438
439 /**
440 * Make seeAlso links from $value
441 *
442 * @param string $value See-also input codes
443 * @param string $anchorTable If $anchorTable is set to a tablename, then references to this table will be made as anchors, not URLs.
444 * @return string See-also links HTML
445 * @todo Define visibility
446 */
447 public function make_seeAlso($value, $anchorTable = '') {
448 // Split references by comma or linebreak
449 $items = preg_split('/[,' . LF . ']/', $value);
450 $lines = array();
451 foreach ($items as $val) {
452 $val = trim($val);
453 if ($val) {
454 $iP = explode(':', $val);
455 $iPUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('|', $val);
456 // URL reference:
457 if (substr($iPUrl[1], 0, 4) == 'http') {
458 $lines[] = '<a href="' . htmlspecialchars($iPUrl[1]) . '" target="_blank"><em>' . htmlspecialchars($iPUrl[0]) . '</em></a>';
459 } elseif (substr($iPUrl[1], 0, 5) == 'FILE:') {
460 $fileName = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(substr($iPUrl[1], 5), 1, 1);
461 if ($fileName && @is_file($fileName)) {
462 $fileName = '../' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($fileName);
463 $lines[] = '<a href="' . htmlspecialchars($fileName) . '" target="_blank"><em>' . htmlspecialchars($iPUrl[0]) . '</em></a>';
464 }
465 } else {
466 // "table" reference
467 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])))) {
468 // Checking read access:
469 if (isset($GLOBALS['TCA_DESCR'][$iP[0]])) {
470 // Make see-also link:
471 $href = $this->renderALL || $anchorTable && $iP[0] == $anchorTable ? '#' . implode('.', $iP) : 'mod.php?M=help_cshmanual&tfID=' . rawurlencode(implode('.', $iP)) . '&back=' . $this->tfID;
472 $label = $this->getTableFieldLabel($iP[0], $iP[1], ' / ');
473 $lines[] = '<a href="' . htmlspecialchars($href) . '">' . htmlspecialchars($label) . '</a>';
474 }
475 }
476 }
477 }
478 }
479 return implode('<br />', $lines);
480 }
481
482 /**
483 * Will return an image tag with description in italics.
484 *
485 * @param string $images Image file reference (list of)
486 * @param string $descr Description string (divided for each image by line break)
487 * @return string Image HTML codes
488 * @todo Define visibility
489 */
490 public function printImage($images, $descr) {
491 $code = '';
492 // Splitting:
493 $imgArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $images, TRUE);
494 if (count($imgArray)) {
495 $descrArray = explode(LF, $descr, count($imgArray));
496 foreach ($imgArray as $k => $image) {
497 $descr = $descrArray[$k];
498 $absImagePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($image, 1, 1);
499 if ($absImagePath && @is_file($absImagePath)) {
500 $imgFile = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($absImagePath);
501 $imgInfo = @getimagesize($absImagePath);
502 if (is_array($imgInfo)) {
503 $imgFile = '../' . $imgFile;
504 $code .= '<br /><img src="' . $imgFile . '" ' . $imgInfo[3] . ' class="c-inlineimg" alt="" /><br />
505 ';
506 $code .= '<p><em>' . htmlspecialchars($descr) . '</em></p>
507 ';
508 } else {
509 $code .= '<div style="background-color: red; border: 1px solid black; color: white;">NOT AN IMAGE: ' . $imgFile . '</div>';
510 }
511 } else {
512 $code .= '<div style="background-color: red; border: 1px solid black; color: white;">IMAGE FILE NOT FOUND: ' . $image . '</div>';
513 }
514 }
515 }
516 return $code;
517 }
518
519 /**
520 * Returns header HTML content
521 *
522 * @param string $str Header text
523 * @param integer $type Header type (1, 0)
524 * @return string The HTML for the header.
525 * @todo Define visibility
526 */
527 public function headerLine($str, $type = 0) {
528 switch ($type) {
529 case 1:
530 $str = '<h2 class="t3-row-header">' . htmlspecialchars($str) . '</h2>
531 ';
532 break;
533 case 0:
534 $str = '<h3 class="divider">' . htmlspecialchars($str) . '</h3>
535 ';
536 break;
537 }
538 return $str;
539 }
540
541 /**
542 * Returns prepared content
543 *
544 * @param string $str Content to format.
545 * @return string Formatted content.
546 * @todo Define visibility
547 */
548 public function prepareContent($str) {
549 return '<p>' . nl2br(trim(strip_tags($str, $this->allowedHTML))) . '</p>
550 ';
551 }
552
553 /**
554 * Prints a single $table/$field information piece
555 * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
556 *
557 * @param string $key CSH key / table name
558 * @param string $field Sub key / field name
559 * @param boolean $anchors If anchors is to be shown.
560 * @return string HTML content
561 * @todo Define visibility
562 */
563 public function printItem($key, $field, $anchors = FALSE) {
564 $out = '';
565 if ($key && (!$field || is_array($GLOBALS['TCA_DESCR'][$key]['columns'][$field]))) {
566 // Make seeAlso references.
567 $seeAlsoRes = $this->make_seeAlso($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['seeAlso'], $anchors ? $key : '');
568 // Making item:
569 $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 />';
570 }
571 return $out;
572 }
573
574 /**
575 * Returns labels for a given field in a given structure
576 *
577 * @param string $key CSH key / table name
578 * @param string $field Sub key / field name
579 * @return array Table and field labels in a numeric array
580 * @todo Define visibility
581 */
582 public function getTableFieldNames($key, $field) {
583 $GLOBALS['LANG']->loadSingleTableDescription($key);
584 // Define the label for the key
585 $keyName = $key;
586 if (is_array($GLOBALS['TCA_DESCR'][$key]['columns']['']) && isset($GLOBALS['TCA_DESCR'][$key]['columns']['']['alttitle'])) {
587 // If there's an alternative title, use it
588 $keyName = $GLOBALS['TCA_DESCR'][$key]['columns']['']['alttitle'];
589 } elseif (isset($GLOBALS['TCA'][$key])) {
590 // Otherwise, if it's a table, use its title
591 $keyName = $GLOBALS['TCA'][$key]['ctrl']['title'];
592 } else {
593 // If no title was found, make sure to remove any "_MOD_"
594 $keyName = preg_replace('/^_MOD_/', '', $key);
595 }
596 // Define the label for the field
597 $fieldName = $field;
598 if (is_array($GLOBALS['TCA_DESCR'][$key]['columns'][$field]) && isset($GLOBALS['TCA_DESCR'][$key]['columns'][$field]['alttitle'])) {
599 // If there's an alternative title, use it
600 $fieldName = $GLOBALS['TCA_DESCR'][$key]['columns'][$field]['alttitle'];
601 } elseif (isset($GLOBALS['TCA'][$key]) && isset($GLOBALS['TCA'][$key]['columns'][$field])) {
602 // Otherwise, if it's a table, use its title
603 $fieldName = $GLOBALS['TCA'][$key]['columns'][$field]['label'];
604 }
605 return array($keyName, $fieldName);
606 }
607
608 /**
609 * Returns composite label for table/field
610 *
611 * @param string $key CSH key / table name
612 * @param string $field Sub key / field name
613 * @param string $mergeToken Token to merge the two strings with
614 * @return string Labels joined with merge token
615 * @see getTableFieldNames()
616 * @todo Define visibility
617 */
618 public function getTableFieldLabel($key, $field = '', $mergeToken = ': ') {
619 $tableName = '';
620 $fieldName = '';
621 // Get table / field parts:
622 list($tableName, $fieldName) = $this->getTableFieldNames($key, $field);
623 // Create label:
624 $labelString = $GLOBALS['LANG']->sL($tableName) . ($field ? $mergeToken . rtrim(trim($GLOBALS['LANG']->sL($fieldName)), ':') : '');
625 return $labelString;
626 }
627
628 /******************************
629 * Glossary related
630 ******************************/
631
632 /**
633 * Creates glossary index in $this->glossaryWords
634 * Glossary is cached in cache_hash cache and so will be updated only when cache is cleared.
635 *
636 * @return void
637 * @todo Define visibility
638 */
639 public function createGlossaryIndex() {
640 // Create hash string and try to retrieve glossary array:
641 $hash = md5('typo3/mod.php?M=help_cshmanual:glossary');
642 $cachedData = BackendUtility::getHash($hash);
643 // Generate glossary words if not found:
644 if (is_array($cachedData)) {
645 list($this->glossaryWords, $this->substWords) = $cachedData;
646 } else {
647 // Initialize:
648 $this->glossaryWords = array();
649 $this->substWords = array();
650 $CSHkeys = array_flip(array_keys($GLOBALS['TCA_DESCR']));
651 // Glossary
652 foreach ($CSHkeys as $cshKey => $value) {
653 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($GLOBALS['TCA'][$cshKey])) {
654 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
655 if (is_array($GLOBALS['TCA_DESCR'][$cshKey]['columns'])) {
656 // Traverse table columns as listed in TCA_DESCR
657 foreach ($GLOBALS['TCA_DESCR'][$cshKey]['columns'] as $field => $data) {
658 if ($field) {
659 $this->glossaryWords[$cshKey . '.' . $field] = array(
660 'title' => trim($data['alttitle'] ?: $cshKey),
661 'description' => str_replace('%22', '%23%23%23', rawurlencode($data['description']))
662 );
663 }
664 }
665 }
666 }
667 }
668 // First, create unique list of words:
669 foreach ($this->glossaryWords as $key => $value) {
670 // Making word lowercase in order to filter out same words in different cases.
671 $word = strtolower($value['title']);
672 if ($word !== '') {
673 $this->substWords[$word] = $value;
674 $this->substWords[$word]['key'] = $key;
675 }
676 }
677 krsort($this->substWords);
678 BackendUtility::storeHash($hash, array($this->glossaryWords, $this->substWords), 'Glossary');
679 }
680 }
681
682 /**
683 * Processing of all non-HTML content in the output
684 * Will be done by a call-back to ->substituteGlossaryWords_htmlcleaner_callback()
685 *
686 * @param string $code Input HTML code
687 * @return string Output HTML code
688 * @todo Define visibility
689 */
690 public function substituteGlossaryWords($code) {
691 $htmlParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Html\HtmlParser');
692 $htmlParser->pObj = $this;
693 $code = $htmlParser->HTMLcleaner($code, array(), 1);
694 return $code;
695 }
696
697 /**
698 * Substituting glossary words in the CSH
699 * This is a call-back function from "class local_t3lib_parsehtml
700 * extends \TYPO3\CMS\Core\Html\HtmlParser", see top of this script
701 *
702 * @param string $code Input HTML string
703 * @return string HTML with substituted words in.
704 * @todo Define visibility
705 */
706 public function substituteGlossaryWords_htmlcleaner_callback($code) {
707 if (is_array($this->substWords) && count($this->substWords) && strlen(trim($code))) {
708 // Substitute words:
709 foreach ($this->substWords as $wordKey => $wordSet) {
710 // quoteMeta used so special chars (which should not occur though) in words will not break the regex. Seemed to work (- kasper)
711 $parts = preg_split('/( |[\\(])(' . quoteMeta($wordSet['title']) . ')([\\.\\!\\)\\?\\:\\,]+| )/i', ' ' . $code . ' ', 2, PREG_SPLIT_DELIM_CAPTURE);
712 if (count($parts) == 5) {
713 $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>';
714 $code = substr(implode('', $parts), 1, -1);
715 // Disable entry so it doesn't get used next time:
716 unset($this->substWords[$wordKey]);
717 }
718 }
719 $code = str_replace('###', '&quot;', rawurldecode($code));
720 }
721 return $code;
722 }
723
724 }