add 404s, fix markdown appearing in og tags
This commit is contained in:
parent
1d4e214b3e
commit
a6454c0d83
6 changed files with 46 additions and 19 deletions
|
@ -1,7 +1,8 @@
|
|||
<?php if (isset($tag)): ?>
|
||||
<?php /** @noinspection PhpUndefinedVariableInspection */
|
||||
if (isset($tag)): ?>
|
||||
<div class="text tag-text">
|
||||
<h1><?= $tag["Name"] ?></h1>
|
||||
<p class="tag-desc"><?= $tag["Description"] ?></p>
|
||||
<p class="tag-desc"><?= $tag["HTMLDescription"] ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
</h3>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($doc["Description"])): ?>
|
||||
<?php if ($doc["HTMLDescription"]): ?>
|
||||
<p class="doc-description"><span
|
||||
class="doc-description-intro"><?= empty($doc["URL"]) ? "Content" : "Description" ?>
|
||||
: </span><?= $doc["Description"] ?></p>
|
||||
: </span><?= $doc["HTMLDescription"] ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="doc-link"><span class="doc-link-intro">Get print label: </span>
|
||||
|
|
|
@ -107,7 +107,7 @@
|
|||
<div class="label-otherinfo-date">(Published: <?= $doc["Published"] ?>)</div>
|
||||
<?php endif; ?>
|
||||
</h3>
|
||||
<p class="label-description"><?= $doc["Description"] ?></p>
|
||||
<p class="label-description"><?= $doc["HTMLDescription"] ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="label-footer">
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
class PileDB
|
||||
{
|
||||
private $db;
|
||||
protected $db;
|
||||
private $pd;
|
||||
|
||||
function __construct($dbpath = "pile.db")
|
||||
{
|
||||
$this->db = new SQLite3($dbpath);
|
||||
$this->pd = new Parsedown();
|
||||
}
|
||||
|
||||
function prepare($statement)
|
||||
|
@ -59,11 +61,20 @@ class PileDB
|
|||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch pile document as an associative array.
|
||||
*
|
||||
* @throws DocumentNotFoundException when document isn't found.
|
||||
*/
|
||||
public function fetchDoc($id)
|
||||
{
|
||||
$stmt_doc = $this->db->prepare("SELECT * FROM Documents WHERE ID = :id");
|
||||
$stmt_doc->bindValue(":id", $id, SQLITE3_INTEGER);
|
||||
$doc = $stmt_doc->execute()->fetchArray(SQLITE3_ASSOC);
|
||||
if ($doc == false) {
|
||||
throw new DocumentNotFoundException();
|
||||
}
|
||||
$doc["HTMLDescription"] = $this->pd->text($doc["Description"]);
|
||||
|
||||
$stmt_tags = $this->db->prepare("SELECT t.ID, t.Name FROM Tags t
|
||||
JOIN DocumentsToTags dt ON t.ID = dt.Tag
|
||||
|
@ -194,7 +205,9 @@ class PileDB
|
|||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM Tags WHERE ID == :tag");
|
||||
$stmt->bindValue(":tag", $tag, SQLITE3_INTEGER);
|
||||
return $stmt->execute()->fetchArray(SQLITE3_ASSOC);
|
||||
$tag = $stmt->execute()->fetchArray(SQLITE3_ASSOC);
|
||||
$tag["HTMLDescription"] = $this->pd->text($tag["Description"]);
|
||||
return $tag;
|
||||
}
|
||||
|
||||
public function updateTag($id, $name, $description)
|
||||
|
@ -244,4 +257,9 @@ class PileDB
|
|||
}
|
||||
}
|
||||
|
||||
class DocumentNotFoundException extends Exception
|
||||
{
|
||||
// noop
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -4,12 +4,19 @@ require '_util/PileDB.php';
|
|||
require '_vendor/erusev/parsedown/Parsedown.php';
|
||||
|
||||
$db = new PileDB();
|
||||
$pd = new Parsedown();
|
||||
session_start();
|
||||
$page = new Template();
|
||||
|
||||
if (isset($_GET["item"])) {
|
||||
try {
|
||||
$doc = $db->fetchDoc($_GET["item"]);
|
||||
$doc["Description"] = $pd->text($doc["Description"]);
|
||||
} catch (DocumentNotFoundException $e) {
|
||||
http_response_code(404);
|
||||
$page->text = "Document not found.";
|
||||
$page->redirect = "/";
|
||||
echo $page->render("full_text.php");
|
||||
die(0);
|
||||
}
|
||||
|
||||
$doc_template = new Template();
|
||||
$doc_template->doc = $doc;
|
||||
|
@ -27,7 +34,6 @@ if (isset($_GET["item"])) {
|
|||
$tag = $db->findTag($_GET["tag"]);
|
||||
}
|
||||
$docs = $db->listDocs($tag["ID"]);
|
||||
$tag["Description"] = $pd->text($tag["Description"]);
|
||||
$selected_tag = $tag;
|
||||
$doc_list_template->tag = $tag;
|
||||
}
|
||||
|
@ -39,7 +45,6 @@ if (isset($_GET["item"])) {
|
|||
$content = $intro_template->render('front_intro.php');
|
||||
}
|
||||
|
||||
$page = new Template();
|
||||
$page->doc_count = $db->getDocCount();
|
||||
$page->none_count = $db->getUntaggedDocCount();
|
||||
$page->tags = $db->getTags();
|
||||
|
|
|
@ -6,13 +6,16 @@ require '_templates/Template.php';
|
|||
require '_util/PileDB.php';
|
||||
|
||||
|
||||
use Mpdf\Mpdf;
|
||||
|
||||
$db = new PileDB();
|
||||
try {
|
||||
$doc = $db->fetchDoc($_GET["id"]);
|
||||
|
||||
$pd = new Parsedown();
|
||||
$doc["Description"] = $pd->text($doc["Description"]);
|
||||
} catch (DocumentNotFoundException $e) {
|
||||
http_response_code(404);
|
||||
$page->text = "Document not found.";
|
||||
$page->redirect = "/";
|
||||
echo $page->render("full_text.php");
|
||||
die(0);
|
||||
}
|
||||
|
||||
$front = new Template();
|
||||
$front->doc = $doc;
|
||||
|
@ -38,7 +41,7 @@ try {
|
|||
$mpdf->showImageErrors = true;
|
||||
$mpdf->WriteHTML($front->render("_templates/label_template.php"));
|
||||
$mpdf->Output();
|
||||
} catch (\Mpdf\MpdfException $exception) {
|
||||
} catch (Exception $exception) {
|
||||
http_response_code(500); ?>
|
||||
<h1>Something went wrong generating the label.</h1>
|
||||
<pre><?= $exception->getMessage() ?></pre>
|
||||
|
|
Loading…
Reference in a new issue