Fixed bug 5701: linkHandler Hook Not Initialized Properly, patch supplied by Jeff...
[Packages/TYPO3.CMS.git] / typo3 / alt_file_navframe.php
index 40bce6f..3e2aae4 100755 (executable)
@@ -72,9 +72,17 @@ class SC_alt_file_navframe {
                // Internal, dynamic:
        var $content;           // Content accumulates in this variable.
        var $foldertree;        // Folder tree object.
-       var $doc;                       // Template object.
+
+       /**
+        * document template object
+        *
+        * @var template
+        */
+       var $doc;
+       var $backPath;
 
                // Internal, static: GPvar:
+       var $ajax;                                                      // Is set, if an AJAX call should be handled.
        var $currentSubScript;
        var $cMR;
 
@@ -87,7 +95,11 @@ class SC_alt_file_navframe {
        function init() {
                global $BE_USER,$BACK_PATH,$CLIENT;
 
+                       // Setting backPath
+               $this->backPath = $BACK_PATH;
+
                        // Setting GPvars:
+               $this->ajax = t3lib_div::_GP('ajax');
                $this->currentSubScript = t3lib_div::_GP('currentSubScript');
                $this->cMR = t3lib_div::_GP('cMR');
 
@@ -96,51 +108,52 @@ class SC_alt_file_navframe {
                $this->foldertree->ext_IconMode = $BE_USER->getTSConfigVal('options.folderTree.disableIconLinkToContextmenu');
                $this->foldertree->thisScript = 'alt_file_navframe.php';
 
-                       // Setting highlight mode:
-               $this->doHighlight = !$BE_USER->getTSConfigVal('options.pageTree.disableTitleHighlight');
-
-                       // Create template object:
-               $this->doc = t3lib_div::makeInstance('template');
-               $this->doc->docType = 'xhtml_trans';
-
-                       // Setting backPath
-               $this->doc->backPath = $BACK_PATH;
-
-                       // Adding javascript code for AJAX (prototype), drag&drop and the pagetree
-               $this->doc->JScode  = '
-               <script type="text/javascript" src="prototype.js"></script>
-               <script type="text/javascript" src="tree.js"></script>'."\n";
-
-                       // Setting JavaScript for menu.
-               $this->doc->JScode .= $this->doc->wrapScriptTags(
-               ($this->currentSubScript?'top.currentSubScript=unescape("'.rawurlencode($this->currentSubScript).'");':'').'
-
-               // setting prefs for pagetree and drag & drop
-               Tree.thisScript    = "'.$this->foldertree->thisScript.'";
-               DragDrop.changeURL = "'.$this->backPath.'alt_clickmenu.php";
-               DragDrop.backPath  = "'.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
-               DragDrop.table     = "folders";
-
-               // Function, loading the list frame from navigation tree:
-               function jumpTo(id, linkObj, highlightID, bank) {
-                       var theUrl = top.TS.PATH_typo3 + top.currentSubScript + "?id=" + id;
-                       top.fsMod.currentBank = bank;
-
-                       if (top.condensedMode) top.content.location.href = theUrl;
-                       else                   parent.list_frame.location.href = theUrl;
-
-                       '.($this->doHighlight ? 'Tree.highlightActiveItem("file", highlightID + "_" + bank);' : '').'
-                       '.(!$GLOBALS['CLIENT']['FORMSTYLE'] ? '' : 'if (linkObj) linkObj.blur(); ').'
-                       return false;
+                       // Use template rendering only if this is a non-AJAX call:
+               if (!$this->ajax) {
+                               // Setting highlight mode:
+                       $this->doHighlight = !$BE_USER->getTSConfigVal('options.pageTree.disableTitleHighlight');
+
+                               // Create template object:
+                       $this->doc = t3lib_div::makeInstance('template');
+                       $this->doc->backPath = $BACK_PATH;
+                       $this->doc->docType = 'xhtml_trans';
+
+                               // Adding javascript code for AJAX (prototype), drag&drop and the pagetree
+                       $this->doc->JScode  = '
+                       <script type="text/javascript" src="'.$this->backPath.'contrib/prototype/prototype.js"></script>
+                       <script type="text/javascript" src="'.$this->backPath.'tree.js"></script>'."\n";
+
+                               // Setting JavaScript for menu.
+                       $this->doc->JScode .= $this->doc->wrapScriptTags(
+                       ($this->currentSubScript?'top.currentSubScript=unescape("'.rawurlencode($this->currentSubScript).'");':'').'
+
+                       // setting prefs for pagetree and drag & drop
+                       Tree.thisScript    = "'.$this->foldertree->thisScript.'";
+                       DragDrop.changeURL = "'.$this->backPath.'alt_clickmenu.php";
+                       DragDrop.backPath  = "'.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
+                       DragDrop.table     = "folders";
+
+                       // Function, loading the list frame from navigation tree:
+                       function jumpTo(id, linkObj, highlightID, bank) {
+                               var theUrl = top.TS.PATH_typo3 + top.currentSubScript + "?id=" + id;
+                               top.fsMod.currentBank = bank;
+
+                               if (top.condensedMode) top.content.location.href = theUrl;
+                               else                   parent.list_frame.location.href = theUrl;
+
+                               '.($this->doHighlight ? 'Tree.highlightActiveItem("file", highlightID + "_" + bank);' : '').'
+                               '.(!$GLOBALS['CLIENT']['FORMSTYLE'] ? '' : 'if (linkObj) linkObj.blur(); ').'
+                               return false;
+                       }
+                       '.($this->cMR ? " jumpTo(top.fsMod.recentIds['file'],'');" : '')
+                       );
+
+                               // Click menu code is added:
+                       $CMparts=$this->doc->getContextMenuCode();
+                       $this->doc->bodyTagAdditions = $CMparts[1];
+                       $this->doc->JScode.= $CMparts[0];
+                       $this->doc->postCode.= $CMparts[2];
                }
-               '.($this->cMR ? " jumpTo(top.fsMod.recentIds['file'],'');" : '')
-               );
-
-                       // Click menu code is added:
-               $CMparts=$this->doc->getContextMenuCode();
-               $this->doc->bodyTagAdditions = $CMparts[1];
-               $this->doc->JScode.= $CMparts[0];
-               $this->doc->postCode.= $CMparts[2];
        }
 
        /**
@@ -154,9 +167,9 @@ class SC_alt_file_navframe {
                        // Produce browse-tree:
                $tree = $this->foldertree->getBrowsableTree();
 
-                       // output only the tree if this is an ajax call
-               if (t3lib_div::_GP('ajax')) {
-                       $this->content = $tree;
+                       // Output only the tree if this is an AJAX call:
+               if ($this->ajax) {
+                       $this->content = $LANG->csConvObj->utf8_encode($tree, $LANG->charSet);
                        return;
                }
 
@@ -191,7 +204,12 @@ class SC_alt_file_navframe {
         * @return      void
         */
        function printContent() {
-               if (!t3lib_div::_GP('ajax')) {
+                       // If we handle an AJAX call, send headers:
+               if ($this->ajax) {
+                       header('X-JSON: ('.($this->foldertree->ajaxStatus?'true':'false').')');
+                       header('Content-type: text/html; charset=utf-8');
+                       // If it's the regular call to fully output the tree:
+               } else {
                        $this->content.= $this->doc->endPage();
                        $this->content = $this->doc->insertStylesAndJS($this->content);
                }