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