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