TYPO3 CMS  TYPO3_7-6
InfoModuleController.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  */
16 
25 
31 {
35  public $pageinfo;
36 
43  public $doc;
44 
48  protected $backendUser;
49 
53  protected $languageService;
54 
60  protected $moduleName = 'web_info';
61 
67  protected $moduleTemplate;
68 
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 = [
81  'name' => $this->moduleName,
82  ];
83  }
84 
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 = ['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 .= '<div>' . $vContent . '</div>';
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 
141  public function printContent()
142  {
144  $this->content = $this->doc->insertStylesAndJS($this->content);
145  echo $this->content;
146  }
147 
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 
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'))
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 
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 
249  public function getModuleTemplate()
250  {
251  return $this->moduleTemplate;
252  }
253 }
static readPageAccess($id, $perms_clause)
static BEgetRootLine($uid, $clause='', $workspaceOL=false)
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static viewOnClick($pageUid, $backPath='', $rootLine=null, $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']