d79736a4f1c38592c55c88186e033b5a7b8c86b4
[Packages/TYPO3.CMS.git] / typo3 / sysext / viewpage / Classes / Controller / ViewModuleController.php
1 <?php
2 namespace TYPO3\CMS\Viewpage\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Felix Kopp <felix-source@phorax.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28 /**
29 * Controller for viewing the frontend
30 *
31 * @author Felix Kopp <felix-source@phorax.com>
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34 class ViewModuleController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
35
36 /**
37 * Show selected page from pagetree in iframe
38 *
39 * @return void
40 */
41 public function showAction() {
42 $this->view->assign('url', $this->getTargetUrl());
43 }
44
45 /**
46 * Determine the url to view
47 *
48 * @return string
49 */
50 protected function getTargetUrl() {
51 $pageIdToShow = intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'));
52 $adminCommand = $this->getAdminCommand($pageIdToShow);
53 $domainName = $this->getDomainName($pageIdToShow);
54 // Mount point overlay: Set new target page id and mp parameter
55 /** @var \TYPO3\CMS\Frontend\Page\PageRepository $sysPage */
56 $sysPage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
57 $sysPage->init(FALSE);
58 $mountPointMpParameter = '';
59 $finalPageIdToShow = $pageIdToShow;
60 $mountPointInformation = $sysPage->getMountPointInfo($pageIdToShow);
61 if ($mountPointInformation && $mountPointInformation['overlay']) {
62 // New page id
63 $finalPageIdToShow = $mountPointInformation['mount_pid'];
64 $mountPointMpParameter = '&MP=' . $mountPointInformation['MPvar'];
65 }
66 // Modify relative path to protocol with host if domain record is given
67 $protocolAndHost = '..';
68 if ($domainName) {
69 $protocol = 'http';
70 $page = (array) $sysPage->getPage($finalPageIdToShow);
71 if ($page['url_scheme'] == 2 || $page['url_scheme'] == 0 && \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
72 $protocol = 'https';
73 }
74 $protocolAndHost = $protocol . '://' . $domainName;
75 }
76 $url = $protocolAndHost . '/index.php?id=' . $finalPageIdToShow . $this->getTypeParameterIfSet($finalPageIdToShow) . $mountPointMpParameter . $adminCommand;
77 return $url;
78 }
79
80 /**
81 * Get admin command
82 *
83 * @param integer $pageId
84 * @return string
85 */
86 protected function getAdminCommand($pageId) {
87 // The page will show only if there is a valid page and if this page may be viewed by the user
88 $pageinfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($pageId, $GLOBALS['BE_USER']->getPagePermsClause(1));
89 $addCommand = '';
90 if (is_array($pageinfo)) {
91 $addCommand = '&ADMCMD_view=1&ADMCMD_editIcons=1' . \TYPO3\CMS\Backend\Utility\BackendUtility::ADMCMD_previewCmds($pageinfo);
92 }
93 return $addCommand;
94 }
95
96 /**
97 * With page TS config it is possible to force a specific type id via mod.web_view.type
98 * for a page id or a page tree.
99 * The method checks if a type is set for the given id and returns the additional GET string.
100 *
101 * @param integer $pageId
102 * @return string
103 */
104 protected function getTypeParameterIfSet($pageId) {
105 $typeParameter = '';
106 $modTSconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($pageId, 'mod.web_view');
107 $typeId = intval($modTSconfig['properties']['type']);
108 if ($typeId > 0) {
109 $typeParameter = '&type=' . $typeId;
110 }
111 return $typeParameter;
112 }
113
114 /**
115 * Get domain name for requested page id
116 *
117 * @param integer $pageId
118 * @return boolean|string Domain name if there is one, FALSE if not
119 */
120 protected function getDomainName($pageId) {
121 $domain = \TYPO3\CMS\Backend\Utility\BackendUtility::firstDomainRecord(\TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($pageId));
122 return $domain;
123 }
124
125 }
126
127
128 ?>