From: <nel...@us...> - 2007-06-25 21:01:52
|
Author: nelius_weiss Date: Mon Jun 25 22:47:38 2007 New Revision: 24214 URL: http://www.egroupware.org/viewvc?rev=3D3D24214&view=3D3Drev Log: clean fields on demand from cntl chars Modified: trunk/importexport/inc/class.import_export_helper_functions.inc.php Modified: trunk/importexport/inc/class.import_export_helper_functions.inc.p= =3D hp URL: http://www.egroupware.org/viewvc/trunk/importexport/inc/class.import_e= =3D xport_helper_functions.inc.php?rev=3D3D24214&r1=3D3D24213&r2=3D3D24214&view= =3D3Ddiff =3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D= =3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D =3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D= =3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D =3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D= =3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D =3D3D=3D3D=3D3D --- trunk/importexport/inc/class.import_export_helper_functions.inc.php (or= =3D iginal) +++ trunk/importexport/inc/class.import_export_helper_functions.inc.php Mon= =3D Jun 25 22:47:38 2007 @@ -174,14 +174,15 @@ */ public static function conversion( $_record, $_conversion, &$_cclass =3D= 3D=3D null ) { if (empty( $_conversion ) ) return $_record; - $values =3D3D $_record; =3D $PSep =3D3D '||'; // Pattern-Separator, separats the pattern-replacement= -p=3D airs in conversion $ASep =3D3D '|>'; // Assignment-Separator, separats pattern and replaces= me=3D nt $CPre =3D3D '|['; $CPos =3D3D ']'; // |[_record-idx] is expanded to the = core=3D spondig value + $TPre =3D3D '|T{'; $TPos =3D3D '}'; // |{_record-idx} is trimmed + $CntlPre =3D3D '|TC{'; // Filter all cntl-chars \x01-\x1f and trim + $CntlnCLPre =3D3D '|TCnCL{'; // Like |C{ but allowes CR and LF =3D foreach ( $_conversion as $idx =3D3D> $conversion_string ) { - =3D if ( empty( $conversion_string ) ) continue; =3D // fetch patterns ($rvalues) @@ -194,7 +195,7 @@ $rvalues[$pattern] =3D3D $replace; // replace two with only one, added= b=3D y the form } =3D - // conversion list may be longer than $_record (no_csv) + // conversion list may be longer than $_record aka (no_csv) $val =3D3D array_key_exists( $idx, $_record ) ? $_record[$idx] : ''; =3D foreach ( $rvalues as $pattern =3D3D> $replace ) { @@ -215,9 +216,12 @@ $val =3D3D preg_replace_callback( "/(cat|account|strtotime)\(([^)]+)\= )/=3D i", array( self, 'c2_dispatcher') , $val ); } } - $values[$idx] =3D3D $val; - } - return $values; + // clean each field + $val =3D3D preg_replace_callback("/(\|T\{|\|TC\{|\|TCnCL\{)(.*)\}/", ar= ra=3D y( self, 'strclean'), $val ); + =3D + $_record[$idx] =3D3D $val; + } + return $_record; } // end of member function conversion =3D /** @@ -238,6 +242,17 @@ default : $method =3D3D (string)$action. ( is_int( $data ) ? '_id2name' : '_name= 2i=3D d' ); return self::$method( $data ); + } + } + =3D + private static function strclean( $_matches ) { + //print_r($_matches); + switch( $_matches[1] ) { + case '|T{' : return trim( $_matches[2] ); + case '|TC{' : return trim( preg_replace( '/[\x01-\x1F]+/', '', $_matche= =3D s[2] ) ); + case '|TCnCL{' : return trim( preg_replace( '/[\x01-\x09\x11\x12\x14-\x= =3D 1F]+/', '', $_matches[2] ) ); =3D + default: + throw new Exception('Error in conversion string! "'. substr( $_matches= =3D [1], 0, -1 ). '" is not valid!'); } } =3D |