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