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