[TASK] BACK_PATH BE controller
[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 use TYPO3\CMS\Core\Utility\GeneralUtility;
17
18 /**
19 * Contains some parts for staging, versioning and workspaces
20 * to interact with the TYPO3 Core Engine
21 */
22 class VersionView {
23
24 /**
25 * Creates the version selector for the page id inputted.
26 * Moved out of the core file \TYPO3\CMS\Backend\Template\DocumentTemplate
27 *
28 * @param int $id Page id to create selector for.
29 * @param bool $noAction If set, there will be no button for swapping page.
30 * @return void
31 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
32 */
33 public function getVersionSelector($id, $noAction = FALSE) {
34 if ($id <= 0) {
35 return;
36 }
37 if ($GLOBALS['BE_USER']->workspace == 0) {
38 // Get Current page record:
39 $curPage = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages', $id);
40 // If the selected page is not online, find the right ID
41 $onlineId = $curPage['pid'] == -1 ? $curPage['t3ver_oid'] : $id;
42 // Select all versions of online version:
43 $versions = \TYPO3\CMS\Backend\Utility\BackendUtility::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id');
44 // If more than one was found...:
45 if (count($versions) > 1) {
46 $selectorLabel = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:version/Resources/Private/Language/locallang.xlf:versionSelect.label', TRUE) . '</strong>';
47 // Create selector box entries:
48 $opt = array();
49 foreach ($versions as $vRow) {
50 if ($vRow['uid'] == $onlineId) {
51 // Live version
52 $label = '[' . $GLOBALS['LANG']->sL('LLL:EXT:version/Resources/Private/Language/locallang.xlf:versionSelect.live', TRUE) . ']';
53 } else {
54 $label = $vRow['t3ver_label'] . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:version/Resources/Private/Language/locallang.xlf:versionId', TRUE) . ' ' . $vRow['t3ver_id'] . ($vRow['t3ver_wsid'] != 0 ? ' ' . $GLOBALS['LANG']->sL('LLL:EXT:version/Resources/Private/Language/locallang.xlf:workspaceId', TRUE) . ' ' . $vRow['t3ver_wsid'] : '') . ')';
55 }
56 $opt[] = '<option value="' . htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $vRow['uid']))) . '"' . ($id == $vRow['uid'] ? ' selected="selected"' : '') . '>' . htmlspecialchars($label) . '</option>';
57 }
58 // Add management link:
59 $management = '<input type="button" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.mgm', TRUE) . '" onclick="window.location.href=\'' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txversionM1', array('table' => 'pages', 'uid' => $onlineId))) . '\';" />';
60 // Create onchange handler:
61 $onChange = 'window.location.href=this.options[this.selectedIndex].value;';
62 // Controls:
63 if ($id == $onlineId) {
64 $controls = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.online', TRUE) . '</strong>';
65 } elseif (!$noAction) {
66 $href = $GLOBALS['TBE_TEMPLATE']->issueCommand(
67 '&cmd[pages][' . $onlineId . '][version][swapWith]=' . $id . '&cmd[pages][' . $onlineId . '][version][action]=swap',
68 GeneralUtility::linkThisScript(array('id' => $onlineId))
69 );
70 $controls = '<a href="' . htmlspecialchars($href) . '" class="text-nowrap">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-version-swap-version', array(
71 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.swapPage', TRUE),
72 'style' => 'margin-left:5px;vertical-align:bottom;'
73 )) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.swap', TRUE) . '</strong></a>';
74 }
75 // Write out HTML code:
76 return '
77 <!--
78 Version selector:
79 -->
80 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
81 <tr>
82 <td>' . $selectorLabel . '</td>
83 <td>
84 <select onchange="' . htmlspecialchars($onChange) . '">
85 ' . implode('', $opt) . '
86 </select></td>
87 <td>' . $controls . '</td>
88 <td>' . $management . '</td>
89 </tr>
90 </table>
91 ';
92 }
93 }
94 }
95
96 }