Cleanup: Updated copyright notices
[Packages/TYPO3.CMS.git] / typo3 / template.php
index 2921ce4..4aa9c2d 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 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
@@ -173,6 +173,7 @@ class template {
        var $form='';                                   // This can be set to the HTML-code for a formtag. Useful when you need a form to span the whole page; Inserted exactly after the body-tag.
        var $JScodeLibArray = array();          // Similar to $JScode (see below) but used as an associative array to prevent double inclusion of JS code. This is used to include certain external Javascript libraries before the inline JS code. <script>-Tags are not wrapped around automatically
        var $JScode='';                                 // Additional header code (eg. a JavaScript section) could be accommulated in this var. It will be directly outputted in the header.
+       var $extJsCode = '';                            // Additional header code for ExtJS. It will be included in document header and inserted in a Ext.onReady(function()
        var $JScodeArray = array();             // Similar to $JScode but for use as array with associative keys to prevent double inclusion of JS code. a <script> tag is automatically wrapped around.
        var $postCode='';                               // Additional 'page-end' code could be accommulated in this var. It will be outputted at the end of page before </body> and some other internal page-end code.
        var $docType = '';                              // Doc-type used in the header. Default is xhtml_trans. You can also set it to 'html_3', 'xhtml_strict' or 'xhtml_frames'.
@@ -683,13 +684,15 @@ class template {
        '.$this->docStyle().'
        '.implode("\n", $this->JScodeLibArray).'
        '.$this->JScode.'
-       '.$this->wrapScriptTags(implode("\n", $this->JScodeArray)).'
+       '.$this->wrapScriptTags(implode("\n", $this->JScodeArray)).
+       ($this->extJsCode ? $this->wrapScriptTags('Ext.onReady(function() {' . chr(10) . $this->extJsCode . chr(10) . '});') : '') .
+       '
        <!--###POSTJSMARKER###-->
 </head>
 ';
-               $this->JScodeLibArray=array();
-               $this->JScode='';
-               $this->JScodeArray=array();
+               $this->JScodeLibArray = array();
+               $this->JScode = $this->extJsCode = '';
+               $this->JScodeArray = array();
 
                if ($this->docType=='xhtml_frames')     {
                        return $str;
@@ -1140,53 +1143,55 @@ $str.=$this->docBodyTagBegin().
 
                // These vars defines the layout for the table produced by the table() function.
                // You can override these values from outside if you like.
-       var $tableLayout = Array (
-               'defRow' => Array (
-                       'defCol' => Array('<td valign="top">','</td>')
+       var $tableLayout = array(
+               'defRow' => array(
+                       'defCol' => array('<td valign="top">','</td>')
                )
        );
        var $table_TR = '<tr>';
        var $table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" id="typo3-tmpltable">';
 
        /**
-        * Returns a table based on the input $arr
+        * Returns a table based on the input $data
         *
         * @param       array           Multidim array with first levels = rows, second levels = cells
         * @param       array           If set, then this provides an alternative layout array instead of $this->tableLayout
         * @return      string          The HTML table.
         * @internal
         */
-       function table($arr, $layout='')        {
-               if (is_array($arr))     {
-                       $tableLayout = (is_array($layout)) ? $layout : $this->tableLayout;
-
-                       reset($arr);
-                       $code='';
-                       $rc=0;
-                       while(list(,$val)=each($arr))   {
-                               if ($rc % 2) {
+       function table($data, $layout = '') {
+               $result = '';
+               if (is_array($data)) {
+                       $tableLayout = (is_array($layout) ? $layout : $this->tableLayout);
+
+                       $rowCount = 0;
+                       foreach ($data as $tableRow) {
+                               if ($rowCount % 2) {
                                        $layout = is_array($tableLayout['defRowOdd']) ? $tableLayout['defRowOdd'] : $tableLayout['defRow'];
                                } else {
                                        $layout = is_array($tableLayout['defRowEven']) ? $tableLayout['defRowEven'] : $tableLayout['defRow'];
                                }
-                               $layoutRow = is_array($tableLayout[$rc]) ? $tableLayout[$rc] : $layout;
-                               $code_td='';
-                               if (is_array($val))     {
-                                       $cc=0;
-                                       while(list(,$content)=each($val))       {
-                                               $wrap= is_array($layoutRow[$cc]) ? $layoutRow[$cc] : (is_array($layoutRow['defCol']) ? $layoutRow['defCol'] : (is_array($layout[$cc]) ? $layout[$cc] : $layout['defCol']));
-                                               $code_td.=$wrap[0].$content.$wrap[1];
-                                               $cc++;
+                               $rowLayout = is_array($tableLayout[$rowCount]) ? $tableLayout[$rowCount] : $layout;
+                               $rowResult = '';
+                               if (is_array($tableRow)) {
+                                       $cellCount = 0;
+                                       foreach ($tableRow as $tableCell) {
+                                               $cellWrap = (is_array($layout[$cellCount])    ? $layout[$cellCount]    : $layout['defCol']);
+                                               $cellWrap = (is_array($rowLayout['defCol'])   ? $rowLayout['defCol']   : $cellWrap);
+                                               $cellWrap = (is_array($rowLayout[$cellCount]) ? $rowLayout[$cellCount] : $cellWrap);
+                                               $rowResult .= $cellWrap[0] . $tableCell . $cellWrap[1];
+                                               $cellCount++;
                                        }
                                }
-                               $trWrap = is_array($layoutRow['tr']) ? $layoutRow['tr'] : (is_array($layout['tr']) ? $layout['tr'] : array($this->table_TR, '</tr>'));
-                               $code.=$trWrap[0].$code_td.$trWrap[1];
-                               $rc++;
+                               $rowWrap = (is_array($layout['tr'])    ? $layout['tr']    : array($this->table_TR, '</tr>'));
+                               $rowWrap = (is_array($rowLayout['tr']) ? $rowLayout['tr'] : $rowWrap);
+                               $result .= $rowWrap[0] . $rowResult . $rowWrap[1];
+                               $rowCount++;
                        }
                        $tableWrap = is_array($tableLayout['table']) ? $tableLayout['table'] : array($this->table_TABLE, '</table>');
-                       $code=$tableWrap[0].$code.$tableWrap[1];
+                       $result = $tableWrap[0] . $result . $tableWrap[1];
                }
-               return $code;
+               return $result;
        }
 
        /**
@@ -1454,6 +1459,9 @@ $str.=$this->docBodyTagBegin().
         * @return      string          JavaScript section for the HTML header.
         */
        function getDynTabMenu($menuItems,$identString,$toggle=0,$foldout=FALSE,$newRowCharLimit=50,$noWrap=1,$fullWidth=FALSE,$defaultTabIndex=1,$dividers2tabs=2)     {
+               // load the static code, if not already done with the function below
+               $this->loadJavascriptLib('js/tabmenu.js');
+
                $content = '';
 
                if (is_array($menuItems))       {
@@ -1485,37 +1493,37 @@ $str.=$this->docBodyTagBegin().
                                        $onclick = 'this.blur(); DTM_activate("'.$id.'","'.$index.'", '.($toggle<0?1:0).'); return false;';
                                }
 
-                               $isNotEmpty = strcmp(trim($def['content']),'');
+                               $isEmpty = !(strcmp(trim($def['content']),'') || strcmp(trim($def['icon']),''));
 
                                // "Removes" empty tabs
-                               if (!$isNotEmpty && $dividers2tabs == 1) {
+                               if ($isEmpty && $dividers2tabs == 1) {
                                        continue;
                                }
 
                                $mouseOverOut = ' onmouseover="DTM_mouseOver(this);" onmouseout="DTM_mouseOut(this);"';
-                               $requiredIcon = '<img name="'.$id.'-'.$index.'-REQ" src="clear.gif" width="10" height="10" hspace="4" alt="" />';
+                               $requiredIcon = '<img name="' . $id . '-' . $index . '-REQ" src="' . $GLOBALS['BACK_PATH'] . 'gfx/clear.gif" width="10" height="10" hspace="4" alt="" />';
 
                                if (!$foldout)  {
                                                // Create TAB cell:
                                        $options[$tabRows][] = '
-                                                       <td class="'.($isNotEmpty ? 'tab' : 'disabled').'" id="'.$id.'-'.$index.'-MENU"'.$noWrap.$mouseOverOut.'>'.
-                                                       ($isNotEmpty ? '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>' : '').
+                                                       <td class="'.($isEmpty ? 'disabled' : 'tab').'" id="'.$id.'-'.$index.'-MENU"'.$noWrap.$mouseOverOut.'>'.
+                                                       ($isEmpty ? '' : '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>').
                                                        $def['icon'].
                                                        ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;').
                                                        $requiredIcon.
                                                        $this->icons($def['stateIcon'],'margin-left: 10px;').
-                                                       ($isNotEmpty ? '</a>' :'').
+                                                       ($isEmpty ? '' : '</a>').
                                                        '</td>';
                                        $titleLenCount+= strlen($def['label']);
                                } else {
                                                // Create DIV layer for content:
                                        $divs[] = '
-                                               <div class="'.($isNotEmpty ? 'tab' : 'disabled').'" id="'.$id.'-'.$index.'-MENU"'.$mouseOverOut.'>'.
-                                                       ($isNotEmpty ? '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>' : '').
+                                               <div class="'.($isEmpty ? 'disabled' : 'tab').'" id="'.$id.'-'.$index.'-MENU"'.$mouseOverOut.'>'.
+                                                       ($isEmpty ? '' : '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>').
                                                        $def['icon'].
                                                        ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;').
                                                        $requiredIcon.
-                                                       ($isNotEmpty ? '</a>' : '').
+                                                       ($isEmpty ? '' : '</a>').
                                                        '</div>';
                                }
 
@@ -1530,7 +1538,7 @@ $str.=$this->docBodyTagBegin().
                                                DTM_array["'.$id.'"]['.$c.'] = "'.$id.'-'.$index.'";
                                ';
                                        // If not empty and we have the toggle option on, check if the tab needs to be expanded
-                               if ($toggle == 1 && $isNotEmpty) {
+                               if ($toggle == 1 && !$isEmpty) {
                                        $JSinit[] = '
                                                if (top.DTM_currentTabs["'.$id.'-'.$index.'"]) { DTM_toggle("'.$id.'","'.$index.'",1); }
                                        ';
@@ -1593,93 +1601,16 @@ $str.=$this->docBodyTagBegin().
 
        /**
         * Returns dynamic tab menu header JS code.
+        * This is now incorporated automatically when the function template::getDynTabMenu is called
+        * (as long as it is called before $this->startPage())
+        * The return value is not needed anymore
         *
-        * @return      string          JavaScript section for the HTML header.
+        * @return      string          JavaScript section for the HTML header. (return value is deprecated since TYPO3 4.3, will be removed in TYPO3 4.5)
         */
        function getDynTabMenuJScode()  {
-               return '
-                       <script type="text/javascript">
-                       /*<![CDATA[*/
-                               var DTM_array = new Array();
-                               var DTM_origClass = new String();
-
-                                       // if tabs are used in a popup window the array might not exists
-                               if(!top.DTM_currentTabs) {
-                                       top.DTM_currentTabs = new Array();
-                               }
-
-                               function DTM_activate(idBase,index,doToogle)    {       //
-                                               // Hiding all:
-                                       if (DTM_array[idBase])  {
-                                               for(cnt = 0; cnt < DTM_array[idBase].length ; cnt++)    {
-                                                       if (DTM_array[idBase][cnt] != idBase+"-"+index) {
-                                                               document.getElementById(DTM_array[idBase][cnt]+"-DIV").style.display = "none";
-                                                               // Only Overriding when Tab not disabled
-                                                               if (document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").nodeValue != "disabled") {
-                                                                       document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
-                                                               }
-                                                       }
-                                               }
-                                       }
-
-                                               // Showing one:
-                                       if (document.getElementById(idBase+"-"+index+"-DIV"))   {
-                                               if (doToogle && document.getElementById(idBase+"-"+index+"-DIV").style.display == "block")      {
-                                                       document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
-                                                       if(DTM_origClass=="") {
-                                                               document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
-                                                       } else {
-                                                               DTM_origClass = "tab";
-                                                       }
-                                                       top.DTM_currentTabs[idBase] = -1;
-                                               } else {
-                                                       document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
-                                                       if(DTM_origClass=="") {
-                                                               document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tabact";
-                                                       } else {
-                                                               DTM_origClass = "tabact";
-                                                       }
-                                                       top.DTM_currentTabs[idBase] = index;
-                                               }
-                                       }
-                               }
-                               function DTM_toggle(idBase,index,isInit)        {       //
-                                               // Showing one:
-                                       if (document.getElementById(idBase+"-"+index+"-DIV"))   {
-                                               if (document.getElementById(idBase+"-"+index+"-DIV").style.display == "block")  {
-                                                       document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
-                                                       if(isInit) {
-                                                               document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
-                                                       } else {
-                                                               DTM_origClass = "tab";
-                                                       }
-                                                       top.DTM_currentTabs[idBase+"-"+index] = 0;
-                                               } else {
-                                                       document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
-                                                       if(isInit) {
-                                                               document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tabact";
-                                                       } else {
-                                                               DTM_origClass = "tabact";
-                                                       }
-                                                       top.DTM_currentTabs[idBase+"-"+index] = 1;
-                                               }
-                                       }
-                               }
-
-                               function DTM_mouseOver(obj) {   //
-                                               DTM_origClass = obj.attributes.getNamedItem(\'class\').nodeValue;
-                                               obj.attributes.getNamedItem(\'class\').nodeValue += "_over";
-                               }
-
-                               function DTM_mouseOut(obj) {    //
-                                               obj.attributes.getNamedItem(\'class\').nodeValue = DTM_origClass;
-                                               DTM_origClass = "";
-                               }
-
-
-                       /*]]>*/
-                       </script>
-               ';
+               $this->loadJavascriptLib('js/tabmenu.js');
+               // return value deprecated since TYPO3 4.3
+               return '';
        }
 
        /**