|
From: Ruediger H. <hae...@us...> - 2005-07-27 06:08:46
|
Update of /cvsroot/pn-commerce/pn-commerce In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32151 Modified Files: pnadmin.php Log Message: Fix: xml can only have _one_ root tag / make xml "well formed" Enhancement: iterate through serialized arrays like "cartdata" in orders table Index: pnadmin.php =================================================================== RCS file: /cvsroot/pn-commerce/pn-commerce/pnadmin.php,v retrieving revision 1.264 retrieving revision 1.265 diff -C2 -d -r1.264 -r1.265 *** pnadmin.php 26 Jul 2005 09:32:50 -0000 1.264 --- pnadmin.php 27 Jul 2005 06:08:34 -0000 1.265 *************** *** 1897,1900 **** --- 1897,1961 ---- function pncommerce_admin_export_table_send() { + + function array2xml($items, $xml, $parent = '') + { + $arrays = array(); + + // first process all elementary types, treat them as xml attributes, + // not as xml tags. + foreach($items as $key => $item) + { + if (is_array($item)) + { + // we need to remember arrays and process them at the end + $arrays[$key] = $item; + } + else + { + $item = str_replace( + array('&', '<', '>', '"'), + array('&', '<', '>', '"'), + $item); + if (ereg('^[0-9]', $key)) + { + // Special case for arrays items indexed with integers: + // xml attributenames must not start with a digit. + // Make tags of them. + $xml .= '>' . "\r\n" . '<' . $parent . '_row id="' . $key . '" value="' . $item . '" /'; + } + else + { + $xml .= $key . '="' . $item .'" '; + } + } + } // foreach(elementary data types... + $xml .= '>' . "\r\n"; + + // all elementary types have been processed, now continue with the + // arrays: + foreach($arrays as $key => $item) + { + if (ereg('^[0-9]', $key)) + { + // special case for arrays just indexed with integers: + // xml tagnames must not start with a digit + $startTag = '<' . $parent . '_row id="' . $key . '" '; + $endTag = '</' . $parent . '_row>' . "\r\n"; + } + else + { + // named keys / associative arrays + $startTag = '<' . $key . ' '; + $endTag = '</' . $key . '>' . "\r\n"; + } + + $xml .= $startTag; + // recursively call this function + array2xml($item, &$xml, $key); + $xml .= $endTag; + } // foeach(arrays... + } // function array2xml + + if (!pnModAPILoad('pncommerce', 'admin')) { *************** *** 1965,1975 **** $mime_type = 'text/xml'; // first add the xml tag ! $dump_buffer .= '<?xml version="1.0" encoding="iso-8859-1"?>'."\n"; // some comments ! $dump_buffer .= '<!-- pncommerce '.pnModGetVar( 'pncommerce', 'Version').' XML-Dump http://www.pncommerce.de (main site)-->'."\n"; // the data foreach ($result as $line) { ! $dump_buffer .= ' <' . $table . '>'."\n"; for ($k=0; $k<count($tablecolumn);$k++) { --- 2026,2037 ---- $mime_type = 'text/xml'; // first add the xml tag ! $dump_buffer .= '<?xml version="1.0" encoding="iso-8859-1"?>'."\r\n"; // some comments ! $dump_buffer .= '<!-- pncommerce '.pnModGetVar( 'pncommerce', 'Version').' XML-Dump http://www.pncommerce.de (main site)-->'."\r\n"; // the data + $dump_buffer .= '<' . $table . '>' . "\r\n"; foreach ($result as $line) { ! $dump_buffer .= '<' . $table . '_row>'."\r\n"; for ($k=0; $k<count($tablecolumn);$k++) { *************** *** 1982,1991 **** $col=$tablecolumnas[$k]; } ! $dump_buffer .=" <".$col.">"; ! $dump_buffer .=$line[$k]; ! $dump_buffer .="</".$col.">\n"; } ! $dump_buffer .= " </" . $table .">\n"; } } else --- 2044,2084 ---- $col=$tablecolumnas[$k]; } ! // fix for incorrect serialized data ! $line[$k] = str_replace('\\"', '"', $line[$k]); ! // end of fix ! if (is_array(unserialize($line[$k]))) ! { ! if (false) ! { ! // write arrays down as CDATA being ignored by xml ! // processors. ! $dump_buffer .="<".$col.">"; ! $dump_buffer .= '<![CDATA[' . "\r\n"; ! $dump_buffer .= $line[$k] . "\r\n"; ! $dump_buffer .= ']]>' . "\r\n"; ! } ! else ! { ! // Array: just open tag, array items will be ! // added as attributes ! $dump_buffer .="<".$col . " "; ! array2xml(unserialize($line[$k]), &$dump_buffer); ! } ! } ! else ! { ! // elementary data type ! $dump_buffer .="<".$col.">"; ! $line[$k] = str_replace( ! array('<', '>', '&' , '"'), ! array('<', '>', '&', '"'), ! $line[$k]); ! $dump_buffer .= $line[$k]; ! } ! $dump_buffer .="</".$col.">\r\n"; } ! $dump_buffer .= "</" . $table ."_row>\r\n"; } + $dump_buffer .= '</' . $table . '>' . "\r\n"; } else |