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 | 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 | //use tecnickcom\TCPDF; |
||
22 | // a complete rewrite by irmtfan to enhance: 1- RTL 2- Multilanguage (EMLH and Xlanguage) |
||
23 | error_reporting(0); |
||
24 | include_once __DIR__ . '/header.php'; |
||
25 | |||
26 | $attach_id = Request::getString('attachid', '', 'GET'); |
||
27 | $forum = Request::getInt('forum', 0, 'GET'); |
||
28 | $topic_id = Request::getInt('topic_id', 0, 'GET'); |
||
29 | $post_id = Request::getInt('post_id', 0, 'GET'); |
||
30 | |||
31 | if (!is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) { |
||
32 | redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $topic_id, 3, 'TCPDF for Xoops not installed'); |
||
33 | } else { |
||
34 | require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php'; |
||
35 | } |
||
36 | |||
37 | if (empty($post_id)) { |
||
0 ignored issues
–
show
$post_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
38 | exit(_MD_NEWBB_ERRORTOPIC); |
||
39 | } |
||
40 | ///** @var \NewbbPostHandler $postHandler */ |
||
41 | //$postHandler = xoops_getModuleHandler('post', 'newbb'); |
||
42 | $post = $postHandler->get($post_id); |
||
43 | if (!$approved = $post->getVar('approved')) { |
||
44 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
45 | } |
||
46 | $post_data = $postHandler->getPostForPDF($post); |
||
47 | //$post_edit = $post->displayPostEdit(); //reserve for future versions to display edit records |
||
48 | ///** @var \NewbbTopicHandler $topicHandler */ |
||
49 | //$topicHandler = xoops_getModuleHandler('topic', 'newbb'); |
||
50 | $forumtopic = $topicHandler->getByPost($post_id); |
||
51 | $topic_id = $forumtopic->getVar('topic_id'); |
||
52 | if (!$approved = $forumtopic->getVar('approved')) { |
||
53 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
54 | } |
||
55 | ///** @var \NewbbForumHandler $forumHandler */ |
||
56 | //$forumHandler = xoops_getModuleHandler('forum', 'newbb'); |
||
57 | $forum = $forum ?: $forumtopic->getVar('forum_id'); |
||
58 | $viewtopic_forum = $forumHandler->get($forum); |
||
59 | $parent_forums = []; |
||
60 | $parent_forums = $forumHandler->getParents($viewtopic_forum); |
||
61 | $pf_title = ''; |
||
62 | if ($parent_forums) { |
||
63 | foreach ($parent_forums as $p_f) { |
||
64 | $pf_title .= $p_f['forum_name'] . ' - '; |
||
65 | } |
||
66 | } |
||
67 | if (!$forumHandler->getPermission($viewtopic_forum)) { |
||
68 | exit(_MD_NEWBB_NORIGHTTOACCESS); |
||
69 | } |
||
70 | if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'view')) { |
||
71 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
72 | } |
||
73 | // irmtfan add pdf permission |
||
74 | if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'pdf')) { |
||
75 | exit(_MD_NEWBB_NORIGHTTOPDF); |
||
76 | } |
||
77 | //$categoryHandler = xoops_getModuleHandler('category', 'newbb'); |
||
78 | $cat = $viewtopic_forum->getVar('cat_id'); |
||
79 | $viewtopic_cat = $categoryHandler->get($cat); |
||
80 | $GLOBALS['xoopsOption']['pdf_cache'] = 0; |
||
81 | $pdf_data['author'] = $myts->undoHtmlSpecialChars($post_data['author']); |
||
82 | $pdf_data['title'] = $myts->undoHtmlSpecialChars($post_data['subject']); |
||
83 | $content = ''; |
||
84 | $content .= '<b>' . $pdf_data['title'] . '</b><br><br>'; |
||
85 | $content .= _MD_NEWBB_AUTHORC . ' ' . $pdf_data['author'] . '<br>'; |
||
86 | $content .= _MD_NEWBB_POSTEDON . ' ' . formatTimestamp($post_data['date']) . '<br><br><br>'; |
||
87 | $content .= $myts->undoHtmlSpecialChars($post_data['text']) . '<br>'; |
||
88 | //$content .= $post_edit . '<br>'; //reserve for future versions to display edit records |
||
89 | $pdf_data['content'] = str_replace('[pagebreak]', '<br>', $content); |
||
90 | $pdf_data['topic_title'] = $forumtopic->getVar('topic_title'); |
||
91 | $pdf_data['forum_title'] = $pf_title . $viewtopic_forum->getVar('forum_name'); |
||
92 | $pdf_data['cat_title'] = $viewtopic_cat->getVar('cat_title'); |
||
93 | $pdf_data['subject'] = _MD_NEWBB_PDF_SUBJECT . ': ' . $pdf_data['topic_title']; |
||
94 | $pdf_data['keywords'] = XOOPS_URL . ', ' . 'XOOPS Project, ' . $pdf_data['topic_title']; |
||
95 | $pdf_data['HeadFirstLine'] = $GLOBALS['xoopsConfig']['sitename'] . ' - ' . $GLOBALS['xoopsConfig']['slogan']; |
||
96 | $pdf_data['HeadSecondLine'] = _MD_NEWBB_FORUMHOME . ' - ' . $pdf_data['cat_title'] . ' - ' . $pdf_data['forum_title'] . ' - ' . $pdf_data['topic_title']; |
||
97 | // START irmtfan to implement EMLH by GIJ |
||
98 | if (function_exists('easiestml')) { |
||
99 | $pdf_data = easiestml($pdf_data); |
||
100 | // END irmtfan to implement EMLH by GIJ |
||
101 | // START irmtfan to implement Xlanguage by phppp(DJ) |
||
102 | } elseif (function_exists('xlanguage_ml')) { |
||
103 | $pdf_data = xlanguage_ml($pdf_data); |
||
104 | } |
||
105 | // END irmtfan to implement Xlanguage by phppp(DJ) |
||
106 | |||
107 | $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false); |
||
108 | // load $localLanguageOptions array with language specific definitions and apply |
||
109 | //if (is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php')) { |
||
110 | // require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php'; |
||
111 | //} else { |
||
112 | // require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/english.php'; |
||
113 | //} |
||
114 | // set some language dependent data: |
||
115 | $lg = []; |
||
116 | $lg['a_meta_charset'] = _CHARSET; |
||
117 | //$lg['a_meta_dir'] = _MD_NEWBB_PDF_META_DIR; |
||
118 | $lg['a_meta_language'] = _LANGCODE; |
||
119 | $lg['w_page'] = _MD_NEWBB_PDF_PAGE2; |
||
120 | |||
121 | // set some language-dependent strings (optional) |
||
122 | $pdf->setLanguageArray($lg); |
||
123 | //$pdf->setLanguageArray($localLanguageOptions); |
||
124 | // set some language-dependent strings (optional) |
||
125 | $pdf->setLanguageArray($lg); |
||
126 | //$pdf->setLanguageArray($localLanguageOptions); |
||
127 | // START irmtfan hack to add RTL-LTR local |
||
128 | // until _RTL added to core 2.6.0 |
||
129 | if (!defined('_RTL')) { |
||
130 | define('_RTL', false); |
||
131 | } |
||
132 | $pdf->setRTL(_RTL); |
||
133 | // END irmtfan hack to add RTL-LTR local |
||
134 | |||
135 | // set document information |
||
136 | $pdf->SetCreator(PDF_CREATOR); |
||
137 | $pdf->SetAuthor(PDF_AUTHOR); |
||
138 | $pdf->SetTitle($pdf_data['forum_title'] . ' - ' . $pdf_data['subject']); |
||
139 | $pdf->SetSubject($pdf_data['subject']); |
||
140 | $pdf->SetKeywords($pdf_data['keywords']); |
||
141 | |||
142 | //$pdf->SetHeaderData('', '5', $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine']); |
||
143 | $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine'], [0, 64, 255], [0, 64, 128]); |
||
144 | |||
145 | //set margins |
||
146 | $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); |
||
147 | $pdf->setHeaderMargin(PDF_MARGIN_HEADER); |
||
148 | $pdf->setFooterMargin(PDF_MARGIN_FOOTER); |
||
149 | |||
150 | //set auto page breaks |
||
151 | $pdf->SetAutoPageBreak(true, 25); |
||
152 | $pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]); |
||
153 | $pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); |
||
154 | $pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]); |
||
155 | $pdf->Open(); |
||
156 | $pdf->AddPage(); |
||
157 | |||
158 | //$pdf->SetFont(PDF_FONT_NAME_MAIN, PDF_FONT_STYLE_MAIN, PDF_FONT_SIZE_MAIN); |
||
159 | $pdf->SetFont('dejavusans', '', 12); |
||
160 | $pdf->writeHTML($pdf_data['content'], true, 0); |
||
161 | $pdf->Output($pdf_data['topic_title'] . '_' . $post_id . '.pdf', 'I'); |
||
162 |
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.