new version main page

This commit is contained in:
Your Name
2021-05-24 01:13:43 +03:00
parent 2f2c1489a2
commit 766e572752
18 changed files with 434 additions and 108 deletions

View File

@@ -105,7 +105,36 @@ function api_restore_hash($hash){
}
# подписчик или нет
function client_status_sub($client_id, $client_group = 3){
if ($client_group == 1 or $client_group == 2){
return True;
}
$findsub = db_get("SELECT number_id FROM `anbuy` WHERE `client_id` = '$client_id' AND `number_id` = '486' AND `buy_status` = '1' LIMIT 1");
if (isset($findsub['number_id'])){
return True;
}
}
# куплена книжка или нет
function client_status_book($book_id, $client_id){
$book_sql = "SELECT buy_id FROM anbuy WHERE number_id = $book_id AND client_id = $client_id AND buy_status = 1";
$book = db_get($book_sql);
if (isset($book['buy_id'])){
return True;
}
return False;
}

View File

@@ -3,9 +3,19 @@
*
*/
function bookid_kuri($hash) {
function bookid_kuri($slug) {
$query = "SELECT `price_id`, `pricename`, `BeginDate`, `priceanons`, `priceimg`, `pricehash`, `price` FROM `price` WHERE `pricehash` = '$hash' LIMIT 1";
$query = "
SELECT
`price_id`, `pricename`, `categoryname`, `categoryslug`, price.category_id AS category_id, `BeginDate`, `priceanons`, `priceimg`, `pricehash`, `price`, `sub`
FROM
`price`
LEFT JOIN `pricecategory`
ON price.category_id = pricecategory.category_id
WHERE
`priceslug` = '$slug'
LIMIT 1
";
$book = dbl_get($query);
@@ -30,9 +40,9 @@ function bookid_kuri($hash) {
/**
* вернуть товары магазина (все или по фильтру)
*/
function api_books_kuri($category = 'all', $page = 1){
function api_books_kuri($category = 'knigi', $filter = 'all', $page = 1){
$limit = 25;
$limit = 24;
if ($page > 1){
$offset = $limit * ($page - 1);
@@ -41,7 +51,7 @@ function api_books_kuri($category = 'all', $page = 1){
else {
$offset_str = '';
}
if ($category == 'all'){
$where = '';
}
@@ -58,9 +68,98 @@ function api_books_kuri($category = 'all', $page = 1){
}
$sql_books = "SELECT * FROM `price` $where ORDER BY `price_id` DESC LIMIT $limit $offset_str";
$db_count = db_get("SELECT COUNT(price_id) AS count FROM `price` $where LIMIT 1;");
return db_get($sql_books);
if (isset($db_count['error']))
return False;
if (isset($db_count['count']))
$count = $db_count['count'];
$sql_books = "SELECT * FROM `price` $where ORDER BY `price_id` DESC LIMIT $limit $offset_str";
$books = db_get($sql_books);
if (!isset($books['error'])) {
if ($count > $limit){
$pages = ceil($count / $limit);
}
else{
$pages = 1;
}
$result['books'] = $books;
$result['count'] = $count;
$result['pages'] = $pages;
$result['page'] = $page;
}
return $result;
}
/**
все категории
*/
function api_cats(){
$cats = db_get(
"SELECT * FROM pricecategory WHERE visibled = 1"
);
if (isset($cats['error']))
return False;
$result = [];
foreach ($cats as $cat){
$result[$cat['categoryslug']] = $cat;
}
return $result;
}
function book_slug($book){
$return = '';
if ($book['category_id'] == 1){
$name = $book['pricename'];
$start = strpos($name, '(');
$end = strpos($name, ')');
$end = $end -1;
$number = substr($book['pricename'], $start + 1, $end - $start);
$result = "argumenty-nedeli-$number";
}
else {
$result = transliturl($book['pricename']);
}
return $result;
}
function add_book_slug(){
$books = db_get(
"SELECT * FROM price;"
);
foreach ($books as $book){
$slug = book_slug($book);
$sql = "UPDATE `price` SET `priceslug` = '$slug' WHERE price_id = ".$book['price_id'].';';
echo "$sql<br>";
}
}

View File

@@ -2,6 +2,7 @@
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL);
if (isset($_SERVER['HTTP_HOST']))

26
app/helpers/linkbook.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
function linkbook($book = array()){
if (defined('CLIENT_ID')) {
$buy = db_get('SELECT * FROM anbuy WHERE client_id = '.CLIENT_ID);
if(isset($buy[''])){
//read
}
else {
//write
}
}
else {
//buy
}
}

View File

@@ -0,0 +1,79 @@
<?php
function transliturl ($text, $translit = 'ru_en') {
$RU['ru'] = array(
'Ё', 'Ж', 'Ц', 'Ч', 'Щ', 'Ш', 'Ы',
'Э', 'Ю', 'Я', 'ё', 'ж', 'ц', 'ч',
'ш', 'щ', 'ы', 'э', 'ю', 'я', 'А',
'Б', 'В', 'Г', 'Д', 'Е', 'З', 'И',
'Й', 'К', 'Л', 'М', 'Н', 'О', 'П',
'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ъ',
'Ь', 'а', 'б', 'в', 'г', 'д', 'е',
'з', 'и', 'й', 'к', 'л', 'м', 'н',
'о', 'п', 'р', 'с', 'т', 'у', 'ф',
'х', 'ъ', 'ь', '/'
);
$EN['en'] = array(
"Yo", "Zh", "Cz", "Ch", "Shh","Sh", "Y'",
"E'", "Yu", "Ya", "yo", "zh", "cz", "ch",
"sh", "shh", "y'", "e'", "yu", "ya", "A",
"B" , "V" , "G", "D", "E", "Z", "I",
"J", "K", "L", "M", "N", "O", "P",
"R", "S", "T", "U", "F", "Kh", "''",
"'", "a", "b", "v", "g", "d", "e",
"z", "i", "j", "k", "l", "m", "n",
"o", "p", "r", "s", "t", "u", "f",
"h", "''", "'", "-"
);
if($translit == 'en_ru') {
$t = str_replace($EN['en'], $RU['ru'], $text);
$t = preg_replace('/(?<=[а-яё])Ь/u', 'ь', $t);
$t = preg_replace('/(?<=[а-яё])Ъ/u', 'ъ', $t);
}
else {
$t = str_replace($RU['ru'], $EN['en'], $text);
$t = preg_replace("/[\s]+/u", "-", $t);
$t = preg_replace("/[^a-z0-9_\-]/iu", "", $t);
$t = strtolower($t);
}
return $t;
}

View File

@@ -19,22 +19,36 @@ require 'api/book.php';
#helpers
require 'helpers/picbook.php';
require 'helpers/transliturl.php';
#middleware
$checklogin = check_login_kuri();
if (!isset($checklogin['error'])){
define('CLIENT_ID', $checklogin['client_id']);
define('CLIENT_GROUP', $checklogin['clientgroup_id']);
define('CLIENT_MAIL', $checklogin['clientmail']);
# подписчик или нет
$client_status_sub = client_status_sub(CLIENT_ID);
define('SUBSTATUS', $client_status_sub);
}
else {
define('SUBSTATUS', 0);
}
# routing
_kuri();
function index_kuri(){
$checklogin = check_login_kuri();
//$checklogin = check_login_kuri();
category_kuri();
if ($checklogin['error'] == 'client not found'){
login_kuri();
}
else {
mybooks_kuri();
}
}

View File

@@ -14,7 +14,7 @@ function login_kuri(){
if (isset($result['data'])) {
add_user_cookie($result['data']['client_id'], $result['data']['clientpassword']);
header('Location: '.SITE.'mybooks');
header('Location: '.SITE);
}
}
@@ -43,7 +43,7 @@ function out_kuri(){
setcookie('code', null, -1, '/', $_SERVER['HTTP_HOST']);
}
header('Location: '.SITE.'login');
header('Location: '.SITE);
}

View File

@@ -1,25 +1,67 @@
<?php
function book_kuri($hash){
function product_kuri($slug){
$book = bookid_kuri($hash);
$book = bookid_kuri($slug);
$breadcrumbs = [
$book['categoryname'] => SITE.'category/'.$book['categoryslug'],
'page' => $book['pricename']
];
$title = $book['pricename'].' - Аргументы Недели';
$description = 'Читайте и покупайте '.$book['pricename'].'. Издательский дом "Аргументы Недели"';
$maintitle = 'Книги Аргументы Недели';
$subtitle = $book['pricename'];
$login = check_login_kuri(); // залогин или нет
$buy_status = False;
# книга входит в состав подписки
if ($book['sub'] == 1 && SUBSTATUS == 1){
$buy_status = True;
}
else {
# купил ли эту книжку
$buy_status = client_status_book($books['book_id'], CLIENT_ID);
}
$tempcontent = VIEWPATH.'book.phtml';
include VIEWPATH.'layout.phtml';
}
function books_kuri($category = 'all', $filter = 'all', $page = 1){
function category_kuri($category = 'knigi', $filter = 'all', $page = 1){
$books = api_books_kuri($category, $page);
$cats = api_cats();
$books = api_books_kuri($category, $filter, $page);
$baseurl = SITE."category/$category/$filter/";
if ($books['pages'] > 1){
$endurl = $baseurl.$books['pages'];
}
if ($page > 1) {
$pagetitle = $cats[$category]['categoryname']." - страница $page";
$prevpage = $page - 1 ;
$prevurl = $baseurl.$prevpage;
}
else {
$pagetitle = $cats[$category]['categoryname'];
}
if ($page < $books['pages']){
$nextpage = $page+1;
$nexturl = $baseurl.$nextpage;
}
if (isset($cats[$category])){
$breadcrumbs['page'] = $pagetitle;
}
$tempcontent = VIEWPATH.'books.phtml';
include VIEWPATH.'layout.phtml';

View File

@@ -1,11 +0,0 @@
<?$checklogin = check_login_kuri();?>
<div id="auth">
<?if ($checklogin['error'] == 'client not found'):?>
<a href="<?=SITE?>login">Войти</a>
<?else:?>
<?=$checklogin['clientmail']?>
<a href="<?=SITE?>mybooks">Моя библиотека</a>&nbsp;
<a href="<?=SITE?>out">Выйти</a>
<?endif?>
</div>

View File

@@ -2,10 +2,12 @@
<div class="book_mini">
<img src="<?=$book['pic']?>">
<p class="book_mini_title"><?=$book['pricename']?></p>
<?if (isset($login['client_id'])):?>
<p><a href="<?=$book['links']['pdf']?>">Режим pdf</a></p>
<p><a href="<?=$book['links']['text']?>">Режим для чтения</a></p>
<p><a href="<?=$book['links']['download']?>">Скачать PDF</a></p>
<?if ($buy_status):?>
<p><a href="<?=$book['links']['pdf']?>">Читать PDF</a></p>
<!-- <p><a href="<?=$book['links']['text']?>">Читать текст</a></p> -->
<?if ($book['category_id'] == 1):?>
<p><a href="<?=$book['links']['download']?>">Скачать PDF</a></p>
<?endif?>
<?else:?>
<?$paylink = 'https://argumenti.ru/robomail/'.$book['price_id']?>
<p><?=$book['price']?> руб.</p>

View File

@@ -1,13 +1,14 @@
<div class="lib_container">
<?foreach ($books as $book):?>
<?foreach ($books['books'] as $book):?>
<div class="book_skeleton">
<div class="book_mini">
<a href="<?=$book['link']?>" target="_blank">
<?$link = SITE.'product/'.$book['priceslug']?>
<a href="<?=$link?>" target="_blank">
<img src="<?=picbook($book, 180, 280)?>" alt="<?=$book['pricename']?>">
<p class="book_mini_title"><?=$book['pricename']?></p>
<p><a href="<?=$paylink?>">Купить</a></p>
<p>Подробнее</p>
</a>
</div>
</div>
<?endforeach?>

View File

@@ -0,0 +1,27 @@
<?if (is_array($breadcrumbs)):?>
<li class="mob-hidden">
<i style="float:left" class="fas fa-arrow-right"></i>
</li>
<?foreach ($breadcrumbs as $bkey=>$item):?>
<?if ($bkey == 'page'):?>
<li class="header-div">
<?=$item?>
</li>
<?else:?>
<li class="header-div mob-hidden">
<a href="<?=$item?>"><?=$bkey?></a>
</li>
<li>
<i style="float:left" class="fas fa-arrow-right"></i>
</li>
<?endif?>
<?endforeach?>
<?endif?>
</ul>

26
app/views/header.phtml Normal file
View File

@@ -0,0 +1,26 @@
<?//if ($type !== 'form'):?>
<li class="mob-hidden">
<i style="float:left" class="fas fa-arrow-right"></i>
</li>
<li class="header-div<?if ($type == 'mybooks'):?> mob-hidden<?endif?>">
<a href="<?=SITE?>mybooks">Моя библиотека</a>
</li>
<?//endif?>
<?if (isset($author) and $author !== ''):?>
<li>
<i style="float:left" class="fas fa-arrow-right"></i>
</li>
<li class="header-div">
<?=$author?>
</li>
<?endif?>
<?if ($title !== '' and $title !== 'Моя библиотека'):?>
<li>
<i style="float:left" class="fas fa-arrow-right"></i>
</li>
<li class="header-div">
<a id="page_title" href="<?=$baseurl?>"><?=$title?></a>
</li>
<?endif?>

View File

@@ -14,6 +14,7 @@
<link rel="stylesheet" href="/pub/fontawesome/css/all.css">
<link rel="stylesheet" href="/pub/fontawesome/css/v4-shims.css">
</head>
<body>
@@ -61,36 +62,23 @@ _tmr.push({id: "1069168", type: "pageView", start: (new Date()).getTime()});
<header>
<ul>
<li class="mob-full">
<img id="logo" alt="Аргументы Недели (argumenti.ru)" src="https://argumenti.ru/images/argumenti/AN2.gif">
<a href="<?=SITE?>">
<img id="logo" alt="Клан Аргументы Недели (klan.argumenti.ru)" src="https://argumenti.ru/images/argumenti/AN2.gif">
</a>
</li>
<?//if ($type !== 'form'):?>
<li class="mob-hidden">
<i style="float:left" class="fas fa-arrow-right"></i>
</li>
<li class="header-div<?if ($type == 'mybooks'):?> mob-hidden<?endif?>">
<a href="<?=SITE?>mybooks">Моя библиотека</a>
</li>
<?//endif?>
<?if (isset($author) and $author !== ''):?>
<li>
<i style="float:left" class="fas fa-arrow-right"></i>
</li>
<li class="header-div">
<?=$author?>
</li>
<?endif?>
<?if ($title !== '' and $title !== 'Моя библиотека'):?>
<li>
<i style="float:left" class="fas fa-arrow-right"></i>
</li>
<li class="header-div">
<a id="page_title" href="<?=$baseurl?>"><?=$title?></a>
</li>
<?endif?>
</ul>
<?include('blocks/auth.phtml')?>
<?php
if (isset($breadcrumbs)){
include VIEWPATH.'breadcrumbs.phtml';
}
else {
include VIEWPATH.'header.phtml';
}?>
<?include VIEWPATH.'menus/auth.phtml';?>
</ul>
</header>
<?if ($checklogin['error'] == 'client not found'):?>
<div class="adv">
<!-- Yandex.RTB R-A-50615-61 -->

View File

@@ -14,7 +14,7 @@
<header style="justify-content:center;">
<div class="lite-logo">
<a href="https://argumenti.ru/an">
<a href="https://klan.argumenti.ru">
<img src="https://argumenti.ru/images/argumenti/klan_logo.png?ver=1">
</a>
</div>

View File

@@ -0,0 +1,8 @@
<div id="auth">
<?if (defined('CLIENT_ID')):?>
<a href="<?=SITE?>mybooks">Моя библиотека</a>&nbsp;
<a href="<?=SITE?>out">Выйти</a>
<?else:?>
<a href="<?=SITE?>login">Войти</a>
<?endif?>
</div>

View File

@@ -1,28 +1,12 @@
<?if ($items['subscript'] == true):?>
<div class="small-mob-hidden"><p>Вам доступен весь архив</p></div>
<?else:?>
<div class="small-mob-hidden"><p>Всего покупок: <?=$items['count']?></p></div>
<?endif?>
<?if (defined('CLIENT_ID') and CLIENT_ID > 0):?>
<?if ($category == 'gazeta'):?>
<div id="years">
<p>
<select id="year_filter" onchange="changeyear()">
<option value="all"<?=$selected?>>Все года</option>
<?for ($y = date('Y'); $y >= 2006; $y--):?>
<?$selected = ($filter == $y) ? ' selected' : ''?>
<option value="<?=$y?>"<?=$selected?>><?=$y?> год</option>
<?endfor?>
</select>
<i class="fas fa-chevron-down"></i>
</p>
<div>
<a href="<?=SITE?>payments">Мои покупки</a>
</div>
<div class="hid460">
<a href="<?=SITE?>form">Консультации</a>
</div>
<?endif?>
<div>
<a href="<?=SITE?>payments">Мои покупки</a>
</div>
<div class="hid460">
<a href="<?=SITE?>form">Консультации</a>
</div>
<?endif?>

View File

@@ -1,11 +1,22 @@
<div id="menu_category">
<ul>
<?if ($category == 'gazeta'):?>
<li class="active">Газета</li>
<li><a href="<?=SITE?>mybooks/books/all/1">Книги</a></li>
<?else:?>
<li><a href="<?=SITE?>mybooks/gazeta/all/1">Газета</a></li>
<li class="active">Книги</li>
<?endif?>
</ul>
</div>
<?$cats = api_cats();?>
<?if (!isset($cats[['error']])):?>
<div id="menu_category">
<ul>
<?foreach($cats as $cat):?>
<?if ($category == $cat['categoryslug']):?>
<li class="active"><?=$cat['categoryname']?></li>
<?else:?>
<li><a href="<?=SITE?>category/<?=$cat['categoryslug']?>"><?=$cat['categoryname']?></a></li>
<?endif?>
<?endforeach?>
</ul>
</div>
<?endif?>