TYPO3 API  SVNRelease
wsol_preview.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2004-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 /**
00025  * Workspace preview module
00026  *
00027  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00028  */
00029 /**
00030  * [CLASS/FUNCTION INDEX of SCRIPT]
00031  *
00032  *
00033  *
00034  *   62: class wsol_preview
00035  *   71:     function main()
00036  *  133:     function generateUrls()
00037  *  164:     function printFrameset()
00038  *  206:     function isBeLogin()
00039  *
00040  * TOTAL FUNCTIONS: 4
00041  * (This index is automatically created/updated by the extension "extdeveval")
00042  *
00043  */
00044 
00045 define('TYPO3_PROCEED_IF_NO_USER', '1');
00046 
00047 unset($MCONF);
00048 require('conf.php');
00049 require($BACK_PATH.'init.php');
00050 require_once('class.wslib.php');
00051 
00052 
00053 
00054 /**
00055  * Workspace dual preview
00056  * 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()
00057  *
00058  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00059  * @package TYPO3
00060  * @subpackage core
00061  */
00062 class wsol_preview {
00063 
00064     var $workspace = 0;     // Which workspace to preview!
00065 
00066     /**
00067      * Main function of class
00068      *
00069      * @return  void
00070      */
00071     function main() {
00072 
00073         if ($this->isBeLogin()) {
00074             $this->workspace = $GLOBALS['BE_USER']->workspace;
00075         }
00076 
00077         if ($header = t3lib_div::_GP('header')) {
00078             if ($header!=='live')   {
00079                 $headerText = 'Workspace Version ('.$this->workspace.'):';
00080                 $color = 'green';
00081             } else {
00082                 $headerText = 'Live Version:';
00083                 $color = 'red';
00084             }
00085 
00086             $output =  '
00087                 <html>
00088                     <head>
00089                         <title>Header</title>
00090                     </head>
00091                     <body bgcolor="'.$color.'">
00092                         <strong style="font-family:Verdana, Arial;font-size:80%;color:white;">'.$headerText.'</strong>
00093                     </body>
00094                 </html>';
00095         } elseif ($msg = t3lib_div::_GP('msg')) {
00096             switch($msg)    {
00097                 case 'branchpoint':
00098                     $message = '<strong>No live page available!</strong><br /><br />
00099                     The previewed page was inside a "Branch" type version and has no traceable counterpart in the live workspace.';
00100                 break;
00101                 case 'newpage':
00102                     $message = '<strong>New page!</strong><br /><br />
00103                     The previewed page is created in the workspace and has no counterpart in the live workspace.';
00104                 break;
00105                 default:
00106                     $message = 'Unknown message code "' . htmlspecialchars($msg) . '"';
00107                 break;
00108             }
00109 
00110             $output =  '
00111                 <html>
00112                     <head>
00113                         <title>Message</title>
00114                     </head>
00115                     <body bgcolor="#eeeeee">
00116                         <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>
00117                     </body>
00118                 </html>';
00119 
00120         } else {
00121             $this->generateUrls();
00122             $output = $this->printFrameset();
00123         }
00124 
00125         echo $output;
00126     }
00127 
00128     /**
00129      * URLs generated in $this->URL array
00130      *
00131      * @return  void
00132      */
00133     function generateUrls() {
00134             // Live URL:
00135         $pageId = intval(t3lib_div::_GP('id'));
00136         $language = intval(t3lib_div::_GP('L'));
00137 
00138         $this->URL = array(
00139             'liveHeader' => 'wsol_preview.php?header=live',
00140             'draftHeader' => 'wsol_preview.php?header=draft',
00141             'live' => t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?id='.$pageId.'&L='.$language.'&ADMCMD_noBeUser=1',
00142             'draft' => t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?id='.$pageId.'&L='.$language.'&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS='.$this->workspace,
00143             'versionMod' => '../../../sysext/version/cm1/index.php?id='.intval(t3lib_div::_GP('id')).'&diffOnly=1'
00144         );
00145 
00146         if ($this->isBeLogin()) {
00147                 // Branchpoint; display error message then:
00148             if (t3lib_BEfunc::isPidInVersionizedBranch($pageId)=='branchpoint') {
00149                 $this->URL['live'] = 'wsol_preview.php?msg=branchpoint';
00150             }
00151 
00152             $rec = t3lib_BEfunc::getRecord('pages',$pageId,'t3ver_state');
00153             if ((int)$rec['t3ver_state']===1)   {
00154                 $this->URL['live'] = 'wsol_preview.php?msg=newpage';
00155             }
00156         }
00157     }
00158 
00159     /**
00160      * Outputting frameset HTML code
00161      *
00162      * @return  void
00163      */
00164     function printFrameset()    {
00165         if ($this->isBeLogin()) {
00166             return '
00167             <html>
00168                 <head>
00169                     <title>Preview and compare workspace version with live version</title>
00170                 </head>
00171                 <frameset cols="60%,40%" framespacing="3" frameborder="3" border="3">
00172                     <frameset rows="20,*,20,*" framespacing="3" frameborder="3" border="3">
00173                         <frame name="frame_liveh" src="'.htmlspecialchars($this->URL['liveHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
00174                         <frame name="frame_live" src="'.htmlspecialchars($this->URL['live']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
00175                         <frame name="frame_drafth" src="'.htmlspecialchars($this->URL['draftHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
00176                         <frame name="frame_draft" src="'.htmlspecialchars($this->URL['draft']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
00177                     </frameset>
00178                     <frame name="be" src="'.htmlspecialchars($this->URL['versionMod']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
00179                 </frameset>
00180             </html>';
00181         } else {
00182             return '
00183             <html>
00184                 <head>
00185                     <title>Preview and compare workspace version with live version</title>
00186                 </head>
00187                 <frameset cols="*,*" framespacing="3" frameborder="3" border="3">
00188                     <frameset rows="20,*" framespacing="3" frameborder="3" border="3">
00189                         <frame name="frame_liveh" src="'.htmlspecialchars($this->URL['liveHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
00190                         <frame name="frame_live" src="'.htmlspecialchars($this->URL['live']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
00191                     </frameset>
00192                     <frameset rows="20,*" framespacing="3" frameborder="3" border="3">
00193                         <frame name="frame_drafth" src="'.htmlspecialchars($this->URL['draftHeader']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
00194                         <frame name="frame_draft" src="'.htmlspecialchars($this->URL['draft']).'" marginwidth="0" marginheight="0" frameborder="1" scrolling="auto">
00195                     </frameset>
00196                 </frameset>
00197             </html>';
00198         }
00199     }
00200 
00201     /**
00202      * 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.
00203      *
00204      * @return  boolean     True, if there is a logged in backend user.
00205      */
00206     function isBeLogin()    {
00207         return is_array($GLOBALS['BE_USER']->user);
00208     }
00209 }
00210 
00211 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/wsol_preview.php'])) {
00212     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/wsol_preview.php']);
00213 }
00214 
00215 $previewObject = t3lib_div::makeInstance('wsol_preview');
00216 $previewObject->main();
00217 ?>