6686983a03fbdb00c737ab1f39e748ce566265c3
[Packages/TYPO3.CMS.git] / typo3 / mod / user / ws / wsol_preview.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * Workspace preview module
26 *
27 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
28 */
29 /**
30 * [CLASS/FUNCTION INDEX of SCRIPT]
31 *
32 *
33 *
34 * 62: class wsol_preview
35 * 71: function main()
36 * 133: function generateUrls()
37 * 164: function printFrameset()
38 * 206: function isBeLogin()
39 *
40 * TOTAL FUNCTIONS: 4
41 * (This index is automatically created/updated by the extension "extdeveval")
42 *
43 */
44
45 define('TYPO3_PROCEED_IF_NO_USER', '1');
46
47 unset($MCONF);
48 require('conf.php');
49 require($BACK_PATH.'init.php');
50 require_once('class.wslib.php');
51
52
53
54 /**
55 * Workspace dual preview
56 * NOTICE: In this module you HAVE to check if a backend user is actually logged in if you perform operations that require a login! See function ->isBeLogin()
57 *
58 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
59 * @package TYPO3
60 * @subpackage core
61 */
62 class wsol_preview {
63
64 var $workspace = 0; // Which workspace to preview!
65
66 /**
67 * Main function of class
68 *
69 * @return void
70 */
71 function main() {
72
73 if ($this->isBeLogin()) {
74 $this->workspace = $GLOBALS['BE_USER']->workspace;
75 }
76
77 if ($header = t3lib_div::_GP('header')) {
78 if ($header!=='live') {
79 $headerText = 'Workspace Version ('.$this->workspace.'):';
80 $color = 'green';
81 } else {
82 $headerText = 'Live Version:';
83 $color = 'red';
84 }
85
86 $output = '
87 <html>
88 <head>
89 <title>Header</title>
90 </head>
91 <body bgcolor="'.$color.'">
92 <font face="verdana,arial" size="2" color="white"><b>'.$headerText.'</b></font>
93 </body>
94 </html>';
95 } elseif ($msg = t3lib_div::_GP('msg')) {
96 switch($msg) {
97 case 'branchpoint':
98 $message = '<b>No live page available!</b><br/><br/>
99 The previewed page was inside a "Branch" type version and has no traceable counterpart in the live workspace.';
100 break;
101 case 'newpage':
102 $message = '<b>New page!</b><br/><br/>
103 The previewed page is created in the workspace and has no counterpart in the live workspace.';
104 break;
105 default:
106 $message = 'Unknown message code "'.$msg.'"';
107 break;
108 }
109
110 $output = '
111 <html>
112 <head>
113 <title>Message</title>
114 </head>
115 <body bgcolor="#eeeeee">
116 <div width="100%" height="100%" style="text-align: center; align: center;"><br/><br/><br/><br/><font face="verdana,arial" size="2" color="#666666">'.$message.'</font></div>
117 </body>
118 </html>';
119
120 } else {
121 $this->generateUrls();
122 $output = $this->printFrameset();
123 }
124
125 echo $output;
126 }
127
128 /**
129 * URLs generated in $this->URL array
130 *
131 * @return void
132 */
133 function generateUrls() {
134 // Live URL:
135 $pageId = intval(t3lib_div::_GP('id'));
136 $language = intval(t3lib_div::_GP('L'));
137
138 $this->URL = array(
139 'liveHeader' => 'wsol_preview.php?header=live',
140 'draftHeader' => 'wsol_preview.php?header=draft',
141 'live' => t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?id='.$pageId.'&L='.$language.'&ADMCMD_noBeUser=1',
142 'draft' => t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?id='.$pageId.'&L='.$language.'&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS='.$this->workspace,
143 'versionMod' => '../../../sysext/version/cm1/index.php?id='.intval(t3lib_div::_GP('id')).'&diffOnly=1'
144 );
145
146 if ($this->isBeLogin()) {
147 // Branchpoint; display error message then:
148 if (t3lib_BEfunc::isPidInVersionizedBranch($pageId)=='branchpoint') {
149 $this->URL['live'] = 'wsol_preview.php?msg=branchpoint';
150 }
151
152 $rec = t3lib_BEfunc::getRecord('pages',$pageId,'t3ver_state');
153 if ((int)$rec['t3ver_state']===1) {
154 $this->URL['live'] = 'wsol_preview.php?msg=newpage';
155 }
156 }
157 }
158
159 /**
160 * Outputting frameset HTML code
161 *
162 * @return void
163 */
164 function printFrameset() {
165 if ($this->isBeLogin()) {
166 return '
167 <html>
168 <head>
169 <title>Preview and compare workspace version with live version</title>
170 </head>
171 <frameset cols="60%,40%" framespacing="3" frameborder="3" border="3">
172 <frameset rows="20,*,20,*" framespacing="3" frameborder="3" border="3">
173 <frame name="frame_liveh" src="'.htmlspecialchars($this->URL['liveHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
174 <frame name="frame_live" src="'.htmlspecialchars($this->URL['live']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
175 <frame name="frame_drafth" src="'.htmlspecialchars($this->URL['draftHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
176 <frame name="frame_draft" src="'.htmlspecialchars($this->URL['draft']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
177 </frameset>
178 <frame name="be" src="'.htmlspecialchars($this->URL['versionMod']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
179 </frameset>
180 </html>';
181 } else {
182 return '
183 <html>
184 <head>
185 <title>Preview and compare workspace version with live version</title>
186 </head>
187 <frameset cols="*,*" framespacing="3" frameborder="3" border="3">
188 <frameset rows="20,*" framespacing="3" frameborder="3" border="3">
189 <frame name="frame_liveh" src="'.htmlspecialchars($this->URL['liveHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
190 <frame name="frame_live" src="'.htmlspecialchars($this->URL['live']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
191 </frameset>
192 <frameset rows="20,*" framespacing="3" frameborder="3" border="3">
193 <frame name="frame_drafth" src="'.htmlspecialchars($this->URL['draftHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
194 <frame name="frame_draft" src="'.htmlspecialchars($this->URL['draft']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
195 </frameset>
196 </frameset>
197 </html>';
198 }
199 }
200
201 /**
202 * Checks if a backend user is logged in. Due to the line "define('TYPO3_PROCEED_IF_NO_USER', '1');" the backend is initialized even if no backend user was authenticated. This is in order to allow previews through this module of yet not-logged in users.
203 *
204 * @return boolean True, if there is a logged in backend user.
205 */
206 function isBeLogin() {
207 return is_array($GLOBALS['BE_USER']->user);
208 }
209 }
210
211 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/wsol_preview.php']) {
212 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/wsol_preview.php']);
213 }
214
215 $previewObject = t3lib_div::makeInstance('wsol_preview');
216 $previewObject->main();
217 ?>