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