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