2005-12-19 Sebastian Kurfuerst <sebastian@garbahe-group.de>
[Packages/TYPO3.CMS.git] / typo3 / alt_clickmenu.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-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 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Context menu
29 *
30 * The script is called in the top frame of the backend typically by a click on an icon for which a context menu should appear.
31 * Either this script displays the context menu horizontally in the top frame or alternatively (default in MSIE, Mozilla) it writes the output to a <div>-layer in the calling document (which then appears as a layer/context sensitive menu)
32 * Writing content back into a <div>-layer is necessary if we want individualized context menus with any specific content for any specific element.
33 * Context menus can appear for either database elements or files
34 * The input to this script is basically the "&init" var which is divided by "|" - each part is a reference to table|uid|listframe-flag.
35 *
36 * If you want to integrate a context menu in your scripts, please see template::getContextMenuCode()
37 *
38 * $Id$
39 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
40 * XHTML compliant
41 *
42 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
43 */
44 /**
45 * [CLASS/FUNCTION INDEX of SCRIPT]
46 *
47 *
48 *
49 * 128: class clickMenu
50 * 160: function init($item)
51 * 203: function doDisplayTopFrameCM()
52 *
53 * SECTION: DATABASE
54 * 231: function printDBClickMenu($table,$uid)
55 * 318: function printNewDBLevel($table,$uid)
56 * 355: function externalProcessingOfDBMenuItems($menuItems)
57 * 367: function processingByExtClassArray($menuItems,$table,$uid)
58 * 386: function urlRefForCM($url,$retUrl='',$hideCM=1)
59 * 403: function DB_copycut($table,$uid,$type)
60 * 432: function DB_paste($table,$uid,$type,$elInfo)
61 * 453: function DB_info($table,$uid)
62 * 469: function DB_history($table,$uid)
63 * 488: function DB_perms($table,$uid,$rec)
64 * 507: function DB_db_list($table,$uid,$rec)
65 * 526: function DB_moveWizard($table,$uid,$rec)
66 * 547: function DB_newWizard($table,$uid,$rec)
67 * 570: function DB_editAccess($table,$uid)
68 * 588: function DB_editPageHeader($uid)
69 * 606: function DB_edit($table,$uid)
70 * 648: function DB_new($table,$uid)
71 * 673: function DB_delete($table,$uid,$elInfo)
72 * 694: function DB_view($id,$anchor='')
73 * 709: function DB_tempMountPoint($page_id)
74 * 727: function DB_hideUnhide($table,$rec,$hideField)
75 * 742: function DB_changeFlag($table, $rec, $flagField, $title, $name, $iconRelPath='gfx/')
76 *
77 * SECTION: FILE
78 * 776: function printFileClickMenu($path)
79 * 840: function externalProcessingOfFileMenuItems($menuItems)
80 * 854: function FILE_launch($path,$script,$type,$image)
81 * 874: function FILE_copycut($path,$type)
82 * 900: function FILE_delete($path)
83 * 922: function FILE_paste($path,$target,$elInfo)
84 *
85 * SECTION: COMMON
86 * 962: function printItems($menuItems,$item)
87 * 1014: function printLayerJScode($menuItems)
88 * 1052: function wrapColorTableCM($str)
89 * 1075: function menuItemsForTopFrame($menuItems)
90 * 1092: function menuItemsForClickMenu($menuItems)
91 * 1126: function addMenuItems($menuItems,$newMenuItems,$position='')
92 * 1202: function linkItem($str,$icon,$onClick,$onlyCM=0,$dontHide=0)
93 * 1226: function excludeIcon($iconCode)
94 * 1236: function enableDisableItems($menuItems)
95 * 1274: function cleanUpSpacers($menuItems)
96 * 1316: function label($label)
97 * 1325: function isCMlayers()
98 * 1335: function frameLocation($str)
99 *
100 *
101 * 1360: class SC_alt_clickmenu
102 * 1379: function init()
103 * 1477: function main()
104 * 1511: function printContent()
105 *
106 * TOTAL FUNCTIONS: 46
107 * (This index is automatically created/updated by the extension "extdeveval")
108 *
109 */
110
111
112 require ('init.php');
113 require ('template.php');
114 require_once (PATH_t3lib.'class.t3lib_clipboard.php');
115 require_once(PATH_t3lib.'class.t3lib_ajax.php');
116 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
117
118
119
120
121 /**
122 * Class for generating the click menu
123 *
124 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
125 * @package TYPO3
126 * @subpackage core
127 * @internal
128 */
129 class clickMenu {
130
131 // Internal, static: GPvar:
132 var $cmLevel=0; // Defines if the click menu is first level or second. Second means the click menu is triggered from another menu.
133 var $CB; // Clipboard array (submitted by eg. pressing the paste button)
134
135 // Internal, static:
136 var $backPath=''; // Backpath for scripts/images.
137 var $PH_backPath='###BACK_PATH###'; // BackPath place holder: We need different backPath set whether the clickmenu is written back to a frame which is not in typo3/ dir or if the clickmenu is shown in the top frame (no backpath)
138 var $listFrame=0; // If set, the calling document should be in the listframe of a frameset.
139 var $isDBmenu=0; // If set, the menu is about database records, not files. (set if part 2 [1] of the item-var is NOT blank)
140 var $alwaysContentFrame=0; // If true, the "content" frame is always used for reference (when condensed mode is enabled)
141 var $iParts=array(); // Stores the parts of the input $item string, splitted by "|": [0] = table/file, [1] = uid/blank, [2] = flag: If set, listFrame, If "2" then "content frame" is forced [3] = ("+" prefix = disable all by default, enable these. Default is to disable) Items key list
142 var $disabledItems=array(); // Contains list of keywords of items to disable in the menu
143 var $dontDisplayTopFrameCM=0; // If true, the context sensitive menu will not appear in the top frame, only as a layer.
144 var $leftIcons=0; // If true, Show icons on the left.
145 var $extClassArray=array(); // Array of classes to be used for user processing of the menu content. This is for the API of adding items to the menu from outside.
146 var $ajax=0; // enable/disable ajax behavior
147
148 // Internal, dynamic:
149 var $elCount=0; // Counter for elements in the menu. Used to number the name / id of the mouse-over icon.
150 var $editPageIconSet=0; // Set, when edit icon is drawn.
151 var $editOK=0; // Set to true, if editing of the element is OK.
152 var $rec=array();
153
154
155
156 /**
157 * Initialize click menu
158 *
159 * @return string The clickmenu HTML content
160 */
161 function init() {
162 // Setting GPvars:
163 $this->cmLevel = intval(t3lib_div::_GP('cmLevel'));
164 $this->CB = t3lib_div::_GP('CB');
165 if(t3lib_div::_GP('ajax')) {
166 $this->ajax = 1;
167 ini_set('display_errors',0); // XML has to be parsed, no parse errors allowed
168 }
169
170 // can be set differently as well
171 $this->iParts[0] = t3lib_div::_GP('table');
172 $this->iParts[1] = t3lib_div::_GP('uid');
173 $this->iParts[2] = t3lib_div::_GP('listFr');
174 $this->iParts[3] = t3lib_div::_GP('enDisItems');
175
176 // Setting flags:
177 if ($this->iParts[2]) $this->listFrame=1;
178 if ($GLOBALS['BE_USER']->uc['condensedMode'] || $this->iParts[2]==2) $this->alwaysContentFrame=1;
179 if (strcmp($this->iParts[1],'')) $this->isDBmenu=1;
180
181 $TSkey =($this->isDBmenu?'page':'folder').($this->listFrame?'List':'Tree');
182 $this->disabledItems = t3lib_div::trimExplode(',',$GLOBALS['BE_USER']->getTSConfigVal('options.contextMenu.'.$TSkey.'.disableItems'),1);
183 $this->leftIcons = $GLOBALS['BE_USER']->getTSConfigVal('options.contextMenu.options.leftIcons');
184
185 // &cmLevel flag detected (2nd level menu)
186 if (!$this->cmLevel) {
187 // Make 1st level clickmenu:
188 if ($this->isDBmenu) {
189 $CMcontent = $this->printDBClickMenu($this->iParts[0],$this->iParts[1]);
190 } else {
191 $CMcontent = $this->printFileClickMenu($this->iParts[0]);
192 }
193 } else {
194 // Make 2nd level clickmenu (only for DBmenus)
195 if ($this->isDBmenu) {
196 $CMcontent = $this->printNewDBLevel($this->iParts[0],$this->iParts[1]);
197 }
198 }
199
200 // Return clickmenu content:
201 return $CMcontent;
202 }
203
204 /**
205 * Returns true if the menu should (also?) be displayed in topframe, not just <div>-layers
206 *
207 * @return boolean
208 */
209 function doDisplayTopFrameCM() {
210 if($this->ajax) {
211 return false;
212 } else {
213 return !$GLOBALS['SOBE']->doc->isCMlayers() || !$this->dontDisplayTopFrameCM;
214 }
215 }
216
217
218
219
220
221
222
223
224
225
226
227
228 /***************************************
229 *
230 * DATABASE
231 *
232 ***************************************/
233
234 /**
235 * Make 1st level clickmenu:
236 *
237 * @param string Table name
238 * @param integer UID for the current record.
239 * @return string HTML content
240 */
241 function printDBClickMenu($table,$uid) {
242 global $TCA, $BE_USER;
243
244 // Get record:
245 $this->rec = t3lib_BEfunc::getRecordWSOL($table,$uid);
246 $menuItems=array();
247 $root=0;
248 if ($table=='pages' && !strcmp($uid,'0')) { // Rootlevel
249 $root=1;
250 }
251
252 // If record found (or root), go ahead and fill the $menuItems array which will contain data for the elements to render.
253 if (is_array($this->rec) || $root) {
254
255 // Get permissions
256 $lCP = $BE_USER->calcPerms(t3lib_BEfunc::getRecord('pages',($table=='pages'?$this->rec['uid']:$this->rec['pid'])));
257
258 // View
259 if (!in_array('view',$this->disabledItems)) {
260 if ($table=='pages') $menuItems['view']=$this->DB_view($uid);
261 if ($table==$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']) $menuItems['view']=$this->DB_view($this->rec['pid'],'#'.$uid);
262 }
263
264 // Edit:
265 if(!$root && ($BE_USER->isPSet($lCP,$table,'edit')||$BE_USER->isPSet($lCP,$table,'editcontent'))) {
266 if (!in_array('edit',$this->disabledItems)) $menuItems['edit']=$this->DB_edit($table,$uid);
267 $this->editOK=1;
268 }
269
270 // New:
271 if (!in_array('new',$this->disabledItems) && $BE_USER->isPSet($lCP,$table,'new')) $menuItems['new']=$this->DB_new($table,$uid);
272
273 // Info:
274 if(!in_array('info',$this->disabledItems) && !$root) $menuItems['info']=$this->DB_info($table,$uid);
275
276 $menuItems['spacer1']='spacer';
277
278 // Copy:
279 if(!in_array('copy',$this->disabledItems) && !$root) $menuItems['copy']=$this->DB_copycut($table,$uid,'copy');
280 // Cut:
281 if(!in_array('cut',$this->disabledItems) && !$root) $menuItems['cut']=$this->DB_copycut($table,$uid,'cut');
282
283 // Paste:
284 $elFromAllTables = count($this->clipObj->elFromTable(''));
285 if (!in_array('paste',$this->disabledItems) && $elFromAllTables) {
286 $selItem = $this->clipObj->getSelectedRecord();
287 $elInfo=array(
288 t3lib_div::fixed_lgd_cs($selItem['_RECORD_TITLE'],$BE_USER->uc['titleLen']),
289 ($root?$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']:t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table,$this->rec),$BE_USER->uc['titleLen'])),
290 $this->clipObj->currentMode()
291 );
292 if ($table=='pages' && ($lCP & 8)) {
293 if ($elFromAllTables) $menuItems['pasteinto']=$this->DB_paste('',$uid,'into',$elInfo);
294 }
295
296 $elFromTable = count($this->clipObj->elFromTable($table));
297 if (!$root && $elFromTable && $TCA[$table]['ctrl']['sortby']) $menuItems['pasteafter']=$this->DB_paste($table,-$uid,'after',$elInfo);
298 }
299
300 // Delete:
301 $elInfo=array(t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table,$this->rec),$BE_USER->uc['titleLen']));
302 if(!in_array('delete',$this->disabledItems) && !$root && $BE_USER->isPSet($lCP,$table,'delete')) {
303 $menuItems['spacer2']='spacer';
304 $menuItems['delete']=$this->DB_delete($table,$uid,$elInfo);
305 }
306 }
307
308 // Adding external elements to the menuItems array
309 $menuItems = $this->processingByExtClassArray($menuItems,$table,$uid);
310
311 // Processing by external functions?
312 $menuItems = $this->externalProcessingOfDBMenuItems($menuItems);
313
314 // Return the printed elements:
315 return $this->printItems($menuItems,
316 $root?
317 '<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/i/_icon_website.gif','width="18" height="16"').' class="absmiddle" alt="" />'.htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']):
318 t3lib_iconWorks::getIconImage($table,$this->rec,$this->PH_backPath,' class="absmiddle" title="'.htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($this->rec,$table)).'"').t3lib_BEfunc::getRecordTitle($table,$this->rec,1)
319 );
320 }
321
322 /**
323 * Make 2nd level clickmenu (only for DBmenus)
324 *
325 * @param string Table name
326 * @param integer UID for the current record.
327 * @return string HTML content
328 */
329 function printNewDBLevel($table,$uid) {
330 global $TCA, $BE_USER;
331
332 // Setting internal record to the table/uid :
333 $this->rec = t3lib_BEfunc::getRecordWSOL($table,$uid);
334 $menuItems=array();
335 $root=0;
336 if ($table=='pages' && !strcmp($uid,'0')) { // Rootlevel
337 $root=1;
338 }
339
340 // If record was found, check permissions and get menu items.
341 if (is_array($this->rec) || $root) {
342 $lCP = $BE_USER->calcPerms(t3lib_BEfunc::getRecord('pages',($table=='pages'?$this->rec['uid']:$this->rec['pid'])));
343 // Edit:
344 if(!$root && ($BE_USER->isPSet($lCP,$table,'edit')||$BE_USER->isPSet($lCP,$table,'editcontent'))) {
345 $this->editOK=1;
346 }
347
348 $menuItems = $this->processingByExtClassArray($menuItems,$table,$uid);
349 }
350
351 // Return the printed elements:
352 if (!is_array($menuItems)) $menuItems=array();
353 return $this->printItems($menuItems,
354 $root?
355 '<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/i/_icon_website.gif','width="18" height="16"').' class="absmiddle" alt="" />'.htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']):
356 t3lib_iconWorks::getIconImage($table,$this->rec,$this->PH_backPath,' class="absmiddle" title="'.htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($this->rec,$table)).'"').t3lib_BEfunc::getRecordTitle($table,$this->rec,1)
357 );
358 }
359
360 /**
361 * Processing the $menuItems array (for extension classes) (DATABASE RECORDS)
362 *
363 * @param array $menuItems array for manipulation.
364 * @return array Processed $menuItems array
365 */
366 function externalProcessingOfDBMenuItems($menuItems) {
367 return $menuItems;
368 }
369
370 /**
371 * Processing the $menuItems array by external classes (typ. adding items)
372 *
373 * @param array $menuItems array for manipulation.
374 * @param string Table name
375 * @param integer UID for the current record.
376 * @return array Processed $menuItems array
377 */
378 function processingByExtClassArray($menuItems,$table,$uid) {
379 if (is_array($this->extClassArray)) {
380 reset($this->extClassArray);
381 while(list(,$conf)=each($this->extClassArray)) {
382 $obj=t3lib_div::makeInstance($conf['name']);
383 $menuItems = $obj->main($this,$menuItems,$table,$uid);
384 }
385 }
386 return $menuItems;
387 }
388
389 /**
390 * Returning JavaScript for the onClick event linking to the input URL.
391 *
392 * @param string The URL relative to TYPO3_mainDir
393 * @param string The return_url-parameter
394 * @param boolean If set, the "hideCM()" will be called
395 * @return string JavaScript for an onClick event.
396 */
397 function urlRefForCM($url,$retUrl='',$hideCM=1) {
398 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
399 $editOnClick='var docRef=(top.content.list_frame)?top.content.list_frame:'.$loc.'; docRef.document.location=top.TS.PATH_typo3+\''.$url.'\''.
400 ($retUrl?"+'&".$retUrl."='+top.rawurlencode(".$this->frameLocation('docRef.document').')':'').';'.
401 ($hideCM?'return hideCM();':'');
402 return $editOnClick;
403 }
404
405 /**
406 * Adding CM element for Clipboard "copy" and "cut"
407 *
408 * @param string Table name
409 * @param integer UID for the current record.
410 * @param string Type: "copy" or "cut"
411 * @return array Item array, element in $menuItems
412 * @internal
413 */
414 function DB_copycut($table,$uid,$type) {
415 if ($this->clipObj->current=='normal') {
416 $isSel = $this->clipObj->isSelected($table,$uid);
417 }
418
419 $addParam = array();
420 if ($this->listFrame) {
421 $addParam['reloadListFrame'] = ($this->alwaysContentFrame ? 2 : 1);
422 }
423
424 return $this->linkItem(
425 $this->label($type),
426 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/clip_'.$type.($isSel==$type?'_h':'').'.gif','width="12" height="12"').' alt="" />'),
427 "top.loadTopMenu('".$this->clipObj->selUrlDB($table,$uid,($type=='copy'?1:0),($isSel==$type),$addParam)."');return false;"
428 );
429 }
430
431 /**
432 * Adding CM element for Clipboard "paste into"/"paste after"
433 * NOTICE: $table and $uid should follow the special syntax for paste, see clipboard-class :: pasteUrl();
434 *
435 * @param string Table name
436 * @param integer UID for the current record. NOTICE: Special syntax!
437 * @param string Type: "into" or "after"
438 * @param array Contains instructions about whether to copy or cut an element.
439 * @return array Item array, element in $menuItems
440 * @see t3lib_clipboard::pasteUrl()
441 * @internal
442 */
443 function DB_paste($table,$uid,$type,$elInfo) {
444 $editOnClick = '';
445 $loc = 'top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
446 if($GLOBALS['BE_USER']->jsConfirmation(2)) {
447 $conf = $loc.' && confirm('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.'.($elInfo[2]=='copy'?'copy':'move').'_'.$type),$elInfo[0],$elInfo[1])).')';
448 } else {
449 $conf = $loc;
450 }
451 $editOnClick = 'if('.$conf.'){'.$loc.'.document.location=top.TS.PATH_typo3+\''.$this->clipObj->pasteUrl($table,$uid,0).'&redirect=\'+top.rawurlencode('.$this->frameLocation($loc.'.document').'); hideCM();}';
452
453 return $this->linkItem(
454 $this->label('paste'.$type),
455 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/clip_paste'.$type.'.gif','width="12" height="12"').' alt="" />'),
456 $editOnClick.'return false;'
457 );
458 }
459
460 /**
461 * Adding CM element for Info
462 *
463 * @param string Table name
464 * @param integer UID for the current record.
465 * @return array Item array, element in $menuItems
466 * @internal
467 */
468 function DB_info($table,$uid) {
469 return $this->linkItem(
470 $this->label('info'),
471 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/zoom2.gif','width="12" height="12"').' alt="" />'),
472 "top.launchView('".$table."', '".$uid."'); return hideCM();"
473 );
474 }
475
476 /**
477 * Adding CM element for History
478 *
479 * @param string Table name
480 * @param integer UID for the current record.
481 * @return array Item array, element in $menuItems
482 * @internal
483 */
484 function DB_history($table,$uid) {
485 $url = 'show_rechis.php?element='.rawurlencode($table.':'.$uid);
486 return $this->linkItem(
487 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_history')),
488 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/history2.gif','width="13" height="12"').' alt="" />'),
489 $this->urlRefForCM($url,'returnUrl'),
490 0
491 );
492 }
493
494 /**
495 * Adding CM element for Permission setting
496 *
497 * @param string Table name
498 * @param integer UID for the current record.
499 * @param array The "pages" record with "perms_*" fields inside.
500 * @return array Item array, element in $menuItems
501 * @internal
502 */
503 function DB_perms($table,$uid,$rec) {
504 $url = 'mod/web/perm/index.php?id='.$uid.($rec['perms_userid']==$GLOBALS['BE_USER']->user['uid']||$GLOBALS['BE_USER']->isAdmin()?'&return_id='.$uid.'&edit=1':'');
505 return $this->linkItem(
506 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_perms')),
507 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/perm.gif','width="7" height="12"').' alt="" />'),
508 $this->urlRefForCM($url),
509 0
510 );
511 }
512
513 /**
514 * Adding CM element for DBlist
515 *
516 * @param string Table name
517 * @param integer UID for the current record.
518 * @param array Record of the element (needs "pid" field if not pages-record)
519 * @return array Item array, element in $menuItems
520 * @internal
521 */
522 function DB_db_list($table,$uid,$rec) {
523 $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR').'db_list.php?table='.($table=='pages'?'':$table).'&id='.($table=='pages'?$uid:$rec['pid']);
524 return $this->linkItem(
525 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_db_list')),
526 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/list.gif','width="11" height="11"').' alt="" />'),
527 "top.nextLoadModuleUrl='".$url."';top.goToModule('web_list',1);",
528 0
529 );
530 }
531
532 /**
533 * Adding CM element for Moving wizard
534 *
535 * @param string Table name
536 * @param integer UID for the current record.
537 * @param array Record. Needed for tt-content elements which will have the sys_language_uid sent
538 * @return array Item array, element in $menuItems
539 * @internal
540 */
541 function DB_moveWizard($table,$uid,$rec) {
542 $url = 'move_el.php?table='.$table.'&uid='.$uid.
543 ($table=='tt_content'?'&sys_language_uid='.intval($rec['sys_language_uid']):''); // Hardcoded field for tt_content elements.
544
545 return $this->linkItem(
546 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_moveWizard'.($table=='pages'?'_page':''))),
547 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/move_'.($table=='pages'?'page':'record').'.gif','width="11" height="12"').' alt="" />'),
548 $this->urlRefForCM($url,'returnUrl'),
549 0
550 );
551 }
552
553 /**
554 * Adding CM element for Create new wizard (either db_new.php or sysext/cms/layout/db_new_content_el.php or custom wizard)
555 *
556 * @param string Table name
557 * @param integer UID for the current record.
558 * @param array Record.
559 * @return array Item array, element in $menuItems
560 * @internal
561 */
562 function DB_newWizard($table,$uid,$rec) {
563 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
564 $tmpTSc = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
565 $tmpTSc = $tmpTSc ['properties']['newContentWiz.']['overrideWithExtension'];
566 $newContentWizScriptPath = t3lib_extMgm::isLoaded($tmpTSc) ? (t3lib_extMgm::extRelPath($tmpTSc).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
567
568 $url = ($table=='pages' || !t3lib_extMgm::isLoaded('cms')) ? 'db_new.php?id='.$uid.'&pagesOnly=1' : $newContentWizScriptPath.'?id='.$rec['pid'].'&sys_language_uid='.intval($rec['sys_language_uid']);
569 return $this->linkItem(
570 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_newWizard')),
571 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/new_'.($table=='pages'?'page':'record').'.gif','width="'.($table=='pages'?'13':'16').'" height="12"').' alt="" />'),
572 $this->urlRefForCM($url,'returnUrl'),
573 0
574 );
575 }
576
577 /**
578 * Adding CM element for Editing of the access related fields of a table (disable, starttime, endtime, fe_groups)
579 *
580 * @param string Table name
581 * @param integer UID for the current record.
582 * @return array Item array, element in $menuItems
583 * @internal
584 */
585 function DB_editAccess($table,$uid) {
586 $addParam='&columnsOnly='.rawurlencode(implode(',',$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']).($table=='pages' ? ',extendToSubpages' :''));
587 $url = 'alt_doc.php?edit['.$table.']['.$uid.']=edit'.$addParam;
588 return $this->linkItem(
589 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_editAccess')),
590 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/editaccess.gif','width="12" height="12"').' alt="" />'),
591 $this->urlRefForCM($url,'returnUrl'),
592 1 // no top frame CM!
593 );
594 }
595
596 /**
597 * Adding CM element for edit page header
598 *
599 * @param integer page uid to edit (PID)
600 * @return array Item array, element in $menuItems
601 * @internal
602 * @deprecated Use DB_editPageProperties instead
603 */
604 function DB_editPageHeader($uid) {
605 return $this->DB_editPageProperties($uid);
606 }
607
608 /**
609 * Adding CM element for edit page properties
610 *
611 * @param integer page uid to edit (PID)
612 * @return array Item array, element in $menuItems
613 * @internal
614 */
615 function DB_editPageProperties($uid) {
616 $url = 'alt_doc.php?edit[pages]['.$uid.']=edit';
617 return $this->linkItem(
618 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_editPageProperties')),
619 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/edit2.gif','width="11" height="12"').' alt="" />'),
620 $this->urlRefForCM($url,'returnUrl'),
621 1 // no top frame CM!
622 );
623 }
624
625 /**
626 * Adding CM element for regular editing of the element!
627 *
628 * @param string Table name
629 * @param integer UID for the current record.
630 * @return array Item array, element in $menuItems
631 * @internal
632 */
633 function DB_edit($table,$uid) {
634 global $BE_USER;
635 // If another module was specified, replace the default Page module with the new one
636 $newPageModule = trim($BE_USER->getTSConfigVal('options.overridePageModule'));
637 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
638
639 $editOnClick='';
640 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
641 $addParam='';
642 $theIcon = t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/edit2.gif','width="11" height="12"');
643 if (
644 $this->iParts[0]=='pages' &&
645 $this->iParts[1] &&
646 $BE_USER->check('modules', $pageModule)
647 ) {
648 $theIcon = t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/edit_page.gif','width="12" height="12"');
649 $this->editPageIconSet=1;
650 if ($BE_USER->uc['classicPageEditMode'] || !t3lib_extMgm::isLoaded('cms')) {
651 $addParam='&editRegularContentFromId='.intval($this->iParts[1]);
652 } else {
653 $editOnClick="top.fsMod.recentIds['web']=".intval($this->iParts[1]).";top.goToModule('".$pageModule."',1);";
654 }
655 }
656 if (!$editOnClick) {
657 $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'alt_doc.php?returnUrl='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'&edit[".$table."][".$uid."]=edit".$addParam."';}";
658 }
659
660 return $this->linkItem(
661 $this->label('edit'),
662 $this->excludeIcon('<img'.$theIcon.' alt="" />'),
663 $editOnClick.'return hideCM();'
664 );
665 }
666
667 /**
668 * Adding CM element for regular Create new element
669 *
670 * @param string Table name
671 * @param integer UID for the current record.
672 * @return array Item array, element in $menuItems
673 * @internal
674 */
675 function DB_new($table,$uid) {
676 $editOnClick='';
677 $loc='top.content'.(!$this->alwaysContentFrame?'.list_frame':'');
678 $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'".
679 ($this->listFrame?
680 "alt_doc.php?returnUrl='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'&edit[".$table."][-".$uid."]=new'":
681 'db_new.php?id='.intval($uid)."'").
682 ';}';
683
684 return $this->linkItem(
685 $this->label('new'),
686 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/new_'.($table=='pages'&&$this->listFrame?'page':'el').'.gif','width="'.($table=='pages'?'13':'11').'" height="12"').' alt="" />'),
687 $editOnClick.'return hideCM();'
688 );
689 }
690
691 /**
692 * Adding CM element for Delete
693 *
694 * @param string Table name
695 * @param integer UID for the current record.
696 * @param array Label for including in the confirmation message, EXT:lang/locallang_core.php:mess.delete
697 * @return array Item array, element in $menuItems
698 * @internal
699 */
700 function DB_delete($table,$uid,$elInfo) {
701 $editOnClick='';
702 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
703 if($GLOBALS['BE_USER']->jsConfirmation(4)) {
704 $conf = "confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.delete'),$elInfo[0])).")";
705 } else {
706 $conf = '1==1';
707 }
708 $editOnClick='if('.$loc." && ".$conf." ){".$loc.".document.location=top.TS.PATH_typo3+'tce_db.php?redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'".
709 "&cmd[".$table.']['.$uid.'][delete]=1&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
710
711 return $this->linkItem(
712 $this->label('delete'),
713 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/garbage.gif','width="11" height="12"').' alt="" />'),
714 $editOnClick.'return false;'
715 );
716 }
717
718 /**
719 * Adding CM element for View Page
720 *
721 * @param integer Page uid (PID)
722 * @param string Anchor, if any
723 * @return array Item array, element in $menuItems
724 * @internal
725 */
726 function DB_view($id,$anchor='') {
727 return $this->linkItem(
728 $this->label('view'),
729 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/zoom.gif','width="12" height="12"').' alt="" />'),
730 t3lib_BEfunc::viewOnClick($id,$this->PH_backPath,t3lib_BEfunc::BEgetRootLine($id),$anchor).'return hideCM();'
731 );
732 }
733
734 /**
735 * Adding element for setting temporary mount point.
736 *
737 * @param integer Page uid (PID)
738 * @return array Item array, element in $menuItems
739 * @internal
740 */
741 function DB_tempMountPoint($page_id) {
742 return $this->linkItem(
743 $this->label('tempMountPoint'),
744 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/placeasroot.gif','width="14" height="12"').' alt="" />'),
745 '',
746 "if (top.content.nav_frame) { top.content.nav_frame.document.location = 'alt_db_navframe.php?setTempDBmount=".intval($page_id)."'; } return hideCM();"
747 );
748 }
749
750 /**
751 * Adding CM element for hide/unhide of the input record
752 *
753 * @param string Table name
754 * @param array Record array
755 * @param string Name of the hide field
756 * @return array Item array, element in $menuItems
757 * @internal
758 */
759 function DB_hideUnhide($table,$rec,$hideField) {
760 return $this->DB_changeFlag($table, $rec, $hideField, $this->label(($rec[$hideField]?'un':'').'hide'), 'hide');
761 }
762
763 /**
764 * Adding CM element for a flag field of the input record
765 *
766 * @param string Table name
767 * @param array Record array
768 * @param string Name of the flag field
769 * @param string Menu item Title
770 * @param string Name of the item used for icons and labels
771 * @param string Icon path relative to typo3/ folder
772 * @return array Item array, element in $menuItems
773 */
774 function DB_changeFlag($table, $rec, $flagField, $title, $name, $iconRelPath='gfx/') {
775 $uid = $rec['_ORIG_uid'] ? $rec['_ORIG_uid'] : $rec['uid'];
776 $editOnClick='';
777 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
778 $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'tce_db.php?redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'".
779 "&data[".$table.']['.$uid.']['.$flagField.']='.($rec[$flagField]?0:1).'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
780
781 return $this->linkItem(
782 $title,
783 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,$iconRelPath.'button_'.($rec[$flagField]?'un':'').$name.'.gif','width="11" height="10"').' alt="" />'),
784 $editOnClick.'return false;',
785 1
786 );
787 }
788
789
790
791
792
793
794
795
796 /***************************************
797 *
798 * FILE
799 *
800 ***************************************/
801
802 /**
803 * Make 1st level clickmenu:
804 *
805 * @param string The absolute path
806 * @return string HTML content
807 */
808 function printFileClickMenu($path) {
809 $menuItems=array();
810
811 if (@file_exists($path) && t3lib_div::isAllowedAbsPath($path)) {
812 $fI = pathinfo($path);
813 $icon = is_dir($path) ? 'folder.gif' : t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
814 $size=' ('.t3lib_div::formatSize(filesize($path)).'bytes)';
815 $icon = '<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/fileicons/'.$icon,'width="18" height="16"').' class="absmiddle" title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
816
817 // edit
818 if (!in_array('edit',$this->disabledItems) && is_file($path) && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'],$fI['extension'])) $menuItems['edit']=$this->FILE_launch($path,'file_edit.php','edit','edit_file.gif');
819 // rename
820 if (!in_array('rename',$this->disabledItems)) $menuItems['rename']=$this->FILE_launch($path,'file_rename.php','rename','rename.gif');
821 // upload
822 if (!in_array('upload',$this->disabledItems) && is_dir($path)) $menuItems['upload']=$this->FILE_launch($path,'file_upload.php','upload','upload.gif');
823 // new
824 if (!in_array('new',$this->disabledItems) && is_dir($path)) $menuItems['new']=$this->FILE_launch($path,'file_newfolder.php','new','new_file.gif');
825 // info
826 if (!in_array('info',$this->disabledItems)) $menuItems['info']=$this->DB_info($path,'');
827
828 $menuItems[]='spacer';
829
830 // copy:
831 if (!in_array('copy',$this->disabledItems)) $menuItems['copy']=$this->FILE_copycut($path,'copy');
832 // cut:
833 if (!in_array('cut',$this->disabledItems)) $menuItems['cut']=$this->FILE_copycut($path,'cut');
834
835 // Paste:
836 $elFromAllTables = count($this->clipObj->elFromTable('_FILE'));
837 if (!in_array('paste',$this->disabledItems) && $elFromAllTables && is_dir($path)) {
838 $elArr = $this->clipObj->elFromTable('_FILE');
839 reset($elArr);
840 $selItem = current($elArr);
841 $elInfo=array(
842 basename($selItem),
843 basename($path),
844 $this->clipObj->currentMode()
845 );
846 $menuItems['pasteinto']=$this->FILE_paste($path,$selItem,$elInfo);
847 }
848
849 $menuItems[]='spacer';
850
851 // delete:
852 if (!in_array('delete',$this->disabledItems)) $menuItems['delete']=$this->FILE_delete($path);
853 }
854
855 // Adding external elements to the menuItems array
856 $menuItems = $this->processingByExtClassArray($menuItems,$path,0);
857
858 // Processing by external functions?
859 $menuItems = $this->externalProcessingOfFileMenuItems($menuItems);
860
861 // Return the printed elements:
862 return $this->printItems($menuItems,$icon.basename($path));
863 }
864
865
866 /**
867 * Processing the $menuItems array (for extension classes) (FILES)
868 *
869 * @param array $menuItems array for manipulation.
870 * @return array Processed $menuItems array
871 */
872 function externalProcessingOfFileMenuItems($menuItems) {
873 return $menuItems;
874 }
875
876 /**
877 * Multi-function for adding an entry to the $menuItems array
878 *
879 * @param string Path to the file/directory (target)
880 * @param string Script (eg. file_edit.php) to pass &target= to
881 * @param string "type" is the code which fetches the correct label for the element from "cm."
882 * @param string icon image-filename from "gfx/" (12x12 icon)
883 * @return array Item array, element in $menuItems
884 * @internal
885 */
886 function FILE_launch($path,$script,$type,$image) {
887 $loc='top.content'.(!$this->alwaysContentFrame?'.list_frame':'');
888
889 $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'".$script.'?target='.rawurlencode($path)."&returnUrl='+top.rawurlencode(".$this->frameLocation($loc.'.document').");}";
890
891 return $this->linkItem(
892 $this->label($type),
893 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/'.$image,'width="12" height="12"').' alt="" />'),
894 $editOnClick.'return hideCM();'
895 );
896 }
897
898 /**
899 * Returns element for copy or cut of files.
900 *
901 * @param string Path to the file/directory (target)
902 * @param string Type: "copy" or "cut"
903 * @return array Item array, element in $menuItems
904 * @internal
905 */
906 function FILE_copycut($path,$type) {
907 $table = '_FILE'; // Pseudo table name for use in the clipboard.
908 $uid = t3lib_div::shortmd5($path);
909 if ($this->clipObj->current=='normal') {
910 $isSel = $this->clipObj->isSelected($table,$uid);
911 }
912
913 $addParam = array();
914 if ($this->listFrame) {
915 $addParam['reloadListFrame'] = ($this->alwaysContentFrame ? 2 : 1);
916 }
917
918 return $this->linkItem(
919 $this->label($type),
920 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/clip_'.$type.($isSel==$type?'_h':'').'.gif','width="12" height="12"').' alt="" />'),
921 "top.loadTopMenu('".$this->clipObj->selUrlFile($path,($type=='copy'?1:0),($isSel==$type),$addParam)."');return false;"
922 );
923 }
924
925 /**
926 * Creates element for deleting of target
927 *
928 * @param string Path to the file/directory (target)
929 * @return array Item array, element in $menuItems
930 * @internal
931 */
932 function FILE_delete($path) {
933 $editOnClick='';
934 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
935 if($GLOBALS['BE_USER']->jsConfirmation(4)) {
936 $conf = "confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.delete'),basename($path))).")";
937 } else {
938 $conf = '1==1';
939 }
940 $editOnClick='if('.$loc." && ".$conf." ){".$loc.".document.location=top.TS.PATH_typo3+'tce_file.php?redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'".
941 "&file[delete][0][data]=".rawurlencode($path).'&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
942
943 return $this->linkItem(
944 $this->label('delete'),
945 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/garbage.gif','width="11" height="12"').' alt="" />'),
946 $editOnClick.'return false;'
947 );
948 }
949
950 /**
951 * Creates element for pasting files.
952 *
953 * @param string Path to the file/directory (target)
954 * @param string target - NOT USED.
955 * @param array Various values for the labels.
956 * @return array Item array, element in $menuItems
957 * @internal
958 */
959 function FILE_paste($path,$target,$elInfo) {
960 $editOnClick='';
961 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
962 if($GLOBALS['BE_USER']->jsConfirmation(2)) {
963 $conf=$loc." && confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.'.($elInfo[2]=='copy'?'copy':'move').'_into'),$elInfo[0],$elInfo[1])).")";
964 } else {
965 $conf=$loc;
966 }
967
968 $editOnClick='if('.$conf.'){'.$loc.".document.location=top.TS.PATH_typo3+'".$this->clipObj->pasteUrl('_FILE',$path,0).
969 "&redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').'); hideCM();}';
970
971 return $this->linkItem(
972 $this->label('pasteinto'),
973 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/clip_pasteinto.gif','width="12" height="12"').' alt="" />'),
974 $editOnClick.'return false;'
975 );
976 }
977
978
979
980
981
982
983
984
985
986
987
988
989
990 /***************************************
991 *
992 * COMMON
993 *
994 **************************************/
995
996 /**
997 * Prints the items from input $menuItems array - both as topframe menu AND the JS section for writing to the div-layers.
998 * Of course the topframe menu will appear only if $this->doDisplayTopFrameCM() returns true
999 *
1000 * @param array $menuItems array
1001 * @param string HTML code for the element which was clicked - shown in the end of the horizontal menu in topframe after the close-button.
1002 * @return string HTML code
1003 */
1004 function printItems($menuItems,$item) {
1005
1006 $out='';
1007
1008 // Enable/Disable items:
1009 $menuItems = $this->enableDisableItems($menuItems);
1010
1011 // Clean up spacers:
1012 $menuItems = $this->cleanUpSpacers($menuItems);
1013
1014 // Adding topframe part (horizontal clickmenu)
1015 if ($this->doDisplayTopFrameCM()) {
1016 $out.= '
1017
1018 <!--
1019 Table, which contains the click menu when shown in the top frame of the backend:
1020 -->
1021 <table border="0" cellpadding="0" cellspacing="0" id="typo3-CSM-top">
1022 <tr>
1023
1024 <!-- Items: -->
1025 <td class="c-item">'.
1026 implode('</td>
1027 <td><img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/acm_spacer2.gif','width="8" height="12"').' alt="" /></td>
1028 <td class="c-item">',$this->menuItemsForTopFrame($menuItems)).
1029 '</td>
1030
1031 <!-- Close button: -->
1032 <td class="c-closebutton"><a href="#" onclick="hideCM();return false;"><img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/close_12h.gif','width="11" height="12"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.close',1).'" alt="" /></a></td>
1033
1034 <!-- The item of the clickmenu: -->
1035 <td class="c-itemicon">'.$item.'</td>
1036 </tr>
1037 </table>
1038 ';
1039
1040 // Set remaining BACK_PATH to blank (if any)
1041 $out = str_replace($this->PH_backPath,'',$out);
1042 }
1043 // Adding JS part:
1044 $out.=$this->printLayerJScode($menuItems);
1045
1046 // Return the content
1047 return $out;
1048 }
1049
1050 /**
1051 * Create the JavaScript section
1052 *
1053 * @param array The $menuItems array to print
1054 * @return string The JavaScript section which will print the content of the CM to the div-layer in the target frame.
1055 */
1056 function printLayerJScode($menuItems) {
1057 $script='';
1058 if ($this->isCMlayers()) { // Clipboard must not be submitted - then it's probably a copy/cut situation.
1059 $frameName = '.'.($this->listFrame ? 'list_frame' : 'nav_frame');
1060 if ($this->alwaysContentFrame) $frameName='';
1061
1062 // Create the table displayed in the clickmenu layer:
1063 $CMtable = '
1064 <table border="0" cellpadding="0" cellspacing="0" class="typo3-CSM bgColor4">
1065 '.implode('',$this->menuItemsForClickMenu($menuItems)).'
1066 </table>';
1067
1068 // Wrap the inner table in another table to create outer border:
1069 $CMtable = $this->wrapColorTableCM($CMtable);
1070
1071 // Set back path place holder to real back path
1072 $CMtable = str_replace($this->PH_backPath,$this->backPath,$CMtable);
1073 if($this->ajax) {
1074 $innerXML = '<data><clickmenu><htmltable><![CDATA['.$CMtable.']]></htmltable><cmlevel>'.$this->cmLevel.'</cmlevel></clickmenu></data>';
1075 return $innerXML;
1076 } else {
1077 // Create JavaScript section:
1078 $script=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
1079
1080 if (top.content && top.content'.$frameName.' && top.content'.$frameName.'.setLayerObj) {
1081 top.content'.$frameName.'.setLayerObj(unescape("'.t3lib_div::rawurlencodeJS($CMtable).'"),'.$this->cmLevel.');
1082 }
1083 '.(!$this->doDisplayTopFrameCM()?'hideCM();':'')
1084 );
1085 return $script;
1086 }
1087 }
1088 }
1089
1090 /**
1091 * Wrapping the input string in a table with background color 4 and a black border style.
1092 * For the pop-up menu
1093 *
1094 * @param string HTML content to wrap in table.
1095 * @return string
1096 */
1097 function wrapColorTableCM($str) {
1098
1099 // Clear-gifs needed if opera is to set the table row height correctly in skins.
1100 $str = '<table border="0" cellspacing="0" class="typo3-CSM-wrapperCM">
1101 <tr class="c-rowA">
1102 <td class="c-aa">'.$str.'</td>
1103 <td class="c-ab"></td>
1104 </tr>
1105 <tr class="c-rowB">
1106 <td class="c-ba"><img src="clear.gif" width="1" height="1" alt="" /></td>
1107 <td class="c-bb"><img src="clear.gif" width="1" height="1" alt="" /></td>
1108 </tr>
1109 </table>';
1110 return $str;
1111 }
1112
1113 /**
1114 * Traverses the menuItems and generates an output array for implosion in the topframe horizontal menu
1115 *
1116 * @param array $menuItem array
1117 * @param array Array with HTML content to be imploded between <td>-tags
1118 * @return array Array of menu items for top frame.
1119 */
1120 function menuItemsForTopFrame($menuItems) {
1121 reset($menuItems);
1122 $out=array();
1123 while(list(,$i)=each($menuItems)) {
1124 if ($i[4]==1 && !$GLOBALS['SOBE']->doc->isCMlayers()) $i[4]=0; // IF the topbar is the ONLY means of the click menu, then items normally disabled from the top menu will appear anyways IF they are disabled with a "1" (2+ will still disallow them in the topbar)
1125 if (is_array($i) && !$i[4]) $out[]=$i[0];
1126 }
1127 return $out;
1128 }
1129
1130 /**
1131 * Traverses the menuItems and generates an output array for implosion in the CM div-layers table.
1132 *
1133 * @param array $menuItem array
1134 * @param array Array with HTML content to be imploded between <td>-tags
1135 * @return array array for implosion in the CM div-layers table.
1136 */
1137 function menuItemsForClickMenu($menuItems) {
1138 reset($menuItems);
1139 $out=array();
1140 while(list($cc,$i)=each($menuItems)) {
1141 if (is_string($i) && $i=='spacer') { // MAKE horizontal spacer
1142 $out[]='
1143 <tr class="bgColor2">
1144 <td colspan="2"><img src="clear.gif" width="1" height="1" alt="" /></td>
1145 </tr>';
1146 } else { // Just make normal element:
1147 $onClick=$i[3];
1148 $onClick=eregi_replace('return[[:space:]]+hideCM\(\)[[:space:]]*;','',$onClick);
1149 $onClick=eregi_replace('return[[:space:]]+false[[:space:]]*;','',$onClick);
1150 $onClick=eregi_replace('hideCM\(\);','',$onClick);
1151 if (!$i[5]) $onClick.='hideEmpty();';
1152
1153 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
1154 $CSM = ' oncontextmenu="'.htmlspecialchars($onClick).';return false;"';
1155 }
1156
1157 $out[]='
1158 <tr class="typo3-CSM-itemRow" onclick="'.htmlspecialchars($onClick).'" onmouseover="this.bgColor=\''.$GLOBALS['TBE_TEMPLATE']->bgColor5.'\';" onmouseout="this.bgColor=\'\';"'.$CSM.'>
1159 '.(!$this->leftIcons?'<td class="typo3-CSM-item">'.$i[1].'</td><td align="center">'.$i[2].'</td>' : '<td align="center">'.$i[2].'</td><td class="typo3-CSM-item">'.$i[1].'</td>').'
1160 </tr>';
1161 }
1162 }
1163 return $out;
1164 }
1165
1166 /**
1167 * Adds or inserts a menu item
1168 * Can be used to set the position of new menu entries within the list of existing menu entries. Has this syntax: [cmd]:[menu entry key],[cmd].... cmd can be "after", "before" or "top" (or blank/"bottom" which is default). If "after"/"before" then menu items will be inserted after/before the existing entry with [menu entry key] if found. "after-spacer" and "before-spacer" do the same, but inserts before or after an item and a spacer. If not found, the bottom of list. If "top" the items are inserted in the top of the list.
1169 *
1170 * @param array Menu items array
1171 * @param array Menu items array to insert
1172 * @param string Position command string. Has this syntax: [cmd]:[menu entry key],[cmd].... cmd can be "after", "before" or "top" (or blank/"bottom" which is default). If "after"/"before" then menu items will be inserted after/before the existing entry with [menu entry key] if found. "after-spacer" and "before-spacer" do the same, but inserts before or after an item and a spacer. If not found, the bottom of list. If "top" the items are inserted in the top of the list.
1173 * @return array Menu items array, processed.
1174 */
1175 function addMenuItems($menuItems,$newMenuItems,$position='') {
1176 if (is_array($newMenuItems)) {
1177
1178 if($position) {
1179
1180 $posArr = t3lib_div::trimExplode(',', $position, 1);
1181 foreach($posArr as $pos) {
1182 list($place,$menuEntry) = t3lib_div::trimExplode(':', $pos, 1);
1183 list($place,$placeExtra) = t3lib_div::trimExplode('-', $place, 1);
1184
1185 // bottom
1186 $pointer = count($menuItems);
1187
1188 $found=FALSE;
1189
1190 if ($place) {
1191 switch(strtolower($place)) {
1192 case 'after':
1193 case 'before':
1194 if ($menuEntry) {
1195 $p=1;
1196 reset ($menuItems);
1197 while (true) {
1198 if (!strcmp(key($menuItems), $menuEntry)) {
1199 $pointer = $p;
1200 $found=TRUE;
1201 break;
1202 }
1203 if (!next($menuItems)) break;
1204 $p++;
1205 }
1206 if (!$found) break;
1207
1208 if ($place=='before') {
1209 $pointer--;
1210 if ($placeExtra=='spacer' AND prev($menuItems)=='spacer') {
1211 $pointer--;
1212 }
1213 } elseif ($place=='after') {
1214 if ($placeExtra=='spacer' AND next($menuItems)=='spacer') {
1215 $pointer++;
1216 }
1217 }
1218 }
1219 break;
1220 default:
1221 if (strtolower($place)=='top') {
1222 $pointer = 0;
1223 } else {
1224 $pointer = count($menuItems);
1225 }
1226 $found=TRUE;
1227 break;
1228 }
1229 }
1230 if($found) break;
1231 }
1232 }
1233 $pointer=max(0,$pointer);
1234 $menuItemsBefore = array_slice($menuItems, 0, ($pointer?$pointer:0));
1235 $menuItemsAfter = array_slice($menuItems, $pointer);
1236 $menuItems = $menuItemsBefore + $newMenuItems + $menuItemsAfter;
1237 }
1238 return $menuItems;
1239 }
1240
1241 /**
1242 * Creating an array with various elements for the clickmenu entry
1243 *
1244 * @param string The label, htmlspecialchar'ed already
1245 * @param string <img>-tag for the icon
1246 * @param string JavaScript onclick event for label/icon
1247 * @param boolean ==1 and the element will NOT appear in clickmenus in the topframe (unless clickmenu is totally unavailable)! ==2 and the item will NEVER appear in top frame. (This is mostly for "less important" options since the top frame is not capable of holding so many elements horizontally)
1248 * @param boolean If set, the clickmenu layer will not hide itself onclick - used for secondary menus to appear...
1249 * @return array $menuItem entry with 6 numerical entries: [0] is the HTML for display of the element with link and icon an mouseover etc., [1]-[5] is simply the input params passed through!
1250 */
1251 function linkItem($str,$icon,$onClick,$onlyCM=0,$dontHide=0) {
1252 $this->elCount++;
1253 if($this->ajax) {
1254 $onClick = str_replace('top.loadTopMenu', 'showClickmenu_raw', $onClick);
1255 }
1256
1257 $WHattribs = t3lib_iconWorks::skinImg($BACK_PATH,'gfx/content_client.gif','width="7" height="10"',2);
1258
1259 return array(
1260 '<img src="clear.gif" '.$WHattribs.' class="c-roimg" name="roimg_'.$this->elCount.'" alt="" />'.
1261 '<a href="#" onclick="'.htmlspecialchars($onClick).'" onmouseover="mo('.$this->elCount.');" onmouseout="mout('.$this->elCount.');">'.
1262 $str.$icon.
1263 '</a>',
1264 $str,
1265 $icon,
1266 $onClick,
1267 $onlyCM,
1268 $dontHide
1269 );
1270 }
1271
1272 /**
1273 * Returns the input string IF not a user setting has disabled display of icons.
1274 *
1275 * @param string The icon-image tag
1276 * @return string The icon-image tag prefixed with space char IF the icon should be printed at all due to user settings
1277 */
1278 function excludeIcon($iconCode) {
1279 return ($GLOBALS['BE_USER']->uc['noMenuMode'] && strcmp($GLOBALS['BE_USER']->uc['noMenuMode'],'icons')) ? '' : ' '.$iconCode;
1280 }
1281
1282 /**
1283 * Enabling / Disabling items based on list provided from GET var ($this->iParts[3])
1284 *
1285 * @param array Menu items array
1286 * @return array Menu items array, processed.
1287 */
1288 function enableDisableItems($menuItems) {
1289 if ($this->iParts[3]) {
1290
1291 // Detect "only" mode: (only showing listed items)
1292 if (substr($this->iParts[3],0,1)=='+') {
1293 $this->iParts[3] = substr($this->iParts[3],1);
1294 $only = TRUE;
1295 } else {
1296 $only = FALSE;
1297 }
1298
1299 // Do filtering:
1300 if ($only) { // Transfer ONLY elements which are mentioned (or are spacers)
1301 $newMenuArray = array();
1302 foreach($menuItems as $key => $value) {
1303 if (t3lib_div::inList($this->iParts[3], $key) || (is_string($value) && $value=='spacer')) {
1304 $newMenuArray[$key] = $value;
1305 }
1306 }
1307 $menuItems = $newMenuArray;
1308 } else { // Traverse all elements except those listed (just unsetting them):
1309 $elements = t3lib_div::trimExplode(',',$this->iParts[3],1);
1310 foreach($elements as $value) {
1311 unset($menuItems[$value]);
1312 }
1313 }
1314 }
1315
1316 // Return processed menu items:
1317 return $menuItems;
1318 }
1319
1320 /**
1321 * Clean up spacers; Will remove any spacers in the start/end of menu items array plus any duplicates.
1322 *
1323 * @param array Menu items array
1324 * @return array Menu items array, processed.
1325 */
1326 function cleanUpSpacers($menuItems) {
1327
1328 // Remove doubles:
1329 $prevItemWasSpacer = FALSE;
1330 foreach($menuItems as $key => $value) {
1331 if (is_string($value) && $value=='spacer') {
1332 if ($prevItemWasSpacer) {
1333 unset($menuItems[$key]);
1334 }
1335 $prevItemWasSpacer = TRUE;
1336 } else {
1337 $prevItemWasSpacer = FALSE;
1338 }
1339 }
1340
1341 // Remove first:
1342 reset($menuItems);
1343 $key = key($menuItems);
1344 $value = current($menuItems);
1345 if (is_string($value) && $value=='spacer') {
1346 unset($menuItems[$key]);
1347 }
1348
1349
1350 // Remove last:
1351 end($menuItems);
1352 $key = key($menuItems);
1353 $value = current($menuItems);
1354 if (is_string($value) && $value=='spacer') {
1355 unset($menuItems[$key]);
1356 }
1357
1358 // Return processed menu items:
1359 return $menuItems;
1360 }
1361
1362 /**
1363 * Get label from locallang_core.php:cm.*
1364 *
1365 * @param string The "cm."-suffix to get.
1366 * @return string
1367 */
1368 function label($label) {
1369 return $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.'.$label,1));
1370 }
1371
1372 /**
1373 * Returns true if there should be writing to the div-layers (commands sent to clipboard MUST NOT write to div-layers)
1374 *
1375 * @return boolean
1376 */
1377 function isCMlayers() {
1378 if($this->ajax) {
1379 return !$this->CB;
1380 } else {
1381 return $GLOBALS['SOBE']->doc->isCMlayers() && !$this->CB;
1382 }
1383 }
1384
1385 /**
1386 * Appends ".location" to input string
1387 *
1388 * @param string Input string, probably a JavaScript document reference
1389 * @return string
1390 */
1391 function frameLocation($str) {
1392 return $str.'.location';
1393 }
1394 }
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408 /**
1409 * Script Class for the Context Sensitive Menu in TYPO3 (rendered in top frame, normally writing content dynamically to list frames).
1410 *
1411 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
1412 * @package TYPO3
1413 * @subpackage core
1414 * @see template::getContextMenuCode()
1415 */
1416 class SC_alt_clickmenu {
1417
1418 // Internal, static: GPvar:
1419 var $backPath; // Back path.
1420 var $item; // Definition of which item the click menu should be made for.
1421 var $reloadListFrame; // Defines the name of the document object for which to reload the URL.
1422
1423 // Internal:
1424 var $content=''; // Content accumulation
1425 var $doc; // Template object
1426 var $include_once=array(); // Files to include_once() - set in init() function
1427 var $extClassArray=array(); // Internal array of classes for extending the clickmenu
1428 var $dontDisplayTopFrameCM=0; // If set, then the clickmenu will NOT display in the top frame.
1429
1430 /**
1431 * Constructor function for script class.
1432 *
1433 * @return void
1434 */
1435 function init() {
1436 global $BE_USER,$BACK_PATH;
1437
1438 // Setting GPvars:
1439 $this->backPath = t3lib_div::_GP('backPath');
1440 $this->item = t3lib_div::_GP('item');
1441 $this->reloadListFrame = t3lib_div::_GP('reloadListFrame');
1442
1443 // Setting pseudo module name
1444 $this->MCONF['name']='xMOD_alt_clickmenu.php';
1445
1446 // Takes the backPath as a parameter BUT since we are worried about someone forging a backPath (XSS security hole) we will check with sent md5 hash:
1447 $inputBP = explode('|',$this->backPath);
1448 if (count($inputBP)==2 && $inputBP[1]==t3lib_div::shortMD5($inputBP[0].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
1449 $this->backPath = $inputBP[0];
1450 } else {
1451 $this->backPath = $BACK_PATH;
1452 }
1453
1454 // Setting internal array of classes for extending the clickmenu:
1455 $this->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses'];
1456
1457 // Traversing that array and setting files for inclusion:
1458 if (is_array($this->extClassArray)) {
1459 foreach($this->extClassArray as $extClassConf) {
1460 if ($extClassConf['path']) $this->include_once[]=$extClassConf['path'];
1461 }
1462 }
1463
1464 // Initialize template object
1465 if(!$this->ajax) {
1466 $this->doc = t3lib_div::makeInstance('template');
1467 $this->doc->docType='xhtml_trans';
1468 $this->doc->backPath = $BACK_PATH;
1469 }
1470
1471 // Setting mode for display and background image in the top frame
1472 $this->dontDisplayTopFrameCM= $this->doc->isCMlayers() && !$BE_USER->getTSConfigVal('options.contextMenu.options.alwaysShowClickMenuInTopFrame');
1473 if ($this->dontDisplayTopFrameCM) {
1474 $this->doc->bodyTagId.= '-notop';
1475 }
1476
1477 // Setting clickmenu timeout
1478 $secs = t3lib_div::intInRange($BE_USER->getTSConfigVal('options.contextMenu.options.clickMenuTimeOut'),1,100,5); // default is 5
1479
1480 // Setting the JavaScript controlling the timer on the page
1481 $listFrameDoc = $this->reloadListFrame!=2 ? 'top.content.list_frame' : 'top.content';
1482 $this->doc->JScode.=$this->doc->wrapScriptTags('
1483 var date = new Date();
1484 var mo_timeout = Math.floor(date.getTime()/1000);
1485
1486 roImg =new Image();
1487 roImg.src = "'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/content_client.gif','width="7" height="10"',1).'";
1488
1489 routImg =new Image();
1490 routImg.src = "clear.gif";
1491
1492 function mo(c) { //
1493 var name="roimg_"+c;
1494 document[name].src = roImg.src;
1495 updateTime();
1496 }
1497 function mout(c) { //
1498 var name="roimg_"+c;
1499 document[name].src = routImg.src;
1500 updateTime();
1501 }
1502 function updateTime() { //
1503 date = new Date();
1504 mo_timeout = Math.floor(date.getTime()/1000);
1505 }
1506 function timeout_func() { //
1507 date = new Date();
1508 if (Math.floor(date.getTime()/1000)-mo_timeout > '.$secs.') {
1509 hideCM();
1510 return false;
1511 } else {
1512 window.setTimeout("timeout_func();",1*1000);
1513 }
1514 }
1515 function hideCM() { //
1516 document.location="alt_topmenu_dummy.php";
1517 return false;
1518 }
1519
1520 // Start timer
1521 timeout_func();
1522
1523 '.($this->reloadListFrame ? '
1524 // Reload list frame:
1525 if('.$listFrameDoc.'){'.$listFrameDoc.'.document.location='.$listFrameDoc.'.document.location;}' :
1526 '').'
1527 ');
1528 }
1529
1530 /**
1531 * Main function - generating the click menu in whatever form it has.
1532 *
1533 * @return void
1534 */
1535 function main() {
1536
1537 $this->ajax = t3lib_div::_GP('ajax')?TRUE:FALSE;
1538
1539 // Initialize Clipboard object:
1540 $clipObj = t3lib_div::makeInstance('t3lib_clipboard');
1541 $clipObj->initializeClipboard();
1542 $clipObj->lockToNormal(); // This locks the clipboard to the Normal for this request.
1543
1544 // Update clipboard if some actions are sent.
1545 $CB = t3lib_div::_GET('CB');
1546 $clipObj->setCmd($CB);
1547 $clipObj->cleanCurrent();
1548 $clipObj->endClipboard(); // Saves
1549
1550 // Create clickmenu object
1551 $clickMenu = t3lib_div::makeInstance('clickMenu');
1552
1553 // Set internal vars in clickmenu object:
1554 $clickMenu->clipObj = $clipObj;
1555 $clickMenu->extClassArray = $this->extClassArray;
1556 $clickMenu->dontDisplayTopFrameCM = $this->dontDisplayTopFrameCM;
1557 $clickMenu->backPath = $this->backPath;
1558
1559 // Start page
1560 if(!$this->ajax) {
1561 $this->content.=$this->doc->startPage('Context Sensitive Menu');
1562 }
1563 // Set content of the clickmenu with the incoming var, "item"
1564 $this->content.= $clickMenu->init();
1565 }
1566
1567 /**
1568 * End page and output content.
1569 *
1570 * @return void
1571 */
1572 function printContent() {
1573 if(!$this->ajax) {
1574 $this->content.= $this->doc->endPage();
1575 echo $this->content;
1576 } else {
1577 t3lib_ajax::outputXMLreply($this->content);
1578 }
1579 }
1580 }
1581
1582 // Include extension?
1583 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php']) {
1584 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php']);
1585 }
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596 // Make instance:
1597 $SOBE = t3lib_div::makeInstance('SC_alt_clickmenu');
1598 $SOBE->init();
1599
1600 // Include files?
1601 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
1602
1603 $SOBE->main();
1604 $SOBE->printContent();
1605 ?>