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