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