https://www.mediawiki.org/wiki/Special:Code/MediaWiki/109202
Revision: 109202 Author: ariel Date: 2012-01-17 20:03:50 +0000 (Tue, 17 Jan 2012) Log Message: ----------- make the friggin dash in the zip work Modified Paths: -------------- trunk/extensions/CongressLookup/CongressLookup.db.php Modified: trunk/extensions/CongressLookup/CongressLookup.db.php =================================================================== --- trunk/extensions/CongressLookup/CongressLookup.db.php 2012-01-17 20:02:44 UTC (rev 109201) +++ trunk/extensions/CongressLookup/CongressLookup.db.php 2012-01-17 20:03:50 UTC (rev 109202) @@ -21,7 +21,7 @@ table or to have NULL for the rep id. */ if ( ( !$row ) || ( !$row->clz5_rep_id ) ) { /* if we got the extra 4 digits, use them */ - $zip9 = intval( $zip ); + $zip9 = intval( self::trimZip( $zip, 9 ) ); // remove the dash and pad if needed if ( $zip9 >= 10000 ) { $row = $dbr->selectRow( 'cl_zip9', 'clz9_rep_id', array( 'clz9_zip' => $zip9 ) ); if ( $row ) { @@ -131,14 +131,22 @@ */ public static function trimZip( $zip, $length ) { $zip = trim( $zip ); - if ( strlen( $zip ) < 5 ) { - $zip = sprintf( "%05d", $zip ); + if ( strpos( $zip, '-' ) === False ) { + if ( strlen( $zip ) < 5 ) { + $zip = sprintf( "%05d", $zip ); + } + elseif ( strlen( $zip ) > 5 ) { + $zip = sprintf( "%09d", $zip ); + } } - elseif ( strlen( $zip ) > 5 ) { - $zip = sprintf( "%09d", $zip ); + else { + $zipPieces = explode( '-', $zip, 2 ); + if (! $zipPieces[1]) { + $zipPieces[1] = 0; + } + $zip = sprintf( "%05d%04d", $zipPieces[0], $zipPieces[1] ); } - $zipPieces = explode( '-', $zip, 2 ); - $zip = substr( $zipPieces[0], 0, $length ); + $zip = substr( $zip, 0, $length ); return $zip; } } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs