More workspace stuff for beta.
[Packages/TYPO3.CMS.git] / typo3 / mod / user / ws / wsol_preview.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004-2005 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 * 109: function generateUrls()
37 * 125: function printFrameset()
38 * 167: 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
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
130 *
131 * @return void
132 */
133 function generateUrls() {
134 // Live URL:
135 $pageId = intval(t3lib_div::_GP('id'));
136
137 $this->URL = array(
138 'liveHeader' => 'wsol_preview.php?header=live',
139 'draftHeader' => 'wsol_preview.php?header=draft',
140 'live' => t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?id='.$pageId.'&ADMCMD_noBeUser=1',
141 'draft' => t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?id='.$pageId.'&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS='.$this->workspace,
142 'versionMod' => '../../../sysext/version/cm1/index.php?id='.intval(t3lib_div::_GP('id')).'&diffOnly=1'
143 );
144
145 if ($this->isBeLogin()) {
146 // Branchpoint; display error message then:
147 if (t3lib_BEfunc::isPidInVersionizedBranch($pageId)=='branchpoint') {
148 $this->URL['live'] = 'wsol_preview.php?msg=branchpoint';
149 }
150
151 $rec = t3lib_BEfunc::getRecord('pages',$pageId,'t3ver_state');
152 if ((int)$rec['t3ver_state']===1) {
153 $this->URL['live'] = 'wsol_preview.php?msg=newpage';
154 }
155 }
156 }
157
158 /**
159 * Outputting frameset
160 *
161 * @return void
162 */
163 function printFrameset() {
164 if ($this->isBeLogin()) {
165 return '
166 <html>
167 <head>
168 <title>Preview and compare workspace version with live version</title>
169 </head>
170 <frameset cols="60%,40%" framespacing="3" frameborder="3" border="3">
171 <frameset rows="20,*,20,*" framespacing="3" frameborder="3" border="3">
172 <frame name="frame_liveh" src="'.htmlspecialchars($this->URL['liveHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
173 <frame name="frame_live" src="'.htmlspecialchars($this->URL['live']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
174 <frame name="frame_drafth" src="'.htmlspecialchars($this->URL['draftHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
175 <frame name="frame_draft" src="'.htmlspecialchars($this->URL['draft']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
176 </frameset>
177 <frame name="be" src="'.htmlspecialchars($this->URL['versionMod']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
178 </frameset>
179 </html>';
180 } else {
181 return '
182 <html>
183 <head>
184 <title>Preview and compare workspace version with live version</title>
185 </head>
186 <frameset cols="*,*" framespacing="3" frameborder="3" border="3">
187 <frameset rows="20,*" framespacing="3" frameborder="3" border="3">
188 <frame name="frame_liveh" src="'.htmlspecialchars($this->URL['liveHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
189 <frame name="frame_live" src="'.htmlspecialchars($this->URL['live']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
190 </frameset>
191 <frameset rows="20,*" framespacing="3" frameborder="3" border="3">
192 <frame name="frame_drafth" src="'.htmlspecialchars($this->URL['draftHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
193 <frame name="frame_draft" src="'.htmlspecialchars($this->URL['draft']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
194 </frameset>
195 </frameset>
196 </html>';
197 }
198 }
199
200 /**
201 * 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.
202 *
203 * @return boolean True, if there is a logged in backend user.
204 */
205 function isBeLogin() {
206 return is_array($GLOBALS['BE_USER']->user);
207 }
208 }
209
210
211
212 $previewObject = t3lib_div::makeInstance('wsol_preview');
213 $previewObject->main();
214 ?>