TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ViewModuleController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Viewpage\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 
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 
94  public function initializeAction()
95  {
96  $this->getLanguageService()->includeLLFile('EXT:viewpage/Resources/Private/Language/locallang.xlf');
97  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
98  $pageRenderer->addInlineLanguageLabelFile('EXT:viewpage/Resources/Private/Language/locallang.xlf');
99  }
100 
106  public function showAction()
107  {
108  $this->view->assign('widths', $this->getPreviewFrameWidths());
109  $this->view->assign('url', $this->getTargetUrl());
110  $this->view->assign('languages', $this->getPreviewLanguages());
111  }
112 
118  protected function getTargetUrl()
119  {
120  $pageIdToShow = (int)GeneralUtility::_GP('id');
121 
122  $permissionClause = $this->getBackendUser()->getPagePermsClause(1);
123  $pageRecord = BackendUtility::readPageAccess($pageIdToShow, $permissionClause);
124  if ($pageRecord) {
125  $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($pageRecord);
126 
127  $adminCommand = $this->getAdminCommand($pageIdToShow);
128  $domainName = $this->getDomainName($pageIdToShow);
129  $languageParameter = $this->getLanguageParameter();
130  // Mount point overlay: Set new target page id and mp parameter
132  $sysPage = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
133  $sysPage->init(false);
134  $mountPointMpParameter = '';
135  $finalPageIdToShow = $pageIdToShow;
136  $mountPointInformation = $sysPage->getMountPointInfo($pageIdToShow);
137  if ($mountPointInformation && $mountPointInformation['overlay']) {
138  // New page id
139  $finalPageIdToShow = $mountPointInformation['mount_pid'];
140  $mountPointMpParameter = '&MP=' . $mountPointInformation['MPvar'];
141  }
142  // Modify relative path to protocol with host if domain record is given
143  $protocolAndHost = '..';
144  if ($domainName) {
145  // TCEMAIN.previewDomain can contain the protocol, check prevents double protocol URLs
146  if (strpos($domainName, '://') !== false) {
147  $protocolAndHost = $domainName;
148  } else {
149  $protocol = 'http';
150  $page = (array)$sysPage->getPage($finalPageIdToShow);
151  if ($page['url_scheme'] == 2 || $page['url_scheme'] == 0 && GeneralUtility::getIndpEnv('TYPO3_SSL')) {
152  $protocol = 'https';
153  }
154  $protocolAndHost = $protocol . '://' . $domainName;
155  }
156  }
157  return $protocolAndHost . '/index.php?id=' . $finalPageIdToShow . $this->getTypeParameterIfSet($finalPageIdToShow) . $mountPointMpParameter . $adminCommand . $languageParameter;
158  } else {
159  return '#';
160  }
161  }
162 
169  protected function getAdminCommand($pageId)
170  {
171  // The page will show only if there is a valid page and if this page may be viewed by the user
172  $pageinfo = BackendUtility::readPageAccess($pageId, $this->getBackendUser()->getPagePermsClause(1));
173  $addCommand = '';
174  if (is_array($pageinfo)) {
175  $addCommand = '&ADMCMD_editIcons=1' . BackendUtility::ADMCMD_previewCmds($pageinfo);
176  }
177  return $addCommand;
178  }
179 
188  protected function getTypeParameterIfSet($pageId)
189  {
190  $typeParameter = '';
191  $modTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.web_view');
192  $typeId = (int)$modTSconfig['properties']['type'];
193  if ($typeId > 0) {
194  $typeParameter = '&type=' . $typeId;
195  }
196  return $typeParameter;
197  }
198 
205  protected function getDomainName($pageId)
206  {
207  $previewDomainConfig = $this->getBackendUser()->getTSConfig('TCEMAIN.previewDomain', BackendUtility::getPagesTSconfig($pageId));
208  if ($previewDomainConfig['value']) {
209  $domain = $previewDomainConfig['value'];
210  } else {
212  }
213  return $domain;
214  }
215 
221  protected function getPreviewFrameWidths()
222  {
223  $pageId = (int)GeneralUtility::_GP('id');
224  $modTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.web_view');
225  $widths = [
226  '100%|100%' => $this->getLanguageService()->getLL('autoSize')
227  ];
228  if (is_array($modTSconfig['properties']['previewFrameWidths.'])) {
229  foreach ($modTSconfig['properties']['previewFrameWidths.'] as $item => $conf) {
230  $label = '';
231 
232  $width = substr($item, 0, -1);
233  $data = ['width' => $width];
234  $label .= $width . 'px ';
235 
236  //if height is set
237  if (isset($conf['height'])) {
238  $label .= ' × ' . $conf['height'] . 'px ';
239  $data['height'] = $conf['height'];
240  }
241 
242  if (substr($conf['label'], 0, 4) !== 'LLL:') {
243  $label .= $conf['label'];
244  } else {
245  $label .= $this->getLanguageService()->sL(trim($conf['label']));
246  }
247  $value = ($data['width'] ?: '100%') . '|' . ($data['height'] ?: '100%');
248  $widths[$value] = $label;
249  }
250  }
251  return $widths;
252  }
253 
259  protected function getPreviewLanguages()
260  {
261  $pageIdToShow = (int)GeneralUtility::_GP('id');
262  $modSharedTSconfig = BackendUtility::getModTSconfig($pageIdToShow, 'mod.SHARED');
263  if ($modSharedTSconfig['properties']['view.']['disableLanguageSelector'] === '1') {
264  return [];
265  }
266  $languages = [
267  0 => isset($modSharedTSconfig['properties']['defaultLanguageLabel'])
268  ? $modSharedTSconfig['properties']['defaultLanguageLabel'] . ' (' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage') . ')'
269  : $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:defaultLanguage')
270  ];
271  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
272  $queryBuilder->getRestrictions()
273  ->removeAll()
274  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
275 
276  if (!$this->getBackendUser()->isAdmin()) {
277  $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
278  }
279 
280  $result = $queryBuilder->select('sys_language.uid', 'sys_language.title')
281  ->from('sys_language')
282  ->join(
283  'sys_language',
284  'pages_language_overlay',
285  'o',
286  $queryBuilder->expr()->eq('o.sys_language_uid', $queryBuilder->quoteIdentifier('sys_language.uid'))
287  )
288  ->where(
289  $queryBuilder->expr()->eq(
290  'o.pid',
291  $queryBuilder->createNamedParameter($pageIdToShow, \PDO::PARAM_INT)
292  )
293  )
294  ->groupBy('sys_language.uid', 'sys_language.title')
295  ->orderBy('sys_language.sorting')
296  ->execute();
297 
298  while ($row = $result->fetch()) {
299  if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
300  $languages[$row['uid']] = $row['title'];
301  }
302  }
303  return $languages;
304  }
305 
311  protected function getLanguageParameter()
312  {
313  $states = $this->getBackendUser()->uc['moduleData']['web_view']['States'];
314  $languages = $this->getPreviewLanguages();
315  $languageParameter = '';
316  if (isset($states['languageSelectorValue']) && isset($languages[$states['languageSelectorValue']])) {
317  $languageParameter = '&L=' . (int)$states['languageSelectorValue'];
318  }
319  return $languageParameter;
320  }
321 
325  protected function getBackendUser()
326  {
327  return $GLOBALS['BE_USER'];
328  }
329 
333  protected function getLanguageService()
334  {
335  return $GLOBALS['LANG'];
336  }
337 }
static BEgetRootLine($uid, $clause= '', $workspaceOL=false)
static getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)