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