Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 383 lines (366 sloc) 13.105 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
<?php

require_once('./settings.php');
require_once('./libs/phpMet/src/Trimet.php');

$stop_ids = '';
$error_msg = '';
$arrivals = array();
if (isset($_GET['LocIDs'])) {
    $stop_ids = $_GET['LocIDs'];
    $LocIDs = explode(',', $stop_ids);

    $LocIDs = array_filter($LocIDs, 'TrimetAPIQuery::sanitizeLocationID');

    if (!empty($LocIDs)) {
        $api = new TrimetAPIQuery();
        $arrivals = $api->getArrivals($LocIDs);
    }
    else {
        $error_msg = 'Invalid stop! Try a numeric stop ID like "1448".';
    }
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<title>Where's My (TriMet) Bus?</title>

<meta name="description" content="Enter your TriMet stop number to find out when your bus will arrive in real time!">
<meta name="author" content="Tristan Waddington">

<style>
html,
body {
margin: 0px;
padding: 0px;
font-size: 14px;
font-family: "Lucida Grande", "Lucida Sans", Arial, Verdana, sans-serif;
}
html {
background-color: #fff;
}
body {
background-color: transparent;
}
.wrap {
position: relative;
min-width: 300px;
max-width: 600px;
margin: 0px auto;
padding: 10px;
}
h1,h2,h3,h4,h5,h6 {
margin: 0px;
padding: 0px;
color: #084C8D;
clear: both;
}
h1 {
margin-top: 20px;
font-size: 24px;
}
h2 {
font-size: 22px;
}
h3 {
font-size: 18px;
}
fieldset {
margin: 0px;
padding: 5px 10px;
color: #fff;
border: none;
background-color: #084C8D;
}
fieldset ol,
fieldset li {
margin: 0px;
padding: 0px;
list-style-type: none;
}
fieldset li {
position: relative;
margin: 5px 0px;
background-color: #fff;
overflow: hidden;
}
fieldset span {
display: block;
margin-top: 5px;
font-size: 12px;
}
input {
position: relative;
margin: 0px;
padding: 0px;
}
input[type="number"] {
position: absolute;
width: 100%;
margin: 0;
padding: 10px;
color: #999;
font-size: 24px;
border: none;
outline: none;
z-index: 1;
}
input[type="submit"] {
display: block;
width: 100px;
margin: 5px;
padding: 8px 0px;
color: #084C8D;
font-size: 16px;
text-transform: uppercase;
border: none;
background: #DADFE1;
cursor: pointer;
z-index: 2;
float: right;
}
#find-stops {
display: none;
text-align: right;
background-color: #084C8D;
}
#find-stops .wrap {
padding: 0;
}
#find-stops a:link,
#find-stops a:visited,
#find-stops a:hover,
#find-stops a:active {
display: block;
margin: 0;
padding: 15px 10px;
color: #fff;
text-decoration: none;
}
#loading {
display: none;
width: 16px;
height: 16px;
margin: 0;
padding: 0;
background: transparent url('images/spinner.gif') no-repeat center;
float: left;
}
#debug {
color: #999;
font-size: 10px;
text-align: center;
}
#results {
margin: 20px 10px;
padding: 0px;
}
#results ul {
display: block;
margin: 10px 0 0 0;
padding: 0;
list-style-type: none;
}
#results li:first-child {
border: none;
}
#results li {
display: block;
margin: 10px 0;
padding: 10px 0 0 0;
color: #666;
font-size: 16px;
border-top: 1px solid #DADFE1;
list-style-type: none;
}
.arrival {
margin: 0 0 2px 0;
color: #333;
}
.arrival-line {
/* stub */
}
.arrival-time {
color: #084C8D;
font-weight: bold;
}
.arrival-status {
color: #A9A9A9;
font-variant: small-caps;
float: right;
}
.arrival-location {
color: #A9A9A9;
font-size: 13px;
}
#stop-list {
display: none;
overflow: hidden;
}
#stop-list ul,
#stop-list li {
display: block;
margin: 0;
padding: 0;
list-style-type: none;
}
#stop-list li a:link,
#stop-list li a:visited {
display: block;
margin: 5px;
padding: 15px 10px;
color: #084C8D;
text-decoration: none;
text-overflow: ellipsis;
white-space: nowrap;
background-color: #DADFE1;
}
#footer {
position: relative;
margin: 20px 0px;
padding: 10px 0;
color: #999;
text-align: right;
border-top: 1px solid #A9A9A9;
}
a:link,
a:visited {
color: #999;
}
a:hover,
a:active {
text-decoration: none;
}
.error {
margin: 20px 10px;
padding: 0px;
color: red;
}
</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
if (navigator.geolocation) {
var find_stops = $('#find-stops');
var stop_list = $('#stop-list');
var loading = $('#loading');

find_stops.show();
find_stops.find('a:first').click(function(e) {
// Show loading indicator
loading.show();

// Get the user's location
navigator.geolocation.getCurrentPosition(function(pos) {
// Debug
$('#debug').text(
pos.coords.latitude + ',' +
pos.coords.longitude + ',' +
pos.coords.accuracy);

// Make our request
$.post('/ajax/stops.php',
{'lat': pos.coords.latitude, 'lng': pos.coords.longitude, 'radius': 75},
function(data) {
if (data && data.length > 0) {
if (data.length === 1) {
// Only one stop found, redirect immediately!
window.location = '?LocIDs=' + data[0].locid;
} else {
$.each(data, function(k,l) {
var a = $('<a/>', {
'href': '/?LocIDs=' + l.locid
}).text('[' + l.locid + '] ' + l.desc + ' ' + l.dir);

var item = $('<li/>').append(a);
stop_list.find('ul:first').append(item);
});
stop_list.show();
}
} else {
find_stops.find('a').text('No stops found! Try again?');
}

// Hide the loading indicator
loading.hide();
}
);
}, function(e) {
loading.hide();
},
{
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 0
});
return false;
});
}
});
</script>
</head>
<body>
<div id="find-stops">
<div class="wrap">
<a href="#">
<div id="loading"></div>
Tap here to find stops near you!
</a>
</div>
</div>
<div class="wrap">
<div id="stop-list">
<ul></ul>
</div>
<h1>Where's My Bus?</h1>
<form action="" method="GET">
<fieldset>
<ol>
<li>
<label for=""></label>
<input type="number" name="LocIDs" placeholder="Stop number..." value="<?php echo $stop_ids; ?>" />
<input type="submit" value="Submit" />
</li>
</ol>
</fieldset>
</form>
<?php if (!empty($error_msg)) : ?>
<div class="error">
<p><?php echo $error_msg; ?></p>
</div>
<?php endif; ?>
<?php if (!empty($arrivals)) : ?>
<div id="results">
<ul>
<?php foreach ($arrivals as $a) : ?>
<li>
<div class="arrival">
<span class="arrival-line"><?php echo $a->shortSign; ?></span>
<?php if ($a->isScheduled()) : ?>
scheduled at
<span class="arrival-time"><?php echo date('g:ia', $a->scheduled->unix_datetime); ?></span>
<?php else : ?>
arriving in
<span class="arrival-time"><?php echo abs($a->getArrivalTime()); ?> minutes</span>
<?php endif; ?>
</div>
<?php if ($a->status != 'estimated') : ?>
<span class="arrival-status"><?php echo $a->status; ?></span>
<?php endif; ?>
<span class="arrival-location"><?php echo $a->location; ?></span>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div id="footer">
<a href="https://github.com/twaddington/trimet-stop-lookup">View Source</a> |
<a href="mailto:consulting@tristanwaddington.com?subject=Where's My Bus Feedback">Send Feedback</a>
</div>
<div id="debug"></div>
</div>
<!-- end .wrap -->
<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2012911-13']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>
</body>
</html>
Something went wrong with that request. Please try again.