Changed t3lib_div::get_tag_attributes/split_tag_attributes so that they always return...
authorMartin Kutschker <martin.t.kutschker@blackbox.net>
Sat, 2 Feb 2008 14:02:49 +0000 (14:02 +0000)
committerMartin Kutschker <martin.t.kutschker@blackbox.net>
Sat, 2 Feb 2008 14:02:49 +0000 (14:02 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@3021 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
typo3/sysext/cms/tslib/class.tslib_content.php

index b76bf7b..23bf12c 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,7 @@
 
        * !!! #7350: Use PHP5 features in class.t3lib_div.php (static and type hinting)
        * #7351: Introduce $ACCESS_TIME/$SIM_ACCESS_TIME to improve Mysql query cache usage
+       * Changed t3lib_div::get_tag_attributes/split_tag_attributes so that they always return an array
 
 2008-02-02  Kasper Skaarhoj <kasper2008@typo3.com>
 
index c4bb3cf..5157fd7 100755 (executable)
@@ -1784,7 +1784,7 @@ class t3lib_div {
        /**
         * Returns an array with all attributes of the input HTML tag as key/value pairs. Attributes are only lowercase a-z
         * $tag is either a whole tag (eg '<TAG OPTION ATTRIB=VALUE>') or the parameterlist (ex ' OPTION ATTRIB=VALUE>')
-        * If a attribute is empty (I call it 'an option'), then the value for the key is empty. You can check if it existed with isset()
+        * If an attribute is empty, then the value for the key is empty. You can check if it existed with isset()
         * Usage: 8
         *
         * @param       string          HTML-tag string (or attributes only)
@@ -1793,29 +1793,27 @@ class t3lib_div {
        public static function get_tag_attributes($tag) {
                $components = t3lib_div::split_tag_attributes($tag);
                $name = '';      // attribute name is stored here
-               $valuemode = '';
-               if (is_array($components))      {
-                       while (list($key,$val) = each ($components))    {
-                               if ($val != '=')        {       // Only if $name is set (if there is an attribute, that waits for a value), that valuemode is enabled. This ensures that the attribute is assigned it's value
-                                       if ($valuemode) {
-                                               if ($name)      {
-                                                       $attributes[$name] = $val;
-                                                       $name = '';
-                                               }
-                                       } else {
-                                               if ($key = strtolower(ereg_replace('[^a-zA-Z0-9]','',$val)))    {
-                                                       $attributes[$key] = '';
-                                                       $name = $key;
-                                               }
+               $valuemode = false;
+               $attributes = array();
+               foreach ($components as $key => $val)   {
+                       if ($val != '=')        {       // Only if $name is set (if there is an attribute, that waits for a value), that valuemode is enabled. This ensures that the attribute is assigned it's value
+                               if ($valuemode) {
+                                       if ($name)      {
+                                               $attributes[$name] = $val;
+                                               $name = '';
                                        }
-                                       $valuemode = '';
                                } else {
-                                       $valuemode = 'on';
+                                       if ($key = strtolower(ereg_replace('[^a-zA-Z0-9]','',$val)))    {
+                                               $attributes[$key] = '';
+                                               $name = $key;
+                                       }
                                }
+                               $valuemode = false;
+                       } else {
+                               $valuemode = true;
                        }
-                       if (is_array($attributes))      reset($attributes);
-                       return $attributes;
                }
+               return $attributes;
        }
 
        /**
@@ -1832,6 +1830,7 @@ class t3lib_div {
                        // Removes any > in the end of the string
                $tag_tmp = trim(eregi_replace ('>$','',$tag_tmp));
 
+               $value = array();
                while (strcmp($tag_tmp,''))     {       // Compared with empty string instead , 030102
                        $firstChar=substr($tag_tmp,0,1);
                        if (!strcmp($firstChar,'"') || !strcmp($firstChar,"'")) {
@@ -1848,7 +1847,7 @@ class t3lib_div {
                                $tag_tmp = trim(substr($tag_tmp,strlen($reg[0]),1).$reg[1]);
                        }
                }
-               if (is_array($value))   reset($value);
+               reset($value);
                return $value;
        }
 
@@ -2318,17 +2317,16 @@ class t3lib_div {
        }
 
        /**
-        * Extract the encoding scheme as found in the first line of an XML document (typically)
+        * Extracts the attributes (typically encoding and version) of an XML prologue (header).
         * Usage: 1
         *
         * @param       string          XML data
-        * @return      string          Encoding scheme (lowercase), if found.
+        * @return      array           Attributes of the xml prologue (header)
         */
        public static function xmlGetHeaderAttribs($xmlData)    {
-               $xmlHeader = substr(trim($xmlData),0,200);
-               $reg=array();
-               if (eregi('^<\?xml([^>]*)\?\>',$xmlHeader,$reg))        {
-                       return t3lib_div::get_tag_attributes($reg[1]);
+               $match = array();
+               if (preg_match('/^\s*<\?xml([^>]*)\?\>/', $xmlData, $match))    {
+                       return t3lib_div::get_tag_attributes($match[1]);
                }
        }
 
index 1654a19..0b87ca4 100755 (executable)
@@ -3850,11 +3850,9 @@ class tslib_cObj {
                if (trim($subparts[0])) {
                                // Get attributes and name
                        $attribs = t3lib_div::get_tag_attributes('<'.$subparts[0].'>');
-                       if (!is_array($attribs))        {$attribs=array();}
                        list($tagName) = explode(' ',$subparts[0],2);
                                // adds/overrides attributes
-                       reset($conf);
-                       while(list($pkey,$val)=each($conf))     {
+                       foreach ($conf as $pkey => $val)        {
                                if (substr($pkey,-1)!='.' && substr($pkey,0,1)!='_')    {
                                        $tmpVal=$this->stdWrap($conf[$pkey],$conf[$pkey.'.']);
                                        if ($lowerCaseAttributes)       { $pkey = strtolower($pkey); }
@@ -3863,7 +3861,7 @@ class tslib_cObj {
                        }
 
                                // Re-assembles the tag and content
-                       $subparts[0]=trim($tagName.' '.t3lib_div::implodeAttributes($attribs));
+                       $subparts[0] = trim($tagName.' '.t3lib_div::implodeAttributes($attribs));
                        $parts[$key] = implode('>',$subparts);
                        $content = implode('<',$parts);
                }