(feature/cleanup) Refactored clickmenu to speed up the BE
[Packages/TYPO3.CMS.git] / typo3 / alt_db_navframe.php
index a8c226a..86a9480 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
  * XHTML compliant
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
+ *  192: class SC_alt_db_navframe
+ *  210:     function init()
+ *  313:     function main()
+ *  387:     function printContent()
  *
- *   72: class localPageTree extends t3lib_browseTree
- *   79:     function localPageTree()
- *   90:     function wrapIcon($icon,&$row)
+ *              SECTION: Temporary DB mounts
+ *  415:     function initializeTemporaryDBmount()
+ *  449:     function settingTemporaryMountPoint($pageId)
  *
- *
- *  131: class SC_alt_db_navframe
- *  147:     function init()
- *  235:     function main()
- *  263:     function printContent()
- *
- * TOTAL FUNCTIONS: 5
+ * TOTAL FUNCTIONS: 9
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
 
 
-$BACK_PATH='';
+$BACK_PATH = '';
 require('init.php');
 require('template.php');
-require_once(PATH_t3lib.'class.t3lib_browsetree.php');
-
-
-
-/**
- * Extension class for the t3lib_browsetree class, specially made for browsing pages in the Web module
- *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
- * @package TYPO3
- * @subpackage core
- * @see class t3lib_browseTree
- */
-class localPageTree extends t3lib_browseTree {
-
-       var $ext_showPageId;
-       var $ext_IconMode;
-
-       /**
-        * Calls init functions
-        *
-        * @return      void
-        */
-       function localPageTree() {
-               $this->init();
-       }
-
-       /**
-        * Wrapping icon in browse tree
-        *
-        * @param       string          Icon IMG code
-        * @param       array           Data row for element.
-        * @return      string          Page icon
-        */
-       function wrapIcon($icon,&$row)  {
-                       // If the record is locked, present a warning sign.
-               if ($lockInfo=t3lib_BEfunc::isRecordLocked('pages',$row['uid']))        {
-                       $aOnClick = 'alert('.$GLOBALS['LANG']->JScharCode($lockInfo['msg']).');return false;';
-                       $lockIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
-                               '<img'.t3lib_iconWorks::skinImg('','gfx/recordlock_warning3.gif','width="17" height="12"').' title="'.htmlspecialchars($lockInfo['msg']).'" alt="" />'.
-                               '</a>';
-               } else $lockIcon = '';
-
-                       // Add title attribute to input icon tag
-               $thePageIcon = $this->addTagAttributes($icon, $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"');
-
-                       // Wrap icon in click-menu link.
-               if (!$this->ext_IconMode)       {
-                       $thePageIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($thePageIcon,'pages',$row['uid'],0);
-               } elseif (!strcmp($this->ext_IconMode,'titlelink'))     {
-                       $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->treeName.'\');';
-                       $thePageIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$thePageIcon.'</a>';
-               }
-
-                       // Add Page ID:
-               if ($this->ext_showPageId)      {
-                       $pageIdStr = '['.$row['uid'].']&nbsp;';
-               } else {
-                       $pageIdStr = '';
-               }
-
-               return $thePageIcon.$lockIcon.$pageIdStr;
-       }
-}
-
-
-
-
-
-
-
-
-
-
+require_once('class.webpagetree.php');
 
 
 /**
  * Main script class for the page tree navigation frame
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  */
@@ -144,10 +70,18 @@ class SC_alt_db_navframe {
                // Internal:
        var $content;
        var $pagetree;
+
+       /**
+        * document template object
+        *
+        * @var template
+        */
        var $doc;
        var $active_tempMountPoint = 0;         // Temporary mount point (record), if any
+       var $backPath;
 
                // Internal, static: GPvar:
+       var $ajax;                                                      // Is set, if an AJAX call should be handled.
        var $currentSubScript;
        var $cMR;
        var $setTempDBmount;                    // If not '' (blank) then it will clear (0) or set (>0) Temporary DB mount.
@@ -160,15 +94,22 @@ class SC_alt_db_navframe {
        function init() {
                global $BE_USER,$BACK_PATH;
 
+                       // Setting backPath
+               $this->backPath = $BACK_PATH;
+
                        // Setting GPvars:
-               $this->currentSubScript = t3lib_div::_GP('currentSubScript');
+               $this->ajax = t3lib_div::_GP('ajax');
                $this->cMR = t3lib_div::_GP('cMR');
+               $this->currentSubScript = t3lib_div::_GP('currentSubScript');
                $this->setTempDBmount = t3lib_div::_GP('setTempDBmount');
 
                        // Create page tree object:
-               $this->pagetree = t3lib_div::makeInstance('localPageTree');
+               $this->pagetree = t3lib_div::makeInstance('webPageTree');
                $this->pagetree->ext_IconMode = $BE_USER->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu');
                $this->pagetree->ext_showPageId = $BE_USER->getTSConfigVal('options.pageTree.showPageIdWithTitle');
+               $this->pagetree->ext_showNavTitle = $BE_USER->getTSConfigVal('options.pageTree.showNavTitle');
+               $this->pagetree->ext_separateNotinmenuPages = $BE_USER->getTSConfigVal('options.pageTree.separateNotinmenuPages');
+               $this->pagetree->ext_alphasortNotinmenuPages = $BE_USER->getTSConfigVal('options.pageTree.alphasortNotinmenuPages');
                $this->pagetree->thisScript = 'alt_db_navframe.php';
                $this->pagetree->addField('alias');
                $this->pagetree->addField('shortcut');
@@ -176,77 +117,63 @@ class SC_alt_db_navframe {
                $this->pagetree->addField('mount_pid');
                $this->pagetree->addField('mount_pid_ol');
                $this->pagetree->addField('nav_hide');
+               $this->pagetree->addField('nav_title');
                $this->pagetree->addField('url');
 
-#              $this->settingTemporaryMountPoint(11);
                        // Temporary DB mounts:
                $this->initializeTemporaryDBmount();
 
-                       // 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;
+                       // 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');
 
-                       // Setting JavaScript for menu.
-               $this->doc->JScode=$this->doc->wrapScriptTags(
-       ($this->currentSubScript?'top.currentSubScript=unescape("'.rawurlencode($this->currentSubScript).'");':'').'
+                               // If highlighting is active, define the CSS class for the active item depending on the workspace
+                       if ($this->doHighlight) {
+                               if ($BE_USER->workspace === 0) $hlClass = 'active';
+                               else $hlClass = 'active active-ws wsver'.$BE_USER->workspace; 
+                       }
 
-               // Function, loading the list frame from navigation tree:
-       function jumpTo(id,linkObj,highLightID) {       //
-               var theUrl = top.TS.PATH_typo3+top.currentSubScript+"?id="+id;
+                               // Create template object:
+                       $this->doc = t3lib_div::makeInstance('template');
+                       $this->doc->backPath = $BACK_PATH;
+                       $this->doc->docType = 'xhtml_trans';
 
-               if (top.condensedMode)  {
-                       top.content.document.location=theUrl;
-               } else {
-                       parent.list_frame.document.location=theUrl;
-               }
+                               // Adding javascript code for AJAX (prototype), drag&drop and the pagetree
+                       $this->doc->loadJavascriptLib('contrib/prototype/prototype.js');
+                       $this->doc->loadJavascriptLib('tree.js');
 
-               '.($this->doHighlight?'hilight_row("web",highLightID);':'').'
+                       $this->doc->JScode .= $this->doc->wrapScriptTags(
+                       ($this->currentSubScript?'top.currentSubScript=unescape("'.rawurlencode($this->currentSubScript).'");':'').'
+                       // setting prefs for pagetree and drag & drop
+                       Tree.thisScript    = "'.$this->pagetree->thisScript.'";
+                       '.($this->doHighlight ? 'Tree.highlightClass = "'.$hlClass.'";' : '').'
 
-               '.(!$GLOBALS['CLIENT']['FORMSTYLE'] ? '' : 'if (linkObj) {linkObj.blur();}').'
-               return false;
-       }
+                       DragDrop.changeURL = "'.$this->backPath.'alt_clickmenu.php";
+                       DragDrop.backPath  = "'.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
+                       DragDrop.table     = "pages";
 
-               // Call this function, refresh_nav(), from another script in the backend if you want to refresh the navigation frame (eg. after having changed a page title or moved pages etc.)
-               // See t3lib_BEfunc::getSetUpdateSignal()
-       function refresh_nav()  {       //
-               window.setTimeout("_refresh_nav();",0);
-       }
-       function _refresh_nav() {       //
-               document.location="'.$this->pagetree->thisScript.'?unique='.time().'";
-       }
+                       // 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;
 
-               // Highlighting rows in the page tree:
-       function hilight_row(frameSetModule,highLightID) {      //
+                               if (top.condensedMode) top.content.location.href = theUrl;
+                               else                   parent.list_frame.location.href=theUrl;
 
-                       // Remove old:
-               theObj = document.getElementById(top.fsMod.navFrameHighlightedID[frameSetModule]);
-               if (theObj)     {
-                       theObj.style.backgroundColor="";
-               }
+                               '.($this->doHighlight ? 'Tree.highlightActiveItem("web", highlightID + "_" + bank);' : '').'
+                               '.(!$GLOBALS['CLIENT']['FORMSTYLE'] ? '' : 'if (linkObj) linkObj.blur(); ').'
+                               return false;
+                       }
+                       '.($this->cMR?"jumpTo(top.fsMod.recentIds['web'],'');":'').'
+                       ');
 
-                       // Set new:
-               top.fsMod.navFrameHighlightedID[frameSetModule] = highLightID;
-               theObj = document.getElementById(highLightID);
-               if (theObj)     {
-                       theObj.style.backgroundColor="'.t3lib_div::modifyHTMLColorAll($this->doc->bgColor,-20).'";
+                               // Click menu code is added:
+                       $this->doc->getContextMenuCode();
+                       $this->doc->bodyTagId = 'bodyTag';
                }
        }
 
-       '.($this->cMR?"jumpTo(top.fsMod.recentIds['web'],'');":'').';
-               ');
-
-                       // Click menu code is added:
-               $CMparts=$this->doc->getContextMenuCode();
-               $this->doc->bodyTagAdditions = $CMparts[1];
-               $this->doc->JScode.= $CMparts[0];
-               $this->doc->postCode.= $CMparts[2];
-       }
 
        /**
         * Main function, rendering the browsable page tree
@@ -259,9 +186,45 @@ class SC_alt_db_navframe {
                        // Produce browse-tree:
                $tree = $this->pagetree->getBrowsableTree();
 
+                       // Output only the tree if this is an AJAX call:
+               if ($this->ajax) {
+                       $this->content = $LANG->csConvObj->utf8_encode($tree, $LANG->charSet);
+                       return;
+               }
+
                        // Start page:
-               $this->content = '';
-               $this->content.= $this->doc->startPage('Page tree');
+               $this->content = $this->doc->startPage('TYPO3 Page Tree');
+               
+                       // Outputting workspace info
+               if ($GLOBALS['BE_USER']->workspace!==0 || $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.onlineWorkspaceInfo'))  {
+                       switch($GLOBALS['BE_USER']->workspace)  {
+                               case 0:
+                                       $wsTitle = '&nbsp;'.$this->doc->icons(2).'['.$LANG->sL('LLL:EXT:lang/locallang_misc.xml:shortcut_onlineWS',1).']';
+                               break;
+                               case -1:
+                                       $wsTitle = '['.$LANG->sL('LLL:EXT:lang/locallang_misc.xml:shortcut_offlineWS',1).']';
+                               break;
+                               default:
+                                       $wsTitle = '['.$GLOBALS['BE_USER']->workspace.'] '.htmlspecialchars($GLOBALS['BE_USER']->workspaceRec['title']);
+                               break;
+                       }
+
+                       $this->content.= '
+                               <div class="bgColor4 workspace-info">'.
+                                       '<a href="'.htmlspecialchars('mod/user/ws/index.php').'" target="content">'.
+                                       '<img'.t3lib_iconWorks::skinImg('','gfx/i/sys_workspace.png','width="18" height="16"').' align="top" alt="" />'.
+                                       '</a>'.$wsTitle.'
+                               </div>
+                       ';
+               }
+
+               if (!$GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.hideFilter'))        {
+                       $this->content.= '
+                                       <div class="bgColor4">
+                                               Filter: <input type="text" value="" name="_livesearch" id="_livesearch" onkeyup="filter(this.value);"/>
+                                       </div><br>
+                       ';
+               }
 
                        // Outputting Temporary DB mount notice:
                if ($this->active_tempMountPoint)       {
@@ -280,12 +243,10 @@ class SC_alt_db_navframe {
                $this->content.= $tree;
 
                        // Outputting refresh-link
-               $refreshUrl = t3lib_div::getIndpEnv('REQUEST_URI');
                $this->content.= '
                        <p class="c-refresh">
-                               <a href="'.htmlspecialchars($refreshUrl).'">'.
+                               <a href="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'">'.
                                '<img'.t3lib_iconWorks::skinImg('','gfx/refresh_n.gif','width="14" height="14"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.refresh',1).'" alt="" />'.
-                               '</a><a href="'.htmlspecialchars($refreshUrl).'">'.
                                $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.refresh',1).'</a>
                        </p>
                        <br />';
@@ -293,10 +254,11 @@ class SC_alt_db_navframe {
                        // CSH icon:
                $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'pagetree', $GLOBALS['BACK_PATH']);
 
-                       // Adding highlight - JavaScript
-               if ($this->doHighlight) $this->content .=$this->doc->wrapScriptTags('
-                       hilight_row("",top.fsMod.navFrameHighlightedID["web"]);
-               ');
+                       // Adding javascript for drag & drop activation and highlighting
+               $this->content .=$this->doc->wrapScriptTags('
+                       '.($this->doHighlight ? 'Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);' : '').'
+                       '.(!$this->doc->isCMlayers() ? 'Tree.activateDragDrop = false;' : 'Tree.registerDragDropHandlers();')
+               );
        }
 
        /**
@@ -305,7 +267,15 @@ class SC_alt_db_navframe {
         * @return      void
         */
        function printContent() {
-               $this->content.= $this->doc->endPage();
+                       // If we handle an AJAX call, send headers:
+               if ($this->ajax) {
+                       header('X-JSON: ('.($this->pagetree->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);
+               }
                echo $this->content;
        }
 
@@ -313,13 +283,6 @@ class SC_alt_db_navframe {
 
 
 
-
-
-
-
-
-
-
        /**********************************
         *
         * Temporary DB mounts
@@ -328,6 +291,8 @@ class SC_alt_db_navframe {
 
        /**
         * Getting temporary DB mount
+        *
+        * @return      void
         */
        function initializeTemporaryDBmount(){
                global $BE_USER;
@@ -347,13 +312,22 @@ class SC_alt_db_navframe {
 
                        // If mount point ID existed and is within users real mount points, then set it temporarily:
                if ($temporaryMountPoint > 0 && $BE_USER->isInWebMount($temporaryMountPoint))   {
-                       $this->pagetree->MOUNTS = array($temporaryMountPoint);
-                       $this->active_tempMountPoint = t3lib_BEfunc::readPageAccess($temporaryMountPoint, $BE_USER->getPagePermsClause(1));
+                       if ($this->active_tempMountPoint = t3lib_BEfunc::readPageAccess($temporaryMountPoint, $BE_USER->getPagePermsClause(1))) {
+                               $this->pagetree->MOUNTS = array($temporaryMountPoint);
+                       }
+                       else {
+                               // Clear temporary mount point as we have no access to it any longer
+                               $this->settingTemporaryMountPoint(0);
+                       }
                }
        }
 
+
        /**
         * Setting temporary page id as DB mount
+        *
+        * @param       integer         The page id to set as DB mount
+        * @return      void
         */
        function settingTemporaryMountPoint($pageId)    {
                global $BE_USER;
@@ -363,6 +337,7 @@ class SC_alt_db_navframe {
        }
 }
 
+
 // Include extension?
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_db_navframe.php'])      {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_db_navframe.php']);
@@ -372,13 +347,6 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_d
 
 
 
-
-
-
-
-
-
-
 // Make instance:
 $SOBE = t3lib_div::makeInstance('SC_alt_db_navframe');
 $SOBE->init();