Browse Source

query for last checkin and offer as an option in place of geolocation

main
Aaron Parecki 1 year ago
parent
commit
710d27281c
5 changed files with 101 additions and 12 deletions
  1. +20
    -5
      controllers/controllers.php
  2. +27
    -0
      lib/helpers.php
  3. +2
    -0
      schema/migrations/0003.sql
  4. +1
    -0
      schema/schema.sql
  5. +51
    -7
      views/new-post.php

+ 20
- 5
controllers/controllers.php View File

@ -188,9 +188,14 @@ $app->post('/post', function() use($app) {
$entry->user_id = $user->id;
$location = false;
if(k($params, 'location') && $location=parse_geo_uri($params['location'])) {
$entry->latitude = $location['latitude'];
$entry->longitude = $location['longitude'];
if(k($params, 'venue_url')) {
$entry->checkin_url = $params['venue_url'];
} else {
if(k($params, 'location') && $location=parse_geo_uri($params['location'])) {
$entry->latitude = $location['latitude'];
$entry->longitude = $location['longitude'];
}
}
if(k($params,'note_date')) {
@ -253,8 +258,10 @@ $app->post('/post', function() use($app) {
'created' => [$published],
'summary' => [$text_content]
);
$location = k($params, 'location');
if($location) {
if($venue = k($params, 'venue_url')) {
$mp_properties['location'] = [$venue];
} elseif($location = k($params, 'location')) {
$mp_properties['location'] = [$location];
}
if($entry->photo_url) {
@ -340,6 +347,14 @@ $app->get('/micropub/config', function() use($app) {
}
});
$app->get('/micropub/last-checkin', function() use($app){
if($user=require_login($app)) {
$checkin = get_micropub_checkin($user);
$app->response()['Content-type'] = 'application/json';
$app->response()->body(json_encode($checkin));
}
});
$app->get('/options.json', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();

+ 27
- 0
lib/helpers.php View File

@ -195,6 +195,33 @@ function get_micropub_config(&$user) {
);
}
function get_micropub_checkin(&$user) {
$r = micropub_get($user->micropub_endpoint, ['q' => 'source', 'limit' => 1, 'post-type' => 'checkin'], $user->access_token);
$url = null;
$name = null;
$lat = null;
$lng = null;
if($r['data'] && is_array($r['data'])) {
if(isset($r['data']['items'][0]['properties']['checkin'][0]) &&
isset($r['data']['items'][0]['properties']['checkin'][0]['properties']['name'][0])) {
$checkin = $r['data']['items'][0]['properties']['checkin'][0];
$url = $r['data']['items'][0]['properties']['url'][0];
$name = $checkin['properties']['name'][0];
$lat = $checkin['properties']['latitude'][0];
$lng = $checkin['properties']['longitude'][0];
}
}
return [
'url' => $url,
'name' => $name,
'lat' => $lat,
'lng' => $lng,
];
}
function build_static_map_url($latitude, $longitude, $height, $width, $zoom) {
return '/map.png?marker[]=lat:' . $latitude . ';lng:' . $longitude . ';icon:small-green-cutout&width=' . $width . '&height=' . $height . '&zoom=' . $zoom;
}

+ 2
- 0
schema/migrations/0003.sql View File

@ -0,0 +1,2 @@
ALTER TABLE entries
ADD COLUMN `checkin_url` VARCHAR(512) NOT NULL DEFAULT '' AFTER `longitude`;

+ 1
- 0
schema/schema.sql View File

@ -29,6 +29,7 @@ CREATE TABLE `entries` (
`tz_offset` int(11) DEFAULT NULL,
`latitude` double DEFAULT NULL,
`longitude` double DEFAULT NULL,
`checkin_url` varchar(512) NOT NULL DEFAULT '',
`type` enum('eat','drink') DEFAULT NULL,
`content` text,
`canonical_url` varchar(255) DEFAULT NULL,

+ 51
- 7
views/new-post.php View File

@ -33,17 +33,26 @@
<div id="entry-buttons">
</div>
<div class="form-group">
<h3>Location <input type="checkbox" id="note_location_chk" value=""><img src="/images/spinner.gif" id="note_location_loading" style="display: none;"></h3>
<input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
<input type="hidden" id="note_location" name="location">
<input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
<div class="hidden" id="note_venue">
<input type="url" id="note_venue_url" name="venue_url" class="hidden">
<ul class="entry-buttons">
<li><input type="button" class="btn btn-default name"></li>
</ul>
</div>
<div id="note_location_img" style="display: none;">
<img src="" height="180" id="note_location_img_wide" class="img-responsive">
<img src="" height="320" id="note_location_img_small" class="img-responsive">
<div id="note_location_fields">
<input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
<input type="hidden" id="note_location" name="location">
<input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
<div id="note_location_img" style="display: none;">
<img src="" height="180" id="note_location_img_wide" class="img-responsive">
<img src="" height="320" id="note_location_img_small" class="img-responsive">
</div>
</div>
</div>
@ -296,6 +305,41 @@ $(function(){
}
});
var last_checkin = false;
function fetch_last_checkin() {
$.get("/micropub/last-checkin", function(data){
if(data.url) {
$("#note_venue").removeClass("hidden");
$("#note_venue .name").val(data.name);
last_checkin = data;
bind_venue_buttons();
}
});
}
function bind_venue_buttons() {
$("#note_venue .entry-buttons li input").click(function(){
if($(this).hasClass("btn-primary")) {
// Disable venue tag
$(this).addClass("btn-default").removeClass("btn-primary");
$("#note_venue_url").val("");
fetch_location();
} else {
// Enable venue tag
$(this).addClass("btn-primary").removeClass("btn-default");
$("#note_venue_url").val(last_checkin.url);
$("#note_location_msg").val(last_checkin.url);
$("#note_location_img_small").attr("src", "");
$("#note_location_img_wide").attr("src", "");
$("#note_location_img_small").attr("src", map_template_small.replace('{lat}', last_checkin.lat).replace('{lng}', last_checkin.lng));
$("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', last_checkin.lat).replace('{lng}', last_checkin.lng));
}
});
}
fetch_last_checkin();
});
</script>

Loading…
Cancel
Save