diff --git a/controllers/controllers.php b/controllers/controllers.php index b1d96c4..4feba3f 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -1085,3 +1085,63 @@ $app->post('/weight', function() use($app) { ))); } }); + + +function create_exercise(&$user, $activity, $minutes, $heartrate, $published) { + $micropub_request = array( + 'type' => ['h-entry'], + 'properties' => [ + 'workout' => [[ + 'type' => ['h-workout'], + 'properties' => [ + 'activity' => [$activity], + 'duration' => [[ + 'type' => ['h-measure'], + 'properties' => [ + 'num' => [($minutes*60)], + 'unit' => ['second'] + ], + ]], + 'heartrate' => [[ + 'type' => 'h-measure', + 'properties' => [ + 'num' => [$heartrate], + 'unit' => ['bpm'], + ] + ]] + ] + ]] + ] + ); + try { + $date = new DateTime($published); + $micropub_request['properties']['published'] = [$date->format('c')]; + } catch(Exception $e) { + } + $r = micropub_post_for_user($user, $micropub_request, null, true); + + return $r; +} + +$app->get('/exercise', function() use($app){ + if($user=require_login($app)) { + render('new-exercise', array( + 'title' => 'New Exercise', + )); + } +}); + +$app->post('/exercise', function() use($app) { + if($user=require_login($app)) { + $params = $app->request()->params(); + + $r = create_exercise($user, $params['activity'], $params['minutes'], $params['heartrate'], $params['published']); + $location = $r['location']; + + $app->response()['Content-type'] = 'application/json'; + $app->response()->body(json_encode(array( + 'location' => $location, + 'error' => $r['error'] + ))); + } +}); diff --git a/views/new-exercise.php b/views/new-exercise.php new file mode 100644 index 0000000..4a451ca --- /dev/null +++ b/views/new-exercise.php @@ -0,0 +1,77 @@ +
+ + +
+ + +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+ +
+ +
+