Completed
Push — master ( 5eefd1...62af87 )
by Michael
14s
created

makepdf.php (2 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 137 and the first side effect is on line 34.

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
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)) {
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.

Loading history...
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_PAGE2;
127
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
142
// set document information
143
$pdf->SetCreator(PDF_CREATOR);
144
$pdf->SetAuthor(PDF_AUTHOR);
145
$pdf->SetTitle($pdf_data['forum_title'] . ' - ' . $pdf_data['subject']);
146
$pdf->SetSubject($pdf_data['subject']);
147
$pdf->SetKeywords($pdf_data['keywords']);
148
149
//$pdf->SetHeaderData('', '5', $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine']);
150
$pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine'], [0, 64, 255], [0, 64, 128]);
151
152
//set margins
153
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
154
$pdf->setHeaderMargin(PDF_MARGIN_HEADER);
155
$pdf->setFooterMargin(PDF_MARGIN_FOOTER);
156
157
//set auto page breaks
158
$pdf->SetAutoPageBreak(true, 25);
159
$pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]);
160
$pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]);
161
$pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]);
162
$pdf->Open();
163
$pdf->AddPage();
164
165
//$pdf->SetFont(PDF_FONT_NAME_MAIN, PDF_FONT_STYLE_MAIN, PDF_FONT_SIZE_MAIN);
166
$pdf->SetFont('dejavusans', '', 12);
167
$pdf->writeHTML($pdf_data['content'], true, 0);
168
$pdf->Output($pdf_data['topic_title'] . '_' . $post_id . '.pdf', 'I');
169