Passed
Pull Request — master (#30)
by
unknown
04:00
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
use XoopsModules\News\Helper;
21
use XoopsModules\News\NewsStory;
22
23
error_reporting(0);
24
25
require_once __DIR__ . '/header.php';
26
27
$moduleDirName      = basename(__DIR__);
28
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
29
30
//2.5.8
31
$helper = Helper::getInstance();
32
if (is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) {
33
    require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php';
34
} else {
35
    redirect_header($helper->url('index.php'), 3, \constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_NO_PDF'));
36
}
37
$myts = \MyTextSanitizer::getInstance();
38
// require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
39
40
$storyid = Request::getInt('storyid', 0, 'GET');
41
42
if (empty($storyid)) {
43
    redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY);
44
}
45
46
$article = new NewsStory($storyid);
47
// Not yet published
48
if (0 == $article->published() || $article->published() > time()) {
49
    redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY);
50
}
51
52
// Expired
53
if (0 != $article->expired() && $article->expired() < time()) {
54
    redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY);
55
}
56
57
/** @var \XoopsGroupPermHandler $grouppermHandler */
58
$grouppermHandler = xoops_getHandler('groupperm');
59
if (is_object($xoopsUser)) {
60
    $groups = $xoopsUser->getGroups();
61
} else {
62
    $groups = XOOPS_GROUP_ANONYMOUS;
63
}
64
if (!$grouppermHandler->checkRight('news_view', $article->topicid(), $groups, $xoopsModule->getVar('mid'))) {
65
    redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
66
}
67
68
$dateformat               = News\Utility::getModuleOption('dateformat');
69
$article_data             = $article->hometext() . $article->bodytext();
70
$article_title            = $article->title();
71
$article_title            = News\Utility::html2text($myts->undoHtmlSpecialChars($article_title));
72
$forumdata['topic_title'] = $article_title;
73
$pdf_data['title']        = $article->title();
74
$topic_title              = $article->topic_title();
75
$topic_title              = News\Utility::html2text($myts->undoHtmlSpecialChars($topic_title));
76
$pdf_data['subtitle']     = $topic_title;
77
$pdf_data['subsubtitle']  = $article->subtitle();
78
$pdf_data['date']         = formatTimestamp($article->published(), $dateformat);
79
$pdf_data['filename']     = preg_replace('/[^0-9a-z\-_\.]/i', '', htmlspecialchars($article->topic_title(), ENT_QUOTES | ENT_HTML5) . ' - ' . $article->title());
80
$hometext                 = $article->hometext();
81
$bodytext                 = $article->bodytext();
82
$content                  = $myts->undoHtmlSpecialChars($hometext) . '<br><br>' . $myts->undoHtmlSpecialChars($bodytext);
83
$content                  = str_replace('[pagebreak]', '<br><br>', $content);
84
$pdf_data['content']      = $content;
85
86
$pdf_data['author'] = $article->uname();
87
88
//Other stuff
89
$puff   = '<br>';
90
$puffer = '<br><br>';
91
92
//create the A4-PDF...
93
$pdf_config['slogan'] = XOOPS_URL . ' - ' . $xoopsConfig['sitename'] . ' - ' . $xoopsConfig['slogan'];
94
95
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false);
0 ignored issues
show
The constant PDF_PAGE_ORIENTATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PDF_UNIT 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...
96
97
//$pdf->setLanguageArray($localLanguageOptions);
98
99
$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...
100
101
$pdf->SetTitle($pdf_data['title']);
102
$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...
103
$pdf->SetSubject($pdf_data['author']);
104
$out = PDF_AUTHOR . ', ' . $pdf_data['author'] . ', ' . $pdf_data['title'] . ', ' . $pdf_data['subtitle'] . ', ' . $pdf_data['subsubtitle'];
105
$pdf->SetKeywords($out);
106
$pdf->SetAutoPageBreak(true, 25);
107
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
0 ignored issues
show
The constant PDF_MARGIN_TOP 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_RIGHT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
108
$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...
109
//$pdf->setHeaderFont(array(PDF_FONT_NAME_SUB, '', PDF_FONT_SIZE_SUB));
110
$pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]);
0 ignored issues
show
The constant PDF_FONT_SIZE_DATA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PDF_FONT_NAME_DATA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
111
$pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]);
112
//$pdf->SetHeaderData('','5',$pdf_config['slogan']);
113
$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_WIDTH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PDF_HEADER_LOGO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
114
//set margins
115
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
116
$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...
117
$pdf->setFooterMargin(PDF_MARGIN_FOOTER);
118
119
$pdf->Open();
120
//First page
121
$pdf->AddPage();
122
$pdf->SetXY(24, 25);
123
$pdf->SetTextColor(10, 60, 160);
124
//$pdf->SetFont(PDF_FONT_NAME_TITLE, PDF_FONT_STYLE_TITLE, PDF_FONT_SIZE_TITLE);
125
$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...
126
//$pdf->Line(25,20,190,20);
127
if ('' !== $pdf_data['subsubtitle']) {
128
    $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...
129
    //    $pdf->SetFont(PDF_FONT_NAME_SUBSUB, PDF_FONT_STYLE_SUBSUB, PDF_FONT_SIZE_SUBSUB);
130
    $pdf->writeHTML($pdf_data['subsubtitle'], '1');
131
}
132
$pdf->writeHTML($puff, '0.2');
133
//$pdf->SetFont(PDF_FONT_NAME_DATA, PDF_FONT_STYLE_DATA, PDF_FONT_SIZE_DATA);
134
$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...
135
$pdf->writeHTML($out, '0.2');
136
$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...
137
$pdf->writeHTML($out, '0.2');
138
$pdf->SetTextColor(0, 0, 0);
139
$pdf->writeHTML($puffer, '1');
140
141
//$pdf->SetFont(PDF_FONT_NAME_MAIN, PDF_FONT_STYLE_MAIN, PDF_FONT_SIZE_MAIN);
142
$pdf->writeHTML($pdf_data['content'], $pdf_config['scale']);
143
144
//2.5.8
145
$pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]);
0 ignored issues
show
The constant PDF_FONT_SIZE_MAIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The constant PDF_FONT_NAME_MAIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
146
$pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]);
147
148
$pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]);
149
150
//initialize document
151
$pdf->Open();
152
$pdf->AddPage();
153
$pdf->writeHTML($content, true, 0, true, 0);
154
155
$pdf->Output();
156