-
Notifications
You must be signed in to change notification settings - Fork 19
/
print.php
136 lines (122 loc) · 5.89 KB
/
print.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
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
<?php declare(strict_types=1);
/*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
// ------------------------------------------------------------------------ //
// Author: phppp (D.J., [email protected]) //
// URL: https://xoops.org //
// Project: Article Project //
// ------------------------------------------------------------------------ //
use Xmf\Request;
use XoopsModules\Newbb\{
Post,
PostHandler,
TopicHandler,
ForumHandler
};
/** @var Post $post */
/** @var TopicHandler $topicHandler */
/** @var ForumHandler $forumHandler */
/** @var PostHandler $postHandler */
/*
* Print contents of a post or a topic
* currently only available for post print
*
* TODO: topic print; print with page splitting
*
*/
require_once __DIR__ . '/header.php';
error_reporting(0);
$xoopsLogger->activated = false;
if (Request::getString('post_data', '', 'POST')) {
$post_data = unserialize(base64_decode(Request::getString('post_data', '', 'POST'), true));
$isPost = 1;
} else {
$forum = Request::getInt('forum', 0, 'GET');
$topic_id = Request::getInt('topic_id', 0, 'GET');
$post_id = Request::getInt('post_id', 0, 'GET');
if (0 === $post_id && 0 === $topic_id) {
exit(_MD_NEWBB_ERRORTOPIC);
}
if (0 !== $post_id) {
// $postHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Post');
$post = $postHandler->get($post_id);
if (!$approved = $post->getVar('approved')) {
exit(_MD_NEWBB_NORIGHTTOVIEW);
}
$topic_id = $post->getVar('topic_id');
$post_data = $postHandler->getPostForPrint($post);
$isPost = 1;
$post_data['url'] = XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $post_id;
if (!empty($GLOBALS['xoopsModuleConfig']['do_rewrite'])) {
$post_data['url'] = seo_urls('<a href="' . $post_data['url'] . '"></a>');
$post_data['url'] = str_replace('<a href="', '', $post_data['url']);
$post_data['url'] = str_replace('"></a>', '', $post_data['url']);
}
}
// $topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic');
$topicObject = $topicHandler->get($topic_id);
$topic_id = $topicObject->getVar('topic_id');
$forum = $topicObject->getVar('forum_id');
if (!$approved = $topicObject->getVar('approved')) {
exit(_MD_NEWBB_NORIGHTTOVIEW);
}
$isAdmin = newbbIsAdmin($forumObject);
if (!$isAdmin && $topicObject->getVar('approved') < 0) {
exit(_MD_NEWBB_NORIGHTTOVIEW);
}
// $forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum');
$forum = $topicObject->getVar('forum_id');
$forumObject = $forumHandler->get($forum);
if (!$forumHandler->getPermission($forumObject)) {
exit(_MD_NEWBB_NORIGHTTOVIEW);
}
if (!$topicHandler->getPermission($forumObject, $topicObject->getVar('topic_status'), 'view')) {
exit(_MD_NEWBB_NORIGHTTOVIEW);
}
// irmtfan add print permission
if (!$topicHandler->getPermission($forumObject, $topicObject->getVar('topic_status'), 'print')) {
exit(_MD_NEWBB_NORIGHTTOPRINT);
}
}
xoops_header(false);
if (empty($isPost)) {
echo "</head><body style='background-color:#ffffff; color:#000000;' onload='window.print()'>
<div style='width: 750px; border: 1px solid #000; padding: 20px;'>
<div style='text-align: center; display: block; margin: 0 0 6px 0;'>
<img src='" . XOOPS_URL . "/modules/newbb/assets/images/xoopsbb_slogo.png' border='0' alt='' >
<br><br> ";
$postsArray = $topicHandler->getAllPosts($topicObject);
foreach ($postsArray as $post) {
if (!$post->getVar('approved')) {
continue;
}
$post_data = $postHandler->getPostForPrint($post);
echo "<h2 style='margin: 0;'>" . $post_data['subject'] . "</h2>
<div align='center'>" . _POSTEDBY . ' ' . $post_data['author'] . ' ' . _ON . ' ' . formatTimestamp($post_data['date']) . "</div>
<div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>
<div>" . $post_data['text'] . "</div>
<div style='padding-top: 12px; border-top: 2px solid #ccc;'></div><br>";
}
echo '<p>' . _MD_NEWBB_COMEFROM . ' ' . XOOPS_URL . '/newbb/viewtopic.php?forum=' . $forum_id . '&topic_id=' . $topic_id . '</p>';
echo '</div></div>';
echo '</body></html>';
} else {
echo "</head><body style='background-color:#ffffff; color:#000000;' onload='window.print()'>
<div style='width: 750px; border: 1px solid #000; padding: 20px;'>
<div style='text-align: center; display: block; margin: 0 0 6px 0;'>
<h2 style='margin: 0;'>" . $post_data['subject'] . "</h2></div>
<div align='center'>" . _POSTEDBY . ' ' . $post_data['author'] . ' ' . _ON . ' ' . formatTimestamp($post_data['date']) . "</div>
<div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>
<div>" . $post_data['text'] . "</div>
<div style='padding-top: 12px; border-top: 2px solid #ccc;'></div>
<p>" . _MD_NEWBB_COMEFROM . ' ' . $post_data['url'] . '</p>
</div>
<br><br></body></html>';
}