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