Completed
Pull Request — master (#5)
by
unknown
02:25
created

makepdf.php (3 issues)

Upgrade to new PHP Analysis Engine

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
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 140 and the first side effect is on line 35.

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.

Loading history...
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
34
// a complete rewrite by irmtfan to enhance: 1- RTL 2- Multilanguage (EMLH and Xlanguage)
35
error_reporting(0);
36
37
include_once __DIR__ . '/header.php';
38
39
$attach_id = Request::getString('attachid', '', 'GET');
40
41
$forum    = Request::getInt('forum', 0, 'GET');
42
$topic_id = Request::getInt('topic_id', 0, 'GET');
43
$post_id  = Request::getInt('post_id', 0, 'GET');
44
45
if (!is_file(XOOPS_PATH . '/vendor/tcpdf/tcpdf.php')) {
46
    redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $topic_id, 3, 'TCPDF for Xoops not installed');
47
}
48
49
if (empty($post_id)) {
50
    exit(_MD_NEWBB_ERRORTOPIC);
51
}
52
53
/** @var \NewbbPostHandler $postHandler */
54
$postHandler = xoops_getModuleHandler('post', 'newbb');
55
$post        = $postHandler->get($post_id);
56
if (!$approved = $post->getVar('approved')) {
57
    exit(_MD_NEWBB_NORIGHTTOVIEW);
58
}
59
60
$post_data = $postHandler->getPostForPDF($post);
61
//$post_edit = $post->displayPostEdit();  //reserve for future versions to display edit records
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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.

Loading history...
62
/** @var \NewbbTopicHandler $topicHandler */
63
$topicHandler = xoops_getModuleHandler('topic', 'newbb');
64
$forumtopic   = $topicHandler->getByPost($post_id);
65
$topic_id     = $forumtopic->getVar('topic_id');
66
if (!$approved = $forumtopic->getVar('approved')) {
67
    exit(_MD_NEWBB_NORIGHTTOVIEW);
68
}
69
70
/** @var \NewbbForumHandler $forumHandler */
71
$forumHandler    = xoops_getModuleHandler('forum', 'newbb');
72
$forum           = $forum ?: $forumtopic->getVar('forum_id');
73
$viewtopic_forum = $forumHandler->get($forum);
74
$parent_forums   = [];
75
$parent_forums   = $forumHandler->getParents($viewtopic_forum);
76
$pf_title        = '';
77
if ($parent_forums) {
78
    foreach ($parent_forums as $p_f) {
79
        $pf_title .= $p_f['forum_name'] . ' - ';
80
    }
81
}
82
83
if (!$forumHandler->getPermission($viewtopic_forum)) {
84
    exit(_MD_NEWBB_NORIGHTTOACCESS);
85
}
86
if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'view')) {
87
    exit(_MD_NEWBB_NORIGHTTOVIEW);
88
}
89
// irmtfan add pdf permission
90
if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'pdf')) {
91
    exit(_MD_NEWBB_NORIGHTTOPDF);
92
}
93
94
$categoryHandler = xoops_getModuleHandler('category', 'newbb');
95
$cat             = $viewtopic_forum->getVar('cat_id');
96
$viewtopic_cat   = $categoryHandler->get($cat);
97
98
$GLOBALS['xoopsOption']['pdf_cache'] = 0;
99
100
$pdf_data['author'] = $myts->undoHtmlSpecialChars($post_data['author']);
101
$pdf_data['title']  = $myts->undoHtmlSpecialChars($post_data['subject']);
102
$content            = '';
103
$content .= '<b>' . $pdf_data['title'] . '</b><br><br>';
104
$content .= _MD_NEWBB_AUTHORC . ' ' . $pdf_data['author'] . '<br>';
105
$content .= _MD_NEWBB_POSTEDON . ' ' . formatTimestamp($post_data['date']) . '<br><br><br>';
106
$content .= $myts->undoHtmlSpecialChars($post_data['text']) . '<br>';
107
//$content .= $post_edit . '<br>'; //reserve for future versions to display edit records
108
$pdf_data['content']        = str_replace('[pagebreak]', '<br>', $content);
109
$pdf_data['topic_title']    = $forumtopic->getVar('topic_title');
110
$pdf_data['forum_title']    = $pf_title . $viewtopic_forum->getVar('forum_name');
111
$pdf_data['cat_title']      = $viewtopic_cat->getVar('cat_title');
112
$pdf_data['subject']        = _MD_NEWBB_PDF_SUBJECT . ': ' . $pdf_data['topic_title'];
113
$pdf_data['keywords']       = XOOPS_URL . ', ' . 'XOOPS Project, ' . $pdf_data['topic_title'];
114
$pdf_data['HeadFirstLine']  = $GLOBALS['xoopsConfig']['sitename'] . ' - ' . $GLOBALS['xoopsConfig']['slogan'];
115
$pdf_data['HeadSecondLine'] = _MD_NEWBB_FORUMHOME . ' - ' . $pdf_data['cat_title'] . ' - ' . $pdf_data['forum_title'] . ' - ' . $pdf_data['topic_title'];
116
117
// START irmtfan to implement EMLH by GIJ
118
if (function_exists('easiestml')) {
119
    $pdf_data = easiestml($pdf_data);
120
    // END irmtfan to implement EMLH by GIJ
121
    // START irmtfan to implement Xlanguage by phppp(DJ)
122
} elseif (function_exists('xlanguage_ml')) {
123
    $pdf_data = xlanguage_ml($pdf_data);
124
}
125
// END irmtfan to implement Xlanguage by phppp(DJ)
126
127
require_once XOOPS_PATH . '/vendor/tcpdf/tcpdf.php';
128
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false);
129
// load $localLanguageOptions array with language specific definitions and apply
130
if (is_file(XOOPS_PATH . '/vendor/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php')) {
131
    require_once XOOPS_PATH . '/vendor/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php';
132
} else {
133
    require_once XOOPS_PATH . '/vendor/tcpdf/config/lang/english.php';
134
}
135
$pdf->setLanguageArray($localLanguageOptions);
136
137
// START irmtfan hack to add RTL-LTR local
138
// until _RTL added to core 2.6.0
139
if (!defined('_RTL')) {
140
    define('_RTL', false);
141
}
142
$pdf->setRTL(_RTL);
143
// END irmtfan hack to add RTL-LTR local
144
145
// set document information
146
$pdf->SetCreator(PDF_CREATOR);
147
$pdf->SetAuthor(PDF_AUTHOR);
148
$pdf->SetTitle($pdf_data['forum_title'] . ' - ' . $pdf_data['subject']);
149
$pdf->SetSubject($pdf_data['subject']);
150
$pdf->SetKeywords($pdf_data['keywords']);
151
152
//$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.

Loading history...
153
$pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine'], [0, 64, 255], [0, 64, 128]);
154
155
//set margins
156
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
157
$pdf->setHeaderMargin(PDF_MARGIN_HEADER);
158
$pdf->setFooterMargin(PDF_MARGIN_FOOTER);
159
//set auto page breaks
160
$pdf->SetAutoPageBreak(true, 25);
161
162
$pdf->setHeaderFont([PDF_FONT_NAME_SUB, '', PDF_FONT_SIZE_SUB]);
163
$pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]);
164
$pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]);
165
166
$pdf->Open();
167
$pdf->AddPage();
168
$pdf->SetFont(PDF_FONT_NAME_MAIN, PDF_FONT_STYLE_MAIN, PDF_FONT_SIZE_MAIN);
169
$pdf->writeHTML($pdf_data['content'], true, 0);
170
$pdf->Output($pdf_data['topic_title'] . '_' . $post_id . '.pdf', 'I');
171