From 23395bbab021028a7b9e750c56e5c25c168605bb Mon Sep 17 00:00:00 2001 From: Martin Kutschker Date: Sat, 2 Feb 2008 14:02:49 +0000 Subject: [PATCH] Changed t3lib_div::get_tag_attributes/split_tag_attributes so that they always return an array git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@3021 709f56b5-9817-0410-a4d7-c38de5d9e867 --- ChangeLog | 1 + t3lib/class.t3lib_div.php | 50 +++++++++---------- .../sysext/cms/tslib/class.tslib_content.php | 6 +-- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index b76bf7b0d1b..23bf12c0a2f 100755 --- 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 diff --git a/t3lib/class.t3lib_div.php b/t3lib/class.t3lib_div.php index c4bb3cfddf7..5157fd7dd94 100755 --- a/t3lib/class.t3lib_div.php +++ b/t3lib/class.t3lib_div.php @@ -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 '') 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]); } } diff --git a/typo3/sysext/cms/tslib/class.tslib_content.php b/typo3/sysext/cms/tslib/class.tslib_content.php index 1654a190825..0b87ca4fdd6 100755 --- a/typo3/sysext/cms/tslib/class.tslib_content.php +++ b/typo3/sysext/cms/tslib/class.tslib_content.php @@ -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); } -- 2.20.1