-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreview.php
68 lines (56 loc) · 1.94 KB
/
preview.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require_once 'utils/bookmeter_utils.php';
require_once 'utils/site_globals.php';
require_once 'utils/bookmeter_entry.php';
require_once 'utils/error_log_file.php';
if(!isset($_COOKIE[session_name()]))
{
error_log_file::append('preview.php 404');
http_response_code(404);
return;
}
session_start();
function success_response($body)
{
$response = new stdClass;
$response->errmsg = '';
$response->body = $body;
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($response);
exit;
}
function error_response($errmsg)
{
$response = new stdClass;
$response->errmsg = htmlspecialchars($errmsg);
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($response);
exit;
}
$bm_entry = new bookmeter_entry;
$bm_entry->set_title($_POST['title_input']);
$bm_entry->set_author($_POST['author_input']);
$bm_entry->set_genre($_POST['genre_select_input'], $_POST['genre_input']);
$bm_entry->set_isbn($_POST['isbn_input']);
$bm_entry->set_translator($_POST['translator_input']);
$bm_entry->set_publisher($_POST['publisher_input']);
$bm_entry->set_number_of_pages($_POST['number_of_pages_input']);
$bm_entry->set_book_form($_POST['book_form_input'] ?? null);
$bm_entry->set_description($_POST['descr_input']);
$bm_entry->set_additional_tags($_POST['tags_input']);
$bm_entry->set_rate($_POST['selected_rating']);
$bm_entry->set_save_additional_tags($_POST['save_tags_input'] ?? null);
$bm_entry->set_bold_labels($_POST['bold_labels_input'] ?? null);
$bm_entry->set_use_star_rating($_POST['use_star_rating_input'] ?? null);
$bm_entry->set_add_ad($_POST['add_ad_input'] ?? null);
$val_error = $bm_entry->validate();
if($val_error != '')
error_response($val_error);
$bmu = new bookmeter_utils;
$predicted_counter = $bmu->get_counter(site_globals::$tag_name) + 1;
$body = $bm_entry->compose_msg($predicted_counter);
$body = htmlspecialchars($body);
$body = nl2br($body);
$bm_entry->save_settings();
success_response($body);
?>