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