diff --git a/controllers/controllers.php b/controllers/controllers.php index dc18584..0de366b 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -1,6 +1,21 @@ request()->params(); + if(array_key_exists('token', $params)) { + try { + $data = JWT::decode($params['token'], Config::$jwtSecret); + $_SESSION['user_id'] = $data->user_id; + $_SESSION['me'] = $data->me; + } catch(DomainException $e) { + header('X-Error: DomainException'); + $app->redirect('/', 301); + } catch(UnexpectedValueException $e) { + header('X-Error: UnexpectedValueException'); + $app->redirect('/', 301); + } + } + if(!array_key_exists('user_id', $_SESSION)) { $app->redirect('/'); return false; @@ -9,6 +24,14 @@ function require_login(&$app) { } } +function generate_login_token() { + return JWT::encode(array( + 'user_id' => $_SESSION['user_id'], + 'me' => $_SESSION['me'], + 'created_at' => time() + ), Config::$jwtSecret); +} + $app->get('/new', function() use($app) { if($user=require_login($app)) { @@ -26,7 +49,7 @@ $app->get('/new', function() use($app) { } } - $html = render('dashboard', array( + $html = render('new-post', array( 'title' => 'New Post', 'micropub_endpoint' => $user->micropub_endpoint, 'micropub_scope' => $user->micropub_scope, @@ -40,6 +63,38 @@ $app->get('/new', function() use($app) { } }); + +$app->get('/bookmark', function() use($app) { + if($user=require_login($app)) { + $params = $app->request()->params(); + + $url = ''; + $name = ''; + $content = ''; + $tags = ''; + + if(array_key_exists('url', $params)) + $url = $params['url']; + + if(array_key_exists('name', $params)) + $name = $params['name']; + + if(array_key_exists('content', $params)) + $content = $params['content']; + + $html = render('new-bookmark', array( + 'title' => 'New Bookmark', + 'bookmark_url' => $url, + 'bookmark_name' => $name, + 'bookmark_content' => $content, + 'bookmark_tags' => $tags, + 'token' => generate_login_token(), + 'syndication_targets' => json_decode($user->syndication_targets, true) + )); + $app->response()->body($html); + } +}); + $app->post('/prefs', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); diff --git a/lib/helpers.php b/lib/helpers.php index 60eda75..cf751c6 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -27,6 +27,10 @@ function partial($template, $data=array(), $debug=false) { return ob_get_clean(); } +function js_bookmarklet($partial, $context) { + return str_replace('+','%20',urlencode(str_replace(array("\n"),array(''),partial($partial, $context)))); +} + function session($key) { if(array_key_exists($key, $_SESSION)) return $_SESSION[$key]; diff --git a/public/css/style.css b/public/css/style.css index 7872e7e..7cb152c 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -109,3 +109,84 @@ body { word-break: break-all; word-wrap: break-word; } + + + + + /* new posts */ + + #syndication-container ul { + list-style-type: none; + margin: 0; + padding: 10px; + } + #syndication-container li { + padding: 0; + margin-bottom: 6px; + } + #syndication-container button { + max-width: 240px; + text-shadow: none; + } + #syndication-container button img { + float: left; + margin-left: 10px; + } + + #last_response_date { + font-size: 80%; + font-weight: normal; + } + + #btn_post { + margin-bottom: 10px; + } + + @media all and (max-width: 480px) { + #note_location_img_wide { + display: none; + } + #note_location_img_small { + display: block; + } + } + @media all and (min-width: 480px) { + #note_location_img_wide { + display: block; + } + #note_location_img_small { + display: none; + } + } + + .img-visible { + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + } + + #note_location_img img { + margin-top: -1px; + border: 1px solid #ccc; + -webkit-border-bottom-right-radius: 4px; + -webkit-border-bottom-left-radius: 4px; + -moz-border-radius-bottomright: 4px; + -moz-border-radius-bottomleft: 4px; + border-bottom-right-radius: 4px; + border-bottom-left-radius: 4px; + } + + .callout { + border-left: 4px #5bc0de solid; + background-color: #f4f8fa; + padding: 20px; + margin-top: 10px; + } + .callout table { + margin-bottom: 0; + } + + diff --git a/views/layout.php b/views/layout.php index 3d181e4..531dec9 100644 --- a/views/layout.php +++ b/views/layout.php @@ -57,6 +57,7 @@ if(session('me')) { ?>