Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php error_reporting(0);?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Craigslist Date Filter</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.8.0/build/reset-fonts-grids/reset-fonts-grids.css">
<style type="text/css">
body,html{background:#999;color:#000;}
#doc{background:#fff;border:1em solid #fff;}
h1{padding:.5em 0;font-size:150%;color:#060;}
h2{padding:.5em 0;font-size:120%;}
h2 a{color:#393;}
li p{font-size:80%;}
form{background:#eee;padding:.5em;overflow:hidden;-moz-box-shadow:4px 4px 4px rgba(0,0,0,.3);}
input[type=submit]{float:right;}
label{padding-right:1em;}
form div{padding-bottom:.5em;}
#ft{color:#ccc;padding:2em 0 0 0;text-align:right;font-size:70%;}
#ft a{color:#999;}
.intro{font-size:110%;padding-bottom:10px;}
</style>
</head>
<body class="yui-skin-sam">
<div id="doc" class="yui-t7">
<div id="hd" role="banner">
<h1>Craigslist Date Filter</h1>
</div>
<div id="bd" role="main">
<p class="intro">This interface makes it easy for you to browse the personals section of craigslist. We are not taking any responsibility for the data returned and are as dubious as anyone about the authenticity of some of the offers. Be safe.</p>
<form action="craigsdate.php">
<div>
<label for="location">Location:</label>
<input type="text" name="location" id="location" value="london">
<label for="location">Query (separate several with a comma):</label>
<input type="text" name="query" id="query">
</div>
<div>
<fieldset>
<legend>Types:</legend>
<input type="checkbox" name="w4m" id="w4m">
<label for="w4m">Women for Men</label>
<input type="checkbox" name="w4w" id="w4w">
<label for="w4w">Women for Women</label>
<input type="checkbox" name="m4m" id="m4m">
<label for="m4m">Men for Men</label>
<input type="checkbox" name="m4w" id="m4w">
<label for="m4w">Men for Women</label>
<input type="checkbox" name="cas" id="cas">
<label for="cas">Casual Encounters</label>
</fieldset>
</div>
<p><input type="submit" name="sent" value="Go fetch!"></p>
</form>
<?php
if(isset($_GET['sent'])){
$query = filter_input(INPUT_GET,'query',FILTER_SANITIZE_ENCODED);
$location = filter_input(INPUT_GET,'location',FILTER_SANITIZE_ENCODED);
$type = array();
$types = array('w4m','w4w','m4m','m4w','cas');
foreach($types as $t){
if($_GET[$t] == 'on'){
$type[] = $t;
}
}
$type = '"'.implode($type,'","').'"';
if($type != '""'){
if(strpos($query,'%2C') > 0){
$yql = 'select * from query.multi where queries=\'';
$queries = explode('%2C',$query);
foreach($queries as $q){
$yql .= 'select item.title,item.description,item.link '.
'from craigslist.search where location="'.$location.
'" and type in ('.$type.') and query="'.$q.'";';
}
$yql .= '\'';
$url = 'http://query.yahooapis.com/v1/public/yql?q='.
urlencode($yql).'&diagnostics=true&'.
'env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys'.
'&format=json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$data = json_decode($output);
echo '<ul id="results">';
foreach($data->query->results->results as $set){
foreach($set->RDF as $r){
echo '<li><h2><a href="'.$r->item->link.'">'.
$r->item->title.'</a></h2><p>'.
$r->item->description.'</p></li>';
}
}
echo '</ul>';
} else {
$yql = 'select item.title,item.description,item.link '.
'from craigslist.search where location="'.$location.
'" and type in ('.$type.') and query="'.$query.'"';
$url = 'http://query.yahooapis.com/v1/public/yql?q='.
urlencode($yql).'&diagnostics=true&'.
'env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys'.
'&format=json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$data = json_decode($output);
echo '<ul id="results">';
foreach($data->query->results->RDF as $r){
echo '<li><h2><a href="'.$r->item->link.'">'.
$r->item->title.'</a></h2><p>'.
$r->item->description.'</p></li>';
}
echo '</ul>';
}
}
}
?>
</div>
<div id="ft" role="contentinfo">
<p>Written by <a href="http://wait-till-i.com">Chris Heilmann</a> using the Magic of <a href="http://developer.yahoo.com/yql">YQL</a></p>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.