TYPO3 CMS  TYPO3_7-6
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  {
90  $result = [];
92  $tsParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
93  $tsParser->tt_track = 0;
94  $tsParser->init();
95  // Gets the rootLine
96  $page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
97  $rootLine = $page->getRootLine($pageId);
98  // This generates the constants/config + hierarchy info for the template.
99  $tsParser->runThroughTemplates($rootLine);
100  // ts-setup & ts-constants of the currently edited template should not be included
101  // therefor we have to delete the last template from the stack
102  array_pop($tsParser->config);
103  array_pop($tsParser->constants);
104  $tsParser->linkObjects = true;
105  $tsParser->ext_regLinenumbers = false;
106  $tsParser->bType = $bType;
107  $tsParser->generateConfig();
108  $result = $this->treeWalkCleanup($tsParser->setup);
109  return $result;
110  }
111 
119  private function treeWalkCleanup(array $treeBranch)
120  {
121  $cleanedTreeBranch = [];
122  foreach ($treeBranch as $key => $value) {
123  $dotCount = substr_count($key, '.');
124  //type definition or value-assignment
125  if ($dotCount == 0) {
126  if ($value != '') {
127  if (strlen($value) > 20) {
128  $value = substr($value, 0, 20);
129  }
130  if (!isset($cleanedTreeBranch[$key])) {
131  $cleanedTreeBranch[$key] = [];
132  }
133  $cleanedTreeBranch[$key]['v'] = $value;
134  }
135  } elseif ($dotCount == 1) {
136  // subtree (definition of properties)
137  $subBranch = $this->treeWalkCleanup($value);
138  if ($subBranch) {
139  $key = str_replace('.', '', $key);
140  if (!isset($cleanedTreeBranch[$key])) {
141  $cleanedTreeBranch[$key] = [];
142  }
143  $cleanedTreeBranch[$key]['c'] = $subBranch;
144  }
145  }
146  }
147  return $cleanedTreeBranch;
148  }
149 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
processAjaxRequest(ServerRequestInterface $request, ResponseInterface $response)