Browse Source

enable opt-in to new h-food format

disable appcache
pull/10/head
Aaron Parecki 8 years ago
parent
commit
fe65066b2d
3 changed files with 47 additions and 16 deletions
  1. +25
    -7
      controllers/controllers.php
  2. +1
    -2
      views/appcache.php
  3. +21
    -7
      views/new-post.php

+ 25
- 7
controllers/controllers.php View File

@ -80,12 +80,20 @@ $app->get('/new', function() use($app) {
'tz_offset' => $tz_offset,
'date_str' => $date_str,
'time_str' => $time_str,
'enable_appcache' => true
'enable_array_micropub' => $user->enable_array_micropub
));
$app->response()->body($html);
}
});
$app->post('/prefs/enable-h-food', function() use($app){
if($user=require_login($app)) {
$user->enable_array_micropub = 1;
$user->save();
}
$app->redirect('/new', 302);
});
$app->post('/prefs', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();
@ -136,7 +144,7 @@ $app->get('/add-to-home', function() use($app) {
if($user=require_login($app)) {
if(array_key_exists('start', $params)) {
$_SESSION['add-to-home-started'] = true;
$token = JWT::encode(array(
'user_id' => $_SESSION['user_id'],
'me' => $_SESSION['me'],
@ -189,7 +197,7 @@ $app->post('/post', function() use($app) {
$now = new DateTime();
$now->setTimeZone(new DateTimeZone($entry->timezone));
$published = $now->format('c');
}
}
}
@ -228,11 +236,21 @@ $app->post('/post', function() use($app) {
$mp_request = array(
'h' => 'entry',
'published' => $published,
'p3k-food' => $entry->content,
'p3k-type' => $type,
'created' => $published,
'location' => k($params, 'location'),
'summary' => $text_content
);
if($user->enable_array_micropub) {
$mp_request[$verb] = [
'type' => 'h-food',
'properties' => [
'name' => $entry->content
]
];
} else {
$mp_request['p3k-food'] = $entry->content;
$mp_request['p3k-type'] = $type;
}
$r = micropub_post($user->micropub_endpoint, $mp_request, $user->access_token);
$request = $r['request'];
@ -289,12 +307,14 @@ $app->get('/map.png', function() use($app) {
$app->response()->body($img);
});
/*
$app->get('/teacup.appcache', function() use($app) {
$content = partial('appcache');
$app->response()['Content-type'] = 'text/cache-manifest';
$app->response()->body($content);
});
*/
$app->get('/:domain', function($domain) use($app) {
$params = $app->request()->params();
@ -372,5 +392,3 @@ $app->get('/:domain/:entry', function($domain, $entry_id) use($app) {
'domain' => '[a-zA-Z0-9\.-]+\.[a-z]+',
'entry' => '\d+'
));

+ 1
- 2
views/appcache.php View File

@ -1,5 +1,4 @@
CACHE MANIFEST
/new
/bootstrap/css/bootstrap.min.css
/bootstrap/css/bootstrap-theme.css
/bootstrap/css/bootstrap-theme.css.map
@ -12,4 +11,4 @@ CACHE MANIFEST
NETWORK:
*
# v29
# v31

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

@ -5,7 +5,7 @@
<div class="form-group">
<h3>Date</h3>
<input type="date" class="form-control" style="max-width:160px; float:left; margin-right: 4px;" id="note_date" name="note_date" value="">
<input type="text" class="form-control" style="max-width:85px; float:left; margin-right: 4px;" id="note_time" name="note_time" value="">
<input type="text" class="form-control" style="max-width:75px;" id="note_tzoffset" name="note_tzoffset" value="">
@ -26,7 +26,7 @@
<img src="" height="320" id="note_location_img_small" class="img-responsive">
</div>
</div>
</form>
<?php if($this->micropub_endpoint): ?>
@ -51,6 +51,19 @@
<td>access token</td>
<td class="break">String of length <b><?= strlen($this->access_token) ?></b><?= (strlen($this->access_token) > 0) ? (', ending in <code>' . substr($this->access_token, -7) . '</code>') : '' ?> (should be greater than length 0)</td>
</tr>
<?php if($this->enable_array_micropub): ?>
<tr>
<td>ate or drank</td>
<td class="break">
<p>The parameter named <code>ate</code> or <code>drank</code> will include an <code>h-food</code> object corresponding to the item you tapped.</p>
<pre>ate[type]=h-food&amp;ate[properties][name]=Coffee</pre>
</td>
</tr>
<?php else: ?>
<tr>
<td>h-food</td>
<td class="break"><form action="/prefs/enable-h-food" method="post"><input type="submit" class="btn btn-default" value="Switch to new h-food format"></form></td>
</tr>
<tr>
<td>p3k-food</td>
<td class="break">The button you tap (or your custom text) will be sent to your Micropub endpoint in a field named <code>p3k-food</code></td>
@ -59,6 +72,7 @@
<td>p3k-type</td>
<td class="break">Will be either <code>drink</code> or <code>eat</code> depending on the type of entry</td>
</tr>
<?php endif; ?>
</table>
</div>
</div>
@ -133,14 +147,14 @@ $(function(){
} else if(err.code == 3) {
location_error("Timed out getting location");
}
// Load the entry buttons with no location context
load_entry_buttons();
});
}
function set_location_enabled(enabled) {
localforage.setItem('location-enabled', {enabled: enabled});
localforage.setItem('location-enabled', {enabled: enabled});
}
function get_location_enabled(callback) {
localforage.getItem('location-enabled', function(err,val){
@ -176,7 +190,7 @@ $(function(){
}
});
// This loads the buttons with or without location
// This loads the buttons with or without location
function load_entry_buttons(coords) {
var latitude = coords ? coords.latitude : '';
var longitude = coords ? coords.longitude : '';
@ -216,13 +230,13 @@ $(function(){
function onUpdateReady() {
// Show the notice that says there is a new version of the app
$("#new_version_available").show();
$("#new_version_available").show();
}
window.applicationCache.addEventListener('updateready', onUpdateReady);
if(window.applicationCache.status === window.applicationCache.UPDATEREADY) {
onUpdateReady();
}
}
});

Loading…
Cancel
Save