http://www.missingkidsmap.com/read.php?state=CA

ZZ

<locations> <maplocation zoom="5" state_long="-119.838867" state_lat="37.370157"/> <location id="1" firstname="Anastasia" lastname=" Shearer " picture="img width=160 target=_new src=http://www.missingkids.com/photographs/NCMC1140669c1.jpg" picture2="img width=160 target=_new src=http://www.missingkids.com/photographs/NCMC1140669e1.jpg" medpic = "img width=60 border=0 target=_new src=http://www.missingkids.com/photographs/NCMC1140669c1.jpg" smallpic="img width=30 border=0 target=_new src=http://www.missingkids.com/photographs/NCMC1140669c1.jpg" policenum="1-661-861-3110" policeadd="Kern County Sheriff\'s Office (California)" policenum2="" policeadd2="" st=" CA" city="BAKERSFIELD" missing="12/26/2009" status="Endangered Runaway" age="16" url="1140669" lat="35.3733333333333" lng="-119.017777777778"/> ... </locations>

SELECT * From xml Where url='http://www.missingkidsmap.com/read.php?state=ZZ'

{ "query":{ "count":"1", "created":"2010-02-19T07:30:44Z", "lang":"en-US", "updated":"2010-02-19T07:30:44Z", "uri":"http://query.yahooapis.com/v1/yql?q=SELECT+*+From+xml%0A+Where+url%3D%27http%3A%2F%2Fwww.missingkidsmap.com%2Fread.php%3Fstate%3DZZ%27", "results":{ "locations":{ "maplocation":{ "state_lat":"40.313043", "state_long":"-94.130859", "zoom":"4" }, "location":[{ "age":"7", "city":"OMAHA", "firstname":"Christopher", "id":"Szczepanik", "lastname":"Szczepanik", "lat":"41.2586111111111", "lng":"-95.9375", "medpic":"img width=60 border=0 target=_new src=http://www.missingkids.com/photographs/NCMC1141175c1.jpg", "missing":"12/14/2009", "picture":"img width=160 target=_new src=http://www.missingkids.com/photographs/NCMC1141175c1.jpg", "picture2":"", "policeadd":"Omaha Police Department (Nebraska)", "policeadd2":"", "policenum":"1-402-444-5600", "policenum2":"", "smallpic":"img width=30 border=0 target=_new src=http://www.missingkids.com/photographs/NCMC1141175c1.jpg", "st":" NE", "status":"Missing", "url":"1141175" }, ... ] } } } }

$json = http_get($missing_kids_url); $o = json_decode($json, 1); $children = $o['query']['results']['locations']['location']; $child = array_rand($children); print_404($child);

http_get

curl_multi

print_404

$child

location

function print_404($child) { $img = preg_replace('/.*src=(.*)/', '$1', $child["medpic"]); $name = $child["firstname"] . " " . $child["lastname"]; $age = $child['age']; $since = strtotime(preg_replace('|(\d\d)/(\d\d)/(\d\d\d\d)|', '$3-$1-$2', $child['missing'])); if($age == 0) { $age = ceil((time()-$since)/60/60/24/30); $age .= ' month'; } else $age .= ' year'; $city = $child['city']; $state = $child['st']; $status = $child['status']; $police = $child['policeadd'] . " at " . $child['policenum']; header('HTTP/1.0 404 Not Found'); ?> <html> <head> ... <p> <strong>Sorry, the page you're trying to find is missing.</strong> </p> <p> We may not be able to find the page, but perhaps you could help find this missing child: </p> <div style="text-align:center;"> <img style="width:320px; padding: 1em;" alt="<?php echo $name ?>" src="<?php echo $img ?>"><br> <div style="text-align: left;"> <?php echo $age ?> old <?php echo $name ?>, from <?php echo "$city, $state" ?> missing since <?php echo strftime("%B %e, %Y", $since); ?>.<br> <strong>Status:</strong> <?php echo $status ?>.<br> <strong>If found, please contact</strong> <?php echo $police ?><br> </div> </div> ... </body> </html> <?php }

ErrorDocument 404 /404.php

It's been a long time since I last posted, and unfortunately I've been unable to churn out a post every week. The month of February has been filled with travel, so I haven't had much time to write.My report on FOSDEM is up on the YDN blog, so I haven't been completely dormant. I also did some stuff at our internal hack day last week. This post is about one of my hacks.The idea is quite simple. People land up on 404 pages all the time. 404 pages are pages that have either gone missing, or were never there to begin with. 404 is the HTTP error code for a missing resource. Most 404 pages are quite bland, simply stating that the requested resource was not found, and that's it. Back when I worked at NCST, I changed the default 404 page to use a local site search based on the requested URL. I used the namazu search engine since I was working on it at the time.This time I decided to do something different. Instead of searching the local site for a missing resource, why not engage the user in trying to find missing kids.I started with trying to find an API for missingkids.com and ended up finding missingkidsmap.com . This service takes the data from Missing Kids and puts it on a google map. The cool thing about the service was that it could return data as XML.Looking through the source code, I found the data URL:The state code is a two letter code for states in the US and Canada. To get all kids, just pass inas the state code.The data returned looks like this:Now I could keep hitting this URL for every 404, but I didn't want to kill their servers, so I decided to pass the URL through YQL and let them cache the data. Of course, now that I was passing it through YQL, I could also do some data transformation and get it out as JSON instead of XML. I ended up with this YQL statement:Pass that through the YQL console to get the URL you should use. The JSON I got back looked like this:Step 2 was to figure out whether the visitor was from the US and Canada, and if so, figure out which state they were from and pass that state code to the URL.This is fairly easy to do at Yahoo!. Not so much on the outside, so I'm going to leave it to you to figure it out (and please let me know when you do).In any case, my code looked like this:is a function I wrote that wraps aroundto fetch and cache locally a URL.is the function that prints out the HTML for the 404 page using thedata object. The object's structure is the same as each of theelements in the JSON above. The important parts of print_404 are:Add in your own CSS and page header, and you've got missing kids on your 404 page.The last thing to do is to tell apache to use this script as your 404 handler. To do that, put the page (I call it 404.php) into your document root, and put this into your apache config (or in a .htaccess file):Restart apache and you're done.To see it in action, visit a missing page on my website. eg: http://bluesmoon.info/foobar The code is now on github: http://github.com/bluesmoon/404kids Scott Hanselman has a Javascript implementation on his blog.There's now a drupal module for this.