Files
anpdf/app/routes/anpdf.php

474 lines
10 KiB
PHP
Raw Normal View History

2020-04-01 17:51:22 +03:00
<?php
2020-04-28 22:35:13 +03:00
function anpromo_kuri($page = 1, $scale = 1){
2020-04-01 17:51:22 +03:00
// $pdfile = 'https://argumenti.ru/templinks/md5files/f9598f88e667146d50d106eeedbd74c1.pdf';
2020-05-08 21:23:23 +03:00
$namefile = 'promo.pdf';
2020-05-09 17:19:32 +03:00
2020-04-02 08:53:50 +00:00
$title = 'Номер 12(706)';
2020-04-29 22:19:45 +03:00
$newcurr = strtotime('2006-05-12');
2020-04-01 17:51:22 +03:00
2020-05-21 20:12:39 +03:00
$file = SITEPATH.'pub/files/pdf/promo.pdf';
2020-05-21 19:28:09 +03:00
2020-05-09 17:19:32 +03:00
$data = pdfs_init($file, $page);
2020-05-21 22:09:07 +03:00
$data['pages'] = pdfs_count($file);
2020-05-21 20:12:39 +03:00
2020-05-21 22:09:07 +03:00
$count = $data['pages'];
2020-05-08 21:23:23 +03:00
2020-05-12 22:56:44 +03:00
$pdfile = SITE.$data['pdfpgurl'];
2020-05-21 19:43:20 +03:00
$category = 1;
2020-05-08 21:23:23 +03:00
$fullpdf = $data['pdfurl'];
2020-05-09 17:19:32 +03:00
$baseurl = "/anpromo/";
$pagenum = 1;
2020-04-29 13:16:40 +03:00
$nextpage = $page + 1;
2020-05-08 21:23:23 +03:00
$filedown = True;
if ($data['count'] > $nextpage){
2020-04-29 13:16:40 +03:00
$nexturl = "$baseurl$nextpage";
2020-04-01 17:51:22 +03:00
}
2020-05-08 21:23:23 +03:00
else {
$nexturl = '';
}
2020-04-01 17:51:22 +03:00
if ($page > 1) {
$prevpage = $page - 1;
2020-04-29 13:16:40 +03:00
$prevurl = "$baseurl$prevpage";
2020-04-01 17:51:22 +03:00
}
2020-04-29 13:16:40 +03:00
2020-05-16 01:20:36 +03:00
$downtitle = 'Скачать в PDF формате';
2020-05-09 17:19:32 +03:00
2020-04-01 17:51:22 +03:00
2020-05-21 19:28:09 +03:00
$tempcontent = VIEWPATH.'anpdf3.phtml'; //подшаблон
2020-04-29 13:16:40 +03:00
include VIEWPATH.'layout.phtml'; //центральный шаблон
2020-04-01 17:51:22 +03:00
2020-04-07 19:09:45 +03:00
}
2020-04-07 20:07:25 +03:00
2020-05-22 17:03:33 +03:00
function promo_kuri ($hash, $page = 0, $scale = 1, $promo = 'pr', $version = null){
2020-04-07 19:09:45 +03:00
2020-05-22 17:03:33 +03:00
return read_kuri($hash, $page, 'pr', $version);
2020-05-09 17:19:32 +03:00
2020-04-29 22:19:45 +03:00
$price = db_get("SELECT `price_id`, `pricename`, `BeginDate` FROM `price` WHERE `pricehash` = '$hash' LIMIT 1");
2020-04-07 19:09:45 +03:00
if (!isset($price['price_id'])){
header("HTTP/1.0 404 Not Found");
echo "file not found";
return False;
}
2020-05-21 16:11:48 +03:00
2020-05-09 17:19:32 +03:00
$file = SITEPATH.'pub/files/source/742.pdf';
2020-04-09 00:53:14 +03:00
$namefile = $hash.'.pdf';
2020-04-28 22:24:58 +03:00
$basepg = PGDIR.$hash.'/'.$hash.'-';
$pgfile = $basepg.$page.'.pdf';
2020-04-23 18:19:11 +03:00
$cachefile = PDFDIR.$namefile;
2020-04-29 22:19:45 +03:00
$newcurr = strtotime($price['BeginDate']);
2020-05-09 17:19:32 +03:00
2020-04-29 22:19:45 +03:00
2020-04-09 00:00:18 +03:00
2020-04-23 22:50:45 +03:00
if (file_exists($cachefile)){
$fullpdf = '/pdf/'.$namefile;
}
else {
$fullpdf = '/file/'.$hash;
}
2020-04-23 23:18:00 +03:00
2020-04-28 21:16:20 +03:00
if (file_exists($pgfile)){
$pdfile = '/pages/'.$hash.'/'.$hash.'-'.$page.'.pdf';
2020-04-23 22:07:26 +03:00
$pagenum = 1;
2020-04-23 21:43:44 +03:00
}
2020-04-28 22:24:58 +03:00
2020-04-28 21:16:20 +03:00
if ($page > 1 or $promo){
$fullpdf = $pdfile;
$downtitle = 'Если по какой-то причине у вас не загрузилась страница ниже, то нажмите сюда, чтобы скачать pdf';
}
else {
$downtitle = 'Если по какой-то причине у вас не загрузилось издание ниже, то нажмите сюда, чтобы скачать pdf';
}
2020-04-07 19:09:45 +03:00
$id = $price['price_id'];
$title = $price['pricename'];
2020-04-07 20:07:25 +03:00
2020-04-23 23:26:28 +03:00
if ($promo){
2020-04-07 20:07:25 +03:00
$filedown = True;
2020-04-23 23:26:28 +03:00
$baseurl = "/promo/$hash/";
}
else {
$filedown = True;
$baseurl = "/read/$hash/";
}
2020-04-07 20:07:25 +03:00
2020-04-28 22:24:58 +03:00
$nextpage = $page + 1;
if (file_exists($basepg.$nextpage.'.pdf')){
$nexturl = "$baseurl$nextpage";
2020-04-07 20:07:25 +03:00
}
if ($page > 1) {
$prevpage = $page - 1;
$prevurl = "$baseurl$prevpage";
}
2020-04-27 12:24:59 +03:00
$tempcontent = VIEWPATH.'anpdf2.phtml'; //подшаблон
include VIEWPATH.'layout.phtml'; //центральный шаблон
2020-04-07 20:07:25 +03:00
2020-04-23 14:42:01 +03:00
}
function text_kuri(){
$id = 659286;
$news = file_get_contents(API.'id/'.$id);
print_r($news);
2020-04-27 12:24:59 +03:00
$tempcontent = VIEWPATH.'anpdf.phtml';
include VIEWPATH.'layout.phtml';
2020-04-23 14:42:01 +03:00
//view( 'views/antext.phtml',['news'=> $news] );
2020-04-07 20:07:25 +03:00
}
2020-04-29 13:16:40 +03:00
2020-05-15 21:02:24 +03:00
//закладки - пока только куки
function bookmark_get($hash){
$bookcook = 'book_'.$hash;
2020-05-15 22:03:09 +03:00
if (isset($_COOKIE[$bookcook])){
2020-05-15 21:02:24 +03:00
return $_COOKIE[$bookcook];
2020-05-15 22:03:09 +03:00
}
2020-05-15 21:02:24 +03:00
else
return false;
}
function bookmark_set($hash, $page){
2020-05-15 21:29:36 +03:00
2020-05-15 21:02:24 +03:00
$bookcook = 'book_'.$hash;
2020-05-15 21:29:36 +03:00
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']);
2020-05-15 21:02:24 +03:00
return true;
}
2020-05-22 17:03:33 +03:00
function read_kuri($hash, $page = 0, $promo = false, $version = null){
2020-04-07 20:07:25 +03:00
2020-05-09 17:19:32 +03:00
# test url http://klan.dv/promo/bac343b41b357fdc8243373a429caa62 (742.pdf source)
2020-04-23 23:21:28 +03:00
2020-05-22 17:03:33 +03:00
2020-05-22 10:40:50 +03:00
$price = api_pricehash($hash);
2020-04-07 20:07:25 +03:00
if (!isset($price['price_id'])){
header("HTTP/1.0 404 Not Found");
echo "file not found";
return False;
}
2020-05-15 23:20:37 +03:00
$bookmark = bookmark_get($hash);
2020-05-15 21:47:01 +03:00
2020-05-15 23:20:37 +03:00
if ($page == 0){ //  не читал ли ранее
2020-05-15 21:29:36 +03:00
$page = 1; //если нет страницы то первая
2020-05-15 21:02:24 +03:00
if ($bookmark !== false and $bookmark > 1){
2020-05-22 17:03:33 +03:00
return read_kuri($hash, $bookmark, $promo, $version);
2020-05-15 21:02:24 +03:00
}
}
2020-05-22 15:32:05 +03:00
2020-05-15 21:29:36 +03:00
//устанавливаем закладку
bookmark_set($hash, $page);
2020-05-15 21:02:24 +03:00
2020-05-09 17:19:32 +03:00
$file = PDFSOURCE."${price['price_id']}.pdf";
$data = pdfs_init($file, $page);
2020-05-21 21:01:42 +03:00
if ($price['pages'] == 0){
$data['pages'] = pdfs_count($file);
2020-05-21 21:13:54 +03:00
$count = $data['pages'];
2020-05-21 21:01:42 +03:00
$pages_sql = "
UPDATE
price
SET
2020-05-21 21:08:43 +03:00
pages = ${data['pages']}
2020-05-21 21:01:42 +03:00
WHERE
price_id = ${price['price_id']}
";
db_get($pages_sql, 'chitatel');
2020-05-21 21:13:54 +03:00
}
else{
$count = $price['pages'];
}
2020-05-22 17:03:33 +03:00
2020-05-24 17:17:31 +03:00
if ($price['html'] == 'html'){
2020-05-24 17:10:45 +03:00
return readbook_kuri($hash, $page = 1);
}
2020-05-22 17:03:33 +03:00
if ($version == null){
2020-05-22 15:32:05 +03:00
$detect = new Mobile_Detect;
2020-05-22 17:03:33 +03:00
2020-05-22 15:32:05 +03:00
if ( $detect->isMobile() ) {
2020-05-22 17:03:33 +03:00
$version = 'html';
2020-05-22 15:32:05 +03:00
}
else
2020-05-22 17:03:33 +03:00
$version = 'pdf';
2020-05-22 15:32:05 +03:00
}
2020-05-22 17:03:33 +03:00
2020-05-22 15:32:05 +03:00
//мобильная версия
2020-05-22 17:03:33 +03:00
if ($version == 'html')
return readtext_kuri($hash, $page, $promo);
2020-05-22 15:32:05 +03:00
2020-05-21 21:01:42 +03:00
2020-05-09 17:19:32 +03:00
$pdfile = $data['pdfpgurl'];
$fullpdf = $data['pdfurl'];
2020-05-21 21:13:54 +03:00
2020-05-09 17:19:32 +03:00
$pagenum = 1;
2020-05-13 01:15:18 +03:00
$newcurr = strtotime($price['BeginDate']);
2020-05-21 17:37:25 +03:00
$category = $price['category_id'];
2020-04-07 19:09:45 +03:00
2020-05-22 17:03:33 +03:00
if ($promo == 'pr'){
$filedown = false;
2020-05-09 17:19:32 +03:00
$baseurl = "/promo/$hash/";
}
else {
2020-05-22 17:03:33 +03:00
$filedown = true;
2020-05-09 17:19:32 +03:00
$baseurl = "/read/$hash/";
2020-05-16 18:51:50 +03:00
}
if ($price['category_id'] == 3)
$filedown = False;
2020-05-09 17:19:32 +03:00
$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){
2020-05-15 23:20:37 +03:00
$downtitle = 'Скачать в pdf формате';
2020-05-09 17:19:32 +03:00
}
}
else {
$title = $price['pricename'];
2020-05-15 23:20:37 +03:00
$downtitle = 'Скачать в pdf формате';
2020-05-09 17:19:32 +03:00
}
2020-05-22 17:03:33 +03:00
$htmlurl = "/readtext/$hash/$page/$promo";
2020-05-12 21:15:26 +03:00
2020-05-21 19:45:51 +03:00
$tempcontent = VIEWPATH.'anpdf3.phtml'; //подшаблон
2020-05-09 17:19:32 +03:00
include VIEWPATH.'layout.phtml'; //центральный шаблон
2020-05-08 13:22:22 +03:00
}
2020-05-22 17:03:33 +03:00
function readtext_kuri($hash, $page = 1, $promo = 'no'){
2020-05-22 13:21:37 +03:00
$price = api_pricehash($hash);
2020-05-22 17:03:33 +03:00
2020-05-22 13:21:37 +03:00
if (!isset($price['price_id'])){
return 'page not found';
}
2020-05-22 15:32:05 +03:00
$count = $price['pages'];
2020-05-23 11:19:00 +03:00
$count = 24;
2020-05-22 15:32:05 +03:00
$baseurl = '/readtext/'.$hash.'/';
$endurl = "$baseurl$count";
2020-05-22 13:21:37 +03:00
$title = $price['pricename'];
2020-05-22 15:32:05 +03:00
$newcurr = strtotime($price['BeginDate']);
2020-05-22 17:03:33 +03:00
$full_ver_url = SITE."read/$hash/$page/$promo/pdf";
2020-05-22 15:32:05 +03:00
2020-05-22 13:21:37 +03:00
$content = apipage_kuri($price['price_id'], $page);
2020-05-23 11:19:00 +03:00
2020-05-23 13:29:28 +03:00
if ($page > 1) {
$prevpage = $page - 1;
for ($p = $prevpage; $p > 0; $p--) {
$prevcontent = apipage_kuri($price['price_id'], $p);
if (count($prevcontent) > 0){
$prevpage = $p;
break;
}
}
$prevurl = $baseurl.$prevpage;
}
2020-05-23 11:19:00 +03:00
if ($count > $page){
/** предварительно сл. полоса если не пустая */
$nextpage = $page + 1;
2020-05-23 13:29:28 +03:00
for ($p = $nextpage; $p <= $count; $p++) {
$nextcontent = apipage_kuri($price['price_id'], $p);
if (count($nextcontent) > 0){
2020-05-23 11:19:00 +03:00
$nextpage = $p;
break;
}
}
2020-05-23 13:29:28 +03:00
$nexturl = $baseurl.$nextpage;
2020-05-23 11:19:00 +03:00
}
2020-05-23 13:29:28 +03:00
2020-05-23 11:19:00 +03:00
2020-05-22 13:21:37 +03:00
$tempcontent = VIEWPATH.'antext.phtml'; //подшаблон
include VIEWPATH.'layout.phtml'; //центральный шаблон
2020-05-22 10:40:50 +03:00
}
2020-05-23 11:19:00 +03:00
function initpageurls($page, $count, $baseurl){
$res['endurl'] = "$baseurl$count";
if ($count > $page){
$nextpage = $page + 1;
$res['nexturl'] = $baseurl.$nextpage;
}
if ($page > 1) {
$prevpage = $page - 1;
$res['prevurl'] = $baseurl.$prevpage;
}
return $res;
}
2020-05-22 10:40:50 +03:00
2020-05-24 17:10:45 +03:00
function readbook_kuri($hash, $page = 1){
2020-05-23 23:19:05 +03:00
require (APPPATH.'functions/xhtmltransform.php');
2020-05-24 17:10:45 +03:00
$price = api_pricehash($hash);
if (!isset($price['price_id'])){
return 'page not found';
}
$file = HTMLSOURCE.$price['price_id'].'.'.$price['html'];
2020-05-24 17:18:50 +03:00
echo $file;
2020-05-24 17:10:45 +03:00
2020-05-23 23:19:05 +03:00
$limit = 4000;
$count = 20;
2020-05-24 17:10:45 +03:00
2020-05-23 23:19:05 +03:00
2020-05-24 17:10:45 +03:00
$htmlfile = APPPATH.'pub/html/furer.html';
2020-05-23 23:19:05 +03:00
2020-05-24 17:10:45 +03:00
$html = convert2html($htmlfile);
$razmer = strlen($html);
$count = $razmer / $limit;
// $html .= convert2html($dir.'chapter-1.xhtml');
2020-05-23 23:19:05 +03:00
$pagehtml = pagehtml($html, $page, $limit);
2020-05-24 17:10:45 +03:00
$baseurl = SITE.'/readbook/'.$hash.'/';
2020-05-23 23:19:05 +03:00
$endurl = $baseurl.$count;
$nextpage = $page + 1;
$nexturl = $baseurl.$nextpage;
$prevpage = $page - 1;
$prevurl = $baseurl.$prevpage;
2020-05-24 17:10:45 +03:00
$title = $price['pricename'];
2020-05-23 23:19:05 +03:00
$tempcontent = VIEWPATH.'epub.phtml'; //подшаблон
include VIEWPATH.'layout.phtml'; //центральный шаблон
}
2020-05-08 13:22:22 +03:00
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';
}
}
2020-04-08 17:05:30 +03:00
}