Follow-up to #12381: Scheduler: BLOB database fields may not be NOT NULL
[Packages/TYPO3.CMS.git] / typo3 / class.browse_links.php
old mode 100755 (executable)
new mode 100644 (file)
index c6f7aa3..5fae15e
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  *
  */
 
-require_once (PATH_t3lib.'class.t3lib_browsetree.php');
-require_once (PATH_t3lib.'class.t3lib_foldertree.php');
-require_once (PATH_t3lib.'class.t3lib_stdgraphic.php');
-require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
-
 
        // Include classes
-require_once (PATH_t3lib.'class.t3lib_page.php');
-require_once (PATH_t3lib.'class.t3lib_recordlist.php');
 require_once (PATH_typo3.'/class.db_list.inc');
 require_once (PATH_typo3.'/class.db_list_extra.inc');
-require_once (PATH_t3lib.'/class.t3lib_pagetree.php');
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 
 
 
@@ -162,6 +139,7 @@ class TBE_browser_recordList extends localRecordList {
         * @return      void
         */
        function TBE_browser_recordList () {
+               parent::__construct();
                $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
        }
 
@@ -215,7 +193,7 @@ class TBE_browser_recordList extends localRecordList {
                if (!$code) {
                        $code = '<i>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</i>';
                } else {
-                       $code = htmlspecialchars(t3lib_div::fixed_lgd_cs($code,$this->fixedL));
+                       $code = t3lib_BEfunc::getRecordTitlePrep($code, $this->fixedL);
                }
 
                $title = t3lib_BEfunc::getRecordTitle($table,$row,FALSE,TRUE);
@@ -552,7 +530,7 @@ class localFolderTree extends t3lib_folderTree {
                        $bgColorClass=($c+1)%2 ? 'bgColor' : 'bgColor-10';
 
                                // Creating blinking arrow, if applicable:
-                       if ($GLOBALS['SOBE']->browser->curUrlInfo['act']=='file' && $cmpPath==$v['row']['path'])        {
+                       if (($GLOBALS['SOBE']->browser->curUrlInfo['act'] == 'file' || $GLOBALS['SOBE']->browser->curUrlInfo['act'] == 'folder') && $cmpPath == $v['row']['path']) {
                                $arrCol='<td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_right.gif','width="5" height="9"').' class="c-blinkArrowR" alt="" /></td>';
                                $bgColorClass='bgColor4';
                        } else {
@@ -661,8 +639,9 @@ class browse_links {
        var $thisScript;                // the script to link to
        var $thisConfig;                // RTE specific TSconfig
        var $setTarget;                 // Target (RTE specific)
+       var $setClass;                  // CSS Class (RTE specific)
        var $setTitle;                  // title (RTE specific)
-       var $doc;                               // Backend template object
+       var $doc;                       // Backend template object
        var $elements = array();        // Holds information about files
 
                // GPvars:      (Input variables from outside)
@@ -708,8 +687,8 @@ class browse_links {
         *
         * Values:
         * 0: form field name reference, eg. "data[tt_content][123][image]"
-        * 1: old/unused?
-        * 2: old/unused?
+        * 1: htlmArea RTE parameters: editorNo:contentTypo3Language:contentTypo3Charset
+        * 2: RTE config parameters: RTEtsConfigParams
         * 3: allowed types. Eg. "tt_content" or "gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai"
         * 4: IRRE uniqueness: target level object-id to perform actions/checks on, eg. "data[79][tt_address][1][<field>][<foreign_table>]"
         * 5: IRRE uniqueness: name of function in opener window that checks if element is already used, eg. "inline.checkUniqueElement"
@@ -757,10 +736,13 @@ class browse_links {
        /**
         * array which holds hook objects (initialised in init() )
         */
-       protected $hookObjects;
+       protected $hookObjects = array();
 
 
-       var     $readOnly = FALSE;      // If set, all operations that changes something should be disabled. This is used for alternativeBrowsing file mounts (see options like "options.folderTree.altElementBrowserMountPoints" in browse_links.php).
+       /**
+        * object for t3lib_basicFileFunctions
+        */
+       public $fileProcessor;
 
 
        /**
@@ -786,12 +768,18 @@ class browse_links {
                if (!$this->mode)       {
                        $this->mode = 'rte';
                }
+                       // Creating backend template object:
+               $this->doc = t3lib_div::makeInstance('template');
+               $this->doc->backPath = $GLOBALS['BACK_PATH'];
+                       // Load the Prototype library and browse_links.js
+               $this->doc->getPageRenderer()->loadPrototype();
+               $this->doc->loadJavascriptLib('js/browse_links.js');
 
                        // init hook objects:
                $this->hookObjects = array();
                if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'])) {
                        foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'] as $classData) {
-                               $processObject = &t3lib_div::getUserObj($classData);
+                               $processObject = t3lib_div::getUserObj($classData);
 
                                if(!($processObject instanceof t3lib_browseLinksHook)) {
                                        throw new UnexpectedValueException('$processObject must implement interface t3lib_browseLinksHook', 1195039394);
@@ -809,13 +797,47 @@ class browse_links {
                        // the script to link to
                $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
 
+                       // init fileProcessor
+               $this->fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
+               $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
+
+
                        // CurrentUrl - the current link url must be passed around if it exists
                if ($this->mode == 'wizard')    {
                        $currentLinkParts = t3lib_div::trimExplode(' ',$this->P['currentValue']);
-                       $this->curUrlArray = array(
-                               'target' => $currentLinkParts[1]
+                       $initialCurUrlArray = array (
+                               'href'   => $currentLinkParts[0],
+                               'target' => $currentLinkParts[1],
+                               'class'  => $currentLinkParts[2],
+                               'title'  => $currentLinkParts[3],
                        );
-                       $this->curUrlInfo=$this->parseCurUrl($this->siteURL.'?id='.$currentLinkParts[0],$this->siteURL);
+                       $this->curUrlArray = (is_array(t3lib_div::_GP('curUrl'))) ?
+                               array_merge($initialCurUrlArray, t3lib_div::_GP('curUrl')) :
+                               $initialCurUrlArray;
+                       $this->curUrlInfo = $this->parseCurUrl($this->siteURL.'?id='.$this->curUrlArray['href'], $this->siteURL);
+                       if ($this->curUrlInfo['pageid'] == 0 && $this->curUrlArray['href']) { // pageid == 0 means that this is not an internal (page) link
+                               if (file_exists(PATH_site.rawurldecode($this->curUrlArray['href'])))    { // check if this is a link to a file
+                                       if (t3lib_div::isFirstPartOfStr($this->curUrlArray['href'], PATH_site)) {
+                                               $currentLinkParts[0] = substr($this->curUrlArray['href'], strlen(PATH_site));
+                                       }
+                                       $this->curUrlInfo = $this->parseCurUrl($this->siteURL.$this->curUrlArray['href'], $this->siteURL);
+                               } elseif (strstr($this->curUrlArray['href'], '@')) { // check for email link
+                                       if (t3lib_div::isFirstPartOfStr($this->curUrlArray['href'], 'mailto:')) {
+                                               $currentLinkParts[0] = substr($this->curUrlArray['href'], 7);
+                                       }
+                                       $this->curUrlInfo = $this->parseCurUrl('mailto:'.$this->curUrlArray['href'], $this->siteURL);
+                               } else { // nothing of the above. this is an external link
+                                       if(strpos($this->curUrlArray['href'], '://') === false) {
+                                               $currentLinkParts[0] = 'http://' . $this->curUrlArray['href'];
+                                       }
+                                       $this->curUrlInfo = $this->parseCurUrl($currentLinkParts[0], $this->siteURL);
+                               }
+                       } elseif (!$this->curUrlArray['href']) {
+                               $this->curUrlInfo = array();
+                               $this->act = 'page';
+                       } else {
+                               $this->curUrlInfo = $this->parseCurUrl($this->siteURL.'?id='.$this->curUrlArray['href'], $this->siteURL);
+                       }
                } else {
                        $this->curUrlArray = t3lib_div::_GP('curUrl');
                        if ($this->curUrlArray['all'])  {
@@ -840,43 +862,44 @@ class browse_links {
                }
 
                        // Initializing the target value (RTE)
-               $this->setTarget = $this->curUrlArray['target'];
+               $this->setTarget = ($this->curUrlArray['target'] != '-') ? $this->curUrlArray['target'] : '';
                if ($this->thisConfig['defaultLinkTarget'] && !isset($this->curUrlArray['target']))     {
                        $this->setTarget=$this->thisConfig['defaultLinkTarget'];
                }
 
-                       // Initializing the title value (RTE)
-               $this->setTitle = $this->curUrlArray['title'];
-
+                       // Initializing the class value (RTE)
+               $this->setClass = ($this->curUrlArray['class'] != '-') ? $this->curUrlArray['class'] : '';
 
-
-                       // Creating backend template object:
-               $this->doc = t3lib_div::makeInstance('template');
-               $this->doc->docType= 'xhtml_trans';
-               $this->doc->backPath = $BACK_PATH;
+                       // Initializing the title value (RTE)
+               $this->setTitle = ($this->curUrlArray['title'] != '-') ? $this->curUrlArray['title'] : '';
 
                        // BEGIN accumulation of header JavaScript:
-               $JScode = '';
-               $JScode.= '
+               $JScode = '
                                // This JavaScript is primarily for RTE/Link. jumpToUrl is used in the other cases as well...
                        var add_href="'.($this->curUrlArray['href']?'&curUrl[href]='.rawurlencode($this->curUrlArray['href']):'').'";
                        var add_target="'.($this->setTarget?'&curUrl[target]='.rawurlencode($this->setTarget):'').'";
+                       var add_class="'.($this->setClass ? '&curUrl[class]='.rawurlencode($this->setClass) : '').'";
                        var add_title="'.($this->setTitle?'&curUrl[title]='.rawurlencode($this->setTitle):'').'";
                        var add_params="'.($this->bparams?'&bparams='.rawurlencode($this->bparams):'').'";
 
                        var cur_href="'.($this->curUrlArray['href']?$this->curUrlArray['href']:'').'";
                        var cur_target="'.($this->setTarget?$this->setTarget:'').'";
+                       var cur_class = "'.($this->setClass ? $this->setClass : '-').'";
                        var cur_title="'.($this->setTitle?$this->setTitle:'').'";
 
-                       function setTarget(target)      {       //
+                       function browse_links_setTarget(target) {       //
                                cur_target=target;
                                add_target="&curUrl[target]="+escape(target);
                        }
-                       function setTitle(title)        {       //
+                       function browse_links_setClass(cssClass) {   //
+                               cur_class = cssClass;
+                               add_class = "&curUrl[class]=" + escape(cssClass);
+                       }
+                       function browse_links_setTitle(title)   {       //
                                cur_title=title;
                                add_title="&curUrl[title]="+escape(title);
                        }
-                       function setValue(value)        {       //
+                       function browse_links_setValue(value) { //
                                cur_href=value;
                                add_href="&curUrl[href]="+value;
                        }
@@ -901,21 +924,30 @@ class browse_links {
 
                        $JScode.='
                                function link_typo3Page(id,anchor)      {       //
-                                       updateValueInMainForm(id+(anchor?anchor:"")+" "+cur_target);
+                                       updateValueInMainForm(id + (anchor ? anchor : ""));
                                        close();
                                        return false;
                                }
                                function link_folder(folder)    {       //
-                                       updateValueInMainForm(folder+" "+cur_target);
+                                       updateValueInMainForm(folder);
                                        close();
                                        return false;
                                }
                                function link_current() {       //
                                        if (cur_href!="http://" && cur_href!="mailto:") {
-                                               var setValue = cur_href+" "+cur_target+" "+cur_title;
-                                               if (setValue.substr(0,7)=="http://")    setValue = setValue.substr(7);
-                                               if (setValue.substr(0,7)=="mailto:")    setValue = setValue.substr(7);
-                                               updateValueInMainForm(setValue);
+                                               returnBeforeCleaned = cur_href;
+                                               if (returnBeforeCleaned.substr(0, 7) == "http://") {
+                                                       returnToMainFormValue = returnBeforeCleaned.substr(7);
+                                               } else if (returnBeforeCleaned.substr(0, 7) == "mailto:") {
+                                                       if (returnBeforeCleaned.substr(0, 14) == "mailto:mailto:") {
+                                                               returnToMainFormValue = returnBeforeCleaned.substr(14);
+                                                       } else {
+                                                               returnToMainFormValue = returnBeforeCleaned.substr(7);
+                                                       }
+                                               } else {
+                                                       returnToMainFormValue = returnBeforeCleaned;
+                                               }
+                                               updateValueInMainForm(returnToMainFormValue);
                                                close();
                                        }
                                        return false;
@@ -930,6 +962,13 @@ class browse_links {
                                function updateValueInMainForm(input)   {       //
                                        var field = checkReference();
                                        if (field)      {
+                                               if (cur_target == "" && (cur_title != "" || cur_class != "-")) {
+                                                       cur_target = "-";
+                                               }
+                                               if (cur_title == "" && cur_class == "-") {
+                                                       cur_class = "";
+                                               }
+                                               input = input + " " + cur_target + " " + cur_class + " " + cur_title;
                                                field.value = input;
                                                '.$update.'
                                        }
@@ -939,21 +978,21 @@ class browse_links {
                        $JScode.='
                                function link_typo3Page(id,anchor)      {       //
                                        var theLink = \''.$this->siteURL.'?id=\'+id+(anchor?anchor:"");
-                                       self.parent.parent.renderPopup_addLink(theLink,cur_target,cur_title);
+                                       self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
                                        return false;
                                }
                                function link_folder(folder)    {       //
                                        var theLink = \''.$this->siteURL.'\'+folder;
-                                       self.parent.parent.renderPopup_addLink(theLink,cur_target,cur_title);
+                                       self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
                                        return false;
                                }
                                function link_spec(theLink)     {       //
-                                       self.parent.parent.renderPopup_addLink(theLink,cur_target,cur_title);
+                                       self.parent.parent.renderPopup_addLink(theLink, cur_target, cur_class, cur_title);
                                        return false;
                                }
                                function link_current() {       //
                                        if (cur_href!="http://" && cur_href!="mailto:") {
-                                               self.parent.parent.renderPopup_addLink(cur_href,cur_target,cur_title);
+                                               self.parent.parent.renderPopup_addLink(cur_href, cur_target, cur_class, cur_title);
                                        }
                                        return false;
                                }
@@ -965,7 +1004,7 @@ class browse_links {
                        function jumpToUrl(URL,anchor)  {       //
                                var add_act = URL.indexOf("act=")==-1 ? "&act='.$this->act.'" : "";
                                var add_mode = URL.indexOf("mode=")==-1 ? "&mode='.$this->mode.'" : "";
-                               var theLocation = URL+add_act+add_mode+add_href+add_target+add_title+add_params'.($addPassOnParams?'+"'.$addPassOnParams.'"':'').'+(anchor?anchor:"");
+                               var theLocation = URL + add_act + add_mode + add_href + add_target + add_class + add_title + add_params'.($addPassOnParams?'+"'.$addPassOnParams.'"':'').'+(anchor?anchor:"");
                                window.location.href = theLocation;
                                return false;
                        }
@@ -1048,11 +1087,7 @@ class browse_links {
                                }
                        }
                        function setReferences()        {       //
-                               if (parent.window.opener
-                               && parent.window.opener.content
-                               && parent.window.opener.content.document.editform
-                               && parent.window.opener.content.document.editform["'.$formFieldName.'"]
-                                               ) {
+                               if (parent.window.opener && parent.window.opener.content && parent.window.opener.content.document.editform && parent.window.opener.content.document.editform["'.$formFieldName.'"]) {
                                        targetDoc = parent.window.opener.content.document;
                                        elRef = targetDoc.editform["'.$formFieldName.'"];
                                        return true;
@@ -1084,8 +1119,6 @@ class browse_links {
                ';
 
                        // Finally, add the accumulated JavaScript to the template object:
-               $this->doc->JScode = '<script type="text/javascript" src="contrib/prototype/prototype.js"></script>'."\n";
-               $this->doc->JScode.= '<script type="text/javascript" src="js/browse_links.js"></script>'."\n";
                $this->doc->JScode.= $this->doc->wrapScriptTags($JScode);
 
                        // Debugging:
@@ -1235,7 +1268,6 @@ class browse_links {
                        // Adding the menu and header to the top of page:
                $content.=$this->printCurrentUrl($this->curUrlInfo['info']).'<br />';
 
-
                        // Depending on the current action we will create the actual module content for selecting a link:
                switch($this->act)      {
                        case 'mail':
@@ -1247,9 +1279,9 @@ class browse_links {
                                        <form action="" name="lurlform" id="lurlform">
                                                <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkMail">
                                                        <tr>
-                                                               <td>'.$GLOBALS['LANG']->getLL('emailAddress',1).':</td>
+                                                               <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('emailAddress', 1) . ':</td>
                                                                <td><input type="text" name="lemail"'.$this->doc->formWidth(20).' value="'.htmlspecialchars($this->curUrlInfo['act']=='mail'?$this->curUrlInfo['info']:'').'" /> '.
-                                                                       '<input type="submit" value="'.$GLOBALS['LANG']->getLL('setLink',1).'" onclick="setTarget(\'\');setValue(\'mailto:\'+document.lurlform.lemail.value); return link_current();" /></td>
+                                                                       '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', 1) . '" onclick="browse_links_setTarget(\'\');browse_links_setValue(\'mailto:\'+document.lurlform.lemail.value); return link_current();" /></td>
                                                        </tr>
                                                </table>
                                        </form>';
@@ -1264,9 +1296,9 @@ class browse_links {
                                        <form action="" name="lurlform" id="lurlform">
                                                <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkURL">
                                                        <tr>
-                                                               <td>URL:</td>
-                                                               <td><input type="text" name="lurl"'.$this->doc->formWidth(20).' value="'.htmlspecialchars($this->curUrlInfo['act']=='url'?$this->curUrlInfo['info']:'http://').'" /> '.
-                                                                       '<input type="submit" value="'.$GLOBALS['LANG']->getLL('setLink',1).'" onclick="setValue(document.lurlform.lurl.value); return link_current();" /></td>
+                                                               <td style="width: 96px;">URL:</td>
+                                                               <td><input type="text" name="lurl"'.$this->doc->formWidth(30).' value="'.htmlspecialchars($this->curUrlInfo['act']=='url'?$this->curUrlInfo['info']:'http://').'" /> '.
+                                                                       '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', 1) . '" onclick="browse_links_setValue(document.lurlform.lurl.value); return link_current();" /></td>
                                                        </tr>
                                                </table>
                                        </form>';
@@ -1282,12 +1314,14 @@ class browse_links {
                                        $cmpPath = '';
                                } elseif (substr(trim($this->curUrlInfo['info']), -1) != '/')   {
                                        $cmpPath = PATH_site.dirname($this->curUrlInfo['info']).'/';
-
                                        if (!isset($this->expandFolder)) {
                                                $this->expandFolder = $cmpPath;
                                        }
                                } else {
                                        $cmpPath = PATH_site.$this->curUrlInfo['info'];
+                                       if (!isset($this->expandFolder) && $this->curUrlInfo['act'] == 'folder') {
+                                               $this->expandFolder = $cmpPath;
+                                       }
                                }
 
                                list(, , $specUid) = explode('_', $this->PM);
@@ -1295,7 +1329,6 @@ class browse_links {
                                        $foldertree->specUIDmap[$specUid],
                                        $this->P['params']['allowedExtensions']
                                );
-
                                $content.= '
 
                        <!--
@@ -1330,7 +1363,7 @@ class browse_links {
 
                                                                // URL + onclick event:
                                                        $onClickEvent='';
-                                                       if (isset($v[$k2i.'.']['target']))      $onClickEvent.="setTarget('".$v[$k2i.'.']['target']."');";
+                                                       if (isset($v[$k2i.'.']['target']))      $onClickEvent.="browse_links_setTarget('".$v[$k2i.'.']['target']."');";
                                                        $v[$k2i.'.']['url'] = str_replace('###_URL###',$this->siteURL,$v[$k2i.'.']['url']);
                                                        if (substr($v[$k2i.'.']['url'],0,7)=='http://' || substr($v[$k2i.'.']['url'],0,7)=='mailto:')   {
                                                                $onClickEvent.="cur_href=unescape('".rawurlencode($v[$k2i.'.']['url'])."');link_current();";
@@ -1390,23 +1423,31 @@ class browse_links {
                                foreach($this->hookObjects as $hookObject) {
                                        $content .= $hookObject->getTab($this->act);
                                }
-
                        break;
                }
 
                $content .= '
 
-
+                       <!--
+                               Selecting class for link:
+                       -->
+                               <form action="" name="lclassform" id="lclassform">
+                                       <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkClass">
+                                               <tr>
+                                                       <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('class', 1) . '</td>
+                                                       <td><input type="text" name="lclass" onchange="browse_links_setClass(this.value);" value="' . htmlspecialchars($this->setClass) . '"' . $this->doc->formWidth(10) . ' /></td>
+                                               </tr>
+                                       </table>
+                               </form>
 
                        <!--
                                Selecting title for link:
                        -->
-                               <form action="" name="ltitleform" id="ltargetform">
-                                       <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">
+                               <form action="" name="ltitleform" id="ltitleform">
+                                       <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTitle">
                                                <tr>
-                                                       <td>'.$GLOBALS['LANG']->getLL('title',1).'</td>
-                                                       <td><input type="text" name="ltitle" onchange="setTitle(this.value);" value="'.htmlspecialchars($this->setTitle).'"'.$this->doc->formWidth(10).' /></td>
-                                                       <td><input type="submit" value="'.$GLOBALS['LANG']->getLL('update',1).'" onclick="return link_current();" /></td>
+                                                       <td style="width: 96px;">' . $GLOBALS['LANG']->getLL('title', 1) . '</td>
+                                                       <td><input type="text" name="ltitle" onchange="browse_links_setTitle(this.value);" value="' . htmlspecialchars($this->setTitle) . '"' . $this->doc->formWidth(10) . ' /></td>
                                                </tr>
                                        </table>
                                </form>
@@ -1425,17 +1466,16 @@ class browse_links {
                                        <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkTarget">
                                                <tr>
                                                        <td>'.$GLOBALS['LANG']->getLL('target',1).':</td>
-                                                       <td><input type="text" name="ltarget" onchange="setTarget(this.value);" value="'.htmlspecialchars($this->setTarget).'"'.$this->doc->formWidth(10).' /></td>
+                                                       <td><input type="text" name="ltarget" onchange="browse_links_setTarget(this.value);" value="' . htmlspecialchars($this->setTarget) . '"' . $this->doc->formWidth(10) . ' /></td>
                                                        <td>
-                                                               <select name="ltarget_type" onchange="setTarget(this.options[this.selectedIndex].value);document.ltargetform.ltarget.value=this.options[this.selectedIndex].value;this.selectedIndex=0;">
+                                                               <select name="ltarget_type" onchange="browse_links_setTarget(this.options[this.selectedIndex].value);document.ltargetform.ltarget.value=this.options[this.selectedIndex].value;this.selectedIndex=0;">
                                                                        <option></option>
                                                                        <option value="_top">'.$GLOBALS['LANG']->getLL('top',1).'</option>
                                                                        <option value="_blank">'.$GLOBALS['LANG']->getLL('newWindow',1).'</option>
                                                                </select>
                                                        </td>
                                                        <td>';
-
-                       if (($this->curUrlInfo['act']=="page" || $this->curUrlInfo['act']=='file') && $this->curUrlArray['href'])       {
+                       if (($this->curUrlInfo['act'] == 'page' || $this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder') && $this->curUrlArray['href'] && $this->curUrlInfo['act'] == $this->act) {
                                $ltarget.='
                                                        <input type="submit" value="'.$GLOBALS['LANG']->getLL('update',1).'" onclick="return link_current();" />';
                        }
@@ -1443,8 +1483,9 @@ class browse_links {
                        $selectJS = '
                                if (document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value>0 && document.ltargetform.popup_height.options[document.ltargetform.popup_height.selectedIndex].value>0)     {
                                        document.ltargetform.ltarget.value = document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value+"x"+document.ltargetform.popup_height.options[document.ltargetform.popup_height.selectedIndex].value;
-                                       setTarget(document.ltargetform.ltarget.value);
-                               setTitle(document.ltitleform.ltitle.value);
+                                       browse_links_setTarget(document.ltargetform.ltarget.value);
+                                       browse_links_setClass(document.lclassform.lclass.value);
+                                       browse_links_setTitle(document.ltitleform.ltitle.value);
                                        document.ltargetform.popup_width.selectedIndex=0;
                                        document.ltargetform.popup_height.selectedIndex=0;
                                }
@@ -1553,13 +1594,12 @@ class browse_links {
                $pArr = explode('|',$this->bparams);
 
                        // Create upload/create folder forms, if a path is given:
-               $fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
-               $fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
                $path=$this->expandFolder;
                if (!$path || !@is_dir($path))  {
-                       $path = $fileProcessor->findTempFolder().'/';   // The closest TEMP-path is found
+                               // The closest TEMP-path is found
+                       $path = $this->fileProcessor->findTempFolder().'/';
                }
-               if ($path!='/' && @is_dir($path) && !$this->readOnly && count($GLOBALS['FILEMOUNTS']))  {
+               if ($path!='/' && @is_dir($path)) {
                        $uploadForm=$this->uploadForm($path);
                        $createFolder=$this->createFolder($path);
                } else {
@@ -1620,7 +1660,7 @@ class browse_links {
                $content.='<br /><br />';
 
                        // Setup indexed elements:
-               $this->doc->JScode.= $this->doc->wrapScriptTags('BrowseLinks.addElements('.t3lib_div::array2json($this->elements).');');
+               $this->doc->JScode.= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
                        // Ending page, returning content:
                $content.= $this->doc->endPage();
                $content = $this->doc->insertStylesAndJS($content);
@@ -1642,18 +1682,13 @@ class browse_links {
                        // Init variable:
                $parameters = explode('|', $this->bparams);
 
-                       // Create upload/create folder forms, if a path is given:
-               $fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
-               $fileProcessor->init(
-                       $GLOBALS['FILEMOUNTS'],
-                       $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']
-               );
 
                $path = $this->expandFolder;
-               if(!$path || !@is_dir($path)) {
-                       $path = $fileProcessor->findTempFolder().'/';   // The closest TEMP-path is found
+               if (!$path || !@is_dir($path)) {
+                               // The closest TEMP-path is found
+                       $path = $this->fileProcessor->findTempFolder().'/';
                }
-               if($path != '/' && @is_dir($path)) {
+               if ($path != '/' && @is_dir($path)) {
                        $createFolder = $this->createFolder($path);
                } else {
                        $createFolder='';
@@ -1751,7 +1786,7 @@ class browse_links {
                                // Create header for listing, showing the page title/icon:
                        $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
                        $mainPageRec = t3lib_BEfunc::getRecordWSOL('pages',$expPageId);
-                       $picon=t3lib_iconWorks::getIconImage('pages',$mainPageRec,'','');
+                       $picon = t3lib_iconWorks::getIconImage('pages', $mainPageRec, $BACK_PATH, '');
                        $picon.= htmlspecialchars(t3lib_div::fixed_lgd_cs($mainPageRec['title'],$titleLen));
                        $out.=$picon.'<br />';
 
@@ -1876,7 +1911,7 @@ class browse_links {
                                //      Add the HTML for the record list to output variable:
                        $out.=$dblist->HTMLcode;
 
-                               // Add support for fieldselectbox in singleTableMode
+                               // Add support for fieldselectbox in singleTableMode
                        if ($dblist->table) {
                                $out.= $dblist->fieldSelectBox($dblist->table);
                        }
@@ -1968,32 +2003,44 @@ class browse_links {
                        $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
                        $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
                        $picon='<a href="#" onclick="return link_folder(\''.t3lib_div::rawUrlEncodeFP(substr($expandFolder,strlen(PATH_site))).'\');">'.$picon.'</a>';
+                       if ($this->curUrlInfo['act'] == 'folder' && $cmpPath == $expandFolder)  {
+                               $out.= '<img'.t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />';
+                       }
                        $out.=$picon.'<br />';
 
                                // Get files from the folder:
-                       $files = t3lib_div::getFilesInDir($expandFolder,$extensionList,1,1);    // $extensionList="",$prependPath=0,$order='')
+                       if ($this->mode == 'wizard' && $this->act == 'folder') {
+                               $files = t3lib_div::get_dirs($expandFolder);
+                       } else {
+                               $files = t3lib_div::getFilesInDir($expandFolder, $extensionList, 1, 1); // $extensionList='', $prependPath=0, $order='')
+                       }
+
                        $c=0;
                        $cc=count($files);
-
                        if (is_array($files))   {
                                foreach($files as $filepath)    {
                                        $c++;
                                        $fI=pathinfo($filepath);
 
-                                               // File icon:
-                                       $icon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
+                                       if ($this->mode == 'wizard' && $this->act == 'folder') {
+                                               $filepath = $expandFolder.$filepath.'/';
+                                               $icon = '<img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
+                                       } else {
+                                                       // File icon:
+                                               $icon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
+
+                                                       // Get size and icon:
+                                               $size = ' (' . t3lib_div::formatSize(filesize($filepath)) . 'bytes)';
+                                               $icon = '<img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/fileicons/' . $icon . '', 'width="18" height="16"') . ' title="' . htmlspecialchars($fI['basename'] . $size) . '" alt="" />';
+                                       }
 
                                                // If the listed file turns out to be the CURRENT file, then show blinking arrow:
-                                       if ($this->curUrlInfo['act']=="file" && $cmpPath==$filepath)    {
+                                       if (($this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder') && $cmpPath == $filepath) {
                                                $arrCol='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_left.gif','width="5" height="9"').' class="c-blinkArrowL" alt="" />';
                                        } else {
                                                $arrCol='';
                                        }
 
-                                               // Get size and icon:
-                                       $size=' ('.t3lib_div::formatSize(filesize($filepath)).'bytes)';
-                                       $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$icon.'','width="18" height="16"').' title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
-
                                                // Put it all together for the file element:
                                        $out.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join'.($c==$cc?'bottom':'').'.gif','width="18" height="16"').' alt="" />'.
                                                        $arrCol.
@@ -2159,7 +2206,7 @@ class browse_links {
                return $out;
        }
 
-       /**
+       /**
         * Render list of folders.
         *
         * @param       array           List of folders. See t3lib_div::get_dirs
@@ -2310,7 +2357,7 @@ class browse_links {
                                                        <td colspan="2">'.$this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')).'</td>
                                                </tr>';
 
-                                               // Fraverse files:
+                                               // Traverse files:
                                        while(list(,$filepath)=each($files))    {
                                                $fI = pathinfo($filepath);
 
@@ -2412,7 +2459,7 @@ class browse_links {
         * @return      boolean         If the input path is found in PATH_site then it returns true.
         */
        function isWebFolder($folder)   {
-               $folder = ereg_replace('\/$','',$folder).'/';
+               $folder = rtrim($folder, '/').'/';
                return t3lib_div::isFirstPartOfStr($folder,PATH_site) ? TRUE : FALSE;
        }
 
@@ -2423,10 +2470,17 @@ class browse_links {
         * @return      boolean         If the input path is found in the backend users filemounts, then return true.
         */
        function checkFolder($folder)   {
-               $fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
-               $fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
+               return $this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/') ? true : false;
+       }
 
-               return $fileProcessor->checkPathAgainstMounts(ereg_replace('\/$','',$folder).'/') ? TRUE : FALSE;
+       /**
+        * Checks, if a path is within a read-only mountpoint of the backend user
+        *
+        * @param       string          Absolute filepath
+        * @return      boolean         If the input path is found in the backend users filemounts and if the filemount is of type readonly, then return true.
+        */
+       function isReadOnlyFolder($folder) {
+               return ($GLOBALS['FILEMOUNTS'][$this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/')]['type'] == 'readonly');
        }
 
        /**
@@ -2511,14 +2565,19 @@ class browse_links {
                                $info['act']='spec';
                        } elseif (t3lib_div::isFirstPartOfStr($href,$siteUrl))  {       // If URL is on the current frontend website:
                                $rel = substr($href,strlen($siteUrl));
-                               if (@file_exists(PATH_site.rawurldecode($rel))) {       // URL is a file, which exists:
+                               if (file_exists(PATH_site.rawurldecode($rel)))  {       // URL is a file, which exists:
                                        $info['value']=rawurldecode($rel);
-                                       $info['act']='file';
+                                       if (@is_dir(PATH_site . $info['value'])) {
+                                               $info['act'] = 'folder';
+                                       } else {
+                                               $info['act'] = 'file';
+                                       }
                                } else {        // URL is a page (id parameter)
                                        $uP=parse_url($rel);
                                        if (!trim($uP['path'])) {
                                                $pp = explode('id=',$uP['query']);
-                                               $id = $pp[1];
+                                               $parameters = explode('&', $pp[1]);
+                                               $id = array_shift($parameters);
                                                if ($id)        {
                                                                // Checking if the id-parameter is an alias.
                                                        if (!t3lib_div::testInt($id))   {
@@ -2532,6 +2591,7 @@ class browse_links {
                                                        $info['pageid']=$id;
                                                        $info['cElement']=$uP['fragment'];
                                                        $info['act']='page';
+                                                       $info['query'] = $parameters[0]?'&'.implode('&', $parameters):'';
                                                }
                                        }
                                }
@@ -2566,11 +2626,20 @@ class browse_links {
         */
        function uploadForm($path)      {
                global $BACK_PATH;
-               $count=3;
+
+               if ($this->isReadOnlyFolder($path)) return '';
+
+                       // Read configuration of upload field count
+               $userSetting = $GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
+               $count = isset($userSetting) ? $userSetting : 3;
+               if ($count === '0') {
+                       return '';
+               }
+               $count = intval($count) == 0 ? 3 : intval($count);
 
                        // Create header, showing upload path:
                $header = t3lib_div::isFirstPartOfStr($path,PATH_site)?substr($path,strlen(PATH_site)):$path;
-               $code=$this->barheader($GLOBALS['LANG']->getLL('uploadImage').':');
+               $code=$this->barheader($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle',1).':');
                $code.='
 
                        <!--
@@ -2620,6 +2689,13 @@ class browse_links {
         */
        function createFolder($path)    {
                global $BACK_PATH;
+
+               if ($this->isReadOnlyFolder($path)) return '';
+
+                       // Don't show Folder-create form if it's denied
+               if ($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.hideCreateFolder')) {
+                       return '';
+               }
                        // Create header, showing upload path:
                $header = t3lib_div::isFirstPartOfStr($path,PATH_site)?substr($path,strlen(PATH_site)):$path;
                $code=$this->barheader($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_newfolder.php.pagetitle').':');
@@ -2678,10 +2754,9 @@ class browse_links {
        }
 }
 
-// Include extension?
+
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.browse_links.php'])   {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.browse_links.php']);
 }
 
-
 ?>
\ No newline at end of file