From 3310a85ac8f276ad270388a4242b623f30abe74d Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 15 Jan 2017 08:07:54 -0800 Subject: store the user's timezone after their location is found --- composer.json | 3 +- composer.lock | 73 +++++++++++++++++++++++++++++++++++---------- controllers/controllers.php | 19 ++++++++++++ public/index.php | 1 + schema/migrations/0003.sql | 2 ++ schema/mysql.sql | 3 +- views/new-post.php | 5 ++++ 7 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 schema/migrations/0003.sql diff --git a/composer.json b/composer.json index fc6ad33..08f960c 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "abraham/twitteroauth": "*", "andreyco/instagram": "3.*", "p3k/multipart": "*", - "tantek/cassis": "*" + "tantek/cassis": "*", + "p3k/timezone": "*" }, "autoload": { "files": [ diff --git a/composer.lock b/composer.lock index 169e3ff..ec0f1ff 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "4756e7ef0035b8f768f07d252adbdc17", - "content-hash": "f4709cc6bd166e3759fbedbfbaa7752e", + "content-hash": "4ec77b1fe4974da5d6a392ec0d362858", "packages": [ { "name": "abraham/twitteroauth", @@ -59,7 +58,7 @@ "social", "twitter" ], - "time": "2016-12-12 17:42:13" + "time": "2016-12-12T17:42:13+00:00" }, { "name": "andreyco/instagram", @@ -102,7 +101,7 @@ "api", "instagram" ], - "time": "2016-07-17 23:42:10" + "time": "2016-07-17T23:42:10+00:00" }, { "name": "barnabywalters/mf-cleaner", @@ -142,7 +141,7 @@ } ], "description": "Cleans up microformats2 array structures", - "time": "2014-10-06 23:11:15" + "time": "2014-10-06T23:11:15+00:00" }, { "name": "firebase/php-jwt", @@ -186,7 +185,7 @@ ], "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", "homepage": "https://github.com/firebase/php-jwt", - "time": "2015-06-22 23:26:39" + "time": "2015-06-22T23:26:39+00:00" }, { "name": "indieauth/client", @@ -225,7 +224,7 @@ } ], "description": "IndieAuth Client Library", - "time": "2016-02-08 23:56:31" + "time": "2016-02-08T23:56:31+00:00" }, { "name": "indieweb/date-formatter", @@ -268,7 +267,7 @@ "microformats", "microformats2" ], - "time": "2015-10-28 00:32:39" + "time": "2015-10-28T00:32:39+00:00" }, { "name": "indieweb/link-rel-parser", @@ -314,7 +313,7 @@ "indieweb", "microformats2" ], - "time": "2013-12-23 00:14:58" + "time": "2013-12-23T00:14:58+00:00" }, { "name": "indieweb/mention-client", @@ -353,7 +352,7 @@ ], "description": "Client library for sending webmention and pingback notifications", "homepage": "https://github.com/indieweb/mention-client-php", - "time": "2015-04-03 11:21:06" + "time": "2015-04-03T11:21:06+00:00" }, { "name": "j4mie/idiorm", @@ -411,7 +410,7 @@ "orm", "query builder" ], - "time": "2013-12-12 10:25:27" + "time": "2013-12-12T10:25:27+00:00" }, { "name": "mf2/mf2", @@ -464,7 +463,7 @@ "parser", "semantic" ], - "time": "2015-07-12 14:10:01" + "time": "2015-07-12T14:10:01+00:00" }, { "name": "mpratt/relativetime", @@ -512,7 +511,7 @@ "time", "time-ago" ], - "time": "2015-12-24 12:43:04" + "time": "2015-12-24T12:43:04+00:00" }, { "name": "p3k/multipart", @@ -548,7 +547,49 @@ } ], "description": "Multipart Encoding Library", - "time": "2015-07-16 19:28:02" + "time": "2015-07-16T19:28:02+00:00" + }, + { + "name": "p3k/timezone", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/aaronpk/p3k-timezone.git", + "reference": "68d3490d896f98cf0727dc937f0bb6b045050c83" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/aaronpk/p3k-timezone/zipball/68d3490d896f98cf0727dc937f0bb6b045050c83", + "reference": "68d3490d896f98cf0727dc937f0bb6b045050c83", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "type": "library", + "autoload": { + "files": [ + "src/p3k/Timezone.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Aaron Parecki", + "homepage": "https://aaronparecki.com" + } + ], + "description": "Find the timezone of a given location", + "homepage": "https://github.com/aaronpk/p3k-timezone", + "keywords": [ + "date", + "p3k", + "timezone" + ], + "time": "2017-01-12T17:30:08+00:00" }, { "name": "saltybeagle/savant3", @@ -626,7 +667,7 @@ "rest", "router" ], - "time": "2012-12-13 02:15:50" + "time": "2012-12-13T02:15:50+00:00" }, { "name": "tantek/cassis", @@ -649,7 +690,7 @@ ] }, "notification-url": "https://packagist.org/downloads/", - "time": "2016-04-04 15:31:04" + "time": "2016-04-04T15:31:04+00:00" } ], "packages-dev": [], diff --git a/controllers/controllers.php b/controllers/controllers.php index 4de4aee..505589f 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -213,6 +213,25 @@ $app->post('/prefs', function() use($app) { ))); }); +$app->post('/prefs/timezone', function() use($app) { + // Called when the interface finds the user's location. + // Look up the timezone for this location and store it as their default. + $timezone = false; + if($user=require_login($app)) { + $params = $app->request()->params(); + $timezone = p3k\Timezone::timezone_for_location($params['latitude'], $params['longitude']); + if($timezone) { + $user->default_timezone = $timezone; + $user->save(); + } + } + $app->response()['Content-type'] = 'application/json'; + $app->response()->body(json_encode(array( + 'result' => 'ok', + 'timezone' => $timezone, + ))); +}); + $app->get('/add-to-home', function() use($app) { $params = $app->request()->params(); header("Cache-Control: no-cache, must-revalidate"); diff --git a/public/index.php b/public/index.php index 0909780..bca3b43 100644 --- a/public/index.php +++ b/public/index.php @@ -13,6 +13,7 @@ $app = new \Slim\Slim(array( require 'controllers/auth.php'; require 'controllers/controllers.php'; +require 'controllers/micropub.php'; require 'controllers/static.php'; require 'controllers/editor.php'; require 'controllers/hooks.php'; diff --git a/schema/migrations/0003.sql b/schema/migrations/0003.sql new file mode 100644 index 0000000..43b72f7 --- /dev/null +++ b/schema/migrations/0003.sql @@ -0,0 +1,2 @@ +ALTER TABLE users +ADD COLUMN `default_timezone` VARCHAR(255); diff --git a/schema/mysql.sql b/schema/mysql.sql index 610b01b..31f10fd 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -21,6 +21,7 @@ CREATE TABLE `users` ( `twitter_token_secret` text, `twitter_username` varchar(255) DEFAULT NULL, `instagram_access_token` text, - `email_username` varchar(255) DEFAULT NULL, + `email_username` vacrchar(255) DEFAULT NULL, + `default_timezone` vacrchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/views/new-post.php b/views/new-post.php index de56ddb..434f54e 100644 --- a/views/new-post.php +++ b/views/new-post.php @@ -532,6 +532,11 @@ $(function(){ $("#note_location_img").show(); $("#note_location_msg").addClass("img-visible"); + $.post("/prefs/timezone", { + latitude: position.coords.latitude, + longitude: position.coords.longitude + }); + }, function(err){ if(err.code == 1) { location_error("The website was not able to get permission"); -- cgit v1.2.3