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