Passed
Pull Request — release-2.1 (#6101)
by Jon
03:54
created

export_attachment()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 51
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 24
c 1
b 0
f 0
nc 7
nop 1
dl 0
loc 51
rs 8.9137

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * This file contains functions to export a member's profile data to a
5
 * downloadable file.
6
 *
7
 * Simple Machines Forum (SMF)
8
 *
9
 * @package SMF
10
 * @author Simple Machines https://www.simplemachines.org
11
 * @copyright 2020 Simple Machines and individual contributors
12
 * @license https://www.simplemachines.org/about/smf/license.php BSD
13
 *
14
 * @version 2.1 RC2
15
 */
16
17
if (!defined('SMF'))
18
	die('No direct access...');
19
20
21
/**
22
 * Initiates exports a member's profile, posts, and personal messages to a file.
23
 *
24
 * @todo Add CSV, JSON as other possible export formats besides XML and HTML?
25
 *
26
 * @param int $uid The ID of the member whose data we're exporting.
27
 */
28
function export_profile_data($uid)
29
{
30
	global $context, $smcFunc, $txt, $modSettings, $sourcedir, $scripturl;
31
	global $query_this_board;
32
33
	if (!isset($context['token_check']))
34
		$context['token_check'] = 'profile-ex' . $uid;
35
36
	$context['export_formats'] = get_export_formats();
37
38
	if (!isset($_POST['format']) || !isset($context['export_formats'][$_POST['format']]))
39
		unset($_POST['format'], $_POST['delete'], $_POST['export_begin']);
40
41
	// This lists the types of data we can export and info for doing so.
42
	$context['export_datatypes'] = array(
43
		'profile' => array(
44
			'label' => null,
45
			'total' => 0,
46
			'latest' => 1,
47
			// Instructions to pass to ExportProfileData background task:
48
			'XML' => array(
49
				'func' => 'getXmlProfile',
50
				'langfile' => 'Profile',
51
			),
52
			'HTML' => array(
53
				'func' => 'getXmlProfile',
54
				'langfile' => 'Profile',
55
			),
56
			'XML_XSLT' => array(
57
				'func' => 'getXmlProfile',
58
				'langfile' => 'Profile',
59
			),
60
			// 'CSV' => array(),
61
			// 'JSON' => array(),
62
		),
63
		'posts' => array(
64
			'label' => $txt['export_include_posts'],
65
			'total' => $context['member']['real_posts'],
66
			'latest' => function($uid)
67
			{
68
				global $smcFunc, $modSettings;
69
70
				static $latest_post;
71
72
				if (isset($latest_post))
73
					return $latest_post;
74
75
				$query_this_board = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? 'b.id_board != ' . $modSettings['recycle_board'] : '1=1';
76
77
				$request = $smcFunc['db_query']('', '
78
					SELECT m.id_msg
79
					FROM {db_prefix}messages as m
80
						INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
81
					WHERE id_member = {int:uid}
82
						AND ' . $query_this_board . '
83
					ORDER BY id_msg DESC
84
					LIMIT {int:limit}',
85
					array(
86
						'limit' => 1,
87
						'uid' => $uid,
88
					)
89
				);
90
				list($latest_post) = $smcFunc['db_fetch_row']($request);
91
				$smcFunc['db_free_result']($request);
92
93
				return $latest_post;
94
			},
95
			// Instructions to pass to ExportProfileData background task:
96
			'XML' => array(
97
				'func' => 'getXmlPosts',
98
				'langfile' => 'Post',
99
			),
100
			'HTML' => array(
101
				'func' => 'getXmlPosts',
102
				'langfile' => 'Post',
103
			),
104
			'XML_XSLT' => array(
105
				'func' => 'getXmlPosts',
106
				'langfile' => 'Post',
107
			),
108
			// 'CSV' => array(),
109
			// 'JSON' => array(),
110
		),
111
		'personal_messages' => array(
112
			'label' => $txt['export_include_personal_messages'],
113
			'total' => function($uid)
114
			{
115
				global $smcFunc;
116
117
				static $total_pms;
118
119
				if (isset($total_pms))
120
					return $total_pms;
121
122
				$request = $smcFunc['db_query']('', '
123
					SELECT COUNT(*)
124
					FROM {db_prefix}personal_messages AS pm
125
						INNER JOIN {db_prefix}pm_recipients AS pmr ON (pm.id_pm = pmr.id_pm)
126
					WHERE (pm.id_member_from = {int:uid} AND pm.deleted_by_sender = {int:not_deleted})
127
						OR (pmr.id_member = {int:uid} AND pmr.deleted = {int:not_deleted})',
128
					array(
129
						'uid' => $uid,
130
						'not_deleted' => 0,
131
					)
132
				);
133
				list($total_pms) = $smcFunc['db_fetch_row']($request);
134
				$smcFunc['db_free_result']($request);
135
136
				return $total_pms;
137
			},
138
			'latest' => function($uid)
139
			{
140
				global $smcFunc;
141
142
				static $latest_pm;
143
144
				if (isset($latest_pm))
145
					return $latest_pm;
146
147
				$request = $smcFunc['db_query']('', '
148
					SELECT pm.id_pm
149
					FROM {db_prefix}personal_messages AS pm
150
						INNER JOIN {db_prefix}pm_recipients AS pmr ON (pm.id_pm = pmr.id_pm)
151
					WHERE (pm.id_member_from = {int:uid} AND pm.deleted_by_sender = {int:not_deleted})
152
						OR (pmr.id_member = {int:uid} AND pmr.deleted = {int:not_deleted})
153
					ORDER BY pm.id_pm DESC
154
					LIMIT {int:limit}',
155
					array(
156
						'limit' => 1,
157
						'uid' => $uid,
158
						'not_deleted' => 0,
159
					)
160
				);
161
				list($latest_pm) = $smcFunc['db_fetch_row']($request);
162
				$smcFunc['db_free_result']($request);
163
164
				return $latest_pm;
165
			},
166
			// Instructions to pass to ExportProfileData background task:
167
			'XML' => array(
168
				'func' => 'getXmlPMs',
169
				'langfile' => 'PersonalMessage',
170
			),
171
			'HTML' => array(
172
				'func' => 'getXmlPMs',
173
				'langfile' => 'PersonalMessage',
174
			),
175
			'XML_XSLT' => array(
176
				'func' => 'getXmlPMs',
177
				'langfile' => 'PersonalMessage',
178
			),
179
			// 'CSV' => array(),
180
			// 'JSON' => array(),
181
		),
182
	);
183
184
	if (empty($modSettings['export_dir']) || !file_exists($modSettings['export_dir']))
185
		create_export_dir();
186
187
	$export_dir_slash = $modSettings['export_dir'] . DIRECTORY_SEPARATOR;
188
189
	$idhash = hash_hmac('sha1', $uid, get_auth_secret());
190
	$dltoken = hash_hmac('sha1', $idhash, get_auth_secret());
191
192
	$query_this_board = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? 'b.id_board != ' . $modSettings['recycle_board'] : '1=1';
193
194
	$context['completed_exports'] = array();
195
	$context['active_exports'] = array();
196
	$existing_export_formats = array();
197
	$latest = array();
198
199
	foreach ($context['export_formats'] as $format => $format_settings)
200
	{
201
		$idhash_ext = $idhash . '.' . $format_settings['extension'];
202
203
		$done = null;
204
		$context['outdated_exports'][$idhash_ext] = array();
205
206
		// $realfile needs to be the highest numbered one, or 1_*** if none exist.
207
		$filenum = 1;
208
		$realfile = $export_dir_slash . $filenum . '_' . $idhash_ext;
209
		while (file_exists($export_dir_slash . ($filenum + 1) . '_' . $idhash_ext))
210
			$realfile = $export_dir_slash . ++$filenum . '_' . $idhash_ext;
211
212
		$tempfile = $export_dir_slash . $idhash_ext . '.tmp';
213
		$progressfile = $export_dir_slash . $idhash_ext . '.progress.json';
214
215
		// If requested by the user, delete any existing export files and background tasks.
216
		if (isset($_POST['delete']) && isset($_POST['format']) && $_POST['format'] === $format && isset($_POST['t']) && $_POST['t'] === $dltoken)
217
		{
218
			$smcFunc['db_query']('', '
219
				DELETE FROM {db_prefix}background_tasks
220
				WHERE task_class = {string:class}
221
					AND task_data LIKE {string:details}',
222
				array(
223
					'class' => 'ExportProfileData_Background',
224
					'details' => substr($smcFunc['json_encode'](array('format' => $format, 'uid' => $uid)), 0, -1) . ',%',
225
				)
226
			);
227
228
			foreach (glob($export_dir_slash . '*' . $idhash_ext . '*') as $fpath)
229
				@unlink($fpath);
230
231
			if (empty($_POST['export_begin']))
232
				redirectexit('action=profile;area=getprofiledata;u=' . $uid);
233
		}
234
235
		$progress = file_exists($progressfile) ? $smcFunc['json_decode'](file_get_contents($progressfile), true) : array();
236
237
		if (!empty($progress))
238
			$included = array_keys($progress);
239
		else
240
			$included = array_intersect(array_keys($context['export_datatypes']), array_keys($_POST));
241
242
		// If we're starting a new export in this format, we're done here.
243
		if (!empty($_POST['export_begin']) && isset($_POST['format']) && $_POST['format'] === $format)
244
			break;
245
246
		// The rest of this loop deals with current exports, if any.
247
248
		$included_desc = array();
249
		foreach ($included as $datatype)
250
			$included_desc[] = $txt[$datatype];
251
252
		$dlfilename = array_merge(array($context['forum_name'], $context['member']['username']), $included_desc);
253
		$dlfilename = preg_replace('/[^\p{L}\p{M}\p{N}_]+/u', '-', str_replace('"', '', un_htmlspecialchars(strip_tags(implode('_', $dlfilename)))));
254
255
		if (file_exists($tempfile) && file_exists($progressfile))
256
		{
257
			$done = false;
258
		}
259
		elseif (file_exists($realfile))
260
		{
261
			// It looks like we're done.
262
			$done = true;
263
264
			// But let's check whether it's outdated.
265
			foreach ($context['export_datatypes'] as $datatype => $datatype_settings)
266
			{
267
				if (!isset($progress[$datatype]))
268
					continue;
269
270
				if (!isset($latest[$datatype]))
271
					$latest[$datatype] = is_callable($datatype_settings['latest']) ? $datatype_settings['latest']($uid) : $datatype_settings['latest'];
272
273
				if ($latest[$datatype] > $progress[$datatype])
274
					$context['outdated_exports'][$idhash_ext][] = $datatype;
275
			}
276
		}
277
278
		if ($done === true)
279
		{
280
			$exportfilepaths = glob($export_dir_slash . '*_' . $idhash_ext);
281
282
			foreach ($exportfilepaths as $exportfilepath)
283
			{
284
				$exportbasename = basename($exportfilepath);
285
286
				$part = substr($exportbasename, 0, strcspn($exportbasename, '_'));
287
				$suffix = count($exportfilepaths) == 1 ? '' : '_' . $part;
288
289
				$size = filesize($exportfilepath) / 1024;
290
				$units = array('KB', 'MB', 'GB', 'TB');
291
				$unitkey = 0;
292
				while ($size > 1024)
293
				{
294
					$size = $size / 1024;
295
					$unitkey++;
296
				}
297
				$size = round($size, 2) . $units[$unitkey];
298
299
				$context['completed_exports'][$idhash_ext][$part] = array(
300
					'realname' => $exportbasename,
301
					'dlbasename' => $dlfilename . $suffix . '.' . $format_settings['extension'],
302
					'dltoken' => $dltoken,
303
					'included' => $included,
304
					'included_desc' => sentence_list($included_desc),
305
					'format' => $format,
306
					'mtime' => timeformat(filemtime($exportfilepath)),
307
					'size' => $size,
308
				);
309
			}
310
311
			ksort($context['completed_exports'][$idhash_ext], SORT_NUMERIC);
312
313
			$existing_export_formats[] = $format;
314
		}
315
		elseif ($done === false)
316
		{
317
			$context['active_exports'][$idhash_ext] = array(
318
				'dltoken' => $dltoken,
319
				'included' => $included,
320
				'included_desc' => sentence_list($included_desc),
321
				'format' => $format,
322
			);
323
324
			$existing_export_formats[] = $format;
325
		}
326
	}
327
328
	if (!empty($_POST['export_begin']))
329
	{
330
		checkSession();
331
		validateToken($context['token_check'], 'post');
332
333
		$format = isset($_POST['format']) && isset($context['export_formats'][$_POST['format']]) ? $_POST['format'] : 'XML';
334
335
		$included = array();
336
		$included_desc = array();
337
		foreach ($context['export_datatypes'] as $datatype => $datatype_settings)
338
		{
339
			if ($datatype == 'profile' || !empty($_POST[$datatype]))
340
			{
341
				$included[$datatype] = $datatype_settings[$format];
342
				$included_desc[] = $txt[$datatype];
343
344
				$start[$datatype] = !empty($start[$datatype]) ? $start[$datatype] : 0;
345
346
				if (!isset($latest[$datatype]))
347
					$latest[$datatype] = is_callable($datatype_settings['latest']) ? $datatype_settings['latest']($uid) : $datatype_settings['latest'];
348
349
				if (!isset($total[$datatype]))
350
					$total[$datatype] = is_callable($datatype_settings['total']) ? $datatype_settings['total']($uid) : $datatype_settings['total'];
351
			}
352
		}
353
354
		$dlfilename = array_merge(array($context['forum_name'], $context['member']['username']), $included_desc);
355
		$dlfilename = preg_replace('/[^\p{L}\p{M}\p{N}_]+/u', '-', str_replace('"', '', un_htmlspecialchars(strip_tags(implode('_', $dlfilename)))));
356
357
		$last_page = ceil(array_sum($total) / $context['export_formats'][$format]['per_page']);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $total does not seem to be defined for all execution paths leading up to this point.
Loading history...
358
359
		$data = $smcFunc['json_encode'](array(
360
			'format' => $format,
361
			'uid' => $uid,
362
			'lang' => $context['member']['language'],
363
			'included' => $included,
364
			'start' => $start,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $start does not seem to be defined for all execution paths leading up to this point.
Loading history...
365
			'latest' => $latest,
366
			'datatype' => isset($current_datatype) ? $current_datatype : key($included),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $current_datatype seems to never exist and therefore isset should always be false.
Loading history...
367
			'format_settings' => $context['export_formats'][$format],
368
			'last_page' => $last_page,
369
			'dlfilename' => $dlfilename,
370
		));
371
372
		$smcFunc['db_insert']('insert', '{db_prefix}background_tasks',
373
			array('task_file' => 'string-255', 'task_class' => 'string-255', 'task_data' => 'string', 'claimed_time' => 'int'),
374
			array('$sourcedir/tasks/ExportProfileData.php', 'ExportProfileData_Background', $data, 0),
375
			array()
376
		);
377
378
		// So the user can see that we've started.
379
		if (!file_exists($tempfile))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tempfile seems to be defined by a foreach iteration on line 199. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
380
			touch($tempfile);
381
		if (!file_exists($progressfile))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $progressfile seems to be defined by a foreach iteration on line 199. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
382
			file_put_contents($progressfile, $smcFunc['json_encode'](array_fill_keys(array_keys($included), 0)));
383
384
		redirectexit('action=profile;area=getprofiledata;u=' . $uid);
385
	}
386
387
	createToken($context['token_check'], 'post');
388
389
	$context['page_title'] = $txt['export_profile_data'];
390
391
	if (empty($modSettings['export_expiry']))
392
		unset($txt['export_profile_data_desc_list']['expiry']);
393
	else
394
		$txt['export_profile_data_desc_list']['expiry'] = sprintf($txt['export_profile_data_desc_list']['expiry'], $modSettings['export_expiry']);
395
396
	$context['export_profile_data_desc'] = sprintf($txt['export_profile_data_desc'], '<li>' . implode('</li><li>', $txt['export_profile_data_desc_list']) . '</li>');
397
398
	addJavaScriptVar('completed_formats', '[\'' . implode('\', \'', array_unique($existing_export_formats)) . '\']', false);
399
}
400
401
/**
402
 * Downloads exported profile data file.
403
 *
404
 * @param int $uid The ID of the member whose data we're exporting.
405
 */
406
function download_export_file($uid)
407
{
408
	global $modSettings, $maintenance, $context, $txt, $smcFunc;
409
410
	$export_formats = get_export_formats();
411
412
	// This is done to clear any output that was made before now.
413
	ob_end_clean();
414
415
	if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0)
416
	{
417
		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler')
418
			$modSettings['enableCompressedOutput'] = 0;
419
420
		else
421
			ob_start('ob_gzhandler');
422
	}
423
424
	if (empty($modSettings['enableCompressedOutput']))
425
	{
426
		ob_start();
427
		header('content-encoding: none');
428
	}
429
430
	// No access in strict maintenance mode.
431
	if (!empty($maintenance) && $maintenance == 2)
432
	{
433
		send_http_status(404);
434
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
435
	}
436
437
	// We can't give them anything without these.
438
	if (empty($_GET['t']) || empty($_GET['format']) || !isset($export_formats[$_GET['format']]))
439
	{
440
		send_http_status(400);
441
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
442
	}
443
444
	$export_dir_slash = $modSettings['export_dir'] . DIRECTORY_SEPARATOR;
445
446
	$idhash = hash_hmac('sha1', $uid, get_auth_secret());
447
	$part = isset($_GET['part']) ? (int) $_GET['part'] : 1;
448
	$extension = $export_formats[$_GET['format']]['extension'];
449
450
	$filepath = $export_dir_slash . $part . '_' . $idhash . '.' . $extension;
451
	$progressfile = $export_dir_slash . $idhash . '.' . $extension . '.progress.json';
452
453
	// Make sure they gave the correct authentication token.
454
	// We use these tokens so the user can download without logging in, as required by the GDPR.
455
	$dltoken = hash_hmac('sha1', $idhash, get_auth_secret());
456
	if ($_GET['t'] !== $dltoken)
457
	{
458
		send_http_status(403);
459
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
460
	}
461
462
	// Obviously we can't give what we don't have.
463
	if (empty($modSettings['export_dir']) || !file_exists($filepath))
464
	{
465
		send_http_status(404);
466
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
467
	}
468
469
	// Figure out the filename we'll tell the browser.
470
	$datatypes = file_exists($progressfile) ? array_keys($smcFunc['json_decode'](file_get_contents($progressfile), true)) : array('profile');
471
	$included_desc = array_map(function ($datatype) use ($txt) { return $txt[$datatype]; }, $datatypes);
472
473
	$dlfilename = array_merge(array($context['forum_name'], $context['member']['username']), $included_desc);
474
	$dlfilename = preg_replace('/[^\p{L}\p{M}\p{N}_]+/u', '-', str_replace('"', '', un_htmlspecialchars(strip_tags(implode('_', $dlfilename)))));
475
476
	$suffix = ($part > 1 || file_exists($export_dir_slash . '2_' . $idhash . '.' . $extension)) ? '_' . $part : '';
477
478
	$dlbasename = $dlfilename . $suffix . '.' . $extension;
479
480
	$mtime = filemtime($filepath);
481
	$size = filesize($filepath);
482
483
	// If it hasn't been modified since the last time it was retrieved, there's no need to serve it again.
484
	if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']))
485
	{
486
		list($modified_since) = explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
487
		if (strtotime($modified_since) >= $mtime)
488
		{
489
			ob_end_clean();
490
491
			// Answer the question - no, it hasn't been modified ;).
492
			send_http_status(304);
493
			exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
494
		}
495
	}
496
497
	// Check whether the ETag was sent back, and cache based on that...
498
	$eTag = md5(implode(' ', array($dlbasename, $size, $mtime)));
499
	if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'], $eTag) !== false)
500
	{
501
		ob_end_clean();
502
503
		send_http_status(304);
504
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
505
	}
506
507
	// If this is a partial download, we need to determine what data range to send
508
	$range = 0;
509
	if (isset($_SERVER['HTTP_RANGE']))
510
	{
511
		list($a, $range) = explode("=", $_SERVER['HTTP_RANGE'], 2);
512
		list($range) = explode(",", $range, 2);
513
		list($range, $range_end) = explode("-", $range);
514
		$range = intval($range);
515
		$range_end = !$range_end ? $size - 1 : intval($range_end);
516
		$new_length = $range_end - $range + 1;
517
	}
518
519
	header('pragma: ');
520
521
	if (!isBrowser('gecko'))
522
		header('content-transfer-encoding: binary');
523
524
	header('expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
525
	header('last-modified: ' . gmdate('D, d M Y H:i:s', $mtime) . ' GMT');
526
	header('accept-ranges: bytes');
527
	header('connection: close');
528
	header('etag: ' . $eTag);
529
	header('content-type: ' . $export_formats[$_GET['format']]['mime']);
530
531
	// Convert the file to UTF-8, cuz most browsers dig that.
532
	$utf8name = !$context['utf8'] && function_exists('iconv') ? iconv($context['character_set'], 'UTF-8', $dlbasename) : (!$context['utf8'] && function_exists('mb_convert_encoding') ? mb_convert_encoding($dlbasename, 'UTF-8', $context['character_set']) : $dlbasename);
533
534
	// Different browsers like different standards...
535
	if (isBrowser('firefox'))
536
		header('content-disposition: attachment; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
537
538
	elseif (isBrowser('opera'))
539
		header('content-disposition: attachment; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
540
541
	elseif (isBrowser('ie'))
542
		header('content-disposition: attachment; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
543
544
	else
545
		header('content-disposition: attachment; filename="' . $utf8name . '"');
546
547
	header('cache-control: max-age=' . (525600 * 60) . ', private');
548
549
	// Multipart and resuming support
550
	if (isset($_SERVER['HTTP_RANGE']))
551
	{
552
		send_http_status(206);
553
		header("content-length: $new_length");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $new_length does not seem to be defined for all execution paths leading up to this point.
Loading history...
554
		header("content-range: bytes $range-$range_end/$size");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $range_end does not seem to be defined for all execution paths leading up to this point.
Loading history...
555
	}
556
	else
557
		header("content-length: $size");
558
559
	// Try to buy some time...
560
	@set_time_limit(600);
561
562
	// For multipart/resumable downloads, send the requested chunk(s) of the file
563
	if (isset($_SERVER['HTTP_RANGE']))
564
	{
565
		while (@ob_get_level() > 0)
566
			@ob_end_clean();
567
568
		// 40 kilobytes is a good-ish amount
569
		$chunksize = 40 * 1024;
570
		$bytes_sent = 0;
571
572
		$fp = fopen($filepath, 'rb');
573
574
		fseek($fp, $range);
0 ignored issues
show
Bug introduced by
It seems like $fp can also be of type false; however, parameter $handle of fseek() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

574
		fseek(/** @scrutinizer ignore-type */ $fp, $range);
Loading history...
575
576
		while (!feof($fp) && (!connection_aborted()) && ($bytes_sent < $new_length))
0 ignored issues
show
Bug introduced by
It seems like $fp can also be of type false; however, parameter $handle of feof() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

576
		while (!feof(/** @scrutinizer ignore-type */ $fp) && (!connection_aborted()) && ($bytes_sent < $new_length))
Loading history...
577
		{
578
			$buffer = fread($fp, $chunksize);
0 ignored issues
show
Bug introduced by
It seems like $fp can also be of type false; however, parameter $handle of fread() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

578
			$buffer = fread(/** @scrutinizer ignore-type */ $fp, $chunksize);
Loading history...
579
			echo($buffer);
580
			flush();
581
			$bytes_sent += strlen($buffer);
582
		}
583
		fclose($fp);
0 ignored issues
show
Bug introduced by
It seems like $fp can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

583
		fclose(/** @scrutinizer ignore-type */ $fp);
Loading history...
584
	}
585
586
	// Since we don't do output compression for files this large...
587
	elseif ($size > 4194304)
588
	{
589
		// Forcibly end any output buffering going on.
590
		while (@ob_get_level() > 0)
591
			@ob_end_clean();
592
593
		$fp = fopen($filepath, 'rb');
594
		while (!feof($fp))
595
		{
596
			echo fread($fp, 8192);
597
			flush();
598
		}
599
		fclose($fp);
600
	}
601
602
	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
603
	elseif (@readfile($filepath) === null)
604
		echo file_get_contents($filepath);
605
606
	exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
607
}
608
609
/**
610
 * Allows a member to export their attachments.
611
 * Mostly just a wrapper for showAttachment() but with a few tweaks.
612
 *
613
 * @param int $uid The ID of the member whose data we're exporting.
614
 */
615
function export_attachment($uid)
616
{
617
	global $sourcedir, $context, $smcFunc;
618
619
	$idhash = hash_hmac('sha1', $uid, get_auth_secret());
620
	$dltoken = hash_hmac('sha1', $idhash, get_auth_secret());
621
	if (!isset($_GET['t']) || $_GET['t'] !== $dltoken)
622
	{
623
		send_http_status(403);
624
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
625
	}
626
627
	$attachId = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0;
628
	if (empty($attachId))
629
	{
630
		send_http_status(404, 'File Not Found');
631
		die('404 File Not Found');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
632
	}
633
634
	// Does this attachment belong to this member?
635
	$request = $smcFunc['db_query']('', '
636
		SELECT m.id_topic
637
		FROM {db_prefix}messages AS m
638
			INNER JOIN {db_prefix}attachments AS a ON (m.id_msg = a.id_msg)
639
		WHERE m.id_member = {int:uid}
640
			AND a.id_attach = {int:attachId}',
641
		array(
642
			'uid' => $uid,
643
			'attachId' => $attachId,
644
		)
645
	);
646
	if ($smcFunc['db_num_rows']($request) == 0)
647
	{
648
		$smcFunc['db_free_result']($request);
649
		send_http_status(403);
650
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
651
	}
652
653
	// We need the topic.
654
	list ($_REQUEST['topic']) = $smcFunc['db_fetch_row']($request);
655
	$smcFunc['db_free_result']($request);
656
657
	// This doesn't count as a normal download.
658
	$context['skip_downloads_increment'] = true;
659
660
	// Try to avoid collisons when attachment names are not unique.
661
	$context['prepend_attachment_id'] = true;
662
663
	// We should now have what we need to serve the file.
664
	require_once($sourcedir . DIRECTORY_SEPARATOR . 'ShowAttachments.php');
665
	showAttachment();
666
}
667
668
/**
669
 * Helper function that defines data export formats in a single location.
670
 *
671
 * @return array Information about supported data formats for profile exports.
672
 */
673
function get_export_formats()
674
{
675
	global $txt;
676
677
	$export_formats = array(
678
		'XML_XSLT' => array(
679
			'extension' => 'styled.xml',
680
			'mime' => 'text/xml',
681
			'description' => $txt['export_format_xml_xslt'],
682
			'per_page' => 500,
683
		),
684
		'HTML' => array(
685
			'extension' => 'html',
686
			'mime' => 'text/html',
687
			'description' => $txt['export_format_html'],
688
			'per_page' => 500,
689
		),
690
		'XML' => array(
691
			'extension' => 'xml',
692
			'mime' => 'text/xml',
693
			'description' => $txt['export_format_xml'],
694
			'per_page' => 2000,
695
		),
696
		// 'CSV' => array(
697
		// 	'extension' => 'csv',
698
		// 	'mime' => 'text/csv',
699
		// 	'description' => $txt['export_format_csv'],
700
		//	'per_page' => 2000,
701
		// ),
702
		// 'JSON' => array(
703
		// 	'extension' => 'json',
704
		// 	'mime' => 'application/json',
705
		// 	'description' => $txt['export_format_json'],
706
		//	'per_page' => 2000,
707
		// ),
708
	);
709
710
	// If these are missing, we can't transform the XML on the server.
711
	if (!class_exists('DOMDocument') || !class_exists('XSLTProcessor'))
712
		unset($export_formats['HTML']);
713
714
	return $export_formats;
715
}
716
717
/**
718
 * Returns the path to a secure directory for storing exported profile data.
719
 *
720
 * The directory is created if it does not yet exist, and is secured using the
721
 * same method that we use to secure attachment directories. Files in this
722
 * directory can only be downloaded via the download_export_file() function.
723
 *
724
 * @return string|bool The path to the directory, or false on error.
725
 */
726
function create_export_dir($fallback = '')
727
{
728
	global $boarddir, $modSettings;
729
730
	// No supplied fallback, so use the default location.
731
	if (empty($fallback))
732
		$fallback = $boarddir . DIRECTORY_SEPARATOR . 'exports';
733
734
	// Automatically set it to the fallback if it is missing.
735
	if (empty($modSettings['export_dir']))
736
		updateSettings(array('export_dir' => $fallback));
737
738
	// Make sure the directory exists.
739
	if (!file_exists($modSettings['export_dir']))
740
		@mkdir($modSettings['export_dir'], null, true);
741
742
	// Make sure the directory has the correct permissions.
743
	if (!is_dir($modSettings['export_dir']) || !smf_chmod($modSettings['export_dir']))
744
	{
745
		loadLanguage('Errors');
746
747
		// Try again at the fallback location.
748
		if ($modSettings['export_dir'] != $fallback)
749
		{
750
			log_error($txt['export_dir_forced_change'], $modSettings['export_dir'], $fallback);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $txt seems to be never defined.
Loading history...
751
			updateSettings(array('export_dir' => $fallback));
752
753
			// Secondary fallback will be the default location, so no parameter this time.
754
			create_export_dir();
755
		}
756
		// Uh-oh. Even the default location failed.
757
		else
758
		{
759
			log_error($txt['export_dir_not_writable']);
760
			return false;
761
		}
762
	}
763
764
	return secureDirectory(array($modSettings['export_dir']), true);
765
}
766
767
/**
768
 * Provides an XSLT stylesheet to transform an XML-based profile export file
769
 * into the desired output format.
770
 *
771
 * @param string $format The desired output format. Currently accepts 'HTML' and 'XML_XSLT'.
772
 * @param int $uid The ID of the member whose data we're exporting.
773
 * @return array The XSLT stylesheet and a (possibly empty) DTD to insert into the source XML document.
774
 */
775
function get_xslt_stylesheet($format, $uid)
776
{
777
	global $context, $txt, $settings, $modSettings, $sourcedir, $forum_copyright, $scripturl, $smcFunc;
778
779
	$doctype = '';
780
	$stylesheet = array();
781
	$context['xslt_settings'] = array();
782
783
	if (in_array($format, array('HTML', 'XML_XSLT')))
784
	{
785
		if (!class_exists('DOMDocument') || !class_exists('XSLTProcessor'))
786
			$format = 'XML_XSLT';
787
788
		$export_formats = get_export_formats();
789
790
		$context['xslt_settings'] = array(
791
			// Do not change any of these to HTTPS URLs. For explanation, see comments in the buildXmlFeed() function.
792
			'namespaces' => array(
793
				'xsl' => 'htt'.'p:/'.'/ww'.'w.w3.o'.'rg/1999/XSL/Transform',
794
				'smf' => 'htt'.'p:/'.'/ww'.'w.simple'.'machines.o'.'rg/xml/profile',
795
				'html' => 'htt'.'p:/'.'/ww'.'w.w3.o'.'rg/1999/xhtml',
796
			),
797
			'exclude-result-prefixes' => array('smf', 'html'),
798
			'output' => array(
799
				'method' => 'html',
800
				'encoding' => $context['character_set'],
801
				'indent' => 'yes',
802
			),
803
			'whitespace' => array('strip' => '*'),
804
		);
805
806
		/* Notes about the XSLT variables array:
807
		 * 1. The 'value' can be one of the following:
808
		 *    - an integer or string
809
		 *    - an XPath expression
810
		 *    - raw XML, which may or not not include other XSLT statements.
811
		 *
812
		 * 2. Always set 'no_cdata_parse' to true when the value is raw XML.
813
		 *
814
		 * 3. Set 'xpath' to true if the value is an XPath expression. When this
815
		 *    is true, the value will be placed in the 'select' attribute of the
816
		 *    <xsl:variable> element rather than in a child node.
817
		 *
818
		 * 4. Set 'param' to true in order to create an <xsl:param> instead
819
		 *    of an <xsl:variable>.
820
		 *
821
		 * A word to PHP coders: Do not let the term "variable" mislead you.
822
		 * XSLT variables are roughly equivalent to PHP constants rather
823
		 * than PHP variables; once the value has been set, it is immutable.
824
		 * Keeping this in mind may spare you from some confusion and
825
		 * frustration while working with XSLT.
826
		 */
827
		$context['xslt_settings']['variables'] = array(
828
			'scripturl' => array(
829
				'value' => $scripturl,
830
			),
831
			'themeurl' => array(
832
				'value' => $settings['default_theme_url'],
833
			),
834
			'member_id' => array(
835
				'value' => $uid,
836
			),
837
			'last_page' => array(
838
				'param' => true,
839
				'value' => !empty($context['export_last_page']) ? $context['export_last_page'] : 1,
840
				'xpath' => true,
841
			),
842
			'dlfilename' => array(
843
				'param' => true,
844
				'value' => !empty($context['export_dlfilename']) ? $context['export_dlfilename'] : '',
845
			),
846
			'ext' => array(
847
				'value' => $export_formats[$format]['extension'],
848
			),
849
			'forum_copyright' => array(
850
				'value' => sprintf($forum_copyright, SMF_FULL_VERSION, SMF_SOFTWARE_YEAR, $scripturl),
851
			),
852
			'txt_summary_heading' => array(
853
				'value' => $txt['summary'],
854
			),
855
			'txt_posts_heading' => array(
856
				'value' => $txt['posts'],
857
			),
858
			'txt_personal_messages_heading' => array(
859
				'value' => $txt['personal_messages'],
860
			),
861
			'txt_id' => array(
862
				'value' => $txt['export_id'],
863
			),
864
			'txt_view_source_button' => array(
865
				'value' => $txt['export_view_source_button'],
866
			),
867
			'txt_download_original' => array(
868
				'value' => $txt['export_download_original'],
869
			),
870
			'txt_help' => array(
871
				'value' => $txt['help'],
872
			),
873
			'txt_terms_rules' => array(
874
				'value' => $txt['terms_and_rules'],
875
			),
876
			'txt_go_up' => array(
877
				'value' => $txt['go_up'],
878
			),
879
			'txt_pages' => array(
880
				'value' => $txt['pages'],
881
			),
882
			'dltoken' => array(
883
				'value' => hash_hmac('sha1', hash_hmac('sha1', $uid, get_auth_secret()), get_auth_secret()),
884
			),
885
		);
886
887
		if ($format == 'XML_XSLT')
888
		{
889
			$doctype = implode("\n", array(
890
				'<!--',
891
				"\t" . $txt['export_open_in_browser'],
892
				'-->',
893
				'<?xml-stylesheet type="text/xsl" href="#stylesheet"?>',
894
				'<!DOCTYPE smf:xml-feed [',
895
				'<!ATTLIST xsl:stylesheet',
896
				'id ID #REQUIRED>',
897
				']>',
898
			));
899
900
			$context['xslt_settings'] += array(
901
				'no_xml_declaration' => true,
902
				'preamble' => "\n\n\t",
903
				'id' => 'stylesheet',
904
				'custom' => array(
905
					'<xsl:template match="xsl:stylesheet"/>',
906
					'<xsl:template match="xsl:stylesheet" mode="detailedinfo"/>',
907
				),
908
				'before_footer' => "\n\t",
909
			);
910
		}
911
912
		export_load_css_js();
913
914
		$stylesheet = loadXslt('export', 'html');
915
	}
916
917
	return array('stylesheet' => $stylesheet, 'doctype' => $doctype);
918
}
919
920
/**
921
 * Loads and prepares CSS and JavaScript for insertion into an XSLT stylesheet.
922
 */
923
function export_load_css_js()
924
{
925
	global $context, $modSettings, $sourcedir, $smcFunc, $user_info;
926
927
	// Avoid unnecessary repetition.
928
	if (isset($context['export_javascript_inline']))
929
		return;
930
931
	// If we're not running a background task, we need to preserve any existing CSS and JavaScript.
932
	if (SMF != 'BACKGROUND')
0 ignored issues
show
introduced by
The condition SMF != 'BACKGROUND' is always true.
Loading history...
933
	{
934
		foreach (array('css_files', 'css_header', 'javascript_vars', 'javascript_files', 'javascript_inline') as $var)
935
		{
936
			if (isset($context[$var]))
937
				$context['real_' . $var] = $context[$var];
938
939
			if ($var == 'javascript_inline')
940
			{
941
				foreach ($context[$var] as $key => $value)
942
					$context[$var][$key] = array();
943
			}
944
			else
945
				$context[$var] = array();
946
		}
947
	}
948
	// Autoloading is unavailable for background tasks, so we have to do things the hard way...
949
	else
950
	{
951
		if (!empty($modSettings['minimize_files']) && (!class_exists('MatthiasMullie\\Minify\\CSS') || !class_exists('MatthiasMullie\\Minify\\JS')))
952
		{
953
			// Include, not require, because minimization is nice to have but not vital here.
954
			include_once(implode(DIRECTORY_SEPARATOR, array($sourcedir, 'minify', 'src', 'Exception.php')));
955
			include_once(implode(DIRECTORY_SEPARATOR, array($sourcedir, 'minify', 'src', 'Exceptions', 'BasicException.php')));
956
			include_once(implode(DIRECTORY_SEPARATOR, array($sourcedir, 'minify', 'src', 'Exceptions', 'FileImportException.php')));
957
			include_once(implode(DIRECTORY_SEPARATOR, array($sourcedir, 'minify', 'src', 'Exceptions', 'IOException.php')));
958
959
			include_once(implode(DIRECTORY_SEPARATOR, array($sourcedir, 'minify', 'src', 'Minify.php')));
960
			include_once(implode(DIRECTORY_SEPARATOR, array($sourcedir, 'minify', 'path-converter', 'src', 'Converter.php')));
961
962
			include_once(implode(DIRECTORY_SEPARATOR, array($sourcedir, 'minify', 'src', 'CSS.php')));
963
			include_once(implode(DIRECTORY_SEPARATOR, array($sourcedir, 'minify', 'src', 'JS.php')));
964
965
			if (!class_exists('MatthiasMullie\\Minify\\CSS') || !class_exists('MatthiasMullie\\Minify\\JS'))
966
				$modSettings['minimize_files'] = false;
967
		}
968
	}
969
970
	// Load our standard CSS files.
971
	loadCSSFile('index.css', array('minimize' => true, 'order_pos' => 1), 'smf_index');
972
	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
973
974
	if ($context['right_to_left'])
975
		loadCSSFile('rtl.css', array('order_pos' => 4000), 'smf_rtl');
976
977
	// In case any mods added relevant CSS.
978
	call_integration_hook('integrate_pre_css_output');
979
980
	// This next chunk mimics some of template_css()
981
	$css_to_minify = array();
982
	$normal_css_files = array();
983
984
	usort($context['css_files'], function ($a, $b)
985
	{
986
		return $a['options']['order_pos'] < $b['options']['order_pos'] ? -1 : ($a['options']['order_pos'] > $b['options']['order_pos'] ? 1 : 0);
987
	});
988
	foreach ($context['css_files'] as $css_file)
989
	{
990
		if (!isset($css_file['options']['minimize']))
991
			$css_file['options']['minimize'] = true;
992
993
		if (!empty($css_file['options']['minimize']) && !empty($modSettings['minimize_files']))
994
			$css_to_minify[] = $css_file;
995
		else
996
			$normal_css_files[] = $css_file;
997
	}
998
999
	$minified_css_files = !empty($css_to_minify) ? custMinify($css_to_minify, 'css') : array();
1000
1001
	$context['css_files'] = array();
1002
	foreach (array_merge($minified_css_files, $normal_css_files) as $css_file)
1003
	{
1004
		// Embed the CSS in a <style> element if possible, since exports are supposed to be standalone files.
1005
		if (file_exists($css_file['filePath']))
1006
			$context['css_header'][] = file_get_contents($css_file['filePath']);
1007
1008
		elseif (!empty($css_file['fileUrl']))
1009
			$context['css_files'][] = $css_file;
1010
	}
1011
1012
	// Next, we need to do for JavaScript what we just did for CSS.
1013
	loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/' . JQUERY_VERSION . '/jquery.min.js', array('external' => true), 'smf_jquery');
1014
1015
	// There might be JavaScript that we need to add in order to support custom BBC or something.
1016
	call_integration_hook('integrate_pre_javascript_output', array(false));
1017
	call_integration_hook('integrate_pre_javascript_output', array(true));
1018
1019
	$js_to_minify = array();
1020
	$all_js_files = array();
1021
1022
	foreach ($context['javascript_files'] as $js_file)
1023
	{
1024
		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
1025
		{
1026
			if (!empty($js_file['options']['async']))
1027
				$js_to_minify['async'][] = $js_file;
1028
1029
			elseif (!empty($js_file['options']['defer']))
1030
				$js_to_minify['defer'][] = $js_file;
1031
1032
			else
1033
				$js_to_minify['standard'][] = $js_file;
1034
		}
1035
		else
1036
			$all_js_files[] = $js_file;
1037
	}
1038
1039
	$context['javascript_files'] = array();
1040
	foreach ($js_to_minify as $type => $js_files)
1041
	{
1042
		if (!empty($js_files))
1043
		{
1044
			$minified_js_files = custMinify($js_files, 'js');
1045
			$all_js_files = array_merge($all_js_files, $minified_js_files);
1046
		}
1047
	}
1048
1049
	foreach ($all_js_files as $js_file)
1050
	{
1051
		// As with the CSS, embed whatever JavaScript we can.
1052
		if (file_exists($js_file['filePath']))
1053
			$context['javascript_inline'][(!empty($js_file['options']['defer']) ? 'defer' : 'standard')][] = file_get_contents($js_file['filePath']);
1054
1055
		elseif (!empty($js_file['fileUrl']))
1056
			$context['javascript_files'][] = $js_file;
1057
	}
1058
1059
	// We need to embed the smiley images, too. To save space, we store the image data in JS variables.
1060
	$smiley_mimetypes = array(
1061
		'gif' => 'image/gif',
1062
		'png' => 'image/png',
1063
		'jpg' => 'image/jpeg',
1064
		'jpeg' => 'image/jpeg',
1065
		'tiff' => 'image/tiff',
1066
		'svg' => 'image/svg+xml',
1067
	);
1068
1069
	foreach (glob(implode(DIRECTORY_SEPARATOR, array($modSettings['smileys_dir'], $user_info['smiley_set'], '*.*'))) as $smiley_file)
1070
	{
1071
		$pathinfo = pathinfo($smiley_file);
1072
1073
		if (!isset($smiley_mimetypes[$pathinfo['extension']]))
1074
			continue;
1075
1076
		$var = implode('_', array('smf', 'smiley', $pathinfo['filename'], $pathinfo['extension']));
1077
1078
		if (!isset($context['javascript_vars'][$var]))
1079
			$context['javascript_vars'][$var] = '\'data:' . $smiley_mimetypes[$pathinfo['extension']] . ';base64,' . base64_encode(file_get_contents($smiley_file)) . '\'';
1080
	}
1081
1082
	$context['javascript_inline']['defer'][] = implode("\n", array(
1083
		'$("img.smiley").each(function() {',
1084
		'	var data_uri_var = $(this).attr("src").replace(/.*\/(\w+)\.(\w+)$/, "smf_smiley_$1_$2");',
1085
		'	$(this).attr("src", window[data_uri_var]);',
1086
		'});',
1087
	));
1088
1089
	// Now move everything to the special export version of these arrays.
1090
	foreach (array('css_files', 'css_header', 'javascript_vars', 'javascript_files', 'javascript_inline') as $var)
1091
	{
1092
		if (isset($context[$var]))
1093
			$context['export_' . $var] = $context[$var];
1094
1095
		unset($context[$var]);
1096
	}
1097
1098
	// Finally, restore the real values.
1099
	if (SMF !== 'BACKGROUND')
0 ignored issues
show
introduced by
The condition SMF !== 'BACKGROUND' is always true.
Loading history...
1100
	{
1101
		foreach (array('css_files', 'css_header', 'javascript_vars', 'javascript_files', 'javascript_inline') as $var)
1102
		{
1103
			if (isset($context['real_' . $var]))
1104
				$context[$var] = $context['real_' . $var];
1105
1106
			unset($context['real_' . $var]);
1107
		}
1108
	}
1109
}
1110
1111
?>