Skip to content

Commit

Permalink
enables clicking on an author name to show posts from that source
Browse files Browse the repository at this point in the history
more discussion: indieweb/microsub#21
  • Loading branch information
aaronpk committed Apr 15, 2019
1 parent 1d4f772 commit c23899c
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 53 deletions.
102 changes: 55 additions & 47 deletions app/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
13 changes: 13 additions & 0 deletions public/assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion views/components/channel-list.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php foreach($_SESSION['channels'] as $channel): ?>
<li data-channel-uid="<?= e($channel['uid']) ?>">
<li data-channel-uid="<?= e($channel['uid']) ?>" class="<?= $selected == $channel['uid'] ? 'selected' : '' ?>">
<a href="/channel/<?= e(urlencode($channel['uid'])) ?>">
<?= e($channel['name']) ?>
<?php if(isset($channel['unread'])): ?>
Expand Down
18 changes: 15 additions & 3 deletions views/timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,32 @@
<div id="main-top">
<label for="nav-trigger" id="nav-trigger-label"></label>
<h2 class="title">
<?= $channel['name'] ?>
<? if($source): ?>
<a href="/channel/<?= e($channel['uid']) ?>"><?= e($channel['name']) ?></a>
<? else: ?>
<?= e($channel['name']) ?>
<? endif ?>
</h2>
</div>


<nav id="side-menu">
<ul class="channels channel-list">
<?= $this->insert('components/channel-list') ?>
<?= $this->insert('components/channel-list', ['selected' => $channel['uid']]) ?>
</ul>
</nav>

<div id="main-container">

<div class="column"><div class="inner">

<? if($source): ?>
<h3 class="source-name">
<a href="/channel/<?= e($channel['uid']) ?>"><i class="fa fa-arrow-circle-left"></i></a>
<?= e($source['name']) ?>
</h3>
<? endif ?>

<? foreach($entries as $i=>$entry): ?>
<div class="entry h-entry <?= isset($entry['like-of']) ? 'like-of' : '' ?> <?= isset($entry['_is_read']) && $entry['_is_read'] == 0 ? 'unread' : 'read' ?>" data-entry="<?= $i ?>" data-entry-id="<?= e($entry['_id']) ?>"
data-is-read="<?= isset($entry['_is_read']) ? ($entry['_is_read'] ? 1 : 0) : 1 ?>">
Expand Down Expand Up @@ -65,7 +77,7 @@

<?= $this->insert('timeline/reply-context', ['entry' => $entry]) ?>

<?= $this->insert('timeline/author-card', ['entry' => $entry]) ?>
<?= $this->insert('timeline/author-card', ['entry' => $entry, 'channel' => $channel]) ?>

<? /* ************************************************ */ ?>
<? /* POST CONTENTS */ ?>
Expand Down
4 changes: 2 additions & 2 deletions views/timeline/author-card.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="author u-author h-card">
<? if(!empty($entry['author']['photo'])): ?>
<img src="<?= e($entry['author']['photo']) ?>" class="u-photo">
<a href="/channel/<?= e($channel['uid']) ?>/<?= e($entry['_source']) ?>"><img src="<?= e($entry['author']['photo']) ?>" class="u-photo"></a>
<? endif ?>
<? if(!empty($entry['author']['name']) || !empty($entry['author']['url'])): ?>
<div class="author-name">
<? if(!empty($entry['author']['url'])): ?>
<? if(!empty($entry['author']['name'])): ?>
<a href="<?= e($entry['author']['url']) ?>" class="name p-name"><?= e($entry['author']['name']) ?></a>
<a href="/channel/<?= e($channel['uid']) ?>/<?= e($entry['_source']) ?>" class="name p-name"><?= e($entry['author']['name']) ?></a>
<? endif ?>
<a href="<?= e($entry['author']['url']) ?>" class="url u-url"><?= e(\p3k\url\display_url($entry['author']['url'])) ?></a>
<? elseif(!empty($entry['author']['name'])): ?>
Expand Down

0 comments on commit c23899c

Please sign in to comment.