new logic pdf loaded

This commit is contained in:
Andrey Kuvshinov
2020-05-09 17:19:32 +03:00
parent 7f4b9ec4ef
commit 3d59541651
4 changed files with 101 additions and 49 deletions

View File

@@ -4,16 +4,19 @@ function anpromo_kuri($page = 1, $scale = 1){
// $pdfile = 'https://argumenti.ru/templinks/md5files/f9598f88e667146d50d106eeedbd74c1.pdf';
$namefile = 'promo.pdf';
$title = 'Номер 12(706)';
$baseurl = '/';
$newcurr = strtotime('2006-05-12');
$file = SITEPATH.'pub/files/pdf/promo.pdf';
$data = pdfs_init($file);
$file = SITEPATH.'pub/files/source/742.pdf';
$data = pdfs_init($file, $page);
$pdfile = $data['pdfpgurl'];
$fullpdf = $data['pdfurl'];
$baseurl = "/anpromo/";
$pagenum = 1;
$nextpage = $page + 1;
$filedown = True;
@@ -30,8 +33,7 @@ function anpromo_kuri($page = 1, $scale = 1){
}
$downtitle = 'Если по какой-то причине у вас не загрузилась страница ниже, то нажмите сюда, чтобы скачать pdf';
$baseurl = "/anpromo/";
$pagenum = 1;
$tempcontent = VIEWPATH.'anpdf2.phtml'; //подшаблон
include VIEWPATH.'layout.phtml'; //центральный шаблон
@@ -44,6 +46,8 @@ function anpromo_kuri($page = 1, $scale = 1){
function read_kuri($hash, $page = 1, $scale = 1, $promo = false){
return promo_kuri($hash, $page, false);
$price = db_get("SELECT `price_id`, `pricename`, `BeginDate` FROM `price` WHERE `pricehash` = '$hash' LIMIT 1");
if (!isset($price['price_id'])){
@@ -52,11 +56,14 @@ function read_kuri($hash, $page = 1, $scale = 1, $promo = false){
return False;
}
$file = SITEPATH.'pub/files/source/742.pdf';
$namefile = $hash.'.pdf';
$basepg = PGDIR.$hash.'/'.$hash.'-';
$pgfile = $basepg.$page.'.pdf';
$cachefile = PDFDIR.$namefile;
$newcurr = strtotime($price['BeginDate']);
if (file_exists($cachefile)){
@@ -126,9 +133,9 @@ function text_kuri(){
function promo_kuri($hash, $page = 1, $scale = 2, $promo = false){
function promo_kuri($hash, $page = 1, $promo = true){
return read_kuri($hash, $page, $scale, true);
# test url http://klan.dv/promo/bac343b41b357fdc8243373a429caa62 (742.pdf source)
$price = db_get("SELECT `price_id`, `pricename` FROM `price` WHERE `pricehash` = '$hash' LIMIT 1");
@@ -138,31 +145,56 @@ function promo_kuri($hash, $page = 1, $scale = 2, $promo = false){
return False;
}
$id = $price['price_id'];
$pdfile = "/file/$hash";
$maxpage = 32;
if ($page > 1)
$title = $price['pricename']."- $page";
else
$title = $price['pricename'];
if (!$promo)
$filedown = False;
$file = PDFSOURCE."${price['price_id']}.pdf";
$data = pdfs_init($file, $page);
$baseurl = "/promo/$hash/";
if ($page < $maxpage){
$nextpage = $page + 1;
$nexturl = "$baseurl$nextpage";
}
$pdfile = $data['pdfpgurl'];
$fullpdf = $data['pdfurl'];
$count = $data['count'];
$pagenum = 1;
if ($page > 1) {
$prevpage = $page - 1;
$prevurl = "$baseurl$prevpage";
}
include ('anpdf2.phtml');
if ($promo){
$filedown = True;
$baseurl = "/promo/$hash/";
}
else {
$filedown = True;
$baseurl = "/read/$hash/";
}
$endurl = "$baseurl$count";
if ($count > $page){
$nextpage = $page + 1;
$nexturl = "$baseurl$nextpage";
}
else {
$nexturl = '';
}
if ($page > 1) {
//$title = $price['pricename']." / $page стр.";
$title = $price['pricename'];
$prevpage = $page - 1;
$prevurl = "$baseurl$prevpage";
if (!$promo){
$downtitle = 'Если по какой-то причине у вас не загрузилась страница ниже, то нажмите сюда, чтобы скачать pdf';
}
}
else {
$title = $price['pricename'];
$downtitle = 'Если по какой-то причине у вас не загрузилось издание ниже, то нажмите сюда, чтобы скачать pdf';
}
$tempcontent = VIEWPATH.'anpdf2.phtml'; //подшаблон
include VIEWPATH.'layout.phtml'; //центральный шаблон
}

View File

@@ -1,7 +1,8 @@
<?php
function pdfs_filename($pdf){
function pdfs_basename($pdf){
return basename($source, ".pdf");
}
@@ -13,15 +14,18 @@ function pdfs_count($pdf){
}
function pdfs_hash($pdf){
$basefile = basename($pdf, ".pdf");
return md5($basefile);
}
function pdfs_cachefile($pdf){
$basefile = basename($pdf);
$cachefile = PDFDIR.$basefile;
$cacheurl = PDFURL.$basefile;
$name = pdfs_hash($pdf).'.pdf';
$cachefile = PDFDIR.$name;
$cacheurl = PDFPATH.$name;
if (!file_exists($cachefile)) {
if (copy($pdf, $cachefile))
return $cacheurl;
@@ -46,7 +50,7 @@ function pdfs_init($source, $page = 1){
$result['pdfurl'] = pdfs_cachefile($source); //полный файл на скачку
$name = basename($source, ".pdf");
$name = pdfs_hash($source);
$cachedir = PGDIR.$name.'/';
$cachefile = $name.'-'.$page.'.pdf';
$fullcachefile = $cachedir.$cachefile;
@@ -56,13 +60,13 @@ function pdfs_init($source, $page = 1){
if (!is_dir($cachedir))
mkdir($cachedir);
$cmd = "pdftk $source cat 1 output $fullcachefile";
$cmd = "pdftk $source cat $page output $fullcachefile";
shell_exec($cmd);
}
if (file_exists($fullcachefile))
$result['pdfpgurl'] = PGURL.$name.'/'.$cachefile;
$result['pdfpgurl'] = PGPATH.$name.'/'.$cachefile;
else
return false;