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