Changed private declarations to protected
[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->docType='xhtml_trans';
254 $this->doc->divClass='typo3-shortcut';
255 $this->doc->JScode.=$this->doc->wrapScriptTags('
256 function jump(url,modName,mainModName) { //
257 // Clear information about which entry in nav. tree that might have been highlighted.
258 top.fsMod.navFrameHighlightedID = new Array();
259 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
260 top.content.nav_frame.refresh_nav();
261 }
262
263 top.nextLoadModuleUrl = url;
264 top.goToModule(modName);
265 }
266 function editSh(uid) { //
267 window.location.href="alt_shortcut.php?editShortcut="+uid;
268 }
269 function submitEditPage(id) { //
270 window.location.href="alt_shortcut.php?editPage="+top.rawurlencode(id);
271 }
272 function changeWorkspace(workspaceId) { //
273 window.location.href="alt_shortcut.php?changeWorkspace="+top.rawurlencode(workspaceId);
274 }
275 function changeWorkspacePreview(newstate) { //
276 window.location.href="alt_shortcut.php?changeWorkspacePreview="+newstate;
277 }
278 function refreshShortcuts() {
279 window.location.href = document.URL;
280 }
281
282 ');
283 $this->content.=$this->doc->startPage('Shortcut frame');
284 }
285
286 /**
287 * Main function, creating content in the frame
288 *
289 * @return void
290 */
291 function main() {
292 global $BE_USER,$LANG,$TCA;
293
294 // By default, 5 groups are set
295 $this->groupLabels=array(
296 1 => 1,
297 2 => 1,
298 3 => 1,
299 4 => 1,
300 5 => 1,
301 );
302
303 $shortCutGroups = $BE_USER->getTSConfig('options.shortcutGroups');
304 if (is_array($shortCutGroups['properties']) && count($shortCutGroups['properties'])) {
305 foreach ($shortCutGroups['properties'] as $k=>$v) {
306 if (strcmp('',$v) && strcmp('0',$v)) {
307 $this->groupLabels[$k] = (string)$v;
308 } elseif ($BE_USER->isAdmin()) {
309 unset($this->groupLabels[$k]);
310 }
311 }
312 }
313
314 // List of global groups that will be loaded. All global groups have negative IDs.
315 $globalGroups = -100; // Group -100 is kind of superglobal and can't be changed.
316 if (count($this->groupLabels)) {
317 $globalGroups .= ','.implode(',',array_keys($this->groupLabels));
318 $globalGroups = str_replace(',',',-',$globalGroups); // Ugly hack to make the UIDs negative - is there any better solution?
319 }
320
321 // Fetching shortcuts to display for this user:
322 $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');
323
324 // Init vars:
325 $this->lines=array();
326 $this->linesPre=array();
327 $this->editSC_rec='';
328 $this->selOpt=array();
329 $formerGr='';
330
331 // Traverse shortcuts
332 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
333 $mParts = explode('|',$row['module_name']);
334 $row['module_name']=$mParts[0];
335 $row['M_module_name']=$mParts[1];
336 $mParts = explode('_',$row['M_module_name']?$row['M_module_name']:$row['module_name']);
337 $qParts = parse_url($row['url']);
338
339 if (!$BE_USER->isAdmin()) {
340 // Check for module access
341 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 :-)
342 continue;
343 }
344
345 $page_id = $this->getLinkedPageId($row['url']);
346 if (t3lib_div::testInt($page_id)) {
347 // Check for webmount access
348 if (!$GLOBALS['BE_USER']->isInWebMount($page_id)) continue;
349
350 // Check for record access
351 $pageRow = t3lib_BEfunc::getRecord('pages',$page_id);
352 if (!$GLOBALS['BE_USER']->doesUserHaveAccess($pageRow,$perms=1)) continue;
353 }
354 }
355
356 if ($this->editSC && $row['uid']==$this->editSC) {
357 $this->editSC_rec=$row;
358 }
359
360 $sc_group = $row['sc_group'];
361 if ($sc_group && strcmp($formerGr,$sc_group)) {
362 if ($sc_group!=-100) {
363 if ($this->groupLabels[abs($sc_group)] && strcmp('1',$this->groupLabels[abs($sc_group)])) {
364 $label = $this->groupLabels[abs($sc_group)];
365 } else {
366 $label = $LANG->getLL('shortcut_group_'.abs($sc_group),1);
367 if (!$label) $label = $LANG->getLL('shortcut_group',1).' '.abs($sc_group); // Fallback label
368 }
369
370 if ($sc_group>=0) {
371 $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL('shortcut_delAllInCat')).')){window.location.href=\'alt_shortcut.php?deleteCategory='.$sc_group.'\';}return false;';
372 $this->linesPre[]='<td>&nbsp;</td><td class="bgColor5"><a href="#" onclick="'.htmlspecialchars($onC).'" title="'.$LANG->getLL('shortcut_delAllInCat',1).'">'.$label.'</a></td>';
373 } else {
374 $label = $LANG->getLL('shortcut_global',1).': '.($label ? $label : abs($sc_group)); // Fallback label
375 $this->lines[]='<td>&nbsp;</td><td class="bgColor5">'.$label.'</td>';
376 }
377 unset($label);
378 }
379 }
380
381 $bgColorClass = $row['uid']==$this->editSC ? 'bgColor5' : ($row['sc_group']<0 ? 'bgColor6' : 'bgColor4');
382
383 if ($row['description']&&($row['uid']!=$this->editSC)) {
384 $label = $row['description'];
385 } else {
386 $label = t3lib_div::fixed_lgd(rawurldecode($qParts['query']),150);
387 }
388 $titleA = $this->itemLabel($label,$row['module_name'],$row['M_module_name']);
389
390 $editSH = ($row['sc_group']>=0 || $BE_USER->isAdmin()) ? 'editSh('.intval($row['uid']).');' : "alert('".$LANG->getLL('shortcut_onlyAdmin')."')";
391 $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
392 $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
393 if ($sc_group>=0) { // user defined groups show up first
394 $this->linesPre[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
395 } else {
396 $this->lines[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
397 }
398 if (trim($row['description'])) {
399 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
400 $this->selOpt[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['description'],50)).'</option>';
401 }
402 $formerGr=$row['sc_group'];
403 }
404 ksort($this->selOpt);
405 array_unshift($this->selOpt,'<option>['.$LANG->getLL('shortcut_selSC',1).']</option>');
406
407 $this->editLoadedFunc();
408 $this->editPageIdFunc();
409
410 if (!$this->editLoaded && t3lib_extMgm::isLoaded('cms')) {
411 $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);" />'.
412 ($this->editError?'&nbsp;<strong><span class="typo3-red">'.htmlspecialchars($this->editError).'</span></strong>':'').
413 (is_array($this->theEditRec)?'&nbsp;<strong>'.$LANG->getLL('shortcut_loadEdit',1).' \''.t3lib_BEfunc::getRecordTitle('pages',$this->theEditRec,TRUE).'\'</strong> ('.htmlspecialchars($this->editPath).')':'').
414 ($this->searchFor?'&nbsp;'.$LANG->getLL('shortcut_searchFor',1).' <strong>\''.htmlspecialchars($this->searchFor).'\'</strong>':'').
415 '</td>';
416 } else $editIdCode = '';
417
418 // Adding CSH:
419 $editIdCode.= '<td>&nbsp;'.t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'shortcuts', $GLOBALS['BACK_PATH'],'',TRUE).'</td>';
420
421 // Compile it all:
422 $this->content.='
423
424 <table border="0" cellpadding="0" cellspacing="0" width="99%">
425 <tr>
426 <td>
427 <!--
428 Shortcut Display Table:
429 -->
430 <table border="0" cellpadding="0" cellspacing="2" id="typo3-shortcuts">
431 <tr>
432 '.implode('
433 ',$this->lines).$editIdCode.'
434 </tr>
435 </table>
436 </td>
437 <td align="right">';
438 if ($this->hasWorkspaceAccess()) {
439 $this->content .= $this->workspaceSelector() .
440 t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'workspaceSelector', $GLOBALS['BACK_PATH'],'',TRUE);
441 }
442 $this->content .= '
443 </td>
444 </tr>
445 </table>
446 ';
447
448 // Launch Edit page:
449 if ($this->theEditRec['uid']) {
450 $this->content.=$this->doc->wrapScriptTags('top.loadEditId('.$this->theEditRec['uid'].');');
451
452 }
453
454 // Load alternative table/uid into editing form.
455 if (count($this->alternativeTableUid)==2 && isset($TCA[$this->alternativeTableUid[0]]) && t3lib_div::testInt($this->alternativeTableUid[1])) {
456 $JSaction = t3lib_BEfunc::editOnClick('&edit['.$this->alternativeTableUid[0].']['.$this->alternativeTableUid[1].']=edit','','dummy.php');
457 $this->content.=$this->doc->wrapScriptTags('function editArbitraryElement() { top.content.'.$JSaction.'; } editArbitraryElement();');
458 }
459
460 // Load search for something.
461 if ($this->searchFor) {
462 $firstMP = intval($GLOBALS['WEBMOUNTS'][0]);
463 $this->content.= $this->doc->wrapScriptTags('jump(unescape("'.rawurlencode('db_list.php?id='.$firstMP.'&search_field='.rawurlencode($this->searchFor).'&search_levels=4').'"),"web_list","web");');
464 }
465 }
466
467 /**
468 * Creates lines for the editing form.
469 *
470 * @return void
471 */
472 function editLoadedFunc() {
473 global $BE_USER,$LANG;
474
475 $this->editLoaded=0;
476 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.
477 $this->editLoaded=1;
478
479 $opt=array();
480 $opt[]='<option value="0"></option>';
481
482 foreach($this->groupLabels as $k=>$v) {
483 if ($v && strcmp('1',$v)) {
484 $label = $v;
485 } else {
486 $label = $LANG->getLL('shortcut_group_'.$k,1);
487 if (!$label) $label = $LANG->getLL('shortcut_group',1).' '.$k; // Fallback label
488 }
489 $opt[]='<option value="'.$k.'"'.(!strcmp($this->editSC_rec['sc_group'],$k)?' selected="selected"':'').'>'.$label.'</option>';
490 }
491
492 if ($BE_USER->isAdmin()) {
493 foreach($this->groupLabels as $k=>$v) {
494 if ($v && strcmp('1',$v)) {
495 $label = $v;
496 } else {
497 $label = $LANG->getLL('shortcut_group_'.$k,1);
498 if (!$label) $label = $LANG->getLL('shortcut_group',1).' '.$k; // Fallback label
499 }
500 $label = $LANG->getLL('shortcut_global',1).': '.$label; // Add a prefix for global groups
501
502 $opt[]='<option value="-'.$k.'"'.(!strcmp($this->editSC_rec['sc_group'],'-'.$k)?' selected="selected"':'').'>'.$label.'</option>';
503 }
504 $opt[]='<option value="-100"'.(!strcmp($this->editSC_rec['sc_group'],'-100')?' selected="selected"':'').'>'.$LANG->getLL('shortcut_global',1).': '.$LANG->getLL('shortcut_all',1).'</option>';
505 }
506
507 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
508 $manageForm='
509
510 <!--
511 Shortcut Editing Form:
512 -->
513 <table border="0" cellpadding="0" cellspacing="0" id="typo3-shortcuts-editing">
514 <tr>
515 <td>&nbsp;&nbsp;</td>
516 <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>
517 <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>
518 <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>
519 <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>
520 <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec['description']).'"'.$this->doc->formWidth(15).' /></td>
521 <td><select name="editGroup">'.implode('',$opt).'</select></td>
522 </tr>
523 </table>
524 <input type="hidden" name="whichItem" value="'.$this->editSC_rec['uid'].'" />
525
526 ';
527 } else $manageForm='';
528
529 if (!$this->editLoaded && count($this->selOpt)>1) {
530 $this->lines[]='<td>&nbsp;</td>';
531 $this->lines[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt).'</select></td>';
532 }
533
534 // $this->linesPre contains elements with sc_group>=0
535 $this->lines = array_merge($this->linesPre,$this->lines);
536
537 if (count($this->lines)) {
538 if (!$BE_USER->getTSConfigVal('options.mayNotCreateEditShortcuts')) {
539 $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);
540 $this->lines[]='<td>'.$manageForm.'</td>';
541 }
542 $this->lines[]='<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
543 }
544 }
545
546 /**
547 * 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.
548 * Returns void
549 *
550 * @return void
551 */
552 function editPageIdFunc() {
553 global $BE_USER,$LANG;
554
555 if (!t3lib_extMgm::isLoaded('cms')) return;
556
557 // EDIT page:
558 $this->editPage = trim($LANG->csConvObj->conv_case($LANG->charSet,$this->editPage,'toLower'));
559 $this->editError = '';
560 $this->theEditRec = '';
561 $this->searchFor = '';
562 if ($this->editPage) {
563
564 // First, test alternative value consisting of [table]:[uid] and if not found, proceed with traditional page ID resolve:
565 $this->alternativeTableUid = explode(':',$this->editPage);
566 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.
567
568 $where = ' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
569 if (t3lib_div::testInt($this->editPage)) {
570 $this->theEditRec = t3lib_BEfunc::getRecordWSOL('pages',$this->editPage,'*',$where);
571 } else {
572 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$this->editPage,$where);
573 if (is_array($records)) {
574 reset($records);
575 $this->theEditRec = current($records);
576 t3lib_BEfunc::workspaceOL('pages',$this->theEditRec);
577 }
578 }
579 if (!is_array($this->theEditRec)) {
580 unset($this->theEditRec);
581 $this->searchFor = $this->editPage;
582 } elseif (!$BE_USER->isInWebMount($this->theEditRec['uid'])) {
583 unset($this->theEditRec);
584 $this->editError=$LANG->getLL('shortcut_notEditable');
585 } else {
586
587 // Visual path set:
588 $perms_clause = $BE_USER->getPagePermsClause(1);
589 $this->editPath = t3lib_BEfunc::getRecordPath($this->theEditRec['pid'], $perms_clause, 30);
590
591 if(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
592
593 // Expanding page tree:
594 t3lib_BEfunc::openPageTree($this->theEditRec['pid'],!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
595 }
596 }
597 }
598 }
599 }
600
601 /**
602 * Outputting the accumulated content to screen
603 *
604 * @return void
605 */
606 function printContent() {
607 $content = '';
608
609 $this->content.= $this->doc->endPage();
610 $this->content = $this->doc->insertStylesAndJS($this->content);
611
612 if($this->editPage && $this->isAjaxCall) {
613 require_once('contrib/json/json.php');
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 $json = new Services_JSON();
639 $content = $json->encode($data);
640
641 header('Content-type: application/json; charset=utf-8');
642 header('X-JSON: '.$content);
643 } else {
644 $content = $this->content;
645 }
646
647 echo $content;
648 }
649
650
651
652
653
654
655
656
657
658 /***************************
659 *
660 * WORKSPACE FUNCTIONS:
661 *
662 ***************************/
663
664 /**
665 * Create selector for workspaces and change workspace if command is given to do that.
666 *
667 * @return string HTML
668 */
669 function workspaceSelector() {
670 global $TYPO3_DB,$BE_USER,$LANG;
671
672 // Changing workspace and if so, reloading entire backend:
673 if (strlen($this->changeWorkspace)) {
674 $BE_USER->setWorkspace($this->changeWorkspace);
675 return $this->doc->wrapScriptTags('top.location.href="'. t3lib_BEfunc::getBackendScript() . '";');
676 }
677 // Changing workspace and if so, reloading entire backend:
678 if (strlen($this->changeWorkspacePreview)) {
679 $BE_USER->setWorkspacePreview($this->changeWorkspacePreview);
680 }
681
682 // Create options array:
683 $options = array();
684 if ($BE_USER->checkWorkspace(array('uid' => 0))) {
685 $options[0] = '['.$LANG->getLL('shortcut_onlineWS').']';
686 }
687 if ($BE_USER->checkWorkspace(array('uid' => -1))) {
688 $options[-1] = '['.$LANG->getLL('shortcut_offlineWS').']';
689 }
690
691 // Add custom workspaces (selecting all, filtering by BE_USER check):
692 $workspaces = $TYPO3_DB->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
693 if (count($workspaces)) {
694 foreach ($workspaces as $rec) {
695 if ($BE_USER->checkWorkspace($rec)) {
696 $options[$rec['uid']] = $rec['uid'].': '.$rec['title'];
697 }
698 }
699 }
700
701 // Build selector box:
702 if (count($options)) {
703 foreach($options as $value => $label) {
704 $selected = ((int)$BE_USER->workspace===$value ? ' selected="selected"' : '');
705 $options[$value] = '<option value="'.htmlspecialchars($value).'"'.$selected.'>'.htmlspecialchars($label).'</option>';
706 }
707 } else {
708 $options[] = '<option value="-99">'.$LANG->getLL('shortcut_noWSfound',1).'</option>';
709 }
710
711 $selector = '';
712 // Preview:
713 if ($BE_USER->workspace!==0) {
714 $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;';
715 }
716
717 $selector.= '<a href="mod/user/ws/index.php" target="content">'.
718 t3lib_iconWorks::getIconImage('sys_workspace',array(),$this->doc->backPath,'align="top"').
719 '</a>';
720 if (count($options) > 1) {
721 $selector .= '<select name="_workspaceSelector" onchange="changeWorkspace(this.options[this.selectedIndex].value);">'.implode('',$options).'</select>';
722 }
723
724 return $selector;
725 }
726
727
728
729
730
731
732
733 /***************************
734 *
735 * OTHER FUNCTIONS:
736 *
737 ***************************/
738
739 /**
740 * Returns relative filename for icon.
741 *
742 * @param string Absolute filename of the icon
743 * @param string Backpath string to prepend the icon after made relative
744 * @return void
745 */
746 function mIconFilename($Ifilename,$backPath) {
747 // Change icon of fileadmin references - otherwise it doesn't differ with Web->List
748 $Ifilename = str_replace ('mod/file/list/list.gif', 'mod/file/file.gif', $Ifilename);
749
750 if (t3lib_div::isAbsPath($Ifilename)) {
751 $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
752 }
753 return $backPath.$Ifilename;
754 }
755
756 /**
757 * Returns icon for shortcut display
758 *
759 * @param string Backend module name
760 * @return string Icon file name
761 */
762 function getIcon($modName) {
763 global $LANG;
764 if ($LANG->moduleLabels['tabs_images'][$modName.'_tab']) {
765 $icon = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$modName.'_tab'],'');
766 } elseif ($modName=='xMOD_alt_doc.php') {
767 $icon = 'gfx/edit2.gif';
768 } elseif ($modName=='xMOD_file_edit.php') {
769 $icon = 'gfx/edit_file.gif';
770 } elseif ($modName=='xMOD_wizard_rte.php') {
771 $icon = 'gfx/edit_rtewiz.gif';
772 } else {
773 $icon = 'gfx/dummy_module.gif';
774 }
775 return $icon;
776 }
777
778 /**
779 * Returns title-label for icon
780 *
781 * @param string In-label
782 * @param string Backend module name (key)
783 * @param string Backend module label (user defined?)
784 * @return string Label for the shortcut item
785 */
786 function itemLabel($inlabel,$modName,$M_modName='') {
787 global $LANG;
788 if (substr($modName,0,5)=='xMOD_') {
789 $label=substr($modName,5);
790 } else {
791 $split = explode('_',$modName);
792 $label = $LANG->moduleLabels['tabs'][$split[0].'_tab'];
793 if (count($split)>1) {
794 $label.='>'.$LANG->moduleLabels['tabs'][$modName.'_tab'];
795 }
796 }
797 if ($M_modName) $label.=' ('.$M_modName.')';
798 $label.=': '.$inlabel;
799 return $label;
800 }
801
802 /**
803 * Return the ID of the page in the URL if found.
804 *
805 * @param string The URL of the current shortcut link
806 * @return string If a page ID was found, it is returned. Otherwise: 0
807 */
808 function getLinkedPageId($url) {
809 return preg_replace('/.*[\?&]id=([^&]+).*/', '$1', $url);
810 }
811
812 /**
813 * Checks if user has access to Workspace module.
814 *
815 * @return boolean Returns true if user has access to workspace module.
816 */
817 function hasWorkspaceAccess() {
818 $MCONF = array();
819 include('mod/user/ws/conf.php');
820 return $GLOBALS['BE_USER']->modAccess(array('name' => 'user', 'access' => 'user,group'), false) && $GLOBALS['BE_USER']->modAccess($MCONF, false);
821 }
822 }
823
824 // Include extension?
825 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']) {
826 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']);
827 }
828
829
830
831
832
833
834
835
836
837
838
839 // Make instance:
840 $SOBE = t3lib_div::makeInstance('SC_alt_shortcut');
841 $SOBE->preinit();
842 $SOBE->preprocess();
843 $SOBE->init();
844 $SOBE->main();
845 $SOBE->printContent();
846 ?>