add front label generation; update composer

This commit is contained in:
Tomáš Mládek 2019-10-17 17:55:32 +02:00
parent 1c945185b4
commit 53d67187ea
6 changed files with 462 additions and 7 deletions

View file

@ -25,6 +25,9 @@
: </span><?= $doc["Description"] ?></p>
<?php endif; ?>
<div class="doc-link"><span class="doc-link-intro">Get print label: </span>
<a href="/label.php?id=<?= $doc["ID"] ?>">https://pile.sdbs.cz/label.php?id=<?= $doc["ID"] ?></a></div>
<?php if (!empty($doc["URL"])): ?>
<div class="doc-link"><span class="doc-link-intro">Access file at: </span><a
href="<?= $doc["URL"] ?>"><?= urldecode($doc["URL"]) ?></a></div>

View file

@ -0,0 +1,131 @@
<?php /** @noinspection PhpUndefinedVariableInspection */ ?>
<head>
<title>LABEL FOR <?= $doc["Title"] ?></title>
<!--suppress CssNoGenericFontName -->
<style>
body {
font-family: prociono;
font-size: 14px;
}
h1, h2, h3 {
margin: 0;
padding: 0;
}
h1, h2 {
font-size: 24px;
}
.exlibris {
text-align: center;
margin-bottom: 10px;
}
.label-outer {
width: 100%;
border: 5px solid black;
padding: 10px;
}
.label-stamp-outer {
float: left;
width: 150px;
}
#pile-logo {
width: 100%;
margin: 10px 0;
}
.label-stamp {
border: 2px solid black;
margin-right: 10px;
}
.label-stamp-subtitle {
text-align: center;
width: 100%;
margin-bottom: 5px;
font-size: 20px;
margin-top: -9px; /* prociono specific */
}
.label-text {
float: right;
}
.label-title {
margin: 0;
padding: 0;
}
.label-otherinfo {
font-size: 14px;
}
.label-description {
text-align: justify;
margin-top: 0;
padding-top: 0;
}
.label-footer {
width: 100%;
text-align: right;
}
.absolute-footer {
width: 100%;
position: absolute;
text-align: center;
bottom: 20px;
left: 0;
}
</style>
</head>
<body>
<h1 class="exlibris">ex libris /-\ pile</h1>
<div class="label-outer">
<div class="label-upper">
<div class="label-stamp-outer">
<div class="label-column label-stamp">
<img id="pile-logo" src="assets/pile_300dpi.png" alt="/-\ Pile"/>
<div class="label-stamp-subtitle">#<?= str_pad($doc["ID"], 4, "0", STR_PAD_LEFT); ?></div>
</div>
</div>
<div class="label-column label-text">
<h2 class="label-title"><?= $doc["Title"] ?></h2>
<h3 class="label-otherinfo">
<? if ($doc["Author"]): ?>
By <?= $doc["Author"] ?>
<? endif; ?>
<? if ($doc["Published"]): ?>
<div class="label-otherinfo-date">(Published: <?= $doc["Published"] ?>)</div>
<? endif; ?>
</h3>
<p class="label-description"><?= $doc["Description"] ?></p>
</div>
</div>
<div class="label-footer">
<? if (count($doc["tags"]) > 0): ?>
<div class="label-footer-tags">Filed under:
<?php
for ($i = 0; $i < count($doc["tags"]); $i++) {
echo $doc["tags"][$i]["Name"];
}
?>
</div>
<? endif; ?>
<div class="label-footer-url">
Available at: https://pile.sdbs.cz/?item=<?= $doc["ID"] ?>
</div>
</div>
</div>
<div class="absolute-footer">
read or share
</div>
</body>

BIN
www/assets/pile_300dpi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -4,6 +4,7 @@
},
"require": {
"erusev/parsedown": "^1.7",
"mpdf/mpdf": "^8.0",
"ext-sqlite3": "*"
}
}

287
www/composer.lock generated
View file

@ -4,23 +4,24 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f493960dbf3229f8998effb35c5e910d",
"content-hash": "07bcf0ebe745edf9a2aff62e65aae616",
"packages": [
{
"name": "erusev/parsedown",
"version": "1.7.0",
"version": "1.7.3",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown.git",
"reference": "6678d59be48c4be64eaca6ce70bea48a09488cc2"
"reference": "6d893938171a817f4e9bc9e86f2da1e370b7bcd7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/6678d59be48c4be64eaca6ce70bea48a09488cc2",
"reference": "6678d59be48c4be64eaca6ce70bea48a09488cc2",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/6d893938171a817f4e9bc9e86f2da1e370b7bcd7",
"reference": "6d893938171a817f4e9bc9e86f2da1e370b7bcd7",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": ">=5.3.0"
},
"require-dev": {
@ -49,7 +50,277 @@
"markdown",
"parser"
],
"time": "2018-02-28T11:41:37+00:00"
"time": "2019-03-17T18:48:37+00:00"
},
{
"name": "mpdf/mpdf",
"version": "v8.0.2",
"source": {
"type": "git",
"url": "https://github.com/mpdf/mpdf.git",
"reference": "ab0662606cc2396015616633946f3b8918d818a7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mpdf/mpdf/zipball/ab0662606cc2396015616633946f3b8918d818a7",
"reference": "ab0662606cc2396015616633946f3b8918d818a7",
"shasum": ""
},
"require": {
"ext-gd": "*",
"ext-mbstring": "*",
"myclabs/deep-copy": "^1.7",
"paragonie/random_compat": "^1.4|^2.0|9.99.99",
"php": "^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0",
"psr/log": "^1.0",
"setasign/fpdi": "^2.1"
},
"require-dev": {
"mockery/mockery": "^0.9.5",
"mpdf/qrcode": "^1.0.0",
"phpunit/phpunit": "^5.0",
"squizlabs/php_codesniffer": "^2.7.0",
"tracy/tracy": "^2.4"
},
"suggest": {
"ext-bcmath": "Needed for generation of some types of barcodes",
"ext-xml": "Needed mainly for SVG manipulation",
"ext-zlib": "Needed for compression of embedded resources, such as fonts"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-development": "7.x-dev"
}
},
"autoload": {
"psr-4": {
"Mpdf\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-only"
],
"authors": [
{
"name": "Matěj Humpál",
"role": "Developer, maintainer"
},
{
"name": "Ian Back",
"role": "Developer (retired)"
}
],
"description": "PHP library generating PDF files from UTF-8 encoded HTML",
"homepage": "https://mpdf.github.io",
"keywords": [
"pdf",
"php",
"utf-8"
],
"time": "2019-06-17T09:03:49+00:00"
},
{
"name": "myclabs/deep-copy",
"version": "1.9.3",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
"reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea",
"reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea",
"shasum": ""
},
"require": {
"php": "^7.1"
},
"replace": {
"myclabs/deep-copy": "self.version"
},
"require-dev": {
"doctrine/collections": "^1.0",
"doctrine/common": "^2.6",
"phpunit/phpunit": "^7.1"
},
"type": "library",
"autoload": {
"psr-4": {
"DeepCopy\\": "src/DeepCopy/"
},
"files": [
"src/DeepCopy/deep_copy.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Create deep copies (clones) of your objects",
"keywords": [
"clone",
"copy",
"duplicate",
"object",
"object graph"
],
"time": "2019-08-09T12:45:53+00:00"
},
{
"name": "paragonie/random_compat",
"version": "v9.99.99",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95",
"reference": "84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95",
"shasum": ""
},
"require": {
"php": "^7"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*",
"vimeo/psalm": "^1"
},
"suggest": {
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
"keywords": [
"csprng",
"polyfill",
"pseudorandom",
"random"
],
"time": "2018-07-02T15:55:56+00:00"
},
{
"name": "psr/log",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"time": "2018-11-20T15:27:04+00:00"
},
{
"name": "setasign/fpdi",
"version": "v2.2.0",
"source": {
"type": "git",
"url": "https://github.com/Setasign/FPDI.git",
"reference": "3c266002f8044f61b17329f7cd702d44d73f0f7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Setasign/FPDI/zipball/3c266002f8044f61b17329f7cd702d44d73f0f7f",
"reference": "3c266002f8044f61b17329f7cd702d44d73f0f7f",
"shasum": ""
},
"require": {
"ext-zlib": "*",
"php": "^5.6 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "~5.7",
"setasign/fpdf": "~1.8",
"setasign/tfpdf": "1.25",
"tecnickcom/tcpdf": "~6.2"
},
"suggest": {
"setasign/fpdf": "FPDI will extend this class but as it is also possible to use TCPDF or tFPDF as an alternative. There's no fixed dependency configured.",
"setasign/fpdi-fpdf": "Use this package to automatically evaluate dependencies to FPDF.",
"setasign/fpdi-tcpdf": "Use this package to automatically evaluate dependencies to TCPDF.",
"setasign/fpdi-tfpdf": "Use this package to automatically evaluate dependencies to tFPDF."
},
"type": "library",
"autoload": {
"psr-4": {
"setasign\\Fpdi\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jan Slabon",
"email": "jan.slabon@setasign.com",
"homepage": "https://www.setasign.com"
},
{
"name": "Maximilian Kresse",
"email": "maximilian.kresse@setasign.com",
"homepage": "https://www.setasign.com"
}
],
"description": "FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF. Because it is also possible to use FPDI with TCPDF, there are no fixed dependencies defined. Please see suggestions for packages which evaluates the dependencies automatically.",
"homepage": "https://www.setasign.com/fpdi",
"keywords": [
"fpdf",
"fpdi",
"pdf"
],
"time": "2019-01-30T14:11:19+00:00"
}
],
"packages-dev": [],
@ -58,6 +329,8 @@
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform": {
"ext-sqlite3": "*"
},
"platform-dev": []
}

47
www/label.php Normal file
View file

@ -0,0 +1,47 @@
<?php
require '_vendor/autoload.php';
require '_vendor/erusev/parsedown/Parsedown.php';
require '_templates/Template.php';
require '_util/PileDB.php';
use Mpdf\Mpdf;
$db = new PileDB();
$doc = $db->fetchDoc($_GET["id"]);
$pd = new Parsedown();
$doc["Description"] = $pd->text($doc["Description"]);
$front = new Template();
$front->doc = $doc;
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
try {
$mpdf = new \Mpdf\Mpdf([
'format' => 'A4',
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/assets',
]),
'fontdata' => $fontData + [
'prociono' => [
'R' => 'Prociono-Regular.ttf',
]
],
'default_font' => 'prociono'
]);
$mpdf->showImageErrors = true;
$mpdf->WriteHTML($front->render("_templates/label_template.php"));
$mpdf->Output();
} catch (\Mpdf\MpdfException $exception) {
http_response_code(500); ?>
<h1>Something went wrong generating the label.</h1>
<pre><?= $exception->getMessage() ?></pre>
<!-- <pre>--><?// print_r($exception); ?><!--</pre>--><?//
}
?>