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