TYPO3 CMS  TYPO3_8-7
CodeCompletion.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
19 
24 {
28  protected $ajaxObj;
29 
33  public function __construct()
34  {
35  $GLOBALS['LANG']->includeLLFile('EXT:t3editor/Resources/Private/Language/locallang.xlf');
36  }
37 
46  public function processAjaxRequest(ServerRequestInterface $request, ResponseInterface $response)
47  {
48  $pageId = (int)(isset($request->getParsedBody()['pageId']) ? $request->getParsedBody()['pageId'] : $request->getQueryParams()['pageId']);
49  return $this->loadTemplates($pageId);
50  }
51 
59  protected function loadTemplates($pageId)
60  {
62  $response = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\Response::class);
63 
64  // Check whether access is granted (only admin have access to sys_template records):
65  if ($GLOBALS['BE_USER']->isAdmin()) {
66  // Check whether there is a pageId given:
67  if ($pageId) {
68  $response->getBody()->write(json_encode($this->getMergedTemplates($pageId)));
69  } else {
70  $response->getBody()->write($GLOBALS['LANG']->getLL('pageIDInteger'));
71  $response = $response->withStatus(500);
72  }
73  } else {
74  $response->getBody()->write($GLOBALS['LANG']->getLL('noPermission'));
75  $response = $response->withStatus(500);
76  }
77  return $response;
78  }
79 
88  protected function getMergedTemplates($pageId, $templateId = 0)
89  {
91  $tsParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
92  $tsParser->init();
93  // Gets the rootLine
94  $page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
95  $rootLine = $page->getRootLine($pageId);
96  // This generates the constants/config + hierarchy info for the template.
97  $tsParser->runThroughTemplates($rootLine);
98  // ts-setup & ts-constants of the currently edited template should not be included
99  // therefor we have to delete the last template from the stack
100  array_pop($tsParser->config);
101  array_pop($tsParser->constants);
102  $tsParser->linkObjects = true;
103  $tsParser->ext_regLinenumbers = false;
104  $tsParser->generateConfig();
105  $result = $this->treeWalkCleanup($tsParser->setup);
106  return $result;
107  }
108 
116  private function treeWalkCleanup(array $treeBranch)
117  {
118  $cleanedTreeBranch = [];
119  foreach ($treeBranch as $key => $value) {
120  $dotCount = substr_count($key, '.');
121  //type definition or value-assignment
122  if ($dotCount == 0) {
123  if ($value != '') {
124  if (strlen($value) > 20) {
125  $value = substr($value, 0, 20);
126  }
127  if (!isset($cleanedTreeBranch[$key])) {
128  $cleanedTreeBranch[$key] = [];
129  }
130  $cleanedTreeBranch[$key]['v'] = $value;
131  }
132  } elseif ($dotCount == 1) {
133  // subtree (definition of properties)
134  $subBranch = $this->treeWalkCleanup($value);
135  if ($subBranch) {
136  $key = str_replace('.', '', $key);
137  if (!isset($cleanedTreeBranch[$key])) {
138  $cleanedTreeBranch[$key] = [];
139  }
140  $cleanedTreeBranch[$key]['c'] = $subBranch;
141  }
142  }
143  }
144  return $cleanedTreeBranch;
145  }
146 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
processAjaxRequest(ServerRequestInterface $request, ResponseInterface $response)