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