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