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