169 lines
3.5 KiB
PHP
169 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
*/
|
|
|
|
function bookid_kuri($slug) {
|
|
|
|
$query = "
|
|
SELECT
|
|
`price_id`, `pricename`, `categoryname`, `priceslug`, `categoryslug`, price.category_id AS category_id, `BeginDate`, `priceanons`, `priceimg`, `pricehash`, `price`, `offline_price`, `sub`
|
|
FROM
|
|
`price`
|
|
LEFT JOIN `pricecategory`
|
|
ON price.category_id = pricecategory.category_id
|
|
WHERE
|
|
`priceslug` = '$slug'
|
|
LIMIT 1
|
|
";
|
|
|
|
$book = dbl_get($query);
|
|
|
|
if (isset($book['price_id'])){
|
|
|
|
//$book['pic'] = IMGSRV."price/300x470/{$book['price_id']}.{$book['priceimg']}";
|
|
$book['pic'] = picbook($book, 300, 470);
|
|
|
|
$book['links']['pdf'] = SITE.'read/'.$book['pricehash'];
|
|
$book['links']['text'] = SITE.'readtext/'.$book['pricehash'];
|
|
$file = PDFSOURCE.$book['price_id'].'.pdf';
|
|
$pdf = pdfs_init($file ,1);
|
|
$book['links']['download'] = $pdf['pdfurl'];
|
|
|
|
return $book;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* вернуть товары магазина (все или по фильтру)
|
|
*/
|
|
function api_books_kuri($category = 'knigi', $filter = 'all', $page = 1){
|
|
|
|
$limit = 24;
|
|
|
|
if ($page > 1){
|
|
$offset = $limit * ($page - 1);
|
|
$offset_str = ", $offset";
|
|
}
|
|
else {
|
|
$offset_str = '';
|
|
}
|
|
|
|
if ($category == 'all'){
|
|
$where = '';
|
|
}
|
|
else {
|
|
|
|
$category_sql = "SELECT `category_id` FROM `pricecategory` WHERE `categoryslug` = '$category' LIMIT 1";
|
|
|
|
$category = db_get($category_sql);
|
|
|
|
if (isset($category['category_id'])) {
|
|
$category_id = $category['category_id'];
|
|
$where = "WHERE `category_id` = $category_id";
|
|
}
|
|
|
|
}
|
|
|
|
$db_count = db_get("SELECT COUNT(price_id) AS count FROM `price` $where LIMIT 1;");
|
|
|
|
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>";
|
|
|
|
}
|
|
|
|
|
|
} |