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