<?
  
function get_remotefile($url$mdate) {
    
$url_stuff parse_url($url);

    if (!
$fp = @fsockopen ($url_stuff['host'], (($url_stuff['port'])?($url_stuff['port']):("80")), $errno$errstr2)) return false;
    else {
      if (
$url_stuff['query']) $url_stuff['path'] .= "?";
      
$header "GET ".$url_stuff['path'].$url_stuff['query']." HTTP/1.0";
      
$header .= "\r\nHost: ".$url_stuff['host'];
      
$header .= "\r\nIf-Modified-Since: $mdate";
      
$header .= "\r\n\r\n";

      
fputs ($fp$header);

      unset(
$header$body$lmdate);
      
$act false;
      
$cnt 0;

      
socket_set_timeout($fp4);

      while ((!
feof($fp))) {
        if (
$cnt == 100) break;
        
$line fgets ($fp1024);
        
$ss socket_get_status($fp);
        if (
$ss[timed_out]) return false;

        if (!
$act) {
          if (
strpos($line"\r\n"0) == 0$act true;
          if ((
$n1 strpos($line"Last-Modified:")) !== false$lmdate trim(substr($line$n1 14));
          if ((
$n2 strpos($line"Location:")) !== false) { $loc trim(substr($line$n2 9)); break; }
          
$header .= $line."\r\n";
        } else {
          
$body .= $line;
          if (
strpos($line"</item>") !== false$cnt++;
        }
      }
      
fclose ($fp);
    }

    if (
$loc) list($header$body$lmdate) = get_remotefile($loc$mdate);

    return array(
$header$body$lmdate);
  }



  
// Include this function on your pages
  
function gzip($contents false) {
    global 
$HTTP_ACCEPT_ENCODING$url;
    if(
headers_sent()) {
      
$encoding false;
    } elseif ( 
strpos($HTTP_ACCEPT_ENCODING'x-gzip') !== false ) {
      
$encoding 'x-gzip';
    } elseif ( 
strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false ) {
      
$encoding 'gzip';
    } else {
      
$encoding false;
    }

    if(
$encoding){
      if (!
$contents$contents ob_get_contents();
      
ob_end_clean();
      if (
stristr($url'tr_authority_t_js'))
        
$contents str_replace('static.technorati.com/static/img/icn''firejune.cdn2.cafe24.com/techonorati'$contents);
      
header('Content-Encoding: '.$encoding);
      print(
"\x1f\x8b\x08\x00\x00\x00\x00\x00");
      
$size strlen($contents);
      
$contents gzcompress($contents9);
      
$contents substr($contents0$size);
      print(
$contents);
      
//exit();
    
} else {
      
ob_end_flush();
      
//exit();
    
}
  }

  
$url "http://local.daum.net/notmp_map/congsoa/route/getSearchRoute.service?".$_GET["params"];
  
$hash md5($url);
  
header("ETag: '".$hash."'");
  
header("Accept-Ranges: bytes");
  
header("Vary: Accept-Encoding");
  
header("Cache-Control: max-age=2592000");
  
header("Expires: "gmdate('D, d M Y H:i:s'time() + 3600 24 30). " GMT");
  
header("Content-Type: text/xml; charset=utf-8");

  if (isset(
$_SERVER['HTTP_IF_NONE_MATCH']) && 
    
stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == '"'.$hash.'"') {
    
header("HTTP/1.0 304 Not Modified");
    
header('Content-Length: 0');
  } else {
    list(
$header$body$lmdate) = @get_remotefile($url"");
  
    if (
$body) {
      
header("Last-Modified: ".$lmdate);
      
header("Content-Length: ".strlen($body));
      
gzip($body);
    } else {
      
header("HTTP/1.0 304 Not Modified");
      
header('Content-Length: 0');
    }
  }

  exit;
?>