Skip to content

Instantly share code, notes, and snippets.

@hideki-a
Created February 12, 2019 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hideki-a/8ed3b067cd8f9bec56eccdd8fe8a17c3 to your computer and use it in GitHub Desktop.
Save hideki-a/8ed3b067cd8f9bec56eccdd8fe8a17c3 to your computer and use it in GitHub Desktop.
<?php
$mt_dir = '/path/to/pcms/';
require_once ( $mt_dir . 'php/mt.php' );
require_once ( $mt_dir . 'addons/DynamicMTML.pack/php/dynamicmtml.php' );
$blog_id = 1;
$mt_config = $mt_dir . 'mt-config.cgi';
$app = new DynamicMTML();
$app->configure( $mt_config );
try {
$mt = MT::get_instance( $blog_id, $mt_config );
} catch ( MTInitException $e ) {
$app->run_callbacks( 'mt_init_exception', $mt, $ctx, $args, $e );
}
if ( isset( $mt ) ) {
$ctx =& $mt->context();
$app->set_context( $mt, $ctx );
}
$q = $app->param( 'q' );
$q = $app->db()->escape( $q );
$q = preg_replace( '/[^0-9]/', '', $q );
if ( $q ) {
$terms = array( 'name' => $q,
'class' => 'customobject' );
$extra = array( 'limit' => 1 );
$postalcode = $app->load( 'CustomObject', $terms, $extra );
if ( $postalcode ) {
$arr = array( 'zipcode' => $postalcode->name,
'address' => $postalcode->body,
'status' => '200' );
} else {
$arr = array( 'zipcode' => $q,
'address' => '',
'status' => '404' );
}
$json = json_encode( $arr );
$app->send_http_header( 'application/json; charset=UTF-8', time(), strlen( $json ) );
echo $json;
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment