[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / version / Classes / ClickMenu / VersionClickMenu.php
1 <?php
2 namespace TYPO3\CMS\Version\ClickMenu;
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 * "Versioning" item added to click menu of elements.
18 *
19 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
20 */
21 class VersionClickMenu {
22
23 /**
24 * Main function, adding the item to input menuItems array
25 *
26 * @param object References to parent clickmenu objects.
27 * @param array Array of existing menu items accumulated. New element added to this.
28 * @param string Table name of the element
29 * @param integer Record UID of the element
30 * @return array Modified menuItems array
31 * @todo Define visibility
32 */
33 public function main(&$backRef, $menuItems, $table, $uid) {
34 $localItems = array();
35 if (!$backRef->cmLevel && $uid > 0 && $GLOBALS['BE_USER']->check('modules', 'web_txversionM1')) {
36 // Returns directly, because the clicked item was not from the pages table
37 if (in_array('versioning', $backRef->disabledItems) || !$GLOBALS['TCA'][$table] || !$GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
38 return $menuItems;
39 }
40 // Adds the regular item
41 $LL = $this->includeLL();
42 // "Versioning" element added:
43 $url = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txversionM1', array('table' => $table, 'uid' => $uid));
44 $localItems[] = $backRef->linkItem($GLOBALS['LANG']->getLLL('title', $LL), $backRef->excludeIcon('<img src="' . $backRef->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('version') . 'cm1/cm_icon.gif" width="15" height="12" border="0" align="top" alt="" />'), $backRef->urlRefForCM($url), 1);
45 // Find position of "delete" element:
46 $c = 0;
47 foreach ($menuItems as $k => $value) {
48 $c++;
49 if ($k === 'delete') {
50 break;
51 }
52 }
53 // .. subtract two (delete item + divider line)
54 $c -= 2;
55 // ... and insert the items just before the delete element.
56 array_splice($menuItems, $c, 0, $localItems);
57 }
58 return $menuItems;
59 }
60
61 /**
62 * Includes the [extDir]/locallang.php and returns the $LOCAL_LANG array found in that file.
63 *
64 * @return array Local lang array
65 * @todo Define visibility
66 */
67 public function includeLL() {
68 return $GLOBALS['LANG']->includeLLFile('EXT:version/locallang.xlf', FALSE);
69 }
70
71 }