Completed
Push — master ( 0a3d23...5fac45 )
by Michael
02:58
created

makepdf.php (1 issue)

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
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
use Xmf\Request;
32
//use tecnickcom\TCPDF;
33
// a complete rewrite by irmtfan to enhance: 1- RTL 2- Multilanguage (EMLH and Xlanguage)
34
error_reporting(0);
35
include_once __DIR__ . '/header.php';
36
$attach_id = Request::getString('attachid', '', 'GET');
37
$forum    = Request::getInt('forum', 0, 'GET');
38
$topic_id = Request::getInt('topic_id', 0, 'GET');
39
$post_id  = Request::getInt('post_id', 0, 'GET');
40
41
if (!is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) {
42
    redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $topic_id, 3, 'TCPDF for Xoops not installed');
43
}
44
if (empty($post_id)) {
45
    exit(_MD_NEWBB_ERRORTOPIC);
46
}
47
///** @var \NewbbPostHandler $postHandler */
48
//$postHandler = xoops_getModuleHandler('post', 'newbb');
49
$post = $postHandler->get($post_id);
50
if (!$approved = $post->getVar('approved')) {
51
    exit(_MD_NEWBB_NORIGHTTOVIEW);
52
}
53
$post_data = $postHandler->getPostForPDF($post);
54
//$post_edit = $post->displayPostEdit();  //reserve for future versions to display edit records
55
///** @var \NewbbTopicHandler $topicHandler */
56
//$topicHandler = xoops_getModuleHandler('topic', 'newbb');
57
$forumtopic = $topicHandler->getByPost($post_id);
58
$topic_id   = $forumtopic->getVar('topic_id');
59
if (!$approved = $forumtopic->getVar('approved')) {
60
    exit(_MD_NEWBB_NORIGHTTOVIEW);
61
}
62
///** @var \NewbbForumHandler $forumHandler */
63
//$forumHandler    = xoops_getModuleHandler('forum', 'newbb');
64
$forum           = $forum ?: $forumtopic->getVar('forum_id');
65
$viewtopic_forum = $forumHandler->get($forum);
66
$parent_forums   = [];
67
$parent_forums   = $forumHandler->getParents($viewtopic_forum);
68
$pf_title        = '';
69
if ($parent_forums) {
70
    foreach ($parent_forums as $p_f) {
71
        $pf_title .= $p_f['forum_name'] . ' - ';
72
    }
73
}
74
if (!$forumHandler->getPermission($viewtopic_forum)) {
75
    exit(_MD_NEWBB_NORIGHTTOACCESS);
76
}
77
if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'view')) {
78
    exit(_MD_NEWBB_NORIGHTTOVIEW);
79
}
80
// irmtfan add pdf permission
81
if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'pdf')) {
82
    exit(_MD_NEWBB_NORIGHTTOPDF);
83
}
84
//$categoryHandler = xoops_getModuleHandler('category', 'newbb');
85
$cat           = $viewtopic_forum->getVar('cat_id');
86
$viewtopic_cat = $categoryHandler->get($cat);
87
$GLOBALS['xoopsOption']['pdf_cache'] = 0;
88
$pdf_data['author'] = $myts->undoHtmlSpecialChars($post_data['author']);
89
$pdf_data['title']  = $myts->undoHtmlSpecialChars($post_data['subject']);
90
$content            = '';
91
$content            .= '<b>' . $pdf_data['title'] . '</b><br><br>';
92
$content            .= _MD_NEWBB_AUTHORC . ' ' . $pdf_data['author'] . '<br>';
93
$content            .= _MD_NEWBB_POSTEDON . ' ' . formatTimestamp($post_data['date']) . '<br><br><br>';
94
$content            .= $myts->undoHtmlSpecialChars($post_data['text']) . '<br>';
95
//$content .= $post_edit . '<br>'; //reserve for future versions to display edit records
96
$pdf_data['content']        = str_replace('[pagebreak]', '<br>', $content);
97
$pdf_data['topic_title']    = $forumtopic->getVar('topic_title');
98
$pdf_data['forum_title']    = $pf_title . $viewtopic_forum->getVar('forum_name');
99
$pdf_data['cat_title']      = $viewtopic_cat->getVar('cat_title');
100
$pdf_data['subject']        = _MD_NEWBB_PDF_SUBJECT . ': ' . $pdf_data['topic_title'];
101
$pdf_data['keywords']       = XOOPS_URL . ', ' . 'XOOPS Project, ' . $pdf_data['topic_title'];
102
$pdf_data['HeadFirstLine']  = $GLOBALS['xoopsConfig']['sitename'] . ' - ' . $GLOBALS['xoopsConfig']['slogan'];
103
$pdf_data['HeadSecondLine'] = _MD_NEWBB_FORUMHOME . ' - ' . $pdf_data['cat_title'] . ' - ' . $pdf_data['forum_title'] . ' - ' . $pdf_data['topic_title'];
104
// START irmtfan to implement EMLH by GIJ
105
if (function_exists('easiestml')) {
106
    $pdf_data = easiestml($pdf_data);
107
    // END irmtfan to implement EMLH by GIJ
108
    // START irmtfan to implement Xlanguage by phppp(DJ)
109
} elseif (function_exists('xlanguage_ml')) {
110
    $pdf_data = xlanguage_ml($pdf_data);
111
}
112
// END irmtfan to implement Xlanguage by phppp(DJ)
113
require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php';
114
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false);
115
// load $localLanguageOptions array with language specific definitions and apply
116
//if (is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php')) {
117
//    require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php';
118
//} else {
119
//    require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/english.php';
120
//}
121
// set some language dependent data:
122
$lg                    = [];
123
$lg['a_meta_charset']  = _CHARSET;
124
//$lg['a_meta_dir']      = _MD_NEWBB_PDF_META_DIR;
125
$lg['a_meta_language'] = _LANGCODE;
126
//$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.

Loading history...
127
$lg['w_page']          = 'page';
128
// set some language-dependent strings (optional)
129
$pdf->setLanguageArray($lg);
130
//$pdf->setLanguageArray($localLanguageOptions);
131
// set some language-dependent strings (optional)
132
$pdf->setLanguageArray($lg);
133
//$pdf->setLanguageArray($localLanguageOptions);
134
// START irmtfan hack to add RTL-LTR local
135
// until _RTL added to core 2.6.0
136
if (!defined('_RTL')) {
137
    define('_RTL', false);
138
}
139
$pdf->setRTL(_RTL);
140
// END irmtfan hack to add RTL-LTR local
141
// set document information
142
$pdf->SetCreator(PDF_CREATOR);
143
$pdf->SetAuthor(PDF_AUTHOR);
144
$pdf->SetTitle($pdf_data['forum_title'] . ' - ' . $pdf_data['subject']);
145
$pdf->SetSubject($pdf_data['subject']);
146
$pdf->SetKeywords($pdf_data['keywords']);
147
//$pdf->SetHeaderData('', '5', $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine']);
148
$pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine'], [0, 64, 255], [0, 64, 128]);
149
//set margins
150
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
151
$pdf->setHeaderMargin(PDF_MARGIN_HEADER);
152
$pdf->setFooterMargin(PDF_MARGIN_FOOTER);
153
//set auto page breaks
154
$pdf->SetAutoPageBreak(true, 25);
155
$pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]);
156
$pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]);
157
$pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]);
158
$pdf->Open();
159
$pdf->AddPage();
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