* Fixed various things in file processing, t3lib_extFileFunc et al.
[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.php');
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[]='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[]='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') : (TYPO3_mainDir.'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 hide/unhide of the input record
663 *
664 * @param string Table name
665 * @param array Record array
666 * @param string Name of the hide field
667 * @return array Item array, element in $menuItems
668 * @internal
669 */
670 function DB_hideUnhide($table,$rec,$hideField) {
671 $uid=$rec['uid'];
672 $editOnClick='';
673 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
674 $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'tce_db.php?redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'".
675 "&data[".$table.']['.$uid.']['.$hideField.']='.($rec[$hideField]?0:1).'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
676
677 return $this->linkItem(
678 $this->label(($rec[$hideField]?'un':'').'hide'),
679 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/button_'.($rec[$hideField]?'un':'').'hide.gif','width="11" height="10"').' alt="" />'),
680 $editOnClick.'return false;',
681 1
682 );
683 }
684
685 /**
686 * Adding CM element for Delete
687 *
688 * @param string Table name
689 * @param integer UID for the current record.
690 * @param array Label for including in the confirmation message, EXT:lang/locallang_core.php:mess.delete
691 * @return array Item array, element in $menuItems
692 * @internal
693 */
694 function DB_delete($table,$uid,$elInfo) {
695 $editOnClick='';
696 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
697 $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').")+'".
698 "&cmd[".$table.']['.$uid.'][delete]=1&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
699
700 return $this->linkItem(
701 $this->label('delete'),
702 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/garbage.gif','width="11" height="12"').' alt="" />'),
703 $editOnClick.'return false;'
704 );
705 }
706
707 /**
708 * Adding CM element for View Page
709 *
710 * @param integer Page uid (PID)
711 * @param string Anchor, if any
712 * @return array Item array, element in $menuItems
713 * @internal
714 */
715 function DB_view($id,$anchor='') {
716 return $this->linkItem(
717 $this->label('view'),
718 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/zoom.gif','width="12" height="12"').' alt="" />'),
719 t3lib_BEfunc::viewOnClick($id,$this->PH_backPath,t3lib_BEfunc::BEgetRootLine($id),$anchor).'return hideCM();'
720 );
721 }
722
723
724
725
726
727
728
729
730
731
732 /***************************************
733 *
734 * FILE
735 *
736 ***************************************/
737
738 /**
739 * Make 1st level clickmenu:
740 *
741 * @param string The absolute path
742 * @return string HTML content
743 */
744 function printFileClickMenu($path) {
745 $menuItems=array();
746
747 if (@file_exists($path) && t3lib_div::isAllowedAbsPath($path)) {
748 $fI = pathinfo($path);
749 $icon = is_dir($path) ? 'folder.gif' : t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
750 $size=' ('.t3lib_div::formatSize(filesize($path)).'bytes)';
751 $icon = '<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/fileicons/'.$icon,'width="18" height="16"').' class="absmiddle" title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
752
753 // edit
754 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');
755 // rename
756 if (!in_array('rename',$this->disabledItems)) $menuItems['rename']=$this->FILE_launch($path,'file_rename.php','rename','rename.gif');
757 // upload
758 if (!in_array('upload',$this->disabledItems) && is_dir($path)) $menuItems['upload']=$this->FILE_launch($path,'file_upload.php','upload','upload.gif');
759 // new
760 if (!in_array('new',$this->disabledItems) && is_dir($path)) $menuItems['new']=$this->FILE_launch($path,'file_newfolder.php','new','new_file.gif');
761 // info
762 if (!in_array('info',$this->disabledItems)) $menuItems['info']=$this->DB_info($path,'');
763
764 $menuItems[]='spacer';
765
766 // copy:
767 if (!in_array('copy',$this->disabledItems)) $menuItems['copy']=$this->FILE_copycut($path,'copy');
768 // cut:
769 if (!in_array('cut',$this->disabledItems)) $menuItems['cut']=$this->FILE_copycut($path,'cut');
770
771 // Paste:
772 $elFromAllTables = count($this->clipObj->elFromTable('_FILE'));
773 if (!in_array('paste',$this->disabledItems) && $elFromAllTables && is_dir($path)) {
774 $elArr = $this->clipObj->elFromTable('_FILE');
775 reset($elArr);
776 $selItem = current($elArr);
777 $elInfo=array(
778 basename($selItem),
779 basename($path),
780 $this->clipObj->currentMode()
781 );
782 $menuItems['pasteinto']=$this->FILE_paste($path,$selItem,$elInfo);
783 }
784
785 $menuItems[]='spacer';
786
787 // delete:
788 if (!in_array('delete',$this->disabledItems)) $menuItems['delete']=$this->FILE_delete($path);
789 }
790
791 // Adding external elements to the menuItems array
792 $menuItems = $this->processingByExtClassArray($menuItems,$path,0);
793
794 // Processing by external functions?
795 $menuItems = $this->externalProcessingOfFileMenuItems($menuItems);
796
797 // Return the printed elements:
798 return $this->printItems($menuItems,$icon.basename($path));
799 }
800
801
802 /**
803 * Processing the $menuItems array (for extension classes) (FILES)
804 *
805 * @param array $menuItems array for manipulation.
806 * @return array Processed $menuItems array
807 */
808 function externalProcessingOfFileMenuItems($menuItems) {
809 return $menuItems;
810 }
811
812 /**
813 * Multi-function for adding an entry to the $menuItems array
814 *
815 * @param string Path to the file/directory (target)
816 * @param string Script (eg. file_edit.php) to pass &target= to
817 * @param string "type" is the code which fetches the correct label for the element from "cm."
818 * @param string icon image-filename from "gfx/" (12x12 icon)
819 * @return array Item array, element in $menuItems
820 * @internal
821 */
822 function FILE_launch($path,$script,$type,$image) {
823 $loc = 'top.content'.(!$this->alwaysContentFrame?'.list_frame':'');
824
825 $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'".$script.'?target='.rawurlencode($path)."&returnUrl='+top.rawurlencode(".$this->frameLocation($loc.'.document').");}";
826
827 return $this->linkItem(
828 $this->label($type),
829 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/'.$image,'width="12" height="12"').' alt="" />'),
830 $editOnClick.'return hideCM();'
831 );
832 }
833
834 /**
835 * Returns element for copy or cut of files.
836 *
837 * @param string Path to the file/directory (target)
838 * @param string Type: "copy" or "cut"
839 * @return array Item array, element in $menuItems
840 * @internal
841 */
842 function FILE_copycut($path,$type) {
843 $table = '_FILE'; // Pseudo table name for use in the clipboard.
844 $uid = t3lib_div::shortmd5($path);
845 if ($this->clipObj->current=='normal') {
846 $isSel = $this->clipObj->isSelected($table,$uid);
847 }
848
849 $addParam = array();
850 if ($this->listFrame) {
851 $addParam['reloadListFrame'] = ($this->alwaysContentFrame ? 2 : 1);
852 }
853
854 return $this->linkItem(
855 $this->label($type),
856 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/clip_'.$type.($isSel==$type?'_h':'').'.gif','width="12" height="12"').' alt="" />'),
857 "top.loadTopMenu('".$this->clipObj->selUrlFile($path,($type=='copy'?1:0),($isSel==$type),$addParam)."');return false;"
858 );
859 }
860
861 /**
862 * Creates element for deleting of target
863 *
864 * @param string Path to the file/directory (target)
865 * @return array Item array, element in $menuItems
866 * @internal
867 */
868 function FILE_delete($path) {
869 $editOnClick='';
870 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
871 $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').")+'".
872 "&file[delete][0][data]=".rawurlencode($path).'&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
873
874 return $this->linkItem(
875 $this->label('delete'),
876 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/garbage.gif','width="11" height="12"').' alt="" />'),
877 $editOnClick.'return false;'
878 );
879 }
880
881 /**
882 * Creates element for pasting files.
883 *
884 * @param string Path to the file/directory (target)
885 * @param string target - NOT USED.
886 * @param array Various values for the labels.
887 * @return array Item array, element in $menuItems
888 * @internal
889 */
890 function FILE_paste($path,$target,$elInfo) {
891 $editOnClick='';
892 $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
893 $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])).")";
894 $editOnClick='if('.$conf.'){'.$loc.".document.location=top.TS.PATH_typo3+'".$this->clipObj->pasteUrl('_FILE',$path,0).
895 "&redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').'); hideCM();}';
896
897 return $this->linkItem(
898 $this->label('pasteinto'),
899 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/clip_pasteinto.gif','width="12" height="12"').' alt="" />'),
900 $editOnClick.'return false;'
901 );
902 }
903
904
905
906
907
908
909
910
911
912
913
914
915
916 /***************************************
917 *
918 * COMMON
919 *
920 **************************************/
921
922 /**
923 * Prints the items from input $menuItems array - both as topframe menu AND the JS section for writing to the div-layers.
924 * Of course the topframe menu will appear only if $this->doDisplayTopFrameCM() returns true
925 *
926 * @param array $menuItems array
927 * @param string HTML code for the element which was clicked - shown in the end of the horizontal menu in topframe after the close-button.
928 * @return string HTML code
929 */
930 function printItems($menuItems,$item) {
931
932 $out='';
933
934 // Enable/Disable items:
935 $menuItems = $this->enableDisableItems($menuItems);
936
937 // Clean up spacers:
938 $menuItems = $this->cleanUpSpacers($menuItems);
939
940 // Adding topframe part (horizontal clickmenu)
941 if ($this->doDisplayTopFrameCM()) {
942 $out.= '
943
944 <!--
945 Table, which contains the click menu when shown in the top frame of the backend:
946 -->
947 <table border="0" cellpadding="0" cellspacing="0" id="typo3-CSM-top">
948 <tr>
949
950 <!-- Items: -->
951 <td class="c-item">'.
952 implode('</td>
953 <td><img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/acm_spacer2.gif','width="8" height="12"').' alt="" /></td>
954 <td class="c-item">',$this->menuItemsForTopFrame($menuItems)).
955 '</td>
956
957 <!-- Close button: -->
958 <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>
959
960 <!-- The item of the clickmenu: -->
961 <td class="c-itemicon">'.$item.'</td>
962 </tr>
963 </table>
964 ';
965
966 // Set remaining BACK_PATH to blank (if any)
967 $out = str_replace($this->PH_backPath,'',$out);
968 }
969 // Adding JS part:
970 $out.=$this->printLayerJScode($menuItems);
971
972 // Return the content
973 return $out;
974 }
975
976 /**
977 * Create the JavaScript section
978 *
979 * @param array The $menuItems array to print
980 * @return string The JavaScript section which will print the content of the CM to the div-layer in the target frame.
981 */
982 function printLayerJScode($menuItems) {
983 $script='';
984 if ($this->isCMlayers()) { // Clipboard must not be submitted - then it's probably a copy/cut situation.
985 $frameName = '.'.($this->listFrame ? 'list_frame' : 'nav_frame');
986 if ($this->alwaysContentFrame) $frameName='';
987
988 // Create the table displayed in the clickmenu layer:
989 $CMtable = '
990 <table border="0" cellpadding="0" cellspacing="0" class="typo3-CSM bgColor4">
991 '.implode('',$this->menuItemsForClickMenu($menuItems)).'
992 </table>';
993
994 // Wrap the inner table in another table to create outer border:
995 $CMtable = $this->wrapColorTableCM($CMtable);
996
997 // Set back path place holder to real back path
998 $CMtable = str_replace($this->PH_backPath,$this->backPath,$CMtable);
999
1000 // Create JavaScript section:
1001 $script=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
1002
1003 if (top.content && top.content'.$frameName.' && top.content'.$frameName.'.setLayerObj) {
1004 top.content'.$frameName.'.setLayerObj(unescape("'.t3lib_div::rawurlencodeJS($CMtable).'"),'.$this->cmLevel.');
1005 }
1006 '.(!$this->doDisplayTopFrameCM()?'hideCM();':'')
1007 );
1008 }
1009
1010 return $script;
1011 }
1012
1013 /**
1014 * Wrapping the input string in a table with background color 4 and a black border style.
1015 * For the pop-up menu
1016 *
1017 * @param string HTML content to wrap in table.
1018 * @return string
1019 */
1020 function wrapColorTableCM($str) {
1021
1022 // Clear-gifs needed if opera is to set the table row height correctly in skins.
1023 $str = '<table border="0" cellspacing="0" class="typo3-CSM-wrapperCM">
1024 <tr class="c-rowA">
1025 <td class="c-aa">'.$str.'</td>
1026 <td class="c-ab"></td>
1027 </tr>
1028 <tr class="c-rowB">
1029 <td class="c-ba"><img src="clear.gif" width="1" height="1" alt="" /></td>
1030 <td class="c-bb"><img src="clear.gif" width="1" height="1" alt="" /></td>
1031 </tr>
1032 </table>';
1033 return $str;
1034 }
1035
1036 /**
1037 * Traverses the menuItems and generates an output array for implosion in the topframe horizontal menu
1038 *
1039 * @param array $menuItem array
1040 * @param array Array with HTML content to be imploded between <td>-tags
1041 * @return array Array of menu items for top frame.
1042 */
1043 function menuItemsForTopFrame($menuItems) {
1044 reset($menuItems);
1045 $out=array();
1046 while(list(,$i)=each($menuItems)) {
1047 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)
1048 if (is_array($i) && !$i[4]) $out[]=$i[0];
1049 }
1050 return $out;
1051 }
1052
1053 /**
1054 * Traverses the menuItems and generates an output array for implosion in the CM div-layers table.
1055 *
1056 * @param array $menuItem array
1057 * @param array Array with HTML content to be imploded between <td>-tags
1058 * @return array array for implosion in the CM div-layers table.
1059 */
1060 function menuItemsForClickMenu($menuItems) {
1061 reset($menuItems);
1062 $out=array();
1063 while(list($cc,$i)=each($menuItems)) {
1064 if (is_string($i) && $i=='spacer') { // MAKE horizontal spacer
1065 $out[]='
1066 <tr class="bgColor2">
1067 <td colspan="2"><img src="clear.gif" width="1" height="1" alt="" /></td>
1068 </tr>';
1069 } else { // Just make normal element:
1070 $onClick=$i[3];
1071 $onClick=eregi_replace('return[[:space:]]+hideCM\(\)[[:space:]]*;','',$onClick);
1072 $onClick=eregi_replace('return[[:space:]]+false[[:space:]]*;','',$onClick);
1073 $onClick=eregi_replace('hideCM\(\);','',$onClick);
1074 if (!$i[5]) $onClick.='hideEmpty();';
1075
1076 $out[]='
1077 <tr class="typo3-CSM-itemRow" onclick="'.htmlspecialchars($onClick).'" onmouseover="this.bgColor=\''.$GLOBALS['TBE_TEMPLATE']->bgColor5.'\';" onmouseout="this.bgColor=\'\';">
1078 '.(!$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>').'
1079 </tr>';
1080 }
1081 }
1082 return $out;
1083 }
1084
1085 /**
1086 * Creating an array with various elements for the clickmenu entry
1087 *
1088 * @param string The label, htmlspecialchar'ed already
1089 * @param string <img>-tag for the icon
1090 * @param string JavaScript onclick event for label/icon
1091 * @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)
1092 * @param boolean If set, the clickmenu layer will not hide itself onclick - used for secondary menus to appear...
1093 * @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!
1094 */
1095 function linkItem($str,$icon,$onClick,$onlyCM=0,$dontHide=0) {
1096 $this->elCount++;
1097
1098 $WHattribs = t3lib_iconWorks::skinImg($BACK_PATH,'gfx/content_client.gif','width="7" height="10"',2);
1099
1100 return array(
1101 '<img src="clear.gif" '.$WHattribs.' class="c-roimg" name="roimg_'.$this->elCount.'" alt="" />'.
1102 '<a href="#" onclick="'.htmlspecialchars($onClick).'" onmouseover="mo('.$this->elCount.');" onmouseout="mout('.$this->elCount.');">'.
1103 $str.$icon.
1104 '</a>',
1105 $str,
1106 $icon,
1107 $onClick,
1108 $onlyCM,
1109 $dontHide
1110 );
1111 }
1112
1113 /**
1114 * Returns the input string IF not a user setting has disabled display of icons.
1115 *
1116 * @param string The icon-image tag
1117 * @return string The icon-image tag prefixed with space char IF the icon should be printed at all due to user settings
1118 */
1119 function excludeIcon($iconCode) {
1120 return ($GLOBALS['BE_USER']->uc['noMenuMode'] && strcmp($GLOBALS['BE_USER']->uc['noMenuMode'],'icons')) ? '' : ' '.$iconCode;
1121 }
1122
1123 /**
1124 * Enabling / Disabling items based on list provided from GET var ($this->iParts[3])
1125 *
1126 * @param array Menu items array
1127 * @return array Menu items array, processed.
1128 */
1129 function enableDisableItems($menuItems) {
1130 if ($this->iParts[3]) {
1131
1132 // Detect "only" mode: (only showing listed items)
1133 if (substr($this->iParts[3],0,1)=='+') {
1134 $this->iParts[3] = substr($this->iParts[3],1);
1135 $only = TRUE;
1136 } else {
1137 $only = FALSE;
1138 }
1139
1140 // Do filtering:
1141 if ($only) { // Transfer ONLY elements which are mentioned (or are spacers)
1142 $newMenuArray = array();
1143 foreach($menuItems as $key => $value) {
1144 if (t3lib_div::inList($this->iParts[3], $key) || (is_string($value) && $value=='spacer')) {
1145 $newMenuArray[$key] = $value;
1146 }
1147 }
1148 $menuItems = $newMenuArray;
1149 } else { // Traverse all elements except those listed (just unsetting them):
1150 $elements = t3lib_div::trimExplode(',',$this->iParts[3],1);
1151 foreach($elements as $value) {
1152 unset($menuItems[$value]);
1153 }
1154 }
1155 }
1156
1157 // Return processed menu items:
1158 return $menuItems;
1159 }
1160
1161 /**
1162 * Clean up spacers; Will remove any spacers in the start/end of menu items array plus any duplicates.
1163 *
1164 * @param array Menu items array
1165 * @return array Menu items array, processed.
1166 */
1167 function cleanUpSpacers($menuItems) {
1168
1169 // Remove doubles:
1170 $prevItemWasSpacer = FALSE;
1171 foreach($menuItems as $key => $value) {
1172 if (is_string($value) && $value=='spacer') {
1173 if ($prevItemWasSpacer) {
1174 unset($menuItems[$key]);
1175 }
1176 $prevItemWasSpacer = TRUE;
1177 } else {
1178 $prevItemWasSpacer = FALSE;
1179 }
1180 }
1181
1182 // Remove first:
1183 reset($menuItems);
1184 $key = key($menuItems);
1185 $value = current($menuItems);
1186 if (is_string($value) && $value=='spacer') {
1187 unset($menuItems[$key]);
1188 }
1189
1190
1191 // Remove last:
1192 end($menuItems);
1193 $key = key($menuItems);
1194 $value = current($menuItems);
1195 if (is_string($value) && $value=='spacer') {
1196 unset($menuItems[$key]);
1197 }
1198
1199 // Return processed menu items:
1200 return $menuItems;
1201 }
1202
1203 /**
1204 * Get label from locallang_core.php:cm.*
1205 *
1206 * @param string The "cm."-suffix to get.
1207 * @return string
1208 */
1209 function label($label) {
1210 return $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.'.$label,1));
1211 }
1212
1213 /**
1214 * Returns true if there should be writing to the div-layers (commands sent to clipboard MUST NOT write to div-layers)
1215 *
1216 * @return boolean
1217 */
1218 function isCMlayers() {
1219 return $GLOBALS['SOBE']->doc->isCMlayers() && !$this->CB;
1220 }
1221
1222 /**
1223 * Appends ".location" to input string
1224 *
1225 * @param string Input string, probably a JavaScript document reference
1226 * @return string
1227 */
1228 function frameLocation($str) {
1229 return $str.'.location';
1230 }
1231 }
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245 /**
1246 * Script Class for the Context Sensitive Menu in TYPO3 (rendered in top frame, normally writing content dynamically to list frames).
1247 *
1248 * @author Kasper Skaarhoj <kasper@typo3.com>
1249 * @package TYPO3
1250 * @subpackage core
1251 * @see template::getContextMenuCode()
1252 */
1253 class SC_alt_clickmenu {
1254
1255 // Internal, static: GPvar:
1256 var $backPath; // Back path.
1257 var $item; // Definition of which item the click menu should be made for.
1258 var $reloadListFrame; // Defines the name of the document object for which to reload the URL.
1259
1260 // Internal:
1261 var $content=''; // Content accumulation
1262 var $doc; // Template object
1263 var $include_once=array(); // Files to include_once() - set in init() function
1264 var $extClassArray=array(); // Internal array of classes for extending the clickmenu
1265 var $dontDisplayTopFrameCM=0; // If set, then the clickmenu will NOT display in the top frame.
1266
1267 /**
1268 * Constructor function for script class.
1269 *
1270 * @return void
1271 */
1272 function init() {
1273 global $BE_USER,$BACK_PATH;
1274
1275 // Setting GPvars:
1276 $this->backPath = t3lib_div::_GP('backPath');
1277 $this->item = t3lib_div::_GP('item');
1278 $this->reloadListFrame = t3lib_div::_GP('reloadListFrame');
1279
1280 // Setting pseudo module name
1281 $this->MCONF['name']='xMOD_alt_clickmenu.php';
1282
1283 // 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:
1284 $inputBP = explode('|',$this->backPath);
1285 if (count($inputBP)==2 && $inputBP[1]==t3lib_div::shortMD5($inputBP[0].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
1286 $this->backPath = $inputBP[0];
1287 } else {
1288 $this->backPath = $BACK_PATH;
1289 }
1290
1291 // Setting internal array of classes for extending the clickmenu:
1292 $this->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses'];
1293
1294 // Traversing that array and setting files for inclusion:
1295 if (is_array($this->extClassArray)) {
1296 foreach($this->extClassArray as $extClassConf) {
1297 if ($extClassConf['path']) $this->include_once[]=$extClassConf['path'];
1298 }
1299 }
1300
1301 // Initialize template object
1302 $this->doc = t3lib_div::makeInstance('template');
1303 $this->doc->docType='xhtml_trans';
1304 $this->doc->backPath = $BACK_PATH;
1305
1306 // Setting mode for display and background image in the top frame
1307 $this->dontDisplayTopFrameCM= $this->doc->isCMlayers() && !$BE_USER->getTSConfigVal('options.contextMenu.options.alwaysShowClickMenuInTopFrame');
1308 if ($this->dontDisplayTopFrameCM) {
1309 $this->doc->bodyTagId.= '-notop';
1310 }
1311
1312 // Setting clickmenu timeout
1313 $secs = t3lib_div::intInRange($BE_USER->getTSConfigVal('options.contextMenu.options.clickMenuTimeOut'),1,100,5); // default is 5
1314
1315 // Setting the JavaScript controlling the timer on the page
1316 $listFrameDoc = $this->reloadListFrame!=2 ? 'top.content.list_frame' : 'top.content';
1317 $this->doc->JScode.=$this->doc->wrapScriptTags('
1318 var date = new Date();
1319 var mo_timeout = Math.floor(date.getTime()/1000);
1320
1321 roImg =new Image();
1322 roImg.src = "'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/content_client.gif','width="7" height="10"',1).'";
1323
1324 routImg =new Image();
1325 routImg.src = "clear.gif";
1326
1327 function mo(c) { //
1328 var name="roimg_"+c;
1329 document[name].src = roImg.src;
1330 updateTime();
1331 }
1332 function mout(c) { //
1333 var name="roimg_"+c;
1334 document[name].src = routImg.src;
1335 updateTime();
1336 }
1337 function updateTime() { //
1338 date = new Date();
1339 mo_timeout = Math.floor(date.getTime()/1000);
1340 }
1341 function timeout_func() { //
1342 date = new Date();
1343 if (Math.floor(date.getTime()/1000)-mo_timeout > '.$secs.') {
1344 hideCM();
1345 return false;
1346 } else {
1347 window.setTimeout("timeout_func();",1*1000);
1348 }
1349 }
1350 function hideCM() { //
1351 document.location="alt_topmenu_dummy.php";
1352 return false;
1353 }
1354
1355 // Start timer
1356 timeout_func();
1357
1358 '.($this->reloadListFrame ? '
1359 // Reload list frame:
1360 if('.$listFrameDoc.'){'.$listFrameDoc.'.document.location='.$listFrameDoc.'.document.location;}' :
1361 '').'
1362 ');
1363 }
1364
1365 /**
1366 * Main function - generating the click menu in whatever form it has.
1367 *
1368 * @return void
1369 */
1370 function main() {
1371
1372 // Initialize Clipboard object:
1373 $clipObj = t3lib_div::makeInstance('t3lib_clipboard');
1374 $clipObj->initializeClipboard();
1375 $clipObj->lockToNormal(); // This locks the clipboard to the Normal for this request.
1376
1377 // Update clipboard if some actions are sent.
1378 $CB = t3lib_div::_GET('CB');
1379 $clipObj->setCmd($CB);
1380 $clipObj->cleanCurrent();
1381 $clipObj->endClipboard(); // Saves
1382
1383 // Create clickmenu object
1384 $clickMenu = t3lib_div::makeInstance('clickMenu');
1385
1386 // Set internal vars in clickmenu object:
1387 $clickMenu->clipObj = $clipObj;
1388 $clickMenu->extClassArray = $this->extClassArray;
1389 $clickMenu->dontDisplayTopFrameCM = $this->dontDisplayTopFrameCM;
1390 $clickMenu->backPath = $this->backPath;
1391
1392 // Start page
1393 $this->content.=$this->doc->startPage('Context Sensitive Menu');
1394
1395 // Set content of the clickmenu with the incoming var, "item"
1396 $this->content.= $clickMenu->init($this->item);
1397 }
1398
1399 /**
1400 * End page and output content.
1401 *
1402 * @return void
1403 */
1404 function printContent() {
1405 $this->content.= $this->doc->endPage();
1406 echo $this->content;
1407 }
1408 }
1409
1410 // Include extension?
1411 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php']) {
1412 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php']);
1413 }
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424 // Make instance:
1425 $SOBE = t3lib_div::makeInstance('SC_alt_clickmenu');
1426 $SOBE->init();
1427
1428 // Include files?
1429 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
1430
1431 $SOBE->main();
1432 $SOBE->printContent();
1433 ?>