495 lines
11 KiB
PHP
495 lines
11 KiB
PHP
<?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 promo_kuri ($hash, $page = 0, $scale = 1, $promo = 'pr', $version = null){
|
||
|
||
return read_kuri($hash, $page, 'pr', $version);
|
||
|
||
$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 == 'pr'){
|
||
$fullpdf = $pdfile;
|
||
$downtitle = 'Если по какой-то причине у вас не загрузилась страница ниже, то нажмите сюда, чтобы скачать pdf';
|
||
}
|
||
else {
|
||
$downtitle = 'Если по какой-то причине у вас не загрузилось издание ниже, то нажмите сюда, чтобы скачать pdf';
|
||
}
|
||
|
||
$id = $price['price_id'];
|
||
$title = $price['pricename'];
|
||
|
||
if ($promo == 'pr'){
|
||
$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 read_kuri($hash, $page = 0, $promo = 'full', $version = null){
|
||
|
||
# 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 read_kuri($hash, $bookmark, $promo, $version);
|
||
}
|
||
}
|
||
|
||
|
||
//устанавливаем закладку
|
||
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'];
|
||
}
|
||
|
||
//залита html версия книги
|
||
if ($price['html'] == 'html'){
|
||
return readbook_kuri($hash, $page);
|
||
}
|
||
|
||
|
||
if ($version == null){
|
||
|
||
$detect = new Mobile_Detect;
|
||
|
||
if ( $detect->isMobile() ) {
|
||
$version = 'html';
|
||
}
|
||
else
|
||
$version = 'pdf';
|
||
}
|
||
|
||
//книжки только pdf :(
|
||
if ($price['category_id'] == 3)
|
||
$version = 'pdf';
|
||
|
||
|
||
|
||
//мобильная версия
|
||
if ($version == 'html')
|
||
return readtext_kuri($hash, $page, $promo);
|
||
|
||
|
||
$pdfile = $data['pdfpgurl'];
|
||
$fullpdf = $data['pdfurl'];
|
||
|
||
$pagenum = 1;
|
||
$newcurr = strtotime($price['BeginDate']);
|
||
$category = $price['category_id'];
|
||
|
||
if ($promo == 'pr'){
|
||
$filedown = false;
|
||
$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 == 'full'){
|
||
$downtitle = 'Скачать pdf';
|
||
}
|
||
}
|
||
else {
|
||
$title = $price['pricename'];
|
||
$downtitle = 'Скачать pdf';
|
||
}
|
||
|
||
$htmlurl = "/readtext/$hash/$page/$promo";
|
||
|
||
$tempcontent = VIEWPATH.'anpdf3.phtml'; //подшаблон
|
||
include VIEWPATH.'layout.phtml'; //центральный шаблон
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
function readtext_kuri($hash, $page = 1, $promo = 'full'){
|
||
|
||
$price = api_pricehash($hash);
|
||
|
||
|
||
if (!isset($price['price_id'])){
|
||
return 'page not found';
|
||
}
|
||
|
||
$count = $price['pages'];
|
||
$baseurl = '/readtext/'.$hash.'/';
|
||
$endurl = "$baseurl$count";
|
||
|
||
$title = $price['pricename'];
|
||
$newcurr = strtotime($price['BeginDate']);
|
||
$full_ver_url = SITE."read/$hash/$page/$promo/pdf";
|
||
|
||
$content['stuff'] = apipage_kuri($price['price_id'], $page);
|
||
|
||
foreach ($content['stuff'] as $news) {
|
||
$author_id = $news['author_id'];
|
||
}
|
||
|
||
$authorname = db_get("SELECT `authorname, descript` FROM `authors` WHERE `author_id` = $author_id LIMIT 1");
|
||
|
||
$content['authorname'] = $authorname['authorname'];
|
||
$content['authordescript'] = $authorname['descript'];
|
||
|
||
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;
|
||
}
|
||
|
||
|
||
if ($count > $page){
|
||
|
||
/** предварительно сл. полоса если не пустая */
|
||
|
||
$nextpage = $page + 1;
|
||
|
||
for ($p = $nextpage; $p <= $count; $p++) {
|
||
$nextcontent = apipage_kuri($price['price_id'], $p);
|
||
if (count($nextcontent) > 0){
|
||
$nextpage = $p;
|
||
break;
|
||
}
|
||
}
|
||
|
||
$nexturl = $baseurl.$nextpage;
|
||
|
||
}
|
||
|
||
|
||
|
||
$tempcontent = VIEWPATH.'antext.phtml'; //подшаблон
|
||
include VIEWPATH.'layout.phtml'; //центральный шаблон
|
||
|
||
|
||
}
|
||
|
||
|
||
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;
|
||
|
||
}
|
||
|
||
|
||
|
||
function readbook_kuri($hash, $page = 1){
|
||
|
||
require (APPPATH.'functions/xhtmltransform.php');
|
||
|
||
$price = api_pricehash($hash);
|
||
|
||
if (!isset($price['price_id'])){
|
||
return 'page not found';
|
||
}
|
||
|
||
$bookmark = bookmark_get($hash);
|
||
|
||
if ($page == 0){ // не читал ли ранее
|
||
$page = 1; //если нет страницы то первая
|
||
if ($bookmark !== false and $bookmark > 1){
|
||
return readbook_kuri($hash, $bookmark);
|
||
}
|
||
}
|
||
|
||
//устанавливаем закладку
|
||
bookmark_set($hash, $page);
|
||
|
||
$htmlfile = HTMLSOURCE.$price['price_id'].'.'.$price['html'];
|
||
|
||
$limit = 4000;
|
||
$count = 20;
|
||
|
||
|
||
$html = convert2html($htmlfile);
|
||
$razmer = strlen($html);
|
||
|
||
$count = floor($razmer / $limit);
|
||
|
||
// $html .= convert2html($dir.'chapter-1.xhtml');
|
||
$pagehtml = pagehtml($html, $page, $limit);
|
||
|
||
$baseurl = SITE.'readbook/'.$hash.'/';
|
||
$endurl = $baseurl.$count;
|
||
|
||
if ($page < $count) {
|
||
$nextpage = $page + 1;
|
||
$nexturl = $baseurl.$nextpage;
|
||
}
|
||
|
||
if ($page > 1) {
|
||
$prevpage = $page - 1;
|
||
$prevurl = $baseurl.$prevpage;
|
||
}
|
||
|
||
$title = $price['pricename'];
|
||
$author = $price['author'];
|
||
|
||
$tempcontent = VIEWPATH.'epub.phtml'; //подшаблон
|
||
include VIEWPATH.'layout.phtml'; //центральный шаблон
|
||
|
||
}
|
||
|
||
|
||
|
||
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';
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|