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 4517b57..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);
@@ -761,7 +739,10 @@ class browse_links {
        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;
 
 
        /**
@@ -787,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);
@@ -810,6 +797,11 @@ 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']);
@@ -881,14 +873,6 @@ class browse_links {
                        // Initializing the title value (RTE)
                $this->setTitle = ($this->curUrlArray['title'] != '-') ? $this->curUrlArray['title'] : '';
 
-                       // Creating backend template object:
-               $this->doc = t3lib_div::makeInstance('template');
-               $this->doc->backPath = $BACK_PATH;
-
-                       // Load the Prototype library and browse_links.js
-               $this->doc->loadJavascriptLib('contrib/prototype/prototype.js');
-               $this->doc->loadJavascriptLib('js/browse_links.js');
-
                        // BEGIN accumulation of header JavaScript:
                $JScode = '
                                // This JavaScript is primarily for RTE/Link. jumpToUrl is used in the other cases as well...
@@ -1610,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 {
@@ -1677,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);
@@ -1699,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='';
@@ -1933,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);
                        }
@@ -2228,7 +2206,7 @@ class browse_links {
                return $out;
        }
 
-       /**
+       /**
         * Render list of folders.
         *
         * @param       array           List of folders. See t3lib_div::get_dirs
@@ -2379,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);
 
@@ -2481,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;
        }
 
@@ -2492,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');
        }
 
        /**
@@ -2641,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.='
 
                        <!--
@@ -2695,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').':');
@@ -2753,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