[TASK] Remove duplicated method in Rtehtmlarea\SelectImage
[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 = (int)$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 ((int)$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']) || ((int)$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 // Add the FlashMessages if any
1373 $content .= $this->doc->getFlashMessages();
1374
1375 // Putting the parts together, side by side:
1376 $content .= '
1377
1378 <!--
1379 Wrapper table for folder tree / file list:
1380 -->
1381 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1382 <tr>
1383 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':'))
1384 . $tree . '</td>
1385 <td class="c-wCell" valign="top">' . $files . '</td>
1386 </tr>
1387 </table>
1388 ';
1389 // Adding create folder + upload forms if applicable:
1390 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1391 $content .= $uploadForm;
1392 }
1393 $content .= $createFolder;
1394 // Add some space
1395 $content .= '<br /><br />';
1396 // Setup indexed elements:
1397 $this->doc->JScode .= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
1398 // Ending page, returning content:
1399 $content .= $this->doc->endPage();
1400 $content = $this->doc->insertStylesAndJS($content);
1401 return $content;
1402 }
1403
1404 /**
1405 * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for folders.
1406 *
1407 * @return string HTML content for the module
1408 * @todo Define visibility
1409 */
1410 public function main_folder() {
1411 // include JS files
1412 $this->doc->getDragDropCode('folders');
1413 // Setting prefs for foldertree
1414 $this->doc->JScode .= $this->doc->wrapScriptTags('
1415 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1416 ');
1417 // Starting content:
1418 $content = $this->doc->startPage('TBE folder selector');
1419 // Init variable:
1420 $parameters = explode('|', $this->bparams);
1421 if ($this->expandFolder) {
1422 $this->selectedFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
1423 }
1424 if ($this->selectedFolder) {
1425 $createFolder = $this->createFolder($this->selectedFolder);
1426 } else {
1427 $createFolder = '';
1428 }
1429 // Create folder tree:
1430 $folderTree = GeneralUtility::makeInstance('TBE_FolderTree');
1431 $folderTree->thisScript = $this->thisScript;
1432 $folderTree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1433 $tree = $folderTree->getBrowsableTree(FALSE);
1434 list(, , $specUid) = explode('_', $this->PM);
1435 if ($this->mode == 'filedrag') {
1436 $folders = $this->TBE_dragNDrop($this->selectedFolder, $parameters[3]);
1437 } else {
1438 $folders = $this->TBE_expandSubFolders($this->selectedFolder);
1439 }
1440 // Putting the parts together, side by side:
1441 $content .= '
1442
1443 <!--
1444 Wrapper table for folder tree / folder list:
1445 -->
1446 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1447 <tr>
1448 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':'))
1449 . $tree . '</td>
1450 <td class="c-wCell" valign="top">' . $folders . '</td>
1451 </tr>
1452 </table>
1453 ';
1454 // Adding create folder if applicable:
1455 $content .= $createFolder;
1456 // Add some space
1457 $content .= '<br /><br />';
1458 // Ending page, returning content:
1459 $content .= $this->doc->endPage();
1460 $content = $this->doc->insertStylesAndJS($content);
1461 return $content;
1462 }
1463
1464 /******************************************************************
1465 *
1466 * Record listing
1467 *
1468 ******************************************************************/
1469 /**
1470 * For RTE: This displays all content elements on a page and lets you create a link to the element.
1471 *
1472 * @return string HTML output. Returns content only if the ->expandPage value is set (pointing to a page uid to show tt_content records from ...)
1473 * @todo Define visibility
1474 */
1475 public function expandPage() {
1476 $out = '';
1477 // Set page id (if any) to expand
1478 $expPageId = $this->expandPage;
1479 // If there is an anchor value (content element reference) in the element reference, then force an ID to expand:
1480 if (!$this->expandPage && $this->curUrlInfo['cElement']) {
1481 // Set to the current link page id.
1482 $expPageId = $this->curUrlInfo['pageid'];
1483 }
1484 // Draw the record list IF there is a page id to expand:
1485 if ($expPageId
1486 && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($expPageId)
1487 && $GLOBALS['BE_USER']->isInWebMount($expPageId)
1488 ) {
1489 // Set header:
1490 $out .= $this->barheader($GLOBALS['LANG']->getLL('contentElements') . ':');
1491 // Create header for listing, showing the page title/icon:
1492 $mainPageRec = BackendUtility::getRecordWSOL('pages', $expPageId);
1493 $picon = IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1494 $picon .= BackendUtility::getRecordTitle('pages', $mainPageRec, TRUE);
1495 $out .= $picon . '<br />';
1496 // Look up tt_content elements from the expanded page:
1497 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1498 'uid,header,hidden,starttime,endtime,fe_group,CType,colPos,bodytext',
1499 'tt_content',
1500 'pid=' . (int)$expPageId . BackendUtility::deleteClause('tt_content')
1501 . BackendUtility::versioningPlaceholderClause('tt_content'),
1502 '',
1503 'colPos,sorting'
1504 );
1505 $cc = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
1506 // Traverse list of records:
1507 $c = 0;
1508 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1509 $c++;
1510 $icon = IconUtility::getSpriteIconForRecord('tt_content', $row);
1511 if ($this->curUrlInfo['act'] == 'page' && $this->curUrlInfo['cElement'] == $row['uid']) {
1512 $arrCol = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"')
1513 . ' class="c-blinkArrowL" alt="" />';
1514 } else {
1515 $arrCol = '';
1516 }
1517 // Putting list element HTML together:
1518 $out .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join' . ($c == $cc ? 'bottom' : '')
1519 . '.gif'), 'width="18" height="16"') . ' alt="" />' . $arrCol
1520 . '<a href="#" onclick="return link_typo3Page(\'' . $expPageId . '\',\'#' . $row['uid'] . '\');">'
1521 . $icon . BackendUtility::getRecordTitle('tt_content', $row, TRUE) . '</a><br />';
1522 // Finding internal anchor points:
1523 if (GeneralUtility::inList('text,textpic', $row['CType'])) {
1524 $split = preg_split('/(<a[^>]+name=[\'"]?([^"\'>[:space:]]+)[\'"]?[^>]*>)/i', $row['bodytext'], -1, PREG_SPLIT_DELIM_CAPTURE);
1525 foreach ($split as $skey => $sval) {
1526 if ($skey % 3 == 2) {
1527 // Putting list element HTML together:
1528 $sval = substr($sval, 0, 100);
1529 $out .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/ol/line.gif',
1530 'width="18" height="16"') . ' alt="" />'
1531 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join'
1532 . ($skey + 3 > count($split) ? 'bottom' : '') . '.gif'), 'width="18" height="16"')
1533 . ' alt="" />' . '<a href="#" onclick="return link_typo3Page(\'' . $expPageId
1534 . '\',\'#' . rawurlencode($sval) . '\');">' . htmlspecialchars((' <A> ' . $sval))
1535 . '</a><br />';
1536 }
1537 }
1538 }
1539 }
1540 }
1541 return $out;
1542 }
1543
1544 /**
1545 * For TYPO3 Element Browser: This lists all content elements from the given list of tables
1546 *
1547 * @param string $tables Comma separated list of tables. Set to "*" if you want all tables.
1548 * @return string HTML output.
1549 * @todo Define visibility
1550 */
1551 public function TBE_expandPage($tables) {
1552 $out = '';
1553 if ($this->expandPage >= 0
1554 && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->expandPage)
1555 && $GLOBALS['BE_USER']->isInWebMount($this->expandPage)
1556 ) {
1557 // Set array with table names to list:
1558 if (trim($tables) === '*') {
1559 $tablesArr = array_keys($GLOBALS['TCA']);
1560 } else {
1561 $tablesArr = GeneralUtility::trimExplode(',', $tables, TRUE);
1562 }
1563 reset($tablesArr);
1564 // Headline for selecting records:
1565 $out .= $this->barheader($GLOBALS['LANG']->getLL('selectRecords') . ':');
1566 // Create the header, showing the current page for which the listing is.
1567 // Includes link to the page itself, if pages are amount allowed tables.
1568 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
1569 $mainPageRec = BackendUtility::getRecordWSOL('pages', $this->expandPage);
1570 $ATag = '';
1571 $ATag_e = '';
1572 $ATag2 = '';
1573 $picon = '';
1574 if (is_array($mainPageRec)) {
1575 $picon = IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1576 if (in_array('pages', $tablesArr)) {
1577 $ATag = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', '
1578 . GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',1);">';
1579 $ATag2 = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', '
1580 . GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',0);">';
1581 $ATag_e = '</a>';
1582 }
1583 }
1584 $pBicon = $ATag2 ? '<img'
1585 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif', 'width="18" height="16"')
1586 . ' alt="" />' : '';
1587 $pText = htmlspecialchars(GeneralUtility::fixed_lgd_cs($mainPageRec['title'], $titleLen));
1588 $out .= $picon . $ATag2 . $pBicon . $ATag_e . $ATag . $pText . $ATag_e . '<br />';
1589 // Initialize the record listing:
1590 $id = $this->expandPage;
1591 $pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
1592 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1593 $pageInfo = BackendUtility::readPageAccess($id, $perms_clause);
1594 // Generate the record list:
1595 /** @var $dbList \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList */
1596 if (is_object($this->recordList)) {
1597 $dbList = $this->recordList;
1598 } else {
1599 $dbList = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\RecordList\\ElementBrowserRecordList');
1600 }
1601 $dbList->thisScript = $this->thisScript;
1602 $dbList->backPath = $GLOBALS['BACK_PATH'];
1603 $dbList->thumbs = 0;
1604 $dbList->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageInfo);
1605 $dbList->noControlPanels = 1;
1606 $dbList->clickMenuEnabled = 0;
1607 $dbList->tableList = implode(',', $tablesArr);
1608 $pArr = explode('|', $this->bparams);
1609 // a string like "data[pages][79][storage_pid]"
1610 $fieldPointerString = $pArr[0];
1611 // parts like: data, pages], 79], storage_pid]
1612 $fieldPointerParts = explode('[', $fieldPointerString);
1613 $relatingTableName = substr($fieldPointerParts[1], 0, -1);
1614 $relatingFieldName = substr($fieldPointerParts[3], 0, -1);
1615 if ($relatingTableName && $relatingFieldName) {
1616 $dbList->setRelatingTableAndField($relatingTableName, $relatingFieldName);
1617 }
1618 $dbList->start($id, GeneralUtility::_GP('table'), $pointer, GeneralUtility::_GP('search_field'),
1619 GeneralUtility::_GP('search_levels'), GeneralUtility::_GP('showLimit')
1620 );
1621 $dbList->setDispFields();
1622 $dbList->generateList();
1623 // Add the HTML for the record list to output variable:
1624 $out .= $dbList->HTMLcode;
1625 // Add support for fieldselectbox in singleTableMode
1626 if ($dbList->table) {
1627 $out .= $dbList->fieldSelectBox($dbList->table);
1628 }
1629 $out .= $dbList->getSearchBox();
1630 }
1631 // Return accumulated content:
1632 return $out;
1633 }
1634
1635 /**
1636 * Render list of folders inside a folder.
1637 *
1638 * @param Folder $folder Folder
1639 * @return string HTML output
1640 * @todo Define visibility
1641 */
1642 public function TBE_expandSubFolders(Folder $folder) {
1643 $content = '';
1644 if ($folder->checkActionPermission('read')) {
1645 $content .= $this->folderList($folder);
1646 }
1647 // Return accumulated content for folderlisting:
1648 return $content;
1649 }
1650
1651 /******************************************************************
1652 *
1653 * File listing
1654 *
1655 ******************************************************************/
1656 /**
1657 * For RTE: This displays all files from folder. No thumbnails shown
1658 *
1659 * @param Folder $folder The folder path to expand
1660 * @param string $extensionList List of file extensions to show
1661 * @return string HTML output
1662 * @todo Define visibility
1663 */
1664 public function expandFolder(Folder $folder, $extensionList = '') {
1665 $out = '';
1666 $renderFolders = $this->act === 'folder';
1667 if ($folder->checkActionPermission('read')) {
1668 // Create header for file listing:
1669 $out .= $this->barheader($GLOBALS['LANG']->getLL('files') . ':');
1670 // Prepare current path value for comparison (showing red arrow)
1671 $currentIdentifier = '';
1672 if ($this->curUrlInfo['value']) {
1673 $currentIdentifier = $this->curUrlInfo['info'];
1674 }
1675 // Create header element; The folder from which files are listed.
1676 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
1677 $folderIcon = IconUtility::getSpriteIconForFile('folder');
1678 $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen));
1679 $picon = '<a href="#" onclick="return link_folder(\'file:' . $folder->getCombinedIdentifier() . '\');">'
1680 . $folderIcon . '</a>';
1681 if ($this->curUrlInfo['act'] == 'folder' && $currentIdentifier == $folder->getCombinedIdentifier()) {
1682 $out .= '<img'
1683 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"')
1684 . ' class="c-blinkArrowL" alt="" />';
1685 }
1686 $out .= $picon . '<br />';
1687 // Get files from the folder:
1688 if ($renderFolders) {
1689 $items = $folder->getSubfolders();
1690 } else {
1691 $items = $this->getFilesInFolder($folder, $extensionList);
1692 }
1693 $c = 0;
1694 $totalItems = count($items);
1695 foreach ($items as $fileOrFolderObject) {
1696 $c++;
1697 if ($renderFolders) {
1698 $fileIdentifier = $fileOrFolderObject->getCombinedIdentifier();
1699 $overlays = array();
1700 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder) {
1701 $overlays = array('status-overlay-locked' => array());
1702 }
1703 $icon = IconUtility::getSpriteIcon(
1704 IconUtility::mapFileExtensionToSpriteIconName('folder'),
1705 array('title' => $fileOrFolderObject->getName()),
1706 $overlays);
1707 $itemUid = 'file:' . $fileIdentifier;
1708 } else {
1709 $fileIdentifier = $fileOrFolderObject->getUid();
1710 // File icon:
1711 $fileExtension = $fileOrFolderObject->getExtension();
1712 // Get size and icon:
1713 $size = ' (' . GeneralUtility::formatSize($fileOrFolderObject->getSize()) . 'bytes)';
1714 $icon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileOrFolderObject->getName() . $size));
1715 $itemUid = 'file:' . $fileIdentifier;
1716 }
1717 // If the listed file turns out to be the CURRENT file, then show blinking arrow:
1718 if (($this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder')
1719 && $currentIdentifier == $fileIdentifier
1720 ) {
1721 $arrCol = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif',
1722 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
1723 } else {
1724 $arrCol = '';
1725 }
1726 // Put it all together for the file element:
1727 $out .=
1728 '<img' .
1729 IconUtility::skinImg(
1730 $GLOBALS['BACK_PATH'],
1731 ('gfx/ol/join' . ($c == $totalItems ? 'bottom' : '') . '.gif'),
1732 'width="18" height="16"'
1733 ) . ' alt="" />' . $arrCol .
1734 '<a href="#" onclick="return link_folder(\'' . $itemUid . '\');">' .
1735 $icon .
1736 htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileOrFolderObject->getName(), $titleLen)) .
1737 '</a><br />';
1738 }
1739 }
1740 return $out;
1741 }
1742
1743 /**
1744 * For TYPO3 Element Browser: Expand folder of files.
1745 *
1746 * @param Folder $folder The folder path to expand
1747 * @param string $extensionList List of fileextensions to show
1748 * @param boolean $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
1749 * @return string HTML output
1750 * @todo Define visibility
1751 */
1752 public function TBE_expandFolder(Folder $folder, $extensionList = '', $noThumbs = FALSE) {
1753 if (!$folder->checkActionPermission('read')) {
1754 return '';
1755 }
1756 $extensionList = $extensionList == '*' ? '' : $extensionList;
1757 $files = $this->getFilesInFolder($folder, $extensionList);
1758 return $this->fileList($files, $folder, $noThumbs);
1759 }
1760
1761 /**
1762 * Render list of files.
1763 *
1764 * @param File[] $files List of files
1765 * @param Folder $folder If set a header with a folder icon and folder name are shown
1766 * @param boolean $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
1767 * @return string HTML output
1768 */
1769 protected function fileList(array $files, Folder $folder = NULL, $noThumbs = FALSE) {
1770 $out = '';
1771
1772 $lines = array();
1773 // Create headline (showing number of files):
1774 $filesCount = count($files);
1775 $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', $filesCount));
1776 $out .= '<div id="filelist">';
1777 $out .= $this->getBulkSelector($filesCount);
1778 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
1779 // Create the header of current folder:
1780 if ($folder) {
1781 $folderIcon = IconUtility::getSpriteIconForFile('folder');
1782 $lines[] = '<tr class="t3-row-header">
1783 <td colspan="4">' . $folderIcon
1784 . htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</td>
1785 </tr>';
1786 }
1787 if ($filesCount == 0) {
1788 $lines[] = '
1789 <tr class="file_list_normal">
1790 <td colspan="4">No files found.</td>
1791 </tr>';
1792 }
1793 // Init graphic object for reading file and image dimensions:
1794 /** @var $imgObj \TYPO3\CMS\Core\Imaging\GraphicalFunctions */
1795 $imgObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
1796 $imgObj->init();
1797 $imgObj->mayScaleUp = 0;
1798 $imgObj->tempPath = PATH_site . $imgObj->tempPath;
1799 // Traverse the file list:
1800 /** @var $fileObject \TYPO3\CMS\Core\Resource\File */
1801 foreach ($files as $fileObject) {
1802 $fileExtension = $fileObject->getExtension();
1803 // Thumbnail/size generation:
1804 if (GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($fileExtension)) && !$noThumbs) {
1805 $imageUrl = $fileObject->process(
1806 \TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW,
1807 array('width' => 64, 'height' => 64)
1808 )->getPublicUrl(TRUE);
1809 $imgInfo = $imgObj->getImageDimensions($fileObject->getForLocalProcessing(FALSE));
1810 $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
1811 $clickIcon = '<img src="' . $imageUrl . '" hspace="5" vspace="5" border="1" />';
1812 } else {
1813 $clickIcon = '';
1814 $pDim = '';
1815 }
1816 // Create file icon:
1817 $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
1818 $icon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
1819 // Create links for adding the file:
1820 $filesIndex = count($this->elements);
1821 $this->elements['file_' . $filesIndex] = array(
1822 'type' => 'file',
1823 'table' => 'sys_file',
1824 'uid' => $fileObject->getUid(),
1825 'fileName' => $fileObject->getName(),
1826 'filePath' => $fileObject->getUid(),
1827 'fileExt' => $fileExtension,
1828 'fileIcon' => $icon
1829 );
1830 if ($this->act === 'plain' && ($imgInfo[0] > $this->plainMaxWidth || $imgInfo[1] > $this->plainMaxHeight) || !GeneralUtility::inList('jpg,jpeg,gif,png', $fileExtension)) {
1831 $ATag = '';
1832 $ATag_alt = '';
1833 $ATag_e = '';
1834 $bulkCheckBox = '';
1835 } else {
1836 $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
1837 $ATag_alt = substr($ATag, 0, -4) . ',1);">';
1838 $bulkCheckBox = '<input type="checkbox" class="typo3-bulk-item" name="file_' . $filesIndex . '" value="0" /> ';
1839 $ATag_e = '</a>';
1840 }
1841 // Create link to showing details about the file in a window:
1842 $Ahref = $GLOBALS['BACK_PATH'] . 'show_item.php?type=file&table=_FILE&uid='
1843 . rawurlencode($fileObject->getCombinedIdentifier())
1844 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
1845 $ATag2 = '<a href="' . htmlspecialchars($Ahref) . '">';
1846 $ATag2_e = '</a>';
1847 // Combine the stuff:
1848 $filenameAndIcon = $bulkCheckBox . $ATag_alt . $icon
1849 . htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
1850 // Show element:
1851 if ($pDim) {
1852 // Image...
1853 $lines[] = '
1854 <tr class="file_list_normal">
1855 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1856 <td>' . ($ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
1857 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
1858 . '" alt="" />' . $ATag_e) . '</td>
1859 <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
1860 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
1861 . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
1862 . $GLOBALS['LANG']->getLL('info', TRUE) . $ATag2_e) . '</td>
1863 <td nowrap="nowrap">&nbsp;' . $pDim . '</td>
1864 </tr>';
1865 $lines[] = '
1866 <tr>
1867 <td class="filelistThumbnail" colspan="4">' . $ATag_alt . $clickIcon . $ATag_e . '</td>
1868 </tr>';
1869 } else {
1870 $lines[] = '
1871 <tr class="file_list_normal">
1872 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1873 <td>' . ($ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
1874 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
1875 . '" alt="" />' . $ATag_e) . '</td>
1876 <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
1877 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
1878 . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
1879 . $GLOBALS['LANG']->getLL('info', TRUE) . $ATag2_e) . '</td>
1880 <td>&nbsp;</td>
1881 </tr>';
1882 }
1883 }
1884 // Wrap all the rows in table tags:
1885 $out .= '
1886
1887 <!--
1888 File listing
1889 -->
1890 <table cellpadding="0" cellspacing="0" id="typo3-filelist">
1891 ' . implode('', $lines) . '
1892 </table>';
1893 // Return accumulated content for file listing:
1894 $out .= '</div>';
1895 return $out;
1896 }
1897
1898 /**
1899 * Render list of folders.
1900 *
1901 * @param Folder $baseFolder
1902 * @return string HTML output
1903 * @todo Define visibility
1904 */
1905 public function folderList(Folder $baseFolder) {
1906 $content = '';
1907 $folders = $baseFolder->getSubfolders();
1908 $baseFolderPath = $baseFolder->getPublicUrl();
1909 // Create headline (showing number of folders):
1910 $content .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('folders') . ' (%s):', count($folders)));
1911 $titleLength = (int)$GLOBALS['BE_USER']->uc['titleLen'];
1912 // Create the header of current folder:
1913 $aTag = '<a href="#" onclick="return insertElement(\'\',\'' . rawurlencode($baseFolderPath)
1914 . '\', \'folder\', \'' . rawurlencode($baseFolderPath) . '\', unescape(\'' . rawurlencode($baseFolderPath)
1915 . '\'), \'\', \'\',\'\',1);">';
1916 // Add the foder icon
1917 $folderIcon = $aTag;
1918 $folderIcon .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif',
1919 'width="18" height="16"') . ' alt="" />';
1920 $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($baseFolder), $titleLength));
1921 $folderIcon .= '</a>';
1922 $content .= $folderIcon . '<br />';
1923
1924 $lines = array();
1925 // Traverse the folder list:
1926 foreach ($folders as $folderPath) {
1927 $pathInfo = pathinfo($folderPath);
1928 // Create folder icon:
1929 $icon = '<img src="clear.gif" width="16" height="16" alt="" /><img'
1930 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif',
1931 'width="16" height="16"') . ' title="' . htmlspecialchars(($pathInfo['basename']))
1932 . '" class="absmiddle" alt="" />';
1933 // Create links for adding the folder:
1934 if ($this->P['itemName'] != '' && $this->P['formName'] != '') {
1935 $aTag = '<a href="#" onclick="return set_folderpath(unescape(\'' . rawurlencode($folderPath)
1936 . '\'));">';
1937 } else {
1938 $aTag = '<a href="#" onclick="return insertElement(\'\',\'' . rawurlencode($folderPath)
1939 . '\', \'folder\', \'' . rawurlencode($folderPath) . '\', unescape(\''
1940 . rawurlencode($folderPath) . '\'), \'' . $pathInfo['extension'] . '\', \'\');">';
1941 }
1942 if (strstr($folderPath, ',') || strstr($folderPath, '|')) {
1943 // In case an invalid character is in the filepath, display error message:
1944 $errorMessage = GeneralUtility::quoteJSvalue(sprintf($GLOBALS['LANG']->getLL('invalidChar'), ', |'));
1945 $aTag = ($aTag_alt = '<a href="#" onclick="alert(' . $errorMessage . ');return false;">');
1946 } else {
1947 // If foldername is OK, just add it:
1948 $aTag_alt = substr($aTag, 0, -4) . ',\'\',1);">';
1949 }
1950 $aTag_e = '</a>';
1951 // Combine icon and folderpath:
1952 $foldernameAndIcon = $aTag_alt . $icon
1953 . htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($folderPath), $titleLength)) . $aTag_e;
1954 if ($this->P['itemName'] != '') {
1955 $lines[] = '
1956 <tr class="bgColor4">
1957 <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
1958 <td>&nbsp;</td>
1959 </tr>';
1960 } else {
1961 $lines[] = '
1962 <tr class="bgColor4">
1963 <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
1964 <td>' . $aTag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
1965 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
1966 . '" alt="" />' . $aTag_e . ' </td>
1967 <td>&nbsp;</td>
1968 </tr>';
1969 }
1970 $lines[] = '
1971 <tr>
1972 <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td>
1973 </tr>';
1974 }
1975 // Wrap all the rows in table tags:
1976 $content .= '
1977
1978 <!--
1979 Folder listing
1980 -->
1981 <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList">
1982 ' . implode('', $lines) . '
1983 </table>';
1984 // Return accumulated content for folderlisting:
1985 return $content;
1986 }
1987
1988 /**
1989 * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images.
1990 * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE
1991 *
1992 * @param Folder $folder The folder path to expand
1993 * @param string $extensionList List of file extensions to show
1994 * @return string HTML output
1995 * @todo Define visibility
1996 */
1997 public function TBE_dragNDrop(Folder $folder, $extensionList = '') {
1998 if (!$folder) {
1999 return '';
2000 }
2001 if (!$folder->getStorage()->isPublic()) {
2002 // Print this warning if the folder is NOT a web folder
2003 return $this->barheader($GLOBALS['LANG']->getLL('files'))
2004 . $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2');
2005 }
2006 $out = '';
2007
2008 // Read files from directory:
2009 $extensionList = $extensionList == '*' ? '' : $extensionList;
2010 $files = $this->getFilesInFolder($folder, $extensionList);
2011
2012 $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files)));
2013 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
2014 $picon = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
2015 $picon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLen));
2016 $out .= $picon . '<br />';
2017 // Init row-array:
2018 $lines = array();
2019 // Add "drag-n-drop" message:
2020 $lines[] = '
2021 <tr>
2022 <td colspan="2">' . $this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')) . '</td>
2023 </tr>';
2024 // Traverse files:
2025 foreach ($files as $fileObject) {
2026 $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
2027 // URL of image:
2028 $iUrl = GeneralUtility::rawurlencodeFP($fileObject->getPublicUrl(TRUE));
2029 // Show only web-images
2030 $fileExtension = strtolower($fileObject->getExtension());
2031 if (GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) {
2032 $imgInfo = @getimagesize($fileObject->getForLocalProcessing(FALSE));
2033 $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
2034 $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
2035 $filenameAndIcon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
2036 if (GeneralUtility::_GP('noLimit')) {
2037 $maxW = 10000;
2038 $maxH = 10000;
2039 } else {
2040 $maxW = 380;
2041 $maxH = 500;
2042 }
2043 $IW = $imgInfo[0];
2044 $IH = $imgInfo[1];
2045 if ($IW > $maxW) {
2046 $IH = ceil($IH / $IW * $maxW);
2047 $IW = $maxW;
2048 }
2049 if ($IH > $maxH) {
2050 $IW = ceil($IW / $IH * $maxH);
2051 $IH = $maxH;
2052 }
2053 // Make row:
2054 $lines[] = '
2055 <tr class="bgColor4">
2056 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
2057 <td nowrap="nowrap">' . ($imgInfo[0] != $IW
2058 ? '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('noLimit' => '1')))
2059 . '">' . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning2.gif',
2060 'width="18" height="16"') . ' title="'
2061 . $GLOBALS['LANG']->getLL('clickToRedrawFullSize', TRUE) . '" alt="" />' . '</a>'
2062 : '')
2063 . $pDim . '&nbsp;</td>
2064 </tr>';
2065 $lines[] = '
2066 <tr>
2067 <td colspan="2"><img src="' . $iUrl . '" data-htmlarea-file-uid="' . $fileObject->getUid()
2068 . '" width="' . $IW . '" height="' . $IH . '" border="1" alt="" /></td>
2069 </tr>';
2070 $lines[] = '
2071 <tr>
2072 <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
2073 </tr>';
2074 }
2075 }
2076 // Finally, wrap all rows in a table tag:
2077 $out .= '
2078
2079
2080 <!--
2081 File listing / Drag-n-drop
2082 -->
2083 <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
2084 ' . implode('', $lines) . '
2085 </table>';
2086
2087 return $out;
2088 }
2089
2090 /******************************************************************
2091 *
2092 * Miscellaneous functions
2093 *
2094 ******************************************************************/
2095 /**
2096 * Verifies that a path is a web-folder:
2097 *
2098 * @param string $folder Absolute filepath
2099 * @return boolean If the input path is found in PATH_site then it returns TRUE.
2100 * @todo Define visibility
2101 */
2102 public function isWebFolder($folder) {
2103 $folder = rtrim($folder, '/') . '/';
2104 return GeneralUtility::isFirstPartOfStr($folder, PATH_site) ? TRUE : FALSE;
2105 }
2106
2107 /**
2108 * Checks, if a path is within the mountpoints of the backend user
2109 *
2110 * @param string $folder Absolute filepath
2111 * @return boolean If the input path is found in the backend users filemounts, then return TRUE.
2112 * @todo Define visibility
2113 */
2114 public function checkFolder($folder) {
2115 return $this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/') ? TRUE : FALSE;
2116 }
2117
2118 /**
2119 * Prints a 'header' where string is in a tablecell
2120 *
2121 * @param string $str The string to print in the header. The value is htmlspecialchars()'ed before output.
2122 * @return string The header HTML (wrapped in a table)
2123 * @todo Define visibility
2124 */
2125 public function barheader($str) {
2126 return '
2127 <!-- Bar header: -->
2128 <h3>' . htmlspecialchars($str) . '</h3>
2129 ';
2130 }
2131
2132 /**
2133 * Displays a message box with the input message
2134 *
2135 * @param string $in_msg Input message to show (will be htmlspecialchars()'ed inside of this function)
2136 * @param string $icon Icon filename body from gfx/ (default is "icon_note") - meant to allow change to warning type icons...
2137 * @return string HTML for the message (wrapped in a table).
2138 * @todo Define visibility
2139 */
2140 public function getMsgBox($in_msg, $icon = 'icon_note') {
2141 $msg = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/' . $icon . '.gif'), 'width="18" height="16"')
2142 . ' alt="" />' . htmlspecialchars($in_msg);
2143 $msg = '
2144
2145 <!--
2146 Message box:
2147 -->
2148 <table cellspacing="0" class="bgColor4" id="typo3-msgBox">
2149 <tr>
2150 <td>' . $msg . '</td>
2151 </tr>
2152 </table>
2153 ';
2154 return $msg;
2155 }
2156
2157 /**
2158 * For RTE/link: This prints the 'currentUrl'
2159 *
2160 * @param string $str URL value. The value is htmlspecialchars()'ed before output.
2161 * @return string HTML content, wrapped in a table.
2162 * @todo Define visibility
2163 */
2164 public function printCurrentUrl($str) {
2165 // Output the folder or file identifier, when working with files
2166 if (isset($str) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($str)
2167 && ($this->act === 'file' || $this->act === 'folder')
2168 ) {
2169 try {
2170 $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($str);
2171 } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
2172 $fileObject = NULL;
2173 }
2174 $str = is_object($fileObject) ? $fileObject->getIdentifier() : '';
2175 }
2176 if (strlen($str)) {
2177 return '
2178 <!-- Print current URL -->
2179 <table border="0" cellpadding="0" cellspacing="0" id="typo3-curUrl">
2180 <tr>
2181 <td>' . $GLOBALS['LANG']->getLL('currentLink', TRUE) . ': '
2182 . htmlspecialchars(rawurldecode($str)) . '</td>
2183 </tr>
2184 </table>';
2185 } else {
2186 return '';
2187 }
2188 }
2189
2190 /**
2191 * For RTE/link: Parses the incoming URL and determines if it's a page, file, external or mail address.
2192 *
2193 * @param string $href HREF value tp analyse
2194 * @param string $siteUrl The URL of the current website (frontend)
2195 * @return array Array with URL information stored in assoc. keys: value, act (page, file, spec, mail), pageid, cElement, info
2196 * @todo Define visibility
2197 */
2198 public function parseCurUrl($href, $siteUrl) {
2199 $href = trim($href);
2200 if ($href) {
2201 $info = array();
2202 // Default is "url":
2203 $info['value'] = $href;
2204 $info['act'] = 'url';
2205 $specialParts = explode('#_SPECIAL', $href);
2206 // Special kind (Something RTE specific: User configurable links through: "userLinks." from ->thisConfig)
2207 if (count($specialParts) == 2) {
2208 $info['value'] = '#_SPECIAL' . $specialParts[1];
2209 $info['act'] = 'spec';
2210 } elseif (strpos($href, 'file:') !== FALSE) {
2211 $rel = substr($href, strpos($href, 'file:') + 5);
2212 $rel = rawurldecode($rel);
2213 // resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier"
2214 $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($rel);
2215 if ($fileOrFolderObject instanceof Folder) {
2216 $info['act'] = 'folder';
2217 $info['value'] = $fileOrFolderObject->getCombinedIdentifier();
2218 } elseif ($fileOrFolderObject instanceof File) {
2219 $info['act'] = 'file';
2220 $info['value'] = $fileOrFolderObject->getUid();
2221 } else {
2222 $info['value'] = $rel;
2223 }
2224 } elseif (GeneralUtility::isFirstPartOfStr($href, $siteUrl)) {
2225 // If URL is on the current frontend website:
2226 // URL is a file, which exists:
2227 if (file_exists(PATH_site . rawurldecode($href))) {
2228 $info['value'] = rawurldecode($href);
2229 if (@is_dir((PATH_site . $info['value']))) {
2230 $info['act'] = 'folder';
2231 } else {
2232 $info['act'] = 'file';
2233 }
2234 } else {
2235 // URL is a page (id parameter)
2236 $uP = parse_url($href);
2237
2238 $pp = preg_split('/^id=/', $uP['query']);
2239 $pp[1] = preg_replace('/&id=[^&]*/', '', $pp[1]);
2240 $parameters = explode('&', $pp[1]);
2241 $id = array_shift($parameters);
2242 if ($id) {
2243 // Checking if the id-parameter is an alias.
2244 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($id)) {
2245 list($idPartR) = BackendUtility::getRecordsByField('pages', 'alias', $id);
2246 $id = (int)$idPartR['uid'];
2247 }
2248 $pageRow = BackendUtility::getRecordWSOL('pages', $id);
2249 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
2250 $info['value'] = ((((($GLOBALS['LANG']->getLL('page', TRUE) . ' \'')
2251 . htmlspecialchars(GeneralUtility::fixed_lgd_cs($pageRow['title'], $titleLen)))
2252 . '\' (ID:') . $id) . ($uP['fragment'] ? ', #' . $uP['fragment'] : '')) . ')';
2253 $info['pageid'] = $id;
2254 $info['cElement'] = $uP['fragment'];
2255 $info['act'] = 'page';
2256 $info['query'] = $parameters[0] ? '&' . implode('&', $parameters) : '';
2257 }
2258 }
2259 } else {
2260 // Email link:
2261 if (strtolower(substr($href, 0, 7)) == 'mailto:') {
2262 $info['value'] = trim(substr($href, 7));
2263 $info['act'] = 'mail';
2264 }
2265 }
2266 $info['info'] = $info['value'];
2267 } else {
2268 // NO value inputted:
2269 $info = array();
2270 $info['info'] = $GLOBALS['LANG']->getLL('none');
2271 $info['value'] = '';
2272 $info['act'] = 'page';
2273 }
2274 // let the hook have a look
2275 foreach ($this->hookObjects as $hookObject) {
2276 $info = $hookObject->parseCurrentUrl($href, $siteUrl, $info);
2277 }
2278 return $info;
2279 }
2280
2281 /**
2282 * Setter for the class that should be used by TBE_expandPage()
2283 * to generate the record list.
2284 *
2285 * @param \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList $recordList
2286 * @throws \InvalidArgumentException
2287 * @return void
2288 */
2289 public function setRecordList($recordList) {
2290 if (!$recordList instanceof \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList) {
2291 throw new \InvalidArgumentException('$recordList needs to be an instance of \\TYPO3\\CMS\\Backend\\RecordList\\ElementBrowserRecordList', 1370878522);
2292 }
2293 $this->recordList = $recordList;
2294 }
2295
2296 /**
2297 * For TBE: Makes an upload form for uploading files to the filemount the user is browsing.
2298 * The files are uploaded to the tce_file.php script in the core which will handle the upload.
2299 *
2300 * @param Folder $folderObject Absolute filepath on server to which to upload.
2301 * @return string HTML for an upload form.
2302 * @todo Define visibility
2303 */
2304 public function uploadForm(Folder $folderObject) {
2305 if (!$folderObject->checkActionPermission('write')) {
2306 return '';
2307 }
2308 // Read configuration of upload field count
2309 $userSetting = $GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
2310 $count = isset($userSetting) ? $userSetting : 3;
2311 if ($count === '0') {
2312 return '';
2313 }
2314 $count = (int)$count === 0 ? 3 : (int)$count;
2315 // Create header, showing upload path:
2316 $header = $folderObject->getIdentifier();
2317 $code = '
2318 <br />
2319 <!--
2320 Form, for uploading files:
2321 -->
2322 <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform"'
2323 . 'id="typo3-uplFilesForm" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">
2324 <table border="0" cellpadding="0" cellspacing="0" id="typo3-uplFiles">
2325 <tr>
2326 <td>' . $this->barheader($GLOBALS['LANG']->sL(
2327 'LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle', TRUE) . ':') . '</td>
2328 </tr>
2329 <tr>
2330 <td class="c-wCell c-hCell"><strong>' . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> '
2331 . htmlspecialchars($header) . '</td>
2332 </tr>
2333 <tr>
2334 <td class="c-wCell c-hCell">';
2335 // Traverse the number of upload fields (default is 3):
2336 for ($a = 1; $a <= $count; $a++) {
2337 $code .= '<input type="file" multiple="multiple" name="upload_' . $a . '[]"' . $this->doc->formWidth(35)
2338 . ' size="50" />
2339 <input type="hidden" name="file[upload][' . $a . '][target]" value="'
2340 . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />
2341 <input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br />';
2342 }
2343 // Make footer of upload form, including the submit button:
2344 $redirectValue = $this->thisScript . '?act=' . $this->act . '&mode=' . $this->mode
2345 . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier())
2346 . '&bparams=' . rawurlencode($this->bparams);
2347 $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
2348 $code .= '
2349 <div id="c-override">
2350 <label><input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> '
2351 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', TRUE) . '</label>
2352 </div>
2353 <input type="submit" name="submit" value="'
2354 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', TRUE) . '" />
2355 ';
2356 $code .= '</td>
2357 </tr>
2358 </table>
2359 </form><br />';
2360 return $code;
2361 }
2362
2363 /**
2364 * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
2365 * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
2366 *
2367 * @param Folder $folderObject Absolute filepath on server in which to create the new folder.
2368 * @return string HTML for the create folder form.
2369 * @todo Define visibility
2370 */
2371 public function createFolder(Folder $folderObject) {
2372 if (!$folderObject->checkActionPermission('write')) {
2373 return '';
2374 }
2375 if (!($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB'))) {
2376 return '';
2377 }
2378 // Don't show Folder-create form if it's denied
2379 if ($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.hideCreateFolder')) {
2380 return '';
2381 }
2382 // Create header, showing upload path:
2383 $header = $folderObject->getIdentifier();
2384 $code = '
2385
2386 <!--
2387 Form, for creating new folders:
2388 -->
2389 <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform2" id="typo3-crFolderForm">
2390 <table border="0" cellpadding="0" cellspacing="0" id="typo3-crFolder">
2391 <tr>
2392 <td>' . $this->barheader($GLOBALS['LANG']->sL(
2393 'LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle') . ':') . '</td>
2394 </tr>
2395 <tr>
2396 <td class="c-wCell c-hCell"><strong>'
2397 . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> ' . htmlspecialchars($header) . '</td>
2398 </tr>
2399 <tr>
2400 <td class="c-wCell c-hCell">';
2401 // Create the new-folder name field:
2402 $a = 1;
2403 $code .= '<input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" />'
2404 . '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="'
2405 . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
2406 // Make footer of upload form, including the submit button:
2407 $redirectValue = $this->thisScript . '?act=' . $this->act . '&mode=' . $this->mode
2408 . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier())
2409 . '&bparams=' . rawurlencode($this->bparams);
2410 $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />'
2411 . '<input type="submit" name="submit" value="'
2412 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', TRUE) . '" />';
2413 $code .= '</td>
2414 </tr>
2415 </table>
2416 </form>';
2417 return $code;
2418 }
2419
2420 /**
2421 * Get the HTML data required for a bulk selection of files of the TYPO3 Element Browser.
2422 *
2423 * @param integer $filesCount Number of files currently displayed
2424 * @return string HTML data required for a bulk selection of files - if $filesCount is 0, nothing is returned
2425 * @todo Define visibility
2426 */
2427 public function getBulkSelector($filesCount) {
2428 if (!$filesCount) {
2429 return '';
2430 }
2431
2432 $labelToggleSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:toggleSelection', TRUE);
2433 $labelImportSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:importSelection', TRUE);
2434 // Getting flag for showing/not showing thumbnails:
2435 $noThumbsInEB = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
2436 $out = $this->doc->spacer(10) . '<div>' . '<a href="#" onclick="BrowseLinks.Selector.handle()">'
2437 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/import.gif', 'width="12" height="12"')
2438 . ' title="' . $labelImportSelection . '" alt="" /> ' . $labelImportSelection . '</a>&nbsp;&nbsp;&nbsp;'
2439 . '<a href="#" onclick="BrowseLinks.Selector.toggle()">' . '<img'
2440 . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/clip_select.gif', 'width="12" height="12"')
2441 . ' title="' . $labelToggleSelection . '" alt="" /> ' . $labelToggleSelection . '</a>' . '</div>';
2442 $thumbNailCheck = '';
2443 if (!$noThumbsInEB && $this->selectedFolder) {
2444 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
2445 $_MOD_MENU = array('displayThumbs' => '');
2446 $_MCONF['name'] = 'file_list';
2447 $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']);
2448 $addParams = '&act=' . $this->act . '&mode=' . $this->mode
2449 . '&expandFolder=' . rawurlencode($this->selectedFolder->getCombinedIdentifier())
2450 . '&bparams=' . rawurlencode($this->bparams);
2451 $thumbNailCheck = BackendUtility::getFuncCheck('', 'SET[displayThumbs]', $_MOD_SETTINGS['displayThumbs'],
2452 $this->thisScript, $addParams, 'id="checkDisplayThumbs"')
2453 . ' <label for="checkDisplayThumbs">'
2454 . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:displayThumbs', TRUE) . '</label>';
2455 $out .= $this->doc->spacer(5) . $thumbNailCheck . $this->doc->spacer(15);
2456 } else {
2457 $out .= $this->doc->spacer(15);
2458 }
2459 return $out;
2460 }
2461
2462 /**
2463 * Determines whether submitted field change functions are valid
2464 * and are coming from the system and not from an external abuse.
2465 *
2466 * @param boolean $handleFlexformSections Whether to handle flexform sections differently
2467 * @return boolean Whether the submitted field change functions are valid
2468 */
2469 protected function areFieldChangeFunctionsValid($handleFlexformSections = FALSE) {
2470 $result = FALSE;
2471 if (isset($this->P['fieldChangeFunc']) && is_array($this->P['fieldChangeFunc']) && isset($this->P['fieldChangeFuncHash'])) {
2472 $matches = array();
2473 $pattern = '#\\[el\\]\\[(([^]-]+-[^]-]+-)(idx\\d+-)([^]]+))\\]#i';
2474 $fieldChangeFunctions = $this->P['fieldChangeFunc'];
2475 // Special handling of flexform sections:
2476 // Field change functions are modified in JavaScript, thus the hash is always invalid
2477 if ($handleFlexformSections && preg_match($pattern, $this->P['itemName'], $matches)) {
2478 $originalName = $matches[1];
2479 $cleanedName = $matches[2] . $matches[4];
2480 foreach ($fieldChangeFunctions as &$value) {
2481 $value = str_replace($originalName, $cleanedName, $value);
2482 }
2483 unset($value);
2484 }
2485 $result = $this->P['fieldChangeFuncHash'] === GeneralUtility::hmac(serialize($fieldChangeFunctions));
2486 }
2487 return $result;
2488 }
2489
2490 /**
2491 * Get a list of Files in a folder filtered by extension
2492 *
2493 * @param \TYPO3\CMS\Core\Resource\Folder $folder
2494 * @param string $extensionList
2495 * @return \TYPO3\CMS\Core\Resource\File[]
2496 */
2497 protected function getFilesInFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList) {
2498 if ($extensionList !== '') {
2499 /** @var \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter $filter */
2500 $filter = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
2501 $filter->setAllowedFileExtensions($extensionList);
2502 $folder->setFileAndFolderNameFilters(array(array($filter, 'filterFileList')));
2503 }
2504 return $folder->getFiles();
2505 }
2506
2507 }