summaryrefslogtreecommitdiff
path: root/controllers/editor.php
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2017-01-15 09:41:26 -0800
committerAaron Parecki <aaron@parecki.com>2017-01-15 09:41:26 -0800
commit8aa73596e81208a97ba7442833ab94aebed66338 (patch)
tree42eca0b2001f8fa5e052bb61bc777730b769e4a2 /controllers/editor.php
parent3b5e3df19e6e1c000c5c50c4ff79069c1a74e755 (diff)
add publish date field to editor
allows backdating and future-dating posts
Diffstat (limited to 'controllers/editor.php')
-rw-r--r--controllers/editor.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/controllers/editor.php b/controllers/editor.php
index bfe70af..81703f6 100644
--- a/controllers/editor.php
+++ b/controllers/editor.php
@@ -35,6 +35,10 @@ $app->post('/editor/publish', function() use($app) {
$micropub_request['post-status'] = $params['status'];
}
+ if(array_key_exists('publish', $params) && $params['publish'] != 'now') {
+ $micropub_request['published'] = $params['publish'];
+ }
+
$r = micropub_post_for_user($user, $micropub_request);
$app->response()['Content-type'] = 'application/json';
@@ -72,6 +76,35 @@ $app->post('/editor/upload', function() use($app) {
}
});
+$app->post('/editor/parse-date', function() use($app) {
+ $date = false;
+ $params = $app->request()->params();
+ if(isset($params['date'])) {
+ if($params['date'] == 'now') {
+ $date = 'now';
+ } else {
+ try {
+ // Check if the provided date has a timezone offset
+ $has_timezone = preg_match('/[-+]\d\d:?\d\d$/', $params['date']);
+
+ if(!$has_timezone && $params['tzoffset']) {
+ $s = (-60) * $params['tzoffset'];
+ $h = $params['tzoffset'] / (-60);
+ $tz = new DateTimeZone($h);
+ $d = new DateTime($params['date'], $tz);
+ } else {
+ $d = new DateTime($params['date']);
+ }
+ $date = $d->format('c');
+ } catch(Exception $e) {
+ }
+ }
+ }
+
+ $app->response()['Content-type'] = 'application/json';
+ $app->response()->body(json_encode(['date'=>$date]));
+});
+
$app->post('/editor/delete-file', function() use($app) {
$app->response()['Content-type'] = 'application/json';
$app->response()->body(json_encode(['result'=>'deleted']));