[TASK] Merge submodule extbase into core
[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 /**
31 * 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.
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 class HelpModuleController {
36
37 /**
38 * @todo Define visibility
39 */
40 public $allowedHTML = '<strong><em><b><i>';
41
42 /**
43 * For these vars, see init()
44 * If set access to fields and tables is checked. Should be done for TRUE database tables.
45 *
46 * @todo Define visibility
47 */
48 public $limitAccess;
49
50 /**
51 * The "table" key
52 *
53 * @todo Define visibility
54 */
55 public $table;
56
57 /**
58 * The "field" key
59 *
60 * @todo Define visibility
61 */
62 public $field;
63
64 /**
65 * Key used to point to the right CSH resource
66 * In simple cases, is equal to $table
67 *
68 * @var string
69 */
70 protected $mainKey;
71
72 /**
73 * Internal, static: GPvar
74 * Table/Field id
75 *
76 * @todo Define visibility
77 */
78 public $tfID;
79
80 /**
81 * Back (previous tfID)
82 *
83 * @todo Define visibility
84 */
85 public $back;
86
87 /**
88 * If set, then in TOC mode the FULL manual will be printed as well!
89 *
90 * @todo Define visibility
91 */
92 public $renderALL;
93
94 /**
95 * Content accumulation
96 *
97 * @todo Define visibility
98 */
99 public $content;
100
101 /**
102 * Glossary words
103 *
104 * @todo Define visibility
105 */
106 public $glossaryWords;
107
108 /**
109 * Initialize the class for various input etc.
110 *
111 * @return void
112 * @todo Define visibility
113 */
114 public function init() {
115 // Setting GPvars:
116 $this->tfID = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tfID');
117 // Sanitizes the tfID using whitelisting.
118 if (!preg_match('/^[a-zA-Z0-9_\\-\\.\\*]*$/', $this->tfID)) {
119 $this->tfID = '';
120 }
121 $this->back = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('back');
122 $this->renderALL = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('renderALL');
123 // Set internal table/field to the parts of "tfID" incoming var.
124 $identifierParts = explode('.', $this->tfID);
125 // The table is the first item
126 $this->table = array_shift($identifierParts);
127 $this->mainKey = $this->table;
128 // The field is the second one
129 $this->field = array_shift($identifierParts);
130 // There may be extra parts for FlexForms
131 if (count($identifierParts) > 0) {
132 // There's at least one extra part
133 $extraIdentifierInformation = array();
134 $extraIdentifierInformation[] = array_shift($identifierParts);
135 // If the ds_pointerField contains a comma, it means the choice of FlexForm DS
136 // is determined by 2 parameters. In this case we have an extra identifier part
137 if (strpos($GLOBALS['TCA'][$this->table]['columns'][$this->field]['config']['ds_pointerField'], ',') !== FALSE) {
138 $extraIdentifierInformation[] = array_shift($identifierParts);
139 }
140 // The remaining parts make up the FlexForm field name itself
141 // (reassembled with dots)
142 $flexFormField = implode('.', $identifierParts);
143 // Assemble a different main key and switch field to use FlexForm field name
144 $this->mainKey .= '.' . $this->field;
145 foreach ($extraIdentifierInformation as $extraKey) {
146 $this->mainKey .= '.' . $extraKey;
147 }
148 $this->field = $flexFormField;
149 }
150 // limitAccess is checked if the $this->table really IS a table (and if the user is NOT a translator who should see all!)
151 $showAllToUser = \TYPO3\CMS\Backend\Utility\BackendUtility::isModuleSetInTBE_MODULES('txllxmltranslateM1') && $GLOBALS['BE_USER']->check('modules', 'txllxmltranslateM1');
152 $this->limitAccess = isset($GLOBALS['TCA'][$this->table]) ? !$showAllToUser : FALSE;
153 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_view_help.xlf', 1);
154 }
155
156 /**
157 * Main function, rendering the display
158 *
159 * @return void
160 * @todo Define visibility
161 */
162 public function main() {
163 // Start HTML output accumulation:
164 $GLOBALS['TBE_TEMPLATE']->divClass = 'typo3-view-help';
165 $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage($GLOBALS['LANG']->getLL('title'));
166 if ($this->field == '*') {
167 // If ALL fields is supposed to be shown:
168 $this->createGlossaryIndex();
169 $this->content .= $this->render_Table($this->mainKey);
170 } elseif ($this->tfID) {
171 // ... otherwise show only single field:
172 $this->createGlossaryIndex();
173 $this->content .= $this->render_Single($this->mainKey, $this->field);
174 } else {
175 // Render Table Of Contents if nothing else:
176 $this->content .= $this->render_TOC();
177 }
178 // End page:
179 $this->content .= '<br/>';
180 $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage();
181 }
182
183 /**
184 * Outputting the accumulated content to screen
185 *
186 * @return void
187 * @todo Define visibility
188 */
189 public function printContent() {
190 echo $this->content;
191 }
192
193 /************************************
194 * Rendering main modes
195 ************************************/
196
197 /**
198 * Creates Table Of Contents and possibly "Full Manual" mode if selected.
199 *
200 * @return string HTML content
201 * @todo Define visibility
202 */
203 public function render_TOC() {
204 // Initialize:
205 $CSHkeys = array_flip(array_keys($GLOBALS['TCA_DESCR']));
206 $TCAkeys = array_keys($GLOBALS['TCA']);
207 $outputSections = array();
208 $tocArray = array();
209 // TYPO3 Core Features:
210 $GLOBALS['LANG']->loadSingleTableDescription('xMOD_csh_corebe');
211 $this->render_TOC_el('xMOD_csh_corebe', 'core', $outputSections, $tocArray, $CSHkeys);
212 // Backend Modules:
213 $loadModules = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleLoader');
214 $loadModules->load($GLOBALS['TBE_MODULES']);
215 foreach ($loadModules->modules as $mainMod => $info) {
216 $cshKey = '_MOD_' . $mainMod;
217 if ($CSHkeys[$cshKey]) {
218 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
219 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
220 }
221 if (is_array($info['sub'])) {
222 foreach ($info['sub'] as $subMod => $subInfo) {
223 $cshKey = '_MOD_' . $mainMod . '_' . $subMod;
224 if ($CSHkeys[$cshKey]) {
225 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
226 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys);
227 }
228 }
229 }
230 }
231 // Database Tables:
232 foreach ($TCAkeys as $table) {
233 // Load descriptions for table $table
234 $GLOBALS['LANG']->loadSingleTableDescription($table);
235 if (is_array($GLOBALS['TCA_DESCR'][$table]['columns']) && $GLOBALS['BE_USER']->check('tables_select', $table)) {
236 $this->render_TOC_el($table, 'tables', $outputSections, $tocArray, $CSHkeys);
237 }
238 }
239 // Extensions
240 foreach ($CSHkeys as $cshKey => $value) {
241 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, 'xEXT_') && !isset($GLOBALS['TCA'][$cshKey])) {
242 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
243 $this->render_TOC_el($cshKey, 'extensions', $outputSections, $tocArray, $CSHkeys);
244 }
245 }
246 // Glossary
247 foreach ($CSHkeys as $cshKey => $value) {
248 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($GLOBALS['TCA'][$cshKey])) {
249 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
250 $this->render_TOC_el($cshKey, 'glossary', $outputSections, $tocArray, $CSHkeys);
251 }
252 }
253 // Other:
254 foreach ($CSHkeys as $cshKey => $value) {
255 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, '_MOD_') && !isset($GLOBALS['TCA'][$cshKey])) {
256 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
257 $this->render_TOC_el($cshKey, 'other', $outputSections, $tocArray, $CSHkeys);
258 }
259 }
260 // COMPILE output:
261 $output = '';
262 $output .= '
263
264 <h1>' . $GLOBALS['LANG']->getLL('manual_title', 1) . '</h1>';
265 $output .= '
266
267 <h2>' . $GLOBALS['LANG']->getLL('introduction', 1) . '</h2>
268 <p>' . $GLOBALS['LANG']->getLL('description', 1) . '</p>';
269 $output .= '
270
271 <h2>' . $GLOBALS['LANG']->getLL('TOC', 1) . '</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', 1) . '</a></p>';
276 }
277 if ($this->renderALL) {
278 $output .= '
279
280 <h2>' . $GLOBALS['LANG']->getLL('full_manual_chapters', 1) . '</h2>' . implode('
281
282
283 <!-- NEW SECTION: -->
284 ', $outputSections);
285 }
286 $output .= '<hr /><p class="manual-title">' . \TYPO3\CMS\Backend\Utility\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', 1) . '</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), 1) . '
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]) && strcmp($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', 1) . '</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, 1) . '</a></p>
431 <p class="c-nav"><a href="mod.php?M=help_cshmanual">' . $GLOBALS['LANG']->getLL('goToToc', 1) . '</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 = '../' . substr($fileName, strlen(PATH_site));
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, 1);
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 = substr($absImagePath, strlen(PATH_site));
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 list($this->glossaryWords, $this->substWords) = unserialize(\TYPO3\CMS\Backend\Utility\BackendUtility::getHash($hash));
643 // Generate glossary words if not found:
644 if (!is_array($this->glossaryWords)) {
645 // Initialize:
646 $this->glossaryWords = array();
647 $this->substWords = array();
648 $CSHkeys = array_flip(array_keys($GLOBALS['TCA_DESCR']));
649 // Glossary
650 foreach ($CSHkeys as $cshKey => $value) {
651 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($cshKey, 'xGLOSSARY_') && !isset($GLOBALS['TCA'][$cshKey])) {
652 $GLOBALS['LANG']->loadSingleTableDescription($cshKey);
653 if (is_array($GLOBALS['TCA_DESCR'][$cshKey]['columns'])) {
654 // Traverse table columns as listed in TCA_DESCR
655 foreach ($GLOBALS['TCA_DESCR'][$cshKey]['columns'] as $field => $data) {
656 if ($field) {
657 $this->glossaryWords[$cshKey . '.' . $field] = array(
658 'title' => trim($data['alttitle'] ? $data['alttitle'] : $cshKey),
659 'description' => str_replace('%22', '%23%23%23', rawurlencode($data['description']))
660 );
661 }
662 }
663 }
664 }
665 }
666 // First, create unique list of words:
667 foreach ($this->glossaryWords as $key => $value) {
668 // Making word lowercase in order to filter out same words in different cases.
669 $word = strtolower($value['title']);
670 if ($word !== '') {
671 $this->substWords[$word] = $value;
672 $this->substWords[$word]['key'] = $key;
673 }
674 }
675 krsort($this->substWords);
676 \TYPO3\CMS\Backend\Utility\BackendUtility::storeHash($hash, serialize(array($this->glossaryWords, $this->substWords)), 'Glossary');
677 }
678 }
679
680 /**
681 * Processing of all non-HTML content in the output
682 * Will be done by a call-back to ->substituteGlossaryWords_htmlcleaner_callback()
683 *
684 * @param string $code Input HTML code
685 * @return string Output HTML code
686 * @todo Define visibility
687 */
688 public function substituteGlossaryWords($code) {
689 $htmlParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Html\HtmlParser');
690 $htmlParser->pObj = $this;
691 $code = $htmlParser->HTMLcleaner($code, array(), 1);
692 return $code;
693 }
694
695 /**
696 * Substituting glossary words in the CSH
697 * This is a call-back function from "class local_t3lib_parsehtml
698 * extends \TYPO3\CMS\Core\Html\HtmlParser", see top of this script
699 *
700 * @param string $code Input HTML string
701 * @return string HTML with substituted words in.
702 * @todo Define visibility
703 */
704 public function substituteGlossaryWords_htmlcleaner_callback($code) {
705 if (is_array($this->substWords) && count($this->substWords) && strlen(trim($code))) {
706 // Substitute words:
707 foreach ($this->substWords as $wordKey => $wordSet) {
708 // quoteMeta used so special chars (which should not occur though) in words will not break the regex. Seemed to work (- kasper)
709 $parts = preg_split('/( |[\\(])(' . quoteMeta($wordSet['title']) . ')([\\.\\!\\)\\?\\:\\,]+| )/i', ' ' . $code . ' ', 2, PREG_SPLIT_DELIM_CAPTURE);
710 if (count($parts) == 5) {
711 $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>';
712 $code = substr(implode('', $parts), 1, -1);
713 // Disable entry so it doesn't get used next time:
714 unset($this->substWords[$wordKey]);
715 }
716 }
717 $code = str_replace('###', '&quot;', rawurldecode($code));
718 }
719 return $code;
720 }
721
722 }
723
724 ?>