add "recent additions" to homepage; add rss feed

https://pile.sdbs.cz/feed.php
This commit is contained in:
Tomáš Mládek 2019-09-19 15:59:06 +02:00 committed by Tomáš Mládek
parent 257be83d9b
commit 0d6a15f06c
7 changed files with 94 additions and 2 deletions

View file

@ -0,0 +1 @@
ALTER TABLE Documents ADD UploadedTime INTEGER;

View file

@ -5,4 +5,24 @@
<p class="intro czech">Tohle je hromádka zajímavýho materiálu co něco znamená v kontextu sdbs - budeme sem postupně
dávat ty nejdůležitější nebo nejzajímavější věci, zatim se o tom ale nikde moc nešiřte.</p>
<p class="intro sign">/-\</p>
</div>
<div class="text recent-additions">
<h2>Recent additions</h2>
<ul>
<?php foreach (array_slice($recent_docs, 0, 5) as $doc): ?>
<li>
<a href="/?item=<?= $doc['ID'] ?>">
<?php if (!empty($doc['UploadedTime'])): ?>
<em>(<?= date("Y/m/d H:i:s", $doc['UploadedTime']); ?>)</em>
<?php endif; ?>
<?= $doc['Title'] ?>
<div class="recent-additions-desc">
<?= $doc['Description'] ?>
</div>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>

View file

@ -113,13 +113,27 @@ class PileDB
return $docs;
}
public function getRecentDocs($count = 15)
{
$query = $this->db->prepare("SELECT * FROM Documents ORDER BY ID DESC LIMIT :count");
$query->bindValue("count", $count);
$query_ret = $query->execute();
$result = [];
while ($row = $query_ret->fetchArray(SQLITE3_ASSOC)) {
array_push($result, $row);
}
return $result;
}
public function updateDoc($id, $title, $author, $description, $published, $url, $tag_ids)
{
if (empty($id)) {
$stmt = $this->db->prepare("INSERT INTO Documents
(ID, Title, Author, Description, Published, URL)
(ID, Title, Author, Description, Published, URL, UploadedTime)
VALUES
(NULL, :title, :author, :description, :published, :url)");
(NULL, :title, :author, :description, :published, :url, :uploadedtime)");
$stmt->bindValue(":uploadedtime", time(), SQLITE3_INTEGER);
} else {
$stmt = $this->db->prepare("UPDATE Documents SET
Title=:title,

View file

@ -23,6 +23,19 @@ a {
text-decoration: none;
}
ul {
padding-left: 20px;
}
ul > li {
list-style: none;
}
ul > li:before {
content: "—";
padding-right: .5rem;
}
#sidebar {
font-family: Prociono, serif;
}
@ -64,6 +77,7 @@ a {
#sidebar-taglist > ul > li:before {
content: "/ ";
padding-right: 0;
}
#sidebar-taglist-top:before {
@ -175,6 +189,22 @@ a {
}
}
.recent-additions li {
margin-bottom: .5em;
}
.recent-additions-desc {
font-size: 12pt;
color: #bfbfbf;
padding-left: calc(20px + .5rem);
line-height: 13pt;
max-height: 26pt;
overflow: hidden;
text-overflow: ellipsis;
}
@media screen and (max-width: 64em ) {
#sidebar-head {
display: flex;

26
www/feed.php Normal file
View file

@ -0,0 +1,26 @@
<?php
require '_util/PileDB.php';
$db = new PileDB();
$recent_docs = $db->getRecentDocs();
header('Content-Type: application/rss+xml');
?>
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>/-\ pile</title>
<link>https://pile.sdbs.cz</link>
<atom:link href="https://pile.sdbs.cz/feed.php" rel="self" type="application/rss+xml" />
<description>A pile of interesting documents.</description>
<?php foreach ($recent_docs as $doc): ?>
<item>
<title><?= $doc['Title'] ?></title>
<link><?= $doc['URL'] ?></link>
<guid>https://pile.sdbs.cz/?item=<?= $doc['ID'] ?></guid>
<description><?= $doc['Description'] ?></description>
</item>
<?php endforeach; ?>
</channel>
</rss>

View file

@ -33,6 +33,7 @@ if (isset($_GET["item"])) {
$content = $doc_list_template->render('front_doc_listing.php');
} else {
$intro_template = new Template();
$intro_template->recent_docs = $db->getRecentDocs();
$content = $intro_template->render('front_intro.php');
}