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