TYPO3 CMS  TYPO3_7-6
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 
25 
30 {
34  protected $defaultViewObjectName = BackendTemplateView::class;
35 
39  protected $view;
40 
46  protected function initializeView(ViewInterface $view)
47  {
49  parent::initializeView($view);
50  $this->registerButtons();
51  }
52 
56  protected function registerButtons()
57  {
58  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
59  $showButton = $buttonBar->makeLinkButton()
60  ->setHref($this->getTargetUrl())
61  ->setOnClick('window.open(this.href, \'newTYPO3frontendWindow\').focus();return false;')
62  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage'))
63  ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-view', Icon::SIZE_SMALL));
64  $buttonBar->addButton($showButton);
65 
66  $refreshButton = $buttonBar->makeLinkButton()
67  ->setHref('javascript:document.getElementById(\'tx_viewpage_iframe\').contentWindow.location.reload(true);')
68  ->setTitle($this->getLanguageService()->sL('LLL:EXT:viewpage/Resources/Private/Language/locallang.xlf:refreshPage'))
69  ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
70  $buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
71 
72  $currentRequest = $this->request;
73  $moduleName = $currentRequest->getPluginName();
74  $getVars = $this->request->getArguments();
75  $extensionName = $currentRequest->getControllerExtensionName();
76  if (count($getVars) === 0) {
77  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
78  $getVars = ['id', 'M', $modulePrefix];
79  }
80  $shortcutButton = $buttonBar->makeShortcutButton()
81  ->setModuleName($moduleName)
82  ->setGetVariables($getVars);
83  $buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT, 2);
84  }
85 
91  public function initializeAction()
92  {
93  $this->getLanguageService()->includeLLFile('EXT:viewpage/Resources/Private/Language/locallang.xlf');
94  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
95  $pageRenderer->addInlineLanguageLabelFile('EXT:viewpage/Resources/Private/Language/locallang.xlf');
96  }
97 
103  public function showAction()
104  {
105  $this->view->assign('widths', $this->getPreviewFrameWidths());
106  $this->view->assign('url', $this->getTargetUrl());
107  $this->view->assign('languages', $this->getPreviewLanguages());
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 = 'http';
147  $page = (array)$sysPage->getPage($finalPageIdToShow);
148  if ($page['url_scheme'] == 2 || $page['url_scheme'] == 0 && GeneralUtility::getIndpEnv('TYPO3_SSL')) {
149  $protocol = 'https';
150  }
151  $protocolAndHost = $protocol . '://' . $domainName;
152  }
153  }
154  return $protocolAndHost . '/index.php?id=' . $finalPageIdToShow . $this->getTypeParameterIfSet($finalPageIdToShow) . $mountPointMpParameter . $adminCommand . $languageParameter;
155  } else {
156  return '#';
157  }
158  }
159 
166  protected function getAdminCommand($pageId)
167  {
168  // The page will show only if there is a valid page and if this page may be viewed by the user
169  $pageinfo = BackendUtility::readPageAccess($pageId, $this->getBackendUser()->getPagePermsClause(1));
170  $addCommand = '';
171  if (is_array($pageinfo)) {
172  $addCommand = '&ADMCMD_editIcons=1' . BackendUtility::ADMCMD_previewCmds($pageinfo);
173  }
174  return $addCommand;
175  }
176 
185  protected function getTypeParameterIfSet($pageId)
186  {
187  $typeParameter = '';
188  $modTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.web_view');
189  $typeId = (int)$modTSconfig['properties']['type'];
190  if ($typeId > 0) {
191  $typeParameter = '&type=' . $typeId;
192  }
193  return $typeParameter;
194  }
195 
202  protected function getDomainName($pageId)
203  {
204  $previewDomainConfig = $this->getBackendUser()->getTSConfig('TCEMAIN.previewDomain', BackendUtility::getPagesTSconfig($pageId));
205  if ($previewDomainConfig['value']) {
206  $domain = $previewDomainConfig['value'];
207  } else {
209  }
210  return $domain;
211  }
212 
218  protected function getPreviewFrameWidths()
219  {
220  $pageId = (int)GeneralUtility::_GP('id');
221  $modTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.web_view');
222  $widths = [
223  '100%|100%' => $this->getLanguageService()->getLL('autoSize')
224  ];
225  if (is_array($modTSconfig['properties']['previewFrameWidths.'])) {
226  foreach ($modTSconfig['properties']['previewFrameWidths.'] as $item => $conf) {
227  $label = '';
228 
229  $width = substr($item, 0, -1);
230  $data = ['width' => $width];
231  $label .= $width . 'px ';
232 
233  //if height is set
234  if (isset($conf['height'])) {
235  $label .= ' × ' . $conf['height'] . 'px ';
236  $data['height'] = $conf['height'];
237  }
238 
239  if (substr($conf['label'], 0, 4) !== 'LLL:') {
240  $label .= $conf['label'];
241  } else {
242  $label .= $this->getLanguageService()->sL(trim($conf['label']));
243  }
244  $value = ($data['width'] ?: '100%') . '|' . ($data['height'] ?: '100%');
245  $widths[$value] = $label;
246  }
247  }
248  return $widths;
249  }
250 
256  protected function getPreviewLanguages()
257  {
258  $pageIdToShow = (int)GeneralUtility::_GP('id');
259  $modSharedTSconfig = BackendUtility::getModTSconfig($pageIdToShow, 'mod.SHARED');
260  if ($modSharedTSconfig['properties']['view.']['disableLanguageSelector'] === '1') {
261  return [];
262  }
263  $languages = [
264  0 => isset($modSharedTSconfig['properties']['defaultLanguageLabel'])
265  ? $modSharedTSconfig['properties']['defaultLanguageLabel'] . ' (' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage') . ')'
266  : $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage')
267  ];
268  $excludeHidden = $this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0';
269  $rows = $this->getDatabaseConnection()->exec_SELECTgetRows(
270  'sys_language.*',
271  'pages_language_overlay JOIN sys_language ON pages_language_overlay.sys_language_uid = sys_language.uid',
272  'pages_language_overlay.pid = ' . (int)$pageIdToShow . BackendUtility::deleteClause('pages_language_overlay') . $excludeHidden,
273  'pages_language_overlay.sys_language_uid, sys_language.uid, sys_language.pid, sys_language.tstamp, sys_language.hidden, sys_language.title, sys_language.static_lang_isocode, sys_language.flag',
274  'sys_language.title'
275  );
276  if (!empty($rows)) {
277  foreach ($rows as $row) {
278  if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
279  $languages[$row['uid']] = $row['title'];
280  }
281  }
282  }
283  return $languages;
284  }
285 
291  protected function getLanguageParameter()
292  {
293  $states = $this->getBackendUser()->uc['moduleData']['web_view']['States'];
294  $languages = $this->getPreviewLanguages();
295  $languageParameter = '';
296  if (isset($states['languageSelectorValue']) && isset($languages[$states['languageSelectorValue']])) {
297  $languageParameter = '&L=' . (int)$states['languageSelectorValue'];
298  }
299  return $languageParameter;
300  }
301 
305  protected function getDatabaseConnection()
306  {
307  return $GLOBALS['TYPO3_DB'];
308  }
309 
313  protected function getBackendUser()
314  {
315  return $GLOBALS['BE_USER'];
316  }
317 
321  protected function getLanguageService()
322  {
323  return $GLOBALS['LANG'];
324  }
325 }
static getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
static readPageAccess($id, $perms_clause)
static BEgetRootLine($uid, $clause='', $workspaceOL=false)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static deleteClause($table, $tableAlias='')