add pdfserver

This commit is contained in:
Andrey Kuvshinov
2020-05-08 21:23:23 +03:00
parent 797ebaa707
commit b384213308
6 changed files with 96 additions and 9 deletions

View File

@@ -3,8 +3,7 @@
"require": {
"php":">=5.3.0",
"masterforweb/kuri":"dev-master",
"masterforweb/db_lite":"dev-master",
"mikehaertl/php-pdftk": "^0.8.0"
"masterforweb/db_lite":"dev-master"
},
"repositories":[

View File

@@ -1,7 +1,7 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
if (isset($_SERVER['HTTP_HOST']))
@@ -14,11 +14,15 @@ else
define('PDFDIR', '/vhosts/anpdf/app/pub/files/pdf/');
define('PGDIR', '/vhosts/anpdf/app/pub/files/pages/');
define('PDFURL', 'pub/files/pdf/');
define('PGURL', 'pub/files/pages/');
define('APPPATH', SITEPATH);
define('VIEWPATH', SITEPATH.'views/');
define('API', 'http://api.argumenti.ru/');
define('IMGSRV', 'https://imgurl.argumenti.ru/');
db_config('argumentiru', 'mysql:host=mysql;dbname=argumentiru', 'newser', 'Chjk90yuiREY');
db_config('reader', 'mysql:host=mysql;dbname=argumentiru', 'reader', 'ghjyjkUIOhg56Fh');
db_config('writer', 'mysql:host=mysql;dbname=argumentiru', 'chitatel', 'hjYu78kl*90Uio');

View File

@@ -8,6 +8,7 @@ require 'routes/price.php';
require 'routes/client.php';
require 'routes/anpdf.php';
require 'routes/auth.php';
require 'routes/pdfserver.php';
#api
require 'api/apiclient.php';

View File

@@ -3,21 +3,33 @@
function anpromo_kuri($page = 1, $scale = 1){
// $pdfile = 'https://argumenti.ru/templinks/md5files/f9598f88e667146d50d106eeedbd74c1.pdf';
$pdfile = '/pub/files/pdf/promo.pdf';
$namefile = 'promo.pdf';
$title = 'Номер 12(706)';
$baseurl = '/';
$newcurr = strtotime('2006-05-12');
$file = SITEPATH.'pub/files/pdf/promo.pdf';
$data = pdfs_init($file);
$pdfile = $data['pdfpgurl'];
$fullpdf = $data['pdfurl'];
$nextpage = $page + 1;
if (file_exists(SITEPATH.$pdfile)){
$filedown = True;
if ($data['count'] > $nextpage){
$nexturl = "$baseurl$nextpage";
}
else {
$nexturl = '';
}
if ($page > 1) {
$prevpage = $page - 1;
$prevurl = "$baseurl$prevpage";
}
$downtitle = 'Если по какой-то причине у вас не загрузилась страница ниже, то нажмите сюда, чтобы скачать pdf';
$baseurl = "/anpromo/";
$pagenum = 1;
@@ -30,7 +42,6 @@ function anpromo_kuri($page = 1, $scale = 1){
function read_kuri($hash, $page = 1, $scale = 1, $promo = false){
$price = db_get("SELECT `price_id`, `pricename`, `BeginDate` FROM `price` WHERE `pricehash` = '$hash' LIMIT 1");
@@ -48,8 +59,6 @@ function read_kuri($hash, $page = 1, $scale = 1, $promo = false){
$newcurr = strtotime($price['BeginDate']);
if (file_exists($cachefile)){
$fullpdf = '/pdf/'.$namefile;
}

72
app/routes/pdfserver.php Normal file
View File

@@ -0,0 +1,72 @@
<?php
function pdfs_filename($pdf){
return basename($source, ".pdf");
}
function pdfs_count($pdf){
$result = exec("pdftk $pdf dump_data | grep NumberOfPages");
return trim(str_replace("NumberOfPages:", '', $result));
}
function pdfs_cachefile($pdf){
$basefile = basename($pdf);
$cachefile = PDFDIR.$basefile;
$cacheurl = PDFURL.$basefile;
if (!file_exists($cachefile)) {
if (copy($pdf, $cachefile))
return $cacheurl;
else
return false;
}
return $cacheurl;
}
function pdfs_init($source, $page = 1){
$result = array();
if (!file_exists($source))
return false;
$result['count'] = pdfs_count($source); // количество страниц
$result['pdfurl'] = pdfs_cachefile($source); //полный файл на скачку
$name = basename($source, ".pdf");
$cachedir = PGDIR.$name.'/';
$cachefile = $name.'-'.$page.'.pdf';
$fullcachefile = $cachedir.$cachefile;
if (!file_exists($fullcachefile)){
if (!is_dir($cachedir))
mkdir($cachedir);
$cmd = "pdftk $source cat 1 output $fullcachefile";
shell_exec($cmd);
}
if (file_exists($fullcachefile))
$result['pdfpgurl'] = PGURL.$name.'/'.$cachefile;
else
return false;
return $result;
}

2
build.sh Normal file
View File

@@ -0,0 +1,2 @@
#!/bin/sh
docker build -t phppdftk .