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 else
define('SITEPATH', dirname(__FILE__)); define('SITEPATH', dirname(__FILE__));
define('PDFDIR', '/vhosts/anpdf/app/pub/files/pdf/'); if (SITE == 'http://klan.argumenti.ru/')
define('PGDIR', '/vhosts/anpdf/app/pub/files/pages/'); define('PDFSOURCE', '/vhosts/an/httpdocs/pub/files/pdf/pdf/');
define('PDFURL', 'pub/files/pdf/'); else
define('PGURL', 'pub/files/pages/'); 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('APPPATH', SITEPATH);
define('VIEWPATH', SITEPATH.'views/'); 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'; // $pdfile = 'https://argumenti.ru/templinks/md5files/f9598f88e667146d50d106eeedbd74c1.pdf';
$namefile = 'promo.pdf'; $namefile = 'promo.pdf';
$title = 'Номер 12(706)'; $title = 'Номер 12(706)';
$baseurl = '/';
$newcurr = strtotime('2006-05-12'); $newcurr = strtotime('2006-05-12');
$file = SITEPATH.'pub/files/pdf/promo.pdf'; $file = SITEPATH.'pub/files/source/742.pdf';
$data = pdfs_init($file); $data = pdfs_init($file, $page);
$pdfile = $data['pdfpgurl']; $pdfile = $data['pdfpgurl'];
$fullpdf = $data['pdfurl']; $fullpdf = $data['pdfurl'];
$baseurl = "/anpromo/";
$pagenum = 1;
$nextpage = $page + 1; $nextpage = $page + 1;
$filedown = True; $filedown = True;
@@ -30,8 +33,7 @@ function anpromo_kuri($page = 1, $scale = 1){
} }
$downtitle = 'Если по какой-то причине у вас не загрузилась страница ниже, то нажмите сюда, чтобы скачать pdf'; $downtitle = 'Если по какой-то причине у вас не загрузилась страница ниже, то нажмите сюда, чтобы скачать pdf';
$baseurl = "/anpromo/";
$pagenum = 1;
$tempcontent = VIEWPATH.'anpdf2.phtml'; //подшаблон $tempcontent = VIEWPATH.'anpdf2.phtml'; //подшаблон
include VIEWPATH.'layout.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){ 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"); $price = db_get("SELECT `price_id`, `pricename`, `BeginDate` FROM `price` WHERE `pricehash` = '$hash' LIMIT 1");
if (!isset($price['price_id'])){ if (!isset($price['price_id'])){
@@ -52,6 +56,8 @@ function read_kuri($hash, $page = 1, $scale = 1, $promo = false){
return False; return False;
} }
$file = SITEPATH.'pub/files/source/742.pdf';
$namefile = $hash.'.pdf'; $namefile = $hash.'.pdf';
$basepg = PGDIR.$hash.'/'.$hash.'-'; $basepg = PGDIR.$hash.'/'.$hash.'-';
$pgfile = $basepg.$page.'.pdf'; $pgfile = $basepg.$page.'.pdf';
@@ -59,6 +65,7 @@ function read_kuri($hash, $page = 1, $scale = 1, $promo = false){
$newcurr = strtotime($price['BeginDate']); $newcurr = strtotime($price['BeginDate']);
if (file_exists($cachefile)){ if (file_exists($cachefile)){
$fullpdf = '/pdf/'.$namefile; $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"); $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; return False;
} }
$id = $price['price_id']; $file = PDFSOURCE."${price['price_id']}.pdf";
$pdfile = "/file/$hash"; $data = pdfs_init($file, $page);
$maxpage = 32;
if ($page > 1) $pdfile = $data['pdfpgurl'];
$title = $price['pricename']."- $page"; $fullpdf = $data['pdfurl'];
else $count = $data['count'];
$title = $price['pricename']; $pagenum = 1;
if (!$promo)
$filedown = False;
if ($promo){
$filedown = True;
$baseurl = "/promo/$hash/"; $baseurl = "/promo/$hash/";
}
else {
$filedown = True;
$baseurl = "/read/$hash/";
}
if ($page < $maxpage){ $endurl = "$baseurl$count";
if ($count > $page){
$nextpage = $page + 1; $nextpage = $page + 1;
$nexturl = "$baseurl$nextpage"; $nexturl = "$baseurl$nextpage";
} }
else {
if ($page > 1) { $nexturl = '';
$prevpage = $page - 1;
$prevurl = "$baseurl$prevpage";
} }
include ('anpdf2.phtml');
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 <?php
function pdfs_filename($pdf){
function pdfs_basename($pdf){
return basename($source, ".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){ function pdfs_cachefile($pdf){
$basefile = basename($pdf); $name = pdfs_hash($pdf).'.pdf';
$cachefile = PDFDIR.$basefile; $cachefile = PDFDIR.$name;
$cacheurl = PDFURL.$basefile; $cacheurl = PDFPATH.$name;
if (!file_exists($cachefile)) { if (!file_exists($cachefile)) {
if (copy($pdf, $cachefile)) if (copy($pdf, $cachefile))
@@ -46,7 +50,7 @@ function pdfs_init($source, $page = 1){
$result['pdfurl'] = pdfs_cachefile($source); //полный файл на скачку $result['pdfurl'] = pdfs_cachefile($source); //полный файл на скачку
$name = basename($source, ".pdf"); $name = pdfs_hash($source);
$cachedir = PGDIR.$name.'/'; $cachedir = PGDIR.$name.'/';
$cachefile = $name.'-'.$page.'.pdf'; $cachefile = $name.'-'.$page.'.pdf';
$fullcachefile = $cachedir.$cachefile; $fullcachefile = $cachedir.$cachefile;
@@ -56,13 +60,13 @@ function pdfs_init($source, $page = 1){
if (!is_dir($cachedir)) if (!is_dir($cachedir))
mkdir($cachedir); mkdir($cachedir);
$cmd = "pdftk $source cat 1 output $fullcachefile"; $cmd = "pdftk $source cat $page output $fullcachefile";
shell_exec($cmd); shell_exec($cmd);
} }
if (file_exists($fullcachefile)) if (file_exists($fullcachefile))
$result['pdfpgurl'] = PGURL.$name.'/'.$cachefile; $result['pdfpgurl'] = PGPATH.$name.'/'.$cachefile;
else else
return false; return false;

View File

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