2005-11-09 Sebastian Kurfuerst <sebastian@garbage-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 $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])).')';
447 $editOnClick = 'if('.$conf.'){'.$loc.'.document.location=top.TS.PATH_typo3+\''.$this->clipObj->pasteUrl($table,$uid,0).'&redirect=\'+top.rawurlencode('.$this->frameLocation($loc.'.document').'); hideCM();}';
448
449 return $this->linkItem(
450 $this->label('paste'.$type),
451 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/clip_paste'.$type.'.gif','width="12" height="12"').' alt="" />'),
452 $editOnClick.'return false;'
453 );
454 }
455
456 /**
457 * Adding CM element for Info
458 *
459 * @param string Table name
460 * @param integer UID for the current record.
461 * @return array Item array, element in $menuItems
462 * @internal
463 */
464 function DB_info($table,$uid) {
465 return $this->linkItem(
466 $this->label('info'),
467 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/zoom2.gif','width="12" height="12"').' alt="" />'),
468 "top.launchView('".$table."', '".$uid."'); return hideCM();"
469 );
470 }
471
472 /**
473 * Adding CM element for History
474 *
475 * @param string Table name
476 * @param integer UID for the current record.
477 * @return array Item array, element in $menuItems
478 * @internal
479 */
480 function DB_history($table,$uid) {
481 $url = 'show_rechis.php?element='.rawurlencode($table.':'.$uid);
482 return $this->linkItem(
483 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_history')),
484 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/history2.gif','width="13" height="12"').' alt="" />'),
485 $this->urlRefForCM($url,'returnUrl'),
486 0
487 );
488 }
489
490 /**
491 * Adding CM element for Permission setting
492 *
493 * @param string Table name
494 * @param integer UID for the current record.
495 * @param array The "pages" record with "perms_*" fields inside.
496 * @return array Item array, element in $menuItems
497 * @internal
498 */
499 function DB_perms($table,$uid,$rec) {
500 $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':'');
501 return $this->linkItem(
502 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_perms')),
503 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/perm.gif','width="7" height="12"').' alt="" />'),
504 $this->urlRefForCM($url),
505 0
506 );
507 }
508
509 /**
510 * Adding CM element for DBlist
511 *
512 * @param string Table name
513 * @param integer UID for the current record.
514 * @param array Record of the element (needs "pid" field if not pages-record)
515 * @return array Item array, element in $menuItems
516 * @internal
517 */
518 function DB_db_list($table,$uid,$rec) {
519 $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR').'db_list.php?table='.($table=='pages'?'':$table).'&id='.($table=='pages'?$uid:$rec['pid']);
520 return $this->linkItem(
521 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_db_list')),
522 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/list.gif','width="11" height="11"').' alt="" />'),
523 "top.nextLoadModuleUrl='".$url."';top.goToModule('web_list',1);",
524 0
525 );
526 }
527
528 /**
529 * Adding CM element for Moving wizard
530 *
531 * @param string Table name
532 * @param integer UID for the current record.
533 * @param array Record. Needed for tt-content elements which will have the sys_language_uid sent
534 * @return array Item array, element in $menuItems
535 * @internal
536 */
537 function DB_moveWizard($table,$uid,$rec) {
538 $url = 'move_el.php?table='.$table.'&uid='.$uid.
539 ($table=='tt_content'?'&sys_language_uid='.intval($rec['sys_language_uid']):''); // Hardcoded field for tt_content elements.
540
541 return $this->linkItem(
542 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_moveWizard'.($table=='pages'?'_page':''))),
543 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/move_'.($table=='pages'?'page':'record').'.gif','width="11" height="12"').' alt="" />'),
544 $this->urlRefForCM($url,'returnUrl'),
545 0
546 );
547 }
548
549 /**
550 * Adding CM element for Create new wizard (either db_new.php or sysext/cms/layout/db_new_content_el.php or custom wizard)
551 *
552 * @param string Table name
553 * @param integer UID for the current record.
554 * @param array Record.
555 * @return array Item array, element in $menuItems
556 * @internal
557 */
558 function DB_newWizard($table,$uid,$rec) {
559 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
560 $tmpTSc = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
561 $tmpTSc = $tmpTSc ['properties']['newContentWiz.']['overrideWithExtension'];
562 $newContentWizScriptPath = t3lib_extMgm::isLoaded($tmpTSc) ? (t3lib_extMgm::extRelPath($tmpTSc).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
563
564 $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']);
565 return $this->linkItem(
566 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_newWizard')),
567 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/new_'.($table=='pages'?'page':'record').'.gif','width="'.($table=='pages'?'13':'16').'" height="12"').' alt="" />'),
568 $this->urlRefForCM($url,'returnUrl'),
569 0
570 );
571 }
572
573 /**
574 * Adding CM element for Editing of the access related fields of a table (disable, starttime, endtime, fe_groups)
575 *
576 * @param string Table name
577 * @param integer UID for the current record.
578 * @return array Item array, element in $menuItems
579 * @internal
580 */
581 function DB_editAccess($table,$uid) {
582 $addParam='&columnsOnly='.rawurlencode(implode(',',$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']).($table=='pages' ? ',extendToSubpages' :''));
583 $url = 'alt_doc.php?edit['.$table.']['.$uid.']=edit'.$addParam;
584 return $this->linkItem(
585 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_editAccess')),
586 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/editaccess.gif','width="12" height="12"').' alt="" />'),
587 $this->urlRefForCM($url,'returnUrl'),
588 1 // no top frame CM!
589 );
590 }
591
592 /**
593 * Adding CM element for edit page header
594 *
595 * @param integer page uid to edit (PID)
596 * @return array Item array, element in $menuItems
597 * @internal
598 */
599 function DB_editPageHeader($uid) {
600 $url = 'alt_doc.php?edit[pages]['.$uid.']=edit';
601 return $this->linkItem(
602 $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_editPageHeader')),
603 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/edit2.gif','width="11" height="12"').' alt="" />'),
604 $this->urlRefForCM($url,'returnUrl'),
605 1 // no top frame CM!
606 );
607 }
608
609 /**
610 * Adding CM element for regular editing of the element!
611 *
612 * @param string Table name
613 * @param integer UID for the current record.
614 * @return array Item array, element in $menuItems
615 * @internal
616 */
617 function DB_edit($table,$uid) {
618 global $BE_USER;
619 // If another module was specified, replace the default Page module with the new one
620 $newPageModule = trim($BE_USER->getTSConfigVal('options.overridePageModule'));
621 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
622
623 $editOnClick='';
624 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
625 $addParam='';
626 $theIcon = t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/edit2.gif','width="11" height="12"');
627 if (
628 $this->iParts[0]=='pages' &&
629 $this->iParts[1] &&
630 $BE_USER->check('modules', $pageModule)
631 ) {
632 $theIcon = t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/edit_page.gif','width="12" height="12"');
633 $this->editPageIconSet=1;
634 if ($BE_USER->uc['classicPageEditMode'] || !t3lib_extMgm::isLoaded('cms')) {
635 $addParam='&editRegularContentFromId='.intval($this->iParts[1]);
636 } else {
637 $editOnClick="top.fsMod.recentIds['web']=".intval($this->iParts[1]).";top.goToModule('".$pageModule."',1);";
638 }
639 }
640 if (!$editOnClick) {
641 $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."';}";
642 }
643
644 return $this->linkItem(
645 $this->label('edit'),
646 $this->excludeIcon('<img'.$theIcon.' alt="" />'),
647 $editOnClick.'return hideCM();'
648 );
649 }
650
651 /**
652 * Adding CM element for regular Create new element
653 *
654 * @param string Table name
655 * @param integer UID for the current record.
656 * @return array Item array, element in $menuItems
657 * @internal
658 */
659 function DB_new($table,$uid) {
660 $editOnClick='';
661 $loc='top.content'.(!$this->alwaysContentFrame?'.list_frame':'');
662 $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'".
663 ($this->listFrame?
664 "alt_doc.php?returnUrl='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'&edit[".$table."][-".$uid."]=new'":
665 'db_new.php?id='.intval($uid)."'").
666 ';}';
667
668 return $this->linkItem(
669 $this->label('new'),
670 $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="" />'),
671 $editOnClick.'return hideCM();'
672 );
673 }
674
675 /**
676 * Adding CM element for Delete
677 *
678 * @param string Table name
679 * @param integer UID for the current record.
680 * @param array Label for including in the confirmation message, EXT:lang/locallang_core.php:mess.delete
681 * @return array Item array, element in $menuItems
682 * @internal
683 */
684 function DB_delete($table,$uid,$elInfo) {
685 $editOnClick='';
686 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
687 $editOnClick='if('.$loc." && confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.delete'),$elInfo[0])).")){".$loc.".document.location=top.TS.PATH_typo3+'tce_db.php?redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'".
688 "&cmd[".$table.']['.$uid.'][delete]=1&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
689
690 return $this->linkItem(
691 $this->label('delete'),
692 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/garbage.gif','width="11" height="12"').' alt="" />'),
693 $editOnClick.'return false;'
694 );
695 }
696
697 /**
698 * Adding CM element for View Page
699 *
700 * @param integer Page uid (PID)
701 * @param string Anchor, if any
702 * @return array Item array, element in $menuItems
703 * @internal
704 */
705 function DB_view($id,$anchor='') {
706 return $this->linkItem(
707 $this->label('view'),
708 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/zoom.gif','width="12" height="12"').' alt="" />'),
709 t3lib_BEfunc::viewOnClick($id,$this->PH_backPath,t3lib_BEfunc::BEgetRootLine($id),$anchor).'return hideCM();'
710 );
711 }
712
713 /**
714 * Adding element for setting temporary mount point.
715 *
716 * @param integer Page uid (PID)
717 * @return array Item array, element in $menuItems
718 * @internal
719 */
720 function DB_tempMountPoint($page_id) {
721 return $this->linkItem(
722 $this->label('tempMountPoint'),
723 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/placeasroot.gif','width="14" height="12"').' alt="" />'),
724 '',
725 "if (top.content.nav_frame) { top.content.nav_frame.document.location = 'alt_db_navframe.php?setTempDBmount=".intval($page_id)."'; } return hideCM();"
726 );
727 }
728
729 /**
730 * Adding CM element for hide/unhide of the input record
731 *
732 * @param string Table name
733 * @param array Record array
734 * @param string Name of the hide field
735 * @return array Item array, element in $menuItems
736 * @internal
737 */
738 function DB_hideUnhide($table,$rec,$hideField) {
739 return $this->DB_changeFlag($table, $rec, $hideField, $this->label(($rec[$hideField]?'un':'').'hide'), 'hide');
740 }
741
742 /**
743 * Adding CM element for a flag field of the input record
744 *
745 * @param string Table name
746 * @param array Record array
747 * @param string Name of the flag field
748 * @param string Menu item Title
749 * @param string Name of the item used for icons and labels
750 * @param string Icon path relative to typo3/ folder
751 * @return array Item array, element in $menuItems
752 */
753 function DB_changeFlag($table, $rec, $flagField, $title, $name, $iconRelPath='gfx/') {
754 $uid = $rec['_ORIG_uid'] ? $rec['_ORIG_uid'] : $rec['uid'];
755 $editOnClick='';
756 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
757 $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'tce_db.php?redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'".
758 "&data[".$table.']['.$uid.']['.$flagField.']='.($rec[$flagField]?0:1).'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
759
760 return $this->linkItem(
761 $title,
762 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,$iconRelPath.'button_'.($rec[$flagField]?'un':'').$name.'.gif','width="11" height="10"').' alt="" />'),
763 $editOnClick.'return false;',
764 1
765 );
766 }
767
768
769
770
771
772
773
774
775 /***************************************
776 *
777 * FILE
778 *
779 ***************************************/
780
781 /**
782 * Make 1st level clickmenu:
783 *
784 * @param string The absolute path
785 * @return string HTML content
786 */
787 function printFileClickMenu($path) {
788 $menuItems=array();
789
790 if (@file_exists($path) && t3lib_div::isAllowedAbsPath($path)) {
791 $fI = pathinfo($path);
792 $icon = is_dir($path) ? 'folder.gif' : t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
793 $size=' ('.t3lib_div::formatSize(filesize($path)).'bytes)';
794 $icon = '<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/fileicons/'.$icon,'width="18" height="16"').' class="absmiddle" title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
795
796 // edit
797 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');
798 // rename
799 if (!in_array('rename',$this->disabledItems)) $menuItems['rename']=$this->FILE_launch($path,'file_rename.php','rename','rename.gif');
800 // upload
801 if (!in_array('upload',$this->disabledItems) && is_dir($path)) $menuItems['upload']=$this->FILE_launch($path,'file_upload.php','upload','upload.gif');
802 // new
803 if (!in_array('new',$this->disabledItems) && is_dir($path)) $menuItems['new']=$this->FILE_launch($path,'file_newfolder.php','new','new_file.gif');
804 // info
805 if (!in_array('info',$this->disabledItems)) $menuItems['info']=$this->DB_info($path,'');
806
807 $menuItems[]='spacer';
808
809 // copy:
810 if (!in_array('copy',$this->disabledItems)) $menuItems['copy']=$this->FILE_copycut($path,'copy');
811 // cut:
812 if (!in_array('cut',$this->disabledItems)) $menuItems['cut']=$this->FILE_copycut($path,'cut');
813
814 // Paste:
815 $elFromAllTables = count($this->clipObj->elFromTable('_FILE'));
816 if (!in_array('paste',$this->disabledItems) && $elFromAllTables && is_dir($path)) {
817 $elArr = $this->clipObj->elFromTable('_FILE');
818 reset($elArr);
819 $selItem = current($elArr);
820 $elInfo=array(
821 basename($selItem),
822 basename($path),
823 $this->clipObj->currentMode()
824 );
825 $menuItems['pasteinto']=$this->FILE_paste($path,$selItem,$elInfo);
826 }
827
828 $menuItems[]='spacer';
829
830 // delete:
831 if (!in_array('delete',$this->disabledItems)) $menuItems['delete']=$this->FILE_delete($path);
832 }
833
834 // Adding external elements to the menuItems array
835 $menuItems = $this->processingByExtClassArray($menuItems,$path,0);
836
837 // Processing by external functions?
838 $menuItems = $this->externalProcessingOfFileMenuItems($menuItems);
839
840 // Return the printed elements:
841 return $this->printItems($menuItems,$icon.basename($path));
842 }
843
844
845 /**
846 * Processing the $menuItems array (for extension classes) (FILES)
847 *
848 * @param array $menuItems array for manipulation.
849 * @return array Processed $menuItems array
850 */
851 function externalProcessingOfFileMenuItems($menuItems) {
852 return $menuItems;
853 }
854
855 /**
856 * Multi-function for adding an entry to the $menuItems array
857 *
858 * @param string Path to the file/directory (target)
859 * @param string Script (eg. file_edit.php) to pass &target= to
860 * @param string "type" is the code which fetches the correct label for the element from "cm."
861 * @param string icon image-filename from "gfx/" (12x12 icon)
862 * @return array Item array, element in $menuItems
863 * @internal
864 */
865 function FILE_launch($path,$script,$type,$image) {
866 $loc='top.content'.(!$this->alwaysContentFrame?'.list_frame':'');
867
868 $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'".$script.'?target='.rawurlencode($path)."&returnUrl='+top.rawurlencode(".$this->frameLocation($loc.'.document').");}";
869
870 return $this->linkItem(
871 $this->label($type),
872 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/'.$image,'width="12" height="12"').' alt="" />'),
873 $editOnClick.'return hideCM();'
874 );
875 }
876
877 /**
878 * Returns element for copy or cut of files.
879 *
880 * @param string Path to the file/directory (target)
881 * @param string Type: "copy" or "cut"
882 * @return array Item array, element in $menuItems
883 * @internal
884 */
885 function FILE_copycut($path,$type) {
886 $table = '_FILE'; // Pseudo table name for use in the clipboard.
887 $uid = t3lib_div::shortmd5($path);
888 if ($this->clipObj->current=='normal') {
889 $isSel = $this->clipObj->isSelected($table,$uid);
890 }
891
892 $addParam = array();
893 if ($this->listFrame) {
894 $addParam['reloadListFrame'] = ($this->alwaysContentFrame ? 2 : 1);
895 }
896
897 return $this->linkItem(
898 $this->label($type),
899 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/clip_'.$type.($isSel==$type?'_h':'').'.gif','width="12" height="12"').' alt="" />'),
900 "top.loadTopMenu('".$this->clipObj->selUrlFile($path,($type=='copy'?1:0),($isSel==$type),$addParam)."');return false;"
901 );
902 }
903
904 /**
905 * Creates element for deleting of target
906 *
907 * @param string Path to the file/directory (target)
908 * @return array Item array, element in $menuItems
909 * @internal
910 */
911 function FILE_delete($path) {
912 $editOnClick='';
913 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
914 $editOnClick='if('.$loc." && confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.delete'),basename($path))).")){".$loc.".document.location=top.TS.PATH_typo3+'tce_file.php?redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'".
915 "&file[delete][0][data]=".rawurlencode($path).'&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
916
917 return $this->linkItem(
918 $this->label('delete'),
919 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/garbage.gif','width="11" height="12"').' alt="" />'),
920 $editOnClick.'return false;'
921 );
922 }
923
924 /**
925 * Creates element for pasting files.
926 *
927 * @param string Path to the file/directory (target)
928 * @param string target - NOT USED.
929 * @param array Various values for the labels.
930 * @return array Item array, element in $menuItems
931 * @internal
932 */
933 function FILE_paste($path,$target,$elInfo) {
934 $editOnClick='';
935 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
936 $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])).")";
937 $editOnClick='if('.$conf.'){'.$loc.".document.location=top.TS.PATH_typo3+'".$this->clipObj->pasteUrl('_FILE',$path,0).
938 "&redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').'); hideCM();}';
939
940 return $this->linkItem(
941 $this->label('pasteinto'),
942 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/clip_pasteinto.gif','width="12" height="12"').' alt="" />'),
943 $editOnClick.'return false;'
944 );
945 }
946
947
948
949
950
951
952
953
954
955
956
957
958
959 /***************************************
960 *
961 * COMMON
962 *
963 **************************************/
964
965 /**
966 * Prints the items from input $menuItems array - both as topframe menu AND the JS section for writing to the div-layers.
967 * Of course the topframe menu will appear only if $this->doDisplayTopFrameCM() returns true
968 *
969 * @param array $menuItems array
970 * @param string HTML code for the element which was clicked - shown in the end of the horizontal menu in topframe after the close-button.
971 * @return string HTML code
972 */
973 function printItems($menuItems,$item) {
974
975 $out='';
976
977 // Enable/Disable items:
978 $menuItems = $this->enableDisableItems($menuItems);
979
980 // Clean up spacers:
981 $menuItems = $this->cleanUpSpacers($menuItems);
982
983 // Adding topframe part (horizontal clickmenu)
984 if ($this->doDisplayTopFrameCM()) {
985 $out.= '
986
987 <!--
988 Table, which contains the click menu when shown in the top frame of the backend:
989 -->
990 <table border="0" cellpadding="0" cellspacing="0" id="typo3-CSM-top">
991 <tr>
992
993 <!-- Items: -->
994 <td class="c-item">'.
995 implode('</td>
996 <td><img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/acm_spacer2.gif','width="8" height="12"').' alt="" /></td>
997 <td class="c-item">',$this->menuItemsForTopFrame($menuItems)).
998 '</td>
999
1000 <!-- Close button: -->
1001 <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>
1002
1003 <!-- The item of the clickmenu: -->
1004 <td class="c-itemicon">'.$item.'</td>
1005 </tr>
1006 </table>
1007 ';
1008
1009 // Set remaining BACK_PATH to blank (if any)
1010 $out = str_replace($this->PH_backPath,'',$out);
1011 }
1012 // Adding JS part:
1013 $out.=$this->printLayerJScode($menuItems);
1014
1015 // Return the content
1016 return $out;
1017 }
1018
1019 /**
1020 * Create the JavaScript section
1021 *
1022 * @param array The $menuItems array to print
1023 * @return string The JavaScript section which will print the content of the CM to the div-layer in the target frame.
1024 */
1025 function printLayerJScode($menuItems) {
1026 $script='';
1027 if ($this->isCMlayers()) { // Clipboard must not be submitted - then it's probably a copy/cut situation.
1028 $frameName = '.'.($this->listFrame ? 'list_frame' : 'nav_frame');
1029 if ($this->alwaysContentFrame) $frameName='';
1030
1031 // Create the table displayed in the clickmenu layer:
1032 $CMtable = '
1033 <table border="0" cellpadding="0" cellspacing="0" class="typo3-CSM bgColor4">
1034 '.implode('',$this->menuItemsForClickMenu($menuItems)).'
1035 </table>';
1036
1037 // Wrap the inner table in another table to create outer border:
1038 $CMtable = $this->wrapColorTableCM($CMtable);
1039
1040 // Set back path place holder to real back path
1041 $CMtable = str_replace($this->PH_backPath,$this->backPath,$CMtable);
1042 if($this->ajax) {
1043 $innerXML = '<data><clickmenu><htmltable><![CDATA['.$CMtable.']]></htmltable><cmlevel>'.$this->cmLevel.'</cmlevel></clickmenu></data>';
1044 return $innerXML;
1045 } else {
1046 // Create JavaScript section:
1047 $script=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
1048
1049 if (top.content && top.content'.$frameName.' && top.content'.$frameName.'.setLayerObj) {
1050 top.content'.$frameName.'.setLayerObj(unescape("'.t3lib_div::rawurlencodeJS($CMtable).'"),'.$this->cmLevel.');
1051 }
1052 '.(!$this->doDisplayTopFrameCM()?'hideCM();':'')
1053 );
1054 return $script;
1055 }
1056 }
1057 }
1058
1059 /**
1060 * Wrapping the input string in a table with background color 4 and a black border style.
1061 * For the pop-up menu
1062 *
1063 * @param string HTML content to wrap in table.
1064 * @return string
1065 */
1066 function wrapColorTableCM($str) {
1067
1068 // Clear-gifs needed if opera is to set the table row height correctly in skins.
1069 $str = '<table border="0" cellspacing="0" class="typo3-CSM-wrapperCM">
1070 <tr class="c-rowA">
1071 <td class="c-aa">'.$str.'</td>
1072 <td class="c-ab"></td>
1073 </tr>
1074 <tr class="c-rowB">
1075 <td class="c-ba"><img src="clear.gif" width="1" height="1" alt="" /></td>
1076 <td class="c-bb"><img src="clear.gif" width="1" height="1" alt="" /></td>
1077 </tr>
1078 </table>';
1079 return $str;
1080 }
1081
1082 /**
1083 * Traverses the menuItems and generates an output array for implosion in the topframe horizontal menu
1084 *
1085 * @param array $menuItem array
1086 * @param array Array with HTML content to be imploded between <td>-tags
1087 * @return array Array of menu items for top frame.
1088 */
1089 function menuItemsForTopFrame($menuItems) {
1090 reset($menuItems);
1091 $out=array();
1092 while(list(,$i)=each($menuItems)) {
1093 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)
1094 if (is_array($i) && !$i[4]) $out[]=$i[0];
1095 }
1096 return $out;
1097 }
1098
1099 /**
1100 * Traverses the menuItems and generates an output array for implosion in the CM div-layers table.
1101 *
1102 * @param array $menuItem array
1103 * @param array Array with HTML content to be imploded between <td>-tags
1104 * @return array array for implosion in the CM div-layers table.
1105 */
1106 function menuItemsForClickMenu($menuItems) {
1107 reset($menuItems);
1108 $out=array();
1109 while(list($cc,$i)=each($menuItems)) {
1110 if (is_string($i) && $i=='spacer') { // MAKE horizontal spacer
1111 $out[]='
1112 <tr class="bgColor2">
1113 <td colspan="2"><img src="clear.gif" width="1" height="1" alt="" /></td>
1114 </tr>';
1115 } else { // Just make normal element:
1116 $onClick=$i[3];
1117 $onClick=eregi_replace('return[[:space:]]+hideCM\(\)[[:space:]]*;','',$onClick);
1118 $onClick=eregi_replace('return[[:space:]]+false[[:space:]]*;','',$onClick);
1119 $onClick=eregi_replace('hideCM\(\);','',$onClick);
1120 if (!$i[5]) $onClick.='hideEmpty();';
1121
1122 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
1123 $CSM = ' oncontextmenu="'.htmlspecialchars($onClick).';return false;"';
1124 }
1125
1126 $out[]='
1127 <tr class="typo3-CSM-itemRow" onclick="'.htmlspecialchars($onClick).'" onmouseover="this.bgColor=\''.$GLOBALS['TBE_TEMPLATE']->bgColor5.'\';" onmouseout="this.bgColor=\'\';"'.$CSM.'>
1128 '.(!$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>').'
1129 </tr>';
1130 }
1131 }
1132 return $out;
1133 }
1134
1135 /**
1136 * Adds or inserts a menu item
1137 * 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.
1138 *
1139 * @param array Menu items array
1140 * @param array Menu items array to insert
1141 * @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.
1142 * @return array Menu items array, processed.
1143 */
1144 function addMenuItems($menuItems,$newMenuItems,$position='') {
1145 if (is_array($newMenuItems)) {
1146
1147 if($position) {
1148
1149 $posArr = t3lib_div::trimExplode(',', $position, 1);
1150 foreach($posArr as $pos) {
1151 list($place,$menuEntry) = t3lib_div::trimExplode(':', $pos, 1);
1152 list($place,$placeExtra) = t3lib_div::trimExplode('-', $place, 1);
1153
1154 // bottom
1155 $pointer = count($menuItems);
1156
1157 $found=FALSE;
1158
1159 if ($place) {
1160 switch(strtolower($place)) {
1161 case 'after':
1162 case 'before':
1163 if ($menuEntry) {
1164 $p=1;
1165 reset ($menuItems);
1166 while (true) {
1167 if (!strcmp(key($menuItems), $menuEntry)) {
1168 $pointer = $p;
1169 $found=TRUE;
1170 break;
1171 }
1172 if (!next($menuItems)) break;
1173 $p++;
1174 }
1175 if (!$found) break;
1176
1177 if ($place=='before') {
1178 $pointer--;
1179 if ($placeExtra=='spacer' AND prev($menuItems)=='spacer') {
1180 $pointer--;
1181 }
1182 } elseif ($place=='after') {
1183 if ($placeExtra=='spacer' AND next($menuItems)=='spacer') {
1184 $pointer++;
1185 }
1186 }
1187 }
1188 break;
1189 default:
1190 if (strtolower($place)=='top') {
1191 $pointer = 0;
1192 } else {
1193 $pointer = count($menuItems);
1194 }
1195 $found=TRUE;
1196 break;
1197 }
1198 }
1199 if($found) break;
1200 }
1201 }
1202 $pointer=max(0,$pointer);
1203 $menuItemsBefore = array_slice($menuItems, 0, ($pointer?$pointer:0));
1204 $menuItemsAfter = array_slice($menuItems, $pointer);
1205 $menuItems = $menuItemsBefore + $newMenuItems + $menuItemsAfter;
1206 }
1207 return $menuItems;
1208 }
1209
1210 /**
1211 * Creating an array with various elements for the clickmenu entry
1212 *
1213 * @param string The label, htmlspecialchar'ed already
1214 * @param string <img>-tag for the icon
1215 * @param string JavaScript onclick event for label/icon
1216 * @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)
1217 * @param boolean If set, the clickmenu layer will not hide itself onclick - used for secondary menus to appear...
1218 * @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!
1219 */
1220 function linkItem($str,$icon,$onClick,$onlyCM=0,$dontHide=0) {
1221 $this->elCount++;
1222 if($this->ajax) {
1223 $onClick = str_replace('top.loadTopMenu', 'showClickmenu_raw', $onClick);
1224 }
1225
1226 $WHattribs = t3lib_iconWorks::skinImg($BACK_PATH,'gfx/content_client.gif','width="7" height="10"',2);
1227
1228 return array(
1229 '<img src="clear.gif" '.$WHattribs.' class="c-roimg" name="roimg_'.$this->elCount.'" alt="" />'.
1230 '<a href="#" onclick="'.htmlspecialchars($onClick).'" onmouseover="mo('.$this->elCount.');" onmouseout="mout('.$this->elCount.');">'.
1231 $str.$icon.
1232 '</a>',
1233 $str,
1234 $icon,
1235 $onClick,
1236 $onlyCM,
1237 $dontHide
1238 );
1239 }
1240
1241 /**
1242 * Returns the input string IF not a user setting has disabled display of icons.
1243 *
1244 * @param string The icon-image tag
1245 * @return string The icon-image tag prefixed with space char IF the icon should be printed at all due to user settings
1246 */
1247 function excludeIcon($iconCode) {
1248 return ($GLOBALS['BE_USER']->uc['noMenuMode'] && strcmp($GLOBALS['BE_USER']->uc['noMenuMode'],'icons')) ? '' : ' '.$iconCode;
1249 }
1250
1251 /**
1252 * Enabling / Disabling items based on list provided from GET var ($this->iParts[3])
1253 *
1254 * @param array Menu items array
1255 * @return array Menu items array, processed.
1256 */
1257 function enableDisableItems($menuItems) {
1258 if ($this->iParts[3]) {
1259
1260 // Detect "only" mode: (only showing listed items)
1261 if (substr($this->iParts[3],0,1)=='+') {
1262 $this->iParts[3] = substr($this->iParts[3],1);
1263 $only = TRUE;
1264 } else {
1265 $only = FALSE;
1266 }
1267
1268 // Do filtering:
1269 if ($only) { // Transfer ONLY elements which are mentioned (or are spacers)
1270 $newMenuArray = array();
1271 foreach($menuItems as $key => $value) {
1272 if (t3lib_div::inList($this->iParts[3], $key) || (is_string($value) && $value=='spacer')) {
1273 $newMenuArray[$key] = $value;
1274 }
1275 }
1276 $menuItems = $newMenuArray;
1277 } else { // Traverse all elements except those listed (just unsetting them):
1278 $elements = t3lib_div::trimExplode(',',$this->iParts[3],1);
1279 foreach($elements as $value) {
1280 unset($menuItems[$value]);
1281 }
1282 }
1283 }
1284
1285 // Return processed menu items:
1286 return $menuItems;
1287 }
1288
1289 /**
1290 * Clean up spacers; Will remove any spacers in the start/end of menu items array plus any duplicates.
1291 *
1292 * @param array Menu items array
1293 * @return array Menu items array, processed.
1294 */
1295 function cleanUpSpacers($menuItems) {
1296
1297 // Remove doubles:
1298 $prevItemWasSpacer = FALSE;
1299 foreach($menuItems as $key => $value) {
1300 if (is_string($value) && $value=='spacer') {
1301 if ($prevItemWasSpacer) {
1302 unset($menuItems[$key]);
1303 }
1304 $prevItemWasSpacer = TRUE;
1305 } else {
1306 $prevItemWasSpacer = FALSE;
1307 }
1308 }
1309
1310 // Remove first:
1311 reset($menuItems);
1312 $key = key($menuItems);
1313 $value = current($menuItems);
1314 if (is_string($value) && $value=='spacer') {
1315 unset($menuItems[$key]);
1316 }
1317
1318
1319 // Remove last:
1320 end($menuItems);
1321 $key = key($menuItems);
1322 $value = current($menuItems);
1323 if (is_string($value) && $value=='spacer') {
1324 unset($menuItems[$key]);
1325 }
1326
1327 // Return processed menu items:
1328 return $menuItems;
1329 }
1330
1331 /**
1332 * Get label from locallang_core.php:cm.*
1333 *
1334 * @param string The "cm."-suffix to get.
1335 * @return string
1336 */
1337 function label($label) {
1338 return $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.'.$label,1));
1339 }
1340
1341 /**
1342 * Returns true if there should be writing to the div-layers (commands sent to clipboard MUST NOT write to div-layers)
1343 *
1344 * @return boolean
1345 */
1346 function isCMlayers() {
1347 if($this->ajax) {
1348 return !$this->CB;
1349 } else {
1350 return $GLOBALS['SOBE']->doc->isCMlayers() && !$this->CB;
1351 }
1352 }
1353
1354 /**
1355 * Appends ".location" to input string
1356 *
1357 * @param string Input string, probably a JavaScript document reference
1358 * @return string
1359 */
1360 function frameLocation($str) {
1361 return $str.'.location';
1362 }
1363 }
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377 /**
1378 * Script Class for the Context Sensitive Menu in TYPO3 (rendered in top frame, normally writing content dynamically to list frames).
1379 *
1380 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
1381 * @package TYPO3
1382 * @subpackage core
1383 * @see template::getContextMenuCode()
1384 */
1385 class SC_alt_clickmenu {
1386
1387 // Internal, static: GPvar:
1388 var $backPath; // Back path.
1389 var $item; // Definition of which item the click menu should be made for.
1390 var $reloadListFrame; // Defines the name of the document object for which to reload the URL.
1391
1392 // Internal:
1393 var $content=''; // Content accumulation
1394 var $doc; // Template object
1395 var $include_once=array(); // Files to include_once() - set in init() function
1396 var $extClassArray=array(); // Internal array of classes for extending the clickmenu
1397 var $dontDisplayTopFrameCM=0; // If set, then the clickmenu will NOT display in the top frame.
1398
1399 /**
1400 * Constructor function for script class.
1401 *
1402 * @return void
1403 */
1404 function init() {
1405 global $BE_USER,$BACK_PATH;
1406
1407 // Setting GPvars:
1408 $this->backPath = t3lib_div::_GP('backPath');
1409 $this->item = t3lib_div::_GP('item');
1410 $this->reloadListFrame = t3lib_div::_GP('reloadListFrame');
1411
1412 // Setting pseudo module name
1413 $this->MCONF['name']='xMOD_alt_clickmenu.php';
1414
1415 // 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:
1416 $inputBP = explode('|',$this->backPath);
1417 if (count($inputBP)==2 && $inputBP[1]==t3lib_div::shortMD5($inputBP[0].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
1418 $this->backPath = $inputBP[0];
1419 } else {
1420 $this->backPath = $BACK_PATH;
1421 }
1422
1423 // Setting internal array of classes for extending the clickmenu:
1424 $this->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses'];
1425
1426 // Traversing that array and setting files for inclusion:
1427 if (is_array($this->extClassArray)) {
1428 foreach($this->extClassArray as $extClassConf) {
1429 if ($extClassConf['path']) $this->include_once[]=$extClassConf['path'];
1430 }
1431 }
1432
1433 // Initialize template object
1434 if(!$this->ajax) {
1435 $this->doc = t3lib_div::makeInstance('template');
1436 $this->doc->docType='xhtml_trans';
1437 $this->doc->backPath = $BACK_PATH;
1438 }
1439
1440 // Setting mode for display and background image in the top frame
1441 $this->dontDisplayTopFrameCM= $this->doc->isCMlayers() && !$BE_USER->getTSConfigVal('options.contextMenu.options.alwaysShowClickMenuInTopFrame');
1442 if ($this->dontDisplayTopFrameCM) {
1443 $this->doc->bodyTagId.= '-notop';
1444 }
1445
1446 // Setting clickmenu timeout
1447 $secs = t3lib_div::intInRange($BE_USER->getTSConfigVal('options.contextMenu.options.clickMenuTimeOut'),1,100,5); // default is 5
1448
1449 // Setting the JavaScript controlling the timer on the page
1450 $listFrameDoc = $this->reloadListFrame!=2 ? 'top.content.list_frame' : 'top.content';
1451 $this->doc->JScode.=$this->doc->wrapScriptTags('
1452 var date = new Date();
1453 var mo_timeout = Math.floor(date.getTime()/1000);
1454
1455 roImg =new Image();
1456 roImg.src = "'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/content_client.gif','width="7" height="10"',1).'";
1457
1458 routImg =new Image();
1459 routImg.src = "clear.gif";
1460
1461 function mo(c) { //
1462 var name="roimg_"+c;
1463 document[name].src = roImg.src;
1464 updateTime();
1465 }
1466 function mout(c) { //
1467 var name="roimg_"+c;
1468 document[name].src = routImg.src;
1469 updateTime();
1470 }
1471 function updateTime() { //
1472 date = new Date();
1473 mo_timeout = Math.floor(date.getTime()/1000);
1474 }
1475 function timeout_func() { //
1476 date = new Date();
1477 if (Math.floor(date.getTime()/1000)-mo_timeout > '.$secs.') {
1478 hideCM();
1479 return false;
1480 } else {
1481 window.setTimeout("timeout_func();",1*1000);
1482 }
1483 }
1484 function hideCM() { //
1485 document.location="alt_topmenu_dummy.php";
1486 return false;
1487 }
1488
1489 // Start timer
1490 timeout_func();
1491
1492 '.($this->reloadListFrame ? '
1493 // Reload list frame:
1494 if('.$listFrameDoc.'){'.$listFrameDoc.'.document.location='.$listFrameDoc.'.document.location;}' :
1495 '').'
1496 ');
1497 }
1498
1499 /**
1500 * Main function - generating the click menu in whatever form it has.
1501 *
1502 * @return void
1503 */
1504 function main() {
1505
1506 $this->ajax = t3lib_div::_GP('ajax')?TRUE:FALSE;
1507
1508 // Initialize Clipboard object:
1509 $clipObj = t3lib_div::makeInstance('t3lib_clipboard');
1510 $clipObj->initializeClipboard();
1511 $clipObj->lockToNormal(); // This locks the clipboard to the Normal for this request.
1512
1513 // Update clipboard if some actions are sent.
1514 $CB = t3lib_div::_GET('CB');
1515 $clipObj->setCmd($CB);
1516 $clipObj->cleanCurrent();
1517 $clipObj->endClipboard(); // Saves
1518
1519 // Create clickmenu object
1520 $clickMenu = t3lib_div::makeInstance('clickMenu');
1521
1522 // Set internal vars in clickmenu object:
1523 $clickMenu->clipObj = $clipObj;
1524 $clickMenu->extClassArray = $this->extClassArray;
1525 $clickMenu->dontDisplayTopFrameCM = $this->dontDisplayTopFrameCM;
1526 $clickMenu->backPath = $this->backPath;
1527
1528 // Start page
1529 if(!$this->ajax) {
1530 $this->content.=$this->doc->startPage('Context Sensitive Menu');
1531 }
1532 // Set content of the clickmenu with the incoming var, "item"
1533 $this->content.= $clickMenu->init();
1534 }
1535
1536 /**
1537 * End page and output content.
1538 *
1539 * @return void
1540 */
1541 function printContent() {
1542 if(!$this->ajax) {
1543 $this->content.= $this->doc->endPage();
1544 echo $this->content;
1545 } else {
1546 t3lib_ajax::outputXMLreply($this->content);
1547 }
1548 }
1549 }
1550
1551 // Include extension?
1552 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php']) {
1553 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php']);
1554 }
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565 // Make instance:
1566 $SOBE = t3lib_div::makeInstance('SC_alt_clickmenu');
1567 $SOBE->init();
1568
1569 // Include files?
1570 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
1571
1572 $SOBE->main();
1573 $SOBE->printContent();
1574 ?>