Fixed bug #6996: Versioning in clickmenu was unavailable for non-admins due to a...
[Packages/TYPO3.CMS.git] / typo3 / sysext / version / class.tx_version_cm1.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * Addition of the versioning item to the clickmenu
26 *
27 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
28 */
29 /**
30 * [CLASS/FUNCTION INDEX of SCRIPT]
31 *
32 *
33 *
34 * 54: class tx_version_cm1
35 * 65: function main(&$backRef,$menuItems,$table,$uid)
36 * 111: function includeLL()
37 *
38 * TOTAL FUNCTIONS: 2
39 * (This index is automatically created/updated by the extension "extdeveval")
40 *
41 */
42
43
44
45
46
47 /**
48 * "Versioning" item added to click menu of elements.
49 *
50 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
51 * @package TYPO3
52 * @subpackage core
53 */
54 class tx_version_cm1 {
55
56 /**
57 * Main function, adding the item to input menuItems array
58 *
59 * @param object References to parent clickmenu objects.
60 * @param array Array of existing menu items accumulated. New element added to this.
61 * @param string Table name of the element
62 * @param integer Record UID of the element
63 * @return array Modified menuItems array
64 */
65 function main(&$backRef,$menuItems,$table,$uid) {
66 global $BE_USER,$TCA,$LANG;
67
68 $localItems = Array();
69 if (!$backRef->cmLevel && $uid>0 && $BE_USER->check('modules','web_txversionM1')) {
70
71 // Returns directly, because the clicked item was not from the pages table
72 if (!$TCA[$table] || !$TCA[$table]['ctrl']['versioningWS']) return $menuItems;
73
74 // Adds the regular item
75 $LL = $this->includeLL();
76
77 // "Versioning" element added:
78 $url = t3lib_extMgm::extRelPath('version').'cm1/index.php?table='.rawurlencode($table).'&uid='.$uid;
79 $localItems[] = $backRef->linkItem(
80 $GLOBALS['LANG']->getLLL('title',$LL),
81 $backRef->excludeIcon('<img src="'.$backRef->backPath.t3lib_extMgm::extRelPath('version').'cm1/cm_icon.gif" width="15" height="12" border="0" align="top" alt="" />'),
82 $backRef->urlRefForCM($url),
83 1
84 );
85
86 // "Send to review" element added:
87 $url = t3lib_extMgm::extRelPath('version').'cm1/index.php?id='.($table=='pages'?$uid:$backRef->rec['pid']).'&table='.rawurlencode($table).'&uid='.$uid.'&sendToReview=1';
88 $localItems[] = $backRef->linkItem(
89 $GLOBALS['LANG']->getLLL('title_review',$LL),
90 $backRef->excludeIcon('<img src="'.$backRef->backPath.t3lib_extMgm::extRelPath('version').'cm1/cm_icon.gif" width="15" height="12" border="0" align="top" alt="" />'),
91 $backRef->urlRefForCM($url),
92 1
93 );
94
95 // Find position of "delete" element:
96 reset($menuItems);
97 $c=0;
98 while(list($k)=each($menuItems)) {
99 $c++;
100 if (!strcmp($k,'delete')) break;
101 }
102 // .. subtract two (delete item + divider line)
103 $c-=2;
104 // ... and insert the items just before the delete element.
105 array_splice(
106 $menuItems,
107 $c,
108 0,
109 $localItems
110 );
111 }
112 return $menuItems;
113 }
114
115 /**
116 * Includes the [extDir]/locallang.php and returns the $LOCAL_LANG array found in that file.
117 *
118 * @return array Local lang array
119 */
120 function includeLL() {
121 global $LANG;
122
123 return $LANG->includeLLFile('EXT:version/locallang.xml',FALSE);
124 }
125 }
126
127
128
129 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/version/class.tx_version_cm1.php']) {
130 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/version/class.tx_version_cm1.php']);
131 }
132 ?>