TYPO3 CMS  TYPO3_6-2
ElementBrowser.php
Go to the documentation of this file.
1 <?php
3 
22 
29 
36  protected $recordList = NULL;
37 
44  public $siteURL;
45 
51  public $thisScript;
52 
58  public $thisConfig;
59 
65  public $setTarget;
66 
72  public $setClass;
73 
79  public $setTitle;
80 
84  public $setParams;
85 
92  public $doc;
93 
99  public $elements = array();
100 
113  public $mode;
114 
123  public $act;
124 
132  public $expandPage;
133 
144 
150  protected $selectedFolder;
151 
159  public $P;
160 
184  public $bparams;
185 
194 
200  public $PM;
201 
207  public $pointer;
208 
217  public $curUrlArray;
218 
227  public $curUrlInfo;
228 
233  protected $hookObjects = array();
234 
239 
243  protected function determineScriptUrl() {
244  if ($moduleName = GeneralUtility::_GP('M')) {
245  $this->thisScript = BackendUtility::getModuleUrl($moduleName);
246  } else {
247  $this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
248  }
249  }
250 
257  public function getThisScript() {
258  return strpos($this->thisScript, '?') === FALSE ? $this->thisScript . '?' : $this->thisScript . '&';
259  }
260 
269  public function init() {
270  $this->initVariables();
271 
272  $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
273  $this->initConfiguration();
274  $this->initDocumentTemplate();
275  // init hook objects:
276  $this->initHookObjects('typo3/class.browse_links.php');
277 
278  $this->initCurrentUrl();
279 
280  // Determine nature of current url:
281  $this->act = GeneralUtility::_GP('act');
282  if (!$this->act) {
283  $this->act = $this->curUrlInfo['act'];
284  }
285 
286  // Initializing the target value (RTE)
287  $this->setTarget = $this->curUrlArray['target'] != '-' ? $this->curUrlArray['target'] : '';
288  if ($this->thisConfig['defaultLinkTarget'] && !isset($this->curUrlArray['target'])) {
289  $this->setTarget = $this->thisConfig['defaultLinkTarget'];
290  }
291  // Initializing the class value (RTE)
292  $this->setClass = $this->curUrlArray['class'] != '-' ? $this->curUrlArray['class'] : '';
293  // Initializing the title value (RTE)
294  $this->setTitle = $this->curUrlArray['title'] != '-' ? $this->curUrlArray['title'] : '';
295  // Initializing the params value
296  $this->setParams = $this->curUrlArray['params'] != '-' ? $this->curUrlArray['params'] : '';
297 
298  // Finally, add the accumulated JavaScript to the template object:
299  // also unset the default jumpToUrl() function before
300  unset($this->doc->JScodeArray['jumpToUrl']);
301  $this->doc->JScode .= $this->doc->wrapScriptTags($this->getJSCode());
302  }
303 
309  public function initVariables() {
310  // Main GPvars:
311  $this->pointer = GeneralUtility::_GP('pointer');
312  $this->bparams = GeneralUtility::_GP('bparams');
313  $this->P = GeneralUtility::_GP('P');
314  $this->expandPage = GeneralUtility::_GP('expandPage');
315  $this->expandFolder = GeneralUtility::_GP('expandFolder');
316  $this->PM = GeneralUtility::_GP('PM');
317 
318  // Site URL
319  // Current site url
320  $this->siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
321  $this->determineScriptUrl();
322 
323  // Find "mode"
324  $this->mode = GeneralUtility::_GP('mode');
325  if (!$this->mode) {
326  $this->mode = 'rte';
327  }
328 
329  // Init fileProcessor
330  $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
331  $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
332  }
333 
339  public function initConfiguration() {
340  // Rich Text Editor specific configuration:
341  if ((string) $this->mode === 'rte') {
342  $this->thisConfig = $this->getRTEConfig();
343  }
344  }
345 
351  protected function initDocumentTemplate() {
352  // Creating backend template object:
353  $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
354  $this->doc->bodyTagId = 'typo3-browse-links-php';
355  $this->doc->backPath = $GLOBALS['BACK_PATH'];
356  // Load the Prototype library and browse_links.js
357  $this->doc->getPageRenderer()->loadPrototype();
358  $this->doc->loadJavascriptLib('js/browse_links.js');
359  $this->doc->loadJavascriptLib('js/tree.js');
360  }
361 
369  protected function initHookObjects($hookKey) {
370  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookKey]['browseLinksHook'])) {
371  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookKey]['browseLinksHook'] as $classData) {
372  $processObject = GeneralUtility::getUserObj($classData);
373  if (!$processObject instanceof \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface) {
374  throw new \UnexpectedValueException('$processObject must implement interface TYPO3\\CMS\\Core\\ElementBrowser\\ElementBrowserHookInterface', 1195039394);
375  }
376  $parameters = array();
377  $processObject->init($this, $parameters);
378  $this->hookObjects[] = $processObject;
379  }
380  }
381  }
382 
388  protected function initCurrentUrl() {
389  // CurrentUrl - the current link url must be passed around if it exists
390  if ($this->mode == 'wizard') {
391  $currentValues = GeneralUtility::trimExplode(LF, trim($this->P['currentValue']));
392  if (count($currentValues) > 0) {
393  $currentValue = array_pop($currentValues);
394  } else {
395  $currentValue = '';
396  }
397  $currentLinkParts = GeneralUtility::unQuoteFilenames($currentValue, TRUE);
398  $initialCurUrlArray = array(
399  'href' => $currentLinkParts[0],
400  'target' => $currentLinkParts[1],
401  'class' => $currentLinkParts[2],
402  'title' => $currentLinkParts[3],
403  'params' => $currentLinkParts[4]
404  );
405  $this->curUrlArray = is_array(GeneralUtility::_GP('curUrl'))
406  ? array_merge($initialCurUrlArray, GeneralUtility::_GP('curUrl'))
407  : $initialCurUrlArray;
408  // Additional fields for page links
409  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'])
410  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'])
411  ) {
412  $conf = array();
413  $_params = array(
414  'conf' => &$conf,
415  'linkParts' => $currentLinkParts
416  );
417  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendUrlArray'] as $objRef) {
418  $processor =& GeneralUtility::getUserObj($objRef);
419  $processor->extendUrlArray($_params, $this);
420  }
421  }
422  $this->curUrlInfo = $this->parseCurUrl($this->siteURL . '?id=' . $this->curUrlArray['href'], $this->siteURL);
423  // pageid == 0 means that this is not an internal (page) link
424  if ($this->curUrlInfo['pageid'] == 0 && $this->curUrlArray['href']) {
425  // Check if there is the FAL API
426  if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], 'file:')) {
427  $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
428  // Remove the "file:" prefix
429  $currentLinkParts[0] = rawurldecode(substr($this->curUrlArray['href'], 5));
430  } elseif (file_exists(PATH_site . rawurldecode($this->curUrlArray['href']))) {
431  if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], PATH_site)) {
432  $currentLinkParts[0] = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->curUrlArray['href']);
433  }
434  $this->curUrlInfo = $this->parseCurUrl($this->siteURL . $this->curUrlArray['href'], $this->siteURL);
435  } elseif (strstr($this->curUrlArray['href'], '@')) {
436  // check for email link
437  if (GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], 'mailto:')) {
438  $currentLinkParts[0] = substr($this->curUrlArray['href'], 7);
439  }
440  $this->curUrlInfo = $this->parseCurUrl('mailto:' . $this->curUrlArray['href'], $this->siteURL);
441  } else {
442  // nothing of the above. this is an external link
443  if (strpos($this->curUrlArray['href'], '://') === FALSE) {
444  $currentLinkParts[0] = 'http://' . $this->curUrlArray['href'];
445  }
446  $this->curUrlInfo = $this->parseCurUrl($currentLinkParts[0], $this->siteURL);
447  }
448  } elseif (!$this->curUrlArray['href']) {
449  $this->curUrlInfo = array();
450  $this->act = 'page';
451  } else {
452  $this->curUrlInfo = $this->parseCurUrl($this->siteURL . '?id=' . $this->curUrlArray['href'], $this->siteURL);
453  }
454  } else {
455  $this->curUrlArray = GeneralUtility::_GP('curUrl');
456  if ($this->curUrlArray['all']) {
457  $this->curUrlArray = GeneralUtility::get_tag_attributes($this->curUrlArray['all']);
458  }
459  $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
460  }
461  }
462 
468  protected function getRTEConfig() {
469  $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
470  $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
471  return BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
472  }
473 
480  public function getJsCode() {
481  // Rich Text Editor specific configuration:
482  $addPassOnParams = '';
483  if ((string) $this->mode == 'rte') {
484  $addPassOnParams .= '&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams);
485  }
486  // BEGIN accumulation of header JavaScript:
487  $JScode = '
488  // This JavaScript is primarily for RTE/Link. jumpToUrl is used in the other cases as well...
489  var add_href=' . GeneralUtility::quoteJSvalue($this->curUrlArray['href'] ? '&curUrl[href]=' . rawurlencode($this->curUrlArray['href']) : '') . ';
490  var add_target=' . GeneralUtility::quoteJSvalue($this->setTarget ? '&curUrl[target]=' . rawurlencode($this->setTarget) : '') . ';
491  var add_class=' . GeneralUtility::quoteJSvalue($this->setClass ? '&curUrl[class]=' . rawurlencode($this->setClass) : '') . ';
492  var add_title=' . GeneralUtility::quoteJSvalue($this->setTitle ? '&curUrl[title]=' . rawurlencode($this->setTitle) : '') . ';
493  var add_params=' . GeneralUtility::quoteJSvalue($this->bparams ? '&bparams=' . rawurlencode($this->bparams) : '') . ';
494 
495  var cur_href=' . GeneralUtility::quoteJSvalue($this->curUrlArray['href'] ?: '') . ';
496  var cur_target=' . GeneralUtility::quoteJSvalue($this->setTarget ?: '') . ';
497  var cur_class=' . GeneralUtility::quoteJSvalue($this->setClass ?: '') . ';
498  var cur_title=' . GeneralUtility::quoteJSvalue($this->setTitle ?: '') . ';
499  var cur_params=' . GeneralUtility::quoteJSvalue($this->setParams ?: '') . ';
500 
501  function browse_links_setTarget(target) { //
502  cur_target=target;
503  add_target="&curUrl[target]="+encodeURIComponent(target);
504  }
505  function browse_links_setClass(cssClass) { //
506  cur_class = cssClass;
507  add_class = "&curUrl[class]=" + encodeURIComponent(cssClass);
508  }
509  function browse_links_setTitle(title) { //
510  cur_title=title;
511  add_title="&curUrl[title]="+encodeURIComponent(title);
512  }
513  function browse_links_setValue(value) { //
514  cur_href=value;
515  add_href="&curUrl[href]="+encodeURIComponent(value);
516  }
517  function browse_links_setParams(params) { //
518  cur_params=params;
519  add_params="&curUrl[params]="+encodeURIComponent(params);
520  }
521  ';
522  // Functions used, if the link selector is in wizard mode (= TCEforms fields)
523  if ($this->mode == 'wizard') {
524  if (!$this->areFieldChangeFunctionsValid() && !$this->areFieldChangeFunctionsValid(TRUE)) {
525  $this->P['fieldChangeFunc'] = array();
526  }
527  unset($this->P['fieldChangeFunc']['alert']);
528  $update = '';
529  foreach ($this->P['fieldChangeFunc'] as $v) {
530  $update .= '
531  window.opener.' . $v;
532  }
533  $P2 = array();
534  $P2['uid'] = $this->P['uid'];
535  $P2['pid'] = $this->P['pid'];
536  $P2['itemName'] = $this->P['itemName'];
537  $P2['formName'] = $this->P['formName'];
538  $P2['fieldChangeFunc'] = $this->P['fieldChangeFunc'];
539  $P2['fieldChangeFuncHash'] = GeneralUtility::hmac(serialize($this->P['fieldChangeFunc']));
540  $P2['params']['allowedExtensions'] = isset($this->P['params']['allowedExtensions']) ? $this->P['params']['allowedExtensions'] : '';
541  $P2['params']['blindLinkOptions'] = isset($this->P['params']['blindLinkOptions']) ? $this->P['params']['blindLinkOptions'] : '';
542  $P2['params']['blindLinkFields'] = isset($this->P['params']['blindLinkFields']) ? $this->P['params']['blindLinkFields']: '';
543  $addPassOnParams .= GeneralUtility::implodeArrayForUrl('P', $P2);
544  $JScode .= '
545  function link_typo3Page(id,anchor) { //
546  updateValueInMainForm(id + (anchor ? anchor : ""));
547  close();
548  return false;
549  }
550  function link_folder(folder) { //
551  updateValueInMainForm(folder);
552  close();
553  return false;
554  }
555  function link_current() { //
556  if (cur_href!="http://" && cur_href!="mailto:") {
557  returnBeforeCleaned = cur_href;
558  if (returnBeforeCleaned.substr(0, 7) == "http://") {
559  returnToMainFormValue = returnBeforeCleaned.substr(7);
560  } else if (returnBeforeCleaned.substr(0, 7) == "mailto:") {
561  if (returnBeforeCleaned.substr(0, 14) == "mailto:mailto:") {
562  returnToMainFormValue = returnBeforeCleaned.substr(14);
563  } else {
564  returnToMainFormValue = returnBeforeCleaned.substr(7);
565  }
566  } else {
567  returnToMainFormValue = returnBeforeCleaned;
568  }
569  updateValueInMainForm(returnToMainFormValue);
570  close();
571  }
572  return false;
573  }
574  function checkReference() { //
575  if (window.opener && window.opener.document && window.opener.document.' . $this->P['formName']
576  . ' && window.opener.document.' . $this->P['formName'] . '[' . GeneralUtility::quoteJSvalue($this->P['itemName']) . '] ) {
577  return window.opener.document.' . $this->P['formName'] . '[' . GeneralUtility::quoteJSvalue($this->P['itemName']) . '];
578  } else {
579  close();
580  }
581  }
582  function updateValueInMainForm(input) { //
583  var field = checkReference();
584  if (field) {
585  if (cur_target == "" && (cur_class != "" || cur_title != "" || cur_params != "")) {
586  cur_target = "-";
587  }
588  if (cur_class == "" && (cur_title != "" || cur_params != "")) {
589  cur_class = "-";
590  }
591  cur_class = cur_class.replace(/[\'\\"]/g, "");
592  if (cur_class.indexOf(" ") != -1) {
593  cur_class = "\\"" + cur_class + "\\"";
594  }
595  if (cur_title == "" && cur_params != "") {
596  cur_title = "-";
597  }
598  cur_title = cur_title.replace(/(^\\")|(\\"$)/g, "");
599  if (cur_title.indexOf(" ") != -1) {
600  cur_title = "\\"" + cur_title + "\\"";
601  }
602  if (cur_params) {
603  cur_params = cur_params.replace(/\\bid\\=.*?(\\&|$)/, "");
604  }
605  input = input + " " + cur_target + " " + cur_class + " " + cur_title + " " + cur_params;
606  input = input.replace(/^\s+|\s+$/g, "");
607  if(field.value && field.className.search(/textarea/) != -1) {
608  field.value += "\\n" + input;
609  } else {
610  field.value = input;
611  }
612  field.onchange();
613  ' . $update . '
614  }
615  }
616  ';
617  } else {
618  // Functions used, if the link selector is in RTE mode:
619  $JScode .= '
620  function link_typo3Page(id,anchor) { //
621  var theLink = ' . GeneralUtility::quoteJSvalue($this->siteURL) . '+\'?id=\'+id+(anchor?anchor:"");
622  self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
623  return false;
624  }
625  function link_folder(folder) { //
626  var theLink = ' . GeneralUtility::quoteJSvalue($this->siteURL) . '+folder;
627  self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
628  return false;
629  }
630  function link_spec(theLink) { //
631  self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
632  return false;
633  }
634  function link_current() { //
635  if (cur_href!="http://" && cur_href!="mailto:") {
636  self.parent.parent.renderPopup_addLink(cur_href, cur_target, cur_class, cur_title);
637  }
638  return false;
639  }
640  ';
641  }
642  // General "jumpToUrl" function:
643  $JScode .= '
644  function jumpToUrl(URL,anchor) { //
645  if (URL.charAt(0) === \'?\') {
646  URL = ' . GeneralUtility::quoteJSvalue($this->getThisScript()) . ' + URL.substring(1);
647  }
648  var add_act = URL.indexOf("act=")==-1 ? "&act="+' . GeneralUtility::quoteJSvalue($this->act) . ' : "";
649  var add_mode = URL.indexOf("mode=")==-1 ? "&mode="+' . GeneralUtility::quoteJSvalue($this->mode) . ' : "";
650  var theLocation = URL + add_act + add_mode + add_href + add_target + add_class + add_title + add_params'
651  . ($addPassOnParams ? '+' . GeneralUtility::quoteJSvalue($addPassOnParams) : '')
652  . '+(typeof(anchor)=="string"?anchor:"");
653  window.location.href = theLocation;
654  return false;
655  }
656  ';
662  $pArr = explode('|', $this->bparams);
663  // This is JavaScript especially for the TBE Element Browser!
664  // insertElement - Call check function (e.g. for uniqueness handling):
665  $JScodeCheck = '';
666  if ($pArr[4] && $pArr[5]) {
667  $JScodeCheck = '
668  // Call a check function in the opener window (e.g. for uniqueness handling):
669  if (parent.window.opener) {
670  var res = parent.window.opener.' . $pArr[5] . '(' . GeneralUtility::quoteJSvalue($pArr[4]) . ',table,uid,type);
671  if (!res.passed) {
672  if (res.message) alert(res.message);
673  performAction = false;
674  }
675  } else {
676  alert("Error - reference to main window is not set properly!");
677  parent.close();
678  }
679  ';
680  }
681  // insertElement - Call helper function:
682  $JScodeHelper = '';
683  if ($pArr[4] && $pArr[6]) {
684  $JScodeHelper = '
685  // Call helper function to manage data in the opener window:
686  if (parent.window.opener) {
687  parent.window.opener.' . $pArr[6] . '(' . GeneralUtility::quoteJSvalue($pArr[4]) . ',table,uid,type,' . GeneralUtility::quoteJSvalue($pArr[0]) . ');
688  } else {
689  alert("Error - reference to main window is not set properly!");
690  parent.close();
691  }
692  ';
693  }
694  // insertElement - perform action commands:
695  $JScodeActionMultiple = '';
696  if ($pArr[4] && $pArr[7]) {
697  // Call user defined action function:
698  $JScodeAction = '
699  if (parent.window.opener) {
700  parent.window.opener.' . $pArr[7] . '(' . GeneralUtility::quoteJSvalue($pArr[4]) . ',table,uid,type);
701  if (close) { focusOpenerAndClose(close); }
702  } else {
703  alert("Error - reference to main window is not set properly!");
704  if (close) { parent.close(); }
705  }
706  ';
707  $JScodeActionMultiple = '
708  // Call helper function to manage data in the opener window:
709  if (parent.window.opener) {
710  parent.window.opener.' . $pArr[7] . 'Multiple(' . GeneralUtility::quoteJSvalue($pArr[4]) . ',table,uid,type,"'
711  . addslashes($pArr[0]) . '");
712  } else {
713  alert("Error - reference to main window is not set properly!");
714  parent.close();
715  }
716  ';
717  } elseif ($pArr[0] && !$pArr[1] && !$pArr[2]) {
718  $JScodeAction = '
719  addElement(filename,table+"_"+uid,fp,close);
720  ';
721  } else {
722  $JScodeAction = '
723  if (setReferences()) {
724  parent.window.opener.group_change("add",'
725  . GeneralUtility::quoteJSvalue($pArr[0]) . ','
726  . GeneralUtility::quoteJSvalue($pArr[1]) . ','
727  . GeneralUtility::quoteJSvalue($pArr[2]) . ',elRef,targetDoc);
728  } else {
729  alert("Error - reference to main window is not set properly!");
730  }
731  focusOpenerAndClose(close);
732  ';
733  }
734  $formFieldName = 'data[' . $pArr[0] . '][' . $pArr[1] . '][' . $pArr[2] . ']';
735  $JScode .= '
736  var elRef="";
737  var targetDoc="";
738 
739  function launchView(url) { //
740  var thePreviewWindow="";
741  thePreviewWindow = window.open("' . $GLOBALS['BACK_PATH'] . 'show_item.php?table="+url,"ShowItem",'
742  . '"height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
743  if (thePreviewWindow && thePreviewWindow.focus) {
744  thePreviewWindow.focus();
745  }
746  }
747  function setReferences() { //
748  if (parent.window.opener && parent.window.opener.content && parent.window.opener.content.document.editform'
749  . '&& parent.window.opener.content.document.editform[' . GeneralUtility::quoteJSvalue($formFieldName) . ']) {
750  targetDoc = parent.window.opener.content.document;
751  elRef = targetDoc.editform[' . GeneralUtility::quoteJSvalue($formFieldName) . '];
752  return true;
753  } else {
754  return false;
755  }
756  }
757  function insertElement(table, uid, type, filename, fp, filetype, imagefile, action, close) { //
758  var performAction = true;
759  ' . $JScodeCheck . '
760  // Call performing function and finish this action:
761  if (performAction) {
762  ' . $JScodeHelper . $JScodeAction . '
763  }
764  return false;
765  }
766  var _hasActionMultipleCode = ' . (!empty($JScodeActionMultiple) ? 'true' : 'false') . ';
767  function insertMultiple(table, uid) {
768  var type = "";
769  ' . $JScodeActionMultiple . '
770  return false;
771  }
772  function addElement(elName, elValue, altElValue, close) { //
773  if (parent.window.opener && parent.window.opener.setFormValueFromBrowseWin) {
774  parent.window.opener.setFormValueFromBrowseWin(' . GeneralUtility::quoteJSvalue($pArr[0]) . ',altElValue?altElValue:elValue,elName);
775  focusOpenerAndClose(close);
776  } else {
777  alert("Error - reference to main window is not set properly!");
778  parent.close();
779  }
780  }
781  function focusOpenerAndClose(close) { //
782  BrowseLinks.focusOpenerAndClose(close);
783  }
784  ';
785  // extends JavaScript code
786  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'])
787  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'])
788  ) {
789  $conf = array();
790  $update = '';
791  $_params = array(
792  'conf' => &$conf,
793  'wizardUpdate' => $update,
794  'addPassOnParams' => $addPassOnParams
795  );
796  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['extendJScode'] as $objRef) {
797  $processor =& GeneralUtility::getUserObj($objRef);
798  $JScode .= $processor->extendJScode($_params, $this);
799  }
800  }
801  return $JScode;
802  }
803 
812  public function processSessionData($data) {
813  $store = FALSE;
814  switch ((string) $this->mode) {
815  case 'db':
816  if (isset($this->expandPage)) {
817  $data['expandPage'] = $this->expandPage;
818  $store = TRUE;
819  } else {
820  $this->expandPage = $data['expandPage'];
821  }
822  break;
823  case 'file':
824 
825  case 'filedrag':
826 
827  case 'folder':
828  if (isset($this->expandFolder)) {
829  $data['expandFolder'] = $this->expandFolder;
830  $store = TRUE;
831  } else {
832  $this->expandFolder = $data['expandFolder'];
833  }
834  break;
835  }
836  return array($data, $store);
837  }
838 
839  /******************************************************************
840  *
841  * Main functions
842  *
843  ******************************************************************/
853  public function main_rte($wiz = FALSE) {
854  // Starting content:
855  $content = $this->doc->startPage('RTE link');
856  // Add the FlashMessages if any
857  $content .= $this->doc->getFlashMessages();
858 
859  // Initializing the action value, possibly removing blinded values etc:
860  $blindLinkOptions = isset($this->thisConfig['blindLinkOptions'])
861  ? GeneralUtility::trimExplode(',', $this->thisConfig['blindLinkOptions'], TRUE)
862  : array();
863  $pBlindLinkOptions = isset($this->P['params']['blindLinkOptions'])
864  ? GeneralUtility::trimExplode(',', $this->P['params']['blindLinkOptions'])
865  : array();
866  $allowedItems = array_diff(array('page', 'file', 'folder', 'url', 'mail', 'spec'), $blindLinkOptions, $pBlindLinkOptions);
867 
868  // Call hook for extra options
869  foreach ($this->hookObjects as $hookObject) {
870  $allowedItems = $hookObject->addAllowedItems($allowedItems);
871  }
872 
873  // Removing link fields if configured
874  $blindLinkFields = isset($this->thisConfig['blindLinkFields'])
875  ? GeneralUtility::trimExplode(',', $this->thisConfig['blindLinkFields'], TRUE)
876  : array();
877  $pBlindLinkFields = isset($this->P['params']['blindLinkFields'])
878  ? GeneralUtility::trimExplode(',', $this->P['params']['blindLinkFields'], TRUE)
879  : array();
880  $allowedFields = array_diff(array('target', 'title', 'class', 'params'), $blindLinkFields, $pBlindLinkFields);
881 
882  // If $this->act is not allowed, default to first allowed
883  if (!in_array($this->act, $allowedItems)) {
884  $this->act = reset($allowedItems);
885  }
886  // Making menu in top:
887  $menuDef = array();
888  if (!$wiz) {
889  $menuDef['removeLink']['isActive'] = $this->act == 'removeLink';
890  $menuDef['removeLink']['label'] = $GLOBALS['LANG']->getLL('removeLink', TRUE);
891  $menuDef['removeLink']['url'] = '#';
892  $menuDef['removeLink']['addParams'] = 'onclick="self.parent.parent.renderPopup_unLink();return false;"';
893  }
894  if (in_array('page', $allowedItems)) {
895  $menuDef['page']['isActive'] = $this->act == 'page';
896  $menuDef['page']['label'] = $GLOBALS['LANG']->getLL('page', TRUE);
897  $menuDef['page']['url'] = '#';
898  $menuDef['page']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=page') . ');return false;"';
899  }
900  if (in_array('file', $allowedItems)) {
901  $menuDef['file']['isActive'] = $this->act == 'file';
902  $menuDef['file']['label'] = $GLOBALS['LANG']->getLL('file', TRUE);
903  $menuDef['file']['url'] = '#';
904  $menuDef['file']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=file') . ');return false;"';
905  }
906  if (in_array('folder', $allowedItems)) {
907  $menuDef['folder']['isActive'] = $this->act == 'folder';
908  $menuDef['folder']['label'] = $GLOBALS['LANG']->getLL('folder', TRUE);
909  $menuDef['folder']['url'] = '#';
910  $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=folder') . ');return false;"';
911  }
912  if (in_array('url', $allowedItems)) {
913  $menuDef['url']['isActive'] = $this->act == 'url';
914  $menuDef['url']['label'] = $GLOBALS['LANG']->getLL('extUrl', TRUE);
915  $menuDef['url']['url'] = '#';
916  $menuDef['url']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=url') . ');return false;"';
917  }
918  if (in_array('mail', $allowedItems)) {
919  $menuDef['mail']['isActive'] = $this->act == 'mail';
920  $menuDef['mail']['label'] = $GLOBALS['LANG']->getLL('email', TRUE);
921  $menuDef['mail']['url'] = '#';
922  $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=mail') . ');return false;"';
923  }
924  if (is_array($this->thisConfig['userLinks.']) && in_array('spec', $allowedItems)) {
925  $menuDef['spec']['isActive'] = $this->act == 'spec';
926  $menuDef['spec']['label'] = $GLOBALS['LANG']->getLL('special', TRUE);
927  $menuDef['spec']['url'] = '#';
928  $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=spec') . ');return false;"';
929  }
930  // Call hook for extra options
931  foreach ($this->hookObjects as $hookObject) {
932  $menuDef = $hookObject->modifyMenuDefinition($menuDef);
933  }
934  $content .= $this->doc->getTabMenuRaw($menuDef);
935  // Adding the menu and header to the top of page:
936  $content .= $this->printCurrentUrl($this->curUrlInfo['info']) . '<br />';
937  // Depending on the current action we will create the actual module content for selecting a link:
938  switch ($this->act) {
939  case 'mail':
940  $extUrl = '
941 
942  <!--
943  Enter mail address:
944  -->
945  <form action="" name="lurlform" id="lurlform">
946  <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkMail">
947  <tr>
948  <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('emailAddress', TRUE) . ':</td>
949  <td><input type="text" name="lemail"' . $this->doc->formWidth(20) . ' value="'
950  . htmlspecialchars(($this->curUrlInfo['act'] == 'mail' ? $this->curUrlInfo['info'] : ''))
951  . '" /> ' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', TRUE)
952  . '" onclick="browse_links_setTarget(\'\');browse_links_setValue(\'mailto:\'+'
953  . 'document.lurlform.lemail.value); return link_current();" /></td>
954  </tr>
955  </table>
956  </form>';
957  $content .= $extUrl;
958  break;
959  case 'url':
960  $extUrl = '
961 
962  <!--
963  Enter External URL:
964  -->
965  <form action="" name="lurlform" id="lurlform">
966  <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkURL">
967  <tr>
968  <td style="width: 96px;">URL:</td>
969  <td><input type="text" name="lurl"' . $this->doc->formWidth(30) . ' value="'
970  . htmlspecialchars(($this->curUrlInfo['act'] == 'url' ? $this->curUrlInfo['info'] : 'http://'))
971  . '" /> ' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', TRUE)
972  . '" onclick="browse_links_setValue(document.lurlform.lurl.value); return link_current();" /></td>
973  </tr>
974  </table>
975  </form>';
976  $content .= $extUrl;
977  break;
978  case 'file':
979 
980  case 'folder':
981  $foldertree = GeneralUtility::makeInstance('localFolderTree');
982  $foldertree->thisScript = $this->thisScript;
983  $tree = $foldertree->getBrowsableTree();
984  if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
985  $cmpPath = '';
986  } else {
987  $cmpPath = $this->curUrlInfo['value'];
988  if (!isset($this->expandFolder)) {
989  $this->expandFolder = $cmpPath;
990  }
991  }
992  // Create upload/create folder forms, if a path is given
993  $selectedFolder = FALSE;
994  if ($this->expandFolder) {
995  $fileOrFolderObject = NULL;
996  try {
997  $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
998  } catch (\Exception $e) {
999  // No path is selected
1000  }
1001 
1002  if ($fileOrFolderObject instanceof Folder) {
1003  // It's a folder
1004  $selectedFolder = $fileOrFolderObject;
1005  } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
1006  // it's a file
1007  try {
1008  $selectedFolder = $fileOrFolderObject->getParentFolder();
1009  } catch (\Exception $e) {
1010  // Accessing the parent folder failed for some reason. e.g. permissions
1011  }
1012  }
1013  }
1014  // Or get the user's default upload folder
1015  if (!$selectedFolder) {
1016  try {
1017  $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
1018  } catch (\Exception $e) {
1019  // The configured default user folder does not exist
1020  }
1021  }
1022  // Build the file upload and folder creation form
1023  $uploadForm = '';
1024  $createFolder = '';
1025  if ($selectedFolder) {
1026  $uploadForm = ($this->act === 'file') ? $this->uploadForm($selectedFolder) : '';
1027  $createFolder = $this->createFolder($selectedFolder);
1028  }
1029  // Insert the upload form on top, if so configured
1030  if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1031  $content .= $uploadForm;
1032  }
1033 
1034  // Render the filelist if there is a folder selected
1035  if ($selectedFolder) {
1036  $allowedExtensions = isset($this->P['params']['allowedExtensions']) ? $this->P['params']['allowedExtensions'] : '';
1037  $files = $this->expandFolder($selectedFolder, $allowedExtensions);
1038  }
1039  $this->doc->JScode .= $this->doc->wrapScriptTags('
1040  Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1041  ');
1042  $content .= '
1043  <!--
1044  Wrapper table for folder tree / file/folder list:
1045  -->
1046  <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
1047  <tr>
1048  <td class="c-wCell" valign="top">'
1049  . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
1050  <td class="c-wCell" valign="top">' . $files . '</td>
1051  </tr>
1052  </table>
1053  <br />
1054  ';
1055  // Adding create folder + upload forms if applicable
1056  if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1057  $content .= $uploadForm;
1058  }
1059  $content .= $createFolder . '<br />';
1060  break;
1061  case 'spec':
1062  if (is_array($this->thisConfig['userLinks.'])) {
1063  $subcats = array();
1064  $v = $this->thisConfig['userLinks.'];
1065  foreach ($v as $k2 => $value) {
1066  $k2i = (int)$k2;
1067  if (substr($k2, -1) == '.' && is_array($v[$k2i . '.'])) {
1068  // Title:
1069  $title = trim($v[$k2i]);
1070  if (!$title) {
1071  $title = $v[$k2i . '.']['url'];
1072  } else {
1073  $title = $GLOBALS['LANG']->sL($title);
1074  }
1075  // Description:
1076  $description = $v[$k2i . '.']['description']
1077  ? $GLOBALS['LANG']->sL($v[($k2i . '.')]['description'], TRUE) . '<br />'
1078  : '';
1079  // URL + onclick event:
1080  $onClickEvent = '';
1081  if (isset($v[$k2i . '.']['target'])) {
1082  $onClickEvent .= 'browse_links_setTarget(' . GeneralUtility::quoteJSvalue($v[($k2i . '.')]['target']) . ');';
1083  }
1084  $v[$k2i . '.']['url'] = str_replace('###_URL###', $this->siteURL, $v[$k2i . '.']['url']);
1085  if (substr($v[$k2i . '.']['url'], 0, 7) === 'http://' || substr($v[$k2i . '.']['url'], 0, 7) === 'mailto:') {
1086  $onClickEvent .= 'cur_href=' . GeneralUtility::quoteJSvalue($v[($k2i . '.')]['url']) . ';link_current();';
1087  } else {
1088  $onClickEvent .= 'link_spec(' . GeneralUtility::quoteJSvalue($this->siteURL . $v[($k2i . '.')]['url']) . ');';
1089  }
1090  // Link:
1091  $A = array('<a href="#" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">', '</a>');
1092  // Adding link to menu of user defined links:
1093  $subcats[$k2i] = '
1094  <tr>
1095  <td class="bgColor4">' . $A[0] . '<strong>' . htmlspecialchars($title)
1096  . ($this->curUrlInfo['info'] == $v[$k2i . '.']['url']
1097  ? '<img' . IconUtility::skinImg(
1098  $GLOBALS['BACK_PATH'],
1099  'gfx/blinkarrow_right.gif',
1100  'width="5" height="9"'
1101  ) . ' class="c-blinkArrowR" alt="" />'
1102  : '')
1103  . '</strong><br />' . $description . $A[1] . '</td>
1104  </tr>';
1105  }
1106  }
1107  // Sort by keys:
1108  ksort($subcats);
1109  // Add menu to content:
1110  $content .= '
1111 
1112  <!--
1113  Special userdefined menu:
1114  -->
1115  <table border="0" cellpadding="1" cellspacing="1" id="typo3-linkSpecial">
1116  <tr>
1117  <td class="bgColor5 c-wCell" valign="top"><strong>'
1118  . $GLOBALS['LANG']->getLL('special', TRUE) . '</strong></td>
1119  </tr>
1120  ' . implode('', $subcats) . '
1121  </table>
1122  ';
1123  }
1124  break;
1125  case 'page':
1126  $pageTree = GeneralUtility::makeInstance('localPageTree');
1127  $pageTree->thisScript = $this->thisScript;
1128  $pageTree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
1129  $pageTree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
1130  $pageTree->addField('nav_title');
1131  $tree = $pageTree->getBrowsableTree();
1132  $cElements = $this->expandPage();
1133 
1134  $content .= '
1135 
1136  <!--
1137  Wrapper table for page tree / record list:
1138  -->
1139  <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkPages">
1140  <tr>
1141  <td class="c-wCell" valign="top">'
1142  . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':'))
1143  . $this->getTemporaryTreeMountCancelNotice()
1144  . $tree . '</td>
1145  <td class="c-wCell" valign="top">' . $cElements . '</td>
1146  </tr>
1147  </table>
1148  ';
1149  break;
1150  default:
1151  // Call hook
1152  foreach ($this->hookObjects as $hookObject) {
1153  $content .= $hookObject->getTab($this->act);
1154  }
1155  }
1156  if (in_array('params', $allowedFields, TRUE)) {
1157  $content .= '
1158  <!--
1159  Selecting params for link:
1160  -->
1161  <form action="" name="lparamsform" id="lparamsform">
1162  <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkParams">
1163  <tr>
1164  <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('params', TRUE) . '</td>
1165  <td><input type="text" name="lparams" class="typo3-link-input" onchange="'
1166  . 'browse_links_setParams(this.value);" value="' . htmlspecialchars($this->setParams)
1167  . '" /></td>
1168  </tr>
1169  </table>
1170  </form>
1171  ';
1172  }
1173  if (in_array('class', $allowedFields, TRUE)) {
1174  $content .= '
1175  <!--
1176  Selecting class for link:
1177  -->
1178  <form action="" name="lclassform" id="lclassform">
1179  <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkClass">
1180  <tr>
1181  <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('class', TRUE) . '</td>
1182  <td><input type="text" name="lclass" class="typo3-link-input" onchange="'
1183  . 'browse_links_setClass(this.value);" value="' . htmlspecialchars($this->setClass)
1184  . '" /></td>
1185  </tr>
1186  </table>
1187  </form>
1188  ';
1189  }
1190  if (in_array('title', $allowedFields, TRUE)) {
1191  $content .= '
1192  <!--
1193  Selecting title for link:
1194  -->
1195  <form action="" name="ltitleform" id="ltitleform">
1196  <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTitle">
1197  <tr>
1198  <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('title', TRUE) . '</td>
1199  <td><input type="text" name="ltitle" class="typo3-link-input" onchange="'
1200  . 'browse_links_setTitle(this.value);" value="' . htmlspecialchars($this->setTitle)
1201  . '" /></td>
1202  </tr>
1203  </table>
1204  </form>
1205  ';
1206  }
1207  // additional fields for page links
1208  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'])
1209  && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'])
1210  ) {
1211  $conf = array();
1212  $_params = array(
1213  'conf' => &$conf
1214  );
1215  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['addFields_PageLink'] as $objRef) {
1216  $processor =& GeneralUtility::getUserObj($objRef);
1217  $content .= $processor->addFields($_params, $this);
1218  }
1219  }
1220  // Target:
1221  if ($this->act != 'mail' && in_array('target', $allowedFields, TRUE)) {
1222  $ltarget = '
1223 
1224  <!--
1225  Selecting target for link:
1226  -->
1227  <form action="" name="ltargetform" id="ltargetform">
1228  <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">
1229  <tr>
1230  <td>' . $GLOBALS['LANG']->getLL('target', TRUE) . ':</td>
1231  <td><input type="text" name="ltarget" onchange="browse_links_setTarget(this.value);" value="'
1232  . htmlspecialchars($this->setTarget) . '"' . $this->doc->formWidth(10) . ' /></td>
1233  <td>
1234  <select name="ltarget_type" onchange="browse_links_setTarget('
1235  . 'this.options[this.selectedIndex].value);document.ltargetform.ltarget.value='
1236  . 'this.options[this.selectedIndex].value;this.selectedIndex=0;">
1237  <option></option>
1238  <option value="_top">' . $GLOBALS['LANG']->getLL('top', TRUE) . '</option>
1239  <option value="_blank">' . $GLOBALS['LANG']->getLL('newWindow', TRUE) . '</option>
1240  </select>
1241  </td>
1242  <td>';
1243  if (($this->curUrlInfo['act'] == 'page' || $this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder')
1244  && $this->curUrlArray['href'] && $this->curUrlInfo['act'] == $this->act
1245  ) {
1246  $ltarget .= '
1247  <input type="submit" value="' . $GLOBALS['LANG']->getLL('update', TRUE)
1248  . '" onclick="return link_current();" />';
1249  }
1250  $selectJS = '
1251  if (document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value>0'
1252  . ' && document.ltargetform.popup_height.options[document.ltargetform.popup_height.selectedIndex].value>0) {
1253  document.ltargetform.ltarget.value = document.ltargetform.popup_width.options['
1254  . 'document.ltargetform.popup_width.selectedIndex].value+"x"'
1255  . '+document.ltargetformbrowse_links_setTarget.popup_height.options['
1256  . 'document.ltargetform.popup_height.selectedIndex].value;
1257  browse_links_setTarget(document.ltargetform.ltarget.value);
1258  browse_links_setClass(document.lclassform.lclass.value);
1259  browse_links_setTitle(document.ltitleform.ltitle.value);
1260  browse_links_setParams(document.lparamsform.lparams.value);
1261  document.ltargetform.popup_width.selectedIndex=0;
1262  document.ltargetform.popup_height.selectedIndex=0;
1263  }
1264  ';
1265  $ltarget .= ' </td>
1266  </tr>
1267  <tr>
1268  <td>' . $GLOBALS['LANG']->getLL('target_popUpWindow', TRUE) . ':</td>
1269  <td colspan="3">
1270  <select name="popup_width" onchange="' . htmlspecialchars($selectJS) . '">
1271  <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_width', TRUE) . '</option>
1272  <option value="300">300</option>
1273  <option value="400">400</option>
1274  <option value="500">500</option>
1275  <option value="600">600</option>
1276  <option value="700">700</option>
1277  <option value="800">800</option>
1278  </select>
1279  x
1280  <select name="popup_height" onchange="' . htmlspecialchars($selectJS) . '">
1281  <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_height', TRUE) . '</option>
1282  <option value="200">200</option>
1283  <option value="300">300</option>
1284  <option value="400">400</option>
1285  <option value="500">500</option>
1286  <option value="600">600</option>
1287  </select>
1288  </td>
1289  </tr>
1290  </table>
1291  </form>';
1292  // Add "target selector" box to content:
1293  $content .= $ltarget;
1294  // Add some space
1295  $content .= '<br /><br />';
1296  }
1297  // End page, return content:
1298  $content .= $this->doc->endPage();
1299  $content = $this->doc->insertStylesAndJS($content);
1300  return $content;
1301  }
1302 
1309  public function main_db() {
1310  // Starting content:
1311  $content = $this->doc->startPage('TBE record selector');
1312  // Init variable:
1313  $pArr = explode('|', $this->bparams);
1314  $tables = $pArr[3];
1315 
1316  // Making the browsable pagetree:
1318  $pagetree = GeneralUtility::makeInstance('TBE_PageTree');
1319  $pagetree->thisScript = $this->thisScript;
1320  $pagetree->ext_pArrPages = $tables === 'pages' ? 1 : 0;
1321  $pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
1322  $pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
1323  $pagetree->addField('nav_title');
1324 
1325  $withTree = TRUE;
1326  if (($tables !== '') && ($tables !== '*')) {
1327  $tablesArr = GeneralUtility::trimExplode(',', $tables, TRUE);
1328  $onlyRootLevel = TRUE;
1329  foreach ($tablesArr as $currentTable) {
1330  $tableTca = $GLOBALS['TCA'][$currentTable];
1331  if (isset($tableTca)) {
1332  if (!isset($tableTca['ctrl']['rootLevel']) || ((int)$tableTca['ctrl']['rootLevel']) != 1) {
1333  $onlyRootLevel = FALSE;
1334  }
1335  }
1336  }
1337  if ($onlyRootLevel) {
1338  $withTree = FALSE;
1339  // page to work on will be root
1340  $this->expandPage = 0;
1341  }
1342  }
1343 
1344  $tree = $pagetree->getBrowsableTree();
1345  // Making the list of elements, if applicable:
1346  $cElements = $this->TBE_expandPage($tables);
1347  // Putting the things together, side by side:
1348  $content .= '
1349 
1350  <!--
1351  Wrapper table for page tree / record list:
1352  -->
1353  <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBrecords">
1354  <tr>';
1355  if ($withTree) {
1356  $content .= '<td class="c-wCell" valign="top">'
1357  . $this->barheader(($GLOBALS['LANG']->getLL('pageTree') . ':'))
1358  . $this->getTemporaryTreeMountCancelNotice()
1359  . $tree . '</td>';
1360  }
1361  $content .= '<td class="c-wCell" valign="top">' . $cElements . '</td>
1362  </tr>
1363  </table>
1364  ';
1365  // Add some space
1366  $content .= '<br /><br />';
1367  // End page, return content:
1368  $content .= $this->doc->endPage();
1369  $content = $this->doc->insertStylesAndJS($content);
1370  return $content;
1371  }
1372 
1379  public function main_file() {
1380  // include JS files and set prefs for foldertree
1381  $this->doc->getDragDropCode('folders');
1382  $this->doc->JScode .= $this->doc->wrapScriptTags('
1383  Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1384  ');
1385  // Starting content:
1386  $content = $this->doc->startPage('TBE file selector');
1387  // Add the FlashMessages if any
1388  $content .= $this->doc->getFlashMessages();
1389  // Init variable:
1390  $pArr = explode('|', $this->bparams);
1391  // The key number 3 of the pArr contains the "allowed" string. Disallowed is not passed to
1392  // the element browser at all but only filtered out in TCEMain afterwards
1393  $allowed = $pArr[3];
1394  if ($allowed !== 'sys_file' && $allowed !== '*' && !empty($allowed)) {
1395  $allowedFileExtensions = $allowed;
1396  }
1397  $this->storages = $GLOBALS['BE_USER']->getFileStorages();
1398  if (isset($allowedFileExtensions)) {
1399  // Create new filter object
1400  $filterObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
1401  $filterObject->setAllowedFileExtensions($allowedFileExtensions);
1402  // Set file extension filters on all storages
1404  foreach ($this->storages as $storage) {
1405  $storage->addFileAndFolderNameFilter(array($filterObject, 'filterFileList'));
1406  }
1407  }
1408  // Create upload/create folder forms, if a path is given
1409  $this->selectedFolder = FALSE;
1410  if ($this->expandFolder) {
1411  $fileOrFolderObject = NULL;
1412 
1413  // Try to fetch the folder the user had open the last time he browsed files
1414  // Fallback to the default folder in case the last used folder is not existing
1415  try {
1416  $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
1417  } catch (\TYPO3\CMS\Core\Resource\Exception $accessException) {
1418  // We're just catching the exception here, nothing to be done if folder does not exist or is not accessible.
1419  }
1420 
1421  if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
1422  // It's a folder
1423  $this->selectedFolder = $fileOrFolderObject;
1424  } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
1425  // It's a file
1426  $this->selectedFolder = $fileOrFolderObject->getParentFolder();
1427  }
1428  }
1429  // Or get the user's default upload folder
1430  if (!$this->selectedFolder) {
1431  try {
1432  $this->selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
1433  } catch (\Exception $e) {
1434  // The configured default user folder does not exist
1435  }
1436  }
1437  // Build the file upload and folder creation form
1438  $uploadForm = '';
1439  $createFolder = '';
1440  if ($this->selectedFolder) {
1441  $uploadForm = $this->uploadForm($this->selectedFolder);
1442  $createFolder = $this->createFolder($this->selectedFolder);
1443  }
1444  // Insert the upload form on top, if so configured
1445  if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1446  $content .= $uploadForm;
1447  }
1448  // Getting flag for showing/not showing thumbnails:
1449  $noThumbs = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
1450  $_MOD_SETTINGS = array();
1451  if (!$noThumbs) {
1452  // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
1453  $_MOD_MENU = array('displayThumbs' => '');
1454  $_MCONF['name'] = 'file_list';
1455  $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']);
1456  }
1457  $noThumbs = $noThumbs ?: !$_MOD_SETTINGS['displayThumbs'];
1458  // Create folder tree:
1459  $folderTree = GeneralUtility::makeInstance('TBE_FolderTree');
1460  $folderTree->thisScript = $this->thisScript;
1461  $folderTree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1462  $tree = $folderTree->getBrowsableTree();
1463  list(, , $specUid) = explode('_', $this->PM);
1464  if ($this->selectedFolder) {
1465  if ($this->mode == 'filedrag') {
1466  $files = $this->TBE_dragNDrop($this->selectedFolder, $pArr[3]);
1467  } else {
1468  $files = $this->TBE_expandFolder($this->selectedFolder, $pArr[3], $noThumbs);
1469  }
1470  } else {
1471  $files = '';
1472  }
1473 
1474  // Putting the parts together, side by side:
1475  $content .= '
1476 
1477  <!--
1478  Wrapper table for folder tree / file list:
1479  -->
1480  <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1481  <tr>
1482  <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':'))
1483  . $tree . '</td>
1484  <td class="c-wCell" valign="top">' . $files . '</td>
1485  </tr>
1486  </table>
1487  ';
1488  // Adding create folder + upload forms if applicable:
1489  if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
1490  $content .= $uploadForm;
1491  }
1492  $content .= $createFolder;
1493  // Add some space
1494  $content .= '<br /><br />';
1495  // Setup indexed elements:
1496  $this->doc->JScode .= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
1497  // Ending page, returning content:
1498  $content .= $this->doc->endPage();
1499  $content = $this->doc->insertStylesAndJS($content);
1500  return $content;
1501  }
1502 
1509  public function main_folder() {
1510  // include JS files
1511  $this->doc->getDragDropCode('folders');
1512  // Setting prefs for foldertree
1513  $this->doc->JScode .= $this->doc->wrapScriptTags('
1514  Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
1515  ');
1516  // Starting content:
1517  $content = $this->doc->startPage('TBE folder selector');
1518  // Add the FlashMessages if any
1519  $content .= $this->doc->getFlashMessages();
1520  // Init variable:
1521  $parameters = explode('|', $this->bparams);
1522  if ($this->expandFolder) {
1523  $this->selectedFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
1524  }
1525  if ($this->selectedFolder) {
1526  $createFolder = $this->createFolder($this->selectedFolder);
1527  } else {
1528  $createFolder = '';
1529  }
1530  // Create folder tree:
1531  $folderTree = GeneralUtility::makeInstance('TBE_FolderTree');
1532  $folderTree->thisScript = $this->thisScript;
1533  $folderTree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
1534  $tree = $folderTree->getBrowsableTree(FALSE);
1535  list(, , $specUid) = explode('_', $this->PM);
1536  if ($this->selectedFolder) {
1537  if ($this->mode == 'filedrag') {
1538  $folders = $this->TBE_dragNDrop($this->selectedFolder, $parameters[3]);
1539  } else {
1540  $folders = $this->TBE_expandSubFolders($this->selectedFolder);
1541  }
1542  }
1543  // Putting the parts together, side by side:
1544  $content .= '
1545 
1546  <!--
1547  Wrapper table for folder tree / folder list:
1548  -->
1549  <table border="0" cellpadding="0" cellspacing="0" id="typo3-EBfiles">
1550  <tr>
1551  <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':'))
1552  . $tree . '</td>
1553  <td class="c-wCell" valign="top">' . $folders . '</td>
1554  </tr>
1555  </table>
1556  ';
1557  // Adding create folder if applicable:
1558  $content .= $createFolder;
1559  // Add some space
1560  $content .= '<br /><br />';
1561  // Ending page, returning content:
1562  $content .= $this->doc->endPage();
1563  $content = $this->doc->insertStylesAndJS($content);
1564  return $content;
1565  }
1566 
1567  /******************************************************************
1568  *
1569  * Record listing
1570  *
1571  ******************************************************************/
1578  public function expandPage() {
1579  $out = '';
1580  // Set page id (if any) to expand
1581  $expPageId = $this->expandPage;
1582  // If there is an anchor value (content element reference) in the element reference, then force an ID to expand:
1583  if (!$this->expandPage && $this->curUrlInfo['cElement']) {
1584  // Set to the current link page id.
1585  $expPageId = $this->curUrlInfo['pageid'];
1586  }
1587  // Draw the record list IF there is a page id to expand:
1588  if ($expPageId
1589  && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($expPageId)
1590  && $GLOBALS['BE_USER']->isInWebMount($expPageId)
1591  ) {
1592  // Set header:
1593  $out .= $this->barheader($GLOBALS['LANG']->getLL('contentElements') . ':');
1594  // Create header for listing, showing the page title/icon:
1595  $mainPageRec = BackendUtility::getRecordWSOL('pages', $expPageId);
1596  $picon = IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1597  $picon .= BackendUtility::getRecordTitle('pages', $mainPageRec, TRUE);
1598  $out .= $picon . '<br />';
1599  // Look up tt_content elements from the expanded page:
1600  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1601  'uid,header,hidden,starttime,endtime,fe_group,CType,colPos,bodytext',
1602  'tt_content',
1603  'pid=' . (int)$expPageId . BackendUtility::deleteClause('tt_content')
1605  '',
1606  'colPos,sorting'
1607  );
1608  $cc = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
1609  // Traverse list of records:
1610  $c = 0;
1611  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1612  $c++;
1613  $icon = IconUtility::getSpriteIconForRecord('tt_content', $row);
1614  if ($this->curUrlInfo['act'] == 'page' && $this->curUrlInfo['cElement'] == $row['uid']) {
1615  $arrCol = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"')
1616  . ' class="c-blinkArrowL" alt="" />';
1617  } else {
1618  $arrCol = '';
1619  }
1620  // Putting list element HTML together:
1621  $out .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join' . ($c == $cc ? 'bottom' : '')
1622  . '.gif'), 'width="18" height="16"') . ' alt="" />' . $arrCol
1623  . '<a href="#" onclick="return link_typo3Page(' . GeneralUtility::quoteJSvalue($expPageId) . ',\'#' . $row['uid'] . '\');">'
1624  . $icon . BackendUtility::getRecordTitle('tt_content', $row, TRUE) . '</a><br />';
1625  // Finding internal anchor points:
1626  if (GeneralUtility::inList('text,textpic', $row['CType'])) {
1627  $split = preg_split('/(<a[^>]+name=[\'"]?([^"\'>[:space:]]+)[\'"]?[^>]*>)/i', $row['bodytext'], -1, PREG_SPLIT_DELIM_CAPTURE);
1628  foreach ($split as $skey => $sval) {
1629  if ($skey % 3 == 2) {
1630  // Putting list element HTML together:
1631  $sval = substr($sval, 0, 100);
1632  $out .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/ol/line.gif',
1633  'width="18" height="16"') . ' alt="" />'
1634  . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/ol/join'
1635  . ($skey + 3 > count($split) ? 'bottom' : '') . '.gif'), 'width="18" height="16"')
1636  . ' alt="" />' . '<a href="#" onclick="return link_typo3Page(' . GeneralUtility::quoteJSvalue($expPageId)
1637  . ',' . GeneralUtility::quoteJSvalue('#' . $sval) . ');">' . htmlspecialchars((' <A> ' . $sval))
1638  . '</a><br />';
1639  }
1640  }
1641  }
1642  }
1643  }
1644  return $out;
1645  }
1646 
1654  public function TBE_expandPage($tables) {
1655  $out = '';
1656  if ($this->expandPage >= 0
1657  && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->expandPage)
1658  && $GLOBALS['BE_USER']->isInWebMount($this->expandPage)
1659  ) {
1660  // Set array with table names to list:
1661  if (trim($tables) === '*') {
1662  $tablesArr = array_keys($GLOBALS['TCA']);
1663  } else {
1664  $tablesArr = GeneralUtility::trimExplode(',', $tables, TRUE);
1665  }
1666  reset($tablesArr);
1667  // Headline for selecting records:
1668  $out .= $this->barheader($GLOBALS['LANG']->getLL('selectRecords') . ':');
1669  // Create the header, showing the current page for which the listing is.
1670  // Includes link to the page itself, if pages are amount allowed tables.
1671  $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
1672  $mainPageRec = BackendUtility::getRecordWSOL('pages', $this->expandPage);
1673  $ATag = '';
1674  $ATag_e = '';
1675  $ATag2 = '';
1676  $picon = '';
1677  if (is_array($mainPageRec)) {
1678  $picon = IconUtility::getSpriteIconForRecord('pages', $mainPageRec);
1679  if (in_array('pages', $tablesArr)) {
1680  $ATag = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', '
1681  . GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',1);">';
1682  $ATag2 = '<a href="#" onclick="return insertElement(\'pages\', \'' . $mainPageRec['uid'] . '\', \'db\', '
1683  . GeneralUtility::quoteJSvalue($mainPageRec['title']) . ', \'\', \'\', \'\',\'\',0);">';
1684  $ATag_e = '</a>';
1685  }
1686  }
1687  $pBicon = $ATag2 ? '<img'
1688  . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif', 'width="18" height="16"')
1689  . ' alt="" />' : '';
1690  $pText = htmlspecialchars(GeneralUtility::fixed_lgd_cs($mainPageRec['title'], $titleLen));
1691  $out .= $picon . $ATag2 . $pBicon . $ATag_e . $ATag . $pText . $ATag_e . '<br />';
1692  // Initialize the record listing:
1693  $id = $this->expandPage;
1694  $pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
1695  $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1696  $pageInfo = BackendUtility::readPageAccess($id, $perms_clause);
1697  // Generate the record list:
1699  if (is_object($this->recordList)) {
1700  $dbList = $this->recordList;
1701  } else {
1702  $dbList = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\RecordList\\ElementBrowserRecordList');
1703  }
1704  $dbList->thisScript = $this->thisScript;
1705  $dbList->backPath = $GLOBALS['BACK_PATH'];
1706  $dbList->thumbs = 0;
1707  $dbList->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageInfo);
1708  $dbList->noControlPanels = 1;
1709  $dbList->clickMenuEnabled = 0;
1710  $dbList->tableList = implode(',', $tablesArr);
1711  $pArr = explode('|', $this->bparams);
1712  // a string like "data[pages][79][storage_pid]"
1713  $fieldPointerString = $pArr[0];
1714  // parts like: data, pages], 79], storage_pid]
1715  $fieldPointerParts = explode('[', $fieldPointerString);
1716  $relatingTableName = substr($fieldPointerParts[1], 0, -1);
1717  $relatingFieldName = substr($fieldPointerParts[3], 0, -1);
1718  if ($relatingTableName && $relatingFieldName) {
1719  $dbList->setRelatingTableAndField($relatingTableName, $relatingFieldName);
1720  }
1721  $dbList->start($id, GeneralUtility::_GP('table'), $pointer, GeneralUtility::_GP('search_field'),
1722  GeneralUtility::_GP('search_levels'), GeneralUtility::_GP('showLimit')
1723  );
1724  $dbList->setDispFields();
1725  $dbList->generateList();
1726  // Add the HTML for the record list to output variable:
1727  $out .= $dbList->HTMLcode;
1728  // Add support for fieldselectbox in singleTableMode
1729  if ($dbList->table) {
1730  $out .= $dbList->fieldSelectBox($dbList->table);
1731  }
1732  $out .= $dbList->getSearchBox();
1733  }
1734  // Return accumulated content:
1735  return $out;
1736  }
1737 
1745  public function TBE_expandSubFolders(Folder $folder) {
1746  $content = '';
1747  if ($folder->checkActionPermission('read')) {
1748  $content .= $this->folderList($folder);
1749  }
1750  // Return accumulated content for folderlisting:
1751  return $content;
1752  }
1753 
1754  /******************************************************************
1755  *
1756  * File listing
1757  *
1758  ******************************************************************/
1767  public function expandFolder(Folder $folder, $extensionList = '') {
1768  $out = '';
1769  $renderFolders = $this->act === 'folder';
1770  if ($folder->checkActionPermission('read')) {
1771  // Create header for file/folder listing:
1772  if ($renderFolders) {
1773  $out = $this->barheader($GLOBALS['LANG']->getLL('folders') . ':');
1774  } else {
1775  $out = $this->barheader($GLOBALS['LANG']->getLL('files') . ':');
1776  }
1777  // Prepare current path value for comparison (showing red arrow)
1778  $currentIdentifier = '';
1779  if ($this->curUrlInfo['value']) {
1780  $currentIdentifier = $this->curUrlInfo['info'];
1781  }
1782  // Create header element; The folder from which files are listed.
1783  $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
1784  $folderIcon = IconUtility::getSpriteIconForResource($folder);
1785  $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen));
1786  $picon = '<a href="#" onclick="return link_folder(' . GeneralUtility::quoteJSvalue('file:' . $folder->getCombinedIdentifier()) . ');">'
1787  . $folderIcon . '</a>';
1788  if ($this->curUrlInfo['act'] == 'folder' && $currentIdentifier == $folder->getCombinedIdentifier()) {
1789  $out .= '<img'
1790  . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"')
1791  . ' class="c-blinkArrowL" alt="" />';
1792  }
1793  $out .= $picon . '<br />';
1794  // Get files from the folder:
1795  if ($renderFolders) {
1796  $items = $folder->getSubfolders();
1797  } else {
1798  $items = $this->getFilesInFolder($folder, $extensionList);
1799  }
1800  $c = 0;
1801  $totalItems = count($items);
1802  foreach ($items as $fileOrFolderObject) {
1803  $c++;
1804  if ($renderFolders) {
1805  $fileIdentifier = $fileOrFolderObject->getCombinedIdentifier();
1806  $overlays = array();
1807  if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder) {
1808  $overlays = array('status-overlay-locked' => array());
1809  }
1810  $icon = IconUtility::getSpriteIcon(
1811  IconUtility::mapFileExtensionToSpriteIconName('folder'),
1812  array('title' => $fileOrFolderObject->getName()),
1813  $overlays);
1814  $itemUid = 'file:' . $fileIdentifier;
1815  } else {
1816  $fileIdentifier = $fileOrFolderObject->getUid();
1817  // File icon:
1818  $fileExtension = $fileOrFolderObject->getExtension();
1819  // Get size and icon:
1820  $size = ' (' . GeneralUtility::formatSize($fileOrFolderObject->getSize()) . 'bytes)';
1821  $icon = IconUtility::getSpriteIconForResource($fileOrFolderObject, array('title' => $fileOrFolderObject->getName() . $size));
1822  $itemUid = 'file:' . $fileIdentifier;
1823  }
1824  // If the listed file turns out to be the CURRENT file, then show blinking arrow:
1825  if (($this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder')
1826  && $currentIdentifier == $fileIdentifier
1827  ) {
1828  $arrCol = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif',
1829  'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
1830  } else {
1831  $arrCol = '';
1832  }
1833  // Put it all together for the file element:
1834  $out .=
1835  '<img' .
1836  IconUtility::skinImg(
1837  $GLOBALS['BACK_PATH'],
1838  ('gfx/ol/join' . ($c == $totalItems ? 'bottom' : '') . '.gif'),
1839  'width="18" height="16"'
1840  ) . ' alt="" />' . $arrCol .
1841  '<a href="#" onclick="return link_folder(' . GeneralUtility::quoteJSvalue($itemUid) . ');">' .
1842  $icon .
1843  htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileOrFolderObject->getName(), $titleLen)) .
1844  '</a><br />';
1845  }
1846  }
1847  return $out;
1848  }
1849 
1859  public function TBE_expandFolder(Folder $folder, $extensionList = '', $noThumbs = FALSE) {
1860  if (!$folder->checkActionPermission('read')) {
1861  return '';
1862  }
1863  $extensionList = $extensionList == '*' ? '' : $extensionList;
1864  $files = $this->getFilesInFolder($folder, $extensionList);
1865  return $this->fileList($files, $folder, $noThumbs);
1866  }
1867 
1876  protected function fileList(array $files, Folder $folder = NULL, $noThumbs = FALSE) {
1877  $out = '';
1878 
1879  $lines = array();
1880  // Create headline (showing number of files):
1881  $filesCount = count($files);
1882  $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', $filesCount));
1883  $out .= '<div id="filelist">';
1884  $out .= $this->getBulkSelector($filesCount);
1885  $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
1886  // Create the header of current folder:
1887  if ($folder) {
1888  $folderIcon = IconUtility::getSpriteIconForResource($folder);
1889  $lines[] = '<tr class="t3-row-header">
1890  <td colspan="4">' . $folderIcon
1891  . htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</td>
1892  </tr>';
1893  }
1894  if ($filesCount == 0) {
1895  $lines[] = '
1896  <tr class="file_list_normal">
1897  <td colspan="4">No files found.</td>
1898  </tr>';
1899  }
1900  // Traverse the file list:
1902  foreach ($files as $fileObject) {
1903  $fileExtension = $fileObject->getExtension();
1904  // Thumbnail/size generation:
1905  $imgInfo = array();
1906  if (GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($fileExtension)) && !$noThumbs) {
1907  $imageUrl = $fileObject->process(
1908  \TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW,
1909  array('width' => 64, 'height' => 64)
1910  )->getPublicUrl(TRUE);
1911  $imgInfo = array(
1912  $fileObject->getProperty('width'),
1913  $fileObject->getProperty('height')
1914  );
1915  $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
1916  $clickIcon = '<img src="' . htmlspecialchars($imageUrl) . '" hspace="5" vspace="5" border="1" />';
1917  } else {
1918  $clickIcon = '';
1919  $pDim = '';
1920  }
1921  // Create file icon:
1922  $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
1923  $icon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName() . $size));
1924  // Create links for adding the file:
1925  $filesIndex = count($this->elements);
1926  $this->elements['file_' . $filesIndex] = array(
1927  'type' => 'file',
1928  'table' => 'sys_file',
1929  'uid' => $fileObject->getUid(),
1930  'fileName' => $fileObject->getName(),
1931  'filePath' => $fileObject->getUid(),
1932  'fileExt' => $fileExtension,
1933  'fileIcon' => $icon
1934  );
1935  if ($this->fileIsSelectableInFileList($fileObject, $imgInfo)) {
1936  $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
1937  $ATag_alt = substr($ATag, 0, -4) . ',1);">';
1938  $bulkCheckBox = '<input type="checkbox" class="typo3-bulk-item" name="file_' . $filesIndex . '" value="0" /> ';
1939  $ATag_e = '</a>';
1940  } else {
1941  $ATag = '';
1942  $ATag_alt = '';
1943  $ATag_e = '';
1944  $bulkCheckBox = '';
1945  }
1946  // Create link to showing details about the file in a window:
1947  $Ahref = $GLOBALS['BACK_PATH'] . 'show_item.php?type=file&table=_FILE&uid='
1948  . rawurlencode($fileObject->getCombinedIdentifier())
1949  . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
1950  $ATag2 = '<a href="' . htmlspecialchars($Ahref) . '">';
1951  $ATag2_e = '</a>';
1952  // Combine the stuff:
1953  $filenameAndIcon = $bulkCheckBox . $ATag_alt . $icon
1954  . htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
1955  // Show element:
1956  if ($pDim) {
1957  // Image...
1958  $lines[] = '
1959  <tr class="file_list_normal">
1960  <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1961  <td>' . ($ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
1962  'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
1963  . '" alt="" />' . $ATag_e) . '</td>
1964  <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
1965  'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
1966  . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
1967  . $GLOBALS['LANG']->getLL('info', TRUE) . $ATag2_e) . '</td>
1968  <td nowrap="nowrap">&nbsp;' . $pDim . '</td>
1969  </tr>';
1970  $lines[] = '
1971  <tr>
1972  <td class="filelistThumbnail" colspan="4">' . $ATag_alt . $clickIcon . $ATag_e . '</td>
1973  </tr>';
1974  } else {
1975  $lines[] = '
1976  <tr class="file_list_normal">
1977  <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
1978  <td>' . ($ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
1979  'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
1980  . '" alt="" />' . $ATag_e) . '</td>
1981  <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
1982  'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
1983  . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
1984  . $GLOBALS['LANG']->getLL('info', TRUE) . $ATag2_e) . '</td>
1985  <td>&nbsp;</td>
1986  </tr>';
1987  }
1988  }
1989  // Wrap all the rows in table tags:
1990  $out .= '
1991 
1992  <!--
1993  File listing
1994  -->
1995  <table cellpadding="0" cellspacing="0" id="typo3-filelist">
1996  ' . implode('', $lines) . '
1997  </table>';
1998  // Return accumulated content for file listing:
1999  $out .= '</div>';
2000  return $out;
2001  }
2002 
2012  protected function fileIsSelectableInFileList(\TYPO3\CMS\Core\Resource\FileInterface $file, array $imgInfo) {
2013  return TRUE;
2014  }
2015 
2023  public function folderList(Folder $baseFolder) {
2024  $content = '';
2025  $folders = $baseFolder->getSubfolders();
2026  $folderIdentifier = $baseFolder->getCombinedIdentifier();
2027  // Create headline (showing number of folders):
2028  $content .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('folders') . ' (%s):', count($folders)));
2029  $titleLength = (int)$GLOBALS['BE_USER']->uc['titleLen'];
2030  // Create the header of current folder:
2031  $aTag = '<a href="#" onclick="return insertElement(\'\',' . GeneralUtility::quoteJSvalue($folderIdentifier)
2032  . ', \'folder\', ' . GeneralUtility::quoteJSvalue($folderIdentifier) . ', ' . GeneralUtility::quoteJSvalue($folderIdentifier)
2033  . ', \'\', \'\',\'\',1);">';
2034  // Add the foder icon
2035  $folderIcon = $aTag;
2036  $folderIcon .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif',
2037  'width="18" height="16"') . ' alt="" />';
2038  $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($baseFolder->getName(), $titleLength));
2039  $folderIcon .= '</a>';
2040  $content .= $folderIcon . '<br />';
2041 
2042  $lines = array();
2043  // Traverse the folder list:
2044  foreach ($folders as $subFolder) {
2045  $subFolderIdentifier = $subFolder->getCombinedIdentifier();
2046  // Create folder icon:
2047  $icon = '<img src="clear.gif" width="16" height="16" alt="" /><img'
2048  . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif',
2049  'width="16" height="16"') . ' title="' . htmlspecialchars($subFolder->getName())
2050  . '" class="absmiddle" alt="" />';
2051  // Create links for adding the folder:
2052  if ($this->P['itemName'] != '' && $this->P['formName'] != '') {
2053  $aTag = '<a href="#" onclick="return set_folderpath(' . GeneralUtility::quoteJSvalue($subFolderIdentifier)
2054  . ');">';
2055  } else {
2056  $aTag = '<a href="#" onclick="return insertElement(\'\',' . GeneralUtility::quoteJSvalue($subFolderIdentifier)
2057  . ', \'folder\', ' . GeneralUtility::quoteJSvalue($subFolderIdentifier) . ', '
2058  . GeneralUtility::quoteJSvalue($subFolderIdentifier) . ', \'\', \'\');">';
2059  }
2060  if (strstr($subFolderIdentifier, ',') || strstr($subFolderIdentifier, '|')) {
2061  // In case an invalid character is in the filepath, display error message:
2062  $errorMessage = GeneralUtility::quoteJSvalue(sprintf($GLOBALS['LANG']->getLL('invalidChar'), ', |'));
2063  $aTag = ($aTag_alt = '<a href="#" onclick="alert(' . $errorMessage . ');return false;">');
2064  } else {
2065  // If foldername is OK, just add it:
2066  $aTag_alt = substr($aTag, 0, -4) . ',\'\',1);">';
2067  }
2068  $aTag_e = '</a>';
2069  // Combine icon and folderpath:
2070  $foldernameAndIcon = $aTag_alt . $icon
2071  . htmlspecialchars(GeneralUtility::fixed_lgd_cs($subFolder->getName(), $titleLength)) . $aTag_e;
2072  if ($this->P['itemName'] != '') {
2073  $lines[] = '
2074  <tr class="bgColor4">
2075  <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
2076  <td>&nbsp;</td>
2077  </tr>';
2078  } else {
2079  $lines[] = '
2080  <tr class="bgColor4">
2081  <td nowrap="nowrap">' . $foldernameAndIcon . '&nbsp;</td>
2082  <td>' . $aTag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
2083  'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
2084  . '" alt="" />' . $aTag_e . ' </td>
2085  <td>&nbsp;</td>
2086  </tr>';
2087  }
2088  $lines[] = '
2089  <tr>
2090  <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td>
2091  </tr>';
2092  }
2093  // Wrap all the rows in table tags:
2094  $content .= '
2095 
2096  <!--
2097  Folder listing
2098  -->
2099  <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList">
2100  ' . implode('', $lines) . '
2101  </table>';
2102  // Return accumulated content for folderlisting:
2103  return $content;
2104  }
2105 
2115  public function TBE_dragNDrop(Folder $folder, $extensionList = '') {
2116  if (!$folder) {
2117  return '';
2118  }
2119  if (!$folder->getStorage()->isPublic()) {
2120  // Print this warning if the folder is NOT a web folder
2121  return $this->barheader($GLOBALS['LANG']->getLL('files'))
2122  . $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2');
2123  }
2124  $out = '';
2125 
2126  // Read files from directory:
2127  $extensionList = $extensionList == '*' ? '' : $extensionList;
2128  $files = $this->getFilesInFolder($folder, $extensionList);
2129 
2130  $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files)));
2131  $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
2132  $picon = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
2133  $picon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLen));
2134  $out .= $picon . '<br />';
2135  // Init row-array:
2136  $lines = array();
2137  // Add "drag-n-drop" message:
2138  $lines[] = '
2139  <tr>
2140  <td colspan="2">' . $this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')) . '</td>
2141  </tr>';
2142  // Traverse files:
2143  foreach ($files as $fileObject) {
2144  $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
2145  // URL of image:
2146  $iUrl = GeneralUtility::rawUrlEncodeFP($fileObject->getPublicUrl(TRUE));
2147  // Show only web-images
2148  $fileExtension = strtolower($fileObject->getExtension());
2149  if (GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) {
2150  $imgInfo = array(
2151  $fileObject->getProperty('width'),
2152  $fileObject->getProperty('height')
2153  );
2154  $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
2155  $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
2156  $filenameAndIcon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName() . $size));
2157  if (GeneralUtility::_GP('noLimit')) {
2158  $maxW = 10000;
2159  $maxH = 10000;
2160  } else {
2161  $maxW = 380;
2162  $maxH = 500;
2163  }
2164  $IW = $imgInfo[0];
2165  $IH = $imgInfo[1];
2166  if ($IW > $maxW) {
2167  $IH = ceil($IH / $IW * $maxW);
2168  $IW = $maxW;
2169  }
2170  if ($IH > $maxH) {
2171  $IW = ceil($IW / $IH * $maxH);
2172  $IH = $maxH;
2173  }
2174  // Make row:
2175  $lines[] = '
2176  <tr class="bgColor4">
2177  <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
2178  <td nowrap="nowrap">' . ($imgInfo[0] != $IW
2179  ? '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('noLimit' => '1')))
2180  . '">' . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning2.gif',
2181  'width="18" height="16"') . ' title="'
2182  . $GLOBALS['LANG']->getLL('clickToRedrawFullSize', TRUE) . '" alt="" />' . '</a>'
2183  : '')
2184  . $pDim . '&nbsp;</td>
2185  </tr>';
2186  $lines[] = '
2187  <tr>
2188  <td colspan="2"><img src="' . htmlspecialchars($iUrl) . '" data-htmlarea-file-uid="' . $fileObject->getUid()
2189  . '" width="' . htmlspecialchars($IW) . '" height="' . htmlspecialchars($IH) . '" border="1" alt="" /></td>
2190  </tr>';
2191  $lines[] = '
2192  <tr>
2193  <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
2194  </tr>';
2195  }
2196  }
2197  // Finally, wrap all rows in a table tag:
2198  $out .= '
2199 
2200 
2201 <!--
2202  File listing / Drag-n-drop
2203 -->
2204  <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
2205  ' . implode('', $lines) . '
2206  </table>';
2207 
2208  return $out;
2209  }
2210 
2211  /******************************************************************
2212  *
2213  * Miscellaneous functions
2214  *
2215  ******************************************************************/
2223  public function isWebFolder($folder) {
2225  $folder = rtrim($folder, '/') . '/';
2226  return GeneralUtility::isFirstPartOfStr($folder, PATH_site) ? TRUE : FALSE;
2227  }
2228 
2236  public function checkFolder($folder) {
2238  return $this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/') ? TRUE : FALSE;
2239  }
2240 
2248  public function barheader($str) {
2249  return '
2250  <!-- Bar header: -->
2251  <h3>' . htmlspecialchars($str) . '</h3>
2252  ';
2253  }
2254 
2263  public function getMsgBox($in_msg, $icon = 'icon_note') {
2264  $msg = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], ('gfx/' . $icon . '.gif'), 'width="18" height="16"')
2265  . ' alt="" />' . htmlspecialchars($in_msg);
2266  $msg = '
2267 
2268  <!--
2269  Message box:
2270  -->
2271  <table cellspacing="0" class="bgColor4" id="typo3-msgBox">
2272  <tr>
2273  <td>' . $msg . '</td>
2274  </tr>
2275  </table>
2276  ';
2277  return $msg;
2278  }
2279 
2287  public function printCurrentUrl($str) {
2288  // Output the folder or file identifier, when working with files
2289  if (isset($str) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($str)
2290  && ($this->act === 'file' || $this->act === 'folder')
2291  ) {
2292  try {
2293  $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($str);
2294  } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
2295  $fileObject = NULL;
2296  }
2297  $str = is_object($fileObject) ? $fileObject->getIdentifier() : '';
2298  }
2299  if (strlen($str)) {
2300  return '
2301  <!-- Print current URL -->
2302  <table border="0" cellpadding="0" cellspacing="0" id="typo3-curUrl">
2303  <tr>
2304  <td>' . $GLOBALS['LANG']->getLL('currentLink', TRUE) . ': '
2305  . htmlspecialchars(rawurldecode($str)) . '</td>
2306  </tr>
2307  </table>';
2308  } else {
2309  return '';
2310  }
2311  }
2312 
2321  public function parseCurUrl($href, $siteUrl) {
2322  $href = trim($href);
2323  if ($href) {
2324  $info = array();
2325  // Default is "url":
2326  $info['value'] = $href;
2327  $info['act'] = 'url';
2328  $specialParts = explode('#_SPECIAL', $href);
2329  // Special kind (Something RTE specific: User configurable links through: "userLinks." from ->thisConfig)
2330  if (count($specialParts) == 2) {
2331  $info['value'] = '#_SPECIAL' . $specialParts[1];
2332  $info['act'] = 'spec';
2333  } elseif (!GeneralUtility::isFirstPartOfStr($href, 'file://') && strpos($href, 'file:') !== FALSE) {
2334  $rel = substr($href, strpos($href, 'file:') + 5);
2335  $rel = rawurldecode($rel);
2336  try {
2337  // resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier"
2338  $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($rel);
2339  if ($fileOrFolderObject instanceof Folder) {
2340  $info['act'] = 'folder';
2341  $info['value'] = $fileOrFolderObject->getCombinedIdentifier();
2342  } elseif ($fileOrFolderObject instanceof File) {
2343  $info['act'] = 'file';
2344  $info['value'] = $fileOrFolderObject->getUid();
2345  } else {
2346  $info['value'] = $rel;
2347  }
2348  } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
2349  // file was deleted or any other reason, don't select any item
2350  if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($rel)) {
2351  $info['act'] = 'file';
2352  } else {
2353  $info['act'] = 'folder';
2354  }
2355  $info['value'] = '';
2356  }
2357  } elseif (GeneralUtility::isFirstPartOfStr($href, $siteUrl)) {
2358  // If URL is on the current frontend website:
2359  // URL is a file, which exists:
2360  if (file_exists(PATH_site . rawurldecode($href))) {
2361  $info['value'] = rawurldecode($href);
2362  if (@is_dir((PATH_site . $info['value']))) {
2363  $info['act'] = 'folder';
2364  } else {
2365  $info['act'] = 'file';
2366  }
2367  } else {
2368  // URL is a page (id parameter)
2369  $uP = parse_url($href);
2370 
2371  $pp = preg_split('/^id=/', $uP['query']);
2372  $pp[1] = preg_replace('/&id=[^&]*/', '', $pp[1]);
2373  $parameters = explode('&', $pp[1]);
2374  $id = array_shift($parameters);
2375  if ($id) {
2376  // Checking if the id-parameter is an alias.
2377  if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($id)) {
2378  list($idPartR) = BackendUtility::getRecordsByField('pages', 'alias', $id);
2379  $id = (int)$idPartR['uid'];
2380  }
2381  $pageRow = BackendUtility::getRecordWSOL('pages', $id);
2382  $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
2383  $info['value'] = ((((($GLOBALS['LANG']->getLL('page', TRUE) . ' \'')
2384  . htmlspecialchars(GeneralUtility::fixed_lgd_cs($pageRow['title'], $titleLen)))
2385  . '\' (ID:') . $id) . ($uP['fragment'] ? ', #' . $uP['fragment'] : '')) . ')';
2386  $info['pageid'] = $id;
2387  $info['cElement'] = $uP['fragment'];
2388  $info['act'] = 'page';
2389  $info['query'] = $parameters[0] ? '&' . implode('&', $parameters) : '';
2390  }
2391  }
2392  } else {
2393  // Email link:
2394  if (strtolower(substr($href, 0, 7)) == 'mailto:') {
2395  $info['value'] = trim(substr($href, 7));
2396  $info['act'] = 'mail';
2397  }
2398  }
2399  $info['info'] = $info['value'];
2400  } else {
2401  // NO value inputted:
2402  $info = array();
2403  $info['info'] = $GLOBALS['LANG']->getLL('none');
2404  $info['value'] = '';
2405  $info['act'] = 'page';
2406  }
2407  // let the hook have a look
2408  foreach ($this->hookObjects as $hookObject) {
2409  $info = $hookObject->parseCurrentUrl($href, $siteUrl, $info);
2410  }
2411  return $info;
2412  }
2413 
2423  public function setRecordList($recordList) {
2424  if (!$recordList instanceof \TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList) {
2425  throw new \InvalidArgumentException('$recordList needs to be an instance of \\TYPO3\\CMS\\Backend\\RecordList\\ElementBrowserRecordList', 1370878522);
2426  }
2427  $this->recordList = $recordList;
2428  }
2429 
2438  public function uploadForm(Folder $folderObject) {
2439  if (!$folderObject->checkActionPermission('write')) {
2440  return '';
2441  }
2442  // Read configuration of upload field count
2443  $userSetting = $GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
2444  $count = isset($userSetting) ? $userSetting : 1;
2445  if ($count === '0') {
2446  return '';
2447  }
2448  $count = (int)$count === 0 ? 1 : (int)$count;
2449  // Create header, showing upload path:
2450  $header = $folderObject->getIdentifier();
2451  $code = '
2452  <br />
2453  <!--
2454  Form, for uploading files:
2455  -->
2456  <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform"'
2457  . ' id="typo3-uplFilesForm" enctype="' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype']) . '">
2458  <table border="0" cellpadding="0" cellspacing="0" id="typo3-uplFiles">
2459  <tr>
2460  <td>' . $this->barheader($GLOBALS['LANG']->sL(
2461  'LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle', TRUE) . ':') . '</td>
2462  </tr>
2463  <tr>
2464  <td class="c-wCell c-hCell"><strong>' . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> '
2465  . htmlspecialchars($header) . '</td>
2466  </tr>
2467  <tr>
2468  <td class="c-wCell c-hCell">';
2469  // Traverse the number of upload fields (default is 3):
2470  for ($a = 1; $a <= $count; $a++) {
2471  $code .= '<input type="file" multiple="multiple" name="upload_' . $a . '[]"' . $this->doc->formWidth(35)
2472  . ' size="50" />
2473  <input type="hidden" name="file[upload][' . $a . '][target]" value="'
2474  . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />
2475  <input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br />';
2476  }
2477  // Make footer of upload form, including the submit button:
2478  $redirectValue = $this->getThisScript() . 'act=' . rawurlencode($this->act) . '&mode=' . rawurlencode($this->mode)
2479  . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier())
2480  . '&bparams=' . rawurlencode($this->bparams)
2481  . (is_array($this->P) ? GeneralUtility::implodeArrayForUrl('P', $this->P) : '');
2482  $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
2483  $code .= \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction');
2484  $code .= '
2485  <div id="c-override">
2486  <label><input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> '
2487  . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', TRUE) . '</label>
2488  </div>
2489  <input type="submit" name="submit" value="'
2490  . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', TRUE) . '" />
2491  ';
2492  $code .= '</td>
2493  </tr>
2494  </table>
2495  </form><br />';
2496  return $code;
2497  }
2498 
2507  public function createFolder(Folder $folderObject) {
2508  if (!$folderObject->checkActionPermission('write')) {
2509  return '';
2510  }
2511  if (!($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB'))) {
2512  return '';
2513  }
2514  // Don't show Folder-create form if it's denied
2515  if ($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.hideCreateFolder')) {
2516  return '';
2517  }
2518  // Create header, showing upload path:
2519  $header = $folderObject->getIdentifier();
2520  $code = '
2521 
2522  <!--
2523  Form, for creating new folders:
2524  -->
2525  <form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform2" id="typo3-crFolderForm">
2526  <table border="0" cellpadding="0" cellspacing="0" id="typo3-crFolder">
2527  <tr>
2528  <td>' . $this->barheader($GLOBALS['LANG']->sL(
2529  'LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle') . ':') . '</td>
2530  </tr>
2531  <tr>
2532  <td class="c-wCell c-hCell"><strong>'
2533  . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> ' . htmlspecialchars($header) . '</td>
2534  </tr>
2535  <tr>
2536  <td class="c-wCell c-hCell">';
2537  // Create the new-folder name field:
2538  $a = 1;
2539  $code .= '<input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" />'
2540  . '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="'
2541  . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
2542  // Make footer of upload form, including the submit button:
2543  $redirectValue = $this->getThisScript() . 'act=' . rawurlencode($this->act) . '&mode=' . rawurlencode($this->mode)
2544  . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier())
2545  . '&bparams=' . rawurlencode($this->bparams)
2546  . (is_array($this->P) ? GeneralUtility::implodeArrayForUrl('P', $this->P) : '');
2547  $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />'
2548  . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction')
2549  . '<input type="submit" name="submit" value="'
2550  . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', TRUE) . '" />';
2551  $code .= '</td>
2552  </tr>
2553  </table>
2554  </form>';
2555  return $code;
2556  }
2557 
2565  public function getBulkSelector($filesCount) {
2566  if (!$filesCount) {
2567  return '';
2568  }
2569 
2570  $labelToggleSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:toggleSelection', TRUE);
2571  $labelImportSelection = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:importSelection', TRUE);
2572  // Getting flag for showing/not showing thumbnails:
2573  $noThumbsInEB = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInEB');
2574  $out = $this->doc->spacer(10) . '<div>' . '<a href="#" onclick="BrowseLinks.Selector.handle()">'
2575  . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/import.gif', 'width="12" height="12"')
2576  . ' title="' . $labelImportSelection . '" alt="" /> ' . $labelImportSelection . '</a>&nbsp;&nbsp;&nbsp;'
2577  . '<a href="#" onclick="BrowseLinks.Selector.toggle()">' . '<img'
2578  . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/clip_select.gif', 'width="12" height="12"')
2579  . ' title="' . $labelToggleSelection . '" alt="" /> ' . $labelToggleSelection . '</a>' . '</div>';
2580  $thumbNailCheck = '';
2581  if (!$noThumbsInEB && $this->selectedFolder) {
2582  // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
2583  $_MOD_MENU = array('displayThumbs' => '');
2584  $_MCONF['name'] = 'file_list';
2585  $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']);
2586  $addParams = '&act=' . $this->act . '&mode=' . $this->mode
2587  . '&expandFolder=' . rawurlencode($this->selectedFolder->getCombinedIdentifier())
2588  . '&bparams=' . rawurlencode($this->bparams);
2589  $thumbNailCheck = BackendUtility::getFuncCheck('', 'SET[displayThumbs]', $_MOD_SETTINGS['displayThumbs'],
2590  GeneralUtility::_GP('M') ? '' : $this->thisScript, $addParams, 'id="checkDisplayThumbs"')
2591  . ' <label for="checkDisplayThumbs">'
2592  . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:displayThumbs', TRUE) . '</label>';
2593  $out .= $this->doc->spacer(5) . $thumbNailCheck . $this->doc->spacer(15);
2594  } else {
2595  $out .= $this->doc->spacer(15);
2596  }
2597  return $out;
2598  }
2599 
2607  protected function areFieldChangeFunctionsValid($handleFlexformSections = FALSE) {
2608  $result = FALSE;
2609  if (isset($this->P['fieldChangeFunc']) && is_array($this->P['fieldChangeFunc']) && isset($this->P['fieldChangeFuncHash'])) {
2610  $matches = array();
2611  $pattern = '#\\[el\\]\\[(([^]-]+-[^]-]+-)(idx\\d+-)([^]]+))\\]#i';
2612  $fieldChangeFunctions = $this->P['fieldChangeFunc'];
2613  // Special handling of flexform sections:
2614  // Field change functions are modified in JavaScript, thus the hash is always invalid
2615  if ($handleFlexformSections && preg_match($pattern, $this->P['itemName'], $matches)) {
2616  $originalName = $matches[1];
2617  $cleanedName = $matches[2] . $matches[4];
2618  foreach ($fieldChangeFunctions as &$value) {
2619  $value = str_replace($originalName, $cleanedName, $value);
2620  }
2621  unset($value);
2622  }
2623  $result = $this->P['fieldChangeFuncHash'] === GeneralUtility::hmac(serialize($fieldChangeFunctions));
2624  }
2625  return $result;
2626  }
2627 
2633  protected function getTemporaryTreeMountCancelNotice() {
2634  if ((int)$GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint') === 0) {
2635  return '';
2636  }
2637  $link = '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('setTempDBmount' => 0))) . '">'
2638  . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xlf:labels.temporaryDBmount', TRUE) . '</a>';
2640  $flashMessage = GeneralUtility::makeInstance(
2641  'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
2642  $link,
2643  '',
2644  \TYPO3\CMS\Core\Messaging\FlashMessage::INFO
2645  );
2646  return $flashMessage->render();
2647  }
2648 
2656  protected function getFilesInFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList) {
2657  if ($extensionList !== '') {
2659  $filter = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
2660  $filter->setAllowedFileExtensions($extensionList);
2661  $folder->setFileAndFolderNameFilters(array(array($filter, 'filterFileList')));
2662  }
2663  return $folder->getFiles();
2664  }
2665 }
static skinImg($backPath, $src, $wHattribs='', $outputMode=0)
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=TRUE, $unsetMovePointers=FALSE)
$parameters
Definition: FileDumpEID.php:15
$moduleName
Definition: mod.php:22
static getRecordsByField($theTable, $theField, $theValue, $whereClause='', $groupBy='', $orderBy='', $limit='', $useDeleteClause=TRUE)
static isFirstPartOfStr($str, $partStr)
static getSpriteIconForResource(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, array $options=array(), array $overlays=array())
TBE_dragNDrop(Folder $folder, $extensionList='')
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static hmac($input, $additionalSecret='')
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static getRecordTitle($table, $row, $prep=FALSE, $forceResult=TRUE)
static getSpriteIconForRecord($table, array $row, array $options=array())
static unQuoteFilenames($parameters, $unQuote=FALSE)
static getModuleUrl($moduleName, $urlParameters=array(), $backPathOverride=FALSE, $returnAbsoluteUrl=FALSE)
TBE_expandFolder(Folder $folder, $extensionList='', $noThumbs=FALSE)
static linkThisScript(array $getParams=array())
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
static RTEsetup($RTEprop, $table, $field, $type='')
static implodeArrayForUrl($name, array $theArray, $str='', $skipBlank=FALSE, $rawurlencodeParamName=FALSE)
static formatSize($sizeInBytes, $labels='')
static fixed_lgd_cs($string, $chars, $appendString='...')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getPagesTSconfig($id, $rootLine=NULL, $returnPartArray=FALSE)
expandFolder(Folder $folder, $extensionList='')
areFieldChangeFunctionsValid($handleFlexformSections=FALSE)
static deleteClause($table, $tableAlias='')