These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | // |
||
3 | // ------------------------------------------------------------------------ // |
||
4 | // XOOPS - PHP Content Management System // |
||
5 | // Copyright (c) 2000-2016 XOOPS.org // |
||
6 | // <https://xoops.org/> // |
||
7 | // ------------------------------------------------------------------------ // |
||
8 | // This program is free software; you can redistribute it and/or modify // |
||
9 | // it under the terms of the GNU General Public License as published by // |
||
10 | // the Free Software Foundation; either version 2 of the License, or // |
||
11 | // (at your option) any later version. // |
||
12 | // // |
||
13 | // You may not change or alter any portion of this comment or credits // |
||
14 | // of supporting developers from this source code or any supporting // |
||
15 | // source code which is considered copyrighted (c) material of the // |
||
16 | // original comment or credit authors. // |
||
17 | // // |
||
18 | // This program is distributed in the hope that it will be useful, // |
||
19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
21 | // GNU General Public License for more details. // |
||
22 | // // |
||
23 | // You should have received a copy of the GNU General Public License // |
||
24 | // along with this program; if not, write to the Free Software // |
||
25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
26 | // ------------------------------------------------------------------------ // |
||
27 | // Author: phppp (D.J., [email protected]) // |
||
28 | // URL: https://xoops.org // |
||
29 | // Project: Article Project // |
||
30 | // ------------------------------------------------------------------------ // |
||
31 | |||
32 | use Xmf\Request; |
||
33 | //use tecnickcom\TCPDF; |
||
34 | |||
35 | // a complete rewrite by irmtfan to enhance: 1- RTL 2- Multilanguage (EMLH and Xlanguage) |
||
36 | error_reporting(0); |
||
37 | |||
38 | include_once __DIR__ . '/header.php'; |
||
39 | |||
40 | $attach_id = Request::getString('attachid', '', 'GET'); |
||
41 | |||
42 | $forum = Request::getInt('forum', 0, 'GET'); |
||
43 | $topic_id = Request::getInt('topic_id', 0, 'GET'); |
||
44 | $post_id = Request::getInt('post_id', 0, 'GET'); |
||
45 | |||
46 | if (!is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) { |
||
47 | redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $topic_id, 3, 'TCPDF for Xoops not installed'); |
||
48 | } |
||
49 | |||
50 | if (empty($post_id)) { |
||
51 | exit(_MD_NEWBB_ERRORTOPIC); |
||
52 | } |
||
53 | |||
54 | ///** @var \NewbbPostHandler $postHandler */ |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
55 | //$postHandler = xoops_getModuleHandler('post', 'newbb'); |
||
56 | $post = $postHandler->get($post_id); |
||
57 | if (!$approved = $post->getVar('approved')) { |
||
58 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
59 | } |
||
60 | |||
61 | $post_data = $postHandler->getPostForPDF($post); |
||
62 | //$post_edit = $post->displayPostEdit(); //reserve for future versions to display edit records |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
52% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
63 | ///** @var \NewbbTopicHandler $topicHandler */ |
||
64 | //$topicHandler = xoops_getModuleHandler('topic', 'newbb'); |
||
65 | $forumtopic = $topicHandler->getByPost($post_id); |
||
66 | $topic_id = $forumtopic->getVar('topic_id'); |
||
67 | if (!$approved = $forumtopic->getVar('approved')) { |
||
68 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
69 | } |
||
70 | |||
71 | ///** @var \NewbbForumHandler $forumHandler */ |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
72 | //$forumHandler = xoops_getModuleHandler('forum', 'newbb'); |
||
73 | $forum = $forum ?: $forumtopic->getVar('forum_id'); |
||
74 | $viewtopic_forum = $forumHandler->get($forum); |
||
75 | $parent_forums = []; |
||
76 | $parent_forums = $forumHandler->getParents($viewtopic_forum); |
||
77 | $pf_title = ''; |
||
78 | if ($parent_forums) { |
||
79 | foreach ($parent_forums as $p_f) { |
||
80 | $pf_title .= $p_f['forum_name'] . ' - '; |
||
81 | } |
||
82 | } |
||
83 | |||
84 | if (!$forumHandler->getPermission($viewtopic_forum)) { |
||
85 | exit(_MD_NEWBB_NORIGHTTOACCESS); |
||
86 | } |
||
87 | if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'view')) { |
||
88 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
89 | } |
||
90 | // irmtfan add pdf permission |
||
91 | if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'pdf')) { |
||
92 | exit(_MD_NEWBB_NORIGHTTOPDF); |
||
93 | } |
||
94 | |||
95 | //$categoryHandler = xoops_getModuleHandler('category', 'newbb'); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
59% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
96 | $cat = $viewtopic_forum->getVar('cat_id'); |
||
97 | $viewtopic_cat = $categoryHandler->get($cat); |
||
98 | |||
99 | $GLOBALS['xoopsOption']['pdf_cache'] = 0; |
||
100 | |||
101 | $pdf_data['author'] = $myts->undoHtmlSpecialChars($post_data['author']); |
||
102 | $pdf_data['title'] = $myts->undoHtmlSpecialChars($post_data['subject']); |
||
103 | $content = ''; |
||
104 | $content .= '<b>' . $pdf_data['title'] . '</b><br><br>'; |
||
105 | $content .= _MD_NEWBB_AUTHORC . ' ' . $pdf_data['author'] . '<br>'; |
||
106 | $content .= _MD_NEWBB_POSTEDON . ' ' . formatTimestamp($post_data['date']) . '<br><br><br>'; |
||
107 | $content .= $myts->undoHtmlSpecialChars($post_data['text']) . '<br>'; |
||
108 | //$content .= $post_edit . '<br>'; //reserve for future versions to display edit records |
||
109 | $pdf_data['content'] = str_replace('[pagebreak]', '<br>', $content); |
||
110 | $pdf_data['topic_title'] = $forumtopic->getVar('topic_title'); |
||
111 | $pdf_data['forum_title'] = $pf_title . $viewtopic_forum->getVar('forum_name'); |
||
112 | $pdf_data['cat_title'] = $viewtopic_cat->getVar('cat_title'); |
||
113 | $pdf_data['subject'] = _MD_NEWBB_PDF_SUBJECT . ': ' . $pdf_data['topic_title']; |
||
114 | $pdf_data['keywords'] = XOOPS_URL . ', ' . 'XOOPS Project, ' . $pdf_data['topic_title']; |
||
115 | $pdf_data['HeadFirstLine'] = $GLOBALS['xoopsConfig']['sitename'] . ' - ' . $GLOBALS['xoopsConfig']['slogan']; |
||
116 | $pdf_data['HeadSecondLine'] = _MD_NEWBB_FORUMHOME . ' - ' . $pdf_data['cat_title'] . ' - ' . $pdf_data['forum_title'] . ' - ' . $pdf_data['topic_title']; |
||
117 | |||
118 | // START irmtfan to implement EMLH by GIJ |
||
119 | if (function_exists('easiestml')) { |
||
120 | $pdf_data = easiestml($pdf_data); |
||
121 | // END irmtfan to implement EMLH by GIJ |
||
122 | // START irmtfan to implement Xlanguage by phppp(DJ) |
||
123 | } elseif (function_exists('xlanguage_ml')) { |
||
124 | $pdf_data = xlanguage_ml($pdf_data); |
||
125 | } |
||
126 | // END irmtfan to implement Xlanguage by phppp(DJ) |
||
127 | |||
128 | require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php'; |
||
129 | $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false); |
||
130 | // load $localLanguageOptions array with language specific definitions and apply |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
41% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
131 | //if (is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php')) { |
||
132 | // require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php'; |
||
133 | //} else { |
||
134 | // require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/english.php'; |
||
135 | //} |
||
136 | |||
137 | // set some language dependent data: |
||
138 | $lg = []; |
||
139 | $lg['a_meta_charset'] = _CHARSET; |
||
140 | //$lg['a_meta_dir'] = _MD_NEWBB_PDF_META_DIR; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
56% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
141 | $lg['a_meta_language'] = _LANGCODE; |
||
142 | //$lg['w_page'] = _MD_NEWBB_PDF_PAGE; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
56% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
143 | $lg['w_page'] = 'page'; |
||
144 | |||
145 | // set some language-dependent strings (optional) |
||
146 | $pdf->setLanguageArray($lg); |
||
147 | |||
148 | //$pdf->setLanguageArray($localLanguageOptions); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
86% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
149 | |||
150 | // START irmtfan hack to add RTL-LTR local |
||
151 | // until _RTL added to core 2.6.0 |
||
152 | if (!defined('_RTL')) { |
||
153 | define('_RTL', false); |
||
154 | } |
||
155 | $pdf->setRTL(_RTL); |
||
156 | // END irmtfan hack to add RTL-LTR local |
||
157 | |||
158 | // set document information |
||
159 | $pdf->SetCreator(PDF_CREATOR); |
||
160 | $pdf->SetAuthor(PDF_AUTHOR); |
||
161 | $pdf->SetTitle($pdf_data['forum_title'] . ' - ' . $pdf_data['subject']); |
||
162 | $pdf->SetSubject($pdf_data['subject']); |
||
163 | $pdf->SetKeywords($pdf_data['keywords']); |
||
164 | |||
165 | //$pdf->SetHeaderData('', '5', $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine']); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
82% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
166 | $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine'], [0, 64, 255], [0, 64, 128]); |
||
167 | |||
168 | //set margins |
||
169 | $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); |
||
170 | $pdf->setHeaderMargin(PDF_MARGIN_HEADER); |
||
171 | $pdf->setFooterMargin(PDF_MARGIN_FOOTER); |
||
172 | //set auto page breaks |
||
173 | $pdf->SetAutoPageBreak(true, 25); |
||
174 | |||
175 | $pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]); |
||
176 | $pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); |
||
177 | |||
178 | $pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]); |
||
179 | |||
180 | $pdf->Open(); |
||
181 | $pdf->AddPage(); |
||
182 | //$pdf->SetFont(PDF_FONT_NAME_MAIN, PDF_FONT_STYLE_MAIN, PDF_FONT_SIZE_MAIN); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
183 | $pdf->SetFont('dejavusans', '', 12); |
||
184 | |||
185 | $pdf->writeHTML($pdf_data['content'], true, 0); |
||
186 | $pdf->Output($pdf_data['topic_title'] . '_' . $post_id . '.pdf', 'I'); |
||
187 | |||
188 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.