|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* NewBB 5.0x, the forum module for XOOPS project |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
6
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
7
|
|
|
* @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
|
8
|
|
|
* @since 4.00 |
|
9
|
|
|
* @package module::newbb |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
use Xmf\Request; |
|
13
|
|
|
use XoopsModules\Newbb; |
|
14
|
|
|
|
|
15
|
|
|
ob_start(); |
|
16
|
|
|
require_once __DIR__ . '/header.php'; |
|
17
|
|
|
require_once $GLOBALS['xoops']->path('header.php'); |
|
18
|
|
|
|
|
19
|
|
|
$attachId = Request::getInt('attachid', 0, 'GET'); |
|
20
|
|
|
$postId = Request::getInt('post_id', 0, 'GET'); |
|
21
|
|
|
|
|
22
|
|
|
if (!$postId || !$attachId) { |
|
23
|
|
|
exit(_MD_NEWBB_NO_SUCH_FILE . ': post_id:' . $postId . '; attachid' . $attachId); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
///** @var Newbb\PostHandler $postHandler */ |
|
27
|
|
|
//$postHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Post'); |
|
28
|
|
|
|
|
29
|
|
|
/** @var Newbb\Post $forumpost */ |
|
30
|
|
|
$forumpost = $postHandler->get($postId); |
|
31
|
|
|
if (!$approved = $forumpost->getVar('approved')) { |
|
32
|
|
|
exit(_MD_NEWBB_NORIGHTTOVIEW); |
|
33
|
|
|
} |
|
34
|
|
|
///** @var TopicHandler $topicHandler */ |
|
35
|
|
|
//$topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic'); |
|
36
|
|
|
$topicObject = $topicHandler->getByPost($postId); |
|
37
|
|
|
$topic_id = $topicObject->getVar('topic_id'); |
|
38
|
|
|
if (!$approved = $topicObject->getVar('approved')) { |
|
39
|
|
|
exit(_MD_NEWBB_NORIGHTTOVIEW); |
|
40
|
|
|
} |
|
41
|
|
|
///** @var NewbbForumHandler $forumHandler */ |
|
42
|
|
|
//$forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum'); |
|
43
|
|
|
$forumObject = $forumHandler->get($topicObject->getVar('forum_id')); |
|
44
|
|
|
if (!$forumHandler->getPermission($forumObject)) { |
|
45
|
|
|
exit(_MD_NEWBB_NORIGHTTOACCESS); |
|
46
|
|
|
} |
|
47
|
|
|
if (!$topicHandler->getPermission($forumObject, $topicObject->getVar('topic_status'), 'view')) { |
|
48
|
|
|
exit(_MD_NEWBB_NORIGHTTOVIEW); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$attachments = $forumpost->getAttachment(); |
|
52
|
|
|
$attach = $attachments[$attachId]; |
|
53
|
|
|
if (!$attach) { |
|
54
|
|
|
exit(_MD_NEWBB_NO_SUCH_FILE); |
|
55
|
|
|
} |
|
56
|
|
|
$file_saved = $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attach['name_saved']); |
|
57
|
|
|
if (!file_exists($file_saved)) { |
|
58
|
|
|
exit(_MD_NEWBB_NO_SUCH_FILE); |
|
59
|
|
|
} |
|
60
|
|
|
$down = $forumpost->incrementDownload($attachId); |
|
61
|
|
|
if ($down) { |
|
62
|
|
|
$forumpost->saveAttachment(); |
|
63
|
|
|
} |
|
64
|
|
|
unset($forumpost); |
|
65
|
|
|
$msg = ob_get_contents(); |
|
66
|
|
|
ob_end_clean(); |
|
67
|
|
|
|
|
68
|
|
|
$xoopsLogger->activated = false; |
|
69
|
|
|
if (!empty($GLOBALS['xoopsModuleConfig']['download_direct'])) { |
|
70
|
|
|
header('Cache-Control: no-store, no-cache, must-revalidate'); |
|
71
|
|
|
header('Cache-Control: post-check=0, pre-check=0', false); |
|
72
|
|
|
header('Pragma: no-cache'); |
|
73
|
|
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
|
74
|
|
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
75
|
|
|
header('location: ' . XOOPS_URL . '/' . $GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attach['name_saved']); |
|
76
|
|
|
} else { |
|
77
|
|
|
$file_display = $attach['nameDisplay']; |
|
78
|
|
|
//$mimetype = $attach['mimetype']; |
|
79
|
|
|
|
|
80
|
|
|
if (ini_get('zlib.output_compression')) { |
|
81
|
|
|
if (false === @ini_set('zlib.output_compression', 'Off')) { |
|
82
|
|
|
throw new \RuntimeException('Setting of zlib.output_compression failed.'); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if (function_exists('mb_http_output')) { |
|
87
|
|
|
mb_http_output('pass'); |
|
88
|
|
|
} |
|
89
|
|
|
header('Expires: 0'); |
|
90
|
|
|
//header('Content-Type: '.$mimetype); |
|
91
|
|
|
header('Content-Type: application/octet-stream'); |
|
92
|
|
|
if (preg_match("/MSIE (\d\.\d{1,2})/", Request::getString('HTTP_USER_AGENT', '', 'SERVER'))) { |
|
93
|
|
|
header('Content-Disposition: attachment; filename="' . $file_display . '"'); |
|
94
|
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
95
|
|
|
header('Pragma: public'); |
|
96
|
|
|
} else { |
|
97
|
|
|
header('Content-Disposition: attachment; filename="' . $file_display . '"'); |
|
98
|
|
|
header('Pragma: no-cache'); |
|
99
|
|
|
} |
|
100
|
|
|
header('Content-Type: application/force-download'); |
|
101
|
|
|
header('Content-Transfer-Encoding: binary'); |
|
102
|
|
|
|
|
103
|
|
|
$handle = fopen($file_saved, 'rb'); |
|
104
|
|
|
while (!feof($handle)) { |
|
|
|
|
|
|
105
|
|
|
$buffer = fread($handle, 4096); |
|
|
|
|
|
|
106
|
|
|
echo $buffer; |
|
107
|
|
|
} |
|
108
|
|
|
fclose($handle); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|