TYPO3 CMS  TYPO3_6-2
ExtendedTemplateService.php
Go to the documentation of this file.
1 <?php
3 
20 
28 
29  // This string is used to indicate the point in a template from where the editable constants are listed. Any vars before this point (if it exists though) is regarded as default values.
33  public $edit_divider = '###MOD_TS:EDITABLE_CONSTANTS###';
34 
38  public $HTMLcolorList = 'aqua,beige,black,blue,brown,fuchsia,gold,gray,green,lime,maroon,navy,olive,orange,purple,red,silver,tan,teal,turquoise,yellow,white';
39 
40  // internal
44  public $categories = array(
45  'basic' => array(),
46  // Constants of superior importance for the template-layout. This is dimensions, imagefiles and enabling of various features. The most basic constants, which you would almost always want to configure.
47  'menu' => array(),
48  // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
49  'content' => array(),
50  // All constants related to the display of pagecontent elements
51  'page' => array(),
52  // General configuration like metatags, link targets
53  'advanced' => array(),
54  // Advanced functions, which are used very seldomly.
55  'all' => array()
56  );
57 
63  protected $categoryLabels = array();
64 
65  // This will be filled with the available categories of the current template.
69  public $subCategories = array(
70  // Standard categories:
71  'enable' => array('Enable features', 'a'),
72  'dims' => array('Dimensions, widths, heights, pixels', 'b'),
73  'file' => array('Files', 'c'),
74  'typo' => array('Typography', 'd'),
75  'color' => array('Colors', 'e'),
76  'links' => array('Links and targets', 'f'),
77  'language' => array('Language specific constants', 'g'),
78  // subcategories based on the default content elements
79  'cheader' => array('Content: \'Header\'', 'ma'),
80  'cheader_g' => array('Content: \'Header\', Graphical', 'ma'),
81  'ctext' => array('Content: \'Text\'', 'mb'),
82  'cimage' => array('Content: \'Image\'', 'md'),
83  'cbullets' => array('Content: \'Bullet list\'', 'me'),
84  'ctable' => array('Content: \'Table\'', 'mf'),
85  'cuploads' => array('Content: \'Filelinks\'', 'mg'),
86  'cmultimedia' => array('Content: \'Multimedia\'', 'mh'),
87  'cmedia' => array('Content: \'Media\'', 'mr'),
88  'cmailform' => array('Content: \'Form\'', 'mi'),
89  'csearch' => array('Content: \'Search\'', 'mj'),
90  'clogin' => array('Content: \'Login\'', 'mk'),
91  'cmenu' => array('Content: \'Menu/Sitemap\'', 'mm'),
92  'cshortcut' => array('Content: \'Insert records\'', 'mn'),
93  'clist' => array('Content: \'List of records\'', 'mo'),
94  'chtml' => array('Content: \'HTML\'', 'mq')
95  );
96 
100  public $backend_info = 1;
101 
102  // Tsconstanteditor
106  public $ext_inBrace = 0;
107 
108  // Tsbrowser
112  public $tsbrowser_searchKeys = array();
113 
117  public $tsbrowser_depthKeys = array();
118 
122  public $constantMode = '';
123 
127  public $regexMode = '';
128 
132  public $fixedLgd = '';
133 
137  public $resourceCheck = 0;
138 
143 
147  public $ext_localGfxPrefix = '';
148 
153 
158 
162  public $ext_noPMicons = 0;
163 
168 
172  public $ext_listOfTemplatesArr = array();
173 
178 
179  // Dont change...
184 
188  public $ext_printAll = 0;
189 
193  public $ext_CEformName = 'forms[0]';
194 
199 
200  // Ts analyzer
204  public $templateTitles = array();
205 
209  protected $lnToScript = NULL;
210 
221  public function flattenSetup($setupArray, $prefix, $resourceFlag) {
222  if (is_array($setupArray)) {
223  // Setting absolute prefixed path for relative resources.
224  $this->getFileName_backPath = PATH_site;
225  foreach ($setupArray as $key => $val) {
226  // We don't want 'TSConstantEditor' in the flattend setup.
227  if ($prefix || substr($key, 0, 16) != 'TSConstantEditor') {
228  if (is_array($val)) {
229  $this->flattenSetup($val, $prefix . $key, $key == 'file.');
230  } elseif ($resourceFlag && $this->resourceCheck) {
231  $this->flatSetup[$prefix . $key] = $this->getFileName($val);
232  if ($this->removeFromGetFilePath && substr($this->flatSetup[$prefix . $key], 0, strlen($this->removeFromGetFilePath)) == $this->removeFromGetFilePath) {
233  $this->flatSetup[$prefix . $key] = substr($this->flatSetup[$prefix . $key], strlen($this->removeFromGetFilePath));
234  }
235  } else {
236  $this->flatSetup[$prefix . $key] = $val;
237  }
238  }
239  }
240  }
241  }
242 
250  public function substituteConstants($all) {
251  $this->Cmarker = substr(md5(uniqid('', TRUE)), 0, 6);
252  return preg_replace_callback('/\\{\\$(.[^}]+)\\}/', array($this, 'substituteConstantsCallBack'), $all);
253  }
254 
263  public function substituteConstantsCallBack($matches) {
264  switch ($this->constantMode) {
265  case 'const':
266  $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? '##' . $this->Cmarker . '_B##' . $matches[0] . '##' . $this->Cmarker . '_E##' : $matches[0];
267  break;
268  case 'subst':
269  $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? '##' . $this->Cmarker . '_B##' . $this->flatSetup[$matches[1]] . '##' . $this->Cmarker . '_E##' : $matches[0];
270  break;
271  case 'untouched':
272  $ret_val = $matches[0];
273  break;
274  default:
275  $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? $this->flatSetup[$matches[1]] : $matches[0];
276  }
277  return $ret_val;
278  }
279 
287  public function substituteCMarkers($all) {
288  switch ($this->constantMode) {
289  case 'const':
290  case 'subst':
291  $all = str_replace(
292  array('##' . $this->Cmarker . '_B##', '##' . $this->Cmarker . '_E##'),
293  array('<font color="green"><strong>', '</strong></font>'),
294  $all
295  );
296  break;
297  default:
298  }
299  return $all;
300  }
301 
309  public function generateConfig_constants() {
310  // These vars are also set lateron...
311  $this->setup['resources'] = $this->resources;
312  $this->setup['sitetitle'] = $this->sitetitle;
313  // Parse constants
314  $constants = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
315  // Register comments!
316  $constants->regComments = 1;
317  $constants->setup = $this->const;
318  $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
320  $matchObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Configuration\\TypoScript\\ConditionMatching\\ConditionMatcher');
321  // Matches ALL conditions in TypoScript
322  $matchObj->setSimulateMatchResult(TRUE);
323  $c = 0;
324  $cc = count($this->constants);
325  foreach ($this->constants as $str) {
326  $c++;
327  if ($c == $cc) {
328  if (strstr($str, $this->edit_divider)) {
329  $parts = explode($this->edit_divider, $str, 2);
330  $str = $parts[1];
331  $constants->parse($parts[0], $matchObj);
332  }
333  $this->flatSetup = array();
334  $this->flattenSetup($constants->setup, '', '');
335  $defaultConstants = $this->flatSetup;
336  }
337  $constants->parse($str, $matchObj);
338  }
339  $this->flatSetup = array();
340  $this->flattenSetup($constants->setup, '', '');
341  $this->setup['constants'] = $constants->setup;
342  return $this->ext_compareFlatSetups($defaultConstants);
343  }
344 
353  public function ext_getSetup($theSetup, $theKey) {
354  $parts = explode('.', $theKey, 2);
355  if ((string)$parts[0] !== '' && is_array($theSetup[$parts[0] . '.'])) {
356  if (trim($parts[1]) !== '') {
357  return $this->ext_getSetup($theSetup[$parts[0] . '.'], trim($parts[1]));
358  } else {
359  return array($theSetup[$parts[0] . '.'], $theSetup[$parts[0]]);
360  }
361  } else {
362  if (trim($theKey) !== '') {
363  return array(array(), $theSetup[$theKey]);
364  } else {
365  return array($theSetup, '');
366  }
367  }
368  }
369 
382  public function ext_getObjTree($arr, $depth_in, $depthData, $parentType = '', $parentValue = '', $alphaSort = '0') {
383  $HTML = '';
384  $a = 0;
385  if ($alphaSort == '1') {
386  ksort($arr);
387  }
388  $keyArr_num = array();
389  $keyArr_alpha = array();
390  foreach ($arr as $key => $value) {
391  // Don't do anything with comments / linenumber registrations...
392  if (substr($key, -2) != '..') {
393  $key = preg_replace('/\\.$/', '', $key);
394  if (substr($key, -1) != '.') {
395  if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($key)) {
396  $keyArr_num[$key] = $arr[$key];
397  } else {
398  $keyArr_alpha[$key] = $arr[$key];
399  }
400  }
401  }
402  }
403  ksort($keyArr_num);
404  $keyArr = $keyArr_num + $keyArr_alpha;
405  $c = count($keyArr);
406  if ($depth_in) {
407  $depth_in = $depth_in . '.';
408  }
409  foreach ($keyArr as $key => $value) {
410  $a++;
411  $depth = $depth_in . $key;
412  // This excludes all constants starting with '_' from being shown.
413  if ($this->bType !== 'const' || $depth[0] !== '_') {
414  $goto = substr(md5($depth), 0, 6);
415  $deeper = is_array($arr[$key . '.']) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes) ? 1 : 0;
416  $PM = 'join';
417  $LN = $a == $c ? 'blank' : 'line';
418  $BTM = $a == $c ? 'bottom' : '';
419  $PM = is_array($arr[$key . '.']) && !$this->ext_noPMicons ? ($deeper ? 'minus' : 'plus') : 'join';
420  $HTML .= $depthData;
421  $theIcon = IconUtility::getSpriteIcon('treeline-' . $PM . $BTM);
422  if ($PM == 'join') {
423  $HTML .= $theIcon;
424  } else {
425  $urlParameters = array(
426  'id' => $GLOBALS['SOBE']->id,
427  'tsbr[' . $depth . ']' => $deeper ? 0 : 1
428  );
429  if (GeneralUtility::_GP('breakPointLN')) {
430  $urlParameters['breakPointLN'] = GeneralUtility::_GP('breakPointLN');
431  }
432  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters) . '#' . $goto;
433  $HTML .= '<a name="' . $goto . '" href="' . htmlspecialchars($aHref) . '">' . $theIcon . '</a>';
434  }
435  $label = $key;
436  // Read only...
437  if (GeneralUtility::inList('types,resources,sitetitle', $depth) && $this->bType == 'setup') {
438  $label = '<font color="#666666">' . $label . '</font>';
439  } else {
440  if ($this->linkObjects) {
441  $urlParameters = array(
442  'id' => $GLOBALS['SOBE']->id,
443  'sObj' => $depth
444  );
445  if (GeneralUtility::_GP('breakPointLN')) {
446  $urlParameters['breakPointLN'] = GeneralUtility::_GP('breakPointLN');
447  }
448  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
449  if ($this->bType != 'const') {
450  $ln = is_array($arr[$key . '.ln..']) ? 'Defined in: ' . $this->lineNumberToScript($arr[($key . '.ln..')]) : 'N/A';
451  } else {
452  $ln = '';
453  }
454  if ($this->tsbrowser_searchKeys[$depth] & 4) {
455  $label = '<strong><font color="red">' . $label . '</font></strong>';
456  }
457  // The key has matched the search string
458  $label = '<a href="' . htmlspecialchars($aHref) . '" title="' . htmlspecialchars($ln) . '">' . $label . '</a>';
459  }
460  }
461  $HTML .= '[' . $label . ']';
462  if (isset($arr[$key])) {
463  $theValue = $arr[$key];
464  if ($this->fixedLgd) {
465  $imgBlocks = ceil(1 + strlen($depthData) / 77);
466  $lgdChars = 68 - ceil(strlen(('[' . $key . ']')) * 0.8) - $imgBlocks * 3;
467  $theValue = $this->ext_fixed_lgd($theValue, $lgdChars);
468  }
469  // The value has matched the search string
470  if ($this->tsbrowser_searchKeys[$depth] & 2) {
471  $HTML .= '&nbsp;=&nbsp;<strong><font color="red">' . $this->makeHtmlspecialchars($theValue) . '</font></strong>';
472  } else {
473  $HTML .= '&nbsp;=&nbsp;<strong>' . $this->makeHtmlspecialchars($theValue) . '</strong>';
474  }
475  if ($this->ext_regComments && isset($arr[$key . '..'])) {
476  $comment = $arr[$key . '..'];
477  // Skip INCLUDE_TYPOSCRIPT comments, they are almost useless
478  if (!preg_match('/### <INCLUDE_TYPOSCRIPT:.*/', $comment)) {
479  // Remove linebreaks, replace with ' '
480  $comment = preg_replace('/[\\r\\n]/', ' ', $comment);
481  // Remove # and * if more than twice in a row
482  $comment = preg_replace('/[#\\*]{2,}/', '', $comment);
483  // Replace leading # (just if it exists) and add it again. Result: Every comment should be prefixed by a '#'.
484  $comment = preg_replace('/^[#\\*\\s]+/', '# ', $comment);
485  // Masking HTML Tags: Replace < with &lt; and > with &gt;
486  $comment = $this->makeHtmlspecialchars($comment);
487  $HTML .= ' <span class="comment">' . trim($comment) . '</span>';
488  }
489  }
490  }
491  $HTML .= '<br />';
492  if ($deeper) {
493  $HTML .= $this->ext_getObjTree($arr[$key . '.'], $depth, $depthData . IconUtility::getSpriteIcon('treeline-' . $LN), '', $arr[$key], $alphaSort);
494  }
495  }
496  }
497  return $HTML;
498  }
499 
511  public function lineNumberToScript(array $lnArr) {
512  // On the first call, construct the lnToScript array.
513  if (!is_array($this->lnToScript)) {
514  $this->lnToScript = array();
515 
516  // aggregatedTotalLineCount
517  $c = 0;
518  foreach ($this->hierarchyInfo as $templateNumber => $info) {
519  // hierarchyInfo has the number of lines in configLines, but unfortunatly this value
520  // was calculated *before* processing of any INCLUDE instructions
521  // for some yet unknown reason we have to add an extra +2 offset
522  $linecountAfterIncludeProcessing = substr_count($this->config[$templateNumber], LF) + 2;
523  $c += $linecountAfterIncludeProcessing;
524  $this->lnToScript[$c] = $info['title'];
525  }
526  }
527 
528  foreach ($lnArr as $k => $ln) {
529  foreach ($this->lnToScript as $endLn => $title) {
530  if ($endLn >= (int)$ln) {
531  $lnArr[$k] = '"' . $title . '", ' . $ln;
532  break;
533  }
534  }
535  }
536 
537  return implode('; ', $lnArr);
538  }
539 
547  public function makeHtmlspecialchars($theValue) {
548  return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
549  }
550 
561  public function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
562  $keyArr = array();
563  foreach ($arr as $key => $value) {
564  $key = preg_replace('/\\.$/', '', $key);
565  if (substr($key, -1) != '.') {
566  $keyArr[$key] = 1;
567  }
568  }
569  $c = count($keyArr);
570  if ($depth_in) {
571  $depth_in = $depth_in . '.';
572  }
573  foreach ($keyArr as $key => $value) {
574  $depth = $depth_in . $key;
575  $deeper = is_array($arr[$key . '.']);
576  if ($this->regexMode) {
577  // The value has matched
578  if (preg_match('/' . $searchString . '/', $arr[$key])) {
579  $this->tsbrowser_searchKeys[$depth] += 2;
580  }
581  // The key has matched
582  if (preg_match('/' . $searchString . '/', $key)) {
583  $this->tsbrowser_searchKeys[$depth] += 4;
584  }
585  // Just open this subtree if the parent key has matched the search
586  if (preg_match('/' . $searchString . '/', $depth_in)) {
587  $this->tsbrowser_searchKeys[$depth] = 1;
588  }
589  } else {
590  // The value has matched
591  if (stristr($arr[$key], $searchString)) {
592  $this->tsbrowser_searchKeys[$depth] += 2;
593  }
594  // The key has matches
595  if (stristr($key, $searchString)) {
596  $this->tsbrowser_searchKeys[$depth] += 4;
597  }
598  // Just open this subtree if the parent key has matched the search
599  if (stristr($depth_in, $searchString)) {
600  $this->tsbrowser_searchKeys[$depth] = 1;
601  }
602  }
603  if ($deeper) {
604  $cS = count($this->tsbrowser_searchKeys);
605  $keyArray = $this->ext_getSearchKeys($arr[$key . '.'], $depth, $searchString, $keyArray);
606  if ($cS != count($this->tsbrowser_searchKeys)) {
607  $keyArray[$depth] = 1;
608  }
609  }
610  }
611  return $keyArray;
612  }
613 
621  public function ext_getRootlineNumber($pid) {
622  if ($pid && is_array($GLOBALS['rootLine'])) {
623  foreach ($GLOBALS['rootLine'] as $key => $val) {
624  if ($val['uid'] == $pid) {
625  return $key;
626  }
627  }
628  }
629  }
630 
641  public function ext_getTemplateHierarchyArr($arr, $depthData, $keyArray, $first = 0) {
642  $keyArr = array();
643  foreach ($arr as $key => $value) {
644  $key = preg_replace('/\\.$/', '', $key);
645  if (substr($key, -1) != '.') {
646  $keyArr[$key] = 1;
647  }
648  }
649  $a = 0;
650  $c = count($keyArr);
651  static $i = 0;
652  foreach ($keyArr as $key => $value) {
653  $HTML = '';
654  $a++;
655  $deeper = is_array($arr[$key . '.']);
656  $row = $arr[$key];
657  $PM = 'join';
658  $LN = $a == $c ? 'blank' : 'line';
659  $BTM = $a == $c ? 'top' : '';
660  $PM = 'join';
661  $HTML .= $depthData;
662  $alttext = '[' . $row['templateID'] . ']';
663  $alttext .= $row['pid'] ? ' - ' . BackendUtility::getRecordPath($row['pid'], $GLOBALS['SOBE']->perms_clause, 20) : '';
664  $icon = substr($row['templateID'], 0, 3) == 'sys' ? \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_template', $row, array('title' => $alttext)) : \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('mimetypes-x-content-template-static', array('title' => $alttext));
665  if (in_array($row['templateID'], $this->clearList_const) || in_array($row['templateID'], $this->clearList_setup)) {
666  $urlParameters = array(
667  'id' => $GLOBALS['SOBE']->id,
668  'template' => $row['templateID']
669  );
670  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
671  $A_B = '<a href="' . htmlspecialchars($aHref) . '">';
672  $A_E = '</a>';
673  if (GeneralUtility::_GP('template') == $row['templateID']) {
674  $A_B = '<strong>' . $A_B;
675  $A_E .= '</strong>';
676  }
677  } else {
678  $A_B = '';
679  $A_E = '';
680  }
681  $HTML .= ($first ? '' : IconUtility::getSpriteIcon('treeline-' . $PM . $BTM)) . $icon . $A_B . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . $A_E . '&nbsp;&nbsp;';
682  $RL = $this->ext_getRootlineNumber($row['pid']);
683  $keyArray[] = '<tr class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '">
684  <td nowrap="nowrap">' . $HTML . '</td>
685  <td align="center">' . ($row['root'] ? \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-status-checked') : '') . '&nbsp;&nbsp;</td>
686  <td align="center">' . ($row['clConf'] ? \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-status-checked') : '') . '&nbsp;&nbsp;' . '</td>
687  <td align="center">' . ($row['clConst'] ? \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-status-checked') : '') . '&nbsp;&nbsp;' . '</td>
688  <td align="center">' . ($row['pid'] ?: '') . '</td>
689  <td align="center">' . (strcmp($RL, '') ? $RL : '') . '</td>
690  <td>' . ($row['next'] ? '&nbsp;' . $row['next'] . '&nbsp;&nbsp;' : '') . '</td>
691  </tr>';
692  if ($deeper) {
693  $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key . '.'], $depthData . ($first ? '' : IconUtility::getSpriteIcon('treeline-' . $LN)), $keyArray);
694  }
695  }
696  return $keyArray;
697  }
698 
708  public function ext_process_hierarchyInfo(array $depthDataArr, &$pointer) {
709  $parent = $this->hierarchyInfo[$pointer - 1]['templateParent'];
710  while ($pointer > 0 && $this->hierarchyInfo[$pointer - 1]['templateParent'] == $parent) {
711  $pointer--;
712  $row = $this->hierarchyInfo[$pointer];
713  $depthDataArr[$row['templateID']] = $row;
714  $depthDataArr[$row['templateID']]['bgcolor_setup'] = isset($this->clearList_setup_temp[$row['templateID']]) ? ' class="bgColor5"' : '';
715  $depthDataArr[$row['templateID']]['bgcolor_const'] = isset($this->clearList_const_temp[$row['templateID']]) ? ' class="bgColor5"' : '';
716  unset($this->clearList_setup_temp[$row['templateID']]);
717  unset($this->clearList_const_temp[$row['templateID']]);
718  $this->templateTitles[$row['templateID']] = $row['title'];
719  if ($row['templateID'] == $this->hierarchyInfo[$pointer - 1]['templateParent']) {
720  $depthDataArr[$row['templateID'] . '.'] = $this->ext_process_hierarchyInfo(array(), $pointer);
721  }
722  }
723  return $depthDataArr;
724  }
725 
740  public function ext_outputTS(
741  array $config, $lineNumbers = FALSE, $comments = FALSE, $crop = FALSE, $syntaxHL = FALSE, $syntaxHLBlockmode = 0
742  ) {
743  $all = '';
744  foreach ($config as $str) {
745  $all .= '[GLOBAL]' . LF . $str;
746  }
747  if ($syntaxHL) {
748  $tsparser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
749  $tsparser->lineNumberOffset = $this->ext_lineNumberOffset + 1;
750  $tsparser->parentObject = $this;
751  return $tsparser->doSyntaxHighlight($all, $lineNumbers ? array($this->ext_lineNumberOffset + 1) : '', $syntaxHLBlockmode);
752  } else {
753  return $this->ext_formatTS($all, $lineNumbers, $comments, $crop);
754  }
755  }
756 
767  public function ext_fixed_lgd($string, $chars) {
768  if ($chars >= 4) {
769  if (strlen($string) > $chars) {
770  if (strlen($string) > 24 && substr($string, 0, 12) == '##' . $this->Cmarker . '_B##') {
771  return '##' . $this->Cmarker . '_B##' . GeneralUtility::fixed_lgd_cs(substr($string, 12, -12), ($chars - 3)) . '##' . $this->Cmarker . '_E##';
772  } else {
773  return GeneralUtility::fixed_lgd_cs($string, $chars - 3);
774  }
775  }
776  }
777  return $string;
778  }
779 
788  public function ext_lnBreakPointWrap($lineNumber, $str) {
789  return '<a href="#" id="line-' . $lineNumber . '" onClick="return brPoint(' . $lineNumber . ',' . ($this->ext_lineNumberOffset_mode == 'setup' ? 1 : 0) . ');">' . $str . '</a>';
790  }
791 
802  public function ext_formatTS($input, $ln, $comments = 1, $crop = 0) {
803  $cArr = explode(LF, $input);
804  $n = ceil(log10(count($cArr) + $this->ext_lineNumberOffset));
805  $lineNum = '';
806  foreach ($cArr as $k => $v) {
807  $lln = $k + $this->ext_lineNumberOffset + 1;
808  if ($ln) {
809  $lineNum = $this->ext_lnBreakPointWrap($lln, str_replace(' ', '&nbsp;', sprintf(('% ' . $n . 'd'), $lln))) . ': ';
810  }
811  $v = htmlspecialchars($v);
812  if ($crop) {
813  $v = $this->ext_fixed_lgd($v, $ln ? 71 : 77);
814  }
815  $cArr[$k] = $lineNum . str_replace(' ', '&nbsp;', $v);
816  $firstChar = substr(trim($v), 0, 1);
817  if ($firstChar == '[') {
818  $cArr[$k] = '<font color="green"><strong>' . $cArr[$k] . '</strong></font>';
819  } elseif ($firstChar == '/' || $firstChar == '#') {
820  if ($comments) {
821  $cArr[$k] = '<span class="typo3-dimmed">' . $cArr[$k] . '</span>';
822  } else {
823  unset($cArr[$k]);
824  }
825  }
826  }
827  $output = implode($cArr, '<br />') . '<br />';
828  return $output;
829  }
830 
839  public function ext_getFirstTemplate($id, $template_uid = 0) {
840  // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
841  if ((int)$id) {
842  if ($template_uid) {
843  $addC = ' AND uid=' . $template_uid;
844  }
845  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid=' . (int)$id . $addC . ' ' . $this->whereClause, '', 'sorting', '1');
846  $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
847  BackendUtility::workspaceOL('sys_template', $row);
848  $GLOBALS['TYPO3_DB']->sql_free_result($res);
849  // Returns the template row if found.
850  return $row;
851  }
852  }
853 
861  public function ext_getAllTemplates($id) {
862  // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
863  if ((int)$id) {
864  $outRes = array();
865  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid=' . (int)$id . ' ' . $this->whereClause, '', 'sorting');
866  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
867  BackendUtility::workspaceOL('sys_template', $row);
868  if (is_array($row)) {
869  $outRes[] = $row;
870  }
871  }
872  $GLOBALS['TYPO3_DB']->sql_free_result($res);
873  // Returns the template rows in an array.
874  return $outRes;
875  }
876  }
877 
886  public function ext_compareFlatSetups($default) {
887  $editableComments = array();
888  foreach ($this->flatSetup as $const => $value) {
889  if (substr($const, -2) != '..' && isset($this->flatSetup[$const . '..'])) {
890  $comment = trim($this->flatSetup[$const . '..']);
891  $c_arr = explode(LF, $comment);
892  foreach ($c_arr as $k => $v) {
893  $line = trim(preg_replace('/^[#\\/]*/', '', $v));
894  if ($line) {
895  $parts = explode(';', $line);
896  foreach ($parts as $par) {
897  if (strstr($par, '=')) {
898  $keyValPair = explode('=', $par, 2);
899  switch (trim(strtolower($keyValPair[0]))) {
900  case 'type':
901  // Type:
902  $editableComments[$const]['type'] = trim($keyValPair[1]);
903  break;
904  case 'cat':
905  // List of categories.
906  $catSplit = explode('/', strtolower($keyValPair[1]));
907  $catSplit[0] = trim($catSplit[0]);
908  if (isset($this->categoryLabels[$catSplit[0]])) {
909  $catSplit[0] = $this->categoryLabels[$catSplit[0]];
910  }
911  $editableComments[$const]['cat'] = $catSplit[0];
912  // This is the subcategory. Must be a key in $this->subCategories[]. catSplit[2] represents the search-order within the subcat.
913  $catSplit[1] = trim($catSplit[1]);
914  if ($catSplit[1] && isset($this->subCategories[$catSplit[1]])) {
915  $editableComments[$const]['subcat_name'] = $catSplit[1];
916  $editableComments[$const]['subcat'] = $this->subCategories[$catSplit[1]][1] . '/' . $catSplit[1] . '/' . trim($catSplit[2]) . 'z';
917  } else {
918  $editableComments[$const]['subcat'] = 'x' . '/' . trim($catSplit[2]) . 'z';
919  }
920  break;
921  case 'label':
922  // Label
923  $editableComments[$const]['label'] = trim($keyValPair[1]);
924  break;
925  case 'customcategory':
926  // Custom category label
927  $customCategory = explode('=', $keyValPair[1], 2);
928  if (trim($customCategory[0])) {
929  $categoryKey = strtolower($customCategory[0]);
930  $this->categoryLabels[$categoryKey] = $GLOBALS['LANG']->sL($customCategory[1]);
931  }
932  break;
933  case 'customsubcategory':
934  // Custom subCategory label
935  $customSubcategory = explode('=', $keyValPair[1], 2);
936  if (trim($customSubcategory[0])) {
937  $subCategoryKey = strtolower($customSubcategory[0]);
938  $this->subCategories[$subCategoryKey][0] = $GLOBALS['LANG']->sL($customSubcategory[1]);
939  }
940  break;
941  }
942  }
943  }
944  }
945  }
946  }
947  if (isset($editableComments[$const])) {
948  $editableComments[$const]['name'] = $const;
949  $editableComments[$const]['value'] = trim($value);
950  if (isset($default[$const])) {
951  $editableComments[$const]['default_value'] = trim($default[$const]);
952  }
953  }
954  }
955  return $editableComments;
956  }
957 
965  public function ext_categorizeEditableConstants($editConstArray) {
966  // Runs through the available constants and fills the $this->categories array with pointers and priority-info
967  foreach ($editConstArray as $constName => $constData) {
968  if (!$constData['type']) {
969  $constData['type'] = 'string';
970  }
971  $cats = explode(',', $constData['cat']);
972  // if = only one category, while allows for many. We have agreed on only one category is the most basic way...
973  foreach ($cats as $theCat) {
974  $theCat = trim($theCat);
975  if ($theCat) {
976  $this->categories[$theCat][$constName] = $constData['subcat'];
977  }
978  }
979  }
980  }
981 
988  public function ext_getCategoryLabelArray() {
989  // Returns array used for labels in the menu.
990  $retArr = array();
991  foreach ($this->categories as $k => $v) {
992  if (count($v)) {
993  $retArr[$k] = strtoupper($k) . ' (' . count($v) . ')';
994  }
995  }
996  return $retArr;
997  }
998 
1006  public function ext_getTypeData($type) {
1007  $retArr = array();
1008  $type = trim($type);
1009  if (!$type) {
1010  $retArr['type'] = 'string';
1011  } else {
1012  $m = strcspn($type, ' [');
1013  $retArr['type'] = strtolower(substr($type, 0, $m));
1014  if (GeneralUtility::inList('int,options,file,boolean,offset,user', $retArr['type'])) {
1015  $p = trim(substr($type, $m));
1016  $reg = array();
1017  preg_match('/\\[(.*)\\]/', $p, $reg);
1018  $p = trim($reg[1]);
1019  if ($p) {
1020  $retArr['paramstr'] = $p;
1021  switch ($retArr['type']) {
1022  case 'int':
1023  if ($retArr['paramstr'][0] === '-') {
1024  $retArr['params'] = GeneralUtility::intExplode('-', substr($retArr['paramstr'], 1));
1025  $retArr['params'][0] = (int)('-' . $retArr['params'][0]);
1026  } else {
1027  $retArr['params'] = GeneralUtility::intExplode('-', $retArr['paramstr']);
1028  }
1029  $retArr['paramstr'] = $retArr['params'][0] . ' - ' . $retArr['params'][1];
1030  break;
1031  case 'options':
1032  $retArr['params'] = explode(',', $retArr['paramstr']);
1033  break;
1034  }
1035  }
1036  }
1037  }
1038  return $retArr;
1039  }
1040 
1048  public function ext_getTSCE_config($category) {
1049  $catConf = $this->setup['constants']['TSConstantEditor.'][$category . '.'];
1050  $out = array();
1051  if (is_array($catConf)) {
1052  foreach ($catConf as $key => $val) {
1053  switch ($key) {
1054  case 'image':
1055  $out['imagetag'] = $this->ext_getTSCE_config_image($catConf['image']);
1056  break;
1057  case 'description':
1058 
1059  case 'bulletlist':
1060 
1061  case 'header':
1062  $out[$key] = $val;
1063  break;
1064  default:
1065  if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($key)) {
1066  $constRefs = explode(',', $val);
1067  foreach ($constRefs as $const) {
1068  $const = trim($const);
1069  if ($const && $const <= 20) {
1070  $out['constants'][$const] .= $this->ext_getKeyImage($key);
1071  }
1072  }
1073  }
1074  }
1075  }
1076  }
1077  $this->helpConfig = $out;
1078  }
1079 
1087  public function ext_getKeyImage($key) {
1088  return '<img src="' . $this->ext_localWebGfxPrefix . 'gfx/' . $key . '.gif" align="top" hspace=2>';
1089  }
1090 
1098  public function ext_getTSCE_config_image($imgConf) {
1099  if (substr($imgConf, 0, 4) == 'gfx/') {
1100  $iFile = $this->ext_localGfxPrefix . $imgConf;
1101  $tFile = $this->ext_localWebGfxPrefix . $imgConf;
1102  } elseif (substr($imgConf, 0, 4) == 'EXT:') {
1103  $iFile = GeneralUtility::getFileAbsFileName($imgConf);
1104  if ($iFile) {
1106  $tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
1107  }
1108  }
1109  $imageInfo = @getImagesize($iFile);
1110  return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
1111  }
1112 
1120  public function ext_fNandV($params) {
1121  $fN = 'data[' . $params['name'] . ']';
1122  $fV = $params['value'];
1123  // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
1124  if (preg_match('/^{[\\$][a-zA-Z0-9\\.]*}$/', trim($fV), $reg)) {
1125  $fV = '';
1126  }
1127  $fV = htmlspecialchars($fV);
1128  return array($fN, $fV, $params);
1129  }
1130 
1139  public function ext_printFields($theConstants, $category) {
1140  reset($theConstants);
1141  $output = '<script type="text/javascript" src="' . $GLOBALS['BACK_PATH'] . 'js/constantEditor.js"></script>
1142  ';
1143  $subcat = '';
1144  if (is_array($this->categories[$category])) {
1145  $help = $this->helpConfig;
1146  if (!$this->doNotSortCategoriesBeforeMakingForm) {
1147  asort($this->categories[$category]);
1148  }
1149  foreach ($this->categories[$category] as $name => $type) {
1150  $params = $theConstants[$name];
1151  if (is_array($params)) {
1152  if ($subcat != $params['subcat_name']) {
1153  $subcat = $params['subcat_name'];
1154  $subcat_name = $params['subcat_name'] ? $this->subCategories[$params['subcat_name']][0] : 'Others';
1155  $output .= '<h3 class="typo3-tstemplate-ceditor-subcat">' . $subcat_name . '</h3>';
1156  }
1157  $label = $GLOBALS['LANG']->sL($params['label']);
1158  $label_parts = explode(':', $label, 2);
1159  if (count($label_parts) == 2) {
1160  $head = trim($label_parts[0]);
1161  $body = trim($label_parts[1]);
1162  } else {
1163  $head = trim($label_parts[0]);
1164  $body = '';
1165  }
1166  if (strlen($head) > 35) {
1167  if (!$body) {
1168  $body = $head;
1169  }
1170  $head = GeneralUtility::fixed_lgd_cs($head, 35);
1171  }
1172  $typeDat = $this->ext_getTypeData($params['type']);
1173  $checked = '';
1174  $p_field = '';
1175  $raname = substr(md5($params['name']), 0, 10);
1176  $aname = '\'' . $raname . '\'';
1177  list($fN, $fV, $params) = $this->ext_fNandV($params);
1178  switch ($typeDat['type']) {
1179  case 'int':
1180 
1181  case 'int+':
1182  $p_field = '<input id="' . $fN . '" type="text" name="' . $fN . '" value="' . $fV . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(5) . ' onChange="uFormUrl(' . $aname . ')" />';
1183  if ($typeDat['paramstr']) {
1184  $p_field .= ' Range: ' . $typeDat['paramstr'];
1185  } elseif ($typeDat['type'] == 'int+') {
1186  $p_field .= ' Range: 0 - ';
1187  } else {
1188  $p_field .= ' (Integer)';
1189  }
1190  break;
1191  case 'color':
1192  $colorNames = explode(',', ',' . $this->HTMLcolorList);
1193  $p_field = '';
1194  foreach ($colorNames as $val) {
1195  $sel = '';
1196  if ($val == strtolower($params['value'])) {
1197  $sel = ' selected';
1198  }
1199  $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $val . '</option>';
1200  }
1201  $p_field = '<select id="select-' . $fN . '" rel="' . $fN . '" name="C' . $fN . '" class="typo3-tstemplate-ceditor-color-select" onChange="uFormUrl(' . $aname . ');">' . $p_field . '</select>';
1202  $p_field .= '<input type="text" id="input-' . $fN . '" rel="' . $fN . '" name="' . $fN . '" class="typo3-tstemplate-ceditor-color-input" value="' . $fV . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(7) . ' onChange="uFormUrl(' . $aname . ')" />';
1203  break;
1204  case 'wrap':
1205  $wArr = explode('|', $fV);
1206  $p_field = '<input type="text" id="' . $fN . '" name="' . $fN . '" value="' . $wArr[0] . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(29) . ' onChange="uFormUrl(' . $aname . ')" />';
1207  $p_field .= ' | ';
1208  $p_field .= '<input type="text" name="W' . $fN . '" value="' . $wArr[1] . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(15) . ' onChange="uFormUrl(' . $aname . ')" />';
1209  break;
1210  case 'offset':
1211  $wArr = explode(',', $fV);
1212  $labels = GeneralUtility::trimExplode(',', $typeDat['paramstr']);
1213  $p_field = ($labels[0] ? $labels[0] : 'x') . ':<input type="text" name="' . $fN . '" value="' . $wArr[0] . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
1214  $p_field .= ' , ';
1215  $p_field .= ($labels[1] ? $labels[1] : 'y') . ':<input type="text" name="W' . $fN . '" value="' . $wArr[1] . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
1216  $labelsCount = count($labels);
1217  for ($aa = 2; $aa < $labelsCount; $aa++) {
1218  if ($labels[$aa]) {
1219  $p_field .= ' , ' . $labels[$aa] . ':<input type="text" name="W' . $aa . $fN . '" value="' . $wArr[$aa] . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
1220  } else {
1221  $p_field .= '<input type="hidden" name="W' . $aa . $fN . '" value="' . $wArr[$aa] . '" />';
1222  }
1223  }
1224  break;
1225  case 'options':
1226  if (is_array($typeDat['params'])) {
1227  $p_field = '';
1228  foreach ($typeDat['params'] as $val) {
1229  $vParts = explode('=', $val, 2);
1230  $label = $vParts[0];
1231  $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
1232  // option tag:
1233  $sel = '';
1234  if ($val == $params['value']) {
1235  $sel = ' selected';
1236  }
1237  $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $GLOBALS['LANG']->sL($label) . '</option>';
1238  }
1239  $p_field = '<select id="' . $fN . '" name="' . $fN . '" onChange="uFormUrl(' . $aname . ')">' . $p_field . '</select>';
1240  }
1241  break;
1242  case 'boolean':
1243  $p_field = '<input type="hidden" name="' . $fN . '" value="0" />';
1244  $sel = '';
1245  if ($fV) {
1246  $sel = ' checked';
1247  }
1248  $p_field .= '<input id="' . $fN . '" type="checkbox" name="' . $fN . '" value="' . ($typeDat['paramstr'] ? $typeDat['paramstr'] : 1) . '"' . $sel . ' onClick="uFormUrl(' . $aname . ')" />';
1249  break;
1250  case 'comment':
1251  $p_field = '<input type="hidden" name="' . $fN . '" value="#" />';
1252  $sel = '';
1253  if (!$fV) {
1254  $sel = ' checked';
1255  }
1256  $p_field .= '<input id="' . $fN . '" type="checkbox" name="' . $fN . '" value=""' . $sel . ' onClick="uFormUrl(' . $aname . ')" />';
1257  break;
1258  case 'file':
1259  $p_field = '<option value=""></option>';
1260  $theImage = '';
1261  // extensionlist
1262  $extList = $typeDat['paramstr'];
1263  $p_field = '<option value="">(' . $extList . ')</option>';
1264  if ($extList == 'IMAGE_EXT') {
1265  $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
1266  }
1267  if (trim($params['value'])) {
1268  $val = $params['value'];
1269  $p_field .= '<option value=""></option>';
1270  $p_field .= '<option value="' . htmlspecialchars($val) . '" selected>' . $val . '</option>';
1271  }
1272  $p_field = '<select id="' . $fN . '" name="' . $fN . '" onChange="uFormUrl(' . $aname . ')">' . $p_field . '</select>';
1273  $p_field .= $theImage;
1274  break;
1275  case 'user':
1276  $userFunction = $typeDat['paramstr'];
1277  $userFunctionParams = array('fieldName' => $fN, 'fieldValue' => $fV);
1278  $p_field = GeneralUtility::callUserFunction($userFunction, $userFunctionParams, $this, '');
1279  break;
1280  case 'small':
1281 
1282  default:
1283  $fwidth = $typeDat['type'] == 'small' ? 10 : 46;
1284  $p_field = '<input id="' . $fN . '" type="text" name="' . $fN . '" value="' . $fV . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth($fwidth) . ' onChange="uFormUrl(' . $aname . ')" />';
1285  }
1286  // Define default names and IDs
1287  $userTyposcriptID = 'userTS-' . $params['name'];
1288  $defaultTyposcriptID = 'defaultTS-' . $params['name'];
1289  $checkboxName = 'check[' . $params['name'] . ']';
1290  $checkboxID = $checkboxName;
1291  // Handle type=color specially
1292  if ($typeDat['type'] == 'color' && substr($params['value'], 0, 2) != '{$') {
1293  $color = '<div id="colorbox-' . $fN . '" class="typo3-tstemplate-ceditor-colorblock" style="background-color:' . $params['value'] . ';">&nbsp;</div>';
1294  } else {
1295  $color = '';
1296  }
1297  if (!$this->ext_dontCheckIssetValues) {
1298  // Set the default styling options
1299  if (isset($this->objReg[$params['name']])) {
1300  $checkboxValue = 'checked';
1301  $userTyposcriptStyle = '';
1302  $defaultTyposcriptStyle = 'style="display:none;"';
1303  } else {
1304  $checkboxValue = '';
1305  $userTyposcriptStyle = 'style="display:none;"';
1306  $defaultTyposcriptStyle = '';
1307  }
1308  $deleteIconHTML = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-undo', array(
1309  'class' => 'typo3-tstemplate-ceditor-control undoIcon',
1310  'alt' => 'Revert to default Constant',
1311  'title' => 'Revert to default Constant',
1312  'rel' => $params['name']
1313  ));
1314  $editIconHTML = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open', array(
1315  'class' => 'typo3-tstemplate-ceditor-control editIcon',
1316  'alt' => 'Edit this Constant',
1317  'title' => 'Edit this Constant',
1318  'rel' => $params['name']
1319  ));
1320  $constantCheckbox = '<input type="hidden" name="' . $checkboxName . '" id="' . $checkboxID . '" value="' . $checkboxValue . '"/>';
1321  // If there's no default value for the field, use a static label.
1322  if (!$params['default_value']) {
1323  $params['default_value'] = '[Empty]';
1324  }
1325  $constantDefaultRow = '<div class="typo3-tstemplate-ceditor-row" id="' . $defaultTyposcriptID . '" ' . $defaultTyposcriptStyle . '>' . $editIconHTML . htmlspecialchars($params['default_value']) . $color . '</div>';
1326  }
1327  $constantEditRow = '<div class="typo3-tstemplate-ceditor-row" id="' . $userTyposcriptID . '" ' . $userTyposcriptStyle . '>' . $deleteIconHTML . $p_field . $color . '</div>';
1328  $constantLabel = '<dt class="typo3-tstemplate-ceditor-label">' . htmlspecialchars($head) . '</dt>';
1329  $constantName = '<dt class="typo3-dimmed">[' . $params['name'] . ']</dt>';
1330  $constantDescription = $body ? '<dd>' . htmlspecialchars($body) . '</dd>' : '';
1331  $constantData = '<dd>' . $constantCheckbox . $constantEditRow . $constantDefaultRow . '</dd>';
1332  $output .= '<a name="' . $raname . '"></a>' . $help['constants'][$params['name']];
1333  $output .= '<dl class="typo3-tstemplate-ceditor-constant">' . $constantLabel . $constantName . $constantDescription . $constantData . '</dl>';
1334  } else {
1335  debug('Error. Constant did not exist. Should not happen.');
1336  }
1337  }
1338  }
1339  return $output;
1340  }
1341 
1342  /***************************
1343  *
1344  * Processing input values
1345  *
1346  ***************************/
1353  // This runs through the lines of the constants-field of the active template and registers the constants-names
1354  // and linepositions in an array, $this->objReg
1355  $this->raw = explode(LF, $constants);
1356  $this->rawP = 0;
1357  // Resetting the objReg if the divider is found!!
1358  $this->objReg = array();
1359  $this->ext_regObjects('');
1360  }
1361 
1369  public function ext_regObjects($pre) {
1370  // Works with regObjectPositions. "expands" the names of the TypoScript objects
1371  while (isset($this->raw[$this->rawP])) {
1372  $line = ltrim($this->raw[$this->rawP]);
1373  if (strstr($line, $this->edit_divider)) {
1374  // Resetting the objReg if the divider is found!!
1375  $this->objReg = array();
1376  }
1377  $this->rawP++;
1378  if ($line) {
1379  if ($line[0] === '[') {
1380 
1381  } elseif (strcspn($line, '}#/') != 0) {
1382  $varL = strcspn($line, ' {=<');
1383  $var = substr($line, 0, $varL);
1384  $line = ltrim(substr($line, $varL));
1385  switch ($line[0]) {
1386  case '=':
1387  $this->objReg[$pre . $var] = $this->rawP - 1;
1388  break;
1389  case '{':
1390  $this->ext_inBrace++;
1391  $this->ext_regObjects($pre . $var . '.');
1392  break;
1393  }
1394  $this->lastComment = '';
1395  } elseif ($line[0] === '}') {
1396  $this->lastComment = '';
1397  $this->ext_inBrace--;
1398  if ($this->ext_inBrace < 0) {
1399  $this->ext_inBrace = 0;
1400  } else {
1401  break;
1402  }
1403  }
1404  }
1405  }
1406  }
1407 
1416  public function ext_putValueInConf($key, $var) {
1417  // Puts the value $var to the TypoScript value $key in the current lines of the templates.
1418  // If the $key is not found in the template constants field, a new line is inserted in the bottom.
1419  $theValue = ' ' . trim($var);
1420  if (isset($this->objReg[$key])) {
1421  $lineNum = $this->objReg[$key];
1422  $parts = explode('=', $this->raw[$lineNum], 2);
1423  if (count($parts) == 2) {
1424  $parts[1] = $theValue;
1425  }
1426  $this->raw[$lineNum] = implode($parts, '=');
1427  } else {
1428  $this->raw[] = $key . ' =' . $theValue;
1429  }
1430  $this->changed = 1;
1431  }
1432 
1440  public function ext_removeValueInConf($key) {
1441  // Removes the value in the configuration
1442  if (isset($this->objReg[$key])) {
1443  $lineNum = $this->objReg[$key];
1444  unset($this->raw[$lineNum]);
1445  }
1446  $this->changed = 1;
1447  }
1448 
1457  public function ext_depthKeys($arr, $settings) {
1458  $tsbrArray = array();
1459  foreach ($arr as $theK => $theV) {
1460  $theKeyParts = explode('.', $theK);
1461  $depth = '';
1462  $c = count($theKeyParts);
1463  $a = 0;
1464  foreach ($theKeyParts as $p) {
1465  $a++;
1466  $depth .= ($depth ? '.' : '') . $p;
1467  $tsbrArray[$depth] = $c == $a ? $theV : 1;
1468  }
1469  }
1470  // Modify settings
1471  foreach ($tsbrArray as $theK => $theV) {
1472  if ($theV) {
1473  $settings[$theK] = 1;
1474  } else {
1475  unset($settings[$theK]);
1476  }
1477  }
1478  return $settings;
1479  }
1480 
1491  public function ext_procesInput($http_post_vars, $http_post_files, $theConstants, $tplRow) {
1492  $data = $http_post_vars['data'];
1493  $check = $http_post_vars['check'];
1494  $Wdata = $http_post_vars['Wdata'];
1495  $W2data = $http_post_vars['W2data'];
1496  $W3data = $http_post_vars['W3data'];
1497  $W4data = $http_post_vars['W4data'];
1498  $W5data = $http_post_vars['W5data'];
1499  if (is_array($data)) {
1500  foreach ($data as $key => $var) {
1501  if (isset($theConstants[$key])) {
1502  // If checkbox is set, update the value
1503  if ($this->ext_dontCheckIssetValues || isset($check[$key])) {
1504  // Exploding with linebreak, just to make sure that no multiline input is given!
1505  list($var) = explode(LF, $var);
1506  $typeDat = $this->ext_getTypeData($theConstants[$key]['type']);
1507  switch ($typeDat['type']) {
1508  case 'int':
1509  if ($typeDat['paramstr']) {
1510  $var = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($var, $typeDat['params'][0], $typeDat['params'][1]);
1511  } else {
1512  $var = (int)$var;
1513  }
1514  break;
1515  case 'int+':
1516  $var = max(0, (int)$var);
1517  break;
1518  case 'color':
1519  $col = array();
1520  if ($var && !GeneralUtility::inList($this->HTMLcolorList, strtolower($var))) {
1521  $var = preg_replace('/[^A-Fa-f0-9]*/', '', $var);
1522  $useFulHex = strlen($var) > 3;
1523  $col[] = HexDec($var[0]);
1524  $col[] = HexDec($var[1]);
1525  $col[] = HexDec($var[2]);
1526  if ($useFulHex) {
1527  $col[] = HexDec($var[3]);
1528  $col[] = HexDec($var[4]);
1529  $col[] = HexDec($var[5]);
1530  }
1531  $var = substr(('0' . DecHex($col[0])), -1) . substr(('0' . DecHex($col[1])), -1) . substr(('0' . DecHex($col[2])), -1);
1532  if ($useFulHex) {
1533  $var .= substr(('0' . DecHex($col[3])), -1) . substr(('0' . DecHex($col[4])), -1) . substr(('0' . DecHex($col[5])), -1);
1534  }
1535  $var = '#' . strtoupper($var);
1536  }
1537  break;
1538  case 'comment':
1539  if ($var) {
1540  $var = '#';
1541  } else {
1542  $var = '';
1543  }
1544  break;
1545  case 'wrap':
1546  if (isset($Wdata[$key])) {
1547  $var .= '|' . $Wdata[$key];
1548  }
1549  break;
1550  case 'offset':
1551  if (isset($Wdata[$key])) {
1552  $var = (int)$var . ',' . (int)$Wdata[$key];
1553  if (isset($W2data[$key])) {
1554  $var .= ',' . (int)$W2data[$key];
1555  if (isset($W3data[$key])) {
1556  $var .= ',' . (int)$W3data[$key];
1557  if (isset($W4data[$key])) {
1558  $var .= ',' . (int)$W4data[$key];
1559  if (isset($W5data[$key])) {
1560  $var .= ',' . (int)$W5data[$key];
1561  }
1562  }
1563  }
1564  }
1565  }
1566  break;
1567  case 'boolean':
1568  if ($var) {
1569  $var = $typeDat['paramstr'] ? $typeDat['paramstr'] : 1;
1570  }
1571  break;
1572  }
1573  if ($this->ext_printAll || (string)$theConstants[$key]['value'] !== (string)$var) {
1574  // Put value in, if changed.
1575  $this->ext_putValueInConf($key, $var);
1576  }
1577  // Remove the entry because it has been "used"
1578  unset($check[$key]);
1579  } else {
1580  $this->ext_removeValueInConf($key);
1581  }
1582  }
1583  }
1584  }
1585  // Remaining keys in $check indicates fields that are just clicked "on" to be edited. Therefore we get the default value and puts that in the template as a start...
1586  if (!$this->ext_dontCheckIssetValues && is_array($check)) {
1587  foreach ($check as $key => $var) {
1588  if (isset($theConstants[$key])) {
1589  $dValue = $theConstants[$key]['default_value'];
1590  $this->ext_putValueInConf($key, $dValue);
1591  }
1592  }
1593  }
1594  }
1595 
1604  public function ext_prevPageWithTemplate($id, $perms_clause) {
1605  $rootLine = BackendUtility::BEgetRootLine($id, $perms_clause ? ' AND ' . $perms_clause : '');
1606  foreach ($rootLine as $p) {
1607  if ($this->ext_getFirstTemplate($p['uid'])) {
1608  return $p;
1609  }
1610  }
1611  }
1612 
1613 }
ext_outputTS(array $config, $lineNumbers=FALSE, $comments=FALSE, $crop=FALSE, $syntaxHL=FALSE, $syntaxHLBlockmode=0)
static BEgetRootLine($uid, $clause='', $workspaceOL=FALSE)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
ext_getObjTree($arr, $depth_in, $depthData, $parentType='', $parentValue='', $alphaSort='0')
static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=FALSE)
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
ext_getTemplateHierarchyArr($arr, $depthData, $keyArray, $first=0)
static callUserFunction($funcName, &$params, &$ref, $checkPrefix='', $errorMode=0)
static getSpriteIconForRecord($table, array $row, array $options=array())
static getModuleUrl($moduleName, $urlParameters=array(), $backPathOverride=FALSE, $returnAbsoluteUrl=FALSE)
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
ext_procesInput($http_post_vars, $http_post_files, $theConstants, $tplRow)
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel=E_DEBUG)
static fixed_lgd_cs($string, $chars, $appendString='...')
ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)
static getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)