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