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