include("config.php");
function delete_litres_book($hub_id){
$mysqli = new mysqli(DBHOST,DBUSER,DBPASS,DBNAME);
//удаляем книги путем простановки options=0
$q = "UPDATE `litres_data` SET options=0 WHERE hub_id=" . $hub_id;
$mysqli->query($q);
}
<?php
ini_set('log_errors', 'On');
ini_set('error_log', 'php_errors.log');
include("config.php");
include("config_litres.php");
include("functions.php");
$allowed_genres = "1";
/*AND local_book_id_litres_catalog IS NULL*/
/*AND ydisk_book_url != ''*/
/*AND hub_id IN (" . $top_ids . ")*/
/*AND has_trial>0*/
$manual_hub_ids = top_sales_hub_ids('https://www.litres.ru/static/ds/topsales3days.yml');
$q = "(SELECT * FROM `litres_data`
WHERE
`type` = 0 AND
`hub_id` > 0
AND local_book_id IS NULL
AND local_book_id_litres_catalog IS NULL
AND genre != ''
AND (" . $allowed_genres . ")
AND options&2
AND hub_id IN (" . implode(',',$manual_hub_ids) . ")
LIMIT 10)
UNION
(SELECT * FROM `litres_data`
WHERE
`type` = 0 AND
`hub_id` > 0 AND (`lang` = 'ru')
AND local_book_id IS NULL
AND local_book_id_litres_catalog IS NULL
AND genre != ''
AND (" . $allowed_genres . ")
AND options&2
ORDER BY date_inserted DESC
LIMIT 5)
";
$result = mysqli_query($db_link, $q);
while ($row = mysqli_fetch_array($result)){
if($row['local_book_id'] == NULL){
$litres_link = 'https://www.litres.ru/' . ($row['litres_url'] != '' ? $row['litres_url'] . '?lfrom=' : 'pages/biblio_book/?art=' . $row['hub_id'] . '&lfrom=' ) . $partner_id;
//жанры
/*
$genres = explode('|',$row['genre'],2);
$rec_cat = mysql_query("SELECT local_category FROM `litres_genres_relation` WHERE local_category > 0 AND litres_token IN ('" . $genres[0] . "','" . $genres[1] . "')");
if (mysql_num_rows($rec_cat) == 0){
echo 'нет жанра в локальной таблице (' . $row['hub_id'] . ')';
//делаем пометку что книгу нельзя импортнуть из-за отсутствия жанра чтобы в след раз опять не дергать эту книгу
$q = "UPDATE `litres_data` SET
local_book_id_litres_catalog = '-1'
WHERE hub_id = " . $row['hub_id'];
mysql_query($q);
continue;
} //если не нашли локальный жанр, то пропускаем книгу
$r_cat = mysql_fetch_array($rec_cat);
$local_categories = $r_cat['local_category'];
*/
$local_categories = 99;
$title = stripslashes(trim($row['author_name'] . ' ' . $row['author_sname']) . ' - ' . $row['book_title']);
//перекодировку не убирать!
$alt_name = totranslit(mb_convert_encoding(stripslashes($row['book_title']),'windows-1251','UTF-8'), true, false );
$dir_name = date("Y-m");
@mkdir(ROOT_DIR . '/uploads/posts/' . $dir_name);
@mkdir(ROOT_DIR . '/uploads/posts/' . $dir_name . '/thumbs');
$pic_name = time() . "_" . $row['hub_id'] . '.jpg';
$full_story = '<div style="text-align:center;"><!--dle_image_begin:http://www.vipbook.su/uploads/posts/' . $dir_name . '/' . $pic_name . '|--><img src="http://www.vipbook.su/uploads/posts/' . $dir_name . '/' . $pic_name . '" alt="Джейн Фэллон - Дважды два - четыре" title="' . $title . '" /><!--dle_image_end--></div><br />
<div style="text-align:center;">' . nl2br(mb_substr($row['annotation'],0,400,'utf-8')) . '<br /><br />
<b>Название:</b> ' . trim($row['book_title']) . '<br />
<b>Автор:</b> ' . trim($row['author_name'] . ' ' . $row['author_sname']) . '<br />
' . ($row['publisher'] != '' ? '<b>Издательство:</b> ' . $row['publisher'] . '<br />' : '') . '
' . ($row['publ_year'] > 0 ? '<b>Год:</b> ' . $row['publ_year'] . '<br />' : '') . '
<b>Формат:</b> RTF/FB2<br />
<b>Язык:</b> Русский
</div><br /><br />';
/*<div style="text-align:center;"><b>Скачать ' . $title . ' [' . ($row['publ_year'] > 0 ? $row['publ_year'] . ', ' : '') . 'RTF/FB2]</b></div><br />*/
$short_story = '<div style="text-align:center;"><!--dle_image_begin:http://www.vipbook.su/uploads/posts/' . $dir_name . '/' . $pic_name . '|--><img src="http://www.vipbook.su/uploads/posts/' . $dir_name . '/' . $pic_name . '" alt="Джейн Фэллон - Дважды два - четыре" title="' . $title . '" /><!--dle_image_end--></div><br />
<div style="text-align:center;">' . nl2br(mb_substr($row['annotation'],0,200,'utf-8')) . '</div>';
$xfields = array(); $xfields_str = '';
if ($r['xfields'] != '') $xfields = explode_xfields($r['xfields']);
$xfields['litres_link'] = $litres_link;
if ($book_type == 0){
$xfields['hub_id'] = $row['hub_id'];
}
elseif($book_type == 1){
$xfields['hub_id_audio'] = $row['hub_id'];
}
//собираем поля xfields в кучу
$xfields_str = implode_xfields($xfields);
//создаем ключевики (функция возвращает глоб переменную $metatags['keywords'])
//create_keywords($full_story);
if ($row['local_book_id_litres_catalog'] == NULL){
echo $q = "INSERT INTO dle_post SET
autor = 'litres',
date = '" . date("Y-m-d H:i:s") . "',
short_story = '" . mysqli_real_escape_string($db_link, $short_story) . "',
full_story = '" . mysqli_real_escape_string($db_link, $full_story) . "',
xfields = '" . mysqli_real_escape_string($db_link, $xfields_str) . "',
title = '" . mysqli_real_escape_string($db_link, $title) . "',
descr = '',
keywords = '',
category = '" . $local_categories . "',
alt_name = '" . $alt_name . "',
comm_num = 0,
allow_comm = 1,
allow_main = 0,
approve = 1,
fixed = 0,
allow_br = 1,
symbol = '',
tags = '',
metatitle = '" . mysqli_real_escape_string($db_link, $title) . "'
";
mysqli_query($db_link, $q);
$local_book_id = mysqli_insert_id($db_link);
echo $q = "INSERT INTO dle_images SET
images = '" . $dir_name . "/" . $pic_name . "',
news_id = " . $local_book_id . ",
author = 'litres',
date = '" . time() . "',
metatitle = '" . mysqli_real_escape_string($db_link, $title) . "'
";
mysqli_query($db_link, $q);
}
else{
echo $q = "UPDATE dle_post SET
short_story = '" . mysqli_real_escape_string($db_link, $short_story) . "',
full_story = '" . mysqli_real_escape_string($db_link, $full_story) . "',
xfields = '" . mysqli_real_escape_string($db_link, $xfields_str) . "',
title = '" . mysqli_real_escape_string($db_link, $row['book_title']) . "',
descr = '',
category = '" . $local_categories . "'
WHERE id = " . $row['local_book_id_litres_catalog'];
mysqli_query($db_link, $q);
$local_book_id = $row['local_book_id_litres_catalog'];
}
echo $q = "UPDATE `litres_data` SET
local_book_id_litres_catalog = " . $local_book_id . "
WHERE hub_id = " . $row['hub_id'];
mysqli_query($db_link, $q);
}
else{
$local_book_id = ($row['local_book_id_litres_catalog'] > 0 ? $row['local_book_id_litres_catalog'] : $row['local_book_id']);
}
//вставка доп данных
$q = "SELECT * FROM dle_post_extras WHERE news_id = " . $local_book_id . " LIMIT 1";
$res_extra = mysqli_query($db_link, $q);
//вставляем данные только если новая книга и записи еще нет
if (mysqli_num_rows($res_extra) == 0){
mysqli_query($db_link, "INSERT IGNORE INTO dle_post_extras (news_id,user_id) VALUES (". $local_book_id .",103342)");
}
/*$q = "INSERT INTO litres_local SET
local_id = " . $local_book_id . ",
hub_id = " . $row['hub_id'] . ",
litres_link = '" . $litres_link . "'
ON DUPLICATE KEY UPDATE
hub_id = " . $row['hub_id'] . ",
litres_link = '" . $litres_link . "'";
mysql_query($q);*/
//файлы
//обложка
$cover_id = $row['litres_id'];
while (strlen($cover_id) < 8){
$cover_id = '0' . $cover_id;
}
$cover_path = 'http://www.litres.ru/static/bookimages/' . $cover_id[0] . $cover_id[1] . '/' . $cover_id[2] . $cover_id[3] . '/' . $cover_id[4] . $cover_id[5] . '/' . $cover_id . '.bin.dir/' . $cover_id . '.cover.' . $row['cover_ext'];
$new_image = new picture($cover_path);
$new_image->imageresizewidth(240);
$new_image->imagesave($new_image->image_type, ROOT_DIR . '/uploads/posts/' . $dir_name . '/' . $pic_name, 85);
$new_image->imageout();
/*
$new_image = new picture($cover_path);
$new_image->imageresizewidth(150);
$new_image->imagesave($new_image->image_type, ROOT_DIR . '/uploads/posts/' . $dir_name . '/thumbs/' . $pic_name, 85);
$new_image->imageout();
*/
//ждем между книгами, чтобы не было банна
sleep(3);
}
?>
php import_book.php
Warning: mysqli_insert_id() expects exactly 1 parameter, 0 given in /var/www/import_books.php on line
147
INSERT INTO dle_images SET
images = '2018-10/1539548905_177489.jpg',
news_id = ,
author = 'litres',
date = '1539548905',
metatitle = 'Руди Рюкер - Что случилось с Гудини?'
UPDATE `litres_data` SET
local_book_id_litres_catalog =
WHERE hub_id = 177489
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/import_
books.php on line 185
$q = "SELECT id FROM `dle_post`
LEFT JOIN litres_local_data USING (id)
WHERE
litresed > 0
";
Warning: implode(): Invalid arguments passed in /var/www/checklist.php on line 31
<?php
include("config.php");
mysqli_query($db_link, "SET NAMES utf8");
$q = "SELECT count(*) AS c FROM `dle_post`";
$result = mysqli_query($db_link, $q);
$row = mysqli_fetch_array($result);
$total_count = $row['c'];
$q = "SELECT id FROM `dle_post`
LEFT JOIN litres_local_data USING (id)
WHERE
litresed > 0
";
$result = mysqli_query($db_link, $q);
$litresed_count = mysqli_num_rows($result);
while ($row = mysqli_fetch_array($result)){
$ids[] = $row['id'];
}
$ids = array();
$ids = implode(',',$ids);
var_dump($ids);
$q = "SELECT * FROM `dle_post`
WHERE
id NOT IN (" . $ids . ")
ORDER BY title";
$result = mysqli_query($db_link, $q);
echo 'В базе: ' . $total_count . ' | ' . 'Совпало: ' . $litresed_count . ' | ' . 'Не совпало: ' . ($total_count - $litresed_count) . "<br><br>";
while ($row = mysqli_fetch_array($result)){
$author = '';
$needle = 'Автор';
if (preg_match("/" . $needle . "(.{3,})</iuU",$row['full_story'],$matches) !== false){
$matches[1] = strip_tags($matches[1]);
$matches[1] = str_replace(':','',$matches[1]);
$matches[1] = stripslashes($matches[1]);
$matches[1] = trim($matches[1]);
$author = $matches[1];
}
echo $row['id'] . '|' . $row['title'] . '|' . $author . "<br>";
}
if (!$result)
var_dump("Errormessage: " . mysqli_error($db_link));
?>
В базе: 3 | Совпало: 0 | Не совпало: 3
string(180) "Errormessage: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY title' at line 3"