forked from GATEOverflow/q2a-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqa-book-overrides.php
executable file
·64 lines (59 loc) · 2.65 KB
/
qa-book-overrides.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
<?php
function qa_get_request_content() {
if(qa_opt('book_plugin_active')) {
$requestlower=strtolower(qa_request());
if($requestlower && $requestlower === qa_opt('book_plugin_request')) {
if(qa_opt('book_plugin_static') && file_exists(qa_opt('book_plugin_loc'))) {
if(qa_opt('book_plugin_refresh') && ((qa_opt('book_plugin_refresh_time') && (int)qa_opt('book_plugin_refresh_hours')) || (qa_get('cron') == 'true' && qa_opt('book_plugin_refresh_cron'))) && time() > qa_opt('book_plugin_refresh_last')+(qa_opt('book_plugin_refresh_hours')*60*60)) {
qa_book_plugin_createBook();
if(qa_get('cron') == 'true') {
echo "true\n";
return false;
}
}
else if (qa_get('cron') == 'true') {
if(!qa_opt('book_plugin_refresh_cron'))
error_log('Q2A Book Recreate Error: cron request not allowed via admin/plugins');
else
error_log('Q2A Book Recreate Error: cron request before minimum time elapsed');
echo "false\n";
return false;
}
include(qa_opt('book_plugin_loc'));
}
else if(file_exists(qa_opt('book_plugin_loc')))
echo qa_book_plugin_createBook(true);
else
echo qa_book_plugin_createBook(false);
return false;
}
else if(qa_opt('book_plugin_pdf') && $requestlower && $requestlower === qa_opt('book_plugin_request_pdf')) {
if(qa_opt('book_plugin_static')) {
// refresh
if(qa_opt('book_plugin_refresh') && (qa_opt('book_plugin_refresh_time') && (int)qa_opt('book_plugin_refresh_hours')) && time() > qa_opt('book_plugin_refresh_last')+(qa_opt('book_plugin_refresh_hours')*60*60)) {
qa_book_plugin_createBook();
}
$pdf = file_get_contents(qa_opt('book_plugin_loc_pdf'));
header('Content-Description: File Transfer');
header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
// force download dialog
header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream', false);
header('Content-Type: application/download', false);
header('Content-Type: application/pdf', false);
// use the Content-Disposition header to supply a recommended filename
header('Content-Disposition: attachment; filename="'.basename(qa_opt('book_plugin_loc_pdf')).'";');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.strlen($pdf));
echo $pdf;
}
else
qa_book_plugin_create_pdf(true);
return false;
}
}
return qa_get_request_content_base();
}