Passed
Pull Request — master (#38)
by Michael
03:42
created

makepdf.php (21 issues)

Labels
Severity
1
<?php declare(strict_types=1);
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
 * @copyright    XOOPS Project (https://xoops.org)
14
 * @license      GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author       XOOPS Development Team, Kazumi Ono (AKA onokazu)
16
 */
17
18
use Xmf\Request;
19
use XoopsModules\News\{
20
    Helper,
21
    NewsStory,
22
    Utility
23
};
24
25
error_reporting(0);
26
27
require_once __DIR__ . '/header.php';
28
29
$moduleDirName      = basename(__DIR__);
30
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
31
32
//2.5.8
33
$helper = Helper::getInstance();
34
if (is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) {
35
    require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php';
36
} else {
37
    redirect_header($helper->url('index.php'), 3, \constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_NO_PDF'));
38
}
39
$myts = \MyTextSanitizer::getInstance();
40
// require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
41
42
$storyid = Request::getInt('storyid', 0, 'GET');
43
44
if (empty($storyid)) {
45
    redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY);
46
}
47
48
$article = new NewsStory($storyid);
49
// Not yet published
50
if (0 == $article->published() || $article->published() > time()) {
51
    redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY);
52
}
53
54
// Expired
55
if (0 != $article->expired() && $article->expired() < time()) {
56
    redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY);
57
}
58
59
/** @var \XoopsGroupPermHandler $grouppermHandler */
60
$grouppermHandler = xoops_getHandler('groupperm');
61
if (is_object($xoopsUser)) {
62
    $groups = $xoopsUser->getGroups();
63
} else {
64
    $groups = XOOPS_GROUP_ANONYMOUS;
65
}
66
if (!$grouppermHandler->checkRight('news_view', $article->topicid(), $groups, $xoopsModule->getVar('mid'))) {
67
    redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
68
}
69
70
$dateformat               = Utility::getModuleOption('dateformat');
71
$article_data             = $article->hometext() . $article->bodytext();
72
$article_title            = $article->title();
73
$article_title            = Utility::html2text($myts->undoHtmlSpecialChars($article_title));
74
$forumdata['topic_title'] = $article_title;
75
$pdf_data['title']        = $article->title();
76
$topic_title              = $article->topic_title();
77
$topic_title              = Utility::html2text($myts->undoHtmlSpecialChars($topic_title));
78
$pdf_data['subtitle']     = $topic_title;
79
$pdf_data['subsubtitle']  = $article->subtitle();
80
$pdf_data['date']         = formatTimestamp($article->published(), $dateformat);
81
$pdf_data['filename']     = preg_replace('/[^0-9a-z\-_\.]/i', '', htmlspecialchars($article->topic_title(), ENT_QUOTES | ENT_HTML5) . ' - ' . $article->title());
82
$hometext                 = $article->hometext();
83
$bodytext                 = $article->bodytext();
84
$content                  = $myts->undoHtmlSpecialChars($hometext) . '<br><br>' . $myts->undoHtmlSpecialChars($bodytext);
85
$content                  = str_replace('[pagebreak]', '<br><br>', $content);
86
$pdf_data['content']      = $content;
87
88
$pdf_data['author'] = $article->uname();
89
90
//Other stuff
91
$puff   = '<br>';
92
$puffer = '<br><br>';
93
94
//create the A4-PDF...
95
$pdf_config['slogan'] = XOOPS_URL . ' - ' . $xoopsConfig['sitename'] . ' - ' . $xoopsConfig['slogan'];
96
97
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false);
0 ignored issues
show
The constant PDF_UNIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PDF_PAGE_ORIENTATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The type TCPDF was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
The constant PDF_PAGE_FORMAT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
98
99
//$pdf->setLanguageArray($localLanguageOptions);
100
101
$pdf->SetCreator(PDF_CREATOR);
0 ignored issues
show
The constant PDF_CREATOR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
102
103
$pdf->SetTitle($pdf_data['title']);
104
$pdf->SetAuthor(PDF_AUTHOR);
0 ignored issues
show
The constant PDF_AUTHOR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
105
$pdf->SetSubject($pdf_data['author']);
106
$out = PDF_AUTHOR . ', ' . $pdf_data['author'] . ', ' . $pdf_data['title'] . ', ' . $pdf_data['subtitle'] . ', ' . $pdf_data['subsubtitle'];
107
$pdf->SetKeywords($out);
108
$pdf->SetAutoPageBreak(true, 25);
109
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
0 ignored issues
show
The constant PDF_MARGIN_RIGHT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PDF_MARGIN_LEFT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PDF_MARGIN_TOP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
110
$pdf->setFooterMargin(PDF_MARGIN_FOOTER);
0 ignored issues
show
The constant PDF_MARGIN_FOOTER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
111
//$pdf->setHeaderFont(array(PDF_FONT_NAME_SUB, '', PDF_FONT_SIZE_SUB));
112
$pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]);
0 ignored issues
show
The constant PDF_FONT_NAME_DATA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PDF_FONT_SIZE_DATA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
113
$pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]);
114
//$pdf->SetHeaderData('','5',$pdf_config['slogan']);
115
$pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_config['slogan'], [0, 64, 255], [0, 64, 128]);
0 ignored issues
show
The constant PDF_HEADER_LOGO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PDF_HEADER_LOGO_WIDTH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
116
//set margins
117
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
118
$pdf->setHeaderMargin(PDF_MARGIN_HEADER);
0 ignored issues
show
The constant PDF_MARGIN_HEADER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
119
$pdf->setFooterMargin(PDF_MARGIN_FOOTER);
120
121
$pdf->Open();
122
//First page
123
$pdf->AddPage();
124
$pdf->SetXY(24, 25);
125
$pdf->SetTextColor(10, 60, 160);
126
//$pdf->SetFont(PDF_FONT_NAME_TITLE, PDF_FONT_STYLE_TITLE, PDF_FONT_SIZE_TITLE);
127
$pdf->writeHTML($pdf_data['title'] . ' - ' . $pdf_data['subtitle'], K_TITLE_MAGNIFICATION);
0 ignored issues
show
The constant K_TITLE_MAGNIFICATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
128
//$pdf->Line(25,20,190,20);
129
if ('' !== $pdf_data['subsubtitle']) {
130
    $pdf->writeHTML($puff, K_XSMALL_RATIO);
0 ignored issues
show
The constant K_XSMALL_RATIO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
131
    //    $pdf->SetFont(PDF_FONT_NAME_SUBSUB, PDF_FONT_STYLE_SUBSUB, PDF_FONT_SIZE_SUBSUB);
132
    $pdf->writeHTML($pdf_data['subsubtitle'], '1');
133
}
134
$pdf->writeHTML($puff, '0.2');
135
//$pdf->SetFont(PDF_FONT_NAME_DATA, PDF_FONT_STYLE_DATA, PDF_FONT_SIZE_DATA);
136
$out = NEWS_PDF_AUTHOR . ': ' . $pdf_data['author'] . '<br>';
0 ignored issues
show
The constant NEWS_PDF_AUTHOR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
137
$pdf->writeHTML($out, '0.2');
138
$out = NEWS_PDF_DATE . ': ' . $pdf_data['date'] . '<br>';
0 ignored issues
show
The constant NEWS_PDF_DATE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
139
$pdf->writeHTML($out, '0.2');
140
$pdf->SetTextColor(0, 0, 0);
141
$pdf->writeHTML($puffer, '1');
142
143
//$pdf->SetFont(PDF_FONT_NAME_MAIN, PDF_FONT_STYLE_MAIN, PDF_FONT_SIZE_MAIN);
144
$pdf->writeHTML($pdf_data['content'], $pdf_config['scale']);
145
146
//2.5.8
147
$pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]);
0 ignored issues
show
The constant PDF_FONT_NAME_MAIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PDF_FONT_SIZE_MAIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
148
$pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]);
149
150
$pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]);
151
152
//initialize document
153
$pdf->Open();
154
$pdf->AddPage();
155
$pdf->writeHTML($content, true, 0, true, 0);
156
157
$pdf->Output();
158