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

@@ -12,10 +12,18 @@ if (isset($_SERVER['HTTP_HOST']))
else
define('SITEPATH', dirname(__FILE__));
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/');
if (SITE == 'http://klan.argumenti.ru/')
define('PDFSOURCE', '/vhosts/an/httpdocs/pub/files/pdf/pdf/');
else
define('PDFSOURCE', SITEPATH.'pub/files/source/');
define('PDFPATH', '/pub/files/pdf/');
define('PGPATH', '/pub/files/pages/');
define('PDFDIR', SITEPATH.PDFPATH);
define('PGDIR', SITEPATH.PGPATH);
define('APPPATH', SITEPATH);
define('VIEWPATH', SITEPATH.'views/');

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,6 +56,8 @@ 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';
@@ -59,6 +65,7 @@ function read_kuri($hash, $page = 1, $scale = 1, $promo = false){
$newcurr = strtotime($price['BeginDate']);
if (file_exists($cachefile)){
$fullpdf = '/pdf/'.$namefile;
}
@@ -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;
$file = PDFSOURCE."${price['price_id']}.pdf";
$data = pdfs_init($file, $page);
if ($page > 1)
$title = $price['pricename']."- $page";
else
$title = $price['pricename'];
$pdfile = $data['pdfpgurl'];
$fullpdf = $data['pdfurl'];
$count = $data['count'];
$pagenum = 1;
if (!$promo)
$filedown = False;
$baseurl = "/promo/$hash/";
if ($promo){
$filedown = True;
$baseurl = "/promo/$hash/";
}
else {
$filedown = True;
$baseurl = "/read/$hash/";
}
if ($page < $maxpage){
$endurl = "$baseurl$count";
if ($count > $page){
$nextpage = $page + 1;
$nexturl = "$baseurl$nextpage";
}
$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'; //центральный шаблон
if ($page > 1) {
$prevpage = $page - 1;
$prevurl = "$baseurl$prevpage";
}
include ('anpdf2.phtml');
}

View File

@@ -1,7 +1,8 @@
<?php
function pdfs_filename($pdf){
function pdfs_basename($pdf){
return basename($source, ".pdf");
}
@@ -13,14 +14,17 @@ 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))
@@ -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;

View File

@@ -1,7 +1,7 @@
<script>
var pdfDoc = null,
pageNum = <?=$pagenum?>,
scale = <?=$scale?>,
scale = 1,
url = '<?=$pdfile?>',
pageRendering = false,
pageNumPending = null,
@@ -11,10 +11,10 @@
</script>
<p id="downloadtitle">
<?if ($filedown):?>
<a href="<?=$fullpdf?>"><?=$downtitle?></a><span id="downarrow"></span>
<?else:?>
<?if ($promo):?>
<a href="https://argumenti.ru/robomail/486?utm_source=argumenti.ru&utm_medium=subscript&utm_campaign=promo">Получайте «Газету на @email»</a>
<?else:?>
<a href="<?=$fullpdf?>"><?=$downtitle?></a><span id="downarrow"></span>
<?endif?>
</p>
@@ -33,6 +33,7 @@
</div>
<div id="pagenav">
<?if (isset($prevurl)):?>
<div class="firstpage">
<a href="<?=$baseurl?>">
@@ -41,10 +42,17 @@
</div>
<div class="navpage"><a href="<?=$prevurl?>"><i class="fas fa-chevron-circle-left"></i></a></div>
<?endif?>
<div id="currpage"><?=$page?></div>
<?if (isset($nexturl)):?>
<div class="navpage"><a href="<?=$nexturl?>"><i class="fas fa-chevron-circle-right"></i></a></div>
<?if (isset($endurl)):?>
<div class="navpage"><a href="<?=$endurl?>"><i class="fas fa-angle-double-right"></i></a></div>
<?endif?>
<?endif?>
</div>
</div>