diff --git a/app/Controller.php b/app/Controller.php index ca32294..e8f6c10 100644 --- a/app/Controller.php +++ b/app/Controller.php @@ -212,71 +212,79 @@ public function micropub_refresh(ServerRequestInterface $request, ResponseInterf return $response->withHeader('Content-type', 'application/json'); } - public function timeline(ServerRequestInterface $request, ResponseInterface $response) { + public function timeline(ServerRequestInterface $request, ResponseInterface $response, $args) { $this->requireLogin(); $params = $request->getQueryParams(); - if(preg_match('/\/channel\/(.+)/', $request->getUri()->getPath(), $match)) { - $uid = $match[1]; - $uid = urldecode($uid); - $channel = false; - foreach($_SESSION['channels'] as $ch) { - if($ch['uid'] == $uid) { - $channel = $ch; - break; - } - } + $uid = urldecode($args['uid']); - if(!$channel) { - $response->getBody()->write('The channel "'.e($uid).'" was not found.'); - return $response->withStatus(404); + $channel = false; + foreach($_SESSION['channels'] as $ch) { + if($ch['uid'] == $uid) { + $channel = $ch; + break; } + } - $q = ['channel'=>$uid]; - if(isset($params['after'])) - $q['after'] = $params['after']; + if(!$channel) { + $response->getBody()->write('The channel "'.e($uid).'" was not found.'); + return $response->withStatus(404); + } - $data = microsub_get($_SESSION['microsub'], $_SESSION['token']['access_token'], 'timeline', $q); - $data = json_decode($data['body'], true); + $q = ['channel'=>$uid]; + if(isset($params['after'])) + $q['after'] = $params['after']; - $entries = $data['items'] ?? []; - $paging = $data['paging'] ?? []; + $source = false; + if(isset($args['source'])) { + $q['source'] = $args['source']; + } - $destination = false; - $responses_enabled = false; + $data = microsub_get($_SESSION['microsub'], $_SESSION['token']['access_token'], 'timeline', $q); + $data = json_decode($data['body'], true); - if(isset($_SESSION['micropub'])) { - if(isset($_SESSION['micropub']['config']['destination'])) { - foreach($_SESSION['micropub']['config']['destination'] as $dest) { - // Enable the selected destination if the channel specifies one - if(isset($channel['destination']) && $dest['uid'] == $channel['destination']) { - $destination = $dest; - $responses_enabled = true; - } - } - // If the channel doesn't specify one, use the first in the list - if(!$destination) { - $destination = $_SESSION['micropub']['config']['destination'][0]; + $entries = $data['items'] ?? []; + $paging = $data['paging'] ?? []; + + if(isset($data['source'])) { + $source = $data['source']; + } + + $destination = false; + $responses_enabled = false; + + if(isset($_SESSION['micropub'])) { + if(isset($_SESSION['micropub']['config']['destination'])) { + foreach($_SESSION['micropub']['config']['destination'] as $dest) { + // Enable the selected destination if the channel specifies one + if(isset($channel['destination']) && $dest['uid'] == $channel['destination']) { + $destination = $dest; $responses_enabled = true; } - } else { - // Enable responses if no destinations are configured or channel destination is not "none" - $responses_enabled = !isset($channel['destination']) || $channel['destination'] != 'none'; } + // If the channel doesn't specify one, use the first in the list + if(!$destination) { + $destination = $_SESSION['micropub']['config']['destination'][0]; + $responses_enabled = true; + } + } else { + // Enable responses if no destinations are configured or channel destination is not "none" + $responses_enabled = !isset($channel['destination']) || $channel['destination'] != 'none'; } - - $response->getBody()->write(view('timeline', [ - 'title' => 'Monocle', - 'channel' => $channel, - 'entries' => $entries, - 'paging' => $paging, - 'destination' => $destination, - 'responses_enabled' => $responses_enabled - ])); } + $response->getBody()->write(view('timeline', [ + 'title' => 'Monocle', + 'channel' => $channel, + 'source' => $source, + 'entries' => $entries, + 'paging' => $paging, + 'destination' => $destination, + 'responses_enabled' => $responses_enabled + ])); + return $response; } } diff --git a/public/assets/styles.css b/public/assets/styles.css index dde6e11..400c3e9 100644 --- a/public/assets/styles.css +++ b/public/assets/styles.css @@ -75,6 +75,13 @@ body { background: #555; border-color: #666; } +#side-menu li.selected { + background: #444; +} +#side-menu li.selected:hover { + background: #666; + border-color: #777; +} #side-menu .tag { float: right; } @@ -104,6 +111,12 @@ body { padding-bottom: 50px; } +h3.source-name { + font-size: 20px; + font-weight: bold; + margin-bottom: 9px; +} + #main-bottom { position: fixed; bottom: 0; diff --git a/public/index.php b/public/index.php index 4b1466f..7a43ea4 100644 --- a/public/index.php +++ b/public/index.php @@ -25,6 +25,7 @@ $route->map('GET', '/logout', 'App\\LoginController::logout'); $route->map('GET', '/channel/{uid}', 'App\\Controller::timeline'); +$route->map('GET', '/channel/{uid}/{source}', 'App\\Controller::timeline'); $route->map('POST', '/channels/reload', 'App\\Controller::reload_channels'); $route->map('POST', '/microsub/mark_read', 'App\\Controller::mark_as_read'); $route->map('POST', '/microsub/mark_unread', 'App\\Controller::mark_as_unread'); diff --git a/views/components/channel-list.php b/views/components/channel-list.php index 4fc338f..ccbf69e 100644 --- a/views/components/channel-list.php +++ b/views/components/channel-list.php @@ -1,5 +1,5 @@ -