[BUGFIX] Move issueCommand to BackendUtility
[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 use TYPO3\CMS\Core\Imaging\Icon;
18 use TYPO3\CMS\Core\Imaging\IconFactory;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Contains some parts for staging, versioning and workspaces
24 * to interact with the TYPO3 Core Engine
25 */
26 class VersionView
27 {
28 /**
29 * Creates the version selector for the page id inputted.
30 * Moved out of the core file \TYPO3\CMS\Backend\Template\DocumentTemplate
31 *
32 * @param int $id Page id to create selector for.
33 * @param bool $noAction If set, there will be no button for swapping page.
34 * @return string
35 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
36 */
37 public function getVersionSelector($id, $noAction = false)
38 {
39 if ($id <= 0) {
40 return '';
41 }
42 if ($GLOBALS['BE_USER']->workspace == 0) {
43 // Get Current page record:
44 $curPage = BackendUtility::getRecord('pages', $id);
45 // If the selected page is not online, find the right ID
46 $onlineId = $curPage['pid'] == -1 ? $curPage['t3ver_oid'] : $id;
47 // Select all versions of online version:
48 $versions = BackendUtility::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id', null);
49 // If more than one was found...:
50 if (count($versions) > 1) {
51 // Create selector box entries:
52 $opt = array();
53 foreach ($versions as $vRow) {
54 if ($vRow['uid'] == $onlineId) {
55 // Live version
56 $label = '[' . $GLOBALS['LANG']->sL('LLL:EXT:version/Resources/Private/Language/locallang.xlf:versionSelect.live', true) . ']';
57 } else {
58 $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'] : '') . ')';
59 }
60 $opt[] = '<option value="' . htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $vRow['uid']))) . '"' . ($id == $vRow['uid'] ? ' selected="selected"' : '') . '>' . htmlspecialchars($label) . '</option>';
61 }
62 /** @var $iconFactory \TYPO3\CMS\Core\Imaging\IconFactory */
63 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
64 // Add management link:
65 $management = '
66 <a class="btn btn-default" href="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txversionM1', array('table' => 'pages', 'uid' => $onlineId))) . '">
67 ' . $iconFactory->getIcon('actions-version-open', Icon::SIZE_SMALL)->render() . '
68 ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.mgm', true) . '
69 </a>';
70 // Create onchange handler:
71 $onChange = 'window.location.href=this.options[this.selectedIndex].value;';
72 // Controls:
73 if ($id == $onlineId) {
74 $controls = '<strong class="text-success">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.online', true) . '</strong>';
75 } elseif (!$noAction) {
76 $href = BackendUtility::getLinkToDataHandlerAction(
77 '&cmd[pages][' . $onlineId . '][version][swapWith]=' . $id . '&cmd[pages][' . $onlineId . '][version][action]=swap',
78 GeneralUtility::linkThisScript(array('id' => $onlineId))
79 );
80 $controls = '
81 <a href="' . htmlspecialchars($href) . '" class="btn btn-default" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.swapPage', true) . '">
82 ' . $iconFactory->getIcon('actions-version-swap-version', Icon::SIZE_SMALL)->render() . '
83 ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.swap', true) . '
84 </a>';
85 }
86 // Write out HTML code:
87 return '
88 <!--
89 Version selector:
90 -->
91 <div id="typo3-version-selector" class="form-inline form-inline-spaced">
92 <div class="form-group">
93 <label for="version-selector">' . $GLOBALS['LANG']->sL('LLL:EXT:version/Resources/Private/Language/locallang.xlf:versionSelect.label', true) . '</label>
94 <select id="version-selector" class="form-control" onchange="' . htmlspecialchars($onChange) . '">
95 ' . implode('', $opt) . '
96 </select>
97 </div>
98 <div class="form-group">
99 ' . $controls . '
100 </div>
101 <div class="form-group">
102 ' . $management . '
103 </div>
104 </div>
105 ';
106 }
107 }
108 }
109 }