diff options
Diffstat (limited to 'controllers')
| -rw-r--r-- | controllers/controllers.php | 99 | 
1 files changed, 99 insertions, 0 deletions
| diff --git a/controllers/controllers.php b/controllers/controllers.php index fe4d89c..ecc3a9e 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -191,6 +191,105 @@ $app->get('/itinerary', function() use($app) {    }  }); +$app->get('/flight', function() use($app) { +  if($user=require_login($app)) { +    $params = $app->request()->params(); + +    render('new-flight', array( +      'title' => 'Flight', +      'authorizing' => false +    )); +  } +}); + +$app->post('/flight', function() use($app) { +  if($user=require_login($app)) { +    $params = $app->request()->params(); + +    $location = false; + +    if($params['action'] == 'find') { + +    } elseif($params['action'] == 'checkin') { + +      $payload = [ +        'type' => ['h-entry'], +        'properties' => [ +          'checkin' => [ +            [ +              'type' => ['h-card'], +              'properties' => [ +                'name' => [$params['flight']], +                'url' => ['http://flightaware.com/live/flight/'.$params['flight']], +              ] +            ] +          ] +        ] +      ]; + +      $r = micropub_post_for_user($user, $payload, null, true); + +      $location = $r['location']; + +      if($location) { +        // Store the checkin in the database to enable the cron job tracking the flight +        $flight = ORM::for_table('flights')->create(); +        $flight->user_id = $_SESSION['user_id']; +        $flight->date_created = date('Y-m-d H:i:s'); +        $flight->active = 1; +        $flight->url = $location; +        $flight->flight = $params['flight']; +        $flight->save(); +      } +    } + +    $app->response()['Content-type'] = 'application/json'; +    $app->response()->body(json_encode(array( +      'result' => 'ok', +      'location' => $location +    ))); +  } +}); + +$app->get('/flight/:id/:flightID/route.json', function($id, $flightID) use($app) { +  $route = false; + +  $flight = ORM::for_table('flights')->where('id', $id)->find_one(); +  if($flight) { +    $lastPosition = json_decode($flight->lastposition, true); +    if($lastPosition['InFlightInfoResult']['faFlightID'] == $flightID) { + +      // {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-122.638351,45.52217]},"properties":{"date":"2016-01-02T23:13:49Z","altitude":42.666666666667}} + +      $route = [ +        'type' => 'FeatureCollection', +        'features' => [] +      ]; + +      $positions = json_decode($flight->positions, true); +      foreach($positions as $p) { +        $route['features'][] = [ +          'type' => 'Feature', +          'geometry' => [ +            'type' => 'Point', +            'coordinates' => [$p['lng'], $p['lat']] +          ], +          'properties' => [ +            'date' => $p['date'], +            'altitude' => $p['altitude'], +            'heading' => $p['heading'], +            'speed' => $p['speed'] +          ] +        ]; +      } + +    } +  } + +  $app->response()['Content-type'] = 'application/json'; +  $app->response()->body(json_encode($route)); +}); +  $app->get('/photo', function() use($app) {    if($user=require_login($app)) {      $params = $app->request()->params(); | 
