[TASK] Cleanup EXT:version
[Packages/TYPO3.CMS.git] / typo3 / sysext / version / Classes / View / VersionView.php
1 <?php
2 namespace TYPO3\CMS\Version\View;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Contains some parts for staging, versioning and workspaces
19 * to interact with the TYPO3 Core Engine
20 */
21 class VersionView {
22
23 /**
24 * Creates the version selector for the page id inputted.
25 * Moved out of the core file \TYPO3\CMS\Backend\Template\DocumentTemplate
26 *
27 * @param integer $id Page id to create selector for.
28 * @param boolean $noAction If set, there will be no button for swapping page.
29 * @return void
30 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
31 */
32 public function getVersionSelector($id, $noAction = FALSE) {
33 if ($id <= 0) {
34 return;
35 }
36 if ($GLOBALS['BE_USER']->workspace == 0) {
37 // Get Current page record:
38 $curPage = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages', $id);
39 // If the selected page is not online, find the right ID
40 $onlineId = $curPage['pid'] == -1 ? $curPage['t3ver_oid'] : $id;
41 // Select all versions of online version:
42 $versions = \TYPO3\CMS\Backend\Utility\BackendUtility::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id');
43 // If more than one was found...:
44 if (count($versions) > 1) {
45 $selectorLabel = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xlf:versionSelect.label', TRUE) . '</strong>';
46 // Create selector box entries:
47 $opt = array();
48 foreach ($versions as $vRow) {
49 if ($vRow['uid'] == $onlineId) {
50 // Live version
51 $label = '[' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xlf:versionSelect.live', TRUE) . ']';
52 } else {
53 $label = $vRow['t3ver_label'] . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xlf:versionId', TRUE) . ' ' . $vRow['t3ver_id'] . ($vRow['t3ver_wsid'] != 0 ? ' ' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xlf:workspaceId', TRUE) . ' ' . $vRow['t3ver_wsid'] : '') . ')';
54 }
55 $opt[] = '<option value="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('id' => $vRow['uid']))) . '"' . ($id == $vRow['uid'] ? ' selected="selected"' : '') . '>' . htmlspecialchars($label) . '</option>';
56 }
57 // Add management link:
58 $management = '<input type="button" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.mgm', TRUE) . '" onclick="window.location.href=\'' . htmlspecialchars($GLOBALS['BACK_PATH'] . \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txversionM1', array('table' => 'pages', 'uid' => $onlineId))) . '\';" />';
59 // Create onchange handler:
60 $onChange = 'window.location.href=this.options[this.selectedIndex].value;';
61 // Controls:
62 if ($id == $onlineId) {
63 $controls .= '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="absmiddle" alt="" /> <strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.online', TRUE) . '</strong>';
64 } elseif (!$noAction) {
65 $controls .= '<a href="' . $GLOBALS['TBE_TEMPLATE']->issueCommand(('&cmd[pages][' . $onlineId . '][version][swapWith]=' . $id . '&cmd[pages][' . $onlineId . '][version][action]=swap'), \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('id' => $onlineId))) . '" class="nobr">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-version-swap-version', array(
66 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.swapPage', TRUE),
67 'style' => 'margin-left:5px;vertical-align:bottom;'
68 )) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.swap', TRUE) . '</strong></a>';
69 }
70 // Write out HTML code:
71 return '
72 <!--
73 Version selector:
74 -->
75 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
76 <tr>
77 <td>' . $selectorLabel . '</td>
78 <td>
79 <select onchange="' . htmlspecialchars($onChange) . '">
80 ' . implode('', $opt) . '
81 </select></td>
82 <td>' . $controls . '</td>
83 <td>' . $management . '</td>
84 </tr>
85 </table>
86 ';
87 }
88 }
89 }
90 }