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