-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathtcpdf_autoconfig.php
More file actions
292 lines (243 loc) · 8.49 KB
/
Copy pathtcpdf_autoconfig.php
File metadata and controls
292 lines (243 loc) · 8.49 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
/**
* @file
* Try to automatically configure some TCPDF constants if not defined.
* @package com.tecnick.tcpdf
*/
// Disable phar stream wrapper globally.
// if (in_array('phar', stream_get_wrappers(), true)) {
// stream_wrapper_unregister('phar');
// }
// DOCUMENT_ROOT fix for IIS Webserver
if (!isset($_SERVER['DOCUMENT_ROOT']) or empty($_SERVER['DOCUMENT_ROOT'])) {
if (isset($_SERVER['SCRIPT_FILENAME'])) {
$_SERVER['DOCUMENT_ROOT'] = str_replace(
'\\',
'/',
substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF'])),
);
} elseif (isset($_SERVER['PATH_TRANSLATED'])) {
$_SERVER['DOCUMENT_ROOT'] = str_replace(
'\\',
'/',
substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 - strlen($_SERVER['PHP_SELF'])),
);
} else {
// define here your DOCUMENT_ROOT path if the previous fails (e.g. '/var/www')
$_SERVER['DOCUMENT_ROOT'] = '/';
}
}
$_SERVER['DOCUMENT_ROOT'] = str_replace('//', '/', $_SERVER['DOCUMENT_ROOT']);
if (substr($_SERVER['DOCUMENT_ROOT'], -1) != '/') {
$_SERVER['DOCUMENT_ROOT'] .= '/';
}
// Load main configuration file only if the K_TCPDF_EXTERNAL_CONFIG constant is set to false.
if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
// define a list of default config files in order of priority
$tcpdf_config_files = [
dirname(__FILE__) . '/config/tcpdf_config.php',
'/etc/php-tcpdf/tcpdf_config.php',
'/etc/tcpdf/tcpdf_config.php',
'/etc/tcpdf_config.php',
];
foreach ($tcpdf_config_files as $tcpdf_config) {
if (!(@file_exists($tcpdf_config) and is_readable($tcpdf_config))) {
continue;
}
require_once $tcpdf_config;
break;
}
}
if (!defined('K_PATH_MAIN')) {
define('K_PATH_MAIN', dirname(__FILE__) . '/');
}
// Load Composer autoloader if available (for tc-lib dependencies).
if (@file_exists(K_PATH_MAIN . 'vendor/autoload.php')) {
require_once K_PATH_MAIN . 'vendor/autoload.php';
}
if (!defined('K_TCPDF_LIB_PDF_PATH')) {
$tcpdf_lib_pdf_path = K_PATH_MAIN . 'vendor/tecnickcom/tc-lib-pdf/src';
if (@is_dir($tcpdf_lib_pdf_path)) {
define('K_TCPDF_LIB_PDF_PATH', $tcpdf_lib_pdf_path);
}
}
if (!defined('K_PATH_FONTS')) {
define('K_PATH_FONTS', K_PATH_MAIN . 'vendor/tecnickcom/tc-lib-pdf-font/target/fonts/');
}
if (!defined('K_PATH_URL')) {
$k_path_url = K_PATH_MAIN; // default value for console mode
if (isset($_SERVER['HTTP_HOST']) and !empty($_SERVER['HTTP_HOST'])) {
if (isset($_SERVER['HTTPS']) and !empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') {
$k_path_url = 'https://';
} else {
$k_path_url = 'http://';
}
$k_path_url .= $_SERVER['HTTP_HOST'];
$k_path_url .= str_replace('\\', '/', substr(K_PATH_MAIN, strlen($_SERVER['DOCUMENT_ROOT']) - 1));
}
define('K_PATH_URL', $k_path_url);
}
if (!defined('K_PATH_IMAGES')) {
$tcpdf_images_dirs = [
K_PATH_MAIN . 'examples/images/',
K_PATH_MAIN . 'images/',
'/usr/share/doc/php-tcpdf/examples/images/',
'/usr/share/doc/tcpdf/examples/images/',
'/usr/share/doc/php/tcpdf/examples/images/',
'/var/www/tcpdf/images/',
'/var/www/html/tcpdf/images/',
'/usr/local/apache2/htdocs/tcpdf/images/',
K_PATH_MAIN,
];
foreach ($tcpdf_images_dirs as $tcpdf_images_path) {
if (!@file_exists($tcpdf_images_path)) {
continue;
}
define('K_PATH_IMAGES', $tcpdf_images_path);
break;
}
}
if (!defined('PDF_HEADER_LOGO')) {
$tcpdf_header_logo = '';
if (@file_exists(K_PATH_IMAGES . 'tcpdf_logo.jpg')) {
$tcpdf_header_logo = 'tcpdf_logo.jpg';
}
define('PDF_HEADER_LOGO', $tcpdf_header_logo);
}
if (!defined('PDF_HEADER_LOGO_WIDTH')) {
if (!empty($tcpdf_header_logo)) {
define('PDF_HEADER_LOGO_WIDTH', 30);
} else {
define('PDF_HEADER_LOGO_WIDTH', 0);
}
}
if (!defined('K_PATH_CACHE')) {
$K_PATH_CACHE = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
if (substr($K_PATH_CACHE, -1) != '/') {
$K_PATH_CACHE .= '/';
}
define('K_PATH_CACHE', $K_PATH_CACHE);
}
if (!defined('K_BLANK_IMAGE')) {
define('K_BLANK_IMAGE', '_blank.png');
}
if (!defined('PDF_PAGE_FORMAT')) {
define('PDF_PAGE_FORMAT', 'A4');
}
if (!defined('PDF_PAGE_ORIENTATION')) {
define('PDF_PAGE_ORIENTATION', 'P');
}
if (!defined('PDF_CREATOR')) {
define('PDF_CREATOR', 'TCPDF');
}
if (!defined('PDF_AUTHOR')) {
define('PDF_AUTHOR', 'TCPDF');
}
if (!defined('PDF_HEADER_TITLE')) {
define('PDF_HEADER_TITLE', 'TCPDF Example');
}
if (!defined('PDF_HEADER_STRING')) {
define('PDF_HEADER_STRING', "Nicola Asuni - Tecnick.com\nhttps://tcpdf.org");
}
if (!defined('PDF_UNIT')) {
define('PDF_UNIT', 'mm');
}
if (!defined('PDF_MARGIN_HEADER')) {
define('PDF_MARGIN_HEADER', 5);
}
if (!defined('PDF_MARGIN_FOOTER')) {
define('PDF_MARGIN_FOOTER', 10);
}
if (!defined('PDF_MARGIN_TOP')) {
define('PDF_MARGIN_TOP', 27);
}
if (!defined('PDF_MARGIN_BOTTOM')) {
define('PDF_MARGIN_BOTTOM', 25);
}
if (!defined('PDF_MARGIN_LEFT')) {
define('PDF_MARGIN_LEFT', 15);
}
if (!defined('PDF_MARGIN_RIGHT')) {
define('PDF_MARGIN_RIGHT', 15);
}
if (!defined('PDF_FONT_NAME_MAIN')) {
define('PDF_FONT_NAME_MAIN', 'helvetica');
}
if (!defined('PDF_FONT_SIZE_MAIN')) {
define('PDF_FONT_SIZE_MAIN', 10);
}
if (!defined('PDF_FONT_NAME_DATA')) {
define('PDF_FONT_NAME_DATA', 'helvetica');
}
if (!defined('PDF_FONT_SIZE_DATA')) {
define('PDF_FONT_SIZE_DATA', 8);
}
if (!defined('PDF_FONT_MONOSPACED')) {
define('PDF_FONT_MONOSPACED', 'courier');
}
if (!defined('PDF_IMAGE_SCALE_RATIO')) {
define('PDF_IMAGE_SCALE_RATIO', 96 / 72);
}
if (!defined('HEAD_MAGNIFICATION')) {
define('HEAD_MAGNIFICATION', 1.1);
}
if (!defined('K_CELL_HEIGHT_RATIO')) {
define('K_CELL_HEIGHT_RATIO', 1.25);
}
if (!defined('K_TITLE_MAGNIFICATION')) {
define('K_TITLE_MAGNIFICATION', 1.3);
}
if (!defined('K_SMALL_RATIO')) {
define('K_SMALL_RATIO', 2 / 3);
}
if (!defined('K_THAI_TOPCHARS')) {
define('K_THAI_TOPCHARS', true);
}
if (!defined('K_TCPDF_CALLS_IN_HTML')) {
define('K_TCPDF_CALLS_IN_HTML', false);
}
if (!defined('K_ALLOWED_TCPDF_TAGS')) {
define('K_ALLOWED_TCPDF_TAGS', '');
}
if (!defined('K_TCPDF_THROW_EXCEPTION_ERROR')) {
define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
}
if (!defined('K_TIMEZONE')) {
define('K_TIMEZONE', @date_default_timezone_get());
}
// ----------------------------------------------------------------------------
// File-access security model (tc-lib-pdf / tc-lib-file).
//
// External resources (images, fonts, SVG, imported PDFs, ...) are loaded
// through a sandboxed file helper. Local reads are restricted to an allowlist
// of trusted directories and remote (HTTP/HTTPS) reads are DISABLED unless an
// explicit allowlist of host names is provided. The constants below feed that
// sandbox; safe defaults keep remote loading off and only the bundled/runtime
// asset directories readable.
// ----------------------------------------------------------------------------
// Additional trusted local directories the library may read files from.
// Array of absolute path prefixes, merged on top of the built-in defaults
// (system temp dir, K_PATH_MAIN, the bundled vendor dir, the working
// directory, K_PATH_FONTS, K_PATH_IMAGES and the running script directory).
// The built-in defaults are always included; this only ever widens access.
if (!defined('K_ALLOWED_PATHS')) {
define('K_ALLOWED_PATHS', []);
}
// Trusted remote host names that enable HTTP/HTTPS resource loading.
// Array of exact host names (e.g. ['cdn.example.com', 'example.org']).
// Leave EMPTY to keep remote URL loading disabled (recommended default and
// the only protection against SSRF when rendering untrusted content).
if (!defined('K_ALLOWED_HOSTS')) {
define('K_ALLOWED_HOSTS', []);
}
// Maximum size, in bytes, accepted for a single remote download.
// Reads exceeding this limit are rejected. Default: 52428800 (50 MiB).
if (!defined('K_MAX_REMOTE_SIZE')) {
define('K_MAX_REMOTE_SIZE', 52428800);
}
// Custom cURL options (array of CURLOPT_* => value) merged over the library
// defaults for remote downloads. Security-critical options (TLS verification,
// redirect handling) are enforced upstream and cannot be overridden here.
if (!defined('K_CURLOPTS')) {
define('K_CURLOPTS', []);
}