[FEATURE] Responsive website preview
[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 public function __construct() {
37 parent::__construct();
38
39 $GLOBALS['LANG']->includeLLFile('EXT:viewpage/Resources/Private/Language/locallang.xlf');
40 }
41
42 /**
43 * Show selected page from pagetree in iframe
44 *
45 * @return void
46 */
47 public function showAction() {
48 $this->view->assignMultiple(
49 array(
50 'widths' => $this->getPreviewFrameWidths(),
51 'url' => $this->getTargetUrl()
52 )
53 );
54 }
55
56 /**
57 * Determine the url to view
58 *
59 * @return string
60 */
61 protected function getTargetUrl() {
62 $pageIdToShow = intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'));
63 $adminCommand = $this->getAdminCommand($pageIdToShow);
64 $domainName = $this->getDomainName($pageIdToShow);
65 // Mount point overlay: Set new target page id and mp parameter
66 /** @var \TYPO3\CMS\Frontend\Page\PageRepository $sysPage */
67 $sysPage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
68 $sysPage->init(FALSE);
69 $mountPointMpParameter = '';
70 $finalPageIdToShow = $pageIdToShow;
71 $mountPointInformation = $sysPage->getMountPointInfo($pageIdToShow);
72 if ($mountPointInformation && $mountPointInformation['overlay']) {
73 // New page id
74 $finalPageIdToShow = $mountPointInformation['mount_pid'];
75 $mountPointMpParameter = '&MP=' . $mountPointInformation['MPvar'];
76 }
77 // Modify relative path to protocol with host if domain record is given
78 $protocolAndHost = '..';
79 if ($domainName) {
80 $protocol = 'http';
81 $page = (array) $sysPage->getPage($finalPageIdToShow);
82 if ($page['url_scheme'] == 2 || $page['url_scheme'] == 0 && \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
83 $protocol = 'https';
84 }
85 $protocolAndHost = $protocol . '://' . $domainName;
86 }
87 $url = $protocolAndHost . '/index.php?id=' . $finalPageIdToShow . $this->getTypeParameterIfSet($finalPageIdToShow) . $mountPointMpParameter . $adminCommand;
88 return $url;
89 }
90
91 /**
92 * Get admin command
93 *
94 * @param integer $pageId
95 * @return string
96 */
97 protected function getAdminCommand($pageId) {
98 // The page will show only if there is a valid page and if this page may be viewed by the user
99 $pageinfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($pageId, $GLOBALS['BE_USER']->getPagePermsClause(1));
100 $addCommand = '';
101 if (is_array($pageinfo)) {
102 $addCommand = '&ADMCMD_view=1&ADMCMD_editIcons=1' . \TYPO3\CMS\Backend\Utility\BackendUtility::ADMCMD_previewCmds($pageinfo);
103 }
104 return $addCommand;
105 }
106
107 /**
108 * With page TS config it is possible to force a specific type id via mod.web_view.type
109 * for a page id or a page tree.
110 * The method checks if a type is set for the given id and returns the additional GET string.
111 *
112 * @param integer $pageId
113 * @return string
114 */
115 protected function getTypeParameterIfSet($pageId) {
116 $typeParameter = '';
117 $modTSconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($pageId, 'mod.web_view');
118 $typeId = intval($modTSconfig['properties']['type']);
119 if ($typeId > 0) {
120 $typeParameter = '&type=' . $typeId;
121 }
122 return $typeParameter;
123 }
124
125 /**
126 * Get domain name for requested page id
127 *
128 * @param integer $pageId
129 * @return boolean|string Domain name if there is one, FALSE if not
130 */
131 protected function getDomainName($pageId) {
132 $domain = \TYPO3\CMS\Backend\Utility\BackendUtility::firstDomainRecord(\TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($pageId));
133 return $domain;
134 }
135
136 /**
137 * Get available widths for preview frame
138 *
139 * @return array
140 */
141 protected function getPreviewFrameWidths() {
142 return array(
143 '1280' => '1280px ' . $GLOBALS['LANG']->getLL('computer'),
144 '1024' => '1024px ' . $GLOBALS['LANG']->getLL('tablet'),
145 '960' => '960px ' . $GLOBALS['LANG']->getLL('mobile'),
146 '800' => '800px ' . $GLOBALS['LANG']->getLL('computer'),
147 '768' => '768px ' . $GLOBALS['LANG']->getLL('tablet'),
148 '600' => '600px ' . $GLOBALS['LANG']->getLL('tablet'),
149 '640' => '640px ' . $GLOBALS['LANG']->getLL('mobile'),
150 '480' => '480px ' . $GLOBALS['LANG']->getLL('mobile'),
151 '400' => '400px ' . $GLOBALS['LANG']->getLL('mobile'),
152 '360' => '360px ' . $GLOBALS['LANG']->getLL('mobile'),
153 '300' => '300px ' . $GLOBALS['LANG']->getLL('mobile')
154 );
155 }
156
157 }
158
159 ?>