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