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