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