Files
anpdf/app/routes/anpdf.php
Andrey Kuvshinov aefbc51b1f add apiconnent
2020-05-22 10:40:50 +03:00

321 lines
7.0 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
function anpromo_kuri($page = 1, $scale = 1){
// $pdfile = 'https://argumenti.ru/templinks/md5files/f9598f88e667146d50d106eeedbd74c1.pdf';
$namefile = 'promo.pdf';
$title = 'Номер 12(706)';
$newcurr = strtotime('2006-05-12');
$file = SITEPATH.'pub/files/pdf/promo.pdf';
$data = pdfs_init($file, $page);
$data['pages'] = pdfs_count($file);
$count = $data['pages'];
$pdfile = SITE.$data['pdfpgurl'];
$category = 1;
$fullpdf = $data['pdfurl'];
$baseurl = "/anpromo/";
$pagenum = 1;
$nextpage = $page + 1;
$filedown = True;
if ($data['count'] > $nextpage){
$nexturl = "$baseurl$nextpage";
}
else {
$nexturl = '';
}
if ($page > 1) {
$prevpage = $page - 1;
$prevurl = "$baseurl$prevpage";
}
$downtitle = 'Скачать в PDF формате';
$tempcontent = VIEWPATH.'anpdf3.phtml'; //подшаблон
include VIEWPATH.'layout.phtml'; //центральный шаблон
}
function read_kuri($hash, $page = 0, $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'])){
header("HTTP/1.0 404 Not Found");
echo "file not found";
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)){
$fullpdf = '/pdf/'.$namefile;
}
else {
$fullpdf = '/file/'.$hash;
}
if (file_exists($pgfile)){
$pdfile = '/pages/'.$hash.'/'.$hash.'-'.$page.'.pdf';
$pagenum = 1;
}
if ($page > 1 or $promo){
$fullpdf = $pdfile;
$downtitle = 'Если по какой-то причине у вас не загрузилась страница ниже, то нажмите сюда, чтобы скачать pdf';
}
else {
$downtitle = 'Если по какой-то причине у вас не загрузилось издание ниже, то нажмите сюда, чтобы скачать pdf';
}
$id = $price['price_id'];
$title = $price['pricename'];
if ($promo){
$filedown = True;
$baseurl = "/promo/$hash/";
}
else {
$filedown = True;
$baseurl = "/read/$hash/";
}
$nextpage = $page + 1;
if (file_exists($basepg.$nextpage.'.pdf')){
$nexturl = "$baseurl$nextpage";
}
if ($page > 1) {
$prevpage = $page - 1;
$prevurl = "$baseurl$prevpage";
}
$tempcontent = VIEWPATH.'anpdf2.phtml'; //подшаблон
include VIEWPATH.'layout.phtml'; //центральный шаблон
}
function text_kuri(){
$id = 659286;
$news = file_get_contents(API.'id/'.$id);
print_r($news);
$tempcontent = VIEWPATH.'anpdf.phtml';
include VIEWPATH.'layout.phtml';
//view( 'views/antext.phtml',['news'=> $news] );
}
//закладки - пока только куки
function bookmark_get($hash){
$bookcook = 'book_'.$hash;
if (isset($_COOKIE[$bookcook])){
return $_COOKIE[$bookcook];
}
else
return false;
}
function bookmark_set($hash, $page){
$bookcook = 'book_'.$hash;
if ($page == 1){ // не устанавливать на первую страницу
if (isset($_COOKIE[$bookcook])){
unset($_COOKIE[$bookcook]);
setcookie($bookcook, null, -1, '/', $_SERVER['HTTP_HOST']);
}
return true;
}
$timeout = time()+(60*60*24*30*2); // хранить 2 месяца
setcookie ($bookcook , $page, $timeout, '/', $_SERVER['HTTP_HOST']);
return true;
}
function promo_kuri($hash, $page = 0, $promo = true){
# test url http://klan.dv/promo/bac343b41b357fdc8243373a429caa62 (742.pdf source)
$price = api_pricehash($hash);
if (!isset($price['price_id'])){
header("HTTP/1.0 404 Not Found");
echo "file not found";
return False;
}
$bookmark = bookmark_get($hash);
if ($page == 0){ //  не читал ли ранее
$page = 1; //если нет страницы то первая
if ($bookmark !== false and $bookmark > 1){
return promo_kuri($hash, $bookmark, $promo);
}
}
//устанавливаем закладку
bookmark_set($hash, $page);
$file = PDFSOURCE."${price['price_id']}.pdf";
$data = pdfs_init($file, $page);
if ($price['pages'] == 0){
$data['pages'] = pdfs_count($file);
$count = $data['pages'];
$pages_sql = "
UPDATE
price
SET
pages = ${data['pages']}
WHERE
price_id = ${price['price_id']}
";
db_get($pages_sql, 'chitatel');
}
else{
$count = $price['pages'];
}
$pdfile = $data['pdfpgurl'];
$fullpdf = $data['pdfurl'];
$pagenum = 1;
$newcurr = strtotime($price['BeginDate']);
$category = $price['category_id'];
if ($promo){
$filedown = True;
$baseurl = "/promo/$hash/";
}
else {
$filedown = True;
$baseurl = "/read/$hash/";
}
if ($price['category_id'] == 3)
$filedown = False;
$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.'anpdf3.phtml'; //подшаблон
include VIEWPATH.'layout.phtml'; //центральный шаблон
}
function text($hash, $page){
}
function pdfscan_kuri(){
$pdfsql = "SELECT price_id, pricehash FROM price WHERE category_id = 1";
$path = '~/vhosts/anpdf/pub/files/pages/';
echo exec('whoami');
$pdfs = dbl_get($pdfsql);
foreach($pdfs as $pdf){
$pagedir = $path.$pdf['pricehash'];
if(!is_dir($pagedir)) {
mkdir($pagedir);
$cmd = 'docker run --name pdftk -it --rm \
--user $(id -u):$(id -g) \
-v "$PDFDIR:/workdir/pdf" \
-v "$OUTDIR:/workdir/pages" \
-w "/workdir" \
masterforweb/pdftk pdftk "pdf/$file" burst output "pages/${name}/${name}-%1d.pdf';
}
}
}