[BUGFIX] Catch exception in element browser
[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] = substr($this->curUrlArray['href'], strlen(PATH_site));
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 && !$this->isReadOnlyFolder($selectedFolder)) {
849 $uploadForm = ($this->act === 'file') ? $this->uploadForm($selectedFolder) : '';
850 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
851 $createFolder = $this->createFolder($selectedFolder);
852 }
853 }
854 // Insert the upload form on top, if so configured
855 if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
856 $content .= $uploadForm;
857 }
858
859 // Render the filelist if there is a folder selected
860 if ($selectedFolder) {
861 $files = $this->expandFolder($selectedFolder, $this->P['params']['allowedExtensions']);
862 }
863 $this->doc->JScode .= $this->doc->wrapScriptTags('
864 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
865 ');
866 $content .= '
867 <!--
868 Wrapper table for folder tree / file/folder list:
869 -->
870 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
871 <tr>
872 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
873 <td class="c-wCell" valign="top">' . $files . '</td>
874 </tr>
875 </table>
876 <br />
877 ';
878 // Adding create folder + upload forms if applicable
879 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
880 $content .= $uploadForm;
881 }
882 $content .= $createFolder . '<br />';
883 break;
884 case 'spec':
885 if (is_array($this->thisConfig['userLinks.'])) {
886 $subcats = array();
887 $v = $this->thisConfig['userLinks.'];
888 foreach ($v as $k2 => $value) {
889 $k2i = intval($k2);
890 if (substr($k2, -1) == '.' && is_array($v[$k2i . '.'])) {
891 // Title:
892 $title = trim($v[$k2i]);
893 if (!$title) {
894 $title = $v[$k2i . '.']['url'];
895 } else {
896 $title = $GLOBALS['LANG']->sL($title);
897 }
898 // Description:
899 $description = $v[$k2i . '.']['description'] ? $GLOBALS['LANG']->sL($v[($k2i . '.')]['description'], TRUE) . '<br />' : '';
900 // URL + onclick event:
901 $onClickEvent = '';
902 if (isset($v[$k2i . '.']['target'])) {
903 $onClickEvent .= 'browse_links_setTarget(\'' . $v[($k2i . '.')]['target'] . '\');';
904 }
905 $v[$k2i . '.']['url'] = str_replace('###_URL###', $this->siteURL, $v[$k2i . '.']['url']);
906 if (substr($v[$k2i . '.']['url'], 0, 7) == 'http://' || substr($v[$k2i . '.']['url'], 0, 7) == 'mailto:') {
907 $onClickEvent .= 'cur_href=unescape(\'' . rawurlencode($v[($k2i . '.')]['url']) . '\');link_current();';
908 } else {
909 $onClickEvent .= 'link_spec(unescape(\'' . $this->siteURL . rawurlencode($v[($k2i . '.')]['url']) . '\'));';
910 }
911 // Link:
912 $A = array('<a href="#" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">', '</a>');
913 // Adding link to menu of user defined links:
914 $subcats[$k2i] = '
915 <tr>
916 <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>
917 </tr>';
918 }
919 }
920 // Sort by keys:
921 ksort($subcats);
922 // Add menu to content:
923 $content .= '
924
925 <!--
926 Special userdefined menu:
927 -->
928 <table border="0" cellpadding="1" cellspacing="1" id="typo3-linkSpecial">
929 <tr>
930 <td class="bgColor5" class="c-wCell" valign="top"><strong>' . $GLOBALS['LANG']->getLL('special', TRUE) . '</strong></td>
931 </tr>
932 ' . implode('', $subcats) . '
933 </table>
934 ';
935 }
936 break;
937 case 'page':
938 $pagetree = GeneralUtility::makeInstance('rtePageTree');
939 $pagetree->thisScript = $this->thisScript;
940 $pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
941 $pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
942 $pagetree->addField('nav_title');
943 $tree = $pagetree->getBrowsableTree();
944 $cElements = $this->expandPage();
945 // Outputting Temporary DB mount notice:
946 if (intval($GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint'))) {
947 $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>';
948 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $link, '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
949 $dbmount = $flashMessage->render();
950 }
951 $content .= '
952
953 <!--
954 Wrapper table for page tree / record list:
955 -->
956 <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkPages">
957 <tr>
958 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':')) . $dbmount . $tree . '</td>
959 <td class="c-wCell" valign="top">' . $cElements . '</td>
960 </tr>
961 </table>
962 ';
963 break;
964 default:
965 // Call hook
966 foreach ($this->hookObjects as $hookObject) {
967 $content .= $hookObject->getTab($this->act);
968 }
969 }
970 if (in_array('params', $allowedFields, TRUE)) {
971 $content .= '
972 <!--
973 Selecting params for link:
974 -->
975 <form action="" name="lparamsform" id="lparamsform">
976 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkParams">
977 <tr>
978 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('params', TRUE) . '</td>
979 <td><input type="text" name="lparams" class="typo3-link-input" onchange="browse_links_setParams(this.value);" value="' . htmlspecialchars($this->setParams) . '" /></td>
980 </tr>
981 </table>
982 </form>
983 ';
984 }
985 if (in_array('class', $allowedFields, TRUE)) {
986 $content .= '
987 <!--
988 Selecting class for link:
989 -->
990 <form action="" name="lclassform" id="lclassform">
991 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkClass">
992 <tr>
993 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('class', TRUE) . '</td>
994 <td><input type="text" name="lclass" class="typo3-link-input" onchange="browse_links_setClass(this.value);" value="' . htmlspecialchars($this->setClass) . '" /></td>
995 </tr>
996 </table>
997 </form>
998 ';
999 }
1000 if (in_array('title', $allowedFields, TRUE)) {
1001 $content .= '
1002 <!--
1003 Selecting title for link:
1004 -->
1005 <form action="" name="ltitleform" id="ltitleform">
1006 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTitle">
1007 <tr>
1008 <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('title', TRUE) . '</td>
1009 <td><input type="text" name="ltitle" class="typo3-link-input" onchange="browse_links_setTitle(this.value);" value="' . htmlspecialchars($this->setTitle) . '" /></td>
1010 </tr>
1011 </table>
1012 </form>
1013 ';
1014 }
1015 // additional fields for page links
1016 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'])) {
1017 $_params = array(
1018 'conf' => &$conf
1019 );
1020 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'] as $objRef) {
1021 $processor =& GeneralUtility::getUserObj($objRef);
1022 $content .= $processor->addFields($_params, $this);
1023 }
1024 }
1025 // Target:
1026 if ($this->act != 'mail' && in_array('target', $allowedFields, TRUE)) {
1027 $ltarget = '
1028
1029 <!--
1030 Selecting target for link:
1031 -->
1032 <form action="" name="ltargetform" id="ltargetform">
1033 <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">
1034 <tr>
1035 <td>' . $GLOBALS['LANG']->getLL('target', TRUE) . ':</td>
1036 <td><input type="text" name="ltarget" onchange="browse_links_setTarget(this.value);" value="' . htmlspecialchars($this->setTarget) . '"' . $this->doc->formWidth(10) . ' /></td>
1037 <td>
1038 <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;">
1039 <option></option>
1040 <option value="_top">' . $GLOBALS['LANG']->getLL('top', TRUE) . '</option>
1041 <option value="_blank">' . $GLOBALS['LANG']->getLL('newWindow', TRUE) . '</option>
1042 </select>
1043 </td>
1044 <td>';
1045 if (($this->curUrlInfo['act'] == 'page' || $this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder') && $this->curUrlArray['href'] && $this->curUrlInfo['act'] == $this->act) {
1046 $ltarget .= '
1047 <input type="submit" value="' . $GLOBALS['LANG']->getLL('update', TRUE) . '" onclick="return link_current();" />';
1048 }
1049 $selectJS = '
1050 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) {
1051 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;
1052 browse_links_setTarget(document.ltargetform.ltarget.value);
1053 browse_links_setClass(document.lclassform.lclass.value);
1054 browse_links_setTitle(document.ltitleform.ltitle.value);
1055 browse_links_setParams(document.lparamsform.lparams.value);
1056 document.ltargetform.popup_width.selectedIndex=0;
1057 document.ltargetform.popup_height.selectedIndex=0;
1058 }
1059 ';
1060 $ltarget .= ' </td>
1061 </tr>
1062 <tr>
1063 <td>' . $GLOBALS['LANG']->getLL('target_popUpWindow', TRUE) . ':</td>
1064 <td colspan="3">
1065 <select name="popup_width" onchange="' . htmlspecialchars($selectJS) . '">
1066 <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_width', TRUE) . '</option>
1067 <option value="300">300</option>
1068 <option value="400">400</option>
1069 <option value="500">500</option>
1070 <option value="600">600</option>
1071 <option value="700">700</option>
1072 <option value="800">800</option>
1073 </select>
1074 x
1075 <select name="popup_height" onchange="' . htmlspecialchars($selectJS) . '">
1076 <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_height', TRUE) . '</option>
1077 <option value="200">200</option>
1078 <option value="300">300</option>
1079 <option value="400">400</option>
1080 <option value="500">500</option>
1081 <option value="600">600</option>
1082 </select>
1083 </td>
1084 </tr>
1085 </table>
1086 </form>';
1087 // Add "target selector" box to content:
1088 $content .= $ltarget;
1089 // Add some space
1090 $content .= '<br /><br />';
1091 }
1092 // End page, return content:
1093 $content .= $this->doc->endPage();
1094 $content = $this->doc->insertStylesAndJS($content);
1095 return $content;
1096 }
1097
1098 /**
1099 * TYPO3 Element Browser: Showing a page tree and allows you to browse for records
1100 *
1101 * @return string HTML content for the module
1102 * @todo Define visibility
1103 */
1104 public function main_db() {
1105 // Starting content:
1106 $content = $this->doc->startPage('TBE record selector');
1107 // Init variable:
1108 $pArr = explode('|', $this->bparams);
1109 $tables = $pArr[3];
1110 // Making the browsable pagetree:
1111 $pagetree = GeneralUtility::makeInstance('TBE_PageTree');
1112 $pagetree->thisScript = $this->thisScript;
1113 $pagetree->ext_pArrPages = !strcmp($tables, 'pages') ? 1 : 0;
1114 $pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
1115 $pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
1116
1117 $withTree = TRUE;
1118 if (($tables !== '') && ($tables !== '*')) {
1119 $tablesArr = GeneralUtility::trimExplode(',', $tables, TRUE);
1120 $onlyRootLevel = TRUE;
1121 foreach ($tablesArr as $currentTable) {
1122 $tableTca = $GLOBALS['TCA'][$currentTable];
1123 if (isset($tableTca)) {
1124 if (!isset($tableTca['ctrl']['rootLevel']) || (intval($tableTca['ctrl']['rootLevel']) != 1)) {
1125 $onlyRootLevel = FALSE;
1126 }
1127 }
1128 }
1129 if ($onlyRootLevel) {
1130 $withTree = FALSE;
1131 // page to work on will be root
1132 $this->expandPage = 0;
1133 }
1134 }
1135
1136 $pagetree->addField('nav_title');
1137 $tree = $pagetree->getBrowsableTree();
1138 // Making the list of elements, if applicable:
1139 $cElements = $this->TBE_expandPage($tables);
1140 // Putting the things together, side by side:
1141 $content .= '
1142
1143 <!--
1144 Wrapper table for page tree / record list:
1145 -->
1146 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBrecords">
1147 <tr>';
1148 if ($withTree) {
1149 $content .= '<td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':')) . $tree . '</td>';
1150 }
1151 $content .= '<td class="c-wCell" valign="top">' . $cElements . '</td>
1152 </tr>
1153 </table>
1154 ';
1155 // Add some space
1156 $content .= '<br /><br />';
1157 // End page, return content:
1158 $content .= $this->doc->endPage();
1159 $content = $this->doc->insertStylesAndJS($content);
1160 return $content;
1161 }
1162
1163 /**
1164 * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for files.
1165 *
1166 * @return string HTML content for the module
1167 * @todo Define visibility
1168 */
1169 public function main_file() {
1170 // include JS files and set prefs for foldertree
1171 $this->doc->getDragDropCode('folders');
1172 $this->doc->JScode .= $this->doc->wrapScriptTags('
1173 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1174 ');
1175 // Starting content:
1176 $content = $this->doc->startPage('TBE file selector');
1177 // Init variable:
1178 $pArr = explode('|', $this->bparams);
1179 // 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
1180 $allowed = $pArr[3];
1181 if ($allowed !== 'sys_file') {
1182 $allowedFileExtensions = $allowed;
1183 }
1184 $this->storages = $GLOBALS['BE_USER']->getFileStorages();
1185 if (isset($allowedFileExtensions)) {
1186 // Create new filter object
1187 $filterObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
1188 $filterObject->setAllowedFileExtensions($allowedFileExtensions);
1189 // Set file extension filters on all storages
1190 /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
1191 foreach ($this->storages as $storage) {
1192 $storage->addFileAndFolderNameFilter(array($filterObject, 'filterFileList'));
1193 }
1194 }
1195 // Create upload/create folder forms, if a path is given
1196 if ($this->expandFolder) {
1197 $this->selectedFolder = FALSE;
1198 $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
1199 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
1200 // It's a folder
1201 $this->selectedFolder = $fileOrFolderObject;
1202 } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
1203 // It's a file
1204 // @todo: find the parent folder, right now done a bit ugly, because the file does not
1205 // support finding the parent folder of a file on purpose
1206 $folderIdentifier = dirname($fileOrFolderObject->getIdentifier());
1207 $this->selectedFolder = $fileOrFolderObject->getStorage()->getFolder($folderIdentifier);
1208 }
1209 }
1210 // Or get the user's default upload folder
1211 if (!$this->selectedFolder) {
1212 $this->selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
1213 }
1214 // Build the file upload and folder creation form
1215 $uploadForm = '';
1216 $createFolder = '';
1217 if ($this->selectedFolder && !$this->isReadOnlyFolder($this->selectedFolder)) {
1218 $uploadForm = ($this->act === 'file') ? $this->uploadForm($this->selectedFolder) : '';
1219 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
1220 $createFolder = $this->createFolder($this->selectedFolder);
1221 }
1222 }
1223 if ($this->selectedFolder) {
1224 $uploadForm = $this->uploadForm($this->selectedFolder);
1225 $createFolder = $this->createFolder($this->selectedFolder);
1226 } else {
1227 $uploadForm = $createFolder = '';
1228 }
1229 // Insert the upload form on top, if so configured
1230 if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1231 $content .= $uploadForm;
1232 }
1233 // Getting flag for showing/not showing thumbnails:
1234 $noThumbs = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
1235 if (!$noThumbs) {
1236 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
1237 $_MOD_MENU = array('displayThumbs' => '');
1238 $_MCONF['name'] = 'file_list';
1239 $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']);
1240 }
1241 $noThumbs = $noThumbs ? $noThumbs : !$_MOD_SETTINGS['displayThumbs'];
1242 // Create folder tree:
1243 $foldertree = GeneralUtility::makeInstance('TBE_FolderTree');
1244 $foldertree->thisScript = $this->thisScript;
1245 $foldertree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1246 $tree = $foldertree->getBrowsableTree();
1247 list(, , $specUid) = explode('_', $this->PM);
1248 if ($this->mode == 'filedrag') {
1249 $files = $this->TBE_dragNDrop($this->selectedFolder, $pArr[3]);
1250 } else {
1251 $files = $this->TBE_expandFolder($this->selectedFolder, $pArr[3], $noThumbs);
1252 }
1253 // Putting the parts together, side by side:
1254 $content .= '
1255
1256 <!--
1257 Wrapper table for folder tree / file list:
1258 -->
1259 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1260 <tr>
1261 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
1262 <td class="c-wCell" valign="top">' . $files . '</td>
1263 </tr>
1264 </table>
1265 ';
1266 // Adding create folder + upload forms if applicable:
1267 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1268 $content .= $uploadForm;
1269 }
1270 $content .= $createFolder;
1271 // Add some space
1272 $content .= '<br /><br />';
1273 // Setup indexed elements:
1274 $this->doc->JScode .= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
1275 // Ending page, returning content:
1276 $content .= $this->doc->endPage();
1277 $content = $this->doc->insertStylesAndJS($content);
1278 return $content;
1279 }
1280
1281 /**
1282 * TYPO3 Element Browser: Showing a folder tree, allowing you to browse for folders.
1283 *
1284 * @return string HTML content for the module
1285 * @todo Define visibility
1286 */
1287 public function main_folder() {
1288 // include JS files
1289 $this->doc->getDragDropCode('folders');
1290 // Setting prefs for foldertree
1291 $this->doc->JScode .= $this->doc->wrapScriptTags('
1292 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1293 ');
1294 // Starting content:
1295 $content = $this->doc->startPage('TBE folder selector');
1296 // Init variable:
1297 $parameters = explode('|', $this->bparams);
1298 if ($this->expandFolder) {
1299 $this->selectedFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
1300 }
1301 if ($this->selectedFolder && !$this->isReadOnlyFolder($this->selectedFolder)) {
1302 $createFolder = $this->createFolder($this->selectedFolder);
1303 } else {
1304 $createFolder = '';
1305 }
1306 // Create folder tree:
1307 $foldertree = GeneralUtility::makeInstance('TBE_FolderTree');
1308 $foldertree->thisScript = $this->thisScript;
1309 $foldertree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1310 $tree = $foldertree->getBrowsableTree(FALSE);
1311 list(, , $specUid) = explode('_', $this->PM);
1312 if ($this->mode == 'filedrag') {
1313 $folders = $this->TBE_dragNDrop($this->selectedFolder, $parameters[3]);
1314 } else {
1315 $folders = $this->TBE_expandSubFolders($this->selectedFolder);
1316 }
1317 // Putting the parts together, side by side:
1318 $content .= '
1319
1320 <!--
1321 Wrapper table for folder tree / folder list:
1322 -->
1323 <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1324 <tr>
1325 <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
1326 <td class="c-wCell" valign="top">' . $folders . '</td>
1327 </tr>
1328 </table>
1329 ';
1330 // Adding create folder if applicable:
1331 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
1332 $content .= $createFolder;
1333 }
1334 // Add some space
1335 $content .= '<br /><br />';
1336 // Ending page, returning content:
1337 $content .= $this->doc->endPage();
1338 $content = $this->doc->insertStylesAndJS($content);
1339 return $content;
1340 }
1341
1342 /******************************************************************
1343 *
1344 * Record listing
1345 *
1346 ******************************************************************/
1347 /**
1348 * For RTE: This displays all content elements on a page and lets you create a link to the element.
1349 *
1350 * @return string HTML output. Returns content only if the ->expandPage value is set (pointing to a page uid to show tt_content records from ...)
1351 * @todo Define visibility
1352 */
1353 public function expandPage() {
1354 $out = '';
1355 // Set page id (if any) to expand
1356 $expPageId = $this->expandPage;
1357 // If there is an anchor value (content element reference) in the element reference, then force an ID to expand:
1358 if (!$this->expandPage && $this->curUrlInfo['cElement']) {
1359 // Set to the current link page id.
1360 $expPageId = $this->curUrlInfo['pageid'];
1361 }
1362 // Draw the record list IF there is a page id to expand:
1363 if ($expPageId && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($expPageId) && $GLOBALS['BE_USER']->isInWebMount($expPageId)) {
1364 // Set header:
1365 $out .= $this->barheader($GLOBALS['LANG']->getLL('contentElements') . ':');
1366 // Create header for listing, showing the page title/icon:
1367 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1368 $mainPageRec = BackendUtility::getRecordWSOL('pages', $expPageId);
1369 $picon = IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1370 $picon .= BackendUtility::getRecordTitle('pages', $mainPageRec, TRUE);
1371 $out .= $picon . '<br />';
1372 // Look up tt_content elements from the expanded page:
1373 $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');
1374 $cc = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
1375 // Traverse list of records:
1376 $c = 0;
1377 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1378 $c++;
1379 $icon = IconUtility::getSpriteIconForRecord('tt_content', $row);
1380 if ($this->curUrlInfo['act'] == 'page' && $this->curUrlInfo['cElement'] == $row['uid']) {
1381 $arrCol = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
1382 } else {
1383 $arrCol = '';
1384 }
1385 // Putting list element HTML together:
1386 $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 />';
1387 // Finding internal anchor points:
1388 if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('text,textpic', $row['CType'])) {
1389 $split = preg_split('/(<a[^>]+name=[\'"]?([^"\'>[:space:]]+)[\'"]?[^>]*>)/i', $row['bodytext'], -1, PREG_SPLIT_DELIM_CAPTURE);
1390 foreach ($split as $skey => $sval) {
1391 if ($skey % 3 == 2) {
1392 // Putting list element HTML together:
1393 $sval = substr($sval, 0, 100);
1394 $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 />';
1395 }
1396 }
1397 }
1398 }
1399 }
1400 return $out;
1401 }
1402
1403 /**
1404 * For TYPO3 Element Browser: This lists all content elements from the given list of tables
1405 *
1406 * @param string $tables Commalist of tables. Set to "*" if you want all tables.
1407 * @return string HTML output.
1408 * @todo Define visibility
1409 */
1410 public function TBE_expandPage($tables) {
1411 $out = '';
1412 if ($this->expandPage >= 0 && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->expandPage) && $GLOBALS['BE_USER']->isInWebMount($this->expandPage)) {
1413 // Set array with table names to list:
1414 if (!strcmp(trim($tables), '*')) {
1415 $tablesArr = array_keys($GLOBALS['TCA']);
1416 } else {
1417 $tablesArr = GeneralUtility::trimExplode(',', $tables, TRUE);
1418 }
1419 reset($tablesArr);
1420 // Headline for selecting records:
1421 $out .= $this->barheader($GLOBALS['LANG']->getLL('selectRecords') . ':');
1422 // Create the header, showing the current page for which the listing is. Includes link to the page itself, if pages are amount allowed tables.
1423 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1424 $mainPageRec = BackendUtility::getRecordWSOL('pages', $this->expandPage);
1425 $ATag = '';
1426 $ATag_e = '';
1427 $ATag2 = '';
1428 $picon = '';
1429 if (is_array($mainPageRec)) {
1430 $picon = IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1431 if (in_array('pages', $tablesArr)) {
1432 $ATag = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', ' . GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',1);">';
1433 $ATag2 = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', ' . GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',0);">';
1434 $ATag_alt = substr($ATag, 0, -4) . ',\'\',1);">';
1435 $ATag_e = '</a>';
1436 }
1437 }
1438 $pBicon = $ATag2 ? '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif', 'width="18" height="16"') . ' alt="" />' : '';
1439 $pText = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($mainPageRec['title'], $titleLen));
1440 $out .= $picon . $ATag2 . $pBicon . $ATag_e . $ATag . $pText . $ATag_e . '<br />';
1441 // Initialize the record listing:
1442 $id = $this->expandPage;
1443 $pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
1444 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1445 $pageinfo = BackendUtility::readPageAccess($id, $perms_clause);
1446 $table = '';
1447 // Generate the record list:
1448 /** @var $dblist \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList */
1449 if (isset($this->recordList)) {
1450 $dblist = $this->recordList;
1451 } else {
1452 $dblist = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\RecordList\\ElementBrowserRecordList');
1453 }
1454 $dblist->thisScript = $this->thisScript;
1455 $dblist->backPath = $GLOBALS['BACK_PATH'];
1456 $dblist->thumbs = 0;
1457 $dblist->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageinfo);
1458 $dblist->noControlPanels = 1;
1459 $dblist->clickMenuEnabled = 0;
1460 $dblist->tableList = implode(',', $tablesArr);
1461 $pArr = explode('|', $this->bparams);
1462 // a string like "data[pages][79][storage_pid]"
1463 $fieldPointerString = $pArr[0];
1464 // parts like: data, pages], 79], storage_pid]
1465 $fieldPointerParts = explode('[', $fieldPointerString);
1466 $relatingTableName = substr($fieldPointerParts[1], 0, -1);
1467 $relatingFieldName = substr($fieldPointerParts[3], 0, -1);
1468 if ($relatingTableName && $relatingFieldName) {
1469 $dblist->setRelatingTableAndField($relatingTableName, $relatingFieldName);
1470 }
1471 $dblist->start($id, GeneralUtility::_GP('table'), $pointer, GeneralUtility::_GP('search_field'), GeneralUtility::_GP('search_levels'), GeneralUtility::_GP('showLimit'));
1472 $dblist->setDispFields();
1473 $dblist->generateList();
1474 // Add the HTML for the record list to output variable:
1475 $out .= $dblist->HTMLcode;
1476 // Add support for fieldselectbox in singleTableMode
1477 if ($dblist->table) {
1478 $out .= $dblist->fieldSelectBox($dblist->table);
1479 }
1480 $out .= $dblist->getSearchBox();
1481 }
1482 // Return accumulated content:
1483 return $out;
1484 }
1485
1486 /**
1487 * Render list of folders inside a folder.
1488 *
1489 * @param string $folder String of the current folder
1490 * @return string HTML output
1491 * @todo Define visibility
1492 */
1493 public function TBE_expandSubFolders(\TYPO3\CMS\Core\Resource\Folder $folder) {
1494 $content = '';
1495 if ($folder->checkActionPermission('read')) {
1496 $content .= $this->folderList($folder);
1497 }
1498 // Return accumulated content for folderlisting:
1499 return $content;
1500 }
1501
1502 /******************************************************************
1503 *
1504 * File listing
1505 *
1506 ******************************************************************/
1507 /**
1508 * For RTE: This displays all files from folder. No thumbnails shown
1509 *
1510 * @param string $folder The folder path to expand
1511 * @param string $extensionList List of fileextensions to show
1512 * @return string HTML output
1513 * @todo Define visibility
1514 */
1515 public function expandFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '') {
1516 $out = '';
1517 $renderFolders = $this->act === 'folder';
1518 if ($folder->checkActionPermission('read')) {
1519 // Create header for filelisting:
1520 $out .= $this->barheader($GLOBALS['LANG']->getLL('files') . ':');
1521 // Prepare current path value for comparison (showing red arrow)
1522 $currentIdentifier = '';
1523 if ($this->curUrlInfo['value']) {
1524 $currentIdentifier = $this->curUrlInfo['info'];
1525 }
1526 // Create header element; The folder from which files are listed.
1527 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1528 $folderIcon = IconUtility::getSpriteIconForFile('folder');
1529 $folderIcon .= htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen));
1530 $picon = '<a href="#" onclick="return link_folder(\'file:' . $folder->getCombinedIdentifier() . '\');">' . $folderIcon . '</a>';
1531 if ($this->curUrlInfo['act'] == 'folder' && $currentIdentifier == $folder->getCombinedIdentifier()) {
1532 $out .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
1533 }
1534 $out .= $picon . '<br />';
1535 // Get files from the folder:
1536 if ($renderFolders) {
1537 $items = $folder->getSubfolders();
1538 } else {
1539 $filter = new \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter();
1540 $filter->setAllowedFileExtensions($extensionList);
1541 $folder->getStorage()->setFileAndFolderNameFilters(array(array($filter, 'filterFileList')));
1542
1543 $items = $folder->getFiles();
1544 }
1545 $c = 0;
1546 $totalItems = count($items);
1547 foreach ($items as $fileOrFolderObject) {
1548 $c++;
1549 if ($renderFolders) {
1550 $fileIdentifier = $fileOrFolderObject->getCombinedIdentifier();
1551 $icon = IconUtility::getSpriteIconForFile('folder');
1552 $itemUid = 'file:' . $fileIdentifier;
1553 } else {
1554 $fileIdentifier = $fileOrFolderObject->getUid();
1555 // File icon:
1556 $fileExtension = $fileOrFolderObject->getExtension();
1557 // Get size and icon:
1558 $size = ' (' . GeneralUtility::formatSize($fileOrFolderObject->getSize()) . 'bytes)';
1559 $icon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileOrFolderObject->getName() . $size));
1560 $itemUid = 'file:' . $fileIdentifier;
1561 }
1562 // If the listed file turns out to be the CURRENT file, then show blinking arrow:
1563 if (($this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder') && $currentIdentifier == $fileIdentifier) {
1564 $arrCol = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
1565 } else {
1566 $arrCol = '';
1567 }
1568 // Put it all together for the file element:
1569 $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 />';
1570 }
1571 }
1572 return $out;
1573 }
1574
1575 /**
1576 * For TYPO3 Element Browser: Expand folder of files.
1577 *
1578 * @param \TYPO3\CMS\Core\Resource\Folder $folder The folder path to expand
1579 * @param string $extensionList List of fileextensions to show
1580 * @param boolean $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
1581 * @return string HTML output
1582 * @todo Define visibility
1583 */
1584 public function TBE_expandFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '', $noThumbs = 0) {
1585 $extensionList = $extensionList == '*' ? '' : $extensionList;
1586 $content = '';
1587 if ($folder->checkActionPermission('read')) {
1588 // Listing the files:
1589 $files = $folder->getFiles($extensionList);
1590 $content = $this->fileList($files, $folder, $noThumbs);
1591 }
1592 // Return accumulated content for filelisting:
1593 return $content;
1594 }
1595
1596 /**
1597 * Render list of files.
1598 *
1599 * @param array $files List of files. See \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir
1600 * @param string \TYPO3\CMS\Core\Resource\Folder $folder If set a header with a folder icon and folder name are shown
1601 * @param boolean $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
1602 * @return string HTML output
1603 * @todo Define visibility
1604 */
1605 public function fileList(array $files, \TYPO3\CMS\Core\Resource\Folder $folder = NULL, $noThumbs = 0) {
1606 $out = '';
1607 // Listing the files:
1608 if (is_array($files)) {
1609 $lines = array();
1610 // Create headline (showing number of files):
1611 $filesCount = count($files);
1612 $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', $filesCount));
1613 $out .= '<div id="filelist">';
1614 $out .= $this->getBulkSelector($filesCount);
1615 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1616 // Create the header of current folder:
1617 if ($folder) {
1618 $folderIcon = IconUtility::getSpriteIconForFile('folder');
1619 $lines[] = '<tr class="t3-row-header">
1620 <td colspan="4">' . $folderIcon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</td>
1621 </tr>';
1622 }
1623 if ($filesCount == 0) {
1624 $lines[] = '
1625 <tr class="file_list_normal">
1626 <td colspan="4">No files found.</td>
1627 </tr>';
1628 }
1629 // Init graphic object for reading file dimensions:
1630 /** @var $imgObj \TYPO3\CMS\Core\Imaging\GraphicalFunctions */
1631 $imgObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
1632 $imgObj->init();
1633 $imgObj->mayScaleUp = 0;
1634 $imgObj->tempPath = PATH_site . $imgObj->tempPath;
1635 // Traverse the file list:
1636 foreach ($files as $fileObject) {
1637 $fileExtension = $fileObject->getExtension();
1638 // Thumbnail/size generation:
1639 if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($fileExtension)) && !$noThumbs) {
1640 $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => 64, 'height' => 64))->getPublicUrl(TRUE);
1641 $imgInfo = $imgObj->getImageDimensions($fileObject->getForLocalProcessing(FALSE));
1642 $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
1643 $clickIcon = '<img src="' . $imageUrl . '" hspace="5" vspace="5" border="1" />';
1644 } else {
1645 $clickIcon = '';
1646 $pDim = '';
1647 }
1648 // Create file icon:
1649 $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
1650 $icon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
1651 // Create links for adding the file:
1652 $filesIndex = count($this->elements);
1653 $this->elements['file_' . $filesIndex] = array(
1654 'type' => 'file',
1655 'table' => 'sys_file',
1656 'uid' => $fileObject->getUid(),
1657 'fileName' => $fileObject->getName(),
1658 'filePath' => $fileObject->getUid(),
1659 'fileExt' => $fileExtension,
1660 'fileIcon' => $icon
1661 );
1662 $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
1663 $ATag_alt = substr($ATag, 0, -4) . ',1);">';
1664 $bulkCheckBox = '<input type="checkbox" class="typo3-bulk-item" name="file_' . $filesIndex . '" value="0" /> ';
1665 $ATag_e = '</a>';
1666 // Create link to showing details about the file in a window:
1667 $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'));
1668 $ATag2 = '<a href="' . htmlspecialchars($Ahref) . '">';
1669 $ATag2_e = '</a>';
1670 // Combine the stuff:
1671 $filenameAndIcon = $bulkCheckBox . $ATag_alt . $icon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
1672 // Show element:
1673 // Image...
1674 if ($pDim) {
1675 $lines[] = '
1676 <tr class="file_list_normal">
1677 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1678 <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>
1679 <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>
1680 <td nowrap="nowrap">&nbsp;' . $pDim . '</td>
1681 </tr>';
1682 $lines[] = '
1683 <tr>
1684 <td class="filelistThumbnail" colspan="4">' . $ATag_alt . $clickIcon . $ATag_e . '</td>
1685 </tr>';
1686 } else {
1687 $lines[] = '
1688 <tr class="file_list_normal">
1689 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1690 <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>
1691 <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>
1692 <td>&nbsp;</td>
1693 </tr>';
1694 }
1695 }
1696 // Wrap all the rows in table tags:
1697 $out .= '
1698
1699 <!--
1700 File listing
1701 -->
1702 <table cellpadding="0" cellspacing="0" id="typo3-filelist">
1703 ' . implode('', $lines) . '
1704 </table>';
1705 }
1706 // Return accumulated content for filelisting:
1707 $out .= '</div>';
1708 return $out;
1709 }
1710
1711 /**
1712 * Render list of folders.
1713 *
1714 * @param array $baseFolder List of folders. See \TYPO3\CMS\Core\Utility\GeneralUtility::get_dirs
1715 * @param string $folders If set a header with a folder icon and folder name are shown
1716 * @return string HTML output
1717 * @todo Define visibility
1718 */
1719 public function folderList($baseFolder, $folders) {
1720 $content = '';
1721 // Create headline (showing number of folders):
1722 $content .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('folders') . ' (%s):', count($folders)));
1723 $titleLength = intval($GLOBALS['BE_USER']->uc['titleLen']);
1724 // Create the header of current folder:
1725 if ($baseFolder) {
1726 if (strstr($baseFolder, ',') || strstr($baseFolder, '|')) {
1727 // In case an invalid character is in the filepath, display error message:
1728 $errorMessage = $GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('invalidChar'), ', |'));
1729 $aTag = ($aTag_alt = '<a href="#" onclick="alert(' . $errorMessage . ');return false;">');
1730 } else {
1731 // If foldername is OK, just add it:
1732 $aTag = '<a href="#" onclick="return insertElement(\'\',\'' . rawurlencode($baseFolder) . '\', \'folder\', \'' . rawurlencode($baseFolder) . '\', unescape(\'' . rawurlencode($baseFolder) . '\'), \'' . $fI['extension'] . '\', \'' . $ficon . '\');">';
1733 $aTag_alt = substr($aTag, 0, -4) . ',\'\',1);">';
1734 }
1735 $aTag_e = '</a>';
1736 // Add the foder icon
1737 $folderIcon = $aTag_alt;
1738 $folderIcon .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
1739 $folderIcon .= htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(basename($baseFolder), $titleLength));
1740 $folderIcon .= $aTag_e;
1741 $content .= $folderIcon . '<br />';
1742 }
1743 // Listing the folders:
1744 if (is_array($folders)) {
1745 if (count($folders) > 0) {
1746 // Traverse the folder list:
1747 $lines = array();
1748 foreach ($folders as $folderPath) {
1749 $pathInfo = pathinfo($folderPath);
1750 // Create folder icon:
1751 $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="" />';
1752 // Create links for adding the folder:
1753 if ($this->P['itemName'] != '' && $this->P['formName'] != '') {
1754 $aTag = '<a href="#" onclick="return set_folderpath(unescape(\'' . rawurlencode($folderPath) . '\'));">';
1755 } else {
1756 $aTag = '<a href="#" onclick="return insertElement(\'\',\'' . rawurlencode($folderPath) . '\', \'folder\', \'' . rawurlencode($folderPath) . '\', unescape(\'' . rawurlencode($folderPath) . '\'), \'' . $pathInfo['extension'] . '\', \'' . $ficon . '\');">';
1757 }
1758 if (strstr($folderPath, ',') || strstr($folderPath, '|')) {
1759 // In case an invalid character is in the filepath, display error message:
1760 $errorMessage = $GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('invalidChar'), ', |'));
1761 $aTag = ($aTag_alt = '<a href="#" onclick="alert(' . $errorMessage . ');return false;">');
1762 } else {
1763 // If foldername is OK, just add it:
1764 $aTag_alt = substr($aTag, 0, -4) . ',\'\',1);">';
1765 }
1766 $aTag_e = '</a>';
1767 // Combine icon and folderpath:
1768 $foldernameAndIcon = $aTag_alt . $icon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(basename($folderPath), $titleLength)) . $aTag_e;
1769 if ($this->P['itemName'] != '') {
1770 $lines[] = '
1771 <tr class="bgColor4">
1772 <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
1773 <td>&nbsp;</td>
1774 </tr>';
1775 } else {
1776 $lines[] = '
1777 <tr class="bgColor4">
1778 <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
1779 <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>
1780 <td>&nbsp;</td>
1781 </tr>';
1782 }
1783 $lines[] = '
1784 <tr>
1785 <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td>
1786 </tr>';
1787 }
1788 }
1789 // Wrap all the rows in table tags:
1790 $content .= '
1791
1792 <!--
1793 Folder listing
1794 -->
1795 <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList">
1796 ' . implode('', $lines) . '
1797 </table>';
1798 }
1799 // Return accumulated content for folderlisting:
1800 return $content;
1801 }
1802
1803 /**
1804 * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images.
1805 * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE
1806 *
1807 * @param \TYPO3\CMS\Core\Resource\Folder $folder The folder path to expand
1808 * @param string $extensionList List of fileextensions to show
1809 * @return string HTML output
1810 * @todo Define visibility
1811 */
1812 public function TBE_dragNDrop(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '') {
1813 $extensionList = $extensionList == '*' ? '' : $extensionList;
1814 $out = '';
1815 if ($folder) {
1816 if ($folder->getStorage()->isPublic()) {
1817 // Read files from directory:
1818 $files = $folder->getFiles($extensionList);
1819 if (is_array($files)) {
1820 $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files)));
1821 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
1822 $picon = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
1823 $picon .= htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLen));
1824 $out .= $picon . '<br />';
1825 // Init row-array:
1826 $lines = array();
1827 // Add "drag-n-drop" message:
1828 $lines[] = '
1829 <tr>
1830 <td colspan="2">' . $this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')) . '</td>
1831 </tr>';
1832 // Traverse files:
1833 foreach ($files as $fileObject) {
1834 $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
1835 // URL of image:
1836 $iUrl = GeneralUtility::rawurlencodeFP($fileObject->getPublicUrl(TRUE));
1837 // Show only web-images
1838 $fileExtension = strtolower($fileObject->getExtension());
1839 if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) {
1840 $imgInfo = @getimagesize($fileObject->getForLocalProcessing(FALSE));
1841 $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
1842 $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
1843 $filenameAndIcon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
1844 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('noLimit')) {
1845 $maxW = 10000;
1846 $maxH = 10000;
1847 } else {
1848 $maxW = 380;
1849 $maxH = 500;
1850 }
1851 $IW = $imgInfo[0];
1852 $IH = $imgInfo[1];
1853 if ($IW > $maxW) {
1854 $IH = ceil($IH / $IW * $maxW);
1855 $IW = $maxW;
1856 }
1857 if ($IH > $maxH) {
1858 $IW = ceil($IW / $IH * $maxH);
1859 $IH = $maxH;
1860 }
1861 // Make row:
1862 $lines[] = '
1863 <tr class="bgColor4">
1864 <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1865 <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>
1866 </tr>';
1867 $lines[] = '
1868 <tr>
1869 <td colspan="2"><img src="' . $iUrl . '" data-htmlarea-file-uid="' . $fileObject->getUid() . '" width="' . $IW . '" height="' . $IH . '" border="1" alt="" /></td>
1870 </tr>';
1871 $lines[] = '
1872 <tr>
1873 <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
1874 </tr>';
1875 }
1876 }
1877 // Finally, wrap all rows in a table tag:
1878 $out .= '
1879
1880
1881 <!--
1882 File listing / Drag-n-drop
1883 -->
1884 <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
1885 ' . implode('', $lines) . '
1886 </table>';
1887 }
1888 } else {
1889 // Print this warning if the folder is NOT a web folder:
1890 $out .= $this->barheader($GLOBALS['LANG']->getLL('files'));
1891 $out .= $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2');
1892 }
1893 }
1894 return $out;
1895 }
1896
1897 /******************************************************************
1898 *
1899 * Miscellaneous functions
1900 *
1901 ******************************************************************/
1902 /**
1903 * Verifies that a path is a web-folder:
1904 *
1905 * @param string $folder Absolute filepath
1906 * @return boolean If the input path is found in PATH_site then it returns TRUE.
1907 * @todo Define visibility
1908 */
1909 public function isWebFolder($folder) {
1910 $folder = rtrim($folder, '/') . '/';
1911 return GeneralUtility::isFirstPartOfStr($folder, PATH_site) ? TRUE : FALSE;
1912 }
1913
1914 /**
1915 * Checks, if a path is within the mountpoints of the backend user
1916 *
1917 * @param string $folder Absolute filepath
1918 * @return boolean If the input path is found in the backend users filemounts, then return TRUE.
1919 * @todo Define visibility
1920 */
1921 public function checkFolder($folder) {
1922 return $this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/') ? TRUE : FALSE;
1923 }
1924
1925 /**
1926 * Checks, if a path is within a read-only mountpoint of the backend user
1927 *
1928 * @param string $folder Absolute filepath
1929 * @return boolean If the input path is found in the backend users filemounts and if the filemount is of type readonly, then return TRUE.
1930 * @todo Define visibility
1931 */
1932 public function isReadOnlyFolder($folder) {
1933 return $GLOBALS['FILEMOUNTS'][$this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/')]['type'] == 'readonly';
1934 }
1935
1936 /**
1937 * Prints a 'header' where string is in a tablecell
1938 *
1939 * @param string $str The string to print in the header. The value is htmlspecialchars()'ed before output.
1940 * @return string The header HTML (wrapped in a table)
1941 * @todo Define visibility
1942 */
1943 public function barheader($str) {
1944 return '
1945 <!-- Bar header: -->
1946 <h3>' . htmlspecialchars($str) . '</h3>
1947 ';
1948 }
1949
1950 /**
1951 * Displays a message box with the input message
1952 *
1953 * @param string $in_msg Input message to show (will be htmlspecialchars()'ed inside of this function)
1954 * @param string $icon Icon filename body from gfx/ (default is "icon_note") - meant to allow change to warning type icons...
1955 * @return string HTML for the message (wrapped in a table).
1956 * @todo Define visibility
1957 */
1958 public function getMsgBox($in_msg, $icon = 'icon_note') {
1959 $msg = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/' . $icon . '.gif'), 'width="18" height="16"') . ' alt="" />' . htmlspecialchars($in_msg);
1960 $msg = '
1961
1962 <!--
1963 Message box:
1964 -->
1965 <table cellspacing="0" class="bgColor4" id="typo3-msgBox">
1966 <tr>
1967 <td>' . $msg . '</td>
1968 </tr>
1969 </table>
1970 ';
1971 return $msg;
1972 }
1973
1974 /**
1975 * For RTE/link: This prints the 'currentUrl'
1976 *
1977 * @param string $str URL value. The value is htmlspecialchars()'ed before output.
1978 * @return string HTML content, wrapped in a table.
1979 * @todo Define visibility
1980 */
1981 public function printCurrentUrl($str) {
1982 // Output the folder or file identifier, when working with files
1983 if (isset($str) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($str) && ($this->act === 'file' || $this->act === 'folder')) {
1984 try {
1985 $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($str);
1986 if (is_object($fileObject)) {
1987 $str = $fileObject->getIdentifier();
1988 }
1989 } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
1990 $str = '';
1991 }
1992 }
1993 if (strlen($str)) {
1994 return '
1995 <!-- Print current URL -->
1996 <table border="0" cellpadding="0" cellspacing="0" id="typo3-curUrl">
1997 <tr>
1998 <td>' . $GLOBALS['LANG']->getLL('currentLink', TRUE) . ': ' . htmlspecialchars(rawurldecode($str)) . '</td>
1999 </tr>
2000 </table>';
2001 } else {
2002 return '';
2003 }
2004 }
2005
2006 /**
2007 * For RTE/link: Parses the incoming URL and determines if it's a page, file, external or mail address.
2008 *
2009 * @param string $href HREF value tp analyse
2010 * @param string $siteUrl The URL of the current website (frontend)
2011 * @return array Array with URL information stored in assoc. keys: value, act (page, file, spec, mail), pageid, cElement, info
2012 * @todo Define visibility
2013 */
2014 public function parseCurUrl($href, $siteUrl) {
2015 $href = trim($href);
2016 if ($href) {
2017 $info = array();
2018 // Default is "url":
2019 $info['value'] = $href;
2020 $info['act'] = 'url';
2021 $specialParts = explode('#_SPECIAL', $href);
2022 // Special kind (Something RTE specific: User configurable links through: "userLinks." from ->thisConfig)
2023 if (count($specialParts) == 2) {
2024 $info['value'] = '#_SPECIAL' . $specialParts[1];
2025 $info['act'] = 'spec';
2026 } elseif (strpos($href, 'file:') !== FALSE) {
2027 $rel = substr($href, strpos($href, 'file:') + 5);
2028 $rel = rawurldecode($rel);
2029 // resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier"
2030 $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($rel);
2031 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
2032 $info['act'] = 'folder';
2033 $info['value'] = $fileOrFolderObject->getCombinedIdentifier();
2034 } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
2035 $info['act'] = 'file';
2036 $info['value'] = $fileOrFolderObject->getUid();
2037 } else {
2038 $info['value'] = $rel;
2039 }
2040 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($href, $siteUrl)) {
2041 // If URL is on the current frontend website:
2042 // URL is a file, which exists:
2043 if (file_exists(PATH_site . rawurldecode($href))) {
2044 $info['value'] = rawurldecode($href);
2045 if (@is_dir((PATH_site . $info['value']))) {
2046 $info['act'] = 'folder';
2047 } else {
2048 $info['act'] = 'file';
2049 }
2050 } else {
2051 // URL is a page (id parameter)
2052 $uP = parse_url($href);
2053
2054 $pp = preg_split('/^id=/', $uP['query']);
2055 $pp[1] = preg_replace('/&id=[^&]*/', '', $pp[1]);
2056 $parameters = explode('&', $pp[1]);
2057 $id = array_shift($parameters);
2058 if ($id) {
2059 // Checking if the id-parameter is an alias.
2060 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($id)) {
2061 list($idPartR) = BackendUtility::getRecordsByField('pages', 'alias', $id);
2062 $id = intval($idPartR['uid']);
2063 }
2064 $pageRow = BackendUtility::getRecordWSOL('pages', $id);
2065 $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
2066 $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'] : '')) . ')';
2067 $info['pageid'] = $id;
2068 $info['cElement'] = $uP['fragment'];
2069 $info['act'] = 'page';
2070 $info['query'] = $parameters[0] ? '&' . implode('&', $parameters) : '';
2071 }
2072 }
2073 } else {
2074 // Email link:
2075 if (strtolower(substr($href, 0, 7)) == 'mailto:') {
2076 $info['value'] = trim(substr($href, 7));
2077 $info['act'] = 'mail';
2078 }
2079 }
2080 $info['info'] = $info['value'];
2081 } else {
2082 // NO value inputted:
2083 $info = array();
2084 $info['info'] = $GLOBALS['LANG']->getLL('none');
2085 $info['value'] = '';
2086 $info['act'] = 'page';
2087 }
2088 // let the hook have a look
2089 foreach ($this->hookObjects as $hookObject) {
2090 $info = $hookObject->parseCurrentUrl($href, $siteUrl, $info);
2091 }
2092 return $info;
2093 }
2094
2095 /**
2096 * Setter for the class that should be used by TBE_expandPage()
2097 * to generate the record list.
2098 *
2099 * @param \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList $recordList
2100 * @throws \InvalidArgumentException
2101 * @return void
2102 */
2103 public function setRecordList($recordList) {
2104 if (!$recordList instanceof \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList) {
2105 throw new \InvalidArgumentException('$recordList needs to be an instance of \\TYPO3\\CMS\\Backend\\RecordList\\ElementBrowserRecordList', 1370878522);
2106 }
2107 $this->recordList = $recordList;
2108 }
2109
2110 /**
2111 * For TBE: Makes an upload form for uploading files to the filemount the user is browsing.
2112 * The files are uploaded to the tce_file.php script in the core which will handle the upload.
2113 *
2114 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Absolute filepath on server to which to upload.
2115 * @return string HTML for an upload form.
2116 * @todo Define visibility
2117 */
2118 public function uploadForm(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
2119 if (!$folderObject->checkActionPermission('write')) {
2120 return '';
2121 }
2122 // Read configuration of upload field count
2123 $userSetting = $GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
2124 $count = isset($userSetting) ? $userSetting : 3;
2125 if ($count === '0') {
2126 return '';
2127 }
2128 $count = intval($count) == 0 ? 3 : intval($count);
2129 // Create header, showing upload path:
2130 $header = $folderObject->getIdentifier();
2131 $code = '
2132 <br />
2133 <!--
2134 Form, for uploading files:
2135 -->
2136 <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform" id="typo3-uplFilesForm" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">
2137 <table border="0" cellpadding="0" cellspacing="0" id="typo3-uplFiles">
2138 <tr>
2139 <td>' . $this->barheader(($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle', TRUE) . ':')) . '</td>
2140 </tr>
2141 <tr>
2142 <td class="c-wCell c-hCell"><strong>' . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> ' . htmlspecialchars($header) . '</td>
2143 </tr>
2144 <tr>
2145 <td class="c-wCell c-hCell">';
2146 // Traverse the number of upload fields (default is 3):
2147 for ($a = 1; $a <= $count; $a++) {
2148 $code .= '<input type="file" multiple="multiple" name="upload_' . $a . '"' . $this->doc->formWidth(35) . ' size="50" />
2149 <input type="hidden" name="file[upload][' . $a . '][target]" value="' . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />
2150 <input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br />';
2151 }
2152 // Make footer of upload form, including the submit button:
2153 $redirectValue = $this->thisScript . '?act=' . $this->act . '&mode=' . $this->mode . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier()) . '&bparams=' . rawurlencode($this->bparams);
2154 $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
2155 $code .= '
2156 <div id="c-override">
2157 <label><input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', TRUE) . '</label>
2158 </div>
2159 <input type="submit" name="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', TRUE) . '" />
2160 ';
2161 $code .= '</td>
2162 </tr>
2163 </table>
2164 </form><br />';
2165 return $code;
2166 }
2167
2168 /**
2169 * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
2170 * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
2171 *
2172 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Absolute filepath on server in which to create the new folder.
2173 * @return string HTML for the create folder form.
2174 * @todo Define visibility
2175 */
2176 public function createFolder(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
2177 if (!$folderObject->checkActionPermission('write')) {
2178 return '';
2179 }
2180 // Don't show Folder-create form if it's denied
2181 if ($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.hideCreateFolder')) {
2182 return '';
2183 }
2184 // Create header, showing upload path:
2185 $header = $folderObject->getIdentifier();
2186 $code = '
2187
2188 <!--
2189 Form, for creating new folders:
2190 -->
2191 <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform2" id="typo3-crFolderForm">
2192 <table border="0" cellpadding="0" cellspacing="0" id="typo3-crFolder">
2193 <tr>
2194 <td>' . $this->barheader(($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle') . ':')) . '</td>
2195 </tr>
2196 <tr>
2197 <td class="c-wCell c-hCell"><strong>' . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> ' . htmlspecialchars($header) . '</td>
2198 </tr>
2199 <tr>
2200 <td class="c-wCell c-hCell">';
2201 // Create the new-folder name field:
2202 $a = 1;
2203 $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()) . '" />';
2204 // Make footer of upload form, including the submit button:
2205 $redirectValue = $this->thisScript . '?act=' . $this->act . '&mode=' . $this->mode . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier()) . '&bparams=' . rawurlencode($this->bparams);
2206 $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) . '" />';
2207 $code .= '</td>
2208 </tr>
2209 </table>
2210 </form>';
2211 return $code;
2212 }
2213
2214 /**
2215 * Get the HTML data required for a bulk selection of files of the TYPO3 Element Browser.
2216 *
2217 * @param integer $filesCount Number of files currently displayed
2218 * @return string HTML data required for a bulk selection of files - if $filesCount is 0, nothing is returned
2219 * @todo Define visibility
2220 */
2221 public function getBulkSelector($filesCount) {
2222 if ($filesCount) {
2223 $labelToggleSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:toggleSelection', TRUE);
2224 $labelImportSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:importSelection', TRUE);
2225 // Getting flag for showing/not showing thumbnails:
2226 $noThumbsInEB = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
2227 $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>';
2228 $thumbNailCheck = '';
2229 if (!$noThumbsInEB && $this->selectedFolder) {
2230 // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
2231 $_MOD_MENU = array('displayThumbs' => '');
2232 $_MCONF['name'] = 'file_list';
2233 $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']);
2234 $addParams = '&act=' . $this->act . '&mode=' . $this->mode . '&expandFolder=' . rawurlencode($this->selectedFolder->getCombinedIdentifier()) . '&bparams=' . rawurlencode($this->bparams);
2235 $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>';
2236 $out .= $this->doc->spacer(5) . $thumbNailCheck . $this->doc->spacer(15);
2237 } else {
2238 $out .= $this->doc->spacer(15);
2239 }
2240 }
2241 return $out;
2242 }
2243
2244 /**
2245 * Determines whether submitted field change functions are valid
2246 * and are coming from the system and not from an external abuse.
2247 *
2248 * @param boolean $handleFlexformSections Whether to handle flexform sections differently
2249 * @return boolean Whether the submitted field change functions are valid
2250 */
2251 protected function areFieldChangeFunctionsValid($handleFlexformSections = FALSE) {
2252 $result = FALSE;
2253 if (isset($this->P['fieldChangeFunc']) && is_array($this->P['fieldChangeFunc']) && isset($this->P['fieldChangeFuncHash'])) {
2254 $matches = array();
2255 $pattern = '#\\[el\\]\\[(([^]-]+-[^]-]+-)(idx\\d+-)([^]]+))\\]#i';
2256 $fieldChangeFunctions = $this->P['fieldChangeFunc'];
2257 // Special handling of flexform sections:
2258 // Field change functions are modified in JavaScript, thus the hash is always invalid
2259 if ($handleFlexformSections && preg_match($pattern, $this->P['itemName'], $matches)) {
2260 $originalName = $matches[1];
2261 $cleanedName = $matches[2] . $matches[4];
2262 foreach ($fieldChangeFunctions as &$value) {
2263 $value = str_replace($originalName, $cleanedName, $value);
2264 }
2265 unset($value);
2266 }
2267 $result = $this->P['fieldChangeFuncHash'] === GeneralUtility::hmac(serialize($fieldChangeFunctions));
2268 }
2269 return $result;
2270 }
2271
2272 }