DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

HCard To JSON Bridge

06.03.2007
| 5510 views |
  • submit to reddit
        // Requires http://pear.php.net/pepr/pepr-proposal-show.php?id=198 and http://allinthehead.com/hkit
// Many thanks to the authors of these libraries and to the microformats community.
// Demo: http://simplelogica.net/cajondesastre/hcard2json/index.php?url=http://11870.com/pro/19483
// Manuel González Noriega for Simplelógica. Hire us at http://simplelogica.net


    include('hkit.class.php');
    include('JSON.class.php');
		
    $debug = true;
		
    $status = '200';
    $ct = 'text/plain';
		
    $hKit = new hKit;
    $json = new Services_JSON();

    if ($_GET['url']) {
      $result = $hKit->getByURL('hcard', $_GET['url']);
	    
      if ($result) {
	$o = ($json->encode($result));
	$ct = ($debug) ? 'text/plain' : 'application/json';			
      }
      else {
	$o = '404 Not Found';
	$status = '404';
      }
    }
    else {
      $o = '400 Bad Request';
      $status = '400';
    }
	
 

  header('Content-type: '.$ct);
  
  switch($status) {
    case '400':
      header("HTTP/1.0 400 Bad Request");
    break;
	
    case '404':
      header("HTTP/1.0 404 Not Found");
    break;

    case '200':
    default:
      header("HTTP/1.0 200 OK");
    break;
}

print $o;