1 | <?php |
||
2 | /* |
||
3 | You may not change or alter any portion of this comment or credits |
||
4 | of supporting developers from this source code or any supporting source code |
||
5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
6 | |||
7 | This program is distributed in the hope that it will be useful, |
||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * oledrion |
||
14 | * |
||
15 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
16 | * @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
||
17 | * @author phppp (D.J., [email protected]) |
||
18 | */ |
||
19 | |||
20 | use Xmf\Request; |
||
21 | |||
22 | //use tecnickcom\TCPDF; |
||
23 | |||
24 | // a complete rewrite by irmtfan to enhance: 1- RTL 2- Multilanguage (EMLH and Xlanguage) |
||
25 | error_reporting(0); |
||
26 | require_once __DIR__ . '/header.php'; |
||
27 | |||
28 | $attach_id = Request::getString('attachid', '', 'GET'); |
||
29 | $forum = Request::getInt('forum', 0, 'GET'); |
||
30 | $topic_id = Request::getInt('topic_id', 0, 'GET'); |
||
31 | $post_id = Request::getInt('post_id', 0, 'GET'); |
||
32 | |||
33 | if (!is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) { |
||
34 | redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $topic_id, 3, 'TCPDF for Xoops not installed'); |
||
35 | } else { |
||
36 | require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php'; |
||
37 | } |
||
38 | |||
39 | if (empty($post_id)) { |
||
40 | exit(_MD_NEWBB_ERRORTOPIC); |
||
41 | } |
||
42 | ///** @var Newbb\PostHandler $postHandler */ |
||
43 | //$postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
||
44 | $post = $postHandler->get($post_id); |
||
45 | if (!$approved = $post->getVar('approved')) { |
||
46 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
47 | } |
||
48 | $post_data = $postHandler->getPostForPDF($post); |
||
49 | //$post_edit = $post->displayPostEdit(); //reserve for future versions to display edit records |
||
50 | ///** @var Newbb\TopicHandler $topicHandler */ |
||
51 | //$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
||
52 | $forumtopic = $topicHandler->getByPost($post_id); |
||
53 | $topic_id = $forumtopic->getVar('topic_id'); |
||
54 | if (!$approved = $forumtopic->getVar('approved')) { |
||
55 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
56 | } |
||
57 | ///** @var Newbb\ForumHandler $forumHandler */ |
||
58 | //$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
||
59 | $forum = $forum ?: $forumtopic->getVar('forum_id'); |
||
60 | $viewtopic_forum = $forumHandler->get($forum); |
||
61 | $parent_forums = []; |
||
62 | $parent_forums = $forumHandler->getParents($viewtopic_forum); |
||
63 | $pf_title = ''; |
||
64 | if ($parent_forums) { |
||
65 | foreach ($parent_forums as $p_f) { |
||
66 | $pf_title .= $p_f['forum_name'] . ' - '; |
||
67 | } |
||
68 | } |
||
69 | if (!$forumHandler->getPermission($viewtopic_forum)) { |
||
70 | exit(_MD_NEWBB_NORIGHTTOACCESS); |
||
71 | } |
||
72 | if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'view')) { |
||
73 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
74 | } |
||
75 | // irmtfan add pdf permission |
||
76 | if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'pdf')) { |
||
77 | exit(_MD_NEWBB_NORIGHTTOPDF); |
||
78 | } |
||
79 | //$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
||
80 | $cat = $viewtopic_forum->getVar('cat_id'); |
||
81 | $viewtopic_cat = $categoryHandler->get($cat); |
||
82 | $GLOBALS['xoopsOption']['pdf_cache'] = 0; |
||
83 | $pdf_data['author'] = $myts->undoHtmlSpecialChars($post_data['author']); |
||
84 | $pdf_data['title'] = $myts->undoHtmlSpecialChars($post_data['subject']); |
||
85 | $content = ''; |
||
86 | $content .= '<b>' . $pdf_data['title'] . '</b><br><br>'; |
||
87 | $content .= _MD_NEWBB_AUTHORC . ' ' . $pdf_data['author'] . '<br>'; |
||
88 | $content .= _MD_NEWBB_POSTEDON . ' ' . formatTimestamp($post_data['date']) . '<br><br><br>'; |
||
89 | $content .= $myts->undoHtmlSpecialChars($post_data['text']) . '<br>'; |
||
90 | //$content .= $post_edit . '<br>'; //reserve for future versions to display edit records |
||
91 | $pdf_data['content'] = str_replace('[pagebreak]', '<br>', $content); |
||
92 | $pdf_data['topic_title'] = $forumtopic->getVar('topic_title'); |
||
93 | $pdf_data['forum_title'] = $pf_title . $viewtopic_forum->getVar('forum_name'); |
||
94 | $pdf_data['cat_title'] = $viewtopic_cat->getVar('cat_title'); |
||
95 | $pdf_data['subject'] = _MD_NEWBB_PDF_SUBJECT . ': ' . $pdf_data['topic_title']; |
||
96 | $pdf_data['keywords'] = XOOPS_URL . ', ' . 'XOOPS Project, ' . $pdf_data['topic_title']; |
||
97 | $pdf_data['HeadFirstLine'] = $GLOBALS['xoopsConfig']['sitename'] . ' - ' . $GLOBALS['xoopsConfig']['slogan']; |
||
98 | $pdf_data['HeadSecondLine'] = _MD_NEWBB_FORUMHOME . ' - ' . $pdf_data['cat_title'] . ' - ' . $pdf_data['forum_title'] . ' - ' . $pdf_data['topic_title']; |
||
99 | // START irmtfan to implement EMLH by GIJ |
||
100 | if (function_exists('easiestml')) { |
||
101 | $pdf_data = easiestml($pdf_data); |
||
102 | // END irmtfan to implement EMLH by GIJ |
||
103 | // START irmtfan to implement Xlanguage by phppp(DJ) |
||
104 | } elseif (function_exists('xlanguage_ml')) { |
||
105 | $pdf_data = xlanguage_ml($pdf_data); |
||
106 | } |
||
107 | // END irmtfan to implement Xlanguage by phppp(DJ) |
||
108 | |||
109 | $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() The type
TCPDF was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
110 | // load $localLanguageOptions array with language specific definitions and apply |
||
111 | //if (is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php')) { |
||
112 | // require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php'; |
||
113 | //} else { |
||
114 | // require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/english.php'; |
||
115 | //} |
||
116 | // set some language dependent data: |
||
117 | $lg = []; |
||
118 | $lg['a_meta_charset'] = _CHARSET; |
||
119 | //$lg['a_meta_dir'] = _MD_NEWBB_PDF_META_DIR; |
||
120 | $lg['a_meta_language'] = _LANGCODE; |
||
121 | $lg['w_page'] = _MD_NEWBB_PDF_PAGE2; |
||
122 | |||
123 | // set some language-dependent strings (optional) |
||
124 | $pdf->setLanguageArray($lg); |
||
125 | //$pdf->setLanguageArray($localLanguageOptions); |
||
126 | // set some language-dependent strings (optional) |
||
127 | $pdf->setLanguageArray($lg); |
||
128 | //$pdf->setLanguageArray($localLanguageOptions); |
||
129 | // START irmtfan hack to add RTL-LTR local |
||
130 | // until _RTL added to core 2.6.0 |
||
131 | if (!defined('_RTL')) { |
||
132 | define('_RTL', false); |
||
133 | } |
||
134 | $pdf->setRTL(_RTL); |
||
135 | // END irmtfan hack to add RTL-LTR local |
||
136 | |||
137 | // set document information |
||
138 | $pdf->SetCreator(PDF_CREATOR); |
||
0 ignored issues
–
show
|
|||
139 | $pdf->SetAuthor(PDF_AUTHOR); |
||
0 ignored issues
–
show
|
|||
140 | $pdf->SetTitle($pdf_data['forum_title'] . ' - ' . $pdf_data['subject']); |
||
141 | $pdf->SetSubject($pdf_data['subject']); |
||
142 | $pdf->SetKeywords($pdf_data['keywords']); |
||
143 | |||
144 | //$pdf->SetHeaderData('', '5', $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine']); |
||
145 | $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine'], [0, 64, 255], [0, 64, 128]); |
||
0 ignored issues
–
show
|
|||
146 | |||
147 | //set margins |
||
148 | $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); |
||
0 ignored issues
–
show
|
|||
149 | $pdf->setHeaderMargin(PDF_MARGIN_HEADER); |
||
0 ignored issues
–
show
|
|||
150 | $pdf->setFooterMargin(PDF_MARGIN_FOOTER); |
||
0 ignored issues
–
show
|
|||
151 | |||
152 | //set auto page breaks |
||
153 | $pdf->SetAutoPageBreak(true, 25); |
||
154 | $pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]); |
||
0 ignored issues
–
show
|
|||
155 | $pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); |
||
0 ignored issues
–
show
|
|||
156 | $pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]); |
||
157 | $pdf->Open(); |
||
158 | $pdf->AddPage(); |
||
159 | |||
160 | //$pdf->SetFont(PDF_FONT_NAME_MAIN, PDF_FONT_STYLE_MAIN, PDF_FONT_SIZE_MAIN); |
||
161 | $pdf->SetFont('dejavusans', '', 12); |
||
162 | $pdf->writeHTML($pdf_data['content'], true, 0); |
||
163 | $pdf->Output($pdf_data['topic_title'] . '_' . $post_id . '.pdf', 'I'); |
||
164 |