TYPO3 API  SVNRelease
class.tx_version_gui.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  (c) 2010-2011 Benjamin Mack (benni@typo3.org)
00007 *
00008 *  All rights reserved
00009 *
00010 *  This script is part of the TYPO3 project. The TYPO3 project is
00011 *  free software; you can redistribute it and/or modify
00012 *  it under the terms of the GNU General Public License as published by
00013 *  the Free Software Foundation; either version 2 of the License, or
00014 *  (at your option) any later version.
00015 *
00016 *  The GNU General Public License can be found at
00017 *  http://www.gnu.org/copyleft/gpl.html.
00018 *  A copy is found in the textfile GPL.txt and important notices to the license
00019 *  from the author is found in LICENSE.txt distributed with these scripts.
00020 *
00021 *
00022 *  This script is distributed in the hope that it will be useful,
00023 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 *  GNU General Public License for more details.
00026 *
00027 *  This copyright notice MUST APPEAR in all copies of the script!
00028 ***************************************************************/
00029 /**
00030  *
00031  * Contains some parts for staging, versioning and workspaces
00032  * to interact with the TYPO3 Core Engine
00033  *
00034  */
00035 class tx_version_gui {
00036 
00037     /**
00038      * Creates the version selector for the page id inputted.
00039      * Moved out of the core file typo3/template.php
00040      *
00041      * @param   integer     Page id to create selector for.
00042      * @param   boolean     If set, there will be no button for swapping page.
00043      * @return  void
00044      */
00045     public function getVersionSelector($id, $noAction = FALSE) {
00046         if ($id <= 0) {
00047             return;
00048         }
00049         if ($GLOBALS['BE_USER']->workspace == 0) {
00050 
00051                 // Get Current page record:
00052             $curPage = t3lib_BEfunc::getRecord('pages', $id);
00053                 // If the selected page is not online, find the right ID
00054             $onlineId = ($curPage['pid']==-1 ? $curPage['t3ver_oid'] : $id);
00055                 // Select all versions of online version:
00056             $versions = t3lib_BEfunc::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id');
00057 
00058                 // If more than one was found...:
00059             if (count($versions) > 1) {
00060                 $selectorLabel = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.label', TRUE) . '</strong>';
00061 
00062                     // Create selector box entries:
00063                 $opt = array();
00064                 foreach ($versions as $vRow) {
00065                     if ($vRow['uid'] == $onlineId) {
00066                             // Live version
00067                         $label = '[' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.live', TRUE) . ']';
00068                     } else {
00069                         $label = $vRow['t3ver_label'] . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionId', TRUE) . ' ' . $vRow['t3ver_id'] .
00070                             ($vRow['t3ver_wsid'] != 0 ? ' ' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspaceId', TRUE) . ' ' . $vRow['t3ver_wsid'] : '') . ')';
00071                     }
00072 
00073                     $opt[] = '<option value="' . htmlspecialchars(t3lib_div::linkThisScript(array('id' => $vRow['uid']))) . '"' .
00074                         ($id == $vRow['uid'] ? ' selected="selected"' : '') . '>' .
00075                         htmlspecialchars($label) . '</option>';
00076                 }
00077 
00078                     // Add management link:
00079                 $management = '<input type="button" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.mgm', TRUE) . '" onclick="window.location.href=\'' .
00080                         htmlspecialchars($GLOBALS['BACK_PATH'] . t3lib_extMgm::extRelPath('version') . 'cm1/index.php?table=pages&uid=' . $onlineId) . '\';" />';
00081                     // Create onchange handler:
00082                 $onChange = "window.location.href=this.options[this.selectedIndex].value;";
00083 
00084                     // Controls:
00085                 if ($id == $onlineId) {
00086                     $controls .= '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif','width="5" height="9"') .
00087                         ' class="absmiddle" alt="" /> <strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.online', TRUE) .
00088                         '</strong>';
00089                 } elseif (!$noAction) {
00090                     $controls .= '<a href="' . $GLOBALS['TBE_TEMPLATE']->issueCommand('&cmd[pages][' . $onlineId . '][version][swapWith]=' . $id .
00091                         '&cmd[pages][' . $onlineId . '][version][action]=swap', t3lib_div::linkThisScript(array('id' => $onlineId))) .
00092                         '" class="nobr">' . t3lib_iconWorks::getSpriteIcon('actions-version-swap-version', array(
00093                             'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.swapPage', TRUE),
00094                             'style' => 'margin-left:5px;vertical-align:bottom;'
00095                         )) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.swap', TRUE) . '</strong></a>';
00096                 }
00097 
00098                     // Write out HTML code:
00099                 return '
00100                     <!--
00101                         Version selector:
00102                     -->
00103                     <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
00104                         <tr>
00105                             <td>' . $selectorLabel . '</td>
00106                             <td>
00107                                 <select onchange="' . htmlspecialchars($onChange) . '">
00108                                     ' . implode('', $opt) . '
00109                                 </select></td>
00110                             <td>' . $controls . '</td>
00111                             <td>' . $management . '</td>
00112                         </tr>
00113                     </table>
00114                 ';
00115             }
00116         } elseif ($GLOBALS['BE_USER']->workspace !== 0) {
00117 
00118                 // Write out HTML code:
00119             switch ($GLOBALS['BE_USER']->workspace) {
00120                 case 0:
00121                     $wsTitle = $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:live', TRUE);
00122                 break;
00123                 case -1:
00124                     $wsTitle = $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:draft', TRUE);
00125                 break;
00126                 default:
00127                     $wsTitle = $GLOBALS['BE_USER']->workspaceRec['title'];
00128                 break;
00129             }
00130 
00131             if (t3lib_BEfunc::isPidInVersionizedBranch($id) == 'branchpoint') {
00132                 return '
00133 
00134                     <!--
00135                         Version selector:
00136                     -->
00137                     <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
00138                         <tr>
00139                             <td>' . $selectorLabel . '</td>
00140                             <td>Workspace: "' . htmlspecialchars($wsTitle) . '"</td>
00141                             <td><em>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.inBranch', TRUE) . '</em></td>
00142                         </tr>
00143                     </table>
00144                 ';
00145             } else {
00146 
00147                     // Get Current page record:
00148                 $curPage = t3lib_BEfunc::getRecord('pages', $id);
00149                     // If the selected page is not online, find the right ID
00150                 $onlineId = ($curPage['pid']==-1 ? $curPage['t3ver_oid'] : $id);
00151                     // The version of page:
00152                 $verPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, 'pages', $onlineId);
00153 
00154                 if (!$verPage) {
00155 
00156                     if (!count(t3lib_BEfunc::countVersionsOfRecordsOnPage($GLOBALS['BE_USER']->workspace, $onlineId))) {
00157                         if ($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(0)) {
00158 
00159                             $onClick = $GLOBALS['TBE_TEMPLATE']->issueCommand('&cmd[pages][' . $onlineId . '][version][action]=new&cmd[pages][' . $onlineId . '][version][treeLevels]=0',
00160                                 t3lib_div::linkThisScript(array(
00161                                     'id' => $onlineId
00162                                 )));
00163                             $onClick = 'window.location.href=\'' . $onClick . '\'; return false;';
00164                                 // Write out HTML code:
00165                             return '
00166 
00167                                 <!--
00168                                     No version yet, create one?
00169                                 -->
00170                                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
00171                                     <tr>
00172                                         <td>' . $selectorLabel . '</td>
00173                                         <td>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspace', TRUE) . ': "' . htmlspecialchars($wsTitle) . '"</td>
00174                                         <td>
00175                                             <input type="button" value="New version of page" name="_" onclick="' . htmlspecialchars($onClick) . '" /></td>
00176                                     </tr>
00177                                 </table>
00178                             ';
00179                         }
00180                     } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['elementVersioningOnly'] == FALSE && $GLOBALS['TYPO3_CONF_VARS']['BE']['newPagesVersioningType'] == 0) {
00181                             // only add this info if old/deprecated newPagesVersioning is allowed
00182                         return '
00183 
00184                             <!--
00185                                 Version selector:
00186                             -->
00187                             <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
00188                                 <tr>
00189                                     <td>' . $selectorLabel . '</td>
00190                                     <td>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspace', TRUE) . ': "' . htmlspecialchars($wsTitle) . '"</td>
00191                                     <td><em>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.versionsFound', TRUE) . '</em></td>
00192                                 </tr>
00193                             </table>
00194                         ';
00195                     }
00196                 } elseif ($verPage['t3ver_swapmode']==0) {
00197                     $onClick = $GLOBALS['TBE_TEMPLATE']->issueCommand('&cmd[pages][' . $onlineId . '][version][action]=swap&cmd[pages][' .
00198                         $onlineId . '][version][swapWith]=' . $verPage['uid'],
00199                         t3lib_div::linkThisScript(array(
00200                             'id' => $onlineId
00201                         )));
00202                     $onClick = 'window.location.href=\'' . $onClick . '\'; return false;';
00203 
00204                         // Write out HTML code:
00205                     return '
00206 
00207                         <!--
00208                             Version selector:
00209                         -->
00210                         <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
00211                             <tr>
00212                                 <td>' . $selectorLabel . '</td>
00213                                 <td>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspace', TRUE) . ': "' . htmlspecialchars($wsTitle) . '"</td>
00214                                 <td>
00215                                     <input type="button" value="' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.publish', TRUE) .
00216                                         '" onclick="' . htmlspecialchars($onClick) . '" /></td>
00217                             </tr>
00218                         </table>
00219                     ';
00220                 }
00221             }
00222         }
00223     }
00224 
00225 }
00226 
00227 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/version/class.tx_version_gui.php'])) {
00228     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/version/class.tx_version_gui.php']);
00229 }
00230 ?>