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