Fixed bug #14335: Install Tool buttons have no hover state (thanks to Steffen Gebert)
[Packages/TYPO3.CMS.git] / typo3 / alt_shortcut.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Shortcut frame
29 * Appears in the bottom frame of the backend frameset.
30 * Provides links to registered shortcuts
31 * If the 'cms' extension is loaded you will also have a field for entering page id/alias which will be found/edited
32 *
33 * $Id$
34 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
35 * XHTML compliant output
36 *
37 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
38 */
39 /**
40 * [CLASS/FUNCTION INDEX of SCRIPT]
41 *
42 *
43 *
44 * 86: class SC_alt_shortcut
45 * 125: function preinit()
46 * 152: function preprocess()
47 * 234: function init()
48 * 275: function main()
49 * 452: function editLoadedFunc()
50 * 532: function editPageIdFunc()
51 * 586: function printContent()
52 *
53 * SECTION: WORKSPACE FUNCTIONS:
54 * 611: function workspaceSelector()
55 *
56 * SECTION: OTHER FUNCTIONS:
57 * 686: function mIconFilename($Ifilename,$backPath)
58 * 702: function getIcon($modName)
59 * 726: function itemLabel($inlabel,$modName,$M_modName='')
60 * 748: function getLinkedPageId($url)
61 *
62 * TOTAL FUNCTIONS: 12
63 * (This index is automatically created/updated by the extension "extdeveval")
64 *
65 */
66
67
68 require('init.php');
69 require('template.php');
70 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
71
72
73
74
75
76
77 /**
78 * Script Class for the shortcut frame, bottom frame of the backend frameset
79 *
80 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
81 * @package TYPO3
82 * @subpackage core
83 */
84 class SC_alt_shortcut {
85
86 // Internal, static: GPvar
87 var $modName;
88 var $M_modName;
89 var $URL;
90 var $editSC;
91 var $deleteCategory;
92 var $editName;
93 var $editGroup;
94 var $whichItem;
95
96 // Internal, static:
97 /**
98 * Object for backend modules, load modules-object
99 *
100 * @var t3lib_loadModules
101 */
102 var $loadModules;
103 protected $isAjaxCall;
104
105 /**
106 * Document template object
107 *
108 * @var template
109 */
110 var $doc;
111
112 // Internal, dynamic:
113 var $content; // Accumulation of output HTML (string)
114 var $lines; // Accumulation of table cells (array)
115
116 var $editLoaded; // Flag for defining whether we are editing
117 var $editError; // Can contain edit error message
118 var $editPath; // Set to the record path of the record being edited.
119 var $editSC_rec; // Holds the shortcut record when editing
120 var $theEditRec; // Page record to be edited
121 var $editPage; // Page alias or id to be edited
122 var $selOpt; // Select options.
123 var $searchFor; // Text to search for...
124 var $groupLabels=array(); // Labels of all groups. If value is 1, the system will try to find a label in the locallang array.
125
126 var $alternativeTableUid = array(); // Array with key 0/1 being table/uid of record to edit. Internally set.
127
128
129
130 /**
131 * Pre-initialization - setting input variables for storing shortcuts etc.
132 *
133 * @return void
134 */
135 function preinit() {
136 global $TBE_MODULES;
137
138 // Setting GPvars:
139 $this->isAjaxCall = (boolean) t3lib_div::_GP('ajax');
140 $this->modName = t3lib_div::_GP('modName');
141 $this->M_modName = t3lib_div::_GP('motherModName');
142 $this->URL = t3lib_div::_GP('URL');
143 $this->editSC = t3lib_div::_GP('editShortcut');
144
145 $this->deleteCategory = t3lib_div::_GP('deleteCategory');
146 $this->editPage = t3lib_div::_GP('editPage');
147 $this->changeWorkspace = t3lib_div::_GP('changeWorkspace');
148 $this->changeWorkspacePreview = t3lib_div::_GP('changeWorkspacePreview');
149 $this->editName = t3lib_div::_GP('editName');
150 $this->editGroup = t3lib_div::_GP('editGroup');
151 $this->whichItem = t3lib_div::_GP('whichItem');
152
153 // Creating modules object
154 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
155 $this->loadModules->load($TBE_MODULES);
156 }
157
158 /**
159 * Adding shortcuts, editing shortcuts etc.
160 *
161 * @return void
162 */
163 function preprocess() {
164 global $BE_USER;
165 $description = ''; // Default description
166 $url = urldecode($this->URL);
167
168 // Lookup the title of this page and use it as default description
169 $page_id = $this->getLinkedPageId($url);
170 if (t3lib_div::testInt($page_id)) {
171 if (preg_match('/\&edit\[(.*)\]\[(.*)\]=edit/',$url,$matches)) {
172 // Edit record
173 $description = ''; // TODO: Set something useful
174 } else {
175 // Page listing
176 $pageRow = t3lib_BEfunc::getRecord('pages',$page_id);
177 if (count($pageRow)) {
178 // If $page_id is an integer, set the description to the title of that page
179 $description = $pageRow['title'];
180 }
181 }
182 } else {
183 if (preg_match('/\/$/', $page_id)) {
184 // If $page_id is a string and ends with a slash, assume it is a fileadmin reference and set the description to the basename of that path
185 $description = basename($page_id);
186 }
187 }
188
189
190 // Adding a shortcut being set from another frame
191 if ($this->modName && $this->URL) {
192 $fields_values = array(
193 'userid' => $BE_USER->user['uid'],
194 'module_name' => $this->modName.'|'.$this->M_modName,
195 'url' => $this->URL,
196 'description' => $description,
197 'sorting' => $GLOBALS['EXEC_TIME'],
198 );
199 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fields_values);
200 }
201
202 // Selection-clause for users - so users can deleted only their own shortcuts (except admins)
203 $addUSERWhere = (!$BE_USER->isAdmin()?' AND userid='.intval($BE_USER->user['uid']):'');
204
205 // Deleting shortcuts:
206 if (strcmp($this->deleteCategory,'')) {
207 if (t3lib_div::testInt($this->deleteCategory)) {
208 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'sc_group='.intval($this->deleteCategory).$addUSERWhere);
209 }
210 }
211
212 // If other changes in post-vars:
213 if (is_array($_POST)) {
214 // Saving:
215 if (isset($_POST['_savedok_x']) || isset($_POST['_saveclosedok_x'])) {
216 $fields_values = array(
217 'description' => $this->editName,
218 'sc_group' => intval($this->editGroup)
219 );
220 if ($fields_values['sc_group']<0 && !$BE_USER->isAdmin()) {
221 $fields_values['sc_group']=0;
222 }
223
224 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_be_shortcuts', 'uid='.intval($this->whichItem).$addUSERWhere, $fields_values);
225 }
226 // If save without close, keep the session going...
227 if (isset($_POST['_savedok_x'])) {
228 $this->editSC=$this->whichItem;
229 }
230 // Deleting a single shortcut ?
231 if (isset($_POST['_deletedok_x'])) {
232 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'uid='.intval($this->whichItem).$addUSERWhere);
233
234 if (!$this->editSC) $this->editSC=-1; // Just to have the checkbox set...
235 }
236 }
237
238 }
239
240 /**
241 * Initialize (page output)
242 *
243 * @return void
244 */
245 function init() {
246 global $BACK_PATH;
247
248 $this->doc = t3lib_div::makeInstance('template');
249 $this->doc->backPath = $BACK_PATH;
250 $this->doc->form='<form action="alt_shortcut.php" name="shForm" method="post">';
251 $this->doc->divClass='typo3-shortcut';
252 $this->doc->JScode.=$this->doc->wrapScriptTags('
253 function jump(url,modName,mainModName) { //
254 // Clear information about which entry in nav. tree that might have been highlighted.
255 top.fsMod.navFrameHighlightedID = new Array();
256 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
257 top.content.nav_frame.refresh_nav();
258 }
259
260 top.nextLoadModuleUrl = url;
261 top.goToModule(modName);
262 }
263 function editSh(uid) { //
264 window.location.href="alt_shortcut.php?editShortcut="+uid;
265 }
266 function submitEditPage(id) { //
267 window.location.href="alt_shortcut.php?editPage="+top.rawurlencodeAndRemoveSiteUrl(id);
268 }
269 function changeWorkspace(workspaceId) { //
270 window.location.href="alt_shortcut.php?changeWorkspace="+top.rawurlencodeAndRemoveSiteUrl(workspaceId);
271 }
272 function changeWorkspacePreview(newstate) { //
273 window.location.href="alt_shortcut.php?changeWorkspacePreview="+newstate;
274 }
275 function refreshShortcuts() {
276 window.location.href = document.URL;
277 }
278
279 ');
280 $this->content.=$this->doc->startPage('Shortcut frame');
281 }
282
283 /**
284 * Main function, creating content in the frame
285 *
286 * @return void
287 */
288 function main() {
289 global $BE_USER,$LANG,$TCA;
290
291 // By default, 5 groups are set
292 $this->groupLabels=array(
293 1 => 1,
294 2 => 1,
295 3 => 1,
296 4 => 1,
297 5 => 1,
298 );
299
300 $shortCutGroups = $BE_USER->getTSConfig('options.shortcutGroups');
301 if (is_array($shortCutGroups['properties']) && count($shortCutGroups['properties'])) {
302 foreach ($shortCutGroups['properties'] as $k=>$v) {
303 if (strcmp('',$v) && strcmp('0',$v)) {
304 $this->groupLabels[$k] = (string)$v;
305 } elseif ($BE_USER->isAdmin()) {
306 unset($this->groupLabels[$k]);
307 }
308 }
309 }
310
311 // List of global groups that will be loaded. All global groups have negative IDs.
312 $globalGroups = -100; // Group -100 is kind of superglobal and can't be changed.
313 if (count($this->groupLabels)) {
314 $globalGroups .= ','.implode(',',array_keys($this->groupLabels));
315 $globalGroups = str_replace(',',',-',$globalGroups); // Ugly hack to make the UIDs negative - is there any better solution?
316 }
317
318 // Fetching shortcuts to display for this user:
319 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_be_shortcuts', '((userid='.$BE_USER->user['uid'].' AND sc_group>=0) OR sc_group IN ('.$globalGroups.'))', '', 'sc_group,sorting');
320
321 // Init vars:
322 $this->lines=array();
323 $this->linesPre=array();
324 $this->editSC_rec='';
325 $this->selOpt=array();
326 $formerGr='';
327
328 // Traverse shortcuts
329 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
330 $mParts = explode('|',$row['module_name']);
331 $row['module_name']=$mParts[0];
332 $row['M_module_name']=$mParts[1];
333 $mParts = explode('_',$row['M_module_name']?$row['M_module_name']:$row['module_name']);
334 $qParts = parse_url($row['url']);
335
336 if (!$BE_USER->isAdmin()) {
337 // Check for module access
338 if (!isset($LANG->moduleLabels['tabs_images'][implode('_',$mParts).'_tab'])) { // Nice hack to check if the user has access to this module - otherwise the translation label would not have been loaded :-)
339 continue;
340 }
341
342 $page_id = $this->getLinkedPageId($row['url']);
343 if (t3lib_div::testInt($page_id)) {
344 // Check for webmount access
345 if (!$GLOBALS['BE_USER']->isInWebMount($page_id)) continue;
346
347 // Check for record access
348 $pageRow = t3lib_BEfunc::getRecord('pages',$page_id);
349 if (!$GLOBALS['BE_USER']->doesUserHaveAccess($pageRow,$perms=1)) continue;
350 }
351 }
352
353 if ($this->editSC && $row['uid']==$this->editSC) {
354 $this->editSC_rec=$row;
355 }
356
357 $sc_group = $row['sc_group'];
358 if ($sc_group && strcmp($formerGr,$sc_group)) {
359 if ($sc_group!=-100) {
360 if ($this->groupLabels[abs($sc_group)] && strcmp('1',$this->groupLabels[abs($sc_group)])) {
361 $label = $this->groupLabels[abs($sc_group)];
362 } else {
363 $label = $LANG->getLL('shortcut_group_'.abs($sc_group),1);
364 if (!$label) $label = $LANG->getLL('shortcut_group',1).' '.abs($sc_group); // Fallback label
365 }
366
367 if ($sc_group>=0) {
368 $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL('shortcut_delAllInCat')).')){window.location.href=\'alt_shortcut.php?deleteCategory='.$sc_group.'\';}return false;';
369 $this->linesPre[]='<td>&nbsp;</td><td class="bgColor5"><a href="#" onclick="'.htmlspecialchars($onC).'" title="'.$LANG->getLL('shortcut_delAllInCat',1).'">'.$label.'</a></td>';
370 } else {
371 $label = $LANG->getLL('shortcut_global',1).': '.($label ? $label : abs($sc_group)); // Fallback label
372 $this->lines[]='<td>&nbsp;</td><td class="bgColor5">'.$label.'</td>';
373 }
374 unset($label);
375 }
376 }
377
378 $bgColorClass = $row['uid']==$this->editSC ? 'bgColor5' : ($row['sc_group']<0 ? 'bgColor6' : 'bgColor4');
379
380 if ($row['description']&&($row['uid']!=$this->editSC)) {
381 $label = $row['description'];
382 } else {
383 $label = t3lib_div::fixed_lgd_cs(rawurldecode($qParts['query']),150);
384 }
385 $titleA = $this->itemLabel($label,$row['module_name'],$row['M_module_name']);
386
387 $editSH = ($row['sc_group']>=0 || $BE_USER->isAdmin()) ? 'editSh('.intval($row['uid']).');' : "alert('".$LANG->getLL('shortcut_onlyAdmin')."')";
388 $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
389 $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
390 if ($sc_group>=0) { // user defined groups show up first
391 $this->linesPre[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
392 } else {
393 $this->lines[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
394 }
395 if (trim($row['description'])) {
396 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
397 $this->selOpt[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['description'],50)).'</option>';
398 }
399 $formerGr=$row['sc_group'];
400 }
401 ksort($this->selOpt);
402 array_unshift($this->selOpt,'<option>['.$LANG->getLL('shortcut_selSC',1).']</option>');
403
404 $this->editLoadedFunc();
405 $this->editPageIdFunc();
406
407 if (!$this->editLoaded && t3lib_extMgm::isLoaded('cms')) {
408 $editIdCode = '<td nowrap="nowrap">'.$LANG->getLL('shortcut_editID',1).': <input type="text" value="'.($this->editError?htmlspecialchars($this->editPage):'').'" name="editPage"'.$this->doc->formWidth(15).' onchange="submitEditPage(this.value);" />'.
409 ($this->editError?'&nbsp;<strong><span class="typo3-red">'.htmlspecialchars($this->editError).'</span></strong>':'').
410 (is_array($this->theEditRec)?'&nbsp;<strong>'.$LANG->getLL('shortcut_loadEdit',1).' \''.t3lib_BEfunc::getRecordTitle('pages',$this->theEditRec,TRUE).'\'</strong> ('.htmlspecialchars($this->editPath).')':'').
411 ($this->searchFor?'&nbsp;'.$LANG->getLL('shortcut_searchFor',1).' <strong>\''.htmlspecialchars($this->searchFor).'\'</strong>':'').
412 '</td>';
413 } else $editIdCode = '';
414
415 // Adding CSH:
416 $editIdCode.= '<td>&nbsp;'.t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'shortcuts', $GLOBALS['BACK_PATH'],'',TRUE).'</td>';
417
418 // Compile it all:
419 $this->content.='
420
421 <table border="0" cellpadding="0" cellspacing="0" width="99%">
422 <tr>
423 <td>
424 <!--
425 Shortcut Display Table:
426 -->
427 <table border="0" cellpadding="0" cellspacing="2" id="typo3-shortcuts">
428 <tr>
429 ';
430 if ($GLOBALS['BE_USER']->getTSConfigVal('options.enableShortcuts')) {
431 $this->content .= implode('
432 ', $this->lines);
433 }
434 $this->content .= $editIdCode . '
435 </tr>
436 </table>
437 </td>
438 <td align="right">';
439 if ($this->hasWorkspaceAccess()) {
440 $this->content .= $this->workspaceSelector() .
441 t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'workspaceSelector', $GLOBALS['BACK_PATH'],'',TRUE);
442 }
443 $this->content .= '
444 </td>
445 </tr>
446 </table>
447 ';
448
449 // Launch Edit page:
450 if ($this->theEditRec['uid']) {
451 $this->content.=$this->doc->wrapScriptTags('top.loadEditId('.$this->theEditRec['uid'].');');
452
453 }
454
455 // Load alternative table/uid into editing form.
456 if (count($this->alternativeTableUid)==2 && isset($TCA[$this->alternativeTableUid[0]]) && t3lib_div::testInt($this->alternativeTableUid[1])) {
457 $JSaction = t3lib_BEfunc::editOnClick('&edit['.$this->alternativeTableUid[0].']['.$this->alternativeTableUid[1].']=edit','','dummy.php');
458 $this->content.=$this->doc->wrapScriptTags('function editArbitraryElement() { top.content.'.$JSaction.'; } editArbitraryElement();');
459 }
460
461 // Load search for something.
462 if ($this->searchFor) {
463 $firstMP = intval($GLOBALS['WEBMOUNTS'][0]);
464 $this->content.= $this->doc->wrapScriptTags('jump(unescape("'.rawurlencode('db_list.php?id='.$firstMP.'&search_field='.rawurlencode($this->searchFor).'&search_levels=4').'"),"web_list","web");');
465 }
466 }
467
468 /**
469 * Creates lines for the editing form.
470 *
471 * @return void
472 */
473 function editLoadedFunc() {
474 global $BE_USER,$LANG;
475
476 $this->editLoaded=0;
477 if (is_array($this->editSC_rec) && ($this->editSC_rec['sc_group']>=0 || $BE_USER->isAdmin())) { // sc_group numbers below 0 requires admin to edit those. sc_group numbers above zero must always be owned by the user himself.
478 $this->editLoaded=1;
479
480 $opt=array();
481 $opt[]='<option value="0"></option>';
482
483 foreach($this->groupLabels as $k=>$v) {
484 if ($v && strcmp('1',$v)) {
485 $label = $v;
486 } else {
487 $label = $LANG->getLL('shortcut_group_'.$k,1);
488 if (!$label) $label = $LANG->getLL('shortcut_group',1).' '.$k; // Fallback label
489 }
490 $opt[]='<option value="'.$k.'"'.(!strcmp($this->editSC_rec['sc_group'],$k)?' selected="selected"':'').'>'.$label.'</option>';
491 }
492
493 if ($BE_USER->isAdmin()) {
494 foreach($this->groupLabels as $k=>$v) {
495 if ($v && strcmp('1',$v)) {
496 $label = $v;
497 } else {
498 $label = $LANG->getLL('shortcut_group_'.$k,1);
499 if (!$label) $label = $LANG->getLL('shortcut_group',1).' '.$k; // Fallback label
500 }
501 $label = $LANG->getLL('shortcut_global',1).': '.$label; // Add a prefix for global groups
502
503 $opt[]='<option value="-'.$k.'"'.(!strcmp($this->editSC_rec['sc_group'],'-'.$k)?' selected="selected"':'').'>'.$label.'</option>';
504 }
505 $opt[]='<option value="-100"'.(!strcmp($this->editSC_rec['sc_group'],'-100')?' selected="selected"':'').'>'.$LANG->getLL('shortcut_global',1).': '.$LANG->getLL('shortcut_all',1).'</option>';
506 }
507
508 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
509 $manageForm='
510
511 <!--
512 Shortcut Editing Form:
513 -->
514 <table border="0" cellpadding="0" cellspacing="0" id="typo3-shortcuts-editing">
515 <tr>
516 <td>&nbsp;&nbsp;</td>
517 <td><input type="image" class="c-inputButton" name="_savedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedok.gif','').' title="'.$LANG->getLL('shortcut_save',1).'" /></td>
518 <td><input type="image" class="c-inputButton" name="_saveclosedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/saveandclosedok.gif','').' title="'.$LANG->getLL('shortcut_saveClose',1).'" /></td>
519 <td><input type="image" class="c-inputButton" name="_closedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/closedok.gif','').' title="'.$LANG->getLL('shortcut_close',1).'" /></td>
520 <td><input type="image" class="c-inputButton" name="_deletedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/deletedok.gif','').' title="'.$LANG->getLL('shortcut_delete',1).'" /></td>
521 <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec['description']).'"'.$this->doc->formWidth(15).' /></td>
522 <td><select name="editGroup">'.implode('',$opt).'</select></td>
523 </tr>
524 </table>
525 <input type="hidden" name="whichItem" value="'.$this->editSC_rec['uid'].'" />
526
527 ';
528 } else $manageForm='';
529
530 if (!$this->editLoaded && count($this->selOpt)>1) {
531 $this->lines[]='<td>&nbsp;</td>';
532 $this->lines[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt).'</select></td>';
533 }
534
535 // $this->linesPre contains elements with sc_group>=0
536 $this->lines = array_merge($this->linesPre,$this->lines);
537
538 if (count($this->lines)) {
539 if (!$BE_USER->getTSConfigVal('options.mayNotCreateEditShortcuts')) {
540 $this->lines=array_merge(array('<td><input type="checkbox" id="editShortcut_check" name="editShortcut_check" value="1"'.($this->editSC?' checked="checked"':'').' /> <label for="editShortcut_check">'.$LANG->getLL('shortcut_edit',1).'</label>&nbsp;</td>'),$this->lines);
541 $this->lines[]='<td>'.$manageForm.'</td>';
542 }
543 $this->lines[]='<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
544 }
545 }
546
547 /**
548 * If "editPage" value is sent to script and it points to an accessible page, the internal var $this->theEditRec is set to the page record which should be loaded.
549 * Returns void
550 *
551 * @return void
552 */
553 function editPageIdFunc() {
554 global $BE_USER,$LANG;
555
556 if (!t3lib_extMgm::isLoaded('cms')) return;
557
558 // EDIT page:
559 $this->editPage = trim($LANG->csConvObj->conv_case($LANG->charSet,$this->editPage,'toLower'));
560 $this->editError = '';
561 $this->theEditRec = '';
562 $this->searchFor = '';
563 if ($this->editPage) {
564
565 // First, test alternative value consisting of [table]:[uid] and if not found, proceed with traditional page ID resolve:
566 $this->alternativeTableUid = explode(':',$this->editPage);
567 if (!(count($this->alternativeTableUid)==2 && $BE_USER->isAdmin())) { // We restrict it to admins only just because I'm not really sure if alt_doc.php properly checks permissions of passed records for editing. If alt_doc.php does that, then we can remove this.
568
569 $where = ' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
570 if (t3lib_div::testInt($this->editPage)) {
571 $this->theEditRec = t3lib_BEfunc::getRecordWSOL('pages',$this->editPage,'*',$where);
572 } else {
573 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$this->editPage,$where);
574 if (is_array($records)) {
575 reset($records);
576 $this->theEditRec = current($records);
577 t3lib_BEfunc::workspaceOL('pages',$this->theEditRec);
578 }
579 }
580 if (!is_array($this->theEditRec)) {
581 unset($this->theEditRec);
582 $this->searchFor = $this->editPage;
583 } elseif (!$BE_USER->isInWebMount($this->theEditRec['uid'])) {
584 unset($this->theEditRec);
585 $this->editError=$LANG->getLL('shortcut_notEditable');
586 } else {
587
588 // Visual path set:
589 $perms_clause = $BE_USER->getPagePermsClause(1);
590 $this->editPath = t3lib_BEfunc::getRecordPath($this->theEditRec['pid'], $perms_clause, 30);
591
592 if(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
593
594 // Expanding page tree:
595 t3lib_BEfunc::openPageTree($this->theEditRec['pid'],!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
596 }
597 }
598 }
599 }
600 }
601
602 /**
603 * Outputting the accumulated content to screen
604 *
605 * @return void
606 */
607 function printContent() {
608 $content = '';
609
610 $this->content.= $this->doc->endPage();
611 $this->content = $this->doc->insertStylesAndJS($this->content);
612
613 if($this->editPage && $this->isAjaxCall) {
614 $data = array();
615
616 // edit page
617 if($this->theEditRec['uid']) {
618 $data['type'] = 'page';
619 $data['editRecord'] = $this->theEditRec['uid'];
620 }
621
622 // edit alternative table/uid
623 if(count($this->alternativeTableUid) == 2
624 && isset($GLOBALS['TCA'][$this->alternativeTableUid[0]])
625 && t3lib_div::testInt($this->alternativeTableUid[1])) {
626 $data['type'] = 'alternative';
627 $data['alternativeTable'] = $this->alternativeTableUid[0];
628 $data['alternativeUid'] = $this->alternativeTableUid[1];
629 }
630
631 // search for something else
632 if($this->searchFor) {
633 $data['type'] = 'search';
634 $data['firstMountPoint'] = intval($GLOBALS['WEBMOUNTS'][0]);
635 $data['searchFor'] = rawurlencode($this->searchFor);
636 }
637
638 $content = json_encode($data);
639
640 header('Content-type: application/json; charset=utf-8');
641 header('X-JSON: '.$content);
642 } else {
643 $content = $this->content;
644 }
645
646 echo $content;
647 }
648
649
650
651
652
653
654
655
656
657 /***************************
658 *
659 * WORKSPACE FUNCTIONS:
660 *
661 ***************************/
662
663 /**
664 * Create selector for workspaces and change workspace if command is given to do that.
665 *
666 * @return string HTML
667 */
668 function workspaceSelector() {
669 global $TYPO3_DB,$BE_USER,$LANG;
670
671 // Changing workspace and if so, reloading entire backend:
672 if (strlen($this->changeWorkspace)) {
673 $BE_USER->setWorkspace($this->changeWorkspace);
674 return $this->doc->wrapScriptTags('top.location.href="'. t3lib_BEfunc::getBackendScript() . '";');
675 }
676 // Changing workspace and if so, reloading entire backend:
677 if (strlen($this->changeWorkspacePreview)) {
678 $BE_USER->setWorkspacePreview($this->changeWorkspacePreview);
679 }
680
681 // Create options array:
682 $options = array();
683 if ($BE_USER->checkWorkspace(array('uid' => 0))) {
684 $options[0] = '['.$LANG->getLL('shortcut_onlineWS').']';
685 }
686 if ($BE_USER->checkWorkspace(array('uid' => -1))) {
687 $options[-1] = '['.$LANG->getLL('shortcut_offlineWS').']';
688 }
689
690 // Add custom workspaces (selecting all, filtering by BE_USER check):
691 $workspaces = $TYPO3_DB->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
692 if (count($workspaces)) {
693 foreach ($workspaces as $rec) {
694 if ($BE_USER->checkWorkspace($rec)) {
695 $options[$rec['uid']] = $rec['uid'].': '.$rec['title'];
696 }
697 }
698 }
699
700 // Build selector box:
701 if (count($options)) {
702 foreach($options as $value => $label) {
703 $selected = ((int)$BE_USER->workspace===$value ? ' selected="selected"' : '');
704 $options[$value] = '<option value="'.htmlspecialchars($value).'"'.$selected.'>'.htmlspecialchars($label).'</option>';
705 }
706 } else {
707 $options[] = '<option value="-99">'.$LANG->getLL('shortcut_noWSfound',1).'</option>';
708 }
709
710 $selector = '';
711 // Preview:
712 if ($BE_USER->workspace!==0) {
713 $selector.= '<label for="workspacePreview">Frontend Preview:</label> <input type="checkbox" name="workspacePreview" id="workspacePreview" onclick="changeWorkspacePreview('.($BE_USER->user['workspace_preview'] ? 0 : 1).')"; '.($BE_USER->user['workspace_preview'] ? 'checked="checked"' : '').'/>&nbsp;';
714 }
715
716 $selector.= '<a href="mod/user/ws/index.php" target="content">'.
717 t3lib_iconWorks::getIconImage('sys_workspace',array(),$this->doc->backPath,'align="top"').
718 '</a>';
719 if (count($options) > 1) {
720 $selector .= '<select name="_workspaceSelector" onchange="changeWorkspace(this.options[this.selectedIndex].value);">'.implode('',$options).'</select>';
721 }
722
723 return $selector;
724 }
725
726
727
728
729
730
731
732 /***************************
733 *
734 * OTHER FUNCTIONS:
735 *
736 ***************************/
737
738 /**
739 * Returns relative filename for icon.
740 *
741 * @param string Absolute filename of the icon
742 * @param string Backpath string to prepend the icon after made relative
743 * @return void
744 */
745 function mIconFilename($Ifilename,$backPath) {
746 // Change icon of fileadmin references - otherwise it doesn't differ with Web->List
747 $Ifilename = str_replace ('mod/file/list/list.gif', 'mod/file/file.gif', $Ifilename);
748
749 if (t3lib_div::isAbsPath($Ifilename)) {
750 $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
751 }
752 return $backPath.$Ifilename;
753 }
754
755 /**
756 * Returns icon for shortcut display
757 *
758 * @param string Backend module name
759 * @return string Icon file name
760 */
761 function getIcon($modName) {
762 global $LANG;
763 if ($LANG->moduleLabels['tabs_images'][$modName.'_tab']) {
764 $icon = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$modName.'_tab'],'');
765 } elseif ($modName=='xMOD_alt_doc.php') {
766 $icon = 'gfx/edit2.gif';
767 } elseif ($modName=='xMOD_file_edit.php') {
768 $icon = 'gfx/edit_file.gif';
769 } elseif ($modName=='xMOD_wizard_rte.php') {
770 $icon = 'gfx/edit_rtewiz.gif';
771 } else {
772 $icon = 'gfx/dummy_module.gif';
773 }
774 return $icon;
775 }
776
777 /**
778 * Returns title-label for icon
779 *
780 * @param string In-label
781 * @param string Backend module name (key)
782 * @param string Backend module label (user defined?)
783 * @return string Label for the shortcut item
784 */
785 function itemLabel($inlabel,$modName,$M_modName='') {
786 global $LANG;
787 if (substr($modName,0,5)=='xMOD_') {
788 $label=substr($modName,5);
789 } else {
790 $split = explode('_',$modName);
791 $label = $LANG->moduleLabels['tabs'][$split[0].'_tab'];
792 if (count($split)>1) {
793 $label.='>'.$LANG->moduleLabels['tabs'][$modName.'_tab'];
794 }
795 }
796 if ($M_modName) $label.=' ('.$M_modName.')';
797 $label.=': '.$inlabel;
798 return $label;
799 }
800
801 /**
802 * Return the ID of the page in the URL if found.
803 *
804 * @param string The URL of the current shortcut link
805 * @return string If a page ID was found, it is returned. Otherwise: 0
806 */
807 function getLinkedPageId($url) {
808 return preg_replace('/.*[\?&]id=([^&]+).*/', '$1', $url);
809 }
810
811 /**
812 * Checks if user has access to Workspace module.
813 *
814 * @return boolean Returns true if user has access to workspace module.
815 */
816 function hasWorkspaceAccess() {
817 $MCONF = array();
818 include('mod/user/ws/conf.php');
819 return $GLOBALS['BE_USER']->modAccess(array('name' => 'user', 'access' => 'user,group'), false) && $GLOBALS['BE_USER']->modAccess($MCONF, false);
820 }
821 }
822
823
824 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']) {
825 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']);
826 }
827
828
829
830 // Make instance:
831 $SOBE = t3lib_div::makeInstance('SC_alt_shortcut');
832 $SOBE->preinit();
833 $SOBE->preprocess();
834 $SOBE->init();
835 $SOBE->main();
836 $SOBE->printContent();
837
838 ?>