b6f443d5c376c20ed120ac6d8228294abe588363
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / Browser / ElementBrowser.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\Browser;
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 text file 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\Core\Resource\File;
31 use TYPO3\CMS\Core\Resource\Folder;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33 use TYPO3\CMS\Backend\Utility\BackendUtility;
34 use TYPO3\CMS\Backend\Utility\IconUtility;
35
36 /**
37 * class for the Element Browser window.
38 *
39 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
40 */
41 class ElementBrowser {
42
43 /**
44 * Optional instance of a record list that TBE_expandPage() should
45 * use to render the records in a page
46 *
47 * @var \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList
48 */
49 protected $recordList = NULL;
50
51 /**
52 * Current site URL (Frontend)
53 *
54 * @var string
55 * @internal
56 */
57 public $siteURL;
58
59 /**
60 * the script to link to
61 *
62 * @todo Define visibility
63 */
64 public $thisScript;
65
66 /**
67 * RTE specific TSconfig
68 *
69 * @todo Define visibility
70 */
71 public $thisConfig;
72
73 /**
74 * Target (RTE specific)
75 *
76 * @todo Define visibility
77 */
78 public $setTarget;
79
80 /**
81 * CSS Class (RTE specific)
82 *
83 * @todo Define visibility
84 */
85 public $setClass;
86
87 /**
88 * title (RTE specific)
89 *
90 * @todo Define visibility
91 */
92 public $setTitle;
93
94 /**
95 * @todo Define visibility
96 */
97 public $setParams;
98
99 /**
100 * Backend template object
101 *
102 * @todo Define visibility
103 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
104 */
105 public $doc;
106
107 /**
108 * Holds information about files
109 *
110 * @todo Define visibility
111 */
112 public $elements = array();
113
114 /**
115 * The mode determines the main kind of output from the element browser.
116 * There are these options for values: rte, db, file, filedrag, wizard.
117 * "rte" will show the link selector for the Rich Text Editor (see main_rte())
118 * "db" will allow you to browse for pages or records in the page tree (for TCEforms, see main_db())
119 * "file"/"filedrag" will allow you to browse for files or folders in the folder mounts (for TCEforms, main_file())
120 * "wizard" will allow you to browse for links (like "rte") which are passed back to TCEforms (see main_rte(1))
121 *
122 * @see main()
123 * @todo Define visibility
124 * @var string
125 */
126 public $mode;
127
128 /**
129 * Link selector action.
130 * page,file,url,mail,spec are allowed values.
131 * These are only important with the link selector function and in that case they switch
132 * between the various menu options.
133 *
134 * @todo Define visibility
135 */
136 public $act;
137
138 /**
139 * When you click a page title/expand icon to see the content of a certain page, this
140 * value will contain that value (the ID of the expanded page). If the value is NOT set,
141 * then it will be restored from the module session data (see main(), mode="db")
142 *
143 * @todo Define visibility
144 */
145 public $expandPage;
146
147 /**
148 * When you click a folder name/expand icon to see the content of a certain file folder,
149 * this value will contain that value (the path of the expanded file folder). If the
150 * value is NOT set, then it will be restored from the module session data (see main(),
151 * mode="file"/"filedrag"). Example value: "/www/htdocs/typo3/32/3dsplm/fileadmin/css/"
152 *
153 * @todo Define visibility
154 * @var string
155 */
156 public $expandFolder;
157
158 /**
159 * the folder object of a parent folder that was selected
160 *
161 * @var Folder
162 */
163 protected $selectedFolder;
164
165 /**
166 * TYPO3 Element Browser, wizard mode parameters. There is a heap of parameters there,
167 * better debug() them out if you need something... :-)
168 *
169 * @todo Define visibility
170 * @var array
171 */
172 public $P;
173
174 /**
175 * Active with TYPO3 Element Browser: Contains the name of the form field for which this window
176 * opens - thus allows us to make references back to the main window in which the form is.
177 * Example value: "data[pages][39][bodytext]|||tt_content|"
178 * or "data[tt_content][NEW3fba56fde763d][image]|||gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai|"
179 *
180 * Values:
181 * 0: form field name reference, eg. "data[tt_content][123][image]"
182 * 1: htlmArea RTE parameters: editorNo:contentTypo3Language:contentTypo3Charset
183 * 2: RTE config parameters: RTEtsConfigParams
184 * 3: allowed types. Eg. "tt_content" or "gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai"
185 * 4: IRRE uniqueness: target level object-id to perform actions/checks on, eg. "data[79][tt_address][1][<field>][<foreign_table>]"
186 * 5: IRRE uniqueness: name of function in opener window that checks if element is already used, eg. "inline.checkUniqueElement"
187 * 6: IRRE uniqueness: name of function in opener window that performs some additional(!) action, eg. "inline.setUniqueElement"
188 * 7: IRRE uniqueness: name of function in opener window that performs action instead of using addElement/insertElement, eg. "inline.importElement"
189 *
190 * $pArr = explode('|', $this->bparams);
191 * $formFieldName = $pArr[0];
192 * $allowedTablesOrFileTypes = $pArr[3];
193 *
194 * @todo Define visibility
195 * @var string
196 */
197 public $bparams;
198
199 /**
200 * Used with the Rich Text Editor.
201 * Example value: "tt_content:NEW3fba58c969f5c:bodytext:23:text:23:"
202 *
203 * @todo Define visibility
204 * @var string
205 */
206 public $RTEtsConfigParams;
207
208 /**
209 * Plus/Minus icon value. Used by the tree class to open/close notes on the trees.
210 *
211 * @todo Define visibility
212 */
213 public $PM;
214
215 /**
216 * Pointer, used when browsing a long list of records etc.
217 *
218 * @todo Define visibility
219 */
220 public $pointer;
221
222 /**
223 * Used with the link selector: Contains the GET input information about the CURRENT link
224 * in the RTE/TCEform field. This consists of "href", "target" and "title" keys.
225 * This information is passed around in links.
226 *
227 * @todo Define visibility
228 * @var array
229 */
230 public $curUrlArray;
231
232 /**
233 * Used with the link selector: Contains a processed version of the input values from curUrlInfo.
234 * This is splitted into pageid, content element id, label value etc.
235 * This is used for the internal processing of that information.
236 *
237 * @todo Define visibility
238 * @var array
239 */
240 public $curUrlInfo;
241
242 /**
243 * array which holds hook objects (initialised in init())
244 * @var \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface[]
245 */
246 protected $hookObjects = array();
247
248 /**
249 * @var \TYPO3\CMS\Core\Utility\File\BasicFileUtility
250 */
251 public $fileProcessor;
252
253 /**
254 * Constructor:
255 * Initializes a lot of variables, setting JavaScript functions in header etc.
256 *
257 * @return void
258 * @todo Define visibility
259 * @throws \UnexpectedValueException
260 */
261 public function init() {
262 // Main GPvars:
263 $this->pointer = GeneralUtility::_GP('pointer');
264 $this->bparams = GeneralUtility::_GP('bparams');
265 $this->P = GeneralUtility::_GP('P');
266 $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
267 $this->expandPage = GeneralUtility::_GP('expandPage');
268 $this->expandFolder = GeneralUtility::_GP('expandFolder');
269 $this->PM = GeneralUtility::_GP('PM');
270 // Find "mode"
271 $this->mode = GeneralUtility::_GP('mode');
272 if (!$this->mode) {
273 $this->mode = 'rte';
274 }
275 // Creating backend template object:
276 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
277 $this->doc->backPath = $GLOBALS['BACK_PATH'];
278 // Load the Prototype library and browse_links.js
279 $this->doc->getPageRenderer()->loadPrototype();
280 $this->doc->loadJavascriptLib('js/browse_links.js');
281 $this->doc->loadJavascriptLib('js/tree.js');
282 // init hook objects:
283 $this->hookObjects = array();
284 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'])) {
285 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'] as $classData) {
286 $processObject = GeneralUtility::getUserObj($classData);
287 if (!$processObject instanceof \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface) {
288 throw new \UnexpectedValueException('$processObject must implement interface TYPO3\\CMS\\Core\\ElementBrowser\\ElementBrowserHookInterface', 1195039394);
289 }
290 $parameters = array();
291 $processObject->init($this, $parameters);
292 $this->hookObjects[] = $processObject;
293 }
294 }
295 // Site URL
296 // Current site url
297 $this->siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
298 // The script to link to
299 $this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
300 // Init fileProcessor
301 $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
302 $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
303 // CurrentUrl - the current link url must be passed around if it exists
304 if ($this->mode == 'wizard') {
305 $currentValues = GeneralUtility::trimExplode(LF, trim($this->P['currentValue']));
306 if (count($currentValues) > 0) {
307 $currentValue = array_pop($currentValues);
308 } else {
309 $currentValue = '';
310 }
311 $currentLinkParts = GeneralUtility::unQuoteFilenames($currentValue, TRUE);
312 $initialCurUrlArray = array(
313 'href' => $currentLinkParts[0],
314 'target' => $currentLinkParts[1],
315 'class' => $currentLinkParts[2],
316 'title' => $currentLinkParts[3],
317 'params' => $currentLinkParts[4]
318 );
319 $this->curUrlArray = is_array(GeneralUtility::_GP('curUrl'))
320 ? array_merge($initialCurUrlArray, GeneralUtility::_GP('curUrl'))
321 : $initialCurUrlArray;
322 // Additional fields for page links
323 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'])
324 && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'])
325 ) {
326 $conf = array();
327 $_params = array(
328 'conf' => &$conf,
329 'linkParts' => $currentLinkParts
330 );
331 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'] as $objRef) {
332 $processor =& GeneralUtility::getUserObj($objRef);
333 $processor->extendUrlArray($_params, $this);
334 }
335 }
336 $this->curUrlInfo = $this->parseCurUrl($this->siteURL . '?id=' . $this->curUrlArray['href'], $this->siteURL);
337 // pageid == 0 means that this is not an internal (page) link
338 if ($this->curUrlInfo['pageid'] == 0 && $this->curUrlArray['href']) {
339 // Check if there is the FAL API
340 if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], 'file:')) {
341 $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
342 // Remove the "file:" prefix
343 $currentLinkParts[0] = rawurldecode(substr($this->curUrlArray['href'], 5));
344 } elseif (file_exists(PATH_site . rawurldecode($this->curUrlArray['href']))) {
345 if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], PATH_site)) {
346 $currentLinkParts[0] = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->curUrlArray['href']);
347 }
348 $this->curUrlInfo = $this->parseCurUrl($this->siteURL . $this->curUrlArray['href'], $this->siteURL);
349 } elseif (strstr($this->curUrlArray['href'], '@')) {
350 // check for email link
351 if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], 'mailto:')) {
352 $currentLinkParts[0] = substr($this->curUrlArray['href'], 7);
353 }
354 $this->curUrlInfo = $this->parseCurUrl('mailto:' . $this->curUrlArray['href'], $this->siteURL);
355 } else {
356 // nothing of the above. this is an external link
357 if (strpos($this->curUrlArray['href'], '://') === FALSE) {
358 $currentLinkParts[0] = 'http://' . $this->curUrlArray['href'];
359 }
360 $this->curUrlInfo = $this->parseCurUrl($currentLinkParts[0], $this->siteURL);
361 }
362 } elseif (!$this->curUrlArray['href']) {
363 $this->curUrlInfo = array();
364 $this->act = 'page';
365 } else {
366 $this->curUrlInfo = $this->parseCurUrl($this->siteURL . '?id=' . $this->curUrlArray['href'], $this->siteURL);
367 }
368 } else {
369 $this->curUrlArray = GeneralUtility::_GP('curUrl');
370 if ($this->curUrlArray['all']) {
371 $this->curUrlArray = GeneralUtility::get_tag_attributes($this->curUrlArray['all']);
372 }
373 $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
374 }
375 // Determine nature of current url:
376 $this->act = GeneralUtility::_GP('act');
377 if (!$this->act) {
378 $this->act = $this->curUrlInfo['act'];
379 }
380 // Rich Text Editor specific configuration:
381 $addPassOnParams = '';
382 if ((string) $this->mode == 'rte') {
383 $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
384 $addPassOnParams .= '&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams);
385 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
386 $this->thisConfig = BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
387 }
388 // Initializing the target value (RTE)
389 $this->setTarget = $this->curUrlArray['target'] != '-' ? rawurlencode($this->curUrlArray['target']) : '';
390 if ($this->thisConfig['defaultLinkTarget'] && !isset($this->curUrlArray['target'])) {
391 $this->setTarget = $this->thisConfig['defaultLinkTarget'];
392 }
393 // Initializing the class value (RTE)
394 $this->setClass = $this->curUrlArray['class'] != '-' ? rawurlencode($this->curUrlArray['class']) : '';
395 // Initializing the title value (RTE)
396 $this->setTitle = $this->curUrlArray['title'] != '-' ? rawurlencode($this->curUrlArray['title']) : '';
397 // Initializing the params value
398 $this->setParams = $this->curUrlArray['params'] != '-' ? rawurlencode($this->curUrlArray['params']) : '';
399 // BEGIN accumulation of header JavaScript:
400 $JScode = '
401 // This JavaScript is primarily for RTE/Link. jumpToUrl is used in the other cases as well...
402 var add_href="' . ($this->curUrlArray['href'] ? '&curUrl[href]=' . rawurlencode($this->curUrlArray['href']) : '') . '";
403 var add_target="' . ($this->setTarget ? '&curUrl[target]=' . rawurlencode($this->setTarget) : '') . '";
404 var add_class="' . ($this->setClass ? '&curUrl[class]=' . rawurlencode($this->setClass) : '') . '";
405 var add_title="' . ($this->setTitle ? '&curUrl[title]=' . rawurlencode($this->setTitle) : '') . '";
406 var add_params="' . ($this->bparams ? '&bparams=' . rawurlencode($this->bparams) : '') . '";
407
408 var cur_href="' . ($this->curUrlArray['href'] ? rawurlencode($this->curUrlArray['href']) : '') . '";
409 var cur_target="' . ($this->setTarget ?: '') . '";
410 var cur_class = "' . ($this->setClass ?: '') . '";
411 var cur_title="' . ($this->setTitle ?: '') . '";
412 var cur_params="' . ($this->setParams ?: '') . '";
413
414 function browse_links_setTarget(target) { //
415 cur_target=target;
416 add_target="&curUrl[target]="+escape(target);
417 }
418 function browse_links_setClass(cssClass) { //
419 cur_class = cssClass;
420 add_class = "&curUrl[class]=" + escape(cssClass);
421 }
422 function browse_links_setTitle(title) { //
423 cur_title=title;
424 add_title="&curUrl[title]="+escape(title);
425 }
426 function browse_links_setValue(value) { //
427 cur_href=value;
428 add_href="&curUrl[href]="+value;
429 }
430 function browse_links_setParams(params) { //
431 cur_params=params;
432 add_params="&curUrl[params]="+escape(params);
433 }
434 ';
435 // Functions used, if the link selector is in wizard mode (= TCEforms fields)
436 if ($this->mode == 'wizard') {
437 if (!$this->areFieldChangeFunctionsValid() && !$this->areFieldChangeFunctionsValid(TRUE)) {
438 $this->P['fieldChangeFunc'] = array();
439 }
440 unset($this->P['fieldChangeFunc']['alert']);
441 $update = '';
442 foreach ($this->P['fieldChangeFunc'] as $v) {
443 $update .= '
444 window.opener.' . $v;
445 }
446 $P2 = array();
447 $P2['itemName'] = $this->P['itemName'];
448 $P2['formName'] = $this->P['formName'];
449 $P2['fieldChangeFunc'] = $this->P['fieldChangeFunc'];
450 $P2['fieldChangeFuncHash'] = GeneralUtility::hmac(serialize($this->P['fieldChangeFunc']));
451 $P2['params']['allowedExtensions'] = isset($this->P['params']['allowedExtensions']) ? $this->P['params']['allowedExtensions'] : '';
452 $P2['params']['blindLinkOptions'] = isset($this->P['params']['blindLinkOptions']) ? $this->P['params']['blindLinkOptions'] : '';
453 $P2['params']['blindLinkFields'] = isset($this->P['params']['blindLinkFields']) ? $this->P['params']['blindLinkFields']: '';
454 $addPassOnParams .= GeneralUtility::implodeArrayForUrl('P', $P2);
455 $JScode .= '
456 function link_typo3Page(id,anchor) { //
457 updateValueInMainForm(id + (anchor ? anchor : ""));
458 close();
459 return false;
460 }
461 function link_folder(folder) { //
462 updateValueInMainForm(folder);
463 close();
464 return false;
465 }
466 function link_current() { //
467 if (cur_href!="http://" && cur_href!="mailto:") {
468 returnBeforeCleaned = cur_href;
469 if (returnBeforeCleaned.substr(0, 7) == "http://") {
470 returnToMainFormValue = returnBeforeCleaned.substr(7);
471 } else if (returnBeforeCleaned.substr(0, 7) == "mailto:") {
472 if (returnBeforeCleaned.substr(0, 14) == "mailto:mailto:") {
473 returnToMainFormValue = returnBeforeCleaned.substr(14);
474 } else {
475 returnToMainFormValue = returnBeforeCleaned.substr(7);
476 }
477 } else {
478 returnToMainFormValue = returnBeforeCleaned;
479 }
480 updateValueInMainForm(returnToMainFormValue);
481 close();
482 }
483 return false;
484 }
485 function checkReference() { //
486 if (window.opener && window.opener.document && window.opener.document.' . $this->P['formName']
487 . ' && window.opener.document.' . $this->P['formName'] . '["' . $this->P['itemName'] . '"] ) {
488 return window.opener.document.' . $this->P['formName'] . '["' . $this->P['itemName'] . '"];
489 } else {
490 close();
491 }
492 }
493 function updateValueInMainForm(input) { //
494 var field = checkReference();
495 if (field) {
496 if (cur_target == "" && (cur_class != "" || cur_title != "" || cur_params != "")) {
497 cur_target = "-";
498 }
499 if (cur_class == "" && (cur_title != "" || cur_params != "")) {
500 cur_class = "-";
501 }
502 cur_class = cur_class.replace(/[\'\\"]/g, "");
503 if (cur_class.indexOf(" ") != -1) {
504 cur_class = "\\"" + cur_class + "\\"";
505 }
506 if (cur_title == "" && cur_params != "") {
507 cur_title = "-";
508 }
509 cur_title = cur_title.replace(/(^\\")|(\\"$)/g, "");
510 if (cur_title.indexOf(" ") != -1) {
511 cur_title = "\\"" + cur_title + "\\"";
512 }
513 if (cur_params) {
514 cur_params = cur_params.replace(/\\bid\\=.*?(\\&|$)/, "");
515 }
516 input = input + " " + cur_target + " " + cur_class + " " + cur_title + " " + cur_params;
517 if(field.value && field.className.search(/textarea/) != -1) {
518 field.value += "\\n" + input;
519 } else {
520 field.value = input;
521 }
522 ' . $update . '
523 }
524 }
525 ';
526 } else {
527 // Functions used, if the link selector is in RTE mode:
528 $JScode .= '
529 function link_typo3Page(id,anchor) { //
530 var theLink = \'' . $this->siteURL . '?id=\'+id+(anchor?anchor:"");
531 self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
532 return false;
533 }
534 function link_folder(folder) { //
535 var theLink = \'' . $this->siteURL . '\'+folder;
536 self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
537 return false;
538 }
539 function link_spec(theLink) { //
540 self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
541 return false;
542 }
543 function link_current() { //
544 if (cur_href!="http://" && cur_href!="mailto:") {
545 self.parent.parent.renderPopup_addLink(cur_href, cur_target, cur_class, cur_title);
546 }
547 return false;
548 }
549 ';
550 }
551 // General "jumpToUrl" function:
552 $JScode .= '
553 function jumpToUrl(URL,anchor) { //
554 var add_act = URL.indexOf("act=")==-1 ? "&act=' . $this->act . '" : "";
555 var add_mode = URL.indexOf("mode=")==-1 ? "&mode=' . $this->mode . '" : "";
556 var theLocation = URL + add_act + add_mode + add_href + add_target + add_class + add_title + add_params'
557 . ($addPassOnParams ? '+"' . $addPassOnParams . '"' : '') . '+(typeof(anchor)=="string"?anchor:"");
558 window.location.href = theLocation;
559 return false;
560 }
561 ';
562 /**
563 * Splits parts of $this->bparams
564 *
565 * @see $bparams
566 */
567 $pArr = explode('|', $this->bparams);
568 // This is JavaScript especially for the TBE Element Browser!
569 $formFieldName = 'data[' . $pArr[0] . '][' . $pArr[1] . '][' . $pArr[2] . ']';
570 // insertElement - Call check function (e.g. for uniqueness handling):
571 $JScodeCheck = '';
572 if ($pArr[4] && $pArr[5]) {
573 $JScodeCheck = '
574 // Call a check function in the opener window (e.g. for uniqueness handling):
575 if (parent.window.opener) {
576 var res = parent.window.opener.' . $pArr[5] . '("' . addslashes($pArr[4]) . '",table,uid,type);
577 if (!res.passed) {
578 if (res.message) alert(res.message);
579 performAction = false;
580 }
581 } else {
582 alert("Error - reference to main window is not set properly!");
583 parent.close();
584 }
585 ';
586 }
587 // insertElement - Call helper function:
588 $JScodeHelper = '';
589 if ($pArr[4] && $pArr[6]) {
590 $JScodeHelper = '
591 // Call helper function to manage data in the opener window:
592 if (parent.window.opener) {
593 parent.window.opener.' . $pArr[6] . '("' . addslashes($pArr[4]) . '",table,uid,type,"' . addslashes($pArr[0]) . '");
594 } else {
595 alert("Error - reference to main window is not set properly!");
596 parent.close();
597 }
598 ';
599 }
600 // insertElement - perform action commands:
601 $JScodeActionMultiple = '';
602 if ($pArr[4] && $pArr[7]) {
603 // Call user defined action function:
604 $JScodeAction = '
605 if (parent.window.opener) {
606 parent.window.opener.' . $pArr[7] . '("' . addslashes($pArr[4]) . '",table,uid,type);
607 if (close) { focusOpenerAndClose(close); }
608 } else {
609 alert("Error - reference to main window is not set properly!");
610 if (close) { parent.close(); }
611 }
612 ';
613 $JScodeActionMultiple = '
614 // Call helper function to manage data in the opener window:
615 if (parent.window.opener) {
616 parent.window.opener.' . $pArr[7] . 'Multiple("' . addslashes($pArr[4]) . '",table,uid,type,"'
617 . addslashes($pArr[0]) . '");
618 } else {
619 alert("Error - reference to main window is not set properly!");
620 parent.close();
621 }
622 ';
623 } elseif ($pArr[0] && !$pArr[1] && !$pArr[2]) {
624 $JScodeAction = '
625 addElement(filename,table+"_"+uid,fp,close);
626 ';
627 } else {
628 $JScodeAction = '
629 if (setReferences()) {
630 parent.window.opener.group_change("add","' . $pArr[0] . '","' . $pArr[1] . '","' . $pArr[2]
631 . '",elRef,targetDoc);
632 } else {
633 alert("Error - reference to main window is not set properly!");
634 }
635 focusOpenerAndClose(close);
636 ';
637 }
638 $JScode .= '
639 var elRef="";
640 var targetDoc="";
641
642 function launchView(url) { //
643 var thePreviewWindow="";
644 thePreviewWindow = window.open("' . $GLOBALS['BACK_PATH'] . 'show_item.php?table="+url,"ShowItem",'
645 . '"height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
646 if (thePreviewWindow && thePreviewWindow.focus) {
647 thePreviewWindow.focus();
648 }
649 }
650 function setReferences() { //
651 if (parent.window.opener && parent.window.opener.content && parent.window.opener.content.document.editform'
652 . '&& parent.window.opener.content.document.editform["' . $formFieldName . '"]) {
653 targetDoc = parent.window.opener.content.document;
654 elRef = targetDoc.editform["' . $formFieldName . '"];
655 return true;
656 } else {
657 return false;
658 }
659 }
660 function insertElement(table, uid, type, filename, fp, filetype, imagefile, action, close) { //
661 var performAction = true;
662 ' . $JScodeCheck . '
663 // Call performing function and finish this action:
664 if (performAction) {
665 ' . $JScodeHelper . $JScodeAction . '
666 }
667 return false;
668 }
669 function insertMultiple(table, uid) {
670 var type = "";
671 ' . $JScodeActionMultiple . '
672 return false;
673 }
674 function addElement(elName, elValue, altElValue, close) { //
675 if (parent.window.opener && parent.window.opener.setFormValueFromBrowseWin) {
676 parent.window.opener.setFormValueFromBrowseWin("' . $pArr[0] . '",altElValue?altElValue:elValue,elName);
677 focusOpenerAndClose(close);
678 } else {
679 alert("Error - reference to main window is not set properly!");
680 parent.close();
681 }
682 }
683 function focusOpenerAndClose(close) { //
684 BrowseLinks.focusOpenerAndClose(close);
685 }
686 ';
687 // extends JavaScript code
688 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'])
689 && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'])
690 ) {
691 $conf = array();
692 $update = '';
693 $_params = array(
694 'conf' => &$conf,
695 'wizardUpdate' => $update,
696 'addPassOnParams' => $addPassOnParams
697 );
698 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'] as $objRef) {
699 $processor =& GeneralUtility::getUserObj($objRef);
700 $JScode .= $processor->extendJScode($_params, $this);
701 }
702 }
703 // Finally, add the accumulated JavaScript to the template object:
704 $this->doc->JScode .= $this->doc->wrapScriptTags($JScode);
705 }
706
707 /**
708 * Session data for this class can be set from outside with this method.
709 * Call after init()
710 *
711 * @param array $data Session data array
712 * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
713 * @todo Define visibility
714 */
715 public function processSessionData($data) {
716 $store = FALSE;
717 switch ((string) $this->mode) {
718 case 'db':
719 if (isset($this->expandPage)) {
720 $data['expandPage'] = $this->expandPage;
721 $store = TRUE;
722 } else {
723 $this->expandPage = $data['expandPage'];
724 }
725 break;
726 case 'file':
727
728 case 'filedrag':
729
730 case 'folder':
731 if (isset($this->expandFolder)) {
732 $data['expandFolder'] = $this->expandFolder;
733 $store = TRUE;
734 } else {
735 $this->expandFolder = $data['expandFolder'];
736 }
737 break;
738 }
739 return array($data, $store);
740 }
741
742 /******************************************************************
743 *
744 * Main functions
745 *
746 ******************************************************************/
747 /**
748 * Rich Text Editor (RTE) link selector (MAIN function)
749 * Generates the link selector for the Rich Text Editor.
750 * Can also be used to select links for the TCEforms (see $wiz)
751 *
752 * @param boolean $wiz If set, the "remove link" is not shown in the menu: Used for the "Select link" wizard which is used by the TCEforms
753 * @return string Modified content variable.
754 * @todo Define visibility
755 */
756 public function main_rte($wiz = FALSE) {
757 // Starting content:
758 $content = $this->doc->startPage('RTE link');
759
760 // Initializing the action value, possibly removing blinded values etc:
761 $blindLinkOptions = isset($this->thisConfig['blindLinkOptions'])
762 ? GeneralUtility::trimExplode(',', $this->thisConfig['blindLinkOptions'], TRUE)
763 : array();
764 $pBlindLinkOptions = isset($this->P['params']['blindLinkOptions'])
765 ? GeneralUtility::trimExplode(',', $this->P['params']['blindLinkOptions'])
766 : array();
767 $allowedItems = array_diff(array('page', 'file', 'folder', 'url', 'mail', 'spec'), $blindLinkOptions, $pBlindLinkOptions);
768
769 // Call hook for extra options
770 foreach ($this->hookObjects as $hookObject) {
771 $allowedItems = $hookObject->addAllowedItems($allowedItems);
772 }
773
774 // Removing link fields if configured
775 $blindLinkFields = isset($this->thisConfig['blindLinkFields'])
776 ? GeneralUtility::trimExplode(',', $this->thisConfig['blindLinkFields'], TRUE)
777 : array();
778 $pBlindLinkFields = isset($this->P['params']['blindLinkFields'])
779 ? GeneralUtility::trimExplode(',', $this->P['params']['blindLinkFields'], TRUE)
780 : array();
781 $allowedFields = array_diff(array('target', 'title', 'class', 'params'), $blindLinkFields, $pBlindLinkFields);
782
783 // If $this->act is not allowed, default to first allowed
784 if (!in_array($this->act, $allowedItems)) {
785 $this->act = reset($allowedItems);
786 }
787 // Making menu in top:
788 $menuDef = array();
789 if (!$wiz) {
790 $menuDef['removeLink']['isActive'] = $this->act == 'removeLink';
791 $menuDef['removeLink']['label'] = $GLOBALS['LANG']->getLL('removeLink', TRUE);
792 $menuDef['removeLink']['url'] = '#';
793 $menuDef['removeLink']['addParams'] = 'onclick="self.parent.parent.renderPopup_unLink();return false;"';
794 }
795 if (in_array('page', $allowedItems)) {
796 $menuDef['page']['isActive'] = $this->act == 'page';
797 $menuDef['page']['label'] = $GLOBALS['LANG']->getLL('page', TRUE);
798 $menuDef['page']['url'] = '#';
799 $menuDef['page']['addParams'] = 'onclick="jumpToUrl(\'?act=page\');return false;"';
800 }
801 if (in_array('file', $allowedItems)) {
802 $menuDef['file']['isActive'] = $this->act == 'file';
803 $menuDef['file']['label'] = $GLOBALS['LANG']->getLL('file', TRUE);
804 $menuDef['file']['url'] = '#';
805 $menuDef['file']['addParams'] = 'onclick="jumpToUrl(\'?act=file\');return false;"';
806 }
807 if (in_array('folder', $allowedItems)) {
808 $menuDef['folder']['isActive'] = $this->act == 'folder';
809 $menuDef['folder']['label'] = $GLOBALS['LANG']->getLL('folder', TRUE);
810 $menuDef['folder']['url'] = '#';
811 $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(\'?act=folder\');return false;"';
812 }
813 if (in_array('url', $allowedItems)) {
814 $menuDef['url']['isActive'] = $this->act == 'url';
815 $menuDef['url']['label'] = $GLOBALS['LANG']->getLL('extUrl', TRUE);
816 $menuDef['url']['url'] = '#';
817 $menuDef['url']['addParams'] = 'onclick="jumpToUrl(\'?act=url\');return false;"';
818 }
819 if (in_array('mail', $allowedItems)) {
820 $menuDef['mail']['isActive'] = $this->act == 'mail';
821 $menuDef['mail']['label'] = $GLOBALS['LANG']->getLL('email', TRUE);
822 $menuDef['mail']['url'] = '#';
823 $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(\'?act=mail\');return false;"';
824 }
825 if (is_array($this->thisConfig['userLinks.']) && in_array('spec', $allowedItems)) {
826 $menuDef['spec']['isActive'] = $this->act == 'spec';
827 $menuDef['spec']['label'] = $GLOBALS['LANG']->getLL('special', TRUE);
828 $menuDef['spec']['url'] = '#';
829 $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(\'?act=spec\');return false;"';
830 }
831 // Call hook for extra options
832 foreach ($this->hookObjects as $hookObject) {
833 $menuDef = $hookObject->modifyMenuDefinition($menuDef);
834 }
835 $content .= $this->doc->getTabMenuRaw($menuDef);
836 // Adding the menu and header to the top of page:
837 $content .= $this->printCurrentUrl($this->curUrlInfo['info']) . '<br />';
838 // Depending on the current action we will create the actual module content for selecting a link:
839 switch ($this->act) {
840 case 'mail':
841 $extUrl = '
842
843 <!--
844 Enter mail address:
845 -->
846 <form action="" name="lurlform" id="lurlform">
847 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkMail">
848 <tr>
849 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('emailAddress', TRUE) . ':</td>
850 <td><input type="text" name="lemail"' . $this->doc->formWidth(20) . ' value="'
851 . htmlspecialchars(($this->curUrlInfo['act'] == 'mail' ? $this->curUrlInfo['info'] : ''))
852 . '" /> ' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', TRUE)
853 . '" onclick="browse_links_setTarget(\'\');browse_links_setValue(\'mailto:\'+'
854 . 'document.lurlform.lemail.value); return link_current();" /></td>
855 </tr>
856 </table>
857 </form>';
858 $content .= $extUrl;
859 break;
860 case 'url':
861 $extUrl = '
862
863 <!--
864 Enter External URL:
865 -->
866 <form action="" name="lurlform" id="lurlform">
867 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkURL">
868 <tr>
869 <td style="width: 96px;">URL:</td>
870 <td><input type="text" name="lurl"' . $this->doc->formWidth(30) . ' value="'
871 . htmlspecialchars(($this->curUrlInfo['act'] == 'url' ? $this->curUrlInfo['info'] : 'http://'))
872 . '" /> ' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', TRUE)
873 . '" onclick="browse_links_setValue(document.lurlform.lurl.value); return link_current();" /></td>
874 </tr>
875 </table>
876 </form>';
877 $content .= $extUrl;
878 break;
879 case 'file':
880
881 case 'folder':
882 $foldertree = GeneralUtility::makeInstance('rteFolderTree');
883 $foldertree->thisScript = $this->thisScript;
884 $tree = $foldertree->getBrowsableTree();
885 if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
886 $cmpPath = '';
887 } else {
888 $cmpPath = $this->curUrlInfo['value'];
889 if (!isset($this->expandFolder)) {
890 $this->expandFolder = $cmpPath;
891 }
892 }
893 // Create upload/create folder forms, if a path is given
894 $selectedFolder = FALSE;
895 if ($this->expandFolder) {
896 $fileOrFolderObject = NULL;
897 try {
898 $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
899 } catch (\Exception $e) {
900 }
901
902 if ($fileOrFolderObject instanceof Folder) {
903 // It's a folder
904 $selectedFolder = $fileOrFolderObject;
905 } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
906 // It's a file
907 // @todo: find the parent folder, right now done a bit ugly, because the file does not
908 // support finding the parent folder of a file on purpose
909 $folderIdentifier = dirname($fileOrFolderObject->getIdentifier());
910 $selectedFolder = $fileOrFolderObject->getStorage()->getFolder($folderIdentifier);
911 }
912 }
913 // Or get the user's default upload folder
914 if (!$selectedFolder) {
915 $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
916 }
917 // Build the file upload and folder creation form
918 $uploadForm = '';
919 $createFolder = '';
920 if ($selectedFolder) {
921 $uploadForm = ($this->act === 'file') ? $this->uploadForm($selectedFolder) : '';
922 $createFolder = $this->createFolder($selectedFolder);
923 }
924 // Insert the upload form on top, if so configured
925 if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
926 $content .= $uploadForm;
927 }
928
929 // Render the filelist if there is a folder selected
930 if ($selectedFolder) {
931 $files = $this->expandFolder($selectedFolder, $this->P['params']['allowedExtensions']);
932 }
933 $this->doc->JScode .= $this->doc->wrapScriptTags('
934 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
935 ');
936 $content .= '
937 <!--
938 Wrapper table for folder tree / file/folder list:
939 -->
940 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
941 <tr>
942 <td class="c-wCell" valign="top">'
943 . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
944 <td class="c-wCell" valign="top">' . $files . '</td>
945 </tr>
946 </table>
947 <br />
948 ';
949 // Adding create folder + upload forms if applicable
950 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
951 $content .= $uploadForm;
952 }
953 $content .= $createFolder . '<br />';
954 break;
955 case 'spec':
956 if (is_array($this->thisConfig['userLinks.'])) {
957 $subcats = array();
958 $v = $this->thisConfig['userLinks.'];
959 foreach ($v as $k2 => $value) {
960 $k2i = intval($k2);
961 if (substr($k2, -1) == '.' && is_array($v[$k2i . '.'])) {
962 // Title:
963 $title = trim($v[$k2i]);
964 if (!$title) {
965 $title = $v[$k2i . '.']['url'];
966 } else {
967 $title = $GLOBALS['LANG']->sL($title);
968 }
969 // Description:
970 $description = $v[$k2i . '.']['description']
971 ? $GLOBALS['LANG']->sL($v[($k2i . '.')]['description'], TRUE) . '<br />'
972 : '';
973 // URL + onclick event:
974 $onClickEvent = '';
975 if (isset($v[$k2i . '.']['target'])) {
976 $onClickEvent .= 'browse_links_setTarget(\'' . $v[($k2i . '.')]['target'] . '\');';
977 }
978 $v[$k2i . '.']['url'] = str_replace('###_URL###', $this->siteURL, $v[$k2i . '.']['url']);
979 if (substr($v[$k2i . '.']['url'], 0, 7) === 'http://' || substr($v[$k2i . '.']['url'], 0, 7) === 'mailto:') {
980 $onClickEvent .= 'cur_href=unescape(\'' . rawurlencode($v[($k2i . '.')]['url']) . '\');link_current();';
981 } else {
982 $onClickEvent .= 'link_spec(unescape(\'' . $this->siteURL . rawurlencode($v[($k2i . '.')]['url']) . '\'));';
983 }
984 // Link:
985 $A = array('<a href="#" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">', '</a>');
986 // Adding link to menu of user defined links:
987 $subcats[$k2i] = '
988 <tr>
989 <td class="bgColor4">' . $A[0] . '<strong>' . htmlspecialchars($title)
990 . ($this->curUrlInfo['info'] == $v[$k2i . '.']['url']
991 ? '<img' . IconUtility::skinImg(
992 $GLOBALS['BACK_PATH'],
993 'gfx/blinkarrow_right.gif',
994 'width="5" height="9"'
995 ) . ' class="c-blinkArrowR" alt="" />'
996 : '')
997 . '</strong><br />' . $description . $A[1] . '</td>
998 </tr>';
999 }
1000 }
1001 // Sort by keys:
1002 ksort($subcats);
1003 // Add menu to content:
1004 $content .= '
1005
1006 <!--
1007 Special userdefined menu:
1008 -->
1009 <table border="0" cellpadding="1" cellspacing="1" id="typo3-linkSpecial">
1010 <tr>
1011 <td class="bgColor5" class="c-wCell" valign="top"><strong>'
1012 . $GLOBALS['LANG']->getLL('special', TRUE) . '</strong></td>
1013 </tr>
1014 ' . implode('', $subcats) . '
1015 </table>
1016 ';
1017 }
1018 break;
1019 case 'page':
1020 $pageTree = GeneralUtility::makeInstance('rtePageTree');
1021 $pageTree->thisScript = $this->thisScript;
1022 $pageTree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
1023 $pageTree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
1024 $pageTree->addField('nav_title');
1025 $tree = $pageTree->getBrowsableTree();
1026 $cElements = $this->expandPage();
1027 // Outputting Temporary DB mount notice:
1028 $dbmount = '';
1029 if (intval($GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint'))) {
1030 $link = '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('setTempDBmount' => 0)))
1031 . '">' . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xlf:labels.temporaryDBmount', TRUE)
1032 . '</a>';
1033 $flashMessage = GeneralUtility::makeInstance(
1034 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
1035 $link,
1036 '',
1037 \TYPO3\CMS\Core\Messaging\FlashMessage::INFO
1038 );
1039 $dbmount = $flashMessage->render();
1040 }
1041 $content .= '
1042
1043 <!--
1044 Wrapper table for page tree / record list:
1045 -->
1046 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkPages">
1047 <tr>
1048 <td class="c-wCell" valign="top">'
1049 . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':')) . $dbmount . $tree
1050 . '</td>
1051 <td class="c-wCell" valign="top">' . $cElements . '</td>
1052 </tr>
1053 </table>
1054 ';
1055 break;
1056 default:
1057 // Call hook
1058 foreach ($this->hookObjects as $hookObject) {
1059 $content .= $hookObject->getTab($this->act);
1060 }
1061 }
1062 if (in_array('params', $allowedFields, TRUE)) {
1063 $content .= '
1064 <!--
1065 Selecting params for link:
1066 -->
1067 <form action="" name="lparamsform" id="lparamsform">
1068 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkParams">
1069 <tr>
1070 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('params', TRUE) . '</td>
1071 <td><input type="text" name="lparams" class="typo3-link-input" onchange="'
1072 . 'browse_links_setParams(this.value);" value="' . htmlspecialchars($this->setParams)
1073 . '" /></td>
1074 </tr>
1075 </table>
1076 </form>
1077 ';
1078 }
1079 if (in_array('class', $allowedFields, TRUE)) {
1080 $content .= '
1081 <!--
1082 Selecting class for link:
1083 -->
1084 <form action="" name="lclassform" id="lclassform">
1085 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkClass">
1086 <tr>
1087 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('class', TRUE) . '</td>
1088 <td><input type="text" name="lclass" class="typo3-link-input" onchange="'
1089 . 'browse_links_setClass(this.value);" value="' . htmlspecialchars($this->setClass)
1090 . '" /></td>
1091 </tr>
1092 </table>
1093 </form>
1094 ';
1095 }
1096 if (in_array('title', $allowedFields, TRUE)) {
1097 $content .= '
1098 <!--
1099 Selecting title for link:
1100 -->
1101 <form action="" name="ltitleform" id="ltitleform">
1102 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTitle">
1103 <tr>
1104 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('title', TRUE) . '</td>
1105 <td><input type="text" name="ltitle" class="typo3-link-input" onchange="'
1106 . 'browse_links_setTitle(this.value);" value="' . htmlspecialchars($this->setTitle)
1107 . '" /></td>
1108 </tr>
1109 </table>
1110 </form>
1111 ';
1112 }
1113 // additional fields for page links
1114 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'])
1115 && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'])
1116 ) {
1117 $conf = array();
1118 $_params = array(
1119 'conf' => &$conf
1120 );
1121 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'] as $objRef) {
1122 $processor =& GeneralUtility::getUserObj($objRef);
1123 $content .= $processor->addFields($_params, $this);
1124 }
1125 }
1126 // Target:
1127 if ($this->act != 'mail' && in_array('target', $allowedFields, TRUE)) {
1128 $ltarget = '
1129
1130 <!--
1131 Selecting target for link:
1132 -->
1133 <form action="" name="ltargetform" id="ltargetform">
1134 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">
1135 <tr>
1136 <td>' . $GLOBALS['LANG']->getLL('target', TRUE) . ':</td>
1137 <td><input type="text" name="ltarget" onchange="browse_links_setTarget(this.value);" value="'
1138 . htmlspecialchars($this->setTarget) . '"' . $this->doc->formWidth(10) . ' /></td>
1139 <td>
1140 <select name="ltarget_type" onchange="browse_links_setTarget('
1141 . 'this.options[this.selectedIndex].value);document.ltargetform.ltarget.value='
1142 . 'this.options[this.selectedIndex].value;this.selectedIndex=0;">
1143 <option></option>
1144 <option value="_top">' . $GLOBALS['LANG']->getLL('top', TRUE) . '</option>
1145 <option value="_blank">' . $GLOBALS['LANG']->getLL('newWindow', TRUE) . '</option>
1146 </select>
1147 </td>
1148 <td>';
1149 if (($this->curUrlInfo['act'] == 'page' || $this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder')
1150 && $this->curUrlArray['href'] && $this->curUrlInfo['act'] == $this->act
1151 ) {
1152 $ltarget .= '
1153 <input type="submit" value="' . $GLOBALS['LANG']->getLL('update', TRUE)
1154 . '" onclick="return link_current();" />';
1155 }
1156 $selectJS = '
1157 if (document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value>0'
1158 . ' && document.ltargetform.popup_height.options[document.ltargetform.popup_height.selectedIndex].value>0) {
1159 document.ltargetform.ltarget.value = document.ltargetform.popup_width.options['
1160 . 'document.ltargetform.popup_width.selectedIndex].value+"x"'
1161 . '+document.ltargetformbrowse_links_setTarget.popup_height.options['
1162 . 'document.ltargetform.popup_height.selectedIndex].value;
1163 browse_links_setTarget(document.ltargetform.ltarget.value);
1164 browse_links_setClass(document.lclassform.lclass.value);
1165 browse_links_setTitle(document.ltitleform.ltitle.value);
1166 browse_links_setParams(document.lparamsform.lparams.value);
1167 document.ltargetform.popup_width.selectedIndex=0;
1168 document.ltargetform.popup_height.selectedIndex=0;
1169 }
1170 ';
1171 $ltarget .= ' </td>
1172 </tr>
1173 <tr>
1174 <td>' . $GLOBALS['LANG']->getLL('target_popUpWindow', TRUE) . ':</td>
1175 <td colspan="3">
1176 <select name="popup_width" onchange="' . htmlspecialchars($selectJS) . '">
1177 <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_width', TRUE) . '</option>
1178 <option value="300">300</option>
1179 <option value="400">400</option>
1180 <option value="500">500</option>
1181 <option value="600">600</option>
1182 <option value="700">700</option>
1183 <option value="800">800</option>
1184 </select>
1185 x
1186 <select name="popup_height" onchange="' . htmlspecialchars($selectJS) . '">
1187 <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_height', TRUE) . '</option>
1188 <option value="200">200</option>
1189 <option value="300">300</option>
1190 <option value="400">400</option>
1191 <option value="500">500</option>
1192 <option value="600">600</option>
1193 </select>
1194 </td>
1195 </tr>
1196 </table>
1197 </form>';
1198 // Add "target selector" box to content:
1199 $content .= $ltarget;
1200 // Add some space
1201 $content .= '<br /><br />';
1202 }
1203 // End page, return content:
1204 $content .= $this->doc->endPage();
1205 $content = $this->doc->insertStylesAndJS($content);
1206 return $content;
1207 }
1208
1209 /**
1210 * TYPO3 Element Browser: Showing a page tree and allows you to browse for records
1211 *
1212 * @return string HTML content for the module
1213 * @todo Define visibility
1214 */
1215 public function main_db() {
1216 // Starting content:
1217 $content = $this->doc->startPage('TBE record selector');
1218 // Init variable:
1219 $pArr = explode('|', $this->bparams);
1220 $tables = $pArr[3];
1221 // Making the browsable pagetree:
1222 $pagetree = GeneralUtility::makeInstance('TBE_PageTree');
1223 $pagetree->thisScript = $this->thisScript;
1224 $pagetree->ext_pArrPages = $tables === 'pages' ? 1 : 0;
1225 $pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
1226 $pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
1227
1228 $withTree = TRUE;
1229 if (($tables !== '') && ($tables !== '*')) {
1230 $tablesArr = GeneralUtility::trimExplode(',', $tables, TRUE);
1231 $onlyRootLevel = TRUE;
1232 foreach ($tablesArr as $currentTable) {
1233 $tableTca = $GLOBALS['TCA'][$currentTable];
1234 if (isset($tableTca)) {
1235 if (!isset($tableTca['ctrl']['rootLevel']) || (intval($tableTca['ctrl']['rootLevel']) != 1)) {
1236 $onlyRootLevel = FALSE;
1237 }
1238 }
1239 }
1240 if ($onlyRootLevel) {
1241 $withTree = FALSE;
1242 // page to work on will be root
1243 $this->expandPage = 0;
1244 }
1245 }
1246
1247 $pagetree->addField('nav_title');
1248 $tree = $pagetree->getBrowsableTree();
1249 // Making the list of elements, if applicable:
1250 $cElements = $this->TBE_expandPage($tables);
1251 // Putting the things together, side by side:
1252 $content .= '
1253
1254 <!--
1255 Wrapper table for page tree / record list:
1256 -->
1257 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBrecords">
1258 <tr>';
1259 if ($withTree) {
1260 $content .= '<td class="c-wCell" valign="top">'
1261 . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':')) . $tree . '</td>';
1262 }
1263 $content .= '<td class="c-wCell" valign="top">' . $cElements . '</td>
1264 </tr>
1265 </table>
1266 ';
1267 // Add some space
1268 $content .= '<br /><br />';
1269 // End page, return content:
1270 $content .= $this->doc->endPage();
1271 $content = $this->doc->insertStylesAndJS($content);
1272 return $content;
1273 }
1274
1275 /**
1276 * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for files.
1277 *
1278 * @return string HTML content for the module
1279 * @todo Define visibility
1280 */
1281 public function main_file() {
1282 // include JS files and set prefs for foldertree
1283 $this->doc->getDragDropCode('folders');
1284 $this->doc->JScode .= $this->doc->wrapScriptTags('
1285 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1286 ');
1287 // Starting content:
1288 $content = $this->doc->startPage('TBE file selector');
1289 // Init variable:
1290 $pArr = explode('|', $this->bparams);
1291 // The key number 3 of the pArr contains the "allowed" string. Disallowed is not passed to
1292 // the element browser at all but only filtered out in TCEMain afterwards
1293 $allowed = $pArr[3];
1294 if ($allowed !== 'sys_file') {
1295 $allowedFileExtensions = $allowed;
1296 }
1297 $this->storages = $GLOBALS['BE_USER']->getFileStorages();
1298 if (isset($allowedFileExtensions)) {
1299 // Create new filter object
1300 $filterObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
1301 $filterObject->setAllowedFileExtensions($allowedFileExtensions);
1302 // Set file extension filters on all storages
1303 /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
1304 foreach ($this->storages as $storage) {
1305 $storage->addFileAndFolderNameFilter(array($filterObject, 'filterFileList'));
1306 }
1307 }
1308 // Create upload/create folder forms, if a path is given
1309 if ($this->expandFolder) {
1310 $this->selectedFolder = FALSE;
1311 $fileOrFolderObject = NULL;
1312
1313 // Try to fetch the folder the user had open the last time he browsed files
1314 // Fallback to the default folder in case the last used folder is not existing
1315 try {
1316 $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
1317 } catch (\TYPO3\CMS\Core\Resource\Exception $accessException) {
1318 // We're just catching the exception here, nothing to be done if folder does not exist or is not accessible.
1319 }
1320
1321 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
1322 // It's a folder
1323 $this->selectedFolder = $fileOrFolderObject;
1324 } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
1325 // It's a file
1326 // @todo: find the parent folder, right now done a bit ugly, because the file does not
1327 // support finding the parent folder of a file on purpose
1328 $folderIdentifier = dirname($fileOrFolderObject->getIdentifier());
1329 $this->selectedFolder = $fileOrFolderObject->getStorage()->getFolder($folderIdentifier);
1330 }
1331 }
1332 // Or get the user's default upload folder
1333 if (!$this->selectedFolder) {
1334 $this->selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
1335 }
1336 // Build the file upload and folder creation form
1337 $uploadForm = '';
1338 $createFolder = '';
1339 if ($this->selectedFolder) {
1340 $uploadForm = $this->uploadForm($this->selectedFolder);
1341 $createFolder = $this->createFolder($this->selectedFolder);
1342 }
1343 // Insert the upload form on top, if so configured
1344 if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1345 $content .= $uploadForm;
1346 }
1347 // Getting flag for showing/not showing thumbnails:
1348 $noThumbs = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
1349 $_MOD_SETTINGS = array();
1350 if (!$noThumbs) {
1351 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
1352 $_MOD_MENU = array('displayThumbs' => '');
1353 $_MCONF['name'] = 'file_list';
1354 $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']);
1355 }
1356 $noThumbs = $noThumbs ?: !$_MOD_SETTINGS['displayThumbs'];
1357 // Create folder tree:
1358 $folderTree = GeneralUtility::makeInstance('TBE_FolderTree');
1359 $folderTree->thisScript = $this->thisScript;
1360 $folderTree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1361 $tree = $folderTree->getBrowsableTree();
1362 list(, , $specUid) = explode('_', $this->PM);
1363 if ($this->selectedFolder) {
1364 if ($this->mode == 'filedrag') {
1365 $files = $this->TBE_dragNDrop($this->selectedFolder, $pArr[3]);
1366 } else {
1367 $files = $this->TBE_expandFolder($this->selectedFolder, $pArr[3], $noThumbs);
1368 }
1369 } else {
1370 $files = '';
1371 }
1372 // Putting the parts together, side by side:
1373 $content .= '
1374
1375 <!--
1376 Wrapper table for folder tree / file list:
1377 -->
1378 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1379 <tr>
1380 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':'))
1381 . $tree . '</td>
1382 <td class="c-wCell" valign="top">' . $files . '</td>
1383 </tr>
1384 </table>
1385 ';
1386 // Adding create folder + upload forms if applicable:
1387 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1388 $content .= $uploadForm;
1389 }
1390 $content .= $createFolder;
1391 // Add some space
1392 $content .= '<br /><br />';
1393 // Setup indexed elements:
1394 $this->doc->JScode .= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
1395 // Ending page, returning content:
1396 $content .= $this->doc->endPage();
1397 $content = $this->doc->insertStylesAndJS($content);
1398 return $content;
1399 }
1400
1401 /**
1402 * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for folders.
1403 *
1404 * @return string HTML content for the module
1405 * @todo Define visibility
1406 */
1407 public function main_folder() {
1408 // include JS files
1409 $this->doc->getDragDropCode('folders');
1410 // Setting prefs for foldertree
1411 $this->doc->JScode .= $this->doc->wrapScriptTags('
1412 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1413 ');
1414 // Starting content:
1415 $content = $this->doc->startPage('TBE folder selector');
1416 // Init variable:
1417 $parameters = explode('|', $this->bparams);
1418 if ($this->expandFolder) {
1419 $this->selectedFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
1420 }
1421 if ($this->selectedFolder) {
1422 $createFolder = $this->createFolder($this->selectedFolder);
1423 } else {
1424 $createFolder = '';
1425 }
1426 // Create folder tree:
1427 $folderTree = GeneralUtility::makeInstance('TBE_FolderTree');
1428 $folderTree->thisScript = $this->thisScript;
1429 $folderTree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1430 $tree = $folderTree->getBrowsableTree(FALSE);
1431 list(, , $specUid) = explode('_', $this->PM);
1432 if ($this->mode == 'filedrag') {
1433 $folders = $this->TBE_dragNDrop($this->selectedFolder, $parameters[3]);
1434 } else {
1435 $folders = $this->TBE_expandSubFolders($this->selectedFolder);
1436 }
1437 // Putting the parts together, side by side:
1438 $content .= '
1439
1440 <!--
1441 Wrapper table for folder tree / folder list:
1442 -->
1443 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1444 <tr>
1445 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':'))
1446 . $tree . '</td>
1447 <td class="c-wCell" valign="top">' . $folders . '</td>
1448 </tr>
1449 </table>
1450 ';
1451 // Adding create folder if applicable:
1452 $content .= $createFolder;
1453 // Add some space
1454 $content .= '<br /><br />';
1455 // Ending page, returning content:
1456 $content .= $this->doc->endPage();
1457 $content = $this->doc->insertStylesAndJS($content);
1458 return $content;
1459 }
1460
1461 /******************************************************************
1462 *
1463 * Record listing
1464 *
1465 ******************************************************************/
1466 /**
1467 * For RTE: This displays all content elements on a page and lets you create a link to the element.
1468 *
1469 * @return string HTML output. Returns content only if the ->expandPage value is set (pointing to a page uid to show tt_content records from ...)
1470 * @todo Define visibility
1471 */
1472 public function expandPage() {
1473 $out = '';
1474 // Set page id (if any) to expand
1475 $expPageId = $this->expandPage;
1476 // If there is an anchor value (content element reference) in the element reference, then force an ID to expand:
1477 if (!$this->expandPage && $this->curUrlInfo['cElement']) {
1478 // Set to the current link page id.
1479 $expPageId = $this->curUrlInfo['pageid'];
1480 }
1481 // Draw the record list IF there is a page id to expand:
1482 if ($expPageId
1483 && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($expPageId)
1484 && $GLOBALS['BE_USER']->isInWebMount($expPageId)
1485 ) {
1486 // Set header:
1487 $out .= $this->barheader($GLOBALS['LANG']->getLL('contentElements') . ':');
1488 // Create header for listing, showing the page title/icon:
1489 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1490 $mainPageRec = BackendUtility::getRecordWSOL('pages', $expPageId);
1491 $picon = IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1492 $picon .= BackendUtility::getRecordTitle('pages', $mainPageRec, TRUE);
1493 $out .= $picon . '<br />';
1494 // Look up tt_content elements from the expanded page:
1495 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1496 'uid,header,hidden,starttime,endtime,fe_group,CType,colPos,bodytext',
1497 'tt_content',
1498 'pid=' . intval($expPageId) . BackendUtility::deleteClause('tt_content')
1499 . BackendUtility::versioningPlaceholderClause('tt_content'),
1500 '',
1501 'colPos,sorting'
1502 );
1503 $cc = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
1504 // Traverse list of records:
1505 $c = 0;
1506 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1507 $c++;
1508 $icon = IconUtility::getSpriteIconForRecord('tt_content', $row);
1509 if ($this->curUrlInfo['act'] == 'page' && $this->curUrlInfo['cElement'] == $row['uid']) {
1510 $arrCol = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"')
1511 . ' class="c-blinkArrowL" alt="" />';
1512 } else {
1513 $arrCol = '';
1514 }
1515 // Putting list element HTML together:
1516 $out .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join' . ($c == $cc ? 'bottom' : '')
1517 . '.gif'), 'width="18" height="16"') . ' alt="" />' . $arrCol
1518 . '<a href="#" onclick="return link_typo3Page(\'' . $expPageId . '\',\'#' . $row['uid'] . '\');">'
1519 . $icon . BackendUtility::getRecordTitle('tt_content', $row, TRUE) . '</a><br />';
1520 // Finding internal anchor points:
1521 if (GeneralUtility::inList('text,textpic', $row['CType'])) {
1522 $split = preg_split('/(<a[^>]+name=[\'"]?([^"\'>[:space:]]+)[\'"]?[^>]*>)/i', $row['bodytext'], -1, PREG_SPLIT_DELIM_CAPTURE);
1523 foreach ($split as $skey => $sval) {
1524 if ($skey % 3 == 2) {
1525 // Putting list element HTML together:
1526 $sval = substr($sval, 0, 100);
1527 $out .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/ol/line.gif',
1528 'width="18" height="16"') . ' alt="" />'
1529 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join'
1530 . ($skey + 3 > count($split) ? 'bottom' : '') . '.gif'), 'width="18" height="16"')
1531 . ' alt="" />' . '<a href="#" onclick="return link_typo3Page(\'' . $expPageId
1532 . '\',\'#' . rawurlencode($sval) . '\');">' . htmlspecialchars((' <A> ' . $sval))
1533 . '</a><br />';
1534 }
1535 }
1536 }
1537 }
1538 }
1539 return $out;
1540 }
1541
1542 /**
1543 * For TYPO3 Element Browser: This lists all content elements from the given list of tables
1544 *
1545 * @param string $tables Comma separated list of tables. Set to "*" if you want all tables.
1546 * @return string HTML output.
1547 * @todo Define visibility
1548 */
1549 public function TBE_expandPage($tables) {
1550 $out = '';
1551 if ($this->expandPage >= 0
1552 && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->expandPage)
1553 && $GLOBALS['BE_USER']->isInWebMount($this->expandPage)
1554 ) {
1555 // Set array with table names to list:
1556 if (trim($tables) === '*') {
1557 $tablesArr = array_keys($GLOBALS['TCA']);
1558 } else {
1559 $tablesArr = GeneralUtility::trimExplode(',', $tables, TRUE);
1560 }
1561 reset($tablesArr);
1562 // Headline for selecting records:
1563 $out .= $this->barheader($GLOBALS['LANG']->getLL('selectRecords') . ':');
1564 // Create the header, showing the current page for which the listing is.
1565 // Includes link to the page itself, if pages are amount allowed tables.
1566 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1567 $mainPageRec = BackendUtility::getRecordWSOL('pages', $this->expandPage);
1568 $ATag = '';
1569 $ATag_e = '';
1570 $ATag2 = '';
1571 $picon = '';
1572 if (is_array($mainPageRec)) {
1573 $picon = IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1574 if (in_array('pages', $tablesArr)) {
1575 $ATag = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', '
1576 . GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',1);">';
1577 $ATag2 = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', '
1578 . GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',0);">';
1579 $ATag_e = '</a>';
1580 }
1581 }
1582 $pBicon = $ATag2 ? '<img'
1583 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif', 'width="18" height="16"')
1584 . ' alt="" />' : '';
1585 $pText = htmlspecialchars(GeneralUtility::fixed_lgd_cs($mainPageRec['title'], $titleLen));
1586 $out .= $picon . $ATag2 . $pBicon . $ATag_e . $ATag . $pText . $ATag_e . '<br />';
1587 // Initialize the record listing:
1588 $id = $this->expandPage;
1589 $pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
1590 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1591 $pageInfo = BackendUtility::readPageAccess($id, $perms_clause);
1592 // Generate the record list:
1593 /** @var $dbList \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList */
1594 if (is_object($this->recordList)) {
1595 $dbList = $this->recordList;
1596 } else {
1597 $dbList = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\RecordList\\ElementBrowserRecordList');
1598 }
1599 $dbList->thisScript = $this->thisScript;
1600 $dbList->backPath = $GLOBALS['BACK_PATH'];
1601 $dbList->thumbs = 0;
1602 $dbList->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageInfo);
1603 $dbList->noControlPanels = 1;
1604 $dbList->clickMenuEnabled = 0;
1605 $dbList->tableList = implode(',', $tablesArr);
1606 $pArr = explode('|', $this->bparams);
1607 // a string like "data[pages][79][storage_pid]"
1608 $fieldPointerString = $pArr[0];
1609 // parts like: data, pages], 79], storage_pid]
1610 $fieldPointerParts = explode('[', $fieldPointerString);
1611 $relatingTableName = substr($fieldPointerParts[1], 0, -1);
1612 $relatingFieldName = substr($fieldPointerParts[3], 0, -1);
1613 if ($relatingTableName && $relatingFieldName) {
1614 $dbList->setRelatingTableAndField($relatingTableName, $relatingFieldName);
1615 }
1616 $dbList->start($id, GeneralUtility::_GP('table'), $pointer, GeneralUtility::_GP('search_field'),
1617 GeneralUtility::_GP('search_levels'), GeneralUtility::_GP('showLimit')
1618 );
1619 $dbList->setDispFields();
1620 $dbList->generateList();
1621 // Add the HTML for the record list to output variable:
1622 $out .= $dbList->HTMLcode;
1623 // Add support for fieldselectbox in singleTableMode
1624 if ($dbList->table) {
1625 $out .= $dbList->fieldSelectBox($dbList->table);
1626 }
1627 $out .= $dbList->getSearchBox();
1628 }
1629 // Return accumulated content:
1630 return $out;
1631 }
1632
1633 /**
1634 * Render list of folders inside a folder.
1635 *
1636 * @param Folder $folder Folder
1637 * @return string HTML output
1638 * @todo Define visibility
1639 */
1640 public function TBE_expandSubFolders(Folder $folder) {
1641 $content = '';
1642 if ($folder->checkActionPermission('read')) {
1643 $content .= $this->folderList($folder);
1644 }
1645 // Return accumulated content for folderlisting:
1646 return $content;
1647 }
1648
1649 /******************************************************************
1650 *
1651 * File listing
1652 *
1653 ******************************************************************/
1654 /**
1655 * For RTE: This displays all files from folder. No thumbnails shown
1656 *
1657 * @param Folder $folder The folder path to expand
1658 * @param string $extensionList List of file extensions to show
1659 * @return string HTML output
1660 * @todo Define visibility
1661 */
1662 public function expandFolder(Folder $folder, $extensionList = '') {
1663 $out = '';
1664 $renderFolders = $this->act === 'folder';
1665 if ($folder->checkActionPermission('read')) {
1666 // Create header for file listing:
1667 $out .= $this->barheader($GLOBALS['LANG']->getLL('files') . ':');
1668 // Prepare current path value for comparison (showing red arrow)
1669 $currentIdentifier = '';
1670 if ($this->curUrlInfo['value']) {
1671 $currentIdentifier = $this->curUrlInfo['info'];
1672 }
1673 // Create header element; The folder from which files are listed.
1674 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1675 $folderIcon = IconUtility::getSpriteIconForFile('folder');
1676 $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen));
1677 $picon = '<a href="#" onclick="return link_folder(\'file:' . $folder->getCombinedIdentifier() . '\');">'
1678 . $folderIcon . '</a>';
1679 if ($this->curUrlInfo['act'] == 'folder' && $currentIdentifier == $folder->getCombinedIdentifier()) {
1680 $out .= '<img'
1681 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"')
1682 . ' class="c-blinkArrowL" alt="" />';
1683 }
1684 $out .= $picon . '<br />';
1685 // Get files from the folder:
1686 if ($renderFolders) {
1687 $items = $folder->getSubfolders();
1688 } else {
1689 $items = $this->getFilesInFolder($folder, $extensionList);
1690 }
1691 $c = 0;
1692 $totalItems = count($items);
1693 foreach ($items as $fileOrFolderObject) {
1694 $c++;
1695 if ($renderFolders) {
1696 $fileIdentifier = $fileOrFolderObject->getCombinedIdentifier();
1697 $overlays = array();
1698 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder) {
1699 $overlays = array('status-overlay-locked' => array());
1700 }
1701 $icon = IconUtility::getSpriteIcon(
1702 IconUtility::mapFileExtensionToSpriteIconName('folder'),
1703 array('title' => $fileOrFolderObject->getName()),
1704 $overlays);
1705 $itemUid = 'file:' . $fileIdentifier;
1706 } else {
1707 $fileIdentifier = $fileOrFolderObject->getUid();
1708 // File icon:
1709 $fileExtension = $fileOrFolderObject->getExtension();
1710 // Get size and icon:
1711 $size = ' (' . GeneralUtility::formatSize($fileOrFolderObject->getSize()) . 'bytes)';
1712 $icon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileOrFolderObject->getName() . $size));
1713 $itemUid = 'file:' . $fileIdentifier;
1714 }
1715 // If the listed file turns out to be the CURRENT file, then show blinking arrow:
1716 if (($this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder')
1717 && $currentIdentifier == $fileIdentifier
1718 ) {
1719 $arrCol = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif',
1720 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
1721 } else {
1722 $arrCol = '';
1723 }
1724 // Put it all together for the file element:
1725 $out .=
1726 '<img' .
1727 IconUtility::skinImg(
1728 $GLOBALS['BACK_PATH'],
1729 ('gfx/ol/join' . ($c == $totalItems ? 'bottom' : '') . '.gif'),
1730 'width="18" height="16"'
1731 ) . ' alt="" />' . $arrCol .
1732 '<a href="#" onclick="return link_folder(\'' . $itemUid . '\');">' .
1733 $icon .
1734 htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileOrFolderObject->getName(), $titleLen)) .
1735 '</a><br />';
1736 }
1737 }
1738 return $out;
1739 }
1740
1741 /**
1742 * For TYPO3 Element Browser: Expand folder of files.
1743 *
1744 * @param Folder $folder The folder path to expand
1745 * @param string $extensionList List of fileextensions to show
1746 * @param boolean $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
1747 * @return string HTML output
1748 * @todo Define visibility
1749 */
1750 public function TBE_expandFolder(Folder $folder, $extensionList = '', $noThumbs = FALSE) {
1751 if (!$folder->checkActionPermission('read')) {
1752 return '';
1753 }
1754 $extensionList = $extensionList == '*' ? '' : $extensionList;
1755 $files = $this->getFilesInFolder($folder, $extensionList);
1756 return $this->fileList($files, $folder, $noThumbs);
1757 }
1758
1759 /**
1760 * Render list of files.
1761 *
1762 * @param File[] $files List of files
1763 * @param Folder $folder If set a header with a folder icon and folder name are shown
1764 * @param boolean $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
1765 * @return string HTML output
1766 */
1767 protected function fileList(array $files, Folder $folder = NULL, $noThumbs = FALSE) {
1768 $out = '';
1769 $lines = array();
1770 // Create headline (showing number of files):
1771 $filesCount = count($files);
1772 $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', $filesCount));
1773 $out .= '<div id="filelist">';
1774 $out .= $this->getBulkSelector($filesCount);
1775 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1776 // Create the header of current folder:
1777 if ($folder) {
1778 $folderIcon = IconUtility::getSpriteIconForFile('folder');
1779 $lines[] = '<tr class="t3-row-header">
1780 <td colspan="4">' . $folderIcon
1781 . htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</td>
1782 </tr>';
1783 }
1784 if ($filesCount == 0) {
1785 $lines[] = '
1786 <tr class="file_list_normal">
1787 <td colspan="4">No files found.</td>
1788 </tr>';
1789 }
1790 // Init graphic object for reading file dimensions:
1791 /** @var $imgObj \TYPO3\CMS\Core\Imaging\GraphicalFunctions */
1792 $imgObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
1793 $imgObj->init();
1794 $imgObj->mayScaleUp = 0;
1795 $imgObj->tempPath = PATH_site . $imgObj->tempPath;
1796 // Traverse the file list:
1797 foreach ($files as $fileObject) {
1798 $fileExtension = $fileObject->getExtension();
1799 // Thumbnail/size generation:
1800 if (GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($fileExtension)) && !$noThumbs) {
1801 $imageUrl = $fileObject->process(
1802 \TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW,
1803 array('width' => 64, 'height' => 64)
1804 )->getPublicUrl(TRUE);
1805 $imgInfo = $imgObj->getImageDimensions($fileObject->getForLocalProcessing(FALSE));
1806 $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
1807 $clickIcon = '<img src="' . $imageUrl . '" hspace="5" vspace="5" border="1" />';
1808 } else {
1809 $clickIcon = '';
1810 $pDim = '';
1811 }
1812 // Create file icon:
1813 $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
1814 $icon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
1815 // Create links for adding the file:
1816 $filesIndex = count($this->elements);
1817 $this->elements['file_' . $filesIndex] = array(
1818 'type' => 'file',
1819 'table' => 'sys_file',
1820 'uid' => $fileObject->getUid(),
1821 'fileName' => $fileObject->getName(),
1822 'filePath' => $fileObject->getUid(),
1823 'fileExt' => $fileExtension,
1824 'fileIcon' => $icon
1825 );
1826 $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
1827 $ATag_alt = substr($ATag, 0, -4) . ',1);">';
1828 $bulkCheckBox = '<input type="checkbox" class="typo3-bulk-item" name="file_' . $filesIndex . '" value="0" /> ';
1829 $ATag_e = '</a>';
1830 // Create link to showing details about the file in a window:
1831 $Ahref = $GLOBALS['BACK_PATH'] . 'show_item.php?type=file&table=_FILE&uid='
1832 . rawurlencode($fileObject->getCombinedIdentifier())
1833 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
1834 $ATag2 = '<a href="' . htmlspecialchars($Ahref) . '">';
1835 $ATag2_e = '</a>';
1836 // Combine the stuff:
1837 $filenameAndIcon = $bulkCheckBox . $ATag_alt . $icon
1838 . htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
1839 // Show element:
1840 // Image...
1841 if ($pDim) {
1842 $lines[] = '
1843 <tr class="file_list_normal">
1844 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1845 <td>' . $ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
1846 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
1847 . '" alt="" />' . $ATag_e . '</td>
1848 <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
1849 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
1850 . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
1851 . $GLOBALS['LANG']->getLL('info', TRUE) . $ATag2_e) . '</td>
1852 <td nowrap="nowrap">&nbsp;' . $pDim . '</td>
1853 </tr>';
1854 $lines[] = '
1855 <tr>
1856 <td class="filelistThumbnail" colspan="4">' . $ATag_alt . $clickIcon . $ATag_e . '</td>
1857 </tr>';
1858 } else {
1859 $lines[] = '
1860 <tr class="file_list_normal">
1861 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1862 <td>' . $ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
1863 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
1864 . '" alt="" />' . $ATag_e . '</td>
1865 <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
1866 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
1867 . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
1868 . $GLOBALS['LANG']->getLL('info', TRUE) . $ATag2_e) . '</td>
1869 <td>&nbsp;</td>
1870 </tr>';
1871 }
1872 }
1873 // Wrap all the rows in table tags:
1874 $out .= '
1875
1876 <!--
1877 File listing
1878 -->
1879 <table cellpadding="0" cellspacing="0" id="typo3-filelist">
1880 ' . implode('', $lines) . '
1881 </table>';
1882 // Return accumulated content for file listing:
1883 $out .= '</div>';
1884 return $out;
1885 }
1886
1887 /**
1888 * Render list of folders.
1889 *
1890 * @param Folder $baseFolder
1891 * @return string HTML output
1892 * @todo Define visibility
1893 */
1894 public function folderList(Folder $baseFolder) {
1895 $content = '';
1896 $folders = $baseFolder->getSubfolders();
1897 $baseFolderPath = $baseFolder->getPublicUrl();
1898 // Create headline (showing number of folders):
1899 $content .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('folders') . ' (%s):', count($folders)));
1900 $titleLength = intval($GLOBALS['BE_USER']->uc['titleLen']);
1901 // Create the header of current folder:
1902 $aTag = '<a href="#" onclick="return insertElement(\'\',\'' . rawurlencode($baseFolderPath)
1903 . '\', \'folder\', \'' . rawurlencode($baseFolderPath) . '\', unescape(\'' . rawurlencode($baseFolderPath)
1904 . '\'), \'\', \'\',\'\',1);">';
1905 // Add the foder icon
1906 $folderIcon = $aTag;
1907 $folderIcon .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif',
1908 'width="18" height="16"') . ' alt="" />';
1909 $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($baseFolder), $titleLength));
1910 $folderIcon .= '</a>';
1911 $content .= $folderIcon . '<br />';
1912
1913 $lines = array();
1914 // Traverse the folder list:
1915 foreach ($folders as $folderPath) {
1916 $pathInfo = pathinfo($folderPath);
1917 // Create folder icon:
1918 $icon = '<img src="clear.gif" width="16" height="16" alt="" /><img'
1919 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif',
1920 'width="16" height="16"') . ' title="' . htmlspecialchars(($pathInfo['basename']))
1921 . '" class="absmiddle" alt="" />';
1922 // Create links for adding the folder:
1923 if ($this->P['itemName'] != '' && $this->P['formName'] != '') {
1924 $aTag = '<a href="#" onclick="return set_folderpath(unescape(\'' . rawurlencode($folderPath)
1925 . '\'));">';
1926 } else {
1927 $aTag = '<a href="#" onclick="return insertElement(\'\',\'' . rawurlencode($folderPath)
1928 . '\', \'folder\', \'' . rawurlencode($folderPath) . '\', unescape(\''
1929 . rawurlencode($folderPath) . '\'), \'' . $pathInfo['extension'] . '\', \'\');">';
1930 }
1931 if (strstr($folderPath, ',') || strstr($folderPath, '|')) {
1932 // In case an invalid character is in the filepath, display error message:
1933 $errorMessage = $GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('invalidChar'), ', |'));
1934 $aTag = ($aTag_alt = '<a href="#" onclick="alert(' . $errorMessage . ');return false;">');
1935 } else {
1936 // If foldername is OK, just add it:
1937 $aTag_alt = substr($aTag, 0, -4) . ',\'\',1);">';
1938 }
1939 $aTag_e = '</a>';
1940 // Combine icon and folderpath:
1941 $foldernameAndIcon = $aTag_alt . $icon
1942 . htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($folderPath), $titleLength)) . $aTag_e;
1943 if ($this->P['itemName'] != '') {
1944 $lines[] = '
1945 <tr class="bgColor4">
1946 <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
1947 <td>&nbsp;</td>
1948 </tr>';
1949 } else {
1950 $lines[] = '
1951 <tr class="bgColor4">
1952 <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
1953 <td>' . $aTag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
1954 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
1955 . '" alt="" />' . $aTag_e . ' </td>
1956 <td>&nbsp;</td>
1957 </tr>';
1958 }
1959 $lines[] = '
1960 <tr>
1961 <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td>
1962 </tr>';
1963 }
1964 // Wrap all the rows in table tags:
1965 $content .= '
1966
1967 <!--
1968 Folder listing
1969 -->
1970 <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList">
1971 ' . implode('', $lines) . '
1972 </table>';
1973 // Return accumulated content for folderlisting:
1974 return $content;
1975 }
1976
1977 /**
1978 * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images.
1979 * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE
1980 *
1981 * @param Folder $folder The folder path to expand
1982 * @param string $extensionList List of file extensions to show
1983 * @return string HTML output
1984 * @todo Define visibility
1985 */
1986 public function TBE_dragNDrop(Folder $folder, $extensionList = '') {
1987 if (!$folder) {
1988 return '';
1989 }
1990 if (!$folder->getStorage()->isPublic()) {
1991 // Print this warning if the folder is NOT a web folder
1992 return $this->barheader($GLOBALS['LANG']->getLL('files'))
1993 . $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2');
1994 }
1995 $out = '';
1996
1997 // Read files from directory:
1998 $extensionList = $extensionList == '*' ? '' : $extensionList;
1999 $files = $this->getFilesInFolder($folder, $extensionList);
2000
2001 $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files)));
2002 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
2003 $picon = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
2004 $picon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLen));
2005 $out .= $picon . '<br />';
2006 // Init row-array:
2007 $lines = array();
2008 // Add "drag-n-drop" message:
2009 $lines[] = '
2010 <tr>
2011 <td colspan="2">' . $this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')) . '</td>
2012 </tr>';
2013 // Traverse files:
2014 foreach ($files as $fileObject) {
2015 $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
2016 // URL of image:
2017 $iUrl = GeneralUtility::rawurlencodeFP($fileObject->getPublicUrl(TRUE));
2018 // Show only web-images
2019 $fileExtension = strtolower($fileObject->getExtension());
2020 if (GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) {
2021 $imgInfo = @getimagesize($fileObject->getForLocalProcessing(FALSE));
2022 $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
2023 $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
2024 $filenameAndIcon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
2025 if (GeneralUtility::_GP('noLimit')) {
2026 $maxW = 10000;
2027 $maxH = 10000;
2028 } else {
2029 $maxW = 380;
2030 $maxH = 500;
2031 }
2032 $IW = $imgInfo[0];
2033 $IH = $imgInfo[1];
2034 if ($IW > $maxW) {
2035 $IH = ceil($IH / $IW * $maxW);
2036 $IW = $maxW;
2037 }
2038 if ($IH > $maxH) {
2039 $IW = ceil($IW / $IH * $maxH);
2040 $IH = $maxH;
2041 }
2042 // Make row:
2043 $lines[] = '
2044 <tr class="bgColor4">
2045 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
2046 <td nowrap="nowrap">' . ($imgInfo[0] != $IW
2047 ? '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('noLimit' => '1')))
2048 . '">' . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning2.gif',
2049 'width="18" height="16"') . ' title="'
2050 . $GLOBALS['LANG']->getLL('clickToRedrawFullSize', TRUE) . '" alt="" />' . '</a>'
2051 : '')
2052 . $pDim . '&nbsp;</td>
2053 </tr>';
2054 $lines[] = '
2055 <tr>
2056 <td colspan="2"><img src="' . $iUrl . '" data-htmlarea-file-uid="' . $fileObject->getUid()
2057 . '" width="' . $IW . '" height="' . $IH . '" border="1" alt="" /></td>
2058 </tr>';
2059 $lines[] = '
2060 <tr>
2061 <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
2062 </tr>';
2063 }
2064 }
2065 // Finally, wrap all rows in a table tag:
2066 $out .= '
2067
2068
2069 <!--
2070 File listing / Drag-n-drop
2071 -->
2072 <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
2073 ' . implode('', $lines) . '
2074 </table>';
2075
2076 return $out;
2077 }
2078
2079 /******************************************************************
2080 *
2081 * Miscellaneous functions
2082 *
2083 ******************************************************************/
2084 /**
2085 * Verifies that a path is a web-folder:
2086 *
2087 * @param string $folder Absolute filepath
2088 * @return boolean If the input path is found in PATH_site then it returns TRUE.
2089 * @todo Define visibility
2090 */
2091 public function isWebFolder($folder) {
2092 $folder = rtrim($folder, '/') . '/';
2093 return GeneralUtility::isFirstPartOfStr($folder, PATH_site) ? TRUE : FALSE;
2094 }
2095
2096 /**
2097 * Checks, if a path is within the mountpoints of the backend user
2098 *
2099 * @param string $folder Absolute filepath
2100 * @return boolean If the input path is found in the backend users filemounts, then return TRUE.
2101 * @todo Define visibility
2102 */
2103 public function checkFolder($folder) {
2104 return $this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/') ? TRUE : FALSE;
2105 }
2106
2107 /**
2108 * Prints a 'header' where string is in a tablecell
2109 *
2110 * @param string $str The string to print in the header. The value is htmlspecialchars()'ed before output.
2111 * @return string The header HTML (wrapped in a table)
2112 * @todo Define visibility
2113 */
2114 public function barheader($str) {
2115 return '
2116 <!-- Bar header: -->
2117 <h3>' . htmlspecialchars($str) . '</h3>
2118 ';
2119 }
2120
2121 /**
2122 * Displays a message box with the input message
2123 *
2124 * @param string $in_msg Input message to show (will be htmlspecialchars()'ed inside of this function)
2125 * @param string $icon Icon filename body from gfx/ (default is "icon_note") - meant to allow change to warning type icons...
2126 * @return string HTML for the message (wrapped in a table).
2127 * @todo Define visibility
2128 */
2129 public function getMsgBox($in_msg, $icon = 'icon_note') {
2130 $msg = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/' . $icon . '.gif'), 'width="18" height="16"')
2131 . ' alt="" />' . htmlspecialchars($in_msg);
2132 $msg = '
2133
2134 <!--
2135 Message box:
2136 -->
2137 <table cellspacing="0" class="bgColor4" id="typo3-msgBox">
2138 <tr>
2139 <td>' . $msg . '</td>
2140 </tr>
2141 </table>
2142 ';
2143 return $msg;
2144 }
2145
2146 /**
2147 * For RTE/link: This prints the 'currentUrl'
2148 *
2149 * @param string $str URL value. The value is htmlspecialchars()'ed before output.
2150 * @return string HTML content, wrapped in a table.
2151 * @todo Define visibility
2152 */
2153 public function printCurrentUrl($str) {
2154 // Output the folder or file identifier, when working with files
2155 if (isset($str) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($str)
2156 && ($this->act === 'file' || $this->act === 'folder')
2157 ) {
2158 try {
2159 $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($str);
2160 } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
2161 $fileObject = NULL;
2162 }
2163 $str = is_object($fileObject) ? $fileObject->getIdentifier() : '';
2164 }
2165 if (strlen($str)) {
2166 return '
2167 <!-- Print current URL -->
2168 <table border="0" cellpadding="0" cellspacing="0" id="typo3-curUrl">
2169 <tr>
2170 <td>' . $GLOBALS['LANG']->getLL('currentLink', TRUE) . ': '
2171 . htmlspecialchars(rawurldecode($str)) . '</td>
2172 </tr>
2173 </table>';
2174 } else {
2175 return '';
2176 }
2177 }
2178
2179 /**
2180 * For RTE/link: Parses the incoming URL and determines if it's a page, file, external or mail address.
2181 *
2182 * @param string $href HREF value tp analyse
2183 * @param string $siteUrl The URL of the current website (frontend)
2184 * @return array Array with URL information stored in assoc. keys: value, act (page, file, spec, mail), pageid, cElement, info
2185 * @todo Define visibility
2186 */
2187 public function parseCurUrl($href, $siteUrl) {
2188 $href = trim($href);
2189 if ($href) {
2190 $info = array();
2191 // Default is "url":
2192 $info['value'] = $href;
2193 $info['act'] = 'url';
2194 $specialParts = explode('#_SPECIAL', $href);
2195 // Special kind (Something RTE specific: User configurable links through: "userLinks." from ->thisConfig)
2196 if (count($specialParts) == 2) {
2197 $info['value'] = '#_SPECIAL' . $specialParts[1];
2198 $info['act'] = 'spec';
2199 } elseif (strpos($href, 'file:') !== FALSE) {
2200 $rel = substr($href, strpos($href, 'file:') + 5);
2201 $rel = rawurldecode($rel);
2202 // resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier"
2203 $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($rel);
2204 if ($fileOrFolderObject instanceof Folder) {
2205 $info['act'] = 'folder';
2206 $info['value'] = $fileOrFolderObject->getCombinedIdentifier();
2207 } elseif ($fileOrFolderObject instanceof File) {
2208 $info['act'] = 'file';
2209 $info['value'] = $fileOrFolderObject->getUid();
2210 } else {
2211 $info['value'] = $rel;
2212 }
2213 } elseif (GeneralUtility::isFirstPartOfStr($href, $siteUrl)) {
2214 // If URL is on the current frontend website:
2215 // URL is a file, which exists:
2216 if (file_exists(PATH_site . rawurldecode($href))) {
2217 $info['value'] = rawurldecode($href);
2218 if (@is_dir((PATH_site . $info['value']))) {
2219 $info['act'] = 'folder';
2220 } else {
2221 $info['act'] = 'file';
2222 }
2223 } else {
2224 // URL is a page (id parameter)
2225 $uP = parse_url($href);
2226
2227 $pp = preg_split('/^id=/', $uP['query']);
2228 $pp[1] = preg_replace('/&id=[^&]*/', '', $pp[1]);
2229 $parameters = explode('&', $pp[1]);
2230 $id = array_shift($parameters);
2231 if ($id) {
2232 // Checking if the id-parameter is an alias.
2233 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($id)) {
2234 list($idPartR) = BackendUtility::getRecordsByField('pages', 'alias', $id);
2235 $id = intval($idPartR['uid']);
2236 }
2237 $pageRow = BackendUtility::getRecordWSOL('pages', $id);
2238 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
2239 $info['value'] = ((((($GLOBALS['LANG']->getLL('page', TRUE) . ' \'')
2240 . htmlspecialchars(GeneralUtility::fixed_lgd_cs($pageRow['title'], $titleLen)))
2241 . '\' (ID:') . $id) . ($uP['fragment'] ? ', #' . $uP['fragment'] : '')) . ')';
2242 $info['pageid'] = $id;
2243 $info['cElement'] = $uP['fragment'];
2244 $info['act'] = 'page';
2245 $info['query'] = $parameters[0] ? '&' . implode('&', $parameters) : '';
2246 }
2247 }
2248 } else {
2249 // Email link:
2250 if (strtolower(substr($href, 0, 7)) == 'mailto:') {
2251 $info['value'] = trim(substr($href, 7));
2252 $info['act'] = 'mail';
2253 }
2254 }
2255 $info['info'] = $info['value'];
2256 } else {
2257 // NO value inputted:
2258 $info = array();
2259 $info['info'] = $GLOBALS['LANG']->getLL('none');
2260 $info['value'] = '';
2261 $info['act'] = 'page';
2262 }
2263 // let the hook have a look
2264 foreach ($this->hookObjects as $hookObject) {
2265 $info = $hookObject->parseCurrentUrl($href, $siteUrl, $info);
2266 }
2267 return $info;
2268 }
2269
2270 /**
2271 * Setter for the class that should be used by TBE_expandPage()
2272 * to generate the record list.
2273 *
2274 * @param \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList $recordList
2275 * @throws \InvalidArgumentException
2276 * @return void
2277 */
2278 public function setRecordList($recordList) {
2279 if (!$recordList instanceof \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList) {
2280 throw new \InvalidArgumentException('$recordList needs to be an instance of \\TYPO3\\CMS\\Backend\\RecordList\\ElementBrowserRecordList', 1370878522);
2281 }
2282 $this->recordList = $recordList;
2283 }
2284
2285 /**
2286 * For TBE: Makes an upload form for uploading files to the filemount the user is browsing.
2287 * The files are uploaded to the tce_file.php script in the core which will handle the upload.
2288 *
2289 * @param Folder $folderObject Absolute filepath on server to which to upload.
2290 * @return string HTML for an upload form.
2291 * @todo Define visibility
2292 */
2293 public function uploadForm(Folder $folderObject) {
2294 if (!$folderObject->checkActionPermission('write')) {
2295 return '';
2296 }
2297 // Read configuration of upload field count
2298 $userSetting = $GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
2299 $count = isset($userSetting) ? $userSetting : 3;
2300 if ($count === '0') {
2301 return '';
2302 }
2303 $count = intval($count) == 0 ? 3 : intval($count);
2304 // Create header, showing upload path:
2305 $header = $folderObject->getIdentifier();
2306 $code = '
2307 <br />
2308 <!--
2309 Form, for uploading files:
2310 -->
2311 <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform"'
2312 . 'id="typo3-uplFilesForm" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">
2313 <table border="0" cellpadding="0" cellspacing="0" id="typo3-uplFiles">
2314 <tr>
2315 <td>' . $this->barheader($GLOBALS['LANG']->sL(
2316 'LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle', TRUE) . ':') . '</td>
2317 </tr>
2318 <tr>
2319 <td class="c-wCell c-hCell"><strong>' . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> '
2320 . htmlspecialchars($header) . '</td>
2321 </tr>
2322 <tr>
2323 <td class="c-wCell c-hCell">';
2324 // Traverse the number of upload fields (default is 3):
2325 for ($a = 1; $a <= $count; $a++) {
2326 $code .= '<input type="file" multiple="multiple" name="upload_' . $a . '"' . $this->doc->formWidth(35)
2327 . ' size="50" />
2328 <input type="hidden" name="file[upload][' . $a . '][target]" value="'
2329 . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />
2330 <input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br />';
2331 }
2332 // Make footer of upload form, including the submit button:
2333 $redirectValue = $this->thisScript . '?act=' . $this->act . '&mode=' . $this->mode
2334 . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier())
2335 . '&bparams=' . rawurlencode($this->bparams);
2336 $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
2337 $code .= '
2338 <div id="c-override">
2339 <label><input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> '
2340 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', TRUE) . '</label>
2341 </div>
2342 <input type="submit" name="submit" value="'
2343 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', TRUE) . '" />
2344 ';
2345 $code .= '</td>
2346 </tr>
2347 </table>
2348 </form><br />';
2349 return $code;
2350 }
2351
2352 /**
2353 * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
2354 * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
2355 *
2356 * @param Folder $folderObject Absolute filepath on server in which to create the new folder.
2357 * @return string HTML for the create folder form.
2358 * @todo Define visibility
2359 */
2360 public function createFolder(Folder $folderObject) {
2361 if (!$folderObject->checkActionPermission('write')) {
2362 return '';
2363 }
2364 if (!($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB'))) {
2365 return '';
2366 }
2367 // Don't show Folder-create form if it's denied
2368 if ($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.hideCreateFolder')) {
2369 return '';
2370 }
2371 // Create header, showing upload path:
2372 $header = $folderObject->getIdentifier();
2373 $code = '
2374
2375 <!--
2376 Form, for creating new folders:
2377 -->
2378 <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform2" id="typo3-crFolderForm">
2379 <table border="0" cellpadding="0" cellspacing="0" id="typo3-crFolder">
2380 <tr>
2381 <td>' . $this->barheader($GLOBALS['LANG']->sL(
2382 'LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle') . ':') . '</td>
2383 </tr>
2384 <tr>
2385 <td class="c-wCell c-hCell"><strong>'
2386 . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> ' . htmlspecialchars($header) . '</td>
2387 </tr>
2388 <tr>
2389 <td class="c-wCell c-hCell">';
2390 // Create the new-folder name field:
2391 $a = 1;
2392 $code .= '<input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" />'
2393 . '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="'
2394 . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
2395 // Make footer of upload form, including the submit button:
2396 $redirectValue = $this->thisScript . '?act=' . $this->act . '&mode=' . $this->mode
2397 . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier())
2398 . '&bparams=' . rawurlencode($this->bparams);
2399 $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />'
2400 . '<input type="submit" name="submit" value="'
2401 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', TRUE) . '" />';
2402 $code .= '</td>
2403 </tr>
2404 </table>
2405 </form>';
2406 return $code;
2407 }
2408
2409 /**
2410 * Get the HTML data required for a bulk selection of files of the TYPO3 Element Browser.
2411 *
2412 * @param integer $filesCount Number of files currently displayed
2413 * @return string HTML data required for a bulk selection of files - if $filesCount is 0, nothing is returned
2414 * @todo Define visibility
2415 */
2416 public function getBulkSelector($filesCount) {
2417 if (!$filesCount) {
2418 return '';
2419 }
2420
2421 $labelToggleSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:toggleSelection', TRUE);
2422 $labelImportSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:importSelection', TRUE);
2423 // Getting flag for showing/not showing thumbnails:
2424 $noThumbsInEB = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
2425 $out = $this->doc->spacer(10) . '<div>' . '<a href="#" onclick="BrowseLinks.Selector.handle()">'
2426 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/import.gif', 'width="12" height="12"')
2427 . ' title="' . $labelImportSelection . '" alt="" /> ' . $labelImportSelection . '</a>&nbsp;&nbsp;&nbsp;'
2428 . '<a href="#" onclick="BrowseLinks.Selector.toggle()">' . '<img'
2429 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/clip_select.gif', 'width="12" height="12"')
2430 . ' title="' . $labelToggleSelection . '" alt="" /> ' . $labelToggleSelection . '</a>' . '</div>';
2431 $thumbNailCheck = '';
2432 if (!$noThumbsInEB && $this->selectedFolder) {
2433 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
2434 $_MOD_MENU = array('displayThumbs' => '');
2435 $_MCONF['name'] = 'file_list';
2436 $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']);
2437 $addParams = '&act=' . $this->act . '&mode=' . $this->mode
2438 . '&expandFolder=' . rawurlencode($this->selectedFolder->getCombinedIdentifier())
2439 . '&bparams=' . rawurlencode($this->bparams);
2440 $thumbNailCheck = BackendUtility::getFuncCheck('', 'SET[displayThumbs]', $_MOD_SETTINGS['displayThumbs'],
2441 $this->thisScript, $addParams, 'id="checkDisplayThumbs"')
2442 . ' <label for="checkDisplayThumbs">'
2443 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:displayThumbs', TRUE) . '</label>';
2444 $out .= $this->doc->spacer(5) . $thumbNailCheck . $this->doc->spacer(15);
2445 } else {
2446 $out .= $this->doc->spacer(15);
2447 }
2448 return $out;
2449 }
2450
2451 /**
2452 * Determines whether submitted field change functions are valid
2453 * and are coming from the system and not from an external abuse.
2454 *
2455 * @param boolean $handleFlexformSections Whether to handle flexform sections differently
2456 * @return boolean Whether the submitted field change functions are valid
2457 */
2458 protected function areFieldChangeFunctionsValid($handleFlexformSections = FALSE) {
2459 $result = FALSE;
2460 if (isset($this->P['fieldChangeFunc']) && is_array($this->P['fieldChangeFunc']) && isset($this->P['fieldChangeFuncHash'])) {
2461 $matches = array();
2462 $pattern = '#\\[el\\]\\[(([^]-]+-[^]-]+-)(idx\\d+-)([^]]+))\\]#i';
2463 $fieldChangeFunctions = $this->P['fieldChangeFunc'];
2464 // Special handling of flexform sections:
2465 // Field change functions are modified in JavaScript, thus the hash is always invalid
2466 if ($handleFlexformSections && preg_match($pattern, $this->P['itemName'], $matches)) {
2467 $originalName = $matches[1];
2468 $cleanedName = $matches[2] . $matches[4];
2469 foreach ($fieldChangeFunctions as &$value) {
2470 $value = str_replace($originalName, $cleanedName, $value);
2471 }
2472 unset($value);
2473 }
2474 $result = $this->P['fieldChangeFuncHash'] === GeneralUtility::hmac(serialize($fieldChangeFunctions));
2475 }
2476 return $result;
2477 }
2478
2479 /**
2480 * Get a list of Files in a folder filtered by extension
2481 *
2482 * @param \TYPO3\CMS\Core\Resource\Folder $folder
2483 * @param string $extensionList
2484 * @return \TYPO3\CMS\Core\Resource\File[]
2485 */
2486 protected function getFilesInFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList) {
2487 if ($extensionList !== '') {
2488 /** @var \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter $filter */
2489 $filter = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
2490 $filter->setAllowedFileExtensions($extensionList);
2491 $folder->setFileAndFolderNameFilters(array(array($filter, 'filterFileList')));
2492 }
2493 return $folder->getFiles();
2494 }
2495
2496 }