Passed
Branch master (d35ec9)
by Michael
03:38 queued 11s
created

makepdf.php (17 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * File : makepdf.php for publisher
7
 * For tcpdf_for_xoops 2.01 and higher
8
 * Created by montuy337513 / philodenelle - http://www.chg-web.org
9
 */
10
11
use Xmf\Request;
12
use XoopsModules\Publisher\{Utility
13
};
14
15
error_reporting(E_ALL);
16
17
require_once __DIR__ . '/header.php';
18
19
$itemId     = Request::getInt('itemid', 0, 'GET');
20
$itemPageId = Request::getInt('page', -1, 'GET');
21
if (0 == $itemId) {
22
    redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED);
23
}
24
25
//2.5.8
26
require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php';
27
28
// Creating the item object for the selected item
29
$itemObj = $helper->getHandler('Item')->get($itemId);
30
31
// if the selected item was not found, exit
32
if (!$itemObj) {
33
    redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED);
34
}
35
36
// Creating the category object that holds the selected item
37
$categoryObj = $helper->getHandler('Category')->get($itemObj->categoryid());
38
39
// Check user permissions to access that category of the selected item
40
if (!$itemObj->accessGranted()) {
41
    redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM);
42
}
43
44
$helper->loadLanguage('main');
45
46
$dateformat    = $itemObj->getDatesub();
47
$sender_inform = sprintf(_MD_PUBLISHER_WHO_WHEN, $itemObj->posterName(), $itemObj->getDatesub());
48
$mainImage     = $itemObj->getMainImage();
49
50
$content = '';
51
if (empty($mainImage['image_path'])) {
52
    $content .= '<img src="' . PUBLISHER_URL . '/assets/images/default_image.jpg" alt="' . $myts->undoHtmlSpecialChars($mainImage['image_name']) . '"><br>';
53
}
54
if ('' != $mainImage['image_path']) {
55
    $content .= '<img src="' . $mainImage['image_path'] . '" alt="' . $myts->undoHtmlSpecialChars($mainImage['image_name']) . '"><br>';
56
}
57
$content .= '<a href="' . PUBLISHER_URL . '/item.php?itemid=' . $itemId . '" style="text-decoration: none; color: #000000; font-size: 120%;" title="' . $myts->undoHtmlSpecialChars($itemObj->getTitle()) . '">' . $myts->undoHtmlSpecialChars($itemObj->getTitle()) . '</a>';
58
$content .= '<br><span style="color: #CCCCCC; font-weight: bold; font-size: 80%;">'
59
            . _CO_PUBLISHER_CATEGORY
60
            . ' : </span><a href="'
61
            . PUBLISHER_URL
62
            . '/category.php?categoryid='
63
            . $itemObj->categoryid()
64
            . '" style="color: #CCCCCC; font-weight: bold; font-size: 80%;" title="'
65
            . $myts->undoHtmlSpecialChars($categoryObj->name())
66
            . '">'
67
            . $myts->undoHtmlSpecialChars($categoryObj->name())
68
            . '</a>';
69
$content .= '<br><span style="font-size: 80%; font-style: italic;">' . $sender_inform . '</span><br>';
70
$content .= $itemObj->getBody();
71
$content = str_replace('[pagebreak]', '', $content);
72
73
// Configuration for TCPDF_for_XOOPS
74
$pdf_data = [
75
    'author'           => $itemObj->posterName(),
76
    'title'            => $myts->undoHtmlSpecialChars($categoryObj->name()),
77
    'page_format'      => 'A4',
78
    'page_orientation' => 'P',
79
    'unit'             => 'mm',
80
    'rtl'              => false, //true if right to left
81
];
82
83
$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false);
0 ignored issues
show
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...
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...
84
85
$doc_title  = Utility::convertCharset($myts->undoHtmlSpecialChars($itemObj->getTitle()));
86
$docSubject = $myts->undoHtmlSpecialChars($categoryObj->name());
87
88
$docKeywords = $myts->undoHtmlSpecialChars($itemObj->meta_keywords());
89
if (array_key_exists('rtl', $pdf_data)) {
90
    $pdf->setRTL($pdf_data['rtl']);
91
}
92
// set document information
93
$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...
94
$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...
95
$pdf->SetTitle($doc_title);
96
$pdf->SetSubject($docSubject);
97
//$pdf->SetKeywords(XOOPS_URL . ', '.' by TCPDF_for_XOOPS (chg-web.org), '.$doc_title);
98
$pdf->SetKeywords($docKeywords);
99
100
$firstLine  = Utility::convertCharset($GLOBALS['xoopsConfig']['sitename']) . ' (' . XOOPS_URL . ')';
101
$secondLine = Utility::convertCharset($GLOBALS['xoopsConfig']['slogan']);
102
103
$PDF_HEADER_LOGO       = '_blank.png';
104
$PDF_HEADER_LOGO_WIDTH = '';
105
106
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $firstLine, $secondLine);
107
$pdf->setHeaderData($PDF_HEADER_LOGO, $PDF_HEADER_LOGO_WIDTH, $firstLine, $secondLine);
108
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
109
110
//print : disable the possibility to print the PDF from any PDF viewer.
111
//modify : prevent the modification of contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
112
//copy : prevent the copy or otherwise extract text and graphics from the document;
113
//annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);
114
//fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
115
//extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
116
//assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
117
//print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.
118
//owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
119
120
$pdf->SetProtection(['modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble']);
121
122
//set margins
123
$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_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...
124
$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...
125
//set auto page breaks
126
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
0 ignored issues
show
The constant PDF_MARGIN_BOTTOM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
127
128
$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...
129
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set image scale factor
0 ignored issues
show
The constant PDF_IMAGE_SCALE_RATIO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
130
131
//2.5.8
132
$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...
133
$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...
134
135
$pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]);
136
137
//initialize document
138
$pdf->Open();
139
$pdf->AddPage();
140
$pdf->writeHTML($content, true, 0, true, 0);
141
$pdf->Output();
142