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