TYPO3 CMS  TYPO3_8-7
ViewModuleController.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 
28 
33 {
37  protected $defaultViewObjectName = BackendTemplateView::class;
38 
42  protected $view;
43 
49  protected function initializeView(ViewInterface $view)
50  {
52  parent::initializeView($view);
53  $this->registerButtons();
54  }
55 
59  protected function registerButtons()
60  {
61  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
62  $showButton = $buttonBar->makeLinkButton()
63  ->setHref($this->getTargetUrl())
64  ->setOnClick('window.open(this.href, \'newTYPO3frontendWindow\').focus();return false;')
65  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
66  ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-view', Icon::SIZE_SMALL));
67  $buttonBar->addButton($showButton);
68 
69  $refreshButton = $buttonBar->makeLinkButton()
70  ->setHref('javascript:document.getElementById(\'tx_viewpage_iframe\').contentWindow.location.reload(true);')
71  ->setTitle($this->getLanguageService()->sL('LLL:EXT:viewpage/Resources/Private/Language/locallang.xlf:refreshPage'))
72  ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
73  $buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
74 
75  $currentRequest = $this->request;
76  $moduleName = $currentRequest->getPluginName();
77  $getVars = $this->request->getArguments();
78  $extensionName = $currentRequest->getControllerExtensionName();
79  if (count($getVars) === 0) {
80  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
81  $getVars = ['id', 'M', $modulePrefix];
82  }
83  $shortcutButton = $buttonBar->makeShortcutButton()
84  ->setModuleName($moduleName)
85  ->setGetVariables($getVars);
86  $buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT, 2);
87  }
88 
92  public function initializeAction()
93  {
94  $this->getLanguageService()->includeLLFile('EXT:viewpage/Resources/Private/Language/locallang.xlf');
95  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
96  $pageRenderer->addInlineLanguageLabelFile('EXT:viewpage/Resources/Private/Language/locallang.xlf');
97  }
98 
102  public function showAction()
103  {
104  $this->view->assign('widths', $this->getPreviewFrameWidths());
105  $this->view->assign('url', $this->getTargetUrl());
106  $this->view->assign('languages', $this->getPreviewLanguages());
107  $this->view->assign('pageTitle', $this->getPageTitle());
108  }
109 
115  protected function getTargetUrl()
116  {
117  $pageIdToShow = (int)GeneralUtility::_GP('id');
118 
119  $permissionClause = $this->getBackendUser()->getPagePermsClause(1);
120  $pageRecord = BackendUtility::readPageAccess($pageIdToShow, $permissionClause);
121  if ($pageRecord) {
122  $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($pageRecord);
123 
124  $adminCommand = $this->getAdminCommand($pageIdToShow);
125  $domainName = $this->getDomainName($pageIdToShow);
126  $languageParameter = $this->getLanguageParameter();
127  // Mount point overlay: Set new target page id and mp parameter
129  $sysPage = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
130  $sysPage->init(false);
131  $mountPointMpParameter = '';
132  $finalPageIdToShow = $pageIdToShow;
133  $mountPointInformation = $sysPage->getMountPointInfo($pageIdToShow);
134  if ($mountPointInformation && $mountPointInformation['overlay']) {
135  // New page id
136  $finalPageIdToShow = $mountPointInformation['mount_pid'];
137  $mountPointMpParameter = '&MP=' . $mountPointInformation['MPvar'];
138  }
139  // Modify relative path to protocol with host if domain record is given
140  $protocolAndHost = '..';
141  if ($domainName) {
142  // TCEMAIN.previewDomain can contain the protocol, check prevents double protocol URLs
143  if (strpos($domainName, '://') !== false) {
144  $protocolAndHost = $domainName;
145  } else {
146  $protocol = GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https' : 'http';
147  $protocolAndHost = $protocol . '://' . $domainName;
148  }
149  }
150  return $protocolAndHost . '/index.php?id=' . $finalPageIdToShow . $this->getTypeParameterIfSet($finalPageIdToShow) . $mountPointMpParameter . $adminCommand . $languageParameter;
151  }
152  return '#';
153  }
154 
161  protected function getAdminCommand($pageId)
162  {
163  // The page will show only if there is a valid page and if this page may be viewed by the user
164  $pageinfo = BackendUtility::readPageAccess($pageId, $this->getBackendUser()->getPagePermsClause(1));
165  $addCommand = '';
166  if (is_array($pageinfo)) {
167  $addCommand = '&ADMCMD_editIcons=1' . BackendUtility::ADMCMD_previewCmds($pageinfo);
168  }
169  return $addCommand;
170  }
171 
180  protected function getTypeParameterIfSet($pageId)
181  {
182  $typeParameter = '';
183  $modTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.web_view');
184  $typeId = (int)$modTSconfig['properties']['type'];
185  if ($typeId > 0) {
186  $typeParameter = '&type=' . $typeId;
187  }
188  return $typeParameter;
189  }
190 
197  protected function getDomainName($pageId)
198  {
199  $previewDomainConfig = $this->getBackendUser()->getTSConfig('TCEMAIN.previewDomain', BackendUtility::getPagesTSconfig($pageId));
200  if ($previewDomainConfig['value']) {
201  $domain = $previewDomainConfig['value'];
202  } else {
204  }
205  return $domain;
206  }
207 
213  protected function getPreviewFrameWidths()
214  {
215  $pageId = (int)GeneralUtility::_GP('id');
216  $modTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.web_view');
217  $widths = [
218  '100%|100%' => $this->getLanguageService()->getLL('autoSize')
219  ];
220  if (is_array($modTSconfig['properties']['previewFrameWidths.'])) {
221  foreach ($modTSconfig['properties']['previewFrameWidths.'] as $item => $conf) {
222  $label = '';
223 
224  $width = substr($item, 0, -1);
225  $data = ['width' => $width];
226  $label .= $width . 'px ';
227 
228  //if height is set
229  if (isset($conf['height'])) {
230  $label .= ' × ' . $conf['height'] . 'px ';
231  $data['height'] = $conf['height'];
232  }
233 
234  if (substr($conf['label'], 0, 4) !== 'LLL:') {
235  $label .= $conf['label'];
236  } else {
237  $label .= $this->getLanguageService()->sL(trim($conf['label']));
238  }
239  $value = ($data['width'] ?: '100%') . '|' . ($data['height'] ?: '100%');
240  $widths[$value] = $label;
241  }
242  }
243  return $widths;
244  }
245 
251  protected function getPreviewLanguages()
252  {
253  $pageIdToShow = (int)GeneralUtility::_GP('id');
254  $modSharedTSconfig = BackendUtility::getModTSconfig($pageIdToShow, 'mod.SHARED');
255  if ($modSharedTSconfig['properties']['view.']['disableLanguageSelector'] === '1') {
256  return [];
257  }
258  $languages = [
259  0 => isset($modSharedTSconfig['properties']['defaultLanguageLabel'])
260  ? $modSharedTSconfig['properties']['defaultLanguageLabel'] . ' (' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage') . ')'
261  : $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage')
262  ];
263  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
264  $queryBuilder->getRestrictions()
265  ->removeAll()
266  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
267 
268  if (!$this->getBackendUser()->isAdmin()) {
269  $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
270  }
271 
272  $result = $queryBuilder->select('sys_language.uid', 'sys_language.title')
273  ->from('sys_language')
274  ->join(
275  'sys_language',
276  'pages_language_overlay',
277  'o',
278  $queryBuilder->expr()->eq('o.sys_language_uid', $queryBuilder->quoteIdentifier('sys_language.uid'))
279  )
280  ->where(
281  $queryBuilder->expr()->eq(
282  'o.pid',
283  $queryBuilder->createNamedParameter($pageIdToShow, \PDO::PARAM_INT)
284  )
285  )
286  ->groupBy('sys_language.uid', 'sys_language.title', 'sys_language.sorting')
287  ->orderBy('sys_language.sorting')
288  ->execute();
289 
290  while ($row = $result->fetch()) {
291  if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
292  $languages[$row['uid']] = $row['title'];
293  }
294  }
295  return $languages;
296  }
297 
303  protected function getPageTitle()
304  {
305  $pageIdToShow = (int)GeneralUtility::_GP('id');
306  $pageRecord = BackendUtility::getRecord('pages', $pageIdToShow);
307  $pageRecordTitle = is_array($pageRecord)
308  ? BackendUtility::getRecordTitle('pages', $pageRecord)
309  : '';
310 
311  return $pageRecordTitle;
312  }
313 
319  protected function getLanguageParameter()
320  {
321  $states = $this->getBackendUser()->uc['moduleData']['web_view']['States'];
322  $languages = $this->getPreviewLanguages();
323  $languageParameter = '';
324  if (isset($states['languageSelectorValue']) && isset($languages[$states['languageSelectorValue']])) {
325  $languageParameter = '&L=' . (int)$states['languageSelectorValue'];
326  }
327  return $languageParameter;
328  }
329 
333  protected function getBackendUser()
334  {
335  return $GLOBALS['BE_USER'];
336  }
337 
341  protected function getLanguageService()
342  {
343  return $GLOBALS['LANG'];
344  }
345 }
static getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
static readPageAccess($id, $perms_clause)
static BEgetRootLine($uid, $clause='', $workspaceOL=false)
static makeInstance($className,... $constructorArguments)
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']