-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpdf.php
More file actions
147 lines (127 loc) · 4.1 KB
/
pdf.php
File metadata and controls
147 lines (127 loc) · 4.1 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* PDF export.
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @author Peter Beauvain <pbeauvain@web.de>
* @author Olivier Plathey <olivier@fpdf.org>
* @author Krzysztof Kruszynski <thywolf@wolf.homelinux.net>
* @author Matteo Scaramuccia <matteo@phpmyfaq.de>
* @copyright 2003-2022 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2003-02-12
*/
use phpMyFAQ\Category;
use phpMyFAQ\Export\Pdf;
use phpMyFAQ\Faq;
use phpMyFAQ\Filter;
use phpMyFAQ\Helper\HttpHelper;
use phpMyFAQ\Language;
use phpMyFAQ\Language\Plurals;
use phpMyFAQ\Permission\MediumPermission;
use phpMyFAQ\Strings;
use phpMyFAQ\Tags;
use phpMyFAQ\User\CurrentUser;
const IS_VALID_PHPMYFAQ = null;
//
// Bootstrapping
//
require 'src/Bootstrap.php';
// get language (default: english)
$Language = new Language($faqConfig);
$faqLangCode = $Language->setLanguage($faqConfig->get('main.languageDetection'), $faqConfig->get('main.language'));
$faqConfig->setLanguage($Language);
// Found an article language?
$lang = Filter::filterInput(INPUT_POST, 'artlang', FILTER_UNSAFE_RAW);
if (is_null($lang) && !Language::isASupportedLanguage($lang)) {
$lang = Filter::filterInput(INPUT_GET, 'artlang', FILTER_UNSAFE_RAW);
if (is_null($lang) && !Language::isASupportedLanguage($lang)) {
$lang = $faqLangCode;
}
}
if (isset($lang) && Language::isASupportedLanguage($lang)) {
require_once 'lang/language_' . $lang . '.php';
} else {
$lang = 'en';
require_once 'lang/language_en.php';
}
//
// Initializing static string wrapper
//
Strings::init($faqLangCode);
$plr = new Plurals($PMF_LANG);
// authenticate with session information
$user = CurrentUser::getFromCookie($faqConfig);
if (!$user instanceof CurrentUser) {
$user = CurrentUser::getFromSession($faqConfig);
}
if ($user instanceof CurrentUser) {
$auth = true;
} else {
$user = null;
}
// Get current user and group id - default: -1
if (!is_null($user) && $user instanceof CurrentUser) {
$currentUser = $user->getUserId();
if ($user->perm instanceof MediumPermission) {
$currentGroups = $user->perm->getUserGroups($currentUser);
} else {
$currentGroups = [-1];
}
if (0 == count($currentGroups)) {
$currentGroups = [-1];
}
} else {
$currentUser = -1;
$currentGroups = [-1];
}
$currentCategory = Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT);
$id = Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
$getAll = Filter::filterInput(INPUT_GET, 'getAll', FILTER_VALIDATE_BOOLEAN, false);
$faq = new Faq($faqConfig);
$faq->setUser($currentUser);
$faq->setGroups($currentGroups);
$category = new Category($faqConfig, $currentGroups, true);
$category->setUser($currentUser);
try {
$pdf = new Pdf($faq, $category, $faqConfig);
} catch (Exception $e) {
// handle exception
}
$http = new HttpHelper();
if (true === $getAll) {
$category->buildCategoryTree();
}
$tags = new Tags($faqConfig);
$headers = [
'Pragma: no-cache',
'Expires: 0',
'Cache-Control: no-store',
];
if (true === $getAll && $user->perm->hasPermission($user->getUserId(), 'export')) {
$filename = 'FAQs.pdf';
$pdfFile = $pdf->generate(0, true, $lang);
} else {
if (is_null($currentCategory) || is_null($id)) {
$http->redirect($faqConfig->getDefaultUrl());
exit();
}
$faq->getRecord($id);
$faq->faqRecord['category_id'] = $currentCategory;
$filename = 'FAQ-' . $id . '-' . $lang . '.pdf';
$pdfFile = $pdf->generateFile($faq->faqRecord, $filename);
}
if (preg_match('/MSIE/i', $_SERVER['HTTP_USER_AGENT'])) {
$headers[] = 'Content-type: application/pdf';
$headers[] = 'Content-Transfer-Encoding: binary';
$headers[] = 'Content-Disposition: attachment; filename=' . $filename;
} else {
$headers[] = 'Content-Type: application/pdf';
}
$http->sendWithHeaders($pdfFile, $headers);