[BUGFIX] Fix 4 CGL viol.: LogicalOperatorSpacing*
[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)) continue;
319 }
320 }
321
322 if ($this->editSC && $row['uid']==$this->editSC) {
323 $this->editSC_rec=$row;
324 }
325
326 $sc_group = $row['sc_group'];
327 if ($sc_group && strcmp($formerGr,$sc_group)) {
328 if ($sc_group!=-100) {
329 if ($this->groupLabels[abs($sc_group)] && strcmp('1',$this->groupLabels[abs($sc_group)])) {
330 $label = $this->groupLabels[abs($sc_group)];
331 } else {
332 $label = $GLOBALS['LANG']->getLL('shortcut_group_'.abs($sc_group),1);
333 if (!$label) $label = $GLOBALS['LANG']->getLL('shortcut_group',1).' '.abs($sc_group); // Fallback label
334 }
335
336 if ($sc_group>=0) {
337 $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->getLL('bookmark_delAllInCat')).')){window.location.href=\'alt_shortcut.php?deleteCategory='.$sc_group.'\';}return false;';
338 $this->linesPre[]='<td>&nbsp;</td><td class="bgColor5"><a href="#" onclick="'.htmlspecialchars($onC).'" title="'.$GLOBALS['LANG']->getLL('bookmark_delAllInCat',1).'">'.$label.'</a></td>';
339 } else {
340 $label = $GLOBALS['LANG']->getLL('bookmark_global',1).': '.($label ? $label : abs($sc_group)); // Fallback label
341 $this->lines[]='<td>&nbsp;</td><td class="bgColor5">'.$label.'</td>';
342 }
343 unset($label);
344 }
345 }
346
347 $bgColorClass = $row['uid']==$this->editSC ? 'bgColor5' : ($row['sc_group']<0 ? 'bgColor6' : 'bgColor4');
348
349 if ($row['description'] && ($row['uid']!=$this->editSC)) {
350 $label = $row['description'];
351 } else {
352 $label = t3lib_div::fixed_lgd_cs(rawurldecode($qParts['query']),150);
353 }
354 $titleA = $this->itemLabel($label,$row['module_name'],$row['M_module_name']);
355
356 $editSH = ($row['sc_group']>=0 || $GLOBALS['BE_USER']->isAdmin()) ? 'editSh('.intval($row['uid']).');' : "alert('".$GLOBALS['LANG']->getLL('bookmark_onlyAdmin')."')";
357 $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
358 $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
359 if ($sc_group>=0) { // user defined groups show up first
360 $this->linesPre[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
361 } else {
362 $this->lines[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
363 }
364 if (trim($row['description'])) {
365 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
366 $this->selOpt[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['description'],50)).'</option>';
367 }
368 $formerGr=$row['sc_group'];
369 }
370 ksort($this->selOpt);
371 array_unshift($this->selOpt,'<option>['.$GLOBALS['LANG']->getLL('bookmark_selSC',1).']</option>');
372
373 $this->editLoadedFunc();
374 $this->editPageIdFunc();
375
376 if (!$this->editLoaded && t3lib_extMgm::isLoaded('cms')) {
377 $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);" />'.
378 ($this->editError?'&nbsp;<strong><span class="typo3-red">'.htmlspecialchars($this->editError).'</span></strong>':'').
379 (is_array($this->theEditRec)?'&nbsp;<strong>'.$GLOBALS['LANG']->getLL('bookmark_loadEdit',1).' \''.t3lib_BEfunc::getRecordTitle('pages',$this->theEditRec,TRUE).'\'</strong> ('.htmlspecialchars($this->editPath).')':'').
380 ($this->searchFor?'&nbsp;'.$GLOBALS['LANG']->getLL('bookmark_searchFor',1).' <strong>\''.htmlspecialchars($this->searchFor).'\'</strong>':'').
381 '</td>';
382 } else $editIdCode = '';
383
384 // Adding CSH:
385 $editIdCode.= '<td>&nbsp;'.t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'bookmarks', $GLOBALS['BACK_PATH'],'',TRUE).'</td>';
386
387 // Compile it all:
388 $this->content.='
389
390 <table border="0" cellpadding="0" cellspacing="0" width="99%">
391 <tr>
392 <td>
393 <!--
394 Shortcut Display Table:
395 -->
396 <table border="0" cellpadding="0" cellspacing="2" id="typo3-shortcuts">
397 <tr>
398 ';
399 if ($GLOBALS['BE_USER']->getTSConfigVal('options.enableBookmarks')) {
400 $this->content .= implode('
401 ', $this->lines);
402 }
403 $this->content .= $editIdCode . '
404 </tr>
405 </table>
406 </td>
407 <td align="right">';
408 if ($this->hasWorkspaceAccess()) {
409 $this->content .= $this->workspaceSelector() .
410 t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'workspaceSelector', $GLOBALS['BACK_PATH'],'',TRUE);
411 }
412 $this->content .= '
413 </td>
414 </tr>
415 </table>
416 ';
417
418 // Launch Edit page:
419 if ($this->theEditRec['uid']) {
420 $this->content.=$this->doc->wrapScriptTags('top.loadEditId('.$this->theEditRec['uid'].');');
421
422 }
423
424 // Load alternative table/uid into editing form.
425 if (count($this->alternativeTableUid)==2 && isset($GLOBALS['TCA'][$this->alternativeTableUid[0]]) && t3lib_utility_Math::canBeInterpretedAsInteger($this->alternativeTableUid[1])) {
426 $JSaction = t3lib_BEfunc::editOnClick('&edit['.$this->alternativeTableUid[0].']['.$this->alternativeTableUid[1].']=edit','','dummy.php');
427 $this->content.=$this->doc->wrapScriptTags('function editArbitraryElement() { top.content.'.$JSaction.'; } editArbitraryElement();');
428 }
429
430 // Load search for something.
431 if ($this->searchFor) {
432 $urlParameters = array();
433 $urlParameters['id'] = intval($GLOBALS['WEBMOUNTS'][0]);
434 $urlParameters['search_field'] = $this->searchFor;
435 $urlParameters['search_levels'] = 4;
436 $this->content .= $this->doc->wrapScriptTags('jump(unescape("' .
437 rawurlencode(t3lib_BEfunc::getModuleUrl('web_list', $urlParameters, '')) .
438 '"), "web_list", "web");');
439 }
440 }
441
442 /**
443 * Creates lines for the editing form.
444 *
445 * @return void
446 */
447 function editLoadedFunc() {
448 $this->editLoaded=0;
449 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.
450 $this->editLoaded=1;
451
452 $opt=array();
453 $opt[]='<option value="0"></option>';
454
455 foreach($this->groupLabels as $k=>$v) {
456 if ($v && strcmp('1',$v)) {
457 $label = $v;
458 } else {
459 $label = $GLOBALS['LANG']->getLL('bookmark_group_'.$k,1);
460 if (!$label) $label = $GLOBALS['LANG']->getLL('bookmark_group',1).' '.$k; // Fallback label
461 }
462 $opt[]='<option value="'.$k.'"'.(!strcmp($this->editSC_rec['sc_group'],$k)?' selected="selected"':'').'>'.$label.'</option>';
463 }
464
465 if ($GLOBALS['BE_USER']->isAdmin()) {
466 foreach($this->groupLabels as $k=>$v) {
467 if ($v && strcmp('1',$v)) {
468 $label = $v;
469 } else {
470 $label = $GLOBALS['LANG']->getLL('bookmark_group_'.$k,1);
471 if (!$label) $label = $GLOBALS['LANG']->getLL('bookmark_group',1).' '.$k; // Fallback label
472 }
473 $label = $GLOBALS['LANG']->getLL('bookmark_global',1).': '.$label; // Add a prefix for global groups
474
475 $opt[]='<option value="-'.$k.'"'.(!strcmp($this->editSC_rec['sc_group'],'-'.$k)?' selected="selected"':'').'>'.$label.'</option>';
476 }
477 $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>';
478 }
479
480 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
481 $manageForm='
482
483 <!--
484 Shortcut Editing Form:
485 -->
486 <table border="0" cellpadding="0" cellspacing="0" id="typo3-shortcuts-editing">
487 <tr>
488 <td>&nbsp;&nbsp;</td>
489 <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>
490 <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>
491 <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>
492 <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>
493 <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec['description']).'"'.$this->doc->formWidth(15).' /></td>
494 <td><select name="editGroup">'.implode('',$opt).'</select></td>
495 </tr>
496 </table>
497 <input type="hidden" name="whichItem" value="'.$this->editSC_rec['uid'].'" />
498
499 ';
500 } else $manageForm='';
501
502 if (!$this->editLoaded && count($this->selOpt)>1) {
503 $this->lines[]='<td>&nbsp;</td>';
504 $this->lines[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt).'</select></td>';
505 }
506
507 // $this->linesPre contains elements with sc_group>=0
508 $this->lines = array_merge($this->linesPre,$this->lines);
509
510 if (count($this->lines)) {
511 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.mayNotCreateEditBookmarks')) {
512 $this->lines = array_merge(array(
513 '<td><input type="checkbox" id="editShortcut_check" name="editShortcut_check" value="1"' . ($this->editSC ? ' checked="checked"' : '') . ' />'
514 . ' <label for="editShortcut_check">' . $GLOBALS['LANG']->getLL('bookmark_edit', 1) . '</label>&nbsp;</td>'
515 ), $this->lines);
516 $this->lines[] = '<td>' . $manageForm . '</td>';
517 }
518 $this->lines[] = '<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
519 }
520 }
521
522 /**
523 * 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.
524 * Returns void
525 *
526 * @return void
527 */
528 function editPageIdFunc() {
529 if (!t3lib_extMgm::isLoaded('cms')) return;
530
531 // EDIT page:
532 $this->editPage = trim($GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet,$this->editPage,'toLower'));
533 $this->editError = '';
534 $this->theEditRec = '';
535 $this->searchFor = '';
536 if ($this->editPage) {
537
538 // First, test alternative value consisting of [table]:[uid] and if not found, proceed with traditional page ID resolve:
539 $this->alternativeTableUid = explode(':',$this->editPage);
540 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.
541
542 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2).' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
543 if (t3lib_utility_Math::canBeInterpretedAsInteger($this->editPage)) {
544 $this->theEditRec = t3lib_BEfunc::getRecordWSOL('pages',$this->editPage,'*',$where);
545 } else {
546 $records = t3lib_BEfunc::getRecordsByField('pages','alias',$this->editPage,$where);
547 if (is_array($records)) {
548 $this->theEditRec = reset($records);
549 t3lib_BEfunc::workspaceOL('pages',$this->theEditRec);
550 }
551 }
552 if (!is_array($this->theEditRec)) {
553 unset($this->theEditRec);
554 $this->searchFor = $this->editPage;
555 } elseif (!$GLOBALS['BE_USER']->isInWebMount($this->theEditRec['uid'])) {
556 unset($this->theEditRec);
557 $this->editError=$GLOBALS['LANG']->getLL('bookmark_notEditable');
558 } else {
559
560 // Visual path set:
561 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
562 $this->editPath = t3lib_BEfunc::getRecordPath($this->theEditRec['pid'], $perms_clause, 30);
563
564 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.bookmark_onEditId_dontSetPageTree')) {
565 $bookmarkKeepExpanded = $GLOBALS['BE_USER']->getTSConfigVal('options.bookmark_onEditId_keepExistingExpanded');
566
567 // Expanding page tree:
568 t3lib_BEfunc::openPageTree($this->theEditRec['pid'], !$bookmarkKeepExpanded);
569 }
570 }
571 }
572 }
573 }
574
575 /**
576 * Outputting the accumulated content to screen
577 *
578 * @return void
579 */
580 function printContent() {
581 $content = '';
582
583 $this->content.= $this->doc->endPage();
584 $this->content = $this->doc->insertStylesAndJS($this->content);
585
586 if($this->editPage && $this->isAjaxCall) {
587 $data = array();
588
589 // edit page
590 if($this->theEditRec['uid']) {
591 $data['type'] = 'page';
592 $data['editRecord'] = $this->theEditRec['uid'];
593 }
594
595 // edit alternative table/uid
596 if(count($this->alternativeTableUid) == 2
597 && isset($GLOBALS['TCA'][$this->alternativeTableUid[0]])
598 && t3lib_utility_Math::canBeInterpretedAsInteger($this->alternativeTableUid[1])) {
599 $data['type'] = 'alternative';
600 $data['alternativeTable'] = $this->alternativeTableUid[0];
601 $data['alternativeUid'] = $this->alternativeTableUid[1];
602 }
603
604 // search for something else
605 if($this->searchFor) {
606 $data['type'] = 'search';
607 $data['firstMountPoint'] = intval($GLOBALS['WEBMOUNTS'][0]);
608 $data['searchFor'] = $this->searchFor;
609 }
610
611 $content = json_encode($data);
612
613 header('Content-type: application/json; charset=utf-8');
614 header('X-JSON: '.$content);
615 } else {
616 $content = $this->content;
617 }
618
619 echo $content;
620 }
621
622
623
624
625
626
627
628
629
630 /***************************
631 *
632 * WORKSPACE FUNCTIONS:
633 *
634 ***************************/
635
636 /**
637 * Create selector for workspaces and change workspace if command is given to do that.
638 *
639 * @return string HTML
640 */
641 function workspaceSelector() {
642
643 // Changing workspace and if so, reloading entire backend:
644 if (strlen($this->changeWorkspace)) {
645 $GLOBALS['BE_USER']->setWorkspace($this->changeWorkspace);
646 return $this->doc->wrapScriptTags('top.location.href="'. t3lib_BEfunc::getBackendScript() . '";');
647 }
648 // Changing workspace and if so, reloading entire backend:
649 if (strlen($this->changeWorkspacePreview)) {
650 $GLOBALS['BE_USER']->setWorkspacePreview($this->changeWorkspacePreview);
651 }
652
653 // Create options array:
654 $options = array();
655 if ($GLOBALS['BE_USER']->checkWorkspace(array('uid' => 0))) {
656 $options[0] = '['.$GLOBALS['LANG']->getLL('bookmark_onlineWS').']';
657 }
658 if ($GLOBALS['BE_USER']->checkWorkspace(array('uid' => -1))) {
659 $options[-1] = '['.$GLOBALS['LANG']->getLL('bookmark_offlineWS').']';
660 }
661
662 // Add custom workspaces (selecting all, filtering by BE_USER check):
663 if (t3lib_extMgm::isLoaded('workspaces')) {
664 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
665 if (count($workspaces)) {
666 foreach ($workspaces as $rec) {
667 if ($GLOBALS['BE_USER']->checkWorkspace($rec)) {
668 $options[$rec['uid']] = $rec['uid'].': '.$rec['title'];
669 }
670 }
671 }
672 }
673
674 // Build selector box:
675 if (count($options)) {
676 foreach($options as $value => $label) {
677 $selected = ((int)$GLOBALS['BE_USER']->workspace===$value ? ' selected="selected"' : '');
678 $options[$value] = '<option value="'.htmlspecialchars($value).'"'.$selected.'>'.htmlspecialchars($label).'</option>';
679 }
680 } else {
681 $options[] = '<option value="-99">'.$GLOBALS['LANG']->getLL('bookmark_noWSfound',1).'</option>';
682 }
683
684 $selector = '';
685 // Preview:
686 if ($GLOBALS['BE_USER']->workspace!==0) {
687 $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;';
688 }
689
690 $selector.= '<a href="mod/user/ws/index.php" target="content">'.
691 t3lib_iconWorks::getSpriteIconForRecord('sys_workspace', array()).
692 '</a>';
693 if (count($options) > 1) {
694 $selector .= '<select name="_workspaceSelector" onchange="changeWorkspace(this.options[this.selectedIndex].value);">'.implode('',$options).'</select>';
695 }
696
697 return $selector;
698 }
699
700
701
702
703
704
705
706 /***************************
707 *
708 * OTHER FUNCTIONS:
709 *
710 ***************************/
711
712 /**
713 * Returns relative filename for icon.
714 *
715 * @param string Absolute filename of the icon
716 * @param string 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 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 In-label
754 * @param string Backend module name (key)
755 * @param string 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 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 ?>