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