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