1b58ce48c8f4afbacb3175e78f58b886bff0142a
[Packages/TYPO3.CMS.git] / typo3 / sysext / info / Classes / Controller / InfoModuleController.php
1 <?php
2 namespace TYPO3\CMS\Info\Controller;
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 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\BaseScriptClass;
20 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Imaging\Icon;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25
26 /**
27 * Script Class for the Web > Info module
28 * This class creates the framework to which other extensions can connect their sub-modules
29 */
30 class InfoModuleController extends BaseScriptClass
31 {
32 /**
33 * @var array
34 */
35 public $pageinfo;
36
37 /**
38 * Document Template Object
39 *
40 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
41 * @deprecated
42 */
43 public $doc;
44
45 /**
46 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
47 */
48 protected $backendUser;
49
50 /**
51 * @var \TYPO3\CMS\Lang\LanguageService
52 */
53 protected $languageService;
54
55 /**
56 * The name of the module
57 *
58 * @var string
59 */
60 protected $moduleName = 'web_info';
61
62 /**
63 * ModuleTemplate Container
64 *
65 * @var ModuleTemplate
66 */
67 protected $moduleTemplate;
68
69 /**
70 * Constructor
71 */
72 public function __construct()
73 {
74 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
75 $this->languageService = $GLOBALS['LANG'];
76 $this->languageService->includeLLFile('EXT:lang/locallang_mod_web_info.xlf');
77
78 $this->backendUser = $GLOBALS['BE_USER'];
79
80 $this->MCONF = array(
81 'name' => $this->moduleName,
82 );
83 }
84
85 /**
86 * Initialize module header etc and call extObjContent function
87 *
88 * @return void
89 */
90 public function main()
91 {
92 // We leave this here because of dependencies to submodules
93 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
94
95 // The page will show only if there is a valid page and if this page
96 // may be viewed by the user
97 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
98 if ($this->pageinfo) {
99 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
100 }
101 $access = is_array($this->pageinfo);
102 if ($this->id && $access || $this->backendUser->user['admin'] && !$this->id) {
103 if ($this->backendUser->user['admin'] && !$this->id) {
104 $this->pageinfo = array('title' => '[root-level]', 'uid' => 0, 'pid' => 0);
105 }
106 // JavaScript
107 $this->moduleTemplate->addJavaScriptCode(
108 'WebFuncInLineJS',
109 'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
110 function jumpToUrl(URL) {
111 window.location.href = URL;
112 return false;
113 }
114 '
115 );
116 // Setting up the context sensitive menu:
117 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
118 $this->content .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl($this->moduleName)) .
119 '" method="post" id="InfoModuleController" name="webinfoForm" class="form-inline form-inline-spaced">';
120 $vContent = $this->moduleTemplate->getVersionSelector($this->id, 1);
121 if ($vContent) {
122 $this->content .= $this->moduleTemplate->section('', $vContent);
123 }
124 $this->extObjContent();
125 // Setting up the buttons and markers for docheader
126 $this->getButtons();
127 $this->generateMenu();
128 $this->content .= '</form>';
129 } else {
130 // If no access or if ID == zero
131 $this->content = $this->doc->header($this->languageService->getLL('title'));
132 }
133 }
134
135 /**
136 * Print module content (from $this->content)
137 *
138 * @return void
139 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
140 */
141 public function printContent()
142 {
143 GeneralUtility::logDeprecatedFunction();
144 $this->content = $this->doc->insertStylesAndJS($this->content);
145 echo $this->content;
146 }
147
148 /**
149 * Injects the request object for the current request or subrequest
150 * Then checks for module functions that have hooked in, and renders menu etc.
151 *
152 * @param ServerRequestInterface $request the current request
153 * @param ResponseInterface $response
154 * @return ResponseInterface the response with the content
155 */
156 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
157 {
158 $GLOBALS['SOBE'] = $this;
159 $this->init();
160
161 // Checking for first level external objects
162 $this->checkExtObj();
163
164 // Checking second level external objects
165 $this->checkSubExtObj();
166 $this->main();
167
168 $this->moduleTemplate->setContent($this->content);
169 $response->getBody()->write($this->moduleTemplate->renderContent());
170 return $response;
171 }
172
173 /**
174 * Create the panel of buttons for submitting the form or otherwise perform operations.
175 */
176 protected function getButtons()
177 {
178 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
179 // CSH
180 $cshButton = $buttonBar->makeHelpButton()
181 ->setModuleName('_MOD_web_info')
182 ->setFieldName('');
183 $buttonBar->addButton($cshButton, ButtonBar::BUTTON_POSITION_LEFT, 0);
184 // View page
185 $viewButton = $buttonBar->makeLinkButton()
186 ->setHref('#')
187 ->setOnClick(BackendUtility::viewOnClick(
188 $this->pageinfo['uid'],
189 '',
190 BackendUtility::BEgetRootLine($this->pageinfo['uid'])
191 ))
192 ->setTitle($this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true))
193 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-view', Icon::SIZE_SMALL));
194 $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
195 // Shortcut
196 $shortCutButton = $buttonBar->makeShortcutButton()
197 ->setModuleName($this->moduleName)
198 ->setDisplayName($this->MOD_MENU['function'][$this->MOD_SETTINGS['function']])
199 ->setGetVariables([
200 'M',
201 'id',
202 'edit_record',
203 'pointer',
204 'new_unique_uid',
205 'search_field',
206 'search_levels',
207 'showLimit'
208 ])
209 ->setSetVariables(array_keys($this->MOD_MENU));
210 $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT);
211 }
212
213 /**
214 * Generate the ModuleMenu
215 */
216 protected function generateMenu()
217 {
218 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
219 $menu->setIdentifier('WebInfoJumpMenu');
220 foreach ($this->MOD_MENU['function'] as $controller => $title) {
221 $item = $menu
222 ->makeMenuItem()
223 ->setHref(
224 BackendUtility::getModuleUrl(
225 $this->moduleName,
226 [
227 'id' => $this->id,
228 'SET' => [
229 'function' => $controller
230 ]
231 ]
232 )
233 )
234 ->setTitle($title);
235 if ($controller === $this->MOD_SETTINGS['function']) {
236 $item->setActive(true);
237 }
238 $menu->addMenuItem($item);
239 }
240 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
241 }
242
243 /**
244 * Returns the ModuleTemplate container
245 * This is used by PageLayoutView.php
246 *
247 * @return ModuleTemplate
248 */
249 public function getModuleTemplate()
250 {
251 return $this->moduleTemplate;
252 }
253 }