Fixed bug #7896: Hide the page browser if not enough entries are available (Thanks...
[Packages/TYPO3.CMS.git] / typo3 / alt_palette.php
old mode 100755 (executable)
new mode 100644 (file)
index 137eabd..60a9115
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@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
@@ -31,7 +31,7 @@
  * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
  * XHTML compliant
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
@@ -60,9 +60,6 @@
 
 require('init.php');
 require('template.php');
-require_once(PATH_t3lib.'class.t3lib_tceforms.php');
-require_once(PATH_t3lib.'class.t3lib_transferdata.php');
-require_once(PATH_t3lib.'class.t3lib_loaddbgroup.php');
 $LANG->includeLLFile('EXT:lang/locallang_alt_doc.xml');
 
 
@@ -74,9 +71,10 @@ $LANG->includeLLFile('EXT:lang/locallang_alt_doc.xml');
  * Class for rendering the form fields.
  * Extending the TCEforms class
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
+ * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.5
  */
 class formRender extends t3lib_TCEforms {
 
@@ -147,7 +145,7 @@ class formRender extends t3lib_TCEforms {
  * Child class for alternative rendering of form fields (when the secondary fields are shown in a little window rather than the top bar).
  * (Used if GET var "backRef" is not set, presuming a window is opened instead.)
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  */
@@ -216,7 +214,7 @@ class formRender_vert extends t3lib_TCEforms {
  * Script Class for rendering the palette form for TCEforms in some other frame (in top frame, horizontally)
  * It can also be called in a pop-up window in which case a vertically oriented set of form fields are rendered instead.
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  */
@@ -247,15 +245,19 @@ class SC_alt_palette {
        function init() {
 
                        // Setting GPvars, etc.
-               $this->formName = t3lib_div::_GP('formName');
-               $this->GPbackref = t3lib_div::_GP('backRef');
+               $this->formName = $this->sanitizeHtmlName(t3lib_div::_GP('formName'));
+               $this->GPbackref = $this->sanitizeHtmlName(t3lib_div::_GP('backRef'));
                $this->inData = t3lib_div::_GP('inData');
-               $this->prependFormFieldNames = t3lib_div::_GP('prependFormFieldNames');
+                       // safeguards the input with whitelisting
+               if (!preg_match('/^[a-zA-Z0-9\-_\:]+$/', $this->inData)) {
+                       $this->inData = '';
+               }
+               $this->prependFormFieldNames =
+                       $this->sanitizeHtmlName(t3lib_div::_GP('prependFormFieldNames'));
                $this->rec = t3lib_div::_GP('rec');
 
                        // Making references:
                $this->backRef = $this->GPbackref ? $this->GPbackref : 'window.opener';
-#              $this->backRef = 'top.content.list_frame.view_frame';
 
                $this->formRef = $this->backRef.'.document.'.$this->formName;
 
@@ -264,7 +266,6 @@ class SC_alt_palette {
                $this->doc->bodyTagMargins['x']=0;
                $this->doc->bodyTagMargins['y']=0;
                $this->doc->form='<form action="#" method="post" name="'.htmlspecialchars($this->formName).'" onsubmit="return false;">';
-               $this->doc->docType = 'xhtml_trans';
                $this->doc->backPath = '';
 
                        // In case the palette is opened in a SEPARATE window (as the case is with frontend editing) then another body-tag id should be used (so we don't get the background image for the palette shown!)
@@ -286,7 +287,7 @@ class SC_alt_palette {
                                } else closePal();
                        }
                        function closePal()     {       //
-                               '.($this->GPbackref?'document.location="alt_topmenu_dummy.php";':'close();').'
+                               '.($this->GPbackref?'window.location.href="alt_topmenu_dummy.php";':'close();').'
                        }
                        timeout_func();
                        onBlur="alert();";
@@ -294,6 +295,24 @@ class SC_alt_palette {
        }
 
        /**
+        * Sanitizes HTML names, IDs, frame names etc.
+        *
+        * @param string $input the string to sanitize
+        *
+        * @return string the unchanged $input if $input is considered to be harmless,
+        *                an empty string otherwise
+        */
+       protected function sanitizeHtmlName($input) {
+               $result = $input;
+
+               if (!preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $result)) {
+                       $result = '';
+               }
+
+               return $result;
+       }
+
+       /**
         * Main function, rendering the palette form
         *
         * @return      void
@@ -301,7 +320,6 @@ class SC_alt_palette {
        function main() {
 
                $this->content='';
-               $this->content.=$this->doc->startPage('TYPO3 Edit Palette');
 
                $inData = explode(':',$this->inData);
 
@@ -331,6 +349,11 @@ class SC_alt_palette {
                                // Add all the content, including JavaScript as needed.
                        $this->content.=$tceforms->printNeededJSFunctions_top().$formContent.$tceforms->printNeededJSFunctions();
                }
+
+               // Assemble the page:
+               $tempContent = $this->content;
+               $this->content = $this->doc->startPage('TYPO3 Edit Palette');
+               $this->content.= $tempContent;
        }
 
        /**
@@ -339,29 +362,23 @@ class SC_alt_palette {
         * @return      void
         */
        function printContent() {
-               echo $this->content.$this->doc->endPage();
+               $this->content.= $this->doc->endPage();
+               $this->content = $this->doc->insertStylesAndJS($this->content);
+               echo $this->content;
        }
 }
 
-// Include extension?
+
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_palette.php'])  {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_palette.php']);
 }
 
 
 
-
-
-
-
-
-
-
-
-
 // Make instance:
 $SOBE = t3lib_div::makeInstance('SC_alt_palette');
 $SOBE->init();
 $SOBE->main();
 $SOBE->printContent();
+
 ?>
\ No newline at end of file